soc.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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. * Component probe and remove ordering levels for components with runtime
  200. * dependencies.
  201. */
  202. #define SND_SOC_COMP_ORDER_FIRST -2
  203. #define SND_SOC_COMP_ORDER_EARLY -1
  204. #define SND_SOC_COMP_ORDER_NORMAL 0
  205. #define SND_SOC_COMP_ORDER_LATE 1
  206. #define SND_SOC_COMP_ORDER_LAST 2
  207. /*
  208. * Bias levels
  209. *
  210. * @ON: Bias is fully on for audio playback and capture operations.
  211. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  212. * stream start and stop operations.
  213. * @STANDBY: Low power standby state when no playback/capture operations are
  214. * in progress. NOTE: The transition time between STANDBY and ON
  215. * should be as fast as possible and no longer than 10ms.
  216. * @OFF: Power Off. No restrictions on transition times.
  217. */
  218. enum snd_soc_bias_level {
  219. SND_SOC_BIAS_OFF = 0,
  220. SND_SOC_BIAS_STANDBY = 1,
  221. SND_SOC_BIAS_PREPARE = 2,
  222. SND_SOC_BIAS_ON = 3,
  223. };
  224. struct snd_jack;
  225. struct snd_soc_card;
  226. struct snd_soc_pcm_stream;
  227. struct snd_soc_ops;
  228. struct snd_soc_pcm_runtime;
  229. struct snd_soc_dai;
  230. struct snd_soc_dai_driver;
  231. struct snd_soc_platform;
  232. struct snd_soc_dai_link;
  233. struct snd_soc_platform_driver;
  234. struct snd_soc_codec;
  235. struct snd_soc_codec_driver;
  236. struct soc_enum;
  237. struct snd_soc_jack;
  238. struct snd_soc_jack_zone;
  239. struct snd_soc_jack_pin;
  240. struct snd_soc_cache_ops;
  241. #include <sound/soc-dapm.h>
  242. #ifdef CONFIG_GPIOLIB
  243. struct snd_soc_jack_gpio;
  244. #endif
  245. typedef int (*hw_write_t)(void *,const char* ,int);
  246. extern struct snd_ac97_bus_ops soc_ac97_ops;
  247. enum snd_soc_control_type {
  248. SND_SOC_I2C = 1,
  249. SND_SOC_SPI,
  250. };
  251. enum snd_soc_compress_type {
  252. SND_SOC_FLAT_COMPRESSION = 1,
  253. SND_SOC_LZO_COMPRESSION,
  254. SND_SOC_RBTREE_COMPRESSION
  255. };
  256. enum snd_soc_pcm_subclass {
  257. SND_SOC_PCM_CLASS_PCM = 0,
  258. SND_SOC_PCM_CLASS_BE = 1,
  259. };
  260. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  261. unsigned int freq, int dir);
  262. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  263. unsigned int freq_in, unsigned int freq_out);
  264. int snd_soc_register_card(struct snd_soc_card *card);
  265. int snd_soc_unregister_card(struct snd_soc_card *card);
  266. int snd_soc_suspend(struct device *dev);
  267. int snd_soc_resume(struct device *dev);
  268. int snd_soc_poweroff(struct device *dev);
  269. int snd_soc_register_platform(struct device *dev,
  270. struct snd_soc_platform_driver *platform_drv);
  271. void snd_soc_unregister_platform(struct device *dev);
  272. int snd_soc_register_codec(struct device *dev,
  273. const struct snd_soc_codec_driver *codec_drv,
  274. struct snd_soc_dai_driver *dai_drv, int num_dai);
  275. void snd_soc_unregister_codec(struct device *dev);
  276. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
  277. unsigned int reg);
  278. int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
  279. unsigned int reg);
  280. int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
  281. unsigned int reg);
  282. int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
  283. int addr_bits, int data_bits,
  284. enum snd_soc_control_type control);
  285. int snd_soc_cache_sync(struct snd_soc_codec *codec);
  286. int snd_soc_cache_init(struct snd_soc_codec *codec);
  287. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  288. int snd_soc_cache_write(struct snd_soc_codec *codec,
  289. unsigned int reg, unsigned int value);
  290. int snd_soc_cache_read(struct snd_soc_codec *codec,
  291. unsigned int reg, unsigned int *value);
  292. int snd_soc_default_volatile_register(struct snd_soc_codec *codec,
  293. unsigned int reg);
  294. int snd_soc_default_readable_register(struct snd_soc_codec *codec,
  295. unsigned int reg);
  296. int snd_soc_default_writable_register(struct snd_soc_codec *codec,
  297. unsigned int reg);
  298. int snd_soc_platform_read(struct snd_soc_platform *platform,
  299. unsigned int reg);
  300. int snd_soc_platform_write(struct snd_soc_platform *platform,
  301. unsigned int reg, unsigned int val);
  302. /* Utility functions to get clock rates from various things */
  303. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  304. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  305. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  306. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  307. /* set runtime hw params */
  308. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  309. const struct snd_pcm_hardware *hw);
  310. /* Jack reporting */
  311. int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
  312. struct snd_soc_jack *jack);
  313. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  314. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  315. struct snd_soc_jack_pin *pins);
  316. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  317. struct notifier_block *nb);
  318. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  319. struct notifier_block *nb);
  320. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  321. struct snd_soc_jack_zone *zones);
  322. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  323. #ifdef CONFIG_GPIOLIB
  324. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  325. struct snd_soc_jack_gpio *gpios);
  326. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  327. struct snd_soc_jack_gpio *gpios);
  328. #endif
  329. /* codec register bit access */
  330. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  331. unsigned int mask, unsigned int value);
  332. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  333. unsigned short reg, unsigned int mask,
  334. unsigned int value);
  335. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  336. unsigned int mask, unsigned int value);
  337. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  338. struct snd_ac97_bus_ops *ops, int num);
  339. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  340. /*
  341. *Controls
  342. */
  343. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  344. void *data, char *long_name,
  345. const char *prefix);
  346. int snd_soc_add_controls(struct snd_soc_codec *codec,
  347. const struct snd_kcontrol_new *controls, int num_controls);
  348. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  349. const struct snd_kcontrol_new *controls, int num_controls);
  350. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  351. struct snd_ctl_elem_info *uinfo);
  352. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  353. struct snd_ctl_elem_info *uinfo);
  354. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  355. struct snd_ctl_elem_value *ucontrol);
  356. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  357. struct snd_ctl_elem_value *ucontrol);
  358. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  359. struct snd_ctl_elem_value *ucontrol);
  360. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  361. struct snd_ctl_elem_value *ucontrol);
  362. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  363. struct snd_ctl_elem_info *uinfo);
  364. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  365. struct snd_ctl_elem_info *uinfo);
  366. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  367. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  368. struct snd_ctl_elem_value *ucontrol);
  369. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  370. struct snd_ctl_elem_value *ucontrol);
  371. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  372. struct snd_ctl_elem_info *uinfo);
  373. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  374. struct snd_ctl_elem_value *ucontrol);
  375. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  376. struct snd_ctl_elem_value *ucontrol);
  377. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  378. struct snd_ctl_elem_info *uinfo);
  379. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  380. struct snd_ctl_elem_value *ucontrol);
  381. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  382. struct snd_ctl_elem_value *ucontrol);
  383. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  384. const char *name, int max);
  385. int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  386. struct snd_ctl_elem_info *uinfo);
  387. int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  388. struct snd_ctl_elem_value *ucontrol);
  389. int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  390. struct snd_ctl_elem_value *ucontrol);
  391. /**
  392. * struct snd_soc_reg_access - Describes whether a given register is
  393. * readable, writable or volatile.
  394. *
  395. * @reg: the register number
  396. * @read: whether this register is readable
  397. * @write: whether this register is writable
  398. * @vol: whether this register is volatile
  399. */
  400. struct snd_soc_reg_access {
  401. u16 reg;
  402. u16 read;
  403. u16 write;
  404. u16 vol;
  405. };
  406. /**
  407. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  408. *
  409. * @pin: name of the pin to update
  410. * @mask: bits to check for in reported jack status
  411. * @invert: if non-zero then pin is enabled when status is not reported
  412. */
  413. struct snd_soc_jack_pin {
  414. struct list_head list;
  415. const char *pin;
  416. int mask;
  417. bool invert;
  418. };
  419. /**
  420. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  421. *
  422. * @min_mv: start voltage in mv
  423. * @max_mv: end voltage in mv
  424. * @jack_type: type of jack that is expected for this voltage
  425. * @debounce_time: debounce_time for jack, codec driver should wait for this
  426. * duration before reading the adc for voltages
  427. * @:list: list container
  428. */
  429. struct snd_soc_jack_zone {
  430. unsigned int min_mv;
  431. unsigned int max_mv;
  432. unsigned int jack_type;
  433. unsigned int debounce_time;
  434. struct list_head list;
  435. };
  436. /**
  437. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  438. *
  439. * @gpio: gpio number
  440. * @name: gpio name
  441. * @report: value to report when jack detected
  442. * @invert: report presence in low state
  443. * @debouce_time: debouce time in ms
  444. * @wake: enable as wake source
  445. * @jack_status_check: callback function which overrides the detection
  446. * to provide more complex checks (eg, reading an
  447. * ADC).
  448. */
  449. #ifdef CONFIG_GPIOLIB
  450. struct snd_soc_jack_gpio {
  451. unsigned int gpio;
  452. const char *name;
  453. int report;
  454. int invert;
  455. int debounce_time;
  456. bool wake;
  457. struct snd_soc_jack *jack;
  458. struct delayed_work work;
  459. int (*jack_status_check)(void);
  460. };
  461. #endif
  462. struct snd_soc_jack {
  463. struct snd_jack *jack;
  464. struct snd_soc_codec *codec;
  465. struct list_head pins;
  466. int status;
  467. struct blocking_notifier_head notifier;
  468. struct list_head jack_zones;
  469. };
  470. /* SoC PCM stream information */
  471. struct snd_soc_pcm_stream {
  472. const char *stream_name;
  473. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  474. unsigned int rates; /* SNDRV_PCM_RATE_* */
  475. unsigned int rate_min; /* min rate */
  476. unsigned int rate_max; /* max rate */
  477. unsigned int channels_min; /* min channels */
  478. unsigned int channels_max; /* max channels */
  479. };
  480. /* SoC audio ops */
  481. struct snd_soc_ops {
  482. int (*startup)(struct snd_pcm_substream *);
  483. void (*shutdown)(struct snd_pcm_substream *);
  484. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  485. int (*hw_free)(struct snd_pcm_substream *);
  486. int (*prepare)(struct snd_pcm_substream *);
  487. int (*trigger)(struct snd_pcm_substream *, int);
  488. };
  489. /* SoC cache ops */
  490. struct snd_soc_cache_ops {
  491. const char *name;
  492. enum snd_soc_compress_type id;
  493. int (*init)(struct snd_soc_codec *codec);
  494. int (*exit)(struct snd_soc_codec *codec);
  495. int (*read)(struct snd_soc_codec *codec, unsigned int reg,
  496. unsigned int *value);
  497. int (*write)(struct snd_soc_codec *codec, unsigned int reg,
  498. unsigned int value);
  499. int (*sync)(struct snd_soc_codec *codec);
  500. };
  501. /* SoC Audio Codec device */
  502. struct snd_soc_codec {
  503. const char *name;
  504. const char *name_prefix;
  505. int id;
  506. struct device *dev;
  507. const struct snd_soc_codec_driver *driver;
  508. struct mutex mutex;
  509. struct snd_soc_card *card;
  510. struct list_head list;
  511. struct list_head card_list;
  512. int num_dai;
  513. enum snd_soc_compress_type compress_type;
  514. size_t reg_size; /* reg_cache_size * reg_word_size */
  515. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  516. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  517. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  518. /* runtime */
  519. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  520. unsigned int active;
  521. unsigned int cache_bypass:1; /* Suppress access to the cache */
  522. unsigned int suspended:1; /* Codec is in suspend PM state */
  523. unsigned int probed:1; /* Codec has been probed */
  524. unsigned int ac97_registered:1; /* Codec has been AC97 registered */
  525. unsigned int ac97_created:1; /* Codec has been created by SoC */
  526. unsigned int sysfs_registered:1; /* codec has been sysfs registered */
  527. unsigned int cache_init:1; /* codec cache has been initialized */
  528. u32 cache_only; /* Suppress writes to hardware */
  529. u32 cache_sync; /* Cache needs to be synced to hardware */
  530. /* codec IO */
  531. void *control_data; /* codec control (i2c/3wire) data */
  532. enum snd_soc_control_type control_type;
  533. hw_write_t hw_write;
  534. unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
  535. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  536. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  537. int (*bulk_write_raw)(struct snd_soc_codec *, unsigned int, const void *, size_t);
  538. void *reg_cache;
  539. const void *reg_def_copy;
  540. const struct snd_soc_cache_ops *cache_ops;
  541. struct mutex cache_rw_mutex;
  542. /* dapm */
  543. struct snd_soc_dapm_context dapm;
  544. #ifdef CONFIG_DEBUG_FS
  545. struct dentry *debugfs_codec_root;
  546. struct dentry *debugfs_reg;
  547. struct dentry *debugfs_dapm;
  548. #endif
  549. };
  550. /* codec driver */
  551. struct snd_soc_codec_driver {
  552. /* driver ops */
  553. int (*probe)(struct snd_soc_codec *);
  554. int (*remove)(struct snd_soc_codec *);
  555. int (*suspend)(struct snd_soc_codec *,
  556. pm_message_t state);
  557. int (*resume)(struct snd_soc_codec *);
  558. /* Default control and setup, added after probe() is run */
  559. const struct snd_kcontrol_new *controls;
  560. int num_controls;
  561. const struct snd_soc_dapm_widget *dapm_widgets;
  562. int num_dapm_widgets;
  563. const struct snd_soc_dapm_route *dapm_routes;
  564. int num_dapm_routes;
  565. /* codec wide operations */
  566. int (*set_sysclk)(struct snd_soc_codec *codec,
  567. int clk_id, unsigned int freq, int dir);
  568. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  569. unsigned int freq_in, unsigned int freq_out);
  570. /* codec IO */
  571. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  572. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  573. int (*display_register)(struct snd_soc_codec *, char *,
  574. size_t, unsigned int);
  575. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  576. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  577. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  578. short reg_cache_size;
  579. short reg_cache_step;
  580. short reg_word_size;
  581. const void *reg_cache_default;
  582. short reg_access_size;
  583. const struct snd_soc_reg_access *reg_access_default;
  584. enum snd_soc_compress_type compress_type;
  585. /* codec bias level */
  586. int (*set_bias_level)(struct snd_soc_codec *,
  587. enum snd_soc_bias_level level);
  588. void (*seq_notifier)(struct snd_soc_dapm_context *,
  589. enum snd_soc_dapm_type, int);
  590. /* probe ordering - for components with runtime dependencies */
  591. int probe_order;
  592. int remove_order;
  593. };
  594. /* SoC platform interface */
  595. struct snd_soc_platform_driver {
  596. int (*probe)(struct snd_soc_platform *);
  597. int (*remove)(struct snd_soc_platform *);
  598. int (*suspend)(struct snd_soc_dai *dai);
  599. int (*resume)(struct snd_soc_dai *dai);
  600. /* pcm creation and destruction */
  601. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  602. void (*pcm_free)(struct snd_pcm *);
  603. /* Default control and setup, added after probe() is run */
  604. const struct snd_kcontrol_new *controls;
  605. int num_controls;
  606. const struct snd_soc_dapm_widget *dapm_widgets;
  607. int num_dapm_widgets;
  608. const struct snd_soc_dapm_route *dapm_routes;
  609. int num_dapm_routes;
  610. /*
  611. * For platform caused delay reporting.
  612. * Optional.
  613. */
  614. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  615. struct snd_soc_dai *);
  616. /* platform stream ops */
  617. struct snd_pcm_ops *ops;
  618. /* probe ordering - for components with runtime dependencies */
  619. int probe_order;
  620. int remove_order;
  621. /* platform IO - used for platform DAPM */
  622. unsigned int (*read)(struct snd_soc_platform *, unsigned int);
  623. int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
  624. };
  625. struct snd_soc_platform {
  626. const char *name;
  627. int id;
  628. struct device *dev;
  629. struct snd_soc_platform_driver *driver;
  630. unsigned int suspended:1; /* platform is suspended */
  631. unsigned int probed:1;
  632. struct snd_soc_card *card;
  633. struct list_head list;
  634. struct list_head card_list;
  635. struct snd_soc_dapm_context dapm;
  636. };
  637. struct snd_soc_dai_link {
  638. /* config - must be set by machine driver */
  639. const char *name; /* Codec name */
  640. const char *stream_name; /* Stream name */
  641. const char *codec_name; /* for multi-codec */
  642. const char *platform_name; /* for multi-platform */
  643. const char *cpu_dai_name;
  644. const char *codec_dai_name;
  645. /* Keep DAI active over suspend */
  646. unsigned int ignore_suspend:1;
  647. /* Symmetry requirements */
  648. unsigned int symmetric_rates:1;
  649. /* codec/machine specific init - e.g. add machine controls */
  650. int (*init)(struct snd_soc_pcm_runtime *rtd);
  651. /* machine stream operations */
  652. struct snd_soc_ops *ops;
  653. };
  654. struct snd_soc_codec_conf {
  655. const char *dev_name;
  656. /*
  657. * optional map of kcontrol, widget and path name prefixes that are
  658. * associated per device
  659. */
  660. const char *name_prefix;
  661. /*
  662. * set this to the desired compression type if you want to
  663. * override the one supplied in codec->driver->compress_type
  664. */
  665. enum snd_soc_compress_type compress_type;
  666. };
  667. struct snd_soc_aux_dev {
  668. const char *name; /* Codec name */
  669. const char *codec_name; /* for multi-codec */
  670. /* codec/machine specific init - e.g. add machine controls */
  671. int (*init)(struct snd_soc_dapm_context *dapm);
  672. };
  673. /* SoC card */
  674. struct snd_soc_card {
  675. const char *name;
  676. const char *long_name;
  677. const char *driver_name;
  678. struct device *dev;
  679. struct snd_card *snd_card;
  680. struct module *owner;
  681. struct list_head list;
  682. struct mutex mutex;
  683. bool instantiated;
  684. int (*probe)(struct snd_soc_card *card);
  685. int (*late_probe)(struct snd_soc_card *card);
  686. int (*remove)(struct snd_soc_card *card);
  687. /* the pre and post PM functions are used to do any PM work before and
  688. * after the codec and DAI's do any PM work. */
  689. int (*suspend_pre)(struct snd_soc_card *card);
  690. int (*suspend_post)(struct snd_soc_card *card);
  691. int (*resume_pre)(struct snd_soc_card *card);
  692. int (*resume_post)(struct snd_soc_card *card);
  693. /* callbacks */
  694. int (*set_bias_level)(struct snd_soc_card *,
  695. struct snd_soc_dapm_context *dapm,
  696. enum snd_soc_bias_level level);
  697. int (*set_bias_level_post)(struct snd_soc_card *,
  698. struct snd_soc_dapm_context *dapm,
  699. enum snd_soc_bias_level level);
  700. long pmdown_time;
  701. /* CPU <--> Codec DAI links */
  702. struct snd_soc_dai_link *dai_link;
  703. int num_links;
  704. struct snd_soc_pcm_runtime *rtd;
  705. int num_rtd;
  706. /* optional codec specific configuration */
  707. struct snd_soc_codec_conf *codec_conf;
  708. int num_configs;
  709. /*
  710. * optional auxiliary devices such as amplifiers or codecs with DAI
  711. * link unused
  712. */
  713. struct snd_soc_aux_dev *aux_dev;
  714. int num_aux_devs;
  715. struct snd_soc_pcm_runtime *rtd_aux;
  716. int num_aux_rtd;
  717. const struct snd_kcontrol_new *controls;
  718. int num_controls;
  719. /*
  720. * Card-specific routes and widgets.
  721. */
  722. const struct snd_soc_dapm_widget *dapm_widgets;
  723. int num_dapm_widgets;
  724. const struct snd_soc_dapm_route *dapm_routes;
  725. int num_dapm_routes;
  726. struct work_struct deferred_resume_work;
  727. /* lists of probed devices belonging to this card */
  728. struct list_head codec_dev_list;
  729. struct list_head platform_dev_list;
  730. struct list_head dai_dev_list;
  731. struct list_head widgets;
  732. struct list_head paths;
  733. struct list_head dapm_list;
  734. /* Generic DAPM context for the card */
  735. struct snd_soc_dapm_context dapm;
  736. #ifdef CONFIG_DEBUG_FS
  737. struct dentry *debugfs_card_root;
  738. struct dentry *debugfs_pop_time;
  739. #endif
  740. u32 pop_time;
  741. void *drvdata;
  742. };
  743. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  744. struct snd_soc_pcm_runtime {
  745. struct device dev;
  746. struct snd_soc_card *card;
  747. struct snd_soc_dai_link *dai_link;
  748. struct mutex pcm_mutex;
  749. enum snd_soc_pcm_subclass pcm_subclass;
  750. struct snd_pcm_ops ops;
  751. unsigned int complete:1;
  752. unsigned int dev_registered:1;
  753. /* Symmetry data - only valid if symmetry is being enforced */
  754. unsigned int rate;
  755. long pmdown_time;
  756. /* runtime devices */
  757. struct snd_pcm *pcm;
  758. struct snd_soc_codec *codec;
  759. struct snd_soc_platform *platform;
  760. struct snd_soc_dai *codec_dai;
  761. struct snd_soc_dai *cpu_dai;
  762. struct delayed_work delayed_work;
  763. };
  764. /* mixer control */
  765. struct soc_mixer_control {
  766. int min, max, platform_max;
  767. unsigned int reg, rreg, shift, rshift, invert;
  768. };
  769. /* enumerated kcontrol */
  770. struct soc_enum {
  771. unsigned short reg;
  772. unsigned short reg2;
  773. unsigned char shift_l;
  774. unsigned char shift_r;
  775. unsigned int max;
  776. unsigned int mask;
  777. const char * const *texts;
  778. const unsigned int *values;
  779. void *dapm;
  780. };
  781. /* codec IO */
  782. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  783. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  784. unsigned int reg, unsigned int val);
  785. unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
  786. unsigned int reg, const void *data, size_t len);
  787. /* device driver data */
  788. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  789. void *data)
  790. {
  791. card->drvdata = data;
  792. }
  793. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  794. {
  795. return card->drvdata;
  796. }
  797. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  798. void *data)
  799. {
  800. dev_set_drvdata(codec->dev, data);
  801. }
  802. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  803. {
  804. return dev_get_drvdata(codec->dev);
  805. }
  806. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  807. void *data)
  808. {
  809. dev_set_drvdata(platform->dev, data);
  810. }
  811. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  812. {
  813. return dev_get_drvdata(platform->dev);
  814. }
  815. static inline void snd_soc_pcm_set_drvdata(struct snd_soc_pcm_runtime *rtd,
  816. void *data)
  817. {
  818. dev_set_drvdata(&rtd->dev, data);
  819. }
  820. static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)
  821. {
  822. return dev_get_drvdata(&rtd->dev);
  823. }
  824. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  825. {
  826. INIT_LIST_HEAD(&card->dai_dev_list);
  827. INIT_LIST_HEAD(&card->codec_dev_list);
  828. INIT_LIST_HEAD(&card->platform_dev_list);
  829. INIT_LIST_HEAD(&card->widgets);
  830. INIT_LIST_HEAD(&card->paths);
  831. INIT_LIST_HEAD(&card->dapm_list);
  832. }
  833. int snd_soc_util_init(void);
  834. void snd_soc_util_exit(void);
  835. #include <sound/soc-dai.h>
  836. #ifdef CONFIG_DEBUG_FS
  837. extern struct dentry *snd_soc_debugfs_root;
  838. #endif
  839. extern const struct dev_pm_ops snd_soc_pm_ops;
  840. #endif