soc.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * linux/sound/soc.h -- ALSA SoC Layer
  3. *
  4. * Author: Liam Girdwood
  5. * Created: Aug 11th 2005
  6. * Copyright: Wolfson Microelectronics. PLC.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __LINUX_SND_SOC_H
  13. #define __LINUX_SND_SOC_H
  14. #include <linux/platform_device.h>
  15. #include <linux/types.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/kernel.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/control.h>
  22. #include <sound/ac97_codec.h>
  23. /*
  24. * Convenience kcontrol builders
  25. */
  26. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
  27. ((unsigned long)&(struct soc_mixer_control) \
  28. {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
  29. .invert = xinvert})
  30. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  31. ((unsigned long)&(struct soc_mixer_control) \
  32. {.reg = xreg, .max = xmax, .invert = xinvert})
  33. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  34. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  35. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  36. .put = snd_soc_put_volsw, \
  37. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  38. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  39. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  40. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  41. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  42. .tlv.p = (tlv_array), \
  43. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  44. .put = snd_soc_put_volsw, \
  45. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  46. #define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \
  47. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  48. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  49. .put = snd_soc_put_volsw, \
  50. .private_value = (unsigned long)&(struct soc_mixer_control) \
  51. {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
  52. .max = xmax, .invert = xinvert} }
  53. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  54. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  55. .info = snd_soc_info_volsw_2r, \
  56. .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
  57. .private_value = (unsigned long)&(struct soc_mixer_control) \
  58. {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
  59. .max = xmax, .invert = xinvert} }
  60. #define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
  61. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  62. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  63. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  64. .tlv.p = (tlv_array), \
  65. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  66. .put = snd_soc_put_volsw, \
  67. .private_value = (unsigned long)&(struct soc_mixer_control) \
  68. {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
  69. .max = xmax, .invert = xinvert} }
  70. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  71. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  72. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  73. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  74. .tlv.p = (tlv_array), \
  75. .info = snd_soc_info_volsw_2r, \
  76. .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
  77. .private_value = (unsigned long)&(struct soc_mixer_control) \
  78. {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
  79. .max = xmax, .invert = xinvert} }
  80. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  81. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  82. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  83. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  84. .tlv.p = (tlv_array), \
  85. .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
  86. .put = snd_soc_put_volsw_s8, \
  87. .private_value = (unsigned long)&(struct soc_mixer_control) \
  88. {.reg = xreg, .min = xmin, .max = xmax} }
  89. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
  90. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  91. .max = xmax, .texts = xtexts }
  92. #define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
  93. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
  94. #define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
  95. { .max = xmax, .texts = xtexts }
  96. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \
  97. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  98. .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues}
  99. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \
  100. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues)
  101. #define SOC_ENUM(xname, xenum) \
  102. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  103. .info = snd_soc_info_enum_double, \
  104. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  105. .private_value = (unsigned long)&xenum }
  106. #define SOC_VALUE_ENUM(xname, xenum) \
  107. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  108. .info = snd_soc_info_enum_double, \
  109. .get = snd_soc_get_value_enum_double, \
  110. .put = snd_soc_put_value_enum_double, \
  111. .private_value = (unsigned long)&xenum }
  112. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  113. xhandler_get, xhandler_put) \
  114. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  115. .info = snd_soc_info_volsw, \
  116. .get = xhandler_get, .put = xhandler_put, \
  117. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  118. #define SOC_DOUBLE_EXT(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  119. xhandler_get, xhandler_put) \
  120. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  121. .info = snd_soc_info_volsw, \
  122. .get = xhandler_get, .put = xhandler_put, \
  123. .private_value = (unsigned long)&(struct soc_mixer_control) \
  124. {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
  125. .max = xmax, .invert = xinvert} }
  126. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  127. xhandler_get, xhandler_put, tlv_array) \
  128. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  129. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  130. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  131. .tlv.p = (tlv_array), \
  132. .info = snd_soc_info_volsw, \
  133. .get = xhandler_get, .put = xhandler_put, \
  134. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  135. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  136. xhandler_get, xhandler_put, tlv_array) \
  137. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  138. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  139. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  140. .tlv.p = (tlv_array), \
  141. .info = snd_soc_info_volsw, \
  142. .get = xhandler_get, .put = xhandler_put, \
  143. .private_value = (unsigned long)&(struct soc_mixer_control) \
  144. {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
  145. .max = xmax, .invert = xinvert} }
  146. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  147. xhandler_get, xhandler_put, tlv_array) \
  148. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  149. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  150. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  151. .tlv.p = (tlv_array), \
  152. .info = snd_soc_info_volsw_2r, \
  153. .get = xhandler_get, .put = xhandler_put, \
  154. .private_value = (unsigned long)&(struct soc_mixer_control) \
  155. {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
  156. .max = xmax, .invert = xinvert} }
  157. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  158. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  159. .info = snd_soc_info_bool_ext, \
  160. .get = xhandler_get, .put = xhandler_put, \
  161. .private_value = xdata }
  162. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  163. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  164. .info = snd_soc_info_enum_ext, \
  165. .get = xhandler_get, .put = xhandler_put, \
  166. .private_value = (unsigned long)&xenum }
  167. /*
  168. * Simplified versions of above macros, declaring a struct and calculating
  169. * ARRAY_SIZE internally
  170. */
  171. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  172. struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  173. ARRAY_SIZE(xtexts), xtexts)
  174. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  175. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  176. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  177. struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  178. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  179. struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  180. ARRAY_SIZE(xtexts), xtexts, xvalues)
  181. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  182. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  183. /*
  184. * Bias levels
  185. *
  186. * @ON: Bias is fully on for audio playback and capture operations.
  187. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  188. * stream start and stop operations.
  189. * @STANDBY: Low power standby state when no playback/capture operations are
  190. * in progress. NOTE: The transition time between STANDBY and ON
  191. * should be as fast as possible and no longer than 10ms.
  192. * @OFF: Power Off. No restrictions on transition times.
  193. */
  194. enum snd_soc_bias_level {
  195. SND_SOC_BIAS_ON,
  196. SND_SOC_BIAS_PREPARE,
  197. SND_SOC_BIAS_STANDBY,
  198. SND_SOC_BIAS_OFF,
  199. };
  200. struct snd_jack;
  201. struct snd_soc_card;
  202. struct snd_soc_device;
  203. struct snd_soc_pcm_stream;
  204. struct snd_soc_ops;
  205. struct snd_soc_dai_mode;
  206. struct snd_soc_pcm_runtime;
  207. struct snd_soc_dai;
  208. struct snd_soc_platform;
  209. struct snd_soc_codec;
  210. struct soc_enum;
  211. struct snd_soc_ac97_ops;
  212. struct snd_soc_jack;
  213. struct snd_soc_jack_pin;
  214. #ifdef CONFIG_GPIOLIB
  215. struct snd_soc_jack_gpio;
  216. #endif
  217. typedef int (*hw_write_t)(void *,const char* ,int);
  218. extern struct snd_ac97_bus_ops soc_ac97_ops;
  219. enum snd_soc_control_type {
  220. SND_SOC_CUSTOM,
  221. SND_SOC_I2C,
  222. SND_SOC_SPI,
  223. };
  224. int snd_soc_register_platform(struct snd_soc_platform *platform);
  225. void snd_soc_unregister_platform(struct snd_soc_platform *platform);
  226. int snd_soc_register_codec(struct snd_soc_codec *codec);
  227. void snd_soc_unregister_codec(struct snd_soc_codec *codec);
  228. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg);
  229. int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
  230. int addr_bits, int data_bits,
  231. enum snd_soc_control_type control);
  232. /* pcm <-> DAI connect */
  233. void snd_soc_free_pcms(struct snd_soc_device *socdev);
  234. int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
  235. /* Utility functions to get clock rates from various things */
  236. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  237. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  238. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  239. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  240. /* set runtime hw params */
  241. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  242. const struct snd_pcm_hardware *hw);
  243. /* Jack reporting */
  244. int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
  245. struct snd_soc_jack *jack);
  246. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  247. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  248. struct snd_soc_jack_pin *pins);
  249. #ifdef CONFIG_GPIOLIB
  250. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  251. struct snd_soc_jack_gpio *gpios);
  252. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  253. struct snd_soc_jack_gpio *gpios);
  254. #endif
  255. /* codec register bit access */
  256. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  257. unsigned int mask, unsigned int value);
  258. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  259. unsigned short reg, unsigned int mask,
  260. unsigned int value);
  261. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  262. unsigned int mask, unsigned int value);
  263. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  264. struct snd_ac97_bus_ops *ops, int num);
  265. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  266. /*
  267. *Controls
  268. */
  269. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  270. void *data, char *long_name);
  271. int snd_soc_add_controls(struct snd_soc_codec *codec,
  272. const struct snd_kcontrol_new *controls, int num_controls);
  273. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  274. struct snd_ctl_elem_info *uinfo);
  275. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  276. struct snd_ctl_elem_info *uinfo);
  277. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  278. struct snd_ctl_elem_value *ucontrol);
  279. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  280. struct snd_ctl_elem_value *ucontrol);
  281. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  282. struct snd_ctl_elem_value *ucontrol);
  283. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  284. struct snd_ctl_elem_value *ucontrol);
  285. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  286. struct snd_ctl_elem_info *uinfo);
  287. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  288. struct snd_ctl_elem_info *uinfo);
  289. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  290. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  291. struct snd_ctl_elem_value *ucontrol);
  292. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  293. struct snd_ctl_elem_value *ucontrol);
  294. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  295. struct snd_ctl_elem_info *uinfo);
  296. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  297. struct snd_ctl_elem_value *ucontrol);
  298. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  299. struct snd_ctl_elem_value *ucontrol);
  300. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  301. struct snd_ctl_elem_info *uinfo);
  302. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  303. struct snd_ctl_elem_value *ucontrol);
  304. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  305. struct snd_ctl_elem_value *ucontrol);
  306. /**
  307. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  308. *
  309. * @pin: name of the pin to update
  310. * @mask: bits to check for in reported jack status
  311. * @invert: if non-zero then pin is enabled when status is not reported
  312. */
  313. struct snd_soc_jack_pin {
  314. struct list_head list;
  315. const char *pin;
  316. int mask;
  317. bool invert;
  318. };
  319. /**
  320. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  321. *
  322. * @gpio: gpio number
  323. * @name: gpio name
  324. * @report: value to report when jack detected
  325. * @invert: report presence in low state
  326. * @debouce_time: debouce time in ms
  327. */
  328. #ifdef CONFIG_GPIOLIB
  329. struct snd_soc_jack_gpio {
  330. unsigned int gpio;
  331. const char *name;
  332. int report;
  333. int invert;
  334. int debounce_time;
  335. struct snd_soc_jack *jack;
  336. struct work_struct work;
  337. int (*jack_status_check)(void);
  338. };
  339. #endif
  340. struct snd_soc_jack {
  341. struct snd_jack *jack;
  342. struct snd_soc_card *card;
  343. struct list_head pins;
  344. int status;
  345. };
  346. /* SoC PCM stream information */
  347. struct snd_soc_pcm_stream {
  348. char *stream_name;
  349. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  350. unsigned int rates; /* SNDRV_PCM_RATE_* */
  351. unsigned int rate_min; /* min rate */
  352. unsigned int rate_max; /* max rate */
  353. unsigned int channels_min; /* min channels */
  354. unsigned int channels_max; /* max channels */
  355. unsigned int active:1; /* stream is in use */
  356. void *dma_data; /* used by platform code */
  357. };
  358. /* SoC audio ops */
  359. struct snd_soc_ops {
  360. int (*startup)(struct snd_pcm_substream *);
  361. void (*shutdown)(struct snd_pcm_substream *);
  362. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  363. int (*hw_free)(struct snd_pcm_substream *);
  364. int (*prepare)(struct snd_pcm_substream *);
  365. int (*trigger)(struct snd_pcm_substream *, int);
  366. };
  367. /* SoC Audio Codec */
  368. struct snd_soc_codec {
  369. char *name;
  370. struct module *owner;
  371. struct mutex mutex;
  372. struct device *dev;
  373. struct snd_soc_device *socdev;
  374. struct list_head list;
  375. /* callbacks */
  376. int (*set_bias_level)(struct snd_soc_codec *,
  377. enum snd_soc_bias_level level);
  378. /* runtime */
  379. struct snd_card *card;
  380. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  381. unsigned int active;
  382. unsigned int pcm_devs;
  383. void *private_data;
  384. /* codec IO */
  385. void *control_data; /* codec control (i2c/3wire) data */
  386. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  387. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  388. int (*display_register)(struct snd_soc_codec *, char *,
  389. size_t, unsigned int);
  390. int (*volatile_register)(unsigned int);
  391. int (*readable_register)(unsigned int);
  392. hw_write_t hw_write;
  393. unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
  394. void *reg_cache;
  395. short reg_cache_size;
  396. short reg_cache_step;
  397. unsigned int idle_bias_off:1; /* Use BIAS_OFF instead of STANDBY */
  398. unsigned int cache_only:1; /* Suppress writes to hardware */
  399. unsigned int cache_sync:1; /* Cache needs to be synced to hardware */
  400. /* dapm */
  401. u32 pop_time;
  402. struct list_head dapm_widgets;
  403. struct list_head dapm_paths;
  404. enum snd_soc_bias_level bias_level;
  405. enum snd_soc_bias_level suspend_bias_level;
  406. struct delayed_work delayed_work;
  407. /* codec DAI's */
  408. struct snd_soc_dai *dai;
  409. unsigned int num_dai;
  410. #ifdef CONFIG_DEBUG_FS
  411. struct dentry *debugfs_codec_root;
  412. struct dentry *debugfs_reg;
  413. struct dentry *debugfs_pop_time;
  414. struct dentry *debugfs_dapm;
  415. #endif
  416. };
  417. /* codec device */
  418. struct snd_soc_codec_device {
  419. int (*probe)(struct platform_device *pdev);
  420. int (*remove)(struct platform_device *pdev);
  421. int (*suspend)(struct platform_device *pdev, pm_message_t state);
  422. int (*resume)(struct platform_device *pdev);
  423. };
  424. /* SoC platform interface */
  425. struct snd_soc_platform {
  426. char *name;
  427. struct list_head list;
  428. int (*probe)(struct platform_device *pdev);
  429. int (*remove)(struct platform_device *pdev);
  430. int (*suspend)(struct snd_soc_dai *dai);
  431. int (*resume)(struct snd_soc_dai *dai);
  432. /* pcm creation and destruction */
  433. int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
  434. struct snd_pcm *);
  435. void (*pcm_free)(struct snd_pcm *);
  436. /* platform stream ops */
  437. struct snd_pcm_ops *pcm_ops;
  438. };
  439. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  440. struct snd_soc_dai_link {
  441. char *name; /* Codec name */
  442. char *stream_name; /* Stream name */
  443. /* DAI */
  444. struct snd_soc_dai *codec_dai;
  445. struct snd_soc_dai *cpu_dai;
  446. /* machine stream operations */
  447. struct snd_soc_ops *ops;
  448. /* codec/machine specific init - e.g. add machine controls */
  449. int (*init)(struct snd_soc_codec *codec);
  450. /* Symmetry requirements */
  451. unsigned int symmetric_rates:1;
  452. /* Symmetry data - only valid if symmetry is being enforced */
  453. unsigned int rate;
  454. /* DAI pcm */
  455. struct snd_pcm *pcm;
  456. };
  457. /* SoC card */
  458. struct snd_soc_card {
  459. char *name;
  460. struct device *dev;
  461. struct list_head list;
  462. int instantiated;
  463. int (*probe)(struct platform_device *pdev);
  464. int (*remove)(struct platform_device *pdev);
  465. /* the pre and post PM functions are used to do any PM work before and
  466. * after the codec and DAI's do any PM work. */
  467. int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
  468. int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
  469. int (*resume_pre)(struct platform_device *pdev);
  470. int (*resume_post)(struct platform_device *pdev);
  471. /* callbacks */
  472. int (*set_bias_level)(struct snd_soc_card *,
  473. enum snd_soc_bias_level level);
  474. long pmdown_time;
  475. /* CPU <--> Codec DAI links */
  476. struct snd_soc_dai_link *dai_link;
  477. int num_links;
  478. struct snd_soc_device *socdev;
  479. struct snd_soc_codec *codec;
  480. struct snd_soc_platform *platform;
  481. struct delayed_work delayed_work;
  482. struct work_struct deferred_resume_work;
  483. };
  484. /* SoC Device - the audio subsystem */
  485. struct snd_soc_device {
  486. struct device *dev;
  487. struct snd_soc_card *card;
  488. struct snd_soc_codec_device *codec_dev;
  489. void *codec_data;
  490. };
  491. /* runtime channel data */
  492. struct snd_soc_pcm_runtime {
  493. struct snd_soc_dai_link *dai;
  494. struct snd_soc_device *socdev;
  495. };
  496. /* mixer control */
  497. struct soc_mixer_control {
  498. int min, max;
  499. unsigned int reg, rreg, shift, rshift, invert;
  500. };
  501. /* enumerated kcontrol */
  502. struct soc_enum {
  503. unsigned short reg;
  504. unsigned short reg2;
  505. unsigned char shift_l;
  506. unsigned char shift_r;
  507. unsigned int max;
  508. unsigned int mask;
  509. const char **texts;
  510. const unsigned int *values;
  511. void *dapm;
  512. };
  513. /* codec IO */
  514. static inline unsigned int snd_soc_read(struct snd_soc_codec *codec,
  515. unsigned int reg)
  516. {
  517. return codec->read(codec, reg);
  518. }
  519. static inline unsigned int snd_soc_write(struct snd_soc_codec *codec,
  520. unsigned int reg, unsigned int val)
  521. {
  522. return codec->write(codec, reg, val);
  523. }
  524. #include <sound/soc-dai.h>
  525. #endif