Lines Matching +full:mclk +full:- +full:div
1 // SPDX-License-Identifier: GPL-2.0
30 #include <sound/soc-dapm.h>
39 struct clk *mclk; member
60 * min : 0 : -74 dB
62 static const DECLARE_TLV_DB_SCALE(adc_tlv, -7400, 100, 0);
63 static const DECLARE_TLV_DB_SCALE(dac_tlv, -7400, 100, 0);
73 unsigned int mclk; member
74 unsigned int div; member
243 { CX2072X_DIGITAL_TEST0, 0x415 }, /* Power down class-D during idle */
488 struct device *dev = &client->dev; in cx2072x_reg_raw_write()
493 return -EINVAL; in cx2072x_reg_raw_write()
503 return ret < 0 ? ret : -EIO; in cx2072x_reg_raw_write()
531 struct device *dev = &client->dev; in cx2072x_reg_read()
543 msgs[0].addr = client->addr; in cx2072x_reg_read()
548 msgs[1].addr = client->addr; in cx2072x_reg_read()
553 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in cx2072x_reg_read()
556 return ret < 0 ? ret : -EIO; in cx2072x_reg_read()
563 /* get suggested pre_div valuce from mclk frequency */
564 static unsigned int get_div_from_mclk(unsigned int mclk) in get_div_from_mclk() argument
566 unsigned int div = 8; in get_div_from_mclk() local
570 if (mclk <= mclk_pre_div[i].mclk) { in get_div_from_mclk()
571 div = mclk_pre_div[i].div; in get_div_from_mclk()
575 return div; in get_div_from_mclk()
580 struct device *dev = cx2072x->dev; in cx2072x_config_pll()
589 unsigned int sample_rate = cx2072x->sample_rate; in cx2072x_config_pll()
612 return -EINVAL; in cx2072x_config_pll()
616 pre_div = get_div_from_mclk(cx2072x->mclk_rate); in cx2072x_config_pll()
617 pll_input = cx2072x->mclk_rate / pre_div; in cx2072x_config_pll()
620 frac_div = pll_output - (int_div * pll_input); in cx2072x_config_pll()
625 frac_num = (u64)(4000 + frac_div) * ((1 << 20) - 4); in cx2072x_config_pll()
629 pre_div_val = (pre_div - 1) * 2; in cx2072x_config_pll()
631 regmap_write(cx2072x->regmap, CX2072X_ANALOG_TEST4, in cx2072x_config_pll()
635 regmap_write(cx2072x->regmap, CX2072X_ANALOG_TEST7, 0x100); in cx2072x_config_pll()
638 regmap_write(cx2072x->regmap, CX2072X_ANALOG_TEST6, in cx2072x_config_pll()
640 regmap_write(cx2072x->regmap, CX2072X_ANALOG_TEST7, in cx2072x_config_pll()
644 int_div--; in cx2072x_config_pll()
645 regmap_write(cx2072x->regmap, CX2072X_ANALOG_TEST8, int_div); in cx2072x_config_pll()
650 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST16, 0x00); in cx2072x_config_pll()
653 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST16, in cx2072x_config_pll()
655 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST17, in cx2072x_config_pll()
657 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST18, in cx2072x_config_pll()
659 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST19, 0x01); in cx2072x_config_pll()
660 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST20, 0x02); in cx2072x_config_pll()
661 regmap_update_bits(cx2072x->regmap, CX2072X_DIGITAL_TEST16, in cx2072x_config_pll()
670 struct device *dev = cx2072x->dev; in cx2072x_config_i2spcm()
677 int frame_len = cx2072x->frame_size; in cx2072x_config_i2spcm()
678 int sample_size = cx2072x->sample_size; in cx2072x_config_i2spcm()
683 u64 div; in cx2072x_config_i2spcm() local
692 const unsigned int fmt = cx2072x->dai_fmt; in cx2072x_config_i2spcm()
696 return -EINVAL; in cx2072x_config_i2spcm()
701 return -EINVAL; in cx2072x_config_i2spcm()
704 dev_dbg(dev, "config_i2spcm set_dai_fmt- %08x\n", fmt); in cx2072x_config_i2spcm()
721 return -EINVAL; in cx2072x_config_i2spcm()
744 return -EINVAL; in cx2072x_config_i2spcm()
771 return -EINVAL; in cx2072x_config_i2spcm()
784 reg1.r.rx_ws_wid = pulse_len - 1; in cx2072x_config_i2spcm()
786 reg1.r.rx_frm_len = frame_len / BITS_PER_SLOT - 1; in cx2072x_config_i2spcm()
787 reg1.r.rx_sa_size = (sample_size / BITS_PER_SLOT) - 1; in cx2072x_config_i2spcm()
790 reg1.r.tx_ws_wid = pulse_len - 1; in cx2072x_config_i2spcm()
796 if (cx2072x->en_aec_ref) in cx2072x_config_i2spcm()
808 if (cx2072x->en_aec_ref) in cx2072x_config_i2spcm()
818 return -EINVAL; in cx2072x_config_i2spcm()
823 bclk_rate = cx2072x->sample_rate * frame_len; in cx2072x_config_i2spcm()
827 regmap_write(cx2072x->regmap, CX2072X_I2SPCM_CONTROL5, 0); in cx2072x_config_i2spcm()
831 div = PLL_OUT_HZ_48; in cx2072x_config_i2spcm()
832 mod = do_div(div, bclk_rate); in cx2072x_config_i2spcm()
835 return -EINVAL; in cx2072x_config_i2spcm()
838 reg5.r.i2s_pcm_clk_div = (u32)div - 1; in cx2072x_config_i2spcm()
842 regmap_write(cx2072x->regmap, CX2072X_I2SPCM_CONTROL1, reg1.ulval); in cx2072x_config_i2spcm()
843 regmap_update_bits(cx2072x->regmap, CX2072X_I2SPCM_CONTROL2, 0xffffffc0, in cx2072x_config_i2spcm()
845 regmap_update_bits(cx2072x->regmap, CX2072X_I2SPCM_CONTROL3, 0xffffffc0, in cx2072x_config_i2spcm()
847 regmap_write(cx2072x->regmap, CX2072X_I2SPCM_CONTROL4, reg4.ulval); in cx2072x_config_i2spcm()
848 regmap_write(cx2072x->regmap, CX2072X_I2SPCM_CONTROL6, reg6.ulval); in cx2072x_config_i2spcm()
849 regmap_write(cx2072x->regmap, CX2072X_I2SPCM_CONTROL5, reg5.ulval); in cx2072x_config_i2spcm()
851 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_BIOS_TEST2, in cx2072x_config_i2spcm()
860 struct snd_soc_component *codec = snd_soc_dapm_to_component(w->dapm); in afg_power_ev()
865 regmap_update_bits(cx2072x->regmap, CX2072X_DIGITAL_BIOS_TEST0, in afg_power_ev()
870 regmap_update_bits(cx2072x->regmap, CX2072X_DIGITAL_BIOS_TEST0, in afg_power_ev()
906 struct snd_soc_component *codec = dai->component; in cx2072x_hw_params()
908 struct device *dev = codec->dev; in cx2072x_hw_params()
922 if (cx2072x->mclk_rate == 0) { in cx2072x_hw_params()
924 return -EINVAL; in cx2072x_hw_params()
927 if (cx2072x->bclk_ratio) in cx2072x_hw_params()
928 frame_size = cx2072x->bclk_ratio; in cx2072x_hw_params()
941 return -EINVAL; in cx2072x_hw_params()
947 cx2072x->frame_size = frame_size; in cx2072x_hw_params()
948 cx2072x->sample_size = sample_size; in cx2072x_hw_params()
949 cx2072x->sample_rate = sample_rate; in cx2072x_hw_params()
951 if (dai->id == CX2072X_DAI_DSP) { in cx2072x_hw_params()
952 cx2072x->en_aec_ref = true; in cx2072x_hw_params()
953 dev_dbg(cx2072x->dev, "enables aec reference\n"); in cx2072x_hw_params()
954 regmap_write(cx2072x->regmap, in cx2072x_hw_params()
958 if (cx2072x->pll_changed) { in cx2072x_hw_params()
960 cx2072x->pll_changed = false; in cx2072x_hw_params()
963 if (cx2072x->i2spcm_changed) { in cx2072x_hw_params()
965 cx2072x->i2spcm_changed = false; in cx2072x_hw_params()
974 struct snd_soc_component *codec = dai->component; in cx2072x_set_dai_bclk_ratio()
977 cx2072x->bclk_ratio = ratio; in cx2072x_set_dai_bclk_ratio()
984 struct snd_soc_component *codec = dai->component; in cx2072x_set_dai_sysclk()
987 if (clk_set_rate(cx2072x->mclk, freq)) { in cx2072x_set_dai_sysclk()
988 dev_err(codec->dev, "set clk rate failed\n"); in cx2072x_set_dai_sysclk()
989 return -EINVAL; in cx2072x_set_dai_sysclk()
992 cx2072x->mclk_rate = freq; in cx2072x_set_dai_sysclk()
998 struct snd_soc_component *codec = dai->component; in cx2072x_set_dai_fmt()
1000 struct device *dev = codec->dev; in cx2072x_set_dai_fmt()
1002 dev_dbg(dev, "set_dai_fmt- %08x\n", fmt); in cx2072x_set_dai_fmt()
1011 return -EINVAL; in cx2072x_set_dai_fmt()
1023 return -EINVAL; in cx2072x_set_dai_fmt()
1036 return -EINVAL; in cx2072x_set_dai_fmt()
1039 cx2072x->dai_fmt = fmt; in cx2072x_set_dai_fmt()
1348 regmap_write(cx2072x->regmap, CX2072X_AFG_POWER_STATE, 0); in cx2072x_set_bias_level()
1350 regmap_write(cx2072x->regmap, CX2072X_AFG_POWER_STATE, 3); in cx2072x_set_bias_level()
1356 * FIXME: the whole jack detection code below is pretty platform-specific;
1358 * However, since we have no other code and reference, take this hard-coded
1368 /* No-sticky input type */ in cx2072x_enable_jack_detect()
1369 regmap_write(cx2072x->regmap, CX2072X_GPIO_STICKY_MASK, 0x1f); in cx2072x_enable_jack_detect()
1372 regmap_write(cx2072x->regmap, CX2072X_UM_INTERRUPT_CRTL_E, 0x12 << 24); in cx2072x_enable_jack_detect()
1375 regmap_write(cx2072x->regmap, CX2072X_PORTA_UNSOLICITED_RESPONSE, 0x80); in cx2072x_enable_jack_detect()
1378 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST15, 0x73); in cx2072x_enable_jack_detect()
1381 regmap_write(cx2072x->regmap, CX2072X_ANALOG_TEST12, 0x300); in cx2072x_enable_jack_detect()
1384 regmap_write(cx2072x->regmap, CX2072X_DIGITAL_TEST1, 0); in cx2072x_enable_jack_detect()
1399 regmap_write(cx2072x->regmap, CX2072X_UM_INTERRUPT_CRTL_E, 0); in cx2072x_disable_jack_detect()
1400 regmap_write(cx2072x->regmap, CX2072X_PORTA_UNSOLICITED_RESPONSE, 0); in cx2072x_disable_jack_detect()
1411 mutex_lock(&cx2072x->lock); in cx2072x_jack_status_check()
1413 regmap_read(cx2072x->regmap, CX2072X_PORTA_PIN_SENSE, &jack); in cx2072x_jack_status_check()
1415 regmap_read(cx2072x->regmap, CX2072X_DIGITAL_TEST11, &type); in cx2072x_jack_status_check()
1435 regmap_write(cx2072x->regmap, CX2072X_UM_INTERRUPT_CRTL_E, 0x12 << 24); in cx2072x_jack_status_check()
1437 mutex_unlock(&cx2072x->lock); in cx2072x_jack_status_check()
1439 dev_dbg(codec->dev, "CX2072X_HSDETECT type=0x%X,Jack state = %x\n", in cx2072x_jack_status_check()
1463 if (!cx2072x->jack_gpio.gpiod_dev) { in cx2072x_set_jack()
1464 cx2072x->jack_gpio = cx2072x_jack_gpio; in cx2072x_set_jack()
1465 cx2072x->jack_gpio.gpiod_dev = codec->dev; in cx2072x_set_jack()
1466 cx2072x->jack_gpio.data = codec; in cx2072x_set_jack()
1467 err = snd_soc_jack_add_gpios(jack, 1, &cx2072x->jack_gpio); in cx2072x_set_jack()
1469 cx2072x->jack_gpio.gpiod_dev = NULL; in cx2072x_set_jack()
1482 cx2072x->codec = codec; in cx2072x_probe()
1485 * FIXME: below is, again, a very platform-specific init sequence, in cx2072x_probe()
1493 pm_runtime_get_sync(codec->dev); in cx2072x_probe()
1494 regmap_write(cx2072x->regmap, CX2072X_AFG_POWER_STATE, 0); in cx2072x_probe()
1496 regmap_multi_reg_write(cx2072x->regmap, cx2072x_reg_init, in cx2072x_probe()
1500 regmap_update_bits(cx2072x->regmap, CX2072X_PORTC_PIN_CTRL, in cx2072x_probe()
1503 regmap_update_bits(cx2072x->regmap, CX2072X_DIGITAL_BIOS_TEST2, in cx2072x_probe()
1506 regmap_write(cx2072x->regmap, CX2072X_AFG_POWER_STATE, 3); in cx2072x_probe()
1507 pm_runtime_put(codec->dev); in cx2072x_probe()
1538 snd_soc_component_get_drvdata(dai->component); in cx2072x_dsp_dai_probe()
1540 cx2072x->en_aec_ref = true; in cx2072x_dsp_dai_probe()
1556 .name = "cx2072x-hifi",
1576 .name = "cx2072x-dsp",
1588 .name = "cx2072x-aec",
1618 clk_disable_unprepare(cx2072x->mclk); in cx2072x_runtime_suspend()
1626 return clk_prepare_enable(cx2072x->mclk); in cx2072x_runtime_resume()
1635 cx2072x = devm_kzalloc(&i2c->dev, sizeof(struct cx2072x_priv), in cx2072x_i2c_probe()
1638 return -ENOMEM; in cx2072x_i2c_probe()
1640 cx2072x->regmap = devm_regmap_init(&i2c->dev, NULL, i2c, in cx2072x_i2c_probe()
1642 if (IS_ERR(cx2072x->regmap)) in cx2072x_i2c_probe()
1643 return PTR_ERR(cx2072x->regmap); in cx2072x_i2c_probe()
1645 mutex_init(&cx2072x->lock); in cx2072x_i2c_probe()
1649 cx2072x->dev = &i2c->dev; in cx2072x_i2c_probe()
1650 cx2072x->pll_changed = true; in cx2072x_i2c_probe()
1651 cx2072x->i2spcm_changed = true; in cx2072x_i2c_probe()
1652 cx2072x->bclk_ratio = 0; in cx2072x_i2c_probe()
1654 cx2072x->mclk = devm_clk_get(cx2072x->dev, "mclk"); in cx2072x_i2c_probe()
1655 if (IS_ERR(cx2072x->mclk)) { in cx2072x_i2c_probe()
1656 dev_err(cx2072x->dev, "Failed to get MCLK\n"); in cx2072x_i2c_probe()
1657 return PTR_ERR(cx2072x->mclk); in cx2072x_i2c_probe()
1660 regmap_read(cx2072x->regmap, CX2072X_VENDOR_ID, &ven_id); in cx2072x_i2c_probe()
1661 regmap_read(cx2072x->regmap, CX2072X_REVISION_ID, &rev_id); in cx2072x_i2c_probe()
1663 dev_info(cx2072x->dev, "codec version: %08x,%08x\n", ven_id, rev_id); in cx2072x_i2c_probe()
1665 ret = devm_snd_soc_register_component(cx2072x->dev, in cx2072x_i2c_probe()
1672 pm_runtime_use_autosuspend(cx2072x->dev); in cx2072x_i2c_probe()
1673 pm_runtime_enable(cx2072x->dev); in cx2072x_i2c_probe()
1680 pm_runtime_disable(&i2c->dev); in cx2072x_i2c_remove()