2 * cs43130.c -- CS43130 ALSA Soc Audio driver
4 * Copyright 2017 Cirrus Logic, Inc.
6 * Authors: Li Xu <li.xu@cirrus.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/gpio.h>
18 #include <linux/gpio/consumer.h>
19 #include <linux/platform_device.h>
21 #include <linux/i2c.h>
22 #include <linux/of_device.h>
23 #include <linux/regmap.h>
24 #include <linux/slab.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
30 #include <sound/initval.h>
31 #include <sound/tlv.h>
32 #include <linux/of_gpio.h>
33 #include <linux/regulator/consumer.h>
34 #include <linux/pm_runtime.h>
35 #include <linux/of_irq.h>
36 #include <linux/completion.h>
37 #include <linux/mutex.h>
38 #include <linux/workqueue.h>
39 #include <sound/jack.h>
43 static const struct reg_default cs43130_reg_defaults[] = {
44 {CS43130_SYS_CLK_CTL_1, 0x06},
45 {CS43130_SP_SRATE, 0x01},
46 {CS43130_SP_BITSIZE, 0x05},
47 {CS43130_PAD_INT_CFG, 0x03},
48 {CS43130_PWDN_CTL, 0xFE},
49 {CS43130_CRYSTAL_SET, 0x04},
50 {CS43130_PLL_SET_1, 0x00},
51 {CS43130_PLL_SET_2, 0x00},
52 {CS43130_PLL_SET_3, 0x00},
53 {CS43130_PLL_SET_4, 0x00},
54 {CS43130_PLL_SET_5, 0x40},
55 {CS43130_PLL_SET_6, 0x10},
56 {CS43130_PLL_SET_7, 0x80},
57 {CS43130_PLL_SET_8, 0x03},
58 {CS43130_PLL_SET_9, 0x02},
59 {CS43130_PLL_SET_10, 0x02},
60 {CS43130_CLKOUT_CTL, 0x00},
61 {CS43130_ASP_NUM_1, 0x01},
62 {CS43130_ASP_NUM_2, 0x00},
63 {CS43130_ASP_DEN_1, 0x08},
64 {CS43130_ASP_DEN_2, 0x00},
65 {CS43130_ASP_LRCK_HI_TIME_1, 0x1F},
66 {CS43130_ASP_LRCK_HI_TIME_2, 0x00},
67 {CS43130_ASP_LRCK_PERIOD_1, 0x3F},
68 {CS43130_ASP_LRCK_PERIOD_2, 0x00},
69 {CS43130_ASP_CLOCK_CONF, 0x0C},
70 {CS43130_ASP_FRAME_CONF, 0x0A},
71 {CS43130_XSP_NUM_1, 0x01},
72 {CS43130_XSP_NUM_2, 0x00},
73 {CS43130_XSP_DEN_1, 0x02},
74 {CS43130_XSP_DEN_2, 0x00},
75 {CS43130_XSP_LRCK_HI_TIME_1, 0x1F},
76 {CS43130_XSP_LRCK_HI_TIME_2, 0x00},
77 {CS43130_XSP_LRCK_PERIOD_1, 0x3F},
78 {CS43130_XSP_LRCK_PERIOD_2, 0x00},
79 {CS43130_XSP_CLOCK_CONF, 0x0C},
80 {CS43130_XSP_FRAME_CONF, 0x0A},
81 {CS43130_ASP_CH_1_LOC, 0x00},
82 {CS43130_ASP_CH_2_LOC, 0x00},
83 {CS43130_ASP_CH_1_SZ_EN, 0x06},
84 {CS43130_ASP_CH_2_SZ_EN, 0x0E},
85 {CS43130_XSP_CH_1_LOC, 0x00},
86 {CS43130_XSP_CH_2_LOC, 0x00},
87 {CS43130_XSP_CH_1_SZ_EN, 0x06},
88 {CS43130_XSP_CH_2_SZ_EN, 0x0E},
89 {CS43130_DSD_VOL_B, 0x78},
90 {CS43130_DSD_VOL_A, 0x78},
91 {CS43130_DSD_PATH_CTL_1, 0xA8},
92 {CS43130_DSD_INT_CFG, 0x00},
93 {CS43130_DSD_PATH_CTL_2, 0x02},
94 {CS43130_DSD_PCM_MIX_CTL, 0x00},
95 {CS43130_DSD_PATH_CTL_3, 0x40},
96 {CS43130_HP_OUT_CTL_1, 0x30},
97 {CS43130_PCM_FILT_OPT, 0x02},
98 {CS43130_PCM_VOL_B, 0x78},
99 {CS43130_PCM_VOL_A, 0x78},
100 {CS43130_PCM_PATH_CTL_1, 0xA8},
101 {CS43130_PCM_PATH_CTL_2, 0x00},
102 {CS43130_CLASS_H_CTL, 0x1E},
103 {CS43130_HP_DETECT, 0x04},
104 {CS43130_HP_LOAD_1, 0x00},
105 {CS43130_HP_MEAS_LOAD_1, 0x00},
106 {CS43130_HP_MEAS_LOAD_2, 0x00},
107 {CS43130_INT_MASK_1, 0xFF},
108 {CS43130_INT_MASK_2, 0xFF},
109 {CS43130_INT_MASK_3, 0xFF},
110 {CS43130_INT_MASK_4, 0xFF},
111 {CS43130_INT_MASK_5, 0xFF},
114 static bool cs43130_volatile_register(struct device *dev, unsigned int reg)
117 case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
118 case CS43130_HP_DC_STAT_1 ... CS43130_HP_DC_STAT_2:
119 case CS43130_HP_AC_STAT_1 ... CS43130_HP_AC_STAT_2:
126 static bool cs43130_readable_register(struct device *dev, unsigned int reg)
129 case CS43130_DEVID_AB ... CS43130_SYS_CLK_CTL_1:
130 case CS43130_SP_SRATE ... CS43130_PAD_INT_CFG:
131 case CS43130_PWDN_CTL:
132 case CS43130_CRYSTAL_SET:
133 case CS43130_PLL_SET_1 ... CS43130_PLL_SET_5:
134 case CS43130_PLL_SET_6:
135 case CS43130_PLL_SET_7:
136 case CS43130_PLL_SET_8:
137 case CS43130_PLL_SET_9:
138 case CS43130_PLL_SET_10:
139 case CS43130_CLKOUT_CTL:
140 case CS43130_ASP_NUM_1 ... CS43130_ASP_FRAME_CONF:
141 case CS43130_XSP_NUM_1 ... CS43130_XSP_FRAME_CONF:
142 case CS43130_ASP_CH_1_LOC:
143 case CS43130_ASP_CH_2_LOC:
144 case CS43130_ASP_CH_1_SZ_EN:
145 case CS43130_ASP_CH_2_SZ_EN:
146 case CS43130_XSP_CH_1_LOC:
147 case CS43130_XSP_CH_2_LOC:
148 case CS43130_XSP_CH_1_SZ_EN:
149 case CS43130_XSP_CH_2_SZ_EN:
150 case CS43130_DSD_VOL_B ... CS43130_DSD_PATH_CTL_3:
151 case CS43130_HP_OUT_CTL_1:
152 case CS43130_PCM_FILT_OPT ... CS43130_PCM_PATH_CTL_2:
153 case CS43130_CLASS_H_CTL:
154 case CS43130_HP_DETECT:
155 case CS43130_HP_STATUS:
156 case CS43130_HP_LOAD_1:
157 case CS43130_HP_MEAS_LOAD_1:
158 case CS43130_HP_MEAS_LOAD_2:
159 case CS43130_HP_DC_STAT_1:
160 case CS43130_HP_DC_STAT_2:
161 case CS43130_HP_AC_STAT_1:
162 case CS43130_HP_AC_STAT_2:
163 case CS43130_HP_LOAD_STAT:
164 case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
165 case CS43130_INT_MASK_1 ... CS43130_INT_MASK_5:
172 static bool cs43130_precious_register(struct device *dev, unsigned int reg)
175 case CS43130_INT_STATUS_1 ... CS43130_INT_STATUS_5:
182 struct cs43130_pll_params {
189 unsigned int pll_out;
193 static const struct cs43130_pll_params pll_ratio_table[] = {
194 {9600000, 0x02, 0x49, 0x800000, 0x00, 0x08, 22579200, 151},
195 {9600000, 0x02, 0x50, 0x000000, 0x00, 0x08, 24576000, 164},
197 {11289600, 0x02, 0X40, 0, 0x01, 0x08, 22579200, 128},
198 {11289600, 0x02, 0x44, 0x06F700, 0x0, 0x08, 24576000, 139},
200 {12000000, 0x02, 0x49, 0x800000, 0x00, 0x0A, 22579200, 120},
201 {12000000, 0x02, 0x40, 0x000000, 0x00, 0x08, 24576000, 131},
203 {12288000, 0x02, 0x49, 0x800000, 0x01, 0x0A, 22579200, 118},
204 {12288000, 0x02, 0x40, 0x000000, 0x01, 0x08, 24576000, 128},
206 {13000000, 0x02, 0x45, 0x797680, 0x01, 0x0A, 22579200, 111},
207 {13000000, 0x02, 0x3C, 0x7EA940, 0x01, 0x08, 24576000, 121},
209 {19200000, 0x03, 0x49, 0x800000, 0x00, 0x08, 22579200, 151},
210 {19200000, 0x03, 0x50, 0x000000, 0x00, 0x08, 24576000, 164},
212 {22579200, 0, 0, 0, 0, 0, 22579200, 0},
213 {22579200, 0x03, 0x44, 0x06F700, 0x00, 0x08, 24576000, 139},
215 {24000000, 0x03, 0x49, 0x800000, 0x00, 0x0A, 22579200, 120},
216 {24000000, 0x03, 0x40, 0x000000, 0x00, 0x08, 24576000, 131},
218 {24576000, 0x03, 0x49, 0x800000, 0x01, 0x0A, 22579200, 118},
219 {24576000, 0, 0, 0, 0, 0, 24576000, 0},
221 {26000000, 0x03, 0x45, 0x797680, 0x01, 0x0A, 22579200, 111},
222 {26000000, 0x03, 0x3C, 0x7EA940, 0x01, 0x08, 24576000, 121},
225 static const struct cs43130_pll_params *cs43130_get_pll_table(
226 unsigned int freq_in, unsigned int freq_out)
230 for (i = 0; i < ARRAY_SIZE(pll_ratio_table); i++) {
231 if (pll_ratio_table[i].pll_in == freq_in &&
232 pll_ratio_table[i].pll_out == freq_out)
233 return &pll_ratio_table[i];
239 static int cs43130_pll_config(struct snd_soc_component *component)
241 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
242 const struct cs43130_pll_params *pll_entry;
244 dev_dbg(component->dev, "cs43130->mclk = %u, cs43130->mclk_int = %u\n",
245 cs43130->mclk, cs43130->mclk_int);
247 pll_entry = cs43130_get_pll_table(cs43130->mclk, cs43130->mclk_int);
251 if (pll_entry->pll_cal_ratio == 0) {
252 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_1,
253 CS43130_PLL_START_MASK, 0);
255 cs43130->pll_bypass = true;
259 cs43130->pll_bypass = false;
261 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_2,
262 CS43130_PLL_DIV_DATA_MASK,
263 pll_entry->pll_div_frac >>
264 CS43130_PLL_DIV_FRAC_0_DATA_SHIFT);
265 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_3,
266 CS43130_PLL_DIV_DATA_MASK,
267 pll_entry->pll_div_frac >>
268 CS43130_PLL_DIV_FRAC_1_DATA_SHIFT);
269 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_4,
270 CS43130_PLL_DIV_DATA_MASK,
271 pll_entry->pll_div_frac >>
272 CS43130_PLL_DIV_FRAC_2_DATA_SHIFT);
273 regmap_write(cs43130->regmap, CS43130_PLL_SET_5,
274 pll_entry->pll_div_int);
275 regmap_write(cs43130->regmap, CS43130_PLL_SET_6, pll_entry->pll_divout);
276 regmap_write(cs43130->regmap, CS43130_PLL_SET_7,
277 pll_entry->pll_cal_ratio);
278 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_8,
279 CS43130_PLL_MODE_MASK,
280 pll_entry->pll_mode << CS43130_PLL_MODE_SHIFT);
281 regmap_write(cs43130->regmap, CS43130_PLL_SET_9,
282 pll_entry->sclk_prediv);
283 regmap_update_bits(cs43130->regmap, CS43130_PLL_SET_1,
284 CS43130_PLL_START_MASK, 1);
289 static int cs43130_set_pll(struct snd_soc_component *component, int pll_id, int source,
290 unsigned int freq_in, unsigned int freq_out)
293 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
306 cs43130->mclk = freq_in;
309 dev_err(component->dev,
310 "unsupported pll input reference clock:%d\n", freq_in);
316 cs43130->mclk_int = freq_out;
319 cs43130->mclk_int = freq_out;
322 dev_err(component->dev,
323 "unsupported pll output ref clock: %u\n", freq_out);
327 ret = cs43130_pll_config(component);
328 dev_dbg(component->dev, "cs43130->pll_bypass = %d", cs43130->pll_bypass);
332 static int cs43130_change_clksrc(struct snd_soc_component *component,
333 enum cs43130_mclk_src_sel src)
336 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
337 int mclk_int_decoded;
339 if (src == cs43130->mclk_int_src) {
340 /* clk source has not changed */
344 switch (cs43130->mclk_int) {
345 case CS43130_MCLK_22M:
346 mclk_int_decoded = CS43130_MCLK_22P5;
348 case CS43130_MCLK_24M:
349 mclk_int_decoded = CS43130_MCLK_24P5;
352 dev_err(component->dev, "Invalid MCLK INT freq: %u\n", cs43130->mclk_int);
357 case CS43130_MCLK_SRC_EXT:
358 cs43130->pll_bypass = true;
359 cs43130->mclk_int_src = CS43130_MCLK_SRC_EXT;
360 if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
361 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
362 CS43130_PDN_XTAL_MASK,
363 1 << CS43130_PDN_XTAL_SHIFT);
365 reinit_completion(&cs43130->xtal_rdy);
366 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
367 CS43130_XTAL_RDY_INT_MASK, 0);
368 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
369 CS43130_PDN_XTAL_MASK, 0);
370 ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
371 msecs_to_jiffies(100));
372 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
373 CS43130_XTAL_RDY_INT_MASK,
374 1 << CS43130_XTAL_RDY_INT_SHIFT);
376 dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
381 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
382 CS43130_MCLK_SRC_SEL_MASK,
383 src << CS43130_MCLK_SRC_SEL_SHIFT);
384 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
385 CS43130_MCLK_INT_MASK,
386 mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
387 usleep_range(150, 200);
389 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
390 CS43130_PDN_PLL_MASK,
391 1 << CS43130_PDN_PLL_SHIFT);
393 case CS43130_MCLK_SRC_PLL:
394 cs43130->pll_bypass = false;
395 cs43130->mclk_int_src = CS43130_MCLK_SRC_PLL;
396 if (cs43130->xtal_ibias == CS43130_XTAL_UNUSED) {
397 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
398 CS43130_PDN_XTAL_MASK,
399 1 << CS43130_PDN_XTAL_SHIFT);
401 reinit_completion(&cs43130->xtal_rdy);
402 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
403 CS43130_XTAL_RDY_INT_MASK, 0);
404 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
405 CS43130_PDN_XTAL_MASK, 0);
406 ret = wait_for_completion_timeout(&cs43130->xtal_rdy,
407 msecs_to_jiffies(100));
408 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
409 CS43130_XTAL_RDY_INT_MASK,
410 1 << CS43130_XTAL_RDY_INT_SHIFT);
412 dev_err(component->dev, "Timeout waiting for XTAL_READY interrupt\n");
417 reinit_completion(&cs43130->pll_rdy);
418 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
419 CS43130_PLL_RDY_INT_MASK, 0);
420 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
421 CS43130_PDN_PLL_MASK, 0);
422 ret = wait_for_completion_timeout(&cs43130->pll_rdy,
423 msecs_to_jiffies(100));
424 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
425 CS43130_PLL_RDY_INT_MASK,
426 1 << CS43130_PLL_RDY_INT_SHIFT);
428 dev_err(component->dev, "Timeout waiting for PLL_READY interrupt\n");
432 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
433 CS43130_MCLK_SRC_SEL_MASK,
434 src << CS43130_MCLK_SRC_SEL_SHIFT);
435 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
436 CS43130_MCLK_INT_MASK,
437 mclk_int_decoded << CS43130_MCLK_INT_SHIFT);
438 usleep_range(150, 200);
440 case CS43130_MCLK_SRC_RCO:
441 cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
443 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
444 CS43130_MCLK_SRC_SEL_MASK,
445 src << CS43130_MCLK_SRC_SEL_SHIFT);
446 regmap_update_bits(cs43130->regmap, CS43130_SYS_CLK_CTL_1,
447 CS43130_MCLK_INT_MASK,
448 CS43130_MCLK_22P5 << CS43130_MCLK_INT_SHIFT);
449 usleep_range(150, 200);
451 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
452 CS43130_PDN_XTAL_MASK,
453 1 << CS43130_PDN_XTAL_SHIFT);
454 regmap_update_bits(cs43130->regmap, CS43130_PWDN_CTL,
455 CS43130_PDN_PLL_MASK,
456 1 << CS43130_PDN_PLL_SHIFT);
459 dev_err(component->dev, "Invalid MCLK source value\n");
466 static const struct cs43130_bitwidth_map cs43130_bitwidth_table[] = {
467 {8, CS43130_SP_BIT_SIZE_8, CS43130_CH_BIT_SIZE_8},
468 {16, CS43130_SP_BIT_SIZE_16, CS43130_CH_BIT_SIZE_16},
469 {24, CS43130_SP_BIT_SIZE_24, CS43130_CH_BIT_SIZE_24},
470 {32, CS43130_SP_BIT_SIZE_32, CS43130_CH_BIT_SIZE_32},
473 static const struct cs43130_bitwidth_map *cs43130_get_bitwidth_table(
474 unsigned int bitwidth)
478 for (i = 0; i < ARRAY_SIZE(cs43130_bitwidth_table); i++) {
479 if (cs43130_bitwidth_table[i].bitwidth == bitwidth)
480 return &cs43130_bitwidth_table[i];
486 static int cs43130_set_bitwidth(int dai_id, unsigned int bitwidth_dai,
487 struct regmap *regmap)
489 const struct cs43130_bitwidth_map *bw_map;
491 bw_map = cs43130_get_bitwidth_table(bitwidth_dai);
496 case CS43130_ASP_PCM_DAI:
497 case CS43130_ASP_DOP_DAI:
498 regmap_update_bits(regmap, CS43130_ASP_CH_1_SZ_EN,
499 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
500 regmap_update_bits(regmap, CS43130_ASP_CH_2_SZ_EN,
501 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
502 regmap_update_bits(regmap, CS43130_SP_BITSIZE,
503 CS43130_ASP_BITSIZE_MASK, bw_map->sp_bit);
505 case CS43130_XSP_DOP_DAI:
506 regmap_update_bits(regmap, CS43130_XSP_CH_1_SZ_EN,
507 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
508 regmap_update_bits(regmap, CS43130_XSP_CH_2_SZ_EN,
509 CS43130_CH_BITSIZE_MASK, bw_map->ch_bit);
510 regmap_update_bits(regmap, CS43130_SP_BITSIZE,
511 CS43130_XSP_BITSIZE_MASK, bw_map->sp_bit <<
512 CS43130_XSP_BITSIZE_SHIFT);
521 static const struct cs43130_rate_map cs43130_rate_table[] = {
522 {32000, CS43130_ASP_SPRATE_32K},
523 {44100, CS43130_ASP_SPRATE_44_1K},
524 {48000, CS43130_ASP_SPRATE_48K},
525 {88200, CS43130_ASP_SPRATE_88_2K},
526 {96000, CS43130_ASP_SPRATE_96K},
527 {176400, CS43130_ASP_SPRATE_176_4K},
528 {192000, CS43130_ASP_SPRATE_192K},
529 {352800, CS43130_ASP_SPRATE_352_8K},
530 {384000, CS43130_ASP_SPRATE_384K},
533 static const struct cs43130_rate_map *cs43130_get_rate_table(int fs)
537 for (i = 0; i < ARRAY_SIZE(cs43130_rate_table); i++) {
538 if (cs43130_rate_table[i].fs == fs)
539 return &cs43130_rate_table[i];
545 static const struct cs43130_clk_gen *cs43130_get_clk_gen(int mclk_int, int fs,
546 const struct cs43130_clk_gen *clk_gen_table, int len_clk_gen_table)
550 for (i = 0; i < len_clk_gen_table; i++) {
551 if (clk_gen_table[i].mclk_int == mclk_int &&
552 clk_gen_table[i].fs == fs)
553 return &clk_gen_table[i];
559 static int cs43130_set_sp_fmt(int dai_id, unsigned int bitwidth_sclk,
560 struct snd_pcm_hw_params *params,
561 struct cs43130_private *cs43130)
574 const struct cs43130_clk_gen *clk_gen;
576 switch (cs43130->dais[dai_id].dai_format) {
577 case SND_SOC_DAIFMT_I2S:
578 hi_size = bitwidth_sclk;
582 case SND_SOC_DAIFMT_LEFT_J:
583 hi_size = bitwidth_sclk;
587 case SND_SOC_DAIFMT_DSP_A:
592 case SND_SOC_DAIFMT_DSP_B:
601 switch (cs43130->dais[dai_id].dai_mode) {
602 case SND_SOC_DAIFMT_CBS_CFS:
605 case SND_SOC_DAIFMT_CBM_CFM:
612 frm_size = bitwidth_sclk * params_channels(params);
616 loc_ch2 = bitwidth_sclk * (params_channels(params) - 1);
618 frm_data = frm_delay & CS43130_SP_FSD_MASK;
619 frm_data |= (frm_phase << CS43130_SP_STP_SHIFT) & CS43130_SP_STP_MASK;
621 clk_data = lrck_edge & CS43130_SP_LCPOL_IN_MASK;
622 clk_data |= (lrck_edge << CS43130_SP_LCPOL_OUT_SHIFT) &
623 CS43130_SP_LCPOL_OUT_MASK;
624 clk_data |= (sclk_edge << CS43130_SP_SCPOL_IN_SHIFT) &
625 CS43130_SP_SCPOL_IN_MASK;
626 clk_data |= (sclk_edge << CS43130_SP_SCPOL_OUT_SHIFT) &
627 CS43130_SP_SCPOL_OUT_MASK;
628 clk_data |= (dai_mode_val << CS43130_SP_MODE_SHIFT) &
629 CS43130_SP_MODE_MASK;
632 case CS43130_ASP_PCM_DAI:
633 case CS43130_ASP_DOP_DAI:
634 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_1,
635 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
636 CS43130_SP_LCPR_LSB_DATA_SHIFT);
637 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_PERIOD_2,
638 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
639 CS43130_SP_LCPR_MSB_DATA_SHIFT);
640 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_1,
641 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
642 CS43130_SP_LCHI_LSB_DATA_SHIFT);
643 regmap_update_bits(cs43130->regmap, CS43130_ASP_LRCK_HI_TIME_2,
644 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
645 CS43130_SP_LCHI_MSB_DATA_SHIFT);
646 regmap_write(cs43130->regmap, CS43130_ASP_FRAME_CONF, frm_data);
647 regmap_write(cs43130->regmap, CS43130_ASP_CH_1_LOC, loc_ch1);
648 regmap_write(cs43130->regmap, CS43130_ASP_CH_2_LOC, loc_ch2);
649 regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_1_SZ_EN,
650 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
651 regmap_update_bits(cs43130->regmap, CS43130_ASP_CH_2_SZ_EN,
652 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
653 regmap_write(cs43130->regmap, CS43130_ASP_CLOCK_CONF, clk_data);
655 case CS43130_XSP_DOP_DAI:
656 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_1,
657 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
658 CS43130_SP_LCPR_LSB_DATA_SHIFT);
659 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_PERIOD_2,
660 CS43130_SP_LCPR_DATA_MASK, (frm_size - 1) >>
661 CS43130_SP_LCPR_MSB_DATA_SHIFT);
662 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_1,
663 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
664 CS43130_SP_LCHI_LSB_DATA_SHIFT);
665 regmap_update_bits(cs43130->regmap, CS43130_XSP_LRCK_HI_TIME_2,
666 CS43130_SP_LCHI_DATA_MASK, (hi_size - 1) >>
667 CS43130_SP_LCHI_MSB_DATA_SHIFT);
668 regmap_write(cs43130->regmap, CS43130_XSP_FRAME_CONF, frm_data);
669 regmap_write(cs43130->regmap, CS43130_XSP_CH_1_LOC, loc_ch1);
670 regmap_write(cs43130->regmap, CS43130_XSP_CH_2_LOC, loc_ch2);
671 regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_1_SZ_EN,
672 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
673 regmap_update_bits(cs43130->regmap, CS43130_XSP_CH_2_SZ_EN,
674 CS43130_CH_EN_MASK, 1 << CS43130_CH_EN_SHIFT);
675 regmap_write(cs43130->regmap, CS43130_XSP_CLOCK_CONF, clk_data);
683 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
686 ARRAY_SIZE(cs43130_16_clk_gen));
689 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
692 ARRAY_SIZE(cs43130_32_clk_gen));
695 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
698 ARRAY_SIZE(cs43130_48_clk_gen));
701 clk_gen = cs43130_get_clk_gen(cs43130->mclk_int,
704 ARRAY_SIZE(cs43130_64_clk_gen));
714 case CS43130_ASP_PCM_DAI:
715 case CS43130_ASP_DOP_DAI:
716 regmap_write(cs43130->regmap, CS43130_ASP_DEN_1,
717 (clk_gen->den & CS43130_SP_M_LSB_DATA_MASK) >>
718 CS43130_SP_M_LSB_DATA_SHIFT);
719 regmap_write(cs43130->regmap, CS43130_ASP_DEN_2,
720 (clk_gen->den & CS43130_SP_M_MSB_DATA_MASK) >>
721 CS43130_SP_M_MSB_DATA_SHIFT);
722 regmap_write(cs43130->regmap, CS43130_ASP_NUM_1,
723 (clk_gen->num & CS43130_SP_N_LSB_DATA_MASK) >>
724 CS43130_SP_N_LSB_DATA_SHIFT);
725 regmap_write(cs43130->regmap, CS43130_ASP_NUM_2,
726 (clk_gen->num & CS43130_SP_N_MSB_DATA_MASK) >>
727 CS43130_SP_N_MSB_DATA_SHIFT);
729 case CS43130_XSP_DOP_DAI:
730 regmap_write(cs43130->regmap, CS43130_XSP_DEN_1,
731 (clk_gen->den & CS43130_SP_M_LSB_DATA_MASK) >>
732 CS43130_SP_M_LSB_DATA_SHIFT);
733 regmap_write(cs43130->regmap, CS43130_XSP_DEN_2,
734 (clk_gen->den & CS43130_SP_M_MSB_DATA_MASK) >>
735 CS43130_SP_M_MSB_DATA_SHIFT);
736 regmap_write(cs43130->regmap, CS43130_XSP_NUM_1,
737 (clk_gen->num & CS43130_SP_N_LSB_DATA_MASK) >>
738 CS43130_SP_N_LSB_DATA_SHIFT);
739 regmap_write(cs43130->regmap, CS43130_XSP_NUM_2,
740 (clk_gen->num & CS43130_SP_N_MSB_DATA_MASK) >>
741 CS43130_SP_N_MSB_DATA_SHIFT);
750 static int cs43130_pcm_dsd_mix(bool en, struct regmap *regmap)
753 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
754 CS43130_MIX_PCM_PREP_MASK,
755 1 << CS43130_MIX_PCM_PREP_SHIFT);
756 usleep_range(6000, 6050);
757 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
758 CS43130_MIX_PCM_DSD_MASK,
759 1 << CS43130_MIX_PCM_DSD_SHIFT);
761 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
762 CS43130_MIX_PCM_DSD_MASK,
763 0 << CS43130_MIX_PCM_DSD_SHIFT);
764 usleep_range(1600, 1650);
765 regmap_update_bits(regmap, CS43130_DSD_PCM_MIX_CTL,
766 CS43130_MIX_PCM_PREP_MASK,
767 0 << CS43130_MIX_PCM_PREP_SHIFT);
773 static int cs43130_dsd_hw_params(struct snd_pcm_substream *substream,
774 struct snd_pcm_hw_params *params,
775 struct snd_soc_dai *dai)
777 struct snd_soc_component *component = dai->component;
778 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
779 unsigned int required_clk;
782 mutex_lock(&cs43130->clk_mutex);
783 if (!cs43130->clk_req) {
784 /* no DAI is currently using clk */
785 if (!(CS43130_MCLK_22M % params_rate(params)))
786 required_clk = CS43130_MCLK_22M;
788 required_clk = CS43130_MCLK_24M;
790 cs43130_set_pll(component, 0, 0, cs43130->mclk, required_clk);
791 if (cs43130->pll_bypass)
792 cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
794 cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
798 if (cs43130->clk_req == 2)
799 cs43130_pcm_dsd_mix(true, cs43130->regmap);
800 mutex_unlock(&cs43130->clk_mutex);
802 switch (params_rate(params)) {
810 dev_err(component->dev, "Rate(%u) not supported\n",
811 params_rate(params));
815 if (cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBM_CFM)
816 regmap_update_bits(cs43130->regmap, CS43130_DSD_INT_CFG,
817 CS43130_DSD_MASTER, CS43130_DSD_MASTER);
819 regmap_update_bits(cs43130->regmap, CS43130_DSD_INT_CFG,
820 CS43130_DSD_MASTER, 0);
822 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
823 CS43130_DSD_SPEED_MASK,
824 dsd_speed << CS43130_DSD_SPEED_SHIFT);
825 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
826 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_DSD <<
827 CS43130_DSD_SRC_SHIFT);
832 static int cs43130_hw_params(struct snd_pcm_substream *substream,
833 struct snd_pcm_hw_params *params,
834 struct snd_soc_dai *dai)
836 struct snd_soc_component *component = dai->component;
837 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
838 const struct cs43130_rate_map *rate_map;
839 unsigned int sclk = cs43130->dais[dai->id].sclk;
840 unsigned int bitwidth_sclk;
841 unsigned int bitwidth_dai = (unsigned int)(params_width(params));
842 unsigned int required_clk;
845 mutex_lock(&cs43130->clk_mutex);
846 if (!cs43130->clk_req) {
847 /* no DAI is currently using clk */
848 if (!(CS43130_MCLK_22M % params_rate(params)))
849 required_clk = CS43130_MCLK_22M;
851 required_clk = CS43130_MCLK_24M;
853 cs43130_set_pll(component, 0, 0, cs43130->mclk, required_clk);
854 if (cs43130->pll_bypass)
855 cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
857 cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
861 if (cs43130->clk_req == 2)
862 cs43130_pcm_dsd_mix(true, cs43130->regmap);
863 mutex_unlock(&cs43130->clk_mutex);
866 case CS43130_ASP_DOP_DAI:
867 case CS43130_XSP_DOP_DAI:
868 /* DoP bitwidth is always 24-bit */
870 sclk = params_rate(params) * bitwidth_dai *
871 params_channels(params);
873 switch (params_rate(params)) {
881 dev_err(component->dev, "Rate(%u) not supported\n",
882 params_rate(params));
886 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
887 CS43130_DSD_SPEED_MASK,
888 dsd_speed << CS43130_DSD_SPEED_SHIFT);
890 case CS43130_ASP_PCM_DAI:
891 rate_map = cs43130_get_rate_table(params_rate(params));
895 regmap_write(cs43130->regmap, CS43130_SP_SRATE, rate_map->val);
898 dev_err(component->dev, "Invalid DAI (%d)\n", dai->id);
903 case CS43130_ASP_DOP_DAI:
904 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
905 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_ASP <<
906 CS43130_DSD_SRC_SHIFT);
908 case CS43130_XSP_DOP_DAI:
909 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
910 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
911 CS43130_DSD_SRC_SHIFT);
915 if (!sclk && cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBM_CFM)
916 /* Calculate SCLK in master mode if unassigned */
917 sclk = params_rate(params) * bitwidth_dai *
918 params_channels(params);
921 /* at this point, SCLK must be set */
922 dev_err(component->dev, "SCLK freq is not set\n");
926 bitwidth_sclk = (sclk / params_rate(params)) / params_channels(params);
927 if (bitwidth_sclk < bitwidth_dai) {
928 dev_err(component->dev, "Format not supported: SCLK freq is too low\n");
932 dev_dbg(component->dev,
933 "sclk = %u, fs = %d, bitwidth_dai = %u\n",
934 sclk, params_rate(params), bitwidth_dai);
936 dev_dbg(component->dev,
937 "bitwidth_sclk = %u, num_ch = %u\n",
938 bitwidth_sclk, params_channels(params));
940 cs43130_set_bitwidth(dai->id, bitwidth_dai, cs43130->regmap);
941 cs43130_set_sp_fmt(dai->id, bitwidth_sclk, params, cs43130);
946 static int cs43130_hw_free(struct snd_pcm_substream *substream,
947 struct snd_soc_dai *dai)
949 struct snd_soc_component *component = dai->component;
950 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
952 mutex_lock(&cs43130->clk_mutex);
954 if (!cs43130->clk_req) {
955 /* no DAI is currently using clk */
956 cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
957 cs43130_pcm_dsd_mix(false, cs43130->regmap);
959 mutex_unlock(&cs43130->clk_mutex);
964 static const DECLARE_TLV_DB_SCALE(pcm_vol_tlv, -12750, 50, 1);
966 static const char * const pcm_ch_text[] = {
973 static const struct reg_sequence pcm_ch_en_seq[] = {
974 {CS43130_DXD1, 0x99},
994 static const struct reg_sequence pcm_ch_dis_seq[] = {
995 {CS43130_DXD1, 0x99},
1015 static int cs43130_pcm_ch_get(struct snd_kcontrol *kcontrol,
1016 struct snd_ctl_elem_value *ucontrol)
1018 return snd_soc_get_enum_double(kcontrol, ucontrol);
1021 static int cs43130_pcm_ch_put(struct snd_kcontrol *kcontrol,
1022 struct snd_ctl_elem_value *ucontrol)
1024 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1025 unsigned int *item = ucontrol->value.enumerated.item;
1026 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1027 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1030 if (item[0] >= e->items)
1032 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
1034 switch (cs43130->dev_id) {
1035 case CS43131_CHIP_ID:
1036 case CS43198_CHIP_ID:
1038 regmap_multi_reg_write(cs43130->regmap, pcm_ch_en_seq,
1039 ARRAY_SIZE(pcm_ch_en_seq));
1041 regmap_multi_reg_write(cs43130->regmap, pcm_ch_dis_seq,
1042 ARRAY_SIZE(pcm_ch_dis_seq));
1046 return snd_soc_put_enum_double(kcontrol, ucontrol);
1049 static SOC_ENUM_SINGLE_DECL(pcm_ch_enum, CS43130_PCM_PATH_CTL_2, 0,
1052 static const char * const pcm_spd_texts[] = {
1057 static SOC_ENUM_SINGLE_DECL(pcm_spd_enum, CS43130_PCM_FILT_OPT, 7,
1060 static const char * const dsd_texts[] = {
1066 static const unsigned int dsd_values[] = {
1067 CS43130_DSD_SRC_DSD,
1068 CS43130_DSD_SRC_ASP,
1069 CS43130_DSD_SRC_XSP,
1072 static SOC_VALUE_ENUM_SINGLE_DECL(dsd_enum, CS43130_DSD_INT_CFG, 0, 0x03,
1073 dsd_texts, dsd_values);
1075 static const struct snd_kcontrol_new cs43130_snd_controls[] = {
1076 SOC_DOUBLE_R_TLV("Master Playback Volume",
1077 CS43130_PCM_VOL_A, CS43130_PCM_VOL_B, 0, 0xFF, 1,
1079 SOC_DOUBLE_R_TLV("Master DSD Playback Volume",
1080 CS43130_DSD_VOL_A, CS43130_DSD_VOL_B, 0, 0xFF, 1,
1082 SOC_ENUM_EXT("PCM Ch Select", pcm_ch_enum, cs43130_pcm_ch_get,
1083 cs43130_pcm_ch_put),
1084 SOC_ENUM("PCM Filter Speed", pcm_spd_enum),
1085 SOC_SINGLE("PCM Phase Compensation", CS43130_PCM_FILT_OPT, 6, 1, 0),
1086 SOC_SINGLE("PCM Nonoversample Emulate", CS43130_PCM_FILT_OPT, 5, 1, 0),
1087 SOC_SINGLE("PCM High-pass Filter", CS43130_PCM_FILT_OPT, 1, 1, 0),
1088 SOC_SINGLE("PCM De-emphasis Filter", CS43130_PCM_FILT_OPT, 0, 1, 0),
1089 SOC_ENUM("DSD Phase Modulation", dsd_enum),
1092 static const struct reg_sequence pcm_seq[] = {
1093 {CS43130_DXD1, 0x99},
1094 {CS43130_DXD7, 0x01},
1096 {CS43130_DXD9, 0x01},
1097 {CS43130_DXD3, 0x12},
1099 {CS43130_DXD10, 0x28},
1100 {CS43130_DXD11, 0x28},
1104 static const struct reg_sequence dsd_seq[] = {
1105 {CS43130_DXD1, 0x99},
1106 {CS43130_DXD7, 0x01},
1108 {CS43130_DXD9, 0x01},
1109 {CS43130_DXD3, 0x12},
1111 {CS43130_DXD10, 0x1E},
1112 {CS43130_DXD11, 0x20},
1116 static const struct reg_sequence pop_free_seq[] = {
1117 {CS43130_DXD1, 0x99},
1118 {CS43130_DXD12, 0x0A},
1122 static const struct reg_sequence pop_free_seq2[] = {
1123 {CS43130_DXD1, 0x99},
1124 {CS43130_DXD13, 0x20},
1128 static const struct reg_sequence mute_seq[] = {
1129 {CS43130_DXD1, 0x99},
1130 {CS43130_DXD3, 0x12},
1131 {CS43130_DXD5, 0x02},
1132 {CS43130_DXD4, 0x12},
1136 static const struct reg_sequence unmute_seq[] = {
1137 {CS43130_DXD1, 0x99},
1138 {CS43130_DXD3, 0x10},
1140 {CS43130_DXD4, 0x16},
1144 static int cs43130_dsd_event(struct snd_soc_dapm_widget *w,
1145 struct snd_kcontrol *kcontrol, int event)
1147 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1148 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1151 case SND_SOC_DAPM_PRE_PMU:
1152 switch (cs43130->dev_id) {
1153 case CS43130_CHIP_ID:
1154 case CS4399_CHIP_ID:
1155 regmap_multi_reg_write(cs43130->regmap, dsd_seq,
1156 ARRAY_SIZE(dsd_seq));
1160 case SND_SOC_DAPM_POST_PMU:
1161 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_1,
1162 CS43130_MUTE_MASK, 0);
1163 switch (cs43130->dev_id) {
1164 case CS43130_CHIP_ID:
1165 case CS4399_CHIP_ID:
1166 regmap_multi_reg_write(cs43130->regmap, unmute_seq,
1167 ARRAY_SIZE(unmute_seq));
1171 case SND_SOC_DAPM_PRE_PMD:
1172 switch (cs43130->dev_id) {
1173 case CS43130_CHIP_ID:
1174 case CS4399_CHIP_ID:
1175 regmap_multi_reg_write(cs43130->regmap, mute_seq,
1176 ARRAY_SIZE(mute_seq));
1177 regmap_update_bits(cs43130->regmap,
1178 CS43130_DSD_PATH_CTL_1,
1179 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1181 * DSD Power Down Sequence
1182 * According to Design, 130ms is preferred.
1186 case CS43131_CHIP_ID:
1187 case CS43198_CHIP_ID:
1188 regmap_update_bits(cs43130->regmap,
1189 CS43130_DSD_PATH_CTL_1,
1190 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1195 dev_err(component->dev, "Invalid event = 0x%x\n", event);
1201 static int cs43130_pcm_event(struct snd_soc_dapm_widget *w,
1202 struct snd_kcontrol *kcontrol, int event)
1204 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1205 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1208 case SND_SOC_DAPM_PRE_PMU:
1209 switch (cs43130->dev_id) {
1210 case CS43130_CHIP_ID:
1211 case CS4399_CHIP_ID:
1212 regmap_multi_reg_write(cs43130->regmap, pcm_seq,
1213 ARRAY_SIZE(pcm_seq));
1217 case SND_SOC_DAPM_POST_PMU:
1218 regmap_update_bits(cs43130->regmap, CS43130_PCM_PATH_CTL_1,
1219 CS43130_MUTE_MASK, 0);
1220 switch (cs43130->dev_id) {
1221 case CS43130_CHIP_ID:
1222 case CS4399_CHIP_ID:
1223 regmap_multi_reg_write(cs43130->regmap, unmute_seq,
1224 ARRAY_SIZE(unmute_seq));
1228 case SND_SOC_DAPM_PRE_PMD:
1229 switch (cs43130->dev_id) {
1230 case CS43130_CHIP_ID:
1231 case CS4399_CHIP_ID:
1232 regmap_multi_reg_write(cs43130->regmap, mute_seq,
1233 ARRAY_SIZE(mute_seq));
1234 regmap_update_bits(cs43130->regmap,
1235 CS43130_PCM_PATH_CTL_1,
1236 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1238 * PCM Power Down Sequence
1239 * According to Design, 130ms is preferred.
1243 case CS43131_CHIP_ID:
1244 case CS43198_CHIP_ID:
1245 regmap_update_bits(cs43130->regmap,
1246 CS43130_PCM_PATH_CTL_1,
1247 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1252 dev_err(component->dev, "Invalid event = 0x%x\n", event);
1258 static const struct reg_sequence dac_postpmu_seq[] = {
1259 {CS43130_DXD9, 0x0C},
1260 {CS43130_DXD3, 0x10},
1261 {CS43130_DXD4, 0x20},
1264 static const struct reg_sequence dac_postpmd_seq[] = {
1265 {CS43130_DXD1, 0x99},
1266 {CS43130_DXD6, 0x01},
1270 static int cs43130_dac_event(struct snd_soc_dapm_widget *w,
1271 struct snd_kcontrol *kcontrol, int event)
1273 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1274 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1277 case SND_SOC_DAPM_PRE_PMU:
1278 switch (cs43130->dev_id) {
1279 case CS43130_CHIP_ID:
1280 case CS4399_CHIP_ID:
1281 regmap_multi_reg_write(cs43130->regmap, pop_free_seq,
1282 ARRAY_SIZE(pop_free_seq));
1284 case CS43131_CHIP_ID:
1285 case CS43198_CHIP_ID:
1286 regmap_multi_reg_write(cs43130->regmap, pop_free_seq2,
1287 ARRAY_SIZE(pop_free_seq2));
1291 case SND_SOC_DAPM_POST_PMU:
1292 usleep_range(10000, 10050);
1294 regmap_write(cs43130->regmap, CS43130_DXD1, 0x99);
1296 switch (cs43130->dev_id) {
1297 case CS43130_CHIP_ID:
1298 case CS4399_CHIP_ID:
1299 regmap_multi_reg_write(cs43130->regmap, dac_postpmu_seq,
1300 ARRAY_SIZE(dac_postpmu_seq));
1302 * Per datasheet, Sec. PCM Power-Up Sequence.
1303 * According to Design, CS43130_DXD12 must be 0 to meet
1304 * THDN and Dynamic Range spec.
1307 regmap_write(cs43130->regmap, CS43130_DXD12, 0);
1309 case CS43131_CHIP_ID:
1310 case CS43198_CHIP_ID:
1311 usleep_range(12000, 12010);
1312 regmap_write(cs43130->regmap, CS43130_DXD13, 0);
1316 regmap_write(cs43130->regmap, CS43130_DXD1, 0);
1318 case SND_SOC_DAPM_POST_PMD:
1319 switch (cs43130->dev_id) {
1320 case CS43130_CHIP_ID:
1321 case CS4399_CHIP_ID:
1322 regmap_multi_reg_write(cs43130->regmap, dac_postpmd_seq,
1323 ARRAY_SIZE(dac_postpmd_seq));
1328 dev_err(component->dev, "Invalid DAC event = 0x%x\n", event);
1334 static const struct reg_sequence hpin_prepmd_seq[] = {
1335 {CS43130_DXD1, 0x99},
1336 {CS43130_DXD15, 0x64},
1342 static const struct reg_sequence hpin_postpmu_seq[] = {
1343 {CS43130_DXD1, 0x99},
1345 {CS43130_DXD14, 0xDC},
1346 {CS43130_DXD15, 0xE4},
1350 static int cs43130_hpin_event(struct snd_soc_dapm_widget *w,
1351 struct snd_kcontrol *kcontrol, int event)
1353 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1354 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1357 case SND_SOC_DAPM_POST_PMD:
1358 regmap_multi_reg_write(cs43130->regmap, hpin_prepmd_seq,
1359 ARRAY_SIZE(hpin_prepmd_seq));
1361 case SND_SOC_DAPM_PRE_PMU:
1362 regmap_multi_reg_write(cs43130->regmap, hpin_postpmu_seq,
1363 ARRAY_SIZE(hpin_postpmu_seq));
1366 dev_err(component->dev, "Invalid HPIN event = 0x%x\n", event);
1372 static const struct snd_soc_dapm_widget digital_hp_widgets[] = {
1373 SND_SOC_DAPM_OUTPUT("HPOUTA"),
1374 SND_SOC_DAPM_OUTPUT("HPOUTB"),
1376 SND_SOC_DAPM_AIF_IN_E("ASPIN PCM", NULL, 0, CS43130_PWDN_CTL,
1377 CS43130_PDN_ASP_SHIFT, 1, cs43130_pcm_event,
1378 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1379 SND_SOC_DAPM_PRE_PMD)),
1381 SND_SOC_DAPM_AIF_IN_E("ASPIN DoP", NULL, 0, CS43130_PWDN_CTL,
1382 CS43130_PDN_ASP_SHIFT, 1, cs43130_dsd_event,
1383 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1384 SND_SOC_DAPM_PRE_PMD)),
1386 SND_SOC_DAPM_AIF_IN_E("XSPIN DoP", NULL, 0, CS43130_PWDN_CTL,
1387 CS43130_PDN_XSP_SHIFT, 1, cs43130_dsd_event,
1388 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1389 SND_SOC_DAPM_PRE_PMD)),
1391 SND_SOC_DAPM_AIF_IN_E("XSPIN DSD", NULL, 0, CS43130_PWDN_CTL,
1392 CS43130_PDN_DSDIF_SHIFT, 1, cs43130_dsd_event,
1393 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1394 SND_SOC_DAPM_PRE_PMD)),
1396 SND_SOC_DAPM_DAC("DSD", NULL, CS43130_DSD_PATH_CTL_2,
1397 CS43130_DSD_EN_SHIFT, 0),
1399 SND_SOC_DAPM_DAC_E("HiFi DAC", NULL, CS43130_PWDN_CTL,
1400 CS43130_PDN_HP_SHIFT, 1, cs43130_dac_event,
1401 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1402 SND_SOC_DAPM_POST_PMD)),
1405 static const struct snd_soc_dapm_widget analog_hp_widgets[] = {
1406 SND_SOC_DAPM_DAC_E("Analog Playback", NULL, CS43130_HP_OUT_CTL_1,
1407 CS43130_HP_IN_EN_SHIFT, 0, cs43130_hpin_event,
1408 (SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)),
1411 static struct snd_soc_dapm_widget all_hp_widgets[
1412 ARRAY_SIZE(digital_hp_widgets) +
1413 ARRAY_SIZE(analog_hp_widgets)];
1415 static const struct snd_soc_dapm_route digital_hp_routes[] = {
1416 {"ASPIN PCM", NULL, "ASP PCM Playback"},
1417 {"ASPIN DoP", NULL, "ASP DoP Playback"},
1418 {"XSPIN DoP", NULL, "XSP DoP Playback"},
1419 {"XSPIN DSD", NULL, "XSP DSD Playback"},
1420 {"DSD", NULL, "ASPIN DoP"},
1421 {"DSD", NULL, "XSPIN DoP"},
1422 {"DSD", NULL, "XSPIN DSD"},
1423 {"HiFi DAC", NULL, "ASPIN PCM"},
1424 {"HiFi DAC", NULL, "DSD"},
1425 {"HPOUTA", NULL, "HiFi DAC"},
1426 {"HPOUTB", NULL, "HiFi DAC"},
1429 static const struct snd_soc_dapm_route analog_hp_routes[] = {
1430 {"HPOUTA", NULL, "Analog Playback"},
1431 {"HPOUTB", NULL, "Analog Playback"},
1434 static struct snd_soc_dapm_route all_hp_routes[
1435 ARRAY_SIZE(digital_hp_routes) +
1436 ARRAY_SIZE(analog_hp_routes)];
1438 static const unsigned int cs43130_asp_src_rates[] = {
1439 32000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
1442 static const struct snd_pcm_hw_constraint_list cs43130_asp_constraints = {
1443 .count = ARRAY_SIZE(cs43130_asp_src_rates),
1444 .list = cs43130_asp_src_rates,
1447 static int cs43130_pcm_startup(struct snd_pcm_substream *substream,
1448 struct snd_soc_dai *dai)
1450 return snd_pcm_hw_constraint_list(substream->runtime, 0,
1451 SNDRV_PCM_HW_PARAM_RATE,
1452 &cs43130_asp_constraints);
1455 static const unsigned int cs43130_dop_src_rates[] = {
1459 static const struct snd_pcm_hw_constraint_list cs43130_dop_constraints = {
1460 .count = ARRAY_SIZE(cs43130_dop_src_rates),
1461 .list = cs43130_dop_src_rates,
1464 static int cs43130_dop_startup(struct snd_pcm_substream *substream,
1465 struct snd_soc_dai *dai)
1467 return snd_pcm_hw_constraint_list(substream->runtime, 0,
1468 SNDRV_PCM_HW_PARAM_RATE,
1469 &cs43130_dop_constraints);
1472 static int cs43130_pcm_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1474 struct snd_soc_component *component = codec_dai->component;
1475 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1477 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1478 case SND_SOC_DAIFMT_CBS_CFS:
1479 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
1481 case SND_SOC_DAIFMT_CBM_CFM:
1482 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
1485 dev_err(component->dev, "unsupported mode\n");
1489 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1490 case SND_SOC_DAIFMT_I2S:
1491 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_I2S;
1493 case SND_SOC_DAIFMT_LEFT_J:
1494 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_LEFT_J;
1496 case SND_SOC_DAIFMT_DSP_A:
1497 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_DSP_A;
1499 case SND_SOC_DAIFMT_DSP_B:
1500 cs43130->dais[codec_dai->id].dai_format = SND_SOC_DAIFMT_DSP_B;
1503 dev_err(component->dev,
1504 "unsupported audio format\n");
1508 dev_dbg(component->dev, "dai_id = %d, dai_mode = %u, dai_format = %u\n",
1510 cs43130->dais[codec_dai->id].dai_mode,
1511 cs43130->dais[codec_dai->id].dai_format);
1516 static int cs43130_dsd_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1518 struct snd_soc_component *component = codec_dai->component;
1519 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1521 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1522 case SND_SOC_DAIFMT_CBS_CFS:
1523 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBS_CFS;
1525 case SND_SOC_DAIFMT_CBM_CFM:
1526 cs43130->dais[codec_dai->id].dai_mode = SND_SOC_DAIFMT_CBM_CFM;
1529 dev_err(component->dev, "Unsupported DAI format.\n");
1533 dev_dbg(component->dev, "dai_mode = 0x%x\n",
1534 cs43130->dais[codec_dai->id].dai_mode);
1539 static int cs43130_set_sysclk(struct snd_soc_dai *codec_dai,
1540 int clk_id, unsigned int freq, int dir)
1542 struct snd_soc_component *component = codec_dai->component;
1543 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1545 cs43130->dais[codec_dai->id].sclk = freq;
1546 dev_dbg(component->dev, "dai_id = %d, sclk = %u\n", codec_dai->id,
1547 cs43130->dais[codec_dai->id].sclk);
1552 static const struct snd_soc_dai_ops cs43130_pcm_ops = {
1553 .startup = cs43130_pcm_startup,
1554 .hw_params = cs43130_hw_params,
1555 .hw_free = cs43130_hw_free,
1556 .set_sysclk = cs43130_set_sysclk,
1557 .set_fmt = cs43130_pcm_set_fmt,
1560 static const struct snd_soc_dai_ops cs43130_dop_ops = {
1561 .startup = cs43130_dop_startup,
1562 .hw_params = cs43130_hw_params,
1563 .hw_free = cs43130_hw_free,
1564 .set_sysclk = cs43130_set_sysclk,
1565 .set_fmt = cs43130_pcm_set_fmt,
1568 static const struct snd_soc_dai_ops cs43130_dsd_ops = {
1569 .startup = cs43130_dop_startup,
1570 .hw_params = cs43130_dsd_hw_params,
1571 .hw_free = cs43130_hw_free,
1572 .set_fmt = cs43130_dsd_set_fmt,
1575 static struct snd_soc_dai_driver cs43130_dai[] = {
1577 .name = "cs43130-asp-pcm",
1578 .id = CS43130_ASP_PCM_DAI,
1580 .stream_name = "ASP PCM Playback",
1583 .rates = SNDRV_PCM_RATE_KNOT,
1584 .formats = CS43130_PCM_FORMATS,
1586 .ops = &cs43130_pcm_ops,
1587 .symmetric_rates = 1,
1590 .name = "cs43130-asp-dop",
1591 .id = CS43130_ASP_DOP_DAI,
1593 .stream_name = "ASP DoP Playback",
1596 .rates = SNDRV_PCM_RATE_KNOT,
1597 .formats = CS43130_DOP_FORMATS,
1599 .ops = &cs43130_dop_ops,
1600 .symmetric_rates = 1,
1603 .name = "cs43130-xsp-dop",
1604 .id = CS43130_XSP_DOP_DAI,
1606 .stream_name = "XSP DoP Playback",
1609 .rates = SNDRV_PCM_RATE_KNOT,
1610 .formats = CS43130_DOP_FORMATS,
1612 .ops = &cs43130_dop_ops,
1613 .symmetric_rates = 1,
1616 .name = "cs43130-xsp-dsd",
1617 .id = CS43130_XSP_DSD_DAI,
1619 .stream_name = "XSP DSD Playback",
1622 .rates = SNDRV_PCM_RATE_KNOT,
1623 .formats = CS43130_DOP_FORMATS,
1625 .ops = &cs43130_dsd_ops,
1630 static int cs43130_component_set_sysclk(struct snd_soc_component *component,
1631 int clk_id, int source, unsigned int freq,
1634 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
1636 dev_dbg(component->dev, "clk_id = %d, source = %d, freq = %d, dir = %d\n",
1637 clk_id, source, freq, dir);
1640 case CS43130_MCLK_22M:
1641 case CS43130_MCLK_24M:
1642 cs43130->mclk = freq;
1645 dev_err(component->dev, "Invalid MCLK INT freq: %u\n", freq);
1649 if (source == CS43130_MCLK_SRC_EXT) {
1650 cs43130->pll_bypass = true;
1652 dev_err(component->dev, "Invalid MCLK source\n");
1659 static inline u16 cs43130_get_ac_reg_val(u16 ac_freq)
1661 /* AC freq is counted in 5.94Hz step. */
1665 static int cs43130_show_dc(struct device *dev, char *buf, u8 ch)
1667 struct i2c_client *client = to_i2c_client(dev);
1668 struct cs43130_private *cs43130 = i2c_get_clientdata(client);
1670 if (!cs43130->hpload_done)
1671 return scnprintf(buf, PAGE_SIZE, "NO_HPLOAD\n");
1673 return scnprintf(buf, PAGE_SIZE, "%u\n",
1674 cs43130->hpload_dc[ch]);
1677 static ssize_t cs43130_show_dc_l(struct device *dev,
1678 struct device_attribute *attr, char *buf)
1680 return cs43130_show_dc(dev, buf, HP_LEFT);
1683 static ssize_t cs43130_show_dc_r(struct device *dev,
1684 struct device_attribute *attr, char *buf)
1686 return cs43130_show_dc(dev, buf, HP_RIGHT);
1689 static u16 const cs43130_ac_freq[CS43130_AC_FREQ] = {
1702 static int cs43130_show_ac(struct device *dev, char *buf, u8 ch)
1705 struct i2c_client *client = to_i2c_client(dev);
1706 struct cs43130_private *cs43130 = i2c_get_clientdata(client);
1708 if (cs43130->hpload_done && cs43130->ac_meas) {
1709 for (i = 0; i < ARRAY_SIZE(cs43130_ac_freq); i++) {
1710 tmp = scnprintf(buf + j, PAGE_SIZE - j, "%u\n",
1711 cs43130->hpload_ac[i][ch]);
1720 return scnprintf(buf, PAGE_SIZE, "NO_HPLOAD\n");
1724 static ssize_t cs43130_show_ac_l(struct device *dev,
1725 struct device_attribute *attr, char *buf)
1727 return cs43130_show_ac(dev, buf, HP_LEFT);
1730 static ssize_t cs43130_show_ac_r(struct device *dev,
1731 struct device_attribute *attr, char *buf)
1733 return cs43130_show_ac(dev, buf, HP_RIGHT);
1736 static DEVICE_ATTR(hpload_dc_l, 0444, cs43130_show_dc_l, NULL);
1737 static DEVICE_ATTR(hpload_dc_r, 0444, cs43130_show_dc_r, NULL);
1738 static DEVICE_ATTR(hpload_ac_l, 0444, cs43130_show_ac_l, NULL);
1739 static DEVICE_ATTR(hpload_ac_r, 0444, cs43130_show_ac_r, NULL);
1741 static struct reg_sequence hp_en_cal_seq[] = {
1742 {CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
1743 {CS43130_HP_MEAS_LOAD_1, 0},
1744 {CS43130_HP_MEAS_LOAD_2, 0},
1745 {CS43130_INT_MASK_4, 0},
1746 {CS43130_DXD1, 0x99},
1747 {CS43130_DXD16, 0xBB},
1748 {CS43130_DXD12, 0x01},
1749 {CS43130_DXD19, 0xCB},
1750 {CS43130_DXD17, 0x95},
1751 {CS43130_DXD18, 0x0B},
1753 {CS43130_HP_LOAD_1, 0x80},
1756 static struct reg_sequence hp_en_cal_seq2[] = {
1757 {CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
1758 {CS43130_HP_MEAS_LOAD_1, 0},
1759 {CS43130_HP_MEAS_LOAD_2, 0},
1760 {CS43130_INT_MASK_4, 0},
1761 {CS43130_HP_LOAD_1, 0x80},
1764 static struct reg_sequence hp_dis_cal_seq[] = {
1765 {CS43130_HP_LOAD_1, 0x80},
1766 {CS43130_DXD1, 0x99},
1769 {CS43130_HP_LOAD_1, 0},
1772 static struct reg_sequence hp_dis_cal_seq2[] = {
1773 {CS43130_HP_LOAD_1, 0x80},
1774 {CS43130_HP_LOAD_1, 0},
1777 static struct reg_sequence hp_dc_ch_l_seq[] = {
1778 {CS43130_DXD1, 0x99},
1779 {CS43130_DXD19, 0x0A},
1780 {CS43130_DXD17, 0x93},
1781 {CS43130_DXD18, 0x0A},
1783 {CS43130_HP_LOAD_1, 0x80},
1784 {CS43130_HP_LOAD_1, 0x81},
1787 static struct reg_sequence hp_dc_ch_l_seq2[] = {
1788 {CS43130_HP_LOAD_1, 0x80},
1789 {CS43130_HP_LOAD_1, 0x81},
1792 static struct reg_sequence hp_dc_ch_r_seq[] = {
1793 {CS43130_DXD1, 0x99},
1794 {CS43130_DXD19, 0x8A},
1795 {CS43130_DXD17, 0x15},
1796 {CS43130_DXD18, 0x06},
1798 {CS43130_HP_LOAD_1, 0x90},
1799 {CS43130_HP_LOAD_1, 0x91},
1802 static struct reg_sequence hp_dc_ch_r_seq2[] = {
1803 {CS43130_HP_LOAD_1, 0x90},
1804 {CS43130_HP_LOAD_1, 0x91},
1807 static struct reg_sequence hp_ac_ch_l_seq[] = {
1808 {CS43130_DXD1, 0x99},
1809 {CS43130_DXD19, 0x0A},
1810 {CS43130_DXD17, 0x93},
1811 {CS43130_DXD18, 0x0A},
1813 {CS43130_HP_LOAD_1, 0x80},
1814 {CS43130_HP_LOAD_1, 0x82},
1817 static struct reg_sequence hp_ac_ch_l_seq2[] = {
1818 {CS43130_HP_LOAD_1, 0x80},
1819 {CS43130_HP_LOAD_1, 0x82},
1822 static struct reg_sequence hp_ac_ch_r_seq[] = {
1823 {CS43130_DXD1, 0x99},
1824 {CS43130_DXD19, 0x8A},
1825 {CS43130_DXD17, 0x15},
1826 {CS43130_DXD18, 0x06},
1828 {CS43130_HP_LOAD_1, 0x90},
1829 {CS43130_HP_LOAD_1, 0x92},
1832 static struct reg_sequence hp_ac_ch_r_seq2[] = {
1833 {CS43130_HP_LOAD_1, 0x90},
1834 {CS43130_HP_LOAD_1, 0x92},
1837 static struct reg_sequence hp_cln_seq[] = {
1838 {CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
1839 {CS43130_HP_MEAS_LOAD_1, 0},
1840 {CS43130_HP_MEAS_LOAD_2, 0},
1843 struct reg_sequences {
1844 struct reg_sequence *seq;
1849 static struct reg_sequences hpload_seq1[] = {
1851 .seq = hp_en_cal_seq,
1852 .size = ARRAY_SIZE(hp_en_cal_seq),
1853 .msk = CS43130_HPLOAD_ON_INT,
1856 .seq = hp_dc_ch_l_seq,
1857 .size = ARRAY_SIZE(hp_dc_ch_l_seq),
1858 .msk = CS43130_HPLOAD_DC_INT,
1861 .seq = hp_ac_ch_l_seq,
1862 .size = ARRAY_SIZE(hp_ac_ch_l_seq),
1863 .msk = CS43130_HPLOAD_AC_INT,
1866 .seq = hp_dis_cal_seq,
1867 .size = ARRAY_SIZE(hp_dis_cal_seq),
1868 .msk = CS43130_HPLOAD_OFF_INT,
1871 .seq = hp_en_cal_seq,
1872 .size = ARRAY_SIZE(hp_en_cal_seq),
1873 .msk = CS43130_HPLOAD_ON_INT,
1876 .seq = hp_dc_ch_r_seq,
1877 .size = ARRAY_SIZE(hp_dc_ch_r_seq),
1878 .msk = CS43130_HPLOAD_DC_INT,
1881 .seq = hp_ac_ch_r_seq,
1882 .size = ARRAY_SIZE(hp_ac_ch_r_seq),
1883 .msk = CS43130_HPLOAD_AC_INT,
1887 static struct reg_sequences hpload_seq2[] = {
1889 .seq = hp_en_cal_seq2,
1890 .size = ARRAY_SIZE(hp_en_cal_seq2),
1891 .msk = CS43130_HPLOAD_ON_INT,
1894 .seq = hp_dc_ch_l_seq2,
1895 .size = ARRAY_SIZE(hp_dc_ch_l_seq2),
1896 .msk = CS43130_HPLOAD_DC_INT,
1899 .seq = hp_ac_ch_l_seq2,
1900 .size = ARRAY_SIZE(hp_ac_ch_l_seq2),
1901 .msk = CS43130_HPLOAD_AC_INT,
1904 .seq = hp_dis_cal_seq2,
1905 .size = ARRAY_SIZE(hp_dis_cal_seq2),
1906 .msk = CS43130_HPLOAD_OFF_INT,
1909 .seq = hp_en_cal_seq2,
1910 .size = ARRAY_SIZE(hp_en_cal_seq2),
1911 .msk = CS43130_HPLOAD_ON_INT,
1914 .seq = hp_dc_ch_r_seq2,
1915 .size = ARRAY_SIZE(hp_dc_ch_r_seq2),
1916 .msk = CS43130_HPLOAD_DC_INT,
1919 .seq = hp_ac_ch_r_seq2,
1920 .size = ARRAY_SIZE(hp_ac_ch_r_seq2),
1921 .msk = CS43130_HPLOAD_AC_INT,
1925 static int cs43130_update_hpload(unsigned int msk, int ac_idx,
1926 struct cs43130_private *cs43130)
1928 bool left_ch = true;
1932 struct snd_soc_component *component = cs43130->component;
1935 case CS43130_HPLOAD_DC_INT:
1936 case CS43130_HPLOAD_AC_INT:
1942 regmap_read(cs43130->regmap, CS43130_HP_LOAD_1, ®);
1943 if (reg & CS43130_HPLOAD_CHN_SEL)
1946 if (msk == CS43130_HPLOAD_DC_INT)
1947 addr = CS43130_HP_DC_STAT_1;
1949 addr = CS43130_HP_AC_STAT_1;
1951 regmap_read(cs43130->regmap, addr, ®);
1952 impedance = reg >> 3;
1953 regmap_read(cs43130->regmap, addr + 1, ®);
1954 impedance |= reg << 5;
1956 if (msk == CS43130_HPLOAD_DC_INT) {
1958 cs43130->hpload_dc[HP_LEFT] = impedance;
1960 cs43130->hpload_dc[HP_RIGHT] = impedance;
1962 dev_dbg(component->dev, "HP DC impedance (Ch %u): %u\n", !left_ch,
1966 cs43130->hpload_ac[ac_idx][HP_LEFT] = impedance;
1968 cs43130->hpload_ac[ac_idx][HP_RIGHT] = impedance;
1970 dev_dbg(component->dev, "HP AC (%u Hz) impedance (Ch %u): %u\n",
1971 cs43130->ac_freq[ac_idx], !left_ch, impedance);
1977 static int cs43130_hpload_proc(struct cs43130_private *cs43130,
1978 struct reg_sequence *seq, int seq_size,
1979 unsigned int rslt_msk, int ac_idx)
1984 struct snd_soc_component *component = cs43130->component;
1986 reinit_completion(&cs43130->hpload_evt);
1988 if (rslt_msk == CS43130_HPLOAD_AC_INT) {
1989 ac_reg_val = cs43130_get_ac_reg_val(cs43130->ac_freq[ac_idx]);
1990 regmap_update_bits(cs43130->regmap, CS43130_HP_LOAD_1,
1991 CS43130_HPLOAD_AC_START, 0);
1992 regmap_update_bits(cs43130->regmap, CS43130_HP_MEAS_LOAD_1,
1993 CS43130_HP_MEAS_LOAD_MASK,
1994 ac_reg_val >> CS43130_HP_MEAS_LOAD_1_SHIFT);
1995 regmap_update_bits(cs43130->regmap, CS43130_HP_MEAS_LOAD_2,
1996 CS43130_HP_MEAS_LOAD_MASK,
1997 ac_reg_val >> CS43130_HP_MEAS_LOAD_2_SHIFT);
2000 regmap_multi_reg_write(cs43130->regmap, seq,
2003 ret = wait_for_completion_timeout(&cs43130->hpload_evt,
2004 msecs_to_jiffies(1000));
2005 regmap_read(cs43130->regmap, CS43130_INT_MASK_4, &msk);
2007 dev_err(component->dev, "Timeout waiting for HPLOAD interrupt\n");
2011 dev_dbg(component->dev, "HP load stat: %x, INT_MASK_4: %x\n",
2012 cs43130->hpload_stat, msk);
2013 if ((cs43130->hpload_stat & (CS43130_HPLOAD_NO_DC_INT |
2014 CS43130_HPLOAD_UNPLUG_INT |
2015 CS43130_HPLOAD_OOR_INT)) ||
2016 !(cs43130->hpload_stat & rslt_msk)) {
2017 dev_dbg(component->dev, "HP load measure failed\n");
2024 static const struct reg_sequence hv_seq[][2] = {
2026 {CS43130_CLASS_H_CTL, 0x1C},
2027 {CS43130_HP_OUT_CTL_1, 0x10},
2030 {CS43130_CLASS_H_CTL, 0x1E},
2031 {CS43130_HP_OUT_CTL_1, 0x20},
2034 {CS43130_CLASS_H_CTL, 0x1E},
2035 {CS43130_HP_OUT_CTL_1, 0x30},
2039 static int cs43130_set_hv(struct regmap *regmap, u16 hpload_dc,
2040 const u16 *dc_threshold)
2044 for (i = 0; i < CS43130_DC_THRESHOLD; i++) {
2045 if (hpload_dc <= dc_threshold[i])
2049 regmap_multi_reg_write(regmap, hv_seq[i], ARRAY_SIZE(hv_seq[i]));
2054 static void cs43130_imp_meas(struct work_struct *wk)
2056 unsigned int reg, seq_size;
2058 struct cs43130_private *cs43130;
2059 struct snd_soc_component *component;
2060 struct reg_sequences *hpload_seq;
2062 cs43130 = container_of(wk, struct cs43130_private, work);
2063 component = cs43130->component;
2068 cs43130->hpload_done = false;
2070 mutex_lock(&cs43130->clk_mutex);
2071 if (!cs43130->clk_req) {
2072 /* clk not in use */
2073 cs43130_set_pll(component, 0, 0, cs43130->mclk, CS43130_MCLK_22M);
2074 if (cs43130->pll_bypass)
2075 cs43130_change_clksrc(component, CS43130_MCLK_SRC_EXT);
2077 cs43130_change_clksrc(component, CS43130_MCLK_SRC_PLL);
2081 mutex_unlock(&cs43130->clk_mutex);
2083 regmap_read(cs43130->regmap, CS43130_INT_STATUS_4, ®);
2085 switch (cs43130->dev_id) {
2086 case CS43130_CHIP_ID:
2087 hpload_seq = hpload_seq1;
2088 seq_size = ARRAY_SIZE(hpload_seq1);
2090 case CS43131_CHIP_ID:
2091 hpload_seq = hpload_seq2;
2092 seq_size = ARRAY_SIZE(hpload_seq2);
2095 WARN(1, "Invalid dev_id for meas: %d", cs43130->dev_id);
2101 while (i < seq_size) {
2102 ret = cs43130_hpload_proc(cs43130, hpload_seq[i].seq,
2104 hpload_seq[i].msk, ac_idx);
2108 cs43130_update_hpload(hpload_seq[i].msk, ac_idx, cs43130);
2110 if (cs43130->ac_meas &&
2111 hpload_seq[i].msk == CS43130_HPLOAD_AC_INT &&
2112 ac_idx < CS43130_AC_FREQ - 1) {
2119 cs43130->hpload_done = true;
2121 if (cs43130->hpload_dc[HP_LEFT] >= CS43130_LINEOUT_LOAD)
2122 snd_soc_jack_report(&cs43130->jack, CS43130_JACK_LINEOUT,
2125 snd_soc_jack_report(&cs43130->jack, CS43130_JACK_HEADPHONE,
2128 dev_dbg(component->dev, "Set HP output control. DC threshold\n");
2129 for (i = 0; i < CS43130_DC_THRESHOLD; i++)
2130 dev_dbg(component->dev, "DC threshold[%d]: %u.\n", i,
2131 cs43130->dc_threshold[i]);
2133 cs43130_set_hv(cs43130->regmap, cs43130->hpload_dc[HP_LEFT],
2134 cs43130->dc_threshold);
2137 switch (cs43130->dev_id) {
2138 case CS43130_CHIP_ID:
2139 cs43130_hpload_proc(cs43130, hp_dis_cal_seq,
2140 ARRAY_SIZE(hp_dis_cal_seq),
2141 CS43130_HPLOAD_OFF_INT, ac_idx);
2143 case CS43131_CHIP_ID:
2144 cs43130_hpload_proc(cs43130, hp_dis_cal_seq2,
2145 ARRAY_SIZE(hp_dis_cal_seq2),
2146 CS43130_HPLOAD_OFF_INT, ac_idx);
2150 regmap_multi_reg_write(cs43130->regmap, hp_cln_seq,
2151 ARRAY_SIZE(hp_cln_seq));
2153 mutex_lock(&cs43130->clk_mutex);
2155 /* clk not in use */
2156 if (!cs43130->clk_req)
2157 cs43130_change_clksrc(component, CS43130_MCLK_SRC_RCO);
2158 mutex_unlock(&cs43130->clk_mutex);
2161 static irqreturn_t cs43130_irq_thread(int irq, void *data)
2163 struct cs43130_private *cs43130 = (struct cs43130_private *)data;
2164 struct snd_soc_component *component = cs43130->component;
2165 unsigned int stickies[CS43130_NUM_INT];
2166 unsigned int irq_occurrence = 0;
2167 unsigned int masks[CS43130_NUM_INT];
2170 for (i = 0; i < ARRAY_SIZE(stickies); i++) {
2171 regmap_read(cs43130->regmap, CS43130_INT_STATUS_1 + i,
2173 regmap_read(cs43130->regmap, CS43130_INT_MASK_1 + i,
2177 for (i = 0; i < ARRAY_SIZE(stickies); i++) {
2178 stickies[i] = stickies[i] & (~masks[i]);
2179 for (j = 0; j < 8; j++)
2180 irq_occurrence += (stickies[i] >> j) & 1;
2182 dev_dbg(component->dev, "number of interrupts occurred (%u)\n",
2185 if (!irq_occurrence)
2188 if (stickies[0] & CS43130_XTAL_RDY_INT) {
2189 complete(&cs43130->xtal_rdy);
2193 if (stickies[0] & CS43130_PLL_RDY_INT) {
2194 complete(&cs43130->pll_rdy);
2198 if (stickies[3] & CS43130_HPLOAD_NO_DC_INT) {
2199 cs43130->hpload_stat = stickies[3];
2200 dev_err(component->dev,
2201 "DC load has not completed before AC load (%x)\n",
2202 cs43130->hpload_stat);
2203 complete(&cs43130->hpload_evt);
2207 if (stickies[3] & CS43130_HPLOAD_UNPLUG_INT) {
2208 cs43130->hpload_stat = stickies[3];
2209 dev_err(component->dev, "HP unplugged during measurement (%x)\n",
2210 cs43130->hpload_stat);
2211 complete(&cs43130->hpload_evt);
2215 if (stickies[3] & CS43130_HPLOAD_OOR_INT) {
2216 cs43130->hpload_stat = stickies[3];
2217 dev_err(component->dev, "HP load out of range (%x)\n",
2218 cs43130->hpload_stat);
2219 complete(&cs43130->hpload_evt);
2223 if (stickies[3] & CS43130_HPLOAD_AC_INT) {
2224 cs43130->hpload_stat = stickies[3];
2225 dev_dbg(component->dev, "HP AC load measurement done (%x)\n",
2226 cs43130->hpload_stat);
2227 complete(&cs43130->hpload_evt);
2231 if (stickies[3] & CS43130_HPLOAD_DC_INT) {
2232 cs43130->hpload_stat = stickies[3];
2233 dev_dbg(component->dev, "HP DC load measurement done (%x)\n",
2234 cs43130->hpload_stat);
2235 complete(&cs43130->hpload_evt);
2239 if (stickies[3] & CS43130_HPLOAD_ON_INT) {
2240 cs43130->hpload_stat = stickies[3];
2241 dev_dbg(component->dev, "HP load state machine on done (%x)\n",
2242 cs43130->hpload_stat);
2243 complete(&cs43130->hpload_evt);
2247 if (stickies[3] & CS43130_HPLOAD_OFF_INT) {
2248 cs43130->hpload_stat = stickies[3];
2249 dev_dbg(component->dev, "HP load state machine off done (%x)\n",
2250 cs43130->hpload_stat);
2251 complete(&cs43130->hpload_evt);
2255 if (stickies[0] & CS43130_XTAL_ERR_INT) {
2256 dev_err(component->dev, "Crystal err: clock is not running\n");
2260 if (stickies[0] & CS43130_HP_UNPLUG_INT) {
2261 dev_dbg(component->dev, "HP unplugged\n");
2262 cs43130->hpload_done = false;
2263 snd_soc_jack_report(&cs43130->jack, 0, CS43130_JACK_MASK);
2267 if (stickies[0] & CS43130_HP_PLUG_INT) {
2268 if (cs43130->dc_meas && !cs43130->hpload_done &&
2269 !work_busy(&cs43130->work)) {
2270 dev_dbg(component->dev, "HP load queue work\n");
2271 queue_work(cs43130->wq, &cs43130->work);
2274 snd_soc_jack_report(&cs43130->jack, SND_JACK_MECHANICAL,
2282 static int cs43130_probe(struct snd_soc_component *component)
2285 struct cs43130_private *cs43130 = snd_soc_component_get_drvdata(component);
2286 struct snd_soc_card *card = component->card;
2289 cs43130->component = component;
2291 if (cs43130->xtal_ibias != CS43130_XTAL_UNUSED) {
2292 regmap_update_bits(cs43130->regmap, CS43130_CRYSTAL_SET,
2293 CS43130_XTAL_IBIAS_MASK,
2294 cs43130->xtal_ibias);
2295 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2296 CS43130_XTAL_ERR_INT, 0);
2299 ret = snd_soc_card_jack_new(card, "Headphone", CS43130_JACK_MASK,
2300 &cs43130->jack, NULL, 0);
2302 dev_err(component->dev, "Cannot create jack\n");
2306 cs43130->hpload_done = false;
2307 if (cs43130->dc_meas) {
2308 ret = device_create_file(component->dev, &dev_attr_hpload_dc_l);
2312 ret = device_create_file(component->dev, &dev_attr_hpload_dc_r);
2316 ret = device_create_file(component->dev, &dev_attr_hpload_ac_l);
2320 ret = device_create_file(component->dev, &dev_attr_hpload_ac_r);
2324 cs43130->wq = create_singlethread_workqueue("cs43130_hp");
2327 INIT_WORK(&cs43130->work, cs43130_imp_meas);
2330 regmap_read(cs43130->regmap, CS43130_INT_STATUS_1, ®);
2331 regmap_read(cs43130->regmap, CS43130_HP_STATUS, ®);
2332 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2333 CS43130_HP_PLUG_INT | CS43130_HP_UNPLUG_INT, 0);
2334 regmap_update_bits(cs43130->regmap, CS43130_HP_DETECT,
2335 CS43130_HP_DETECT_CTRL_MASK, 0);
2336 regmap_update_bits(cs43130->regmap, CS43130_HP_DETECT,
2337 CS43130_HP_DETECT_CTRL_MASK,
2338 CS43130_HP_DETECT_CTRL_MASK);
2343 static struct snd_soc_component_driver soc_component_dev_cs43130 = {
2344 .probe = cs43130_probe,
2345 .controls = cs43130_snd_controls,
2346 .num_controls = ARRAY_SIZE(cs43130_snd_controls),
2347 .set_sysclk = cs43130_component_set_sysclk,
2348 .set_pll = cs43130_set_pll,
2350 .use_pmdown_time = 1,
2352 .non_legacy_dai_naming = 1,
2355 static const struct regmap_config cs43130_regmap = {
2360 .max_register = CS43130_LASTREG,
2361 .reg_defaults = cs43130_reg_defaults,
2362 .num_reg_defaults = ARRAY_SIZE(cs43130_reg_defaults),
2363 .readable_reg = cs43130_readable_register,
2364 .precious_reg = cs43130_precious_register,
2365 .volatile_reg = cs43130_volatile_register,
2366 .cache_type = REGCACHE_RBTREE,
2367 /* needed for regcache_sync */
2368 .use_single_read = true,
2369 .use_single_write = true,
2372 static u16 const cs43130_dc_threshold[CS43130_DC_THRESHOLD] = {
2377 static int cs43130_handle_device_data(struct i2c_client *i2c_client,
2378 struct cs43130_private *cs43130)
2380 struct device_node *np = i2c_client->dev.of_node;
2384 if (of_property_read_u32(np, "cirrus,xtal-ibias", &val) < 0) {
2385 /* Crystal is unused. System clock is used for external MCLK */
2386 cs43130->xtal_ibias = CS43130_XTAL_UNUSED;
2392 cs43130->xtal_ibias = CS43130_XTAL_IBIAS_7_5UA;
2395 cs43130->xtal_ibias = CS43130_XTAL_IBIAS_12_5UA;
2398 cs43130->xtal_ibias = CS43130_XTAL_IBIAS_15UA;
2401 dev_err(&i2c_client->dev,
2402 "Invalid cirrus,xtal-ibias value: %d\n", val);
2406 cs43130->dc_meas = of_property_read_bool(np, "cirrus,dc-measure");
2407 cs43130->ac_meas = of_property_read_bool(np, "cirrus,ac-measure");
2409 if (of_property_read_u16_array(np, "cirrus,ac-freq", cs43130->ac_freq,
2410 CS43130_AC_FREQ) < 0) {
2411 for (i = 0; i < CS43130_AC_FREQ; i++)
2412 cs43130->ac_freq[i] = cs43130_ac_freq[i];
2415 if (of_property_read_u16_array(np, "cirrus,dc-threshold",
2416 cs43130->dc_threshold,
2417 CS43130_DC_THRESHOLD) < 0) {
2418 for (i = 0; i < CS43130_DC_THRESHOLD; i++)
2419 cs43130->dc_threshold[i] = cs43130_dc_threshold[i];
2425 static int cs43130_i2c_probe(struct i2c_client *client,
2426 const struct i2c_device_id *id)
2428 struct cs43130_private *cs43130;
2430 unsigned int devid = 0;
2434 cs43130 = devm_kzalloc(&client->dev, sizeof(*cs43130), GFP_KERNEL);
2438 i2c_set_clientdata(client, cs43130);
2440 cs43130->regmap = devm_regmap_init_i2c(client, &cs43130_regmap);
2441 if (IS_ERR(cs43130->regmap)) {
2442 ret = PTR_ERR(cs43130->regmap);
2446 if (client->dev.of_node) {
2447 ret = cs43130_handle_device_data(client, cs43130);
2451 for (i = 0; i < ARRAY_SIZE(cs43130->supplies); i++)
2452 cs43130->supplies[i].supply = cs43130_supply_names[i];
2454 ret = devm_regulator_bulk_get(&client->dev,
2455 ARRAY_SIZE(cs43130->supplies),
2458 dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
2461 ret = regulator_bulk_enable(ARRAY_SIZE(cs43130->supplies),
2464 dev_err(&client->dev, "Failed to enable supplies: %d\n", ret);
2468 cs43130->reset_gpio = devm_gpiod_get_optional(&client->dev,
2469 "reset", GPIOD_OUT_LOW);
2470 if (IS_ERR(cs43130->reset_gpio))
2471 return PTR_ERR(cs43130->reset_gpio);
2473 gpiod_set_value_cansleep(cs43130->reset_gpio, 1);
2475 usleep_range(2000, 2050);
2477 ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, ®);
2479 devid = (reg & 0xFF) << 12;
2480 ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, ®);
2481 devid |= (reg & 0xFF) << 4;
2482 ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, ®);
2483 devid |= (reg & 0xF0) >> 4;
2486 case CS43130_CHIP_ID:
2487 case CS4399_CHIP_ID:
2488 case CS43131_CHIP_ID:
2489 case CS43198_CHIP_ID:
2492 dev_err(&client->dev,
2493 "CS43130 Device ID %X. Expected ID %X, %X, %X or %X\n",
2494 devid, CS43130_CHIP_ID, CS4399_CHIP_ID,
2495 CS43131_CHIP_ID, CS43198_CHIP_ID);
2500 cs43130->dev_id = devid;
2501 ret = regmap_read(cs43130->regmap, CS43130_REV_ID, ®);
2503 dev_err(&client->dev, "Get Revision ID failed\n");
2507 dev_info(&client->dev,
2508 "Cirrus Logic CS43130 (%x), Revision: %02X\n", devid,
2511 mutex_init(&cs43130->clk_mutex);
2513 init_completion(&cs43130->xtal_rdy);
2514 init_completion(&cs43130->pll_rdy);
2515 init_completion(&cs43130->hpload_evt);
2517 ret = devm_request_threaded_irq(&client->dev, client->irq,
2518 NULL, cs43130_irq_thread,
2519 IRQF_ONESHOT | IRQF_TRIGGER_LOW,
2520 "cs43130", cs43130);
2522 dev_err(&client->dev, "Failed to request IRQ: %d\n", ret);
2526 cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
2528 pm_runtime_set_autosuspend_delay(&client->dev, 100);
2529 pm_runtime_use_autosuspend(&client->dev);
2530 pm_runtime_set_active(&client->dev);
2531 pm_runtime_enable(&client->dev);
2533 switch (cs43130->dev_id) {
2534 case CS43130_CHIP_ID:
2535 case CS43131_CHIP_ID:
2536 memcpy(all_hp_widgets, digital_hp_widgets,
2537 sizeof(digital_hp_widgets));
2538 memcpy(all_hp_widgets + ARRAY_SIZE(digital_hp_widgets),
2539 analog_hp_widgets, sizeof(analog_hp_widgets));
2540 memcpy(all_hp_routes, digital_hp_routes,
2541 sizeof(digital_hp_routes));
2542 memcpy(all_hp_routes + ARRAY_SIZE(digital_hp_routes),
2543 analog_hp_routes, sizeof(analog_hp_routes));
2545 soc_component_dev_cs43130.dapm_widgets =
2547 soc_component_dev_cs43130.num_dapm_widgets =
2548 ARRAY_SIZE(all_hp_widgets);
2549 soc_component_dev_cs43130.dapm_routes =
2551 soc_component_dev_cs43130.num_dapm_routes =
2552 ARRAY_SIZE(all_hp_routes);
2554 case CS43198_CHIP_ID:
2555 case CS4399_CHIP_ID:
2556 soc_component_dev_cs43130.dapm_widgets =
2558 soc_component_dev_cs43130.num_dapm_widgets =
2559 ARRAY_SIZE(digital_hp_widgets);
2560 soc_component_dev_cs43130.dapm_routes =
2562 soc_component_dev_cs43130.num_dapm_routes =
2563 ARRAY_SIZE(digital_hp_routes);
2567 ret = devm_snd_soc_register_component(&client->dev,
2568 &soc_component_dev_cs43130,
2569 cs43130_dai, ARRAY_SIZE(cs43130_dai));
2571 dev_err(&client->dev,
2572 "snd_soc_register_component failed with ret = %d\n", ret);
2576 regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
2577 CS43130_ASP_3ST_MASK, 0);
2578 regmap_update_bits(cs43130->regmap, CS43130_PAD_INT_CFG,
2579 CS43130_XSP_3ST_MASK, 0);
2586 static int cs43130_i2c_remove(struct i2c_client *client)
2588 struct cs43130_private *cs43130 = i2c_get_clientdata(client);
2590 if (cs43130->xtal_ibias != CS43130_XTAL_UNUSED)
2591 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2592 CS43130_XTAL_ERR_INT,
2593 1 << CS43130_XTAL_ERR_INT_SHIFT);
2595 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2596 CS43130_HP_PLUG_INT | CS43130_HP_UNPLUG_INT,
2597 CS43130_HP_PLUG_INT | CS43130_HP_UNPLUG_INT);
2599 if (cs43130->dc_meas) {
2600 cancel_work_sync(&cs43130->work);
2601 flush_workqueue(cs43130->wq);
2603 device_remove_file(&client->dev, &dev_attr_hpload_dc_l);
2604 device_remove_file(&client->dev, &dev_attr_hpload_dc_r);
2605 device_remove_file(&client->dev, &dev_attr_hpload_ac_l);
2606 device_remove_file(&client->dev, &dev_attr_hpload_ac_r);
2609 gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
2611 pm_runtime_disable(&client->dev);
2612 regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies);
2617 static int __maybe_unused cs43130_runtime_suspend(struct device *dev)
2619 struct cs43130_private *cs43130 = dev_get_drvdata(dev);
2621 if (cs43130->xtal_ibias != CS43130_XTAL_UNUSED)
2622 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2623 CS43130_XTAL_ERR_INT,
2624 1 << CS43130_XTAL_ERR_INT_SHIFT);
2626 regcache_cache_only(cs43130->regmap, true);
2627 regcache_mark_dirty(cs43130->regmap);
2629 gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
2631 regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies);
2636 static int __maybe_unused cs43130_runtime_resume(struct device *dev)
2638 struct cs43130_private *cs43130 = dev_get_drvdata(dev);
2641 ret = regulator_bulk_enable(CS43130_NUM_SUPPLIES, cs43130->supplies);
2643 dev_err(dev, "Failed to enable supplies: %d\n", ret);
2647 regcache_cache_only(cs43130->regmap, false);
2649 gpiod_set_value_cansleep(cs43130->reset_gpio, 1);
2651 usleep_range(2000, 2050);
2653 ret = regcache_sync(cs43130->regmap);
2655 dev_err(dev, "Failed to restore register cache\n");
2659 if (cs43130->xtal_ibias != CS43130_XTAL_UNUSED)
2660 regmap_update_bits(cs43130->regmap, CS43130_INT_MASK_1,
2661 CS43130_XTAL_ERR_INT, 0);
2665 regcache_cache_only(cs43130->regmap, true);
2666 regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies);
2671 static const struct dev_pm_ops cs43130_runtime_pm = {
2672 SET_RUNTIME_PM_OPS(cs43130_runtime_suspend, cs43130_runtime_resume,
2676 static const struct of_device_id cs43130_of_match[] = {
2677 {.compatible = "cirrus,cs43130",},
2678 {.compatible = "cirrus,cs4399",},
2679 {.compatible = "cirrus,cs43131",},
2680 {.compatible = "cirrus,cs43198",},
2684 MODULE_DEVICE_TABLE(of, cs43130_of_match);
2686 static const struct i2c_device_id cs43130_i2c_id[] = {
2694 MODULE_DEVICE_TABLE(i2c, cs43130_i2c_id);
2696 static struct i2c_driver cs43130_i2c_driver = {
2699 .of_match_table = cs43130_of_match,
2700 .pm = &cs43130_runtime_pm,
2702 .id_table = cs43130_i2c_id,
2703 .probe = cs43130_i2c_probe,
2704 .remove = cs43130_i2c_remove,
2707 module_i2c_driver(cs43130_i2c_driver);
2709 MODULE_AUTHOR("Li Xu <li.xu@cirrus.com>");
2710 MODULE_DESCRIPTION("Cirrus Logic CS43130 ALSA SoC Codec Driver");
2711 MODULE_LICENSE("GPL");