wm_hubs.c 32 KB

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