blob: fed6ea9b019f70867f1201c8bed2130c1e5d3614 [file] [log] [blame]
Mark Browna2342ae2009-07-29 21:21:49 +01001/*
2 * wm_hubs.c -- WM8993/4 common code
3 *
Mark Brown656baae2012-05-23 12:39:07 +01004 * Copyright 2009-12 Wolfson Microelectronics plc
Mark Browna2342ae2009-07-29 21:21:49 +01005 *
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
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/pm.h>
19#include <linux/i2c.h>
Mark Brown79ef0ab2011-08-01 13:02:17 +090020#include <linux/mfd/wm8994/registers.h>
Mark Browna2342ae2009-07-29 21:21:49 +010021#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
Mark Browna2342ae2009-07-29 21:21:49 +010025#include <sound/initval.h>
26#include <sound/tlv.h>
27
28#include "wm8993.h"
29#include "wm_hubs.h"
30
31const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv, -300, 300, 0);
32EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv);
33
34static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1650, 150, 0);
35static const DECLARE_TLV_DB_SCALE(inmix_sw_tlv, 0, 3000, 0);
36static const DECLARE_TLV_DB_SCALE(inmix_tlv, -1500, 300, 1);
37static const DECLARE_TLV_DB_SCALE(earpiece_tlv, -600, 600, 0);
38static const DECLARE_TLV_DB_SCALE(outmix_tlv, -2100, 300, 0);
39static const DECLARE_TLV_DB_SCALE(spkmixout_tlv, -1800, 600, 1);
40static const DECLARE_TLV_DB_SCALE(outpga_tlv, -5700, 100, 0);
Lars-Peter Clausen2e45a252015-08-02 17:20:10 +020041static const DECLARE_TLV_DB_RANGE(spkboost_tlv,
Mark Browna2342ae2009-07-29 21:21:49 +010042 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
Lars-Peter Clausen2e45a252015-08-02 17:20:10 +020043 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0)
44);
Mark Browna2342ae2009-07-29 21:21:49 +010045static const DECLARE_TLV_DB_SCALE(line_tlv, -600, 600, 0);
46
47static const char *speaker_ref_text[] = {
48 "SPKVDD/2",
49 "VMID",
50};
51
Takashi Iwaiabc4b4f2014-02-18 10:47:17 +010052static SOC_ENUM_SINGLE_DECL(speaker_ref,
53 WM8993_SPEAKER_MIXER, 8, speaker_ref_text);
Mark Browna2342ae2009-07-29 21:21:49 +010054
55static const char *speaker_mode_text[] = {
56 "Class D",
57 "Class AB",
58};
59
Takashi Iwaiabc4b4f2014-02-18 10:47:17 +010060static SOC_ENUM_SINGLE_DECL(speaker_mode,
61 WM8993_SPKMIXR_ATTENUATION, 8, speaker_mode_text);
Mark Browna2342ae2009-07-29 21:21:49 +010062
Kuninori Morimoto00a69412018-01-29 03:12:21 +000063static void wait_for_dc_servo(struct snd_soc_component *component, unsigned int op)
Mark Browna2342ae2009-07-29 21:21:49 +010064{
Kuninori Morimoto00a69412018-01-29 03:12:21 +000065 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Browna2342ae2009-07-29 21:21:49 +010066 unsigned int reg;
67 int count = 0;
Mark Brown1479c3f2011-07-15 17:33:26 +090068 int timeout;
Mark Brown4dcc93d2010-03-29 17:18:41 +010069 unsigned int val;
70
71 val = op | WM8993_DCS_ENA_CHAN_0 | WM8993_DCS_ENA_CHAN_1;
72
73 /* Trigger the command */
Kuninori Morimoto00a69412018-01-29 03:12:21 +000074 snd_soc_component_write(component, WM8993_DC_SERVO_0, val);
Mark Browna2342ae2009-07-29 21:21:49 +010075
Kuninori Morimoto00a69412018-01-29 03:12:21 +000076 dev_dbg(component->dev, "Waiting for DC servo...\n");
Mark Brown3ed70742010-01-20 17:39:45 +000077
Mark Brown1479c3f2011-07-15 17:33:26 +090078 if (hubs->dcs_done_irq)
79 timeout = 4;
80 else
81 timeout = 400;
82
83 do {
84 count++;
85
86 if (hubs->dcs_done_irq)
87 wait_for_completion_timeout(&hubs->dcs_done,
88 msecs_to_jiffies(250));
89 else
90 msleep(1);
Mark Brownd96ca3c2011-07-12 15:25:03 +090091
Kuninori Morimoto00a69412018-01-29 03:12:21 +000092 reg = snd_soc_component_read32(component, WM8993_DC_SERVO_0);
93 dev_dbg(component->dev, "DC servo: %x\n", reg);
Mark Brown1479c3f2011-07-15 17:33:26 +090094 } while (reg & op && count < timeout);
Mark Browna2342ae2009-07-29 21:21:49 +010095
Mark Brown4dcc93d2010-03-29 17:18:41 +010096 if (reg & op)
Kuninori Morimoto00a69412018-01-29 03:12:21 +000097 dev_err(component->dev, "Timed out waiting for DC Servo %x\n",
Mark Brown5a9f91c2011-02-17 12:05:46 -080098 op);
Mark Browna2342ae2009-07-29 21:21:49 +010099}
100
Mark Brownd96ca3c2011-07-12 15:25:03 +0900101irqreturn_t wm_hubs_dcs_done(int irq, void *data)
102{
103 struct wm_hubs_data *hubs = data;
104
105 complete(&hubs->dcs_done);
106
107 return IRQ_HANDLED;
108}
109EXPORT_SYMBOL_GPL(wm_hubs_dcs_done);
110
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000111static bool wm_hubs_dac_hp_direct(struct snd_soc_component *component)
Mark Brownaf31a222012-04-26 20:06:56 +0100112{
113 int reg;
114
115 /* If we're going via the mixer we'll need to do additional checks */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000116 reg = snd_soc_component_read32(component, WM8993_OUTPUT_MIXER1);
Mark Brownaf31a222012-04-26 20:06:56 +0100117 if (!(reg & WM8993_DACL_TO_HPOUT1L)) {
118 if (reg & ~WM8993_DACL_TO_MIXOUTL) {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000119 dev_vdbg(component->dev, "Analogue paths connected: %x\n",
Mark Brownaf31a222012-04-26 20:06:56 +0100120 reg & ~WM8993_DACL_TO_HPOUT1L);
121 return false;
122 } else {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000123 dev_vdbg(component->dev, "HPL connected to mixer\n");
Mark Brownaf31a222012-04-26 20:06:56 +0100124 }
125 } else {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000126 dev_vdbg(component->dev, "HPL connected to DAC\n");
Mark Brownaf31a222012-04-26 20:06:56 +0100127 }
128
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000129 reg = snd_soc_component_read32(component, WM8993_OUTPUT_MIXER2);
Mark Brownaf31a222012-04-26 20:06:56 +0100130 if (!(reg & WM8993_DACR_TO_HPOUT1R)) {
131 if (reg & ~WM8993_DACR_TO_MIXOUTR) {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000132 dev_vdbg(component->dev, "Analogue paths connected: %x\n",
Mark Brownaf31a222012-04-26 20:06:56 +0100133 reg & ~WM8993_DACR_TO_HPOUT1R);
134 return false;
135 } else {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000136 dev_vdbg(component->dev, "HPR connected to mixer\n");
Mark Brownaf31a222012-04-26 20:06:56 +0100137 }
138 } else {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000139 dev_vdbg(component->dev, "HPR connected to DAC\n");
Mark Brownaf31a222012-04-26 20:06:56 +0100140 }
141
142 return true;
143}
144
Mark Brown94aa7332012-05-01 18:45:09 +0100145struct wm_hubs_dcs_cache {
146 struct list_head list;
147 unsigned int left;
148 unsigned int right;
149 u16 dcs_cfg;
150};
151
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000152static bool wm_hubs_dcs_cache_get(struct snd_soc_component *component,
Mark Brown94aa7332012-05-01 18:45:09 +0100153 struct wm_hubs_dcs_cache **entry)
154{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000155 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown94aa7332012-05-01 18:45:09 +0100156 struct wm_hubs_dcs_cache *cache;
157 unsigned int left, right;
158
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000159 left = snd_soc_component_read32(component, WM8993_LEFT_OUTPUT_VOLUME);
Mark Brown94aa7332012-05-01 18:45:09 +0100160 left &= WM8993_HPOUT1L_VOL_MASK;
161
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000162 right = snd_soc_component_read32(component, WM8993_RIGHT_OUTPUT_VOLUME);
Mark Brown94aa7332012-05-01 18:45:09 +0100163 right &= WM8993_HPOUT1R_VOL_MASK;
164
165 list_for_each_entry(cache, &hubs->dcs_cache, list) {
166 if (cache->left != left || cache->right != right)
167 continue;
168
169 *entry = cache;
170 return true;
171 }
172
173 return false;
174}
175
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000176static void wm_hubs_dcs_cache_set(struct snd_soc_component *component, u16 dcs_cfg)
Mark Brown94aa7332012-05-01 18:45:09 +0100177{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000178 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown94aa7332012-05-01 18:45:09 +0100179 struct wm_hubs_dcs_cache *cache;
180
181 if (hubs->no_cache_dac_hp_direct)
182 return;
183
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000184 cache = devm_kzalloc(component->dev, sizeof(*cache), GFP_KERNEL);
Sachin Kamatba546682014-06-20 15:29:12 +0530185 if (!cache)
Mark Brown94aa7332012-05-01 18:45:09 +0100186 return;
Mark Brown94aa7332012-05-01 18:45:09 +0100187
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000188 cache->left = snd_soc_component_read32(component, WM8993_LEFT_OUTPUT_VOLUME);
Mark Brown94aa7332012-05-01 18:45:09 +0100189 cache->left &= WM8993_HPOUT1L_VOL_MASK;
190
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000191 cache->right = snd_soc_component_read32(component, WM8993_RIGHT_OUTPUT_VOLUME);
Mark Brown94aa7332012-05-01 18:45:09 +0100192 cache->right &= WM8993_HPOUT1R_VOL_MASK;
193
194 cache->dcs_cfg = dcs_cfg;
195
196 list_add_tail(&cache->list, &hubs->dcs_cache);
197}
198
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000199static int wm_hubs_read_dc_servo(struct snd_soc_component *component,
Mark Brownfae4efa2012-07-23 19:49:06 +0100200 u16 *reg_l, u16 *reg_r)
201{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000202 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brownfae4efa2012-07-23 19:49:06 +0100203 u16 dcs_reg, reg;
Tim Gardner1f5353e2013-03-10 10:58:21 -0600204 int ret = 0;
Mark Brownfae4efa2012-07-23 19:49:06 +0100205
206 switch (hubs->dcs_readback_mode) {
207 case 2:
208 dcs_reg = WM8994_DC_SERVO_4E;
209 break;
210 case 1:
211 dcs_reg = WM8994_DC_SERVO_READBACK;
212 break;
213 default:
214 dcs_reg = WM8993_DC_SERVO_3;
215 break;
216 }
217
218 /* Different chips in the family support different readback
219 * methods.
220 */
221 switch (hubs->dcs_readback_mode) {
222 case 0:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000223 *reg_l = snd_soc_component_read32(component, WM8993_DC_SERVO_READBACK_1)
Mark Brownfae4efa2012-07-23 19:49:06 +0100224 & WM8993_DCS_INTEG_CHAN_0_MASK;
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000225 *reg_r = snd_soc_component_read32(component, WM8993_DC_SERVO_READBACK_2)
Mark Brownfae4efa2012-07-23 19:49:06 +0100226 & WM8993_DCS_INTEG_CHAN_1_MASK;
227 break;
228 case 2:
229 case 1:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000230 reg = snd_soc_component_read32(component, dcs_reg);
Mark Brownfae4efa2012-07-23 19:49:06 +0100231 *reg_r = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK)
232 >> WM8993_DCS_DAC_WR_VAL_1_SHIFT;
233 *reg_l = reg & WM8993_DCS_DAC_WR_VAL_0_MASK;
234 break;
235 default:
236 WARN(1, "Unknown DCS readback method\n");
Tim Gardner1f5353e2013-03-10 10:58:21 -0600237 ret = -1;
Mark Brownfae4efa2012-07-23 19:49:06 +0100238 }
Tim Gardner1f5353e2013-03-10 10:58:21 -0600239 return ret;
Mark Brownfae4efa2012-07-23 19:49:06 +0100240}
241
Mark Browna2342ae2009-07-29 21:21:49 +0100242/*
Mark Brown3ed70742010-01-20 17:39:45 +0000243 * Startup calibration of the DC servo
244 */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000245static void enable_dc_servo(struct snd_soc_component *component)
Mark Brown3ed70742010-01-20 17:39:45 +0000246{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000247 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown94aa7332012-05-01 18:45:09 +0100248 struct wm_hubs_dcs_cache *cache;
Mark Brown20a4e7f2011-01-21 12:47:33 +0000249 s8 offset;
Mark Brownfae4efa2012-07-23 19:49:06 +0100250 u16 reg_l, reg_r, dcs_cfg, dcs_reg;
Mark Brown79ef0ab2011-08-01 13:02:17 +0900251
252 switch (hubs->dcs_readback_mode) {
253 case 2:
254 dcs_reg = WM8994_DC_SERVO_4E;
255 break;
256 default:
257 dcs_reg = WM8993_DC_SERVO_3;
258 break;
259 }
Mark Brown3ed70742010-01-20 17:39:45 +0000260
Mark Brownfec6dd82010-10-27 13:48:36 -0700261 /* If we're using a digital only path and have a previously
262 * callibrated DC servo offset stored then use that. */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000263 if (wm_hubs_dac_hp_direct(component) &&
264 wm_hubs_dcs_cache_get(component, &cache)) {
265 dev_dbg(component->dev, "Using cached DCS offset %x for %d,%d\n",
Mark Brown94aa7332012-05-01 18:45:09 +0100266 cache->dcs_cfg, cache->left, cache->right);
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000267 snd_soc_component_write(component, dcs_reg, cache->dcs_cfg);
268 wait_for_dc_servo(component,
Mark Brownfec6dd82010-10-27 13:48:36 -0700269 WM8993_DCS_TRIG_DAC_WR_0 |
270 WM8993_DCS_TRIG_DAC_WR_1);
271 return;
272 }
273
Mark Brownf9acf9f2011-06-07 23:23:52 +0100274 if (hubs->series_startup) {
Mark Brown11cef5f2010-11-26 17:23:44 +0000275 /* Set for 32 series updates */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000276 snd_soc_component_update_bits(component, WM8993_DC_SERVO_1,
Mark Brown11cef5f2010-11-26 17:23:44 +0000277 WM8993_DCS_SERIES_NO_01_MASK,
278 32 << WM8993_DCS_SERIES_NO_01_SHIFT);
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000279 wait_for_dc_servo(component,
Mark Brown11cef5f2010-11-26 17:23:44 +0000280 WM8993_DCS_TRIG_SERIES_0 |
281 WM8993_DCS_TRIG_SERIES_1);
282 } else {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000283 wait_for_dc_servo(component,
Mark Brown11cef5f2010-11-26 17:23:44 +0000284 WM8993_DCS_TRIG_STARTUP_0 |
285 WM8993_DCS_TRIG_STARTUP_1);
286 }
Mark Brown3ed70742010-01-20 17:39:45 +0000287
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000288 if (wm_hubs_read_dc_servo(component, &reg_l, &reg_r) < 0)
Tim Gardner1f5353e2013-03-10 10:58:21 -0600289 return;
Mark Brownfec6dd82010-10-27 13:48:36 -0700290
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000291 dev_dbg(component->dev, "DCS input: %x %x\n", reg_l, reg_r);
Mark Brownfec6dd82010-10-27 13:48:36 -0700292
Mark Brown3ed70742010-01-20 17:39:45 +0000293 /* Apply correction to DC servo result */
Mark Brown4537c4e2011-08-01 13:10:16 +0900294 if (hubs->dcs_codes_l || hubs->dcs_codes_r) {
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000295 dev_dbg(component->dev,
Mark Brown4537c4e2011-08-01 13:10:16 +0900296 "Applying %d/%d code DC servo correction\n",
297 hubs->dcs_codes_l, hubs->dcs_codes_r);
Mark Brown3ed70742010-01-20 17:39:45 +0000298
Mark Brownd5b040c2011-06-07 23:28:45 +0100299 /* HPOUT1R */
Mark Brown363947d2012-08-20 19:54:24 +0100300 offset = (s8)reg_r;
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000301 dev_dbg(component->dev, "DCS right %d->%d\n", offset,
Mark Brown20bac1f2012-08-20 20:01:51 +0100302 offset + hubs->dcs_codes_r);
Mark Brown4537c4e2011-08-01 13:10:16 +0900303 offset += hubs->dcs_codes_r;
Mark Brown20a4e7f2011-01-21 12:47:33 +0000304 dcs_cfg = (u8)offset << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
Mark Brown3ed70742010-01-20 17:39:45 +0000305
Mark Brownd5b040c2011-06-07 23:28:45 +0100306 /* HPOUT1L */
Mark Brown363947d2012-08-20 19:54:24 +0100307 offset = (s8)reg_l;
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000308 dev_dbg(component->dev, "DCS left %d->%d\n", offset,
Mark Brown20bac1f2012-08-20 20:01:51 +0100309 offset + hubs->dcs_codes_l);
Mark Brown4537c4e2011-08-01 13:10:16 +0900310 offset += hubs->dcs_codes_l;
Mark Brown20a4e7f2011-01-21 12:47:33 +0000311 dcs_cfg |= (u8)offset;
Mark Brown3ed70742010-01-20 17:39:45 +0000312
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000313 dev_dbg(component->dev, "DCS result: %x\n", dcs_cfg);
Mark Brown3254d282010-05-10 14:56:03 +0100314
Mark Brown3ed70742010-01-20 17:39:45 +0000315 /* Do it */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000316 snd_soc_component_write(component, dcs_reg, dcs_cfg);
317 wait_for_dc_servo(component,
Mark Brown4dcc93d2010-03-29 17:18:41 +0100318 WM8993_DCS_TRIG_DAC_WR_0 |
319 WM8993_DCS_TRIG_DAC_WR_1);
Mark Brownfec6dd82010-10-27 13:48:36 -0700320 } else {
Mark Brownd5b040c2011-06-07 23:28:45 +0100321 dcs_cfg = reg_r << WM8993_DCS_DAC_WR_VAL_1_SHIFT;
322 dcs_cfg |= reg_l;
Mark Brown3ed70742010-01-20 17:39:45 +0000323 }
Mark Brownfec6dd82010-10-27 13:48:36 -0700324
325 /* Save the callibrated offset if we're in class W mode and
326 * therefore don't have any analogue signal mixed in. */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000327 if (wm_hubs_dac_hp_direct(component))
328 wm_hubs_dcs_cache_set(component, dcs_cfg);
Mark Brown3ed70742010-01-20 17:39:45 +0000329}
330
331/*
Mark Browna2342ae2009-07-29 21:21:49 +0100332 * Update the DC servo calibration on gain changes
333 */
334static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
Mark Brown3ed70742010-01-20 17:39:45 +0000335 struct snd_ctl_elem_value *ucontrol)
Mark Browna2342ae2009-07-29 21:21:49 +0100336{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000337 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
338 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Browna2342ae2009-07-29 21:21:49 +0100339 int ret;
340
Peter Ujfalusic4671a92011-10-06 09:59:12 +0300341 ret = snd_soc_put_volsw(kcontrol, ucontrol);
Mark Browna2342ae2009-07-29 21:21:49 +0100342
Mark Brownae9d8602010-03-29 16:34:42 +0100343 /* If we're applying an offset correction then updating the
344 * callibration would be likely to introduce further offsets. */
Mark Brown4537c4e2011-08-01 13:10:16 +0900345 if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update)
Mark Brownae9d8602010-03-29 16:34:42 +0100346 return ret;
347
Mark Browna2342ae2009-07-29 21:21:49 +0100348 /* Only need to do this if the outputs are active */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000349 if (snd_soc_component_read32(component, WM8993_POWER_MANAGEMENT_1)
Mark Browna2342ae2009-07-29 21:21:49 +0100350 & (WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA))
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000351 snd_soc_component_update_bits(component,
Mark Browna2342ae2009-07-29 21:21:49 +0100352 WM8993_DC_SERVO_0,
353 WM8993_DCS_TRIG_SINGLE_0 |
354 WM8993_DCS_TRIG_SINGLE_1,
355 WM8993_DCS_TRIG_SINGLE_0 |
356 WM8993_DCS_TRIG_SINGLE_1);
357
358 return ret;
359}
360
361static const struct snd_kcontrol_new analogue_snd_controls[] = {
362SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
363 inpga_tlv),
364SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
Mark Brownea02c632011-05-27 21:56:16 +0800365SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 6, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100366
367SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0,
368 inpga_tlv),
369SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1),
Mark Brownea02c632011-05-27 21:56:16 +0800370SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 6, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100371
372
373SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
374 inpga_tlv),
375SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
Mark Brownea02c632011-05-27 21:56:16 +0800376SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 6, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100377
378SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0,
379 inpga_tlv),
380SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1),
Mark Brownea02c632011-05-27 21:56:16 +0800381SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 6, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100382
383SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0,
384 inmix_sw_tlv),
385SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0,
386 inmix_sw_tlv),
387SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0,
388 inmix_tlv),
389SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv),
390SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0,
391 inmix_tlv),
392
393SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0,
394 inmix_sw_tlv),
395SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0,
396 inmix_sw_tlv),
397SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0,
398 inmix_tlv),
399SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv),
400SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0,
401 inmix_tlv),
402
403SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1,
404 outmix_tlv),
405SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1,
406 outmix_tlv),
407SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1,
408 outmix_tlv),
409SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1,
410 outmix_tlv),
411SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1,
412 outmix_tlv),
413SOC_SINGLE_TLV("Left Output Mixer Right Input Volume",
414 WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv),
415SOC_SINGLE_TLV("Left Output Mixer Left Input Volume",
416 WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv),
417SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1,
418 outmix_tlv),
419
420SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume",
421 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
422SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume",
423 WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv),
424SOC_SINGLE_TLV("Right Output Mixer IN1L Volume",
425 WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv),
426SOC_SINGLE_TLV("Right Output Mixer IN1R Volume",
427 WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv),
428SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume",
429 WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv),
430SOC_SINGLE_TLV("Right Output Mixer Left Input Volume",
431 WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv),
432SOC_SINGLE_TLV("Right Output Mixer Right Input Volume",
433 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv),
434SOC_SINGLE_TLV("Right Output Mixer DAC Volume",
435 WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv),
436
437SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME,
438 WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv),
439SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME,
440 WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0),
441SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME,
442 WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0),
443
444SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1),
445SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv),
446
447SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION,
448 5, 1, 1, wm_hubs_spkmix_tlv),
449SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION,
450 4, 1, 1, wm_hubs_spkmix_tlv),
451SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION,
452 3, 1, 1, wm_hubs_spkmix_tlv),
453
454SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION,
455 5, 1, 1, wm_hubs_spkmix_tlv),
456SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION,
457 4, 1, 1, wm_hubs_spkmix_tlv),
458SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION,
459 3, 1, 1, wm_hubs_spkmix_tlv),
460
461SOC_DOUBLE_R_TLV("Speaker Mixer Volume",
462 WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION,
463 0, 3, 1, spkmixout_tlv),
464SOC_DOUBLE_R_TLV("Speaker Volume",
465 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
466 0, 63, 0, outpga_tlv),
467SOC_DOUBLE_R("Speaker Switch",
468 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
469 6, 1, 0),
470SOC_DOUBLE_R("Speaker ZC Switch",
471 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT,
472 7, 1, 0),
Uk Kimed8cc472010-12-05 17:26:07 +0900473SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 3, 0, 7, 0,
Mark Browna2342ae2009-07-29 21:21:49 +0100474 spkboost_tlv),
475SOC_ENUM("Speaker Reference", speaker_ref),
476SOC_ENUM("Speaker Mode", speaker_mode),
477
Peter Ujfalusi0f9887d2011-10-05 10:29:19 +0300478SOC_DOUBLE_R_EXT_TLV("Headphone Volume",
479 WM8993_LEFT_OUTPUT_VOLUME, WM8993_RIGHT_OUTPUT_VOLUME,
Peter Ujfalusic4671a92011-10-06 09:59:12 +0300480 0, 63, 0, snd_soc_get_volsw, wm8993_put_dc_servo,
Peter Ujfalusi0f9887d2011-10-05 10:29:19 +0300481 outpga_tlv),
482
Mark Browna2342ae2009-07-29 21:21:49 +0100483SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME,
484 WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0),
485SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME,
486 WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
487
488SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1),
489SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1),
490SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1,
491 line_tlv),
492
493SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1),
494SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1),
495SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
496 line_tlv),
497};
498
Mark Brown3ed70742010-01-20 17:39:45 +0000499static int hp_supply_event(struct snd_soc_dapm_widget *w,
500 struct snd_kcontrol *kcontrol, int event)
501{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000502 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
503 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown3ed70742010-01-20 17:39:45 +0000504
505 switch (event) {
506 case SND_SOC_DAPM_PRE_PMU:
507 switch (hubs->hp_startup_mode) {
508 case 0:
509 break;
510 case 1:
511 /* Enable the headphone amp */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000512 snd_soc_component_update_bits(component, WM8993_POWER_MANAGEMENT_1,
Mark Brown3ed70742010-01-20 17:39:45 +0000513 WM8993_HPOUT1L_ENA |
514 WM8993_HPOUT1R_ENA,
515 WM8993_HPOUT1L_ENA |
516 WM8993_HPOUT1R_ENA);
517
518 /* Enable the second stage */
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000519 snd_soc_component_update_bits(component, WM8993_ANALOGUE_HP_0,
Mark Brown3ed70742010-01-20 17:39:45 +0000520 WM8993_HPOUT1L_DLY |
521 WM8993_HPOUT1R_DLY,
522 WM8993_HPOUT1L_DLY |
523 WM8993_HPOUT1R_DLY);
524 break;
525 default:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000526 dev_err(component->dev, "Unknown HP startup mode %d\n",
Mark Brown3ed70742010-01-20 17:39:45 +0000527 hubs->hp_startup_mode);
528 break;
529 }
Takashi Iwai268ff142013-10-30 08:35:02 +0100530 break;
Mark Brown3ed70742010-01-20 17:39:45 +0000531
532 case SND_SOC_DAPM_PRE_PMD:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000533 snd_soc_component_update_bits(component, WM8993_CHARGE_PUMP_1,
Mark Brown3ed70742010-01-20 17:39:45 +0000534 WM8993_CP_ENA, 0);
535 break;
536 }
537
538 return 0;
539}
540
Mark Browna2342ae2009-07-29 21:21:49 +0100541static int hp_event(struct snd_soc_dapm_widget *w,
542 struct snd_kcontrol *kcontrol, int event)
543{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000544 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
545 unsigned int reg = snd_soc_component_read32(component, WM8993_ANALOGUE_HP_0);
Mark Browna2342ae2009-07-29 21:21:49 +0100546
547 switch (event) {
548 case SND_SOC_DAPM_POST_PMU:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000549 snd_soc_component_update_bits(component, WM8993_CHARGE_PUMP_1,
Mark Browna2342ae2009-07-29 21:21:49 +0100550 WM8993_CP_ENA, WM8993_CP_ENA);
551
552 msleep(5);
553
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000554 snd_soc_component_update_bits(component, WM8993_POWER_MANAGEMENT_1,
Mark Browna2342ae2009-07-29 21:21:49 +0100555 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
556 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA);
557
558 reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY;
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000559 snd_soc_component_write(component, WM8993_ANALOGUE_HP_0, reg);
Mark Browna2342ae2009-07-29 21:21:49 +0100560
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000561 snd_soc_component_update_bits(component, WM8993_DC_SERVO_1,
Mark Brownf9925d42011-07-28 12:44:44 +0100562 WM8993_DCS_TIMER_PERIOD_01_MASK, 0);
Mark Brown3ed70742010-01-20 17:39:45 +0000563
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000564 enable_dc_servo(component);
Mark Browna2342ae2009-07-29 21:21:49 +0100565
566 reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT |
567 WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT;
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000568 snd_soc_component_write(component, WM8993_ANALOGUE_HP_0, reg);
Mark Browna2342ae2009-07-29 21:21:49 +0100569 break;
570
571 case SND_SOC_DAPM_PRE_PMD:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000572 snd_soc_component_update_bits(component, WM8993_ANALOGUE_HP_0,
Mark Brown6adb26b2010-05-10 16:13:11 +0100573 WM8993_HPOUT1L_OUTP |
574 WM8993_HPOUT1R_OUTP |
Mark Brown3ed70742010-01-20 17:39:45 +0000575 WM8993_HPOUT1L_RMV_SHORT |
576 WM8993_HPOUT1R_RMV_SHORT, 0);
Mark Browna2342ae2009-07-29 21:21:49 +0100577
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000578 snd_soc_component_update_bits(component, WM8993_ANALOGUE_HP_0,
Mark Brown6adb26b2010-05-10 16:13:11 +0100579 WM8993_HPOUT1L_DLY |
580 WM8993_HPOUT1R_DLY, 0);
Mark Browna2342ae2009-07-29 21:21:49 +0100581
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000582 snd_soc_component_write(component, WM8993_DC_SERVO_0, 0);
Mark Brown395e4b72010-05-10 21:06:14 +0100583
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000584 snd_soc_component_update_bits(component, WM8993_POWER_MANAGEMENT_1,
Mark Browna2342ae2009-07-29 21:21:49 +0100585 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
586 0);
Mark Browna2342ae2009-07-29 21:21:49 +0100587 break;
588 }
589
590 return 0;
591}
592
593static int earpiece_event(struct snd_soc_dapm_widget *w,
594 struct snd_kcontrol *control, int event)
595{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000596 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
597 u16 reg = snd_soc_component_read32(component, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
Mark Browna2342ae2009-07-29 21:21:49 +0100598
599 switch (event) {
600 case SND_SOC_DAPM_PRE_PMU:
601 reg |= WM8993_HPOUT2_IN_ENA;
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000602 snd_soc_component_write(component, WM8993_ANTIPOP1, reg);
Mark Browna2342ae2009-07-29 21:21:49 +0100603 udelay(50);
604 break;
605
606 case SND_SOC_DAPM_POST_PMD:
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000607 snd_soc_component_write(component, WM8993_ANTIPOP1, reg);
Mark Browna2342ae2009-07-29 21:21:49 +0100608 break;
609
610 default:
Takashi Iwai9a743402013-11-06 11:07:18 +0100611 WARN(1, "Invalid event %d\n", event);
Mark Browna2342ae2009-07-29 21:21:49 +0100612 break;
613 }
614
615 return 0;
616}
617
Mark Brown5f2f3892012-02-08 18:51:42 +0000618static int lineout_event(struct snd_soc_dapm_widget *w,
619 struct snd_kcontrol *control, int event)
620{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000621 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
622 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown5f2f3892012-02-08 18:51:42 +0000623 bool *flag;
624
625 switch (w->shift) {
626 case WM8993_LINEOUT1N_ENA_SHIFT:
627 flag = &hubs->lineout1n_ena;
628 break;
629 case WM8993_LINEOUT1P_ENA_SHIFT:
630 flag = &hubs->lineout1p_ena;
631 break;
632 case WM8993_LINEOUT2N_ENA_SHIFT:
633 flag = &hubs->lineout2n_ena;
634 break;
635 case WM8993_LINEOUT2P_ENA_SHIFT:
636 flag = &hubs->lineout2p_ena;
637 break;
638 default:
639 WARN(1, "Unknown line output");
640 return -EINVAL;
641 }
642
643 *flag = SND_SOC_DAPM_EVENT_ON(event);
644
645 return 0;
646}
647
Mark Brown02e79472012-08-21 17:54:52 +0100648static int micbias_event(struct snd_soc_dapm_widget *w,
649 struct snd_kcontrol *kcontrol, int event)
650{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000651 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
652 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown02e79472012-08-21 17:54:52 +0100653
654 switch (w->shift) {
655 case WM8993_MICB1_ENA_SHIFT:
656 if (hubs->micb1_delay)
657 msleep(hubs->micb1_delay);
658 break;
659 case WM8993_MICB2_ENA_SHIFT:
660 if (hubs->micb2_delay)
661 msleep(hubs->micb2_delay);
662 break;
663 default:
664 return -EINVAL;
665 }
666
667 return 0;
668}
669
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000670void wm_hubs_update_class_w(struct snd_soc_component *component)
Mark Brownc3403042012-04-26 21:29:29 +0100671{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000672 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brownc3403042012-04-26 21:29:29 +0100673 int enable = WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ;
674
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000675 if (!wm_hubs_dac_hp_direct(component))
Mark Brownc3403042012-04-26 21:29:29 +0100676 enable = false;
677
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000678 if (hubs->check_class_w_digital && !hubs->check_class_w_digital(component))
Mark Brownc3403042012-04-26 21:29:29 +0100679 enable = false;
680
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000681 dev_vdbg(component->dev, "Class W %s\n", enable ? "enabled" : "disabled");
Mark Brownc3403042012-04-26 21:29:29 +0100682
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000683 snd_soc_component_update_bits(component, WM8993_CLASS_W_0,
Mark Brownc3403042012-04-26 21:29:29 +0100684 WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ, enable);
Mark Browneb4d5fc2012-09-27 18:35:24 +0100685
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000686 snd_soc_component_write(component, WM8993_LEFT_OUTPUT_VOLUME,
687 snd_soc_component_read32(component, WM8993_LEFT_OUTPUT_VOLUME));
688 snd_soc_component_write(component, WM8993_RIGHT_OUTPUT_VOLUME,
689 snd_soc_component_read32(component, WM8993_RIGHT_OUTPUT_VOLUME));
Mark Brownc3403042012-04-26 21:29:29 +0100690}
691EXPORT_SYMBOL_GPL(wm_hubs_update_class_w);
692
Mark Brown04de57c2012-04-26 22:08:50 +0100693#define WM_HUBS_SINGLE_W(xname, reg, shift, max, invert) \
Lars-Peter Clausen98809ae2013-06-19 19:34:01 +0200694 SOC_SINGLE_EXT(xname, reg, shift, max, invert, \
695 snd_soc_dapm_get_volsw, class_w_put_volsw)
Mark Brown04de57c2012-04-26 22:08:50 +0100696
697static int class_w_put_volsw(struct snd_kcontrol *kcontrol,
698 struct snd_ctl_elem_value *ucontrol)
699{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000700 struct snd_soc_component *component = snd_soc_dapm_kcontrol_component(kcontrol);
Mark Brown04de57c2012-04-26 22:08:50 +0100701 int ret;
702
703 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
704
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000705 wm_hubs_update_class_w(component);
Mark Brown04de57c2012-04-26 22:08:50 +0100706
707 return ret;
708}
709
Mark Brownc3403042012-04-26 21:29:29 +0100710#define WM_HUBS_ENUM_W(xname, xenum) \
711{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
712 .info = snd_soc_info_enum_double, \
713 .get = snd_soc_dapm_get_enum_double, \
Mark Brown04de57c2012-04-26 22:08:50 +0100714 .put = class_w_put_double, \
Mark Brownc3403042012-04-26 21:29:29 +0100715 .private_value = (unsigned long)&xenum }
716
Mark Brown04de57c2012-04-26 22:08:50 +0100717static int class_w_put_double(struct snd_kcontrol *kcontrol,
718 struct snd_ctl_elem_value *ucontrol)
Mark Brownc3403042012-04-26 21:29:29 +0100719{
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000720 struct snd_soc_component *component = snd_soc_dapm_kcontrol_component(kcontrol);
Mark Brownc3403042012-04-26 21:29:29 +0100721 int ret;
722
723 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
724
Kuninori Morimoto00a69412018-01-29 03:12:21 +0000725 wm_hubs_update_class_w(component);
Mark Brownc3403042012-04-26 21:29:29 +0100726
727 return ret;
728}
729
730static const char *hp_mux_text[] = {
731 "Mixer",
732 "DAC",
733};
734
Takashi Iwaiabc4b4f2014-02-18 10:47:17 +0100735static SOC_ENUM_SINGLE_DECL(hpl_enum,
736 WM8993_OUTPUT_MIXER1, 8, hp_mux_text);
Mark Brownc3403042012-04-26 21:29:29 +0100737
738const struct snd_kcontrol_new wm_hubs_hpl_mux =
739 WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum);
740EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux);
741
Takashi Iwaiabc4b4f2014-02-18 10:47:17 +0100742static SOC_ENUM_SINGLE_DECL(hpr_enum,
743 WM8993_OUTPUT_MIXER2, 8, hp_mux_text);
Mark Brownc3403042012-04-26 21:29:29 +0100744
745const struct snd_kcontrol_new wm_hubs_hpr_mux =
746 WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum);
747EXPORT_SYMBOL_GPL(wm_hubs_hpr_mux);
748
Mark Browna2342ae2009-07-29 21:21:49 +0100749static const struct snd_kcontrol_new in1l_pga[] = {
750SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0),
751SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0),
752};
753
754static const struct snd_kcontrol_new in1r_pga[] = {
755SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0),
756SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0),
757};
758
759static const struct snd_kcontrol_new in2l_pga[] = {
760SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0),
761SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0),
762};
763
764static const struct snd_kcontrol_new in2r_pga[] = {
765SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0),
766SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0),
767};
768
769static const struct snd_kcontrol_new mixinl[] = {
770SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0),
771SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0),
772};
773
774static const struct snd_kcontrol_new mixinr[] = {
775SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0),
776SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0),
777};
778
779static const struct snd_kcontrol_new left_output_mixer[] = {
Mark Brown04de57c2012-04-26 22:08:50 +0100780WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0),
781WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0),
782WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0),
783WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0),
784WM_HUBS_SINGLE_W("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0),
785WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0),
786WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0),
787WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100788};
789
790static const struct snd_kcontrol_new right_output_mixer[] = {
Mark Brown04de57c2012-04-26 22:08:50 +0100791WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0),
792WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0),
793WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0),
794WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0),
795WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0),
796WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0),
797WM_HUBS_SINGLE_W("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0),
798WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100799};
800
801static const struct snd_kcontrol_new earpiece_mixer[] = {
802SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0),
803SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0),
804SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0),
805};
806
807static const struct snd_kcontrol_new left_speaker_boost[] = {
808SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0),
809SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0),
810SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0),
811};
812
813static const struct snd_kcontrol_new right_speaker_boost[] = {
814SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0),
815SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0),
816SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0),
817};
818
819static const struct snd_kcontrol_new line1_mix[] = {
820SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0),
821SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0),
822SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
823};
824
825static const struct snd_kcontrol_new line1n_mix[] = {
826SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0),
827SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0),
828};
829
830static const struct snd_kcontrol_new line1p_mix[] = {
831SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0),
832};
833
834static const struct snd_kcontrol_new line2_mix[] = {
Mark Brown43b6cec2012-02-01 23:46:58 +0000835SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER2, 2, 1, 0),
836SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER2, 1, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100837SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
838};
839
840static const struct snd_kcontrol_new line2n_mix[] = {
UK KIM114395c2012-01-28 01:52:22 +0900841SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 5, 1, 0),
842SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 6, 1, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100843};
844
845static const struct snd_kcontrol_new line2p_mix[] = {
846SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0),
847};
848
849static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = {
850SND_SOC_DAPM_INPUT("IN1LN"),
851SND_SOC_DAPM_INPUT("IN1LP"),
852SND_SOC_DAPM_INPUT("IN2LN"),
Joonyoung Shim34825942009-12-04 15:12:10 +0900853SND_SOC_DAPM_INPUT("IN2LP:VXRN"),
Mark Browna2342ae2009-07-29 21:21:49 +0100854SND_SOC_DAPM_INPUT("IN1RN"),
855SND_SOC_DAPM_INPUT("IN1RP"),
856SND_SOC_DAPM_INPUT("IN2RN"),
Joonyoung Shim34825942009-12-04 15:12:10 +0900857SND_SOC_DAPM_INPUT("IN2RP:VXRP"),
Mark Browna2342ae2009-07-29 21:21:49 +0100858
Mark Brown02e79472012-08-21 17:54:52 +0100859SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0,
860 micbias_event, SND_SOC_DAPM_POST_PMU),
861SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0,
862 micbias_event, SND_SOC_DAPM_POST_PMU),
Mark Browna2342ae2009-07-29 21:21:49 +0100863
864SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0,
865 in1l_pga, ARRAY_SIZE(in1l_pga)),
866SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0,
867 in1r_pga, ARRAY_SIZE(in1r_pga)),
868
869SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0,
870 in2l_pga, ARRAY_SIZE(in2l_pga)),
871SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0,
872 in2r_pga, ARRAY_SIZE(in2r_pga)),
873
Mark Browna2342ae2009-07-29 21:21:49 +0100874SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0,
875 mixinl, ARRAY_SIZE(mixinl)),
876SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0,
877 mixinr, ARRAY_SIZE(mixinr)),
878
Mark Browna2342ae2009-07-29 21:21:49 +0100879SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0,
880 left_output_mixer, ARRAY_SIZE(left_output_mixer)),
881SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0,
882 right_output_mixer, ARRAY_SIZE(right_output_mixer)),
883
884SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0),
885SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0),
886
Mark Brown3ed70742010-01-20 17:39:45 +0000887SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event,
888 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Brown26422622012-02-21 09:36:49 +0000889SND_SOC_DAPM_OUT_DRV_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
890 hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Browna2342ae2009-07-29 21:21:49 +0100891
892SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
893 earpiece_mixer, ARRAY_SIZE(earpiece_mixer)),
894SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0,
895 NULL, 0, earpiece_event,
896 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
897
898SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0,
899 left_speaker_boost, ARRAY_SIZE(left_speaker_boost)),
900SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0,
901 right_speaker_boost, ARRAY_SIZE(right_speaker_boost)),
902
Mark Brown03431972011-11-04 17:11:54 +0000903SND_SOC_DAPM_SUPPLY("TSHUT", WM8993_POWER_MANAGEMENT_2, 14, 0, NULL, 0),
Mark Browndc9c7452012-02-07 14:24:57 +0000904SND_SOC_DAPM_OUT_DRV("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0,
905 NULL, 0),
906SND_SOC_DAPM_OUT_DRV("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0,
907 NULL, 0),
Mark Browna2342ae2009-07-29 21:21:49 +0100908
909SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0,
910 line1_mix, ARRAY_SIZE(line1_mix)),
911SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0,
912 line2_mix, ARRAY_SIZE(line2_mix)),
913
914SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0,
915 line1n_mix, ARRAY_SIZE(line1n_mix)),
916SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0,
917 line1p_mix, ARRAY_SIZE(line1p_mix)),
918SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0,
919 line2n_mix, ARRAY_SIZE(line2n_mix)),
920SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0,
921 line2p_mix, ARRAY_SIZE(line2p_mix)),
922
Mark Brown5f2f3892012-02-08 18:51:42 +0000923SND_SOC_DAPM_OUT_DRV_E("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0,
924 NULL, 0, lineout_event,
925 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
926SND_SOC_DAPM_OUT_DRV_E("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0,
927 NULL, 0, lineout_event,
928 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
929SND_SOC_DAPM_OUT_DRV_E("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0,
930 NULL, 0, lineout_event,
931 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
932SND_SOC_DAPM_OUT_DRV_E("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0,
933 NULL, 0, lineout_event,
934 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
Mark Browna2342ae2009-07-29 21:21:49 +0100935
936SND_SOC_DAPM_OUTPUT("SPKOUTLP"),
937SND_SOC_DAPM_OUTPUT("SPKOUTLN"),
938SND_SOC_DAPM_OUTPUT("SPKOUTRP"),
939SND_SOC_DAPM_OUTPUT("SPKOUTRN"),
940SND_SOC_DAPM_OUTPUT("HPOUT1L"),
941SND_SOC_DAPM_OUTPUT("HPOUT1R"),
942SND_SOC_DAPM_OUTPUT("HPOUT2P"),
943SND_SOC_DAPM_OUTPUT("HPOUT2N"),
944SND_SOC_DAPM_OUTPUT("LINEOUT1P"),
945SND_SOC_DAPM_OUTPUT("LINEOUT1N"),
946SND_SOC_DAPM_OUTPUT("LINEOUT2P"),
947SND_SOC_DAPM_OUTPUT("LINEOUT2N"),
948};
949
950static const struct snd_soc_dapm_route analogue_routes[] = {
Mark Brown4baafdd2011-02-18 15:05:53 -0800951 { "MICBIAS1", NULL, "CLK_SYS" },
952 { "MICBIAS2", NULL, "CLK_SYS" },
953
Mark Browna2342ae2009-07-29 21:21:49 +0100954 { "IN1L PGA", "IN1LP Switch", "IN1LP" },
955 { "IN1L PGA", "IN1LN Switch", "IN1LN" },
956
Mark Brown4e04ada2011-07-15 15:12:31 +0900957 { "IN1L PGA", NULL, "VMID" },
958 { "IN1R PGA", NULL, "VMID" },
959 { "IN2L PGA", NULL, "VMID" },
960 { "IN2R PGA", NULL, "VMID" },
961
Mark Browna2342ae2009-07-29 21:21:49 +0100962 { "IN1R PGA", "IN1RP Switch", "IN1RP" },
963 { "IN1R PGA", "IN1RN Switch", "IN1RN" },
964
Joonyoung Shim34825942009-12-04 15:12:10 +0900965 { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" },
Mark Browna2342ae2009-07-29 21:21:49 +0100966 { "IN2L PGA", "IN2LN Switch", "IN2LN" },
967
Joonyoung Shim34825942009-12-04 15:12:10 +0900968 { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" },
Mark Browna2342ae2009-07-29 21:21:49 +0100969 { "IN2R PGA", "IN2RN Switch", "IN2RN" },
970
Joonyoung Shim34825942009-12-04 15:12:10 +0900971 { "Direct Voice", NULL, "IN2LP:VXRN" },
972 { "Direct Voice", NULL, "IN2RP:VXRP" },
Mark Browna2342ae2009-07-29 21:21:49 +0100973
974 { "MIXINL", "IN1L Switch", "IN1L PGA" },
975 { "MIXINL", "IN2L Switch", "IN2L PGA" },
976 { "MIXINL", NULL, "Direct Voice" },
977 { "MIXINL", NULL, "IN1LP" },
978 { "MIXINL", NULL, "Left Output Mixer" },
Mark Brown4e04ada2011-07-15 15:12:31 +0900979 { "MIXINL", NULL, "VMID" },
Mark Browna2342ae2009-07-29 21:21:49 +0100980
981 { "MIXINR", "IN1R Switch", "IN1R PGA" },
982 { "MIXINR", "IN2R Switch", "IN2R PGA" },
983 { "MIXINR", NULL, "Direct Voice" },
984 { "MIXINR", NULL, "IN1RP" },
985 { "MIXINR", NULL, "Right Output Mixer" },
Mark Brown4e04ada2011-07-15 15:12:31 +0900986 { "MIXINR", NULL, "VMID" },
Mark Browna2342ae2009-07-29 21:21:49 +0100987
988 { "ADCL", NULL, "MIXINL" },
989 { "ADCR", NULL, "MIXINR" },
990
991 { "Left Output Mixer", "Left Input Switch", "MIXINL" },
992 { "Left Output Mixer", "Right Input Switch", "MIXINR" },
993 { "Left Output Mixer", "IN2RN Switch", "IN2RN" },
994 { "Left Output Mixer", "IN2LN Switch", "IN2LN" },
Joonyoung Shim34825942009-12-04 15:12:10 +0900995 { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" },
Mark Browna2342ae2009-07-29 21:21:49 +0100996 { "Left Output Mixer", "IN1L Switch", "IN1L PGA" },
997 { "Left Output Mixer", "IN1R Switch", "IN1R PGA" },
998
999 { "Right Output Mixer", "Left Input Switch", "MIXINL" },
1000 { "Right Output Mixer", "Right Input Switch", "MIXINR" },
1001 { "Right Output Mixer", "IN2LN Switch", "IN2LN" },
1002 { "Right Output Mixer", "IN2RN Switch", "IN2RN" },
Joonyoung Shim34825942009-12-04 15:12:10 +09001003 { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" },
Mark Browna2342ae2009-07-29 21:21:49 +01001004 { "Right Output Mixer", "IN1L Switch", "IN1L PGA" },
1005 { "Right Output Mixer", "IN1R Switch", "IN1R PGA" },
1006
1007 { "Left Output PGA", NULL, "Left Output Mixer" },
1008 { "Left Output PGA", NULL, "TOCLK" },
1009
1010 { "Right Output PGA", NULL, "Right Output Mixer" },
1011 { "Right Output PGA", NULL, "TOCLK" },
1012
1013 { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" },
1014 { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" },
1015 { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" },
1016
Mark Brown4e04ada2011-07-15 15:12:31 +09001017 { "Earpiece Driver", NULL, "VMID" },
Mark Browna2342ae2009-07-29 21:21:49 +01001018 { "Earpiece Driver", NULL, "Earpiece Mixer" },
1019 { "HPOUT2N", NULL, "Earpiece Driver" },
1020 { "HPOUT2P", NULL, "Earpiece Driver" },
1021
1022 { "SPKL", "Input Switch", "MIXINL" },
1023 { "SPKL", "IN1LP Switch", "IN1LP" },
Mark Brown39cca162011-04-08 16:32:16 +09001024 { "SPKL", "Output Switch", "Left Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001025 { "SPKL", NULL, "TOCLK" },
1026
1027 { "SPKR", "Input Switch", "MIXINR" },
1028 { "SPKR", "IN1RP Switch", "IN1RP" },
Mark Brown39cca162011-04-08 16:32:16 +09001029 { "SPKR", "Output Switch", "Right Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001030 { "SPKR", NULL, "TOCLK" },
1031
1032 { "SPKL Boost", "Direct Voice Switch", "Direct Voice" },
1033 { "SPKL Boost", "SPKL Switch", "SPKL" },
1034 { "SPKL Boost", "SPKR Switch", "SPKR" },
1035
1036 { "SPKR Boost", "Direct Voice Switch", "Direct Voice" },
1037 { "SPKR Boost", "SPKR Switch", "SPKR" },
1038 { "SPKR Boost", "SPKL Switch", "SPKL" },
1039
Mark Brown4e04ada2011-07-15 15:12:31 +09001040 { "SPKL Driver", NULL, "VMID" },
Mark Browna2342ae2009-07-29 21:21:49 +01001041 { "SPKL Driver", NULL, "SPKL Boost" },
1042 { "SPKL Driver", NULL, "CLK_SYS" },
Mark Brown03431972011-11-04 17:11:54 +00001043 { "SPKL Driver", NULL, "TSHUT" },
Mark Browna2342ae2009-07-29 21:21:49 +01001044
Mark Brown4e04ada2011-07-15 15:12:31 +09001045 { "SPKR Driver", NULL, "VMID" },
Mark Browna2342ae2009-07-29 21:21:49 +01001046 { "SPKR Driver", NULL, "SPKR Boost" },
1047 { "SPKR Driver", NULL, "CLK_SYS" },
Mark Brown03431972011-11-04 17:11:54 +00001048 { "SPKR Driver", NULL, "TSHUT" },
Mark Browna2342ae2009-07-29 21:21:49 +01001049
1050 { "SPKOUTLP", NULL, "SPKL Driver" },
1051 { "SPKOUTLN", NULL, "SPKL Driver" },
1052 { "SPKOUTRP", NULL, "SPKR Driver" },
1053 { "SPKOUTRN", NULL, "SPKR Driver" },
1054
Mark Brown39cca162011-04-08 16:32:16 +09001055 { "Left Headphone Mux", "Mixer", "Left Output PGA" },
1056 { "Right Headphone Mux", "Mixer", "Right Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001057
1058 { "Headphone PGA", NULL, "Left Headphone Mux" },
1059 { "Headphone PGA", NULL, "Right Headphone Mux" },
Mark Brown4e04ada2011-07-15 15:12:31 +09001060 { "Headphone PGA", NULL, "VMID" },
Mark Browna2342ae2009-07-29 21:21:49 +01001061 { "Headphone PGA", NULL, "CLK_SYS" },
Mark Brown3ed70742010-01-20 17:39:45 +00001062 { "Headphone PGA", NULL, "Headphone Supply" },
Mark Browna2342ae2009-07-29 21:21:49 +01001063
1064 { "HPOUT1L", NULL, "Headphone PGA" },
1065 { "HPOUT1R", NULL, "Headphone PGA" },
1066
Mark Brown4e04ada2011-07-15 15:12:31 +09001067 { "LINEOUT1N Driver", NULL, "VMID" },
1068 { "LINEOUT1P Driver", NULL, "VMID" },
1069 { "LINEOUT2N Driver", NULL, "VMID" },
1070 { "LINEOUT2P Driver", NULL, "VMID" },
1071
Mark Browna2342ae2009-07-29 21:21:49 +01001072 { "LINEOUT1N", NULL, "LINEOUT1N Driver" },
1073 { "LINEOUT1P", NULL, "LINEOUT1P Driver" },
1074 { "LINEOUT2N", NULL, "LINEOUT2N Driver" },
1075 { "LINEOUT2P", NULL, "LINEOUT2P Driver" },
1076};
1077
1078static const struct snd_soc_dapm_route lineout1_diff_routes[] = {
1079 { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" },
1080 { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" },
Mark Brownd0b48af2011-05-14 17:21:28 -07001081 { "LINEOUT1 Mixer", "Output Switch", "Left Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001082
1083 { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" },
1084 { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" },
1085};
1086
1087static const struct snd_soc_dapm_route lineout1_se_routes[] = {
Mark Brownd0b48af2011-05-14 17:21:28 -07001088 { "LINEOUT1N Mixer", "Left Output Switch", "Left Output PGA" },
1089 { "LINEOUT1N Mixer", "Right Output Switch", "Right Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001090
Mark Brownd0b48af2011-05-14 17:21:28 -07001091 { "LINEOUT1P Mixer", "Left Output Switch", "Left Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001092
1093 { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" },
1094 { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" },
1095};
1096
1097static const struct snd_soc_dapm_route lineout2_diff_routes[] = {
Mark Brownee767442012-01-31 11:55:32 +00001098 { "LINEOUT2 Mixer", "IN1L Switch", "IN1L PGA" },
1099 { "LINEOUT2 Mixer", "IN1R Switch", "IN1R PGA" },
Mark Brownd0b48af2011-05-14 17:21:28 -07001100 { "LINEOUT2 Mixer", "Output Switch", "Right Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001101
1102 { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" },
1103 { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" },
1104};
1105
1106static const struct snd_soc_dapm_route lineout2_se_routes[] = {
Mark Brownd0b48af2011-05-14 17:21:28 -07001107 { "LINEOUT2N Mixer", "Left Output Switch", "Left Output PGA" },
1108 { "LINEOUT2N Mixer", "Right Output Switch", "Right Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001109
Mark Brownd0b48af2011-05-14 17:21:28 -07001110 { "LINEOUT2P Mixer", "Right Output Switch", "Right Output PGA" },
Mark Browna2342ae2009-07-29 21:21:49 +01001111
1112 { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" },
1113 { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" },
1114};
1115
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001116int wm_hubs_add_analogue_controls(struct snd_soc_component *component)
Mark Browna2342ae2009-07-29 21:21:49 +01001117{
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001118 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001119
Mark Browna2342ae2009-07-29 21:21:49 +01001120 /* Latch volume update bits & default ZC on */
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001121 snd_soc_component_update_bits(component, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
Mark Browna2342ae2009-07-29 21:21:49 +01001122 WM8993_IN1_VU, WM8993_IN1_VU);
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001123 snd_soc_component_update_bits(component, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME,
Mark Browna2342ae2009-07-29 21:21:49 +01001124 WM8993_IN1_VU, WM8993_IN1_VU);
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001125 snd_soc_component_update_bits(component, WM8993_LEFT_LINE_INPUT_3_4_VOLUME,
Mark Browna2342ae2009-07-29 21:21:49 +01001126 WM8993_IN2_VU, WM8993_IN2_VU);
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001127 snd_soc_component_update_bits(component, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME,
Mark Browna2342ae2009-07-29 21:21:49 +01001128 WM8993_IN2_VU, WM8993_IN2_VU);
1129
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001130 snd_soc_component_update_bits(component, WM8993_SPEAKER_VOLUME_LEFT,
Mark Brownfb5af532011-05-15 12:18:38 -07001131 WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001132 snd_soc_component_update_bits(component, WM8993_SPEAKER_VOLUME_RIGHT,
Mark Browna2342ae2009-07-29 21:21:49 +01001133 WM8993_SPKOUT_VU, WM8993_SPKOUT_VU);
1134
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001135 snd_soc_component_update_bits(component, WM8993_LEFT_OUTPUT_VOLUME,
Mark Brownfb5af532011-05-15 12:18:38 -07001136 WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC,
1137 WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC);
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001138 snd_soc_component_update_bits(component, WM8993_RIGHT_OUTPUT_VOLUME,
Mark Browna2342ae2009-07-29 21:21:49 +01001139 WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC,
1140 WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC);
1141
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001142 snd_soc_component_update_bits(component, WM8993_LEFT_OPGA_VOLUME,
Mark Brownfb5af532011-05-15 12:18:38 -07001143 WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU,
1144 WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU);
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001145 snd_soc_component_update_bits(component, WM8993_RIGHT_OPGA_VOLUME,
Mark Browna2342ae2009-07-29 21:21:49 +01001146 WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU,
1147 WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU);
1148
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001149 snd_soc_add_component_controls(component, analogue_snd_controls,
Mark Browna2342ae2009-07-29 21:21:49 +01001150 ARRAY_SIZE(analogue_snd_controls));
1151
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001152 snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets,
Mark Browna2342ae2009-07-29 21:21:49 +01001153 ARRAY_SIZE(analogue_dapm_widgets));
1154 return 0;
1155}
1156EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls);
1157
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001158int wm_hubs_add_analogue_routes(struct snd_soc_component *component,
Mark Browna2342ae2009-07-29 21:21:49 +01001159 int lineout1_diff, int lineout2_diff)
1160{
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001161 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
1162 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001163
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001164 hubs->component = component;
Mark Brown8cb8e832012-07-25 18:10:03 +01001165
Mark Brown94aa7332012-05-01 18:45:09 +01001166 INIT_LIST_HEAD(&hubs->dcs_cache);
Mark Brownd96ca3c2011-07-12 15:25:03 +09001167 init_completion(&hubs->dcs_done);
1168
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001169 snd_soc_dapm_add_routes(dapm, analogue_routes,
Mark Browna2342ae2009-07-29 21:21:49 +01001170 ARRAY_SIZE(analogue_routes));
1171
1172 if (lineout1_diff)
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001173 snd_soc_dapm_add_routes(dapm,
Mark Browna2342ae2009-07-29 21:21:49 +01001174 lineout1_diff_routes,
1175 ARRAY_SIZE(lineout1_diff_routes));
1176 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001177 snd_soc_dapm_add_routes(dapm,
Mark Browna2342ae2009-07-29 21:21:49 +01001178 lineout1_se_routes,
1179 ARRAY_SIZE(lineout1_se_routes));
1180
1181 if (lineout2_diff)
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001182 snd_soc_dapm_add_routes(dapm,
Mark Browna2342ae2009-07-29 21:21:49 +01001183 lineout2_diff_routes,
1184 ARRAY_SIZE(lineout2_diff_routes));
1185 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001186 snd_soc_dapm_add_routes(dapm,
Mark Browna2342ae2009-07-29 21:21:49 +01001187 lineout2_se_routes,
1188 ARRAY_SIZE(lineout2_se_routes));
1189
1190 return 0;
1191}
1192EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes);
1193
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001194int wm_hubs_handle_analogue_pdata(struct snd_soc_component *component,
Mark Brownaa983d92009-09-30 14:16:11 +01001195 int lineout1_diff, int lineout2_diff,
1196 int lineout1fb, int lineout2fb,
Mark Brown02e79472012-08-21 17:54:52 +01001197 int jd_scthr, int jd_thr,
1198 int micbias1_delay, int micbias2_delay,
1199 int micbias1_lvl, int micbias2_lvl)
Mark Brownaa983d92009-09-30 14:16:11 +01001200{
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001201 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown5f2f3892012-02-08 18:51:42 +00001202
1203 hubs->lineout1_se = !lineout1_diff;
1204 hubs->lineout2_se = !lineout2_diff;
Mark Brown02e79472012-08-21 17:54:52 +01001205 hubs->micb1_delay = micbias1_delay;
1206 hubs->micb2_delay = micbias2_delay;
Mark Brown5f2f3892012-02-08 18:51:42 +00001207
Mark Brownaa983d92009-09-30 14:16:11 +01001208 if (!lineout1_diff)
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001209 snd_soc_component_update_bits(component, WM8993_LINE_MIXER1,
Mark Brownaa983d92009-09-30 14:16:11 +01001210 WM8993_LINEOUT1_MODE,
1211 WM8993_LINEOUT1_MODE);
1212 if (!lineout2_diff)
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001213 snd_soc_component_update_bits(component, WM8993_LINE_MIXER2,
Mark Brownaa983d92009-09-30 14:16:11 +01001214 WM8993_LINEOUT2_MODE,
1215 WM8993_LINEOUT2_MODE);
1216
Mark Brown5472bbc2012-03-19 17:31:56 +00001217 if (!lineout1_diff && !lineout2_diff)
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001218 snd_soc_component_update_bits(component, WM8993_ANTIPOP1,
Mark Brown5472bbc2012-03-19 17:31:56 +00001219 WM8993_LINEOUT_VMID_BUF_ENA,
1220 WM8993_LINEOUT_VMID_BUF_ENA);
1221
Mark Brownaa983d92009-09-30 14:16:11 +01001222 if (lineout1fb)
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001223 snd_soc_component_update_bits(component, WM8993_ADDITIONAL_CONTROL,
Mark Brownaa983d92009-09-30 14:16:11 +01001224 WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
1225
1226 if (lineout2fb)
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001227 snd_soc_component_update_bits(component, WM8993_ADDITIONAL_CONTROL,
Mark Brownaa983d92009-09-30 14:16:11 +01001228 WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
1229
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001230 snd_soc_component_update_bits(component, WM8993_MICBIAS,
Mark Brownaa983d92009-09-30 14:16:11 +01001231 WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
1232 WM8993_MICB1_LVL | WM8993_MICB2_LVL,
1233 jd_scthr << WM8993_JD_SCTHR_SHIFT |
1234 jd_thr << WM8993_JD_THR_SHIFT |
1235 micbias1_lvl |
1236 micbias2_lvl << WM8993_MICB2_LVL_SHIFT);
1237
1238 return 0;
1239}
1240EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata);
1241
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001242void wm_hubs_vmid_ena(struct snd_soc_component *component)
Mark Brown5f2f3892012-02-08 18:51:42 +00001243{
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001244 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brown5f2f3892012-02-08 18:51:42 +00001245 int val = 0;
1246
1247 if (hubs->lineout1_se)
1248 val |= WM8993_LINEOUT1N_ENA | WM8993_LINEOUT1P_ENA;
1249
1250 if (hubs->lineout2_se)
1251 val |= WM8993_LINEOUT2N_ENA | WM8993_LINEOUT2P_ENA;
1252
1253 /* Enable the line outputs while we power up */
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001254 snd_soc_component_update_bits(component, WM8993_POWER_MANAGEMENT_3, val, val);
Mark Brown5f2f3892012-02-08 18:51:42 +00001255}
1256EXPORT_SYMBOL_GPL(wm_hubs_vmid_ena);
1257
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001258void wm_hubs_set_bias_level(struct snd_soc_component *component,
Mark Brown5f2f3892012-02-08 18:51:42 +00001259 enum snd_soc_bias_level level)
1260{
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001261 struct wm_hubs_data *hubs = snd_soc_component_get_drvdata(component);
Mark Brownde050ac2012-04-17 20:28:10 +01001262 int mask, val;
Mark Brown5f2f3892012-02-08 18:51:42 +00001263
1264 switch (level) {
Mark Brownd60d6c32012-02-10 18:09:42 +00001265 case SND_SOC_BIAS_STANDBY:
1266 /* Clamp the inputs to VMID while we ramp to charge caps */
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001267 snd_soc_component_update_bits(component, WM8993_INPUTS_CLAMP_REG,
Mark Brownd60d6c32012-02-10 18:09:42 +00001268 WM8993_INPUTS_CLAMP, WM8993_INPUTS_CLAMP);
1269 break;
1270
Mark Brown5f2f3892012-02-08 18:51:42 +00001271 case SND_SOC_BIAS_ON:
Masahiro Yamada4d39f0a2017-02-27 14:29:17 -08001272 /* Turn off any unneeded single ended outputs */
Mark Brown5f2f3892012-02-08 18:51:42 +00001273 val = 0;
Mark Brownde050ac2012-04-17 20:28:10 +01001274 mask = 0;
1275
1276 if (hubs->lineout1_se)
1277 mask |= WM8993_LINEOUT1N_ENA | WM8993_LINEOUT1P_ENA;
1278
1279 if (hubs->lineout2_se)
1280 mask |= WM8993_LINEOUT2N_ENA | WM8993_LINEOUT2P_ENA;
Mark Brown5f2f3892012-02-08 18:51:42 +00001281
1282 if (hubs->lineout1_se && hubs->lineout1n_ena)
1283 val |= WM8993_LINEOUT1N_ENA;
1284
1285 if (hubs->lineout1_se && hubs->lineout1p_ena)
1286 val |= WM8993_LINEOUT1P_ENA;
1287
1288 if (hubs->lineout2_se && hubs->lineout2n_ena)
1289 val |= WM8993_LINEOUT2N_ENA;
1290
1291 if (hubs->lineout2_se && hubs->lineout2p_ena)
1292 val |= WM8993_LINEOUT2P_ENA;
1293
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001294 snd_soc_component_update_bits(component, WM8993_POWER_MANAGEMENT_3,
Mark Brownde050ac2012-04-17 20:28:10 +01001295 mask, val);
Mark Brown5f2f3892012-02-08 18:51:42 +00001296
Mark Brownd60d6c32012-02-10 18:09:42 +00001297 /* Remove the input clamps */
Kuninori Morimoto00a69412018-01-29 03:12:21 +00001298 snd_soc_component_update_bits(component, WM8993_INPUTS_CLAMP_REG,
Mark Brownd60d6c32012-02-10 18:09:42 +00001299 WM8993_INPUTS_CLAMP, 0);
Mark Brown5f2f3892012-02-08 18:51:42 +00001300 break;
1301
1302 default:
1303 break;
1304 }
1305}
1306EXPORT_SYMBOL_GPL(wm_hubs_set_bias_level);
1307
Mark Browna2342ae2009-07-29 21:21:49 +01001308MODULE_DESCRIPTION("Shared support for Wolfson hubs products");
1309MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1310MODULE_LICENSE("GPL");