soundbus.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * soundbus generic definitions
  3. *
  4. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * GPL v2, can be found in COPYING.
  7. */
  8. #ifndef __SOUNDBUS_H
  9. #define __SOUNDBUS_H
  10. #include <linux/of_device.h>
  11. #include <sound/pcm.h>
  12. #include <linux/list.h>
  13. /* When switching from master to slave or the other way around,
  14. * you don't want to have the codec chip acting as clock source
  15. * while the bus still is.
  16. * More importantly, while switch from slave to master, you need
  17. * to turn off the chip's master function first, but then there's
  18. * no clock for a while and other chips might reset, so we notify
  19. * their drivers after having switched.
  20. * The constants here are codec-point of view, so when we switch
  21. * the soundbus to master we tell the codec we're going to switch
  22. * and give it CLOCK_SWITCH_PREPARE_SLAVE!
  23. */
  24. enum clock_switch {
  25. CLOCK_SWITCH_PREPARE_SLAVE,
  26. CLOCK_SWITCH_PREPARE_MASTER,
  27. CLOCK_SWITCH_SLAVE,
  28. CLOCK_SWITCH_MASTER,
  29. CLOCK_SWITCH_NOTIFY,
  30. };
  31. /* information on a transfer the codec can take */
  32. struct transfer_info {
  33. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  34. unsigned int rates; /* SNDRV_PCM_RATE_* */
  35. /* flags */
  36. u32 transfer_in:1, /* input = 1, output = 0 */
  37. must_be_clock_source:1;
  38. /* for codecs to distinguish among their TIs */
  39. int tag;
  40. };
  41. struct codec_info_item {
  42. struct codec_info *codec;
  43. void *codec_data;
  44. struct soundbus_dev *sdev;
  45. /* internal, to be used by the soundbus provider */
  46. struct list_head list;
  47. };
  48. /* for prepare, where the codecs need to know
  49. * what we're going to drive the bus with */
  50. struct bus_info {
  51. /* see below */
  52. int sysclock_factor;
  53. int bus_factor;
  54. };
  55. /* information on the codec itself, plus function pointers */
  56. struct codec_info {
  57. /* the module this lives in */
  58. struct module *owner;
  59. /* supported transfer possibilities, array terminated by
  60. * formats or rates being 0. */
  61. struct transfer_info *transfers;
  62. /* Master clock speed factor
  63. * to be used (master clock speed = sysclock_factor * sampling freq)
  64. * Unused if the soundbus provider has no such notion.
  65. */
  66. int sysclock_factor;
  67. /* Bus factor, bus clock speed = bus_factor * sampling freq)
  68. * Unused if the soundbus provider has no such notion.
  69. */
  70. int bus_factor;
  71. /* operations */
  72. /* clock switching, see above */
  73. int (*switch_clock)(struct codec_info_item *cii,
  74. enum clock_switch clock);
  75. /* called for each transfer_info when the user
  76. * opens the pcm device to determine what the
  77. * hardware can support at this point in time.
  78. * That can depend on other user-switchable controls.
  79. * Return 1 if usable, 0 if not.
  80. * out points to another instance of a transfer_info
  81. * which is initialised to the values in *ti, and
  82. * it's format and rate values can be modified by
  83. * the callback if it is necessary to further restrict
  84. * the formats that can be used at the moment, for
  85. * example when one codec has multiple logical codec
  86. * info structs for multiple inputs.
  87. */
  88. int (*usable)(struct codec_info_item *cii,
  89. struct transfer_info *ti,
  90. struct transfer_info *out);
  91. /* called when pcm stream is opened, probably not implemented
  92. * most of the time since it isn't too useful */
  93. int (*open)(struct codec_info_item *cii,
  94. struct snd_pcm_substream *substream);
  95. /* called when the pcm stream is closed, at this point
  96. * the user choices can all be unlocked (see below) */
  97. int (*close)(struct codec_info_item *cii,
  98. struct snd_pcm_substream *substream);
  99. /* if the codec must forbid some user choices because
  100. * they are not valid with the substream/transfer info,
  101. * it must do so here. Example: no digital output for
  102. * incompatible framerate, say 8KHz, on Onyx.
  103. * If the selected stuff in the substream is NOT
  104. * compatible, you have to reject this call! */
  105. int (*prepare)(struct codec_info_item *cii,
  106. struct bus_info *bi,
  107. struct snd_pcm_substream *substream);
  108. /* start() is called before data is pushed to the codec.
  109. * Note that start() must be atomic! */
  110. int (*start)(struct codec_info_item *cii,
  111. struct snd_pcm_substream *substream);
  112. /* stop() is called after data is no longer pushed to the codec.
  113. * Note that stop() must be atomic! */
  114. int (*stop)(struct codec_info_item *cii,
  115. struct snd_pcm_substream *substream);
  116. int (*suspend)(struct codec_info_item *cii, pm_message_t state);
  117. int (*resume)(struct codec_info_item *cii);
  118. };
  119. /* information on a soundbus device */
  120. struct soundbus_dev {
  121. /* the bus it belongs to */
  122. struct list_head onbuslist;
  123. /* the of device it represents */
  124. struct platform_device ofdev;
  125. /* what modules go by */
  126. char modalias[32];
  127. /* These fields must be before attach_codec can be called.
  128. * They should be set by the owner of the alsa card object
  129. * that is needed, and whoever sets them must make sure
  130. * that they are unique within that alsa card object. */
  131. char *pcmname;
  132. int pcmid;
  133. /* this is assigned by the soundbus provider in attach_codec */
  134. struct snd_pcm *pcm;
  135. /* operations */
  136. /* attach a codec to this soundbus, give the alsa
  137. * card object the PCMs for this soundbus should be in.
  138. * The 'data' pointer must be unique, it is used as the
  139. * key for detach_codec(). */
  140. int (*attach_codec)(struct soundbus_dev *dev, struct snd_card *card,
  141. struct codec_info *ci, void *data);
  142. void (*detach_codec)(struct soundbus_dev *dev, void *data);
  143. /* TODO: suspend/resume */
  144. /* private for the soundbus provider */
  145. struct list_head codec_list;
  146. u32 have_out:1, have_in:1;
  147. };
  148. #define to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev.dev)
  149. #define of_to_soundbus_device(d) container_of(d, struct soundbus_dev, ofdev)
  150. extern int soundbus_add_one(struct soundbus_dev *dev);
  151. extern void soundbus_remove_one(struct soundbus_dev *dev);
  152. extern struct soundbus_dev *soundbus_dev_get(struct soundbus_dev *dev);
  153. extern void soundbus_dev_put(struct soundbus_dev *dev);
  154. struct soundbus_driver {
  155. char *name;
  156. struct module *owner;
  157. /* we don't implement any matching at all */
  158. int (*probe)(struct soundbus_dev* dev);
  159. int (*remove)(struct soundbus_dev* dev);
  160. int (*suspend)(struct soundbus_dev* dev, pm_message_t state);
  161. int (*resume)(struct soundbus_dev* dev);
  162. int (*shutdown)(struct soundbus_dev* dev);
  163. struct device_driver driver;
  164. };
  165. #define to_soundbus_driver(drv) container_of(drv,struct soundbus_driver, driver)
  166. extern int soundbus_register_driver(struct soundbus_driver *drv);
  167. extern void soundbus_unregister_driver(struct soundbus_driver *drv);
  168. extern struct device_attribute soundbus_dev_attrs[];
  169. #endif /* __SOUNDBUS_H */