soc.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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/compress_driver.h>
  24. #include <sound/control.h>
  25. #include <sound/ac97_codec.h>
  26. /*
  27. * Convenience kcontrol builders
  28. */
  29. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert) \
  30. ((unsigned long)&(struct soc_mixer_control) \
  31. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  32. .rshift = shift_right, .max = xmax, .platform_max = xmax, \
  33. .invert = xinvert})
  34. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
  35. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert)
  36. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  37. ((unsigned long)&(struct soc_mixer_control) \
  38. {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
  39. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  40. ((unsigned long)&(struct soc_mixer_control) \
  41. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  42. .max = xmax, .platform_max = xmax, .invert = xinvert})
  43. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  44. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  45. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  46. .put = snd_soc_put_volsw, \
  47. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  48. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  49. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  50. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  51. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  52. .tlv.p = (tlv_array), \
  53. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  54. .put = snd_soc_put_volsw, \
  55. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  56. #define SOC_SINGLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  57. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  58. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  59. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  60. .tlv.p = (tlv_array), \
  61. .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
  62. .put = snd_soc_put_volsw_s8, \
  63. .private_value = (unsigned long)&(struct soc_mixer_control) \
  64. {.reg = xreg, .min = xmin, .max = xmax, \
  65. .platform_max = xmax} }
  66. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  67. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  68. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  69. .put = snd_soc_put_volsw, \
  70. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  71. max, invert) }
  72. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  73. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  74. .info = snd_soc_info_volsw, \
  75. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  76. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  77. xmax, xinvert) }
  78. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  79. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  80. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  81. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  82. .tlv.p = (tlv_array), \
  83. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  84. .put = snd_soc_put_volsw, \
  85. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  86. max, invert) }
  87. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  88. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  89. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  90. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  91. .tlv.p = (tlv_array), \
  92. .info = snd_soc_info_volsw, \
  93. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  94. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  95. xmax, xinvert) }
  96. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  97. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  98. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  99. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  100. .tlv.p = (tlv_array), \
  101. .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
  102. .put = snd_soc_put_volsw_s8, \
  103. .private_value = (unsigned long)&(struct soc_mixer_control) \
  104. {.reg = xreg, .min = xmin, .max = xmax, \
  105. .platform_max = xmax} }
  106. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
  107. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  108. .max = xmax, .texts = xtexts }
  109. #define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
  110. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
  111. #define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
  112. { .max = xmax, .texts = xtexts }
  113. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \
  114. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  115. .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues}
  116. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \
  117. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues)
  118. #define SOC_ENUM(xname, xenum) \
  119. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  120. .info = snd_soc_info_enum_double, \
  121. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  122. .private_value = (unsigned long)&xenum }
  123. #define SOC_VALUE_ENUM(xname, xenum) \
  124. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  125. .info = snd_soc_info_enum_double, \
  126. .get = snd_soc_get_value_enum_double, \
  127. .put = snd_soc_put_value_enum_double, \
  128. .private_value = (unsigned long)&xenum }
  129. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  130. xhandler_get, xhandler_put) \
  131. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  132. .info = snd_soc_info_volsw, \
  133. .get = xhandler_get, .put = xhandler_put, \
  134. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  135. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  136. xhandler_get, xhandler_put) \
  137. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  138. .info = snd_soc_info_volsw, \
  139. .get = xhandler_get, .put = xhandler_put, \
  140. .private_value = \
  141. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert) }
  142. #define SOC_SINGLE_MULTI_EXT(xname, xreg, xshift, xmax, xinvert, xcount,\
  143. xhandler_get, xhandler_put) \
  144. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  145. .info = snd_soc_info_multi_ext, \
  146. .get = xhandler_get, .put = xhandler_put, \
  147. .private_value = (unsigned long)&(struct soc_multi_mixer_control) \
  148. {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
  149. .count = xcount, .platform_max = xmax, .invert = xinvert} }
  150. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  151. xhandler_get, xhandler_put, tlv_array) \
  152. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  153. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  154. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  155. .tlv.p = (tlv_array), \
  156. .info = snd_soc_info_volsw, \
  157. .get = xhandler_get, .put = xhandler_put, \
  158. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  159. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  160. xhandler_get, xhandler_put, tlv_array) \
  161. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  162. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  163. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  164. .tlv.p = (tlv_array), \
  165. .info = snd_soc_info_volsw, \
  166. .get = xhandler_get, .put = xhandler_put, \
  167. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  168. xmax, xinvert) }
  169. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  170. xhandler_get, xhandler_put, 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, \
  176. .get = xhandler_get, .put = xhandler_put, \
  177. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  178. xmax, xinvert) }
  179. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  180. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  181. .info = snd_soc_info_bool_ext, \
  182. .get = xhandler_get, .put = xhandler_put, \
  183. .private_value = xdata }
  184. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  185. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  186. .info = snd_soc_info_enum_ext, \
  187. .get = xhandler_get, .put = xhandler_put, \
  188. .private_value = (unsigned long)&xenum }
  189. #define SOC_DOUBLE_R_SX_TLV(xname, xreg_left, xreg_right, xshift,\
  190. xmin, xmax, tlv_array) \
  191. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  192. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  193. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  194. .tlv.p = (tlv_array), \
  195. .info = snd_soc_info_volsw_2r_sx, \
  196. .get = snd_soc_get_volsw_2r_sx, \
  197. .put = snd_soc_put_volsw_2r_sx, \
  198. .private_value = (unsigned long)&(struct soc_mixer_control) \
  199. {.reg = xreg_left, \
  200. .rreg = xreg_right, .shift = xshift, \
  201. .min = xmin, .max = xmax} }
  202. /*
  203. * Simplified versions of above macros, declaring a struct and calculating
  204. * ARRAY_SIZE internally
  205. */
  206. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  207. struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  208. ARRAY_SIZE(xtexts), xtexts)
  209. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  210. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  211. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  212. struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  213. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  214. struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  215. ARRAY_SIZE(xtexts), xtexts, xvalues)
  216. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  217. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  218. /* DAI Link Host Mode Support */
  219. #define SND_SOC_DAI_LINK_NO_HOST 0x1
  220. #define SND_SOC_DAI_LINK_OPT_HOST 0x2
  221. #define snd_soc_get_enum_text(soc_enum, idx) \
  222. (soc_enum->texts ? soc_enum->texts[idx] : soc_enum->dtexts[idx])
  223. /*
  224. * Component probe and remove ordering levels for components with runtime
  225. * dependencies.
  226. */
  227. #define SND_SOC_COMP_ORDER_FIRST -2
  228. #define SND_SOC_COMP_ORDER_EARLY -1
  229. #define SND_SOC_COMP_ORDER_NORMAL 0
  230. #define SND_SOC_COMP_ORDER_LATE 1
  231. #define SND_SOC_COMP_ORDER_LAST 2
  232. /*
  233. * Bias levels
  234. *
  235. * @ON: Bias is fully on for audio playback and capture operations.
  236. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  237. * stream start and stop operations.
  238. * @STANDBY: Low power standby state when no playback/capture operations are
  239. * in progress. NOTE: The transition time between STANDBY and ON
  240. * should be as fast as possible and no longer than 10ms.
  241. * @OFF: Power Off. No restrictions on transition times.
  242. */
  243. enum snd_soc_bias_level {
  244. SND_SOC_BIAS_OFF = 0,
  245. SND_SOC_BIAS_STANDBY = 1,
  246. SND_SOC_BIAS_PREPARE = 2,
  247. SND_SOC_BIAS_ON = 3,
  248. };
  249. struct device_node;
  250. struct snd_jack;
  251. struct snd_soc_card;
  252. struct snd_soc_pcm_stream;
  253. struct snd_soc_ops;
  254. struct snd_soc_pcm_runtime;
  255. struct snd_soc_dai;
  256. struct snd_soc_dai_driver;
  257. struct snd_soc_platform;
  258. struct snd_soc_dai_link;
  259. struct snd_soc_platform_driver;
  260. struct snd_soc_codec;
  261. struct snd_soc_codec_driver;
  262. struct soc_enum;
  263. struct snd_soc_jack;
  264. struct snd_soc_jack_zone;
  265. struct snd_soc_jack_pin;
  266. struct snd_soc_cache_ops;
  267. struct snd_soc_dpcm_link;
  268. #include <sound/soc-dapm.h>
  269. #ifdef CONFIG_GPIOLIB
  270. struct snd_soc_jack_gpio;
  271. #endif
  272. typedef int (*hw_write_t)(void *,const char* ,int);
  273. extern struct snd_ac97_bus_ops soc_ac97_ops;
  274. enum snd_soc_control_type {
  275. SND_SOC_I2C = 1,
  276. SND_SOC_SPI,
  277. SND_SOC_REGMAP,
  278. };
  279. enum snd_soc_compress_type {
  280. SND_SOC_FLAT_COMPRESSION = 1,
  281. };
  282. enum snd_soc_pcm_subclass {
  283. SND_SOC_PCM_CLASS_PCM = 0,
  284. SND_SOC_PCM_CLASS_BE = 1,
  285. };
  286. /*
  287. * Dynamic PCM DAI link states.
  288. */
  289. enum snd_soc_dpcm_state {
  290. SND_SOC_DPCM_STATE_NEW = 0,
  291. SND_SOC_DPCM_STATE_OPEN,
  292. SND_SOC_DPCM_STATE_HW_PARAMS,
  293. SND_SOC_DPCM_STATE_PREPARE,
  294. SND_SOC_DPCM_STATE_START,
  295. SND_SOC_DPCM_STATE_STOP,
  296. SND_SOC_DPCM_STATE_PAUSED,
  297. SND_SOC_DPCM_STATE_SUSPEND,
  298. SND_SOC_DPCM_STATE_HW_FREE,
  299. SND_SOC_DPCM_STATE_CLOSE,
  300. };
  301. /*
  302. * Dynamic PCM trigger ordering. Triggering flexibility is required as some
  303. * DSPs require triggering before/after their clients/hosts.
  304. *
  305. * i.e. some clients may want to manually order this call in their PCM
  306. * trigger() whilst others will just use the regular core ordering.
  307. */
  308. enum snd_soc_dpcm_trigger {
  309. SND_SOC_DPCM_TRIGGER_PRE = 0,
  310. SND_SOC_DPCM_TRIGGER_POST,
  311. SND_SOC_DPCM_TRIGGER_BESPOKE,
  312. };
  313. enum snd_soc_card_subclass {
  314. SND_SOC_CARD_CLASS_INIT = 0,
  315. SND_SOC_CARD_CLASS_PCM = 1,
  316. };
  317. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  318. int source, unsigned int freq, int dir);
  319. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  320. unsigned int freq_in, unsigned int freq_out);
  321. int snd_soc_register_card(struct snd_soc_card *card);
  322. int snd_soc_unregister_card(struct snd_soc_card *card);
  323. int snd_soc_suspend(struct device *dev);
  324. int snd_soc_resume(struct device *dev);
  325. int snd_soc_poweroff(struct device *dev);
  326. int snd_soc_register_platform(struct device *dev,
  327. struct snd_soc_platform_driver *platform_drv);
  328. void snd_soc_unregister_platform(struct device *dev);
  329. int snd_soc_register_codec(struct device *dev,
  330. const struct snd_soc_codec_driver *codec_drv,
  331. struct snd_soc_dai_driver *dai_drv, int num_dai);
  332. void snd_soc_unregister_codec(struct device *dev);
  333. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
  334. unsigned int reg);
  335. int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
  336. unsigned int reg);
  337. int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
  338. unsigned int reg);
  339. int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
  340. int addr_bits, int data_bits,
  341. enum snd_soc_control_type control);
  342. int snd_soc_cache_sync(struct snd_soc_codec *codec);
  343. int snd_soc_cache_init(struct snd_soc_codec *codec);
  344. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  345. int snd_soc_cache_write(struct snd_soc_codec *codec,
  346. unsigned int reg, unsigned int value);
  347. int snd_soc_cache_read(struct snd_soc_codec *codec,
  348. unsigned int reg, unsigned int *value);
  349. int snd_soc_default_volatile_register(struct snd_soc_codec *codec,
  350. unsigned int reg);
  351. int snd_soc_default_readable_register(struct snd_soc_codec *codec,
  352. unsigned int reg);
  353. int snd_soc_default_writable_register(struct snd_soc_codec *codec,
  354. unsigned int reg);
  355. int snd_soc_platform_read(struct snd_soc_platform *platform,
  356. unsigned int reg);
  357. int snd_soc_platform_write(struct snd_soc_platform *platform,
  358. unsigned int reg, unsigned int val);
  359. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  360. int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num);
  361. struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
  362. const char *dai_link, int stream);
  363. struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  364. const char *dai_link);
  365. /* Utility functions to get clock rates from various things */
  366. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  367. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  368. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  369. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  370. /* set runtime hw params */
  371. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  372. const struct snd_pcm_hardware *hw);
  373. /* Jack reporting */
  374. int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
  375. struct snd_soc_jack *jack);
  376. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  377. void snd_soc_jack_report_no_dapm(struct snd_soc_jack *jack, int status,
  378. int mask);
  379. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  380. struct snd_soc_jack_pin *pins);
  381. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  382. struct notifier_block *nb);
  383. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  384. struct notifier_block *nb);
  385. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  386. struct snd_soc_jack_zone *zones);
  387. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  388. #ifdef CONFIG_GPIOLIB
  389. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  390. struct snd_soc_jack_gpio *gpios);
  391. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  392. struct snd_soc_jack_gpio *gpios);
  393. #endif
  394. /* codec register bit access */
  395. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  396. unsigned int mask, unsigned int value);
  397. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  398. unsigned short reg, unsigned int mask,
  399. unsigned int value);
  400. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  401. unsigned int mask, unsigned int value);
  402. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  403. struct snd_ac97_bus_ops *ops, int num);
  404. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  405. void snd_soc_card_change_online_state(struct snd_soc_card *soc_card,
  406. int online);
  407. /*
  408. *Controls
  409. */
  410. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  411. void *data, char *long_name,
  412. const char *prefix);
  413. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  414. const struct snd_kcontrol_new *controls, int num_controls);
  415. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  416. const struct snd_kcontrol_new *controls, int num_controls);
  417. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  418. const struct snd_kcontrol_new *controls, int num_controls);
  419. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  420. const struct snd_kcontrol_new *controls, int num_controls);
  421. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  422. struct snd_ctl_elem_info *uinfo);
  423. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  424. struct snd_ctl_elem_info *uinfo);
  425. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  426. struct snd_ctl_elem_value *ucontrol);
  427. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  428. struct snd_ctl_elem_value *ucontrol);
  429. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  430. struct snd_ctl_elem_value *ucontrol);
  431. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  432. struct snd_ctl_elem_value *ucontrol);
  433. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  434. struct snd_ctl_elem_info *uinfo);
  435. int snd_soc_info_multi_ext(struct snd_kcontrol *kcontrol,
  436. struct snd_ctl_elem_info *uinfo);
  437. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  438. struct snd_ctl_elem_info *uinfo);
  439. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  440. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  441. struct snd_ctl_elem_value *ucontrol);
  442. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  443. struct snd_ctl_elem_value *ucontrol);
  444. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  445. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  446. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  447. struct snd_ctl_elem_info *uinfo);
  448. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  449. struct snd_ctl_elem_value *ucontrol);
  450. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  451. struct snd_ctl_elem_value *ucontrol);
  452. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  453. const char *name, int max);
  454. int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  455. struct snd_ctl_elem_info *uinfo);
  456. int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  457. struct snd_ctl_elem_value *ucontrol);
  458. int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  459. struct snd_ctl_elem_value *ucontrol);
  460. /**
  461. * struct snd_soc_reg_access - Describes whether a given register is
  462. * readable, writable or volatile.
  463. *
  464. * @reg: the register number
  465. * @read: whether this register is readable
  466. * @write: whether this register is writable
  467. * @vol: whether this register is volatile
  468. */
  469. struct snd_soc_reg_access {
  470. u16 reg;
  471. u16 read;
  472. u16 write;
  473. u16 vol;
  474. };
  475. /**
  476. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  477. *
  478. * @pin: name of the pin to update
  479. * @mask: bits to check for in reported jack status
  480. * @invert: if non-zero then pin is enabled when status is not reported
  481. */
  482. struct snd_soc_jack_pin {
  483. struct list_head list;
  484. const char *pin;
  485. int mask;
  486. bool invert;
  487. };
  488. /**
  489. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  490. *
  491. * @min_mv: start voltage in mv
  492. * @max_mv: end voltage in mv
  493. * @jack_type: type of jack that is expected for this voltage
  494. * @debounce_time: debounce_time for jack, codec driver should wait for this
  495. * duration before reading the adc for voltages
  496. * @:list: list container
  497. */
  498. struct snd_soc_jack_zone {
  499. unsigned int min_mv;
  500. unsigned int max_mv;
  501. unsigned int jack_type;
  502. unsigned int debounce_time;
  503. struct list_head list;
  504. };
  505. /**
  506. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  507. *
  508. * @gpio: gpio number
  509. * @name: gpio name
  510. * @report: value to report when jack detected
  511. * @invert: report presence in low state
  512. * @debouce_time: debouce time in ms
  513. * @wake: enable as wake source
  514. * @jack_status_check: callback function which overrides the detection
  515. * to provide more complex checks (eg, reading an
  516. * ADC).
  517. */
  518. #ifdef CONFIG_GPIOLIB
  519. struct snd_soc_jack_gpio {
  520. unsigned int gpio;
  521. const char *name;
  522. int report;
  523. int invert;
  524. int debounce_time;
  525. bool wake;
  526. struct snd_soc_jack *jack;
  527. struct delayed_work work;
  528. int (*jack_status_check)(void);
  529. };
  530. #endif
  531. struct snd_soc_jack {
  532. struct mutex mutex;
  533. struct snd_jack *jack;
  534. struct snd_soc_codec *codec;
  535. struct list_head pins;
  536. int status;
  537. struct blocking_notifier_head notifier;
  538. struct list_head jack_zones;
  539. };
  540. /* SoC PCM stream information */
  541. struct snd_soc_pcm_stream {
  542. const char *stream_name;
  543. const char *aif_name; /* DAPM AIF widget name */
  544. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  545. unsigned int rates; /* SNDRV_PCM_RATE_* */
  546. unsigned int rate_min; /* min rate */
  547. unsigned int rate_max; /* max rate */
  548. unsigned int channels_min; /* min channels */
  549. unsigned int channels_max; /* max channels */
  550. unsigned int sig_bits; /* number of bits of content */
  551. };
  552. /* SoC audio ops */
  553. struct snd_soc_ops {
  554. int (*startup)(struct snd_pcm_substream *);
  555. void (*shutdown)(struct snd_pcm_substream *);
  556. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  557. int (*hw_free)(struct snd_pcm_substream *);
  558. int (*prepare)(struct snd_pcm_substream *);
  559. int (*trigger)(struct snd_pcm_substream *, int);
  560. };
  561. struct snd_soc_compr_ops {
  562. int (*startup)(struct snd_compr_stream *);
  563. void (*shutdown)(struct snd_compr_stream *);
  564. int (*set_params)(struct snd_compr_stream *);
  565. int (*trigger)(struct snd_compr_stream *);
  566. };
  567. /* SoC cache ops */
  568. struct snd_soc_cache_ops {
  569. const char *name;
  570. enum snd_soc_compress_type id;
  571. int (*init)(struct snd_soc_codec *codec);
  572. int (*exit)(struct snd_soc_codec *codec);
  573. int (*read)(struct snd_soc_codec *codec, unsigned int reg,
  574. unsigned int *value);
  575. int (*write)(struct snd_soc_codec *codec, unsigned int reg,
  576. unsigned int value);
  577. int (*sync)(struct snd_soc_codec *codec);
  578. };
  579. /* SoC Audio Codec device */
  580. struct snd_soc_codec {
  581. const char *name;
  582. const char *name_prefix;
  583. int id;
  584. struct device *dev;
  585. const struct snd_soc_codec_driver *driver;
  586. struct mutex mutex;
  587. struct snd_soc_card *card;
  588. struct list_head list;
  589. struct list_head card_list;
  590. int num_dai;
  591. enum snd_soc_compress_type compress_type;
  592. size_t reg_size; /* reg_cache_size * reg_word_size */
  593. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  594. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  595. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  596. /* runtime */
  597. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  598. unsigned int active;
  599. unsigned int cache_bypass:1; /* Suppress access to the cache */
  600. unsigned int suspended:1; /* Codec is in suspend PM state */
  601. unsigned int probed:1; /* Codec has been probed */
  602. unsigned int ac97_registered:1; /* Codec has been AC97 registered */
  603. unsigned int ac97_created:1; /* Codec has been created by SoC */
  604. unsigned int sysfs_registered:1; /* codec has been sysfs registered */
  605. unsigned int cache_init:1; /* codec cache has been initialized */
  606. unsigned int using_regmap:1; /* using regmap access */
  607. u32 cache_only; /* Suppress writes to hardware */
  608. u32 cache_sync; /* Cache needs to be synced to hardware */
  609. /* codec IO */
  610. void *control_data; /* codec control (i2c/3wire) data */
  611. enum snd_soc_control_type control_type;
  612. hw_write_t hw_write;
  613. unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
  614. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  615. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  616. int (*bulk_write_raw)(struct snd_soc_codec *, unsigned int, const void *, size_t);
  617. void *reg_cache;
  618. const void *reg_def_copy;
  619. const struct snd_soc_cache_ops *cache_ops;
  620. struct mutex cache_rw_mutex;
  621. int val_bytes;
  622. /* dapm */
  623. struct snd_soc_dapm_context dapm;
  624. unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
  625. #ifdef CONFIG_DEBUG_FS
  626. struct dentry *debugfs_codec_root;
  627. struct dentry *debugfs_reg;
  628. struct dentry *debugfs_dapm;
  629. #endif
  630. };
  631. /* codec driver */
  632. struct snd_soc_codec_driver {
  633. /* driver ops */
  634. int (*probe)(struct snd_soc_codec *);
  635. int (*remove)(struct snd_soc_codec *);
  636. int (*suspend)(struct snd_soc_codec *);
  637. int (*resume)(struct snd_soc_codec *);
  638. /* Default control and setup, added after probe() is run */
  639. const struct snd_kcontrol_new *controls;
  640. int num_controls;
  641. const struct snd_soc_dapm_widget *dapm_widgets;
  642. int num_dapm_widgets;
  643. const struct snd_soc_dapm_route *dapm_routes;
  644. int num_dapm_routes;
  645. /* codec wide operations */
  646. int (*set_sysclk)(struct snd_soc_codec *codec,
  647. int clk_id, int source, unsigned int freq, int dir);
  648. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  649. unsigned int freq_in, unsigned int freq_out);
  650. /* codec IO */
  651. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  652. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  653. int (*display_register)(struct snd_soc_codec *, char *,
  654. size_t, unsigned int);
  655. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  656. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  657. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  658. unsigned int reg_cache_size;
  659. short reg_cache_step;
  660. short reg_word_size;
  661. const void *reg_cache_default;
  662. short reg_access_size;
  663. const struct snd_soc_reg_access *reg_access_default;
  664. enum snd_soc_compress_type compress_type;
  665. /* codec bias level */
  666. int (*set_bias_level)(struct snd_soc_codec *,
  667. enum snd_soc_bias_level level);
  668. bool idle_bias_off;
  669. void (*seq_notifier)(struct snd_soc_dapm_context *,
  670. enum snd_soc_dapm_type, int);
  671. /* codec stream completion event */
  672. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  673. /* probe ordering - for components with runtime dependencies */
  674. int probe_order;
  675. int remove_order;
  676. };
  677. /* SoC platform interface */
  678. struct snd_soc_platform_driver {
  679. int (*probe)(struct snd_soc_platform *);
  680. int (*remove)(struct snd_soc_platform *);
  681. int (*suspend)(struct snd_soc_dai *dai);
  682. int (*resume)(struct snd_soc_dai *dai);
  683. /* pcm creation and destruction */
  684. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  685. void (*pcm_free)(struct snd_pcm *);
  686. /* Default control and setup, added after probe() is run */
  687. const struct snd_kcontrol_new *controls;
  688. int num_controls;
  689. const struct snd_soc_dapm_widget *dapm_widgets;
  690. int num_dapm_widgets;
  691. const struct snd_soc_dapm_route *dapm_routes;
  692. int num_dapm_routes;
  693. /*
  694. * For platform caused delay reporting.
  695. * Optional.
  696. */
  697. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  698. struct snd_soc_dai *);
  699. /* platform stream pcm ops */
  700. struct snd_pcm_ops *ops;
  701. /* platform stream compress ops */
  702. struct snd_compr_ops *compr_ops;
  703. /* platform stream completion event */
  704. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  705. /* probe ordering - for components with runtime dependencies */
  706. int probe_order;
  707. int remove_order;
  708. /* platform IO - used for platform DAPM */
  709. unsigned int (*read)(struct snd_soc_platform *, unsigned int);
  710. int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
  711. int (*bespoke_trigger)(struct snd_pcm_substream *, int);
  712. };
  713. struct snd_soc_platform {
  714. const char *name;
  715. int id;
  716. struct device *dev;
  717. struct snd_soc_platform_driver *driver;
  718. unsigned int suspended:1; /* platform is suspended */
  719. unsigned int probed:1;
  720. struct snd_soc_card *card;
  721. struct list_head list;
  722. struct list_head card_list;
  723. struct snd_soc_dapm_context dapm;
  724. #ifdef CONFIG_DEBUG_FS
  725. struct dentry *debugfs_platform_root;
  726. struct dentry *debugfs_dapm;
  727. #endif
  728. };
  729. struct snd_soc_dai_link {
  730. /* config - must be set by machine driver */
  731. const char *name; /* Codec name */
  732. const char *stream_name; /* Stream name */
  733. const char *codec_name; /* for multi-codec */
  734. const struct device_node *codec_of_node;
  735. const char *platform_name; /* for multi-platform */
  736. const struct device_node *platform_of_node;
  737. const char *cpu_dai_name;
  738. const struct device_node *cpu_dai_of_node;
  739. const char *codec_dai_name;
  740. unsigned int dai_fmt; /* format to set on init */
  741. enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
  742. /* Keep DAI active over suspend */
  743. unsigned int ignore_suspend:1;
  744. /* Symmetry requirements */
  745. unsigned int symmetric_rates:1;
  746. /* No PCM created for this DAI link */
  747. unsigned int no_pcm:1;
  748. /* This DAI link can change CODEC and platform at runtime*/
  749. unsigned int dynamic:1;
  750. /* This DAI has a Backend ID */
  751. unsigned int be_id;
  752. /* This DAI can support no host IO (no pcm data is copied to from host) */
  753. unsigned int no_host_mode:2;
  754. /* pmdown_time is ignored at stop */
  755. unsigned int ignore_pmdown_time:1;
  756. /* codec/machine specific init - e.g. add machine controls */
  757. int (*init)(struct snd_soc_pcm_runtime *rtd);
  758. /* hw_params re-writing for BE and FE sync */
  759. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  760. struct snd_pcm_hw_params *params);
  761. /* machine stream operations */
  762. struct snd_soc_ops *ops;
  763. struct snd_soc_compr_ops *compr_ops;
  764. };
  765. struct snd_soc_codec_conf {
  766. const char *dev_name;
  767. /*
  768. * optional map of kcontrol, widget and path name prefixes that are
  769. * associated per device
  770. */
  771. const char *name_prefix;
  772. /*
  773. * set this to the desired compression type if you want to
  774. * override the one supplied in codec->driver->compress_type
  775. */
  776. enum snd_soc_compress_type compress_type;
  777. };
  778. struct snd_soc_aux_dev {
  779. const char *name; /* Codec name */
  780. const char *codec_name; /* for multi-codec */
  781. /* codec/machine specific init - e.g. add machine controls */
  782. int (*init)(struct snd_soc_dapm_context *dapm);
  783. };
  784. /* SoC card */
  785. struct snd_soc_card {
  786. const char *name;
  787. const char *long_name;
  788. const char *driver_name;
  789. struct device *dev;
  790. struct snd_card *snd_card;
  791. struct module *owner;
  792. struct list_head list;
  793. struct mutex mutex;
  794. struct mutex dpcm_mutex;
  795. struct mutex dapm_mutex;
  796. struct mutex dapm_power_mutex;
  797. struct mutex dsp_mutex;
  798. spinlock_t dsp_spinlock;
  799. bool instantiated;
  800. int (*probe)(struct snd_soc_card *card);
  801. int (*late_probe)(struct snd_soc_card *card);
  802. int (*remove)(struct snd_soc_card *card);
  803. /* the pre and post PM functions are used to do any PM work before and
  804. * after the codec and DAI's do any PM work. */
  805. int (*suspend_pre)(struct snd_soc_card *card);
  806. int (*suspend_post)(struct snd_soc_card *card);
  807. int (*resume_pre)(struct snd_soc_card *card);
  808. int (*resume_post)(struct snd_soc_card *card);
  809. /* callbacks */
  810. int (*set_bias_level)(struct snd_soc_card *,
  811. struct snd_soc_dapm_context *dapm,
  812. enum snd_soc_bias_level level);
  813. int (*set_bias_level_post)(struct snd_soc_card *,
  814. struct snd_soc_dapm_context *dapm,
  815. enum snd_soc_bias_level level);
  816. long pmdown_time;
  817. /* CPU <--> Codec DAI links */
  818. struct snd_soc_dai_link *dai_link;
  819. int num_links;
  820. struct snd_soc_pcm_runtime *rtd;
  821. int num_rtd;
  822. int num_playback_channels;
  823. int num_capture_channels;
  824. /* optional codec specific configuration */
  825. struct snd_soc_codec_conf *codec_conf;
  826. int num_configs;
  827. /*
  828. * optional auxiliary devices such as amplifiers or codecs with DAI
  829. * link unused
  830. */
  831. struct snd_soc_aux_dev *aux_dev;
  832. int num_aux_devs;
  833. struct snd_soc_pcm_runtime *rtd_aux;
  834. int num_aux_rtd;
  835. const struct snd_kcontrol_new *controls;
  836. int num_controls;
  837. /*
  838. * Card-specific routes and widgets.
  839. */
  840. const struct snd_soc_dapm_widget *dapm_widgets;
  841. int num_dapm_widgets;
  842. const struct snd_soc_dapm_route *dapm_routes;
  843. int num_dapm_routes;
  844. bool fully_routed;
  845. struct work_struct deferred_resume_work;
  846. /* lists of probed devices belonging to this card */
  847. struct list_head codec_dev_list;
  848. struct list_head platform_dev_list;
  849. struct list_head dai_dev_list;
  850. struct list_head widgets;
  851. struct list_head paths;
  852. struct list_head dapm_list;
  853. struct list_head dapm_dirty;
  854. /* Generic DAPM context for the card */
  855. struct snd_soc_dapm_context dapm;
  856. struct snd_soc_dapm_stats dapm_stats;
  857. #ifdef CONFIG_DEBUG_FS
  858. struct dentry *debugfs_card_root;
  859. struct dentry *debugfs_pop_time;
  860. #endif
  861. u32 pop_time;
  862. void *drvdata;
  863. };
  864. /* DSP runtime data */
  865. struct snd_soc_dpcm_runtime {
  866. struct list_head be_clients;
  867. struct list_head fe_clients;
  868. int users;
  869. struct snd_pcm_runtime *runtime;
  870. struct snd_pcm_hw_params hw_params;
  871. int runtime_update;
  872. enum snd_soc_dpcm_state state;
  873. };
  874. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  875. struct snd_soc_pcm_runtime {
  876. struct device *dev;
  877. struct snd_soc_card *card;
  878. struct snd_soc_dai_link *dai_link;
  879. struct mutex pcm_mutex;
  880. enum snd_soc_pcm_subclass pcm_subclass;
  881. struct snd_pcm_ops ops;
  882. unsigned int dev_registered:1;
  883. /* Dynamic PCM BE runtime data */
  884. struct snd_soc_dpcm_runtime dpcm[2];
  885. int fe_compr;
  886. long pmdown_time;
  887. /* runtime devices */
  888. struct snd_pcm *pcm;
  889. struct snd_compr *compr;
  890. struct snd_soc_codec *codec;
  891. struct snd_soc_platform *platform;
  892. struct snd_soc_dai *codec_dai;
  893. struct snd_soc_dai *cpu_dai;
  894. struct delayed_work delayed_work;
  895. #ifdef CONFIG_DEBUG_FS
  896. struct dentry *debugfs_dpcm_root;
  897. struct dentry *debugfs_dpcm_state;
  898. #endif
  899. };
  900. /* mixer control */
  901. struct soc_mixer_control {
  902. int min, max, platform_max;
  903. unsigned int reg, rreg, shift, rshift, invert;
  904. };
  905. struct soc_multi_mixer_control {
  906. int min, max, platform_max, count;
  907. unsigned int reg, rreg, shift, rshift, invert;
  908. };
  909. /* enumerated kcontrol */
  910. struct soc_enum {
  911. unsigned short reg;
  912. unsigned short reg2;
  913. unsigned char shift_l;
  914. unsigned char shift_r;
  915. unsigned int max;
  916. unsigned int mask;
  917. const char * const *texts;
  918. char **dtexts;
  919. const unsigned int *values;
  920. void *dapm;
  921. };
  922. /* codec IO */
  923. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  924. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  925. unsigned int reg, unsigned int val);
  926. unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
  927. unsigned int reg, const void *data, size_t len);
  928. /* device driver data */
  929. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  930. void *data)
  931. {
  932. card->drvdata = data;
  933. }
  934. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  935. {
  936. return card->drvdata;
  937. }
  938. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  939. void *data)
  940. {
  941. dev_set_drvdata(codec->dev, data);
  942. }
  943. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  944. {
  945. return dev_get_drvdata(codec->dev);
  946. }
  947. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  948. void *data)
  949. {
  950. dev_set_drvdata(platform->dev, data);
  951. }
  952. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  953. {
  954. return dev_get_drvdata(platform->dev);
  955. }
  956. static inline void snd_soc_pcm_set_drvdata(struct snd_soc_pcm_runtime *rtd,
  957. void *data)
  958. {
  959. dev_set_drvdata(rtd->dev, data);
  960. }
  961. static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)
  962. {
  963. return dev_get_drvdata(rtd->dev);
  964. }
  965. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  966. {
  967. INIT_LIST_HEAD(&card->dai_dev_list);
  968. INIT_LIST_HEAD(&card->codec_dev_list);
  969. INIT_LIST_HEAD(&card->platform_dev_list);
  970. INIT_LIST_HEAD(&card->widgets);
  971. INIT_LIST_HEAD(&card->paths);
  972. INIT_LIST_HEAD(&card->dapm_list);
  973. }
  974. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  975. {
  976. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  977. return 0;
  978. /*
  979. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  980. * mc->reg != mc->rreg means that the control is
  981. * stereo (bits in one register or in two registers)
  982. */
  983. return 1;
  984. }
  985. int snd_soc_util_init(void);
  986. void snd_soc_util_exit(void);
  987. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  988. const char *propname);
  989. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  990. const char *propname);
  991. #include <sound/soc-dai.h>
  992. #ifdef CONFIG_DEBUG_FS
  993. extern struct dentry *snd_soc_debugfs_root;
  994. #endif
  995. extern const struct dev_pm_ops snd_soc_pm_ops;
  996. #endif