Lines Matching refs:rt5659
3 * rt5659.c -- RT5659/RT5658 ALSA SoC audio codec driver
28 #include <sound/rt5659.h>
31 #include "rt5659.h"
1264 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
1296 rt5659->jack_type = SND_JACK_HEADSET;
1301 rt5659->jack_type = SND_JACK_HEADPHONE;
1309 if (rt5659->jack_type == SND_JACK_HEADSET)
1311 rt5659->jack_type = 0;
1314 dev_dbg(component->dev, "jack_type = %d\n", rt5659->jack_type);
1315 return rt5659->jack_type;
1331 struct rt5659_priv *rt5659 = data;
1334 &rt5659->jack_detect_work, msecs_to_jiffies(250));
1342 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
1344 rt5659->hs_jack = hs_jack;
1346 rt5659_irq(0, rt5659);
1354 struct rt5659_priv *rt5659 =
1358 if (!rt5659->component)
1361 val = snd_soc_component_read(rt5659->component, RT5659_INT_ST_1) & 0x0080;
1364 if (rt5659->jack_type == 0) {
1366 report = rt5659_headset_detect(rt5659->component, 1);
1370 btn_type = rt5659_button_detect(rt5659->component);
1372 * rt5659 can report three kinds of button behavior,
1403 dev_err(rt5659->component->dev,
1411 report = rt5659->jack_type;
1415 report = rt5659_headset_detect(rt5659->component, 0);
1418 snd_soc_jack_report(rt5659->hs_jack, report, SND_JACK_HEADSET |
1425 struct rt5659_priv *rt5659 =
1430 if (!rt5659->hs_jack)
1434 regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value);
1437 if (hp_flag != rt5659->hda_hp_plugged) {
1438 rt5659->hda_hp_plugged = hp_flag;
1441 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
1443 rt5659->jack_type |= SND_JACK_HEADPHONE;
1445 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
1447 rt5659->jack_type = rt5659->jack_type &
1451 snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type,
1456 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value);
1457 regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value);
1460 if (mic_flag != rt5659->hda_mic_plugged) {
1461 rt5659->hda_mic_plugged = mic_flag;
1463 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
1465 rt5659->jack_type |= SND_JACK_MICROPHONE;
1467 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
1469 rt5659->jack_type = rt5659->jack_type
1473 snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type,
1568 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
1571 pd = rl6231_get_pre_div(rt5659->regmap,
1573 idx = rl6231_calc_dmic_clk(rt5659->sysclk / pd);
3279 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3283 rt5659->lrck[dai->id] = params_rate(params);
3284 pre_div = rl6231_get_clk_info(rt5659->sysclk, rt5659->lrck[dai->id]);
3287 rt5659->lrck[dai->id], dai->id);
3297 rt5659->lrck[dai->id], pre_div, dai->id);
3341 switch (rt5659->lrck[dai->id]) {
3362 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3367 rt5659->master[dai->id] = 1;
3371 rt5659->master[dai->id] = 0;
3429 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3433 if (freq == rt5659->sysclk && clk_id == rt5659->sysclk_src)
3438 ret = clk_set_rate(rt5659->mclk, freq);
3456 rt5659->sysclk = freq;
3457 rt5659->sysclk_src = clk_id;
3469 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3473 if (source == rt5659->pll_src && freq_in == rt5659->pll_in &&
3474 freq_out == rt5659->pll_out)
3480 rt5659->pll_in = 0;
3481 rt5659->pll_out = 0;
3525 rt5659->pll_in = freq_in;
3526 rt5659->pll_out = freq_out;
3527 rt5659->pll_src = source;
3587 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3591 rt5659->bclk[dai->id] = ratio;
3615 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3620 regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC,
3622 regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1,
3624 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
3628 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
3635 ret = clk_prepare_enable(rt5659->mclk);
3645 regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1,
3647 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
3651 regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC,
3653 clk_disable_unprepare(rt5659->mclk);
3667 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3669 rt5659->component = component;
3671 switch (rt5659->pdata.jd_src) {
3687 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3689 regmap_write(rt5659->regmap, RT5659_RESET, 0);
3695 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3697 regcache_cache_only(rt5659->regmap, true);
3698 regcache_mark_dirty(rt5659->regmap);
3704 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3706 regcache_cache_only(rt5659->regmap, false);
3707 regcache_sync(rt5659->regmap);
3729 .name = "rt5659-aif1",
3748 .name = "rt5659-aif2",
3767 .name = "rt5659-aif3",
3819 { "rt5659", 0 },
3824 static int rt5659_parse_dt(struct rt5659_priv *rt5659, struct device *dev)
3826 rt5659->pdata.in1_diff = device_property_read_bool(dev,
3828 rt5659->pdata.in3_diff = device_property_read_bool(dev,
3830 rt5659->pdata.in4_diff = device_property_read_bool(dev,
3835 &rt5659->pdata.dmic1_data_pin);
3837 &rt5659->pdata.dmic2_data_pin);
3839 &rt5659->pdata.jd_src);
3844 static void rt5659_calibrate(struct rt5659_priv *rt5659)
3850 regmap_write(rt5659->regmap, RT5659_BIAS_CUR_CTRL_8, 0xa502);
3851 regmap_write(rt5659->regmap, RT5659_CHOP_DAC, 0x3030);
3853 regmap_write(rt5659->regmap, RT5659_PRE_DIV_1, 0xef00);
3854 regmap_write(rt5659->regmap, RT5659_PRE_DIV_2, 0xeffc);
3855 regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0280);
3856 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0001);
3857 regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x8000);
3859 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xaa7e);
3861 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe7e);
3863 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0004);
3864 regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0400);
3866 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0080);
3868 regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0009);
3870 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0f80);
3872 regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0e16);
3876 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0505);
3878 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0184);
3879 regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x3c05);
3880 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c1);
3883 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
3884 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x5100);
3885 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0014);
3886 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0xd100);
3890 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
3891 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4900);
3892 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0016);
3893 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1,
3898 regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value);
3905 dev_err(rt5659->component->dev,
3914 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
3915 regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x0000);
3916 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4500);
3917 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x001f);
3918 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1,
3923 regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value);
3930 dev_err(rt5659->component->dev,
3938 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0000);
3939 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0);
3943 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021);
3944 regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0260);
3945 regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x3000);
3946 regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0xc000);
3947 regmap_write(rt5659->regmap, RT5659_A_DAC_MUX, 0x000c);
3948 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x8000);
3949 regmap_write(rt5659->regmap, RT5659_SPO_VOL, 0x0808);
3950 regmap_write(rt5659->regmap, RT5659_SPK_L_MIXER, 0x001e);
3951 regmap_write(rt5659->regmap, RT5659_SPK_R_MIXER, 0x001e);
3952 regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0803);
3953 regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0554);
3954 regmap_write(rt5659->regmap, RT5659_SPO_AMP_GAIN, 0x1103);
3957 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0909);
3958 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x0001,
3962 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000);
3963 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x0021);
3964 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1, 0x3e80);
3965 regmap_update_bits(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1,
3970 regmap_read(rt5659->regmap,
3978 dev_err(rt5659->component->dev,
3988 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0000);
3989 regmap_write(rt5659->regmap, RT5659_MONOMIX_IN_GAIN, 0x021f);
3990 regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0x480a);
3992 regmap_write(rt5659->regmap, RT5659_MONO_GAIN, 0x0003);
3993 regmap_write(rt5659->regmap, RT5659_MONO_NG2_CTRL_5, 0x0009);
3996 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x000f);
3997 regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00);
3998 regmap_update_bits(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1,
4003 regmap_read(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1,
4011 dev_err(rt5659->component->dev,
4019 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003);
4023 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0808);
4024 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0000);
4025 regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x2005);
4026 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0);
4027 regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0000);
4028 regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0011);
4029 regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0150);
4030 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe3e);
4031 regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0xc80a);
4032 regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04);
4033 regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x0000);
4034 regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0x0000);
4035 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0000);
4036 regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0000);
4037 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0x003e);
4038 regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0060);
4039 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021);
4040 regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x0000);
4041 regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0080);
4042 regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x8080);
4043 regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0c16);
4046 static void rt5659_intel_hd_header_probe_setup(struct rt5659_priv *rt5659)
4050 regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value);
4052 rt5659->hda_hp_plugged = true;
4053 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
4056 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
4060 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
4064 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
4067 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_3, RT5659_PWR_LDO2,
4069 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_2, RT5659_PWR_MB1,
4071 regmap_update_bits(rt5659->regmap, RT5659_PWR_VOL, RT5659_PWR_MIC_DET,
4075 regmap_update_bits(rt5659->regmap, RT5659_4BTN_IL_CMD_2,
4077 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value);
4078 regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value);
4079 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value);
4082 rt5659->hda_mic_plugged = true;
4083 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
4086 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
4090 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
4097 struct rt5659_priv *rt5659;
4101 rt5659 = devm_kzalloc(&i2c->dev, sizeof(struct rt5659_priv),
4104 if (rt5659 == NULL)
4107 i2c_set_clientdata(i2c, rt5659);
4110 rt5659->pdata = *pdata;
4112 rt5659_parse_dt(rt5659, &i2c->dev);
4114 rt5659->gpiod_ldo1_en = devm_gpiod_get_optional(&i2c->dev, "ldo1-en",
4116 if (IS_ERR(rt5659->gpiod_ldo1_en))
4119 rt5659->gpiod_reset = devm_gpiod_get_optional(&i2c->dev, "reset",
4125 rt5659->regmap = devm_regmap_init_i2c(i2c, &rt5659_regmap);
4126 if (IS_ERR(rt5659->regmap)) {
4127 ret = PTR_ERR(rt5659->regmap);
4133 regmap_read(rt5659->regmap, RT5659_DEVICE_ID, &val);
4136 "Device with ID register %x is not rt5659\n", val);
4140 regmap_write(rt5659->regmap, RT5659_RESET, 0);
4143 rt5659->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
4144 if (IS_ERR(rt5659->mclk))
4145 return PTR_ERR(rt5659->mclk);
4147 rt5659_calibrate(rt5659);
4150 if (rt5659->pdata.in1_diff)
4151 regmap_update_bits(rt5659->regmap, RT5659_IN1_IN2,
4153 if (rt5659->pdata.in3_diff)
4154 regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4,
4156 if (rt5659->pdata.in4_diff)
4157 regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4,
4161 if (rt5659->pdata.dmic1_data_pin != RT5659_DMIC1_NULL ||
4162 rt5659->pdata.dmic2_data_pin != RT5659_DMIC2_NULL) {
4163 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4166 switch (rt5659->pdata.dmic1_data_pin) {
4168 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4173 regmap_update_bits(rt5659->regmap,
4177 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4179 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4184 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4186 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4191 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4193 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4203 switch (rt5659->pdata.dmic2_data_pin) {
4205 regmap_update_bits(rt5659->regmap,
4212 regmap_update_bits(rt5659->regmap,
4216 regmap_update_bits(rt5659->regmap,
4223 regmap_update_bits(rt5659->regmap,
4227 regmap_update_bits(rt5659->regmap,
4234 regmap_update_bits(rt5659->regmap,
4238 regmap_update_bits(rt5659->regmap,
4250 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4259 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4264 switch (rt5659->pdata.jd_src) {
4266 regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0xa880);
4267 regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x9000);
4268 regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_1, 0xc800);
4269 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
4271 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_2, 0x0001);
4272 regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_2, 0x0040);
4273 INIT_DELAYED_WORK(&rt5659->jack_detect_work,
4277 regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_3, 0x8000);
4278 regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x0900);
4279 regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0x70c0);
4280 regmap_write(rt5659->regmap, RT5659_JD_CTRL_1, 0x2000);
4281 regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_1, 0x0040);
4282 INIT_DELAYED_WORK(&rt5659->jack_detect_work,
4284 rt5659_intel_hd_header_probe_setup(rt5659);
4293 | IRQF_ONESHOT, "rt5659", rt5659);
4298 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4309 struct rt5659_priv *rt5659 = i2c_get_clientdata(client);
4311 regmap_write(rt5659->regmap, RT5659_RESET, 0);
4317 { .compatible = "realtek,rt5659", },
4334 .name = "rt5659",