Lines Matching full:nau8325
3 // nau8325.c -- Nuvoton NAU8325 audio codec driver
23 #include "nau8325.h"
220 struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); in nau8325_dac_event() local
224 regmap_update_bits(nau8325->regmap, NAU8325_R12_MUTE_CTRL, in nau8325_dac_event()
230 regmap_update_bits(nau8325->regmap, NAU8325_R12_MUTE_CTRL, in nau8325_dac_event()
246 struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); in nau8325_powerup_event() local
248 if (nau8325->clock_detection) in nau8325_powerup_event()
253 regmap_update_bits(nau8325->regmap, NAU8325_R40_CLK_DET_CTRL, in nau8325_powerup_event()
257 regmap_update_bits(nau8325->regmap, NAU8325_R40_CLK_DET_CTRL, in nau8325_powerup_event()
293 static int nau8325_srate_clk_apply(struct nau8325 *nau8325, in nau8325_srate_clk_apply() argument
299 dev_dbg(nau8325->dev, "The CLK isn't supported."); in nau8325_srate_clk_apply()
303 regmap_update_bits(nau8325->regmap, NAU8325_R40_CLK_DET_CTRL, in nau8325_srate_clk_apply()
307 regmap_update_bits(nau8325->regmap, NAU8325_R03_CLK_CTRL, in nau8325_srate_clk_apply()
309 regmap_update_bits(nau8325->regmap, NAU8325_R03_CLK_CTRL, in nau8325_srate_clk_apply()
314 regmap_update_bits(nau8325->regmap, NAU8325_R03_CLK_CTRL, in nau8325_srate_clk_apply()
319 regmap_update_bits(nau8325->regmap, NAU8325_R03_CLK_CTRL, in nau8325_srate_clk_apply()
325 regmap_update_bits(nau8325->regmap, NAU8325_R65_ANALOG_CONTROL_5, in nau8325_srate_clk_apply()
329 regmap_update_bits(nau8325->regmap, NAU8325_R65_ANALOG_CONTROL_5, in nau8325_srate_clk_apply()
334 regmap_update_bits(nau8325->regmap, NAU8325_R65_ANALOG_CONTROL_5, in nau8325_srate_clk_apply()
342 static int nau8325_clksrc_n2(struct nau8325 *nau8325, in nau8325_clksrc_n2() argument
385 static int nau8325_clksrc_choose(struct nau8325 *nau8325, in nau8325_clksrc_choose() argument
391 if (!nau8325->mclk || !nau8325->fs) in nau8325_clksrc_choose()
395 *srate_table = target_srate_attribute(nau8325->fs); in nau8325_clksrc_choose()
402 ratio = nau8325_clksrc_n2(nau8325, *srate_table, nau8325->mclk, n2_sel); in nau8325_clksrc_choose()
414 mclk = nau8325->mclk << mclk_n3_mult[j].param; in nau8325_clksrc_choose()
416 ratio = nau8325_clksrc_n2(nau8325, in nau8325_clksrc_choose()
436 dev_dbg(nau8325->dev, "The MCLK %d is invalid. It can't get MCLK_SRC of 256/400/500 FS (%d)", in nau8325_clksrc_choose()
437 nau8325->mclk, nau8325->fs); in nau8325_clksrc_choose()
440 …dev_dbg(nau8325->dev, "nau8325->fs=%d,range=0x%x, %s, (n1,mu,n2,dmu):(%d,%d,%d), MCLK_SRC=%uHz (%d… in nau8325_clksrc_choose()
441 nau8325->fs, (*srate_table)->range, in nau8325_clksrc_choose()
449 (*srate_table)->mclk_src[ratio] / nau8325->fs); in nau8325_clksrc_choose()
454 static int nau8325_clock_config(struct nau8325 *nau8325) in nau8325_clock_config() argument
459 ret = nau8325_clksrc_choose(nau8325, &srate_table, in nau8325_clock_config()
464 ret = nau8325_srate_clk_apply(nau8325, srate_table, in nau8325_clock_config()
474 static const struct nau8325_osr_attr *nau8325_get_osr(struct nau8325 *nau8325) in nau8325_get_osr() argument
478 regmap_read(nau8325->regmap, NAU8325_R29_DAC_CTRL1, &osr); in nau8325_get_osr()
490 struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); in nau8325_dai_startup() local
493 osr = nau8325_get_osr(nau8325); in nau8325_dai_startup()
507 struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); in nau8325_hw_params() local
512 nau8325->fs = params_rate(params); in nau8325_hw_params()
513 osr = nau8325_get_osr(nau8325); in nau8325_hw_params()
514 if (!osr || !osr->osr || nau8325->fs * osr->osr > CLK_DA_AD_MAX) { in nau8325_hw_params()
518 regmap_update_bits(nau8325->regmap, NAU8325_R03_CLK_CTRL, in nau8325_hw_params()
522 ret = nau8325_clock_config(nau8325); in nau8325_hw_params()
544 regmap_update_bits(nau8325->regmap, NAU8325_R0D_I2S_PCM_CTRL1, in nau8325_hw_params()
556 struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); in nau8325_set_fmt() local
597 regmap_update_bits(nau8325->regmap, NAU8325_R0D_I2S_PCM_CTRL1, in nau8325_set_fmt()
607 struct nau8325 *nau8325 = snd_soc_component_get_drvdata(component); in nau8325_set_sysclk() local
610 dev_dbg(nau8325->dev, "MCLK exceeds the range, MCLK:%d", freq); in nau8325_set_sysclk()
614 nau8325->mclk = freq; in nau8325_set_sysclk()
615 dev_dbg(nau8325->dev, "MCLK %dHz", nau8325->mclk); in nau8325_set_sysclk()
673 static void nau8325_init_regs(struct nau8325 *nau8325) in nau8325_init_regs() argument
675 struct regmap *regmap = nau8325->regmap; in nau8325_init_regs()
676 struct device *dev = nau8325->dev; in nau8325_init_regs()
688 if (nau8325->alc_enable) in nau8325_init_regs()
691 if (nau8325->clock_detection) in nau8325_init_regs()
699 if (nau8325->clock_det_data) in nau8325_init_regs()
707 switch (nau8325->dac_vref_microvolt) { in nau8325_init_regs()
725 dev_dbg(dev, "Invalid dac-vref-microvolt %d", nau8325->dac_vref_microvolt); in nau8325_init_regs()
737 switch (nau8325->vref_impedance_ohms) { in nau8325_init_regs()
755 dev_dbg(dev, "Invalid vref-impedance-ohms %d", nau8325->vref_impedance_ohms); in nau8325_init_regs()
775 if (nau8325->alc_enable) in nau8325_init_regs()
778 if (nau8325->clock_det_data) in nau8325_init_regs()
784 if (nau8325->clock_detection) in nau8325_init_regs()
797 static void nau8325_print_device_properties(struct nau8325 *nau8325) in nau8325_print_device_properties() argument
799 struct device *dev = nau8325->dev; in nau8325_print_device_properties()
801 dev_dbg(dev, "vref-impedance-ohms: %d", nau8325->vref_impedance_ohms); in nau8325_print_device_properties()
802 dev_dbg(dev, "dac-vref-microvolt: %d", nau8325->dac_vref_microvolt); in nau8325_print_device_properties()
803 dev_dbg(dev, "alc-enable: %d", nau8325->alc_enable); in nau8325_print_device_properties()
804 dev_dbg(dev, "clock-det-data: %d", nau8325->clock_det_data); in nau8325_print_device_properties()
805 dev_dbg(dev, "clock-detection-disable: %d", nau8325->clock_detection); in nau8325_print_device_properties()
809 struct nau8325 *nau8325) in nau8325_read_device_properties() argument
813 nau8325->alc_enable = in nau8325_read_device_properties()
815 nau8325->clock_det_data = in nau8325_read_device_properties()
817 nau8325->clock_detection = in nau8325_read_device_properties()
821 &nau8325->vref_impedance_ohms); in nau8325_read_device_properties()
823 nau8325->vref_impedance_ohms = 125000; in nau8325_read_device_properties()
825 &nau8325->dac_vref_microvolt); in nau8325_read_device_properties()
827 nau8325->dac_vref_microvolt = 2880000; in nau8325_read_device_properties()
836 struct nau8325 *nau8325 = dev_get_platdata(dev); in nau8325_i2c_probe() local
839 if (!nau8325) { in nau8325_i2c_probe()
840 nau8325 = devm_kzalloc(dev, sizeof(*nau8325), GFP_KERNEL); in nau8325_i2c_probe()
841 if (!nau8325) { in nau8325_i2c_probe()
845 ret = nau8325_read_device_properties(dev, nau8325); in nau8325_i2c_probe()
849 i2c_set_clientdata(i2c, nau8325); in nau8325_i2c_probe()
851 nau8325->regmap = devm_regmap_init_i2c(i2c, &nau8325_regmap_config); in nau8325_i2c_probe()
852 if (IS_ERR(nau8325->regmap)) { in nau8325_i2c_probe()
853 ret = PTR_ERR(nau8325->regmap); in nau8325_i2c_probe()
856 nau8325->dev = dev; in nau8325_i2c_probe()
857 nau8325_print_device_properties(nau8325); in nau8325_i2c_probe()
859 nau8325_reset_chip(nau8325->regmap); in nau8325_i2c_probe()
860 ret = regmap_read(nau8325->regmap, NAU8325_R02_DEVICE_ID, &value); in nau8325_i2c_probe()
865 nau8325_init_regs(nau8325); in nau8325_i2c_probe()
874 { "nau8325" },
881 { .compatible = "nuvoton,nau8325", },
889 .name = "nau8325",
897 MODULE_DESCRIPTION("ASoC NAU8325 driver");