xref: /openbmc/linux/sound/soc/codecs/alc5623.c (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
26f4bc952SArnaud Patard (Rtp) /*
36f4bc952SArnaud Patard (Rtp)  * alc5623.c  --  alc562[123] ALSA Soc Audio driver
46f4bc952SArnaud Patard (Rtp)  *
56f4bc952SArnaud Patard (Rtp)  * Copyright 2008 Realtek Microelectronics
66f4bc952SArnaud Patard (Rtp)  * Author: flove <flove@realtek.com> Ethan <eku@marvell.com>
76f4bc952SArnaud Patard (Rtp)  *
86f4bc952SArnaud Patard (Rtp)  * Copyright 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
96f4bc952SArnaud Patard (Rtp)  *
106f4bc952SArnaud Patard (Rtp)  * Based on WM8753.c
116f4bc952SArnaud Patard (Rtp)  */
126f4bc952SArnaud Patard (Rtp) 
136f4bc952SArnaud Patard (Rtp) #include <linux/module.h>
146f4bc952SArnaud Patard (Rtp) #include <linux/kernel.h>
156f4bc952SArnaud Patard (Rtp) #include <linux/init.h>
166f4bc952SArnaud Patard (Rtp) #include <linux/delay.h>
176f4bc952SArnaud Patard (Rtp) #include <linux/pm.h>
186f4bc952SArnaud Patard (Rtp) #include <linux/i2c.h>
190cd257bfSMark Brown #include <linux/regmap.h>
206f4bc952SArnaud Patard (Rtp) #include <linux/slab.h>
217d6d478fSAndrew Lunn #include <linux/of.h>
226f4bc952SArnaud Patard (Rtp) #include <sound/core.h>
236f4bc952SArnaud Patard (Rtp) #include <sound/pcm.h>
246f4bc952SArnaud Patard (Rtp) #include <sound/pcm_params.h>
256f4bc952SArnaud Patard (Rtp) #include <sound/tlv.h>
266f4bc952SArnaud Patard (Rtp) #include <sound/soc.h>
276f4bc952SArnaud Patard (Rtp) #include <sound/initval.h>
286f4bc952SArnaud Patard (Rtp) #include <sound/alc5623.h>
296f4bc952SArnaud Patard (Rtp) 
306f4bc952SArnaud Patard (Rtp) #include "alc5623.h"
316f4bc952SArnaud Patard (Rtp) 
326f4bc952SArnaud Patard (Rtp) static int caps_charge = 2000;
336f4bc952SArnaud Patard (Rtp) module_param(caps_charge, int, 0);
346f4bc952SArnaud Patard (Rtp) MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)");
356f4bc952SArnaud Patard (Rtp) 
366f4bc952SArnaud Patard (Rtp) /* codec private data */
376f4bc952SArnaud Patard (Rtp) struct alc5623_priv {
380cd257bfSMark Brown 	struct regmap *regmap;
396f4bc952SArnaud Patard (Rtp) 	u8 id;
406f4bc952SArnaud Patard (Rtp) 	unsigned int sysclk;
416f4bc952SArnaud Patard (Rtp) 	unsigned int add_ctrl;
426f4bc952SArnaud Patard (Rtp) 	unsigned int jack_det_ctrl;
436f4bc952SArnaud Patard (Rtp) };
446f4bc952SArnaud Patard (Rtp) 
alc5623_reset(struct snd_soc_component * component)45fd7c728dSKuninori Morimoto static inline int alc5623_reset(struct snd_soc_component *component)
466f4bc952SArnaud Patard (Rtp) {
47fd7c728dSKuninori Morimoto 	return snd_soc_component_write(component, ALC5623_RESET, 0);
486f4bc952SArnaud Patard (Rtp) }
496f4bc952SArnaud Patard (Rtp) 
amp_mixer_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)506f4bc952SArnaud Patard (Rtp) static int amp_mixer_event(struct snd_soc_dapm_widget *w,
516f4bc952SArnaud Patard (Rtp) 	struct snd_kcontrol *kcontrol, int event)
526f4bc952SArnaud Patard (Rtp) {
53fd7c728dSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
54a50d761fSLars-Peter Clausen 
556f4bc952SArnaud Patard (Rtp) 	/* to power-on/off class-d amp generators/speaker */
566f4bc952SArnaud Patard (Rtp) 	/* need to write to 'index-46h' register :        */
576f4bc952SArnaud Patard (Rtp) 	/* so write index num (here 0x46) to reg 0x6a     */
586f4bc952SArnaud Patard (Rtp) 	/* and then 0xffff/0 to reg 0x6c                  */
59fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_HID_CTRL_INDEX, 0x46);
606f4bc952SArnaud Patard (Rtp) 
616f4bc952SArnaud Patard (Rtp) 	switch (event) {
626f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAPM_PRE_PMU:
63fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_HID_CTRL_DATA, 0xFFFF);
646f4bc952SArnaud Patard (Rtp) 		break;
656f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAPM_POST_PMD:
66fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_HID_CTRL_DATA, 0);
676f4bc952SArnaud Patard (Rtp) 		break;
686f4bc952SArnaud Patard (Rtp) 	}
696f4bc952SArnaud Patard (Rtp) 
706f4bc952SArnaud Patard (Rtp) 	return 0;
716f4bc952SArnaud Patard (Rtp) }
726f4bc952SArnaud Patard (Rtp) 
736f4bc952SArnaud Patard (Rtp) /*
746f4bc952SArnaud Patard (Rtp)  * ALC5623 Controls
756f4bc952SArnaud Patard (Rtp)  */
766f4bc952SArnaud Patard (Rtp) 
776f4bc952SArnaud Patard (Rtp) static const DECLARE_TLV_DB_SCALE(vol_tlv, -3450, 150, 0);
786f4bc952SArnaud Patard (Rtp) static const DECLARE_TLV_DB_SCALE(hp_tlv, -4650, 150, 0);
796f4bc952SArnaud Patard (Rtp) static const DECLARE_TLV_DB_SCALE(adc_rec_tlv, -1650, 150, 0);
80c8aeb0f6SLars-Peter Clausen static const DECLARE_TLV_DB_RANGE(boost_tlv,
816f4bc952SArnaud Patard (Rtp) 	0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
826f4bc952SArnaud Patard (Rtp) 	1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
83c8aeb0f6SLars-Peter Clausen 	2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0)
84c8aeb0f6SLars-Peter Clausen );
856f4bc952SArnaud Patard (Rtp) static const DECLARE_TLV_DB_SCALE(dig_tlv, 0, 600, 0);
866f4bc952SArnaud Patard (Rtp) 
876048ef76SAxel Lin static const struct snd_kcontrol_new alc5621_vol_snd_controls[] = {
886f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Speaker Playback Volume",
896f4bc952SArnaud Patard (Rtp) 			ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
906f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Speaker Playback Switch",
916f4bc952SArnaud Patard (Rtp) 			ALC5623_SPK_OUT_VOL, 15, 7, 1, 1),
926f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Headphone Playback Volume",
936f4bc952SArnaud Patard (Rtp) 			ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv),
946f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Headphone Playback Switch",
956f4bc952SArnaud Patard (Rtp) 			ALC5623_HP_OUT_VOL, 15, 7, 1, 1),
966f4bc952SArnaud Patard (Rtp) };
976f4bc952SArnaud Patard (Rtp) 
986048ef76SAxel Lin static const struct snd_kcontrol_new alc5622_vol_snd_controls[] = {
996f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Speaker Playback Volume",
1006f4bc952SArnaud Patard (Rtp) 			ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
1016f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Speaker Playback Switch",
1026f4bc952SArnaud Patard (Rtp) 			ALC5623_SPK_OUT_VOL, 15, 7, 1, 1),
1036f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Line Playback Volume",
1046f4bc952SArnaud Patard (Rtp) 			ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv),
1056f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Line Playback Switch",
1066f4bc952SArnaud Patard (Rtp) 			ALC5623_HP_OUT_VOL, 15, 7, 1, 1),
1076f4bc952SArnaud Patard (Rtp) };
1086f4bc952SArnaud Patard (Rtp) 
1096f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_vol_snd_controls[] = {
1106f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Line Playback Volume",
1116f4bc952SArnaud Patard (Rtp) 			ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv),
1126f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Line Playback Switch",
1136f4bc952SArnaud Patard (Rtp) 			ALC5623_SPK_OUT_VOL, 15, 7, 1, 1),
1146f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Headphone Playback Volume",
1156f4bc952SArnaud Patard (Rtp) 			ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv),
1166f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Headphone Playback Switch",
1176f4bc952SArnaud Patard (Rtp) 			ALC5623_HP_OUT_VOL, 15, 7, 1, 1),
1186f4bc952SArnaud Patard (Rtp) };
1196f4bc952SArnaud Patard (Rtp) 
1206f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_snd_controls[] = {
1216f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Auxout Playback Volume",
1226f4bc952SArnaud Patard (Rtp) 			ALC5623_MONO_AUX_OUT_VOL, 8, 0, 31, 1, hp_tlv),
1236f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE("Auxout Playback Switch",
1246f4bc952SArnaud Patard (Rtp) 			ALC5623_MONO_AUX_OUT_VOL, 15, 7, 1, 1),
1256f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("PCM Playback Volume",
1266f4bc952SArnaud Patard (Rtp) 			ALC5623_STEREO_DAC_VOL, 8, 0, 31, 1, vol_tlv),
1276f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("AuxI Capture Volume",
1286f4bc952SArnaud Patard (Rtp) 			ALC5623_AUXIN_VOL, 8, 0, 31, 1, vol_tlv),
1296f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("LineIn Capture Volume",
1306f4bc952SArnaud Patard (Rtp) 			ALC5623_LINE_IN_VOL, 8, 0, 31, 1, vol_tlv),
1316f4bc952SArnaud Patard (Rtp) 	SOC_SINGLE_TLV("Mic1 Capture Volume",
1326f4bc952SArnaud Patard (Rtp) 			ALC5623_MIC_VOL, 8, 31, 1, vol_tlv),
1336f4bc952SArnaud Patard (Rtp) 	SOC_SINGLE_TLV("Mic2 Capture Volume",
1346f4bc952SArnaud Patard (Rtp) 			ALC5623_MIC_VOL, 0, 31, 1, vol_tlv),
1356f4bc952SArnaud Patard (Rtp) 	SOC_DOUBLE_TLV("Rec Capture Volume",
1366f4bc952SArnaud Patard (Rtp) 			ALC5623_ADC_REC_GAIN, 7, 0, 31, 0, adc_rec_tlv),
1376f4bc952SArnaud Patard (Rtp) 	SOC_SINGLE_TLV("Mic 1 Boost Volume",
1386f4bc952SArnaud Patard (Rtp) 			ALC5623_MIC_CTRL, 10, 2, 0, boost_tlv),
1396f4bc952SArnaud Patard (Rtp) 	SOC_SINGLE_TLV("Mic 2 Boost Volume",
1406f4bc952SArnaud Patard (Rtp) 			ALC5623_MIC_CTRL, 8, 2, 0, boost_tlv),
1416f4bc952SArnaud Patard (Rtp) 	SOC_SINGLE_TLV("Digital Boost Volume",
1426f4bc952SArnaud Patard (Rtp) 			ALC5623_ADD_CTRL_REG, 4, 3, 0, dig_tlv),
1436f4bc952SArnaud Patard (Rtp) };
1446f4bc952SArnaud Patard (Rtp) 
1456f4bc952SArnaud Patard (Rtp) /*
1466f4bc952SArnaud Patard (Rtp)  * DAPM Controls
1476f4bc952SArnaud Patard (Rtp)  */
1486f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_hp_mixer_controls[] = {
1496f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5623_LINE_IN_VOL, 15, 1, 1),
1506f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("AUXI2HP Playback Switch", ALC5623_AUXIN_VOL, 15, 1, 1),
1516f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5623_MIC_ROUTING_CTRL, 15, 1, 1),
1526f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5623_MIC_ROUTING_CTRL, 7, 1, 1),
1536f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("DAC2HP Playback Switch", ALC5623_STEREO_DAC_VOL, 15, 1, 1),
1546f4bc952SArnaud Patard (Rtp) };
1556f4bc952SArnaud Patard (Rtp) 
1566f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_hpl_mixer_controls[] = {
1576f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5623_ADC_REC_GAIN, 15, 1, 1),
1586f4bc952SArnaud Patard (Rtp) };
1596f4bc952SArnaud Patard (Rtp) 
1606f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_hpr_mixer_controls[] = {
1616f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5623_ADC_REC_GAIN, 14, 1, 1),
1626f4bc952SArnaud Patard (Rtp) };
1636f4bc952SArnaud Patard (Rtp) 
1646f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_mono_mixer_controls[] = {
1656f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5623_ADC_REC_GAIN, 13, 1, 1),
1666f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5623_ADC_REC_GAIN, 12, 1, 1),
1676f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5623_LINE_IN_VOL, 13, 1, 1),
1686f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("AUXI2MONO Playback Switch", ALC5623_AUXIN_VOL, 13, 1, 1),
1696f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MIC12MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL, 13, 1, 1),
1706f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MIC22MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL, 5, 1, 1),
1716f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5623_STEREO_DAC_VOL, 13, 1, 1),
1726f4bc952SArnaud Patard (Rtp) };
1736f4bc952SArnaud Patard (Rtp) 
1746f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_speaker_mixer_controls[] = {
1756f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5623_LINE_IN_VOL, 14, 1, 1),
1766f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("AUXI2SPK Playback Switch", ALC5623_AUXIN_VOL, 14, 1, 1),
1776f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MIC12SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL, 14, 1, 1),
1786f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MIC22SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL, 6, 1, 1),
1796f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5623_STEREO_DAC_VOL, 14, 1, 1),
1806f4bc952SArnaud Patard (Rtp) };
1816f4bc952SArnaud Patard (Rtp) 
1826f4bc952SArnaud Patard (Rtp) /* Left Record Mixer */
1836f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_captureL_mixer_controls[] = {
1846f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER, 14, 1, 1),
1856f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER, 13, 1, 1),
1866f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("LineInL Capture Switch", ALC5623_ADC_REC_MIXER, 12, 1, 1),
1876f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("Left AuxI Capture Switch", ALC5623_ADC_REC_MIXER, 11, 1, 1),
1886f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("HPMixerL Capture Switch", ALC5623_ADC_REC_MIXER, 10, 1, 1),
1896f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER, 9, 1, 1),
1906f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER, 8, 1, 1),
1916f4bc952SArnaud Patard (Rtp) };
1926f4bc952SArnaud Patard (Rtp) 
1936f4bc952SArnaud Patard (Rtp) /* Right Record Mixer */
1946f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_captureR_mixer_controls[] = {
1956f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER, 6, 1, 1),
1966f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER, 5, 1, 1),
1976f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("LineInR Capture Switch", ALC5623_ADC_REC_MIXER, 4, 1, 1),
1986f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("Right AuxI Capture Switch", ALC5623_ADC_REC_MIXER, 3, 1, 1),
1996f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("HPMixerR Capture Switch", ALC5623_ADC_REC_MIXER, 2, 1, 1),
2006f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER, 1, 1, 1),
2016f4bc952SArnaud Patard (Rtp) SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER, 0, 1, 1),
2026f4bc952SArnaud Patard (Rtp) };
2036f4bc952SArnaud Patard (Rtp) 
2046f4bc952SArnaud Patard (Rtp) static const char *alc5623_spk_n_sour_sel[] = {
2056f4bc952SArnaud Patard (Rtp) 		"RN/-R", "RP/+R", "LN/-R", "Vmid" };
2066f4bc952SArnaud Patard (Rtp) static const char *alc5623_hpl_out_input_sel[] = {
2076f4bc952SArnaud Patard (Rtp) 		"Vmid", "HP Left Mix"};
2086f4bc952SArnaud Patard (Rtp) static const char *alc5623_hpr_out_input_sel[] = {
2096f4bc952SArnaud Patard (Rtp) 		"Vmid", "HP Right Mix"};
2106f4bc952SArnaud Patard (Rtp) static const char *alc5623_spkout_input_sel[] = {
2116f4bc952SArnaud Patard (Rtp) 		"Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
2126f4bc952SArnaud Patard (Rtp) static const char *alc5623_aux_out_input_sel[] = {
2136f4bc952SArnaud Patard (Rtp) 		"Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
2146f4bc952SArnaud Patard (Rtp) 
2156f4bc952SArnaud Patard (Rtp) /* auxout output mux */
21698bf1b5eSTakashi Iwai static SOC_ENUM_SINGLE_DECL(alc5623_aux_out_input_enum,
21798bf1b5eSTakashi Iwai 			    ALC5623_OUTPUT_MIXER_CTRL, 6,
21898bf1b5eSTakashi Iwai 			    alc5623_aux_out_input_sel);
2196f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_auxout_mux_controls =
2206f4bc952SArnaud Patard (Rtp) SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum);
2216f4bc952SArnaud Patard (Rtp) 
2226f4bc952SArnaud Patard (Rtp) /* speaker output mux */
22398bf1b5eSTakashi Iwai static SOC_ENUM_SINGLE_DECL(alc5623_spkout_input_enum,
22498bf1b5eSTakashi Iwai 			    ALC5623_OUTPUT_MIXER_CTRL, 10,
22598bf1b5eSTakashi Iwai 			    alc5623_spkout_input_sel);
2266f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_spkout_mux_controls =
2276f4bc952SArnaud Patard (Rtp) SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum);
2286f4bc952SArnaud Patard (Rtp) 
2296f4bc952SArnaud Patard (Rtp) /* headphone left output mux */
23098bf1b5eSTakashi Iwai static SOC_ENUM_SINGLE_DECL(alc5623_hpl_out_input_enum,
23198bf1b5eSTakashi Iwai 			    ALC5623_OUTPUT_MIXER_CTRL, 9,
23298bf1b5eSTakashi Iwai 			    alc5623_hpl_out_input_sel);
2336f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls =
2346f4bc952SArnaud Patard (Rtp) SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum);
2356f4bc952SArnaud Patard (Rtp) 
2366f4bc952SArnaud Patard (Rtp) /* headphone right output mux */
23798bf1b5eSTakashi Iwai static SOC_ENUM_SINGLE_DECL(alc5623_hpr_out_input_enum,
23898bf1b5eSTakashi Iwai 			    ALC5623_OUTPUT_MIXER_CTRL, 8,
23998bf1b5eSTakashi Iwai 			    alc5623_hpr_out_input_sel);
2406f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls =
2416f4bc952SArnaud Patard (Rtp) SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum);
2426f4bc952SArnaud Patard (Rtp) 
2436f4bc952SArnaud Patard (Rtp) /* speaker output N select */
24498bf1b5eSTakashi Iwai static SOC_ENUM_SINGLE_DECL(alc5623_spk_n_sour_enum,
24598bf1b5eSTakashi Iwai 			    ALC5623_OUTPUT_MIXER_CTRL, 14,
24698bf1b5eSTakashi Iwai 			    alc5623_spk_n_sour_sel);
2476f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls =
2486f4bc952SArnaud Patard (Rtp) SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum);
2496f4bc952SArnaud Patard (Rtp) 
2506f4bc952SArnaud Patard (Rtp) static const struct snd_soc_dapm_widget alc5623_dapm_widgets[] = {
2516f4bc952SArnaud Patard (Rtp) /* Muxes */
2526f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM, 0, 0,
2536f4bc952SArnaud Patard (Rtp) 	&alc5623_auxout_mux_controls),
2546f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM, 0, 0,
2556f4bc952SArnaud Patard (Rtp) 	&alc5623_spkout_mux_controls),
2566f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0,
2576f4bc952SArnaud Patard (Rtp) 	&alc5623_hpl_out_mux_controls),
2586f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0,
2596f4bc952SArnaud Patard (Rtp) 	&alc5623_hpr_out_mux_controls),
2606f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM, 0, 0,
2616f4bc952SArnaud Patard (Rtp) 	&alc5623_spkoutn_mux_controls),
2626f4bc952SArnaud Patard (Rtp) 
2636f4bc952SArnaud Patard (Rtp) /* output mixers */
2646f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM, 0, 0,
2656f4bc952SArnaud Patard (Rtp) 	&alc5623_hp_mixer_controls[0],
2666f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_hp_mixer_controls)),
2676f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("HPR Mix", ALC5623_PWR_MANAG_ADD2, 4, 0,
2686f4bc952SArnaud Patard (Rtp) 	&alc5623_hpr_mixer_controls[0],
2696f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_hpr_mixer_controls)),
2706f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("HPL Mix", ALC5623_PWR_MANAG_ADD2, 5, 0,
2716f4bc952SArnaud Patard (Rtp) 	&alc5623_hpl_mixer_controls[0],
2726f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_hpl_mixer_controls)),
2736f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
2746f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("Mono Mix", ALC5623_PWR_MANAG_ADD2, 2, 0,
2756f4bc952SArnaud Patard (Rtp) 	&alc5623_mono_mixer_controls[0],
2766f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_mono_mixer_controls)),
2776f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("Speaker Mix", ALC5623_PWR_MANAG_ADD2, 3, 0,
2786f4bc952SArnaud Patard (Rtp) 	&alc5623_speaker_mixer_controls[0],
2796f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_speaker_mixer_controls)),
2806f4bc952SArnaud Patard (Rtp) 
2816f4bc952SArnaud Patard (Rtp) /* input mixers */
2826f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5623_PWR_MANAG_ADD2, 1, 0,
2836f4bc952SArnaud Patard (Rtp) 	&alc5623_captureL_mixer_controls[0],
2846f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_captureL_mixer_controls)),
2856f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5623_PWR_MANAG_ADD2, 0, 0,
2866f4bc952SArnaud Patard (Rtp) 	&alc5623_captureR_mixer_controls[0],
2876f4bc952SArnaud Patard (Rtp) 	ARRAY_SIZE(alc5623_captureR_mixer_controls)),
2886f4bc952SArnaud Patard (Rtp) 
2896f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
2906f4bc952SArnaud Patard (Rtp) 	ALC5623_PWR_MANAG_ADD2, 9, 0),
2916f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
2926f4bc952SArnaud Patard (Rtp) 	ALC5623_PWR_MANAG_ADD2, 8, 0),
2936f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("I2S Mix", ALC5623_PWR_MANAG_ADD1, 15, 0, NULL, 0),
2946f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("AuxI Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
2956f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM, 0, 0, NULL, 0),
2966f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture",
2976f4bc952SArnaud Patard (Rtp) 	ALC5623_PWR_MANAG_ADD2, 7, 0),
2986f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture",
2996f4bc952SArnaud Patard (Rtp) 	ALC5623_PWR_MANAG_ADD2, 6, 0),
3006f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Left Headphone", ALC5623_PWR_MANAG_ADD3, 10, 0, NULL, 0),
3016f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Right Headphone", ALC5623_PWR_MANAG_ADD3, 9, 0, NULL, 0),
3026f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("SpeakerOut", ALC5623_PWR_MANAG_ADD3, 12, 0, NULL, 0),
3036f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Left AuxOut", ALC5623_PWR_MANAG_ADD3, 14, 0, NULL, 0),
3046f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Right AuxOut", ALC5623_PWR_MANAG_ADD3, 13, 0, NULL, 0),
3056f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Left LineIn", ALC5623_PWR_MANAG_ADD3, 7, 0, NULL, 0),
3066f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Right LineIn", ALC5623_PWR_MANAG_ADD3, 6, 0, NULL, 0),
3076f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Left AuxI", ALC5623_PWR_MANAG_ADD3, 5, 0, NULL, 0),
3086f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("Right AuxI", ALC5623_PWR_MANAG_ADD3, 4, 0, NULL, 0),
3096f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("MIC1 PGA", ALC5623_PWR_MANAG_ADD3, 3, 0, NULL, 0),
3106f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("MIC2 PGA", ALC5623_PWR_MANAG_ADD3, 2, 0, NULL, 0),
3116f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5623_PWR_MANAG_ADD3, 1, 0, NULL, 0),
3126f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5623_PWR_MANAG_ADD3, 0, 0, NULL, 0),
3136f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MICBIAS("Mic Bias1", ALC5623_PWR_MANAG_ADD1, 11, 0),
3146f4bc952SArnaud Patard (Rtp) 
3156f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_OUTPUT("AUXOUTL"),
3166f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_OUTPUT("AUXOUTR"),
3176f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_OUTPUT("HPL"),
3186f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_OUTPUT("HPR"),
3196f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_OUTPUT("SPKOUT"),
3206f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_OUTPUT("SPKOUTN"),
3216f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_INPUT("LINEINL"),
3226f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_INPUT("LINEINR"),
3236f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_INPUT("AUXINL"),
3246f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_INPUT("AUXINR"),
3256f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_INPUT("MIC1"),
3266f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_INPUT("MIC2"),
3276f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_VMID("Vmid"),
3286f4bc952SArnaud Patard (Rtp) };
3296f4bc952SArnaud Patard (Rtp) 
3306f4bc952SArnaud Patard (Rtp) static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"};
33198bf1b5eSTakashi Iwai static SOC_ENUM_SINGLE_DECL(alc5623_amp_enum,
33298bf1b5eSTakashi Iwai 			    ALC5623_OUTPUT_MIXER_CTRL, 13,
33398bf1b5eSTakashi Iwai 			    alc5623_amp_names);
3346f4bc952SArnaud Patard (Rtp) static const struct snd_kcontrol_new alc5623_amp_mux_controls =
3356f4bc952SArnaud Patard (Rtp) 	SOC_DAPM_ENUM("Route", alc5623_amp_enum);
3366f4bc952SArnaud Patard (Rtp) 
3376f4bc952SArnaud Patard (Rtp) static const struct snd_soc_dapm_widget alc5623_dapm_amp_widgets[] = {
3386f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA_E("D Amp", ALC5623_PWR_MANAG_ADD2, 14, 0, NULL, 0,
3396f4bc952SArnaud Patard (Rtp) 	amp_mixer_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
3406f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_PGA("AB Amp", ALC5623_PWR_MANAG_ADD2, 15, 0, NULL, 0),
3416f4bc952SArnaud Patard (Rtp) SND_SOC_DAPM_MUX("AB-D Amp Mux", SND_SOC_NOPM, 0, 0,
3426f4bc952SArnaud Patard (Rtp) 	&alc5623_amp_mux_controls),
3436f4bc952SArnaud Patard (Rtp) };
3446f4bc952SArnaud Patard (Rtp) 
3456f4bc952SArnaud Patard (Rtp) static const struct snd_soc_dapm_route intercon[] = {
3466f4bc952SArnaud Patard (Rtp) 	/* virtual mixer - mixes left & right channels */
3476f4bc952SArnaud Patard (Rtp) 	{"I2S Mix", NULL,				"Left DAC"},
3486f4bc952SArnaud Patard (Rtp) 	{"I2S Mix", NULL,				"Right DAC"},
3496f4bc952SArnaud Patard (Rtp) 	{"Line Mix", NULL,				"Right LineIn"},
3506f4bc952SArnaud Patard (Rtp) 	{"Line Mix", NULL,				"Left LineIn"},
3516f4bc952SArnaud Patard (Rtp) 	{"AuxI Mix", NULL,				"Left AuxI"},
3526f4bc952SArnaud Patard (Rtp) 	{"AuxI Mix", NULL,				"Right AuxI"},
3536f4bc952SArnaud Patard (Rtp) 	{"AUXOUTL", NULL,				"Left AuxOut"},
3546f4bc952SArnaud Patard (Rtp) 	{"AUXOUTR", NULL,				"Right AuxOut"},
3556f4bc952SArnaud Patard (Rtp) 
3566f4bc952SArnaud Patard (Rtp) 	/* HP mixer */
3576f4bc952SArnaud Patard (Rtp) 	{"HPL Mix", "ADC2HP_L Playback Switch",		"Left Capture Mix"},
3586f4bc952SArnaud Patard (Rtp) 	{"HPL Mix", NULL,				"HP Mix"},
3596f4bc952SArnaud Patard (Rtp) 	{"HPR Mix", "ADC2HP_R Playback Switch",		"Right Capture Mix"},
3606f4bc952SArnaud Patard (Rtp) 	{"HPR Mix", NULL,				"HP Mix"},
3616f4bc952SArnaud Patard (Rtp) 	{"HP Mix", "LI2HP Playback Switch",		"Line Mix"},
3626f4bc952SArnaud Patard (Rtp) 	{"HP Mix", "AUXI2HP Playback Switch",		"AuxI Mix"},
3636f4bc952SArnaud Patard (Rtp) 	{"HP Mix", "MIC12HP Playback Switch",		"MIC1 PGA"},
3646f4bc952SArnaud Patard (Rtp) 	{"HP Mix", "MIC22HP Playback Switch",		"MIC2 PGA"},
3656f4bc952SArnaud Patard (Rtp) 	{"HP Mix", "DAC2HP Playback Switch",		"I2S Mix"},
3666f4bc952SArnaud Patard (Rtp) 
3676f4bc952SArnaud Patard (Rtp) 	/* speaker mixer */
3686f4bc952SArnaud Patard (Rtp) 	{"Speaker Mix", "LI2SPK Playback Switch",	"Line Mix"},
3696f4bc952SArnaud Patard (Rtp) 	{"Speaker Mix", "AUXI2SPK Playback Switch",	"AuxI Mix"},
3706f4bc952SArnaud Patard (Rtp) 	{"Speaker Mix", "MIC12SPK Playback Switch",	"MIC1 PGA"},
3716f4bc952SArnaud Patard (Rtp) 	{"Speaker Mix", "MIC22SPK Playback Switch",	"MIC2 PGA"},
3726f4bc952SArnaud Patard (Rtp) 	{"Speaker Mix", "DAC2SPK Playback Switch",	"I2S Mix"},
3736f4bc952SArnaud Patard (Rtp) 
3746f4bc952SArnaud Patard (Rtp) 	/* mono mixer */
3756f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "ADC2MONO_L Playback Switch",	"Left Capture Mix"},
3766f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "ADC2MONO_R Playback Switch",	"Right Capture Mix"},
3776f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "LI2MONO Playback Switch",		"Line Mix"},
3786f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "AUXI2MONO Playback Switch",	"AuxI Mix"},
3796f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "MIC12MONO Playback Switch",	"MIC1 PGA"},
3806f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "MIC22MONO Playback Switch",	"MIC2 PGA"},
3816f4bc952SArnaud Patard (Rtp) 	{"Mono Mix", "DAC2MONO Playback Switch",	"I2S Mix"},
3826f4bc952SArnaud Patard (Rtp) 
3836f4bc952SArnaud Patard (Rtp) 	/* Left record mixer */
3846f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "LineInL Capture Switch",	"LINEINL"},
3856f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "Left AuxI Capture Switch", "AUXINL"},
3866f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "Mic1 Capture Switch",	"MIC1 Pre Amp"},
3876f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "Mic2 Capture Switch",	"MIC2 Pre Amp"},
3886f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "HPMixerL Capture Switch", "HPL Mix"},
3896f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
3906f4bc952SArnaud Patard (Rtp) 	{"Left Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
3916f4bc952SArnaud Patard (Rtp) 
3926f4bc952SArnaud Patard (Rtp) 	/*Right record mixer */
3936f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "LineInR Capture Switch",	"LINEINR"},
3946f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "Right AuxI Capture Switch",	"AUXINR"},
3956f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "Mic1 Capture Switch",	"MIC1 Pre Amp"},
3966f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "Mic2 Capture Switch",	"MIC2 Pre Amp"},
3976f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "HPMixerR Capture Switch", "HPR Mix"},
3986f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
3996f4bc952SArnaud Patard (Rtp) 	{"Right Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
4006f4bc952SArnaud Patard (Rtp) 
4016f4bc952SArnaud Patard (Rtp) 	/* headphone left mux */
4026f4bc952SArnaud Patard (Rtp) 	{"Left Headphone Mux", "HP Left Mix",		"HPL Mix"},
4036f4bc952SArnaud Patard (Rtp) 	{"Left Headphone Mux", "Vmid",			"Vmid"},
4046f4bc952SArnaud Patard (Rtp) 
4056f4bc952SArnaud Patard (Rtp) 	/* headphone right mux */
4066f4bc952SArnaud Patard (Rtp) 	{"Right Headphone Mux", "HP Right Mix",		"HPR Mix"},
4076f4bc952SArnaud Patard (Rtp) 	{"Right Headphone Mux", "Vmid",			"Vmid"},
4086f4bc952SArnaud Patard (Rtp) 
4096f4bc952SArnaud Patard (Rtp) 	/* speaker out mux */
4106f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut Mux", "Vmid",			"Vmid"},
4116f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut Mux", "HPOut Mix",			"HPOut Mix"},
4126f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut Mux", "Speaker Mix",		"Speaker Mix"},
4136f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut Mux", "Mono Mix",			"Mono Mix"},
4146f4bc952SArnaud Patard (Rtp) 
4156f4bc952SArnaud Patard (Rtp) 	/* Mono/Aux Out mux */
4166f4bc952SArnaud Patard (Rtp) 	{"AuxOut Mux", "Vmid",				"Vmid"},
4176f4bc952SArnaud Patard (Rtp) 	{"AuxOut Mux", "HPOut Mix",			"HPOut Mix"},
4186f4bc952SArnaud Patard (Rtp) 	{"AuxOut Mux", "Speaker Mix",			"Speaker Mix"},
4196f4bc952SArnaud Patard (Rtp) 	{"AuxOut Mux", "Mono Mix",			"Mono Mix"},
4206f4bc952SArnaud Patard (Rtp) 
4216f4bc952SArnaud Patard (Rtp) 	/* output pga */
4226f4bc952SArnaud Patard (Rtp) 	{"HPL", NULL,					"Left Headphone"},
4236f4bc952SArnaud Patard (Rtp) 	{"Left Headphone", NULL,			"Left Headphone Mux"},
4246f4bc952SArnaud Patard (Rtp) 	{"HPR", NULL,					"Right Headphone"},
4256f4bc952SArnaud Patard (Rtp) 	{"Right Headphone", NULL,			"Right Headphone Mux"},
4266f4bc952SArnaud Patard (Rtp) 	{"Left AuxOut", NULL,				"AuxOut Mux"},
4276f4bc952SArnaud Patard (Rtp) 	{"Right AuxOut", NULL,				"AuxOut Mux"},
4286f4bc952SArnaud Patard (Rtp) 
4296f4bc952SArnaud Patard (Rtp) 	/* input pga */
4306f4bc952SArnaud Patard (Rtp) 	{"Left LineIn", NULL,				"LINEINL"},
4316f4bc952SArnaud Patard (Rtp) 	{"Right LineIn", NULL,				"LINEINR"},
4326f4bc952SArnaud Patard (Rtp) 	{"Left AuxI", NULL,				"AUXINL"},
4336f4bc952SArnaud Patard (Rtp) 	{"Right AuxI", NULL,				"AUXINR"},
4346f4bc952SArnaud Patard (Rtp) 	{"MIC1 Pre Amp", NULL,				"MIC1"},
4356f4bc952SArnaud Patard (Rtp) 	{"MIC2 Pre Amp", NULL,				"MIC2"},
4366f4bc952SArnaud Patard (Rtp) 	{"MIC1 PGA", NULL,				"MIC1 Pre Amp"},
4376f4bc952SArnaud Patard (Rtp) 	{"MIC2 PGA", NULL,				"MIC2 Pre Amp"},
4386f4bc952SArnaud Patard (Rtp) 
4396f4bc952SArnaud Patard (Rtp) 	/* left ADC */
4406f4bc952SArnaud Patard (Rtp) 	{"Left ADC", NULL,				"Left Capture Mix"},
4416f4bc952SArnaud Patard (Rtp) 
4426f4bc952SArnaud Patard (Rtp) 	/* right ADC */
4436f4bc952SArnaud Patard (Rtp) 	{"Right ADC", NULL,				"Right Capture Mix"},
4446f4bc952SArnaud Patard (Rtp) 
4456f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut N Mux", "RN/-R",			"SpeakerOut"},
4466f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut N Mux", "RP/+R",			"SpeakerOut"},
4476f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut N Mux", "LN/-R",			"SpeakerOut"},
4486f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut N Mux", "Vmid",			"Vmid"},
4496f4bc952SArnaud Patard (Rtp) 
4506f4bc952SArnaud Patard (Rtp) 	{"SPKOUT", NULL,				"SpeakerOut"},
4516f4bc952SArnaud Patard (Rtp) 	{"SPKOUTN", NULL,				"SpeakerOut N Mux"},
4526f4bc952SArnaud Patard (Rtp) };
4536f4bc952SArnaud Patard (Rtp) 
4546f4bc952SArnaud Patard (Rtp) static const struct snd_soc_dapm_route intercon_spk[] = {
4556f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut", NULL,				"SpeakerOut Mux"},
4566f4bc952SArnaud Patard (Rtp) };
4576f4bc952SArnaud Patard (Rtp) 
4586f4bc952SArnaud Patard (Rtp) static const struct snd_soc_dapm_route intercon_amp_spk[] = {
4596f4bc952SArnaud Patard (Rtp) 	{"AB Amp", NULL,				"SpeakerOut Mux"},
4606f4bc952SArnaud Patard (Rtp) 	{"D Amp", NULL,					"SpeakerOut Mux"},
4616f4bc952SArnaud Patard (Rtp) 	{"AB-D Amp Mux", "AB Amp",			"AB Amp"},
4626f4bc952SArnaud Patard (Rtp) 	{"AB-D Amp Mux", "D Amp",			"D Amp"},
4636f4bc952SArnaud Patard (Rtp) 	{"SpeakerOut", NULL,				"AB-D Amp Mux"},
4646f4bc952SArnaud Patard (Rtp) };
4656f4bc952SArnaud Patard (Rtp) 
4666f4bc952SArnaud Patard (Rtp) /* PLL divisors */
4676f4bc952SArnaud Patard (Rtp) struct _pll_div {
4686f4bc952SArnaud Patard (Rtp) 	u32 pll_in;
4696f4bc952SArnaud Patard (Rtp) 	u32 pll_out;
4706f4bc952SArnaud Patard (Rtp) 	u16 regvalue;
4716f4bc952SArnaud Patard (Rtp) };
4726f4bc952SArnaud Patard (Rtp) 
4736f4bc952SArnaud Patard (Rtp) /* Note : pll code from original alc5623 driver. Not sure of how good it is */
47425985edcSLucas De Marchi /* useful only for master mode */
4756f4bc952SArnaud Patard (Rtp) static const struct _pll_div codec_master_pll_div[] = {
4766f4bc952SArnaud Patard (Rtp) 
4776f4bc952SArnaud Patard (Rtp) 	{  2048000,  8192000,	0x0ea0},
4786f4bc952SArnaud Patard (Rtp) 	{  3686400,  8192000,	0x4e27},
4796f4bc952SArnaud Patard (Rtp) 	{ 12000000,  8192000,	0x456b},
4806f4bc952SArnaud Patard (Rtp) 	{ 13000000,  8192000,	0x495f},
4816f4bc952SArnaud Patard (Rtp) 	{ 13100000,  8192000,	0x0320},
4826f4bc952SArnaud Patard (Rtp) 	{  2048000,  11289600,	0xf637},
4836f4bc952SArnaud Patard (Rtp) 	{  3686400,  11289600,	0x2f22},
4846f4bc952SArnaud Patard (Rtp) 	{ 12000000,  11289600,	0x3e2f},
4856f4bc952SArnaud Patard (Rtp) 	{ 13000000,  11289600,	0x4d5b},
4866f4bc952SArnaud Patard (Rtp) 	{ 13100000,  11289600,	0x363b},
4876f4bc952SArnaud Patard (Rtp) 	{  2048000,  16384000,	0x1ea0},
4886f4bc952SArnaud Patard (Rtp) 	{  3686400,  16384000,	0x9e27},
4896f4bc952SArnaud Patard (Rtp) 	{ 12000000,  16384000,	0x452b},
4906f4bc952SArnaud Patard (Rtp) 	{ 13000000,  16384000,	0x542f},
4916f4bc952SArnaud Patard (Rtp) 	{ 13100000,  16384000,	0x03a0},
4926f4bc952SArnaud Patard (Rtp) 	{  2048000,  16934400,	0xe625},
4936f4bc952SArnaud Patard (Rtp) 	{  3686400,  16934400,	0x9126},
4946f4bc952SArnaud Patard (Rtp) 	{ 12000000,  16934400,	0x4d2c},
4956f4bc952SArnaud Patard (Rtp) 	{ 13000000,  16934400,	0x742f},
4966f4bc952SArnaud Patard (Rtp) 	{ 13100000,  16934400,	0x3c27},
4976f4bc952SArnaud Patard (Rtp) 	{  2048000,  22579200,	0x2aa0},
4986f4bc952SArnaud Patard (Rtp) 	{  3686400,  22579200,	0x2f20},
4996f4bc952SArnaud Patard (Rtp) 	{ 12000000,  22579200,	0x7e2f},
5006f4bc952SArnaud Patard (Rtp) 	{ 13000000,  22579200,	0x742f},
5016f4bc952SArnaud Patard (Rtp) 	{ 13100000,  22579200,	0x3c27},
5026f4bc952SArnaud Patard (Rtp) 	{  2048000,  24576000,	0x2ea0},
5036f4bc952SArnaud Patard (Rtp) 	{  3686400,  24576000,	0xee27},
5046f4bc952SArnaud Patard (Rtp) 	{ 12000000,  24576000,	0x2915},
5056f4bc952SArnaud Patard (Rtp) 	{ 13000000,  24576000,	0x772e},
5066f4bc952SArnaud Patard (Rtp) 	{ 13100000,  24576000,	0x0d20},
5076f4bc952SArnaud Patard (Rtp) };
5086f4bc952SArnaud Patard (Rtp) 
5096f4bc952SArnaud Patard (Rtp) static const struct _pll_div codec_slave_pll_div[] = {
5106f4bc952SArnaud Patard (Rtp) 
5116f4bc952SArnaud Patard (Rtp) 	{  1024000,  16384000,  0x3ea0},
5126f4bc952SArnaud Patard (Rtp) 	{  1411200,  22579200,	0x3ea0},
5136f4bc952SArnaud Patard (Rtp) 	{  1536000,  24576000,	0x3ea0},
5146f4bc952SArnaud Patard (Rtp) 	{  2048000,  16384000,  0x1ea0},
5156f4bc952SArnaud Patard (Rtp) 	{  2822400,  22579200,	0x1ea0},
5166f4bc952SArnaud Patard (Rtp) 	{  3072000,  24576000,	0x1ea0},
5176f4bc952SArnaud Patard (Rtp) 
5186f4bc952SArnaud Patard (Rtp) };
5196f4bc952SArnaud Patard (Rtp) 
alc5623_set_dai_pll(struct snd_soc_dai * codec_dai,int pll_id,int source,unsigned int freq_in,unsigned int freq_out)5206f4bc952SArnaud Patard (Rtp) static int alc5623_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
5216f4bc952SArnaud Patard (Rtp) 		int source, unsigned int freq_in, unsigned int freq_out)
5226f4bc952SArnaud Patard (Rtp) {
5236f4bc952SArnaud Patard (Rtp) 	int i;
524fd7c728dSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
5256f4bc952SArnaud Patard (Rtp) 	int gbl_clk = 0, pll_div = 0;
5266f4bc952SArnaud Patard (Rtp) 	u16 reg;
5276f4bc952SArnaud Patard (Rtp) 
5286f4bc952SArnaud Patard (Rtp) 	if (pll_id < ALC5623_PLL_FR_MCLK || pll_id > ALC5623_PLL_FR_BCK)
5296f4bc952SArnaud Patard (Rtp) 		return -ENODEV;
5306f4bc952SArnaud Patard (Rtp) 
5316f4bc952SArnaud Patard (Rtp) 	/* Disable PLL power */
532fd7c728dSKuninori Morimoto 	snd_soc_component_update_bits(component, ALC5623_PWR_MANAG_ADD2,
5336f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD2_PLL,
5346f4bc952SArnaud Patard (Rtp) 				0);
5356f4bc952SArnaud Patard (Rtp) 
5366f4bc952SArnaud Patard (Rtp) 	/* pll is not used in slave mode */
537e896c1edSKuninori Morimoto 	reg = snd_soc_component_read(component, ALC5623_DAI_CONTROL);
5386f4bc952SArnaud Patard (Rtp) 	if (reg & ALC5623_DAI_SDP_SLAVE_MODE)
5396f4bc952SArnaud Patard (Rtp) 		return 0;
5406f4bc952SArnaud Patard (Rtp) 
5416f4bc952SArnaud Patard (Rtp) 	if (!freq_in || !freq_out)
5426f4bc952SArnaud Patard (Rtp) 		return 0;
5436f4bc952SArnaud Patard (Rtp) 
5446f4bc952SArnaud Patard (Rtp) 	switch (pll_id) {
5456f4bc952SArnaud Patard (Rtp) 	case ALC5623_PLL_FR_MCLK:
5466f4bc952SArnaud Patard (Rtp) 		for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) {
5476f4bc952SArnaud Patard (Rtp) 			if (codec_master_pll_div[i].pll_in == freq_in
5486f4bc952SArnaud Patard (Rtp) 			   && codec_master_pll_div[i].pll_out == freq_out) {
5496f4bc952SArnaud Patard (Rtp) 				/* PLL source from MCLK */
5506f4bc952SArnaud Patard (Rtp) 				pll_div  = codec_master_pll_div[i].regvalue;
5516f4bc952SArnaud Patard (Rtp) 				break;
5526f4bc952SArnaud Patard (Rtp) 			}
5536f4bc952SArnaud Patard (Rtp) 		}
5546f4bc952SArnaud Patard (Rtp) 		break;
5556f4bc952SArnaud Patard (Rtp) 	case ALC5623_PLL_FR_BCK:
5566f4bc952SArnaud Patard (Rtp) 		for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) {
5576f4bc952SArnaud Patard (Rtp) 			if (codec_slave_pll_div[i].pll_in == freq_in
5586f4bc952SArnaud Patard (Rtp) 			   && codec_slave_pll_div[i].pll_out == freq_out) {
5596f4bc952SArnaud Patard (Rtp) 				/* PLL source from Bitclk */
5606f4bc952SArnaud Patard (Rtp) 				gbl_clk = ALC5623_GBL_CLK_PLL_SOUR_SEL_BITCLK;
5616f4bc952SArnaud Patard (Rtp) 				pll_div = codec_slave_pll_div[i].regvalue;
5626f4bc952SArnaud Patard (Rtp) 				break;
5636f4bc952SArnaud Patard (Rtp) 			}
5646f4bc952SArnaud Patard (Rtp) 		}
5656f4bc952SArnaud Patard (Rtp) 		break;
5666f4bc952SArnaud Patard (Rtp) 	default:
5676f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
5686f4bc952SArnaud Patard (Rtp) 	}
5696f4bc952SArnaud Patard (Rtp) 
5706f4bc952SArnaud Patard (Rtp) 	if (!pll_div)
5716f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
5726f4bc952SArnaud Patard (Rtp) 
573fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_GLOBAL_CLK_CTRL_REG, gbl_clk);
574fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_PLL_CTRL, pll_div);
575fd7c728dSKuninori Morimoto 	snd_soc_component_update_bits(component, ALC5623_PWR_MANAG_ADD2,
5766f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD2_PLL,
5776f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD2_PLL);
5786f4bc952SArnaud Patard (Rtp) 	gbl_clk |= ALC5623_GBL_CLK_SYS_SOUR_SEL_PLL;
579fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_GLOBAL_CLK_CTRL_REG, gbl_clk);
5806f4bc952SArnaud Patard (Rtp) 
5816f4bc952SArnaud Patard (Rtp) 	return 0;
5826f4bc952SArnaud Patard (Rtp) }
5836f4bc952SArnaud Patard (Rtp) 
5846f4bc952SArnaud Patard (Rtp) struct _coeff_div {
5856f4bc952SArnaud Patard (Rtp) 	u16 fs;
5866f4bc952SArnaud Patard (Rtp) 	u16 regvalue;
5876f4bc952SArnaud Patard (Rtp) };
5886f4bc952SArnaud Patard (Rtp) 
5896f4bc952SArnaud Patard (Rtp) /* codec hifi mclk (after PLL) clock divider coefficients */
5906f4bc952SArnaud Patard (Rtp) /* values inspired from column BCLK=32Fs of Appendix A table */
5916f4bc952SArnaud Patard (Rtp) static const struct _coeff_div coeff_div[] = {
5926f4bc952SArnaud Patard (Rtp) 	{256*8, 0x3a69},
5936f4bc952SArnaud Patard (Rtp) 	{384*8, 0x3c6b},
5946f4bc952SArnaud Patard (Rtp) 	{256*4, 0x2a69},
5956f4bc952SArnaud Patard (Rtp) 	{384*4, 0x2c6b},
5966f4bc952SArnaud Patard (Rtp) 	{256*2, 0x1a69},
5976f4bc952SArnaud Patard (Rtp) 	{384*2, 0x1c6b},
5986f4bc952SArnaud Patard (Rtp) 	{256*1, 0x0a69},
5996f4bc952SArnaud Patard (Rtp) 	{384*1, 0x0c6b},
6006f4bc952SArnaud Patard (Rtp) };
6016f4bc952SArnaud Patard (Rtp) 
get_coeff(struct snd_soc_component * component,int rate)602fd7c728dSKuninori Morimoto static int get_coeff(struct snd_soc_component *component, int rate)
6036f4bc952SArnaud Patard (Rtp) {
604fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
6056f4bc952SArnaud Patard (Rtp) 	int i;
6066f4bc952SArnaud Patard (Rtp) 
6076f4bc952SArnaud Patard (Rtp) 	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
6086f4bc952SArnaud Patard (Rtp) 		if (coeff_div[i].fs * rate == alc5623->sysclk)
6096f4bc952SArnaud Patard (Rtp) 			return i;
6106f4bc952SArnaud Patard (Rtp) 	}
6116f4bc952SArnaud Patard (Rtp) 	return -EINVAL;
6126f4bc952SArnaud Patard (Rtp) }
6136f4bc952SArnaud Patard (Rtp) 
6146f4bc952SArnaud Patard (Rtp) /*
6156f4bc952SArnaud Patard (Rtp)  * Clock after PLL and dividers
6166f4bc952SArnaud Patard (Rtp)  */
alc5623_set_dai_sysclk(struct snd_soc_dai * codec_dai,int clk_id,unsigned int freq,int dir)6176f4bc952SArnaud Patard (Rtp) static int alc5623_set_dai_sysclk(struct snd_soc_dai *codec_dai,
6186f4bc952SArnaud Patard (Rtp) 		int clk_id, unsigned int freq, int dir)
6196f4bc952SArnaud Patard (Rtp) {
620fd7c728dSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
621fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
6226f4bc952SArnaud Patard (Rtp) 
6236f4bc952SArnaud Patard (Rtp) 	switch (freq) {
6246f4bc952SArnaud Patard (Rtp) 	case  8192000:
6256f4bc952SArnaud Patard (Rtp) 	case 11289600:
6266f4bc952SArnaud Patard (Rtp) 	case 12288000:
6276f4bc952SArnaud Patard (Rtp) 	case 16384000:
6286f4bc952SArnaud Patard (Rtp) 	case 16934400:
6296f4bc952SArnaud Patard (Rtp) 	case 18432000:
6306f4bc952SArnaud Patard (Rtp) 	case 22579200:
6316f4bc952SArnaud Patard (Rtp) 	case 24576000:
6326f4bc952SArnaud Patard (Rtp) 		alc5623->sysclk = freq;
6336f4bc952SArnaud Patard (Rtp) 		return 0;
6346f4bc952SArnaud Patard (Rtp) 	}
6356f4bc952SArnaud Patard (Rtp) 	return -EINVAL;
6366f4bc952SArnaud Patard (Rtp) }
6376f4bc952SArnaud Patard (Rtp) 
alc5623_set_dai_fmt(struct snd_soc_dai * codec_dai,unsigned int fmt)6386f4bc952SArnaud Patard (Rtp) static int alc5623_set_dai_fmt(struct snd_soc_dai *codec_dai,
6396f4bc952SArnaud Patard (Rtp) 		unsigned int fmt)
6406f4bc952SArnaud Patard (Rtp) {
641fd7c728dSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
6426f4bc952SArnaud Patard (Rtp) 	u16 iface = 0;
6436f4bc952SArnaud Patard (Rtp) 
6442a36bd83SMark Brown 	/* set audio interface clocking */
6452a36bd83SMark Brown 	switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
6462a36bd83SMark Brown 	case SND_SOC_DAIFMT_CBP_CFP:
6476f4bc952SArnaud Patard (Rtp) 		iface = ALC5623_DAI_SDP_MASTER_MODE;
6486f4bc952SArnaud Patard (Rtp) 		break;
6492a36bd83SMark Brown 	case SND_SOC_DAIFMT_CBC_CFC:
6506f4bc952SArnaud Patard (Rtp) 		iface = ALC5623_DAI_SDP_SLAVE_MODE;
6516f4bc952SArnaud Patard (Rtp) 		break;
6526f4bc952SArnaud Patard (Rtp) 	default:
6536f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
6546f4bc952SArnaud Patard (Rtp) 	}
6556f4bc952SArnaud Patard (Rtp) 
6566f4bc952SArnaud Patard (Rtp) 	/* interface format */
6576f4bc952SArnaud Patard (Rtp) 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
6586f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_I2S:
6596f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DF_I2S;
6606f4bc952SArnaud Patard (Rtp) 		break;
6616f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_RIGHT_J:
6626f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DF_RIGHT;
6636f4bc952SArnaud Patard (Rtp) 		break;
6646f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_LEFT_J:
6656f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DF_LEFT;
6666f4bc952SArnaud Patard (Rtp) 		break;
6676f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_DSP_A:
6686f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DF_PCM;
6696f4bc952SArnaud Patard (Rtp) 		break;
6706f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_DSP_B:
6716f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DF_PCM | ALC5623_DAI_I2S_PCM_MODE;
6726f4bc952SArnaud Patard (Rtp) 		break;
6736f4bc952SArnaud Patard (Rtp) 	default:
6746f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
6756f4bc952SArnaud Patard (Rtp) 	}
6766f4bc952SArnaud Patard (Rtp) 
6776f4bc952SArnaud Patard (Rtp) 	/* clock inversion */
6786f4bc952SArnaud Patard (Rtp) 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
6796f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_NB_NF:
6806f4bc952SArnaud Patard (Rtp) 		break;
6816f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_IB_IF:
6826f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL;
6836f4bc952SArnaud Patard (Rtp) 		break;
6846f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_IB_NF:
6856f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL;
6866f4bc952SArnaud Patard (Rtp) 		break;
6876f4bc952SArnaud Patard (Rtp) 	case SND_SOC_DAIFMT_NB_IF:
6886f4bc952SArnaud Patard (Rtp) 		break;
6896f4bc952SArnaud Patard (Rtp) 	default:
6906f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
6916f4bc952SArnaud Patard (Rtp) 	}
6926f4bc952SArnaud Patard (Rtp) 
693fd7c728dSKuninori Morimoto 	return snd_soc_component_write(component, ALC5623_DAI_CONTROL, iface);
6946f4bc952SArnaud Patard (Rtp) }
6956f4bc952SArnaud Patard (Rtp) 
alc5623_pcm_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)6966f4bc952SArnaud Patard (Rtp) static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream,
6976f4bc952SArnaud Patard (Rtp) 		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
6986f4bc952SArnaud Patard (Rtp) {
699fd7c728dSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
700fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
7016f4bc952SArnaud Patard (Rtp) 	int coeff, rate;
7026f4bc952SArnaud Patard (Rtp) 	u16 iface;
7036f4bc952SArnaud Patard (Rtp) 
704e896c1edSKuninori Morimoto 	iface = snd_soc_component_read(component, ALC5623_DAI_CONTROL);
7056f4bc952SArnaud Patard (Rtp) 	iface &= ~ALC5623_DAI_I2S_DL_MASK;
7066f4bc952SArnaud Patard (Rtp) 
7076f4bc952SArnaud Patard (Rtp) 	/* bit size */
7084a608b3aSMark Brown 	switch (params_width(params)) {
7094a608b3aSMark Brown 	case 16:
7106f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DL_16;
7116f4bc952SArnaud Patard (Rtp) 		break;
7124a608b3aSMark Brown 	case 20:
7136f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DL_20;
7146f4bc952SArnaud Patard (Rtp) 		break;
7154a608b3aSMark Brown 	case 24:
7166f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DL_24;
7176f4bc952SArnaud Patard (Rtp) 		break;
7184a608b3aSMark Brown 	case 32:
7196f4bc952SArnaud Patard (Rtp) 		iface |= ALC5623_DAI_I2S_DL_32;
7206f4bc952SArnaud Patard (Rtp) 		break;
7216f4bc952SArnaud Patard (Rtp) 	default:
7226f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
7236f4bc952SArnaud Patard (Rtp) 	}
7246f4bc952SArnaud Patard (Rtp) 
7256f4bc952SArnaud Patard (Rtp) 	/* set iface & srate */
726fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_DAI_CONTROL, iface);
7276f4bc952SArnaud Patard (Rtp) 	rate = params_rate(params);
728fd7c728dSKuninori Morimoto 	coeff = get_coeff(component, rate);
7296f4bc952SArnaud Patard (Rtp) 	if (coeff < 0)
7306f4bc952SArnaud Patard (Rtp) 		return -EINVAL;
7316f4bc952SArnaud Patard (Rtp) 
7326f4bc952SArnaud Patard (Rtp) 	coeff = coeff_div[coeff].regvalue;
733fd7c728dSKuninori Morimoto 	dev_dbg(component->dev, "%s: sysclk=%d,rate=%d,coeff=0x%04x\n",
7346f4bc952SArnaud Patard (Rtp) 		__func__, alc5623->sysclk, rate, coeff);
735fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_STEREO_AD_DA_CLK_CTRL, coeff);
7366f4bc952SArnaud Patard (Rtp) 
7376f4bc952SArnaud Patard (Rtp) 	return 0;
7386f4bc952SArnaud Patard (Rtp) }
7396f4bc952SArnaud Patard (Rtp) 
alc5623_mute(struct snd_soc_dai * dai,int mute,int direction)7404c66c2fcSKuninori Morimoto static int alc5623_mute(struct snd_soc_dai *dai, int mute, int direction)
7416f4bc952SArnaud Patard (Rtp) {
742fd7c728dSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
7436f4bc952SArnaud Patard (Rtp) 	u16 hp_mute = ALC5623_MISC_M_DAC_L_INPUT | ALC5623_MISC_M_DAC_R_INPUT;
744e896c1edSKuninori Morimoto 	u16 mute_reg = snd_soc_component_read(component, ALC5623_MISC_CTRL) & ~hp_mute;
7456f4bc952SArnaud Patard (Rtp) 
7466f4bc952SArnaud Patard (Rtp) 	if (mute)
7476f4bc952SArnaud Patard (Rtp) 		mute_reg |= hp_mute;
7486f4bc952SArnaud Patard (Rtp) 
749fd7c728dSKuninori Morimoto 	return snd_soc_component_write(component, ALC5623_MISC_CTRL, mute_reg);
7506f4bc952SArnaud Patard (Rtp) }
7516f4bc952SArnaud Patard (Rtp) 
7526f4bc952SArnaud Patard (Rtp) #define ALC5623_ADD2_POWER_EN (ALC5623_PWR_ADD2_VREF \
7536f4bc952SArnaud Patard (Rtp) 	| ALC5623_PWR_ADD2_DAC_REF_CIR)
7546f4bc952SArnaud Patard (Rtp) 
7556f4bc952SArnaud Patard (Rtp) #define ALC5623_ADD3_POWER_EN (ALC5623_PWR_ADD3_MAIN_BIAS \
7566f4bc952SArnaud Patard (Rtp) 	| ALC5623_PWR_ADD3_MIC1_BOOST_AD)
7576f4bc952SArnaud Patard (Rtp) 
7586f4bc952SArnaud Patard (Rtp) #define ALC5623_ADD1_POWER_EN \
7596f4bc952SArnaud Patard (Rtp) 	(ALC5623_PWR_ADD1_SHORT_CURR_DET_EN | ALC5623_PWR_ADD1_SOFTGEN_EN \
7606f4bc952SArnaud Patard (Rtp) 	| ALC5623_PWR_ADD1_DEPOP_BUF_HP | ALC5623_PWR_ADD1_HP_OUT_AMP \
7616f4bc952SArnaud Patard (Rtp) 	| ALC5623_PWR_ADD1_HP_OUT_ENH_AMP)
7626f4bc952SArnaud Patard (Rtp) 
7636f4bc952SArnaud Patard (Rtp) #define ALC5623_ADD1_POWER_EN_5622 \
7646f4bc952SArnaud Patard (Rtp) 	(ALC5623_PWR_ADD1_SHORT_CURR_DET_EN \
7656f4bc952SArnaud Patard (Rtp) 	| ALC5623_PWR_ADD1_HP_OUT_AMP)
7666f4bc952SArnaud Patard (Rtp) 
enable_power_depop(struct snd_soc_component * component)767fd7c728dSKuninori Morimoto static void enable_power_depop(struct snd_soc_component *component)
7686f4bc952SArnaud Patard (Rtp) {
769fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
7706f4bc952SArnaud Patard (Rtp) 
771fd7c728dSKuninori Morimoto 	snd_soc_component_update_bits(component, ALC5623_PWR_MANAG_ADD1,
7726f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD1_SOFTGEN_EN,
7736f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD1_SOFTGEN_EN);
7746f4bc952SArnaud Patard (Rtp) 
775fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD3, ALC5623_ADD3_POWER_EN);
7766f4bc952SArnaud Patard (Rtp) 
777fd7c728dSKuninori Morimoto 	snd_soc_component_update_bits(component, ALC5623_MISC_CTRL,
7786f4bc952SArnaud Patard (Rtp) 				ALC5623_MISC_HP_DEPOP_MODE2_EN,
7796f4bc952SArnaud Patard (Rtp) 				ALC5623_MISC_HP_DEPOP_MODE2_EN);
7806f4bc952SArnaud Patard (Rtp) 
7816f4bc952SArnaud Patard (Rtp) 	msleep(500);
7826f4bc952SArnaud Patard (Rtp) 
783fd7c728dSKuninori Morimoto 	snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD2, ALC5623_ADD2_POWER_EN);
7846f4bc952SArnaud Patard (Rtp) 
7856f4bc952SArnaud Patard (Rtp) 	/* avoid writing '1' into 5622 reserved bits */
7866f4bc952SArnaud Patard (Rtp) 	if (alc5623->id == 0x22)
787fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD1,
7886f4bc952SArnaud Patard (Rtp) 			ALC5623_ADD1_POWER_EN_5622);
7896f4bc952SArnaud Patard (Rtp) 	else
790fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD1,
7916f4bc952SArnaud Patard (Rtp) 			ALC5623_ADD1_POWER_EN);
7926f4bc952SArnaud Patard (Rtp) 
7936f4bc952SArnaud Patard (Rtp) 	/* disable HP Depop2 */
794fd7c728dSKuninori Morimoto 	snd_soc_component_update_bits(component, ALC5623_MISC_CTRL,
7956f4bc952SArnaud Patard (Rtp) 				ALC5623_MISC_HP_DEPOP_MODE2_EN,
7966f4bc952SArnaud Patard (Rtp) 				0);
7976f4bc952SArnaud Patard (Rtp) 
7986f4bc952SArnaud Patard (Rtp) }
7996f4bc952SArnaud Patard (Rtp) 
alc5623_set_bias_level(struct snd_soc_component * component,enum snd_soc_bias_level level)800fd7c728dSKuninori Morimoto static int alc5623_set_bias_level(struct snd_soc_component *component,
8016f4bc952SArnaud Patard (Rtp) 				      enum snd_soc_bias_level level)
8026f4bc952SArnaud Patard (Rtp) {
8036f4bc952SArnaud Patard (Rtp) 	switch (level) {
8046f4bc952SArnaud Patard (Rtp) 	case SND_SOC_BIAS_ON:
805fd7c728dSKuninori Morimoto 		enable_power_depop(component);
8066f4bc952SArnaud Patard (Rtp) 		break;
8076f4bc952SArnaud Patard (Rtp) 	case SND_SOC_BIAS_PREPARE:
8086f4bc952SArnaud Patard (Rtp) 		break;
8096f4bc952SArnaud Patard (Rtp) 	case SND_SOC_BIAS_STANDBY:
8106f4bc952SArnaud Patard (Rtp) 		/* everything off except vref/vmid, */
811fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD2,
8126f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD2_VREF);
813fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD3,
8146f4bc952SArnaud Patard (Rtp) 				ALC5623_PWR_ADD3_MAIN_BIAS);
8156f4bc952SArnaud Patard (Rtp) 		break;
8166f4bc952SArnaud Patard (Rtp) 	case SND_SOC_BIAS_OFF:
8176f4bc952SArnaud Patard (Rtp) 		/* everything off, dac mute, inactive */
818fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD2, 0);
819fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD3, 0);
820fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD1, 0);
8216f4bc952SArnaud Patard (Rtp) 		break;
8226f4bc952SArnaud Patard (Rtp) 	}
8236f4bc952SArnaud Patard (Rtp) 	return 0;
8246f4bc952SArnaud Patard (Rtp) }
8256f4bc952SArnaud Patard (Rtp) 
8266f4bc952SArnaud Patard (Rtp) #define ALC5623_FORMATS	(SNDRV_PCM_FMTBIT_S16_LE \
8276f4bc952SArnaud Patard (Rtp) 			| SNDRV_PCM_FMTBIT_S24_LE \
8286f4bc952SArnaud Patard (Rtp) 			| SNDRV_PCM_FMTBIT_S32_LE)
8296f4bc952SArnaud Patard (Rtp) 
83085e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops alc5623_dai_ops = {
8316f4bc952SArnaud Patard (Rtp) 		.hw_params = alc5623_pcm_hw_params,
8324c66c2fcSKuninori Morimoto 		.mute_stream = alc5623_mute,
8336f4bc952SArnaud Patard (Rtp) 		.set_fmt = alc5623_set_dai_fmt,
8346f4bc952SArnaud Patard (Rtp) 		.set_sysclk = alc5623_set_dai_sysclk,
8356f4bc952SArnaud Patard (Rtp) 		.set_pll = alc5623_set_dai_pll,
8364c66c2fcSKuninori Morimoto 		.no_capture_mute = 1,
8376f4bc952SArnaud Patard (Rtp) };
8386f4bc952SArnaud Patard (Rtp) 
8396f4bc952SArnaud Patard (Rtp) static struct snd_soc_dai_driver alc5623_dai = {
8406f4bc952SArnaud Patard (Rtp) 	.name = "alc5623-hifi",
8416f4bc952SArnaud Patard (Rtp) 	.playback = {
8426f4bc952SArnaud Patard (Rtp) 		.stream_name = "Playback",
8436f4bc952SArnaud Patard (Rtp) 		.channels_min = 1,
8446f4bc952SArnaud Patard (Rtp) 		.channels_max = 2,
8456f4bc952SArnaud Patard (Rtp) 		.rate_min =	8000,
8466f4bc952SArnaud Patard (Rtp) 		.rate_max =	48000,
8476f4bc952SArnaud Patard (Rtp) 		.rates = SNDRV_PCM_RATE_8000_48000,
8486f4bc952SArnaud Patard (Rtp) 		.formats = ALC5623_FORMATS,},
8496f4bc952SArnaud Patard (Rtp) 	.capture = {
8506f4bc952SArnaud Patard (Rtp) 		.stream_name = "Capture",
8516f4bc952SArnaud Patard (Rtp) 		.channels_min = 1,
8526f4bc952SArnaud Patard (Rtp) 		.channels_max = 2,
8536f4bc952SArnaud Patard (Rtp) 		.rate_min =	8000,
8546f4bc952SArnaud Patard (Rtp) 		.rate_max =	48000,
8556f4bc952SArnaud Patard (Rtp) 		.rates = SNDRV_PCM_RATE_8000_48000,
8566f4bc952SArnaud Patard (Rtp) 		.formats = ALC5623_FORMATS,},
8576f4bc952SArnaud Patard (Rtp) 
8586f4bc952SArnaud Patard (Rtp) 	.ops = &alc5623_dai_ops,
8596f4bc952SArnaud Patard (Rtp) };
8606f4bc952SArnaud Patard (Rtp) 
alc5623_suspend(struct snd_soc_component * component)861fd7c728dSKuninori Morimoto static int alc5623_suspend(struct snd_soc_component *component)
8626f4bc952SArnaud Patard (Rtp) {
863fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
8640cd257bfSMark Brown 
8650cd257bfSMark Brown 	regcache_cache_only(alc5623->regmap, true);
8660cd257bfSMark Brown 
8676f4bc952SArnaud Patard (Rtp) 	return 0;
8686f4bc952SArnaud Patard (Rtp) }
8696f4bc952SArnaud Patard (Rtp) 
alc5623_resume(struct snd_soc_component * component)870fd7c728dSKuninori Morimoto static int alc5623_resume(struct snd_soc_component *component)
8716f4bc952SArnaud Patard (Rtp) {
872fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
8730cd257bfSMark Brown 	int ret;
8746f4bc952SArnaud Patard (Rtp) 
8756f4bc952SArnaud Patard (Rtp) 	/* Sync reg_cache with the hardware */
8760cd257bfSMark Brown 	regcache_cache_only(alc5623->regmap, false);
8770cd257bfSMark Brown 	ret = regcache_sync(alc5623->regmap);
8780cd257bfSMark Brown 	if (ret != 0) {
879fd7c728dSKuninori Morimoto 		dev_err(component->dev, "Failed to sync register cache: %d\n",
8800cd257bfSMark Brown 			ret);
8810cd257bfSMark Brown 		regcache_cache_only(alc5623->regmap, true);
8820cd257bfSMark Brown 		return ret;
8830cd257bfSMark Brown 	}
8846f4bc952SArnaud Patard (Rtp) 
8856f4bc952SArnaud Patard (Rtp) 	return 0;
8866f4bc952SArnaud Patard (Rtp) }
8876f4bc952SArnaud Patard (Rtp) 
alc5623_probe(struct snd_soc_component * component)888fd7c728dSKuninori Morimoto static int alc5623_probe(struct snd_soc_component *component)
8896f4bc952SArnaud Patard (Rtp) {
890fd7c728dSKuninori Morimoto 	struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component);
891fd7c728dSKuninori Morimoto 	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
8926f4bc952SArnaud Patard (Rtp) 
893fd7c728dSKuninori Morimoto 	alc5623_reset(component);
8946f4bc952SArnaud Patard (Rtp) 
8956f4bc952SArnaud Patard (Rtp) 	if (alc5623->add_ctrl) {
896fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_ADD_CTRL_REG,
8976f4bc952SArnaud Patard (Rtp) 				alc5623->add_ctrl);
8986f4bc952SArnaud Patard (Rtp) 	}
8996f4bc952SArnaud Patard (Rtp) 
9006f4bc952SArnaud Patard (Rtp) 	if (alc5623->jack_det_ctrl) {
901fd7c728dSKuninori Morimoto 		snd_soc_component_write(component, ALC5623_JACK_DET_CTRL,
9026f4bc952SArnaud Patard (Rtp) 				alc5623->jack_det_ctrl);
9036f4bc952SArnaud Patard (Rtp) 	}
9046f4bc952SArnaud Patard (Rtp) 
9056f4bc952SArnaud Patard (Rtp) 	switch (alc5623->id) {
9066f4bc952SArnaud Patard (Rtp) 	case 0x21:
907fd7c728dSKuninori Morimoto 		snd_soc_add_component_controls(component, alc5621_vol_snd_controls,
9086048ef76SAxel Lin 			ARRAY_SIZE(alc5621_vol_snd_controls));
9096f4bc952SArnaud Patard (Rtp) 		break;
9106f4bc952SArnaud Patard (Rtp) 	case 0x22:
911fd7c728dSKuninori Morimoto 		snd_soc_add_component_controls(component, alc5622_vol_snd_controls,
9126048ef76SAxel Lin 			ARRAY_SIZE(alc5622_vol_snd_controls));
9136f4bc952SArnaud Patard (Rtp) 		break;
9146f4bc952SArnaud Patard (Rtp) 	case 0x23:
915fd7c728dSKuninori Morimoto 		snd_soc_add_component_controls(component, alc5623_vol_snd_controls,
9166f4bc952SArnaud Patard (Rtp) 			ARRAY_SIZE(alc5623_vol_snd_controls));
9176f4bc952SArnaud Patard (Rtp) 		break;
9184bd3a1f4SAxel Lin 	default:
9194bd3a1f4SAxel Lin 		return -EINVAL;
9206f4bc952SArnaud Patard (Rtp) 	}
9216f4bc952SArnaud Patard (Rtp) 
922fd7c728dSKuninori Morimoto 	snd_soc_add_component_controls(component, alc5623_snd_controls,
9236f4bc952SArnaud Patard (Rtp) 			ARRAY_SIZE(alc5623_snd_controls));
9246f4bc952SArnaud Patard (Rtp) 
925ce6120ccSLiam Girdwood 	snd_soc_dapm_new_controls(dapm, alc5623_dapm_widgets,
9266f4bc952SArnaud Patard (Rtp) 					ARRAY_SIZE(alc5623_dapm_widgets));
9276f4bc952SArnaud Patard (Rtp) 
9286f4bc952SArnaud Patard (Rtp) 	/* set up audio path interconnects */
929ce6120ccSLiam Girdwood 	snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
9306f4bc952SArnaud Patard (Rtp) 
9316f4bc952SArnaud Patard (Rtp) 	switch (alc5623->id) {
9326f4bc952SArnaud Patard (Rtp) 	case 0x21:
9336f4bc952SArnaud Patard (Rtp) 	case 0x22:
934ce6120ccSLiam Girdwood 		snd_soc_dapm_new_controls(dapm, alc5623_dapm_amp_widgets,
9356f4bc952SArnaud Patard (Rtp) 					ARRAY_SIZE(alc5623_dapm_amp_widgets));
936ce6120ccSLiam Girdwood 		snd_soc_dapm_add_routes(dapm, intercon_amp_spk,
9376f4bc952SArnaud Patard (Rtp) 					ARRAY_SIZE(intercon_amp_spk));
9386f4bc952SArnaud Patard (Rtp) 		break;
9396f4bc952SArnaud Patard (Rtp) 	case 0x23:
940ce6120ccSLiam Girdwood 		snd_soc_dapm_add_routes(dapm, intercon_spk,
9416f4bc952SArnaud Patard (Rtp) 					ARRAY_SIZE(intercon_spk));
9426f4bc952SArnaud Patard (Rtp) 		break;
9434bd3a1f4SAxel Lin 	default:
9444bd3a1f4SAxel Lin 		return -EINVAL;
9456f4bc952SArnaud Patard (Rtp) 	}
9466f4bc952SArnaud Patard (Rtp) 
947f78b1e0aSChristoph Jaeger 	return 0;
9486f4bc952SArnaud Patard (Rtp) }
9496f4bc952SArnaud Patard (Rtp) 
950fd7c728dSKuninori Morimoto static const struct snd_soc_component_driver soc_component_device_alc5623 = {
9516f4bc952SArnaud Patard (Rtp) 	.probe			= alc5623_probe,
9526f4bc952SArnaud Patard (Rtp) 	.suspend		= alc5623_suspend,
9536f4bc952SArnaud Patard (Rtp) 	.resume			= alc5623_resume,
9546f4bc952SArnaud Patard (Rtp) 	.set_bias_level		= alc5623_set_bias_level,
955fd7c728dSKuninori Morimoto 	.suspend_bias_off	= 1,
956fd7c728dSKuninori Morimoto 	.idle_bias_on		= 1,
957fd7c728dSKuninori Morimoto 	.use_pmdown_time	= 1,
958fd7c728dSKuninori Morimoto 	.endianness		= 1,
9590cd257bfSMark Brown };
9600cd257bfSMark Brown 
9610cd257bfSMark Brown static const struct regmap_config alc5623_regmap = {
9620cd257bfSMark Brown 	.reg_bits = 8,
9630cd257bfSMark Brown 	.val_bits = 16,
9640cd257bfSMark Brown 	.reg_stride = 2,
9650cd257bfSMark Brown 
9660cd257bfSMark Brown 	.max_register = ALC5623_VENDOR_ID2,
9670cd257bfSMark Brown 	.cache_type = REGCACHE_RBTREE,
9686f4bc952SArnaud Patard (Rtp) };
9696f4bc952SArnaud Patard (Rtp) 
9709d8f2eddSStephen Kitt static const struct i2c_device_id alc5623_i2c_table[] = {
9719d8f2eddSStephen Kitt 	{"alc5621", 0x21},
9729d8f2eddSStephen Kitt 	{"alc5622", 0x22},
9739d8f2eddSStephen Kitt 	{"alc5623", 0x23},
9749d8f2eddSStephen Kitt 	{}
9759d8f2eddSStephen Kitt };
9769d8f2eddSStephen Kitt MODULE_DEVICE_TABLE(i2c, alc5623_i2c_table);
9779d8f2eddSStephen Kitt 
9786f4bc952SArnaud Patard (Rtp) /*
9796f4bc952SArnaud Patard (Rtp)  * ALC5623 2 wire address is determined by A1 pin
9806f4bc952SArnaud Patard (Rtp)  * state during powerup.
9816f4bc952SArnaud Patard (Rtp)  *    low  = 0x1a
9826f4bc952SArnaud Patard (Rtp)  *    high = 0x1b
9836f4bc952SArnaud Patard (Rtp)  */
alc5623_i2c_probe(struct i2c_client * client)9849d8f2eddSStephen Kitt static int alc5623_i2c_probe(struct i2c_client *client)
9856f4bc952SArnaud Patard (Rtp) {
9866f4bc952SArnaud Patard (Rtp) 	struct alc5623_platform_data *pdata;
9876f4bc952SArnaud Patard (Rtp) 	struct alc5623_priv *alc5623;
9887d6d478fSAndrew Lunn 	struct device_node *np;
9890cd257bfSMark Brown 	unsigned int vid1, vid2;
9900cd257bfSMark Brown 	int ret;
9917d6d478fSAndrew Lunn 	u32 val32;
9929d8f2eddSStephen Kitt 	const struct i2c_device_id *id;
9936f4bc952SArnaud Patard (Rtp) 
9940cd257bfSMark Brown 	alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv),
9950cd257bfSMark Brown 			       GFP_KERNEL);
9960cd257bfSMark Brown 	if (alc5623 == NULL)
9970cd257bfSMark Brown 		return -ENOMEM;
9980cd257bfSMark Brown 
9990cd257bfSMark Brown 	alc5623->regmap = devm_regmap_init_i2c(client, &alc5623_regmap);
10000cd257bfSMark Brown 	if (IS_ERR(alc5623->regmap)) {
10010cd257bfSMark Brown 		ret = PTR_ERR(alc5623->regmap);
10020cd257bfSMark Brown 		dev_err(&client->dev, "Failed to initialise I/O: %d\n", ret);
10030cd257bfSMark Brown 		return ret;
10040cd257bfSMark Brown 	}
10050cd257bfSMark Brown 
10060cd257bfSMark Brown 	ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID1, &vid1);
10070cd257bfSMark Brown 	if (ret < 0) {
10080cd257bfSMark Brown 		dev_err(&client->dev, "failed to read vendor ID1: %d\n", ret);
10090cd257bfSMark Brown 		return ret;
10106f4bc952SArnaud Patard (Rtp) 	}
10116f4bc952SArnaud Patard (Rtp) 
10120cd257bfSMark Brown 	ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID2, &vid2);
10130cd257bfSMark Brown 	if (ret < 0) {
10140cd257bfSMark Brown 		dev_err(&client->dev, "failed to read vendor ID2: %d\n", ret);
10150cd257bfSMark Brown 		return ret;
10166f4bc952SArnaud Patard (Rtp) 	}
10178aaa414fSAndrew Lunn 	vid2 >>= 8;
10186f4bc952SArnaud Patard (Rtp) 
10199d8f2eddSStephen Kitt 	id = i2c_match_id(alc5623_i2c_table, client);
10209d8f2eddSStephen Kitt 
10216f4bc952SArnaud Patard (Rtp) 	if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) {
10226f4bc952SArnaud Patard (Rtp) 		dev_err(&client->dev, "unknown or wrong codec\n");
10236f4bc952SArnaud Patard (Rtp) 		dev_err(&client->dev, "Expected %x:%lx, got %x:%x\n",
10246f4bc952SArnaud Patard (Rtp) 				0x10ec, id->driver_data,
10256f4bc952SArnaud Patard (Rtp) 				vid1, vid2);
10266f4bc952SArnaud Patard (Rtp) 		return -ENODEV;
10276f4bc952SArnaud Patard (Rtp) 	}
10286f4bc952SArnaud Patard (Rtp) 
10296f4bc952SArnaud Patard (Rtp) 	dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2);
10306f4bc952SArnaud Patard (Rtp) 
10316f4bc952SArnaud Patard (Rtp) 	pdata = client->dev.platform_data;
10326f4bc952SArnaud Patard (Rtp) 	if (pdata) {
10336f4bc952SArnaud Patard (Rtp) 		alc5623->add_ctrl = pdata->add_ctrl;
10346f4bc952SArnaud Patard (Rtp) 		alc5623->jack_det_ctrl = pdata->jack_det_ctrl;
10357d6d478fSAndrew Lunn 	} else {
10367d6d478fSAndrew Lunn 		if (client->dev.of_node) {
10377d6d478fSAndrew Lunn 			np = client->dev.of_node;
10387d6d478fSAndrew Lunn 			ret = of_property_read_u32(np, "add-ctrl", &val32);
10397d6d478fSAndrew Lunn 			if (!ret)
10407d6d478fSAndrew Lunn 				alc5623->add_ctrl = val32;
10417d6d478fSAndrew Lunn 			ret = of_property_read_u32(np, "jack-det-ctrl", &val32);
10427d6d478fSAndrew Lunn 			if (!ret)
10437d6d478fSAndrew Lunn 				alc5623->jack_det_ctrl = val32;
10447d6d478fSAndrew Lunn 		}
10456f4bc952SArnaud Patard (Rtp) 	}
10466f4bc952SArnaud Patard (Rtp) 
10476f4bc952SArnaud Patard (Rtp) 	alc5623->id = vid2;
10486f4bc952SArnaud Patard (Rtp) 	switch (alc5623->id) {
10496f4bc952SArnaud Patard (Rtp) 	case 0x21:
10506f4bc952SArnaud Patard (Rtp) 		alc5623_dai.name = "alc5621-hifi";
10516f4bc952SArnaud Patard (Rtp) 		break;
10526f4bc952SArnaud Patard (Rtp) 	case 0x22:
10536f4bc952SArnaud Patard (Rtp) 		alc5623_dai.name = "alc5622-hifi";
10546f4bc952SArnaud Patard (Rtp) 		break;
10556f4bc952SArnaud Patard (Rtp) 	case 0x23:
10566f4bc952SArnaud Patard (Rtp) 		alc5623_dai.name = "alc5623-hifi";
10576f4bc952SArnaud Patard (Rtp) 		break;
10584bd3a1f4SAxel Lin 	default:
10594bd3a1f4SAxel Lin 		return -EINVAL;
10606f4bc952SArnaud Patard (Rtp) 	}
10616f4bc952SArnaud Patard (Rtp) 
10626f4bc952SArnaud Patard (Rtp) 	i2c_set_clientdata(client, alc5623);
10636f4bc952SArnaud Patard (Rtp) 
1064fd7c728dSKuninori Morimoto 	ret =  devm_snd_soc_register_component(&client->dev,
1065fd7c728dSKuninori Morimoto 		&soc_component_device_alc5623, &alc5623_dai, 1);
1066360b70caSAxel Lin 	if (ret != 0)
10676f4bc952SArnaud Patard (Rtp) 		dev_err(&client->dev, "Failed to register codec: %d\n", ret);
10686f4bc952SArnaud Patard (Rtp) 
10696f4bc952SArnaud Patard (Rtp) 	return ret;
10706f4bc952SArnaud Patard (Rtp) }
10716f4bc952SArnaud Patard (Rtp) 
1072d11f8974SKrzysztof Kozlowski #ifdef CONFIG_OF
10737d6d478fSAndrew Lunn static const struct of_device_id alc5623_of_match[] = {
10747d6d478fSAndrew Lunn 	{ .compatible = "realtek,alc5623", },
10757d6d478fSAndrew Lunn 	{ }
10767d6d478fSAndrew Lunn };
10777d6d478fSAndrew Lunn MODULE_DEVICE_TABLE(of, alc5623_of_match);
1078d11f8974SKrzysztof Kozlowski #endif
10797d6d478fSAndrew Lunn 
10806f4bc952SArnaud Patard (Rtp) /*  i2c codec control layer */
10816f4bc952SArnaud Patard (Rtp) static struct i2c_driver alc5623_i2c_driver = {
10826f4bc952SArnaud Patard (Rtp) 	.driver = {
10836f4bc952SArnaud Patard (Rtp) 		.name = "alc562x-codec",
10847d6d478fSAndrew Lunn 		.of_match_table = of_match_ptr(alc5623_of_match),
10856f4bc952SArnaud Patard (Rtp) 	},
1086*9abcd240SUwe Kleine-König 	.probe = alc5623_i2c_probe,
10876f4bc952SArnaud Patard (Rtp) 	.id_table = alc5623_i2c_table,
10886f4bc952SArnaud Patard (Rtp) };
10896f4bc952SArnaud Patard (Rtp) 
10909c78a017SAxel Lin module_i2c_driver(alc5623_i2c_driver);
10916f4bc952SArnaud Patard (Rtp) 
10926f4bc952SArnaud Patard (Rtp) MODULE_DESCRIPTION("ASoC alc5621/2/3 driver");
10936f4bc952SArnaud Patard (Rtp) MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
10946f4bc952SArnaud Patard (Rtp) MODULE_LICENSE("GPL");
1095