H A D | rt5645.c | 2 * rt5645.c -- RT5645 ALSA SoC audio codec driver 35 #include "rt5645.h" 501 struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component); rt5645_hweq_get() local 507 eq_param[i].reg = cpu_to_be16(rt5645->eq_param[i].reg); rt5645_hweq_get() 508 eq_param[i].val = cpu_to_be16(rt5645->eq_param[i].val); rt5645_hweq_get() 527 struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component); rt5645_hweq_put() local 555 memcpy(rt5645->eq_param, eq_param, rt5645_hweq_put() 572 struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component); rt5645_spk_put_volsw() local 575 cancel_delayed_work_sync(&rt5645->rcclock_work); rt5645_spk_put_volsw() 577 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, rt5645_spk_put_volsw() 582 queue_delayed_work(system_power_efficient_wq, &rt5645->rcclock_work, rt5645_spk_put_volsw() 668 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); set_dmic_clk() local 671 rate = rt5645->sysclk / rl6231_get_pre_div(rt5645->regmap, set_dmic_clk() 746 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_enable_hweq() local 750 if (rt5645_validate_hweq(rt5645->eq_param[i].reg)) rt5645_enable_hweq() 751 regmap_write(rt5645->regmap, rt5645->eq_param[i].reg, rt5645_enable_hweq() 752 rt5645->eq_param[i].val); rt5645_enable_hweq() 1502 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); hp_amp_power() local 1506 if (rt5645->codec_type == CODEC_TYPE_RT5650) { hp_amp_power() 1511 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1516 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1519 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1523 rt5645->hp_on = true; hp_amp_power() 1529 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1551 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1553 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1561 if (rt5645->codec_type == CODEC_TYPE_RT5650) { hp_amp_power() 1562 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1565 regmap_write(rt5645->regmap, RT5645_PR_BASE + hp_amp_power() 1595 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_hp_event() local 1601 if (rt5645->codec_type == CODEC_TYPE_RT5645) { rt5645_hp_event() 1608 regmap_write(rt5645->regmap, RT5645_PR_BASE + rt5645_hp_event() 1628 if (rt5645->codec_type == CODEC_TYPE_RT5645) { rt5645_hp_event() 1635 regmap_write(rt5645->regmap, RT5645_PR_BASE + rt5645_hp_event() 1747 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5650_hp_event() local 1751 if (rt5645->hp_on) { rt5650_hp_event() 1753 rt5645->hp_on = false; rt5650_hp_event() 2535 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_hw_params() local 2539 rt5645->lrck[dai->id] = params_rate(params); rt5645_hw_params() 2540 pre_div = rl6231_get_clk_info(rt5645->sysclk, rt5645->lrck[dai->id]); rt5645_hw_params() 2551 switch (rt5645->codec_type) { rt5645_hw_params() 2561 rt5645->bclk[dai->id] = rt5645->lrck[dai->id] * (32 << bclk_ms); rt5645_hw_params() 2564 rt5645->bclk[dai->id], rt5645->lrck[dai->id]); rt5645_hw_params() 2611 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_set_dai_fmt() local 2614 switch (rt5645->codec_type) { rt5645_set_dai_fmt() 2625 rt5645->master[dai->id] = 1; rt5645_set_dai_fmt() 2629 rt5645->master[dai->id] = 0; rt5645_set_dai_fmt() 2682 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_set_dai_sysclk() local 2685 if (freq == rt5645->sysclk && clk_id == rt5645->sysclk_src) rt5645_set_dai_sysclk() 2704 rt5645->sysclk = freq; rt5645_set_dai_sysclk() 2705 rt5645->sysclk_src = clk_id; rt5645_set_dai_sysclk() 2716 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_set_dai_pll() local 2720 if (source == rt5645->pll_src && freq_in == rt5645->pll_in && rt5645_set_dai_pll() 2721 freq_out == rt5645->pll_out) rt5645_set_dai_pll() 2727 rt5645->pll_in = 0; rt5645_set_dai_pll() 2728 rt5645->pll_out = 0; rt5645_set_dai_pll() 2776 rt5645->pll_in = freq_in; rt5645_set_dai_pll() 2777 rt5645->pll_out = freq_out; rt5645_set_dai_pll() 2778 rt5645->pll_src = source; rt5645_set_dai_pll() 2787 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_set_tdm_slot() local 2791 switch (rt5645->codec_type) { rt5645_set_tdm_slot() 2809 if (rt5645->codec_type == CODEC_TYPE_RT5645) rt5645_set_tdm_slot() 2852 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_set_bias_level() local 2880 if (rt5645->en_button_func && rt5645_set_bias_level() 2883 &rt5645->jack_detect_work, msecs_to_jiffies(0)); rt5645_set_bias_level() 2888 if (!rt5645->en_button_func) rt5645_set_bias_level() 2934 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_jack_detect() local 2938 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0006); rt5645_jack_detect() 2947 regmap_update_bits(rt5645->regmap, RT5645_PWR_ANLG1, rt5645_jack_detect() 2950 regmap_update_bits(rt5645->regmap, RT5645_PWR_MIXER, rt5645_jack_detect() 2952 regmap_update_bits(rt5645->regmap, RT5645_PWR_VOL, rt5645_jack_detect() 2956 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0); rt5645_jack_detect() 2957 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, rt5645_jack_detect() 2959 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, rt5645_jack_detect() 2962 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, rt5645_jack_detect() 2966 regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val); rt5645_jack_detect() 2971 rt5645->jack_type = SND_JACK_HEADSET; rt5645_jack_detect() 2972 if (rt5645->en_button_func) { rt5645_jack_detect() 2978 rt5645->jack_type = SND_JACK_HEADPHONE; rt5645_jack_detect() 2980 if (rt5645->pdata.jd_invert) rt5645_jack_detect() 2981 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, rt5645_jack_detect() 2984 rt5645->jack_type = 0; rt5645_jack_detect() 2986 regmap_update_bits(rt5645->regmap, RT5645_HP_VOL, rt5645_jack_detect() 2989 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, rt5645_jack_detect() 2991 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, rt5645_jack_detect() 2994 if (rt5645->en_button_func) rt5645_jack_detect() 2997 if (rt5645->pdata.jd_mode == 0) rt5645_jack_detect() 3001 if (rt5645->pdata.jd_invert) rt5645_jack_detect() 3002 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, rt5645_jack_detect() 3006 return rt5645->jack_type; rt5645_jack_detect() 3027 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_set_jack_detect() local 3029 rt5645->hp_jack = hp_jack; rt5645_set_jack_detect() 3030 rt5645->mic_jack = mic_jack; rt5645_set_jack_detect() 3031 rt5645->btn_jack = btn_jack; rt5645_set_jack_detect() 3032 if (rt5645->btn_jack && rt5645->codec_type == CODEC_TYPE_RT5650) { rt5645_set_jack_detect() 3033 rt5645->en_button_func = true; rt5645_set_jack_detect() 3034 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_set_jack_detect() 3036 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1, rt5645_set_jack_detect() 3039 rt5645_irq(0, rt5645); rt5645_set_jack_detect() 3047 struct rt5645_priv *rt5645 = rt5645_jack_detect_work() local 3051 if (!rt5645->codec) rt5645_jack_detect_work() 3054 switch (rt5645->pdata.jd_mode) { rt5645_jack_detect_work() 3055 case 0: /* Not using rt5645 JD */ rt5645_jack_detect_work() 3056 if (rt5645->gpiod_hp_det) { rt5645_jack_detect_work() 3057 gpio_state = gpiod_get_value(rt5645->gpiod_hp_det); rt5645_jack_detect_work() 3058 dev_dbg(rt5645->codec->dev, "gpio_state = %d\n", rt5645_jack_detect_work() 3060 report = rt5645_jack_detect(rt5645->codec, gpio_state); rt5645_jack_detect_work() 3062 snd_soc_jack_report(rt5645->hp_jack, rt5645_jack_detect_work() 3064 snd_soc_jack_report(rt5645->mic_jack, rt5645_jack_detect_work() 3068 val = snd_soc_read(rt5645->codec, RT5645_A_JD_CTRL1) & 0x0070; rt5645_jack_detect_work() 3071 val = snd_soc_read(rt5645->codec, RT5645_A_JD_CTRL1) & 0x0020; rt5645_jack_detect_work() 3080 if (rt5645->jack_type == 0) { rt5645_jack_detect_work() 3081 report = rt5645_jack_detect(rt5645->codec, 1); rt5645_jack_detect_work() 3086 if (snd_soc_read(rt5645->codec, RT5645_INT_IRQ_ST) & 0x4) { rt5645_jack_detect_work() 3089 btn_type = rt5645_button_detect(rt5645->codec); rt5645_jack_detect_work() 3119 dev_err(rt5645->codec->dev, rt5645_jack_detect_work() 3126 report = rt5645->jack_type; rt5645_jack_detect_work() 3134 snd_soc_update_bits(rt5645->codec, rt5645_jack_detect_work() 3136 rt5645_jack_detect(rt5645->codec, 0); rt5645_jack_detect_work() 3142 snd_soc_jack_report(rt5645->hp_jack, report, SND_JACK_HEADPHONE); rt5645_jack_detect_work() 3143 snd_soc_jack_report(rt5645->mic_jack, report, SND_JACK_MICROPHONE); rt5645_jack_detect_work() 3144 if (rt5645->en_button_func) rt5645_jack_detect_work() 3145 snd_soc_jack_report(rt5645->btn_jack, rt5645_jack_detect_work() 3152 struct rt5645_priv *rt5645 = rt5645_rcclock_work() local 3155 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, rt5645_rcclock_work() 3161 struct rt5645_priv *rt5645 = data; rt5645_irq() local 3164 &rt5645->jack_detect_work, msecs_to_jiffies(250)); rt5645_irq() 3172 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_probe() local 3174 rt5645->codec = codec; rt5645_probe() 3176 switch (rt5645->codec_type) { rt5645_probe() 3198 if (rt5645->pdata.jd_mode) { rt5645_probe() 3204 rt5645->eq_param = devm_kzalloc(codec->dev, rt5645_probe() 3219 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_suspend() local 3221 regcache_cache_only(rt5645->regmap, true); rt5645_suspend() 3222 regcache_mark_dirty(rt5645->regmap); rt5645_suspend() 3229 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); rt5645_resume() local 3231 regcache_cache_only(rt5645->regmap, false); rt5645_resume() 3232 regcache_sync(rt5645->regmap); rt5645_resume() 3255 .name = "rt5645-aif1", 3274 .name = "rt5645-aif2", 3326 { "rt5645", 0 }, 3435 static int rt5645_parse_dt(struct rt5645_priv *rt5645, struct device *dev) rt5645_parse_dt() argument 3437 rt5645->pdata.in2_diff = device_property_read_bool(dev, rt5645_parse_dt() 3440 "realtek,dmic1-data-pin", &rt5645->pdata.dmic1_data_pin); rt5645_parse_dt() 3442 "realtek,dmic2-data-pin", &rt5645->pdata.dmic2_data_pin); rt5645_parse_dt() 3444 "realtek,jd-mode", &rt5645->pdata.jd_mode); rt5645_parse_dt() 3453 struct rt5645_priv *rt5645; rt5645_i2c_probe() local 3457 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), rt5645_i2c_probe() 3459 if (rt5645 == NULL) rt5645_i2c_probe() 3462 rt5645->i2c = i2c; rt5645_i2c_probe() 3463 i2c_set_clientdata(i2c, rt5645); rt5645_i2c_probe() 3466 rt5645->pdata = *pdata; rt5645_i2c_probe() 3469 rt5645->pdata = *rt5645_pdata; rt5645_i2c_probe() 3471 rt5645_parse_dt(rt5645, &i2c->dev); rt5645_i2c_probe() 3473 rt5645->gpiod_hp_det = devm_gpiod_get_optional(&i2c->dev, "hp-detect", rt5645_i2c_probe() 3476 if (IS_ERR(rt5645->gpiod_hp_det)) { rt5645_i2c_probe() 3478 return PTR_ERR(rt5645->gpiod_hp_det); rt5645_i2c_probe() 3481 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap); rt5645_i2c_probe() 3482 if (IS_ERR(rt5645->regmap)) { rt5645_i2c_probe() 3483 ret = PTR_ERR(rt5645->regmap); rt5645_i2c_probe() 3489 for (i = 0; i < ARRAY_SIZE(rt5645->supplies); i++) rt5645_i2c_probe() 3490 rt5645->supplies[i].supply = rt5645_supply_names[i]; rt5645_i2c_probe() 3493 ARRAY_SIZE(rt5645->supplies), rt5645_i2c_probe() 3494 rt5645->supplies); rt5645_i2c_probe() 3500 ret = regulator_bulk_enable(ARRAY_SIZE(rt5645->supplies), rt5645_i2c_probe() 3501 rt5645->supplies); rt5645_i2c_probe() 3507 regmap_read(rt5645->regmap, RT5645_VENDOR_ID2, &val); rt5645_i2c_probe() 3511 rt5645->codec_type = CODEC_TYPE_RT5645; rt5645_i2c_probe() 3514 rt5645->codec_type = CODEC_TYPE_RT5650; rt5645_i2c_probe() 3518 "Device with ID register %#x is not rt5645 or rt5650\n", rt5645_i2c_probe() 3524 regmap_write(rt5645->regmap, RT5645_RESET, 0); rt5645_i2c_probe() 3526 ret = regmap_register_patch(rt5645->regmap, init_list, rt5645_i2c_probe() 3531 if (rt5645->codec_type == CODEC_TYPE_RT5650) { rt5645_i2c_probe() 3532 ret = regmap_register_patch(rt5645->regmap, rt5650_init_list, rt5645_i2c_probe() 3539 if (rt5645->pdata.in2_diff) rt5645_i2c_probe() 3540 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL, rt5645_i2c_probe() 3543 if (rt5645->pdata.dmic1_data_pin || rt5645->pdata.dmic2_data_pin) { rt5645_i2c_probe() 3544 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3547 switch (rt5645->pdata.dmic1_data_pin) { rt5645_i2c_probe() 3549 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3554 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3556 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3558 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3563 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3565 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3574 switch (rt5645->pdata.dmic2_data_pin) { rt5645_i2c_probe() 3576 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3581 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3583 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3588 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3590 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3596 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, rt5645_i2c_probe() 3598 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3607 if (rt5645->pdata.jd_mode) { rt5645_i2c_probe() 3608 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, rt5645_i2c_probe() 3611 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, rt5645_i2c_probe() 3613 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, rt5645_i2c_probe() 3615 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, rt5645_i2c_probe() 3617 regmap_update_bits(rt5645->regmap, RT5645_HPO_MIXER, rt5645_i2c_probe() 3619 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, rt5645_i2c_probe() 3621 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, rt5645_i2c_probe() 3623 switch (rt5645->pdata.jd_mode) { rt5645_i2c_probe() 3625 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, rt5645_i2c_probe() 3630 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, rt5645_i2c_probe() 3635 regmap_update_bits(rt5645->regmap, RT5645_A_JD_CTRL1, rt5645_i2c_probe() 3644 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work); rt5645_i2c_probe() 3645 INIT_DELAYED_WORK(&rt5645->rcclock_work, rt5645_rcclock_work); rt5645_i2c_probe() 3647 if (rt5645->i2c->irq) { rt5645_i2c_probe() 3648 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, rt5645_i2c_probe() 3650 | IRQF_ONESHOT, "rt5645", rt5645); rt5645_i2c_probe() 3665 if (rt5645->i2c->irq) rt5645_i2c_probe() 3666 free_irq(rt5645->i2c->irq, rt5645); rt5645_i2c_probe() 3668 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); rt5645_i2c_probe() 3674 struct rt5645_priv *rt5645 = i2c_get_clientdata(i2c); rt5645_i2c_remove() local 3677 free_irq(i2c->irq, rt5645); rt5645_i2c_remove() 3679 cancel_delayed_work_sync(&rt5645->jack_detect_work); rt5645_i2c_remove() 3680 cancel_delayed_work_sync(&rt5645->rcclock_work); rt5645_i2c_remove() 3683 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); rt5645_i2c_remove() 3690 struct rt5645_priv *rt5645 = i2c_get_clientdata(i2c); rt5645_i2c_shutdown() local 3692 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, rt5645_i2c_shutdown() 3694 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, RT5645_CBJ_MN_JD, rt5645_i2c_shutdown() 3696 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, RT5645_CBJ_BST1_EN, rt5645_i2c_shutdown() 3699 regmap_write(rt5645->regmap, RT5645_RESET, 0); rt5645_i2c_shutdown() 3704 .name = "rt5645",
|