soc.h 22 KB

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