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
),
533 static const struct snd_kcontrol_new aux1_switch_controls
=
534 SOC_DAPM_SINGLE("Switch", PM860X_ANA_TO_ANA
, 4, 1, 0);
537 static const struct snd_kcontrol_new aux2_switch_controls
=
538 SOC_DAPM_SINGLE("Switch", PM860X_ANA_TO_ANA
, 5, 1, 0);
540 /* Left Ex. PA Switch */
541 static const struct snd_kcontrol_new lepa_switch_controls
=
542 SOC_DAPM_SINGLE("Switch", PM860X_DAC_EN_2
, 2, 1, 0);
544 /* Right Ex. PA Switch */
545 static const struct snd_kcontrol_new repa_switch_controls
=
546 SOC_DAPM_SINGLE("Switch", PM860X_DAC_EN_2
, 1, 1, 0);
549 static const char *i2s_din_text
[] = {
553 static SOC_ENUM_SINGLE_DECL(i2s_din_enum
,
554 PM860X_I2S_IFACE_3
, 1, i2s_din_text
);
556 static const struct snd_kcontrol_new i2s_din_mux
=
557 SOC_DAPM_ENUM("I2S DIN Mux", i2s_din_enum
);
559 /* I2S Mic Mux / Mux8 */
560 static const char *i2s_mic_text
[] = {
564 static SOC_ENUM_SINGLE_DECL(i2s_mic_enum
,
565 PM860X_I2S_IFACE_3
, 4, i2s_mic_text
);
567 static const struct snd_kcontrol_new i2s_mic_mux
=
568 SOC_DAPM_ENUM("I2S Mic Mux", i2s_mic_enum
);
570 /* ADCL Mux / Mux2 */
571 static const char *adcl_text
[] = {
575 static SOC_ENUM_SINGLE_DECL(adcl_enum
,
576 PM860X_PCM_IFACE_3
, 4, adcl_text
);
578 static const struct snd_kcontrol_new adcl_mux
=
579 SOC_DAPM_ENUM("ADC Left Mux", adcl_enum
);
581 /* ADCR Mux / Mux3 */
582 static const char *adcr_text
[] = {
586 static SOC_ENUM_SINGLE_DECL(adcr_enum
,
587 PM860X_PCM_IFACE_3
, 2, adcr_text
);
589 static const struct snd_kcontrol_new adcr_mux
=
590 SOC_DAPM_ENUM("ADC Right Mux", adcr_enum
);
592 /* ADCR EC Mux / Mux6 */
593 static const char *adcr_ec_text
[] = {
597 static SOC_ENUM_SINGLE_DECL(adcr_ec_enum
,
598 PM860X_ADC_EN_2
, 3, adcr_ec_text
);
600 static const struct snd_kcontrol_new adcr_ec_mux
=
601 SOC_DAPM_ENUM("ADCR EC Mux", adcr_ec_enum
);
604 static const char *ec_text
[] = {
605 "Left", "Right", "Left + Right",
608 static SOC_ENUM_SINGLE_DECL(ec_enum
,
609 PM860X_EC_PATH
, 1, ec_text
);
611 static const struct snd_kcontrol_new ec_mux
=
612 SOC_DAPM_ENUM("EC Mux", ec_enum
);
614 static const char *dac_text
[] = {
615 "No input", "Right", "Left", "No input",
618 /* DAC Headset 1 Mux / Mux10 */
619 static SOC_ENUM_SINGLE_DECL(dac_hs1_enum
,
620 PM860X_ANA_INPUT_SEL_1
, 0, dac_text
);
622 static const struct snd_kcontrol_new dac_hs1_mux
=
623 SOC_DAPM_ENUM("DAC HS1 Mux", dac_hs1_enum
);
625 /* DAC Headset 2 Mux / Mux11 */
626 static SOC_ENUM_SINGLE_DECL(dac_hs2_enum
,
627 PM860X_ANA_INPUT_SEL_1
, 2, dac_text
);
629 static const struct snd_kcontrol_new dac_hs2_mux
=
630 SOC_DAPM_ENUM("DAC HS2 Mux", dac_hs2_enum
);
632 /* DAC Lineout 1 Mux / Mux12 */
633 static SOC_ENUM_SINGLE_DECL(dac_lo1_enum
,
634 PM860X_ANA_INPUT_SEL_1
, 4, dac_text
);
636 static const struct snd_kcontrol_new dac_lo1_mux
=
637 SOC_DAPM_ENUM("DAC LO1 Mux", dac_lo1_enum
);
639 /* DAC Lineout 2 Mux / Mux13 */
640 static SOC_ENUM_SINGLE_DECL(dac_lo2_enum
,
641 PM860X_ANA_INPUT_SEL_1
, 6, dac_text
);
643 static const struct snd_kcontrol_new dac_lo2_mux
=
644 SOC_DAPM_ENUM("DAC LO2 Mux", dac_lo2_enum
);
646 /* DAC Spearker Earphone Mux / Mux14 */
647 static SOC_ENUM_SINGLE_DECL(dac_spk_ear_enum
,
648 PM860X_ANA_INPUT_SEL_2
, 0, dac_text
);
650 static const struct snd_kcontrol_new dac_spk_ear_mux
=
651 SOC_DAPM_ENUM("DAC SP Mux", dac_spk_ear_enum
);
653 /* Headset 1 Mux / Mux15 */
654 static const char *in_text
[] = {
658 static SOC_ENUM_SINGLE_DECL(hs1_enum
,
659 PM860X_ANA_TO_ANA
, 0, in_text
);
661 static const struct snd_kcontrol_new hs1_mux
=
662 SOC_DAPM_ENUM("Headset1 Mux", hs1_enum
);
664 /* Headset 2 Mux / Mux16 */
665 static SOC_ENUM_SINGLE_DECL(hs2_enum
,
666 PM860X_ANA_TO_ANA
, 1, in_text
);
668 static const struct snd_kcontrol_new hs2_mux
=
669 SOC_DAPM_ENUM("Headset2 Mux", hs2_enum
);
671 /* Lineout 1 Mux / Mux17 */
672 static SOC_ENUM_SINGLE_DECL(lo1_enum
,
673 PM860X_ANA_TO_ANA
, 2, in_text
);
675 static const struct snd_kcontrol_new lo1_mux
=
676 SOC_DAPM_ENUM("Lineout1 Mux", lo1_enum
);
678 /* Lineout 2 Mux / Mux18 */
679 static SOC_ENUM_SINGLE_DECL(lo2_enum
,
680 PM860X_ANA_TO_ANA
, 3, in_text
);
682 static const struct snd_kcontrol_new lo2_mux
=
683 SOC_DAPM_ENUM("Lineout2 Mux", lo2_enum
);
685 /* Speaker Earpiece Demux */
686 static const char *spk_text
[] = {
687 "Earpiece", "Speaker",
690 static SOC_ENUM_SINGLE_DECL(spk_enum
,
691 PM860X_ANA_TO_ANA
, 6, spk_text
);
693 static const struct snd_kcontrol_new spk_demux
=
694 SOC_DAPM_ENUM("Speaker Earpiece Demux", spk_enum
);
697 static const char *mic_text
[] = {
701 static SOC_ENUM_SINGLE_DECL(mic_enum
,
702 PM860X_ADC_ANA_4
, 4, mic_text
);
704 static const struct snd_kcontrol_new mic_mux
=
705 SOC_DAPM_ENUM("MIC Mux", mic_enum
);
707 static const struct snd_soc_dapm_widget pm860x_dapm_widgets
[] = {
708 SND_SOC_DAPM_AIF_IN("PCM SDI", "PCM Playback", 0,
709 PM860X_ADC_EN_2
, 0, 0),
710 SND_SOC_DAPM_AIF_OUT("PCM SDO", "PCM Capture", 0,
711 PM860X_PCM_IFACE_3
, 1, 1),
714 SND_SOC_DAPM_AIF_IN("I2S DIN", "I2S Playback", 0,
716 SND_SOC_DAPM_AIF_IN("I2S DIN1", "I2S Playback", 0,
718 SND_SOC_DAPM_AIF_OUT("I2S DOUT", "I2S Capture", 0,
719 PM860X_I2S_IFACE_3
, 5, 1),
720 SND_SOC_DAPM_SUPPLY("I2S CLK", PM860X_DAC_EN_2
, 0, 0, NULL
, 0),
721 SND_SOC_DAPM_MUX("I2S Mic Mux", SND_SOC_NOPM
, 0, 0, &i2s_mic_mux
),
722 SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM
, 0, 0, &adcl_mux
),
723 SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM
, 0, 0, &adcr_mux
),
724 SND_SOC_DAPM_MUX("EC Mux", SND_SOC_NOPM
, 0, 0, &ec_mux
),
725 SND_SOC_DAPM_MUX("ADCR EC Mux", SND_SOC_NOPM
, 0, 0, &adcr_ec_mux
),
726 SND_SOC_DAPM_SWITCH("Left EPA", SND_SOC_NOPM
, 0, 0,
727 &lepa_switch_controls
),
728 SND_SOC_DAPM_SWITCH("Right EPA", SND_SOC_NOPM
, 0, 0,
729 &repa_switch_controls
),
731 SND_SOC_DAPM_REG(snd_soc_dapm_supply
, "Left ADC MOD", PM860X_ADC_EN_1
,
733 SND_SOC_DAPM_REG(snd_soc_dapm_supply
, "Right ADC MOD", PM860X_ADC_EN_1
,
735 SND_SOC_DAPM_ADC("Left ADC", NULL
, PM860X_ADC_EN_2
, 5, 0),
736 SND_SOC_DAPM_ADC("Right ADC", NULL
, PM860X_ADC_EN_2
, 4, 0),
738 SND_SOC_DAPM_SWITCH("AUX1 Switch", SND_SOC_NOPM
, 0, 0,
739 &aux1_switch_controls
),
740 SND_SOC_DAPM_SWITCH("AUX2 Switch", SND_SOC_NOPM
, 0, 0,
741 &aux2_switch_controls
),
743 SND_SOC_DAPM_MUX("MIC Mux", SND_SOC_NOPM
, 0, 0, &mic_mux
),
744 SND_SOC_DAPM_MICBIAS("Mic1 Bias", PM860X_ADC_ANA_1
, 2, 0),
745 SND_SOC_DAPM_MICBIAS("Mic3 Bias", PM860X_ADC_ANA_1
, 7, 0),
746 SND_SOC_DAPM_PGA("MIC1 Volume", PM860X_ADC_EN_1
, 2, 0, NULL
, 0),
747 SND_SOC_DAPM_PGA("MIC3 Volume", PM860X_ADC_EN_1
, 3, 0, NULL
, 0),
748 SND_SOC_DAPM_PGA("AUX1 Volume", PM860X_ADC_EN_1
, 4, 0, NULL
, 0),
749 SND_SOC_DAPM_PGA("AUX2 Volume", PM860X_ADC_EN_1
, 5, 0, NULL
, 0),
750 SND_SOC_DAPM_PGA("Sidetone PGA", PM860X_ADC_EN_2
, 1, 0, NULL
, 0),
751 SND_SOC_DAPM_PGA("Lofi PGA", PM860X_ADC_EN_2
, 2, 0, NULL
, 0),
753 SND_SOC_DAPM_INPUT("AUX1"),
754 SND_SOC_DAPM_INPUT("AUX2"),
755 SND_SOC_DAPM_INPUT("MIC1P"),
756 SND_SOC_DAPM_INPUT("MIC1N"),
757 SND_SOC_DAPM_INPUT("MIC2P"),
758 SND_SOC_DAPM_INPUT("MIC2N"),
759 SND_SOC_DAPM_INPUT("MIC3P"),
760 SND_SOC_DAPM_INPUT("MIC3N"),
762 SND_SOC_DAPM_DAC_E("Left DAC", NULL
, SND_SOC_NOPM
, 0, 0,
764 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_PRE_PMD
),
765 SND_SOC_DAPM_DAC_E("Right DAC", NULL
, SND_SOC_NOPM
, 0, 0,
767 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_PRE_PMD
),
769 SND_SOC_DAPM_MUX("I2S DIN Mux", SND_SOC_NOPM
, 0, 0, &i2s_din_mux
),
770 SND_SOC_DAPM_MUX("DAC HS1 Mux", SND_SOC_NOPM
, 0, 0, &dac_hs1_mux
),
771 SND_SOC_DAPM_MUX("DAC HS2 Mux", SND_SOC_NOPM
, 0, 0, &dac_hs2_mux
),
772 SND_SOC_DAPM_MUX("DAC LO1 Mux", SND_SOC_NOPM
, 0, 0, &dac_lo1_mux
),
773 SND_SOC_DAPM_MUX("DAC LO2 Mux", SND_SOC_NOPM
, 0, 0, &dac_lo2_mux
),
774 SND_SOC_DAPM_MUX("DAC SP Mux", SND_SOC_NOPM
, 0, 0, &dac_spk_ear_mux
),
775 SND_SOC_DAPM_MUX("Headset1 Mux", SND_SOC_NOPM
, 0, 0, &hs1_mux
),
776 SND_SOC_DAPM_MUX("Headset2 Mux", SND_SOC_NOPM
, 0, 0, &hs2_mux
),
777 SND_SOC_DAPM_MUX("Lineout1 Mux", SND_SOC_NOPM
, 0, 0, &lo1_mux
),
778 SND_SOC_DAPM_MUX("Lineout2 Mux", SND_SOC_NOPM
, 0, 0, &lo2_mux
),
779 SND_SOC_DAPM_MUX("Speaker Earpiece Demux", SND_SOC_NOPM
, 0, 0,
783 SND_SOC_DAPM_PGA("Headset1 PGA", PM860X_DAC_EN_1
, 0, 0, NULL
, 0),
784 SND_SOC_DAPM_PGA("Headset2 PGA", PM860X_DAC_EN_1
, 1, 0, NULL
, 0),
785 SND_SOC_DAPM_OUTPUT("HS1"),
786 SND_SOC_DAPM_OUTPUT("HS2"),
787 SND_SOC_DAPM_PGA("Lineout1 PGA", PM860X_DAC_EN_1
, 2, 0, NULL
, 0),
788 SND_SOC_DAPM_PGA("Lineout2 PGA", PM860X_DAC_EN_1
, 3, 0, NULL
, 0),
789 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
790 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
791 SND_SOC_DAPM_PGA("Earpiece PGA", PM860X_DAC_EN_1
, 4, 0, NULL
, 0),
792 SND_SOC_DAPM_OUTPUT("EARP"),
793 SND_SOC_DAPM_OUTPUT("EARN"),
794 SND_SOC_DAPM_PGA("Speaker PGA", PM860X_DAC_EN_1
, 5, 0, NULL
, 0),
795 SND_SOC_DAPM_OUTPUT("LSP"),
796 SND_SOC_DAPM_OUTPUT("LSN"),
797 SND_SOC_DAPM_REG(snd_soc_dapm_supply
, "VCODEC", PM860X_AUDIO_SUPPLIES_2
,
798 0, SUPPLY_MASK
, SUPPLY_MASK
, 0),
800 PM860X_DAPM_OUTPUT("RSYNC", pm860x_rsync_event
),
803 static const struct snd_soc_dapm_route pm860x_dapm_routes
[] = {
805 {"Left DAC", NULL
, "VCODEC"},
806 {"Right DAC", NULL
, "VCODEC"},
807 {"Left ADC", NULL
, "VCODEC"},
808 {"Right ADC", NULL
, "VCODEC"},
809 {"Left ADC", NULL
, "Left ADC MOD"},
810 {"Right ADC", NULL
, "Right ADC MOD"},
813 {"I2S DIN", NULL
, "I2S CLK"},
814 {"I2S DIN1", NULL
, "I2S CLK"},
815 {"I2S DOUT", NULL
, "I2S CLK"},
817 /* PCM/AIF1 Inputs */
818 {"PCM SDO", NULL
, "ADC Left Mux"},
819 {"PCM SDO", NULL
, "ADCR EC Mux"},
821 /* PCM/AFI2 Outputs */
822 {"Lofi PGA", NULL
, "PCM SDI"},
823 {"Lofi PGA", NULL
, "Sidetone PGA"},
824 {"Left DAC", NULL
, "Lofi PGA"},
825 {"Right DAC", NULL
, "Lofi PGA"},
827 /* I2S/AIF2 Inputs */
828 {"MIC Mux", "Mic 1", "MIC1P"},
829 {"MIC Mux", "Mic 1", "MIC1N"},
830 {"MIC Mux", "Mic 2", "MIC2P"},
831 {"MIC Mux", "Mic 2", "MIC2N"},
832 {"MIC1 Volume", NULL
, "MIC Mux"},
833 {"MIC3 Volume", NULL
, "MIC3P"},
834 {"MIC3 Volume", NULL
, "MIC3N"},
835 {"Left ADC", NULL
, "MIC1 Volume"},
836 {"Right ADC", NULL
, "MIC3 Volume"},
837 {"ADC Left Mux", "ADCR", "Right ADC"},
838 {"ADC Left Mux", "ADCL", "Left ADC"},
839 {"ADC Right Mux", "ADCL", "Left ADC"},
840 {"ADC Right Mux", "ADCR", "Right ADC"},
841 {"Left EPA", "Switch", "Left DAC"},
842 {"Right EPA", "Switch", "Right DAC"},
843 {"EC Mux", "Left", "Left DAC"},
844 {"EC Mux", "Right", "Right DAC"},
845 {"EC Mux", "Left + Right", "Left DAC"},
846 {"EC Mux", "Left + Right", "Right DAC"},
847 {"ADCR EC Mux", "ADCR", "ADC Right Mux"},
848 {"ADCR EC Mux", "EC", "EC Mux"},
849 {"I2S Mic Mux", "Ex PA", "Left EPA"},
850 {"I2S Mic Mux", "Ex PA", "Right EPA"},
851 {"I2S Mic Mux", "ADC", "ADC Left Mux"},
852 {"I2S Mic Mux", "ADC", "ADCR EC Mux"},
853 {"I2S DOUT", NULL
, "I2S Mic Mux"},
855 /* I2S/AIF2 Outputs */
856 {"I2S DIN Mux", "DIN", "I2S DIN"},
857 {"I2S DIN Mux", "DIN1", "I2S DIN1"},
858 {"Left DAC", NULL
, "I2S DIN Mux"},
859 {"Right DAC", NULL
, "I2S DIN Mux"},
860 {"DAC HS1 Mux", "Left", "Left DAC"},
861 {"DAC HS1 Mux", "Right", "Right DAC"},
862 {"DAC HS2 Mux", "Left", "Left DAC"},
863 {"DAC HS2 Mux", "Right", "Right DAC"},
864 {"DAC LO1 Mux", "Left", "Left DAC"},
865 {"DAC LO1 Mux", "Right", "Right DAC"},
866 {"DAC LO2 Mux", "Left", "Left DAC"},
867 {"DAC LO2 Mux", "Right", "Right DAC"},
868 {"Headset1 Mux", "Digital", "DAC HS1 Mux"},
869 {"Headset2 Mux", "Digital", "DAC HS2 Mux"},
870 {"Lineout1 Mux", "Digital", "DAC LO1 Mux"},
871 {"Lineout2 Mux", "Digital", "DAC LO2 Mux"},
872 {"Headset1 PGA", NULL
, "Headset1 Mux"},
873 {"Headset2 PGA", NULL
, "Headset2 Mux"},
874 {"Lineout1 PGA", NULL
, "Lineout1 Mux"},
875 {"Lineout2 PGA", NULL
, "Lineout2 Mux"},
876 {"DAC SP Mux", "Left", "Left DAC"},
877 {"DAC SP Mux", "Right", "Right DAC"},
878 {"Speaker Earpiece Demux", "Speaker", "DAC SP Mux"},
879 {"Speaker PGA", NULL
, "Speaker Earpiece Demux"},
880 {"Earpiece PGA", NULL
, "Speaker Earpiece Demux"},
882 {"RSYNC", NULL
, "Headset1 PGA"},
883 {"RSYNC", NULL
, "Headset2 PGA"},
884 {"RSYNC", NULL
, "Lineout1 PGA"},
885 {"RSYNC", NULL
, "Lineout2 PGA"},
886 {"RSYNC", NULL
, "Speaker PGA"},
887 {"RSYNC", NULL
, "Speaker PGA"},
888 {"RSYNC", NULL
, "Earpiece PGA"},
889 {"RSYNC", NULL
, "Earpiece PGA"},
891 {"HS1", NULL
, "RSYNC"},
892 {"HS2", NULL
, "RSYNC"},
893 {"LINEOUT1", NULL
, "RSYNC"},
894 {"LINEOUT2", NULL
, "RSYNC"},
895 {"LSP", NULL
, "RSYNC"},
896 {"LSN", NULL
, "RSYNC"},
897 {"EARP", NULL
, "RSYNC"},
898 {"EARN", NULL
, "RSYNC"},
902 * Use MUTE_LEFT & MUTE_RIGHT to implement digital mute.
903 * These bits can also be used to mute.
905 static int pm860x_digital_mute(struct snd_soc_dai
*codec_dai
, int mute
)
907 struct snd_soc_component
*component
= codec_dai
->component
;
908 int data
= 0, mask
= MUTE_LEFT
| MUTE_RIGHT
;
912 snd_soc_component_update_bits(component
, PM860X_DAC_OFFSET
, mask
, data
);
913 snd_soc_component_update_bits(component
, PM860X_EAR_CTRL_2
,
914 RSYNC_CHANGE
, RSYNC_CHANGE
);
918 static int pm860x_pcm_hw_params(struct snd_pcm_substream
*substream
,
919 struct snd_pcm_hw_params
*params
,
920 struct snd_soc_dai
*dai
)
922 struct snd_soc_component
*component
= dai
->component
;
923 unsigned char inf
= 0, mask
= 0;
926 switch (params_width(params
)) {
928 inf
&= ~PCM_INF2_18WL
;
931 inf
|= PCM_INF2_18WL
;
936 mask
|= PCM_INF2_18WL
;
937 snd_soc_component_update_bits(component
, PM860X_PCM_IFACE_2
, mask
, inf
);
940 switch (params_rate(params
)) {
956 snd_soc_component_update_bits(component
, PM860X_PCM_RATE
, 0x0f, inf
);
961 static int pm860x_pcm_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
964 struct snd_soc_component
*component
= codec_dai
->component
;
965 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
966 unsigned char inf
= 0, mask
= 0;
969 mask
|= PCM_INF2_BCLK
| PCM_INF2_FS
| PCM_INF2_MASTER
;
971 /* set master/slave audio interface */
972 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
973 case SND_SOC_DAIFMT_CBM_CFM
:
974 case SND_SOC_DAIFMT_CBM_CFS
:
975 if (pm860x
->dir
== PM860X_CLK_DIR_OUT
) {
976 inf
|= PCM_INF2_MASTER
;
980 case SND_SOC_DAIFMT_CBS_CFS
:
981 if (pm860x
->dir
== PM860X_CLK_DIR_IN
) {
982 inf
&= ~PCM_INF2_MASTER
;
988 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
989 case SND_SOC_DAIFMT_I2S
:
990 inf
|= PCM_EXACT_I2S
;
994 mask
|= PCM_MODE_MASK
;
997 snd_soc_component_update_bits(component
, PM860X_PCM_IFACE_2
, mask
, inf
);
1001 static int pm860x_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
1002 int clk_id
, unsigned int freq
, int dir
)
1004 struct snd_soc_component
*component
= codec_dai
->component
;
1005 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1007 if (dir
== PM860X_CLK_DIR_OUT
)
1008 pm860x
->dir
= PM860X_CLK_DIR_OUT
;
1009 else /* Slave mode is not supported */
1015 static int pm860x_i2s_hw_params(struct snd_pcm_substream
*substream
,
1016 struct snd_pcm_hw_params
*params
,
1017 struct snd_soc_dai
*dai
)
1019 struct snd_soc_component
*component
= dai
->component
;
1023 switch (params_width(params
)) {
1028 inf
= PCM_INF2_18WL
;
1033 snd_soc_component_update_bits(component
, PM860X_I2S_IFACE_2
, PCM_INF2_18WL
, inf
);
1036 switch (params_rate(params
)) {
1061 snd_soc_component_update_bits(component
, PM860X_I2S_IFACE_4
, 0xf, inf
);
1066 static int pm860x_i2s_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
1069 struct snd_soc_component
*component
= codec_dai
->component
;
1070 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1071 unsigned char inf
= 0, mask
= 0;
1073 mask
|= PCM_INF2_BCLK
| PCM_INF2_FS
| PCM_INF2_MASTER
;
1075 /* set master/slave audio interface */
1076 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1077 case SND_SOC_DAIFMT_CBM_CFM
:
1078 if (pm860x
->dir
== PM860X_CLK_DIR_OUT
)
1079 inf
|= PCM_INF2_MASTER
;
1083 case SND_SOC_DAIFMT_CBS_CFS
:
1084 if (pm860x
->dir
== PM860X_CLK_DIR_IN
)
1085 inf
&= ~PCM_INF2_MASTER
;
1093 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1094 case SND_SOC_DAIFMT_I2S
:
1095 inf
|= PCM_EXACT_I2S
;
1100 mask
|= PCM_MODE_MASK
;
1101 snd_soc_component_update_bits(component
, PM860X_I2S_IFACE_2
, mask
, inf
);
1105 static int pm860x_set_bias_level(struct snd_soc_component
*component
,
1106 enum snd_soc_bias_level level
)
1108 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1112 case SND_SOC_BIAS_ON
:
1115 case SND_SOC_BIAS_PREPARE
:
1118 case SND_SOC_BIAS_STANDBY
:
1119 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
1120 /* Enable Audio PLL & Audio section */
1121 data
= AUDIO_PLL
| AUDIO_SECTION_ON
;
1122 pm860x_reg_write(pm860x
->i2c
, REG_MISC2
, data
);
1124 data
= AUDIO_PLL
| AUDIO_SECTION_RESET
1126 pm860x_reg_write(pm860x
->i2c
, REG_MISC2
, data
);
1130 case SND_SOC_BIAS_OFF
:
1131 data
= AUDIO_PLL
| AUDIO_SECTION_RESET
| AUDIO_SECTION_ON
;
1132 pm860x_set_bits(pm860x
->i2c
, REG_MISC2
, data
, 0);
1138 static const struct snd_soc_dai_ops pm860x_pcm_dai_ops
= {
1139 .digital_mute
= pm860x_digital_mute
,
1140 .hw_params
= pm860x_pcm_hw_params
,
1141 .set_fmt
= pm860x_pcm_set_dai_fmt
,
1142 .set_sysclk
= pm860x_set_dai_sysclk
,
1145 static const struct snd_soc_dai_ops pm860x_i2s_dai_ops
= {
1146 .digital_mute
= pm860x_digital_mute
,
1147 .hw_params
= pm860x_i2s_hw_params
,
1148 .set_fmt
= pm860x_i2s_set_dai_fmt
,
1149 .set_sysclk
= pm860x_set_dai_sysclk
,
1152 #define PM860X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | \
1153 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
1155 static struct snd_soc_dai_driver pm860x_dai
[] = {
1158 .name
= "88pm860x-pcm",
1161 .stream_name
= "PCM Playback",
1164 .rates
= PM860X_RATES
,
1165 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| \
1166 SNDRV_PCM_FMTBIT_S18_3LE
,
1169 .stream_name
= "PCM Capture",
1172 .rates
= PM860X_RATES
,
1173 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| \
1174 SNDRV_PCM_FMTBIT_S18_3LE
,
1176 .ops
= &pm860x_pcm_dai_ops
,
1179 .name
= "88pm860x-i2s",
1182 .stream_name
= "I2S Playback",
1185 .rates
= SNDRV_PCM_RATE_8000_48000
,
1186 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| \
1187 SNDRV_PCM_FMTBIT_S18_3LE
,
1190 .stream_name
= "I2S Capture",
1193 .rates
= SNDRV_PCM_RATE_8000_48000
,
1194 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| \
1195 SNDRV_PCM_FMTBIT_S18_3LE
,
1197 .ops
= &pm860x_i2s_dai_ops
,
1201 static irqreturn_t
pm860x_component_handler(int irq
, void *data
)
1203 struct pm860x_priv
*pm860x
= data
;
1204 int status
, shrt
, report
= 0, mic_report
= 0;
1207 status
= pm860x_reg_read(pm860x
->i2c
, REG_STATUS_1
);
1208 shrt
= pm860x_reg_read(pm860x
->i2c
, REG_SHORTS
);
1209 mask
= pm860x
->det
.hs_shrt
| pm860x
->det
.hook_det
| pm860x
->det
.lo_shrt
1210 | pm860x
->det
.hp_det
;
1212 #ifndef CONFIG_SND_SOC_88PM860X_MODULE
1213 if (status
& (HEADSET_STATUS
| MIC_STATUS
| SHORT_HS1
| SHORT_HS2
|
1214 SHORT_LO1
| SHORT_LO2
))
1215 trace_snd_soc_jack_irq(dev_name(pm860x
->component
->dev
));
1218 if ((pm860x
->det
.hp_det
& SND_JACK_HEADPHONE
)
1219 && (status
& HEADSET_STATUS
))
1220 report
|= SND_JACK_HEADPHONE
;
1222 if ((pm860x
->det
.mic_det
& SND_JACK_MICROPHONE
)
1223 && (status
& MIC_STATUS
))
1224 mic_report
|= SND_JACK_MICROPHONE
;
1226 if (pm860x
->det
.hs_shrt
&& (shrt
& (SHORT_HS1
| SHORT_HS2
)))
1227 report
|= pm860x
->det
.hs_shrt
;
1229 if (pm860x
->det
.hook_det
&& (status
& HOOK_STATUS
))
1230 report
|= pm860x
->det
.hook_det
;
1232 if (pm860x
->det
.lo_shrt
&& (shrt
& (SHORT_LO1
| SHORT_LO2
)))
1233 report
|= pm860x
->det
.lo_shrt
;
1236 snd_soc_jack_report(pm860x
->det
.hp_jack
, report
, mask
);
1238 snd_soc_jack_report(pm860x
->det
.mic_jack
, SND_JACK_MICROPHONE
,
1239 SND_JACK_MICROPHONE
);
1241 dev_dbg(pm860x
->component
->dev
, "headphone report:0x%x, mask:%x\n",
1243 dev_dbg(pm860x
->component
->dev
, "microphone report:0x%x\n", mic_report
);
1247 int pm860x_hs_jack_detect(struct snd_soc_component
*component
,
1248 struct snd_soc_jack
*jack
,
1249 int det
, int hook
, int hs_shrt
, int lo_shrt
)
1251 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1254 pm860x
->det
.hp_jack
= jack
;
1255 pm860x
->det
.hp_det
= det
;
1256 pm860x
->det
.hook_det
= hook
;
1257 pm860x
->det
.hs_shrt
= hs_shrt
;
1258 pm860x
->det
.lo_shrt
= lo_shrt
;
1260 if (det
& SND_JACK_HEADPHONE
)
1261 pm860x_set_bits(pm860x
->i2c
, REG_HS_DET
,
1262 EN_HS_DET
, EN_HS_DET
);
1263 /* headset short detect */
1265 data
= CLR_SHORT_HS2
| CLR_SHORT_HS1
;
1266 pm860x_set_bits(pm860x
->i2c
, REG_SHORTS
, data
, data
);
1268 /* Lineout short detect */
1270 data
= CLR_SHORT_LO2
| CLR_SHORT_LO1
;
1271 pm860x_set_bits(pm860x
->i2c
, REG_SHORTS
, data
, data
);
1275 pm860x_component_handler(0, pm860x
);
1278 EXPORT_SYMBOL_GPL(pm860x_hs_jack_detect
);
1280 int pm860x_mic_jack_detect(struct snd_soc_component
*component
,
1281 struct snd_soc_jack
*jack
, int det
)
1283 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1285 pm860x
->det
.mic_jack
= jack
;
1286 pm860x
->det
.mic_det
= det
;
1288 if (det
& SND_JACK_MICROPHONE
)
1289 pm860x_set_bits(pm860x
->i2c
, REG_MIC_DET
,
1290 MICDET_MASK
, MICDET_MASK
);
1293 pm860x_component_handler(0, pm860x
);
1296 EXPORT_SYMBOL_GPL(pm860x_mic_jack_detect
);
1298 static int pm860x_probe(struct snd_soc_component
*component
)
1300 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1303 pm860x
->component
= component
;
1304 snd_soc_component_init_regmap(component
, pm860x
->regmap
);
1306 for (i
= 0; i
< 4; i
++) {
1307 ret
= request_threaded_irq(pm860x
->irq
[i
], NULL
,
1308 pm860x_component_handler
, IRQF_ONESHOT
,
1309 pm860x
->name
[i
], pm860x
);
1311 dev_err(component
->dev
, "Failed to request IRQ!\n");
1320 free_irq(pm860x
->irq
[i
], pm860x
);
1324 static void pm860x_remove(struct snd_soc_component
*component
)
1326 struct pm860x_priv
*pm860x
= snd_soc_component_get_drvdata(component
);
1329 for (i
= 3; i
>= 0; i
--)
1330 free_irq(pm860x
->irq
[i
], pm860x
);
1333 static const struct snd_soc_component_driver soc_component_dev_pm860x
= {
1334 .probe
= pm860x_probe
,
1335 .remove
= pm860x_remove
,
1336 .set_bias_level
= pm860x_set_bias_level
,
1337 .controls
= pm860x_snd_controls
,
1338 .num_controls
= ARRAY_SIZE(pm860x_snd_controls
),
1339 .dapm_widgets
= pm860x_dapm_widgets
,
1340 .num_dapm_widgets
= ARRAY_SIZE(pm860x_dapm_widgets
),
1341 .dapm_routes
= pm860x_dapm_routes
,
1342 .num_dapm_routes
= ARRAY_SIZE(pm860x_dapm_routes
),
1344 .use_pmdown_time
= 1,
1346 .non_legacy_dai_naming
= 1,
1349 static int pm860x_codec_probe(struct platform_device
*pdev
)
1351 struct pm860x_chip
*chip
= dev_get_drvdata(pdev
->dev
.parent
);
1352 struct pm860x_priv
*pm860x
;
1353 struct resource
*res
;
1356 pm860x
= devm_kzalloc(&pdev
->dev
, sizeof(struct pm860x_priv
),
1361 pm860x
->chip
= chip
;
1362 pm860x
->i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client
1364 pm860x
->regmap
= (chip
->id
== CHIP_PM8607
) ? chip
->regmap
1365 : chip
->regmap_companion
;
1366 platform_set_drvdata(pdev
, pm860x
);
1368 for (i
= 0; i
< 4; i
++) {
1369 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, i
);
1371 dev_err(&pdev
->dev
, "Failed to get IRQ resources\n");
1374 pm860x
->irq
[i
] = res
->start
+ chip
->irq_base
;
1375 strncpy(pm860x
->name
[i
], res
->name
, MAX_NAME_LEN
);
1378 ret
= devm_snd_soc_register_component(&pdev
->dev
,
1379 &soc_component_dev_pm860x
,
1380 pm860x_dai
, ARRAY_SIZE(pm860x_dai
));
1382 dev_err(&pdev
->dev
, "Failed to register component\n");
1388 static int pm860x_codec_remove(struct platform_device
*pdev
)
1393 static struct platform_driver pm860x_codec_driver
= {
1395 .name
= "88pm860x-codec",
1397 .probe
= pm860x_codec_probe
,
1398 .remove
= pm860x_codec_remove
,
1401 module_platform_driver(pm860x_codec_driver
);
1403 MODULE_DESCRIPTION("ASoC 88PM860x driver");
1404 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
1405 MODULE_LICENSE("GPL");
1406 MODULE_ALIAS("platform:88pm860x-codec");