wm_hubs.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  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(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. SOC_DOUBLE_R_EXT_TLV("Headphone Volume",
  313. WM8993_LEFT_OUTPUT_VOLUME, WM8993_RIGHT_OUTPUT_VOLUME,
  314. 0, 63, 0, snd_soc_get_volsw, wm8993_put_dc_servo,
  315. outpga_tlv),
  316. SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
  317. WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
  318. SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
  319. WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
  320. SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1),
  321. SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1),
  322. SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1,
  323. line_tlv),
  324. SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1),
  325. SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1),
  326. SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
  327. line_tlv),
  328. };
  329. static int hp_supply_event(struct snd_soc_dapm_widget *w,
  330. struct snd_kcontrol *kcontrol, int event)
  331. {
  332. struct snd_soc_codec *codec = w->codec;
  333. struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
  334. switch (event) {
  335. case SND_SOC_DAPM_PRE_PMU:
  336. switch (hubs->hp_startup_mode) {
  337. case 0:
  338. break;
  339. case 1:
  340. /* Enable the headphone amp */
  341. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  342. WM8993_HPOUT1L_ENA |
  343. WM8993_HPOUT1R_ENA,
  344. WM8993_HPOUT1L_ENA |
  345. WM8993_HPOUT1R_ENA);
  346. /* Enable the second stage */
  347. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  348. WM8993_HPOUT1L_DLY |
  349. WM8993_HPOUT1R_DLY,
  350. WM8993_HPOUT1L_DLY |
  351. WM8993_HPOUT1R_DLY);
  352. break;
  353. default:
  354. dev_err(codec->dev, "Unknown HP startup mode %d\n",
  355. hubs->hp_startup_mode);
  356. break;
  357. }
  358. case SND_SOC_DAPM_PRE_PMD:
  359. snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
  360. WM8993_CP_ENA, 0);
  361. break;
  362. }
  363. return 0;
  364. }
  365. static int hp_event(struct snd_soc_dapm_widget *w,
  366. struct snd_kcontrol *kcontrol, int event)
  367. {
  368. struct snd_soc_codec *codec = w->codec;
  369. unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0);
  370. switch (event) {
  371. case SND_SOC_DAPM_POST_PMU:
  372. snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
  373. WM8993_CP_ENA, WM8993_CP_ENA);
  374. msleep(5);
  375. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  376. WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
  377. WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA);
  378. reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY;
  379. snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
  380. snd_soc_update_bits(codec, WM8993_DC_SERVO_1,
  381. WM8993_DCS_TIMER_PERIOD_01_MASK, 0);
  382. calibrate_dc_servo(codec);
  383. reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT |
  384. WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT;
  385. snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg);
  386. break;
  387. case SND_SOC_DAPM_PRE_PMD:
  388. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  389. WM8993_HPOUT1L_OUTP |
  390. WM8993_HPOUT1R_OUTP |
  391. WM8993_HPOUT1L_RMV_SHORT |
  392. WM8993_HPOUT1R_RMV_SHORT, 0);
  393. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  394. WM8993_HPOUT1L_DLY |
  395. WM8993_HPOUT1R_DLY, 0);
  396. snd_soc_write(codec, WM8993_DC_SERVO_0, 0);
  397. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  398. WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
  399. 0);
  400. break;
  401. }
  402. return 0;
  403. }
  404. static int earpiece_event(struct snd_soc_dapm_widget *w,
  405. struct snd_kcontrol *control, int event)
  406. {
  407. struct snd_soc_codec *codec = w->codec;
  408. u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
  409. switch (event) {
  410. case SND_SOC_DAPM_PRE_PMU:
  411. reg |= WM8993_HPOUT2_IN_ENA;
  412. snd_soc_write(codec, WM8993_ANTIPOP1, reg);
  413. udelay(50);
  414. break;
  415. case SND_SOC_DAPM_POST_PMD:
  416. snd_soc_write(codec, WM8993_ANTIPOP1, reg);
  417. break;
  418. default:
  419. BUG();
  420. break;
  421. }
  422. return 0;
  423. }
  424. static const struct snd_kcontrol_new in1l_pga[] = {
  425. SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
  426. SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
  427. };
  428. static const struct snd_kcontrol_new in1r_pga[] = {
  429. SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0),
  430. SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0),
  431. };
  432. static const struct snd_kcontrol_new in2l_pga[] = {
  433. SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0),
  434. SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0),
  435. };
  436. static const struct snd_kcontrol_new in2r_pga[] = {
  437. SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0),
  438. SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0),
  439. };
  440. static const struct snd_kcontrol_new mixinl[] = {
  441. SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0),
  442. SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0),
  443. };
  444. static const struct snd_kcontrol_new mixinr[] = {
  445. SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0),
  446. SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
  447. };
  448. static const struct snd_kcontrol_new left_output_mixer[] = {
  449. SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
  450. SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
  451. SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
  452. SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
  453. SOC_DAPM_SINGLE("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
  454. SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
  455. SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
  456. SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
  457. };
  458. static const struct snd_kcontrol_new right_output_mixer[] = {
  459. SOC_DAPM_SINGLE("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
  460. SOC_DAPM_SINGLE("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
  461. SOC_DAPM_SINGLE("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
  462. SOC_DAPM_SINGLE("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
  463. SOC_DAPM_SINGLE("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
  464. SOC_DAPM_SINGLE("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
  465. SOC_DAPM_SINGLE("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
  466. SOC_DAPM_SINGLE("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
  467. };
  468. static const struct snd_kcontrol_new earpiece_mixer[] = {
  469. SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0),
  470. SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0),
  471. SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0),
  472. };
  473. static const struct snd_kcontrol_new left_speaker_boost[] = {
  474. SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0),
  475. SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0),
  476. SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0),
  477. };
  478. static const struct snd_kcontrol_new right_speaker_boost[] = {
  479. SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0),
  480. SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0),
  481. SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0),
  482. };
  483. static const struct snd_kcontrol_new line1_mix[] = {
  484. SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0),
  485. SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0),
  486. SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
  487. };
  488. static const struct snd_kcontrol_new line1n_mix[] = {
  489. SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0),
  490. SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0),
  491. };
  492. static const struct snd_kcontrol_new line1p_mix[] = {
  493. SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
  494. };
  495. static const struct snd_kcontrol_new line2_mix[] = {
  496. SOC_DAPM_SINGLE("IN2R Switch", WM8993_LINE_MIXER2, 2, 1, 0),
  497. SOC_DAPM_SINGLE("IN2L Switch", WM8993_LINE_MIXER2, 1, 1, 0),
  498. SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
  499. };
  500. static const struct snd_kcontrol_new line2n_mix[] = {
  501. SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 6, 1, 0),
  502. SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 5, 1, 0),
  503. };
  504. static const struct snd_kcontrol_new line2p_mix[] = {
  505. SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
  506. };
  507. static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
  508. SND_SOC_DAPM_INPUT("IN1LN"),
  509. SND_SOC_DAPM_INPUT("IN1LP"),
  510. SND_SOC_DAPM_INPUT("IN2LN"),
  511. SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
  512. SND_SOC_DAPM_INPUT("IN1RN"),
  513. SND_SOC_DAPM_INPUT("IN1RP"),
  514. SND_SOC_DAPM_INPUT("IN2RN"),
  515. SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
  516. SND_SOC_DAPM_MICBIAS("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0),
  517. SND_SOC_DAPM_MICBIAS("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0),
  518. SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0,
  519. in1l_pga, ARRAY_SIZE(in1l_pga)),
  520. SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0,
  521. in1r_pga, ARRAY_SIZE(in1r_pga)),
  522. SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0,
  523. in2l_pga, ARRAY_SIZE(in2l_pga)),
  524. SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0,
  525. in2r_pga, ARRAY_SIZE(in2r_pga)),
  526. SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0,
  527. mixinl, ARRAY_SIZE(mixinl)),
  528. SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0,
  529. mixinr, ARRAY_SIZE(mixinr)),
  530. SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0,
  531. left_output_mixer, ARRAY_SIZE(left_output_mixer)),
  532. SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0,
  533. right_output_mixer, ARRAY_SIZE(right_output_mixer)),
  534. SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0),
  535. SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0),
  536. SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event,
  537. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  538. SND_SOC_DAPM_PGA_E("Headphone PGA", SND_SOC_NOPM, 0, 0,
  539. NULL, 0,
  540. hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  541. SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
  542. earpiece_mixer, ARRAY_SIZE(earpiece_mixer)),
  543. SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0,
  544. NULL, 0, earpiece_event,
  545. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  546. SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0,
  547. left_speaker_boost, ARRAY_SIZE(left_speaker_boost)),
  548. SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0,
  549. right_speaker_boost, ARRAY_SIZE(right_speaker_boost)),
  550. SND_SOC_DAPM_PGA("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
  551. NULL, 0),
  552. SND_SOC_DAPM_PGA("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
  553. NULL, 0),
  554. SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0,
  555. line1_mix, ARRAY_SIZE(line1_mix)),
  556. SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0,
  557. line2_mix, ARRAY_SIZE(line2_mix)),
  558. SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0,
  559. line1n_mix, ARRAY_SIZE(line1n_mix)),
  560. SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0,
  561. line1p_mix, ARRAY_SIZE(line1p_mix)),
  562. SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0,
  563. line2n_mix, ARRAY_SIZE(line2n_mix)),
  564. SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0,
  565. line2p_mix, ARRAY_SIZE(line2p_mix)),
  566. SND_SOC_DAPM_PGA("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
  567. NULL, 0),
  568. SND_SOC_DAPM_PGA("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
  569. NULL, 0),
  570. SND_SOC_DAPM_PGA("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
  571. NULL, 0),
  572. SND_SOC_DAPM_PGA("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
  573. NULL, 0),
  574. SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
  575. SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
  576. SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
  577. SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
  578. SND_SOC_DAPM_OUTPUT("HPOUT1L"),
  579. SND_SOC_DAPM_OUTPUT("HPOUT1R"),
  580. SND_SOC_DAPM_OUTPUT("HPOUT2P"),
  581. SND_SOC_DAPM_OUTPUT("HPOUT2N"),
  582. SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
  583. SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
  584. SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
  585. SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
  586. };
  587. static const struct snd_soc_dapm_route analogue_routes[] = {
  588. { "MICBIAS1", NULL, "CLK_SYS" },
  589. { "MICBIAS2", NULL, "CLK_SYS" },
  590. { "IN1L PGA", "IN1LP Switch", "IN1LP" },
  591. { "IN1L PGA", "IN1LN Switch", "IN1LN" },
  592. { "IN1L PGA", NULL, "VMID" },
  593. { "IN1R PGA", NULL, "VMID" },
  594. { "IN2L PGA", NULL, "VMID" },
  595. { "IN2R PGA", NULL, "VMID" },
  596. { "IN1R PGA", "IN1RP Switch", "IN1RP" },
  597. { "IN1R PGA", "IN1RN Switch", "IN1RN" },
  598. { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
  599. { "IN2L PGA", "IN2LN Switch", "IN2LN" },
  600. { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
  601. { "IN2R PGA", "IN2RN Switch", "IN2RN" },
  602. { "Direct Voice", NULL, "IN2LP:VXRN" },
  603. { "Direct Voice", NULL, "IN2RP:VXRP" },
  604. { "MIXINL", "IN1L Switch", "IN1L PGA" },
  605. { "MIXINL", "IN2L Switch", "IN2L PGA" },
  606. { "MIXINL", NULL, "Direct Voice" },
  607. { "MIXINL", NULL, "IN1LP" },
  608. { "MIXINL", NULL, "Left Output Mixer" },
  609. { "MIXINL", NULL, "VMID" },
  610. { "MIXINR", "IN1R Switch", "IN1R PGA" },
  611. { "MIXINR", "IN2R Switch", "IN2R PGA" },
  612. { "MIXINR", NULL, "Direct Voice" },
  613. { "MIXINR", NULL, "IN1RP" },
  614. { "MIXINR", NULL, "Right Output Mixer" },
  615. { "MIXINR", NULL, "VMID" },
  616. { "ADCL", NULL, "MIXINL" },
  617. { "ADCR", NULL, "MIXINR" },
  618. { "Left Output Mixer", "Left Input Switch", "MIXINL" },
  619. { "Left Output Mixer", "Right Input Switch", "MIXINR" },
  620. { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
  621. { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
  622. { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
  623. { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
  624. { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
  625. { "Right Output Mixer", "Left Input Switch", "MIXINL" },
  626. { "Right Output Mixer", "Right Input Switch", "MIXINR" },
  627. { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
  628. { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
  629. { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
  630. { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
  631. { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
  632. { "Left Output PGA", NULL, "Left Output Mixer" },
  633. { "Left Output PGA", NULL, "TOCLK" },
  634. { "Right Output PGA", NULL, "Right Output Mixer" },
  635. { "Right Output PGA", NULL, "TOCLK" },
  636. { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" },
  637. { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
  638. { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
  639. { "Earpiece Driver", NULL, "VMID" },
  640. { "Earpiece Driver", NULL, "Earpiece Mixer" },
  641. { "HPOUT2N", NULL, "Earpiece Driver" },
  642. { "HPOUT2P", NULL, "Earpiece Driver" },
  643. { "SPKL", "Input Switch", "MIXINL" },
  644. { "SPKL", "IN1LP Switch", "IN1LP" },
  645. { "SPKL", "Output Switch", "Left Output PGA" },
  646. { "SPKL", NULL, "TOCLK" },
  647. { "SPKR", "Input Switch", "MIXINR" },
  648. { "SPKR", "IN1RP Switch", "IN1RP" },
  649. { "SPKR", "Output Switch", "Right Output PGA" },
  650. { "SPKR", NULL, "TOCLK" },
  651. { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
  652. { "SPKL Boost", "SPKL Switch", "SPKL" },
  653. { "SPKL Boost", "SPKR Switch", "SPKR" },
  654. { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
  655. { "SPKR Boost", "SPKR Switch", "SPKR" },
  656. { "SPKR Boost", "SPKL Switch", "SPKL" },
  657. { "SPKL Driver", NULL, "VMID" },
  658. { "SPKL Driver", NULL, "SPKL Boost" },
  659. { "SPKL Driver", NULL, "CLK_SYS" },
  660. { "SPKR Driver", NULL, "VMID" },
  661. { "SPKR Driver", NULL, "SPKR Boost" },
  662. { "SPKR Driver", NULL, "CLK_SYS" },
  663. { "SPKOUTLP", NULL, "SPKL Driver" },
  664. { "SPKOUTLN", NULL, "SPKL Driver" },
  665. { "SPKOUTRP", NULL, "SPKR Driver" },
  666. { "SPKOUTRN", NULL, "SPKR Driver" },
  667. { "Left Headphone Mux", "Mixer", "Left Output PGA" },
  668. { "Right Headphone Mux", "Mixer", "Right Output PGA" },
  669. { "Headphone PGA", NULL, "Left Headphone Mux" },
  670. { "Headphone PGA", NULL, "Right Headphone Mux" },
  671. { "Headphone PGA", NULL, "VMID" },
  672. { "Headphone PGA", NULL, "CLK_SYS" },
  673. { "Headphone PGA", NULL, "Headphone Supply" },
  674. { "HPOUT1L", NULL, "Headphone PGA" },
  675. { "HPOUT1R", NULL, "Headphone PGA" },
  676. { "LINEOUT1N Driver", NULL, "VMID" },
  677. { "LINEOUT1P Driver", NULL, "VMID" },
  678. { "LINEOUT2N Driver", NULL, "VMID" },
  679. { "LINEOUT2P Driver", NULL, "VMID" },
  680. { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
  681. { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
  682. { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
  683. { "LINEOUT2P", NULL, "LINEOUT2P Driver" },
  684. };
  685. static const struct snd_soc_dapm_route lineout1_diff_routes[] = {
  686. { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" },
  687. { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" },
  688. { "LINEOUT1 Mixer", "Output Switch", "Left Output PGA" },
  689. { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" },
  690. { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" },
  691. };
  692. static const struct snd_soc_dapm_route lineout1_se_routes[] = {
  693. { "LINEOUT1N Mixer", "Left Output Switch", "Left Output PGA" },
  694. { "LINEOUT1N Mixer", "Right Output Switch", "Right Output PGA" },
  695. { "LINEOUT1P Mixer", "Left Output Switch", "Left Output PGA" },
  696. { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" },
  697. { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" },
  698. };
  699. static const struct snd_soc_dapm_route lineout2_diff_routes[] = {
  700. { "LINEOUT2 Mixer", "IN2L Switch", "IN2L PGA" },
  701. { "LINEOUT2 Mixer", "IN2R Switch", "IN2R PGA" },
  702. { "LINEOUT2 Mixer", "Output Switch", "Right Output PGA" },
  703. { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" },
  704. { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" },
  705. };
  706. static const struct snd_soc_dapm_route lineout2_se_routes[] = {
  707. { "LINEOUT2N Mixer", "Left Output Switch", "Left Output PGA" },
  708. { "LINEOUT2N Mixer", "Right Output Switch", "Right Output PGA" },
  709. { "LINEOUT2P Mixer", "Right Output Switch", "Right Output PGA" },
  710. { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" },
  711. { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" },
  712. };
  713. int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
  714. {
  715. struct snd_soc_dapm_context *dapm = &codec->dapm;
  716. /* Latch volume update bits & default ZC on */
  717. snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
  718. WM8993_IN1_VU, WM8993_IN1_VU);
  719. snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME,
  720. WM8993_IN1_VU, WM8993_IN1_VU);
  721. snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_3_4_VOLUME,
  722. WM8993_IN2_VU, WM8993_IN2_VU);
  723. snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME,
  724. WM8993_IN2_VU, WM8993_IN2_VU);
  725. snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_LEFT,
  726. WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
  727. snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT,
  728. WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
  729. snd_soc_update_bits(codec, WM8993_LEFT_OUTPUT_VOLUME,
  730. WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC,
  731. WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC);
  732. snd_soc_update_bits(codec, WM8993_RIGHT_OUTPUT_VOLUME,
  733. WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC,
  734. WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC);
  735. snd_soc_update_bits(codec, WM8993_LEFT_OPGA_VOLUME,
  736. WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU,
  737. WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU);
  738. snd_soc_update_bits(codec, WM8993_RIGHT_OPGA_VOLUME,
  739. WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU,
  740. WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU);
  741. snd_soc_add_controls(codec, analogue_snd_controls,
  742. ARRAY_SIZE(analogue_snd_controls));
  743. snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets,
  744. ARRAY_SIZE(analogue_dapm_widgets));
  745. return 0;
  746. }
  747. EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
  748. int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
  749. int lineout1_diff, int lineout2_diff)
  750. {
  751. struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
  752. struct snd_soc_dapm_context *dapm = &codec->dapm;
  753. init_completion(&hubs->dcs_done);
  754. snd_soc_dapm_add_routes(dapm, analogue_routes,
  755. ARRAY_SIZE(analogue_routes));
  756. if (lineout1_diff)
  757. snd_soc_dapm_add_routes(dapm,
  758. lineout1_diff_routes,
  759. ARRAY_SIZE(lineout1_diff_routes));
  760. else
  761. snd_soc_dapm_add_routes(dapm,
  762. lineout1_se_routes,
  763. ARRAY_SIZE(lineout1_se_routes));
  764. if (lineout2_diff)
  765. snd_soc_dapm_add_routes(dapm,
  766. lineout2_diff_routes,
  767. ARRAY_SIZE(lineout2_diff_routes));
  768. else
  769. snd_soc_dapm_add_routes(dapm,
  770. lineout2_se_routes,
  771. ARRAY_SIZE(lineout2_se_routes));
  772. return 0;
  773. }
  774. EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
  775. int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec,
  776. int lineout1_diff, int lineout2_diff,
  777. int lineout1fb, int lineout2fb,
  778. int jd_scthr, int jd_thr, int micbias1_lvl,
  779. int micbias2_lvl)
  780. {
  781. if (!lineout1_diff)
  782. snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
  783. WM8993_LINEOUT1_MODE,
  784. WM8993_LINEOUT1_MODE);
  785. if (!lineout2_diff)
  786. snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
  787. WM8993_LINEOUT2_MODE,
  788. WM8993_LINEOUT2_MODE);
  789. /* If the line outputs are differential then we aren't presenting
  790. * VMID as an output and can disable it.
  791. */
  792. if (lineout1_diff && lineout2_diff)
  793. codec->dapm.idle_bias_off = 1;
  794. if (lineout1fb)
  795. snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
  796. WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
  797. if (lineout2fb)
  798. snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
  799. WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
  800. snd_soc_update_bits(codec, WM8993_MICBIAS,
  801. WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
  802. WM8993_MICB1_LVL | WM8993_MICB2_LVL,
  803. jd_scthr << WM8993_JD_SCTHR_SHIFT |
  804. jd_thr << WM8993_JD_THR_SHIFT |
  805. micbias1_lvl |
  806. micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
  807. return 0;
  808. }
  809. EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
  810. MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
  811. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  812. MODULE_LICENSE("GPL");