1 // SPDX-License-Identifier: GPL-2.0-only
3 * 88pm860x-codec.c -- 88PM860x ALSA SoC Audio Driver
5 * Copyright 2010 Marvell International Ltd.
6 * Author: Haojian Zhuang <haojian.zhuang@marvell.com>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/i2c.h>
12 #include <linux/platform_device.h>
13 #include <linux/mfd/88pm860x.h>
14 #include <linux/slab.h>
15 #include <linux/delay.h>
16 #include <linux/regmap.h>
17 #include <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include <sound/soc.h>
21 #include <sound/tlv.h>
22 #include <sound/initval.h>
23 #include <sound/jack.h>
24 #include <trace/events/asoc.h>
26 #include "88pm860x-codec.h"
28 #define MAX_NAME_LEN 20
29 #define REG_CACHE_SIZE 0x40
30 #define REG_CACHE_BASE 0xb0
32 /* Status Register 1 (0x01) */
33 #define REG_STATUS_1 0x01
34 #define MIC_STATUS (1 << 7)
35 #define HOOK_STATUS (1 << 6)
36 #define HEADSET_STATUS (1 << 5)
38 /* Mic Detection Register (0x37) */
39 #define REG_MIC_DET 0x37
40 #define CONTINUOUS_POLLING (3 << 1)
41 #define EN_MIC_DET (1 << 0)
42 #define MICDET_MASK 0x07
44 /* Headset Detection Register (0x38) */
45 #define REG_HS_DET 0x38
46 #define EN_HS_DET (1 << 0)
48 /* Misc2 Register (0x42) */
49 #define REG_MISC2 0x42
50 #define AUDIO_PLL (1 << 5)
51 #define AUDIO_SECTION_RESET (1 << 4)
52 #define AUDIO_SECTION_ON (1 << 3)
54 /* PCM Interface Register 2 (0xb1) */
55 #define PCM_INF2_BCLK (1 << 6) /* Bit clock polarity */
56 #define PCM_INF2_FS (1 << 5) /* Frame Sync polarity */
57 #define PCM_INF2_MASTER (1 << 4) /* Master / Slave */
58 #define PCM_INF2_18WL (1 << 3) /* 18 / 16 bits */
59 #define PCM_GENERAL_I2S 0
60 #define PCM_EXACT_I2S 1
61 #define PCM_LEFT_I2S 2
62 #define PCM_RIGHT_I2S 3
63 #define PCM_SHORT_FS 4
65 #define PCM_MODE_MASK 7
67 /* I2S Interface Register 4 (0xbe) */
68 #define I2S_EQU_BYP (1 << 6)
70 /* DAC Offset Register (0xcb) */
71 #define DAC_MUTE (1 << 7)
72 #define MUTE_LEFT (1 << 6)
73 #define MUTE_RIGHT (1 << 2)
75 /* ADC Analog Register 1 (0xd0) */
76 #define REG_ADC_ANA_1 0xd0
77 #define MIC1BIAS_MASK 0x60
79 /* Earpiece/Speaker Control Register 2 (0xda) */
81 #define RSYNC_CHANGE (1 << 2)
83 /* Audio Supplies Register 2 (0xdc) */
84 #define REG_SUPPLIES2 0xdc
85 #define LDO15_READY (1 << 4)
86 #define LDO15_EN (1 << 3)
87 #define CPUMP_READY (1 << 2)
88 #define CPUMP_EN (1 << 1)
89 #define AUDIO_EN (1 << 0)
90 #define SUPPLY_MASK (LDO15_EN | CPUMP_EN | AUDIO_EN)
92 /* Audio Enable Register 1 (0xdd) */
93 #define ADC_MOD_RIGHT (1 << 1)
94 #define ADC_MOD_LEFT (1 << 0)
96 /* Audio Enable Register 2 (0xde) */
97 #define ADC_LEFT (1 << 5)
98 #define ADC_RIGHT (1 << 4)
100 /* DAC Enable Register 2 (0xe1) */
101 #define DAC_LEFT (1 << 5)
102 #define DAC_RIGHT (1 << 4)
103 #define MODULATOR (1 << 3)
105 /* Shorts Register (0xeb) */
106 #define REG_SHORTS 0xeb
107 #define CLR_SHORT_LO2 (1 << 7)
108 #define SHORT_LO2 (1 << 6)
109 #define CLR_SHORT_LO1 (1 << 5)
110 #define SHORT_LO1 (1 << 4)
111 #define CLR_SHORT_HS2 (1 << 3)
112 #define SHORT_HS2 (1 << 2)
113 #define CLR_SHORT_HS1 (1 << 1)
114 #define SHORT_HS1 (1 << 0)
117 * This widget should be just after DAC & PGA in DAPM power-on sequence and
118 * before DAC & PGA in DAPM power-off sequence.
120 #define PM860X_DAPM_OUTPUT(wname, wevent) \
121 SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, 0, 0, NULL, 0, wevent, \
122 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD)
125 struct snd_soc_jack *hp_jack;
126 struct snd_soc_jack *mic_jack;
139 struct snd_soc_component *component;
140 struct i2c_client *i2c;
141 struct regmap *regmap;
142 struct pm860x_chip *chip;
143 struct pm860x_det det;
146 unsigned char name[4][MAX_NAME_LEN+1];
149 /* -9450dB to 0dB in 150dB steps ( mute instead of -9450dB) */
150 static const DECLARE_TLV_DB_SCALE(dpga_tlv, -9450, 150, 1);
152 /* -9dB to 0db in 3dB steps */
153 static const DECLARE_TLV_DB_SCALE(adc_tlv, -900, 300, 0);
155 /* {-23, -17, -13.5, -11, -9, -6, -3, 0}dB */
156 static const DECLARE_TLV_DB_RANGE(mic_tlv,
157 0, 0, TLV_DB_SCALE_ITEM(-2300, 0, 0),
158 1, 1, TLV_DB_SCALE_ITEM(-1700, 0, 0),
159 2, 2, TLV_DB_SCALE_ITEM(-1350, 0, 0),
160 3, 3, TLV_DB_SCALE_ITEM(-1100, 0, 0),
161 4, 7, TLV_DB_SCALE_ITEM(-900, 300, 0)
164 /* {0, 0, 0, -6, 0, 6, 12, 18}dB */
165 static const DECLARE_TLV_DB_RANGE(aux_tlv,
166 0, 2, TLV_DB_SCALE_ITEM(0, 0, 0),
167 3, 7, TLV_DB_SCALE_ITEM(-600, 600, 0)
170 /* {-16, -13, -10, -7, -5.2, -3,3, -2.2, 0}dB, mute instead of -16dB */
171 static const DECLARE_TLV_DB_RANGE(out_tlv,
172 0, 3, TLV_DB_SCALE_ITEM(-1600, 300, 1),
173 4, 4, TLV_DB_SCALE_ITEM(-520, 0, 0),
174 5, 5, TLV_DB_SCALE_ITEM(-330, 0, 0),
175 6, 7, TLV_DB_SCALE_ITEM(-220, 220, 0)
178 static const DECLARE_TLV_DB_RANGE(st_tlv,
179 0, 1, TLV_DB_SCALE_ITEM(-12041, 602, 0),
180 2, 3, TLV_DB_SCALE_ITEM(-11087, 250, 0),
181 4, 5, TLV_DB_SCALE_ITEM(-10643, 158, 0),
182 6, 7, TLV_DB_SCALE_ITEM(-10351, 116, 0),
183 8, 9, TLV_DB_SCALE_ITEM(-10133, 92, 0),
184 10, 13, TLV_DB_SCALE_ITEM(-9958, 70, 0),
185 14, 17, TLV_DB_SCALE_ITEM(-9689, 53, 0),
186 18, 271, TLV_DB_SCALE_ITEM(-9484, 37, 0)
189 /* Sidetone Gain = M * 2^(-5-N) */
196 static struct st_gain st_table[] = {
197 {-12041, 1, 15}, {-11439, 1, 14}, {-11087, 3, 15}, {-10837, 1, 13},
198 {-10643, 5, 15}, {-10485, 3, 14}, {-10351, 7, 15}, {-10235, 1, 12},
199 {-10133, 9, 15}, {-10041, 5, 14}, { -9958, 11, 15}, { -9883, 3, 13},
200 { -9813, 13, 15}, { -9749, 7, 14}, { -9689, 15, 15}, { -9633, 1, 11},
201 { -9580, 17, 15}, { -9531, 9, 14}, { -9484, 19, 15}, { -9439, 5, 13},
202 { -9397, 21, 15}, { -9356, 11, 14}, { -9318, 23, 15}, { -9281, 3, 12},
203 { -9245, 25, 15}, { -9211, 13, 14}, { -9178, 27, 15}, { -9147, 7, 13},
204 { -9116, 29, 15}, { -9087, 15, 14}, { -9058, 31, 15}, { -9031, 1, 10},
205 { -8978, 17, 14}, { -8929, 9, 13}, { -8882, 19, 14}, { -8837, 5, 12},
206 { -8795, 21, 14}, { -8754, 11, 13}, { -8716, 23, 14}, { -8679, 3, 11},
207 { -8643, 25, 14}, { -8609, 13, 13}, { -8576, 27, 14}, { -8545, 7, 12},
208 { -8514, 29, 14}, { -8485, 15, 13}, { -8456, 31, 14}, { -8429, 1, 9},
209 { -8376, 17, 13}, { -8327, 9, 12}, { -8280, 19, 13}, { -8235, 5, 11},
210 { -8193, 21, 13}, { -8152, 11, 12}, { -8114, 23, 13}, { -8077, 3, 10},
211 { -8041, 25, 13}, { -8007, 13, 12}, { -7974, 27, 13}, { -7943, 7, 11},
212 { -7912, 29, 13}, { -7883, 15, 12}, { -7854, 31, 13}, { -7827, 1, 8},
213 { -7774, 17, 12}, { -7724, 9, 11}, { -7678, 19, 12}, { -7633, 5, 10},
214 { -7591, 21, 12}, { -7550, 11, 11}, { -7512, 23, 12}, { -7475, 3, 9},
215 { -7439, 25, 12}, { -7405, 13, 11}, { -7372, 27, 12}, { -7341, 7, 10},
216 { -7310, 29, 12}, { -7281, 15, 11}, { -7252, 31, 12}, { -7225, 1, 7},
217 { -7172, 17, 11}, { -7122, 9, 10}, { -7075, 19, 11}, { -7031, 5, 9},
218 { -6989, 21, 11}, { -6948, 11, 10}, { -6910, 23, 11}, { -6873, 3, 8},
219 { -6837, 25, 11}, { -6803, 13, 10}, { -6770, 27, 11}, { -6739, 7, 9},
220 { -6708, 29, 11}, { -6679, 15, 10}, { -6650, 31, 11}, { -6623, 1, 6},
221 { -6570, 17, 10}, { -6520, 9, 9}, { -6473, 19, 10}, { -6429, 5, 8},
222 { -6386, 21, 10}, { -6346, 11, 9}, { -6307, 23, 10}, { -6270, 3, 7},
223 { -6235, 25, 10}, { -6201, 13, 9}, { -6168, 27, 10}, { -6137, 7, 8},
224 { -6106, 29, 10}, { -6077, 15, 9}, { -6048, 31, 10}, { -6021, 1, 5},
225 { -5968, 17, 9}, { -5918, 9, 8}, { -5871, 19, 9}, { -5827, 5, 7},
226 { -5784, 21, 9}, { -5744, 11, 8}, { -5705, 23, 9}, { -5668, 3, 6},
227 { -5633, 25, 9}, { -5599, 13, 8}, { -5566, 27, 9}, { -5535, 7, 7},
228 { -5504, 29, 9}, { -5475, 15, 8}, { -5446, 31, 9}, { -5419, 1, 4},
229 { -5366, 17, 8}, { -5316, 9, 7}, { -5269, 19, 8}, { -5225, 5, 6},
230 { -5182, 21, 8}, { -5142, 11, 7}, { -5103, 23, 8}, { -5066, 3, 5},
231 { -5031, 25, 8}, { -4997, 13, 7}, { -4964, 27, 8}, { -4932, 7, 6},
232 { -4902, 29, 8}, { -4873, 15, 7}, { -4844, 31, 8}, { -4816, 1, 3},
233 { -4764, 17, 7}, { -4714, 9, 6}, { -4667, 19, 7}, { -4623, 5, 5},
234 { -4580, 21, 7}, { -4540, 11, 6}, { -4501, 23, 7}, { -4464, 3, 4},
235 { -4429, 25, 7}, { -4395, 13, 6}, { -4362, 27, 7}, { -4330, 7, 5},
236 { -4300, 29, 7}, { -4270, 15, 6}, { -4242, 31, 7}, { -4214, 1, 2},
237 { -4162, 17, 6}, { -4112, 9, 5}, { -4065, 19, 6}, { -4021, 5, 4},
238 { -3978, 21, 6}, { -3938, 11, 5}, { -3899, 23, 6}, { -3862, 3, 3},
239 { -3827, 25, 6}, { -3793, 13, 5}, { -3760, 27, 6}, { -3728, 7, 4},
240 { -3698, 29, 6}, { -3668, 15, 5}, { -3640, 31, 6}, { -3612, 1, 1},
241 { -3560, 17, 5}, { -3510, 9, 4}, { -3463, 19, 5}, { -3419, 5, 3},
242 { -3376, 21, 5}, { -3336, 11, 4}, { -3297, 23, 5}, { -3260, 3, 2},
243 { -3225, 25, 5}, { -3191, 13, 4}, { -3158, 27, 5}, { -3126, 7, 3},
244 { -3096, 29, 5}, { -3066, 15, 4}, { -3038, 31, 5}, { -3010, 1, 0},
245 { -2958, 17, 4}, { -2908, 9, 3}, { -2861, 19, 4}, { -2816, 5, 2},
246 { -2774, 21, 4}, { -2734, 11, 3}, { -2695, 23, 4}, { -2658, 3, 1},
247 { -2623, 25, 4}, { -2589, 13, 3}, { -2556, 27, 4}, { -2524, 7, 2},
248 { -2494, 29, 4}, { -2464, 15, 3}, { -2436, 31, 4}, { -2408, 2, 0},
249 { -2356, 17, 3}, { -2306, 9, 2}, { -2259, 19, 3}, { -2214, 5, 1},
250 { -2172, 21, 3}, { -2132, 11, 2}, { -2093, 23, 3}, { -2056, 3, 0},
251 { -2021, 25, 3}, { -1987, 13, 2}, { -1954, 27, 3}, { -1922, 7, 1},
252 { -1892, 29, 3}, { -1862, 15, 2}, { -1834, 31, 3}, { -1806, 4, 0},
253 { -1754, 17, 2}, { -1704, 9, 1}, { -1657, 19, 2}, { -1612, 5, 0},
254 { -1570, 21, 2}, { -1530, 11, 1}, { -1491, 23, 2}, { -1454, 6, 0},
255 { -1419, 25, 2}, { -1384, 13, 1}, { -1352, 27, 2}, { -1320, 7, 0},
256 { -1290, 29, 2}, { -1260, 15, 1}, { -1232, 31, 2}, { -1204, 8, 0},
257 { -1151, 17, 1}, { -1102, 9, 0}, { -1055, 19, 1}, { -1010, 10, 0},
258 { -968, 21, 1}, { -928, 11, 0}, { -889, 23, 1}, { -852, 12, 0},
259 { -816, 25, 1}, { -782, 13, 0}, { -750, 27, 1}, { -718, 14, 0},
260 { -688, 29, 1}, { -658, 15, 0}, { -630, 31, 1}, { -602, 16, 0},
261 { -549, 17, 0}, { -500, 18, 0}, { -453, 19, 0}, { -408, 20, 0},
262 { -366, 21, 0}, { -325, 22, 0}, { -287, 23, 0}, { -250, 24, 0},
263 { -214, 25, 0}, { -180, 26, 0}, { -148, 27, 0}, { -116, 28, 0},
264 { -86, 29, 0}, { -56, 30, 0}, { -28, 31, 0}, { 0, 0, 0},
267 static int snd_soc_get_volsw_2r_st(struct snd_kcontrol *kcontrol,
268 struct snd_ctl_elem_value *ucontrol)
270 struct soc_mixer_control *mc =
271 (struct soc_mixer_control *)kcontrol->private_value;
272 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
273 unsigned int reg = mc->reg;
274 unsigned int reg2 = mc->rreg;
275 int val[2], val2[2], i;
277 val[0] = snd_soc_component_read32(component, reg) & 0x3f;
278 val[1] = (snd_soc_component_read32(component, PM860X_SIDETONE_SHIFT) >> 4) & 0xf;
279 val2[0] = snd_soc_component_read32(component, reg2) & 0x3f;
280 val2[1] = (snd_soc_component_read32(component, PM860X_SIDETONE_SHIFT)) & 0xf;
282 for (i = 0; i < ARRAY_SIZE(st_table); i++) {
283 if ((st_table[i].m == val[0]) && (st_table[i].n == val[1]))
284 ucontrol->value.integer.value[0] = i;
285 if ((st_table[i].m == val2[0]) && (st_table[i].n == val2[1]))
286 ucontrol->value.integer.value[1] = i;
291 static int snd_soc_put_volsw_2r_st(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
294 struct soc_mixer_control *mc =
295 (struct soc_mixer_control *)kcontrol->private_value;
296 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
297 unsigned int reg = mc->reg;
298 unsigned int reg2 = mc->rreg;
300 unsigned int val, val2;
302 val = ucontrol->value.integer.value[0];
303 val2 = ucontrol->value.integer.value[1];
305 if (val >= ARRAY_SIZE(st_table) || val2 >= ARRAY_SIZE(st_table))
308 err = snd_soc_component_update_bits(component, reg, 0x3f, st_table[val].m);
311 err = snd_soc_component_update_bits(component, PM860X_SIDETONE_SHIFT, 0xf0,
312 st_table[val].n << 4);
316 err = snd_soc_component_update_bits(component, reg2, 0x3f, st_table[val2].m);
319 err = snd_soc_component_update_bits(component, PM860X_SIDETONE_SHIFT, 0x0f,
324 static int snd_soc_get_volsw_2r_out(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
327 struct soc_mixer_control *mc =
328 (struct soc_mixer_control *)kcontrol->private_value;
329 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
330 unsigned int reg = mc->reg;
331 unsigned int reg2 = mc->rreg;
332 unsigned int shift = mc->shift;
333 int max = mc->max, val, val2;
334 unsigned int mask = (1 << fls(max)) - 1;
336 val = snd_soc_component_read32(component, reg) >> shift;
337 val2 = snd_soc_component_read32(component, reg2) >> shift;
338 ucontrol->value.integer.value[0] = (max - val) & mask;
339 ucontrol->value.integer.value[1] = (max - val2) & mask;
344 static int snd_soc_put_volsw_2r_out(struct snd_kcontrol *kcontrol,
345 struct snd_ctl_elem_value *ucontrol)
347 struct soc_mixer_control *mc =
348 (struct soc_mixer_control *)kcontrol->private_value;
349 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
350 unsigned int reg = mc->reg;
351 unsigned int reg2 = mc->rreg;
352 unsigned int shift = mc->shift;
354 unsigned int mask = (1 << fls(max)) - 1;
356 unsigned int val, val2, val_mask;
358 val_mask = mask << shift;
359 val = ((max - ucontrol->value.integer.value[0]) & mask);
360 val2 = ((max - ucontrol->value.integer.value[1]) & mask);
363 val2 = val2 << shift;
365 err = snd_soc_component_update_bits(component, reg, val_mask, val);
369 err = snd_soc_component_update_bits(component, reg2, val_mask, val2);
373 /* DAPM Widget Events */
375 * A lot registers are belong to RSYNC domain. It requires enabling RSYNC bit
376 * after updating these registers. Otherwise, these updated registers won't
379 static int pm860x_rsync_event(struct snd_soc_dapm_widget *w,
380 struct snd_kcontrol *kcontrol, int event)
382 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
385 * In order to avoid current on the load, mute power-on and power-off
386 * should be transients.
387 * Unmute by DAC_MUTE. It should be unmuted when DAPM sequence is
390 snd_soc_component_update_bits(component, PM860X_DAC_OFFSET, DAC_MUTE, 0);
391 snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
392 RSYNC_CHANGE, RSYNC_CHANGE);
396 static int pm860x_dac_event(struct snd_soc_dapm_widget *w,
397 struct snd_kcontrol *kcontrol, int event)
399 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
400 unsigned int dac = 0;
403 if (!strcmp(w->name, "Left DAC"))
405 if (!strcmp(w->name, "Right DAC"))
408 case SND_SOC_DAPM_PRE_PMU:
410 /* Auto mute in power-on sequence. */
412 snd_soc_component_update_bits(component, PM860X_DAC_OFFSET,
414 snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
415 RSYNC_CHANGE, RSYNC_CHANGE);
417 snd_soc_component_update_bits(component, PM860X_DAC_EN_2,
421 case SND_SOC_DAPM_PRE_PMD:
423 /* Auto mute in power-off sequence. */
424 snd_soc_component_update_bits(component, PM860X_DAC_OFFSET,
426 snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
427 RSYNC_CHANGE, RSYNC_CHANGE);
429 data = snd_soc_component_read32(component, PM860X_DAC_EN_2);
431 if (!(data & (DAC_LEFT | DAC_RIGHT)))
433 snd_soc_component_write(component, PM860X_DAC_EN_2, data);
440 static const char *pm860x_opamp_texts[] = {"-50%", "-25%", "0%", "75%"};
442 static const char *pm860x_pa_texts[] = {"-33%", "0%", "33%", "66%"};
444 static SOC_ENUM_SINGLE_DECL(pm860x_hs1_opamp_enum,
445 PM860X_HS1_CTRL, 5, pm860x_opamp_texts);
447 static SOC_ENUM_SINGLE_DECL(pm860x_hs2_opamp_enum,
448 PM860X_HS2_CTRL, 5, pm860x_opamp_texts);
450 static SOC_ENUM_SINGLE_DECL(pm860x_hs1_pa_enum,
451 PM860X_HS1_CTRL, 3, pm860x_pa_texts);
453 static SOC_ENUM_SINGLE_DECL(pm860x_hs2_pa_enum,
454 PM860X_HS2_CTRL, 3, pm860x_pa_texts);
456 static SOC_ENUM_SINGLE_DECL(pm860x_lo1_opamp_enum,
457 PM860X_LO1_CTRL, 5, pm860x_opamp_texts);
459 static SOC_ENUM_SINGLE_DECL(pm860x_lo2_opamp_enum,
460 PM860X_LO2_CTRL, 5, pm860x_opamp_texts);
462 static SOC_ENUM_SINGLE_DECL(pm860x_lo1_pa_enum,
463 PM860X_LO1_CTRL, 3, pm860x_pa_texts);
465 static SOC_ENUM_SINGLE_DECL(pm860x_lo2_pa_enum,
466 PM860X_LO2_CTRL, 3, pm860x_pa_texts);
468 static SOC_ENUM_SINGLE_DECL(pm860x_spk_pa_enum,
469 PM860X_EAR_CTRL_1, 5, pm860x_pa_texts);
471 static SOC_ENUM_SINGLE_DECL(pm860x_ear_pa_enum,
472 PM860X_EAR_CTRL_2, 0, pm860x_pa_texts);
474 static SOC_ENUM_SINGLE_DECL(pm860x_spk_ear_opamp_enum,
475 PM860X_EAR_CTRL_1, 3, pm860x_opamp_texts);
477 static const struct snd_kcontrol_new pm860x_snd_controls[] = {
478 SOC_DOUBLE_R_TLV("ADC Capture Volume", PM860X_ADC_ANA_2,
479 PM860X_ADC_ANA_3, 6, 3, 0, adc_tlv),
480 SOC_DOUBLE_TLV("AUX Capture Volume", PM860X_ADC_ANA_3, 0, 3, 7, 0,
482 SOC_SINGLE_TLV("MIC1 Capture Volume", PM860X_ADC_ANA_2, 0, 7, 0,
484 SOC_SINGLE_TLV("MIC3 Capture Volume", PM860X_ADC_ANA_2, 3, 7, 0,
486 SOC_DOUBLE_R_EXT_TLV("Sidetone Volume", PM860X_SIDETONE_L_GAIN,
487 PM860X_SIDETONE_R_GAIN, 0, ARRAY_SIZE(st_table)-1,
488 0, snd_soc_get_volsw_2r_st,
489 snd_soc_put_volsw_2r_st, st_tlv),
490 SOC_SINGLE_TLV("Speaker Playback Volume", PM860X_EAR_CTRL_1,
492 SOC_DOUBLE_R_TLV("Line Playback Volume", PM860X_LO1_CTRL,
493 PM860X_LO2_CTRL, 0, 7, 0, out_tlv),
494 SOC_DOUBLE_R_TLV("Headset Playback Volume", PM860X_HS1_CTRL,
495 PM860X_HS2_CTRL, 0, 7, 0, out_tlv),
496 SOC_DOUBLE_R_EXT_TLV("Hifi Left Playback Volume",
497 PM860X_HIFIL_GAIN_LEFT,
498 PM860X_HIFIL_GAIN_RIGHT, 0, 63, 0,
499 snd_soc_get_volsw_2r_out,
500 snd_soc_put_volsw_2r_out, dpga_tlv),
501 SOC_DOUBLE_R_EXT_TLV("Hifi Right Playback Volume",
502 PM860X_HIFIR_GAIN_LEFT,
503 PM860X_HIFIR_GAIN_RIGHT, 0, 63, 0,
504 snd_soc_get_volsw_2r_out,
505 snd_soc_put_volsw_2r_out, dpga_tlv),
506 SOC_DOUBLE_R_EXT_TLV("Lofi Playback Volume", PM860X_LOFI_GAIN_LEFT,
507 PM860X_LOFI_GAIN_RIGHT, 0, 63, 0,
508 snd_soc_get_volsw_2r_out,
509 snd_soc_put_volsw_2r_out, dpga_tlv),
510 SOC_ENUM("Headset1 Operational Amplifier Current",
511 pm860x_hs1_opamp_enum),
512 SOC_ENUM("Headset2 Operational Amplifier Current",
513 pm860x_hs2_opamp_enum),
514 SOC_ENUM("Headset1 Amplifier Current", pm860x_hs1_pa_enum),
515 SOC_ENUM("Headset2 Amplifier Current", pm860x_hs2_pa_enum),
516 SOC_ENUM("Lineout1 Operational Amplifier Current",
517 pm860x_lo1_opamp_enum),
518 SOC_ENUM("Lineout2 Operational Amplifier Current",
519 pm860x_lo2_opamp_enum),
520 SOC_ENUM("Lineout1 Amplifier Current", pm860x_lo1_pa_enum),
521 SOC_ENUM("Lineout2 Amplifier Current", pm860x_lo2_pa_enum),
522 SOC_ENUM("Speaker Operational Amplifier Current",
523 pm860x_spk_ear_opamp_enum),
524 SOC_ENUM("Speaker Amplifier Current", pm860x_spk_pa_enum),
525 SOC_ENUM("Earpiece Amplifier Current", pm860x_ear_pa_enum),
532 /* PCM Switch / PCM Interface */
533 static const struct snd_kcontrol_new pcm_switch_controls =
534 SOC_DAPM_SINGLE("Switch", PM860X_ADC_EN_2, 0, 1, 0);
537 static const struct snd_kcontrol_new aux1_switch_controls =
538 SOC_DAPM_SINGLE("Switch", PM860X_ANA_TO_ANA, 4, 1, 0);
541 static const struct snd_kcontrol_new aux2_switch_controls =
542 SOC_DAPM_SINGLE("Switch", PM860X_ANA_TO_ANA, 5, 1, 0);
544 /* Left Ex. PA Switch */
545 static const struct snd_kcontrol_new lepa_switch_controls =
546 SOC_DAPM_SINGLE("Switch", PM860X_DAC_EN_2, 2, 1, 0);
548 /* Right Ex. PA Switch */
549 static const struct snd_kcontrol_new repa_switch_controls =
550 SOC_DAPM_SINGLE("Switch", PM860X_DAC_EN_2, 1, 1, 0);
553 static const char *aif1_text[] = {
557 static SOC_ENUM_SINGLE_DECL(aif1_enum,
558 PM860X_PCM_IFACE_3, 6, aif1_text);
560 static const struct snd_kcontrol_new aif1_mux =
561 SOC_DAPM_ENUM("PCM Mux", aif1_enum);
564 static const char *i2s_din_text[] = {
568 static SOC_ENUM_SINGLE_DECL(i2s_din_enum,
569 PM860X_I2S_IFACE_3, 1, i2s_din_text);
571 static const struct snd_kcontrol_new i2s_din_mux =
572 SOC_DAPM_ENUM("I2S DIN Mux", i2s_din_enum);
574 /* I2S Mic Mux / Mux8 */
575 static const char *i2s_mic_text[] = {
579 static SOC_ENUM_SINGLE_DECL(i2s_mic_enum,
580 PM860X_I2S_IFACE_3, 4, i2s_mic_text);
582 static const struct snd_kcontrol_new i2s_mic_mux =
583 SOC_DAPM_ENUM("I2S Mic Mux", i2s_mic_enum);
585 /* ADCL Mux / Mux2 */
586 static const char *adcl_text[] = {
590 static SOC_ENUM_SINGLE_DECL(adcl_enum,
591 PM860X_PCM_IFACE_3, 4, adcl_text);
593 static const struct snd_kcontrol_new adcl_mux =
594 SOC_DAPM_ENUM("ADC Left Mux", adcl_enum);
596 /* ADCR Mux / Mux3 */
597 static const char *adcr_text[] = {
601 static SOC_ENUM_SINGLE_DECL(adcr_enum,
602 PM860X_PCM_IFACE_3, 2, adcr_text);
604 static const struct snd_kcontrol_new adcr_mux =
605 SOC_DAPM_ENUM("ADC Right Mux", adcr_enum);
607 /* ADCR EC Mux / Mux6 */
608 static const char *adcr_ec_text[] = {
612 static SOC_ENUM_SINGLE_DECL(adcr_ec_enum,
613 PM860X_ADC_EN_2, 3, adcr_ec_text);
615 static const struct snd_kcontrol_new adcr_ec_mux =
616 SOC_DAPM_ENUM("ADCR EC Mux", adcr_ec_enum);
619 static const char *ec_text[] = {
620 "Left", "Right", "Left + Right",
623 static SOC_ENUM_SINGLE_DECL(ec_enum,
624 PM860X_EC_PATH, 1, ec_text);
626 static const struct snd_kcontrol_new ec_mux =
627 SOC_DAPM_ENUM("EC Mux", ec_enum);
629 static const char *dac_text[] = {
630 "No input", "Right", "Left", "No input",
633 /* DAC Headset 1 Mux / Mux10 */
634 static SOC_ENUM_SINGLE_DECL(dac_hs1_enum,
635 PM860X_ANA_INPUT_SEL_1, 0, dac_text);
637 static const struct snd_kcontrol_new dac_hs1_mux =
638 SOC_DAPM_ENUM("DAC HS1 Mux", dac_hs1_enum);
640 /* DAC Headset 2 Mux / Mux11 */
641 static SOC_ENUM_SINGLE_DECL(dac_hs2_enum,
642 PM860X_ANA_INPUT_SEL_1, 2, dac_text);
644 static const struct snd_kcontrol_new dac_hs2_mux =
645 SOC_DAPM_ENUM("DAC HS2 Mux", dac_hs2_enum);
647 /* DAC Lineout 1 Mux / Mux12 */
648 static SOC_ENUM_SINGLE_DECL(dac_lo1_enum,
649 PM860X_ANA_INPUT_SEL_1, 4, dac_text);
651 static const struct snd_kcontrol_new dac_lo1_mux =
652 SOC_DAPM_ENUM("DAC LO1 Mux", dac_lo1_enum);
654 /* DAC Lineout 2 Mux / Mux13 */
655 static SOC_ENUM_SINGLE_DECL(dac_lo2_enum,
656 PM860X_ANA_INPUT_SEL_1, 6, dac_text);
658 static const struct snd_kcontrol_new dac_lo2_mux =
659 SOC_DAPM_ENUM("DAC LO2 Mux", dac_lo2_enum);
661 /* DAC Spearker Earphone Mux / Mux14 */
662 static SOC_ENUM_SINGLE_DECL(dac_spk_ear_enum,
663 PM860X_ANA_INPUT_SEL_2, 0, dac_text);
665 static const struct snd_kcontrol_new dac_spk_ear_mux =
666 SOC_DAPM_ENUM("DAC SP Mux", dac_spk_ear_enum);
668 /* Headset 1 Mux / Mux15 */
669 static const char *in_text[] = {
673 static SOC_ENUM_SINGLE_DECL(hs1_enum,
674 PM860X_ANA_TO_ANA, 0, in_text);
676 static const struct snd_kcontrol_new hs1_mux =
677 SOC_DAPM_ENUM("Headset1 Mux", hs1_enum);
679 /* Headset 2 Mux / Mux16 */
680 static SOC_ENUM_SINGLE_DECL(hs2_enum,
681 PM860X_ANA_TO_ANA, 1, in_text);
683 static const struct snd_kcontrol_new hs2_mux =
684 SOC_DAPM_ENUM("Headset2 Mux", hs2_enum);
686 /* Lineout 1 Mux / Mux17 */
687 static SOC_ENUM_SINGLE_DECL(lo1_enum,
688 PM860X_ANA_TO_ANA, 2, in_text);
690 static const struct snd_kcontrol_new lo1_mux =
691 SOC_DAPM_ENUM("Lineout1 Mux", lo1_enum);
693 /* Lineout 2 Mux / Mux18 */
694 static SOC_ENUM_SINGLE_DECL(lo2_enum,
695 PM860X_ANA_TO_ANA, 3, in_text);
697 static const struct snd_kcontrol_new lo2_mux =
698 SOC_DAPM_ENUM("Lineout2 Mux", lo2_enum);
700 /* Speaker Earpiece Demux */
701 static const char *spk_text[] = {
702 "Earpiece", "Speaker",
705 static SOC_ENUM_SINGLE_DECL(spk_enum,
706 PM860X_ANA_TO_ANA, 6, spk_text);
708 static const struct snd_kcontrol_new spk_demux =
709 SOC_DAPM_ENUM("Speaker Earpiece Demux", spk_enum);
712 static const char *mic_text[] = {
716 static SOC_ENUM_SINGLE_DECL(mic_enum,
717 PM860X_ADC_ANA_4, 4, mic_text);
719 static const struct snd_kcontrol_new mic_mux =
720 SOC_DAPM_ENUM("MIC Mux", mic_enum);
722 static const struct snd_soc_dapm_widget pm860x_dapm_widgets[] = {
723 SND_SOC_DAPM_AIF_IN("PCM SDI", "PCM Playback", 0,
724 PM860X_ADC_EN_2, 0, 0),
725 SND_SOC_DAPM_AIF_OUT("PCM SDO", "PCM Capture", 0,
726 PM860X_PCM_IFACE_3, 1, 1),
729 SND_SOC_DAPM_AIF_IN("I2S DIN", "I2S Playback", 0,
731 SND_SOC_DAPM_AIF_IN("I2S DIN1", "I2S Playback", 0,
733 SND_SOC_DAPM_AIF_OUT("I2S DOUT", "I2S Capture", 0,
734 PM860X_I2S_IFACE_3, 5, 1),
735 SND_SOC_DAPM_SUPPLY("I2S CLK", PM860X_DAC_EN_2, 0, 0, NULL, 0),
736 SND_SOC_DAPM_MUX("I2S Mic Mux", SND_SOC_NOPM, 0, 0, &i2s_mic_mux),
737 SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM, 0, 0, &adcl_mux),
738 SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM, 0, 0, &adcr_mux),
739 SND_SOC_DAPM_MUX("EC Mux", SND_SOC_NOPM, 0, 0, &ec_mux),
740 SND_SOC_DAPM_MUX("ADCR EC Mux", SND_SOC_NOPM, 0, 0, &adcr_ec_mux),
741 SND_SOC_DAPM_SWITCH("Left EPA", SND_SOC_NOPM, 0, 0,
742 &lepa_switch_controls),
743 SND_SOC_DAPM_SWITCH("Right EPA", SND_SOC_NOPM, 0, 0,
744 &repa_switch_controls),
746 SND_SOC_DAPM_REG(snd_soc_dapm_supply, "Left ADC MOD", PM860X_ADC_EN_1,
748 SND_SOC_DAPM_REG(snd_soc_dapm_supply, "Right ADC MOD", PM860X_ADC_EN_1,
750 SND_SOC_DAPM_ADC("Left ADC", NULL, PM860X_ADC_EN_2, 5, 0),
751 SND_SOC_DAPM_ADC("Right ADC", NULL, PM860X_ADC_EN_2, 4, 0),
753 SND_SOC_DAPM_SWITCH("AUX1 Switch", SND_SOC_NOPM, 0, 0,
754 &aux1_switch_controls),
755 SND_SOC_DAPM_SWITCH("AUX2 Switch", SND_SOC_NOPM, 0, 0,
756 &aux2_switch_controls),
758 SND_SOC_DAPM_MUX("MIC Mux", SND_SOC_NOPM, 0, 0, &mic_mux),
759 SND_SOC_DAPM_MICBIAS("Mic1 Bias", PM860X_ADC_ANA_1, 2, 0),
760 SND_SOC_DAPM_MICBIAS("Mic3 Bias", PM860X_ADC_ANA_1, 7, 0),
761 SND_SOC_DAPM_PGA("MIC1 Volume", PM860X_ADC_EN_1, 2, 0, NULL, 0),
762 SND_SOC_DAPM_PGA("MIC3 Volume", PM860X_ADC_EN_1, 3, 0, NULL, 0),
763 SND_SOC_DAPM_PGA("AUX1 Volume", PM860X_ADC_EN_1, 4, 0, NULL, 0),
764 SND_SOC_DAPM_PGA("AUX2 Volume", PM860X_ADC_EN_1, 5, 0, NULL, 0),
765 SND_SOC_DAPM_PGA("Sidetone PGA", PM860X_ADC_EN_2, 1, 0, NULL, 0),
766 SND_SOC_DAPM_PGA("Lofi PGA", PM860X_ADC_EN_2, 2, 0, NULL, 0),
768 SND_SOC_DAPM_INPUT("AUX1"),
769 SND_SOC_DAPM_INPUT("AUX2"),
770 SND_SOC_DAPM_INPUT("MIC1P"),
771 SND_SOC_DAPM_INPUT("MIC1N"),
772 SND_SOC_DAPM_INPUT("MIC2P"),
773 SND_SOC_DAPM_INPUT("MIC2N"),
774 SND_SOC_DAPM_INPUT("MIC3P"),
775 SND_SOC_DAPM_INPUT("MIC3N"),
777 SND_SOC_DAPM_DAC_E("Left DAC", NULL, SND_SOC_NOPM, 0, 0,
779 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
780 SND_SOC_DAPM_DAC_E("Right DAC", NULL, SND_SOC_NOPM, 0, 0,
782 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
784 SND_SOC_DAPM_MUX("I2S DIN Mux", SND_SOC_NOPM, 0, 0, &i2s_din_mux),
785 SND_SOC_DAPM_MUX("DAC HS1 Mux", SND_SOC_NOPM, 0, 0, &dac_hs1_mux),
786 SND_SOC_DAPM_MUX("DAC HS2 Mux", SND_SOC_NOPM, 0, 0, &dac_hs2_mux),
787 SND_SOC_DAPM_MUX("DAC LO1 Mux", SND_SOC_NOPM, 0, 0, &dac_lo1_mux),
788 SND_SOC_DAPM_MUX("DAC LO2 Mux", SND_SOC_NOPM, 0, 0, &dac_lo2_mux),
789 SND_SOC_DAPM_MUX("DAC SP Mux", SND_SOC_NOPM, 0, 0, &dac_spk_ear_mux),
790 SND_SOC_DAPM_MUX("Headset1 Mux", SND_SOC_NOPM, 0, 0, &hs1_mux),
791 SND_SOC_DAPM_MUX("Headset2 Mux", SND_SOC_NOPM, 0, 0, &hs2_mux),
792 SND_SOC_DAPM_MUX("Lineout1 Mux", SND_SOC_NOPM, 0, 0, &lo1_mux),
793 SND_SOC_DAPM_MUX("Lineout2 Mux", SND_SOC_NOPM, 0, 0, &lo2_mux),
794 SND_SOC_DAPM_MUX("Speaker Earpiece Demux", SND_SOC_NOPM, 0, 0,
798 SND_SOC_DAPM_PGA("Headset1 PGA", PM860X_DAC_EN_1, 0, 0, NULL, 0),
799 SND_SOC_DAPM_PGA("Headset2 PGA", PM860X_DAC_EN_1, 1, 0, NULL, 0),
800 SND_SOC_DAPM_OUTPUT("HS1"),
801 SND_SOC_DAPM_OUTPUT("HS2"),
802 SND_SOC_DAPM_PGA("Lineout1 PGA", PM860X_DAC_EN_1, 2, 0, NULL, 0),
803 SND_SOC_DAPM_PGA("Lineout2 PGA", PM860X_DAC_EN_1, 3, 0, NULL, 0),
804 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
805 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
806 SND_SOC_DAPM_PGA("Earpiece PGA", PM860X_DAC_EN_1, 4, 0, NULL, 0),
807 SND_SOC_DAPM_OUTPUT("EARP"),
808 SND_SOC_DAPM_OUTPUT("EARN"),
809 SND_SOC_DAPM_PGA("Speaker PGA", PM860X_DAC_EN_1, 5, 0, NULL, 0),
810 SND_SOC_DAPM_OUTPUT("LSP"),
811 SND_SOC_DAPM_OUTPUT("LSN"),
812 SND_SOC_DAPM_REG(snd_soc_dapm_supply, "VCODEC", PM860X_AUDIO_SUPPLIES_2,
813 0, SUPPLY_MASK, SUPPLY_MASK, 0),
815 PM860X_DAPM_OUTPUT("RSYNC", pm860x_rsync_event),
818 static const struct snd_soc_dapm_route pm860x_dapm_routes[] = {
820 {"Left DAC", NULL, "VCODEC"},
821 {"Right DAC", NULL, "VCODEC"},
822 {"Left ADC", NULL, "VCODEC"},
823 {"Right ADC", NULL, "VCODEC"},
824 {"Left ADC", NULL, "Left ADC MOD"},
825 {"Right ADC", NULL, "Right ADC MOD"},
828 {"I2S DIN", NULL, "I2S CLK"},
829 {"I2S DIN1", NULL, "I2S CLK"},
830 {"I2S DOUT", NULL, "I2S CLK"},
832 /* PCM/AIF1 Inputs */
833 {"PCM SDO", NULL, "ADC Left Mux"},
834 {"PCM SDO", NULL, "ADCR EC Mux"},
836 /* PCM/AFI2 Outputs */
837 {"Lofi PGA", NULL, "PCM SDI"},
838 {"Lofi PGA", NULL, "Sidetone PGA"},
839 {"Left DAC", NULL, "Lofi PGA"},
840 {"Right DAC", NULL, "Lofi PGA"},
842 /* I2S/AIF2 Inputs */
843 {"MIC Mux", "Mic 1", "MIC1P"},
844 {"MIC Mux", "Mic 1", "MIC1N"},
845 {"MIC Mux", "Mic 2", "MIC2P"},
846 {"MIC Mux", "Mic 2", "MIC2N"},
847 {"MIC1 Volume", NULL, "MIC Mux"},
848 {"MIC3 Volume", NULL, "MIC3P"},
849 {"MIC3 Volume", NULL, "MIC3N"},
850 {"Left ADC", NULL, "MIC1 Volume"},
851 {"Right ADC", NULL, "MIC3 Volume"},
852 {"ADC Left Mux", "ADCR", "Right ADC"},
853 {"ADC Left Mux", "ADCL", "Left ADC"},
854 {"ADC Right Mux", "ADCL", "Left ADC"},
855 {"ADC Right Mux", "ADCR", "Right ADC"},
856 {"Left EPA", "Switch", "Left DAC"},
857 {"Right EPA", "Switch", "Right DAC"},
858 {"EC Mux", "Left", "Left DAC"},
859 {"EC Mux", "Right", "Right DAC"},
860 {"EC Mux", "Left + Right", "Left DAC"},
861 {"EC Mux", "Left + Right", "Right DAC"},
862 {"ADCR EC Mux", "ADCR", "ADC Right Mux"},
863 {"ADCR EC Mux", "EC", "EC Mux"},
864 {"I2S Mic Mux", "Ex PA", "Left EPA"},
865 {"I2S Mic Mux", "Ex PA", "Right EPA"},
866 {"I2S Mic Mux", "ADC", "ADC Left Mux"},
867 {"I2S Mic Mux", "ADC", "ADCR EC Mux"},
868 {"I2S DOUT", NULL, "I2S Mic Mux"},
870 /* I2S/AIF2 Outputs */
871 {"I2S DIN Mux", "DIN", "I2S DIN"},
872 {"I2S DIN Mux", "DIN1", "I2S DIN1"},
873 {"Left DAC", NULL, "I2S DIN Mux"},
874 {"Right DAC", NULL, "I2S DIN Mux"},
875 {"DAC HS1 Mux", "Left", "Left DAC"},
876 {"DAC HS1 Mux", "Right", "Right DAC"},
877 {"DAC HS2 Mux", "Left", "Left DAC"},
878 {"DAC HS2 Mux", "Right", "Right DAC"},
879 {"DAC LO1 Mux", "Left", "Left DAC"},
880 {"DAC LO1 Mux", "Right", "Right DAC"},
881 {"DAC LO2 Mux", "Left", "Left DAC"},
882 {"DAC LO2 Mux", "Right", "Right DAC"},
883 {"Headset1 Mux", "Digital", "DAC HS1 Mux"},
884 {"Headset2 Mux", "Digital", "DAC HS2 Mux"},
885 {"Lineout1 Mux", "Digital", "DAC LO1 Mux"},
886 {"Lineout2 Mux", "Digital", "DAC LO2 Mux"},
887 {"Headset1 PGA", NULL, "Headset1 Mux"},
888 {"Headset2 PGA", NULL, "Headset2 Mux"},
889 {"Lineout1 PGA", NULL, "Lineout1 Mux"},
890 {"Lineout2 PGA", NULL, "Lineout2 Mux"},
891 {"DAC SP Mux", "Left", "Left DAC"},
892 {"DAC SP Mux", "Right", "Right DAC"},
893 {"Speaker Earpiece Demux", "Speaker", "DAC SP Mux"},
894 {"Speaker PGA", NULL, "Speaker Earpiece Demux"},
895 {"Earpiece PGA", NULL, "Speaker Earpiece Demux"},
897 {"RSYNC", NULL, "Headset1 PGA"},
898 {"RSYNC", NULL, "Headset2 PGA"},
899 {"RSYNC", NULL, "Lineout1 PGA"},
900 {"RSYNC", NULL, "Lineout2 PGA"},
901 {"RSYNC", NULL, "Speaker PGA"},
902 {"RSYNC", NULL, "Speaker PGA"},
903 {"RSYNC", NULL, "Earpiece PGA"},
904 {"RSYNC", NULL, "Earpiece PGA"},
906 {"HS1", NULL, "RSYNC"},
907 {"HS2", NULL, "RSYNC"},
908 {"LINEOUT1", NULL, "RSYNC"},
909 {"LINEOUT2", NULL, "RSYNC"},
910 {"LSP", NULL, "RSYNC"},
911 {"LSN", NULL, "RSYNC"},
912 {"EARP", NULL, "RSYNC"},
913 {"EARN", NULL, "RSYNC"},
917 * Use MUTE_LEFT & MUTE_RIGHT to implement digital mute.
918 * These bits can also be used to mute.
920 static int pm860x_digital_mute(struct snd_soc_dai *codec_dai, int mute)
922 struct snd_soc_component *component = codec_dai->component;
923 int data = 0, mask = MUTE_LEFT | MUTE_RIGHT;
927 snd_soc_component_update_bits(component, PM860X_DAC_OFFSET, mask, data);
928 snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
929 RSYNC_CHANGE, RSYNC_CHANGE);
933 static int pm860x_pcm_hw_params(struct snd_pcm_substream *substream,
934 struct snd_pcm_hw_params *params,
935 struct snd_soc_dai *dai)
937 struct snd_soc_component *component = dai->component;
938 unsigned char inf = 0, mask = 0;
941 switch (params_width(params)) {
943 inf &= ~PCM_INF2_18WL;
946 inf |= PCM_INF2_18WL;
951 mask |= PCM_INF2_18WL;
952 snd_soc_component_update_bits(component, PM860X_PCM_IFACE_2, mask, inf);
955 switch (params_rate(params)) {
971 snd_soc_component_update_bits(component, PM860X_PCM_RATE, 0x0f, inf);
976 static int pm860x_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai,
979 struct snd_soc_component *component = codec_dai->component;
980 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
981 unsigned char inf = 0, mask = 0;
984 mask |= PCM_INF2_BCLK | PCM_INF2_FS | PCM_INF2_MASTER;
986 /* set master/slave audio interface */
987 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
988 case SND_SOC_DAIFMT_CBM_CFM:
989 case SND_SOC_DAIFMT_CBM_CFS:
990 if (pm860x->dir == PM860X_CLK_DIR_OUT) {
991 inf |= PCM_INF2_MASTER;
995 case SND_SOC_DAIFMT_CBS_CFS:
996 if (pm860x->dir == PM860X_CLK_DIR_IN) {
997 inf &= ~PCM_INF2_MASTER;
1003 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1004 case SND_SOC_DAIFMT_I2S:
1005 inf |= PCM_EXACT_I2S;
1009 mask |= PCM_MODE_MASK;
1012 snd_soc_component_update_bits(component, PM860X_PCM_IFACE_2, mask, inf);
1016 static int pm860x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1017 int clk_id, unsigned int freq, int dir)
1019 struct snd_soc_component *component = codec_dai->component;
1020 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1022 if (dir == PM860X_CLK_DIR_OUT)
1023 pm860x->dir = PM860X_CLK_DIR_OUT;
1024 else /* Slave mode is not supported */
1030 static int pm860x_i2s_hw_params(struct snd_pcm_substream *substream,
1031 struct snd_pcm_hw_params *params,
1032 struct snd_soc_dai *dai)
1034 struct snd_soc_component *component = dai->component;
1038 switch (params_width(params)) {
1043 inf = PCM_INF2_18WL;
1048 snd_soc_component_update_bits(component, PM860X_I2S_IFACE_2, PCM_INF2_18WL, inf);
1051 switch (params_rate(params)) {
1076 snd_soc_component_update_bits(component, PM860X_I2S_IFACE_4, 0xf, inf);
1081 static int pm860x_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
1084 struct snd_soc_component *component = codec_dai->component;
1085 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1086 unsigned char inf = 0, mask = 0;
1088 mask |= PCM_INF2_BCLK | PCM_INF2_FS | PCM_INF2_MASTER;
1090 /* set master/slave audio interface */
1091 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1092 case SND_SOC_DAIFMT_CBM_CFM:
1093 if (pm860x->dir == PM860X_CLK_DIR_OUT)
1094 inf |= PCM_INF2_MASTER;
1098 case SND_SOC_DAIFMT_CBS_CFS:
1099 if (pm860x->dir == PM860X_CLK_DIR_IN)
1100 inf &= ~PCM_INF2_MASTER;
1108 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1109 case SND_SOC_DAIFMT_I2S:
1110 inf |= PCM_EXACT_I2S;
1115 mask |= PCM_MODE_MASK;
1116 snd_soc_component_update_bits(component, PM860X_I2S_IFACE_2, mask, inf);
1120 static int pm860x_set_bias_level(struct snd_soc_component *component,
1121 enum snd_soc_bias_level level)
1123 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1127 case SND_SOC_BIAS_ON:
1130 case SND_SOC_BIAS_PREPARE:
1133 case SND_SOC_BIAS_STANDBY:
1134 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
1135 /* Enable Audio PLL & Audio section */
1136 data = AUDIO_PLL | AUDIO_SECTION_ON;
1137 pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
1139 data = AUDIO_PLL | AUDIO_SECTION_RESET
1141 pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
1145 case SND_SOC_BIAS_OFF:
1146 data = AUDIO_PLL | AUDIO_SECTION_RESET | AUDIO_SECTION_ON;
1147 pm860x_set_bits(pm860x->i2c, REG_MISC2, data, 0);
1153 static const struct snd_soc_dai_ops pm860x_pcm_dai_ops = {
1154 .digital_mute = pm860x_digital_mute,
1155 .hw_params = pm860x_pcm_hw_params,
1156 .set_fmt = pm860x_pcm_set_dai_fmt,
1157 .set_sysclk = pm860x_set_dai_sysclk,
1160 static const struct snd_soc_dai_ops pm860x_i2s_dai_ops = {
1161 .digital_mute = pm860x_digital_mute,
1162 .hw_params = pm860x_i2s_hw_params,
1163 .set_fmt = pm860x_i2s_set_dai_fmt,
1164 .set_sysclk = pm860x_set_dai_sysclk,
1167 #define PM860X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | \
1168 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
1170 static struct snd_soc_dai_driver pm860x_dai[] = {
1173 .name = "88pm860x-pcm",
1176 .stream_name = "PCM Playback",
1179 .rates = PM860X_RATES,
1180 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1181 SNDRV_PCM_FMTBIT_S18_3LE,
1184 .stream_name = "PCM Capture",
1187 .rates = PM860X_RATES,
1188 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1189 SNDRV_PCM_FMTBIT_S18_3LE,
1191 .ops = &pm860x_pcm_dai_ops,
1194 .name = "88pm860x-i2s",
1197 .stream_name = "I2S Playback",
1200 .rates = SNDRV_PCM_RATE_8000_48000,
1201 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1202 SNDRV_PCM_FMTBIT_S18_3LE,
1205 .stream_name = "I2S Capture",
1208 .rates = SNDRV_PCM_RATE_8000_48000,
1209 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1210 SNDRV_PCM_FMTBIT_S18_3LE,
1212 .ops = &pm860x_i2s_dai_ops,
1216 static irqreturn_t pm860x_component_handler(int irq, void *data)
1218 struct pm860x_priv *pm860x = data;
1219 int status, shrt, report = 0, mic_report = 0;
1222 status = pm860x_reg_read(pm860x->i2c, REG_STATUS_1);
1223 shrt = pm860x_reg_read(pm860x->i2c, REG_SHORTS);
1224 mask = pm860x->det.hs_shrt | pm860x->det.hook_det | pm860x->det.lo_shrt
1225 | pm860x->det.hp_det;
1227 #ifndef CONFIG_SND_SOC_88PM860X_MODULE
1228 if (status & (HEADSET_STATUS | MIC_STATUS | SHORT_HS1 | SHORT_HS2 |
1229 SHORT_LO1 | SHORT_LO2))
1230 trace_snd_soc_jack_irq(dev_name(pm860x->component->dev));
1233 if ((pm860x->det.hp_det & SND_JACK_HEADPHONE)
1234 && (status & HEADSET_STATUS))
1235 report |= SND_JACK_HEADPHONE;
1237 if ((pm860x->det.mic_det & SND_JACK_MICROPHONE)
1238 && (status & MIC_STATUS))
1239 mic_report |= SND_JACK_MICROPHONE;
1241 if (pm860x->det.hs_shrt && (shrt & (SHORT_HS1 | SHORT_HS2)))
1242 report |= pm860x->det.hs_shrt;
1244 if (pm860x->det.hook_det && (status & HOOK_STATUS))
1245 report |= pm860x->det.hook_det;
1247 if (pm860x->det.lo_shrt && (shrt & (SHORT_LO1 | SHORT_LO2)))
1248 report |= pm860x->det.lo_shrt;
1251 snd_soc_jack_report(pm860x->det.hp_jack, report, mask);
1253 snd_soc_jack_report(pm860x->det.mic_jack, SND_JACK_MICROPHONE,
1254 SND_JACK_MICROPHONE);
1256 dev_dbg(pm860x->component->dev, "headphone report:0x%x, mask:%x\n",
1258 dev_dbg(pm860x->component->dev, "microphone report:0x%x\n", mic_report);
1262 int pm860x_hs_jack_detect(struct snd_soc_component *component,
1263 struct snd_soc_jack *jack,
1264 int det, int hook, int hs_shrt, int lo_shrt)
1266 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1269 pm860x->det.hp_jack = jack;
1270 pm860x->det.hp_det = det;
1271 pm860x->det.hook_det = hook;
1272 pm860x->det.hs_shrt = hs_shrt;
1273 pm860x->det.lo_shrt = lo_shrt;
1275 if (det & SND_JACK_HEADPHONE)
1276 pm860x_set_bits(pm860x->i2c, REG_HS_DET,
1277 EN_HS_DET, EN_HS_DET);
1278 /* headset short detect */
1280 data = CLR_SHORT_HS2 | CLR_SHORT_HS1;
1281 pm860x_set_bits(pm860x->i2c, REG_SHORTS, data, data);
1283 /* Lineout short detect */
1285 data = CLR_SHORT_LO2 | CLR_SHORT_LO1;
1286 pm860x_set_bits(pm860x->i2c, REG_SHORTS, data, data);
1290 pm860x_component_handler(0, pm860x);
1293 EXPORT_SYMBOL_GPL(pm860x_hs_jack_detect);
1295 int pm860x_mic_jack_detect(struct snd_soc_component *component,
1296 struct snd_soc_jack *jack, int det)
1298 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1300 pm860x->det.mic_jack = jack;
1301 pm860x->det.mic_det = det;
1303 if (det & SND_JACK_MICROPHONE)
1304 pm860x_set_bits(pm860x->i2c, REG_MIC_DET,
1305 MICDET_MASK, MICDET_MASK);
1308 pm860x_component_handler(0, pm860x);
1311 EXPORT_SYMBOL_GPL(pm860x_mic_jack_detect);
1313 static int pm860x_probe(struct snd_soc_component *component)
1315 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1318 pm860x->component = component;
1319 snd_soc_component_init_regmap(component, pm860x->regmap);
1321 for (i = 0; i < 4; i++) {
1322 ret = request_threaded_irq(pm860x->irq[i], NULL,
1323 pm860x_component_handler, IRQF_ONESHOT,
1324 pm860x->name[i], pm860x);
1326 dev_err(component->dev, "Failed to request IRQ!\n");
1335 free_irq(pm860x->irq[i], pm860x);
1339 static void pm860x_remove(struct snd_soc_component *component)
1341 struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
1344 for (i = 3; i >= 0; i--)
1345 free_irq(pm860x->irq[i], pm860x);
1348 static const struct snd_soc_component_driver soc_component_dev_pm860x = {
1349 .probe = pm860x_probe,
1350 .remove = pm860x_remove,
1351 .set_bias_level = pm860x_set_bias_level,
1352 .controls = pm860x_snd_controls,
1353 .num_controls = ARRAY_SIZE(pm860x_snd_controls),
1354 .dapm_widgets = pm860x_dapm_widgets,
1355 .num_dapm_widgets = ARRAY_SIZE(pm860x_dapm_widgets),
1356 .dapm_routes = pm860x_dapm_routes,
1357 .num_dapm_routes = ARRAY_SIZE(pm860x_dapm_routes),
1359 .use_pmdown_time = 1,
1361 .non_legacy_dai_naming = 1,
1364 static int pm860x_codec_probe(struct platform_device *pdev)
1366 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
1367 struct pm860x_priv *pm860x;
1368 struct resource *res;
1371 pm860x = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_priv),
1376 pm860x->chip = chip;
1377 pm860x->i2c = (chip->id == CHIP_PM8607) ? chip->client
1379 pm860x->regmap = (chip->id == CHIP_PM8607) ? chip->regmap
1380 : chip->regmap_companion;
1381 platform_set_drvdata(pdev, pm860x);
1383 for (i = 0; i < 4; i++) {
1384 res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
1386 dev_err(&pdev->dev, "Failed to get IRQ resources\n");
1389 pm860x->irq[i] = res->start + chip->irq_base;
1390 strncpy(pm860x->name[i], res->name, MAX_NAME_LEN);
1393 ret = devm_snd_soc_register_component(&pdev->dev,
1394 &soc_component_dev_pm860x,
1395 pm860x_dai, ARRAY_SIZE(pm860x_dai));
1397 dev_err(&pdev->dev, "Failed to register component\n");
1403 static int pm860x_codec_remove(struct platform_device *pdev)
1408 static struct platform_driver pm860x_codec_driver = {
1410 .name = "88pm860x-codec",
1412 .probe = pm860x_codec_probe,
1413 .remove = pm860x_codec_remove,
1416 module_platform_driver(pm860x_codec_driver);
1418 MODULE_DESCRIPTION("ASoC 88PM860x driver");
1419 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
1420 MODULE_LICENSE("GPL");
1421 MODULE_ALIAS("platform:88pm860x-codec");