wm_hubs.c 32 KB

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