Lines Matching +full:tx +full:- +full:clk +full:- +full:10 +full:- +full:inverted

1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm8960.c -- WM8960 ALSA SoC Audio driver
5 * Copyright 2007-11 Wolfson Microelectronics, plc
15 #include <linux/clk.h>
29 /* R25 - Power 1 */
33 /* R26 - Power 2 */
38 /* R28 - Anti-pop 1 */
45 /* R29 - Anti-pop 2 */
133 struct clk *mclk;
155 static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted",
156 "Right Inverted", "Stereo Inversion"};
192 if (wm8960->deemph) { in wm8960_set_deemph()
195 if (abs(deemph_settings[i] - wm8960->lrclk) < in wm8960_set_deemph()
196 abs(deemph_settings[best] - wm8960->lrclk)) in wm8960_set_deemph()
205 dev_dbg(component->dev, "Set deemphasis %d\n", val); in wm8960_set_deemph()
217 ucontrol->value.integer.value[0] = wm8960->deemph; in wm8960_get_deemph()
226 unsigned int deemph = ucontrol->value.integer.value[0]; in wm8960_put_deemph()
229 return -EINVAL; in wm8960_put_deemph()
231 wm8960->deemph = deemph; in wm8960_put_deemph()
236 static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
237 static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1725, 75, 0);
238 static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
239 static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);
240 static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
241 static const DECLARE_TLV_DB_SCALE(lineinboost_tlv, -1500, 300, 1);
283 SOC_SINGLE("PCM Playback -6dB Switch", WM8960_DACCTL1, 7, 1, 0),
291 SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[2]),
292 SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[3]),
490 struct wm8960_data *pdata = &wm8960->pdata; in wm8960_add_widgets()
502 if (pdata && pdata->capless) { in wm8960_add_widgets()
521 list_for_each_entry(w, &component->card->widgets, list) { in wm8960_add_widgets()
522 if (w->dapm != dapm) in wm8960_add_widgets()
524 if (strcmp(w->name, "LOUT1 PGA") == 0) in wm8960_add_widgets()
525 wm8960->lout1 = w; in wm8960_add_widgets()
526 if (strcmp(w->name, "ROUT1 PGA") == 0) in wm8960_add_widgets()
527 wm8960->rout1 = w; in wm8960_add_widgets()
528 if (strcmp(w->name, "OUT3 VMID") == 0) in wm8960_add_widgets()
529 wm8960->out3 = w; in wm8960_add_widgets()
538 struct snd_soc_component *component = codec_dai->component; in wm8960_set_dai_fmt()
549 return -EINVAL; in wm8960_set_dai_fmt()
569 return -EINVAL; in wm8960_set_dai_fmt()
586 return -EINVAL; in wm8960_set_dai_fmt()
609 /* -1 for reserved value */
610 static const int sysclk_divs[] = { 1, -1, 2, -1 };
615 /* Multiply 10 to eliminate decimials */
617 10, 15, 20, 30, 40, 55, 60, 80, 110,
622 * wm8960_configure_sysclk - checks if there is a sysclk frequency available
624 * - sysclk = MCLK / sysclk_divs
625 * - lrclk = sysclk / dac_divs
626 * - 10 * bclk = sysclk / bclk_divs
635 * -1, in case no sysclk frequency available found
648 *bclk_idx = -1; in wm8960_configure_sysclk()
650 bclk = wm8960->bclk; in wm8960_configure_sysclk()
651 lrclk = wm8960->lrclk; in wm8960_configure_sysclk()
655 if (sysclk_divs[i] == -1) in wm8960_configure_sysclk()
662 diff = sysclk - bclk * bclk_divs[k] / 10; in wm8960_configure_sysclk()
680 * wm8960_configure_pll - checks if there is a PLL out frequency available
682 * - sysclk = lrclk * dac_divs
683 * - freq_out = sysclk * sysclk_divs
684 * - 10 * sysclk = bclk * bclk_divs
710 bclk = wm8960->bclk; in wm8960_configure_pll()
711 lrclk = wm8960->lrclk; in wm8960_configure_pll()
714 best_freq_out = -EINVAL; in wm8960_configure_pll()
715 *sysclk_idx = *dac_idx = *bclk_idx = -1; in wm8960_configure_pll()
723 for (i = ARRAY_SIZE(sysclk_divs) - 1; i >= 0; --i) { in wm8960_configure_pll()
724 if (sysclk_divs[i] == -1) in wm8960_configure_pll()
734 diff = sysclk - bclk * bclk_divs[k] / 10; in wm8960_configure_pll()
766 * compatible issue, just add '!wm8960->sysclk' condition in in wm8960_configure_clocking()
769 if (!(iface1 & (1 << 6)) && !wm8960->sysclk) { in wm8960_configure_clocking()
770 dev_warn(component->dev, in wm8960_configure_clocking()
775 if (wm8960->clk_id != WM8960_SYSCLK_MCLK && !wm8960->freq_in) { in wm8960_configure_clocking()
776 dev_err(component->dev, "No MCLK configured\n"); in wm8960_configure_clocking()
777 return -EINVAL; in wm8960_configure_clocking()
780 freq_in = wm8960->freq_in; in wm8960_configure_clocking()
787 if (wm8960->clk_id == WM8960_SYSCLK_AUTO) { in wm8960_configure_clocking()
791 } else if (wm8960->sysclk) { in wm8960_configure_clocking()
792 freq_out = wm8960->sysclk; in wm8960_configure_clocking()
794 dev_err(component->dev, "No SYSCLK configured\n"); in wm8960_configure_clocking()
795 return -EINVAL; in wm8960_configure_clocking()
798 if (wm8960->clk_id != WM8960_SYSCLK_PLL) { in wm8960_configure_clocking()
802 } else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) { in wm8960_configure_clocking()
803 dev_err(component->dev, "failed to configure clock\n"); in wm8960_configure_clocking()
804 return -EINVAL; in wm8960_configure_clocking()
810 dev_err(component->dev, "failed to configure clock via PLL\n"); in wm8960_configure_clocking()
833 struct snd_soc_component *component = dai->component; in wm8960_hw_params()
836 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in wm8960_hw_params() local
839 wm8960->bclk = snd_soc_params_to_bclk(params); in wm8960_hw_params()
841 wm8960->bclk *= 2; in wm8960_hw_params()
861 dev_err(component->dev, "unsupported width %d\n", in wm8960_hw_params()
863 return -EINVAL; in wm8960_hw_params()
866 wm8960->lrclk = params_rate(params); in wm8960_hw_params()
868 if (tx) { in wm8960_hw_params()
881 wm8960->is_stream_in_use[tx] = true; in wm8960_hw_params()
883 if (!wm8960->is_stream_in_use[!tx]) in wm8960_hw_params()
892 struct snd_soc_component *component = dai->component; in wm8960_hw_free()
894 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in wm8960_hw_free() local
896 wm8960->is_stream_in_use[tx] = false; in wm8960_hw_free()
903 struct snd_soc_component *component = dai->component; in wm8960_mute()
927 if (!IS_ERR(wm8960->mclk)) { in wm8960_set_bias_level_out3()
928 ret = clk_prepare_enable(wm8960->mclk); in wm8960_set_bias_level_out3()
930 dev_err(component->dev, in wm8960_set_bias_level_out3()
950 if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1)) in wm8960_set_bias_level_out3()
953 if (!IS_ERR(wm8960->mclk)) in wm8960_set_bias_level_out3()
954 clk_disable_unprepare(wm8960->mclk); in wm8960_set_bias_level_out3()
966 tout = WM8960_DSCH_TOUT - ktime_ms_delta(ktime_get(), wm8960->dsch_start); in wm8960_set_bias_level_out3()
970 regcache_sync(wm8960->regmap); in wm8960_set_bias_level_out3()
972 /* Enable anti-pop features */ in wm8960_set_bias_level_out3()
985 /* Disable anti-pop features */ in wm8960_set_bias_level_out3()
994 /* Enable anti-pop features */ in wm8960_set_bias_level_out3()
1001 wm8960->dsch_start = ktime_get(); in wm8960_set_bias_level_out3()
1031 if (wm8960->lout1 && wm8960->lout1->power) in wm8960_set_bias_level_capless()
1033 if (wm8960->rout1 && wm8960->rout1->power) in wm8960_set_bias_level_capless()
1035 if (wm8960->out3 && wm8960->out3->power) in wm8960_set_bias_level_capless()
1055 if (!IS_ERR(wm8960->mclk)) { in wm8960_set_bias_level_capless()
1056 ret = clk_prepare_enable(wm8960->mclk); in wm8960_set_bias_level_capless()
1058 dev_err(component->dev, in wm8960_set_bias_level_capless()
1076 if (wm8960->clk_id == WM8960_SYSCLK_AUTO && (pm2 & 0x1)) in wm8960_set_bias_level_capless()
1079 if (!IS_ERR(wm8960->mclk)) in wm8960_set_bias_level_capless()
1080 clk_disable_unprepare(wm8960->mclk); in wm8960_set_bias_level_capless()
1082 /* Enable anti-pop mode */ in wm8960_set_bias_level_capless()
1095 regcache_sync(wm8960->regmap); in wm8960_set_bias_level_capless()
1110 /* Disable anti-pop features */ in wm8960_set_bias_level_capless()
1159 /* The size in bits of the pll divide multiplied by 10
1161 #define FIXED_PLL_SIZE ((1 << 24) * 10)
1169 pr_debug("WM8960 PLL: setting %dHz->%dHz\n", source, target); in pll_factors()
1177 pll_div->pre_div = 1; in pll_factors()
1180 pll_div->pre_div = 0; in pll_factors()
1184 return -EINVAL; in pll_factors()
1187 pll_div->n = Ndiv; in pll_factors()
1196 if ((K % 10) >= 5) in pll_factors()
1200 K /= 10; in pll_factors()
1202 pll_div->k = K; in pll_factors()
1205 pll_div->n, pll_div->k, pll_div->pre_div); in pll_factors()
1255 struct snd_soc_component *component = codec_dai->component; in wm8960_set_dai_pll()
1258 wm8960->freq_in = freq_in; in wm8960_set_dai_pll()
1269 struct snd_soc_component *component = codec_dai->component; in wm8960_set_dai_clkdiv()
1294 return -EINVAL; in wm8960_set_dai_clkdiv()
1305 return wm8960->set_bias_level(component, level); in wm8960_set_bias_level()
1311 struct snd_soc_component *component = dai->component; in wm8960_set_dai_sysclk()
1326 return -EINVAL; in wm8960_set_dai_sysclk()
1329 wm8960->sysclk = freq; in wm8960_set_dai_sysclk()
1330 wm8960->clk_id = clk_id; in wm8960_set_dai_sysclk()
1353 .name = "wm8960-hifi",
1373 struct wm8960_data *pdata = &wm8960->pdata; in wm8960_probe()
1375 if (pdata->capless) in wm8960_probe()
1376 wm8960->set_bias_level = wm8960_set_bias_level_capless; in wm8960_probe()
1378 wm8960->set_bias_level = wm8960_set_bias_level_out3; in wm8960_probe()
1411 const struct device_node *np = i2c->dev.of_node; in wm8960_set_pdata_from_of()
1414 pdata->capless = true; in wm8960_set_pdata_from_of()
1416 if (of_property_read_bool(np, "wlf,shared-lrclk")) in wm8960_set_pdata_from_of()
1417 pdata->shared_lrclk = true; in wm8960_set_pdata_from_of()
1419 of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_cfg, in wm8960_set_pdata_from_of()
1420 ARRAY_SIZE(pdata->gpio_cfg)); in wm8960_set_pdata_from_of()
1422 of_property_read_u32_array(np, "wlf,hp-cfg", pdata->hp_cfg, in wm8960_set_pdata_from_of()
1423 ARRAY_SIZE(pdata->hp_cfg)); in wm8960_set_pdata_from_of()
1428 struct wm8960_data *pdata = dev_get_platdata(&i2c->dev); in wm8960_i2c_probe()
1434 wm8960 = devm_kzalloc(&i2c->dev, sizeof(struct wm8960_priv), in wm8960_i2c_probe()
1437 return -ENOMEM; in wm8960_i2c_probe()
1439 wm8960->mclk = devm_clk_get(&i2c->dev, "mclk"); in wm8960_i2c_probe()
1440 if (IS_ERR(wm8960->mclk)) { in wm8960_i2c_probe()
1441 if (PTR_ERR(wm8960->mclk) == -EPROBE_DEFER) in wm8960_i2c_probe()
1442 return -EPROBE_DEFER; in wm8960_i2c_probe()
1444 ret = clk_get_rate(wm8960->mclk); in wm8960_i2c_probe()
1446 wm8960->freq_in = ret; in wm8960_i2c_probe()
1448 dev_err(&i2c->dev, "Failed to read MCLK rate: %d\n", in wm8960_i2c_probe()
1453 for (i = 0; i < ARRAY_SIZE(wm8960->supplies); i++) in wm8960_i2c_probe()
1454 wm8960->supplies[i].supply = wm8960_supply_names[i]; in wm8960_i2c_probe()
1456 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8960->supplies), in wm8960_i2c_probe()
1457 wm8960->supplies); in wm8960_i2c_probe()
1459 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); in wm8960_i2c_probe()
1463 ret = regulator_bulk_enable(ARRAY_SIZE(wm8960->supplies), in wm8960_i2c_probe()
1464 wm8960->supplies); in wm8960_i2c_probe()
1466 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); in wm8960_i2c_probe()
1470 wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap); in wm8960_i2c_probe()
1471 if (IS_ERR(wm8960->regmap)) { in wm8960_i2c_probe()
1472 ret = PTR_ERR(wm8960->regmap); in wm8960_i2c_probe()
1477 memcpy(&wm8960->pdata, pdata, sizeof(struct wm8960_data)); in wm8960_i2c_probe()
1478 else if (i2c->dev.of_node) in wm8960_i2c_probe()
1479 wm8960_set_pdata_from_of(i2c, &wm8960->pdata); in wm8960_i2c_probe()
1483 dev_err(&i2c->dev, "Not wm8960, wm8960 reg can not read by i2c\n"); in wm8960_i2c_probe()
1484 ret = -EINVAL; in wm8960_i2c_probe()
1488 ret = wm8960_reset(wm8960->regmap); in wm8960_i2c_probe()
1490 dev_err(&i2c->dev, "Failed to issue reset\n"); in wm8960_i2c_probe()
1494 if (wm8960->pdata.shared_lrclk) { in wm8960_i2c_probe()
1495 ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, in wm8960_i2c_probe()
1498 dev_err(&i2c->dev, "Failed to enable LRCM: %d\n", in wm8960_i2c_probe()
1505 regmap_update_bits(wm8960->regmap, WM8960_LINVOL, 0x100, 0x100); in wm8960_i2c_probe()
1506 regmap_update_bits(wm8960->regmap, WM8960_RINVOL, 0x100, 0x100); in wm8960_i2c_probe()
1507 regmap_update_bits(wm8960->regmap, WM8960_LADC, 0x100, 0x100); in wm8960_i2c_probe()
1508 regmap_update_bits(wm8960->regmap, WM8960_RADC, 0x100, 0x100); in wm8960_i2c_probe()
1509 regmap_update_bits(wm8960->regmap, WM8960_LDAC, 0x100, 0x100); in wm8960_i2c_probe()
1510 regmap_update_bits(wm8960->regmap, WM8960_RDAC, 0x100, 0x100); in wm8960_i2c_probe()
1511 regmap_update_bits(wm8960->regmap, WM8960_LOUT1, 0x100, 0x100); in wm8960_i2c_probe()
1512 regmap_update_bits(wm8960->regmap, WM8960_ROUT1, 0x100, 0x100); in wm8960_i2c_probe()
1513 regmap_update_bits(wm8960->regmap, WM8960_LOUT2, 0x100, 0x100); in wm8960_i2c_probe()
1514 regmap_update_bits(wm8960->regmap, WM8960_ROUT2, 0x100, 0x100); in wm8960_i2c_probe()
1517 regmap_update_bits(wm8960->regmap, WM8960_IFACE2, 1 << 6, in wm8960_i2c_probe()
1518 wm8960->pdata.gpio_cfg[0] << 6); in wm8960_i2c_probe()
1519 regmap_update_bits(wm8960->regmap, WM8960_ADDCTL4, 0xF << 4, in wm8960_i2c_probe()
1520 wm8960->pdata.gpio_cfg[1] << 4); in wm8960_i2c_probe()
1523 regmap_update_bits(wm8960->regmap, WM8960_ADDCTL4, 3 << 2, in wm8960_i2c_probe()
1524 wm8960->pdata.hp_cfg[0] << 2); in wm8960_i2c_probe()
1525 regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, 3 << 5, in wm8960_i2c_probe()
1526 wm8960->pdata.hp_cfg[1] << 5); in wm8960_i2c_probe()
1527 regmap_update_bits(wm8960->regmap, WM8960_ADDCTL1, 3, in wm8960_i2c_probe()
1528 wm8960->pdata.hp_cfg[2]); in wm8960_i2c_probe()
1532 ret = devm_snd_soc_register_component(&i2c->dev, in wm8960_i2c_probe()
1540 regulator_bulk_disable(ARRAY_SIZE(wm8960->supplies), wm8960->supplies); in wm8960_i2c_probe()
1548 regulator_bulk_disable(ARRAY_SIZE(wm8960->supplies), wm8960->supplies); in wm8960_i2c_remove()