soc.h 21 KB

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