Lines Matching refs:rt5659

3  * rt5659.c  --  RT5659/RT5658 ALSA SoC audio codec driver
29 #include <sound/rt5659.h>
32 #include "rt5659.h"
1265 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
1297 rt5659->jack_type = SND_JACK_HEADSET;
1302 rt5659->jack_type = SND_JACK_HEADPHONE;
1310 if (rt5659->jack_type == SND_JACK_HEADSET)
1312 rt5659->jack_type = 0;
1315 dev_dbg(component->dev, "jack_type = %d\n", rt5659->jack_type);
1316 return rt5659->jack_type;
1332 struct rt5659_priv *rt5659 = data;
1335 &rt5659->jack_detect_work, msecs_to_jiffies(250));
1343 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
1345 rt5659->hs_jack = hs_jack;
1347 rt5659_irq(0, rt5659);
1355 struct rt5659_priv *rt5659 =
1359 if (!rt5659->component)
1362 val = snd_soc_component_read(rt5659->component, RT5659_INT_ST_1) & 0x0080;
1365 if (rt5659->jack_type == 0) {
1367 report = rt5659_headset_detect(rt5659->component, 1);
1371 btn_type = rt5659_button_detect(rt5659->component);
1373 * rt5659 can report three kinds of button behavior,
1404 dev_err(rt5659->component->dev,
1412 report = rt5659->jack_type;
1416 report = rt5659_headset_detect(rt5659->component, 0);
1419 snd_soc_jack_report(rt5659->hs_jack, report, SND_JACK_HEADSET |
1426 struct rt5659_priv *rt5659 =
1431 if (!rt5659->hs_jack)
1435 regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value);
1438 if (hp_flag != rt5659->hda_hp_plugged) {
1439 rt5659->hda_hp_plugged = hp_flag;
1442 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
1444 rt5659->jack_type |= SND_JACK_HEADPHONE;
1446 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
1448 rt5659->jack_type = rt5659->jack_type &
1452 snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type,
1457 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value);
1458 regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value);
1461 if (mic_flag != rt5659->hda_mic_plugged) {
1462 rt5659->hda_mic_plugged = mic_flag;
1464 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
1466 rt5659->jack_type |= SND_JACK_MICROPHONE;
1468 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
1470 rt5659->jack_type = rt5659->jack_type
1474 snd_soc_jack_report(rt5659->hs_jack, rt5659->jack_type,
1569 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
1572 pd = rl6231_get_pre_div(rt5659->regmap,
1574 idx = rl6231_calc_dmic_clk(rt5659->sysclk / pd);
3280 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3284 rt5659->lrck[dai->id] = params_rate(params);
3285 pre_div = rl6231_get_clk_info(rt5659->sysclk, rt5659->lrck[dai->id]);
3288 rt5659->lrck[dai->id], dai->id);
3298 rt5659->lrck[dai->id], pre_div, dai->id);
3342 switch (rt5659->lrck[dai->id]) {
3363 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3368 rt5659->master[dai->id] = 1;
3372 rt5659->master[dai->id] = 0;
3430 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3434 if (freq == rt5659->sysclk && clk_id == rt5659->sysclk_src)
3439 ret = clk_set_rate(rt5659->mclk, freq);
3457 rt5659->sysclk = freq;
3458 rt5659->sysclk_src = clk_id;
3470 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3474 if (source == rt5659->pll_src && freq_in == rt5659->pll_in &&
3475 freq_out == rt5659->pll_out)
3481 rt5659->pll_in = 0;
3482 rt5659->pll_out = 0;
3526 rt5659->pll_in = freq_in;
3527 rt5659->pll_out = freq_out;
3528 rt5659->pll_src = source;
3588 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3592 rt5659->bclk[dai->id] = ratio;
3616 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3621 regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC,
3623 regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1,
3625 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
3629 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
3636 ret = clk_prepare_enable(rt5659->mclk);
3646 regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1,
3648 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
3652 regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC,
3654 clk_disable_unprepare(rt5659->mclk);
3668 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3670 rt5659->component = component;
3672 switch (rt5659->pdata.jd_src) {
3688 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3690 regmap_write(rt5659->regmap, RT5659_RESET, 0);
3696 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3698 regcache_cache_only(rt5659->regmap, true);
3699 regcache_mark_dirty(rt5659->regmap);
3705 struct rt5659_priv *rt5659 = snd_soc_component_get_drvdata(component);
3707 regcache_cache_only(rt5659->regmap, false);
3708 regcache_sync(rt5659->regmap);
3730 .name = "rt5659-aif1",
3749 .name = "rt5659-aif2",
3768 .name = "rt5659-aif3",
3821 { "rt5659", 0 },
3826 static int rt5659_parse_dt(struct rt5659_priv *rt5659, struct device *dev)
3828 rt5659->pdata.in1_diff = device_property_read_bool(dev,
3830 rt5659->pdata.in3_diff = device_property_read_bool(dev,
3832 rt5659->pdata.in4_diff = device_property_read_bool(dev,
3837 &rt5659->pdata.dmic1_data_pin);
3839 &rt5659->pdata.dmic2_data_pin);
3841 &rt5659->pdata.jd_src);
3846 static void rt5659_calibrate(struct rt5659_priv *rt5659)
3852 regmap_write(rt5659->regmap, RT5659_BIAS_CUR_CTRL_8, 0xa502);
3853 regmap_write(rt5659->regmap, RT5659_CHOP_DAC, 0x3030);
3855 regmap_write(rt5659->regmap, RT5659_PRE_DIV_1, 0xef00);
3856 regmap_write(rt5659->regmap, RT5659_PRE_DIV_2, 0xeffc);
3857 regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0280);
3858 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0001);
3859 regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x8000);
3861 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xaa7e);
3863 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe7e);
3865 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0004);
3866 regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0400);
3868 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0080);
3870 regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0009);
3872 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0f80);
3874 regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0e16);
3878 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0505);
3880 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0184);
3881 regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x3c05);
3882 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c1);
3885 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
3886 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x5100);
3887 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0014);
3888 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0xd100);
3892 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
3893 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4900);
3894 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0016);
3895 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1,
3900 regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value);
3907 dev_err(rt5659->component->dev,
3916 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x2cc1);
3917 regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x0000);
3918 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, 0x4500);
3919 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x001f);
3920 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_1,
3925 regmap_read(rt5659->regmap, RT5659_HP_CALIB_CTRL_1, &value);
3932 dev_err(rt5659->component->dev,
3940 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_7, 0x0000);
3941 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0);
3945 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021);
3946 regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0260);
3947 regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x3000);
3948 regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0xc000);
3949 regmap_write(rt5659->regmap, RT5659_A_DAC_MUX, 0x000c);
3950 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x8000);
3951 regmap_write(rt5659->regmap, RT5659_SPO_VOL, 0x0808);
3952 regmap_write(rt5659->regmap, RT5659_SPK_L_MIXER, 0x001e);
3953 regmap_write(rt5659->regmap, RT5659_SPK_R_MIXER, 0x001e);
3954 regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0803);
3955 regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0554);
3956 regmap_write(rt5659->regmap, RT5659_SPO_AMP_GAIN, 0x1103);
3959 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0909);
3960 regmap_update_bits(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x0001,
3964 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0000);
3965 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x0021);
3966 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1, 0x3e80);
3967 regmap_update_bits(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_1,
3972 regmap_read(rt5659->regmap,
3980 dev_err(rt5659->component->dev,
3990 regmap_write(rt5659->regmap, RT5659_DIG_MISC, 0x0000);
3991 regmap_write(rt5659->regmap, RT5659_MONOMIX_IN_GAIN, 0x021f);
3992 regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0x480a);
3994 regmap_write(rt5659->regmap, RT5659_MONO_GAIN, 0x0003);
3995 regmap_write(rt5659->regmap, RT5659_MONO_NG2_CTRL_5, 0x0009);
3998 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x000f);
3999 regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e00);
4000 regmap_update_bits(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1,
4005 regmap_read(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1,
4013 dev_err(rt5659->component->dev,
4021 regmap_write(rt5659->regmap, RT5659_SPK_DC_CAILB_CTRL_3, 0x0003);
4025 regmap_write(rt5659->regmap, RT5659_CAL_REC, 0x0808);
4026 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_3, 0x0000);
4027 regmap_write(rt5659->regmap, RT5659_CALIB_ADC_CTRL, 0x2005);
4028 regmap_write(rt5659->regmap, RT5659_HP_CALIB_CTRL_2, 0x20c0);
4029 regmap_write(rt5659->regmap, RT5659_DEPOP_1, 0x0000);
4030 regmap_write(rt5659->regmap, RT5659_CLASSD_1, 0x0011);
4031 regmap_write(rt5659->regmap, RT5659_CLASSD_2, 0x0150);
4032 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0xfe3e);
4033 regmap_write(rt5659->regmap, RT5659_MONO_OUT, 0xc80a);
4034 regmap_write(rt5659->regmap, RT5659_MONO_AMP_CALIB_CTRL_1, 0x1e04);
4035 regmap_write(rt5659->regmap, RT5659_PWR_MIXER, 0x0000);
4036 regmap_write(rt5659->regmap, RT5659_PWR_VOL, 0x0000);
4037 regmap_write(rt5659->regmap, RT5659_PWR_DIG_1, 0x0000);
4038 regmap_write(rt5659->regmap, RT5659_PWR_DIG_2, 0x0000);
4039 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_1, 0x003e);
4040 regmap_write(rt5659->regmap, RT5659_CLASSD_CTRL_1, 0x0060);
4041 regmap_write(rt5659->regmap, RT5659_CLASSD_0, 0x2021);
4042 regmap_write(rt5659->regmap, RT5659_GLB_CLK, 0x0000);
4043 regmap_write(rt5659->regmap, RT5659_MICBIAS_2, 0x0080);
4044 regmap_write(rt5659->regmap, RT5659_HP_VOL, 0x8080);
4045 regmap_write(rt5659->regmap, RT5659_HP_CHARGE_PUMP_1, 0x0c16);
4048 static void rt5659_intel_hd_header_probe_setup(struct rt5659_priv *rt5659)
4052 regmap_read(rt5659->regmap, RT5659_GPIO_STA, &value);
4054 rt5659->hda_hp_plugged = true;
4055 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
4058 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_1,
4062 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
4066 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
4069 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_3, RT5659_PWR_LDO2,
4071 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_2, RT5659_PWR_MB1,
4073 regmap_update_bits(rt5659->regmap, RT5659_PWR_VOL, RT5659_PWR_MIC_DET,
4077 regmap_update_bits(rt5659->regmap, RT5659_4BTN_IL_CMD_2,
4079 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value);
4080 regmap_write(rt5659->regmap, RT5659_4BTN_IL_CMD_1, value);
4081 regmap_read(rt5659->regmap, RT5659_4BTN_IL_CMD_1, &value);
4084 rt5659->hda_mic_plugged = true;
4085 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
4088 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
4092 regmap_update_bits(rt5659->regmap, RT5659_IRQ_CTRL_2,
4100 struct rt5659_priv *rt5659;
4104 rt5659 = devm_kzalloc(&i2c->dev, sizeof(struct rt5659_priv),
4107 if (rt5659 == NULL)
4110 i2c_set_clientdata(i2c, rt5659);
4113 rt5659->pdata = *pdata;
4115 rt5659_parse_dt(rt5659, &i2c->dev);
4117 rt5659->gpiod_ldo1_en = devm_gpiod_get_optional(&i2c->dev, "ldo1-en",
4119 if (IS_ERR(rt5659->gpiod_ldo1_en))
4122 rt5659->gpiod_reset = devm_gpiod_get_optional(&i2c->dev, "reset",
4128 rt5659->regmap = devm_regmap_init_i2c(i2c, &rt5659_regmap);
4129 if (IS_ERR(rt5659->regmap)) {
4130 ret = PTR_ERR(rt5659->regmap);
4136 regmap_read(rt5659->regmap, RT5659_DEVICE_ID, &val);
4139 "Device with ID register %x is not rt5659\n", val);
4143 regmap_write(rt5659->regmap, RT5659_RESET, 0);
4146 rt5659->mclk = devm_clk_get(&i2c->dev, "mclk");
4147 if (IS_ERR(rt5659->mclk)) {
4148 if (PTR_ERR(rt5659->mclk) != -ENOENT)
4149 return PTR_ERR(rt5659->mclk);
4151 rt5659->mclk = NULL;
4154 rt5659_calibrate(rt5659);
4157 if (rt5659->pdata.in1_diff)
4158 regmap_update_bits(rt5659->regmap, RT5659_IN1_IN2,
4160 if (rt5659->pdata.in3_diff)
4161 regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4,
4163 if (rt5659->pdata.in4_diff)
4164 regmap_update_bits(rt5659->regmap, RT5659_IN3_IN4,
4168 if (rt5659->pdata.dmic1_data_pin != RT5659_DMIC1_NULL ||
4169 rt5659->pdata.dmic2_data_pin != RT5659_DMIC2_NULL) {
4170 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4173 switch (rt5659->pdata.dmic1_data_pin) {
4175 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4180 regmap_update_bits(rt5659->regmap,
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,
4198 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4200 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4210 switch (rt5659->pdata.dmic2_data_pin) {
4212 regmap_update_bits(rt5659->regmap,
4219 regmap_update_bits(rt5659->regmap,
4223 regmap_update_bits(rt5659->regmap,
4230 regmap_update_bits(rt5659->regmap,
4234 regmap_update_bits(rt5659->regmap,
4241 regmap_update_bits(rt5659->regmap,
4245 regmap_update_bits(rt5659->regmap,
4257 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4266 regmap_update_bits(rt5659->regmap, RT5659_DMIC_CTRL_1,
4271 switch (rt5659->pdata.jd_src) {
4273 regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0xa880);
4274 regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x9000);
4275 regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_1, 0xc800);
4276 regmap_update_bits(rt5659->regmap, RT5659_PWR_ANLG_1,
4278 regmap_write(rt5659->regmap, RT5659_PWR_ANLG_2, 0x0001);
4279 regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_2, 0x0040);
4280 INIT_DELAYED_WORK(&rt5659->jack_detect_work,
4284 regmap_write(rt5659->regmap, RT5659_GPIO_CTRL_3, 0x8000);
4285 regmap_write(rt5659->regmap, RT5659_RC_CLK_CTRL, 0x0900);
4286 regmap_write(rt5659->regmap, RT5659_EJD_CTRL_1, 0x70c0);
4287 regmap_write(rt5659->regmap, RT5659_JD_CTRL_1, 0x2000);
4288 regmap_write(rt5659->regmap, RT5659_IRQ_CTRL_1, 0x0040);
4289 INIT_DELAYED_WORK(&rt5659->jack_detect_work,
4291 rt5659_intel_hd_header_probe_setup(rt5659);
4300 | IRQF_ONESHOT, "rt5659", rt5659);
4305 regmap_update_bits(rt5659->regmap, RT5659_GPIO_CTRL_1,
4316 struct rt5659_priv *rt5659 = i2c_get_clientdata(client);
4318 regmap_write(rt5659->regmap, RT5659_RESET, 0);
4324 { .compatible = "realtek,rt5659", },
4341 .name = "rt5659",