Lines Matching full:cs35l45

3 // cs35l45.c - CS35L45 ALSA SoC audio driver
21 #include "cs35l45.h"
46 static int cs35l45_set_cspl_mbox_cmd(struct cs35l45_private *cs35l45, in cs35l45_set_cspl_mbox_cmd() argument
53 if (!cs35l45->dsp.cs_dsp.running) { in cs35l45_set_cspl_mbox_cmd()
54 dev_err(cs35l45->dev, "DSP not running\n"); in cs35l45_set_cspl_mbox_cmd()
62 dev_err(cs35l45->dev, "Failed to write MBOX: %d\n", ret); in cs35l45_set_cspl_mbox_cmd()
72 dev_err(cs35l45->dev, "Failed to read MBOX STS: %d\n", ret); in cs35l45_set_cspl_mbox_cmd()
77 dev_dbg(cs35l45->dev, "[%u] cmd %u returned invalid sts %u", i, cmd, sts); in cs35l45_set_cspl_mbox_cmd()
83 dev_err(cs35l45->dev, "Failed to set mailbox cmd %u (status %u)\n", cmd, sts); in cs35l45_set_cspl_mbox_cmd()
92 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(component); in cs35l45_global_en_ev() local
94 dev_dbg(cs35l45->dev, "%s event : %x\n", __func__, event); in cs35l45_global_en_ev()
98 regmap_write(cs35l45->regmap, CS35L45_GLOBAL_ENABLES, in cs35l45_global_en_ev()
106 regmap_write(cs35l45->regmap, CS35L45_GLOBAL_ENABLES, 0); in cs35l45_global_en_ev()
119 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(component); in cs35l45_dsp_preload_ev() local
124 if (cs35l45->dsp.cs_dsp.booted) in cs35l45_dsp_preload_ev()
129 if (cs35l45->dsp.cs_dsp.running) in cs35l45_dsp_preload_ev()
132 regmap_set_bits(cs35l45->regmap, CS35L45_PWRMGT_CTL, in cs35l45_dsp_preload_ev()
137 if (cs35l45->dsp.preloaded) in cs35l45_dsp_preload_ev()
140 if (cs35l45->dsp.cs_dsp.running) { in cs35l45_dsp_preload_ev()
156 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(component); in cs35l45_dsp_audio_ev() local
160 return cs35l45_set_cspl_mbox_cmd(cs35l45, cs35l45->regmap, in cs35l45_dsp_audio_ev()
163 return cs35l45_set_cspl_mbox_cmd(cs35l45, cs35l45->regmap, in cs35l45_dsp_audio_ev()
449 static int cs35l45_set_pll(struct cs35l45_private *cs35l45, unsigned int freq) in cs35l45_set_pll() argument
456 dev_err(cs35l45->dev, "Invalid freq: %u\n", freq); in cs35l45_set_pll()
460 regmap_read(cs35l45->regmap, CS35L45_REFCLK_INPUT, &val); in cs35l45_set_pll()
465 regmap_set_bits(cs35l45->regmap, CS35L45_REFCLK_INPUT, CS35L45_PLL_OPEN_LOOP_MASK); in cs35l45_set_pll()
466 regmap_update_bits(cs35l45->regmap, CS35L45_REFCLK_INPUT, in cs35l45_set_pll()
469 regmap_clear_bits(cs35l45->regmap, CS35L45_REFCLK_INPUT, CS35L45_PLL_REFCLK_EN_MASK); in cs35l45_set_pll()
470 regmap_clear_bits(cs35l45->regmap, CS35L45_REFCLK_INPUT, CS35L45_PLL_OPEN_LOOP_MASK); in cs35l45_set_pll()
471 regmap_set_bits(cs35l45->regmap, CS35L45_REFCLK_INPUT, CS35L45_PLL_REFCLK_EN_MASK); in cs35l45_set_pll()
478 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(codec_dai->component); in cs35l45_asp_set_fmt() local
485 dev_err(cs35l45->dev, "Invalid DAI clocking\n"); in cs35l45_asp_set_fmt()
497 dev_err(cs35l45->dev, "Invalid DAI format\n"); in cs35l45_asp_set_fmt()
519 dev_warn(cs35l45->dev, "Invalid DAI clock polarity\n"); in cs35l45_asp_set_fmt()
523 regmap_update_bits(cs35l45->regmap, CS35L45_ASP_CONTROL2, in cs35l45_asp_set_fmt()
538 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(dai->component); in cs35l45_asp_hw_params() local
556 dev_warn(cs35l45->dev, "Unsupported sample rate (%d)\n", in cs35l45_asp_hw_params()
561 regmap_update_bits(cs35l45->regmap, CS35L45_GLOBAL_SAMPLE_RATE, in cs35l45_asp_hw_params()
567 if (cs35l45->slot_width) in cs35l45_asp_hw_params()
568 asp_width = cs35l45->slot_width; in cs35l45_asp_hw_params()
573 regmap_update_bits(cs35l45->regmap, CS35L45_ASP_CONTROL2, in cs35l45_asp_hw_params()
577 regmap_update_bits(cs35l45->regmap, CS35L45_ASP_DATA_CONTROL5, in cs35l45_asp_hw_params()
581 regmap_update_bits(cs35l45->regmap, CS35L45_ASP_CONTROL2, in cs35l45_asp_hw_params()
585 regmap_update_bits(cs35l45->regmap, CS35L45_ASP_DATA_CONTROL1, in cs35l45_asp_hw_params()
590 if (cs35l45->sysclk_set) in cs35l45_asp_hw_params()
594 regmap_read(cs35l45->regmap, CS35L45_ASP_CONTROL2, &asp_fmt); in cs35l45_asp_hw_params()
602 cs35l45->slot_count, slot_multiple); in cs35l45_asp_hw_params()
604 return cs35l45_set_pll(cs35l45, bclk); in cs35l45_asp_hw_params()
611 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(dai->component); in cs35l45_asp_set_tdm_slot() local
616 cs35l45->slot_width = slot_width; in cs35l45_asp_set_tdm_slot()
617 cs35l45->slot_count = slots; in cs35l45_asp_set_tdm_slot()
625 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(dai->component); in cs35l45_asp_set_sysclk() local
629 dev_err(cs35l45->dev, "Invalid clk_id %d\n", clk_id); in cs35l45_asp_set_sysclk()
633 cs35l45->sysclk_set = false; in cs35l45_asp_set_sysclk()
637 ret = cs35l45_set_pll(cs35l45, freq); in cs35l45_asp_set_sysclk()
641 cs35l45->sysclk_set = true; in cs35l45_asp_set_sysclk()
648 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(dai->component); in cs35l45_mute_stream() local
654 regmap_read(cs35l45->regmap, CS35L45_GLOBAL_SAMPLE_RATE, &global_fs); in cs35l45_mute_stream()
668 regmap_read(cs35l45->regmap, CS35L45_AMP_PCM_HPF_TST, &val); in cs35l45_mute_stream()
679 regmap_multi_reg_write(cs35l45->regmap, hpf_override_seq, in cs35l45_mute_stream()
696 .name = "cs35l45",
719 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(component); in cs35l45_component_probe() local
721 return wm_adsp2_component_probe(&cs35l45->dsp, component); in cs35l45_component_probe()
726 struct cs35l45_private *cs35l45 = snd_soc_component_get_drvdata(component); in cs35l45_component_remove() local
728 wm_adsp2_component_remove(&cs35l45->dsp, component); in cs35l45_component_remove()
744 .name = "cs35l45",
749 static void cs35l45_setup_hibernate(struct cs35l45_private *cs35l45) in cs35l45_setup_hibernate() argument
753 if (cs35l45->bus_type == CONTROL_BUS_I2C) in cs35l45_setup_hibernate()
758 regmap_update_bits(cs35l45->regmap, CS35L45_WAKESRC_CTL, in cs35l45_setup_hibernate()
762 regmap_set_bits(cs35l45->regmap, CS35L45_WAKESRC_CTL, in cs35l45_setup_hibernate()
765 regmap_update_bits(cs35l45->regmap, CS35L45_WKI2C_CTL, in cs35l45_setup_hibernate()
766 CS35L45_WKI2C_ADDR_MASK, cs35l45->i2c_addr); in cs35l45_setup_hibernate()
768 regmap_set_bits(cs35l45->regmap, CS35L45_WKI2C_CTL, in cs35l45_setup_hibernate()
772 static int cs35l45_enter_hibernate(struct cs35l45_private *cs35l45) in cs35l45_enter_hibernate() argument
774 dev_dbg(cs35l45->dev, "Enter hibernate\n"); in cs35l45_enter_hibernate()
776 cs35l45_setup_hibernate(cs35l45); in cs35l45_enter_hibernate()
778 regmap_set_bits(cs35l45->regmap, CS35L45_IRQ1_MASK_2, CS35L45_DSP_VIRT2_MBOX_MASK); in cs35l45_enter_hibernate()
781 regmap_write(cs35l45->regmap, CS35L45_DSP_VIRT1_MBOX_1, CSPL_MBOX_CMD_HIBERNATE); in cs35l45_enter_hibernate()
786 static int cs35l45_exit_hibernate(struct cs35l45_private *cs35l45) in cs35l45_exit_hibernate() argument
793 dev_dbg(cs35l45->dev, "Exit hibernate\n"); in cs35l45_exit_hibernate()
796 ret = cs35l45_set_cspl_mbox_cmd(cs35l45, cs35l45->regmap, in cs35l45_exit_hibernate()
799 dev_dbg(cs35l45->dev, "Wake success at cycle: %d\n", j); in cs35l45_exit_hibernate()
800 regmap_clear_bits(cs35l45->regmap, CS35L45_IRQ1_MASK_2, in cs35l45_exit_hibernate()
807 dev_err(cs35l45->dev, "Wake failed, re-enter hibernate: %d\n", ret); in cs35l45_exit_hibernate()
809 cs35l45_setup_hibernate(cs35l45); in cs35l45_exit_hibernate()
812 dev_err(cs35l45->dev, "Timed out waking device\n"); in cs35l45_exit_hibernate()
819 struct cs35l45_private *cs35l45 = dev_get_drvdata(dev); in cs35l45_runtime_suspend() local
821 if (!cs35l45->dsp.preloaded || !cs35l45->dsp.cs_dsp.running) in cs35l45_runtime_suspend()
824 cs35l45_enter_hibernate(cs35l45); in cs35l45_runtime_suspend()
826 regcache_cache_only(cs35l45->regmap, true); in cs35l45_runtime_suspend()
827 regcache_mark_dirty(cs35l45->regmap); in cs35l45_runtime_suspend()
829 dev_dbg(cs35l45->dev, "Runtime suspended\n"); in cs35l45_runtime_suspend()
836 struct cs35l45_private *cs35l45 = dev_get_drvdata(dev); in cs35l45_runtime_resume() local
839 if (!cs35l45->dsp.preloaded || !cs35l45->dsp.cs_dsp.running) in cs35l45_runtime_resume()
842 dev_dbg(cs35l45->dev, "Runtime resume\n"); in cs35l45_runtime_resume()
844 regcache_cache_only(cs35l45->regmap, false); in cs35l45_runtime_resume()
846 ret = cs35l45_exit_hibernate(cs35l45); in cs35l45_runtime_resume()
850 ret = regcache_sync(cs35l45->regmap); in cs35l45_runtime_resume()
852 dev_warn(cs35l45->dev, "regcache_sync failed: %d\n", ret); in cs35l45_runtime_resume()
855 regmap_clear_bits(cs35l45->regmap, CS35L45_ERROR_RELEASE, CS35L45_GLOBAL_ERR_RLS_MASK); in cs35l45_runtime_resume()
856 regmap_set_bits(cs35l45->regmap, CS35L45_ERROR_RELEASE, CS35L45_GLOBAL_ERR_RLS_MASK); in cs35l45_runtime_resume()
857 regmap_clear_bits(cs35l45->regmap, CS35L45_ERROR_RELEASE, CS35L45_GLOBAL_ERR_RLS_MASK); in cs35l45_runtime_resume()
863 struct cs35l45_private *cs35l45 = dev_get_drvdata(dev); in cs35l45_sys_suspend() local
865 dev_dbg(cs35l45->dev, "System suspend, disabling IRQ\n"); in cs35l45_sys_suspend()
866 disable_irq(cs35l45->irq); in cs35l45_sys_suspend()
873 struct cs35l45_private *cs35l45 = dev_get_drvdata(dev); in cs35l45_sys_suspend_noirq() local
875 dev_dbg(cs35l45->dev, "Late system suspend, reenabling IRQ\n"); in cs35l45_sys_suspend_noirq()
876 enable_irq(cs35l45->irq); in cs35l45_sys_suspend_noirq()
883 struct cs35l45_private *cs35l45 = dev_get_drvdata(dev); in cs35l45_sys_resume_noirq() local
885 dev_dbg(cs35l45->dev, "Early system resume, disabling IRQ\n"); in cs35l45_sys_resume_noirq()
886 disable_irq(cs35l45->irq); in cs35l45_sys_resume_noirq()
893 struct cs35l45_private *cs35l45 = dev_get_drvdata(dev); in cs35l45_sys_resume() local
895 dev_dbg(cs35l45->dev, "System resume, reenabling IRQ\n"); in cs35l45_sys_resume()
896 enable_irq(cs35l45->irq); in cs35l45_sys_resume()
901 static int cs35l45_apply_property_config(struct cs35l45_private *cs35l45) in cs35l45_apply_property_config() argument
903 struct device_node *node = cs35l45->dev->of_node; in cs35l45_apply_property_config()
924 regmap_update_bits(cs35l45->regmap, gpio_regs[i], in cs35l45_apply_property_config()
930 regmap_update_bits(cs35l45->regmap, gpio_regs[i], in cs35l45_apply_property_config()
936 regmap_update_bits(cs35l45->regmap, gpio_regs[i], in cs35l45_apply_property_config()
942 regmap_update_bits(cs35l45->regmap, gpio_regs[i], in cs35l45_apply_property_config()
948 regmap_update_bits(cs35l45->regmap, pad_regs[i], in cs35l45_apply_property_config()
954 regmap_update_bits(cs35l45->regmap, pad_regs[i], in cs35l45_apply_property_config()
958 cs35l45->irq_invert = val; in cs35l45_apply_property_config()
964 if (device_property_read_u32(cs35l45->dev, in cs35l45_apply_property_config()
966 regmap_update_bits(cs35l45->regmap, CS35L45_ASP_CONTROL3, in cs35l45_apply_property_config()
974 static int cs35l45_dsp_virt2_mbox3_irq_handle(struct cs35l45_private *cs35l45, in cs35l45_dsp_virt2_mbox3_irq_handle() argument
994 dev_info(cs35l45->dev, "MBOX event (SPEAKER_STATUS): %s\n", in cs35l45_dsp_virt2_mbox3_irq_handle()
998 dev_dbg(cs35l45->dev, "MBOX event (BOOT_DONE)\n"); in cs35l45_dsp_virt2_mbox3_irq_handle()
1001 dev_err(cs35l45->dev, "MBOX event not supported %u\n", cmd); in cs35l45_dsp_virt2_mbox3_irq_handle()
1010 struct cs35l45_private *cs35l45 = data; in cs35l45_dsp_virt2_mbox_cb() local
1014 ret = regmap_read(cs35l45->regmap, CS35L45_DSP_VIRT2_MBOX_3, &mbox_val); in cs35l45_dsp_virt2_mbox_cb()
1016 cs35l45_dsp_virt2_mbox3_irq_handle(cs35l45, mbox_val & CS35L45_MBOX3_CMD_MASK, in cs35l45_dsp_virt2_mbox_cb()
1020 ret = regmap_read(cs35l45->regmap, CS35L45_DSP_VIRT2_MBOX_4, &mbox_val); in cs35l45_dsp_virt2_mbox_cb()
1022 dev_err(cs35l45->dev, "Spurious DSP MBOX4 IRQ\n"); in cs35l45_dsp_virt2_mbox_cb()
1030 struct cs35l45_private *cs35l45 = data; in cs35l45_pll_unlock() local
1032 dev_dbg(cs35l45->dev, "PLL unlock detected!"); in cs35l45_pll_unlock()
1039 struct cs35l45_private *cs35l45 = data; in cs35l45_pll_lock() local
1041 dev_dbg(cs35l45->dev, "PLL lock detected!"); in cs35l45_pll_lock()
1065 struct cs35l45_private *cs35l45 = data; in cs35l45_spk_safe_err() local
1068 i = irq - regmap_irq_get_virq(cs35l45->irq_data, 0); in cs35l45_spk_safe_err()
1071 dev_err(cs35l45->dev, "Unspecified global error condition (%d) detected!\n", irq); in cs35l45_spk_safe_err()
1073 dev_err(cs35l45->dev, "%s condition detected!\n", cs35l45_irqs[i].name); in cs35l45_spk_safe_err()
1094 .name = "cs35l45 IRQ1 Controller",
1105 static int cs35l45_initialize(struct cs35l45_private *cs35l45) in cs35l45_initialize() argument
1107 struct device *dev = cs35l45->dev; in cs35l45_initialize()
1112 ret = regmap_read_poll_timeout(cs35l45->regmap, CS35L45_IRQ1_EINT_4, sts, in cs35l45_initialize()
1116 dev_err(cs35l45->dev, "Timeout waiting for OTP boot\n"); in cs35l45_initialize()
1120 ret = regmap_bulk_read(cs35l45->regmap, CS35L45_DEVID, dev_id, ARRAY_SIZE(dev_id)); in cs35l45_initialize()
1122 dev_err(cs35l45->dev, "Get Device ID failed: %d\n", ret); in cs35l45_initialize()
1131 dev_err(cs35l45->dev, "Bad DEVID 0x%x\n", dev_id[0]); in cs35l45_initialize()
1135 dev_info(cs35l45->dev, "Cirrus Logic CS35L45: REVID %02X OTPID %02X\n", in cs35l45_initialize()
1138 regmap_write(cs35l45->regmap, CS35L45_IRQ1_EINT_4, in cs35l45_initialize()
1141 ret = cs35l45_apply_patch(cs35l45); in cs35l45_initialize()
1147 ret = cs35l45_apply_property_config(cs35l45); in cs35l45_initialize()
1181 static int cs35l45_dsp_init(struct cs35l45_private *cs35l45) in cs35l45_dsp_init() argument
1183 struct wm_adsp *dsp = &cs35l45->dsp; in cs35l45_dsp_init()
1186 dsp->part = "cs35l45"; in cs35l45_dsp_init()
1192 dsp->cs_dsp.dev = cs35l45->dev; in cs35l45_dsp_init()
1193 dsp->cs_dsp.regmap = cs35l45->regmap; in cs35l45_dsp_init()
1202 regmap_multi_reg_write(cs35l45->regmap, cs35l45_fs_errata_patch, in cs35l45_dsp_init()
1208 int cs35l45_probe(struct cs35l45_private *cs35l45) in cs35l45_probe() argument
1210 struct device *dev = cs35l45->dev; in cs35l45_probe()
1214 cs35l45->vdd_batt = devm_regulator_get(dev, "vdd-batt"); in cs35l45_probe()
1215 if (IS_ERR(cs35l45->vdd_batt)) in cs35l45_probe()
1216 return dev_err_probe(dev, PTR_ERR(cs35l45->vdd_batt), in cs35l45_probe()
1219 cs35l45->vdd_a = devm_regulator_get(dev, "vdd-a"); in cs35l45_probe()
1220 if (IS_ERR(cs35l45->vdd_a)) in cs35l45_probe()
1221 return dev_err_probe(dev, PTR_ERR(cs35l45->vdd_a), in cs35l45_probe()
1225 ret = regulator_enable(cs35l45->vdd_batt); in cs35l45_probe()
1229 ret = regulator_enable(cs35l45->vdd_a); in cs35l45_probe()
1234 cs35l45->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in cs35l45_probe()
1235 if (IS_ERR(cs35l45->reset_gpio)) { in cs35l45_probe()
1236 ret = PTR_ERR(cs35l45->reset_gpio); in cs35l45_probe()
1237 cs35l45->reset_gpio = NULL; in cs35l45_probe()
1246 if (cs35l45->reset_gpio) { in cs35l45_probe()
1248 gpiod_set_value_cansleep(cs35l45->reset_gpio, 1); in cs35l45_probe()
1253 ret = cs35l45_initialize(cs35l45); in cs35l45_probe()
1257 ret = cs35l45_dsp_init(cs35l45); in cs35l45_probe()
1261 pm_runtime_set_autosuspend_delay(cs35l45->dev, 3000); in cs35l45_probe()
1262 pm_runtime_use_autosuspend(cs35l45->dev); in cs35l45_probe()
1263 pm_runtime_mark_last_busy(cs35l45->dev); in cs35l45_probe()
1264 pm_runtime_set_active(cs35l45->dev); in cs35l45_probe()
1265 pm_runtime_get_noresume(cs35l45->dev); in cs35l45_probe()
1266 pm_runtime_enable(cs35l45->dev); in cs35l45_probe()
1268 if (cs35l45->irq) { in cs35l45_probe()
1269 if (cs35l45->irq_invert) in cs35l45_probe()
1274 ret = devm_regmap_add_irq_chip(dev, cs35l45->regmap, cs35l45->irq, irq_pol, 0, in cs35l45_probe()
1275 &cs35l45_regmap_irq_chip, &cs35l45->irq_data); in cs35l45_probe()
1282 irq = regmap_irq_get_virq(cs35l45->irq_data, cs35l45_irqs[i].irq); in cs35l45_probe()
1290 irq_pol, cs35l45_irqs[i].name, cs35l45); in cs35l45_probe()
1305 pm_runtime_put_autosuspend(cs35l45->dev); in cs35l45_probe()
1310 pm_runtime_disable(cs35l45->dev); in cs35l45_probe()
1311 pm_runtime_put_noidle(cs35l45->dev); in cs35l45_probe()
1312 wm_adsp2_remove(&cs35l45->dsp); in cs35l45_probe()
1315 gpiod_set_value_cansleep(cs35l45->reset_gpio, 0); in cs35l45_probe()
1317 regulator_disable(cs35l45->vdd_a); in cs35l45_probe()
1318 regulator_disable(cs35l45->vdd_batt); in cs35l45_probe()
1324 void cs35l45_remove(struct cs35l45_private *cs35l45) in cs35l45_remove() argument
1326 pm_runtime_get_sync(cs35l45->dev); in cs35l45_remove()
1327 pm_runtime_disable(cs35l45->dev); in cs35l45_remove()
1328 wm_adsp2_remove(&cs35l45->dsp); in cs35l45_remove()
1330 gpiod_set_value_cansleep(cs35l45->reset_gpio, 0); in cs35l45_remove()
1332 pm_runtime_put_noidle(cs35l45->dev); in cs35l45_remove()
1333 regulator_disable(cs35l45->vdd_a); in cs35l45_remove()
1335 regulator_disable(cs35l45->vdd_batt); in cs35l45_remove()
1346 MODULE_DESCRIPTION("ASoC CS35L45 driver");