Lines Matching refs:rt5663
3 * rt5663.c -- RT5663 ALSA SoC audio codec driver
28 #include "rt5663.h"
1400 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
1412 switch (rt5663->codec_ver) {
1427 switch (rt5663->codec_ver) {
1466 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
1496 rt5663->jack_type = SND_JACK_HEADSET;
1505 rt5663->jack_type = SND_JACK_HEADPHONE;
1511 if (rt5663->jack_type == SND_JACK_HEADSET) {
1519 rt5663->jack_type = 0;
1522 dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type);
1523 return rt5663->jack_type;
1537 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
1587 regmap_read(rt5663->regmap, RT5663_INT_ST_2, &val);
1608 rt5663->jack_type = SND_JACK_HEADSET;
1611 if (rt5663->pdata.impedance_sensing_num)
1614 if (rt5663->pdata.dc_offset_l_manual_mic) {
1615 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2,
1616 rt5663->pdata.dc_offset_l_manual_mic >>
1618 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_3,
1619 rt5663->pdata.dc_offset_l_manual_mic &
1623 if (rt5663->pdata.dc_offset_r_manual_mic) {
1624 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_5,
1625 rt5663->pdata.dc_offset_r_manual_mic >>
1627 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_6,
1628 rt5663->pdata.dc_offset_r_manual_mic &
1633 rt5663->jack_type = SND_JACK_HEADPHONE;
1638 if (rt5663->pdata.impedance_sensing_num)
1641 if (rt5663->pdata.dc_offset_l_manual) {
1642 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2,
1643 rt5663->pdata.dc_offset_l_manual >> 16);
1644 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_3,
1645 rt5663->pdata.dc_offset_l_manual &
1649 if (rt5663->pdata.dc_offset_r_manual) {
1650 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_5,
1651 rt5663->pdata.dc_offset_r_manual >> 16);
1652 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_6,
1653 rt5663->pdata.dc_offset_r_manual &
1659 if (rt5663->jack_type == SND_JACK_HEADSET)
1661 rt5663->jack_type = 0;
1667 dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type);
1668 return rt5663->jack_type;
1673 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
1676 for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) {
1677 if (rt5663->imp_table[i].vol == 7)
1681 if (rt5663->jack_type == SND_JACK_HEADSET) {
1683 rt5663->imp_table[i].dc_offset_l_manual_mic >> 16);
1685 rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff);
1687 rt5663->imp_table[i].dc_offset_r_manual_mic >> 16);
1689 rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff);
1692 rt5663->imp_table[i].dc_offset_l_manual >> 16);
1694 rt5663->imp_table[i].dc_offset_l_manual & 0xffff);
1696 rt5663->imp_table[i].dc_offset_r_manual >> 16);
1698 rt5663->imp_table[i].dc_offset_r_manual & 0xffff);
1808 for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) {
1809 if (value >= rt5663->imp_table[i].imp_min &&
1810 value <= rt5663->imp_table[i].imp_max)
1815 rt5663->imp_table[i].vol);
1817 rt5663->imp_table[i].vol);
1819 if (rt5663->jack_type == SND_JACK_HEADSET) {
1821 rt5663->imp_table[i].dc_offset_l_manual_mic >> 16);
1823 rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff);
1825 rt5663->imp_table[i].dc_offset_r_manual_mic >> 16);
1827 rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff);
1830 rt5663->imp_table[i].dc_offset_l_manual >> 16);
1832 rt5663->imp_table[i].dc_offset_l_manual & 0xffff);
1834 rt5663->imp_table[i].dc_offset_r_manual >> 16);
1836 rt5663->imp_table[i].dc_offset_r_manual & 0xffff);
1856 struct rt5663_priv *rt5663 = data;
1858 dev_dbg(regmap_get_device(rt5663->regmap), "%s IRQ queue work\n",
1861 queue_delayed_work(system_wq, &rt5663->jack_detect_work,
1870 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
1872 rt5663->hs_jack = hs_jack;
1874 rt5663_irq(0, rt5663);
1881 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
1887 switch (rt5663->codec_ver) {
1901 struct rt5663_priv *rt5663 =
1903 struct snd_soc_component *component = rt5663->component;
1911 if (rt5663->jack_type == 0) {
1913 switch (rt5663->codec_ver) {
1916 rt5663->component, 1);
1919 report = rt5663_jack_detect(rt5663->component, 1);
1920 if (rt5663->pdata.impedance_sensing_num)
1921 rt5663_impedance_sensing(rt5663->component);
1932 btn_type = rt5663_button_detect(rt5663->component);
1934 * rt5663 can report three kinds of button behavior,
1965 dev_err(rt5663->component->dev,
1972 report = rt5663->jack_type;
1974 &rt5663->jd_unplug_work);
1977 &rt5663->jd_unplug_work,
1983 switch (rt5663->codec_ver) {
1985 report = rt5663_v2_jack_detect(rt5663->component, 0);
1988 report = rt5663_jack_detect(rt5663->component, 0);
1995 snd_soc_jack_report(rt5663->hs_jack, report, SND_JACK_HEADSET |
2002 struct rt5663_priv *rt5663 =
2004 struct snd_soc_component *component = rt5663->component;
2011 switch (rt5663->codec_ver) {
2013 rt5663_v2_jack_detect(rt5663->component, 0);
2016 rt5663_jack_detect(rt5663->component, 0);
2022 snd_soc_jack_report(rt5663->hs_jack, 0, SND_JACK_HEADSET |
2026 queue_delayed_work(system_wq, &rt5663->jd_unplug_work,
2088 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2090 if (rt5663->codec_ver == CODEC_VER_1) {
2130 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2135 switch (rt5663->codec_ver) {
2150 if (rt5663->sysclk > rt5663->lrck * 384)
2175 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2196 switch (rt5663->codec_ver) {
2322 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2326 if (rt5663->codec_ver == CODEC_VER_1) {
2354 if (rt5663->codec_ver == CODEC_VER_1) {
2380 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2384 if (rt5663->codec_ver == CODEC_VER_0) {
2393 if (rt5663->codec_ver == CODEC_VER_0) {
2766 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2770 rt5663->lrck = params_rate(params);
2773 rt5663->lrck, rt5663->sysclk);
2775 pre_div = rl6231_get_clk_info(rt5663->sysclk, rt5663->lrck);
2778 rt5663->lrck, dai->id);
2861 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2864 if (freq == rt5663->sysclk && clk_id == rt5663->sysclk_src)
2883 rt5663->sysclk = freq;
2884 rt5663->sysclk_src = clk_id;
2896 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
2901 if (source == rt5663->pll_src && freq_in == rt5663->pll_in &&
2902 freq_out == rt5663->pll_out)
2908 rt5663->pll_in = 0;
2909 rt5663->pll_out = 0;
2915 switch (rt5663->codec_ver) {
2958 rt5663->pll_in = freq_in;
2959 rt5663->pll_out = freq_out;
2960 rt5663->pll_src = source;
2969 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3013 switch (rt5663->codec_ver) {
3035 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3040 if (rt5663->codec_ver == CODEC_VER_1)
3077 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3087 if (rt5663->codec_ver == CODEC_VER_1) {
3100 if (rt5663->codec_ver == CODEC_VER_1)
3110 if (rt5663->codec_ver == CODEC_VER_1) {
3120 if (rt5663->jack_type != SND_JACK_HEADSET)
3143 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3145 rt5663->component = component;
3147 switch (rt5663->codec_ver) {
3168 if (!rt5663->imp_table)
3179 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3181 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3187 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3189 regcache_cache_only(rt5663->regmap, true);
3190 regcache_mark_dirty(rt5663->regmap);
3197 struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
3199 regcache_cache_only(rt5663->regmap, false);
3200 regcache_sync(rt5663->regmap);
3202 rt5663_irq(0, rt5663);
3226 .name = "rt5663-aif",
3300 { "rt5663", 0 },
3307 { .compatible = "realtek,rt5663", },
3321 static void rt5663_v2_calibrate(struct rt5663_priv *rt5663)
3323 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
3324 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0100);
3325 regmap_write(rt5663->regmap, RT5663_RECMIX, 0x4040);
3326 regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x0001);
3327 regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380);
3328 regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000);
3329 regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000);
3330 regmap_write(rt5663->regmap, RT5663_CHOP_DAC_L, 0x3030);
3331 regmap_write(rt5663->regmap, RT5663_CALIB_ADC, 0x3c05);
3332 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23e);
3334 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23e);
3335 regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x0321);
3336 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0xfc00);
3340 static void rt5663_calibrate(struct rt5663_priv *rt5663)
3344 regmap_write(rt5663->regmap, RT5663_RESET, 0x0000);
3346 regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_4, 0x00a1);
3347 regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380);
3348 regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000);
3349 regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000);
3350 regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
3351 regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x000c);
3352 regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x0324);
3353 regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x8001);
3354 regmap_write(rt5663->regmap, RT5663_VREFADJ_OP, 0x0f28);
3355 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23b);
3357 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23b);
3358 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8000);
3359 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x0008);
3360 regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_1, 0xffff);
3361 regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_2, 0xffff);
3362 regmap_write(rt5663->regmap, RT5663_CBJ_1, 0x8c10);
3363 regmap_write(rt5663->regmap, RT5663_IL_CMD_2, 0x00c1);
3364 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb880);
3365 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4110);
3366 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4118);
3370 regmap_read(rt5663->regmap, RT5663_INT_ST_2, &value);
3380 regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x0000);
3381 regmap_write(rt5663->regmap, RT5663_DEPOP_2, 0x3003);
3382 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0038);
3383 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x003b);
3384 regmap_write(rt5663->regmap, RT5663_PWR_DIG_2, 0x8400);
3385 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x8df8);
3386 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8003);
3387 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x018c);
3388 regmap_write(rt5663->regmap, RT5663_HP_CHARGE_PUMP_1, 0x1e32);
3389 regmap_write(rt5663->regmap, RT5663_DUMMY_2, 0x8089);
3390 regmap_write(rt5663->regmap, RT5663_DACREF_LDO, 0x3b0b);
3392 regmap_write(rt5663->regmap, RT5663_STO_DAC_MIXER, 0x0000);
3393 regmap_write(rt5663->regmap, RT5663_BYPASS_STO_DAC, 0x000c);
3394 regmap_write(rt5663->regmap, RT5663_HP_BIAS, 0xafaa);
3395 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_1, 0x2224);
3396 regmap_write(rt5663->regmap, RT5663_HP_OUT_EN, 0x8088);
3397 regmap_write(rt5663->regmap, RT5663_STO_DRE_9, 0x0017);
3398 regmap_write(rt5663->regmap, RT5663_STO_DRE_10, 0x0017);
3399 regmap_write(rt5663->regmap, RT5663_STO1_ADC_MIXER, 0x4040);
3400 regmap_write(rt5663->regmap, RT5663_CHOP_ADC, 0x3000);
3401 regmap_write(rt5663->regmap, RT5663_RECMIX, 0x0005);
3402 regmap_write(rt5663->regmap, RT5663_ADDA_RST, 0xc000);
3403 regmap_write(rt5663->regmap, RT5663_STO1_HPF_ADJ1, 0x3320);
3404 regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x00c9);
3405 regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x004c);
3406 regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_1, 0x1111);
3407 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0x4402);
3408 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x3311);
3409 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0x0069);
3410 regmap_write(rt5663->regmap, RT5663_HP_CALIB_3, 0x06ce);
3411 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6800);
3412 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x1100);
3413 regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0057);
3414 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe800);
3418 regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value);
3429 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6200);
3430 regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0059);
3431 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe200);
3435 regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value);
3446 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb8e0);
3448 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0x003b);
3450 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0000);
3452 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x000b);
3454 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0008);
3456 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x0000);
3460 static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
3466 &rt5663->pdata.dc_offset_l_manual);
3468 &rt5663->pdata.dc_offset_r_manual);
3470 &rt5663->pdata.dc_offset_l_manual_mic);
3472 &rt5663->pdata.dc_offset_r_manual_mic);
3474 &rt5663->pdata.impedance_sensing_num);
3476 if (rt5663->pdata.impedance_sensing_num) {
3478 rt5663->pdata.impedance_sensing_num;
3479 rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
3480 if (!rt5663->imp_table)
3484 (u32 *)rt5663->imp_table, table_size);
3495 struct rt5663_priv *rt5663;
3500 rt5663 = devm_kzalloc(&i2c->dev, sizeof(struct rt5663_priv),
3503 if (rt5663 == NULL)
3506 i2c_set_clientdata(i2c, rt5663);
3509 rt5663->pdata = *pdata;
3511 ret = rt5663_parse_dp(rt5663, &i2c->dev);
3516 for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++)
3517 rt5663->supplies[i].supply = rt5663_supply_names[i];
3520 ARRAY_SIZE(rt5663->supplies),
3521 rt5663->supplies);
3528 for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) {
3529 ret = regulator_set_load(rt5663->supplies[i].consumer,
3534 rt5663->supplies[i].supply, ret);
3539 ret = regulator_bulk_enable(ARRAY_SIZE(rt5663->supplies),
3540 rt5663->supplies);
3559 "Device with ID register %#x is not rt5663, retry one time.\n",
3567 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap);
3568 rt5663->codec_ver = CODEC_VER_1;
3571 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_regmap);
3572 rt5663->codec_ver = CODEC_VER_0;
3576 "Device with ID register %#x is not rt5663\n",
3582 if (IS_ERR(rt5663->regmap)) {
3583 ret = PTR_ERR(rt5663->regmap);
3590 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3591 regcache_cache_bypass(rt5663->regmap, true);
3592 switch (rt5663->codec_ver) {
3594 rt5663_v2_calibrate(rt5663);
3597 rt5663_calibrate(rt5663);
3602 regcache_cache_bypass(rt5663->regmap, false);
3603 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3606 switch (rt5663->codec_ver) {
3610 ret = regmap_register_patch(rt5663->regmap, rt5663_patch_list,
3621 regmap_update_bits(rt5663->regmap, RT5663_GPIO_1, RT5663_GP1_PIN_MASK,
3624 regmap_update_bits(rt5663->regmap, RT5663_IL_CMD_5,
3627 switch (rt5663->codec_ver) {
3629 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
3631 regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
3634 regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_2,
3636 regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
3639 regmap_update_bits(rt5663->regmap, RT5663_HP_LOGIC_2,
3641 regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
3646 regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
3648 regmap_update_bits(rt5663->regmap, RT5663_GPIO_3,
3650 regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_1,
3655 regmap_update_bits(rt5663->regmap, RT5663_DIG_MISC,
3657 regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
3659 regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
3661 regmap_update_bits(rt5663->regmap, RT5663_GPIO_1,
3663 regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
3664 regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
3667 regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
3669 regmap_update_bits(rt5663->regmap, RT5663_TDM_2,
3677 INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work);
3678 INIT_DELAYED_WORK(&rt5663->jd_unplug_work, rt5663_jd_unplug_work);
3683 | IRQF_ONESHOT, "rt5663", rt5663);
3707 free_irq(i2c->irq, rt5663);
3709 regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
3715 struct rt5663_priv *rt5663 = i2c_get_clientdata(i2c);
3718 free_irq(i2c->irq, rt5663);
3720 regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
3725 struct rt5663_priv *rt5663 = i2c_get_clientdata(client);
3727 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3732 .name = "rt5663",