1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs43130.c -- CS43130 ALSA Soc Audio driver
5 * Copyright 2017 Cirrus Logic, Inc.
7 * Authors: Li Xu <li.xu@cirrus.com>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/gpio.h>
15 #include <linux/gpio/consumer.h>
16 #include <linux/platform_device.h>
18 #include <linux/i2c.h>
19 #include <linux/of_device.h>
20 #include <linux/regmap.h>
21 #include <linux/slab.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/soc-dapm.h>
27 #include <sound/initval.h>
28 #include <sound/tlv.h>
29 #include <linux/of_gpio.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/pm_runtime.h>
32 #include <linux/of_irq.h>
33 #include <linux/completion.h>
34 #include <linux/mutex.h>
35 #include <linux/workqueue.h>
36 #include <sound/jack.h>
40 static const struct reg_default cs43130_reg_defaults
[] = {
41 {CS43130_SYS_CLK_CTL_1
, 0x06},
42 {CS43130_SP_SRATE
, 0x01},
43 {CS43130_SP_BITSIZE
, 0x05},
44 {CS43130_PAD_INT_CFG
, 0x03},
45 {CS43130_PWDN_CTL
, 0xFE},
46 {CS43130_CRYSTAL_SET
, 0x04},
47 {CS43130_PLL_SET_1
, 0x00},
48 {CS43130_PLL_SET_2
, 0x00},
49 {CS43130_PLL_SET_3
, 0x00},
50 {CS43130_PLL_SET_4
, 0x00},
51 {CS43130_PLL_SET_5
, 0x40},
52 {CS43130_PLL_SET_6
, 0x10},
53 {CS43130_PLL_SET_7
, 0x80},
54 {CS43130_PLL_SET_8
, 0x03},
55 {CS43130_PLL_SET_9
, 0x02},
56 {CS43130_PLL_SET_10
, 0x02},
57 {CS43130_CLKOUT_CTL
, 0x00},
58 {CS43130_ASP_NUM_1
, 0x01},
59 {CS43130_ASP_NUM_2
, 0x00},
60 {CS43130_ASP_DEN_1
, 0x08},
61 {CS43130_ASP_DEN_2
, 0x00},
62 {CS43130_ASP_LRCK_HI_TIME_1
, 0x1F},
63 {CS43130_ASP_LRCK_HI_TIME_2
, 0x00},
64 {CS43130_ASP_LRCK_PERIOD_1
, 0x3F},
65 {CS43130_ASP_LRCK_PERIOD_2
, 0x00},
66 {CS43130_ASP_CLOCK_CONF
, 0x0C},
67 {CS43130_ASP_FRAME_CONF
, 0x0A},
68 {CS43130_XSP_NUM_1
, 0x01},
69 {CS43130_XSP_NUM_2
, 0x00},
70 {CS43130_XSP_DEN_1
, 0x02},
71 {CS43130_XSP_DEN_2
, 0x00},
72 {CS43130_XSP_LRCK_HI_TIME_1
, 0x1F},
73 {CS43130_XSP_LRCK_HI_TIME_2
, 0x00},
74 {CS43130_XSP_LRCK_PERIOD_1
, 0x3F},
75 {CS43130_XSP_LRCK_PERIOD_2
, 0x00},
76 {CS43130_XSP_CLOCK_CONF
, 0x0C},
77 {CS43130_XSP_FRAME_CONF
, 0x0A},
78 {CS43130_ASP_CH_1_LOC
, 0x00},
79 {CS43130_ASP_CH_2_LOC
, 0x00},
80 {CS43130_ASP_CH_1_SZ_EN
, 0x06},
81 {CS43130_ASP_CH_2_SZ_EN
, 0x0E},
82 {CS43130_XSP_CH_1_LOC
, 0x00},
83 {CS43130_XSP_CH_2_LOC
, 0x00},
84 {CS43130_XSP_CH_1_SZ_EN
, 0x06},
85 {CS43130_XSP_CH_2_SZ_EN
, 0x0E},
86 {CS43130_DSD_VOL_B
, 0x78},
87 {CS43130_DSD_VOL_A
, 0x78},
88 {CS43130_DSD_PATH_CTL_1
, 0xA8},
89 {CS43130_DSD_INT_CFG
, 0x00},
90 {CS43130_DSD_PATH_CTL_2
, 0x02},
91 {CS43130_DSD_PCM_MIX_CTL
, 0x00},
92 {CS43130_DSD_PATH_CTL_3
, 0x40},
93 {CS43130_HP_OUT_CTL_1
, 0x30},
94 {CS43130_PCM_FILT_OPT
, 0x02},
95 {CS43130_PCM_VOL_B
, 0x78},
96 {CS43130_PCM_VOL_A
, 0x78},
97 {CS43130_PCM_PATH_CTL_1
, 0xA8},
98 {CS43130_PCM_PATH_CTL_2
, 0x00},
99 {CS43130_CLASS_H_CTL
, 0x1E},
100 {CS43130_HP_DETECT
, 0x04},
101 {CS43130_HP_LOAD_1
, 0x00},
102 {CS43130_HP_MEAS_LOAD_1
, 0x00},
103 {CS43130_HP_MEAS_LOAD_2
, 0x00},
104 {CS43130_INT_MASK_1
, 0xFF},
105 {CS43130_INT_MASK_2
, 0xFF},
106 {CS43130_INT_MASK_3
, 0xFF},
107 {CS43130_INT_MASK_4
, 0xFF},
108 {CS43130_INT_MASK_5
, 0xFF},
111 static bool cs43130_volatile_register(struct device
*dev
, unsigned int reg
)
114 case CS43130_INT_STATUS_1
... CS43130_INT_STATUS_5
:
115 case CS43130_HP_DC_STAT_1
... CS43130_HP_DC_STAT_2
:
116 case CS43130_HP_AC_STAT_1
... CS43130_HP_AC_STAT_2
:
123 static bool cs43130_readable_register(struct device
*dev
, unsigned int reg
)
126 case CS43130_DEVID_AB
... CS43130_SYS_CLK_CTL_1
:
127 case CS43130_SP_SRATE
... CS43130_PAD_INT_CFG
:
128 case CS43130_PWDN_CTL
:
129 case CS43130_CRYSTAL_SET
:
130 case CS43130_PLL_SET_1
... CS43130_PLL_SET_5
:
131 case CS43130_PLL_SET_6
:
132 case CS43130_PLL_SET_7
:
133 case CS43130_PLL_SET_8
:
134 case CS43130_PLL_SET_9
:
135 case CS43130_PLL_SET_10
:
136 case CS43130_CLKOUT_CTL
:
137 case CS43130_ASP_NUM_1
... CS43130_ASP_FRAME_CONF
:
138 case CS43130_XSP_NUM_1
... CS43130_XSP_FRAME_CONF
:
139 case CS43130_ASP_CH_1_LOC
:
140 case CS43130_ASP_CH_2_LOC
:
141 case CS43130_ASP_CH_1_SZ_EN
:
142 case CS43130_ASP_CH_2_SZ_EN
:
143 case CS43130_XSP_CH_1_LOC
:
144 case CS43130_XSP_CH_2_LOC
:
145 case CS43130_XSP_CH_1_SZ_EN
:
146 case CS43130_XSP_CH_2_SZ_EN
:
147 case CS43130_DSD_VOL_B
... CS43130_DSD_PATH_CTL_3
:
148 case CS43130_HP_OUT_CTL_1
:
149 case CS43130_PCM_FILT_OPT
... CS43130_PCM_PATH_CTL_2
:
150 case CS43130_CLASS_H_CTL
:
151 case CS43130_HP_DETECT
:
152 case CS43130_HP_STATUS
:
153 case CS43130_HP_LOAD_1
:
154 case CS43130_HP_MEAS_LOAD_1
:
155 case CS43130_HP_MEAS_LOAD_2
:
156 case CS43130_HP_DC_STAT_1
:
157 case CS43130_HP_DC_STAT_2
:
158 case CS43130_HP_AC_STAT_1
:
159 case CS43130_HP_AC_STAT_2
:
160 case CS43130_HP_LOAD_STAT
:
161 case CS43130_INT_STATUS_1
... CS43130_INT_STATUS_5
:
162 case CS43130_INT_MASK_1
... CS43130_INT_MASK_5
:
169 static bool cs43130_precious_register(struct device
*dev
, unsigned int reg
)
172 case CS43130_INT_STATUS_1
... CS43130_INT_STATUS_5
:
179 struct cs43130_pll_params
{
186 unsigned int pll_out
;
190 static const struct cs43130_pll_params pll_ratio_table
[] = {
191 {9600000, 0x02, 0x49, 0x800000, 0x00, 0x08, 22579200, 151},
192 {9600000, 0x02, 0x50, 0x000000, 0x00, 0x08, 24576000, 164},
194 {11289600, 0x02, 0X40, 0, 0x01, 0x08, 22579200, 128},
195 {11289600, 0x02, 0x44, 0x06F700, 0x0, 0x08, 24576000, 139},
197 {12000000, 0x02, 0x49, 0x800000, 0x00, 0x0A, 22579200, 120},
198 {12000000, 0x02, 0x40, 0x000000, 0x00, 0x08, 24576000, 131},
200 {12288000, 0x02, 0x49, 0x800000, 0x01, 0x0A, 22579200, 118},
201 {12288000, 0x02, 0x40, 0x000000, 0x01, 0x08, 24576000, 128},
203 {13000000, 0x02, 0x45, 0x797680, 0x01, 0x0A, 22579200, 111},
204 {13000000, 0x02, 0x3C, 0x7EA940, 0x01, 0x08, 24576000, 121},
206 {19200000, 0x03, 0x49, 0x800000, 0x00, 0x08, 22579200, 151},
207 {19200000, 0x03, 0x50, 0x000000, 0x00, 0x08, 24576000, 164},
209 {22579200, 0, 0, 0, 0, 0, 22579200, 0},
210 {22579200, 0x03, 0x44, 0x06F700, 0x00, 0x08, 24576000, 139},
212 {24000000, 0x03, 0x49, 0x800000, 0x00, 0x0A, 22579200, 120},
213 {24000000, 0x03, 0x40, 0x000000, 0x00, 0x08, 24576000, 131},
215 {24576000, 0x03, 0x49, 0x800000, 0x01, 0x0A, 22579200, 118},
216 {24576000, 0, 0, 0, 0, 0, 24576000, 0},
218 {26000000, 0x03, 0x45, 0x797680, 0x01, 0x0A, 22579200, 111},
219 {26000000, 0x03, 0x3C, 0x7EA940, 0x01, 0x08, 24576000, 121},
222 static const struct cs43130_pll_params
*cs43130_get_pll_table(
223 unsigned int freq_in
, unsigned int freq_out
)
227 for (i
= 0; i
< ARRAY_SIZE(pll_ratio_table
); i
++) {
228 if (pll_ratio_table
[i
].pll_in
== freq_in
&&
229 pll_ratio_table
[i
].pll_out
== freq_out
)
230 return &pll_ratio_table
[i
];
236 static int cs43130_pll_config(struct snd_soc_component
*component
)
238 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
239 const struct cs43130_pll_params
*pll_entry
;
241 dev_dbg(component
->dev
, "cs43130->mclk = %u, cs43130->mclk_int = %u\n",
242 cs43130
->mclk
, cs43130
->mclk_int
);
244 pll_entry
= cs43130_get_pll_table(cs43130
->mclk
, cs43130
->mclk_int
);
248 if (pll_entry
->pll_cal_ratio
== 0) {
249 regmap_update_bits(cs43130
->regmap
, CS43130_PLL_SET_1
,
250 CS43130_PLL_START_MASK
, 0);
252 cs43130
->pll_bypass
= true;
256 cs43130
->pll_bypass
= false;
258 regmap_update_bits(cs43130
->regmap
, CS43130_PLL_SET_2
,
259 CS43130_PLL_DIV_DATA_MASK
,
260 pll_entry
->pll_div_frac
>>
261 CS43130_PLL_DIV_FRAC_0_DATA_SHIFT
);
262 regmap_update_bits(cs43130
->regmap
, CS43130_PLL_SET_3
,
263 CS43130_PLL_DIV_DATA_MASK
,
264 pll_entry
->pll_div_frac
>>
265 CS43130_PLL_DIV_FRAC_1_DATA_SHIFT
);
266 regmap_update_bits(cs43130
->regmap
, CS43130_PLL_SET_4
,
267 CS43130_PLL_DIV_DATA_MASK
,
268 pll_entry
->pll_div_frac
>>
269 CS43130_PLL_DIV_FRAC_2_DATA_SHIFT
);
270 regmap_write(cs43130
->regmap
, CS43130_PLL_SET_5
,
271 pll_entry
->pll_div_int
);
272 regmap_write(cs43130
->regmap
, CS43130_PLL_SET_6
, pll_entry
->pll_divout
);
273 regmap_write(cs43130
->regmap
, CS43130_PLL_SET_7
,
274 pll_entry
->pll_cal_ratio
);
275 regmap_update_bits(cs43130
->regmap
, CS43130_PLL_SET_8
,
276 CS43130_PLL_MODE_MASK
,
277 pll_entry
->pll_mode
<< CS43130_PLL_MODE_SHIFT
);
278 regmap_write(cs43130
->regmap
, CS43130_PLL_SET_9
,
279 pll_entry
->sclk_prediv
);
280 regmap_update_bits(cs43130
->regmap
, CS43130_PLL_SET_1
,
281 CS43130_PLL_START_MASK
, 1);
286 static int cs43130_set_pll(struct snd_soc_component
*component
, int pll_id
, int source
,
287 unsigned int freq_in
, unsigned int freq_out
)
290 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
303 cs43130
->mclk
= freq_in
;
306 dev_err(component
->dev
,
307 "unsupported pll input reference clock:%d\n", freq_in
);
313 cs43130
->mclk_int
= freq_out
;
316 cs43130
->mclk_int
= freq_out
;
319 dev_err(component
->dev
,
320 "unsupported pll output ref clock: %u\n", freq_out
);
324 ret
= cs43130_pll_config(component
);
325 dev_dbg(component
->dev
, "cs43130->pll_bypass = %d", cs43130
->pll_bypass
);
329 static int cs43130_change_clksrc(struct snd_soc_component
*component
,
330 enum cs43130_mclk_src_sel src
)
333 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
334 int mclk_int_decoded
;
336 if (src
== cs43130
->mclk_int_src
) {
337 /* clk source has not changed */
341 switch (cs43130
->mclk_int
) {
342 case CS43130_MCLK_22M
:
343 mclk_int_decoded
= CS43130_MCLK_22P5
;
345 case CS43130_MCLK_24M
:
346 mclk_int_decoded
= CS43130_MCLK_24P5
;
349 dev_err(component
->dev
, "Invalid MCLK INT freq: %u\n", cs43130
->mclk_int
);
354 case CS43130_MCLK_SRC_EXT
:
355 cs43130
->pll_bypass
= true;
356 cs43130
->mclk_int_src
= CS43130_MCLK_SRC_EXT
;
357 if (cs43130
->xtal_ibias
== CS43130_XTAL_UNUSED
) {
358 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
359 CS43130_PDN_XTAL_MASK
,
360 1 << CS43130_PDN_XTAL_SHIFT
);
362 reinit_completion(&cs43130
->xtal_rdy
);
363 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
364 CS43130_XTAL_RDY_INT_MASK
, 0);
365 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
366 CS43130_PDN_XTAL_MASK
, 0);
367 ret
= wait_for_completion_timeout(&cs43130
->xtal_rdy
,
368 msecs_to_jiffies(100));
369 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
370 CS43130_XTAL_RDY_INT_MASK
,
371 1 << CS43130_XTAL_RDY_INT_SHIFT
);
373 dev_err(component
->dev
, "Timeout waiting for XTAL_READY interrupt\n");
378 regmap_update_bits(cs43130
->regmap
, CS43130_SYS_CLK_CTL_1
,
379 CS43130_MCLK_SRC_SEL_MASK
,
380 src
<< CS43130_MCLK_SRC_SEL_SHIFT
);
381 regmap_update_bits(cs43130
->regmap
, CS43130_SYS_CLK_CTL_1
,
382 CS43130_MCLK_INT_MASK
,
383 mclk_int_decoded
<< CS43130_MCLK_INT_SHIFT
);
384 usleep_range(150, 200);
386 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
387 CS43130_PDN_PLL_MASK
,
388 1 << CS43130_PDN_PLL_SHIFT
);
390 case CS43130_MCLK_SRC_PLL
:
391 cs43130
->pll_bypass
= false;
392 cs43130
->mclk_int_src
= CS43130_MCLK_SRC_PLL
;
393 if (cs43130
->xtal_ibias
== CS43130_XTAL_UNUSED
) {
394 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
395 CS43130_PDN_XTAL_MASK
,
396 1 << CS43130_PDN_XTAL_SHIFT
);
398 reinit_completion(&cs43130
->xtal_rdy
);
399 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
400 CS43130_XTAL_RDY_INT_MASK
, 0);
401 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
402 CS43130_PDN_XTAL_MASK
, 0);
403 ret
= wait_for_completion_timeout(&cs43130
->xtal_rdy
,
404 msecs_to_jiffies(100));
405 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
406 CS43130_XTAL_RDY_INT_MASK
,
407 1 << CS43130_XTAL_RDY_INT_SHIFT
);
409 dev_err(component
->dev
, "Timeout waiting for XTAL_READY interrupt\n");
414 reinit_completion(&cs43130
->pll_rdy
);
415 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
416 CS43130_PLL_RDY_INT_MASK
, 0);
417 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
418 CS43130_PDN_PLL_MASK
, 0);
419 ret
= wait_for_completion_timeout(&cs43130
->pll_rdy
,
420 msecs_to_jiffies(100));
421 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
422 CS43130_PLL_RDY_INT_MASK
,
423 1 << CS43130_PLL_RDY_INT_SHIFT
);
425 dev_err(component
->dev
, "Timeout waiting for PLL_READY interrupt\n");
429 regmap_update_bits(cs43130
->regmap
, CS43130_SYS_CLK_CTL_1
,
430 CS43130_MCLK_SRC_SEL_MASK
,
431 src
<< CS43130_MCLK_SRC_SEL_SHIFT
);
432 regmap_update_bits(cs43130
->regmap
, CS43130_SYS_CLK_CTL_1
,
433 CS43130_MCLK_INT_MASK
,
434 mclk_int_decoded
<< CS43130_MCLK_INT_SHIFT
);
435 usleep_range(150, 200);
437 case CS43130_MCLK_SRC_RCO
:
438 cs43130
->mclk_int_src
= CS43130_MCLK_SRC_RCO
;
440 regmap_update_bits(cs43130
->regmap
, CS43130_SYS_CLK_CTL_1
,
441 CS43130_MCLK_SRC_SEL_MASK
,
442 src
<< CS43130_MCLK_SRC_SEL_SHIFT
);
443 regmap_update_bits(cs43130
->regmap
, CS43130_SYS_CLK_CTL_1
,
444 CS43130_MCLK_INT_MASK
,
445 CS43130_MCLK_22P5
<< CS43130_MCLK_INT_SHIFT
);
446 usleep_range(150, 200);
448 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
449 CS43130_PDN_XTAL_MASK
,
450 1 << CS43130_PDN_XTAL_SHIFT
);
451 regmap_update_bits(cs43130
->regmap
, CS43130_PWDN_CTL
,
452 CS43130_PDN_PLL_MASK
,
453 1 << CS43130_PDN_PLL_SHIFT
);
456 dev_err(component
->dev
, "Invalid MCLK source value\n");
463 static const struct cs43130_bitwidth_map cs43130_bitwidth_table
[] = {
464 {8, CS43130_SP_BIT_SIZE_8
, CS43130_CH_BIT_SIZE_8
},
465 {16, CS43130_SP_BIT_SIZE_16
, CS43130_CH_BIT_SIZE_16
},
466 {24, CS43130_SP_BIT_SIZE_24
, CS43130_CH_BIT_SIZE_24
},
467 {32, CS43130_SP_BIT_SIZE_32
, CS43130_CH_BIT_SIZE_32
},
470 static const struct cs43130_bitwidth_map
*cs43130_get_bitwidth_table(
471 unsigned int bitwidth
)
475 for (i
= 0; i
< ARRAY_SIZE(cs43130_bitwidth_table
); i
++) {
476 if (cs43130_bitwidth_table
[i
].bitwidth
== bitwidth
)
477 return &cs43130_bitwidth_table
[i
];
483 static int cs43130_set_bitwidth(int dai_id
, unsigned int bitwidth_dai
,
484 struct regmap
*regmap
)
486 const struct cs43130_bitwidth_map
*bw_map
;
488 bw_map
= cs43130_get_bitwidth_table(bitwidth_dai
);
493 case CS43130_ASP_PCM_DAI
:
494 case CS43130_ASP_DOP_DAI
:
495 regmap_update_bits(regmap
, CS43130_ASP_CH_1_SZ_EN
,
496 CS43130_CH_BITSIZE_MASK
, bw_map
->ch_bit
);
497 regmap_update_bits(regmap
, CS43130_ASP_CH_2_SZ_EN
,
498 CS43130_CH_BITSIZE_MASK
, bw_map
->ch_bit
);
499 regmap_update_bits(regmap
, CS43130_SP_BITSIZE
,
500 CS43130_ASP_BITSIZE_MASK
, bw_map
->sp_bit
);
502 case CS43130_XSP_DOP_DAI
:
503 regmap_update_bits(regmap
, CS43130_XSP_CH_1_SZ_EN
,
504 CS43130_CH_BITSIZE_MASK
, bw_map
->ch_bit
);
505 regmap_update_bits(regmap
, CS43130_XSP_CH_2_SZ_EN
,
506 CS43130_CH_BITSIZE_MASK
, bw_map
->ch_bit
);
507 regmap_update_bits(regmap
, CS43130_SP_BITSIZE
,
508 CS43130_XSP_BITSIZE_MASK
, bw_map
->sp_bit
<<
509 CS43130_XSP_BITSIZE_SHIFT
);
518 static const struct cs43130_rate_map cs43130_rate_table
[] = {
519 {32000, CS43130_ASP_SPRATE_32K
},
520 {44100, CS43130_ASP_SPRATE_44_1K
},
521 {48000, CS43130_ASP_SPRATE_48K
},
522 {88200, CS43130_ASP_SPRATE_88_2K
},
523 {96000, CS43130_ASP_SPRATE_96K
},
524 {176400, CS43130_ASP_SPRATE_176_4K
},
525 {192000, CS43130_ASP_SPRATE_192K
},
526 {352800, CS43130_ASP_SPRATE_352_8K
},
527 {384000, CS43130_ASP_SPRATE_384K
},
530 static const struct cs43130_rate_map
*cs43130_get_rate_table(int fs
)
534 for (i
= 0; i
< ARRAY_SIZE(cs43130_rate_table
); i
++) {
535 if (cs43130_rate_table
[i
].fs
== fs
)
536 return &cs43130_rate_table
[i
];
542 static const struct cs43130_clk_gen
*cs43130_get_clk_gen(int mclk_int
, int fs
,
543 const struct cs43130_clk_gen
*clk_gen_table
, int len_clk_gen_table
)
547 for (i
= 0; i
< len_clk_gen_table
; i
++) {
548 if (clk_gen_table
[i
].mclk_int
== mclk_int
&&
549 clk_gen_table
[i
].fs
== fs
)
550 return &clk_gen_table
[i
];
556 static int cs43130_set_sp_fmt(int dai_id
, unsigned int bitwidth_sclk
,
557 struct snd_pcm_hw_params
*params
,
558 struct cs43130_private
*cs43130
)
571 const struct cs43130_clk_gen
*clk_gen
;
573 switch (cs43130
->dais
[dai_id
].dai_format
) {
574 case SND_SOC_DAIFMT_I2S
:
575 hi_size
= bitwidth_sclk
;
579 case SND_SOC_DAIFMT_LEFT_J
:
580 hi_size
= bitwidth_sclk
;
584 case SND_SOC_DAIFMT_DSP_A
:
589 case SND_SOC_DAIFMT_DSP_B
:
598 switch (cs43130
->dais
[dai_id
].dai_mode
) {
599 case SND_SOC_DAIFMT_CBS_CFS
:
602 case SND_SOC_DAIFMT_CBM_CFM
:
609 frm_size
= bitwidth_sclk
* params_channels(params
);
613 loc_ch2
= bitwidth_sclk
* (params_channels(params
) - 1);
615 frm_data
= frm_delay
& CS43130_SP_FSD_MASK
;
616 frm_data
|= (frm_phase
<< CS43130_SP_STP_SHIFT
) & CS43130_SP_STP_MASK
;
618 clk_data
= lrck_edge
& CS43130_SP_LCPOL_IN_MASK
;
619 clk_data
|= (lrck_edge
<< CS43130_SP_LCPOL_OUT_SHIFT
) &
620 CS43130_SP_LCPOL_OUT_MASK
;
621 clk_data
|= (sclk_edge
<< CS43130_SP_SCPOL_IN_SHIFT
) &
622 CS43130_SP_SCPOL_IN_MASK
;
623 clk_data
|= (sclk_edge
<< CS43130_SP_SCPOL_OUT_SHIFT
) &
624 CS43130_SP_SCPOL_OUT_MASK
;
625 clk_data
|= (dai_mode_val
<< CS43130_SP_MODE_SHIFT
) &
626 CS43130_SP_MODE_MASK
;
629 case CS43130_ASP_PCM_DAI
:
630 case CS43130_ASP_DOP_DAI
:
631 regmap_update_bits(cs43130
->regmap
, CS43130_ASP_LRCK_PERIOD_1
,
632 CS43130_SP_LCPR_DATA_MASK
, (frm_size
- 1) >>
633 CS43130_SP_LCPR_LSB_DATA_SHIFT
);
634 regmap_update_bits(cs43130
->regmap
, CS43130_ASP_LRCK_PERIOD_2
,
635 CS43130_SP_LCPR_DATA_MASK
, (frm_size
- 1) >>
636 CS43130_SP_LCPR_MSB_DATA_SHIFT
);
637 regmap_update_bits(cs43130
->regmap
, CS43130_ASP_LRCK_HI_TIME_1
,
638 CS43130_SP_LCHI_DATA_MASK
, (hi_size
- 1) >>
639 CS43130_SP_LCHI_LSB_DATA_SHIFT
);
640 regmap_update_bits(cs43130
->regmap
, CS43130_ASP_LRCK_HI_TIME_2
,
641 CS43130_SP_LCHI_DATA_MASK
, (hi_size
- 1) >>
642 CS43130_SP_LCHI_MSB_DATA_SHIFT
);
643 regmap_write(cs43130
->regmap
, CS43130_ASP_FRAME_CONF
, frm_data
);
644 regmap_write(cs43130
->regmap
, CS43130_ASP_CH_1_LOC
, loc_ch1
);
645 regmap_write(cs43130
->regmap
, CS43130_ASP_CH_2_LOC
, loc_ch2
);
646 regmap_update_bits(cs43130
->regmap
, CS43130_ASP_CH_1_SZ_EN
,
647 CS43130_CH_EN_MASK
, 1 << CS43130_CH_EN_SHIFT
);
648 regmap_update_bits(cs43130
->regmap
, CS43130_ASP_CH_2_SZ_EN
,
649 CS43130_CH_EN_MASK
, 1 << CS43130_CH_EN_SHIFT
);
650 regmap_write(cs43130
->regmap
, CS43130_ASP_CLOCK_CONF
, clk_data
);
652 case CS43130_XSP_DOP_DAI
:
653 regmap_update_bits(cs43130
->regmap
, CS43130_XSP_LRCK_PERIOD_1
,
654 CS43130_SP_LCPR_DATA_MASK
, (frm_size
- 1) >>
655 CS43130_SP_LCPR_LSB_DATA_SHIFT
);
656 regmap_update_bits(cs43130
->regmap
, CS43130_XSP_LRCK_PERIOD_2
,
657 CS43130_SP_LCPR_DATA_MASK
, (frm_size
- 1) >>
658 CS43130_SP_LCPR_MSB_DATA_SHIFT
);
659 regmap_update_bits(cs43130
->regmap
, CS43130_XSP_LRCK_HI_TIME_1
,
660 CS43130_SP_LCHI_DATA_MASK
, (hi_size
- 1) >>
661 CS43130_SP_LCHI_LSB_DATA_SHIFT
);
662 regmap_update_bits(cs43130
->regmap
, CS43130_XSP_LRCK_HI_TIME_2
,
663 CS43130_SP_LCHI_DATA_MASK
, (hi_size
- 1) >>
664 CS43130_SP_LCHI_MSB_DATA_SHIFT
);
665 regmap_write(cs43130
->regmap
, CS43130_XSP_FRAME_CONF
, frm_data
);
666 regmap_write(cs43130
->regmap
, CS43130_XSP_CH_1_LOC
, loc_ch1
);
667 regmap_write(cs43130
->regmap
, CS43130_XSP_CH_2_LOC
, loc_ch2
);
668 regmap_update_bits(cs43130
->regmap
, CS43130_XSP_CH_1_SZ_EN
,
669 CS43130_CH_EN_MASK
, 1 << CS43130_CH_EN_SHIFT
);
670 regmap_update_bits(cs43130
->regmap
, CS43130_XSP_CH_2_SZ_EN
,
671 CS43130_CH_EN_MASK
, 1 << CS43130_CH_EN_SHIFT
);
672 regmap_write(cs43130
->regmap
, CS43130_XSP_CLOCK_CONF
, clk_data
);
680 clk_gen
= cs43130_get_clk_gen(cs43130
->mclk_int
,
683 ARRAY_SIZE(cs43130_16_clk_gen
));
686 clk_gen
= cs43130_get_clk_gen(cs43130
->mclk_int
,
689 ARRAY_SIZE(cs43130_32_clk_gen
));
692 clk_gen
= cs43130_get_clk_gen(cs43130
->mclk_int
,
695 ARRAY_SIZE(cs43130_48_clk_gen
));
698 clk_gen
= cs43130_get_clk_gen(cs43130
->mclk_int
,
701 ARRAY_SIZE(cs43130_64_clk_gen
));
711 case CS43130_ASP_PCM_DAI
:
712 case CS43130_ASP_DOP_DAI
:
713 regmap_write(cs43130
->regmap
, CS43130_ASP_DEN_1
,
714 (clk_gen
->den
& CS43130_SP_M_LSB_DATA_MASK
) >>
715 CS43130_SP_M_LSB_DATA_SHIFT
);
716 regmap_write(cs43130
->regmap
, CS43130_ASP_DEN_2
,
717 (clk_gen
->den
& CS43130_SP_M_MSB_DATA_MASK
) >>
718 CS43130_SP_M_MSB_DATA_SHIFT
);
719 regmap_write(cs43130
->regmap
, CS43130_ASP_NUM_1
,
720 (clk_gen
->num
& CS43130_SP_N_LSB_DATA_MASK
) >>
721 CS43130_SP_N_LSB_DATA_SHIFT
);
722 regmap_write(cs43130
->regmap
, CS43130_ASP_NUM_2
,
723 (clk_gen
->num
& CS43130_SP_N_MSB_DATA_MASK
) >>
724 CS43130_SP_N_MSB_DATA_SHIFT
);
726 case CS43130_XSP_DOP_DAI
:
727 regmap_write(cs43130
->regmap
, CS43130_XSP_DEN_1
,
728 (clk_gen
->den
& CS43130_SP_M_LSB_DATA_MASK
) >>
729 CS43130_SP_M_LSB_DATA_SHIFT
);
730 regmap_write(cs43130
->regmap
, CS43130_XSP_DEN_2
,
731 (clk_gen
->den
& CS43130_SP_M_MSB_DATA_MASK
) >>
732 CS43130_SP_M_MSB_DATA_SHIFT
);
733 regmap_write(cs43130
->regmap
, CS43130_XSP_NUM_1
,
734 (clk_gen
->num
& CS43130_SP_N_LSB_DATA_MASK
) >>
735 CS43130_SP_N_LSB_DATA_SHIFT
);
736 regmap_write(cs43130
->regmap
, CS43130_XSP_NUM_2
,
737 (clk_gen
->num
& CS43130_SP_N_MSB_DATA_MASK
) >>
738 CS43130_SP_N_MSB_DATA_SHIFT
);
747 static int cs43130_pcm_dsd_mix(bool en
, struct regmap
*regmap
)
750 regmap_update_bits(regmap
, CS43130_DSD_PCM_MIX_CTL
,
751 CS43130_MIX_PCM_PREP_MASK
,
752 1 << CS43130_MIX_PCM_PREP_SHIFT
);
753 usleep_range(6000, 6050);
754 regmap_update_bits(regmap
, CS43130_DSD_PCM_MIX_CTL
,
755 CS43130_MIX_PCM_DSD_MASK
,
756 1 << CS43130_MIX_PCM_DSD_SHIFT
);
758 regmap_update_bits(regmap
, CS43130_DSD_PCM_MIX_CTL
,
759 CS43130_MIX_PCM_DSD_MASK
,
760 0 << CS43130_MIX_PCM_DSD_SHIFT
);
761 usleep_range(1600, 1650);
762 regmap_update_bits(regmap
, CS43130_DSD_PCM_MIX_CTL
,
763 CS43130_MIX_PCM_PREP_MASK
,
764 0 << CS43130_MIX_PCM_PREP_SHIFT
);
770 static int cs43130_dsd_hw_params(struct snd_pcm_substream
*substream
,
771 struct snd_pcm_hw_params
*params
,
772 struct snd_soc_dai
*dai
)
774 struct snd_soc_component
*component
= dai
->component
;
775 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
776 unsigned int required_clk
;
779 mutex_lock(&cs43130
->clk_mutex
);
780 if (!cs43130
->clk_req
) {
781 /* no DAI is currently using clk */
782 if (!(CS43130_MCLK_22M
% params_rate(params
)))
783 required_clk
= CS43130_MCLK_22M
;
785 required_clk
= CS43130_MCLK_24M
;
787 cs43130_set_pll(component
, 0, 0, cs43130
->mclk
, required_clk
);
788 if (cs43130
->pll_bypass
)
789 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_EXT
);
791 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_PLL
);
795 if (cs43130
->clk_req
== 2)
796 cs43130_pcm_dsd_mix(true, cs43130
->regmap
);
797 mutex_unlock(&cs43130
->clk_mutex
);
799 switch (params_rate(params
)) {
807 dev_err(component
->dev
, "Rate(%u) not supported\n",
808 params_rate(params
));
812 if (cs43130
->dais
[dai
->id
].dai_mode
== SND_SOC_DAIFMT_CBM_CFM
)
813 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_INT_CFG
,
814 CS43130_DSD_MASTER
, CS43130_DSD_MASTER
);
816 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_INT_CFG
,
817 CS43130_DSD_MASTER
, 0);
819 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_PATH_CTL_2
,
820 CS43130_DSD_SPEED_MASK
,
821 dsd_speed
<< CS43130_DSD_SPEED_SHIFT
);
822 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_PATH_CTL_2
,
823 CS43130_DSD_SRC_MASK
, CS43130_DSD_SRC_DSD
<<
824 CS43130_DSD_SRC_SHIFT
);
829 static int cs43130_hw_params(struct snd_pcm_substream
*substream
,
830 struct snd_pcm_hw_params
*params
,
831 struct snd_soc_dai
*dai
)
833 struct snd_soc_component
*component
= dai
->component
;
834 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
835 const struct cs43130_rate_map
*rate_map
;
836 unsigned int sclk
= cs43130
->dais
[dai
->id
].sclk
;
837 unsigned int bitwidth_sclk
;
838 unsigned int bitwidth_dai
= (unsigned int)(params_width(params
));
839 unsigned int required_clk
;
842 mutex_lock(&cs43130
->clk_mutex
);
843 if (!cs43130
->clk_req
) {
844 /* no DAI is currently using clk */
845 if (!(CS43130_MCLK_22M
% params_rate(params
)))
846 required_clk
= CS43130_MCLK_22M
;
848 required_clk
= CS43130_MCLK_24M
;
850 cs43130_set_pll(component
, 0, 0, cs43130
->mclk
, required_clk
);
851 if (cs43130
->pll_bypass
)
852 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_EXT
);
854 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_PLL
);
858 if (cs43130
->clk_req
== 2)
859 cs43130_pcm_dsd_mix(true, cs43130
->regmap
);
860 mutex_unlock(&cs43130
->clk_mutex
);
863 case CS43130_ASP_DOP_DAI
:
864 case CS43130_XSP_DOP_DAI
:
865 /* DoP bitwidth is always 24-bit */
867 sclk
= params_rate(params
) * bitwidth_dai
*
868 params_channels(params
);
870 switch (params_rate(params
)) {
878 dev_err(component
->dev
, "Rate(%u) not supported\n",
879 params_rate(params
));
883 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_PATH_CTL_2
,
884 CS43130_DSD_SPEED_MASK
,
885 dsd_speed
<< CS43130_DSD_SPEED_SHIFT
);
887 case CS43130_ASP_PCM_DAI
:
888 rate_map
= cs43130_get_rate_table(params_rate(params
));
892 regmap_write(cs43130
->regmap
, CS43130_SP_SRATE
, rate_map
->val
);
895 dev_err(component
->dev
, "Invalid DAI (%d)\n", dai
->id
);
900 case CS43130_ASP_DOP_DAI
:
901 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_PATH_CTL_2
,
902 CS43130_DSD_SRC_MASK
, CS43130_DSD_SRC_ASP
<<
903 CS43130_DSD_SRC_SHIFT
);
905 case CS43130_XSP_DOP_DAI
:
906 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_PATH_CTL_2
,
907 CS43130_DSD_SRC_MASK
, CS43130_DSD_SRC_XSP
<<
908 CS43130_DSD_SRC_SHIFT
);
912 if (!sclk
&& cs43130
->dais
[dai
->id
].dai_mode
== SND_SOC_DAIFMT_CBM_CFM
)
913 /* Calculate SCLK in master mode if unassigned */
914 sclk
= params_rate(params
) * bitwidth_dai
*
915 params_channels(params
);
918 /* at this point, SCLK must be set */
919 dev_err(component
->dev
, "SCLK freq is not set\n");
923 bitwidth_sclk
= (sclk
/ params_rate(params
)) / params_channels(params
);
924 if (bitwidth_sclk
< bitwidth_dai
) {
925 dev_err(component
->dev
, "Format not supported: SCLK freq is too low\n");
929 dev_dbg(component
->dev
,
930 "sclk = %u, fs = %d, bitwidth_dai = %u\n",
931 sclk
, params_rate(params
), bitwidth_dai
);
933 dev_dbg(component
->dev
,
934 "bitwidth_sclk = %u, num_ch = %u\n",
935 bitwidth_sclk
, params_channels(params
));
937 cs43130_set_bitwidth(dai
->id
, bitwidth_dai
, cs43130
->regmap
);
938 cs43130_set_sp_fmt(dai
->id
, bitwidth_sclk
, params
, cs43130
);
943 static int cs43130_hw_free(struct snd_pcm_substream
*substream
,
944 struct snd_soc_dai
*dai
)
946 struct snd_soc_component
*component
= dai
->component
;
947 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
949 mutex_lock(&cs43130
->clk_mutex
);
951 if (!cs43130
->clk_req
) {
952 /* no DAI is currently using clk */
953 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_RCO
);
954 cs43130_pcm_dsd_mix(false, cs43130
->regmap
);
956 mutex_unlock(&cs43130
->clk_mutex
);
961 static const DECLARE_TLV_DB_SCALE(pcm_vol_tlv
, -12750, 50, 1);
963 static const char * const pcm_ch_text
[] = {
970 static const struct reg_sequence pcm_ch_en_seq
[] = {
971 {CS43130_DXD1
, 0x99},
991 static const struct reg_sequence pcm_ch_dis_seq
[] = {
992 {CS43130_DXD1
, 0x99},
1012 static int cs43130_pcm_ch_get(struct snd_kcontrol
*kcontrol
,
1013 struct snd_ctl_elem_value
*ucontrol
)
1015 return snd_soc_get_enum_double(kcontrol
, ucontrol
);
1018 static int cs43130_pcm_ch_put(struct snd_kcontrol
*kcontrol
,
1019 struct snd_ctl_elem_value
*ucontrol
)
1021 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1022 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
1023 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
1024 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1027 if (item
[0] >= e
->items
)
1029 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
1031 switch (cs43130
->dev_id
) {
1032 case CS43131_CHIP_ID
:
1033 case CS43198_CHIP_ID
:
1035 regmap_multi_reg_write(cs43130
->regmap
, pcm_ch_en_seq
,
1036 ARRAY_SIZE(pcm_ch_en_seq
));
1038 regmap_multi_reg_write(cs43130
->regmap
, pcm_ch_dis_seq
,
1039 ARRAY_SIZE(pcm_ch_dis_seq
));
1043 return snd_soc_put_enum_double(kcontrol
, ucontrol
);
1046 static SOC_ENUM_SINGLE_DECL(pcm_ch_enum
, CS43130_PCM_PATH_CTL_2
, 0,
1049 static const char * const pcm_spd_texts
[] = {
1054 static SOC_ENUM_SINGLE_DECL(pcm_spd_enum
, CS43130_PCM_FILT_OPT
, 7,
1057 static const char * const dsd_texts
[] = {
1063 static const unsigned int dsd_values
[] = {
1064 CS43130_DSD_SRC_DSD
,
1065 CS43130_DSD_SRC_ASP
,
1066 CS43130_DSD_SRC_XSP
,
1069 static SOC_VALUE_ENUM_SINGLE_DECL(dsd_enum
, CS43130_DSD_INT_CFG
, 0, 0x03,
1070 dsd_texts
, dsd_values
);
1072 static const struct snd_kcontrol_new cs43130_snd_controls
[] = {
1073 SOC_DOUBLE_R_TLV("Master Playback Volume",
1074 CS43130_PCM_VOL_A
, CS43130_PCM_VOL_B
, 0, 0xFF, 1,
1076 SOC_DOUBLE_R_TLV("Master DSD Playback Volume",
1077 CS43130_DSD_VOL_A
, CS43130_DSD_VOL_B
, 0, 0xFF, 1,
1079 SOC_ENUM_EXT("PCM Ch Select", pcm_ch_enum
, cs43130_pcm_ch_get
,
1080 cs43130_pcm_ch_put
),
1081 SOC_ENUM("PCM Filter Speed", pcm_spd_enum
),
1082 SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT
, 6, 1, 0),
1083 SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT
, 5, 1, 0),
1084 SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT
, 1, 1, 0),
1085 SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT
, 0, 1, 0),
1086 SOC_ENUM("DSD Phase Modulation", dsd_enum
),
1089 static const struct reg_sequence pcm_seq
[] = {
1090 {CS43130_DXD1
, 0x99},
1091 {CS43130_DXD7
, 0x01},
1093 {CS43130_DXD9
, 0x01},
1094 {CS43130_DXD3
, 0x12},
1096 {CS43130_DXD10
, 0x28},
1097 {CS43130_DXD11
, 0x28},
1101 static const struct reg_sequence dsd_seq
[] = {
1102 {CS43130_DXD1
, 0x99},
1103 {CS43130_DXD7
, 0x01},
1105 {CS43130_DXD9
, 0x01},
1106 {CS43130_DXD3
, 0x12},
1108 {CS43130_DXD10
, 0x1E},
1109 {CS43130_DXD11
, 0x20},
1113 static const struct reg_sequence pop_free_seq
[] = {
1114 {CS43130_DXD1
, 0x99},
1115 {CS43130_DXD12
, 0x0A},
1119 static const struct reg_sequence pop_free_seq2
[] = {
1120 {CS43130_DXD1
, 0x99},
1121 {CS43130_DXD13
, 0x20},
1125 static const struct reg_sequence mute_seq
[] = {
1126 {CS43130_DXD1
, 0x99},
1127 {CS43130_DXD3
, 0x12},
1128 {CS43130_DXD5
, 0x02},
1129 {CS43130_DXD4
, 0x12},
1133 static const struct reg_sequence unmute_seq
[] = {
1134 {CS43130_DXD1
, 0x99},
1135 {CS43130_DXD3
, 0x10},
1137 {CS43130_DXD4
, 0x16},
1141 static int cs43130_dsd_event(struct snd_soc_dapm_widget
*w
,
1142 struct snd_kcontrol
*kcontrol
, int event
)
1144 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
1145 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1148 case SND_SOC_DAPM_PRE_PMU
:
1149 switch (cs43130
->dev_id
) {
1150 case CS43130_CHIP_ID
:
1151 case CS4399_CHIP_ID
:
1152 regmap_multi_reg_write(cs43130
->regmap
, dsd_seq
,
1153 ARRAY_SIZE(dsd_seq
));
1157 case SND_SOC_DAPM_POST_PMU
:
1158 regmap_update_bits(cs43130
->regmap
, CS43130_DSD_PATH_CTL_1
,
1159 CS43130_MUTE_MASK
, 0);
1160 switch (cs43130
->dev_id
) {
1161 case CS43130_CHIP_ID
:
1162 case CS4399_CHIP_ID
:
1163 regmap_multi_reg_write(cs43130
->regmap
, unmute_seq
,
1164 ARRAY_SIZE(unmute_seq
));
1168 case SND_SOC_DAPM_PRE_PMD
:
1169 switch (cs43130
->dev_id
) {
1170 case CS43130_CHIP_ID
:
1171 case CS4399_CHIP_ID
:
1172 regmap_multi_reg_write(cs43130
->regmap
, mute_seq
,
1173 ARRAY_SIZE(mute_seq
));
1174 regmap_update_bits(cs43130
->regmap
,
1175 CS43130_DSD_PATH_CTL_1
,
1176 CS43130_MUTE_MASK
, CS43130_MUTE_EN
);
1178 * DSD Power Down Sequence
1179 * According to Design, 130ms is preferred.
1183 case CS43131_CHIP_ID
:
1184 case CS43198_CHIP_ID
:
1185 regmap_update_bits(cs43130
->regmap
,
1186 CS43130_DSD_PATH_CTL_1
,
1187 CS43130_MUTE_MASK
, CS43130_MUTE_EN
);
1192 dev_err(component
->dev
, "Invalid event = 0x%x\n", event
);
1198 static int cs43130_pcm_event(struct snd_soc_dapm_widget
*w
,
1199 struct snd_kcontrol
*kcontrol
, int event
)
1201 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
1202 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1205 case SND_SOC_DAPM_PRE_PMU
:
1206 switch (cs43130
->dev_id
) {
1207 case CS43130_CHIP_ID
:
1208 case CS4399_CHIP_ID
:
1209 regmap_multi_reg_write(cs43130
->regmap
, pcm_seq
,
1210 ARRAY_SIZE(pcm_seq
));
1214 case SND_SOC_DAPM_POST_PMU
:
1215 regmap_update_bits(cs43130
->regmap
, CS43130_PCM_PATH_CTL_1
,
1216 CS43130_MUTE_MASK
, 0);
1217 switch (cs43130
->dev_id
) {
1218 case CS43130_CHIP_ID
:
1219 case CS4399_CHIP_ID
:
1220 regmap_multi_reg_write(cs43130
->regmap
, unmute_seq
,
1221 ARRAY_SIZE(unmute_seq
));
1225 case SND_SOC_DAPM_PRE_PMD
:
1226 switch (cs43130
->dev_id
) {
1227 case CS43130_CHIP_ID
:
1228 case CS4399_CHIP_ID
:
1229 regmap_multi_reg_write(cs43130
->regmap
, mute_seq
,
1230 ARRAY_SIZE(mute_seq
));
1231 regmap_update_bits(cs43130
->regmap
,
1232 CS43130_PCM_PATH_CTL_1
,
1233 CS43130_MUTE_MASK
, CS43130_MUTE_EN
);
1235 * PCM Power Down Sequence
1236 * According to Design, 130ms is preferred.
1240 case CS43131_CHIP_ID
:
1241 case CS43198_CHIP_ID
:
1242 regmap_update_bits(cs43130
->regmap
,
1243 CS43130_PCM_PATH_CTL_1
,
1244 CS43130_MUTE_MASK
, CS43130_MUTE_EN
);
1249 dev_err(component
->dev
, "Invalid event = 0x%x\n", event
);
1255 static const struct reg_sequence dac_postpmu_seq
[] = {
1256 {CS43130_DXD9
, 0x0C},
1257 {CS43130_DXD3
, 0x10},
1258 {CS43130_DXD4
, 0x20},
1261 static const struct reg_sequence dac_postpmd_seq
[] = {
1262 {CS43130_DXD1
, 0x99},
1263 {CS43130_DXD6
, 0x01},
1267 static int cs43130_dac_event(struct snd_soc_dapm_widget
*w
,
1268 struct snd_kcontrol
*kcontrol
, int event
)
1270 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
1271 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1274 case SND_SOC_DAPM_PRE_PMU
:
1275 switch (cs43130
->dev_id
) {
1276 case CS43130_CHIP_ID
:
1277 case CS4399_CHIP_ID
:
1278 regmap_multi_reg_write(cs43130
->regmap
, pop_free_seq
,
1279 ARRAY_SIZE(pop_free_seq
));
1281 case CS43131_CHIP_ID
:
1282 case CS43198_CHIP_ID
:
1283 regmap_multi_reg_write(cs43130
->regmap
, pop_free_seq2
,
1284 ARRAY_SIZE(pop_free_seq2
));
1288 case SND_SOC_DAPM_POST_PMU
:
1289 usleep_range(10000, 10050);
1291 regmap_write(cs43130
->regmap
, CS43130_DXD1
, 0x99);
1293 switch (cs43130
->dev_id
) {
1294 case CS43130_CHIP_ID
:
1295 case CS4399_CHIP_ID
:
1296 regmap_multi_reg_write(cs43130
->regmap
, dac_postpmu_seq
,
1297 ARRAY_SIZE(dac_postpmu_seq
));
1299 * Per datasheet, Sec. PCM Power-Up Sequence.
1300 * According to Design, CS43130_DXD12 must be 0 to meet
1301 * THDN and Dynamic Range spec.
1304 regmap_write(cs43130
->regmap
, CS43130_DXD12
, 0);
1306 case CS43131_CHIP_ID
:
1307 case CS43198_CHIP_ID
:
1308 usleep_range(12000, 12010);
1309 regmap_write(cs43130
->regmap
, CS43130_DXD13
, 0);
1313 regmap_write(cs43130
->regmap
, CS43130_DXD1
, 0);
1315 case SND_SOC_DAPM_POST_PMD
:
1316 switch (cs43130
->dev_id
) {
1317 case CS43130_CHIP_ID
:
1318 case CS4399_CHIP_ID
:
1319 regmap_multi_reg_write(cs43130
->regmap
, dac_postpmd_seq
,
1320 ARRAY_SIZE(dac_postpmd_seq
));
1325 dev_err(component
->dev
, "Invalid DAC event = 0x%x\n", event
);
1331 static const struct reg_sequence hpin_prepmd_seq
[] = {
1332 {CS43130_DXD1
, 0x99},
1333 {CS43130_DXD15
, 0x64},
1339 static const struct reg_sequence hpin_postpmu_seq
[] = {
1340 {CS43130_DXD1
, 0x99},
1342 {CS43130_DXD14
, 0xDC},
1343 {CS43130_DXD15
, 0xE4},
1347 static int cs43130_hpin_event(struct snd_soc_dapm_widget
*w
,
1348 struct snd_kcontrol
*kcontrol
, int event
)
1350 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
1351 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1354 case SND_SOC_DAPM_POST_PMD
:
1355 regmap_multi_reg_write(cs43130
->regmap
, hpin_prepmd_seq
,
1356 ARRAY_SIZE(hpin_prepmd_seq
));
1358 case SND_SOC_DAPM_PRE_PMU
:
1359 regmap_multi_reg_write(cs43130
->regmap
, hpin_postpmu_seq
,
1360 ARRAY_SIZE(hpin_postpmu_seq
));
1363 dev_err(component
->dev
, "Invalid HPIN event = 0x%x\n", event
);
1369 static const struct snd_soc_dapm_widget digital_hp_widgets
[] = {
1370 SND_SOC_DAPM_OUTPUT("HPOUTA"),
1371 SND_SOC_DAPM_OUTPUT("HPOUTB"),
1373 SND_SOC_DAPM_AIF_IN_E("ASPIN PCM", NULL
, 0, CS43130_PWDN_CTL
,
1374 CS43130_PDN_ASP_SHIFT
, 1, cs43130_pcm_event
,
1375 (SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1376 SND_SOC_DAPM_PRE_PMD
)),
1378 SND_SOC_DAPM_AIF_IN_E("ASPIN DoP", NULL
, 0, CS43130_PWDN_CTL
,
1379 CS43130_PDN_ASP_SHIFT
, 1, cs43130_dsd_event
,
1380 (SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1381 SND_SOC_DAPM_PRE_PMD
)),
1383 SND_SOC_DAPM_AIF_IN_E("XSPIN DoP", NULL
, 0, CS43130_PWDN_CTL
,
1384 CS43130_PDN_XSP_SHIFT
, 1, cs43130_dsd_event
,
1385 (SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1386 SND_SOC_DAPM_PRE_PMD
)),
1388 SND_SOC_DAPM_AIF_IN_E("XSPIN DSD", NULL
, 0, CS43130_PWDN_CTL
,
1389 CS43130_PDN_DSDIF_SHIFT
, 1, cs43130_dsd_event
,
1390 (SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1391 SND_SOC_DAPM_PRE_PMD
)),
1393 SND_SOC_DAPM_DAC("DSD", NULL
, CS43130_DSD_PATH_CTL_2
,
1394 CS43130_DSD_EN_SHIFT
, 0),
1396 SND_SOC_DAPM_DAC_E("HiFi DAC", NULL
, CS43130_PWDN_CTL
,
1397 CS43130_PDN_HP_SHIFT
, 1, cs43130_dac_event
,
1398 (SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
1399 SND_SOC_DAPM_POST_PMD
)),
1402 static const struct snd_soc_dapm_widget analog_hp_widgets
[] = {
1403 SND_SOC_DAPM_DAC_E("Analog Playback", NULL
, CS43130_HP_OUT_CTL_1
,
1404 CS43130_HP_IN_EN_SHIFT
, 0, cs43130_hpin_event
,
1405 (SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
)),
1408 static struct snd_soc_dapm_widget all_hp_widgets
[
1409 ARRAY_SIZE(digital_hp_widgets
) +
1410 ARRAY_SIZE(analog_hp_widgets
)];
1412 static const struct snd_soc_dapm_route digital_hp_routes
[] = {
1413 {"ASPIN PCM", NULL
, "ASP PCM Playback"},
1414 {"ASPIN DoP", NULL
, "ASP DoP Playback"},
1415 {"XSPIN DoP", NULL
, "XSP DoP Playback"},
1416 {"XSPIN DSD", NULL
, "XSP DSD Playback"},
1417 {"DSD", NULL
, "ASPIN DoP"},
1418 {"DSD", NULL
, "XSPIN DoP"},
1419 {"DSD", NULL
, "XSPIN DSD"},
1420 {"HiFi DAC", NULL
, "ASPIN PCM"},
1421 {"HiFi DAC", NULL
, "DSD"},
1422 {"HPOUTA", NULL
, "HiFi DAC"},
1423 {"HPOUTB", NULL
, "HiFi DAC"},
1426 static const struct snd_soc_dapm_route analog_hp_routes
[] = {
1427 {"HPOUTA", NULL
, "Analog Playback"},
1428 {"HPOUTB", NULL
, "Analog Playback"},
1431 static struct snd_soc_dapm_route all_hp_routes
[
1432 ARRAY_SIZE(digital_hp_routes
) +
1433 ARRAY_SIZE(analog_hp_routes
)];
1435 static const unsigned int cs43130_asp_src_rates
[] = {
1436 32000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
1439 static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints
= {
1440 .count
= ARRAY_SIZE(cs43130_asp_src_rates
),
1441 .list
= cs43130_asp_src_rates
,
1444 static int cs43130_pcm_startup(struct snd_pcm_substream
*substream
,
1445 struct snd_soc_dai
*dai
)
1447 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1448 SNDRV_PCM_HW_PARAM_RATE
,
1449 &cs43130_asp_constraints
);
1452 static const unsigned int cs43130_dop_src_rates
[] = {
1456 static const struct snd_pcm_hw_constraint_list cs43130_dop_constraints
= {
1457 .count
= ARRAY_SIZE(cs43130_dop_src_rates
),
1458 .list
= cs43130_dop_src_rates
,
1461 static int cs43130_dop_startup(struct snd_pcm_substream
*substream
,
1462 struct snd_soc_dai
*dai
)
1464 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1465 SNDRV_PCM_HW_PARAM_RATE
,
1466 &cs43130_dop_constraints
);
1469 static int cs43130_pcm_set_fmt(struct snd_soc_dai
*codec_dai
, unsigned int fmt
)
1471 struct snd_soc_component
*component
= codec_dai
->component
;
1472 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1474 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1475 case SND_SOC_DAIFMT_CBS_CFS
:
1476 cs43130
->dais
[codec_dai
->id
].dai_mode
= SND_SOC_DAIFMT_CBS_CFS
;
1478 case SND_SOC_DAIFMT_CBM_CFM
:
1479 cs43130
->dais
[codec_dai
->id
].dai_mode
= SND_SOC_DAIFMT_CBM_CFM
;
1482 dev_err(component
->dev
, "unsupported mode\n");
1486 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1487 case SND_SOC_DAIFMT_I2S
:
1488 cs43130
->dais
[codec_dai
->id
].dai_format
= SND_SOC_DAIFMT_I2S
;
1490 case SND_SOC_DAIFMT_LEFT_J
:
1491 cs43130
->dais
[codec_dai
->id
].dai_format
= SND_SOC_DAIFMT_LEFT_J
;
1493 case SND_SOC_DAIFMT_DSP_A
:
1494 cs43130
->dais
[codec_dai
->id
].dai_format
= SND_SOC_DAIFMT_DSP_A
;
1496 case SND_SOC_DAIFMT_DSP_B
:
1497 cs43130
->dais
[codec_dai
->id
].dai_format
= SND_SOC_DAIFMT_DSP_B
;
1500 dev_err(component
->dev
,
1501 "unsupported audio format\n");
1505 dev_dbg(component
->dev
, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
1507 cs43130
->dais
[codec_dai
->id
].dai_mode
,
1508 cs43130
->dais
[codec_dai
->id
].dai_format
);
1513 static int cs43130_dsd_set_fmt(struct snd_soc_dai
*codec_dai
, unsigned int fmt
)
1515 struct snd_soc_component
*component
= codec_dai
->component
;
1516 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1518 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1519 case SND_SOC_DAIFMT_CBS_CFS
:
1520 cs43130
->dais
[codec_dai
->id
].dai_mode
= SND_SOC_DAIFMT_CBS_CFS
;
1522 case SND_SOC_DAIFMT_CBM_CFM
:
1523 cs43130
->dais
[codec_dai
->id
].dai_mode
= SND_SOC_DAIFMT_CBM_CFM
;
1526 dev_err(component
->dev
, "Unsupported DAI format.\n");
1530 dev_dbg(component
->dev
, "dai_mode = 0x%x\n",
1531 cs43130
->dais
[codec_dai
->id
].dai_mode
);
1536 static int cs43130_set_sysclk(struct snd_soc_dai
*codec_dai
,
1537 int clk_id
, unsigned int freq
, int dir
)
1539 struct snd_soc_component
*component
= codec_dai
->component
;
1540 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1542 cs43130
->dais
[codec_dai
->id
].sclk
= freq
;
1543 dev_dbg(component
->dev
, "dai_id = %d, sclk = %u\n", codec_dai
->id
,
1544 cs43130
->dais
[codec_dai
->id
].sclk
);
1549 static const struct snd_soc_dai_ops cs43130_pcm_ops
= {
1550 .startup
= cs43130_pcm_startup
,
1551 .hw_params
= cs43130_hw_params
,
1552 .hw_free
= cs43130_hw_free
,
1553 .set_sysclk
= cs43130_set_sysclk
,
1554 .set_fmt
= cs43130_pcm_set_fmt
,
1557 static const struct snd_soc_dai_ops cs43130_dop_ops
= {
1558 .startup
= cs43130_dop_startup
,
1559 .hw_params
= cs43130_hw_params
,
1560 .hw_free
= cs43130_hw_free
,
1561 .set_sysclk
= cs43130_set_sysclk
,
1562 .set_fmt
= cs43130_pcm_set_fmt
,
1565 static const struct snd_soc_dai_ops cs43130_dsd_ops
= {
1566 .startup
= cs43130_dop_startup
,
1567 .hw_params
= cs43130_dsd_hw_params
,
1568 .hw_free
= cs43130_hw_free
,
1569 .set_fmt
= cs43130_dsd_set_fmt
,
1572 static struct snd_soc_dai_driver cs43130_dai
[] = {
1574 .name
= "cs43130-asp-pcm",
1575 .id
= CS43130_ASP_PCM_DAI
,
1577 .stream_name
= "ASP PCM Playback",
1580 .rates
= SNDRV_PCM_RATE_KNOT
,
1581 .formats
= CS43130_PCM_FORMATS
,
1583 .ops
= &cs43130_pcm_ops
,
1584 .symmetric_rates
= 1,
1587 .name
= "cs43130-asp-dop",
1588 .id
= CS43130_ASP_DOP_DAI
,
1590 .stream_name
= "ASP DoP Playback",
1593 .rates
= SNDRV_PCM_RATE_KNOT
,
1594 .formats
= CS43130_DOP_FORMATS
,
1596 .ops
= &cs43130_dop_ops
,
1597 .symmetric_rates
= 1,
1600 .name
= "cs43130-xsp-dop",
1601 .id
= CS43130_XSP_DOP_DAI
,
1603 .stream_name
= "XSP DoP Playback",
1606 .rates
= SNDRV_PCM_RATE_KNOT
,
1607 .formats
= CS43130_DOP_FORMATS
,
1609 .ops
= &cs43130_dop_ops
,
1610 .symmetric_rates
= 1,
1613 .name
= "cs43130-xsp-dsd",
1614 .id
= CS43130_XSP_DSD_DAI
,
1616 .stream_name
= "XSP DSD Playback",
1619 .rates
= SNDRV_PCM_RATE_KNOT
,
1620 .formats
= CS43130_DOP_FORMATS
,
1622 .ops
= &cs43130_dsd_ops
,
1627 static int cs43130_component_set_sysclk(struct snd_soc_component
*component
,
1628 int clk_id
, int source
, unsigned int freq
,
1631 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
1633 dev_dbg(component
->dev
, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
1634 clk_id
, source
, freq
, dir
);
1637 case CS43130_MCLK_22M
:
1638 case CS43130_MCLK_24M
:
1639 cs43130
->mclk
= freq
;
1642 dev_err(component
->dev
, "Invalid MCLK INT freq: %u\n", freq
);
1646 if (source
== CS43130_MCLK_SRC_EXT
) {
1647 cs43130
->pll_bypass
= true;
1649 dev_err(component
->dev
, "Invalid MCLK source\n");
1656 static inline u16
cs43130_get_ac_reg_val(u16 ac_freq
)
1658 /* AC freq is counted in 5.94Hz step. */
1662 static int cs43130_show_dc(struct device
*dev
, char *buf
, u8 ch
)
1664 struct i2c_client
*client
= to_i2c_client(dev
);
1665 struct cs43130_private
*cs43130
= i2c_get_clientdata(client
);
1667 if (!cs43130
->hpload_done
)
1668 return scnprintf(buf
, PAGE_SIZE
, "NO_HPLOAD\n");
1670 return scnprintf(buf
, PAGE_SIZE
, "%u\n",
1671 cs43130
->hpload_dc
[ch
]);
1674 static ssize_t
cs43130_show_dc_l(struct device
*dev
,
1675 struct device_attribute
*attr
, char *buf
)
1677 return cs43130_show_dc(dev
, buf
, HP_LEFT
);
1680 static ssize_t
cs43130_show_dc_r(struct device
*dev
,
1681 struct device_attribute
*attr
, char *buf
)
1683 return cs43130_show_dc(dev
, buf
, HP_RIGHT
);
1686 static u16
const cs43130_ac_freq
[CS43130_AC_FREQ
] = {
1699 static int cs43130_show_ac(struct device
*dev
, char *buf
, u8 ch
)
1702 struct i2c_client
*client
= to_i2c_client(dev
);
1703 struct cs43130_private
*cs43130
= i2c_get_clientdata(client
);
1705 if (cs43130
->hpload_done
&& cs43130
->ac_meas
) {
1706 for (i
= 0; i
< ARRAY_SIZE(cs43130_ac_freq
); i
++) {
1707 tmp
= scnprintf(buf
+ j
, PAGE_SIZE
- j
, "%u\n",
1708 cs43130
->hpload_ac
[i
][ch
]);
1717 return scnprintf(buf
, PAGE_SIZE
, "NO_HPLOAD\n");
1721 static ssize_t
cs43130_show_ac_l(struct device
*dev
,
1722 struct device_attribute
*attr
, char *buf
)
1724 return cs43130_show_ac(dev
, buf
, HP_LEFT
);
1727 static ssize_t
cs43130_show_ac_r(struct device
*dev
,
1728 struct device_attribute
*attr
, char *buf
)
1730 return cs43130_show_ac(dev
, buf
, HP_RIGHT
);
1733 static DEVICE_ATTR(hpload_dc_l
, 0444, cs43130_show_dc_l
, NULL
);
1734 static DEVICE_ATTR(hpload_dc_r
, 0444, cs43130_show_dc_r
, NULL
);
1735 static DEVICE_ATTR(hpload_ac_l
, 0444, cs43130_show_ac_l
, NULL
);
1736 static DEVICE_ATTR(hpload_ac_r
, 0444, cs43130_show_ac_r
, NULL
);
1738 static struct reg_sequence hp_en_cal_seq
[] = {
1739 {CS43130_INT_MASK_4
, CS43130_INT_MASK_ALL
},
1740 {CS43130_HP_MEAS_LOAD_1
, 0},
1741 {CS43130_HP_MEAS_LOAD_2
, 0},
1742 {CS43130_INT_MASK_4
, 0},
1743 {CS43130_DXD1
, 0x99},
1744 {CS43130_DXD16
, 0xBB},
1745 {CS43130_DXD12
, 0x01},
1746 {CS43130_DXD19
, 0xCB},
1747 {CS43130_DXD17
, 0x95},
1748 {CS43130_DXD18
, 0x0B},
1750 {CS43130_HP_LOAD_1
, 0x80},
1753 static struct reg_sequence hp_en_cal_seq2
[] = {
1754 {CS43130_INT_MASK_4
, CS43130_INT_MASK_ALL
},
1755 {CS43130_HP_MEAS_LOAD_1
, 0},
1756 {CS43130_HP_MEAS_LOAD_2
, 0},
1757 {CS43130_INT_MASK_4
, 0},
1758 {CS43130_HP_LOAD_1
, 0x80},
1761 static struct reg_sequence hp_dis_cal_seq
[] = {
1762 {CS43130_HP_LOAD_1
, 0x80},
1763 {CS43130_DXD1
, 0x99},
1766 {CS43130_HP_LOAD_1
, 0},
1769 static struct reg_sequence hp_dis_cal_seq2
[] = {
1770 {CS43130_HP_LOAD_1
, 0x80},
1771 {CS43130_HP_LOAD_1
, 0},
1774 static struct reg_sequence hp_dc_ch_l_seq
[] = {
1775 {CS43130_DXD1
, 0x99},
1776 {CS43130_DXD19
, 0x0A},
1777 {CS43130_DXD17
, 0x93},
1778 {CS43130_DXD18
, 0x0A},
1780 {CS43130_HP_LOAD_1
, 0x80},
1781 {CS43130_HP_LOAD_1
, 0x81},
1784 static struct reg_sequence hp_dc_ch_l_seq2
[] = {
1785 {CS43130_HP_LOAD_1
, 0x80},
1786 {CS43130_HP_LOAD_1
, 0x81},
1789 static struct reg_sequence hp_dc_ch_r_seq
[] = {
1790 {CS43130_DXD1
, 0x99},
1791 {CS43130_DXD19
, 0x8A},
1792 {CS43130_DXD17
, 0x15},
1793 {CS43130_DXD18
, 0x06},
1795 {CS43130_HP_LOAD_1
, 0x90},
1796 {CS43130_HP_LOAD_1
, 0x91},
1799 static struct reg_sequence hp_dc_ch_r_seq2
[] = {
1800 {CS43130_HP_LOAD_1
, 0x90},
1801 {CS43130_HP_LOAD_1
, 0x91},
1804 static struct reg_sequence hp_ac_ch_l_seq
[] = {
1805 {CS43130_DXD1
, 0x99},
1806 {CS43130_DXD19
, 0x0A},
1807 {CS43130_DXD17
, 0x93},
1808 {CS43130_DXD18
, 0x0A},
1810 {CS43130_HP_LOAD_1
, 0x80},
1811 {CS43130_HP_LOAD_1
, 0x82},
1814 static struct reg_sequence hp_ac_ch_l_seq2
[] = {
1815 {CS43130_HP_LOAD_1
, 0x80},
1816 {CS43130_HP_LOAD_1
, 0x82},
1819 static struct reg_sequence hp_ac_ch_r_seq
[] = {
1820 {CS43130_DXD1
, 0x99},
1821 {CS43130_DXD19
, 0x8A},
1822 {CS43130_DXD17
, 0x15},
1823 {CS43130_DXD18
, 0x06},
1825 {CS43130_HP_LOAD_1
, 0x90},
1826 {CS43130_HP_LOAD_1
, 0x92},
1829 static struct reg_sequence hp_ac_ch_r_seq2
[] = {
1830 {CS43130_HP_LOAD_1
, 0x90},
1831 {CS43130_HP_LOAD_1
, 0x92},
1834 static struct reg_sequence hp_cln_seq
[] = {
1835 {CS43130_INT_MASK_4
, CS43130_INT_MASK_ALL
},
1836 {CS43130_HP_MEAS_LOAD_1
, 0},
1837 {CS43130_HP_MEAS_LOAD_2
, 0},
1840 struct reg_sequences
{
1841 struct reg_sequence
*seq
;
1846 static struct reg_sequences hpload_seq1
[] = {
1848 .seq
= hp_en_cal_seq
,
1849 .size
= ARRAY_SIZE(hp_en_cal_seq
),
1850 .msk
= CS43130_HPLOAD_ON_INT
,
1853 .seq
= hp_dc_ch_l_seq
,
1854 .size
= ARRAY_SIZE(hp_dc_ch_l_seq
),
1855 .msk
= CS43130_HPLOAD_DC_INT
,
1858 .seq
= hp_ac_ch_l_seq
,
1859 .size
= ARRAY_SIZE(hp_ac_ch_l_seq
),
1860 .msk
= CS43130_HPLOAD_AC_INT
,
1863 .seq
= hp_dis_cal_seq
,
1864 .size
= ARRAY_SIZE(hp_dis_cal_seq
),
1865 .msk
= CS43130_HPLOAD_OFF_INT
,
1868 .seq
= hp_en_cal_seq
,
1869 .size
= ARRAY_SIZE(hp_en_cal_seq
),
1870 .msk
= CS43130_HPLOAD_ON_INT
,
1873 .seq
= hp_dc_ch_r_seq
,
1874 .size
= ARRAY_SIZE(hp_dc_ch_r_seq
),
1875 .msk
= CS43130_HPLOAD_DC_INT
,
1878 .seq
= hp_ac_ch_r_seq
,
1879 .size
= ARRAY_SIZE(hp_ac_ch_r_seq
),
1880 .msk
= CS43130_HPLOAD_AC_INT
,
1884 static struct reg_sequences hpload_seq2
[] = {
1886 .seq
= hp_en_cal_seq2
,
1887 .size
= ARRAY_SIZE(hp_en_cal_seq2
),
1888 .msk
= CS43130_HPLOAD_ON_INT
,
1891 .seq
= hp_dc_ch_l_seq2
,
1892 .size
= ARRAY_SIZE(hp_dc_ch_l_seq2
),
1893 .msk
= CS43130_HPLOAD_DC_INT
,
1896 .seq
= hp_ac_ch_l_seq2
,
1897 .size
= ARRAY_SIZE(hp_ac_ch_l_seq2
),
1898 .msk
= CS43130_HPLOAD_AC_INT
,
1901 .seq
= hp_dis_cal_seq2
,
1902 .size
= ARRAY_SIZE(hp_dis_cal_seq2
),
1903 .msk
= CS43130_HPLOAD_OFF_INT
,
1906 .seq
= hp_en_cal_seq2
,
1907 .size
= ARRAY_SIZE(hp_en_cal_seq2
),
1908 .msk
= CS43130_HPLOAD_ON_INT
,
1911 .seq
= hp_dc_ch_r_seq2
,
1912 .size
= ARRAY_SIZE(hp_dc_ch_r_seq2
),
1913 .msk
= CS43130_HPLOAD_DC_INT
,
1916 .seq
= hp_ac_ch_r_seq2
,
1917 .size
= ARRAY_SIZE(hp_ac_ch_r_seq2
),
1918 .msk
= CS43130_HPLOAD_AC_INT
,
1922 static int cs43130_update_hpload(unsigned int msk
, int ac_idx
,
1923 struct cs43130_private
*cs43130
)
1925 bool left_ch
= true;
1929 struct snd_soc_component
*component
= cs43130
->component
;
1932 case CS43130_HPLOAD_DC_INT
:
1933 case CS43130_HPLOAD_AC_INT
:
1939 regmap_read(cs43130
->regmap
, CS43130_HP_LOAD_1
, ®
);
1940 if (reg
& CS43130_HPLOAD_CHN_SEL
)
1943 if (msk
== CS43130_HPLOAD_DC_INT
)
1944 addr
= CS43130_HP_DC_STAT_1
;
1946 addr
= CS43130_HP_AC_STAT_1
;
1948 regmap_read(cs43130
->regmap
, addr
, ®
);
1949 impedance
= reg
>> 3;
1950 regmap_read(cs43130
->regmap
, addr
+ 1, ®
);
1951 impedance
|= reg
<< 5;
1953 if (msk
== CS43130_HPLOAD_DC_INT
) {
1955 cs43130
->hpload_dc
[HP_LEFT
] = impedance
;
1957 cs43130
->hpload_dc
[HP_RIGHT
] = impedance
;
1959 dev_dbg(component
->dev
, "HP DC impedance (Ch %u): %u\n", !left_ch
,
1963 cs43130
->hpload_ac
[ac_idx
][HP_LEFT
] = impedance
;
1965 cs43130
->hpload_ac
[ac_idx
][HP_RIGHT
] = impedance
;
1967 dev_dbg(component
->dev
, "HP AC (%u Hz) impedance (Ch %u): %u\n",
1968 cs43130
->ac_freq
[ac_idx
], !left_ch
, impedance
);
1974 static int cs43130_hpload_proc(struct cs43130_private
*cs43130
,
1975 struct reg_sequence
*seq
, int seq_size
,
1976 unsigned int rslt_msk
, int ac_idx
)
1981 struct snd_soc_component
*component
= cs43130
->component
;
1983 reinit_completion(&cs43130
->hpload_evt
);
1985 if (rslt_msk
== CS43130_HPLOAD_AC_INT
) {
1986 ac_reg_val
= cs43130_get_ac_reg_val(cs43130
->ac_freq
[ac_idx
]);
1987 regmap_update_bits(cs43130
->regmap
, CS43130_HP_LOAD_1
,
1988 CS43130_HPLOAD_AC_START
, 0);
1989 regmap_update_bits(cs43130
->regmap
, CS43130_HP_MEAS_LOAD_1
,
1990 CS43130_HP_MEAS_LOAD_MASK
,
1991 ac_reg_val
>> CS43130_HP_MEAS_LOAD_1_SHIFT
);
1992 regmap_update_bits(cs43130
->regmap
, CS43130_HP_MEAS_LOAD_2
,
1993 CS43130_HP_MEAS_LOAD_MASK
,
1994 ac_reg_val
>> CS43130_HP_MEAS_LOAD_2_SHIFT
);
1997 regmap_multi_reg_write(cs43130
->regmap
, seq
,
2000 ret
= wait_for_completion_timeout(&cs43130
->hpload_evt
,
2001 msecs_to_jiffies(1000));
2002 regmap_read(cs43130
->regmap
, CS43130_INT_MASK_4
, &msk
);
2004 dev_err(component
->dev
, "Timeout waiting for HPLOAD interrupt\n");
2008 dev_dbg(component
->dev
, "HP load stat: %x, INT_MASK_4: %x\n",
2009 cs43130
->hpload_stat
, msk
);
2010 if ((cs43130
->hpload_stat
& (CS43130_HPLOAD_NO_DC_INT
|
2011 CS43130_HPLOAD_UNPLUG_INT
|
2012 CS43130_HPLOAD_OOR_INT
)) ||
2013 !(cs43130
->hpload_stat
& rslt_msk
)) {
2014 dev_dbg(component
->dev
, "HP load measure failed\n");
2021 static const struct reg_sequence hv_seq
[][2] = {
2023 {CS43130_CLASS_H_CTL
, 0x1C},
2024 {CS43130_HP_OUT_CTL_1
, 0x10},
2027 {CS43130_CLASS_H_CTL
, 0x1E},
2028 {CS43130_HP_OUT_CTL_1
, 0x20},
2031 {CS43130_CLASS_H_CTL
, 0x1E},
2032 {CS43130_HP_OUT_CTL_1
, 0x30},
2036 static int cs43130_set_hv(struct regmap
*regmap
, u16 hpload_dc
,
2037 const u16
*dc_threshold
)
2041 for (i
= 0; i
< CS43130_DC_THRESHOLD
; i
++) {
2042 if (hpload_dc
<= dc_threshold
[i
])
2046 regmap_multi_reg_write(regmap
, hv_seq
[i
], ARRAY_SIZE(hv_seq
[i
]));
2051 static void cs43130_imp_meas(struct work_struct
*wk
)
2053 unsigned int reg
, seq_size
;
2055 struct cs43130_private
*cs43130
;
2056 struct snd_soc_component
*component
;
2057 struct reg_sequences
*hpload_seq
;
2059 cs43130
= container_of(wk
, struct cs43130_private
, work
);
2060 component
= cs43130
->component
;
2065 cs43130
->hpload_done
= false;
2067 mutex_lock(&cs43130
->clk_mutex
);
2068 if (!cs43130
->clk_req
) {
2069 /* clk not in use */
2070 cs43130_set_pll(component
, 0, 0, cs43130
->mclk
, CS43130_MCLK_22M
);
2071 if (cs43130
->pll_bypass
)
2072 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_EXT
);
2074 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_PLL
);
2078 mutex_unlock(&cs43130
->clk_mutex
);
2080 regmap_read(cs43130
->regmap
, CS43130_INT_STATUS_4
, ®
);
2082 switch (cs43130
->dev_id
) {
2083 case CS43130_CHIP_ID
:
2084 hpload_seq
= hpload_seq1
;
2085 seq_size
= ARRAY_SIZE(hpload_seq1
);
2087 case CS43131_CHIP_ID
:
2088 hpload_seq
= hpload_seq2
;
2089 seq_size
= ARRAY_SIZE(hpload_seq2
);
2092 WARN(1, "Invalid dev_id for meas: %d", cs43130
->dev_id
);
2098 while (i
< seq_size
) {
2099 ret
= cs43130_hpload_proc(cs43130
, hpload_seq
[i
].seq
,
2101 hpload_seq
[i
].msk
, ac_idx
);
2105 cs43130_update_hpload(hpload_seq
[i
].msk
, ac_idx
, cs43130
);
2107 if (cs43130
->ac_meas
&&
2108 hpload_seq
[i
].msk
== CS43130_HPLOAD_AC_INT
&&
2109 ac_idx
< CS43130_AC_FREQ
- 1) {
2116 cs43130
->hpload_done
= true;
2118 if (cs43130
->hpload_dc
[HP_LEFT
] >= CS43130_LINEOUT_LOAD
)
2119 snd_soc_jack_report(&cs43130
->jack
, CS43130_JACK_LINEOUT
,
2122 snd_soc_jack_report(&cs43130
->jack
, CS43130_JACK_HEADPHONE
,
2125 dev_dbg(component
->dev
, "Set HP output control. DC threshold\n");
2126 for (i
= 0; i
< CS43130_DC_THRESHOLD
; i
++)
2127 dev_dbg(component
->dev
, "DC threshold[%d]: %u.\n", i
,
2128 cs43130
->dc_threshold
[i
]);
2130 cs43130_set_hv(cs43130
->regmap
, cs43130
->hpload_dc
[HP_LEFT
],
2131 cs43130
->dc_threshold
);
2134 switch (cs43130
->dev_id
) {
2135 case CS43130_CHIP_ID
:
2136 cs43130_hpload_proc(cs43130
, hp_dis_cal_seq
,
2137 ARRAY_SIZE(hp_dis_cal_seq
),
2138 CS43130_HPLOAD_OFF_INT
, ac_idx
);
2140 case CS43131_CHIP_ID
:
2141 cs43130_hpload_proc(cs43130
, hp_dis_cal_seq2
,
2142 ARRAY_SIZE(hp_dis_cal_seq2
),
2143 CS43130_HPLOAD_OFF_INT
, ac_idx
);
2147 regmap_multi_reg_write(cs43130
->regmap
, hp_cln_seq
,
2148 ARRAY_SIZE(hp_cln_seq
));
2150 mutex_lock(&cs43130
->clk_mutex
);
2152 /* clk not in use */
2153 if (!cs43130
->clk_req
)
2154 cs43130_change_clksrc(component
, CS43130_MCLK_SRC_RCO
);
2155 mutex_unlock(&cs43130
->clk_mutex
);
2158 static irqreturn_t
cs43130_irq_thread(int irq
, void *data
)
2160 struct cs43130_private
*cs43130
= (struct cs43130_private
*)data
;
2161 struct snd_soc_component
*component
= cs43130
->component
;
2162 unsigned int stickies
[CS43130_NUM_INT
];
2163 unsigned int irq_occurrence
= 0;
2164 unsigned int masks
[CS43130_NUM_INT
];
2167 for (i
= 0; i
< ARRAY_SIZE(stickies
); i
++) {
2168 regmap_read(cs43130
->regmap
, CS43130_INT_STATUS_1
+ i
,
2170 regmap_read(cs43130
->regmap
, CS43130_INT_MASK_1
+ i
,
2174 for (i
= 0; i
< ARRAY_SIZE(stickies
); i
++) {
2175 stickies
[i
] = stickies
[i
] & (~masks
[i
]);
2176 for (j
= 0; j
< 8; j
++)
2177 irq_occurrence
+= (stickies
[i
] >> j
) & 1;
2179 dev_dbg(component
->dev
, "number of interrupts occurred (%u)\n",
2182 if (!irq_occurrence
)
2185 if (stickies
[0] & CS43130_XTAL_RDY_INT
) {
2186 complete(&cs43130
->xtal_rdy
);
2190 if (stickies
[0] & CS43130_PLL_RDY_INT
) {
2191 complete(&cs43130
->pll_rdy
);
2195 if (stickies
[3] & CS43130_HPLOAD_NO_DC_INT
) {
2196 cs43130
->hpload_stat
= stickies
[3];
2197 dev_err(component
->dev
,
2198 "DC load has not completed before AC load (%x)\n",
2199 cs43130
->hpload_stat
);
2200 complete(&cs43130
->hpload_evt
);
2204 if (stickies
[3] & CS43130_HPLOAD_UNPLUG_INT
) {
2205 cs43130
->hpload_stat
= stickies
[3];
2206 dev_err(component
->dev
, "HP unplugged during measurement (%x)\n",
2207 cs43130
->hpload_stat
);
2208 complete(&cs43130
->hpload_evt
);
2212 if (stickies
[3] & CS43130_HPLOAD_OOR_INT
) {
2213 cs43130
->hpload_stat
= stickies
[3];
2214 dev_err(component
->dev
, "HP load out of range (%x)\n",
2215 cs43130
->hpload_stat
);
2216 complete(&cs43130
->hpload_evt
);
2220 if (stickies
[3] & CS43130_HPLOAD_AC_INT
) {
2221 cs43130
->hpload_stat
= stickies
[3];
2222 dev_dbg(component
->dev
, "HP AC load measurement done (%x)\n",
2223 cs43130
->hpload_stat
);
2224 complete(&cs43130
->hpload_evt
);
2228 if (stickies
[3] & CS43130_HPLOAD_DC_INT
) {
2229 cs43130
->hpload_stat
= stickies
[3];
2230 dev_dbg(component
->dev
, "HP DC load measurement done (%x)\n",
2231 cs43130
->hpload_stat
);
2232 complete(&cs43130
->hpload_evt
);
2236 if (stickies
[3] & CS43130_HPLOAD_ON_INT
) {
2237 cs43130
->hpload_stat
= stickies
[3];
2238 dev_dbg(component
->dev
, "HP load state machine on done (%x)\n",
2239 cs43130
->hpload_stat
);
2240 complete(&cs43130
->hpload_evt
);
2244 if (stickies
[3] & CS43130_HPLOAD_OFF_INT
) {
2245 cs43130
->hpload_stat
= stickies
[3];
2246 dev_dbg(component
->dev
, "HP load state machine off done (%x)\n",
2247 cs43130
->hpload_stat
);
2248 complete(&cs43130
->hpload_evt
);
2252 if (stickies
[0] & CS43130_XTAL_ERR_INT
) {
2253 dev_err(component
->dev
, "Crystal err: clock is not running\n");
2257 if (stickies
[0] & CS43130_HP_UNPLUG_INT
) {
2258 dev_dbg(component
->dev
, "HP unplugged\n");
2259 cs43130
->hpload_done
= false;
2260 snd_soc_jack_report(&cs43130
->jack
, 0, CS43130_JACK_MASK
);
2264 if (stickies
[0] & CS43130_HP_PLUG_INT
) {
2265 if (cs43130
->dc_meas
&& !cs43130
->hpload_done
&&
2266 !work_busy(&cs43130
->work
)) {
2267 dev_dbg(component
->dev
, "HP load queue work\n");
2268 queue_work(cs43130
->wq
, &cs43130
->work
);
2271 snd_soc_jack_report(&cs43130
->jack
, SND_JACK_MECHANICAL
,
2279 static int cs43130_probe(struct snd_soc_component
*component
)
2282 struct cs43130_private
*cs43130
= snd_soc_component_get_drvdata(component
);
2283 struct snd_soc_card
*card
= component
->card
;
2286 cs43130
->component
= component
;
2288 if (cs43130
->xtal_ibias
!= CS43130_XTAL_UNUSED
) {
2289 regmap_update_bits(cs43130
->regmap
, CS43130_CRYSTAL_SET
,
2290 CS43130_XTAL_IBIAS_MASK
,
2291 cs43130
->xtal_ibias
);
2292 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
2293 CS43130_XTAL_ERR_INT
, 0);
2296 ret
= snd_soc_card_jack_new(card
, "Headphone", CS43130_JACK_MASK
,
2297 &cs43130
->jack
, NULL
, 0);
2299 dev_err(component
->dev
, "Cannot create jack\n");
2303 cs43130
->hpload_done
= false;
2304 if (cs43130
->dc_meas
) {
2305 ret
= device_create_file(component
->dev
, &dev_attr_hpload_dc_l
);
2309 ret
= device_create_file(component
->dev
, &dev_attr_hpload_dc_r
);
2313 ret
= device_create_file(component
->dev
, &dev_attr_hpload_ac_l
);
2317 ret
= device_create_file(component
->dev
, &dev_attr_hpload_ac_r
);
2321 cs43130
->wq
= create_singlethread_workqueue("cs43130_hp");
2324 INIT_WORK(&cs43130
->work
, cs43130_imp_meas
);
2327 regmap_read(cs43130
->regmap
, CS43130_INT_STATUS_1
, ®
);
2328 regmap_read(cs43130
->regmap
, CS43130_HP_STATUS
, ®
);
2329 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
2330 CS43130_HP_PLUG_INT
| CS43130_HP_UNPLUG_INT
, 0);
2331 regmap_update_bits(cs43130
->regmap
, CS43130_HP_DETECT
,
2332 CS43130_HP_DETECT_CTRL_MASK
, 0);
2333 regmap_update_bits(cs43130
->regmap
, CS43130_HP_DETECT
,
2334 CS43130_HP_DETECT_CTRL_MASK
,
2335 CS43130_HP_DETECT_CTRL_MASK
);
2340 static struct snd_soc_component_driver soc_component_dev_cs43130
= {
2341 .probe
= cs43130_probe
,
2342 .controls
= cs43130_snd_controls
,
2343 .num_controls
= ARRAY_SIZE(cs43130_snd_controls
),
2344 .set_sysclk
= cs43130_component_set_sysclk
,
2345 .set_pll
= cs43130_set_pll
,
2347 .use_pmdown_time
= 1,
2349 .non_legacy_dai_naming
= 1,
2352 static const struct regmap_config cs43130_regmap
= {
2357 .max_register
= CS43130_LASTREG
,
2358 .reg_defaults
= cs43130_reg_defaults
,
2359 .num_reg_defaults
= ARRAY_SIZE(cs43130_reg_defaults
),
2360 .readable_reg
= cs43130_readable_register
,
2361 .precious_reg
= cs43130_precious_register
,
2362 .volatile_reg
= cs43130_volatile_register
,
2363 .cache_type
= REGCACHE_RBTREE
,
2364 /* needed for regcache_sync */
2365 .use_single_read
= true,
2366 .use_single_write
= true,
2369 static u16
const cs43130_dc_threshold
[CS43130_DC_THRESHOLD
] = {
2374 static int cs43130_handle_device_data(struct i2c_client
*i2c_client
,
2375 struct cs43130_private
*cs43130
)
2377 struct device_node
*np
= i2c_client
->dev
.of_node
;
2381 if (of_property_read_u32(np
, "cirrus,xtal-ibias", &val
) < 0) {
2382 /* Crystal is unused. System clock is used for external MCLK */
2383 cs43130
->xtal_ibias
= CS43130_XTAL_UNUSED
;
2389 cs43130
->xtal_ibias
= CS43130_XTAL_IBIAS_7_5UA
;
2392 cs43130
->xtal_ibias
= CS43130_XTAL_IBIAS_12_5UA
;
2395 cs43130
->xtal_ibias
= CS43130_XTAL_IBIAS_15UA
;
2398 dev_err(&i2c_client
->dev
,
2399 "Invalid cirrus,xtal-ibias value: %d\n", val
);
2403 cs43130
->dc_meas
= of_property_read_bool(np
, "cirrus,dc-measure");
2404 cs43130
->ac_meas
= of_property_read_bool(np
, "cirrus,ac-measure");
2406 if (of_property_read_u16_array(np
, "cirrus,ac-freq", cs43130
->ac_freq
,
2407 CS43130_AC_FREQ
) < 0) {
2408 for (i
= 0; i
< CS43130_AC_FREQ
; i
++)
2409 cs43130
->ac_freq
[i
] = cs43130_ac_freq
[i
];
2412 if (of_property_read_u16_array(np
, "cirrus,dc-threshold",
2413 cs43130
->dc_threshold
,
2414 CS43130_DC_THRESHOLD
) < 0) {
2415 for (i
= 0; i
< CS43130_DC_THRESHOLD
; i
++)
2416 cs43130
->dc_threshold
[i
] = cs43130_dc_threshold
[i
];
2422 static int cs43130_i2c_probe(struct i2c_client
*client
,
2423 const struct i2c_device_id
*id
)
2425 struct cs43130_private
*cs43130
;
2427 unsigned int devid
= 0;
2431 cs43130
= devm_kzalloc(&client
->dev
, sizeof(*cs43130
), GFP_KERNEL
);
2435 i2c_set_clientdata(client
, cs43130
);
2437 cs43130
->regmap
= devm_regmap_init_i2c(client
, &cs43130_regmap
);
2438 if (IS_ERR(cs43130
->regmap
)) {
2439 ret
= PTR_ERR(cs43130
->regmap
);
2443 if (client
->dev
.of_node
) {
2444 ret
= cs43130_handle_device_data(client
, cs43130
);
2448 for (i
= 0; i
< ARRAY_SIZE(cs43130
->supplies
); i
++)
2449 cs43130
->supplies
[i
].supply
= cs43130_supply_names
[i
];
2451 ret
= devm_regulator_bulk_get(&client
->dev
,
2452 ARRAY_SIZE(cs43130
->supplies
),
2455 dev_err(&client
->dev
, "Failed to request supplies: %d\n", ret
);
2458 ret
= regulator_bulk_enable(ARRAY_SIZE(cs43130
->supplies
),
2461 dev_err(&client
->dev
, "Failed to enable supplies: %d\n", ret
);
2465 cs43130
->reset_gpio
= devm_gpiod_get_optional(&client
->dev
,
2466 "reset", GPIOD_OUT_LOW
);
2467 if (IS_ERR(cs43130
->reset_gpio
))
2468 return PTR_ERR(cs43130
->reset_gpio
);
2470 gpiod_set_value_cansleep(cs43130
->reset_gpio
, 1);
2472 usleep_range(2000, 2050);
2474 ret
= regmap_read(cs43130
->regmap
, CS43130_DEVID_AB
, ®
);
2476 devid
= (reg
& 0xFF) << 12;
2477 ret
= regmap_read(cs43130
->regmap
, CS43130_DEVID_CD
, ®
);
2478 devid
|= (reg
& 0xFF) << 4;
2479 ret
= regmap_read(cs43130
->regmap
, CS43130_DEVID_E
, ®
);
2480 devid
|= (reg
& 0xF0) >> 4;
2483 case CS43130_CHIP_ID
:
2484 case CS4399_CHIP_ID
:
2485 case CS43131_CHIP_ID
:
2486 case CS43198_CHIP_ID
:
2489 dev_err(&client
->dev
,
2490 "CS43130 Device ID %X. Expected ID %X, %X, %X or %X\n",
2491 devid
, CS43130_CHIP_ID
, CS4399_CHIP_ID
,
2492 CS43131_CHIP_ID
, CS43198_CHIP_ID
);
2497 cs43130
->dev_id
= devid
;
2498 ret
= regmap_read(cs43130
->regmap
, CS43130_REV_ID
, ®
);
2500 dev_err(&client
->dev
, "Get Revision ID failed\n");
2504 dev_info(&client
->dev
,
2505 "Cirrus Logic CS43130 (%x), Revision: %02X\n", devid
,
2508 mutex_init(&cs43130
->clk_mutex
);
2510 init_completion(&cs43130
->xtal_rdy
);
2511 init_completion(&cs43130
->pll_rdy
);
2512 init_completion(&cs43130
->hpload_evt
);
2514 ret
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
2515 NULL
, cs43130_irq_thread
,
2516 IRQF_ONESHOT
| IRQF_TRIGGER_LOW
,
2517 "cs43130", cs43130
);
2519 dev_err(&client
->dev
, "Failed to request IRQ: %d\n", ret
);
2523 cs43130
->mclk_int_src
= CS43130_MCLK_SRC_RCO
;
2525 pm_runtime_set_autosuspend_delay(&client
->dev
, 100);
2526 pm_runtime_use_autosuspend(&client
->dev
);
2527 pm_runtime_set_active(&client
->dev
);
2528 pm_runtime_enable(&client
->dev
);
2530 switch (cs43130
->dev_id
) {
2531 case CS43130_CHIP_ID
:
2532 case CS43131_CHIP_ID
:
2533 memcpy(all_hp_widgets
, digital_hp_widgets
,
2534 sizeof(digital_hp_widgets
));
2535 memcpy(all_hp_widgets
+ ARRAY_SIZE(digital_hp_widgets
),
2536 analog_hp_widgets
, sizeof(analog_hp_widgets
));
2537 memcpy(all_hp_routes
, digital_hp_routes
,
2538 sizeof(digital_hp_routes
));
2539 memcpy(all_hp_routes
+ ARRAY_SIZE(digital_hp_routes
),
2540 analog_hp_routes
, sizeof(analog_hp_routes
));
2542 soc_component_dev_cs43130
.dapm_widgets
=
2544 soc_component_dev_cs43130
.num_dapm_widgets
=
2545 ARRAY_SIZE(all_hp_widgets
);
2546 soc_component_dev_cs43130
.dapm_routes
=
2548 soc_component_dev_cs43130
.num_dapm_routes
=
2549 ARRAY_SIZE(all_hp_routes
);
2551 case CS43198_CHIP_ID
:
2552 case CS4399_CHIP_ID
:
2553 soc_component_dev_cs43130
.dapm_widgets
=
2555 soc_component_dev_cs43130
.num_dapm_widgets
=
2556 ARRAY_SIZE(digital_hp_widgets
);
2557 soc_component_dev_cs43130
.dapm_routes
=
2559 soc_component_dev_cs43130
.num_dapm_routes
=
2560 ARRAY_SIZE(digital_hp_routes
);
2564 ret
= devm_snd_soc_register_component(&client
->dev
,
2565 &soc_component_dev_cs43130
,
2566 cs43130_dai
, ARRAY_SIZE(cs43130_dai
));
2568 dev_err(&client
->dev
,
2569 "snd_soc_register_component failed with ret = %d\n", ret
);
2573 regmap_update_bits(cs43130
->regmap
, CS43130_PAD_INT_CFG
,
2574 CS43130_ASP_3ST_MASK
, 0);
2575 regmap_update_bits(cs43130
->regmap
, CS43130_PAD_INT_CFG
,
2576 CS43130_XSP_3ST_MASK
, 0);
2583 static int cs43130_i2c_remove(struct i2c_client
*client
)
2585 struct cs43130_private
*cs43130
= i2c_get_clientdata(client
);
2587 if (cs43130
->xtal_ibias
!= CS43130_XTAL_UNUSED
)
2588 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
2589 CS43130_XTAL_ERR_INT
,
2590 1 << CS43130_XTAL_ERR_INT_SHIFT
);
2592 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
2593 CS43130_HP_PLUG_INT
| CS43130_HP_UNPLUG_INT
,
2594 CS43130_HP_PLUG_INT
| CS43130_HP_UNPLUG_INT
);
2596 if (cs43130
->dc_meas
) {
2597 cancel_work_sync(&cs43130
->work
);
2598 flush_workqueue(cs43130
->wq
);
2600 device_remove_file(&client
->dev
, &dev_attr_hpload_dc_l
);
2601 device_remove_file(&client
->dev
, &dev_attr_hpload_dc_r
);
2602 device_remove_file(&client
->dev
, &dev_attr_hpload_ac_l
);
2603 device_remove_file(&client
->dev
, &dev_attr_hpload_ac_r
);
2606 gpiod_set_value_cansleep(cs43130
->reset_gpio
, 0);
2608 pm_runtime_disable(&client
->dev
);
2609 regulator_bulk_disable(CS43130_NUM_SUPPLIES
, cs43130
->supplies
);
2614 static int __maybe_unused
cs43130_runtime_suspend(struct device
*dev
)
2616 struct cs43130_private
*cs43130
= dev_get_drvdata(dev
);
2618 if (cs43130
->xtal_ibias
!= CS43130_XTAL_UNUSED
)
2619 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
2620 CS43130_XTAL_ERR_INT
,
2621 1 << CS43130_XTAL_ERR_INT_SHIFT
);
2623 regcache_cache_only(cs43130
->regmap
, true);
2624 regcache_mark_dirty(cs43130
->regmap
);
2626 gpiod_set_value_cansleep(cs43130
->reset_gpio
, 0);
2628 regulator_bulk_disable(CS43130_NUM_SUPPLIES
, cs43130
->supplies
);
2633 static int __maybe_unused
cs43130_runtime_resume(struct device
*dev
)
2635 struct cs43130_private
*cs43130
= dev_get_drvdata(dev
);
2638 ret
= regulator_bulk_enable(CS43130_NUM_SUPPLIES
, cs43130
->supplies
);
2640 dev_err(dev
, "Failed to enable supplies: %d\n", ret
);
2644 regcache_cache_only(cs43130
->regmap
, false);
2646 gpiod_set_value_cansleep(cs43130
->reset_gpio
, 1);
2648 usleep_range(2000, 2050);
2650 ret
= regcache_sync(cs43130
->regmap
);
2652 dev_err(dev
, "Failed to restore register cache\n");
2656 if (cs43130
->xtal_ibias
!= CS43130_XTAL_UNUSED
)
2657 regmap_update_bits(cs43130
->regmap
, CS43130_INT_MASK_1
,
2658 CS43130_XTAL_ERR_INT
, 0);
2662 regcache_cache_only(cs43130
->regmap
, true);
2663 regulator_bulk_disable(CS43130_NUM_SUPPLIES
, cs43130
->supplies
);
2668 static const struct dev_pm_ops cs43130_runtime_pm
= {
2669 SET_RUNTIME_PM_OPS(cs43130_runtime_suspend
, cs43130_runtime_resume
,
2673 static const struct of_device_id cs43130_of_match
[] = {
2674 {.compatible
= "cirrus,cs43130",},
2675 {.compatible
= "cirrus,cs4399",},
2676 {.compatible
= "cirrus,cs43131",},
2677 {.compatible
= "cirrus,cs43198",},
2681 MODULE_DEVICE_TABLE(of
, cs43130_of_match
);
2683 static const struct i2c_device_id cs43130_i2c_id
[] = {
2691 MODULE_DEVICE_TABLE(i2c
, cs43130_i2c_id
);
2693 static struct i2c_driver cs43130_i2c_driver
= {
2696 .of_match_table
= cs43130_of_match
,
2697 .pm
= &cs43130_runtime_pm
,
2699 .id_table
= cs43130_i2c_id
,
2700 .probe
= cs43130_i2c_probe
,
2701 .remove
= cs43130_i2c_remove
,
2704 module_i2c_driver(cs43130_i2c_driver
);
2706 MODULE_AUTHOR("Li Xu <li.xu@cirrus.com>");
2707 MODULE_DESCRIPTION("Cirrus Logic CS43130 ALSA SoC Codec Driver");
2708 MODULE_LICENSE("GPL");