wm_hubs.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /*
  2. * wm_hubs.c -- WM8993/4 common code
  3. *
  4. * Copyright 2009 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/i2c.h>
  19. #include <linux/platform_device.h>
  20. #include <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/soc.h>
  24. #include <sound/initval.h>
  25. #include <sound/tlv.h>
  26. #include "wm8993.h"
  27. #include "wm_hubs.h"
  28. const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv, -300, 300, 0);
  29. EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv);
  30. static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1650, 150, 0);
  31. static const DECLARE_TLV_DB_SCALE(inmix_sw_tlv, 0, 3000, 0);
  32. static const DECLARE_TLV_DB_SCALE(inmix_tlv, -1500, 300, 1);
  33. static const DECLARE_TLV_DB_SCALE(earpiece_tlv, -600, 600, 0);
  34. static const DECLARE_TLV_DB_SCALE(outmix_tlv, -2100, 300, 0);
  35. static const DECLARE_TLV_DB_SCALE(spkmixout_tlv, -1800, 600, 1);
  36. static const DECLARE_TLV_DB_SCALE(outpga_tlv, -5700, 100, 0);
  37. static const unsigned int spkboost_tlv[] = {
  38. TLV_DB_RANGE_HEAD(7),
  39. 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
  40. 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
  41. };
  42. static const DECLARE_TLV_DB_SCALE(line_tlv, -600, 600, 0);
  43. static const char *speaker_ref_text[] = {
  44. "SPKVDD/2",
  45. "VMID",
  46. };
  47. static const struct soc_enum speaker_ref =
  48. SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER, 8, 2, speaker_ref_text);
  49. static const char *speaker_mode_text[] = {
  50. "Class D",
  51. "Class AB",
  52. };
  53. static const struct soc_enum speaker_mode =
  54. SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION, 8, 2, speaker_mode_text);
  55. static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op)
  56. {
  57. unsigned int reg;
  58. int count = 0;
  59. unsigned int val;
  60. val = op | WM8993_DCS_ENA_CHAN_0 | WM8993_DCS_ENA_CHAN_1;
  61. /* Trigger the command */
  62. snd_soc_write(codec, WM8993_DC_SERVO_0, val);
  63. dev_dbg(codec->dev, "Waiting for DC servo...\n");
  64. do {
  65. count++;
  66. msleep(1);
  67. reg = snd_soc_read(codec, WM8993_DC_SERVO_0);
  68. dev_dbg(codec->dev, "DC servo: %x\n", reg);
  69. } while (reg & op && count < 400);
  70. if (reg & op)
  71. dev_err(codec->dev, "Timed out waiting for DC Servo %x\n",
  72. op);
  73. }
  74. /*
  75. * Startup calibration of the DC servo
  76. */
  77. static void calibrate_dc_servo(struct snd_soc_codec *codec)
  78. {
  79. struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
  80. s8 offset;
  81. u16 reg, reg_l, reg_r, dcs_cfg;
  82. /* If we're using a digital only path and have a previously
  83. * callibrated DC servo offset stored then use that. */
  84. if (hubs->class_w && hubs->class_w_dcs) {
  85. dev_dbg(codec->dev, "Using cached DC servo offset %x\n",
  86. hubs->class_w_dcs);
  87. snd_soc_write(codec, WM8993_DC_SERVO_3, hubs->class_w_dcs);
  88. wait_for_dc_servo(codec,
  89. WM8993_DCS_TRIG_DAC_WR_0 |
  90. WM8993_DCS_TRIG_DAC_WR_1);
  91. return;
  92. }
  93. /* Devices not using a DCS code correction have startup mode */
  94. if (hubs->dcs_codes) {
  95. /* Set for 32 series updates */
  96. snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
  97. WM8993_DCS_SERIES_NO_01_MASK,
  98. 32 << WM8993_DCS_SERIES_NO_01_SHIFT);
  99. wait_for_dc_servo(codec,
  100. WM8993_DCS_TRIG_SERIES_0 |
  101. WM8993_DCS_TRIG_SERIES_1);
  102. } else {
  103. wait_for_dc_servo(codec,
  104. WM8993_DCS_TRIG_STARTUP_0 |
  105. WM8993_DCS_TRIG_STARTUP_1);
  106. }
  107. /* Different chips in the family support different readback
  108. * methods.
  109. */
  110. switch (hubs->dcs_readback_mode) {
  111. case 0:
  112. reg_l = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1)
  113. & WM8993_DCS_INTEG_CHAN_0_MASK;
  114. reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2)
  115. & WM8993_DCS_INTEG_CHAN_1_MASK;
  116. break;
  117. case 1:
  118. reg = snd_soc_read(codec, WM8993_DC_SERVO_3);
  119. reg_l = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
  120. >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
  121. reg_r = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
  122. break;
  123. default:
  124. WARN(1, "Unknown DCS readback method\n");
  125. break;
  126. }
  127. dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
  128. /* Apply correction to DC servo result */
  129. if (hubs->dcs_codes) {
  130. dev_dbg(codec->dev, "Applying %d code DC servo correction\n",
  131. hubs->dcs_codes);
  132. /* HPOUT1L */
  133. offset = reg_l;
  134. offset += hubs->dcs_codes;
  135. dcs_cfg = (u8)offset << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
  136. /* HPOUT1R */
  137. offset = reg_r;
  138. offset += hubs->dcs_codes;
  139. dcs_cfg |= (u8)offset;
  140. dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
  141. /* Do it */
  142. snd_soc_write(codec, WM8993_DC_SERVO_3, dcs_cfg);
  143. wait_for_dc_servo(codec,
  144. WM8993_DCS_TRIG_DAC_WR_0 |
  145. WM8993_DCS_TRIG_DAC_WR_1);
  146. } else {
  147. dcs_cfg = reg_l << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
  148. dcs_cfg |= reg_r;
  149. }
  150. /* Save the callibrated offset if we're in class W mode and
  151. * therefore don't have any analogue signal mixed in. */
  152. if (hubs->class_w)
  153. hubs->class_w_dcs = dcs_cfg;
  154. }
  155. /*
  156. * Update the DC servo calibration on gain changes
  157. */
  158. static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
  159. struct snd_ctl_elem_value *ucontrol)
  160. {
  161. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  162. struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
  163. int ret;
  164. ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
  165. /* Updating the analogue gains invalidates the DC servo cache */
  166. hubs->class_w_dcs = 0;
  167. /* If we're applying an offset correction then updating the
  168. * callibration would be likely to introduce further offsets. */
  169. if (hubs->dcs_codes)
  170. return ret;
  171. /* Only need to do this if the outputs are active */
  172. if (snd_soc_read(codec, WM8993_POWER_MANAGEMENT_1)
  173. & (WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA))
  174. snd_soc_update_bits(codec,
  175. WM8993_DC_SERVO_0,
  176. WM8993_DCS_TRIG_SINGLE_0 |
  177. WM8993_DCS_TRIG_SINGLE_1,
  178. WM8993_DCS_TRIG_SINGLE_0 |
  179. WM8993_DCS_TRIG_SINGLE_1);
  180. return ret;
  181. }
  182. static const struct snd_kcontrol_new analogue_snd_controls[] = {
  183. SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
  184. inpga_tlv),
  185. SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
  186. SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 6, 1, 0),
  187. SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
  188. inpga_tlv),
  189. SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
  190. SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 6, 1, 0),
  191. SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
  192. inpga_tlv),
  193. SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
  194. SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 6, 1, 0),
  195. SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
  196. inpga_tlv),
  197. SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
  198. SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 6, 1, 0),
  199. SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0,
  200. inmix_sw_tlv),
  201. SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0,
  202. inmix_sw_tlv),
  203. SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0,
  204. inmix_tlv),
  205. SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv),
  206. SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0,
  207. inmix_tlv),
  208. SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0,
  209. inmix_sw_tlv),
  210. SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0,
  211. inmix_sw_tlv),
  212. SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0,
  213. inmix_tlv),
  214. SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv),
  215. SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0,
  216. inmix_tlv),
  217. SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1,
  218. outmix_tlv),
  219. SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1,
  220. outmix_tlv),
  221. SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1,
  222. outmix_tlv),
  223. SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1,
  224. outmix_tlv),
  225. SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1,
  226. outmix_tlv),
  227. SOC_SINGLE_TLV("Left Output Mixer Right Input Volume",
  228. WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv),
  229. SOC_SINGLE_TLV("Left Output Mixer Left Input Volume",
  230. WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv),
  231. SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1,
  232. outmix_tlv),
  233. SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume",
  234. WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
  235. SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume",
  236. WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv),
  237. SOC_SINGLE_TLV("Right Output Mixer IN1L Volume",
  238. WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv),
  239. SOC_SINGLE_TLV("Right Output Mixer IN1R Volume",
  240. WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv),
  241. SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume",
  242. WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv),
  243. SOC_SINGLE_TLV("Right Output Mixer Left Input Volume",
  244. WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv),
  245. SOC_SINGLE_TLV("Right Output Mixer Right Input Volume",
  246. WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
  247. SOC_SINGLE_TLV("Right Output Mixer DAC Volume",
  248. WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv),
  249. SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME,
  250. WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv),
  251. SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME,
  252. WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0),
  253. SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME,
  254. WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0),
  255. SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1),
  256. SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv),
  257. SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION,
  258. 5, 1, 1, wm_hubs_spkmix_tlv),
  259. SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION,
  260. 4, 1, 1, wm_hubs_spkmix_tlv),
  261. SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION,
  262. 3, 1, 1, wm_hubs_spkmix_tlv),
  263. SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION,
  264. 5, 1, 1, wm_hubs_spkmix_tlv),
  265. SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION,
  266. 4, 1, 1, wm_hubs_spkmix_tlv),
  267. SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION,
  268. 3, 1, 1, wm_hubs_spkmix_tlv),
  269. SOC_DOUBLE_R_TLV("Speaker Mixer Volume",
  270. WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION,
  271. 0, 3, 1, spkmixout_tlv),
  272. SOC_DOUBLE_R_TLV("Speaker Volume",
  273. WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
  274. 0, 63, 0, outpga_tlv),
  275. SOC_DOUBLE_R("Speaker Switch",
  276. WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
  277. 6, 1, 0),
  278. SOC_DOUBLE_R("Speaker ZC Switch",
  279. WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
  280. 7, 1, 0),
  281. SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 3, 0, 7, 0,
  282. spkboost_tlv),
  283. SOC_ENUM("Speaker Reference", speaker_ref),
  284. SOC_ENUM("Speaker Mode", speaker_mode),
  285. {
  286. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Headphone Volume",
  287. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  288. SNDRV_CTL_ELEM_ACCESS_READWRITE,
  289. .tlv.p = outpga_tlv,
  290. .info = snd_soc_info_volsw_2r,
  291. .get = snd_soc_get_volsw_2r, .put = wm8993_put_dc_servo,
  292. .private_value = (unsigned long)&(struct soc_mixer_control) {
  293. .reg = WM8993_LEFT_OUTPUT_VOLUME,
  294. .rreg = WM8993_RIGHT_OUTPUT_VOLUME,
  295. .shift = 0, .max = 63
  296. },
  297. },
  298. SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
  299. WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
  300. SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
  301. WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
  302. SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1),
  303. SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1),
  304. SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1,
  305. line_tlv),
  306. SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1),
  307. SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1),
  308. SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
  309. line_tlv),
  310. };
  311. static int hp_supply_event(struct snd_soc_dapm_widget *w,
  312. struct snd_kcontrol *kcontrol, int event)
  313. {
  314. struct snd_soc_codec *codec = w->codec;
  315. struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
  316. switch (event) {
  317. case SND_SOC_DAPM_PRE_PMU:
  318. switch (hubs->hp_startup_mode) {
  319. case 0:
  320. break;
  321. case 1:
  322. /* Enable the headphone amp */
  323. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  324. WM8993_HPOUT1L_ENA |
  325. WM8993_HPOUT1R_ENA,
  326. WM8993_HPOUT1L_ENA |
  327. WM8993_HPOUT1R_ENA);
  328. /* Enable the second stage */
  329. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  330. WM8993_HPOUT1L_DLY |
  331. WM8993_HPOUT1R_DLY,
  332. WM8993_HPOUT1L_DLY |
  333. WM8993_HPOUT1R_DLY);
  334. break;
  335. default:
  336. dev_err(codec->dev, "Unknown HP startup mode %d\n",
  337. hubs->hp_startup_mode);
  338. break;
  339. }
  340. case SND_SOC_DAPM_PRE_PMD:
  341. snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
  342. WM8993_CP_ENA, 0);
  343. break;
  344. }
  345. return 0;
  346. }
  347. static int hp_event(struct snd_soc_dapm_widget *w,
  348. struct snd_kcontrol *kcontrol, int event)
  349. {
  350. struct snd_soc_codec *codec = w->codec;
  351. unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0);
  352. switch (event) {
  353. case SND_SOC_DAPM_POST_PMU:
  354. snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
  355. WM8993_CP_ENA, WM8993_CP_ENA);
  356. msleep(5);
  357. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  358. WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
  359. WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA);
  360. reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY;
  361. snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
  362. /* Smallest supported update interval */
  363. snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
  364. WM8993_DCS_TIMER_PERIOD_01_MASK, 1);
  365. calibrate_dc_servo(codec);
  366. reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT |
  367. WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT;
  368. snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
  369. break;
  370. case SND_SOC_DAPM_PRE_PMD:
  371. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  372. WM8993_HPOUT1L_OUTP |
  373. WM8993_HPOUT1R_OUTP |
  374. WM8993_HPOUT1L_RMV_SHORT |
  375. WM8993_HPOUT1R_RMV_SHORT, 0);
  376. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  377. WM8993_HPOUT1L_DLY |
  378. WM8993_HPOUT1R_DLY, 0);
  379. snd_soc_write(codec, WM8993_DC_SERVO_0, 0);
  380. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  381. WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
  382. 0);
  383. break;
  384. }
  385. return 0;
  386. }
  387. static int earpiece_event(struct snd_soc_dapm_widget *w,
  388. struct snd_kcontrol *control, int event)
  389. {
  390. struct snd_soc_codec *codec = w->codec;
  391. u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
  392. switch (event) {
  393. case SND_SOC_DAPM_PRE_PMU:
  394. reg |= WM8993_HPOUT2_IN_ENA;
  395. snd_soc_write(codec, WM8993_ANTIPOP1, reg);
  396. udelay(50);
  397. break;
  398. case SND_SOC_DAPM_POST_PMD:
  399. snd_soc_write(codec, WM8993_ANTIPOP1, reg);
  400. break;
  401. default:
  402. BUG();
  403. break;
  404. }
  405. return 0;
  406. }
  407. static const struct snd_kcontrol_new in1l_pga[] = {
  408. SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
  409. SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
  410. };
  411. static const struct snd_kcontrol_new in1r_pga[] = {
  412. SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0),
  413. SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0),
  414. };
  415. static const struct snd_kcontrol_new in2l_pga[] = {
  416. SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0),
  417. SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0),
  418. };
  419. static const struct snd_kcontrol_new in2r_pga[] = {
  420. SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0),
  421. SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0),
  422. };
  423. static const struct snd_kcontrol_new mixinl[] = {
  424. SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0),
  425. SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0),
  426. };
  427. static const struct snd_kcontrol_new mixinr[] = {
  428. SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0),
  429. SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
  430. };
  431. static const struct snd_kcontrol_new left_output_mixer[] = {
  432. SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
  433. SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
  434. SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
  435. SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
  436. SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
  437. SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
  438. SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
  439. SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
  440. };
  441. static const struct snd_kcontrol_new right_output_mixer[] = {
  442. SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
  443. SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
  444. SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
  445. SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
  446. SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
  447. SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
  448. SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
  449. SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
  450. };
  451. static const struct snd_kcontrol_new earpiece_mixer[] = {
  452. SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0),
  453. SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0),
  454. SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0),
  455. };
  456. static const struct snd_kcontrol_new left_speaker_boost[] = {
  457. SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0),
  458. SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0),
  459. SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0),
  460. };
  461. static const struct snd_kcontrol_new right_speaker_boost[] = {
  462. SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0),
  463. SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0),
  464. SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0),
  465. };
  466. static const struct snd_kcontrol_new line1_mix[] = {
  467. SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0),
  468. SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0),
  469. SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
  470. };
  471. static const struct snd_kcontrol_new line1n_mix[] = {
  472. SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0),
  473. SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0),
  474. };
  475. static const struct snd_kcontrol_new line1p_mix[] = {
  476. SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
  477. };
  478. static const struct snd_kcontrol_new line2_mix[] = {
  479. SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER2, 2, 1, 0),
  480. SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER2, 1, 1, 0),
  481. SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
  482. };
  483. static const struct snd_kcontrol_new line2n_mix[] = {
  484. SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 5, 1, 0),
  485. SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 6, 1, 0),
  486. };
  487. static const struct snd_kcontrol_new line2p_mix[] = {
  488. SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
  489. };
  490. static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
  491. SND_SOC_DAPM_INPUT("IN1LN"),
  492. SND_SOC_DAPM_INPUT("IN1LP"),
  493. SND_SOC_DAPM_INPUT("IN2LN"),
  494. SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
  495. SND_SOC_DAPM_INPUT("IN1RN"),
  496. SND_SOC_DAPM_INPUT("IN1RP"),
  497. SND_SOC_DAPM_INPUT("IN2RN"),
  498. SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
  499. SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
  500. SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
  501. SND_SOC_DAPM_SUPPLY("LINEOUT_VMID_BUF", WM8993_ANTIPOP1, 7, 0, NULL, 0),
  502. SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0,
  503. in1l_pga, ARRAY_SIZE(in1l_pga)),
  504. SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0,
  505. in1r_pga, ARRAY_SIZE(in1r_pga)),
  506. SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0,
  507. in2l_pga, ARRAY_SIZE(in2l_pga)),
  508. SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0,
  509. in2r_pga, ARRAY_SIZE(in2r_pga)),
  510. /* Dummy widgets to represent differential paths */
  511. SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
  512. SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0,
  513. mixinl, ARRAY_SIZE(mixinl)),
  514. SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0,
  515. mixinr, ARRAY_SIZE(mixinr)),
  516. SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0,
  517. left_output_mixer, ARRAY_SIZE(left_output_mixer)),
  518. SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0,
  519. right_output_mixer, ARRAY_SIZE(right_output_mixer)),
  520. SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0),
  521. SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0),
  522. SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event,
  523. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  524. SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0,
  525. NULL, 0,
  526. hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  527. SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
  528. earpiece_mixer, ARRAY_SIZE(earpiece_mixer)),
  529. SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0,
  530. NULL, 0, earpiece_event,
  531. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  532. SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0,
  533. left_speaker_boost, ARRAY_SIZE(left_speaker_boost)),
  534. SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0,
  535. right_speaker_boost, ARRAY_SIZE(right_speaker_boost)),
  536. SND_SOC_DAPM_PGA("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
  537. NULL, 0),
  538. SND_SOC_DAPM_PGA("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
  539. NULL, 0),
  540. SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0,
  541. line1_mix, ARRAY_SIZE(line1_mix)),
  542. SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0,
  543. line2_mix, ARRAY_SIZE(line2_mix)),
  544. SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0,
  545. line1n_mix, ARRAY_SIZE(line1n_mix)),
  546. SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0,
  547. line1p_mix, ARRAY_SIZE(line1p_mix)),
  548. SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0,
  549. line2n_mix, ARRAY_SIZE(line2n_mix)),
  550. SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0,
  551. line2p_mix, ARRAY_SIZE(line2p_mix)),
  552. SND_SOC_DAPM_PGA("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
  553. NULL, 0),
  554. SND_SOC_DAPM_PGA("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
  555. NULL, 0),
  556. SND_SOC_DAPM_PGA("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
  557. NULL, 0),
  558. SND_SOC_DAPM_PGA("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
  559. NULL, 0),
  560. SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
  561. SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
  562. SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
  563. SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
  564. SND_SOC_DAPM_OUTPUT("HPOUT1L"),
  565. SND_SOC_DAPM_OUTPUT("HPOUT1R"),
  566. SND_SOC_DAPM_OUTPUT("HPOUT2P"),
  567. SND_SOC_DAPM_OUTPUT("HPOUT2N"),
  568. SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
  569. SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
  570. SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
  571. SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
  572. };
  573. static const struct snd_soc_dapm_route analogue_routes[] = {
  574. { "MICBIAS1", NULL, "CLK_SYS" },
  575. { "MICBIAS2", NULL, "CLK_SYS" },
  576. { "IN1L PGA", "IN1LP Switch", "IN1LP" },
  577. { "IN1L PGA", "IN1LN Switch", "IN1LN" },
  578. { "IN1R PGA", "IN1RP Switch", "IN1RP" },
  579. { "IN1R PGA", "IN1RN Switch", "IN1RN" },
  580. { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
  581. { "IN2L PGA", "IN2LN Switch", "IN2LN" },
  582. { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
  583. { "IN2R PGA", "IN2RN Switch", "IN2RN" },
  584. { "Direct Voice", NULL, "IN2LP:VXRN" },
  585. { "Direct Voice", NULL, "IN2RP:VXRP" },
  586. { "MIXINL", "IN1L Switch", "IN1L PGA" },
  587. { "MIXINL", "IN2L Switch", "IN2L PGA" },
  588. { "MIXINL", NULL, "Direct Voice" },
  589. { "MIXINL", NULL, "IN1LP" },
  590. { "MIXINL", NULL, "Left Output Mixer" },
  591. { "MIXINR", "IN1R Switch", "IN1R PGA" },
  592. { "MIXINR", "IN2R Switch", "IN2R PGA" },
  593. { "MIXINR", NULL, "Direct Voice" },
  594. { "MIXINR", NULL, "IN1RP" },
  595. { "MIXINR", NULL, "Right Output Mixer" },
  596. { "ADCL", NULL, "MIXINL" },
  597. { "ADCR", NULL, "MIXINR" },
  598. { "Left Output Mixer", "Left Input Switch", "MIXINL" },
  599. { "Left Output Mixer", "Right Input Switch", "MIXINR" },
  600. { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
  601. { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
  602. { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
  603. { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
  604. { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
  605. { "Right Output Mixer", "Left Input Switch", "MIXINL" },
  606. { "Right Output Mixer", "Right Input Switch", "MIXINR" },
  607. { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
  608. { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
  609. { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
  610. { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
  611. { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
  612. { "Left Output PGA", NULL, "Left Output Mixer" },
  613. { "Left Output PGA", NULL, "TOCLK" },
  614. { "Right Output PGA", NULL, "Right Output Mixer" },
  615. { "Right Output PGA", NULL, "TOCLK" },
  616. { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" },
  617. { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
  618. { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
  619. { "Earpiece Driver", NULL, "Earpiece Mixer" },
  620. { "HPOUT2N", NULL, "Earpiece Driver" },
  621. { "HPOUT2P", NULL, "Earpiece Driver" },
  622. { "SPKL", "Input Switch", "MIXINL" },
  623. { "SPKL", "IN1LP Switch", "IN1LP" },
  624. { "SPKL", "Output Switch", "Left Output PGA" },
  625. { "SPKL", NULL, "TOCLK" },
  626. { "SPKR", "Input Switch", "MIXINR" },
  627. { "SPKR", "IN1RP Switch", "IN1RP" },
  628. { "SPKR", "Output Switch", "Right Output PGA" },
  629. { "SPKR", NULL, "TOCLK" },
  630. { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
  631. { "SPKL Boost", "SPKL Switch", "SPKL" },
  632. { "SPKL Boost", "SPKR Switch", "SPKR" },
  633. { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
  634. { "SPKR Boost", "SPKR Switch", "SPKR" },
  635. { "SPKR Boost", "SPKL Switch", "SPKL" },
  636. { "SPKL Driver", NULL, "SPKL Boost" },
  637. { "SPKL Driver", NULL, "CLK_SYS" },
  638. { "SPKR Driver", NULL, "SPKR Boost" },
  639. { "SPKR Driver", NULL, "CLK_SYS" },
  640. { "SPKOUTLP", NULL, "SPKL Driver" },
  641. { "SPKOUTLN", NULL, "SPKL Driver" },
  642. { "SPKOUTRP", NULL, "SPKR Driver" },
  643. { "SPKOUTRN", NULL, "SPKR Driver" },
  644. { "Left Headphone Mux", "Mixer", "Left Output PGA" },
  645. { "Right Headphone Mux", "Mixer", "Right Output PGA" },
  646. { "Headphone PGA", NULL, "Left Headphone Mux" },
  647. { "Headphone PGA", NULL, "Right Headphone Mux" },
  648. { "Headphone PGA", NULL, "CLK_SYS" },
  649. { "Headphone PGA", NULL, "Headphone Supply" },
  650. { "HPOUT1L", NULL, "Headphone PGA" },
  651. { "HPOUT1R", NULL, "Headphone PGA" },
  652. { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
  653. { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
  654. { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
  655. { "LINEOUT2P", NULL, "LINEOUT2P Driver" },
  656. };
  657. static const struct snd_soc_dapm_route lineout1_diff_routes[] = {
  658. { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" },
  659. { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" },
  660. { "LINEOUT1 Mixer", "Output Switch", "Left Output PGA" },
  661. { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" },
  662. { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" },
  663. };
  664. static const struct snd_soc_dapm_route lineout1_se_routes[] = {
  665. { "LINEOUT1N Mixer", NULL, "LINEOUT_VMID_BUF" },
  666. { "LINEOUT1N Mixer", "Left Output Switch", "Left Output PGA" },
  667. { "LINEOUT1N Mixer", "Right Output Switch", "Right Output PGA" },
  668. { "LINEOUT1P Mixer", NULL, "LINEOUT_VMID_BUF" },
  669. { "LINEOUT1P Mixer", "Left Output Switch", "Left Output PGA" },
  670. { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" },
  671. { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" },
  672. };
  673. static const struct snd_soc_dapm_route lineout2_diff_routes[] = {
  674. { "LINEOUT2 Mixer", "IN1L Switch", "IN1L PGA" },
  675. { "LINEOUT2 Mixer", "IN1R Switch", "IN1R PGA" },
  676. { "LINEOUT2 Mixer", "Output Switch", "Right Output PGA" },
  677. { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" },
  678. { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" },
  679. };
  680. static const struct snd_soc_dapm_route lineout2_se_routes[] = {
  681. { "LINEOUT2N Mixer", NULL, "LINEOUT_VMID_BUF" },
  682. { "LINEOUT2N Mixer", "Left Output Switch", "Left Output PGA" },
  683. { "LINEOUT2N Mixer", "Right Output Switch", "Right Output PGA" },
  684. { "LINEOUT2P Mixer", NULL, "LINEOUT_VMID_BUF" },
  685. { "LINEOUT2P Mixer", "Right Output Switch", "Right Output PGA" },
  686. { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" },
  687. { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" },
  688. };
  689. int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
  690. {
  691. struct snd_soc_dapm_context *dapm = &codec->dapm;
  692. /* Latch volume update bits & default ZC on */
  693. snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
  694. WM8993_IN1_VU, WM8993_IN1_VU);
  695. snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME,
  696. WM8993_IN1_VU, WM8993_IN1_VU);
  697. snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_3_4_VOLUME,
  698. WM8993_IN2_VU, WM8993_IN2_VU);
  699. snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME,
  700. WM8993_IN2_VU, WM8993_IN2_VU);
  701. snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_LEFT,
  702. WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
  703. snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT,
  704. WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
  705. snd_soc_update_bits(codec, WM8993_LEFT_OUTPUT_VOLUME,
  706. WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC,
  707. WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC);
  708. snd_soc_update_bits(codec, WM8993_RIGHT_OUTPUT_VOLUME,
  709. WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC,
  710. WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC);
  711. snd_soc_update_bits(codec, WM8993_LEFT_OPGA_VOLUME,
  712. WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU,
  713. WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU);
  714. snd_soc_update_bits(codec, WM8993_RIGHT_OPGA_VOLUME,
  715. WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU,
  716. WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU);
  717. snd_soc_add_controls(codec, analogue_snd_controls,
  718. ARRAY_SIZE(analogue_snd_controls));
  719. snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets,
  720. ARRAY_SIZE(analogue_dapm_widgets));
  721. return 0;
  722. }
  723. EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
  724. int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
  725. int lineout1_diff, int lineout2_diff)
  726. {
  727. struct snd_soc_dapm_context *dapm = &codec->dapm;
  728. snd_soc_dapm_add_routes(dapm, analogue_routes,
  729. ARRAY_SIZE(analogue_routes));
  730. if (lineout1_diff)
  731. snd_soc_dapm_add_routes(dapm,
  732. lineout1_diff_routes,
  733. ARRAY_SIZE(lineout1_diff_routes));
  734. else
  735. snd_soc_dapm_add_routes(dapm,
  736. lineout1_se_routes,
  737. ARRAY_SIZE(lineout1_se_routes));
  738. if (lineout2_diff)
  739. snd_soc_dapm_add_routes(dapm,
  740. lineout2_diff_routes,
  741. ARRAY_SIZE(lineout2_diff_routes));
  742. else
  743. snd_soc_dapm_add_routes(dapm,
  744. lineout2_se_routes,
  745. ARRAY_SIZE(lineout2_se_routes));
  746. return 0;
  747. }
  748. EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
  749. int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec,
  750. int lineout1_diff, int lineout2_diff,
  751. int lineout1fb, int lineout2fb,
  752. int jd_scthr, int jd_thr, int micbias1_lvl,
  753. int micbias2_lvl)
  754. {
  755. if (!lineout1_diff)
  756. snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
  757. WM8993_LINEOUT1_MODE,
  758. WM8993_LINEOUT1_MODE);
  759. if (!lineout2_diff)
  760. snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
  761. WM8993_LINEOUT2_MODE,
  762. WM8993_LINEOUT2_MODE);
  763. /* If the line outputs are differential then we aren't presenting
  764. * VMID as an output and can disable it.
  765. */
  766. if (lineout1_diff && lineout2_diff)
  767. codec->dapm.idle_bias_off = 1;
  768. if (lineout1fb)
  769. snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
  770. WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
  771. if (lineout2fb)
  772. snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
  773. WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
  774. snd_soc_update_bits(codec, WM8993_MICBIAS,
  775. WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
  776. WM8993_MICB1_LVL | WM8993_MICB2_LVL,
  777. jd_scthr << WM8993_JD_SCTHR_SHIFT |
  778. jd_thr << WM8993_JD_THR_SHIFT |
  779. micbias1_lvl |
  780. micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
  781. return 0;
  782. }
  783. EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
  784. MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
  785. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  786. MODULE_LICENSE("GPL");