wm8400.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  1. /*
  2. * wm8400.c -- WM8400 ALSA Soc Audio driver
  3. *
  4. * Copyright 2008, 2009 Wolfson Microelectronics PLC.
  5. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/kernel.h>
  16. #include <linux/slab.h>
  17. #include <linux/init.h>
  18. #include <linux/delay.h>
  19. #include <linux/pm.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/mfd/wm8400-audio.h>
  23. #include <linux/mfd/wm8400-private.h>
  24. #include <linux/mfd/core.h>
  25. #include <sound/core.h>
  26. #include <sound/pcm.h>
  27. #include <sound/pcm_params.h>
  28. #include <sound/soc.h>
  29. #include <sound/initval.h>
  30. #include <sound/tlv.h>
  31. #include "wm8400.h"
  32. /* Fake register for internal state */
  33. #define WM8400_INTDRIVBITS (WM8400_REGISTER_COUNT + 1)
  34. #define WM8400_INMIXL_PWR 0
  35. #define WM8400_AINLMUX_PWR 1
  36. #define WM8400_INMIXR_PWR 2
  37. #define WM8400_AINRMUX_PWR 3
  38. static struct regulator_bulk_data power[] = {
  39. {
  40. .supply = "I2S1VDD",
  41. },
  42. {
  43. .supply = "I2S2VDD",
  44. },
  45. {
  46. .supply = "DCVDD",
  47. },
  48. {
  49. .supply = "AVDD",
  50. },
  51. {
  52. .supply = "FLLVDD",
  53. },
  54. {
  55. .supply = "HPVDD",
  56. },
  57. {
  58. .supply = "SPKVDD",
  59. },
  60. };
  61. /* codec private data */
  62. struct wm8400_priv {
  63. struct snd_soc_codec *codec;
  64. struct wm8400 *wm8400;
  65. u16 fake_register;
  66. unsigned int sysclk;
  67. unsigned int pcmclk;
  68. struct work_struct work;
  69. int fll_in, fll_out;
  70. };
  71. static inline unsigned int wm8400_read(struct snd_soc_codec *codec,
  72. unsigned int reg)
  73. {
  74. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  75. if (reg == WM8400_INTDRIVBITS)
  76. return wm8400->fake_register;
  77. else
  78. return wm8400_reg_read(wm8400->wm8400, reg);
  79. }
  80. /*
  81. * write to the wm8400 register space
  82. */
  83. static int wm8400_write(struct snd_soc_codec *codec, unsigned int reg,
  84. unsigned int value)
  85. {
  86. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  87. if (reg == WM8400_INTDRIVBITS) {
  88. wm8400->fake_register = value;
  89. return 0;
  90. } else
  91. return wm8400_set_bits(wm8400->wm8400, reg, 0xffff, value);
  92. }
  93. static void wm8400_codec_reset(struct snd_soc_codec *codec)
  94. {
  95. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  96. wm8400_reset_codec_reg_cache(wm8400->wm8400);
  97. }
  98. static const DECLARE_TLV_DB_SCALE(rec_mix_tlv, -1500, 600, 0);
  99. static const DECLARE_TLV_DB_SCALE(in_pga_tlv, -1650, 3000, 0);
  100. static const DECLARE_TLV_DB_SCALE(out_mix_tlv, -2100, 0, 0);
  101. static const DECLARE_TLV_DB_SCALE(out_pga_tlv, -7300, 600, 0);
  102. static const DECLARE_TLV_DB_SCALE(out_omix_tlv, -600, 0, 0);
  103. static const DECLARE_TLV_DB_SCALE(out_dac_tlv, -7163, 0, 0);
  104. static const DECLARE_TLV_DB_SCALE(in_adc_tlv, -7163, 1763, 0);
  105. static const DECLARE_TLV_DB_SCALE(out_sidetone_tlv, -3600, 0, 0);
  106. static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
  107. struct snd_ctl_elem_value *ucontrol)
  108. {
  109. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  110. struct soc_mixer_control *mc =
  111. (struct soc_mixer_control *)kcontrol->private_value;
  112. int reg = mc->reg;
  113. int ret;
  114. u16 val;
  115. ret = snd_soc_put_volsw(kcontrol, ucontrol);
  116. if (ret < 0)
  117. return ret;
  118. /* now hit the volume update bits (always bit 8) */
  119. val = wm8400_read(codec, reg);
  120. return wm8400_write(codec, reg, val | 0x0100);
  121. }
  122. #define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \
  123. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  124. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  125. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  126. .tlv.p = (tlv_array), \
  127. .info = snd_soc_info_volsw, \
  128. .get = snd_soc_get_volsw, .put = wm8400_outpga_put_volsw_vu, \
  129. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  130. static const char *wm8400_digital_sidetone[] =
  131. {"None", "Left ADC", "Right ADC", "Reserved"};
  132. static const struct soc_enum wm8400_left_digital_sidetone_enum =
  133. SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE,
  134. WM8400_ADC_TO_DACL_SHIFT, 2, wm8400_digital_sidetone);
  135. static const struct soc_enum wm8400_right_digital_sidetone_enum =
  136. SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE,
  137. WM8400_ADC_TO_DACR_SHIFT, 2, wm8400_digital_sidetone);
  138. static const char *wm8400_adcmode[] =
  139. {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
  140. static const struct soc_enum wm8400_right_adcmode_enum =
  141. SOC_ENUM_SINGLE(WM8400_ADC_CTRL, WM8400_ADC_HPF_CUT_SHIFT, 3, wm8400_adcmode);
  142. static const struct snd_kcontrol_new wm8400_snd_controls[] = {
  143. /* INMIXL */
  144. SOC_SINGLE("LIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L12MNBST_SHIFT,
  145. 1, 0),
  146. SOC_SINGLE("LIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L34MNBST_SHIFT,
  147. 1, 0),
  148. /* INMIXR */
  149. SOC_SINGLE("RIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R12MNBST_SHIFT,
  150. 1, 0),
  151. SOC_SINGLE("RIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R34MNBST_SHIFT,
  152. 1, 0),
  153. /* LOMIX */
  154. SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER3,
  155. WM8400_LLI3LOVOL_SHIFT, 7, 0, out_mix_tlv),
  156. SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3,
  157. WM8400_LR12LOVOL_SHIFT, 7, 0, out_mix_tlv),
  158. SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3,
  159. WM8400_LL12LOVOL_SHIFT, 7, 0, out_mix_tlv),
  160. SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER5,
  161. WM8400_LRI3LOVOL_SHIFT, 7, 0, out_mix_tlv),
  162. SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER5,
  163. WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv),
  164. SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER5,
  165. WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv),
  166. /* ROMIX */
  167. SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER4,
  168. WM8400_RRI3ROVOL_SHIFT, 7, 0, out_mix_tlv),
  169. SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4,
  170. WM8400_RL12ROVOL_SHIFT, 7, 0, out_mix_tlv),
  171. SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4,
  172. WM8400_RR12ROVOL_SHIFT, 7, 0, out_mix_tlv),
  173. SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER6,
  174. WM8400_RLI3ROVOL_SHIFT, 7, 0, out_mix_tlv),
  175. SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER6,
  176. WM8400_RLBROVOL_SHIFT, 7, 0, out_mix_tlv),
  177. SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER6,
  178. WM8400_RRBROVOL_SHIFT, 7, 0, out_mix_tlv),
  179. /* LOUT */
  180. WM8400_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8400_LEFT_OUTPUT_VOLUME,
  181. WM8400_LOUTVOL_SHIFT, WM8400_LOUTVOL_MASK, 0, out_pga_tlv),
  182. SOC_SINGLE("LOUT ZC", WM8400_LEFT_OUTPUT_VOLUME, WM8400_LOZC_SHIFT, 1, 0),
  183. /* ROUT */
  184. WM8400_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8400_RIGHT_OUTPUT_VOLUME,
  185. WM8400_ROUTVOL_SHIFT, WM8400_ROUTVOL_MASK, 0, out_pga_tlv),
  186. SOC_SINGLE("ROUT ZC", WM8400_RIGHT_OUTPUT_VOLUME, WM8400_ROZC_SHIFT, 1, 0),
  187. /* LOPGA */
  188. WM8400_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8400_LEFT_OPGA_VOLUME,
  189. WM8400_LOPGAVOL_SHIFT, WM8400_LOPGAVOL_MASK, 0, out_pga_tlv),
  190. SOC_SINGLE("LOPGA ZC Switch", WM8400_LEFT_OPGA_VOLUME,
  191. WM8400_LOPGAZC_SHIFT, 1, 0),
  192. /* ROPGA */
  193. WM8400_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8400_RIGHT_OPGA_VOLUME,
  194. WM8400_ROPGAVOL_SHIFT, WM8400_ROPGAVOL_MASK, 0, out_pga_tlv),
  195. SOC_SINGLE("ROPGA ZC Switch", WM8400_RIGHT_OPGA_VOLUME,
  196. WM8400_ROPGAZC_SHIFT, 1, 0),
  197. SOC_SINGLE("LON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
  198. WM8400_LONMUTE_SHIFT, 1, 0),
  199. SOC_SINGLE("LOP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
  200. WM8400_LOPMUTE_SHIFT, 1, 0),
  201. SOC_SINGLE("LOP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME,
  202. WM8400_LOATTN_SHIFT, 1, 0),
  203. SOC_SINGLE("RON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
  204. WM8400_RONMUTE_SHIFT, 1, 0),
  205. SOC_SINGLE("ROP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
  206. WM8400_ROPMUTE_SHIFT, 1, 0),
  207. SOC_SINGLE("ROP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME,
  208. WM8400_ROATTN_SHIFT, 1, 0),
  209. SOC_SINGLE("OUT3 Mute Switch", WM8400_OUT3_4_VOLUME,
  210. WM8400_OUT3MUTE_SHIFT, 1, 0),
  211. SOC_SINGLE("OUT3 Attenuation Switch", WM8400_OUT3_4_VOLUME,
  212. WM8400_OUT3ATTN_SHIFT, 1, 0),
  213. SOC_SINGLE("OUT4 Mute Switch", WM8400_OUT3_4_VOLUME,
  214. WM8400_OUT4MUTE_SHIFT, 1, 0),
  215. SOC_SINGLE("OUT4 Attenuation Switch", WM8400_OUT3_4_VOLUME,
  216. WM8400_OUT4ATTN_SHIFT, 1, 0),
  217. SOC_SINGLE("Speaker Mode Switch", WM8400_CLASSD1,
  218. WM8400_CDMODE_SHIFT, 1, 0),
  219. SOC_SINGLE("Speaker Output Attenuation Volume", WM8400_SPEAKER_VOLUME,
  220. WM8400_SPKATTN_SHIFT, WM8400_SPKATTN_MASK, 0),
  221. SOC_SINGLE("Speaker DC Boost Volume", WM8400_CLASSD3,
  222. WM8400_DCGAIN_SHIFT, 6, 0),
  223. SOC_SINGLE("Speaker AC Boost Volume", WM8400_CLASSD3,
  224. WM8400_ACGAIN_SHIFT, 6, 0),
  225. WM8400_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume",
  226. WM8400_LEFT_DAC_DIGITAL_VOLUME, WM8400_DACL_VOL_SHIFT,
  227. 127, 0, out_dac_tlv),
  228. WM8400_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume",
  229. WM8400_RIGHT_DAC_DIGITAL_VOLUME, WM8400_DACR_VOL_SHIFT,
  230. 127, 0, out_dac_tlv),
  231. SOC_ENUM("Left Digital Sidetone", wm8400_left_digital_sidetone_enum),
  232. SOC_ENUM("Right Digital Sidetone", wm8400_right_digital_sidetone_enum),
  233. SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE,
  234. WM8400_ADCL_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv),
  235. SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE,
  236. WM8400_ADCR_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv),
  237. SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8400_ADC_CTRL,
  238. WM8400_ADC_HPF_ENA_SHIFT, 1, 0),
  239. SOC_ENUM("ADC HPF Mode", wm8400_right_adcmode_enum),
  240. WM8400_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume",
  241. WM8400_LEFT_ADC_DIGITAL_VOLUME,
  242. WM8400_ADCL_VOL_SHIFT,
  243. WM8400_ADCL_VOL_MASK,
  244. 0,
  245. in_adc_tlv),
  246. WM8400_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume",
  247. WM8400_RIGHT_ADC_DIGITAL_VOLUME,
  248. WM8400_ADCR_VOL_SHIFT,
  249. WM8400_ADCR_VOL_MASK,
  250. 0,
  251. in_adc_tlv),
  252. WM8400_OUTPGA_SINGLE_R_TLV("LIN12 Volume",
  253. WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
  254. WM8400_LIN12VOL_SHIFT,
  255. WM8400_LIN12VOL_MASK,
  256. 0,
  257. in_pga_tlv),
  258. SOC_SINGLE("LIN12 ZC Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
  259. WM8400_LI12ZC_SHIFT, 1, 0),
  260. SOC_SINGLE("LIN12 Mute Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
  261. WM8400_LI12MUTE_SHIFT, 1, 0),
  262. WM8400_OUTPGA_SINGLE_R_TLV("LIN34 Volume",
  263. WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
  264. WM8400_LIN34VOL_SHIFT,
  265. WM8400_LIN34VOL_MASK,
  266. 0,
  267. in_pga_tlv),
  268. SOC_SINGLE("LIN34 ZC Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
  269. WM8400_LI34ZC_SHIFT, 1, 0),
  270. SOC_SINGLE("LIN34 Mute Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
  271. WM8400_LI34MUTE_SHIFT, 1, 0),
  272. WM8400_OUTPGA_SINGLE_R_TLV("RIN12 Volume",
  273. WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
  274. WM8400_RIN12VOL_SHIFT,
  275. WM8400_RIN12VOL_MASK,
  276. 0,
  277. in_pga_tlv),
  278. SOC_SINGLE("RIN12 ZC Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
  279. WM8400_RI12ZC_SHIFT, 1, 0),
  280. SOC_SINGLE("RIN12 Mute Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
  281. WM8400_RI12MUTE_SHIFT, 1, 0),
  282. WM8400_OUTPGA_SINGLE_R_TLV("RIN34 Volume",
  283. WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
  284. WM8400_RIN34VOL_SHIFT,
  285. WM8400_RIN34VOL_MASK,
  286. 0,
  287. in_pga_tlv),
  288. SOC_SINGLE("RIN34 ZC Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
  289. WM8400_RI34ZC_SHIFT, 1, 0),
  290. SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
  291. WM8400_RI34MUTE_SHIFT, 1, 0),
  292. };
  293. /* add non dapm controls */
  294. static int wm8400_add_controls(struct snd_soc_codec *codec)
  295. {
  296. return snd_soc_add_controls(codec, wm8400_snd_controls,
  297. ARRAY_SIZE(wm8400_snd_controls));
  298. }
  299. /*
  300. * _DAPM_ Controls
  301. */
  302. static int inmixer_event (struct snd_soc_dapm_widget *w,
  303. struct snd_kcontrol *kcontrol, int event)
  304. {
  305. u16 reg, fakepower;
  306. reg = wm8400_read(w->codec, WM8400_POWER_MANAGEMENT_2);
  307. fakepower = wm8400_read(w->codec, WM8400_INTDRIVBITS);
  308. if (fakepower & ((1 << WM8400_INMIXL_PWR) |
  309. (1 << WM8400_AINLMUX_PWR))) {
  310. reg |= WM8400_AINL_ENA;
  311. } else {
  312. reg &= ~WM8400_AINL_ENA;
  313. }
  314. if (fakepower & ((1 << WM8400_INMIXR_PWR) |
  315. (1 << WM8400_AINRMUX_PWR))) {
  316. reg |= WM8400_AINR_ENA;
  317. } else {
  318. reg &= ~WM8400_AINL_ENA;
  319. }
  320. wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg);
  321. return 0;
  322. }
  323. static int outmixer_event (struct snd_soc_dapm_widget *w,
  324. struct snd_kcontrol * kcontrol, int event)
  325. {
  326. struct soc_mixer_control *mc =
  327. (struct soc_mixer_control *)kcontrol->private_value;
  328. u32 reg_shift = mc->shift;
  329. int ret = 0;
  330. u16 reg;
  331. switch (reg_shift) {
  332. case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) :
  333. reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER1);
  334. if (reg & WM8400_LDLO) {
  335. printk(KERN_WARNING
  336. "Cannot set as Output Mixer 1 LDLO Set\n");
  337. ret = -1;
  338. }
  339. break;
  340. case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8):
  341. reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER2);
  342. if (reg & WM8400_RDRO) {
  343. printk(KERN_WARNING
  344. "Cannot set as Output Mixer 2 RDRO Set\n");
  345. ret = -1;
  346. }
  347. break;
  348. case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8):
  349. reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER);
  350. if (reg & WM8400_LDSPK) {
  351. printk(KERN_WARNING
  352. "Cannot set as Speaker Mixer LDSPK Set\n");
  353. ret = -1;
  354. }
  355. break;
  356. case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8):
  357. reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER);
  358. if (reg & WM8400_RDSPK) {
  359. printk(KERN_WARNING
  360. "Cannot set as Speaker Mixer RDSPK Set\n");
  361. ret = -1;
  362. }
  363. break;
  364. }
  365. return ret;
  366. }
  367. /* INMIX dB values */
  368. static const unsigned int in_mix_tlv[] = {
  369. TLV_DB_RANGE_HEAD(1),
  370. 0,7, TLV_DB_SCALE_ITEM(-1200, 600, 0),
  371. };
  372. /* Left In PGA Connections */
  373. static const struct snd_kcontrol_new wm8400_dapm_lin12_pga_controls[] = {
  374. SOC_DAPM_SINGLE("LIN1 Switch", WM8400_INPUT_MIXER2, WM8400_LMN1_SHIFT, 1, 0),
  375. SOC_DAPM_SINGLE("LIN2 Switch", WM8400_INPUT_MIXER2, WM8400_LMP2_SHIFT, 1, 0),
  376. };
  377. static const struct snd_kcontrol_new wm8400_dapm_lin34_pga_controls[] = {
  378. SOC_DAPM_SINGLE("LIN3 Switch", WM8400_INPUT_MIXER2, WM8400_LMN3_SHIFT, 1, 0),
  379. SOC_DAPM_SINGLE("LIN4 Switch", WM8400_INPUT_MIXER2, WM8400_LMP4_SHIFT, 1, 0),
  380. };
  381. /* Right In PGA Connections */
  382. static const struct snd_kcontrol_new wm8400_dapm_rin12_pga_controls[] = {
  383. SOC_DAPM_SINGLE("RIN1 Switch", WM8400_INPUT_MIXER2, WM8400_RMN1_SHIFT, 1, 0),
  384. SOC_DAPM_SINGLE("RIN2 Switch", WM8400_INPUT_MIXER2, WM8400_RMP2_SHIFT, 1, 0),
  385. };
  386. static const struct snd_kcontrol_new wm8400_dapm_rin34_pga_controls[] = {
  387. SOC_DAPM_SINGLE("RIN3 Switch", WM8400_INPUT_MIXER2, WM8400_RMN3_SHIFT, 1, 0),
  388. SOC_DAPM_SINGLE("RIN4 Switch", WM8400_INPUT_MIXER2, WM8400_RMP4_SHIFT, 1, 0),
  389. };
  390. /* INMIXL */
  391. static const struct snd_kcontrol_new wm8400_dapm_inmixl_controls[] = {
  392. SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8400_INPUT_MIXER3,
  393. WM8400_LDBVOL_SHIFT, WM8400_LDBVOL_MASK, 0, in_mix_tlv),
  394. SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8400_INPUT_MIXER5, WM8400_LI2BVOL_SHIFT,
  395. 7, 0, in_mix_tlv),
  396. SOC_DAPM_SINGLE("LINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
  397. 1, 0),
  398. SOC_DAPM_SINGLE("LINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
  399. 1, 0),
  400. };
  401. /* INMIXR */
  402. static const struct snd_kcontrol_new wm8400_dapm_inmixr_controls[] = {
  403. SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8400_INPUT_MIXER4,
  404. WM8400_RDBVOL_SHIFT, WM8400_RDBVOL_MASK, 0, in_mix_tlv),
  405. SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8400_INPUT_MIXER6, WM8400_RI2BVOL_SHIFT,
  406. 7, 0, in_mix_tlv),
  407. SOC_DAPM_SINGLE("RINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
  408. 1, 0),
  409. SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
  410. 1, 0),
  411. };
  412. /* AINLMUX */
  413. static const char *wm8400_ainlmux[] =
  414. {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
  415. static const struct soc_enum wm8400_ainlmux_enum =
  416. SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINLMODE_SHIFT,
  417. ARRAY_SIZE(wm8400_ainlmux), wm8400_ainlmux);
  418. static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls =
  419. SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum);
  420. /* DIFFINL */
  421. /* AINRMUX */
  422. static const char *wm8400_ainrmux[] =
  423. {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
  424. static const struct soc_enum wm8400_ainrmux_enum =
  425. SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINRMODE_SHIFT,
  426. ARRAY_SIZE(wm8400_ainrmux), wm8400_ainrmux);
  427. static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls =
  428. SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum);
  429. /* RXVOICE */
  430. static const struct snd_kcontrol_new wm8400_dapm_rxvoice_controls[] = {
  431. SOC_DAPM_SINGLE_TLV("LIN4/RXN", WM8400_INPUT_MIXER5, WM8400_LR4BVOL_SHIFT,
  432. WM8400_LR4BVOL_MASK, 0, in_mix_tlv),
  433. SOC_DAPM_SINGLE_TLV("RIN4/RXP", WM8400_INPUT_MIXER6, WM8400_RL4BVOL_SHIFT,
  434. WM8400_RL4BVOL_MASK, 0, in_mix_tlv),
  435. };
  436. /* LOMIX */
  437. static const struct snd_kcontrol_new wm8400_dapm_lomix_controls[] = {
  438. SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
  439. WM8400_LRBLO_SHIFT, 1, 0),
  440. SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
  441. WM8400_LLBLO_SHIFT, 1, 0),
  442. SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
  443. WM8400_LRI3LO_SHIFT, 1, 0),
  444. SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
  445. WM8400_LLI3LO_SHIFT, 1, 0),
  446. SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
  447. WM8400_LR12LO_SHIFT, 1, 0),
  448. SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
  449. WM8400_LL12LO_SHIFT, 1, 0),
  450. SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8400_OUTPUT_MIXER1,
  451. WM8400_LDLO_SHIFT, 1, 0),
  452. };
  453. /* ROMIX */
  454. static const struct snd_kcontrol_new wm8400_dapm_romix_controls[] = {
  455. SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
  456. WM8400_RLBRO_SHIFT, 1, 0),
  457. SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
  458. WM8400_RRBRO_SHIFT, 1, 0),
  459. SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
  460. WM8400_RLI3RO_SHIFT, 1, 0),
  461. SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
  462. WM8400_RRI3RO_SHIFT, 1, 0),
  463. SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
  464. WM8400_RL12RO_SHIFT, 1, 0),
  465. SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
  466. WM8400_RR12RO_SHIFT, 1, 0),
  467. SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8400_OUTPUT_MIXER2,
  468. WM8400_RDRO_SHIFT, 1, 0),
  469. };
  470. /* LONMIX */
  471. static const struct snd_kcontrol_new wm8400_dapm_lonmix_controls[] = {
  472. SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
  473. WM8400_LLOPGALON_SHIFT, 1, 0),
  474. SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER1,
  475. WM8400_LROPGALON_SHIFT, 1, 0),
  476. SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8400_LINE_MIXER1,
  477. WM8400_LOPLON_SHIFT, 1, 0),
  478. };
  479. /* LOPMIX */
  480. static const struct snd_kcontrol_new wm8400_dapm_lopmix_controls[] = {
  481. SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER1,
  482. WM8400_LR12LOP_SHIFT, 1, 0),
  483. SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER1,
  484. WM8400_LL12LOP_SHIFT, 1, 0),
  485. SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
  486. WM8400_LLOPGALOP_SHIFT, 1, 0),
  487. };
  488. /* RONMIX */
  489. static const struct snd_kcontrol_new wm8400_dapm_ronmix_controls[] = {
  490. SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
  491. WM8400_RROPGARON_SHIFT, 1, 0),
  492. SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER2,
  493. WM8400_RLOPGARON_SHIFT, 1, 0),
  494. SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8400_LINE_MIXER2,
  495. WM8400_ROPRON_SHIFT, 1, 0),
  496. };
  497. /* ROPMIX */
  498. static const struct snd_kcontrol_new wm8400_dapm_ropmix_controls[] = {
  499. SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER2,
  500. WM8400_RL12ROP_SHIFT, 1, 0),
  501. SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER2,
  502. WM8400_RR12ROP_SHIFT, 1, 0),
  503. SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
  504. WM8400_RROPGAROP_SHIFT, 1, 0),
  505. };
  506. /* OUT3MIX */
  507. static const struct snd_kcontrol_new wm8400_dapm_out3mix_controls[] = {
  508. SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
  509. WM8400_LI4O3_SHIFT, 1, 0),
  510. SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8400_OUT3_4_MIXER,
  511. WM8400_LPGAO3_SHIFT, 1, 0),
  512. };
  513. /* OUT4MIX */
  514. static const struct snd_kcontrol_new wm8400_dapm_out4mix_controls[] = {
  515. SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8400_OUT3_4_MIXER,
  516. WM8400_RPGAO4_SHIFT, 1, 0),
  517. SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
  518. WM8400_RI4O4_SHIFT, 1, 0),
  519. };
  520. /* SPKMIX */
  521. static const struct snd_kcontrol_new wm8400_dapm_spkmix_controls[] = {
  522. SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
  523. WM8400_LI2SPK_SHIFT, 1, 0),
  524. SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8400_SPEAKER_MIXER,
  525. WM8400_LB2SPK_SHIFT, 1, 0),
  526. SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8400_SPEAKER_MIXER,
  527. WM8400_LOPGASPK_SHIFT, 1, 0),
  528. SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8400_SPEAKER_MIXER,
  529. WM8400_LDSPK_SHIFT, 1, 0),
  530. SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8400_SPEAKER_MIXER,
  531. WM8400_RDSPK_SHIFT, 1, 0),
  532. SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8400_SPEAKER_MIXER,
  533. WM8400_ROPGASPK_SHIFT, 1, 0),
  534. SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8400_SPEAKER_MIXER,
  535. WM8400_RL12ROP_SHIFT, 1, 0),
  536. SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
  537. WM8400_RI2SPK_SHIFT, 1, 0),
  538. };
  539. static const struct snd_soc_dapm_widget wm8400_dapm_widgets[] = {
  540. /* Input Side */
  541. /* Input Lines */
  542. SND_SOC_DAPM_INPUT("LIN1"),
  543. SND_SOC_DAPM_INPUT("LIN2"),
  544. SND_SOC_DAPM_INPUT("LIN3"),
  545. SND_SOC_DAPM_INPUT("LIN4/RXN"),
  546. SND_SOC_DAPM_INPUT("RIN3"),
  547. SND_SOC_DAPM_INPUT("RIN4/RXP"),
  548. SND_SOC_DAPM_INPUT("RIN1"),
  549. SND_SOC_DAPM_INPUT("RIN2"),
  550. SND_SOC_DAPM_INPUT("Internal ADC Source"),
  551. /* DACs */
  552. SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8400_POWER_MANAGEMENT_2,
  553. WM8400_ADCL_ENA_SHIFT, 0),
  554. SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8400_POWER_MANAGEMENT_2,
  555. WM8400_ADCR_ENA_SHIFT, 0),
  556. /* Input PGAs */
  557. SND_SOC_DAPM_MIXER("LIN12 PGA", WM8400_POWER_MANAGEMENT_2,
  558. WM8400_LIN12_ENA_SHIFT,
  559. 0, &wm8400_dapm_lin12_pga_controls[0],
  560. ARRAY_SIZE(wm8400_dapm_lin12_pga_controls)),
  561. SND_SOC_DAPM_MIXER("LIN34 PGA", WM8400_POWER_MANAGEMENT_2,
  562. WM8400_LIN34_ENA_SHIFT,
  563. 0, &wm8400_dapm_lin34_pga_controls[0],
  564. ARRAY_SIZE(wm8400_dapm_lin34_pga_controls)),
  565. SND_SOC_DAPM_MIXER("RIN12 PGA", WM8400_POWER_MANAGEMENT_2,
  566. WM8400_RIN12_ENA_SHIFT,
  567. 0, &wm8400_dapm_rin12_pga_controls[0],
  568. ARRAY_SIZE(wm8400_dapm_rin12_pga_controls)),
  569. SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2,
  570. WM8400_RIN34_ENA_SHIFT,
  571. 0, &wm8400_dapm_rin34_pga_controls[0],
  572. ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)),
  573. /* INMIXL */
  574. SND_SOC_DAPM_MIXER_E("INMIXL", WM8400_INTDRIVBITS, WM8400_INMIXL_PWR, 0,
  575. &wm8400_dapm_inmixl_controls[0],
  576. ARRAY_SIZE(wm8400_dapm_inmixl_controls),
  577. inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  578. /* AINLMUX */
  579. SND_SOC_DAPM_MUX_E("AILNMUX", WM8400_INTDRIVBITS, WM8400_AINLMUX_PWR, 0,
  580. &wm8400_dapm_ainlmux_controls, inmixer_event,
  581. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  582. /* INMIXR */
  583. SND_SOC_DAPM_MIXER_E("INMIXR", WM8400_INTDRIVBITS, WM8400_INMIXR_PWR, 0,
  584. &wm8400_dapm_inmixr_controls[0],
  585. ARRAY_SIZE(wm8400_dapm_inmixr_controls),
  586. inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  587. /* AINRMUX */
  588. SND_SOC_DAPM_MUX_E("AIRNMUX", WM8400_INTDRIVBITS, WM8400_AINRMUX_PWR, 0,
  589. &wm8400_dapm_ainrmux_controls, inmixer_event,
  590. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  591. /* Output Side */
  592. /* DACs */
  593. SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8400_POWER_MANAGEMENT_3,
  594. WM8400_DACL_ENA_SHIFT, 0),
  595. SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8400_POWER_MANAGEMENT_3,
  596. WM8400_DACR_ENA_SHIFT, 0),
  597. /* LOMIX */
  598. SND_SOC_DAPM_MIXER_E("LOMIX", WM8400_POWER_MANAGEMENT_3,
  599. WM8400_LOMIX_ENA_SHIFT,
  600. 0, &wm8400_dapm_lomix_controls[0],
  601. ARRAY_SIZE(wm8400_dapm_lomix_controls),
  602. outmixer_event, SND_SOC_DAPM_PRE_REG),
  603. /* LONMIX */
  604. SND_SOC_DAPM_MIXER("LONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LON_ENA_SHIFT,
  605. 0, &wm8400_dapm_lonmix_controls[0],
  606. ARRAY_SIZE(wm8400_dapm_lonmix_controls)),
  607. /* LOPMIX */
  608. SND_SOC_DAPM_MIXER("LOPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LOP_ENA_SHIFT,
  609. 0, &wm8400_dapm_lopmix_controls[0],
  610. ARRAY_SIZE(wm8400_dapm_lopmix_controls)),
  611. /* OUT3MIX */
  612. SND_SOC_DAPM_MIXER("OUT3MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT3_ENA_SHIFT,
  613. 0, &wm8400_dapm_out3mix_controls[0],
  614. ARRAY_SIZE(wm8400_dapm_out3mix_controls)),
  615. /* SPKMIX */
  616. SND_SOC_DAPM_MIXER_E("SPKMIX", WM8400_POWER_MANAGEMENT_1, WM8400_SPK_ENA_SHIFT,
  617. 0, &wm8400_dapm_spkmix_controls[0],
  618. ARRAY_SIZE(wm8400_dapm_spkmix_controls), outmixer_event,
  619. SND_SOC_DAPM_PRE_REG),
  620. /* OUT4MIX */
  621. SND_SOC_DAPM_MIXER("OUT4MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT4_ENA_SHIFT,
  622. 0, &wm8400_dapm_out4mix_controls[0],
  623. ARRAY_SIZE(wm8400_dapm_out4mix_controls)),
  624. /* ROPMIX */
  625. SND_SOC_DAPM_MIXER("ROPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_ROP_ENA_SHIFT,
  626. 0, &wm8400_dapm_ropmix_controls[0],
  627. ARRAY_SIZE(wm8400_dapm_ropmix_controls)),
  628. /* RONMIX */
  629. SND_SOC_DAPM_MIXER("RONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_RON_ENA_SHIFT,
  630. 0, &wm8400_dapm_ronmix_controls[0],
  631. ARRAY_SIZE(wm8400_dapm_ronmix_controls)),
  632. /* ROMIX */
  633. SND_SOC_DAPM_MIXER_E("ROMIX", WM8400_POWER_MANAGEMENT_3,
  634. WM8400_ROMIX_ENA_SHIFT,
  635. 0, &wm8400_dapm_romix_controls[0],
  636. ARRAY_SIZE(wm8400_dapm_romix_controls),
  637. outmixer_event, SND_SOC_DAPM_PRE_REG),
  638. /* LOUT PGA */
  639. SND_SOC_DAPM_PGA("LOUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_LOUT_ENA_SHIFT,
  640. 0, NULL, 0),
  641. /* ROUT PGA */
  642. SND_SOC_DAPM_PGA("ROUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_ROUT_ENA_SHIFT,
  643. 0, NULL, 0),
  644. /* LOPGA */
  645. SND_SOC_DAPM_PGA("LOPGA", WM8400_POWER_MANAGEMENT_3, WM8400_LOPGA_ENA_SHIFT, 0,
  646. NULL, 0),
  647. /* ROPGA */
  648. SND_SOC_DAPM_PGA("ROPGA", WM8400_POWER_MANAGEMENT_3, WM8400_ROPGA_ENA_SHIFT, 0,
  649. NULL, 0),
  650. /* MICBIAS */
  651. SND_SOC_DAPM_MICBIAS("MICBIAS", WM8400_POWER_MANAGEMENT_1,
  652. WM8400_MIC1BIAS_ENA_SHIFT, 0),
  653. SND_SOC_DAPM_OUTPUT("LON"),
  654. SND_SOC_DAPM_OUTPUT("LOP"),
  655. SND_SOC_DAPM_OUTPUT("OUT3"),
  656. SND_SOC_DAPM_OUTPUT("LOUT"),
  657. SND_SOC_DAPM_OUTPUT("SPKN"),
  658. SND_SOC_DAPM_OUTPUT("SPKP"),
  659. SND_SOC_DAPM_OUTPUT("ROUT"),
  660. SND_SOC_DAPM_OUTPUT("OUT4"),
  661. SND_SOC_DAPM_OUTPUT("ROP"),
  662. SND_SOC_DAPM_OUTPUT("RON"),
  663. SND_SOC_DAPM_OUTPUT("Internal DAC Sink"),
  664. };
  665. static const struct snd_soc_dapm_route audio_map[] = {
  666. /* Make DACs turn on when playing even if not mixed into any outputs */
  667. {"Internal DAC Sink", NULL, "Left DAC"},
  668. {"Internal DAC Sink", NULL, "Right DAC"},
  669. /* Make ADCs turn on when recording
  670. * even if not mixed from any inputs */
  671. {"Left ADC", NULL, "Internal ADC Source"},
  672. {"Right ADC", NULL, "Internal ADC Source"},
  673. /* Input Side */
  674. /* LIN12 PGA */
  675. {"LIN12 PGA", "LIN1 Switch", "LIN1"},
  676. {"LIN12 PGA", "LIN2 Switch", "LIN2"},
  677. /* LIN34 PGA */
  678. {"LIN34 PGA", "LIN3 Switch", "LIN3"},
  679. {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"},
  680. /* INMIXL */
  681. {"INMIXL", "Record Left Volume", "LOMIX"},
  682. {"INMIXL", "LIN2 Volume", "LIN2"},
  683. {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
  684. {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
  685. /* AILNMUX */
  686. {"AILNMUX", "INMIXL Mix", "INMIXL"},
  687. {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"},
  688. {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"},
  689. {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"},
  690. {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"},
  691. /* ADC */
  692. {"Left ADC", NULL, "AILNMUX"},
  693. /* RIN12 PGA */
  694. {"RIN12 PGA", "RIN1 Switch", "RIN1"},
  695. {"RIN12 PGA", "RIN2 Switch", "RIN2"},
  696. /* RIN34 PGA */
  697. {"RIN34 PGA", "RIN3 Switch", "RIN3"},
  698. {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"},
  699. /* INMIXL */
  700. {"INMIXR", "Record Right Volume", "ROMIX"},
  701. {"INMIXR", "RIN2 Volume", "RIN2"},
  702. {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
  703. {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
  704. /* AIRNMUX */
  705. {"AIRNMUX", "INMIXR Mix", "INMIXR"},
  706. {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"},
  707. {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"},
  708. {"AIRNMUX", "RXVOICE Mix", "LIN4/RXN"},
  709. {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"},
  710. /* ADC */
  711. {"Right ADC", NULL, "AIRNMUX"},
  712. /* LOMIX */
  713. {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"},
  714. {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"},
  715. {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
  716. {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
  717. {"LOMIX", "LOMIX Right ADC Bypass Switch", "AIRNMUX"},
  718. {"LOMIX", "LOMIX Left ADC Bypass Switch", "AILNMUX"},
  719. {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"},
  720. /* ROMIX */
  721. {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"},
  722. {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"},
  723. {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
  724. {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
  725. {"ROMIX", "ROMIX Right ADC Bypass Switch", "AIRNMUX"},
  726. {"ROMIX", "ROMIX Left ADC Bypass Switch", "AILNMUX"},
  727. {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"},
  728. /* SPKMIX */
  729. {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"},
  730. {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"},
  731. {"SPKMIX", "SPKMIX LADC Bypass Switch", "AILNMUX"},
  732. {"SPKMIX", "SPKMIX RADC Bypass Switch", "AIRNMUX"},
  733. {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"},
  734. {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"},
  735. {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"},
  736. {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"},
  737. /* LONMIX */
  738. {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"},
  739. {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"},
  740. {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"},
  741. /* LOPMIX */
  742. {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"},
  743. {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"},
  744. {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"},
  745. /* OUT3MIX */
  746. {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"},
  747. {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"},
  748. /* OUT4MIX */
  749. {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"},
  750. {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"},
  751. /* RONMIX */
  752. {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"},
  753. {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"},
  754. {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"},
  755. /* ROPMIX */
  756. {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"},
  757. {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"},
  758. {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"},
  759. /* Out Mixer PGAs */
  760. {"LOPGA", NULL, "LOMIX"},
  761. {"ROPGA", NULL, "ROMIX"},
  762. {"LOUT PGA", NULL, "LOMIX"},
  763. {"ROUT PGA", NULL, "ROMIX"},
  764. /* Output Pins */
  765. {"LON", NULL, "LONMIX"},
  766. {"LOP", NULL, "LOPMIX"},
  767. {"OUT3", NULL, "OUT3MIX"},
  768. {"LOUT", NULL, "LOUT PGA"},
  769. {"SPKN", NULL, "SPKMIX"},
  770. {"ROUT", NULL, "ROUT PGA"},
  771. {"OUT4", NULL, "OUT4MIX"},
  772. {"ROP", NULL, "ROPMIX"},
  773. {"RON", NULL, "RONMIX"},
  774. };
  775. static int wm8400_add_widgets(struct snd_soc_codec *codec)
  776. {
  777. struct snd_soc_dapm_context *dapm = &codec->dapm;
  778. snd_soc_dapm_new_controls(dapm, wm8400_dapm_widgets,
  779. ARRAY_SIZE(wm8400_dapm_widgets));
  780. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  781. return 0;
  782. }
  783. /*
  784. * Clock after FLL and dividers
  785. */
  786. static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  787. int clk_id, unsigned int freq, int dir)
  788. {
  789. struct snd_soc_codec *codec = codec_dai->codec;
  790. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  791. wm8400->sysclk = freq;
  792. return 0;
  793. }
  794. struct fll_factors {
  795. u16 n;
  796. u16 k;
  797. u16 outdiv;
  798. u16 fratio;
  799. u16 freq_ref;
  800. };
  801. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  802. static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors,
  803. unsigned int Fref, unsigned int Fout)
  804. {
  805. u64 Kpart;
  806. unsigned int K, Nmod, target;
  807. factors->outdiv = 2;
  808. while (Fout * factors->outdiv < 90000000 ||
  809. Fout * factors->outdiv > 100000000) {
  810. factors->outdiv *= 2;
  811. if (factors->outdiv > 32) {
  812. dev_err(wm8400->wm8400->dev,
  813. "Unsupported FLL output frequency %uHz\n",
  814. Fout);
  815. return -EINVAL;
  816. }
  817. }
  818. target = Fout * factors->outdiv;
  819. factors->outdiv = factors->outdiv >> 2;
  820. if (Fref < 48000)
  821. factors->freq_ref = 1;
  822. else
  823. factors->freq_ref = 0;
  824. if (Fref < 1000000)
  825. factors->fratio = 9;
  826. else
  827. factors->fratio = 0;
  828. /* Ensure we have a fractional part */
  829. do {
  830. if (Fref < 1000000)
  831. factors->fratio--;
  832. else
  833. factors->fratio++;
  834. if (factors->fratio < 1 || factors->fratio > 8) {
  835. dev_err(wm8400->wm8400->dev,
  836. "Unable to calculate FRATIO\n");
  837. return -EINVAL;
  838. }
  839. factors->n = target / (Fref * factors->fratio);
  840. Nmod = target % (Fref * factors->fratio);
  841. } while (Nmod == 0);
  842. /* Calculate fractional part - scale up so we can round. */
  843. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  844. do_div(Kpart, (Fref * factors->fratio));
  845. K = Kpart & 0xFFFFFFFF;
  846. if ((K % 10) >= 5)
  847. K += 5;
  848. /* Move down to proper range now rounding is done */
  849. factors->k = K / 10;
  850. dev_dbg(wm8400->wm8400->dev,
  851. "FLL: Fref=%u Fout=%u N=%x K=%x, FRATIO=%x OUTDIV=%x\n",
  852. Fref, Fout,
  853. factors->n, factors->k, factors->fratio, factors->outdiv);
  854. return 0;
  855. }
  856. static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
  857. int source, unsigned int freq_in,
  858. unsigned int freq_out)
  859. {
  860. struct snd_soc_codec *codec = codec_dai->codec;
  861. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  862. struct fll_factors factors;
  863. int ret;
  864. u16 reg;
  865. if (freq_in == wm8400->fll_in && freq_out == wm8400->fll_out)
  866. return 0;
  867. if (freq_out) {
  868. ret = fll_factors(wm8400, &factors, freq_in, freq_out);
  869. if (ret != 0)
  870. return ret;
  871. } else {
  872. /* Bodge GCC 4.4.0 uninitialised variable warning - it
  873. * doesn't seem capable of working out that we exit if
  874. * freq_out is 0 before any of the uses. */
  875. memset(&factors, 0, sizeof(factors));
  876. }
  877. wm8400->fll_out = freq_out;
  878. wm8400->fll_in = freq_in;
  879. /* We *must* disable the FLL before any changes */
  880. reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_2);
  881. reg &= ~WM8400_FLL_ENA;
  882. wm8400_write(codec, WM8400_POWER_MANAGEMENT_2, reg);
  883. reg = wm8400_read(codec, WM8400_FLL_CONTROL_1);
  884. reg &= ~WM8400_FLL_OSC_ENA;
  885. wm8400_write(codec, WM8400_FLL_CONTROL_1, reg);
  886. if (!freq_out)
  887. return 0;
  888. reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK);
  889. reg |= WM8400_FLL_FRAC | factors.fratio;
  890. reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT;
  891. wm8400_write(codec, WM8400_FLL_CONTROL_1, reg);
  892. wm8400_write(codec, WM8400_FLL_CONTROL_2, factors.k);
  893. wm8400_write(codec, WM8400_FLL_CONTROL_3, factors.n);
  894. reg = wm8400_read(codec, WM8400_FLL_CONTROL_4);
  895. reg &= WM8400_FLL_OUTDIV_MASK;
  896. reg |= factors.outdiv;
  897. wm8400_write(codec, WM8400_FLL_CONTROL_4, reg);
  898. return 0;
  899. }
  900. /*
  901. * Sets ADC and Voice DAC format.
  902. */
  903. static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai,
  904. unsigned int fmt)
  905. {
  906. struct snd_soc_codec *codec = codec_dai->codec;
  907. u16 audio1, audio3;
  908. audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
  909. audio3 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_3);
  910. /* set master/slave audio interface */
  911. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  912. case SND_SOC_DAIFMT_CBS_CFS:
  913. audio3 &= ~WM8400_AIF_MSTR1;
  914. break;
  915. case SND_SOC_DAIFMT_CBM_CFM:
  916. audio3 |= WM8400_AIF_MSTR1;
  917. break;
  918. default:
  919. return -EINVAL;
  920. }
  921. audio1 &= ~WM8400_AIF_FMT_MASK;
  922. /* interface format */
  923. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  924. case SND_SOC_DAIFMT_I2S:
  925. audio1 |= WM8400_AIF_FMT_I2S;
  926. audio1 &= ~WM8400_AIF_LRCLK_INV;
  927. break;
  928. case SND_SOC_DAIFMT_RIGHT_J:
  929. audio1 |= WM8400_AIF_FMT_RIGHTJ;
  930. audio1 &= ~WM8400_AIF_LRCLK_INV;
  931. break;
  932. case SND_SOC_DAIFMT_LEFT_J:
  933. audio1 |= WM8400_AIF_FMT_LEFTJ;
  934. audio1 &= ~WM8400_AIF_LRCLK_INV;
  935. break;
  936. case SND_SOC_DAIFMT_DSP_A:
  937. audio1 |= WM8400_AIF_FMT_DSP;
  938. audio1 &= ~WM8400_AIF_LRCLK_INV;
  939. break;
  940. case SND_SOC_DAIFMT_DSP_B:
  941. audio1 |= WM8400_AIF_FMT_DSP | WM8400_AIF_LRCLK_INV;
  942. break;
  943. default:
  944. return -EINVAL;
  945. }
  946. wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
  947. wm8400_write(codec, WM8400_AUDIO_INTERFACE_3, audio3);
  948. return 0;
  949. }
  950. static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
  951. int div_id, int div)
  952. {
  953. struct snd_soc_codec *codec = codec_dai->codec;
  954. u16 reg;
  955. switch (div_id) {
  956. case WM8400_MCLK_DIV:
  957. reg = wm8400_read(codec, WM8400_CLOCKING_2) &
  958. ~WM8400_MCLK_DIV_MASK;
  959. wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
  960. break;
  961. case WM8400_DACCLK_DIV:
  962. reg = wm8400_read(codec, WM8400_CLOCKING_2) &
  963. ~WM8400_DAC_CLKDIV_MASK;
  964. wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
  965. break;
  966. case WM8400_ADCCLK_DIV:
  967. reg = wm8400_read(codec, WM8400_CLOCKING_2) &
  968. ~WM8400_ADC_CLKDIV_MASK;
  969. wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
  970. break;
  971. case WM8400_BCLK_DIV:
  972. reg = wm8400_read(codec, WM8400_CLOCKING_1) &
  973. ~WM8400_BCLK_DIV_MASK;
  974. wm8400_write(codec, WM8400_CLOCKING_1, reg | div);
  975. break;
  976. default:
  977. return -EINVAL;
  978. }
  979. return 0;
  980. }
  981. /*
  982. * Set PCM DAI bit size and sample rate.
  983. */
  984. static int wm8400_hw_params(struct snd_pcm_substream *substream,
  985. struct snd_pcm_hw_params *params,
  986. struct snd_soc_dai *dai)
  987. {
  988. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  989. struct snd_soc_codec *codec = rtd->codec;
  990. u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
  991. audio1 &= ~WM8400_AIF_WL_MASK;
  992. /* bit size */
  993. switch (params_format(params)) {
  994. case SNDRV_PCM_FORMAT_S16_LE:
  995. break;
  996. case SNDRV_PCM_FORMAT_S20_3LE:
  997. audio1 |= WM8400_AIF_WL_20BITS;
  998. break;
  999. case SNDRV_PCM_FORMAT_S24_LE:
  1000. audio1 |= WM8400_AIF_WL_24BITS;
  1001. break;
  1002. case SNDRV_PCM_FORMAT_S32_LE:
  1003. audio1 |= WM8400_AIF_WL_32BITS;
  1004. break;
  1005. }
  1006. wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
  1007. return 0;
  1008. }
  1009. static int wm8400_mute(struct snd_soc_dai *dai, int mute)
  1010. {
  1011. struct snd_soc_codec *codec = dai->codec;
  1012. u16 val = wm8400_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE;
  1013. if (mute)
  1014. wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
  1015. else
  1016. wm8400_write(codec, WM8400_DAC_CTRL, val);
  1017. return 0;
  1018. }
  1019. /* TODO: set bias for best performance at standby */
  1020. static int wm8400_set_bias_level(struct snd_soc_codec *codec,
  1021. enum snd_soc_bias_level level)
  1022. {
  1023. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  1024. u16 val;
  1025. int ret;
  1026. switch (level) {
  1027. case SND_SOC_BIAS_ON:
  1028. break;
  1029. case SND_SOC_BIAS_PREPARE:
  1030. /* VMID=2*50k */
  1031. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) &
  1032. ~WM8400_VMID_MODE_MASK;
  1033. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2);
  1034. break;
  1035. case SND_SOC_BIAS_STANDBY:
  1036. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  1037. ret = regulator_bulk_enable(ARRAY_SIZE(power),
  1038. &power[0]);
  1039. if (ret != 0) {
  1040. dev_err(wm8400->wm8400->dev,
  1041. "Failed to enable regulators: %d\n",
  1042. ret);
  1043. return ret;
  1044. }
  1045. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1,
  1046. WM8400_CODEC_ENA | WM8400_SYSCLK_ENA);
  1047. /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */
  1048. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1049. WM8400_BUFDCOPEN | WM8400_POBCTRL);
  1050. msleep(50);
  1051. /* Enable VREF & VMID at 2x50k */
  1052. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1053. val |= 0x2 | WM8400_VREF_ENA;
  1054. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1055. /* Enable BUFIOEN */
  1056. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1057. WM8400_BUFDCOPEN | WM8400_POBCTRL |
  1058. WM8400_BUFIOEN);
  1059. /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
  1060. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN);
  1061. }
  1062. /* VMID=2*300k */
  1063. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) &
  1064. ~WM8400_VMID_MODE_MASK;
  1065. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4);
  1066. break;
  1067. case SND_SOC_BIAS_OFF:
  1068. /* Enable POBCTRL and SOFT_ST */
  1069. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1070. WM8400_POBCTRL | WM8400_BUFIOEN);
  1071. /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */
  1072. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1073. WM8400_BUFDCOPEN | WM8400_POBCTRL |
  1074. WM8400_BUFIOEN);
  1075. /* mute DAC */
  1076. val = wm8400_read(codec, WM8400_DAC_CTRL);
  1077. wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
  1078. /* Enable any disabled outputs */
  1079. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1080. val |= WM8400_SPK_ENA | WM8400_OUT3_ENA |
  1081. WM8400_OUT4_ENA | WM8400_LOUT_ENA |
  1082. WM8400_ROUT_ENA;
  1083. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1084. /* Disable VMID */
  1085. val &= ~WM8400_VMID_MODE_MASK;
  1086. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1087. msleep(300);
  1088. /* Enable all output discharge bits */
  1089. wm8400_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE |
  1090. WM8400_DIS_RLINE | WM8400_DIS_OUT3 |
  1091. WM8400_DIS_OUT4 | WM8400_DIS_LOUT |
  1092. WM8400_DIS_ROUT);
  1093. /* Disable VREF */
  1094. val &= ~WM8400_VREF_ENA;
  1095. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1096. /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
  1097. wm8400_write(codec, WM8400_ANTIPOP2, 0x0);
  1098. ret = regulator_bulk_disable(ARRAY_SIZE(power),
  1099. &power[0]);
  1100. if (ret != 0)
  1101. return ret;
  1102. break;
  1103. }
  1104. codec->dapm.bias_level = level;
  1105. return 0;
  1106. }
  1107. #define WM8400_RATES SNDRV_PCM_RATE_8000_96000
  1108. #define WM8400_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1109. SNDRV_PCM_FMTBIT_S24_LE)
  1110. static struct snd_soc_dai_ops wm8400_dai_ops = {
  1111. .hw_params = wm8400_hw_params,
  1112. .digital_mute = wm8400_mute,
  1113. .set_fmt = wm8400_set_dai_fmt,
  1114. .set_clkdiv = wm8400_set_dai_clkdiv,
  1115. .set_sysclk = wm8400_set_dai_sysclk,
  1116. .set_pll = wm8400_set_dai_pll,
  1117. };
  1118. /*
  1119. * The WM8400 supports 2 different and mutually exclusive DAI
  1120. * configurations.
  1121. *
  1122. * 1. ADC/DAC on Primary Interface
  1123. * 2. ADC on Primary Interface/DAC on secondary
  1124. */
  1125. static struct snd_soc_dai_driver wm8400_dai = {
  1126. /* ADC/DAC on primary */
  1127. .name = "wm8400-hifi",
  1128. .playback = {
  1129. .stream_name = "Playback",
  1130. .channels_min = 1,
  1131. .channels_max = 2,
  1132. .rates = WM8400_RATES,
  1133. .formats = WM8400_FORMATS,
  1134. },
  1135. .capture = {
  1136. .stream_name = "Capture",
  1137. .channels_min = 1,
  1138. .channels_max = 2,
  1139. .rates = WM8400_RATES,
  1140. .formats = WM8400_FORMATS,
  1141. },
  1142. .ops = &wm8400_dai_ops,
  1143. };
  1144. static int wm8400_suspend(struct snd_soc_codec *codec, pm_message_t state)
  1145. {
  1146. wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1147. return 0;
  1148. }
  1149. static int wm8400_resume(struct snd_soc_codec *codec)
  1150. {
  1151. wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1152. return 0;
  1153. }
  1154. static void wm8400_probe_deferred(struct work_struct *work)
  1155. {
  1156. struct wm8400_priv *priv = container_of(work, struct wm8400_priv,
  1157. work);
  1158. struct snd_soc_codec *codec = priv->codec;
  1159. /* charge output caps */
  1160. wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1161. }
  1162. static int wm8400_codec_probe(struct snd_soc_codec *codec)
  1163. {
  1164. struct wm8400 *wm8400 = dev_get_platdata(codec->dev);
  1165. struct wm8400_priv *priv;
  1166. int ret;
  1167. u16 reg;
  1168. priv = kzalloc(sizeof(struct wm8400_priv), GFP_KERNEL);
  1169. if (priv == NULL)
  1170. return -ENOMEM;
  1171. snd_soc_codec_set_drvdata(codec, priv);
  1172. codec->control_data = priv->wm8400 = wm8400;
  1173. priv->codec = codec;
  1174. ret = regulator_bulk_get(wm8400->dev,
  1175. ARRAY_SIZE(power), &power[0]);
  1176. if (ret != 0) {
  1177. dev_err(codec->dev, "Failed to get regulators: %d\n", ret);
  1178. goto err;
  1179. }
  1180. INIT_WORK(&priv->work, wm8400_probe_deferred);
  1181. wm8400_codec_reset(codec);
  1182. reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1183. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA);
  1184. /* Latch volume update bits */
  1185. reg = wm8400_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME);
  1186. wm8400_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
  1187. reg & WM8400_IPVU);
  1188. reg = wm8400_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME);
  1189. wm8400_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
  1190. reg & WM8400_IPVU);
  1191. wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
  1192. wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
  1193. if (!schedule_work(&priv->work)) {
  1194. ret = -EINVAL;
  1195. goto err_regulator;
  1196. }
  1197. wm8400_add_controls(codec);
  1198. wm8400_add_widgets(codec);
  1199. return 0;
  1200. err_regulator:
  1201. regulator_bulk_free(ARRAY_SIZE(power), power);
  1202. err:
  1203. kfree(priv);
  1204. return ret;
  1205. }
  1206. static int wm8400_codec_remove(struct snd_soc_codec *codec)
  1207. {
  1208. struct wm8400_priv *priv = snd_soc_codec_get_drvdata(codec);
  1209. u16 reg;
  1210. reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1211. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1,
  1212. reg & (~WM8400_CODEC_ENA));
  1213. regulator_bulk_free(ARRAY_SIZE(power), power);
  1214. kfree(priv);
  1215. return 0;
  1216. }
  1217. static struct snd_soc_codec_driver soc_codec_dev_wm8400 = {
  1218. .probe = wm8400_codec_probe,
  1219. .remove = wm8400_codec_remove,
  1220. .suspend = wm8400_suspend,
  1221. .resume = wm8400_resume,
  1222. .read = wm8400_read,
  1223. .write = wm8400_write,
  1224. .set_bias_level = wm8400_set_bias_level,
  1225. };
  1226. static int __devinit wm8400_probe(struct platform_device *pdev)
  1227. {
  1228. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8400,
  1229. &wm8400_dai, 1);
  1230. }
  1231. static int __devexit wm8400_remove(struct platform_device *pdev)
  1232. {
  1233. snd_soc_unregister_codec(&pdev->dev);
  1234. return 0;
  1235. }
  1236. static struct platform_driver wm8400_codec_driver = {
  1237. .driver = {
  1238. .name = "wm8400-codec",
  1239. .owner = THIS_MODULE,
  1240. },
  1241. .probe = wm8400_probe,
  1242. .remove = __devexit_p(wm8400_remove),
  1243. };
  1244. static __init int wm8400_init(void)
  1245. {
  1246. return platform_driver_register(&wm8400_codec_driver);
  1247. }
  1248. module_init(wm8400_init);
  1249. static __exit void wm8400_exit(void)
  1250. {
  1251. platform_driver_unregister(&wm8400_codec_driver);
  1252. }
  1253. module_exit(wm8400_exit);
  1254. MODULE_DESCRIPTION("ASoC WM8400 driver");
  1255. MODULE_AUTHOR("Mark Brown");
  1256. MODULE_LICENSE("GPL");
  1257. MODULE_ALIAS("platform:wm8400-codec");