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",
3301 { "rt5663", 0 },
3308 { .compatible = "realtek,rt5663", },
3322 static void rt5663_v2_calibrate(struct rt5663_priv *rt5663)
3324 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
3325 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0100);
3326 regmap_write(rt5663->regmap, RT5663_RECMIX, 0x4040);
3327 regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x0001);
3328 regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380);
3329 regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000);
3330 regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000);
3331 regmap_write(rt5663->regmap, RT5663_CHOP_DAC_L, 0x3030);
3332 regmap_write(rt5663->regmap, RT5663_CALIB_ADC, 0x3c05);
3333 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23e);
3335 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23e);
3336 regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x0321);
3337 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0xfc00);
3341 static void rt5663_calibrate(struct rt5663_priv *rt5663)
3345 regmap_write(rt5663->regmap, RT5663_RESET, 0x0000);
3347 regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_4, 0x00a1);
3348 regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380);
3349 regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000);
3350 regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000);
3351 regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
3352 regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x000c);
3353 regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x0324);
3354 regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x8001);
3355 regmap_write(rt5663->regmap, RT5663_VREFADJ_OP, 0x0f28);
3356 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23b);
3358 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23b);
3359 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8000);
3360 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x0008);
3361 regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_1, 0xffff);
3362 regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_2, 0xffff);
3363 regmap_write(rt5663->regmap, RT5663_CBJ_1, 0x8c10);
3364 regmap_write(rt5663->regmap, RT5663_IL_CMD_2, 0x00c1);
3365 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb880);
3366 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4110);
3367 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4118);
3371 regmap_read(rt5663->regmap, RT5663_INT_ST_2, &value);
3381 regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x0000);
3382 regmap_write(rt5663->regmap, RT5663_DEPOP_2, 0x3003);
3383 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0038);
3384 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x003b);
3385 regmap_write(rt5663->regmap, RT5663_PWR_DIG_2, 0x8400);
3386 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x8df8);
3387 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8003);
3388 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x018c);
3389 regmap_write(rt5663->regmap, RT5663_HP_CHARGE_PUMP_1, 0x1e32);
3390 regmap_write(rt5663->regmap, RT5663_DUMMY_2, 0x8089);
3391 regmap_write(rt5663->regmap, RT5663_DACREF_LDO, 0x3b0b);
3393 regmap_write(rt5663->regmap, RT5663_STO_DAC_MIXER, 0x0000);
3394 regmap_write(rt5663->regmap, RT5663_BYPASS_STO_DAC, 0x000c);
3395 regmap_write(rt5663->regmap, RT5663_HP_BIAS, 0xafaa);
3396 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_1, 0x2224);
3397 regmap_write(rt5663->regmap, RT5663_HP_OUT_EN, 0x8088);
3398 regmap_write(rt5663->regmap, RT5663_STO_DRE_9, 0x0017);
3399 regmap_write(rt5663->regmap, RT5663_STO_DRE_10, 0x0017);
3400 regmap_write(rt5663->regmap, RT5663_STO1_ADC_MIXER, 0x4040);
3401 regmap_write(rt5663->regmap, RT5663_CHOP_ADC, 0x3000);
3402 regmap_write(rt5663->regmap, RT5663_RECMIX, 0x0005);
3403 regmap_write(rt5663->regmap, RT5663_ADDA_RST, 0xc000);
3404 regmap_write(rt5663->regmap, RT5663_STO1_HPF_ADJ1, 0x3320);
3405 regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x00c9);
3406 regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x004c);
3407 regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_1, 0x1111);
3408 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0x4402);
3409 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x3311);
3410 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0x0069);
3411 regmap_write(rt5663->regmap, RT5663_HP_CALIB_3, 0x06ce);
3412 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6800);
3413 regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x1100);
3414 regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0057);
3415 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe800);
3419 regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value);
3430 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6200);
3431 regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0059);
3432 regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe200);
3436 regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value);
3447 regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb8e0);
3449 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0x003b);
3451 regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0000);
3453 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x000b);
3455 regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0008);
3457 regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x0000);
3461 static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
3467 &rt5663->pdata.dc_offset_l_manual);
3469 &rt5663->pdata.dc_offset_r_manual);
3471 &rt5663->pdata.dc_offset_l_manual_mic);
3473 &rt5663->pdata.dc_offset_r_manual_mic);
3475 &rt5663->pdata.impedance_sensing_num);
3477 if (rt5663->pdata.impedance_sensing_num) {
3479 rt5663->pdata.impedance_sensing_num;
3480 rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
3481 if (!rt5663->imp_table)
3485 (u32 *)rt5663->imp_table, table_size);
3497 struct rt5663_priv *rt5663;
3502 rt5663 = devm_kzalloc(&i2c->dev, sizeof(struct rt5663_priv),
3505 if (rt5663 == NULL)
3508 i2c_set_clientdata(i2c, rt5663);
3511 rt5663->pdata = *pdata;
3513 ret = rt5663_parse_dp(rt5663, &i2c->dev);
3518 for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++)
3519 rt5663->supplies[i].supply = rt5663_supply_names[i];
3522 ARRAY_SIZE(rt5663->supplies),
3523 rt5663->supplies);
3530 for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) {
3531 ret = regulator_set_load(rt5663->supplies[i].consumer,
3536 rt5663->supplies[i].supply, ret);
3541 ret = regulator_bulk_enable(ARRAY_SIZE(rt5663->supplies),
3542 rt5663->supplies);
3561 "Device with ID register %#x is not rt5663, retry one time.\n",
3569 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap);
3570 rt5663->codec_ver = CODEC_VER_1;
3573 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_regmap);
3574 rt5663->codec_ver = CODEC_VER_0;
3578 "Device with ID register %#x is not rt5663\n",
3584 if (IS_ERR(rt5663->regmap)) {
3585 ret = PTR_ERR(rt5663->regmap);
3592 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3593 regcache_cache_bypass(rt5663->regmap, true);
3594 switch (rt5663->codec_ver) {
3596 rt5663_v2_calibrate(rt5663);
3599 rt5663_calibrate(rt5663);
3604 regcache_cache_bypass(rt5663->regmap, false);
3605 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3608 switch (rt5663->codec_ver) {
3612 ret = regmap_register_patch(rt5663->regmap, rt5663_patch_list,
3623 regmap_update_bits(rt5663->regmap, RT5663_GPIO_1, RT5663_GP1_PIN_MASK,
3626 regmap_update_bits(rt5663->regmap, RT5663_IL_CMD_5,
3629 switch (rt5663->codec_ver) {
3631 regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
3633 regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
3636 regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_2,
3638 regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
3641 regmap_update_bits(rt5663->regmap, RT5663_HP_LOGIC_2,
3643 regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
3648 regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
3650 regmap_update_bits(rt5663->regmap, RT5663_GPIO_3,
3652 regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_1,
3657 regmap_update_bits(rt5663->regmap, RT5663_DIG_MISC,
3659 regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
3661 regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
3663 regmap_update_bits(rt5663->regmap, RT5663_GPIO_1,
3665 regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
3666 regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
3669 regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
3671 regmap_update_bits(rt5663->regmap, RT5663_TDM_2,
3679 INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work);
3680 INIT_DELAYED_WORK(&rt5663->jd_unplug_work, rt5663_jd_unplug_work);
3685 | IRQF_ONESHOT, "rt5663", rt5663);
3709 free_irq(i2c->irq, rt5663);
3711 regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
3717 struct rt5663_priv *rt5663 = i2c_get_clientdata(i2c);
3720 free_irq(i2c->irq, rt5663);
3722 regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
3729 struct rt5663_priv *rt5663 = i2c_get_clientdata(client);
3731 regmap_write(rt5663->regmap, RT5663_RESET, 0);
3736 .name = "rt5663",