1 // SPDX-License-Identifier: GPL-2.0
3 // MAX9867 ALSA SoC codec driver
5 // Copyright 2013-2015 Maxim Integrated Products
6 // Copyright 2018 Ladislav Michl <ladis@linux-mips.org>
9 #include <linux/delay.h>
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/regmap.h>
13 #include <sound/pcm_params.h>
14 #include <sound/soc.h>
15 #include <sound/tlv.h>
19 struct regmap
*regmap
;
20 const struct snd_pcm_hw_constraint_list
*constraints
;
21 unsigned int sysclk
, pclk
;
23 unsigned int adc_dac_active
;
26 static const char *const max9867_spmode
[] = {
27 "Stereo Diff", "Mono Diff",
28 "Stereo Cap", "Mono Cap",
29 "Stereo Single", "Mono Single",
30 "Stereo Single Fast", "Mono Single Fast"
32 static const char *const max9867_filter_text
[] = {"IIR", "FIR"};
34 static const char *const max9867_adc_dac_filter_text
[] = {
43 enum max9867_adc_dac
{
50 static int max9867_adc_dac_event(struct snd_soc_dapm_widget
*w
,
51 struct snd_kcontrol
*kcontrol
, int event
)
53 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
54 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
55 enum max9867_adc_dac adc_dac
;
57 if (!strcmp(w
->name
, "ADCL"))
58 adc_dac
= MAX9867_ADC_LEFT
;
59 else if (!strcmp(w
->name
, "ADCR"))
60 adc_dac
= MAX9867_ADC_RIGHT
;
61 else if (!strcmp(w
->name
, "DACL"))
62 adc_dac
= MAX9867_DAC_LEFT
;
63 else if (!strcmp(w
->name
, "DACR"))
64 adc_dac
= MAX9867_DAC_RIGHT
;
68 if (SND_SOC_DAPM_EVENT_ON(event
))
69 max9867
->adc_dac_active
|= BIT(adc_dac
);
70 else if (SND_SOC_DAPM_EVENT_OFF(event
))
71 max9867
->adc_dac_active
&= ~BIT(adc_dac
);
76 static int max9867_filter_get(struct snd_kcontrol
*kcontrol
,
77 struct snd_ctl_elem_value
*ucontrol
)
79 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
80 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
84 ret
= regmap_read(max9867
->regmap
, MAX9867_CODECFLTR
, ®
);
88 if (reg
& MAX9867_CODECFLTR_MODE
)
89 ucontrol
->value
.enumerated
.item
[0] = 1;
91 ucontrol
->value
.enumerated
.item
[0] = 0;
96 static int max9867_filter_set(struct snd_kcontrol
*kcontrol
,
97 struct snd_ctl_elem_value
*ucontrol
)
99 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
100 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
101 unsigned int reg
, mode
= ucontrol
->value
.enumerated
.item
[0];
107 /* don't allow change if ADC/DAC active */
108 if (max9867
->adc_dac_active
)
111 /* read current filter mode */
112 ret
= regmap_read(max9867
->regmap
, MAX9867_CODECFLTR
, ®
);
117 mode
= MAX9867_CODECFLTR_MODE
;
119 /* check if change is needed */
120 if ((reg
& MAX9867_CODECFLTR_MODE
) == mode
)
123 /* shutdown codec before switching filter mode */
124 regmap_update_bits(max9867
->regmap
, MAX9867_PWRMAN
,
125 MAX9867_PWRMAN_SHDN
, 0);
127 /* switch filter mode */
128 regmap_update_bits(max9867
->regmap
, MAX9867_CODECFLTR
,
129 MAX9867_CODECFLTR_MODE
, mode
);
131 /* out of shutdown now */
132 regmap_update_bits(max9867
->regmap
, MAX9867_PWRMAN
,
133 MAX9867_PWRMAN_SHDN
, MAX9867_PWRMAN_SHDN
);
138 static SOC_ENUM_SINGLE_EXT_DECL(max9867_filter
, max9867_filter_text
);
139 static SOC_ENUM_SINGLE_DECL(max9867_dac_filter
, MAX9867_CODECFLTR
, 0,
140 max9867_adc_dac_filter_text
);
141 static SOC_ENUM_SINGLE_DECL(max9867_adc_filter
, MAX9867_CODECFLTR
, 4,
142 max9867_adc_dac_filter_text
);
143 static SOC_ENUM_SINGLE_DECL(max9867_spkmode
, MAX9867_MODECONFIG
, 0,
145 static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(max9867_master_tlv
,
146 0, 2, TLV_DB_SCALE_ITEM(-8600, 200, 1),
147 3, 17, TLV_DB_SCALE_ITEM(-7800, 400, 0),
148 18, 25, TLV_DB_SCALE_ITEM(-2000, 200, 0),
149 26, 34, TLV_DB_SCALE_ITEM( -500, 100, 0),
150 35, 40, TLV_DB_SCALE_ITEM( 350, 50, 0),
152 static DECLARE_TLV_DB_SCALE(max9867_mic_tlv
, 0, 100, 0);
153 static DECLARE_TLV_DB_SCALE(max9867_line_tlv
, -600, 200, 0);
154 static DECLARE_TLV_DB_SCALE(max9867_adc_tlv
, -1200, 100, 0);
155 static DECLARE_TLV_DB_SCALE(max9867_dac_tlv
, -1500, 100, 0);
156 static DECLARE_TLV_DB_SCALE(max9867_dacboost_tlv
, 0, 600, 0);
157 static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(max9867_micboost_tlv
,
158 0, 2, TLV_DB_SCALE_ITEM(-2000, 2000, 1),
159 3, 3, TLV_DB_SCALE_ITEM(3000, 0, 0),
162 static const struct snd_kcontrol_new max9867_snd_controls
[] = {
163 SOC_DOUBLE_R_TLV("Master Playback Volume", MAX9867_LEFTVOL
,
164 MAX9867_RIGHTVOL
, 0, 40, 1, max9867_master_tlv
),
165 SOC_DOUBLE_R_TLV("Line Capture Volume", MAX9867_LEFTLINELVL
,
166 MAX9867_RIGHTLINELVL
, 0, 15, 1, max9867_line_tlv
),
167 SOC_DOUBLE_R_TLV("Mic Capture Volume", MAX9867_LEFTMICGAIN
,
168 MAX9867_RIGHTMICGAIN
, 0, 20, 1, max9867_mic_tlv
),
169 SOC_DOUBLE_R_TLV("Mic Boost Capture Volume", MAX9867_LEFTMICGAIN
,
170 MAX9867_RIGHTMICGAIN
, 5, 3, 0, max9867_micboost_tlv
),
171 SOC_SINGLE("Digital Sidetone Volume", MAX9867_SIDETONE
, 0, 31, 1),
172 SOC_SINGLE_TLV("Digital Playback Volume", MAX9867_DACLEVEL
, 0, 15, 1,
174 SOC_SINGLE_TLV("Digital Boost Playback Volume", MAX9867_DACLEVEL
, 4, 3, 0,
175 max9867_dacboost_tlv
),
176 SOC_DOUBLE_TLV("Digital Capture Volume", MAX9867_ADCLEVEL
, 4, 0, 15, 1,
178 SOC_ENUM("Speaker Mode", max9867_spkmode
),
179 SOC_SINGLE("Volume Smoothing Switch", MAX9867_MODECONFIG
, 6, 1, 0),
180 SOC_SINGLE("Line ZC Switch", MAX9867_MODECONFIG
, 5, 1, 0),
181 SOC_ENUM_EXT("DSP Filter", max9867_filter
, max9867_filter_get
, max9867_filter_set
),
182 SOC_ENUM("ADC Filter", max9867_adc_filter
),
183 SOC_ENUM("DAC Filter", max9867_dac_filter
),
184 SOC_SINGLE("Mono Playback Switch", MAX9867_IFC1B
, 3, 1, 0),
188 static const struct snd_kcontrol_new max9867_input_mixer_controls
[] = {
189 SOC_DAPM_DOUBLE("Line Capture Switch", MAX9867_INPUTCONFIG
, 7, 5, 1, 0),
190 SOC_DAPM_DOUBLE("Mic Capture Switch", MAX9867_INPUTCONFIG
, 6, 4, 1, 0),
194 static const struct snd_kcontrol_new max9867_output_mixer_controls
[] = {
195 SOC_DAPM_DOUBLE_R("Line Bypass Switch",
196 MAX9867_LEFTLINELVL
, MAX9867_RIGHTLINELVL
, 6, 1, 1),
200 static const struct snd_kcontrol_new max9867_sidetone_mixer_controls
[] = {
201 SOC_DAPM_DOUBLE("Sidetone Switch", MAX9867_SIDETONE
, 6, 7, 1, 0),
204 /* Line out switch */
205 static const struct snd_kcontrol_new max9867_line_out_control
=
206 SOC_DAPM_DOUBLE_R("Switch",
207 MAX9867_LEFTVOL
, MAX9867_RIGHTVOL
, 6, 1, 1);
210 static const char *const dmic_mux_text
[] = {
213 static SOC_ENUM_SINGLE_DECL(left_dmic_mux_enum
,
214 MAX9867_MICCONFIG
, 5, dmic_mux_text
);
215 static SOC_ENUM_SINGLE_DECL(right_dmic_mux_enum
,
216 MAX9867_MICCONFIG
, 4, dmic_mux_text
);
217 static const struct snd_kcontrol_new max9867_left_dmic_mux
=
218 SOC_DAPM_ENUM("DMICL Mux", left_dmic_mux_enum
);
219 static const struct snd_kcontrol_new max9867_right_dmic_mux
=
220 SOC_DAPM_ENUM("DMICR Mux", right_dmic_mux_enum
);
222 static const struct snd_soc_dapm_widget max9867_dapm_widgets
[] = {
223 SND_SOC_DAPM_INPUT("MICL"),
224 SND_SOC_DAPM_INPUT("MICR"),
225 SND_SOC_DAPM_INPUT("DMICL"),
226 SND_SOC_DAPM_INPUT("DMICR"),
227 SND_SOC_DAPM_INPUT("LINL"),
228 SND_SOC_DAPM_INPUT("LINR"),
230 SND_SOC_DAPM_PGA("Left Line Input", SND_SOC_NOPM
, 0, 0, NULL
, 0),
231 SND_SOC_DAPM_PGA("Right Line Input", SND_SOC_NOPM
, 0, 0, NULL
, 0),
232 SND_SOC_DAPM_MIXER_NAMED_CTL("Input Mixer", SND_SOC_NOPM
, 0, 0,
233 max9867_input_mixer_controls
,
234 ARRAY_SIZE(max9867_input_mixer_controls
)),
235 SND_SOC_DAPM_MUX("DMICL Mux", SND_SOC_NOPM
, 0, 0,
236 &max9867_left_dmic_mux
),
237 SND_SOC_DAPM_MUX("DMICR Mux", SND_SOC_NOPM
, 0, 0,
238 &max9867_right_dmic_mux
),
239 SND_SOC_DAPM_ADC_E("ADCL", "HiFi Capture", SND_SOC_NOPM
, 0, 0,
240 max9867_adc_dac_event
,
241 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
242 SND_SOC_DAPM_ADC_E("ADCR", "HiFi Capture", SND_SOC_NOPM
, 0, 0,
243 max9867_adc_dac_event
,
244 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
246 SND_SOC_DAPM_MIXER("Digital", SND_SOC_NOPM
, 0, 0,
247 max9867_sidetone_mixer_controls
,
248 ARRAY_SIZE(max9867_sidetone_mixer_controls
)),
249 SND_SOC_DAPM_MIXER_NAMED_CTL("Output Mixer", SND_SOC_NOPM
, 0, 0,
250 max9867_output_mixer_controls
,
251 ARRAY_SIZE(max9867_output_mixer_controls
)),
252 SND_SOC_DAPM_DAC_E("DACL", "HiFi Playback", SND_SOC_NOPM
, 0, 0,
253 max9867_adc_dac_event
,
254 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
255 SND_SOC_DAPM_DAC_E("DACR", "HiFi Playback", SND_SOC_NOPM
, 0, 0,
256 max9867_adc_dac_event
,
257 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
258 SND_SOC_DAPM_SWITCH("Master Playback", SND_SOC_NOPM
, 0, 0,
259 &max9867_line_out_control
),
260 SND_SOC_DAPM_OUTPUT("LOUT"),
261 SND_SOC_DAPM_OUTPUT("ROUT"),
264 static const struct snd_soc_dapm_route max9867_audio_map
[] = {
265 {"Left Line Input", NULL
, "LINL"},
266 {"Right Line Input", NULL
, "LINR"},
267 {"Input Mixer", "Mic Capture Switch", "MICL"},
268 {"Input Mixer", "Mic Capture Switch", "MICR"},
269 {"Input Mixer", "Line Capture Switch", "Left Line Input"},
270 {"Input Mixer", "Line Capture Switch", "Right Line Input"},
271 {"DMICL Mux", "DMIC", "DMICL"},
272 {"DMICR Mux", "DMIC", "DMICR"},
273 {"DMICL Mux", "ADC", "Input Mixer"},
274 {"DMICR Mux", "ADC", "Input Mixer"},
275 {"ADCL", NULL
, "DMICL Mux"},
276 {"ADCR", NULL
, "DMICR Mux"},
278 {"Digital", "Sidetone Switch", "ADCL"},
279 {"Digital", "Sidetone Switch", "ADCR"},
280 {"DACL", NULL
, "Digital"},
281 {"DACR", NULL
, "Digital"},
283 {"Output Mixer", "Line Bypass Switch", "Left Line Input"},
284 {"Output Mixer", "Line Bypass Switch", "Right Line Input"},
285 {"Output Mixer", NULL
, "DACL"},
286 {"Output Mixer", NULL
, "DACR"},
287 {"Master Playback", "Switch", "Output Mixer"},
288 {"LOUT", NULL
, "Master Playback"},
289 {"ROUT", NULL
, "Master Playback"},
292 static const unsigned int max9867_rates_44k1
[] = {
296 static const struct snd_pcm_hw_constraint_list max9867_constraints_44k1
= {
297 .list
= max9867_rates_44k1
,
298 .count
= ARRAY_SIZE(max9867_rates_44k1
),
301 static const unsigned int max9867_rates_48k
[] = {
302 8000, 16000, 32000, 48000,
305 static const struct snd_pcm_hw_constraint_list max9867_constraints_48k
= {
306 .list
= max9867_rates_48k
,
307 .count
= ARRAY_SIZE(max9867_rates_48k
),
310 static int max9867_startup(struct snd_pcm_substream
*substream
,
311 struct snd_soc_dai
*dai
)
313 struct max9867_priv
*max9867
=
314 snd_soc_component_get_drvdata(dai
->component
);
316 if (max9867
->constraints
)
317 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
318 SNDRV_PCM_HW_PARAM_RATE
, max9867
->constraints
);
323 static int max9867_dai_hw_params(struct snd_pcm_substream
*substream
,
324 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
327 unsigned long int rate
, ratio
;
328 struct snd_soc_component
*component
= dai
->component
;
329 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
330 unsigned int ni
= DIV_ROUND_CLOSEST_ULL(96ULL * 0x10000 * params_rate(params
),
333 /* set up the ni value */
334 regmap_update_bits(max9867
->regmap
, MAX9867_AUDIOCLKHIGH
,
335 MAX9867_NI_HIGH_MASK
, (0xFF00 & ni
) >> 8);
336 regmap_update_bits(max9867
->regmap
, MAX9867_AUDIOCLKLOW
,
337 MAX9867_NI_LOW_MASK
, 0x00FF & ni
);
338 if (max9867
->master
) {
339 if (max9867
->dsp_a
) {
340 value
= MAX9867_IFC1B_48X
;
342 rate
= params_rate(params
) * 2 * params_width(params
);
343 ratio
= max9867
->pclk
/ rate
;
344 switch (params_width(params
)) {
349 value
= MAX9867_IFC1B_PCLK_2
;
352 value
= MAX9867_IFC1B_PCLK_4
;
355 value
= MAX9867_IFC1B_PCLK_8
;
358 value
= MAX9867_IFC1B_PCLK_16
;
365 value
= MAX9867_IFC1B_48X
;
368 value
= MAX9867_IFC1B_64X
;
374 regmap_update_bits(max9867
->regmap
, MAX9867_IFC1B
,
375 MAX9867_IFC1B_BCLK_MASK
, value
);
378 * digital pll locks on to any externally supplied LRCLK signal
379 * and also enable rapid lock mode.
381 regmap_update_bits(max9867
->regmap
, MAX9867_AUDIOCLKLOW
,
382 MAX9867_RAPID_LOCK
, MAX9867_RAPID_LOCK
);
383 regmap_update_bits(max9867
->regmap
, MAX9867_AUDIOCLKHIGH
,
384 MAX9867_PLL
, MAX9867_PLL
);
389 static int max9867_mute(struct snd_soc_dai
*dai
, int mute
, int direction
)
391 struct snd_soc_component
*component
= dai
->component
;
392 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
394 return regmap_update_bits(max9867
->regmap
, MAX9867_DACLEVEL
,
395 1 << 6, !!mute
<< 6);
398 static int max9867_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
399 int clk_id
, unsigned int freq
, int dir
)
401 struct snd_soc_component
*component
= codec_dai
->component
;
402 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
405 /* Set the prescaler based on the master clock frequency*/
406 if (freq
>= 10000000 && freq
<= 20000000) {
407 value
|= MAX9867_PSCLK_10_20
;
408 max9867
->pclk
= freq
;
409 } else if (freq
>= 20000000 && freq
<= 40000000) {
410 value
|= MAX9867_PSCLK_20_40
;
411 max9867
->pclk
= freq
/ 2;
412 } else if (freq
>= 40000000 && freq
<= 60000000) {
413 value
|= MAX9867_PSCLK_40_60
;
414 max9867
->pclk
= freq
/ 4;
416 dev_err(component
->dev
,
417 "Invalid clock frequency %uHz (required 10-60MHz)\n",
421 if (freq
% 48000 == 0)
422 max9867
->constraints
= &max9867_constraints_48k
;
423 else if (freq
% 44100 == 0)
424 max9867
->constraints
= &max9867_constraints_44k1
;
426 dev_warn(component
->dev
,
427 "Unable to set exact rate with %uHz clock frequency\n",
429 max9867
->sysclk
= freq
;
430 value
= value
<< MAX9867_PSCLK_SHIFT
;
431 /* exact integer mode is not supported */
432 value
&= ~MAX9867_FREQ_MASK
;
433 regmap_update_bits(max9867
->regmap
, MAX9867_SYSCLK
,
434 MAX9867_PSCLK_MASK
, value
);
438 static int max9867_dai_set_fmt(struct snd_soc_dai
*codec_dai
,
441 struct snd_soc_component
*component
= codec_dai
->component
;
442 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
445 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
446 case SND_SOC_DAIFMT_CBM_CFM
:
447 max9867
->master
= true;
448 iface1A
= MAX9867_MASTER
;
449 iface1B
= MAX9867_IFC1B_48X
;
451 case SND_SOC_DAIFMT_CBS_CFS
:
452 max9867
->master
= false;
453 iface1A
= iface1B
= 0;
459 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
460 case SND_SOC_DAIFMT_I2S
:
461 max9867
->dsp_a
= false;
462 iface1A
|= MAX9867_I2S_DLY
;
464 case SND_SOC_DAIFMT_DSP_A
:
465 max9867
->dsp_a
= true;
466 iface1A
|= MAX9867_TDM_MODE
| MAX9867_SDOUT_HIZ
;
472 /* Clock inversion bits, BCI and WCI */
473 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
474 case SND_SOC_DAIFMT_NB_NF
:
476 case SND_SOC_DAIFMT_IB_IF
:
477 iface1A
|= MAX9867_WCI_MODE
| MAX9867_BCI_MODE
;
479 case SND_SOC_DAIFMT_IB_NF
:
480 iface1A
|= MAX9867_BCI_MODE
;
482 case SND_SOC_DAIFMT_NB_IF
:
483 iface1A
|= MAX9867_WCI_MODE
;
489 regmap_write(max9867
->regmap
, MAX9867_IFC1A
, iface1A
);
490 regmap_update_bits(max9867
->regmap
, MAX9867_IFC1B
,
491 MAX9867_IFC1B_BCLK_MASK
, iface1B
);
496 static const struct snd_soc_dai_ops max9867_dai_ops
= {
497 .set_sysclk
= max9867_set_dai_sysclk
,
498 .set_fmt
= max9867_dai_set_fmt
,
499 .mute_stream
= max9867_mute
,
500 .startup
= max9867_startup
,
501 .hw_params
= max9867_dai_hw_params
,
502 .no_capture_mute
= 1,
505 static struct snd_soc_dai_driver max9867_dai
[] = {
507 .name
= "max9867-aif1",
509 .stream_name
= "HiFi Playback",
512 .rates
= SNDRV_PCM_RATE_8000_48000
,
513 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
516 .stream_name
= "HiFi Capture",
519 .rates
= SNDRV_PCM_RATE_8000_48000
,
520 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
522 .ops
= &max9867_dai_ops
,
523 .symmetric_rates
= 1,
528 static int max9867_suspend(struct snd_soc_component
*component
)
530 snd_soc_component_force_bias_level(component
, SND_SOC_BIAS_OFF
);
535 static int max9867_resume(struct snd_soc_component
*component
)
537 snd_soc_component_force_bias_level(component
, SND_SOC_BIAS_STANDBY
);
542 #define max9867_suspend NULL
543 #define max9867_resume NULL
546 static int max9867_set_bias_level(struct snd_soc_component
*component
,
547 enum snd_soc_bias_level level
)
550 struct max9867_priv
*max9867
= snd_soc_component_get_drvdata(component
);
553 case SND_SOC_BIAS_STANDBY
:
554 if (snd_soc_component_get_bias_level(component
) == SND_SOC_BIAS_OFF
) {
555 err
= regcache_sync(max9867
->regmap
);
559 err
= regmap_write(max9867
->regmap
,
560 MAX9867_PWRMAN
, 0xff);
565 case SND_SOC_BIAS_OFF
:
566 err
= regmap_write(max9867
->regmap
, MAX9867_PWRMAN
, 0);
570 regcache_mark_dirty(max9867
->regmap
);
579 static const struct snd_soc_component_driver max9867_component
= {
580 .controls
= max9867_snd_controls
,
581 .num_controls
= ARRAY_SIZE(max9867_snd_controls
),
582 .dapm_routes
= max9867_audio_map
,
583 .num_dapm_routes
= ARRAY_SIZE(max9867_audio_map
),
584 .dapm_widgets
= max9867_dapm_widgets
,
585 .num_dapm_widgets
= ARRAY_SIZE(max9867_dapm_widgets
),
586 .suspend
= max9867_suspend
,
587 .resume
= max9867_resume
,
588 .set_bias_level
= max9867_set_bias_level
,
590 .use_pmdown_time
= 1,
592 .non_legacy_dai_naming
= 1,
595 static bool max9867_volatile_register(struct device
*dev
, unsigned int reg
)
599 case MAX9867_JACKSTATUS
:
600 case MAX9867_AUXHIGH
:
608 static const struct regmap_config max9867_regmap
= {
611 .max_register
= MAX9867_REVISION
,
612 .volatile_reg
= max9867_volatile_register
,
613 .cache_type
= REGCACHE_RBTREE
,
616 static int max9867_i2c_probe(struct i2c_client
*i2c
,
617 const struct i2c_device_id
*id
)
619 struct max9867_priv
*max9867
;
622 max9867
= devm_kzalloc(&i2c
->dev
, sizeof(*max9867
), GFP_KERNEL
);
626 i2c_set_clientdata(i2c
, max9867
);
627 max9867
->regmap
= devm_regmap_init_i2c(i2c
, &max9867_regmap
);
628 if (IS_ERR(max9867
->regmap
)) {
629 ret
= PTR_ERR(max9867
->regmap
);
630 dev_err(&i2c
->dev
, "Failed to allocate regmap: %d\n", ret
);
633 ret
= regmap_read(max9867
->regmap
, MAX9867_REVISION
, ®
);
635 dev_err(&i2c
->dev
, "Failed to read: %d\n", ret
);
638 dev_info(&i2c
->dev
, "device revision: %x\n", reg
);
639 ret
= devm_snd_soc_register_component(&i2c
->dev
, &max9867_component
,
640 max9867_dai
, ARRAY_SIZE(max9867_dai
));
642 dev_err(&i2c
->dev
, "Failed to register component: %d\n", ret
);
646 static const struct i2c_device_id max9867_i2c_id
[] = {
650 MODULE_DEVICE_TABLE(i2c
, max9867_i2c_id
);
653 static const struct of_device_id max9867_of_match
[] = {
654 { .compatible
= "maxim,max9867", },
657 MODULE_DEVICE_TABLE(of
, max9867_of_match
);
660 static struct i2c_driver max9867_i2c_driver
= {
663 .of_match_table
= of_match_ptr(max9867_of_match
),
665 .probe
= max9867_i2c_probe
,
666 .id_table
= max9867_i2c_id
,
669 module_i2c_driver(max9867_i2c_driver
);
671 MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>");
672 MODULE_DESCRIPTION("ASoC MAX9867 driver");
673 MODULE_LICENSE("GPL");