2 * Common code for ADAU1X61 and ADAU1X81 codecs
4 * Copyright 2011-2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 * Licensed under the GPL-2 or later.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/pcm_params.h>
17 #include <sound/soc.h>
18 #include <sound/tlv.h>
19 #include <linux/gcd.h>
20 #include <linux/i2c.h>
21 #include <linux/spi/spi.h>
22 #include <linux/regmap.h>
27 static const char * const adau17x1_capture_mixer_boost_text
[] = {
28 "Normal operation", "Boost Level 1", "Boost Level 2", "Boost Level 3",
31 static SOC_ENUM_SINGLE_DECL(adau17x1_capture_boost_enum
,
32 ADAU17X1_REC_POWER_MGMT
, 5, adau17x1_capture_mixer_boost_text
);
34 static const char * const adau17x1_mic_bias_mode_text
[] = {
35 "Normal operation", "High performance",
38 static SOC_ENUM_SINGLE_DECL(adau17x1_mic_bias_mode_enum
,
39 ADAU17X1_MICBIAS
, 3, adau17x1_mic_bias_mode_text
);
41 static const DECLARE_TLV_DB_MINMAX(adau17x1_digital_tlv
, -9563, 0);
43 static const struct snd_kcontrol_new adau17x1_controls
[] = {
44 SOC_DOUBLE_R_TLV("Digital Capture Volume",
45 ADAU17X1_LEFT_INPUT_DIGITAL_VOL
,
46 ADAU17X1_RIGHT_INPUT_DIGITAL_VOL
,
47 0, 0xff, 1, adau17x1_digital_tlv
),
48 SOC_DOUBLE_R_TLV("Digital Playback Volume", ADAU17X1_DAC_CONTROL1
,
49 ADAU17X1_DAC_CONTROL2
, 0, 0xff, 1, adau17x1_digital_tlv
),
51 SOC_SINGLE("ADC High Pass Filter Switch", ADAU17X1_ADC_CONTROL
,
53 SOC_SINGLE("Playback De-emphasis Switch", ADAU17X1_DAC_CONTROL0
,
56 SOC_ENUM("Capture Boost", adau17x1_capture_boost_enum
),
58 SOC_ENUM("Mic Bias Mode", adau17x1_mic_bias_mode_enum
),
61 static int adau17x1_pll_event(struct snd_soc_dapm_widget
*w
,
62 struct snd_kcontrol
*kcontrol
, int event
)
64 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
65 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
68 if (SND_SOC_DAPM_EVENT_ON(event
)) {
69 adau
->pll_regs
[5] = 1;
71 adau
->pll_regs
[5] = 0;
72 /* Bypass the PLL when disabled, otherwise registers will become
74 regmap_update_bits(adau
->regmap
, ADAU17X1_CLOCK_CONTROL
,
75 ADAU17X1_CLOCK_CONTROL_CORECLK_SRC_PLL
, 0);
78 /* The PLL register is 6 bytes long and can only be written at once. */
79 ret
= regmap_raw_write(adau
->regmap
, ADAU17X1_PLL_CONTROL
,
80 adau
->pll_regs
, ARRAY_SIZE(adau
->pll_regs
));
82 if (SND_SOC_DAPM_EVENT_ON(event
)) {
84 regmap_update_bits(adau
->regmap
, ADAU17X1_CLOCK_CONTROL
,
85 ADAU17X1_CLOCK_CONTROL_CORECLK_SRC_PLL
,
86 ADAU17X1_CLOCK_CONTROL_CORECLK_SRC_PLL
);
92 static const char * const adau17x1_mono_stereo_text
[] = {
94 "Mono Left Channel (L+R)",
95 "Mono Right Channel (L+R)",
99 static SOC_ENUM_SINGLE_DECL(adau17x1_dac_mode_enum
,
100 ADAU17X1_DAC_CONTROL0
, 6, adau17x1_mono_stereo_text
);
102 static const struct snd_kcontrol_new adau17x1_dac_mode_mux
=
103 SOC_DAPM_ENUM("DAC Mono-Stereo-Mode", adau17x1_dac_mode_enum
);
105 static const struct snd_soc_dapm_widget adau17x1_dapm_widgets
[] = {
106 SND_SOC_DAPM_SUPPLY_S("PLL", 3, SND_SOC_NOPM
, 0, 0, adau17x1_pll_event
,
107 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
109 SND_SOC_DAPM_SUPPLY("AIFCLK", SND_SOC_NOPM
, 0, 0, NULL
, 0),
111 SND_SOC_DAPM_SUPPLY("MICBIAS", ADAU17X1_MICBIAS
, 0, 0, NULL
, 0),
113 SND_SOC_DAPM_SUPPLY("Left Playback Enable", ADAU17X1_PLAY_POWER_MGMT
,
115 SND_SOC_DAPM_SUPPLY("Right Playback Enable", ADAU17X1_PLAY_POWER_MGMT
,
118 SND_SOC_DAPM_MUX("Left DAC Mode Mux", SND_SOC_NOPM
, 0, 0,
119 &adau17x1_dac_mode_mux
),
120 SND_SOC_DAPM_MUX("Right DAC Mode Mux", SND_SOC_NOPM
, 0, 0,
121 &adau17x1_dac_mode_mux
),
123 SND_SOC_DAPM_ADC("Left Decimator", NULL
, ADAU17X1_ADC_CONTROL
, 0, 0),
124 SND_SOC_DAPM_ADC("Right Decimator", NULL
, ADAU17X1_ADC_CONTROL
, 1, 0),
125 SND_SOC_DAPM_DAC("Left DAC", NULL
, ADAU17X1_DAC_CONTROL0
, 0, 0),
126 SND_SOC_DAPM_DAC("Right DAC", NULL
, ADAU17X1_DAC_CONTROL0
, 1, 0),
129 static const struct snd_soc_dapm_route adau17x1_dapm_routes
[] = {
130 { "Left Decimator", NULL
, "SYSCLK" },
131 { "Right Decimator", NULL
, "SYSCLK" },
132 { "Left DAC", NULL
, "SYSCLK" },
133 { "Right DAC", NULL
, "SYSCLK" },
134 { "Capture", NULL
, "SYSCLK" },
135 { "Playback", NULL
, "SYSCLK" },
137 { "Left DAC", NULL
, "Left DAC Mode Mux" },
138 { "Right DAC", NULL
, "Right DAC Mode Mux" },
140 { "Capture", NULL
, "AIFCLK" },
141 { "Playback", NULL
, "AIFCLK" },
144 static const struct snd_soc_dapm_route adau17x1_dapm_pll_route
= {
145 "SYSCLK", NULL
, "PLL",
149 * The MUX register for the Capture and Playback MUXs selects either DSP as
150 * source/destination or one of the TDM slots. The TDM slot is selected via
151 * snd_soc_dai_set_tdm_slot(), so we only expose whether to go to the DSP or
152 * directly to the DAI interface with this control.
154 static int adau17x1_dsp_mux_enum_put(struct snd_kcontrol
*kcontrol
,
155 struct snd_ctl_elem_value
*ucontrol
)
157 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
158 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
159 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
160 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
161 struct snd_soc_dapm_update update
;
162 unsigned int stream
= e
->shift_l
;
163 unsigned int val
, change
;
166 if (ucontrol
->value
.enumerated
.item
[0] >= e
->items
)
169 switch (ucontrol
->value
.enumerated
.item
[0]) {
172 adau
->dsp_bypass
[stream
] = false;
175 val
= (adau
->tdm_slot
[stream
] * 2) + 1;
176 adau
->dsp_bypass
[stream
] = true;
180 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
181 reg
= ADAU17X1_SERIAL_INPUT_ROUTE
;
183 reg
= ADAU17X1_SERIAL_OUTPUT_ROUTE
;
185 change
= snd_soc_test_bits(codec
, reg
, 0xff, val
);
187 update
.kcontrol
= kcontrol
;
192 snd_soc_dapm_mux_update_power(dapm
, kcontrol
,
193 ucontrol
->value
.enumerated
.item
[0], e
, &update
);
199 static int adau17x1_dsp_mux_enum_get(struct snd_kcontrol
*kcontrol
,
200 struct snd_ctl_elem_value
*ucontrol
)
202 struct snd_soc_codec
*codec
= snd_soc_dapm_kcontrol_codec(kcontrol
);
203 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
204 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
205 unsigned int stream
= e
->shift_l
;
206 unsigned int reg
, val
;
209 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
210 reg
= ADAU17X1_SERIAL_INPUT_ROUTE
;
212 reg
= ADAU17X1_SERIAL_OUTPUT_ROUTE
;
214 ret
= regmap_read(adau
->regmap
, reg
, &val
);
220 ucontrol
->value
.enumerated
.item
[0] = val
;
225 #define DECLARE_ADAU17X1_DSP_MUX_CTRL(_name, _label, _stream, _text) \
226 const struct snd_kcontrol_new _name = \
227 SOC_DAPM_ENUM_EXT(_label, (const struct soc_enum)\
228 SOC_ENUM_SINGLE(SND_SOC_NOPM, _stream, \
229 ARRAY_SIZE(_text), _text), \
230 adau17x1_dsp_mux_enum_get, adau17x1_dsp_mux_enum_put)
232 static const char * const adau17x1_dac_mux_text
[] = {
237 static const char * const adau17x1_capture_mux_text
[] = {
242 static DECLARE_ADAU17X1_DSP_MUX_CTRL(adau17x1_dac_mux
, "DAC Playback Mux",
243 SNDRV_PCM_STREAM_PLAYBACK
, adau17x1_dac_mux_text
);
245 static DECLARE_ADAU17X1_DSP_MUX_CTRL(adau17x1_capture_mux
, "Capture Mux",
246 SNDRV_PCM_STREAM_CAPTURE
, adau17x1_capture_mux_text
);
248 static const struct snd_soc_dapm_widget adau17x1_dsp_dapm_widgets
[] = {
249 SND_SOC_DAPM_PGA("DSP", ADAU17X1_DSP_RUN
, 0, 0, NULL
, 0),
250 SND_SOC_DAPM_SIGGEN("DSP Siggen"),
252 SND_SOC_DAPM_MUX("DAC Playback Mux", SND_SOC_NOPM
, 0, 0,
254 SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM
, 0, 0,
255 &adau17x1_capture_mux
),
258 static const struct snd_soc_dapm_route adau17x1_dsp_dapm_routes
[] = {
259 { "DAC Playback Mux", "DSP", "DSP" },
260 { "DAC Playback Mux", "AIFIN", "Playback" },
262 { "Left DAC Mode Mux", "Stereo", "DAC Playback Mux" },
263 { "Left DAC Mode Mux", "Mono (L+R)", "DAC Playback Mux" },
264 { "Left DAC Mode Mux", "Mono Left Channel (L+R)", "DAC Playback Mux" },
265 { "Right DAC Mode Mux", "Stereo", "DAC Playback Mux" },
266 { "Right DAC Mode Mux", "Mono (L+R)", "DAC Playback Mux" },
267 { "Right DAC Mode Mux", "Mono Right Channel (L+R)", "DAC Playback Mux" },
269 { "Capture Mux", "DSP", "DSP" },
270 { "Capture Mux", "Decimator", "Left Decimator" },
271 { "Capture Mux", "Decimator", "Right Decimator" },
273 { "Capture", NULL
, "Capture Mux" },
275 { "DSP", NULL
, "DSP Siggen" },
277 { "DSP", NULL
, "Left Decimator" },
278 { "DSP", NULL
, "Right Decimator" },
281 static const struct snd_soc_dapm_route adau17x1_no_dsp_dapm_routes
[] = {
282 { "Left DAC Mode Mux", "Stereo", "Playback" },
283 { "Left DAC Mode Mux", "Mono (L+R)", "Playback" },
284 { "Left DAC Mode Mux", "Mono Left Channel (L+R)", "Playback" },
285 { "Right DAC Mode Mux", "Stereo", "Playback" },
286 { "Right DAC Mode Mux", "Mono (L+R)", "Playback" },
287 { "Right DAC Mode Mux", "Mono Right Channel (L+R)", "Playback" },
288 { "Capture", NULL
, "Left Decimator" },
289 { "Capture", NULL
, "Right Decimator" },
292 bool adau17x1_has_dsp(struct adau
*adau
)
294 switch (adau
->type
) {
303 EXPORT_SYMBOL_GPL(adau17x1_has_dsp
);
305 static int adau17x1_hw_params(struct snd_pcm_substream
*substream
,
306 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
308 struct snd_soc_codec
*codec
= dai
->codec
;
309 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
310 unsigned int val
, div
, dsp_div
;
314 if (adau
->clk_src
== ADAU17X1_CLK_SRC_PLL
)
315 freq
= adau
->pll_freq
;
319 if (freq
% params_rate(params
) != 0)
322 switch (freq
/ params_rate(params
)) {
327 case 6144: /* fs / 6 */
331 case 4096: /* fs / 4 */
335 case 3072: /* fs / 3 */
339 case 2048: /* fs / 2 */
343 case 1536: /* fs / 1.5 */
347 case 512: /* fs / 0.5 */
355 regmap_update_bits(adau
->regmap
, ADAU17X1_CONVERTER0
,
356 ADAU17X1_CONVERTER0_CONVSR_MASK
, div
);
357 if (adau17x1_has_dsp(adau
)) {
358 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_SAMPLING_RATE
, div
);
359 regmap_write(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, dsp_div
);
362 if (adau
->sigmadsp
) {
363 ret
= adau17x1_setup_firmware(adau
, params_rate(params
));
368 if (adau
->dai_fmt
!= SND_SOC_DAIFMT_RIGHT_J
)
371 switch (params_width(params
)) {
373 val
= ADAU17X1_SERIAL_PORT1_DELAY16
;
376 val
= ADAU17X1_SERIAL_PORT1_DELAY8
;
379 val
= ADAU17X1_SERIAL_PORT1_DELAY0
;
385 return regmap_update_bits(adau
->regmap
, ADAU17X1_SERIAL_PORT1
,
386 ADAU17X1_SERIAL_PORT1_DELAY_MASK
, val
);
389 static int adau17x1_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
,
390 int source
, unsigned int freq_in
, unsigned int freq_out
)
392 struct snd_soc_codec
*codec
= dai
->codec
;
393 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
394 unsigned int r
, n
, m
, i
, j
;
398 if (freq_in
< 8000000 || freq_in
> 27000000)
407 if (freq_out
% freq_in
!= 0) {
408 div
= DIV_ROUND_UP(freq_in
, 13500000);
410 r
= freq_out
/ freq_in
;
411 i
= freq_out
% freq_in
;
417 r
= freq_out
/ freq_in
;
422 if (n
> 0xffff || m
> 0xffff || div
> 3 || r
> 8 || r
< 2)
426 adau
->pll_regs
[0] = m
>> 8;
427 adau
->pll_regs
[1] = m
& 0xff;
428 adau
->pll_regs
[2] = n
>> 8;
429 adau
->pll_regs
[3] = n
& 0xff;
430 adau
->pll_regs
[4] = (r
<< 3) | (div
<< 1);
432 adau
->pll_regs
[4] |= 1; /* Fractional mode */
434 /* The PLL register is 6 bytes long and can only be written at once. */
435 ret
= regmap_raw_write(adau
->regmap
, ADAU17X1_PLL_CONTROL
,
436 adau
->pll_regs
, ARRAY_SIZE(adau
->pll_regs
));
440 adau
->pll_freq
= freq_out
;
445 static int adau17x1_set_dai_sysclk(struct snd_soc_dai
*dai
,
446 int clk_id
, unsigned int freq
, int dir
)
448 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(dai
->codec
);
449 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
452 case ADAU17X1_CLK_SRC_MCLK
:
453 case ADAU17X1_CLK_SRC_PLL
:
461 if (adau
->clk_src
!= clk_id
) {
462 if (clk_id
== ADAU17X1_CLK_SRC_PLL
) {
463 snd_soc_dapm_add_routes(dapm
,
464 &adau17x1_dapm_pll_route
, 1);
466 snd_soc_dapm_del_routes(dapm
,
467 &adau17x1_dapm_pll_route
, 1);
471 adau
->clk_src
= clk_id
;
476 static int adau17x1_set_dai_fmt(struct snd_soc_dai
*dai
,
479 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
480 unsigned int ctrl0
, ctrl1
;
483 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
484 case SND_SOC_DAIFMT_CBM_CFM
:
485 ctrl0
= ADAU17X1_SERIAL_PORT0_MASTER
;
488 case SND_SOC_DAIFMT_CBS_CFS
:
490 adau
->master
= false;
496 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
497 case SND_SOC_DAIFMT_I2S
:
499 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY1
;
501 case SND_SOC_DAIFMT_LEFT_J
:
502 case SND_SOC_DAIFMT_RIGHT_J
:
504 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY0
;
506 case SND_SOC_DAIFMT_DSP_A
:
508 ctrl0
|= ADAU17X1_SERIAL_PORT0_PULSE_MODE
;
509 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY1
;
511 case SND_SOC_DAIFMT_DSP_B
:
513 ctrl0
|= ADAU17X1_SERIAL_PORT0_PULSE_MODE
;
514 ctrl1
= ADAU17X1_SERIAL_PORT1_DELAY0
;
520 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
521 case SND_SOC_DAIFMT_NB_NF
:
523 case SND_SOC_DAIFMT_IB_NF
:
524 ctrl0
|= ADAU17X1_SERIAL_PORT0_BCLK_POL
;
526 case SND_SOC_DAIFMT_NB_IF
:
527 lrclk_pol
= !lrclk_pol
;
529 case SND_SOC_DAIFMT_IB_IF
:
530 ctrl0
|= ADAU17X1_SERIAL_PORT0_BCLK_POL
;
531 lrclk_pol
= !lrclk_pol
;
538 ctrl0
|= ADAU17X1_SERIAL_PORT0_LRCLK_POL
;
540 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_PORT0
, ctrl0
);
541 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_PORT1
, ctrl1
);
543 adau
->dai_fmt
= fmt
& SND_SOC_DAIFMT_FORMAT_MASK
;
548 static int adau17x1_set_dai_tdm_slot(struct snd_soc_dai
*dai
,
549 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
551 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
552 unsigned int ser_ctrl0
, ser_ctrl1
;
553 unsigned int conv_ctrl0
, conv_ctrl1
;
565 ser_ctrl0
= ADAU17X1_SERIAL_PORT0_STEREO
;
568 ser_ctrl0
= ADAU17X1_SERIAL_PORT0_TDM4
;
571 if (adau
->type
== ADAU1361
)
574 ser_ctrl0
= ADAU17X1_SERIAL_PORT0_TDM8
;
580 switch (slot_width
* slots
) {
582 if (adau
->type
== ADAU1761
)
585 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK32
;
588 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK64
;
591 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK48
;
594 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK128
;
597 if (adau
->type
== ADAU1361
)
600 ser_ctrl1
= ADAU17X1_SERIAL_PORT1_BCLK256
;
608 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(1);
609 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 0;
612 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(2);
613 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 1;
616 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(3);
617 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 2;
620 conv_ctrl1
= ADAU17X1_CONVERTER1_ADC_PAIR(4);
621 adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] = 3;
629 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(1);
630 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 0;
633 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(2);
634 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 1;
637 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(3);
638 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 2;
641 conv_ctrl0
= ADAU17X1_CONVERTER0_DAC_PAIR(4);
642 adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] = 3;
648 regmap_update_bits(adau
->regmap
, ADAU17X1_CONVERTER0
,
649 ADAU17X1_CONVERTER0_DAC_PAIR_MASK
, conv_ctrl0
);
650 regmap_update_bits(adau
->regmap
, ADAU17X1_CONVERTER1
,
651 ADAU17X1_CONVERTER1_ADC_PAIR_MASK
, conv_ctrl1
);
652 regmap_update_bits(adau
->regmap
, ADAU17X1_SERIAL_PORT0
,
653 ADAU17X1_SERIAL_PORT0_TDM_MASK
, ser_ctrl0
);
654 regmap_update_bits(adau
->regmap
, ADAU17X1_SERIAL_PORT1
,
655 ADAU17X1_SERIAL_PORT1_BCLK_MASK
, ser_ctrl1
);
657 if (!adau17x1_has_dsp(adau
))
660 if (adau
->dsp_bypass
[SNDRV_PCM_STREAM_PLAYBACK
]) {
661 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_INPUT_ROUTE
,
662 (adau
->tdm_slot
[SNDRV_PCM_STREAM_PLAYBACK
] * 2) + 1);
665 if (adau
->dsp_bypass
[SNDRV_PCM_STREAM_CAPTURE
]) {
666 regmap_write(adau
->regmap
, ADAU17X1_SERIAL_OUTPUT_ROUTE
,
667 (adau
->tdm_slot
[SNDRV_PCM_STREAM_CAPTURE
] * 2) + 1);
673 static int adau17x1_startup(struct snd_pcm_substream
*substream
,
674 struct snd_soc_dai
*dai
)
676 struct adau
*adau
= snd_soc_codec_get_drvdata(dai
->codec
);
679 return sigmadsp_restrict_params(adau
->sigmadsp
, substream
);
684 const struct snd_soc_dai_ops adau17x1_dai_ops
= {
685 .hw_params
= adau17x1_hw_params
,
686 .set_sysclk
= adau17x1_set_dai_sysclk
,
687 .set_fmt
= adau17x1_set_dai_fmt
,
688 .set_pll
= adau17x1_set_dai_pll
,
689 .set_tdm_slot
= adau17x1_set_dai_tdm_slot
,
690 .startup
= adau17x1_startup
,
692 EXPORT_SYMBOL_GPL(adau17x1_dai_ops
);
694 int adau17x1_set_micbias_voltage(struct snd_soc_codec
*codec
,
695 enum adau17x1_micbias_voltage micbias
)
697 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
700 case ADAU17X1_MICBIAS_0_90_AVDD
:
701 case ADAU17X1_MICBIAS_0_65_AVDD
:
707 return regmap_write(adau
->regmap
, ADAU17X1_MICBIAS
, micbias
<< 2);
709 EXPORT_SYMBOL_GPL(adau17x1_set_micbias_voltage
);
711 bool adau17x1_precious_register(struct device
*dev
, unsigned int reg
)
713 /* SigmaDSP parameter memory */
719 EXPORT_SYMBOL_GPL(adau17x1_precious_register
);
721 bool adau17x1_readable_register(struct device
*dev
, unsigned int reg
)
723 /* SigmaDSP parameter memory */
728 case ADAU17X1_CLOCK_CONTROL
:
729 case ADAU17X1_PLL_CONTROL
:
730 case ADAU17X1_REC_POWER_MGMT
:
731 case ADAU17X1_MICBIAS
:
732 case ADAU17X1_SERIAL_PORT0
:
733 case ADAU17X1_SERIAL_PORT1
:
734 case ADAU17X1_CONVERTER0
:
735 case ADAU17X1_CONVERTER1
:
736 case ADAU17X1_LEFT_INPUT_DIGITAL_VOL
:
737 case ADAU17X1_RIGHT_INPUT_DIGITAL_VOL
:
738 case ADAU17X1_ADC_CONTROL
:
739 case ADAU17X1_PLAY_POWER_MGMT
:
740 case ADAU17X1_DAC_CONTROL0
:
741 case ADAU17X1_DAC_CONTROL1
:
742 case ADAU17X1_DAC_CONTROL2
:
743 case ADAU17X1_SERIAL_PORT_PAD
:
744 case ADAU17X1_CONTROL_PORT_PAD0
:
745 case ADAU17X1_CONTROL_PORT_PAD1
:
746 case ADAU17X1_DSP_SAMPLING_RATE
:
747 case ADAU17X1_SERIAL_INPUT_ROUTE
:
748 case ADAU17X1_SERIAL_OUTPUT_ROUTE
:
749 case ADAU17X1_DSP_ENABLE
:
750 case ADAU17X1_DSP_RUN
:
751 case ADAU17X1_SERIAL_SAMPLING_RATE
:
758 EXPORT_SYMBOL_GPL(adau17x1_readable_register
);
760 bool adau17x1_volatile_register(struct device
*dev
, unsigned int reg
)
762 /* SigmaDSP parameter and program memory */
767 /* The PLL register is 6 bytes long */
768 case ADAU17X1_PLL_CONTROL
:
769 case ADAU17X1_PLL_CONTROL
+ 1:
770 case ADAU17X1_PLL_CONTROL
+ 2:
771 case ADAU17X1_PLL_CONTROL
+ 3:
772 case ADAU17X1_PLL_CONTROL
+ 4:
773 case ADAU17X1_PLL_CONTROL
+ 5:
781 EXPORT_SYMBOL_GPL(adau17x1_volatile_register
);
783 int adau17x1_setup_firmware(struct adau
*adau
, unsigned int rate
)
788 ret
= regmap_read(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, &dspsr
);
792 regmap_write(adau
->regmap
, ADAU17X1_DSP_ENABLE
, 1);
793 regmap_write(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, 0xf);
795 ret
= sigmadsp_setup(adau
->sigmadsp
, rate
);
797 regmap_write(adau
->regmap
, ADAU17X1_DSP_ENABLE
, 0);
800 regmap_write(adau
->regmap
, ADAU17X1_DSP_SAMPLING_RATE
, dspsr
);
804 EXPORT_SYMBOL_GPL(adau17x1_setup_firmware
);
806 int adau17x1_add_widgets(struct snd_soc_codec
*codec
)
808 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
809 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
812 ret
= snd_soc_add_codec_controls(codec
, adau17x1_controls
,
813 ARRAY_SIZE(adau17x1_controls
));
816 ret
= snd_soc_dapm_new_controls(dapm
, adau17x1_dapm_widgets
,
817 ARRAY_SIZE(adau17x1_dapm_widgets
));
821 if (adau17x1_has_dsp(adau
)) {
822 ret
= snd_soc_dapm_new_controls(dapm
, adau17x1_dsp_dapm_widgets
,
823 ARRAY_SIZE(adau17x1_dsp_dapm_widgets
));
830 ret
= sigmadsp_attach(adau
->sigmadsp
, &codec
->component
);
832 dev_err(codec
->dev
, "Failed to attach firmware: %d\n",
840 EXPORT_SYMBOL_GPL(adau17x1_add_widgets
);
842 int adau17x1_add_routes(struct snd_soc_codec
*codec
)
844 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
845 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
848 ret
= snd_soc_dapm_add_routes(dapm
, adau17x1_dapm_routes
,
849 ARRAY_SIZE(adau17x1_dapm_routes
));
853 if (adau17x1_has_dsp(adau
)) {
854 ret
= snd_soc_dapm_add_routes(dapm
, adau17x1_dsp_dapm_routes
,
855 ARRAY_SIZE(adau17x1_dsp_dapm_routes
));
857 ret
= snd_soc_dapm_add_routes(dapm
, adau17x1_no_dsp_dapm_routes
,
858 ARRAY_SIZE(adau17x1_no_dsp_dapm_routes
));
862 EXPORT_SYMBOL_GPL(adau17x1_add_routes
);
864 int adau17x1_resume(struct snd_soc_codec
*codec
)
866 struct adau
*adau
= snd_soc_codec_get_drvdata(codec
);
868 if (adau
->switch_mode
)
869 adau
->switch_mode(codec
->dev
);
871 regcache_sync(adau
->regmap
);
875 EXPORT_SYMBOL_GPL(adau17x1_resume
);
877 int adau17x1_probe(struct device
*dev
, struct regmap
*regmap
,
878 enum adau17x1_type type
, void (*switch_mode
)(struct device
*dev
),
879 const char *firmware_name
)
884 return PTR_ERR(regmap
);
886 adau
= devm_kzalloc(dev
, sizeof(*adau
), GFP_KERNEL
);
890 adau
->regmap
= regmap
;
891 adau
->switch_mode
= switch_mode
;
894 dev_set_drvdata(dev
, adau
);
897 adau
->sigmadsp
= devm_sigmadsp_init_regmap(dev
, regmap
, NULL
,
899 if (IS_ERR(adau
->sigmadsp
)) {
900 dev_warn(dev
, "Could not find firmware file: %ld\n",
901 PTR_ERR(adau
->sigmadsp
));
902 adau
->sigmadsp
= NULL
;
911 EXPORT_SYMBOL_GPL(adau17x1_probe
);
913 MODULE_DESCRIPTION("ASoC ADAU1X61/ADAU1X81 common code");
914 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
915 MODULE_LICENSE("GPL");