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>
39 #include "cirrus_legacy.h"
41 static const struct reg_default cs43130_reg_defaults[] = {
42 {CS43130_SYS_CLK_CTL_1, 0x06},
43 {CS43130_SP_SRATE, 0x01},
44 {CS43130_SP_BITSIZE, 0x05},
45 {CS43130_PAD_INT_CFG, 0x03},
46 {CS43130_PWDN_CTL, 0xFE},
47 {CS43130_CRYSTAL_SET, 0x04},
48 {CS43130_PLL_SET_1, 0x00},
49 {CS43130_PLL_SET_2, 0x00},
50 {CS43130_PLL_SET_3, 0x00},
51 {CS43130_PLL_SET_4, 0x00},
52 {CS43130_PLL_SET_5, 0x40},
53 {CS43130_PLL_SET_6, 0x10},
54 {CS43130_PLL_SET_7, 0x80},
55 {CS43130_PLL_SET_8, 0x03},
56 {CS43130_PLL_SET_9, 0x02},
57 {CS43130_PLL_SET_10, 0x02},
58 {CS43130_CLKOUT_CTL, 0x00},
59 {CS43130_ASP_NUM_1, 0x01},
60 {CS43130_ASP_NUM_2, 0x00},
61 {CS43130_ASP_DEN_1, 0x08},
62 {CS43130_ASP_DEN_2, 0x00},
63 {CS43130_ASP_LRCK_HI_TIME_1, 0x1F},
64 {CS43130_ASP_LRCK_HI_TIME_2, 0x00},
65 {CS43130_ASP_LRCK_PERIOD_1, 0x3F},
66 {CS43130_ASP_LRCK_PERIOD_2, 0x00},
67 {CS43130_ASP_CLOCK_CONF, 0x0C},
68 {CS43130_ASP_FRAME_CONF, 0x0A},
69 {CS43130_XSP_NUM_1, 0x01},
70 {CS43130_XSP_NUM_2, 0x00},
71 {CS43130_XSP_DEN_1, 0x02},
72 {CS43130_XSP_DEN_2, 0x00},
73 {CS43130_XSP_LRCK_HI_TIME_1, 0x1F},
74 {CS43130_XSP_LRCK_HI_TIME_2, 0x00},
75 {CS43130_XSP_LRCK_PERIOD_1, 0x3F},
76 {CS43130_XSP_LRCK_PERIOD_2, 0x00},
77 {CS43130_XSP_CLOCK_CONF, 0x0C},
78 {CS43130_XSP_FRAME_CONF, 0x0A},
79 {CS43130_ASP_CH_1_LOC, 0x00},
80 {CS43130_ASP_CH_2_LOC, 0x00},
81 {CS43130_ASP_CH_1_SZ_EN, 0x06},
82 {CS43130_ASP_CH_2_SZ_EN, 0x0E},
83 {CS43130_XSP_CH_1_LOC, 0x00},
84 {CS43130_XSP_CH_2_LOC, 0x00},
85 {CS43130_XSP_CH_1_SZ_EN, 0x06},
86 {CS43130_XSP_CH_2_SZ_EN, 0x0E},
87 {CS43130_DSD_VOL_B, 0x78},
88 {CS43130_DSD_VOL_A, 0x78},
89 {CS43130_DSD_PATH_CTL_1, 0xA8},
90 {CS43130_DSD_INT_CFG, 0x00},
91 {CS43130_DSD_PATH_CTL_2, 0x02},
92 {CS43130_DSD_PCM_MIX_CTL, 0x00},
93 {CS43130_DSD_PATH_CTL_3, 0x40},
94 {CS43130_HP_OUT_CTL_1, 0x30},
95 {CS43130_PCM_FILT_OPT, 0x02},
96 {CS43130_PCM_VOL_B, 0x78},
97 {CS43130_PCM_VOL_A, 0x78},
98 {CS43130_PCM_PATH_CTL_1, 0xA8},
99 {CS43130_PCM_PATH_CTL_2, 0x00},
100 {CS43130_CLASS_H_CTL, 0x1E},
101 {CS43130_HP_DETECT, 0x04},
102 {CS43130_HP_LOAD_1, 0x00},
103 {CS43130_HP_MEAS_LOAD_1, 0x00},
104 {CS43130_HP_MEAS_LOAD_2, 0x00},
105 {CS43130_INT_MASK_1, 0xFF},
106 {CS43130_INT_MASK_2, 0xFF},
107 {CS43130_INT_MASK_3, 0xFF},
108 {CS43130_INT_MASK_4, 0xFF},
109 {CS43130_INT_MASK_5, 0xFF},
112 static bool cs43130_volatile_register(struct device *dev, unsigned int reg)
115 case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
116 case CS43130_HP_DC_STAT_1 ... CS43130_HP_DC_STAT_2:
117 case CS43130_HP_AC_STAT_1 ... CS43130_HP_AC_STAT_2:
124 static bool cs43130_readable_register(struct device *dev, unsigned int reg)
127 case CS43130_DEVID_AB ... CS43130_SYS_CLK_CTL_1:
128 case CS43130_SP_SRATE ... CS43130_PAD_INT_CFG:
129 case CS43130_PWDN_CTL:
130 case CS43130_CRYSTAL_SET:
131 case CS43130_PLL_SET_1 ... CS43130_PLL_SET_5:
132 case CS43130_PLL_SET_6:
133 case CS43130_PLL_SET_7:
134 case CS43130_PLL_SET_8:
135 case CS43130_PLL_SET_9:
136 case CS43130_PLL_SET_10:
137 case CS43130_CLKOUT_CTL:
138 case CS43130_ASP_NUM_1 ... CS43130_ASP_FRAME_CONF:
139 case CS43130_XSP_NUM_1 ... CS43130_XSP_FRAME_CONF:
140 case CS43130_ASP_CH_1_LOC:
141 case CS43130_ASP_CH_2_LOC:
142 case CS43130_ASP_CH_1_SZ_EN:
143 case CS43130_ASP_CH_2_SZ_EN:
144 case CS43130_XSP_CH_1_LOC:
145 case CS43130_XSP_CH_2_LOC:
146 case CS43130_XSP_CH_1_SZ_EN:
147 case CS43130_XSP_CH_2_SZ_EN:
148 case CS43130_DSD_VOL_B ... CS43130_DSD_PATH_CTL_3:
149 case CS43130_HP_OUT_CTL_1:
150 case CS43130_PCM_FILT_OPT ... CS43130_PCM_PATH_CTL_2:
151 case CS43130_CLASS_H_CTL:
152 case CS43130_HP_DETECT:
153 case CS43130_HP_STATUS:
154 case CS43130_HP_LOAD_1:
155 case CS43130_HP_MEAS_LOAD_1:
156 case CS43130_HP_MEAS_LOAD_2:
157 case CS43130_HP_DC_STAT_1:
158 case CS43130_HP_DC_STAT_2:
159 case CS43130_HP_AC_STAT_1:
160 case CS43130_HP_AC_STAT_2:
161 case CS43130_HP_LOAD_STAT:
162 case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
163 case CS43130_INT_MASK_1 ... CS43130_INT_MASK_5:
170 static bool cs43130_precious_register(struct device *dev, unsigned int reg)
173 case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
180 struct cs43130_pll_params {
187 unsigned int pll_out;
191 static const struct cs43130_pll_params pll_ratio_table[] = {
192 {9600000, 0x02, 0x49, 0x800000, 0x00, 0x08, 22579200, 151},
193 {9600000, 0x02, 0x50, 0x000000, 0x00, 0x08, 24576000, 164},
195 {11289600, 0x02, 0X40, 0, 0x01, 0x08, 22579200, 128},
196 {11289600, 0x02, 0x44, 0x06F700, 0x0, 0x08, 24576000, 139},
198 {12000000, 0x02, 0x49, 0x800000, 0x00, 0x0A, 22579200, 120},
199 {12000000, 0x02, 0x40, 0x000000, 0x00, 0x08, 24576000, 131},
201 {12288000, 0x02, 0x49, 0x800000, 0x01, 0x0A, 22579200, 118},
202 {12288000, 0x02, 0x40, 0x000000, 0x01, 0x08, 24576000, 128},
204 {13000000, 0x02, 0x45, 0x797680, 0x01, 0x0A, 22579200, 111},
205 {13000000, 0x02, 0x3C, 0x7EA940, 0x01, 0x08, 24576000, 121},
207 {19200000, 0x03, 0x49, 0x800000, 0x00, 0x08, 22579200, 151},
208 {19200000, 0x03, 0x50, 0x000000, 0x00, 0x08, 24576000, 164},
210 {22579200, 0, 0, 0, 0, 0, 22579200, 0},
211 {22579200, 0x03, 0x44, 0x06F700, 0x00, 0x08, 24576000, 139},
213 {24000000, 0x03, 0x49, 0x800000, 0x00, 0x0A, 22579200, 120},
214 {24000000, 0x03, 0x40, 0x000000, 0x00, 0x08, 24576000, 131},
216 {24576000, 0x03, 0x49, 0x800000, 0x01, 0x0A, 22579200, 118},
217 {24576000, 0, 0, 0, 0, 0, 24576000, 0},
219 {26000000, 0x03, 0x45, 0x797680, 0x01, 0x0A, 22579200, 111},
220 {26000000, 0x03, 0x3C, 0x7EA940, 0x01, 0x08, 24576000, 121},
223 static const struct cs43130_pll_params *cs43130_get_pll_table(
224 unsigned int freq_in, unsigned int freq_out)
228 for (i = 0; i < ARRAY_SIZE(pll_ratio_table); i++) {
229 if (pll_ratio_table[i].pll_in == freq_in &&
230 pll_ratio_table[i].pll_out == freq_out)
231 return &pll_ratio_table[i];
237 static int cs43130_pll_config(struct snd_soc_component *component)
239 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
240 const struct cs43130_pll_params *pll_entry;
242 dev_dbg(component->dev, "cs43130->mclk = %u, cs43130->mclk_int = %u\n",
243 cs43130->mclk, cs43130->mclk_int);
245 pll_entry = cs43130_get_pll_table(cs43130->mclk, cs43130->mclk_int);
249 if (pll_entry->pll_cal_ratio == 0) {
250 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_1,
251 CS43130_PLL_START_MASK, 0);
253 cs43130->pll_bypass = true;
257 cs43130->pll_bypass = false;
259 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_2,
260 CS43130_PLL_DIV_DATA_MASK,
261 pll_entry->pll_div_frac >>
262 CS43130_PLL_DIV_FRAC_0_DATA_SHIFT);
263 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_3,
264 CS43130_PLL_DIV_DATA_MASK,
265 pll_entry->pll_div_frac >>
266 CS43130_PLL_DIV_FRAC_1_DATA_SHIFT);
267 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_4,
268 CS43130_PLL_DIV_DATA_MASK,
269 pll_entry->pll_div_frac >>
270 CS43130_PLL_DIV_FRAC_2_DATA_SHIFT);
271 regmap_write(cs43130->regmap, CS43130_PLL_SET_5,
272 pll_entry->pll_div_int);
273 regmap_write(cs43130->regmap, CS43130_PLL_SET_6, pll_entry->pll_divout);
274 regmap_write(cs43130->regmap, CS43130_PLL_SET_7,
275 pll_entry->pll_cal_ratio);
276 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_8,
277 CS43130_PLL_MODE_MASK,
278 pll_entry->pll_mode << CS43130_PLL_MODE_SHIFT);
279 regmap_write(cs43130->regmap, CS43130_PLL_SET_9,
280 pll_entry->sclk_prediv);
281 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_1,
282 CS43130_PLL_START_MASK, 1);
287 static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int source,
288 unsigned int freq_in, unsigned int freq_out)
291 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
304 cs43130->mclk = freq_in;
307 dev_err(component->dev,
308 "unsupported pll input reference clock:%d\n", freq_in);
314 cs43130->mclk_int = freq_out;
317 cs43130->mclk_int = freq_out;
320 dev_err(component->dev,
321 "unsupported pll output ref clock: %u\n", freq_out);
325 ret = cs43130_pll_config(component);
326 dev_dbg(component->dev, "cs43130->pll_bypass = %d", cs43130->pll_bypass);
330 static int cs43130_change_clksrc(struct snd_soc_component *component,
331 enum cs43130_mclk_src_sel src)
334 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
335 int mclk_int_decoded;
337 if (src == cs43130->mclk_int_src) {
338 /* clk source has not changed */
342 switch (cs43130->mclk_int) {
343 case CS43130_MCLK_22M:
344 mclk_int_decoded = CS43130_MCLK_22P5;
346 case CS43130_MCLK_24M:
347 mclk_int_decoded = CS43130_MCLK_24P5;
350 dev_err(component->dev, "Invalid MCLK INT freq: %u\n", cs43130->mclk_int);
355 case CS43130_MCLK_SRC_EXT:
356 cs43130->pll_bypass = true;
357 cs43130->mclk_int_src = CS43130_MCLK_SRC_EXT;
358 if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
359 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
360 CS43130_PDN_XTAL_MASK,
361 1 << CS43130_PDN_XTAL_SHIFT);
363 reinit_completion(&cs43130->xtal_rdy);
364 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
365 CS43130_XTAL_RDY_INT_MASK, 0);
366 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
367 CS43130_PDN_XTAL_MASK, 0);
368 ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
369 msecs_to_jiffies(100));
370 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
371 CS43130_XTAL_RDY_INT_MASK,
372 1 << CS43130_XTAL_RDY_INT_SHIFT);
374 dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
379 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
380 CS43130_MCLK_SRC_SEL_MASK,
381 src << CS43130_MCLK_SRC_SEL_SHIFT);
382 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
383 CS43130_MCLK_INT_MASK,
384 mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
385 usleep_range(150, 200);
387 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
388 CS43130_PDN_PLL_MASK,
389 1 << CS43130_PDN_PLL_SHIFT);
391 case CS43130_MCLK_SRC_PLL:
392 cs43130->pll_bypass = false;
393 cs43130->mclk_int_src = CS43130_MCLK_SRC_PLL;
394 if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
395 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
396 CS43130_PDN_XTAL_MASK,
397 1 << CS43130_PDN_XTAL_SHIFT);
399 reinit_completion(&cs43130->xtal_rdy);
400 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
401 CS43130_XTAL_RDY_INT_MASK, 0);
402 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
403 CS43130_PDN_XTAL_MASK, 0);
404 ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
405 msecs_to_jiffies(100));
406 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
407 CS43130_XTAL_RDY_INT_MASK,
408 1 << CS43130_XTAL_RDY_INT_SHIFT);
410 dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
415 reinit_completion(&cs43130->pll_rdy);
416 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
417 CS43130_PLL_RDY_INT_MASK, 0);
418 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
419 CS43130_PDN_PLL_MASK, 0);
420 ret = wait_for_completion_timeout(&cs43130->pll_rdy,
421 msecs_to_jiffies(100));
422 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
423 CS43130_PLL_RDY_INT_MASK,
424 1 << CS43130_PLL_RDY_INT_SHIFT);
426 dev_err(component->dev, "Timeout waiting for PLL_READY interrupt\n");
430 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
431 CS43130_MCLK_SRC_SEL_MASK,
432 src << CS43130_MCLK_SRC_SEL_SHIFT);
433 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
434 CS43130_MCLK_INT_MASK,
435 mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
436 usleep_range(150, 200);
438 case CS43130_MCLK_SRC_RCO:
439 cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
441 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
442 CS43130_MCLK_SRC_SEL_MASK,
443 src << CS43130_MCLK_SRC_SEL_SHIFT);
444 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
445 CS43130_MCLK_INT_MASK,
446 CS43130_MCLK_22P5 << CS43130_MCLK_INT_SHIFT);
447 usleep_range(150, 200);
449 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
450 CS43130_PDN_XTAL_MASK,
451 1 << CS43130_PDN_XTAL_SHIFT);
452 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
453 CS43130_PDN_PLL_MASK,
454 1 << CS43130_PDN_PLL_SHIFT);
457 dev_err(component->dev, "Invalid MCLK source value\n");
464 static const struct cs43130_bitwidth_map cs43130_bitwidth_table[] = {
465 {8, CS43130_SP_BIT_SIZE_8, CS43130_CH_BIT_SIZE_8},
466 {16, CS43130_SP_BIT_SIZE_16, CS43130_CH_BIT_SIZE_16},
467 {24, CS43130_SP_BIT_SIZE_24, CS43130_CH_BIT_SIZE_24},
468 {32, CS43130_SP_BIT_SIZE_32, CS43130_CH_BIT_SIZE_32},
471 static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
472 unsigned int bitwidth)
476 for (i = 0; i < ARRAY_SIZE(cs43130_bitwidth_table); i++) {
477 if (cs43130_bitwidth_table[i].bitwidth == bitwidth)
478 return &cs43130_bitwidth_table[i];
484 static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
485 struct regmap *regmap)
487 const struct cs43130_bitwidth_map *bw_map;
489 bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
494 case CS43130_ASP_PCM_DAI:
495 case CS43130_ASP_DOP_DAI:
496 regmap_update_bits(regmap, CS43130_ASP_CH_1_SZ_EN,
497 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
498 regmap_update_bits(regmap, CS43130_ASP_CH_2_SZ_EN,
499 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
500 regmap_update_bits(regmap, CS43130_SP_BITSIZE,
501 CS43130_ASP_BITSIZE_MASK, bw_map->sp_bit);
503 case CS43130_XSP_DOP_DAI:
504 regmap_update_bits(regmap, CS43130_XSP_CH_1_SZ_EN,
505 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
506 regmap_update_bits(regmap, CS43130_XSP_CH_2_SZ_EN,
507 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
508 regmap_update_bits(regmap, CS43130_SP_BITSIZE,
509 CS43130_XSP_BITSIZE_MASK, bw_map->sp_bit <<
510 CS43130_XSP_BITSIZE_SHIFT);
519 static const struct cs43130_rate_map cs43130_rate_table[] = {
520 {32000, CS43130_ASP_SPRATE_32K},
521 {44100, CS43130_ASP_SPRATE_44_1K},
522 {48000, CS43130_ASP_SPRATE_48K},
523 {88200, CS43130_ASP_SPRATE_88_2K},
524 {96000, CS43130_ASP_SPRATE_96K},
525 {176400, CS43130_ASP_SPRATE_176_4K},
526 {192000, CS43130_ASP_SPRATE_192K},
527 {352800, CS43130_ASP_SPRATE_352_8K},
528 {384000, CS43130_ASP_SPRATE_384K},
531 static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
535 for (i = 0; i < ARRAY_SIZE(cs43130_rate_table); i++) {
536 if (cs43130_rate_table[i].fs == fs)
537 return &cs43130_rate_table[i];
543 static const struct cs43130_clk_gen *cs43130_get_clk_gen(int mclk_int, int fs,
544 const struct cs43130_clk_gen *clk_gen_table, int len_clk_gen_table)
548 for (i = 0; i < len_clk_gen_table; i++) {
549 if (clk_gen_table[i].mclk_int == mclk_int &&
550 clk_gen_table[i].fs == fs)
551 return &clk_gen_table[i];
557 static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk,
558 struct snd_pcm_hw_params *params,
559 struct cs43130_private *cs43130)
572 const struct cs43130_clk_gen *clk_gen;
574 switch (cs43130->dais[dai_id].dai_format) {
575 case SND_SOC_DAIFMT_I2S:
576 hi_size = bitwidth_sclk;
580 case SND_SOC_DAIFMT_LEFT_J:
581 hi_size = bitwidth_sclk;
585 case SND_SOC_DAIFMT_DSP_A:
590 case SND_SOC_DAIFMT_DSP_B:
599 switch (cs43130->dais[dai_id].dai_mode) {
600 case SND_SOC_DAIFMT_CBS_CFS:
603 case SND_SOC_DAIFMT_CBM_CFM:
610 frm_size = bitwidth_sclk * params_channels(params);
614 loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
616 frm_data = frm_delay & CS43130_SP_FSD_MASK;
617 frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
619 clk_data = lrck_edge & CS43130_SP_LCPOL_IN_MASK;
620 clk_data |= (lrck_edge << CS43130_SP_LCPOL_OUT_SHIFT) &
621 CS43130_SP_LCPOL_OUT_MASK;
622 clk_data |= (sclk_edge << CS43130_SP_SCPOL_IN_SHIFT) &
623 CS43130_SP_SCPOL_IN_MASK;
624 clk_data |= (sclk_edge << CS43130_SP_SCPOL_OUT_SHIFT) &
625 CS43130_SP_SCPOL_OUT_MASK;
626 clk_data |= (dai_mode_val << CS43130_SP_MODE_SHIFT) &
627 CS43130_SP_MODE_MASK;
630 case CS43130_ASP_PCM_DAI:
631 case CS43130_ASP_DOP_DAI:
632 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_1,
633 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
634 CS43130_SP_LCPR_LSB_DATA_SHIFT);
635 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_2,
636 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
637 CS43130_SP_LCPR_MSB_DATA_SHIFT);
638 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_1,
639 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
640 CS43130_SP_LCHI_LSB_DATA_SHIFT);
641 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_2,
642 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
643 CS43130_SP_LCHI_MSB_DATA_SHIFT);
644 regmap_write(cs43130->regmap, CS43130_ASP_FRAME_CONF, frm_data);
645 regmap_write(cs43130->regmap, CS43130_ASP_CH_1_LOC, loc_ch1);
646 regmap_write(cs43130->regmap, CS43130_ASP_CH_2_LOC, loc_ch2);
647 regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_1_SZ_EN,
648 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
649 regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_2_SZ_EN,
650 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
651 regmap_write(cs43130->regmap, CS43130_ASP_CLOCK_CONF, clk_data);
653 case CS43130_XSP_DOP_DAI:
654 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_1,
655 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
656 CS43130_SP_LCPR_LSB_DATA_SHIFT);
657 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_2,
658 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
659 CS43130_SP_LCPR_MSB_DATA_SHIFT);
660 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_1,
661 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
662 CS43130_SP_LCHI_LSB_DATA_SHIFT);
663 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_2,
664 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
665 CS43130_SP_LCHI_MSB_DATA_SHIFT);
666 regmap_write(cs43130->regmap, CS43130_XSP_FRAME_CONF, frm_data);
667 regmap_write(cs43130->regmap, CS43130_XSP_CH_1_LOC, loc_ch1);
668 regmap_write(cs43130->regmap, CS43130_XSP_CH_2_LOC, loc_ch2);
669 regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_1_SZ_EN,
670 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
671 regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_2_SZ_EN,
672 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
673 regmap_write(cs43130->regmap, CS43130_XSP_CLOCK_CONF, clk_data);
681 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
684 ARRAY_SIZE(cs43130_16_clk_gen));
687 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
690 ARRAY_SIZE(cs43130_32_clk_gen));
693 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
696 ARRAY_SIZE(cs43130_48_clk_gen));
699 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
702 ARRAY_SIZE(cs43130_64_clk_gen));
712 case CS43130_ASP_PCM_DAI:
713 case CS43130_ASP_DOP_DAI:
714 regmap_write(cs43130->regmap, CS43130_ASP_DEN_1,
715 (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
716 CS43130_SP_M_LSB_DATA_SHIFT);
717 regmap_write(cs43130->regmap, CS43130_ASP_DEN_2,
718 (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
719 CS43130_SP_M_MSB_DATA_SHIFT);
720 regmap_write(cs43130->regmap, CS43130_ASP_NUM_1,
721 (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
722 CS43130_SP_N_LSB_DATA_SHIFT);
723 regmap_write(cs43130->regmap, CS43130_ASP_NUM_2,
724 (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
725 CS43130_SP_N_MSB_DATA_SHIFT);
727 case CS43130_XSP_DOP_DAI:
728 regmap_write(cs43130->regmap, CS43130_XSP_DEN_1,
729 (clk_gen->v.denominator & CS43130_SP_M_LSB_DATA_MASK) >>
730 CS43130_SP_M_LSB_DATA_SHIFT);
731 regmap_write(cs43130->regmap, CS43130_XSP_DEN_2,
732 (clk_gen->v.denominator & CS43130_SP_M_MSB_DATA_MASK) >>
733 CS43130_SP_M_MSB_DATA_SHIFT);
734 regmap_write(cs43130->regmap, CS43130_XSP_NUM_1,
735 (clk_gen->v.numerator & CS43130_SP_N_LSB_DATA_MASK) >>
736 CS43130_SP_N_LSB_DATA_SHIFT);
737 regmap_write(cs43130->regmap, CS43130_XSP_NUM_2,
738 (clk_gen->v.numerator & CS43130_SP_N_MSB_DATA_MASK) >>
739 CS43130_SP_N_MSB_DATA_SHIFT);
748 static int cs43130_pcm_dsd_mix(bool en, struct regmap *regmap)
751 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
752 CS43130_MIX_PCM_PREP_MASK,
753 1 << CS43130_MIX_PCM_PREP_SHIFT);
754 usleep_range(6000, 6050);
755 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
756 CS43130_MIX_PCM_DSD_MASK,
757 1 << CS43130_MIX_PCM_DSD_SHIFT);
759 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
760 CS43130_MIX_PCM_DSD_MASK,
761 0 << CS43130_MIX_PCM_DSD_SHIFT);
762 usleep_range(1600, 1650);
763 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
764 CS43130_MIX_PCM_PREP_MASK,
765 0 << CS43130_MIX_PCM_PREP_SHIFT);
771 static int cs43130_dsd_hw_params(struct snd_pcm_substream *substream,
772 struct snd_pcm_hw_params *params,
773 struct snd_soc_dai *dai)
775 struct snd_soc_component *component = dai->component;
776 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
777 unsigned int required_clk;
780 mutex_lock(&cs43130->clk_mutex);
781 if (!cs43130->clk_req) {
782 /* no DAI is currently using clk */
783 if (!(CS43130_MCLK_22M % params_rate(params)))
784 required_clk = CS43130_MCLK_22M;
786 required_clk = CS43130_MCLK_24M;
788 cs43130_set_pll(component, 0, 0, cs43130->mclk, required_clk);
789 if (cs43130->pll_bypass)
790 cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
792 cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
796 if (cs43130->clk_req == 2)
797 cs43130_pcm_dsd_mix(true, cs43130->regmap);
798 mutex_unlock(&cs43130->clk_mutex);
800 switch (params_rate(params)) {
808 dev_err(component->dev, "Rate(%u) not supported\n",
809 params_rate(params));
813 if (cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBM_CFM)
814 regmap_update_bits(cs43130->regmap, CS43130_DSD_INT_CFG,
815 CS43130_DSD_MASTER, CS43130_DSD_MASTER);
817 regmap_update_bits(cs43130->regmap, CS43130_DSD_INT_CFG,
818 CS43130_DSD_MASTER, 0);
820 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
821 CS43130_DSD_SPEED_MASK,
822 dsd_speed << CS43130_DSD_SPEED_SHIFT);
823 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
824 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_DSD <<
825 CS43130_DSD_SRC_SHIFT);
830 static int cs43130_hw_params(struct snd_pcm_substream *substream,
831 struct snd_pcm_hw_params *params,
832 struct snd_soc_dai *dai)
834 struct snd_soc_component *component = dai->component;
835 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
836 const struct cs43130_rate_map *rate_map;
837 unsigned int sclk = cs43130->dais[dai->id].sclk;
838 unsigned int bitwidth_sclk;
839 unsigned int bitwidth_dai = (unsigned int)(params_width(params));
840 unsigned int required_clk;
843 mutex_lock(&cs43130->clk_mutex);
844 if (!cs43130->clk_req) {
845 /* no DAI is currently using clk */
846 if (!(CS43130_MCLK_22M % params_rate(params)))
847 required_clk = CS43130_MCLK_22M;
849 required_clk = CS43130_MCLK_24M;
851 cs43130_set_pll(component, 0, 0, cs43130->mclk, required_clk);
852 if (cs43130->pll_bypass)
853 cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
855 cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
859 if (cs43130->clk_req == 2)
860 cs43130_pcm_dsd_mix(true, cs43130->regmap);
861 mutex_unlock(&cs43130->clk_mutex);
864 case CS43130_ASP_DOP_DAI:
865 case CS43130_XSP_DOP_DAI:
866 /* DoP bitwidth is always 24-bit */
868 sclk = params_rate(params) * bitwidth_dai *
869 params_channels(params);
871 switch (params_rate(params)) {
879 dev_err(component->dev, "Rate(%u) not supported\n",
880 params_rate(params));
884 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
885 CS43130_DSD_SPEED_MASK,
886 dsd_speed << CS43130_DSD_SPEED_SHIFT);
888 case CS43130_ASP_PCM_DAI:
889 rate_map = cs43130_get_rate_table(params_rate(params));
893 regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
896 dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
901 case CS43130_ASP_DOP_DAI:
902 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
903 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_ASP <<
904 CS43130_DSD_SRC_SHIFT);
906 case CS43130_XSP_DOP_DAI:
907 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
908 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
909 CS43130_DSD_SRC_SHIFT);
913 if (!sclk && cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBM_CFM)
914 /* Calculate SCLK in master mode if unassigned */
915 sclk = params_rate(params) * bitwidth_dai *
916 params_channels(params);
919 /* at this point, SCLK must be set */
920 dev_err(component->dev, "SCLK freq is not set\n");
924 bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params);
925 if (bitwidth_sclk < bitwidth_dai) {
926 dev_err(component->dev, "Format not supported: SCLK freq is too low\n");
930 dev_dbg(component->dev,
931 "sclk = %u, fs = %d, bitwidth_dai = %u\n",
932 sclk, params_rate(params), bitwidth_dai);
934 dev_dbg(component->dev,
935 "bitwidth_sclk = %u, num_ch = %u\n",
936 bitwidth_sclk, params_channels(params));
938 cs43130_set_bitwidth(dai->id, bitwidth_dai, cs43130->regmap);
939 cs43130_set_sp_fmt(dai->id, bitwidth_sclk, params, cs43130);
944 static int cs43130_hw_free(struct snd_pcm_substream *substream,
945 struct snd_soc_dai *dai)
947 struct snd_soc_component *component = dai->component;
948 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
950 mutex_lock(&cs43130->clk_mutex);
952 if (!cs43130->clk_req) {
953 /* no DAI is currently using clk */
954 cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
955 cs43130_pcm_dsd_mix(false, cs43130->regmap);
957 mutex_unlock(&cs43130->clk_mutex);
962 static const DECLARE_TLV_DB_SCALE(pcm_vol_tlv, -12750, 50, 1);
964 static const char * const pcm_ch_text[] = {
971 static const struct reg_sequence pcm_ch_en_seq[] = {
972 {CS43130_DXD1, 0x99},
992 static const struct reg_sequence pcm_ch_dis_seq[] = {
993 {CS43130_DXD1, 0x99},
1013 static int cs43130_pcm_ch_get(struct snd_kcontrol *kcontrol,
1014 struct snd_ctl_elem_value *ucontrol)
1016 return snd_soc_get_enum_double(kcontrol, ucontrol);
1019 static int cs43130_pcm_ch_put(struct snd_kcontrol *kcontrol,
1020 struct snd_ctl_elem_value *ucontrol)
1022 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1023 unsigned int *item = ucontrol->value.enumerated.item;
1024 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1025 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1028 if (item[0] >= e->items)
1030 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
1032 switch (cs43130->dev_id) {
1033 case CS43131_CHIP_ID:
1034 case CS43198_CHIP_ID:
1036 regmap_multi_reg_write(cs43130->regmap, pcm_ch_en_seq,
1037 ARRAY_SIZE(pcm_ch_en_seq));
1039 regmap_multi_reg_write(cs43130->regmap, pcm_ch_dis_seq,
1040 ARRAY_SIZE(pcm_ch_dis_seq));
1044 return snd_soc_put_enum_double(kcontrol, ucontrol);
1047 static SOC_ENUM_SINGLE_DECL(pcm_ch_enum, CS43130_PCM_PATH_CTL_2, 0,
1050 static const char * const pcm_spd_texts[] = {
1055 static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
1058 static const char * const dsd_texts[] = {
1064 static const unsigned int dsd_values[] = {
1065 CS43130_DSD_SRC_DSD,
1066 CS43130_DSD_SRC_ASP,
1067 CS43130_DSD_SRC_XSP,
1070 static SOC_VALUE_ENUM_SINGLE_DECL(dsd_enum, CS43130_DSD_INT_CFG, 0, 0x03,
1071 dsd_texts, dsd_values);
1073 static const struct snd_kcontrol_new cs43130_snd_controls[] = {
1074 SOC_DOUBLE_R_TLV("Master Playback Volume",
1075 CS43130_PCM_VOL_A, CS43130_PCM_VOL_B, 0, 0xFF, 1,
1077 SOC_DOUBLE_R_TLV("Master DSD Playback Volume",
1078 CS43130_DSD_VOL_A, CS43130_DSD_VOL_B, 0, 0xFF, 1,
1080 SOC_ENUM_EXT("PCM Ch Select", pcm_ch_enum, cs43130_pcm_ch_get,
1081 cs43130_pcm_ch_put),
1082 SOC_ENUM("PCM Filter Speed", pcm_spd_enum),
1083 SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT, 6, 1, 0),
1084 SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT, 5, 1, 0),
1085 SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT, 1, 1, 0),
1086 SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT, 0, 1, 0),
1087 SOC_ENUM("DSD Phase Modulation", dsd_enum),
1090 static const struct reg_sequence pcm_seq[] = {
1091 {CS43130_DXD1, 0x99},
1092 {CS43130_DXD7, 0x01},
1094 {CS43130_DXD9, 0x01},
1095 {CS43130_DXD3, 0x12},
1097 {CS43130_DXD10, 0x28},
1098 {CS43130_DXD11, 0x28},
1102 static const struct reg_sequence dsd_seq[] = {
1103 {CS43130_DXD1, 0x99},
1104 {CS43130_DXD7, 0x01},
1106 {CS43130_DXD9, 0x01},
1107 {CS43130_DXD3, 0x12},
1109 {CS43130_DXD10, 0x1E},
1110 {CS43130_DXD11, 0x20},
1114 static const struct reg_sequence pop_free_seq[] = {
1115 {CS43130_DXD1, 0x99},
1116 {CS43130_DXD12, 0x0A},
1120 static const struct reg_sequence pop_free_seq2[] = {
1121 {CS43130_DXD1, 0x99},
1122 {CS43130_DXD13, 0x20},
1126 static const struct reg_sequence mute_seq[] = {
1127 {CS43130_DXD1, 0x99},
1128 {CS43130_DXD3, 0x12},
1129 {CS43130_DXD5, 0x02},
1130 {CS43130_DXD4, 0x12},
1134 static const struct reg_sequence unmute_seq[] = {
1135 {CS43130_DXD1, 0x99},
1136 {CS43130_DXD3, 0x10},
1138 {CS43130_DXD4, 0x16},
1142 static int cs43130_dsd_event(struct snd_soc_dapm_widget *w,
1143 struct snd_kcontrol *kcontrol, int event)
1145 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1146 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1149 case SND_SOC_DAPM_PRE_PMU:
1150 switch (cs43130->dev_id) {
1151 case CS43130_CHIP_ID:
1152 case CS4399_CHIP_ID:
1153 regmap_multi_reg_write(cs43130->regmap, dsd_seq,
1154 ARRAY_SIZE(dsd_seq));
1158 case SND_SOC_DAPM_POST_PMU:
1159 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_1,
1160 CS43130_MUTE_MASK, 0);
1161 switch (cs43130->dev_id) {
1162 case CS43130_CHIP_ID:
1163 case CS4399_CHIP_ID:
1164 regmap_multi_reg_write(cs43130->regmap, unmute_seq,
1165 ARRAY_SIZE(unmute_seq));
1169 case SND_SOC_DAPM_PRE_PMD:
1170 switch (cs43130->dev_id) {
1171 case CS43130_CHIP_ID:
1172 case CS4399_CHIP_ID:
1173 regmap_multi_reg_write(cs43130->regmap, mute_seq,
1174 ARRAY_SIZE(mute_seq));
1175 regmap_update_bits(cs43130->regmap,
1176 CS43130_DSD_PATH_CTL_1,
1177 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1179 * DSD Power Down Sequence
1180 * According to Design, 130ms is preferred.
1184 case CS43131_CHIP_ID:
1185 case CS43198_CHIP_ID:
1186 regmap_update_bits(cs43130->regmap,
1187 CS43130_DSD_PATH_CTL_1,
1188 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1193 dev_err(component->dev, "Invalid event = 0x%x\n", event);
1199 static int cs43130_pcm_event(struct snd_soc_dapm_widget *w,
1200 struct snd_kcontrol *kcontrol, int event)
1202 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1203 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1206 case SND_SOC_DAPM_PRE_PMU:
1207 switch (cs43130->dev_id) {
1208 case CS43130_CHIP_ID:
1209 case CS4399_CHIP_ID:
1210 regmap_multi_reg_write(cs43130->regmap, pcm_seq,
1211 ARRAY_SIZE(pcm_seq));
1215 case SND_SOC_DAPM_POST_PMU:
1216 regmap_update_bits(cs43130->regmap, CS43130_PCM_PATH_CTL_1,
1217 CS43130_MUTE_MASK, 0);
1218 switch (cs43130->dev_id) {
1219 case CS43130_CHIP_ID:
1220 case CS4399_CHIP_ID:
1221 regmap_multi_reg_write(cs43130->regmap, unmute_seq,
1222 ARRAY_SIZE(unmute_seq));
1226 case SND_SOC_DAPM_PRE_PMD:
1227 switch (cs43130->dev_id) {
1228 case CS43130_CHIP_ID:
1229 case CS4399_CHIP_ID:
1230 regmap_multi_reg_write(cs43130->regmap, mute_seq,
1231 ARRAY_SIZE(mute_seq));
1232 regmap_update_bits(cs43130->regmap,
1233 CS43130_PCM_PATH_CTL_1,
1234 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1236 * PCM Power Down Sequence
1237 * According to Design, 130ms is preferred.
1241 case CS43131_CHIP_ID:
1242 case CS43198_CHIP_ID:
1243 regmap_update_bits(cs43130->regmap,
1244 CS43130_PCM_PATH_CTL_1,
1245 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1250 dev_err(component->dev, "Invalid event = 0x%x\n", event);
1256 static const struct reg_sequence dac_postpmu_seq[] = {
1257 {CS43130_DXD9, 0x0C},
1258 {CS43130_DXD3, 0x10},
1259 {CS43130_DXD4, 0x20},
1262 static const struct reg_sequence dac_postpmd_seq[] = {
1263 {CS43130_DXD1, 0x99},
1264 {CS43130_DXD6, 0x01},
1268 static int cs43130_dac_event(struct snd_soc_dapm_widget *w,
1269 struct snd_kcontrol *kcontrol, int event)
1271 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1272 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1275 case SND_SOC_DAPM_PRE_PMU:
1276 switch (cs43130->dev_id) {
1277 case CS43130_CHIP_ID:
1278 case CS4399_CHIP_ID:
1279 regmap_multi_reg_write(cs43130->regmap, pop_free_seq,
1280 ARRAY_SIZE(pop_free_seq));
1282 case CS43131_CHIP_ID:
1283 case CS43198_CHIP_ID:
1284 regmap_multi_reg_write(cs43130->regmap, pop_free_seq2,
1285 ARRAY_SIZE(pop_free_seq2));
1289 case SND_SOC_DAPM_POST_PMU:
1290 usleep_range(10000, 10050);
1292 regmap_write(cs43130->regmap, CS43130_DXD1, 0x99);
1294 switch (cs43130->dev_id) {
1295 case CS43130_CHIP_ID:
1296 case CS4399_CHIP_ID:
1297 regmap_multi_reg_write(cs43130->regmap, dac_postpmu_seq,
1298 ARRAY_SIZE(dac_postpmu_seq));
1300 * Per datasheet, Sec. PCM Power-Up Sequence.
1301 * According to Design, CS43130_DXD12 must be 0 to meet
1302 * THDN and Dynamic Range spec.
1305 regmap_write(cs43130->regmap, CS43130_DXD12, 0);
1307 case CS43131_CHIP_ID:
1308 case CS43198_CHIP_ID:
1309 usleep_range(12000, 12010);
1310 regmap_write(cs43130->regmap, CS43130_DXD13, 0);
1314 regmap_write(cs43130->regmap, CS43130_DXD1, 0);
1316 case SND_SOC_DAPM_POST_PMD:
1317 switch (cs43130->dev_id) {
1318 case CS43130_CHIP_ID:
1319 case CS4399_CHIP_ID:
1320 regmap_multi_reg_write(cs43130->regmap, dac_postpmd_seq,
1321 ARRAY_SIZE(dac_postpmd_seq));
1326 dev_err(component->dev, "Invalid DAC event = 0x%x\n", event);
1332 static const struct reg_sequence hpin_prepmd_seq[] = {
1333 {CS43130_DXD1, 0x99},
1334 {CS43130_DXD15, 0x64},
1340 static const struct reg_sequence hpin_postpmu_seq[] = {
1341 {CS43130_DXD1, 0x99},
1343 {CS43130_DXD14, 0xDC},
1344 {CS43130_DXD15, 0xE4},
1348 static int cs43130_hpin_event(struct snd_soc_dapm_widget *w,
1349 struct snd_kcontrol *kcontrol, int event)
1351 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1352 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1355 case SND_SOC_DAPM_POST_PMD:
1356 regmap_multi_reg_write(cs43130->regmap, hpin_prepmd_seq,
1357 ARRAY_SIZE(hpin_prepmd_seq));
1359 case SND_SOC_DAPM_PRE_PMU:
1360 regmap_multi_reg_write(cs43130->regmap, hpin_postpmu_seq,
1361 ARRAY_SIZE(hpin_postpmu_seq));
1364 dev_err(component->dev, "Invalid HPIN event = 0x%x\n", event);
1370 static const struct snd_soc_dapm_widget digital_hp_widgets[] = {
1371 SND_SOC_DAPM_OUTPUT("HPOUTA"),
1372 SND_SOC_DAPM_OUTPUT("HPOUTB"),
1374 SND_SOC_DAPM_AIF_IN_E("ASPIN PCM", NULL, 0, CS43130_PWDN_CTL,
1375 CS43130_PDN_ASP_SHIFT, 1, cs43130_pcm_event,
1376 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1377 SND_SOC_DAPM_PRE_PMD)),
1379 SND_SOC_DAPM_AIF_IN_E("ASPIN DoP", NULL, 0, CS43130_PWDN_CTL,
1380 CS43130_PDN_ASP_SHIFT, 1, cs43130_dsd_event,
1381 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1382 SND_SOC_DAPM_PRE_PMD)),
1384 SND_SOC_DAPM_AIF_IN_E("XSPIN DoP", NULL, 0, CS43130_PWDN_CTL,
1385 CS43130_PDN_XSP_SHIFT, 1, cs43130_dsd_event,
1386 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1387 SND_SOC_DAPM_PRE_PMD)),
1389 SND_SOC_DAPM_AIF_IN_E("XSPIN DSD", NULL, 0, CS43130_PWDN_CTL,
1390 CS43130_PDN_DSDIF_SHIFT, 1, cs43130_dsd_event,
1391 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1392 SND_SOC_DAPM_PRE_PMD)),
1394 SND_SOC_DAPM_DAC("DSD", NULL, CS43130_DSD_PATH_CTL_2,
1395 CS43130_DSD_EN_SHIFT, 0),
1397 SND_SOC_DAPM_DAC_E("HiFi DAC", NULL, CS43130_PWDN_CTL,
1398 CS43130_PDN_HP_SHIFT, 1, cs43130_dac_event,
1399 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1400 SND_SOC_DAPM_POST_PMD)),
1403 static const struct snd_soc_dapm_widget analog_hp_widgets[] = {
1404 SND_SOC_DAPM_DAC_E("Analog Playback", NULL, CS43130_HP_OUT_CTL_1,
1405 CS43130_HP_IN_EN_SHIFT, 0, cs43130_hpin_event,
1406 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)),
1409 static struct snd_soc_dapm_widget all_hp_widgets[
1410 ARRAY_SIZE(digital_hp_widgets) +
1411 ARRAY_SIZE(analog_hp_widgets)];
1413 static const struct snd_soc_dapm_route digital_hp_routes[] = {
1414 {"ASPIN PCM", NULL, "ASP PCM Playback"},
1415 {"ASPIN DoP", NULL, "ASP DoP Playback"},
1416 {"XSPIN DoP", NULL, "XSP DoP Playback"},
1417 {"XSPIN DSD", NULL, "XSP DSD Playback"},
1418 {"DSD", NULL, "ASPIN DoP"},
1419 {"DSD", NULL, "XSPIN DoP"},
1420 {"DSD", NULL, "XSPIN DSD"},
1421 {"HiFi DAC", NULL, "ASPIN PCM"},
1422 {"HiFi DAC", NULL, "DSD"},
1423 {"HPOUTA", NULL, "HiFi DAC"},
1424 {"HPOUTB", NULL, "HiFi DAC"},
1427 static const struct snd_soc_dapm_route analog_hp_routes[] = {
1428 {"HPOUTA", NULL, "Analog Playback"},
1429 {"HPOUTB", NULL, "Analog Playback"},
1432 static struct snd_soc_dapm_route all_hp_routes[
1433 ARRAY_SIZE(digital_hp_routes) +
1434 ARRAY_SIZE(analog_hp_routes)];
1436 static const unsigned int cs43130_asp_src_rates[] = {
1437 32000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
1440 static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints = {
1441 .count = ARRAY_SIZE(cs43130_asp_src_rates),
1442 .list = cs43130_asp_src_rates,
1445 static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
1446 struct snd_soc_dai *dai)
1448 return snd_pcm_hw_constraint_list(substream->runtime, 0,
1449 SNDRV_PCM_HW_PARAM_RATE,
1450 &cs43130_asp_constraints);
1453 static const unsigned int cs43130_dop_src_rates[] = {
1457 static const struct snd_pcm_hw_constraint_list cs43130_dop_constraints = {
1458 .count = ARRAY_SIZE(cs43130_dop_src_rates),
1459 .list = cs43130_dop_src_rates,
1462 static int cs43130_dop_startup(struct snd_pcm_substream *substream,
1463 struct snd_soc_dai *dai)
1465 return snd_pcm_hw_constraint_list(substream->runtime, 0,
1466 SNDRV_PCM_HW_PARAM_RATE,
1467 &cs43130_dop_constraints);
1470 static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1472 struct snd_soc_component *component = codec_dai->component;
1473 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1475 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1476 case SND_SOC_DAIFMT_CBS_CFS:
1477 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
1479 case SND_SOC_DAIFMT_CBM_CFM:
1480 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
1483 dev_err(component->dev, "unsupported mode\n");
1487 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1488 case SND_SOC_DAIFMT_I2S:
1489 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_I2S;
1491 case SND_SOC_DAIFMT_LEFT_J:
1492 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
1494 case SND_SOC_DAIFMT_DSP_A:
1495 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_DSP_A;
1497 case SND_SOC_DAIFMT_DSP_B:
1498 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_DSP_B;
1501 dev_err(component->dev,
1502 "unsupported audio format\n");
1506 dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
1508 cs43130->dais[codec_dai->id].dai_mode,
1509 cs43130->dais[codec_dai->id].dai_format);
1514 static int cs43130_dsd_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1516 struct snd_soc_component *component = codec_dai->component;
1517 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1519 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1520 case SND_SOC_DAIFMT_CBS_CFS:
1521 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
1523 case SND_SOC_DAIFMT_CBM_CFM:
1524 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
1527 dev_err(component->dev, "Unsupported DAI format.\n");
1531 dev_dbg(component->dev, "dai_mode = 0x%x\n",
1532 cs43130->dais[codec_dai->id].dai_mode);
1537 static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
1538 int clk_id, unsigned int freq, int dir)
1540 struct snd_soc_component *component = codec_dai->component;
1541 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1543 cs43130->dais[codec_dai->id].sclk = freq;
1544 dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id,
1545 cs43130->dais[codec_dai->id].sclk);
1550 static const struct snd_soc_dai_ops cs43130_pcm_ops = {
1551 .startup = cs43130_pcm_startup,
1552 .hw_params = cs43130_hw_params,
1553 .hw_free = cs43130_hw_free,
1554 .set_sysclk = cs43130_set_sysclk,
1555 .set_fmt = cs43130_pcm_set_fmt,
1558 static const struct snd_soc_dai_ops cs43130_dop_ops = {
1559 .startup = cs43130_dop_startup,
1560 .hw_params = cs43130_hw_params,
1561 .hw_free = cs43130_hw_free,
1562 .set_sysclk = cs43130_set_sysclk,
1563 .set_fmt = cs43130_pcm_set_fmt,
1566 static const struct snd_soc_dai_ops cs43130_dsd_ops = {
1567 .startup = cs43130_dop_startup,
1568 .hw_params = cs43130_dsd_hw_params,
1569 .hw_free = cs43130_hw_free,
1570 .set_fmt = cs43130_dsd_set_fmt,
1573 static struct snd_soc_dai_driver cs43130_dai[] = {
1575 .name = "cs43130-asp-pcm",
1576 .id = CS43130_ASP_PCM_DAI,
1578 .stream_name = "ASP PCM Playback",
1581 .rates = SNDRV_PCM_RATE_KNOT,
1582 .formats = CS43130_PCM_FORMATS,
1584 .ops = &cs43130_pcm_ops,
1585 .symmetric_rate = 1,
1588 .name = "cs43130-asp-dop",
1589 .id = CS43130_ASP_DOP_DAI,
1591 .stream_name = "ASP DoP Playback",
1594 .rates = SNDRV_PCM_RATE_KNOT,
1595 .formats = CS43130_DOP_FORMATS,
1597 .ops = &cs43130_dop_ops,
1598 .symmetric_rate = 1,
1601 .name = "cs43130-xsp-dop",
1602 .id = CS43130_XSP_DOP_DAI,
1604 .stream_name = "XSP DoP Playback",
1607 .rates = SNDRV_PCM_RATE_KNOT,
1608 .formats = CS43130_DOP_FORMATS,
1610 .ops = &cs43130_dop_ops,
1611 .symmetric_rate = 1,
1614 .name = "cs43130-xsp-dsd",
1615 .id = CS43130_XSP_DSD_DAI,
1617 .stream_name = "XSP DSD Playback",
1620 .rates = SNDRV_PCM_RATE_KNOT,
1621 .formats = CS43130_DOP_FORMATS,
1623 .ops = &cs43130_dsd_ops,
1628 static int cs43130_component_set_sysclk(struct snd_soc_component *component,
1629 int clk_id, int source, unsigned int freq,
1632 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1634 dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
1635 clk_id, source, freq, dir);
1638 case CS43130_MCLK_22M:
1639 case CS43130_MCLK_24M:
1640 cs43130->mclk = freq;
1643 dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
1647 if (source == CS43130_MCLK_SRC_EXT) {
1648 cs43130->pll_bypass = true;
1650 dev_err(component->dev, "Invalid MCLK source\n");
1657 static inline u16 cs43130_get_ac_reg_val(u16 ac_freq)
1659 /* AC freq is counted in 5.94Hz step. */
1663 static int cs43130_show_dc(struct device *dev, char *buf, u8 ch)
1665 struct i2c_client *client = to_i2c_client(dev);
1666 struct cs43130_private *cs43130 = i2c_get_clientdata(client);
1668 if (!cs43130->hpload_done)
1669 return sysfs_emit(buf, "NO_HPLOAD\n");
1671 return sysfs_emit(buf, "%u\n", cs43130->hpload_dc[ch]);
1674 static ssize_t hpload_dc_l_show(struct device *dev,
1675 struct device_attribute *attr, char *buf)
1677 return cs43130_show_dc(dev, buf, HP_LEFT);
1680 static ssize_t hpload_dc_r_show(struct device *dev,
1681 struct device_attribute *attr, char *buf)
1683 return cs43130_show_dc(dev, buf, HP_RIGHT);
1686 static const u16 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 = sysfs_emit_at(buf, j, "%u\n",
1708 cs43130->hpload_ac[i][ch]);
1717 return sysfs_emit(buf, "NO_HPLOAD\n");
1721 static ssize_t hpload_ac_l_show(struct device *dev,
1722 struct device_attribute *attr, char *buf)
1724 return cs43130_show_ac(dev, buf, HP_LEFT);
1727 static ssize_t hpload_ac_r_show(struct device *dev,
1728 struct device_attribute *attr, char *buf)
1730 return cs43130_show_ac(dev, buf, HP_RIGHT);
1733 static DEVICE_ATTR_RO(hpload_dc_l);
1734 static DEVICE_ATTR_RO(hpload_dc_r);
1735 static DEVICE_ATTR_RO(hpload_ac_l);
1736 static DEVICE_ATTR_RO(hpload_ac_r);
1738 static struct attribute *hpload_attrs[] = {
1739 &dev_attr_hpload_dc_l.attr,
1740 &dev_attr_hpload_dc_r.attr,
1741 &dev_attr_hpload_ac_l.attr,
1742 &dev_attr_hpload_ac_r.attr,
1744 ATTRIBUTE_GROUPS(hpload);
1746 static struct reg_sequence hp_en_cal_seq[] = {
1747 {CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
1748 {CS43130_HP_MEAS_LOAD_1, 0},
1749 {CS43130_HP_MEAS_LOAD_2, 0},
1750 {CS43130_INT_MASK_4, 0},
1751 {CS43130_DXD1, 0x99},
1752 {CS43130_DXD16, 0xBB},
1753 {CS43130_DXD12, 0x01},
1754 {CS43130_DXD19, 0xCB},
1755 {CS43130_DXD17, 0x95},
1756 {CS43130_DXD18, 0x0B},
1758 {CS43130_HP_LOAD_1, 0x80},
1761 static struct reg_sequence hp_en_cal_seq2[] = {
1762 {CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
1763 {CS43130_HP_MEAS_LOAD_1, 0},
1764 {CS43130_HP_MEAS_LOAD_2, 0},
1765 {CS43130_INT_MASK_4, 0},
1766 {CS43130_HP_LOAD_1, 0x80},
1769 static struct reg_sequence hp_dis_cal_seq[] = {
1770 {CS43130_HP_LOAD_1, 0x80},
1771 {CS43130_DXD1, 0x99},
1774 {CS43130_HP_LOAD_1, 0},
1777 static struct reg_sequence hp_dis_cal_seq2[] = {
1778 {CS43130_HP_LOAD_1, 0x80},
1779 {CS43130_HP_LOAD_1, 0},
1782 static struct reg_sequence hp_dc_ch_l_seq[] = {
1783 {CS43130_DXD1, 0x99},
1784 {CS43130_DXD19, 0x0A},
1785 {CS43130_DXD17, 0x93},
1786 {CS43130_DXD18, 0x0A},
1788 {CS43130_HP_LOAD_1, 0x80},
1789 {CS43130_HP_LOAD_1, 0x81},
1792 static struct reg_sequence hp_dc_ch_l_seq2[] = {
1793 {CS43130_HP_LOAD_1, 0x80},
1794 {CS43130_HP_LOAD_1, 0x81},
1797 static struct reg_sequence hp_dc_ch_r_seq[] = {
1798 {CS43130_DXD1, 0x99},
1799 {CS43130_DXD19, 0x8A},
1800 {CS43130_DXD17, 0x15},
1801 {CS43130_DXD18, 0x06},
1803 {CS43130_HP_LOAD_1, 0x90},
1804 {CS43130_HP_LOAD_1, 0x91},
1807 static struct reg_sequence hp_dc_ch_r_seq2[] = {
1808 {CS43130_HP_LOAD_1, 0x90},
1809 {CS43130_HP_LOAD_1, 0x91},
1812 static struct reg_sequence hp_ac_ch_l_seq[] = {
1813 {CS43130_DXD1, 0x99},
1814 {CS43130_DXD19, 0x0A},
1815 {CS43130_DXD17, 0x93},
1816 {CS43130_DXD18, 0x0A},
1818 {CS43130_HP_LOAD_1, 0x80},
1819 {CS43130_HP_LOAD_1, 0x82},
1822 static struct reg_sequence hp_ac_ch_l_seq2[] = {
1823 {CS43130_HP_LOAD_1, 0x80},
1824 {CS43130_HP_LOAD_1, 0x82},
1827 static struct reg_sequence hp_ac_ch_r_seq[] = {
1828 {CS43130_DXD1, 0x99},
1829 {CS43130_DXD19, 0x8A},
1830 {CS43130_DXD17, 0x15},
1831 {CS43130_DXD18, 0x06},
1833 {CS43130_HP_LOAD_1, 0x90},
1834 {CS43130_HP_LOAD_1, 0x92},
1837 static struct reg_sequence hp_ac_ch_r_seq2[] = {
1838 {CS43130_HP_LOAD_1, 0x90},
1839 {CS43130_HP_LOAD_1, 0x92},
1842 static struct reg_sequence hp_cln_seq[] = {
1843 {CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
1844 {CS43130_HP_MEAS_LOAD_1, 0},
1845 {CS43130_HP_MEAS_LOAD_2, 0},
1848 struct reg_sequences {
1849 struct reg_sequence *seq;
1854 static struct reg_sequences hpload_seq1[] = {
1856 .seq = hp_en_cal_seq,
1857 .size = ARRAY_SIZE(hp_en_cal_seq),
1858 .msk = CS43130_HPLOAD_ON_INT,
1861 .seq = hp_dc_ch_l_seq,
1862 .size = ARRAY_SIZE(hp_dc_ch_l_seq),
1863 .msk = CS43130_HPLOAD_DC_INT,
1866 .seq = hp_ac_ch_l_seq,
1867 .size = ARRAY_SIZE(hp_ac_ch_l_seq),
1868 .msk = CS43130_HPLOAD_AC_INT,
1871 .seq = hp_dis_cal_seq,
1872 .size = ARRAY_SIZE(hp_dis_cal_seq),
1873 .msk = CS43130_HPLOAD_OFF_INT,
1876 .seq = hp_en_cal_seq,
1877 .size = ARRAY_SIZE(hp_en_cal_seq),
1878 .msk = CS43130_HPLOAD_ON_INT,
1881 .seq = hp_dc_ch_r_seq,
1882 .size = ARRAY_SIZE(hp_dc_ch_r_seq),
1883 .msk = CS43130_HPLOAD_DC_INT,
1886 .seq = hp_ac_ch_r_seq,
1887 .size = ARRAY_SIZE(hp_ac_ch_r_seq),
1888 .msk = CS43130_HPLOAD_AC_INT,
1892 static struct reg_sequences hpload_seq2[] = {
1894 .seq = hp_en_cal_seq2,
1895 .size = ARRAY_SIZE(hp_en_cal_seq2),
1896 .msk = CS43130_HPLOAD_ON_INT,
1899 .seq = hp_dc_ch_l_seq2,
1900 .size = ARRAY_SIZE(hp_dc_ch_l_seq2),
1901 .msk = CS43130_HPLOAD_DC_INT,
1904 .seq = hp_ac_ch_l_seq2,
1905 .size = ARRAY_SIZE(hp_ac_ch_l_seq2),
1906 .msk = CS43130_HPLOAD_AC_INT,
1909 .seq = hp_dis_cal_seq2,
1910 .size = ARRAY_SIZE(hp_dis_cal_seq2),
1911 .msk = CS43130_HPLOAD_OFF_INT,
1914 .seq = hp_en_cal_seq2,
1915 .size = ARRAY_SIZE(hp_en_cal_seq2),
1916 .msk = CS43130_HPLOAD_ON_INT,
1919 .seq = hp_dc_ch_r_seq2,
1920 .size = ARRAY_SIZE(hp_dc_ch_r_seq2),
1921 .msk = CS43130_HPLOAD_DC_INT,
1924 .seq = hp_ac_ch_r_seq2,
1925 .size = ARRAY_SIZE(hp_ac_ch_r_seq2),
1926 .msk = CS43130_HPLOAD_AC_INT,
1930 static int cs43130_update_hpload(unsigned int msk, int ac_idx,
1931 struct cs43130_private *cs43130)
1933 bool left_ch = true;
1937 struct snd_soc_component *component = cs43130->component;
1940 case CS43130_HPLOAD_DC_INT:
1941 case CS43130_HPLOAD_AC_INT:
1947 regmap_read(cs43130->regmap, CS43130_HP_LOAD_1, ®);
1948 if (reg & CS43130_HPLOAD_CHN_SEL)
1951 if (msk == CS43130_HPLOAD_DC_INT)
1952 addr = CS43130_HP_DC_STAT_1;
1954 addr = CS43130_HP_AC_STAT_1;
1956 regmap_read(cs43130->regmap, addr, ®);
1957 impedance = reg >> 3;
1958 regmap_read(cs43130->regmap, addr + 1, ®);
1959 impedance |= reg << 5;
1961 if (msk == CS43130_HPLOAD_DC_INT) {
1963 cs43130->hpload_dc[HP_LEFT] = impedance;
1965 cs43130->hpload_dc[HP_RIGHT] = impedance;
1967 dev_dbg(component->dev, "HP DC impedance (Ch %u): %u\n", !left_ch,
1971 cs43130->hpload_ac[ac_idx][HP_LEFT] = impedance;
1973 cs43130->hpload_ac[ac_idx][HP_RIGHT] = impedance;
1975 dev_dbg(component->dev, "HP AC (%u Hz) impedance (Ch %u): %u\n",
1976 cs43130->ac_freq[ac_idx], !left_ch, impedance);
1982 static int cs43130_hpload_proc(struct cs43130_private *cs43130,
1983 struct reg_sequence *seq, int seq_size,
1984 unsigned int rslt_msk, int ac_idx)
1989 struct snd_soc_component *component = cs43130->component;
1991 reinit_completion(&cs43130->hpload_evt);
1993 if (rslt_msk == CS43130_HPLOAD_AC_INT) {
1994 ac_reg_val = cs43130_get_ac_reg_val(cs43130->ac_freq[ac_idx]);
1995 regmap_update_bits(cs43130->regmap, CS43130_HP_LOAD_1,
1996 CS43130_HPLOAD_AC_START, 0);
1997 regmap_update_bits(cs43130->regmap, CS43130_HP_MEAS_LOAD_1,
1998 CS43130_HP_MEAS_LOAD_MASK,
1999 ac_reg_val >> CS43130_HP_MEAS_LOAD_1_SHIFT);
2000 regmap_update_bits(cs43130->regmap, CS43130_HP_MEAS_LOAD_2,
2001 CS43130_HP_MEAS_LOAD_MASK,
2002 ac_reg_val >> CS43130_HP_MEAS_LOAD_2_SHIFT);
2005 regmap_multi_reg_write(cs43130->regmap, seq,
2008 ret = wait_for_completion_timeout(&cs43130->hpload_evt,
2009 msecs_to_jiffies(1000));
2010 regmap_read(cs43130->regmap, CS43130_INT_MASK_4, &msk);
2012 dev_err(component->dev, "Timeout waiting for HPLOAD interrupt\n");
2016 dev_dbg(component->dev, "HP load stat: %x, INT_MASK_4: %x\n",
2017 cs43130->hpload_stat, msk);
2018 if ((cs43130->hpload_stat & (CS43130_HPLOAD_NO_DC_INT |
2019 CS43130_HPLOAD_UNPLUG_INT |
2020 CS43130_HPLOAD_OOR_INT)) ||
2021 !(cs43130->hpload_stat & rslt_msk)) {
2022 dev_dbg(component->dev, "HP load measure failed\n");
2029 static const struct reg_sequence hv_seq[][2] = {
2031 {CS43130_CLASS_H_CTL, 0x1C},
2032 {CS43130_HP_OUT_CTL_1, 0x10},
2035 {CS43130_CLASS_H_CTL, 0x1E},
2036 {CS43130_HP_OUT_CTL_1, 0x20},
2039 {CS43130_CLASS_H_CTL, 0x1E},
2040 {CS43130_HP_OUT_CTL_1, 0x30},
2044 static int cs43130_set_hv(struct regmap *regmap, u16 hpload_dc,
2045 const u16 *dc_threshold)
2049 for (i = 0; i < CS43130_DC_THRESHOLD; i++) {
2050 if (hpload_dc <= dc_threshold[i])
2054 regmap_multi_reg_write(regmap, hv_seq[i], ARRAY_SIZE(hv_seq[i]));
2059 static void cs43130_imp_meas(struct work_struct *wk)
2061 unsigned int reg, seq_size;
2063 struct cs43130_private *cs43130;
2064 struct snd_soc_component *component;
2065 struct reg_sequences *hpload_seq;
2067 cs43130 = container_of(wk, struct cs43130_private, work);
2068 component = cs43130->component;
2073 cs43130->hpload_done = false;
2075 mutex_lock(&cs43130->clk_mutex);
2076 if (!cs43130->clk_req) {
2077 /* clk not in use */
2078 cs43130_set_pll(component, 0, 0, cs43130->mclk, CS43130_MCLK_22M);
2079 if (cs43130->pll_bypass)
2080 cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
2082 cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
2086 mutex_unlock(&cs43130->clk_mutex);
2088 regmap_read(cs43130->regmap, CS43130_INT_STATUS_4, ®);
2090 switch (cs43130->dev_id) {
2091 case CS43130_CHIP_ID:
2092 hpload_seq = hpload_seq1;
2093 seq_size = ARRAY_SIZE(hpload_seq1);
2095 case CS43131_CHIP_ID:
2096 hpload_seq = hpload_seq2;
2097 seq_size = ARRAY_SIZE(hpload_seq2);
2100 WARN(1, "Invalid dev_id for meas: %d", cs43130->dev_id);
2106 while (i < seq_size) {
2107 ret = cs43130_hpload_proc(cs43130, hpload_seq[i].seq,
2109 hpload_seq[i].msk, ac_idx);
2113 cs43130_update_hpload(hpload_seq[i].msk, ac_idx, cs43130);
2115 if (cs43130->ac_meas &&
2116 hpload_seq[i].msk == CS43130_HPLOAD_AC_INT &&
2117 ac_idx < CS43130_AC_FREQ - 1) {
2124 cs43130->hpload_done = true;
2126 if (cs43130->hpload_dc[HP_LEFT] >= CS43130_LINEOUT_LOAD)
2127 snd_soc_jack_report(&cs43130->jack, CS43130_JACK_LINEOUT,
2130 snd_soc_jack_report(&cs43130->jack, CS43130_JACK_HEADPHONE,
2133 dev_dbg(component->dev, "Set HP output control. DC threshold\n");
2134 for (i = 0; i < CS43130_DC_THRESHOLD; i++)
2135 dev_dbg(component->dev, "DC threshold[%d]: %u.\n", i,
2136 cs43130->dc_threshold[i]);
2138 cs43130_set_hv(cs43130->regmap, cs43130->hpload_dc[HP_LEFT],
2139 cs43130->dc_threshold);
2142 switch (cs43130->dev_id) {
2143 case CS43130_CHIP_ID:
2144 cs43130_hpload_proc(cs43130, hp_dis_cal_seq,
2145 ARRAY_SIZE(hp_dis_cal_seq),
2146 CS43130_HPLOAD_OFF_INT, ac_idx);
2148 case CS43131_CHIP_ID:
2149 cs43130_hpload_proc(cs43130, hp_dis_cal_seq2,
2150 ARRAY_SIZE(hp_dis_cal_seq2),
2151 CS43130_HPLOAD_OFF_INT, ac_idx);
2155 regmap_multi_reg_write(cs43130->regmap, hp_cln_seq,
2156 ARRAY_SIZE(hp_cln_seq));
2158 mutex_lock(&cs43130->clk_mutex);
2160 /* clk not in use */
2161 if (!cs43130->clk_req)
2162 cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
2163 mutex_unlock(&cs43130->clk_mutex);
2166 static irqreturn_t cs43130_irq_thread(int irq, void *data)
2168 struct cs43130_private *cs43130 = (struct cs43130_private *)data;
2169 struct snd_soc_component *component = cs43130->component;
2170 unsigned int stickies[CS43130_NUM_INT];
2171 unsigned int irq_occurrence = 0;
2172 unsigned int masks[CS43130_NUM_INT];
2175 for (i = 0; i < ARRAY_SIZE(stickies); i++) {
2176 regmap_read(cs43130->regmap, CS43130_INT_STATUS_1 + i,
2178 regmap_read(cs43130->regmap, CS43130_INT_MASK_1 + i,
2182 for (i = 0; i < ARRAY_SIZE(stickies); i++) {
2183 stickies[i] = stickies[i] & (~masks[i]);
2184 for (j = 0; j < 8; j++)
2185 irq_occurrence += (stickies[i] >> j) & 1;
2187 dev_dbg(component->dev, "number of interrupts occurred (%u)\n",
2190 if (!irq_occurrence)
2193 if (stickies[0] & CS43130_XTAL_RDY_INT) {
2194 complete(&cs43130->xtal_rdy);
2198 if (stickies[0] & CS43130_PLL_RDY_INT) {
2199 complete(&cs43130->pll_rdy);
2203 if (stickies[3] & CS43130_HPLOAD_NO_DC_INT) {
2204 cs43130->hpload_stat = stickies[3];
2205 dev_err(component->dev,
2206 "DC load has not completed before AC load (%x)\n",
2207 cs43130->hpload_stat);
2208 complete(&cs43130->hpload_evt);
2212 if (stickies[3] & CS43130_HPLOAD_UNPLUG_INT) {
2213 cs43130->hpload_stat = stickies[3];
2214 dev_err(component->dev, "HP unplugged during measurement (%x)\n",
2215 cs43130->hpload_stat);
2216 complete(&cs43130->hpload_evt);
2220 if (stickies[3] & CS43130_HPLOAD_OOR_INT) {
2221 cs43130->hpload_stat = stickies[3];
2222 dev_err(component->dev, "HP load out of range (%x)\n",
2223 cs43130->hpload_stat);
2224 complete(&cs43130->hpload_evt);
2228 if (stickies[3] & CS43130_HPLOAD_AC_INT) {
2229 cs43130->hpload_stat = stickies[3];
2230 dev_dbg(component->dev, "HP AC load measurement done (%x)\n",
2231 cs43130->hpload_stat);
2232 complete(&cs43130->hpload_evt);
2236 if (stickies[3] & CS43130_HPLOAD_DC_INT) {
2237 cs43130->hpload_stat = stickies[3];
2238 dev_dbg(component->dev, "HP DC load measurement done (%x)\n",
2239 cs43130->hpload_stat);
2240 complete(&cs43130->hpload_evt);
2244 if (stickies[3] & CS43130_HPLOAD_ON_INT) {
2245 cs43130->hpload_stat = stickies[3];
2246 dev_dbg(component->dev, "HP load state machine on done (%x)\n",
2247 cs43130->hpload_stat);
2248 complete(&cs43130->hpload_evt);
2252 if (stickies[3] & CS43130_HPLOAD_OFF_INT) {
2253 cs43130->hpload_stat = stickies[3];
2254 dev_dbg(component->dev, "HP load state machine off done (%x)\n",
2255 cs43130->hpload_stat);
2256 complete(&cs43130->hpload_evt);
2260 if (stickies[0] & CS43130_XTAL_ERR_INT) {
2261 dev_err(component->dev, "Crystal err: clock is not running\n");
2265 if (stickies[0] & CS43130_HP_UNPLUG_INT) {
2266 dev_dbg(component->dev, "HP unplugged\n");
2267 cs43130->hpload_done = false;
2268 snd_soc_jack_report(&cs43130->jack, 0, CS43130_JACK_MASK);
2272 if (stickies[0] & CS43130_HP_PLUG_INT) {
2273 if (cs43130->dc_meas && !cs43130->hpload_done &&
2274 !work_busy(&cs43130->work)) {
2275 dev_dbg(component->dev, "HP load queue work\n");
2276 queue_work(cs43130->wq, &cs43130->work);
2279 snd_soc_jack_report(&cs43130->jack, SND_JACK_MECHANICAL,
2287 static int cs43130_probe(struct snd_soc_component *component)
2290 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
2291 struct snd_soc_card *card = component->card;
2294 cs43130->component = component;
2296 if (cs43130->xtal_ibias != CS43130_XTAL_UNUSED) {
2297 regmap_update_bits(cs43130->regmap, CS43130_CRYSTAL_SET,
2298 CS43130_XTAL_IBIAS_MASK,
2299 cs43130->xtal_ibias);
2300 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2301 CS43130_XTAL_ERR_INT, 0);
2304 ret = snd_soc_card_jack_new(card, "Headphone", CS43130_JACK_MASK,
2307 dev_err(component->dev, "Cannot create jack\n");
2311 cs43130->hpload_done = false;
2312 if (cs43130->dc_meas) {
2313 ret = sysfs_create_groups(&component->dev->kobj, hpload_groups);
2317 cs43130->wq = create_singlethread_workqueue("cs43130_hp");
2319 sysfs_remove_groups(&component->dev->kobj, hpload_groups);
2322 INIT_WORK(&cs43130->work, cs43130_imp_meas);
2325 regmap_read(cs43130->regmap, CS43130_INT_STATUS_1, ®);
2326 regmap_read(cs43130->regmap, CS43130_HP_STATUS, ®);
2327 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2328 CS43130_HP_PLUG_INT | CS43130_HP_UNPLUG_INT, 0);
2329 regmap_update_bits(cs43130->regmap, CS43130_HP_DETECT,
2330 CS43130_HP_DETECT_CTRL_MASK, 0);
2331 regmap_update_bits(cs43130->regmap, CS43130_HP_DETECT,
2332 CS43130_HP_DETECT_CTRL_MASK,
2333 CS43130_HP_DETECT_CTRL_MASK);
2338 static struct snd_soc_component_driver soc_component_dev_cs43130 = {
2339 .probe = cs43130_probe,
2340 .controls = cs43130_snd_controls,
2341 .num_controls = ARRAY_SIZE(cs43130_snd_controls),
2342 .set_sysclk = cs43130_component_set_sysclk,
2343 .set_pll = cs43130_set_pll,
2345 .use_pmdown_time = 1,
2349 static const struct regmap_config cs43130_regmap = {
2354 .max_register = CS43130_LASTREG,
2355 .reg_defaults = cs43130_reg_defaults,
2356 .num_reg_defaults = ARRAY_SIZE(cs43130_reg_defaults),
2357 .readable_reg = cs43130_readable_register,
2358 .precious_reg = cs43130_precious_register,
2359 .volatile_reg = cs43130_volatile_register,
2360 .cache_type = REGCACHE_MAPLE,
2361 /* needed for regcache_sync */
2362 .use_single_read = true,
2363 .use_single_write = true,
2366 static const u16 cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
2371 static int cs43130_handle_device_data(struct i2c_client *i2c_client,
2372 struct cs43130_private *cs43130)
2374 struct device_node *np = i2c_client->dev.of_node;
2378 if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) {
2379 /* Crystal is unused. System clock is used for external MCLK */
2380 cs43130->xtal_ibias = CS43130_XTAL_UNUSED;
2386 cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
2389 cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
2392 cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
2395 dev_err(&i2c_client->dev,
2396 "Invalid cirrus,xtal-ibias value: %d\n", val);
2400 cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
2401 cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
2403 if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq,
2404 CS43130_AC_FREQ) < 0) {
2405 for (i = 0; i < CS43130_AC_FREQ; i++)
2406 cs43130->ac_freq[i] = cs43130_ac_freq[i];
2409 if (of_property_read_u16_array(np, "cirrus,dc-threshold",
2410 cs43130->dc_threshold,
2411 CS43130_DC_THRESHOLD) < 0) {
2412 for (i = 0; i < CS43130_DC_THRESHOLD; i++)
2413 cs43130->dc_threshold[i] = cs43130_dc_threshold[i];
2419 static int cs43130_i2c_probe(struct i2c_client *client)
2421 struct cs43130_private *cs43130;
2426 cs43130 = devm_kzalloc(&client->dev, sizeof(*cs43130), GFP_KERNEL);
2430 i2c_set_clientdata(client, cs43130);
2432 cs43130->regmap = devm_regmap_init_i2c(client, &cs43130_regmap);
2433 if (IS_ERR(cs43130->regmap)) {
2434 ret = PTR_ERR(cs43130->regmap);
2438 if (client->dev.of_node) {
2439 ret = cs43130_handle_device_data(client, cs43130);
2443 for (i = 0; i < ARRAY_SIZE(cs43130->supplies); i++)
2444 cs43130->supplies[i].supply = cs43130_supply_names[i];
2446 ret = devm_regulator_bulk_get(&client->dev,
2447 ARRAY_SIZE(cs43130->supplies),
2450 dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
2453 ret = regulator_bulk_enable(ARRAY_SIZE(cs43130->supplies),
2456 dev_err(&client->dev, "Failed to enable supplies: %d\n", ret);
2460 cs43130->reset_gpio = devm_gpiod_get_optional(&client->dev,
2461 "reset", GPIOD_OUT_LOW);
2462 if (IS_ERR(cs43130->reset_gpio)) {
2463 ret = PTR_ERR(cs43130->reset_gpio);
2467 gpiod_set_value_cansleep(cs43130->reset_gpio, 1);
2469 usleep_range(2000, 2050);
2471 devid = cirrus_read_device_id(cs43130->regmap, CS43130_DEVID_AB);
2474 dev_err(&client->dev, "Failed to read device ID: %d\n", ret);
2479 case CS43130_CHIP_ID:
2480 case CS4399_CHIP_ID:
2481 case CS43131_CHIP_ID:
2482 case CS43198_CHIP_ID:
2485 dev_err(&client->dev,
2486 "CS43130 Device ID %X. Expected ID %X, %X, %X or %X\n",
2487 devid, CS43130_CHIP_ID, CS4399_CHIP_ID,
2488 CS43131_CHIP_ID, CS43198_CHIP_ID);
2493 cs43130->dev_id = devid;
2494 ret = regmap_read(cs43130->regmap, CS43130_REV_ID, ®);
2496 dev_err(&client->dev, "Get Revision ID failed\n");
2500 dev_info(&client->dev,
2501 "Cirrus Logic CS43130 (%x), Revision: %02X\n", devid,
2504 mutex_init(&cs43130->clk_mutex);
2506 init_completion(&cs43130->xtal_rdy);
2507 init_completion(&cs43130->pll_rdy);
2508 init_completion(&cs43130->hpload_evt);
2510 ret = devm_request_threaded_irq(&client->dev, client->irq,
2511 NULL, cs43130_irq_thread,
2512 IRQF_ONESHOT | IRQF_TRIGGER_LOW,
2513 "cs43130", cs43130);
2515 dev_err(&client->dev, "Failed to request IRQ: %d\n", ret);
2519 cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
2521 pm_runtime_set_autosuspend_delay(&client->dev, 100);
2522 pm_runtime_use_autosuspend(&client->dev);
2523 pm_runtime_set_active(&client->dev);
2524 pm_runtime_enable(&client->dev);
2526 switch (cs43130->dev_id) {
2527 case CS43130_CHIP_ID:
2528 case CS43131_CHIP_ID:
2529 memcpy(all_hp_widgets, digital_hp_widgets,
2530 sizeof(digital_hp_widgets));
2531 memcpy(all_hp_widgets + ARRAY_SIZE(digital_hp_widgets),
2532 analog_hp_widgets, sizeof(analog_hp_widgets));
2533 memcpy(all_hp_routes, digital_hp_routes,
2534 sizeof(digital_hp_routes));
2535 memcpy(all_hp_routes + ARRAY_SIZE(digital_hp_routes),
2536 analog_hp_routes, sizeof(analog_hp_routes));
2538 soc_component_dev_cs43130.dapm_widgets =
2540 soc_component_dev_cs43130.num_dapm_widgets =
2541 ARRAY_SIZE(all_hp_widgets);
2542 soc_component_dev_cs43130.dapm_routes =
2544 soc_component_dev_cs43130.num_dapm_routes =
2545 ARRAY_SIZE(all_hp_routes);
2547 case CS43198_CHIP_ID:
2548 case CS4399_CHIP_ID:
2549 soc_component_dev_cs43130.dapm_widgets =
2551 soc_component_dev_cs43130.num_dapm_widgets =
2552 ARRAY_SIZE(digital_hp_widgets);
2553 soc_component_dev_cs43130.dapm_routes =
2555 soc_component_dev_cs43130.num_dapm_routes =
2556 ARRAY_SIZE(digital_hp_routes);
2560 ret = devm_snd_soc_register_component(&client->dev,
2561 &soc_component_dev_cs43130,
2562 cs43130_dai, ARRAY_SIZE(cs43130_dai));
2564 dev_err(&client->dev,
2565 "snd_soc_register_component failed with ret = %d\n", ret);
2569 regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
2570 CS43130_ASP_3ST_MASK, 0);
2571 regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
2572 CS43130_XSP_3ST_MASK, 0);
2577 gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
2579 regulator_bulk_disable(ARRAY_SIZE(cs43130->supplies),
2585 static void cs43130_i2c_remove(struct i2c_client *client)
2587 struct cs43130_private *cs43130 = i2c_get_clientdata(client);
2589 if (cs43130->xtal_ibias != CS43130_XTAL_UNUSED)
2590 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2591 CS43130_XTAL_ERR_INT,
2592 1 << CS43130_XTAL_ERR_INT_SHIFT);
2594 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2595 CS43130_HP_PLUG_INT | CS43130_HP_UNPLUG_INT,
2596 CS43130_HP_PLUG_INT | CS43130_HP_UNPLUG_INT);
2598 if (cs43130->dc_meas) {
2599 cancel_work_sync(&cs43130->work);
2600 flush_workqueue(cs43130->wq);
2602 device_remove_file(&client->dev, &dev_attr_hpload_dc_l);
2603 device_remove_file(&client->dev, &dev_attr_hpload_dc_r);
2604 device_remove_file(&client->dev, &dev_attr_hpload_ac_l);
2605 device_remove_file(&client->dev, &dev_attr_hpload_ac_r);
2608 gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
2610 pm_runtime_disable(&client->dev);
2611 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");