26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/slab.h>
31 #include <linux/module.h>
43 #define SN95031_RATES (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100)
44 #define SN95031_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
81 static int find_free_channel(
struct snd_soc_codec *sn95031_codec)
98 return (i == SN95031_ADC_CHANLS_MAX) ? (-
EINVAL) : i;
102 static int sn95031_initialize_adc(
struct snd_soc_codec *sn95031_codec)
104 int base_addr, chnl_addr;
109 channel_index = find_free_channel(sn95031_codec);
110 if (channel_index < 0) {
111 pr_err(
"No free ADC channels");
112 return channel_index;
133 pr_debug(
"mid_initialize : %x", chnl_addr);
134 configure_adc(sn95031_codec, 1);
142 u16 adc_adr = sn95031_initialize_adc(codec);
143 u16 adc_val1, adc_val2;
144 unsigned int mic_bias;
146 sn95031_enable_mic_bias(codec);
160 mic_bias = (adc_val1 << 2) + (adc_val2 & 3);
162 pr_debug(
"mic bias = %dmV\n", mic_bias);
167 static inline unsigned int sn95031_read(
struct snd_soc_codec *codec,
175 pr_err(
"read of %x failed, err %d\n", reg, ret);
181 unsigned int reg,
unsigned int value)
187 pr_err(
"write of %x failed, err %d\n", reg, ret);
191 static int sn95031_set_vaud_bias(
struct snd_soc_codec *codec,
200 pr_debug(
"vaud_bias powering up pll\n");
211 pr_debug(
"vaud_bias power up rail\n");
218 pr_debug(
"vaud_bias power dn pcm\n");
226 pr_debug(
"vaud_bias _OFF doing rail shutdown\n");
239 pr_debug(
"VHS SND_SOC_DAPM_EVENT_ON doing rail startup now\n");
245 pr_debug(
"VHS SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n");
256 pr_debug(
"VIHF SND_SOC_DAPM_EVENT_ON doing rail startup now\n");
261 pr_debug(
"VIHF SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n");
270 unsigned int ldo = 0, clk_dir = 0,
data_dir = 0;
287 unsigned int ldo = 0, clk_dir = 0,
data_dir = 0;
304 unsigned int ldo = 0;
315 static const char *sn95031_mic_texts[] = {
"AMIC",
"LineIn" };
317 static const struct soc_enum sn95031_micl_enum =
323 static const struct soc_enum sn95031_micr_enum =
329 static const char *sn95031_input_texts[] = {
"DMIC1",
"DMIC2",
"DMIC3",
330 "DMIC4",
"DMIC5",
"DMIC6",
331 "ADC Left",
"ADC Right" };
333 static const struct soc_enum sn95031_input1_enum =
339 static const struct soc_enum sn95031_input2_enum =
345 static const struct soc_enum sn95031_input3_enum =
351 static const struct soc_enum sn95031_input4_enum =
359 static const char *sn95031_micmode_text[] = {
"Single Ended",
"Differential"};
364 static const struct soc_enum sn95031_micmode1_enum =
366 static const struct soc_enum sn95031_micmode2_enum =
369 static const char *sn95031_dmic_cfg_text[] = {
"GPO",
"DMIC"};
371 static const struct soc_enum sn95031_dmic12_cfg_enum =
373 static const struct soc_enum sn95031_dmic34_cfg_enum =
375 static const struct soc_enum sn95031_dmic56_cfg_enum =
379 SOC_ENUM(
"Mic1Mode Capture Route", sn95031_micmode1_enum),
380 SOC_ENUM(
"Mic2Mode Capture Route", sn95031_micmode2_enum),
381 SOC_ENUM(
"DMIC12 Capture Route", sn95031_dmic12_cfg_enum),
382 SOC_ENUM(
"DMIC34 Capture Route", sn95031_dmic34_cfg_enum),
383 SOC_ENUM(
"DMIC56 Capture Route", sn95031_dmic56_cfg_enum),
422 sn95031_dmic12_event,
425 sn95031_dmic34_event,
428 sn95031_dmic56_event,
522 {
"HPOUTL",
NULL,
"Headset Rail"},
523 {
"HPOUTR",
NULL,
"Headset Rail"},
524 {
"HPOUTL",
NULL,
"Headset Left Playback" },
525 {
"HPOUTR",
NULL,
"Headset Right Playback" },
526 {
"EPOUT",
NULL,
"Earpiece Playback" },
527 {
"Headset Left Playback",
NULL,
"Headset Left Filter"},
528 {
"Headset Right Playback",
NULL,
"Headset Right Filter"},
529 {
"Earpiece Playback",
NULL,
"Headset Left Filter"},
530 {
"Headset Left Filter",
NULL,
"HSDAC Left"},
531 {
"Headset Right Filter",
NULL,
"HSDAC Right"},
534 {
"IHFOUTL",
NULL,
"Speaker Rail"},
535 {
"IHFOUTR",
NULL,
"Speaker Rail"},
536 {
"IHFOUTL",
"NULL",
"Speaker Left Playback"},
537 {
"IHFOUTR",
"NULL",
"Speaker Right Playback"},
538 {
"Speaker Left Playback",
NULL,
"Speaker Left Filter"},
539 {
"Speaker Right Playback",
NULL,
"Speaker Right Filter"},
540 {
"Speaker Left Filter",
NULL,
"IHFDAC Left"},
541 {
"Speaker Right Filter",
NULL,
"IHFDAC Right"},
544 {
"VIB1OUT",
NULL,
"Vibra1 Playback"},
545 {
"Vibra1 Playback",
NULL,
"Vibra1 DAC"},
547 {
"VIB2OUT",
NULL,
"Vibra2 Playback"},
548 {
"Vibra2 Playback",
NULL,
"Vibra2 DAC"},
551 {
"LINEOUTL",
NULL,
"Lineout Left Playback"},
552 {
"LINEOUTR",
NULL,
"Lineout Right Playback"},
553 {
"Lineout Left Playback",
NULL,
"Headset Left Filter"},
554 {
"Lineout Left Playback",
NULL,
"Speaker Left Filter"},
555 {
"Lineout Left Playback",
NULL,
"Vibra1 DAC"},
556 {
"Lineout Right Playback",
NULL,
"Headset Right Filter"},
557 {
"Lineout Right Playback",
NULL,
"Speaker Right Filter"},
558 {
"Lineout Right Playback",
NULL,
"Vibra2 DAC"},
561 {
"AMIC1Bias",
NULL,
"AMIC1"},
562 {
"MIC1 Enable",
NULL,
"AMIC1Bias"},
563 {
"Mic_InputL Capture Route",
"AMIC",
"MIC1 Enable"},
566 {
"AMIC2Bias",
NULL,
"AMIC2"},
567 {
"MIC2 Enable",
NULL,
"AMIC2Bias"},
568 {
"Mic_InputR Capture Route",
"AMIC",
"MIC2 Enable"},
572 {
"LineIn Enable Left",
NULL,
"LINEINL"},
573 {
"LineIn Enable Right",
NULL,
"LINEINR"},
574 {
"Mic_InputL Capture Route",
"LineIn",
"LineIn Enable Left"},
575 {
"Mic_InputR Capture Route",
"LineIn",
"LineIn Enable Right"},
578 {
"ADC Left",
NULL,
"Mic_InputL Capture Route"},
579 {
"ADC Right",
NULL,
"Mic_InputR Capture Route"},
582 {
"DMIC1",
NULL,
"DMIC12supply"},
583 {
"DMIC2",
NULL,
"DMIC12supply"},
584 {
"DMIC3",
NULL,
"DMIC34supply"},
585 {
"DMIC4",
NULL,
"DMIC34supply"},
586 {
"DMIC5",
NULL,
"DMIC56supply"},
587 {
"DMIC6",
NULL,
"DMIC56supply"},
589 {
"DMIC12Bias",
NULL,
"DMIC1"},
590 {
"DMIC12Bias",
NULL,
"DMIC2"},
591 {
"DMIC34Bias",
NULL,
"DMIC3"},
592 {
"DMIC34Bias",
NULL,
"DMIC4"},
593 {
"DMIC56Bias",
NULL,
"DMIC5"},
594 {
"DMIC56Bias",
NULL,
"DMIC6"},
597 {
"Txpath1 Capture Route",
"ADC Left",
"ADC Left"},
598 {
"Txpath2 Capture Route",
"ADC Left",
"ADC Left"},
599 {
"Txpath3 Capture Route",
"ADC Left",
"ADC Left"},
600 {
"Txpath4 Capture Route",
"ADC Left",
"ADC Left"},
601 {
"Txpath1 Capture Route",
"ADC Right",
"ADC Right"},
602 {
"Txpath2 Capture Route",
"ADC Right",
"ADC Right"},
603 {
"Txpath3 Capture Route",
"ADC Right",
"ADC Right"},
604 {
"Txpath4 Capture Route",
"ADC Right",
"ADC Right"},
605 {
"Txpath1 Capture Route",
"DMIC1",
"DMIC1"},
606 {
"Txpath2 Capture Route",
"DMIC1",
"DMIC1"},
607 {
"Txpath3 Capture Route",
"DMIC1",
"DMIC1"},
608 {
"Txpath4 Capture Route",
"DMIC1",
"DMIC1"},
609 {
"Txpath1 Capture Route",
"DMIC2",
"DMIC2"},
610 {
"Txpath2 Capture Route",
"DMIC2",
"DMIC2"},
611 {
"Txpath3 Capture Route",
"DMIC2",
"DMIC2"},
612 {
"Txpath4 Capture Route",
"DMIC2",
"DMIC2"},
613 {
"Txpath1 Capture Route",
"DMIC3",
"DMIC3"},
614 {
"Txpath2 Capture Route",
"DMIC3",
"DMIC3"},
615 {
"Txpath3 Capture Route",
"DMIC3",
"DMIC3"},
616 {
"Txpath4 Capture Route",
"DMIC3",
"DMIC3"},
617 {
"Txpath1 Capture Route",
"DMIC4",
"DMIC4"},
618 {
"Txpath2 Capture Route",
"DMIC4",
"DMIC4"},
619 {
"Txpath3 Capture Route",
"DMIC4",
"DMIC4"},
620 {
"Txpath4 Capture Route",
"DMIC4",
"DMIC4"},
621 {
"Txpath1 Capture Route",
"DMIC5",
"DMIC5"},
622 {
"Txpath2 Capture Route",
"DMIC5",
"DMIC5"},
623 {
"Txpath3 Capture Route",
"DMIC5",
"DMIC5"},
624 {
"Txpath4 Capture Route",
"DMIC5",
"DMIC5"},
625 {
"Txpath1 Capture Route",
"DMIC6",
"DMIC6"},
626 {
"Txpath2 Capture Route",
"DMIC6",
"DMIC6"},
627 {
"Txpath3 Capture Route",
"DMIC6",
"DMIC6"},
628 {
"Txpath4 Capture Route",
"DMIC6",
"DMIC6"},
631 {
"TX1 Enable",
NULL,
"Txpath1 Capture Route"},
632 {
"TX2 Enable",
NULL,
"Txpath2 Capture Route"},
633 {
"TX3 Enable",
NULL,
"Txpath3 Capture Route"},
634 {
"TX4 Enable",
NULL,
"Txpath4 Capture Route"},
635 {
"PCM_Out",
NULL,
"TX1 Enable"},
636 {
"PCM_Out",
NULL,
"TX2 Enable"},
637 {
"PCM_Out",
NULL,
"TX3 Enable"},
638 {
"PCM_Out",
NULL,
"TX4 Enable"},
652 static int sn95031_pcm_spkr_mute(
struct snd_soc_dai *dai,
int mute)
702 .digital_mute = sn95031_pcm_hs_mute,
703 .hw_params = sn95031_pcm_hw_params,
707 .digital_mute = sn95031_pcm_spkr_mute,
708 .hw_params = sn95031_pcm_hw_params,
712 .hw_params = sn95031_pcm_hw_params,
716 .hw_params = sn95031_pcm_hw_params,
721 .name =
"SN95031 Headset",
723 .stream_name =
"Headset",
730 .stream_name =
"Capture",
736 .ops = &sn95031_headset_dai_ops,
738 { .name =
"SN95031 Speaker",
740 .stream_name =
"Speaker",
746 .ops = &sn95031_speaker_dai_ops,
748 { .name =
"SN95031 Vibra1",
750 .stream_name =
"Vibra1",
756 .ops = &sn95031_vib1_dai_ops,
758 { .name =
"SN95031 Vibra2",
760 .stream_name =
"Vibra2",
766 .ops = &sn95031_vib2_dai_ops,
770 static inline void sn95031_disable_jack_btn(
struct snd_soc_codec *codec)
775 static inline void sn95031_enable_jack_btn(
struct snd_soc_codec *codec)
783 int micbias = sn95031_get_mic_bias(mfld_jack->
codec);
787 pr_debug(
"jack type detected = %d\n", jack_type);
789 sn95031_enable_jack_btn(mfld_jack->
codec);
799 if (jack_data->
intr_id & 0x1) {
802 }
else if (jack_data->
intr_id & 0x2) {
805 }
else if (jack_data->
intr_id & 0x4) {
806 pr_debug(
"headset or headphones inserted\n");
807 status = sn95031_get_headset_state(jack_data->
mfld_jack);
808 }
else if (jack_data->
intr_id & 0x8) {
809 pr_debug(
"headset or headphones removed\n");
811 sn95031_disable_jack_btn(jack_data->
mfld_jack->codec);
813 pr_err(
"unidentified interrupt\n");
887 .probe = sn95031_codec_probe,
888 .remove = sn95031_codec_remove,
889 .read = sn95031_read,
890 .write = sn95031_write,
891 .set_bias_level = sn95031_set_vaud_bias,
892 .idle_bias_off =
true,
893 .dapm_widgets = sn95031_dapm_widgets,
894 .num_dapm_widgets =
ARRAY_SIZE(sn95031_dapm_widgets),
895 .dapm_routes = sn95031_audio_map,
896 .num_dapm_routes =
ARRAY_SIZE(sn95031_audio_map),
901 pr_debug(
"codec device probe called for %s\n", dev_name(&pdev->
dev));
908 pr_debug(
"codec device remove called\n");
918 .probe = sn95031_device_probe,