soc.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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 <linux/regmap.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/control.h>
  24. #include <sound/ac97_codec.h>
  25. /*
  26. * Convenience kcontrol builders
  27. */
  28. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert) \
  29. ((unsigned long)&(struct soc_mixer_control) \
  30. {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
  31. .max = xmax, .platform_max = xmax, .invert = xinvert})
  32. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
  33. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert)
  34. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  35. ((unsigned long)&(struct soc_mixer_control) \
  36. {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
  37. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  38. ((unsigned long)&(struct soc_mixer_control) \
  39. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  40. .max = xmax, .platform_max = xmax, .invert = xinvert})
  41. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  42. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  43. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  44. .put = snd_soc_put_volsw, \
  45. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  46. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  47. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  48. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  49. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  50. .tlv.p = (tlv_array), \
  51. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  52. .put = snd_soc_put_volsw, \
  53. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  54. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  55. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  56. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  57. .put = snd_soc_put_volsw, \
  58. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  59. max, invert) }
  60. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  61. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  62. .info = snd_soc_info_volsw_2r, \
  63. .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
  64. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  65. xmax, xinvert) }
  66. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  67. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  68. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  69. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  70. .tlv.p = (tlv_array), \
  71. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  72. .put = snd_soc_put_volsw, \
  73. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  74. max, invert) }
  75. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  76. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  77. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  78. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  79. .tlv.p = (tlv_array), \
  80. .info = snd_soc_info_volsw_2r, \
  81. .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
  82. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  83. xmax, xinvert) }
  84. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  85. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  86. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  87. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  88. .tlv.p = (tlv_array), \
  89. .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
  90. .put = snd_soc_put_volsw_s8, \
  91. .private_value = (unsigned long)&(struct soc_mixer_control) \
  92. {.reg = xreg, .min = xmin, .max = xmax, \
  93. .platform_max = xmax} }
  94. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
  95. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  96. .max = xmax, .texts = xtexts }
  97. #define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
  98. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
  99. #define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
  100. { .max = xmax, .texts = xtexts }
  101. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \
  102. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  103. .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues}
  104. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \
  105. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues)
  106. #define SOC_ENUM(xname, xenum) \
  107. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  108. .info = snd_soc_info_enum_double, \
  109. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  110. .private_value = (unsigned long)&xenum }
  111. #define SOC_VALUE_ENUM(xname, xenum) \
  112. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  113. .info = snd_soc_info_enum_double, \
  114. .get = snd_soc_get_value_enum_double, \
  115. .put = snd_soc_put_value_enum_double, \
  116. .private_value = (unsigned long)&xenum }
  117. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  118. xhandler_get, xhandler_put) \
  119. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  120. .info = snd_soc_info_volsw, \
  121. .get = xhandler_get, .put = xhandler_put, \
  122. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  123. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  124. xhandler_get, xhandler_put) \
  125. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  126. .info = snd_soc_info_volsw, \
  127. .get = xhandler_get, .put = xhandler_put, \
  128. .private_value = \
  129. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert) }
  130. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  131. xhandler_get, xhandler_put, tlv_array) \
  132. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  133. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  134. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  135. .tlv.p = (tlv_array), \
  136. .info = snd_soc_info_volsw, \
  137. .get = xhandler_get, .put = xhandler_put, \
  138. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  139. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  140. xhandler_get, xhandler_put, tlv_array) \
  141. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  142. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  143. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  144. .tlv.p = (tlv_array), \
  145. .info = snd_soc_info_volsw, \
  146. .get = xhandler_get, .put = xhandler_put, \
  147. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  148. xmax, xinvert) }
  149. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  150. xhandler_get, xhandler_put, tlv_array) \
  151. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  152. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  153. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  154. .tlv.p = (tlv_array), \
  155. .info = snd_soc_info_volsw_2r, \
  156. .get = xhandler_get, .put = xhandler_put, \
  157. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  158. xmax, 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. SND_SOC_REGMAP,
  251. };
  252. enum snd_soc_compress_type {
  253. SND_SOC_FLAT_COMPRESSION = 1,
  254. SND_SOC_LZO_COMPRESSION,
  255. SND_SOC_RBTREE_COMPRESSION
  256. };
  257. enum snd_soc_pcm_subclass {
  258. SND_SOC_PCM_CLASS_PCM = 0,
  259. SND_SOC_PCM_CLASS_BE = 1,
  260. };
  261. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  262. int source, unsigned int freq, int dir);
  263. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  264. unsigned int freq_in, unsigned int freq_out);
  265. int snd_soc_register_card(struct snd_soc_card *card);
  266. int snd_soc_unregister_card(struct snd_soc_card *card);
  267. int snd_soc_suspend(struct device *dev);
  268. int snd_soc_resume(struct device *dev);
  269. int snd_soc_poweroff(struct device *dev);
  270. int snd_soc_register_platform(struct device *dev,
  271. struct snd_soc_platform_driver *platform_drv);
  272. void snd_soc_unregister_platform(struct device *dev);
  273. int snd_soc_register_codec(struct device *dev,
  274. const struct snd_soc_codec_driver *codec_drv,
  275. struct snd_soc_dai_driver *dai_drv, int num_dai);
  276. void snd_soc_unregister_codec(struct device *dev);
  277. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
  278. unsigned int reg);
  279. int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
  280. unsigned int reg);
  281. int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
  282. unsigned int reg);
  283. int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
  284. int addr_bits, int data_bits,
  285. enum snd_soc_control_type control);
  286. int snd_soc_cache_sync(struct snd_soc_codec *codec);
  287. int snd_soc_cache_init(struct snd_soc_codec *codec);
  288. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  289. int snd_soc_cache_write(struct snd_soc_codec *codec,
  290. unsigned int reg, unsigned int value);
  291. int snd_soc_cache_read(struct snd_soc_codec *codec,
  292. unsigned int reg, unsigned int *value);
  293. int snd_soc_default_volatile_register(struct snd_soc_codec *codec,
  294. unsigned int reg);
  295. int snd_soc_default_readable_register(struct snd_soc_codec *codec,
  296. unsigned int reg);
  297. int snd_soc_default_writable_register(struct snd_soc_codec *codec,
  298. unsigned int reg);
  299. int snd_soc_platform_read(struct snd_soc_platform *platform,
  300. unsigned int reg);
  301. int snd_soc_platform_write(struct snd_soc_platform *platform,
  302. unsigned int reg, unsigned int val);
  303. /* Utility functions to get clock rates from various things */
  304. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  305. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  306. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  307. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  308. /* set runtime hw params */
  309. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  310. const struct snd_pcm_hardware *hw);
  311. /* Jack reporting */
  312. int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
  313. struct snd_soc_jack *jack);
  314. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  315. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  316. struct snd_soc_jack_pin *pins);
  317. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  318. struct notifier_block *nb);
  319. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  320. struct notifier_block *nb);
  321. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  322. struct snd_soc_jack_zone *zones);
  323. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  324. #ifdef CONFIG_GPIOLIB
  325. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  326. struct snd_soc_jack_gpio *gpios);
  327. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  328. struct snd_soc_jack_gpio *gpios);
  329. #endif
  330. /* codec register bit access */
  331. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  332. unsigned int mask, unsigned int value);
  333. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  334. unsigned short reg, unsigned int mask,
  335. unsigned int value);
  336. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  337. unsigned int mask, unsigned int value);
  338. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  339. struct snd_ac97_bus_ops *ops, int num);
  340. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  341. /*
  342. *Controls
  343. */
  344. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  345. void *data, char *long_name,
  346. const char *prefix);
  347. int snd_soc_add_controls(struct snd_soc_codec *codec,
  348. const struct snd_kcontrol_new *controls, int num_controls);
  349. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  350. const struct snd_kcontrol_new *controls, int num_controls);
  351. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  352. struct snd_ctl_elem_info *uinfo);
  353. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  354. struct snd_ctl_elem_info *uinfo);
  355. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  356. struct snd_ctl_elem_value *ucontrol);
  357. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  358. struct snd_ctl_elem_value *ucontrol);
  359. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  360. struct snd_ctl_elem_value *ucontrol);
  361. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  362. struct snd_ctl_elem_value *ucontrol);
  363. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  364. struct snd_ctl_elem_info *uinfo);
  365. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  366. struct snd_ctl_elem_info *uinfo);
  367. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  368. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  369. struct snd_ctl_elem_value *ucontrol);
  370. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  371. struct snd_ctl_elem_value *ucontrol);
  372. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  373. struct snd_ctl_elem_info *uinfo);
  374. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  375. struct snd_ctl_elem_value *ucontrol);
  376. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  377. struct snd_ctl_elem_value *ucontrol);
  378. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  379. struct snd_ctl_elem_info *uinfo);
  380. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  381. struct snd_ctl_elem_value *ucontrol);
  382. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  383. struct snd_ctl_elem_value *ucontrol);
  384. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  385. const char *name, int max);
  386. int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  387. struct snd_ctl_elem_info *uinfo);
  388. int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  389. struct snd_ctl_elem_value *ucontrol);
  390. int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  391. struct snd_ctl_elem_value *ucontrol);
  392. /**
  393. * struct snd_soc_reg_access - Describes whether a given register is
  394. * readable, writable or volatile.
  395. *
  396. * @reg: the register number
  397. * @read: whether this register is readable
  398. * @write: whether this register is writable
  399. * @vol: whether this register is volatile
  400. */
  401. struct snd_soc_reg_access {
  402. u16 reg;
  403. u16 read;
  404. u16 write;
  405. u16 vol;
  406. };
  407. /**
  408. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  409. *
  410. * @pin: name of the pin to update
  411. * @mask: bits to check for in reported jack status
  412. * @invert: if non-zero then pin is enabled when status is not reported
  413. */
  414. struct snd_soc_jack_pin {
  415. struct list_head list;
  416. const char *pin;
  417. int mask;
  418. bool invert;
  419. };
  420. /**
  421. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  422. *
  423. * @min_mv: start voltage in mv
  424. * @max_mv: end voltage in mv
  425. * @jack_type: type of jack that is expected for this voltage
  426. * @debounce_time: debounce_time for jack, codec driver should wait for this
  427. * duration before reading the adc for voltages
  428. * @:list: list container
  429. */
  430. struct snd_soc_jack_zone {
  431. unsigned int min_mv;
  432. unsigned int max_mv;
  433. unsigned int jack_type;
  434. unsigned int debounce_time;
  435. struct list_head list;
  436. };
  437. /**
  438. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  439. *
  440. * @gpio: gpio number
  441. * @name: gpio name
  442. * @report: value to report when jack detected
  443. * @invert: report presence in low state
  444. * @debouce_time: debouce time in ms
  445. * @wake: enable as wake source
  446. * @jack_status_check: callback function which overrides the detection
  447. * to provide more complex checks (eg, reading an
  448. * ADC).
  449. */
  450. #ifdef CONFIG_GPIOLIB
  451. struct snd_soc_jack_gpio {
  452. unsigned int gpio;
  453. const char *name;
  454. int report;
  455. int invert;
  456. int debounce_time;
  457. bool wake;
  458. struct snd_soc_jack *jack;
  459. struct delayed_work work;
  460. int (*jack_status_check)(void);
  461. };
  462. #endif
  463. struct snd_soc_jack {
  464. struct snd_jack *jack;
  465. struct snd_soc_codec *codec;
  466. struct list_head pins;
  467. int status;
  468. struct blocking_notifier_head notifier;
  469. struct list_head jack_zones;
  470. };
  471. /* SoC PCM stream information */
  472. struct snd_soc_pcm_stream {
  473. const char *stream_name;
  474. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  475. unsigned int rates; /* SNDRV_PCM_RATE_* */
  476. unsigned int rate_min; /* min rate */
  477. unsigned int rate_max; /* max rate */
  478. unsigned int channels_min; /* min channels */
  479. unsigned int channels_max; /* max channels */
  480. };
  481. /* SoC audio ops */
  482. struct snd_soc_ops {
  483. int (*startup)(struct snd_pcm_substream *);
  484. void (*shutdown)(struct snd_pcm_substream *);
  485. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  486. int (*hw_free)(struct snd_pcm_substream *);
  487. int (*prepare)(struct snd_pcm_substream *);
  488. int (*trigger)(struct snd_pcm_substream *, int);
  489. };
  490. /* SoC cache ops */
  491. struct snd_soc_cache_ops {
  492. const char *name;
  493. enum snd_soc_compress_type id;
  494. int (*init)(struct snd_soc_codec *codec);
  495. int (*exit)(struct snd_soc_codec *codec);
  496. int (*read)(struct snd_soc_codec *codec, unsigned int reg,
  497. unsigned int *value);
  498. int (*write)(struct snd_soc_codec *codec, unsigned int reg,
  499. unsigned int value);
  500. int (*sync)(struct snd_soc_codec *codec);
  501. };
  502. /* SoC Audio Codec device */
  503. struct snd_soc_codec {
  504. const char *name;
  505. const char *name_prefix;
  506. int id;
  507. struct device *dev;
  508. const struct snd_soc_codec_driver *driver;
  509. struct mutex mutex;
  510. struct snd_soc_card *card;
  511. struct list_head list;
  512. struct list_head card_list;
  513. int num_dai;
  514. enum snd_soc_compress_type compress_type;
  515. size_t reg_size; /* reg_cache_size * reg_word_size */
  516. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  517. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  518. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  519. /* runtime */
  520. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  521. unsigned int active;
  522. unsigned int cache_bypass:1; /* Suppress access to the cache */
  523. unsigned int suspended:1; /* Codec is in suspend PM state */
  524. unsigned int probed:1; /* Codec has been probed */
  525. unsigned int ac97_registered:1; /* Codec has been AC97 registered */
  526. unsigned int ac97_created:1; /* Codec has been created by SoC */
  527. unsigned int sysfs_registered:1; /* codec has been sysfs registered */
  528. unsigned int cache_init:1; /* codec cache has been initialized */
  529. u32 cache_only; /* Suppress writes to hardware */
  530. u32 cache_sync; /* Cache needs to be synced to hardware */
  531. /* codec IO */
  532. void *control_data; /* codec control (i2c/3wire) data */
  533. enum snd_soc_control_type control_type;
  534. hw_write_t hw_write;
  535. unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
  536. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  537. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  538. int (*bulk_write_raw)(struct snd_soc_codec *, unsigned int, const void *, size_t);
  539. void *reg_cache;
  540. const void *reg_def_copy;
  541. const struct snd_soc_cache_ops *cache_ops;
  542. struct mutex cache_rw_mutex;
  543. int val_bytes;
  544. /* dapm */
  545. struct snd_soc_dapm_context dapm;
  546. #ifdef CONFIG_DEBUG_FS
  547. struct dentry *debugfs_codec_root;
  548. struct dentry *debugfs_reg;
  549. struct dentry *debugfs_dapm;
  550. #endif
  551. };
  552. /* codec driver */
  553. struct snd_soc_codec_driver {
  554. /* driver ops */
  555. int (*probe)(struct snd_soc_codec *);
  556. int (*remove)(struct snd_soc_codec *);
  557. int (*suspend)(struct snd_soc_codec *,
  558. pm_message_t state);
  559. int (*resume)(struct snd_soc_codec *);
  560. /* Default control and setup, added after probe() is run */
  561. const struct snd_kcontrol_new *controls;
  562. int num_controls;
  563. const struct snd_soc_dapm_widget *dapm_widgets;
  564. int num_dapm_widgets;
  565. const struct snd_soc_dapm_route *dapm_routes;
  566. int num_dapm_routes;
  567. /* codec wide operations */
  568. int (*set_sysclk)(struct snd_soc_codec *codec,
  569. int clk_id, int source, unsigned int freq, int dir);
  570. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  571. unsigned int freq_in, unsigned int freq_out);
  572. /* codec IO */
  573. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  574. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  575. int (*display_register)(struct snd_soc_codec *, char *,
  576. size_t, unsigned int);
  577. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  578. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  579. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  580. unsigned int reg_cache_size;
  581. short reg_cache_step;
  582. short reg_word_size;
  583. const void *reg_cache_default;
  584. short reg_access_size;
  585. const struct snd_soc_reg_access *reg_access_default;
  586. enum snd_soc_compress_type compress_type;
  587. /* codec bias level */
  588. int (*set_bias_level)(struct snd_soc_codec *,
  589. enum snd_soc_bias_level level);
  590. bool idle_bias_off;
  591. void (*seq_notifier)(struct snd_soc_dapm_context *,
  592. enum snd_soc_dapm_type, int);
  593. /* codec stream completion event */
  594. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  595. /* probe ordering - for components with runtime dependencies */
  596. int probe_order;
  597. int remove_order;
  598. };
  599. /* SoC platform interface */
  600. struct snd_soc_platform_driver {
  601. int (*probe)(struct snd_soc_platform *);
  602. int (*remove)(struct snd_soc_platform *);
  603. int (*suspend)(struct snd_soc_dai *dai);
  604. int (*resume)(struct snd_soc_dai *dai);
  605. /* pcm creation and destruction */
  606. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  607. void (*pcm_free)(struct snd_pcm *);
  608. /* Default control and setup, added after probe() is run */
  609. const struct snd_kcontrol_new *controls;
  610. int num_controls;
  611. const struct snd_soc_dapm_widget *dapm_widgets;
  612. int num_dapm_widgets;
  613. const struct snd_soc_dapm_route *dapm_routes;
  614. int num_dapm_routes;
  615. /*
  616. * For platform caused delay reporting.
  617. * Optional.
  618. */
  619. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  620. struct snd_soc_dai *);
  621. /* platform stream ops */
  622. struct snd_pcm_ops *ops;
  623. /* platform stream completion event */
  624. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  625. /* probe ordering - for components with runtime dependencies */
  626. int probe_order;
  627. int remove_order;
  628. /* platform IO - used for platform DAPM */
  629. unsigned int (*read)(struct snd_soc_platform *, unsigned int);
  630. int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
  631. };
  632. struct snd_soc_platform {
  633. const char *name;
  634. int id;
  635. struct device *dev;
  636. struct snd_soc_platform_driver *driver;
  637. unsigned int suspended:1; /* platform is suspended */
  638. unsigned int probed:1;
  639. struct snd_soc_card *card;
  640. struct list_head list;
  641. struct list_head card_list;
  642. struct snd_soc_dapm_context dapm;
  643. };
  644. struct snd_soc_dai_link {
  645. /* config - must be set by machine driver */
  646. const char *name; /* Codec name */
  647. const char *stream_name; /* Stream name */
  648. const char *codec_name; /* for multi-codec */
  649. const char *platform_name; /* for multi-platform */
  650. const char *cpu_dai_name;
  651. const char *codec_dai_name;
  652. unsigned int dai_fmt; /* format to set on init */
  653. /* Keep DAI active over suspend */
  654. unsigned int ignore_suspend:1;
  655. /* Symmetry requirements */
  656. unsigned int symmetric_rates:1;
  657. /* codec/machine specific init - e.g. add machine controls */
  658. int (*init)(struct snd_soc_pcm_runtime *rtd);
  659. /* machine stream operations */
  660. struct snd_soc_ops *ops;
  661. };
  662. struct snd_soc_codec_conf {
  663. const char *dev_name;
  664. /*
  665. * optional map of kcontrol, widget and path name prefixes that are
  666. * associated per device
  667. */
  668. const char *name_prefix;
  669. /*
  670. * set this to the desired compression type if you want to
  671. * override the one supplied in codec->driver->compress_type
  672. */
  673. enum snd_soc_compress_type compress_type;
  674. };
  675. struct snd_soc_aux_dev {
  676. const char *name; /* Codec name */
  677. const char *codec_name; /* for multi-codec */
  678. /* codec/machine specific init - e.g. add machine controls */
  679. int (*init)(struct snd_soc_dapm_context *dapm);
  680. };
  681. /* SoC card */
  682. struct snd_soc_card {
  683. const char *name;
  684. const char *long_name;
  685. const char *driver_name;
  686. struct device *dev;
  687. struct snd_card *snd_card;
  688. struct module *owner;
  689. struct list_head list;
  690. struct mutex mutex;
  691. bool instantiated;
  692. int (*probe)(struct snd_soc_card *card);
  693. int (*late_probe)(struct snd_soc_card *card);
  694. int (*remove)(struct snd_soc_card *card);
  695. /* the pre and post PM functions are used to do any PM work before and
  696. * after the codec and DAI's do any PM work. */
  697. int (*suspend_pre)(struct snd_soc_card *card);
  698. int (*suspend_post)(struct snd_soc_card *card);
  699. int (*resume_pre)(struct snd_soc_card *card);
  700. int (*resume_post)(struct snd_soc_card *card);
  701. /* callbacks */
  702. int (*set_bias_level)(struct snd_soc_card *,
  703. struct snd_soc_dapm_context *dapm,
  704. enum snd_soc_bias_level level);
  705. int (*set_bias_level_post)(struct snd_soc_card *,
  706. struct snd_soc_dapm_context *dapm,
  707. enum snd_soc_bias_level level);
  708. long pmdown_time;
  709. /* CPU <--> Codec DAI links */
  710. struct snd_soc_dai_link *dai_link;
  711. int num_links;
  712. struct snd_soc_pcm_runtime *rtd;
  713. int num_rtd;
  714. /* optional codec specific configuration */
  715. struct snd_soc_codec_conf *codec_conf;
  716. int num_configs;
  717. /*
  718. * optional auxiliary devices such as amplifiers or codecs with DAI
  719. * link unused
  720. */
  721. struct snd_soc_aux_dev *aux_dev;
  722. int num_aux_devs;
  723. struct snd_soc_pcm_runtime *rtd_aux;
  724. int num_aux_rtd;
  725. const struct snd_kcontrol_new *controls;
  726. int num_controls;
  727. /*
  728. * Card-specific routes and widgets.
  729. */
  730. const struct snd_soc_dapm_widget *dapm_widgets;
  731. int num_dapm_widgets;
  732. const struct snd_soc_dapm_route *dapm_routes;
  733. int num_dapm_routes;
  734. struct work_struct deferred_resume_work;
  735. /* lists of probed devices belonging to this card */
  736. struct list_head codec_dev_list;
  737. struct list_head platform_dev_list;
  738. struct list_head dai_dev_list;
  739. struct list_head widgets;
  740. struct list_head paths;
  741. struct list_head dapm_list;
  742. /* Generic DAPM context for the card */
  743. struct snd_soc_dapm_context dapm;
  744. struct snd_soc_dapm_stats dapm_stats;
  745. #ifdef CONFIG_DEBUG_FS
  746. struct dentry *debugfs_card_root;
  747. struct dentry *debugfs_pop_time;
  748. #endif
  749. u32 pop_time;
  750. void *drvdata;
  751. };
  752. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  753. struct snd_soc_pcm_runtime {
  754. struct device dev;
  755. struct snd_soc_card *card;
  756. struct snd_soc_dai_link *dai_link;
  757. struct mutex pcm_mutex;
  758. enum snd_soc_pcm_subclass pcm_subclass;
  759. struct snd_pcm_ops ops;
  760. unsigned int complete:1;
  761. unsigned int dev_registered:1;
  762. long pmdown_time;
  763. /* runtime devices */
  764. struct snd_pcm *pcm;
  765. struct snd_soc_codec *codec;
  766. struct snd_soc_platform *platform;
  767. struct snd_soc_dai *codec_dai;
  768. struct snd_soc_dai *cpu_dai;
  769. struct delayed_work delayed_work;
  770. };
  771. /* mixer control */
  772. struct soc_mixer_control {
  773. int min, max, platform_max;
  774. unsigned int reg, rreg, shift, rshift, invert;
  775. };
  776. /* enumerated kcontrol */
  777. struct soc_enum {
  778. unsigned short reg;
  779. unsigned short reg2;
  780. unsigned char shift_l;
  781. unsigned char shift_r;
  782. unsigned int max;
  783. unsigned int mask;
  784. const char * const *texts;
  785. const unsigned int *values;
  786. void *dapm;
  787. };
  788. /* codec IO */
  789. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  790. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  791. unsigned int reg, unsigned int val);
  792. unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
  793. unsigned int reg, const void *data, size_t len);
  794. /* device driver data */
  795. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  796. void *data)
  797. {
  798. card->drvdata = data;
  799. }
  800. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  801. {
  802. return card->drvdata;
  803. }
  804. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  805. void *data)
  806. {
  807. dev_set_drvdata(codec->dev, data);
  808. }
  809. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  810. {
  811. return dev_get_drvdata(codec->dev);
  812. }
  813. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  814. void *data)
  815. {
  816. dev_set_drvdata(platform->dev, data);
  817. }
  818. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  819. {
  820. return dev_get_drvdata(platform->dev);
  821. }
  822. static inline void snd_soc_pcm_set_drvdata(struct snd_soc_pcm_runtime *rtd,
  823. void *data)
  824. {
  825. dev_set_drvdata(&rtd->dev, data);
  826. }
  827. static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)
  828. {
  829. return dev_get_drvdata(&rtd->dev);
  830. }
  831. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  832. {
  833. INIT_LIST_HEAD(&card->dai_dev_list);
  834. INIT_LIST_HEAD(&card->codec_dev_list);
  835. INIT_LIST_HEAD(&card->platform_dev_list);
  836. INIT_LIST_HEAD(&card->widgets);
  837. INIT_LIST_HEAD(&card->paths);
  838. INIT_LIST_HEAD(&card->dapm_list);
  839. }
  840. int snd_soc_util_init(void);
  841. void snd_soc_util_exit(void);
  842. #include <sound/soc-dai.h>
  843. #ifdef CONFIG_DEBUG_FS
  844. extern struct dentry *snd_soc_debugfs_root;
  845. #endif
  846. extern const struct dev_pm_ops snd_soc_pm_ops;
  847. #endif