wm8400.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  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. /*
  294. * _DAPM_ Controls
  295. */
  296. static int inmixer_event (struct snd_soc_dapm_widget *w,
  297. struct snd_kcontrol *kcontrol, int event)
  298. {
  299. u16 reg, fakepower;
  300. reg = wm8400_read(w->codec, WM8400_POWER_MANAGEMENT_2);
  301. fakepower = wm8400_read(w->codec, WM8400_INTDRIVBITS);
  302. if (fakepower & ((1 << WM8400_INMIXL_PWR) |
  303. (1 << WM8400_AINLMUX_PWR))) {
  304. reg |= WM8400_AINL_ENA;
  305. } else {
  306. reg &= ~WM8400_AINL_ENA;
  307. }
  308. if (fakepower & ((1 << WM8400_INMIXR_PWR) |
  309. (1 << WM8400_AINRMUX_PWR))) {
  310. reg |= WM8400_AINR_ENA;
  311. } else {
  312. reg &= ~WM8400_AINR_ENA;
  313. }
  314. wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg);
  315. return 0;
  316. }
  317. static int outmixer_event (struct snd_soc_dapm_widget *w,
  318. struct snd_kcontrol * kcontrol, int event)
  319. {
  320. struct soc_mixer_control *mc =
  321. (struct soc_mixer_control *)kcontrol->private_value;
  322. u32 reg_shift = mc->shift;
  323. int ret = 0;
  324. u16 reg;
  325. switch (reg_shift) {
  326. case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) :
  327. reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER1);
  328. if (reg & WM8400_LDLO) {
  329. printk(KERN_WARNING
  330. "Cannot set as Output Mixer 1 LDLO Set\n");
  331. ret = -1;
  332. }
  333. break;
  334. case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8):
  335. reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER2);
  336. if (reg & WM8400_RDRO) {
  337. printk(KERN_WARNING
  338. "Cannot set as Output Mixer 2 RDRO Set\n");
  339. ret = -1;
  340. }
  341. break;
  342. case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8):
  343. reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER);
  344. if (reg & WM8400_LDSPK) {
  345. printk(KERN_WARNING
  346. "Cannot set as Speaker Mixer LDSPK Set\n");
  347. ret = -1;
  348. }
  349. break;
  350. case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8):
  351. reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER);
  352. if (reg & WM8400_RDSPK) {
  353. printk(KERN_WARNING
  354. "Cannot set as Speaker Mixer RDSPK Set\n");
  355. ret = -1;
  356. }
  357. break;
  358. }
  359. return ret;
  360. }
  361. /* INMIX dB values */
  362. static const unsigned int in_mix_tlv[] = {
  363. TLV_DB_RANGE_HEAD(1),
  364. 0,7, TLV_DB_SCALE_ITEM(-1200, 600, 0),
  365. };
  366. /* Left In PGA Connections */
  367. static const struct snd_kcontrol_new wm8400_dapm_lin12_pga_controls[] = {
  368. SOC_DAPM_SINGLE("LIN1 Switch", WM8400_INPUT_MIXER2, WM8400_LMN1_SHIFT, 1, 0),
  369. SOC_DAPM_SINGLE("LIN2 Switch", WM8400_INPUT_MIXER2, WM8400_LMP2_SHIFT, 1, 0),
  370. };
  371. static const struct snd_kcontrol_new wm8400_dapm_lin34_pga_controls[] = {
  372. SOC_DAPM_SINGLE("LIN3 Switch", WM8400_INPUT_MIXER2, WM8400_LMN3_SHIFT, 1, 0),
  373. SOC_DAPM_SINGLE("LIN4 Switch", WM8400_INPUT_MIXER2, WM8400_LMP4_SHIFT, 1, 0),
  374. };
  375. /* Right In PGA Connections */
  376. static const struct snd_kcontrol_new wm8400_dapm_rin12_pga_controls[] = {
  377. SOC_DAPM_SINGLE("RIN1 Switch", WM8400_INPUT_MIXER2, WM8400_RMN1_SHIFT, 1, 0),
  378. SOC_DAPM_SINGLE("RIN2 Switch", WM8400_INPUT_MIXER2, WM8400_RMP2_SHIFT, 1, 0),
  379. };
  380. static const struct snd_kcontrol_new wm8400_dapm_rin34_pga_controls[] = {
  381. SOC_DAPM_SINGLE("RIN3 Switch", WM8400_INPUT_MIXER2, WM8400_RMN3_SHIFT, 1, 0),
  382. SOC_DAPM_SINGLE("RIN4 Switch", WM8400_INPUT_MIXER2, WM8400_RMP4_SHIFT, 1, 0),
  383. };
  384. /* INMIXL */
  385. static const struct snd_kcontrol_new wm8400_dapm_inmixl_controls[] = {
  386. SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8400_INPUT_MIXER3,
  387. WM8400_LDBVOL_SHIFT, WM8400_LDBVOL_MASK, 0, in_mix_tlv),
  388. SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8400_INPUT_MIXER5, WM8400_LI2BVOL_SHIFT,
  389. 7, 0, in_mix_tlv),
  390. SOC_DAPM_SINGLE("LINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
  391. 1, 0),
  392. SOC_DAPM_SINGLE("LINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
  393. 1, 0),
  394. };
  395. /* INMIXR */
  396. static const struct snd_kcontrol_new wm8400_dapm_inmixr_controls[] = {
  397. SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8400_INPUT_MIXER4,
  398. WM8400_RDBVOL_SHIFT, WM8400_RDBVOL_MASK, 0, in_mix_tlv),
  399. SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8400_INPUT_MIXER6, WM8400_RI2BVOL_SHIFT,
  400. 7, 0, in_mix_tlv),
  401. SOC_DAPM_SINGLE("RINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
  402. 1, 0),
  403. SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
  404. 1, 0),
  405. };
  406. /* AINLMUX */
  407. static const char *wm8400_ainlmux[] =
  408. {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
  409. static const struct soc_enum wm8400_ainlmux_enum =
  410. SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINLMODE_SHIFT,
  411. ARRAY_SIZE(wm8400_ainlmux), wm8400_ainlmux);
  412. static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls =
  413. SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum);
  414. /* DIFFINL */
  415. /* AINRMUX */
  416. static const char *wm8400_ainrmux[] =
  417. {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
  418. static const struct soc_enum wm8400_ainrmux_enum =
  419. SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINRMODE_SHIFT,
  420. ARRAY_SIZE(wm8400_ainrmux), wm8400_ainrmux);
  421. static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls =
  422. SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum);
  423. /* RXVOICE */
  424. static const struct snd_kcontrol_new wm8400_dapm_rxvoice_controls[] = {
  425. SOC_DAPM_SINGLE_TLV("LIN4/RXN", WM8400_INPUT_MIXER5, WM8400_LR4BVOL_SHIFT,
  426. WM8400_LR4BVOL_MASK, 0, in_mix_tlv),
  427. SOC_DAPM_SINGLE_TLV("RIN4/RXP", WM8400_INPUT_MIXER6, WM8400_RL4BVOL_SHIFT,
  428. WM8400_RL4BVOL_MASK, 0, in_mix_tlv),
  429. };
  430. /* LOMIX */
  431. static const struct snd_kcontrol_new wm8400_dapm_lomix_controls[] = {
  432. SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
  433. WM8400_LRBLO_SHIFT, 1, 0),
  434. SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
  435. WM8400_LLBLO_SHIFT, 1, 0),
  436. SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
  437. WM8400_LRI3LO_SHIFT, 1, 0),
  438. SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
  439. WM8400_LLI3LO_SHIFT, 1, 0),
  440. SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
  441. WM8400_LR12LO_SHIFT, 1, 0),
  442. SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
  443. WM8400_LL12LO_SHIFT, 1, 0),
  444. SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8400_OUTPUT_MIXER1,
  445. WM8400_LDLO_SHIFT, 1, 0),
  446. };
  447. /* ROMIX */
  448. static const struct snd_kcontrol_new wm8400_dapm_romix_controls[] = {
  449. SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
  450. WM8400_RLBRO_SHIFT, 1, 0),
  451. SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
  452. WM8400_RRBRO_SHIFT, 1, 0),
  453. SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
  454. WM8400_RLI3RO_SHIFT, 1, 0),
  455. SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
  456. WM8400_RRI3RO_SHIFT, 1, 0),
  457. SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
  458. WM8400_RL12RO_SHIFT, 1, 0),
  459. SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
  460. WM8400_RR12RO_SHIFT, 1, 0),
  461. SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8400_OUTPUT_MIXER2,
  462. WM8400_RDRO_SHIFT, 1, 0),
  463. };
  464. /* LONMIX */
  465. static const struct snd_kcontrol_new wm8400_dapm_lonmix_controls[] = {
  466. SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
  467. WM8400_LLOPGALON_SHIFT, 1, 0),
  468. SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER1,
  469. WM8400_LROPGALON_SHIFT, 1, 0),
  470. SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8400_LINE_MIXER1,
  471. WM8400_LOPLON_SHIFT, 1, 0),
  472. };
  473. /* LOPMIX */
  474. static const struct snd_kcontrol_new wm8400_dapm_lopmix_controls[] = {
  475. SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER1,
  476. WM8400_LR12LOP_SHIFT, 1, 0),
  477. SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER1,
  478. WM8400_LL12LOP_SHIFT, 1, 0),
  479. SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
  480. WM8400_LLOPGALOP_SHIFT, 1, 0),
  481. };
  482. /* RONMIX */
  483. static const struct snd_kcontrol_new wm8400_dapm_ronmix_controls[] = {
  484. SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
  485. WM8400_RROPGARON_SHIFT, 1, 0),
  486. SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER2,
  487. WM8400_RLOPGARON_SHIFT, 1, 0),
  488. SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8400_LINE_MIXER2,
  489. WM8400_ROPRON_SHIFT, 1, 0),
  490. };
  491. /* ROPMIX */
  492. static const struct snd_kcontrol_new wm8400_dapm_ropmix_controls[] = {
  493. SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER2,
  494. WM8400_RL12ROP_SHIFT, 1, 0),
  495. SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER2,
  496. WM8400_RR12ROP_SHIFT, 1, 0),
  497. SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
  498. WM8400_RROPGAROP_SHIFT, 1, 0),
  499. };
  500. /* OUT3MIX */
  501. static const struct snd_kcontrol_new wm8400_dapm_out3mix_controls[] = {
  502. SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
  503. WM8400_LI4O3_SHIFT, 1, 0),
  504. SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8400_OUT3_4_MIXER,
  505. WM8400_LPGAO3_SHIFT, 1, 0),
  506. };
  507. /* OUT4MIX */
  508. static const struct snd_kcontrol_new wm8400_dapm_out4mix_controls[] = {
  509. SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8400_OUT3_4_MIXER,
  510. WM8400_RPGAO4_SHIFT, 1, 0),
  511. SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
  512. WM8400_RI4O4_SHIFT, 1, 0),
  513. };
  514. /* SPKMIX */
  515. static const struct snd_kcontrol_new wm8400_dapm_spkmix_controls[] = {
  516. SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
  517. WM8400_LI2SPK_SHIFT, 1, 0),
  518. SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8400_SPEAKER_MIXER,
  519. WM8400_LB2SPK_SHIFT, 1, 0),
  520. SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8400_SPEAKER_MIXER,
  521. WM8400_LOPGASPK_SHIFT, 1, 0),
  522. SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8400_SPEAKER_MIXER,
  523. WM8400_LDSPK_SHIFT, 1, 0),
  524. SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8400_SPEAKER_MIXER,
  525. WM8400_RDSPK_SHIFT, 1, 0),
  526. SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8400_SPEAKER_MIXER,
  527. WM8400_ROPGASPK_SHIFT, 1, 0),
  528. SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8400_SPEAKER_MIXER,
  529. WM8400_RL12ROP_SHIFT, 1, 0),
  530. SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
  531. WM8400_RI2SPK_SHIFT, 1, 0),
  532. };
  533. static const struct snd_soc_dapm_widget wm8400_dapm_widgets[] = {
  534. /* Input Side */
  535. /* Input Lines */
  536. SND_SOC_DAPM_INPUT("LIN1"),
  537. SND_SOC_DAPM_INPUT("LIN2"),
  538. SND_SOC_DAPM_INPUT("LIN3"),
  539. SND_SOC_DAPM_INPUT("LIN4/RXN"),
  540. SND_SOC_DAPM_INPUT("RIN3"),
  541. SND_SOC_DAPM_INPUT("RIN4/RXP"),
  542. SND_SOC_DAPM_INPUT("RIN1"),
  543. SND_SOC_DAPM_INPUT("RIN2"),
  544. SND_SOC_DAPM_INPUT("Internal ADC Source"),
  545. /* DACs */
  546. SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8400_POWER_MANAGEMENT_2,
  547. WM8400_ADCL_ENA_SHIFT, 0),
  548. SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8400_POWER_MANAGEMENT_2,
  549. WM8400_ADCR_ENA_SHIFT, 0),
  550. /* Input PGAs */
  551. SND_SOC_DAPM_MIXER("LIN12 PGA", WM8400_POWER_MANAGEMENT_2,
  552. WM8400_LIN12_ENA_SHIFT,
  553. 0, &wm8400_dapm_lin12_pga_controls[0],
  554. ARRAY_SIZE(wm8400_dapm_lin12_pga_controls)),
  555. SND_SOC_DAPM_MIXER("LIN34 PGA", WM8400_POWER_MANAGEMENT_2,
  556. WM8400_LIN34_ENA_SHIFT,
  557. 0, &wm8400_dapm_lin34_pga_controls[0],
  558. ARRAY_SIZE(wm8400_dapm_lin34_pga_controls)),
  559. SND_SOC_DAPM_MIXER("RIN12 PGA", WM8400_POWER_MANAGEMENT_2,
  560. WM8400_RIN12_ENA_SHIFT,
  561. 0, &wm8400_dapm_rin12_pga_controls[0],
  562. ARRAY_SIZE(wm8400_dapm_rin12_pga_controls)),
  563. SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2,
  564. WM8400_RIN34_ENA_SHIFT,
  565. 0, &wm8400_dapm_rin34_pga_controls[0],
  566. ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)),
  567. /* INMIXL */
  568. SND_SOC_DAPM_MIXER_E("INMIXL", WM8400_INTDRIVBITS, WM8400_INMIXL_PWR, 0,
  569. &wm8400_dapm_inmixl_controls[0],
  570. ARRAY_SIZE(wm8400_dapm_inmixl_controls),
  571. inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  572. /* AINLMUX */
  573. SND_SOC_DAPM_MUX_E("AILNMUX", WM8400_INTDRIVBITS, WM8400_AINLMUX_PWR, 0,
  574. &wm8400_dapm_ainlmux_controls, inmixer_event,
  575. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  576. /* INMIXR */
  577. SND_SOC_DAPM_MIXER_E("INMIXR", WM8400_INTDRIVBITS, WM8400_INMIXR_PWR, 0,
  578. &wm8400_dapm_inmixr_controls[0],
  579. ARRAY_SIZE(wm8400_dapm_inmixr_controls),
  580. inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  581. /* AINRMUX */
  582. SND_SOC_DAPM_MUX_E("AIRNMUX", WM8400_INTDRIVBITS, WM8400_AINRMUX_PWR, 0,
  583. &wm8400_dapm_ainrmux_controls, inmixer_event,
  584. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  585. /* Output Side */
  586. /* DACs */
  587. SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8400_POWER_MANAGEMENT_3,
  588. WM8400_DACL_ENA_SHIFT, 0),
  589. SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8400_POWER_MANAGEMENT_3,
  590. WM8400_DACR_ENA_SHIFT, 0),
  591. /* LOMIX */
  592. SND_SOC_DAPM_MIXER_E("LOMIX", WM8400_POWER_MANAGEMENT_3,
  593. WM8400_LOMIX_ENA_SHIFT,
  594. 0, &wm8400_dapm_lomix_controls[0],
  595. ARRAY_SIZE(wm8400_dapm_lomix_controls),
  596. outmixer_event, SND_SOC_DAPM_PRE_REG),
  597. /* LONMIX */
  598. SND_SOC_DAPM_MIXER("LONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LON_ENA_SHIFT,
  599. 0, &wm8400_dapm_lonmix_controls[0],
  600. ARRAY_SIZE(wm8400_dapm_lonmix_controls)),
  601. /* LOPMIX */
  602. SND_SOC_DAPM_MIXER("LOPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LOP_ENA_SHIFT,
  603. 0, &wm8400_dapm_lopmix_controls[0],
  604. ARRAY_SIZE(wm8400_dapm_lopmix_controls)),
  605. /* OUT3MIX */
  606. SND_SOC_DAPM_MIXER("OUT3MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT3_ENA_SHIFT,
  607. 0, &wm8400_dapm_out3mix_controls[0],
  608. ARRAY_SIZE(wm8400_dapm_out3mix_controls)),
  609. /* SPKMIX */
  610. SND_SOC_DAPM_MIXER_E("SPKMIX", WM8400_POWER_MANAGEMENT_1, WM8400_SPK_ENA_SHIFT,
  611. 0, &wm8400_dapm_spkmix_controls[0],
  612. ARRAY_SIZE(wm8400_dapm_spkmix_controls), outmixer_event,
  613. SND_SOC_DAPM_PRE_REG),
  614. /* OUT4MIX */
  615. SND_SOC_DAPM_MIXER("OUT4MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT4_ENA_SHIFT,
  616. 0, &wm8400_dapm_out4mix_controls[0],
  617. ARRAY_SIZE(wm8400_dapm_out4mix_controls)),
  618. /* ROPMIX */
  619. SND_SOC_DAPM_MIXER("ROPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_ROP_ENA_SHIFT,
  620. 0, &wm8400_dapm_ropmix_controls[0],
  621. ARRAY_SIZE(wm8400_dapm_ropmix_controls)),
  622. /* RONMIX */
  623. SND_SOC_DAPM_MIXER("RONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_RON_ENA_SHIFT,
  624. 0, &wm8400_dapm_ronmix_controls[0],
  625. ARRAY_SIZE(wm8400_dapm_ronmix_controls)),
  626. /* ROMIX */
  627. SND_SOC_DAPM_MIXER_E("ROMIX", WM8400_POWER_MANAGEMENT_3,
  628. WM8400_ROMIX_ENA_SHIFT,
  629. 0, &wm8400_dapm_romix_controls[0],
  630. ARRAY_SIZE(wm8400_dapm_romix_controls),
  631. outmixer_event, SND_SOC_DAPM_PRE_REG),
  632. /* LOUT PGA */
  633. SND_SOC_DAPM_PGA("LOUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_LOUT_ENA_SHIFT,
  634. 0, NULL, 0),
  635. /* ROUT PGA */
  636. SND_SOC_DAPM_PGA("ROUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_ROUT_ENA_SHIFT,
  637. 0, NULL, 0),
  638. /* LOPGA */
  639. SND_SOC_DAPM_PGA("LOPGA", WM8400_POWER_MANAGEMENT_3, WM8400_LOPGA_ENA_SHIFT, 0,
  640. NULL, 0),
  641. /* ROPGA */
  642. SND_SOC_DAPM_PGA("ROPGA", WM8400_POWER_MANAGEMENT_3, WM8400_ROPGA_ENA_SHIFT, 0,
  643. NULL, 0),
  644. /* MICBIAS */
  645. SND_SOC_DAPM_SUPPLY("MICBIAS", WM8400_POWER_MANAGEMENT_1,
  646. WM8400_MIC1BIAS_ENA_SHIFT, 0, NULL, 0),
  647. SND_SOC_DAPM_OUTPUT("LON"),
  648. SND_SOC_DAPM_OUTPUT("LOP"),
  649. SND_SOC_DAPM_OUTPUT("OUT3"),
  650. SND_SOC_DAPM_OUTPUT("LOUT"),
  651. SND_SOC_DAPM_OUTPUT("SPKN"),
  652. SND_SOC_DAPM_OUTPUT("SPKP"),
  653. SND_SOC_DAPM_OUTPUT("ROUT"),
  654. SND_SOC_DAPM_OUTPUT("OUT4"),
  655. SND_SOC_DAPM_OUTPUT("ROP"),
  656. SND_SOC_DAPM_OUTPUT("RON"),
  657. SND_SOC_DAPM_OUTPUT("Internal DAC Sink"),
  658. };
  659. static const struct snd_soc_dapm_route wm8400_dapm_routes[] = {
  660. /* Make DACs turn on when playing even if not mixed into any outputs */
  661. {"Internal DAC Sink", NULL, "Left DAC"},
  662. {"Internal DAC Sink", NULL, "Right DAC"},
  663. /* Make ADCs turn on when recording
  664. * even if not mixed from any inputs */
  665. {"Left ADC", NULL, "Internal ADC Source"},
  666. {"Right ADC", NULL, "Internal ADC Source"},
  667. /* Input Side */
  668. /* LIN12 PGA */
  669. {"LIN12 PGA", "LIN1 Switch", "LIN1"},
  670. {"LIN12 PGA", "LIN2 Switch", "LIN2"},
  671. /* LIN34 PGA */
  672. {"LIN34 PGA", "LIN3 Switch", "LIN3"},
  673. {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"},
  674. /* INMIXL */
  675. {"INMIXL", "Record Left Volume", "LOMIX"},
  676. {"INMIXL", "LIN2 Volume", "LIN2"},
  677. {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
  678. {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
  679. /* AILNMUX */
  680. {"AILNMUX", "INMIXL Mix", "INMIXL"},
  681. {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"},
  682. {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"},
  683. {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"},
  684. {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"},
  685. /* ADC */
  686. {"Left ADC", NULL, "AILNMUX"},
  687. /* RIN12 PGA */
  688. {"RIN12 PGA", "RIN1 Switch", "RIN1"},
  689. {"RIN12 PGA", "RIN2 Switch", "RIN2"},
  690. /* RIN34 PGA */
  691. {"RIN34 PGA", "RIN3 Switch", "RIN3"},
  692. {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"},
  693. /* INMIXL */
  694. {"INMIXR", "Record Right Volume", "ROMIX"},
  695. {"INMIXR", "RIN2 Volume", "RIN2"},
  696. {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
  697. {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
  698. /* AIRNMUX */
  699. {"AIRNMUX", "INMIXR Mix", "INMIXR"},
  700. {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"},
  701. {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"},
  702. {"AIRNMUX", "RXVOICE Mix", "LIN4/RXN"},
  703. {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"},
  704. /* ADC */
  705. {"Right ADC", NULL, "AIRNMUX"},
  706. /* LOMIX */
  707. {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"},
  708. {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"},
  709. {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
  710. {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
  711. {"LOMIX", "LOMIX Right ADC Bypass Switch", "AIRNMUX"},
  712. {"LOMIX", "LOMIX Left ADC Bypass Switch", "AILNMUX"},
  713. {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"},
  714. /* ROMIX */
  715. {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"},
  716. {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"},
  717. {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
  718. {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
  719. {"ROMIX", "ROMIX Right ADC Bypass Switch", "AIRNMUX"},
  720. {"ROMIX", "ROMIX Left ADC Bypass Switch", "AILNMUX"},
  721. {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"},
  722. /* SPKMIX */
  723. {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"},
  724. {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"},
  725. {"SPKMIX", "SPKMIX LADC Bypass Switch", "AILNMUX"},
  726. {"SPKMIX", "SPKMIX RADC Bypass Switch", "AIRNMUX"},
  727. {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"},
  728. {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"},
  729. {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"},
  730. {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"},
  731. /* LONMIX */
  732. {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"},
  733. {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"},
  734. {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"},
  735. /* LOPMIX */
  736. {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"},
  737. {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"},
  738. {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"},
  739. /* OUT3MIX */
  740. {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"},
  741. {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"},
  742. /* OUT4MIX */
  743. {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"},
  744. {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"},
  745. /* RONMIX */
  746. {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"},
  747. {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"},
  748. {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"},
  749. /* ROPMIX */
  750. {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"},
  751. {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"},
  752. {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"},
  753. /* Out Mixer PGAs */
  754. {"LOPGA", NULL, "LOMIX"},
  755. {"ROPGA", NULL, "ROMIX"},
  756. {"LOUT PGA", NULL, "LOMIX"},
  757. {"ROUT PGA", NULL, "ROMIX"},
  758. /* Output Pins */
  759. {"LON", NULL, "LONMIX"},
  760. {"LOP", NULL, "LOPMIX"},
  761. {"OUT3", NULL, "OUT3MIX"},
  762. {"LOUT", NULL, "LOUT PGA"},
  763. {"SPKN", NULL, "SPKMIX"},
  764. {"ROUT", NULL, "ROUT PGA"},
  765. {"OUT4", NULL, "OUT4MIX"},
  766. {"ROP", NULL, "ROPMIX"},
  767. {"RON", NULL, "RONMIX"},
  768. };
  769. /*
  770. * Clock after FLL and dividers
  771. */
  772. static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  773. int clk_id, unsigned int freq, int dir)
  774. {
  775. struct snd_soc_codec *codec = codec_dai->codec;
  776. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  777. wm8400->sysclk = freq;
  778. return 0;
  779. }
  780. struct fll_factors {
  781. u16 n;
  782. u16 k;
  783. u16 outdiv;
  784. u16 fratio;
  785. u16 freq_ref;
  786. };
  787. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  788. static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors,
  789. unsigned int Fref, unsigned int Fout)
  790. {
  791. u64 Kpart;
  792. unsigned int K, Nmod, target;
  793. factors->outdiv = 2;
  794. while (Fout * factors->outdiv < 90000000 ||
  795. Fout * factors->outdiv > 100000000) {
  796. factors->outdiv *= 2;
  797. if (factors->outdiv > 32) {
  798. dev_err(wm8400->wm8400->dev,
  799. "Unsupported FLL output frequency %uHz\n",
  800. Fout);
  801. return -EINVAL;
  802. }
  803. }
  804. target = Fout * factors->outdiv;
  805. factors->outdiv = factors->outdiv >> 2;
  806. if (Fref < 48000)
  807. factors->freq_ref = 1;
  808. else
  809. factors->freq_ref = 0;
  810. if (Fref < 1000000)
  811. factors->fratio = 9;
  812. else
  813. factors->fratio = 0;
  814. /* Ensure we have a fractional part */
  815. do {
  816. if (Fref < 1000000)
  817. factors->fratio--;
  818. else
  819. factors->fratio++;
  820. if (factors->fratio < 1 || factors->fratio > 8) {
  821. dev_err(wm8400->wm8400->dev,
  822. "Unable to calculate FRATIO\n");
  823. return -EINVAL;
  824. }
  825. factors->n = target / (Fref * factors->fratio);
  826. Nmod = target % (Fref * factors->fratio);
  827. } while (Nmod == 0);
  828. /* Calculate fractional part - scale up so we can round. */
  829. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  830. do_div(Kpart, (Fref * factors->fratio));
  831. K = Kpart & 0xFFFFFFFF;
  832. if ((K % 10) >= 5)
  833. K += 5;
  834. /* Move down to proper range now rounding is done */
  835. factors->k = K / 10;
  836. dev_dbg(wm8400->wm8400->dev,
  837. "FLL: Fref=%u Fout=%u N=%x K=%x, FRATIO=%x OUTDIV=%x\n",
  838. Fref, Fout,
  839. factors->n, factors->k, factors->fratio, factors->outdiv);
  840. return 0;
  841. }
  842. static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
  843. int source, unsigned int freq_in,
  844. unsigned int freq_out)
  845. {
  846. struct snd_soc_codec *codec = codec_dai->codec;
  847. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  848. struct fll_factors factors;
  849. int ret;
  850. u16 reg;
  851. if (freq_in == wm8400->fll_in && freq_out == wm8400->fll_out)
  852. return 0;
  853. if (freq_out) {
  854. ret = fll_factors(wm8400, &factors, freq_in, freq_out);
  855. if (ret != 0)
  856. return ret;
  857. } else {
  858. /* Bodge GCC 4.4.0 uninitialised variable warning - it
  859. * doesn't seem capable of working out that we exit if
  860. * freq_out is 0 before any of the uses. */
  861. memset(&factors, 0, sizeof(factors));
  862. }
  863. wm8400->fll_out = freq_out;
  864. wm8400->fll_in = freq_in;
  865. /* We *must* disable the FLL before any changes */
  866. reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_2);
  867. reg &= ~WM8400_FLL_ENA;
  868. wm8400_write(codec, WM8400_POWER_MANAGEMENT_2, reg);
  869. reg = wm8400_read(codec, WM8400_FLL_CONTROL_1);
  870. reg &= ~WM8400_FLL_OSC_ENA;
  871. wm8400_write(codec, WM8400_FLL_CONTROL_1, reg);
  872. if (!freq_out)
  873. return 0;
  874. reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK);
  875. reg |= WM8400_FLL_FRAC | factors.fratio;
  876. reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT;
  877. wm8400_write(codec, WM8400_FLL_CONTROL_1, reg);
  878. wm8400_write(codec, WM8400_FLL_CONTROL_2, factors.k);
  879. wm8400_write(codec, WM8400_FLL_CONTROL_3, factors.n);
  880. reg = wm8400_read(codec, WM8400_FLL_CONTROL_4);
  881. reg &= ~WM8400_FLL_OUTDIV_MASK;
  882. reg |= factors.outdiv;
  883. wm8400_write(codec, WM8400_FLL_CONTROL_4, reg);
  884. return 0;
  885. }
  886. /*
  887. * Sets ADC and Voice DAC format.
  888. */
  889. static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai,
  890. unsigned int fmt)
  891. {
  892. struct snd_soc_codec *codec = codec_dai->codec;
  893. u16 audio1, audio3;
  894. audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
  895. audio3 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_3);
  896. /* set master/slave audio interface */
  897. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  898. case SND_SOC_DAIFMT_CBS_CFS:
  899. audio3 &= ~WM8400_AIF_MSTR1;
  900. break;
  901. case SND_SOC_DAIFMT_CBM_CFM:
  902. audio3 |= WM8400_AIF_MSTR1;
  903. break;
  904. default:
  905. return -EINVAL;
  906. }
  907. audio1 &= ~WM8400_AIF_FMT_MASK;
  908. /* interface format */
  909. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  910. case SND_SOC_DAIFMT_I2S:
  911. audio1 |= WM8400_AIF_FMT_I2S;
  912. audio1 &= ~WM8400_AIF_LRCLK_INV;
  913. break;
  914. case SND_SOC_DAIFMT_RIGHT_J:
  915. audio1 |= WM8400_AIF_FMT_RIGHTJ;
  916. audio1 &= ~WM8400_AIF_LRCLK_INV;
  917. break;
  918. case SND_SOC_DAIFMT_LEFT_J:
  919. audio1 |= WM8400_AIF_FMT_LEFTJ;
  920. audio1 &= ~WM8400_AIF_LRCLK_INV;
  921. break;
  922. case SND_SOC_DAIFMT_DSP_A:
  923. audio1 |= WM8400_AIF_FMT_DSP;
  924. audio1 &= ~WM8400_AIF_LRCLK_INV;
  925. break;
  926. case SND_SOC_DAIFMT_DSP_B:
  927. audio1 |= WM8400_AIF_FMT_DSP | WM8400_AIF_LRCLK_INV;
  928. break;
  929. default:
  930. return -EINVAL;
  931. }
  932. wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
  933. wm8400_write(codec, WM8400_AUDIO_INTERFACE_3, audio3);
  934. return 0;
  935. }
  936. static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
  937. int div_id, int div)
  938. {
  939. struct snd_soc_codec *codec = codec_dai->codec;
  940. u16 reg;
  941. switch (div_id) {
  942. case WM8400_MCLK_DIV:
  943. reg = wm8400_read(codec, WM8400_CLOCKING_2) &
  944. ~WM8400_MCLK_DIV_MASK;
  945. wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
  946. break;
  947. case WM8400_DACCLK_DIV:
  948. reg = wm8400_read(codec, WM8400_CLOCKING_2) &
  949. ~WM8400_DAC_CLKDIV_MASK;
  950. wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
  951. break;
  952. case WM8400_ADCCLK_DIV:
  953. reg = wm8400_read(codec, WM8400_CLOCKING_2) &
  954. ~WM8400_ADC_CLKDIV_MASK;
  955. wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
  956. break;
  957. case WM8400_BCLK_DIV:
  958. reg = wm8400_read(codec, WM8400_CLOCKING_1) &
  959. ~WM8400_BCLK_DIV_MASK;
  960. wm8400_write(codec, WM8400_CLOCKING_1, reg | div);
  961. break;
  962. default:
  963. return -EINVAL;
  964. }
  965. return 0;
  966. }
  967. /*
  968. * Set PCM DAI bit size and sample rate.
  969. */
  970. static int wm8400_hw_params(struct snd_pcm_substream *substream,
  971. struct snd_pcm_hw_params *params,
  972. struct snd_soc_dai *dai)
  973. {
  974. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  975. struct snd_soc_codec *codec = rtd->codec;
  976. u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
  977. audio1 &= ~WM8400_AIF_WL_MASK;
  978. /* bit size */
  979. switch (params_format(params)) {
  980. case SNDRV_PCM_FORMAT_S16_LE:
  981. break;
  982. case SNDRV_PCM_FORMAT_S20_3LE:
  983. audio1 |= WM8400_AIF_WL_20BITS;
  984. break;
  985. case SNDRV_PCM_FORMAT_S24_LE:
  986. audio1 |= WM8400_AIF_WL_24BITS;
  987. break;
  988. case SNDRV_PCM_FORMAT_S32_LE:
  989. audio1 |= WM8400_AIF_WL_32BITS;
  990. break;
  991. }
  992. wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
  993. return 0;
  994. }
  995. static int wm8400_mute(struct snd_soc_dai *dai, int mute)
  996. {
  997. struct snd_soc_codec *codec = dai->codec;
  998. u16 val = wm8400_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE;
  999. if (mute)
  1000. wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
  1001. else
  1002. wm8400_write(codec, WM8400_DAC_CTRL, val);
  1003. return 0;
  1004. }
  1005. /* TODO: set bias for best performance at standby */
  1006. static int wm8400_set_bias_level(struct snd_soc_codec *codec,
  1007. enum snd_soc_bias_level level)
  1008. {
  1009. struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
  1010. u16 val;
  1011. int ret;
  1012. switch (level) {
  1013. case SND_SOC_BIAS_ON:
  1014. break;
  1015. case SND_SOC_BIAS_PREPARE:
  1016. /* VMID=2*50k */
  1017. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) &
  1018. ~WM8400_VMID_MODE_MASK;
  1019. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2);
  1020. break;
  1021. case SND_SOC_BIAS_STANDBY:
  1022. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  1023. ret = regulator_bulk_enable(ARRAY_SIZE(power),
  1024. &power[0]);
  1025. if (ret != 0) {
  1026. dev_err(wm8400->wm8400->dev,
  1027. "Failed to enable regulators: %d\n",
  1028. ret);
  1029. return ret;
  1030. }
  1031. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1,
  1032. WM8400_CODEC_ENA | WM8400_SYSCLK_ENA);
  1033. /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */
  1034. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1035. WM8400_BUFDCOPEN | WM8400_POBCTRL);
  1036. msleep(50);
  1037. /* Enable VREF & VMID at 2x50k */
  1038. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1039. val |= 0x2 | WM8400_VREF_ENA;
  1040. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1041. /* Enable BUFIOEN */
  1042. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1043. WM8400_BUFDCOPEN | WM8400_POBCTRL |
  1044. WM8400_BUFIOEN);
  1045. /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
  1046. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN);
  1047. }
  1048. /* VMID=2*300k */
  1049. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) &
  1050. ~WM8400_VMID_MODE_MASK;
  1051. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4);
  1052. break;
  1053. case SND_SOC_BIAS_OFF:
  1054. /* Enable POBCTRL and SOFT_ST */
  1055. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1056. WM8400_POBCTRL | WM8400_BUFIOEN);
  1057. /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */
  1058. wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
  1059. WM8400_BUFDCOPEN | WM8400_POBCTRL |
  1060. WM8400_BUFIOEN);
  1061. /* mute DAC */
  1062. val = wm8400_read(codec, WM8400_DAC_CTRL);
  1063. wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
  1064. /* Enable any disabled outputs */
  1065. val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1066. val |= WM8400_SPK_ENA | WM8400_OUT3_ENA |
  1067. WM8400_OUT4_ENA | WM8400_LOUT_ENA |
  1068. WM8400_ROUT_ENA;
  1069. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1070. /* Disable VMID */
  1071. val &= ~WM8400_VMID_MODE_MASK;
  1072. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1073. msleep(300);
  1074. /* Enable all output discharge bits */
  1075. wm8400_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE |
  1076. WM8400_DIS_RLINE | WM8400_DIS_OUT3 |
  1077. WM8400_DIS_OUT4 | WM8400_DIS_LOUT |
  1078. WM8400_DIS_ROUT);
  1079. /* Disable VREF */
  1080. val &= ~WM8400_VREF_ENA;
  1081. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
  1082. /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
  1083. wm8400_write(codec, WM8400_ANTIPOP2, 0x0);
  1084. ret = regulator_bulk_disable(ARRAY_SIZE(power),
  1085. &power[0]);
  1086. if (ret != 0)
  1087. return ret;
  1088. break;
  1089. }
  1090. codec->dapm.bias_level = level;
  1091. return 0;
  1092. }
  1093. #define WM8400_RATES SNDRV_PCM_RATE_8000_96000
  1094. #define WM8400_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1095. SNDRV_PCM_FMTBIT_S24_LE)
  1096. static const struct snd_soc_dai_ops wm8400_dai_ops = {
  1097. .hw_params = wm8400_hw_params,
  1098. .digital_mute = wm8400_mute,
  1099. .set_fmt = wm8400_set_dai_fmt,
  1100. .set_clkdiv = wm8400_set_dai_clkdiv,
  1101. .set_sysclk = wm8400_set_dai_sysclk,
  1102. .set_pll = wm8400_set_dai_pll,
  1103. };
  1104. /*
  1105. * The WM8400 supports 2 different and mutually exclusive DAI
  1106. * configurations.
  1107. *
  1108. * 1. ADC/DAC on Primary Interface
  1109. * 2. ADC on Primary Interface/DAC on secondary
  1110. */
  1111. static struct snd_soc_dai_driver wm8400_dai = {
  1112. /* ADC/DAC on primary */
  1113. .name = "wm8400-hifi",
  1114. .playback = {
  1115. .stream_name = "Playback",
  1116. .channels_min = 1,
  1117. .channels_max = 2,
  1118. .rates = WM8400_RATES,
  1119. .formats = WM8400_FORMATS,
  1120. },
  1121. .capture = {
  1122. .stream_name = "Capture",
  1123. .channels_min = 1,
  1124. .channels_max = 2,
  1125. .rates = WM8400_RATES,
  1126. .formats = WM8400_FORMATS,
  1127. },
  1128. .ops = &wm8400_dai_ops,
  1129. };
  1130. static int wm8400_suspend(struct snd_soc_codec *codec)
  1131. {
  1132. wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1133. return 0;
  1134. }
  1135. static int wm8400_resume(struct snd_soc_codec *codec)
  1136. {
  1137. wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1138. return 0;
  1139. }
  1140. static void wm8400_probe_deferred(struct work_struct *work)
  1141. {
  1142. struct wm8400_priv *priv = container_of(work, struct wm8400_priv,
  1143. work);
  1144. struct snd_soc_codec *codec = priv->codec;
  1145. /* charge output caps */
  1146. wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1147. }
  1148. static int wm8400_codec_probe(struct snd_soc_codec *codec)
  1149. {
  1150. struct wm8400 *wm8400 = dev_get_platdata(codec->dev);
  1151. struct wm8400_priv *priv;
  1152. int ret;
  1153. u16 reg;
  1154. priv = devm_kzalloc(codec->dev, sizeof(struct wm8400_priv),
  1155. GFP_KERNEL);
  1156. if (priv == NULL)
  1157. return -ENOMEM;
  1158. snd_soc_codec_set_drvdata(codec, priv);
  1159. codec->control_data = priv->wm8400 = wm8400;
  1160. priv->codec = codec;
  1161. ret = regulator_bulk_get(wm8400->dev,
  1162. ARRAY_SIZE(power), &power[0]);
  1163. if (ret != 0) {
  1164. dev_err(codec->dev, "Failed to get regulators: %d\n", ret);
  1165. return ret;
  1166. }
  1167. INIT_WORK(&priv->work, wm8400_probe_deferred);
  1168. wm8400_codec_reset(codec);
  1169. reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1170. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA);
  1171. /* Latch volume update bits */
  1172. reg = wm8400_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME);
  1173. wm8400_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
  1174. reg & WM8400_IPVU);
  1175. reg = wm8400_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME);
  1176. wm8400_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
  1177. reg & WM8400_IPVU);
  1178. wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
  1179. wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
  1180. if (!schedule_work(&priv->work)) {
  1181. ret = -EINVAL;
  1182. goto err_regulator;
  1183. }
  1184. return 0;
  1185. err_regulator:
  1186. regulator_bulk_free(ARRAY_SIZE(power), power);
  1187. return ret;
  1188. }
  1189. static int wm8400_codec_remove(struct snd_soc_codec *codec)
  1190. {
  1191. u16 reg;
  1192. reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
  1193. wm8400_write(codec, WM8400_POWER_MANAGEMENT_1,
  1194. reg & (~WM8400_CODEC_ENA));
  1195. regulator_bulk_free(ARRAY_SIZE(power), power);
  1196. return 0;
  1197. }
  1198. static struct snd_soc_codec_driver soc_codec_dev_wm8400 = {
  1199. .probe = wm8400_codec_probe,
  1200. .remove = wm8400_codec_remove,
  1201. .suspend = wm8400_suspend,
  1202. .resume = wm8400_resume,
  1203. .read = wm8400_read,
  1204. .write = wm8400_write,
  1205. .set_bias_level = wm8400_set_bias_level,
  1206. .controls = wm8400_snd_controls,
  1207. .num_controls = ARRAY_SIZE(wm8400_snd_controls),
  1208. .dapm_widgets = wm8400_dapm_widgets,
  1209. .num_dapm_widgets = ARRAY_SIZE(wm8400_dapm_widgets),
  1210. .dapm_routes = wm8400_dapm_routes,
  1211. .num_dapm_routes = ARRAY_SIZE(wm8400_dapm_routes),
  1212. };
  1213. static int __devinit wm8400_probe(struct platform_device *pdev)
  1214. {
  1215. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8400,
  1216. &wm8400_dai, 1);
  1217. }
  1218. static int __devexit wm8400_remove(struct platform_device *pdev)
  1219. {
  1220. snd_soc_unregister_codec(&pdev->dev);
  1221. return 0;
  1222. }
  1223. static struct platform_driver wm8400_codec_driver = {
  1224. .driver = {
  1225. .name = "wm8400-codec",
  1226. .owner = THIS_MODULE,
  1227. },
  1228. .probe = wm8400_probe,
  1229. .remove = __devexit_p(wm8400_remove),
  1230. };
  1231. module_platform_driver(wm8400_codec_driver);
  1232. MODULE_DESCRIPTION("ASoC WM8400 driver");
  1233. MODULE_AUTHOR("Mark Brown");
  1234. MODULE_LICENSE("GPL");
  1235. MODULE_ALIAS("platform:wm8400-codec");