Lines Matching +full:tx1 +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0
3 // cs35l41.c -- CS35l41 ALSA SoC audio driver
5 // Copyright 2017-2021 Cirrus Logic, Inc.
22 #include <sound/soc-dapm.h>
38 { 32768, 0x00 },
39 { 8000, 0x01 },
40 { 11025, 0x02 },
41 { 12000, 0x03 },
42 { 16000, 0x04 },
43 { 22050, 0x05 },
44 { 24000, 0x06 },
45 { 32000, 0x07 },
46 { 44100, 0x08 },
47 { 48000, 0x09 },
48 { 88200, 0x0A },
49 { 96000, 0x0B },
50 { 128000, 0x0C },
51 { 176400, 0x0D },
52 { 192000, 0x0E },
53 { 256000, 0x0F },
54 { 352800, 0x10 },
55 { 384000, 0x11 },
56 { 512000, 0x12 },
57 { 705600, 0x13 },
58 { 750000, 0x14 },
59 { 768000, 0x15 },
60 { 1000000, 0x16 },
61 { 1024000, 0x17 },
62 { 1200000, 0x18 },
63 { 1411200, 0x19 },
64 { 1500000, 0x1A },
65 { 1536000, 0x1B },
66 { 2000000, 0x1C },
67 { 2048000, 0x1D },
68 { 2400000, 0x1E },
69 { 2822400, 0x1F },
70 { 3000000, 0x20 },
71 { 3072000, 0x21 },
72 { 3200000, 0x22 },
73 { 4000000, 0x23 },
74 { 4096000, 0x24 },
75 { 4800000, 0x25 },
76 { 5644800, 0x26 },
77 { 6000000, 0x27 },
78 { 6144000, 0x28 },
79 { 6250000, 0x29 },
80 { 6400000, 0x2A },
81 { 6500000, 0x2B },
82 { 6750000, 0x2C },
83 { 7526400, 0x2D },
84 { 8000000, 0x2E },
85 { 8192000, 0x2F },
86 { 9600000, 0x30 },
87 { 11289600, 0x31 },
88 { 12000000, 0x32 },
89 { 12288000, 0x33 },
90 { 12500000, 0x34 },
91 { 12800000, 0x35 },
92 { 13000000, 0x36 },
93 { 13500000, 0x37 },
94 { 19200000, 0x38 },
95 { 22579200, 0x39 },
96 { 24000000, 0x3A },
97 { 24576000, 0x3B },
98 { 25000000, 0x3C },
99 { 25600000, 0x3D },
100 { 26000000, 0x3E },
101 { 27000000, 0x3F },
152 { 12288000, 0, 0 },
159 for (i = 0; i < ARRAY_SIZE(cs35l41_fs_mon); i++) { in cs35l41_get_fs_mon_config_index()
164 return -EINVAL; in cs35l41_get_fs_mon_config_index()
168 0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
169 1, 913, TLV_DB_MINMAX_ITEM(-10200, 1200));
170 static DECLARE_TLV_DB_SCALE(amp_gain_tlv, 50, 100, 0);
173 SOC_DAPM_SINGLE("Switch", CS35L41_PWR_CTRL3, 20, 1, 0);
180 CS35L41_AMP_DIG_VOL_CTRL, 0,
186 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs35l41_dsp_preload_ev()
192 if (cs35l41->dsp.cs_dsp.booted) in cs35l41_dsp_preload_ev()
193 return 0; in cs35l41_dsp_preload_ev()
197 if (cs35l41->dsp.preloaded) in cs35l41_dsp_preload_ev()
198 return 0; in cs35l41_dsp_preload_ev()
200 if (cs35l41->dsp.cs_dsp.running) { in cs35l41_dsp_preload_ev()
208 return 0; in cs35l41_dsp_preload_ev()
215 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs35l41_dsp_audio_ev()
222 if (!cs35l41->dsp.cs_dsp.running) in cs35l41_dsp_audio_ev()
225 ret = regmap_read(cs35l41->regmap, CS35L41_DSP_MBOX_2, &fw_status); in cs35l41_dsp_audio_ev()
226 if (ret < 0) { in cs35l41_dsp_audio_ev()
227 dev_err(cs35l41->dev, in cs35l41_dsp_audio_ev()
237 dev_err(cs35l41->dev, "Firmware status is invalid: %u\n", in cs35l41_dsp_audio_ev()
239 return -EINVAL; in cs35l41_dsp_audio_ev()
242 return cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap, in cs35l41_dsp_audio_ev()
245 return cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap, in cs35l41_dsp_audio_ev()
248 return 0; in cs35l41_dsp_audio_ev()
253 static const unsigned int cs35l41_pcm_source_values[] = {0x08, 0x32};
256 0, CS35L41_ASP_SOURCE_MASK,
269 0x00, CS35L41_INPUT_SRC_ASPRX1, CS35L41_INPUT_SRC_ASPRX2,
276 0, CS35L41_ASP_SOURCE_MASK,
285 0, CS35L41_ASP_SOURCE_MASK,
294 0, CS35L41_ASP_SOURCE_MASK,
303 0, CS35L41_ASP_SOURCE_MASK,
312 0, CS35L41_ASP_SOURCE_MASK,
321 0, CS35L41_ASP_SOURCE_MASK,
330 3, 0x4CF, 0x391, dig_vol_tlv),
331 SOC_SINGLE_TLV("Analog PCM Volume", CS35L41_AMP_GAIN_CTRL, 5, 0x14, 0,
334 SOC_SINGLE("HW Noise Gate Enable", CS35L41_NG_CFG, 8, 63, 0),
335 SOC_SINGLE("HW Noise Gate Delay", CS35L41_NG_CFG, 4, 7, 0),
336 SOC_SINGLE("HW Noise Gate Threshold", CS35L41_NG_CFG, 0, 7, 0),
338 CS35L41_MIXER_NGATE_CH1_CFG, 16, 1, 0),
340 CS35L41_MIXER_NGATE_CH1_CFG, 8, 15, 0),
342 CS35L41_MIXER_NGATE_CH1_CFG, 0, 7, 0),
344 CS35L41_MIXER_NGATE_CH2_CFG, 8, 15, 0),
346 CS35L41_MIXER_NGATE_CH2_CFG, 16, 1, 0),
348 CS35L41_MIXER_NGATE_CH2_CFG, 0, 7, 0),
349 SOC_SINGLE("SCLK Force Switch", CS35L41_SP_FORMAT, CS35L41_SCLK_FRC_SHIFT, 1, 0),
350 SOC_SINGLE("LRCLK Force Switch", CS35L41_SP_FORMAT, CS35L41_LRCLK_FRC_SHIFT, 1, 0),
352 CS35L41_AMP_INV_PCM_SHIFT, 1, 0),
354 CS35L41_AMP_GAIN_ZC_SHIFT, 1, 0),
356 WM_ADSP_FW_CONTROL("DSP1", 0),
361 switch (cs35l41->hw_cfg.bst_type) { in cs35l41_boost_enable()
365 regmap_update_bits(cs35l41->regmap, CS35L41_PWR_CTRL2, CS35L41_BST_EN_MASK, in cs35l41_boost_enable()
377 regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, irq_err_bit); in cs35l41_error_release()
378 regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0); in cs35l41_error_release()
379 regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, rel_err_bit, rel_err_bit); in cs35l41_error_release()
380 regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, rel_err_bit, 0); in cs35l41_error_release()
386 unsigned int status[4] = { 0, 0, 0, 0 }; in cs35l41_irq()
387 unsigned int masks[4] = { 0, 0, 0, 0 }; in cs35l41_irq()
391 ret = pm_runtime_resume_and_get(cs35l41->dev); in cs35l41_irq()
392 if (ret < 0) { in cs35l41_irq()
393 dev_err(cs35l41->dev, in cs35l41_irq()
401 for (i = 0; i < ARRAY_SIZE(status); i++) { in cs35l41_irq()
402 regmap_read(cs35l41->regmap, in cs35l41_irq()
405 regmap_read(cs35l41->regmap, in cs35l41_irq()
411 if (!(status[0] & ~masks[0]) && !(status[1] & ~masks[1]) && in cs35l41_irq()
416 regmap_update_bits(cs35l41->regmap, CS35L41_IRQ1_MASK4, in cs35l41_irq()
423 * speaker out of Safe-Mode. in cs35l41_irq()
425 if (status[0] & CS35L41_AMP_SHORT_ERR) { in cs35l41_irq()
426 dev_crit_ratelimited(cs35l41->dev, "Amp short error\n"); in cs35l41_irq()
431 if (status[0] & CS35L41_TEMP_WARN) { in cs35l41_irq()
432 dev_crit_ratelimited(cs35l41->dev, "Over temperature warning\n"); in cs35l41_irq()
437 if (status[0] & CS35L41_TEMP_ERR) { in cs35l41_irq()
438 dev_crit_ratelimited(cs35l41->dev, "Over temperature error\n"); in cs35l41_irq()
443 if (status[0] & CS35L41_BST_OVP_ERR) { in cs35l41_irq()
444 dev_crit_ratelimited(cs35l41->dev, "VBST Over Voltage error\n"); in cs35l41_irq()
445 cs35l41_boost_enable(cs35l41, 0); in cs35l41_irq()
451 if (status[0] & CS35L41_BST_DCM_UVP_ERR) { in cs35l41_irq()
452 dev_crit_ratelimited(cs35l41->dev, "DCM VBST Under Voltage Error\n"); in cs35l41_irq()
453 cs35l41_boost_enable(cs35l41, 0); in cs35l41_irq()
459 if (status[0] & CS35L41_BST_SHORT_ERR) { in cs35l41_irq()
460 dev_crit_ratelimited(cs35l41->dev, "LBST error: powering off!\n"); in cs35l41_irq()
461 cs35l41_boost_enable(cs35l41, 0); in cs35l41_irq()
468 regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS3, CS35L41_PLL_LOCK); in cs35l41_irq()
470 if (cs35l41->hw_cfg.bst_type == CS35L41_SHD_BOOST_ACTV || in cs35l41_irq()
471 cs35l41->hw_cfg.bst_type == CS35L41_SHD_BOOST_PASS) { in cs35l41_irq()
472 ret = cs35l41_mdsync_up(cs35l41->regmap); in cs35l41_irq()
474 dev_err(cs35l41->dev, "MDSYNC-up failed: %d\n", ret); in cs35l41_irq()
476 dev_dbg(cs35l41->dev, "MDSYNC-up done\n"); in cs35l41_irq()
478 dev_dbg(cs35l41->dev, "PUP-done status: %d\n", in cs35l41_irq()
479 !!(status[0] & CS35L41_PUP_DONE_MASK)); in cs35l41_irq()
486 pm_runtime_mark_last_busy(cs35l41->dev); in cs35l41_irq()
487 pm_runtime_put_autosuspend(cs35l41->dev); in cs35l41_irq()
493 { CS35L41_TEST_KEY_CTL, 0x00000055 },
494 { CS35L41_TEST_KEY_CTL, 0x000000AA },
495 { 0x00002084, 0x002F1AA0 },
496 { CS35L41_TEST_KEY_CTL, 0x000000CC },
497 { CS35L41_TEST_KEY_CTL, 0x00000033 },
501 { CS35L41_TEST_KEY_CTL, 0x00000055 },
502 { CS35L41_TEST_KEY_CTL, 0x000000AA },
503 { 0x00002084, 0x002F1AA3 },
504 { CS35L41_TEST_KEY_CTL, 0x000000CC },
505 { CS35L41_TEST_KEY_CTL, 0x00000033 },
511 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs35l41_main_amp_event()
513 int ret = 0; in cs35l41_main_amp_event()
517 regmap_multi_reg_write_bypassed(cs35l41->regmap, in cs35l41_main_amp_event()
521 ret = cs35l41_global_enable(cs35l41->dev, cs35l41->regmap, cs35l41->hw_cfg.bst_type, in cs35l41_main_amp_event()
522 1, &cs35l41->dsp.cs_dsp); in cs35l41_main_amp_event()
525 ret = cs35l41_global_enable(cs35l41->dev, cs35l41->regmap, cs35l41->hw_cfg.bst_type, in cs35l41_main_amp_event()
526 0, &cs35l41->dsp.cs_dsp); in cs35l41_main_amp_event()
528 regmap_multi_reg_write_bypassed(cs35l41->regmap, in cs35l41_main_amp_event()
533 dev_err(cs35l41->dev, "Invalid event = 0x%x\n", event); in cs35l41_main_amp_event()
534 ret = -EINVAL; in cs35l41_main_amp_event()
542 SND_SOC_DAPM_SUPPLY_S("DSP1 Preloader", 100, SND_SOC_NOPM, 0, 0,
545 SND_SOC_DAPM_OUT_DRV_E("DSP1", SND_SOC_NOPM, 0, 0, NULL, 0,
551 SND_SOC_DAPM_AIF_IN("ASPRX1", NULL, 0, CS35L41_SP_ENABLES, 16, 0),
552 SND_SOC_DAPM_AIF_IN("ASPRX2", NULL, 0, CS35L41_SP_ENABLES, 17, 0),
553 SND_SOC_DAPM_AIF_OUT("ASPTX1", NULL, 0, CS35L41_SP_ENABLES, 0, 0),
554 SND_SOC_DAPM_AIF_OUT("ASPTX2", NULL, 0, CS35L41_SP_ENABLES, 1, 0),
555 SND_SOC_DAPM_AIF_OUT("ASPTX3", NULL, 0, CS35L41_SP_ENABLES, 2, 0),
556 SND_SOC_DAPM_AIF_OUT("ASPTX4", NULL, 0, CS35L41_SP_ENABLES, 3, 0),
564 SND_SOC_DAPM_SUPPLY("VMON", CS35L41_PWR_CTRL2, 12, 0, NULL, 0),
565 SND_SOC_DAPM_SUPPLY("IMON", CS35L41_PWR_CTRL2, 13, 0, NULL, 0),
566 SND_SOC_DAPM_SUPPLY("VPMON", CS35L41_PWR_CTRL2, 8, 0, NULL, 0),
567 SND_SOC_DAPM_SUPPLY("VBSTMON", CS35L41_PWR_CTRL2, 9, 0, NULL, 0),
568 SND_SOC_DAPM_SUPPLY("TEMPMON", CS35L41_PWR_CTRL2, 10, 0, NULL, 0),
570 SND_SOC_DAPM_ADC("VMON ADC", NULL, SND_SOC_NOPM, 0, 0),
571 SND_SOC_DAPM_ADC("IMON ADC", NULL, SND_SOC_NOPM, 0, 0),
572 SND_SOC_DAPM_ADC("VPMON ADC", NULL, SND_SOC_NOPM, 0, 0),
573 SND_SOC_DAPM_ADC("VBSTMON ADC", NULL, SND_SOC_NOPM, 0, 0),
574 SND_SOC_DAPM_ADC("TEMPMON ADC", NULL, SND_SOC_NOPM, 0, 0),
576 SND_SOC_DAPM_ADC("CLASS H", NULL, CS35L41_PWR_CTRL3, 4, 0),
578 SND_SOC_DAPM_OUT_DRV_E("Main AMP", CS35L41_PWR_CTRL2, 0, 0, NULL, 0,
582 SND_SOC_DAPM_MUX("ASP TX1 Source", SND_SOC_NOPM, 0, 0, &asp_tx1_mux),
583 SND_SOC_DAPM_MUX("ASP TX2 Source", SND_SOC_NOPM, 0, 0, &asp_tx2_mux),
584 SND_SOC_DAPM_MUX("ASP TX3 Source", SND_SOC_NOPM, 0, 0, &asp_tx3_mux),
585 SND_SOC_DAPM_MUX("ASP TX4 Source", SND_SOC_NOPM, 0, 0, &asp_tx4_mux),
586 SND_SOC_DAPM_MUX("DSP RX1 Source", SND_SOC_NOPM, 0, 0, &dsp_rx1_mux),
587 SND_SOC_DAPM_MUX("DSP RX2 Source", SND_SOC_NOPM, 0, 0, &dsp_rx2_mux),
588 SND_SOC_DAPM_MUX("PCM Source", SND_SOC_NOPM, 0, 0, &pcm_source_mux),
589 SND_SOC_DAPM_SWITCH("DRE", SND_SOC_NOPM, 0, 0, &dre_ctrl),
601 {"ASP TX1 Source", "VMON", "VMON ADC"},
602 {"ASP TX1 Source", "IMON", "IMON ADC"},
603 {"ASP TX1 Source", "VPMON", "VPMON ADC"},
604 {"ASP TX1 Source", "VBSTMON", "VBSTMON ADC"},
605 {"ASP TX1 Source", "DSPTX1", "DSP1"},
606 {"ASP TX1 Source", "DSPTX2", "DSP1"},
607 {"ASP TX1 Source", "ASPRX1", "ASPRX1" },
608 {"ASP TX1 Source", "ASPRX2", "ASPRX2" },
633 {"ASPTX1", NULL, "ASP TX1 Source"},
679 struct cs35l41_private *cs35l41 = snd_soc_component_get_drvdata(dai->component); in cs35l41_set_channel_map()
681 return cs35l41_set_channels(cs35l41->dev, cs35l41->regmap, tx_n, tx_slot, rx_n, rx_slot); in cs35l41_set_channel_map()
686 struct cs35l41_private *cs35l41 = snd_soc_component_get_drvdata(dai->component); in cs35l41_set_dai_fmt()
687 unsigned int daifmt = 0; in cs35l41_set_dai_fmt()
696 dev_warn(cs35l41->dev, "Mixed provider/consumer mode unsupported\n"); in cs35l41_set_dai_fmt()
697 return -EINVAL; in cs35l41_set_dai_fmt()
707 dev_warn(cs35l41->dev, "Invalid or unsupported DAI format\n"); in cs35l41_set_dai_fmt()
708 return -EINVAL; in cs35l41_set_dai_fmt()
724 dev_warn(cs35l41->dev, "Invalid DAI clock INV\n"); in cs35l41_set_dai_fmt()
725 return -EINVAL; in cs35l41_set_dai_fmt()
728 return regmap_update_bits(cs35l41->regmap, CS35L41_SP_FORMAT, in cs35l41_set_dai_fmt()
740 { 12000, 0x01 },
741 { 24000, 0x02 },
742 { 48000, 0x03 },
743 { 96000, 0x04 },
744 { 192000, 0x05 },
745 { 11025, 0x09 },
746 { 22050, 0x0A },
747 { 44100, 0x0B },
748 { 88200, 0x0C },
749 { 176400, 0x0D },
750 { 8000, 0x11 },
751 { 16000, 0x12 },
752 { 32000, 0x13 },
759 struct cs35l41_private *cs35l41 = snd_soc_component_get_drvdata(dai->component); in cs35l41_pcm_hw_params()
764 for (i = 0; i < ARRAY_SIZE(cs35l41_fs_rates); i++) { in cs35l41_pcm_hw_params()
770 dev_err(cs35l41->dev, "Unsupported rate: %u\n", rate); in cs35l41_pcm_hw_params()
771 return -EINVAL; in cs35l41_pcm_hw_params()
776 regmap_update_bits(cs35l41->regmap, CS35L41_GLOBAL_CLK_CTRL, in cs35l41_pcm_hw_params()
780 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in cs35l41_pcm_hw_params()
781 regmap_update_bits(cs35l41->regmap, CS35L41_SP_FORMAT, in cs35l41_pcm_hw_params()
784 regmap_update_bits(cs35l41->regmap, CS35L41_SP_RX_WL, in cs35l41_pcm_hw_params()
788 regmap_update_bits(cs35l41->regmap, CS35L41_SP_FORMAT, in cs35l41_pcm_hw_params()
791 regmap_update_bits(cs35l41->regmap, CS35L41_SP_TX_WL, in cs35l41_pcm_hw_params()
796 return 0; in cs35l41_pcm_hw_params()
803 for (i = 0; i < ARRAY_SIZE(cs35l41_pll_sysclk); i++) { in cs35l41_get_clk_config()
808 return -EINVAL; in cs35l41_get_clk_config()
829 dev_err(cs35l41->dev, "Invalid CLK Config\n"); in cs35l41_component_set_sysclk()
830 return -EINVAL; in cs35l41_component_set_sysclk()
835 if (extclk_cfg < 0) { in cs35l41_component_set_sysclk()
836 dev_err(cs35l41->dev, "Invalid CLK Config: %d, freq: %u\n", in cs35l41_component_set_sysclk()
838 return -EINVAL; in cs35l41_component_set_sysclk()
841 regmap_update_bits(cs35l41->regmap, CS35L41_PLL_CLK_CTRL, in cs35l41_component_set_sysclk()
844 regmap_update_bits(cs35l41->regmap, CS35L41_PLL_CLK_CTRL, in cs35l41_component_set_sysclk()
847 regmap_update_bits(cs35l41->regmap, CS35L41_PLL_CLK_CTRL, in cs35l41_component_set_sysclk()
849 0 << CS35L41_PLL_CLK_EN_SHIFT); in cs35l41_component_set_sysclk()
850 regmap_update_bits(cs35l41->regmap, CS35L41_PLL_CLK_CTRL, in cs35l41_component_set_sysclk()
852 regmap_update_bits(cs35l41->regmap, CS35L41_PLL_CLK_CTRL, in cs35l41_component_set_sysclk()
854 0 << CS35L41_PLL_OPENLOOP_SHIFT); in cs35l41_component_set_sysclk()
855 regmap_update_bits(cs35l41->regmap, CS35L41_PLL_CLK_CTRL, in cs35l41_component_set_sysclk()
859 return 0; in cs35l41_component_set_sysclk()
865 struct cs35l41_private *cs35l41 = snd_soc_component_get_drvdata(dai->component); in cs35l41_dai_set_sysclk()
872 if (fsindex < 0) { in cs35l41_dai_set_sysclk()
873 dev_err(cs35l41->dev, "Invalid CLK Config freq: %u\n", freq); in cs35l41_dai_set_sysclk()
874 return -EINVAL; in cs35l41_dai_set_sysclk()
877 dev_dbg(cs35l41->dev, "Set DAI sysclk %d\n", freq); in cs35l41_dai_set_sysclk()
884 /* Use hard-coded values */ in cs35l41_dai_set_sysclk()
885 fs1_val = 0x10; in cs35l41_dai_set_sysclk()
886 fs2_val = 0x24; in cs35l41_dai_set_sysclk()
891 regmap_write(cs35l41->regmap, CS35L41_TST_FS_MON0, val); in cs35l41_dai_set_sysclk()
893 return 0; in cs35l41_dai_set_sysclk()
898 struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; in cs35l41_set_pdata()
901 if (!hw_cfg->valid) in cs35l41_set_pdata()
902 return -EINVAL; in cs35l41_set_pdata()
904 if (hw_cfg->bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) in cs35l41_set_pdata()
905 return -EINVAL; in cs35l41_set_pdata()
908 ret = cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, hw_cfg); in cs35l41_set_pdata()
913 if (hw_cfg->dout_hiz <= CS35L41_ASP_DOUT_HIZ_MASK && hw_cfg->dout_hiz >= 0) in cs35l41_set_pdata()
914 regmap_update_bits(cs35l41->regmap, CS35L41_SP_HIZ_CTRL, CS35L41_ASP_DOUT_HIZ_MASK, in cs35l41_set_pdata()
915 hw_cfg->dout_hiz); in cs35l41_set_pdata()
917 return 0; in cs35l41_set_pdata()
925 SND_SOC_DAPM_SUPPLY("VSPK", CS35L41_GPIO1_CTRL1, CS35L41_GPIO_LVL_SHIFT, 0, NULL, 0),
934 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST) { in cs35l41_component_probe()
946 return wm_adsp2_component_probe(&cs35l41->dsp, component); in cs35l41_component_probe()
953 wm_adsp2_component_remove(&cs35l41->dsp, component); in cs35l41_component_remove()
974 .name = "cs35l41-pcm",
975 .id = 0,
996 .name = "cs35l41-codec",
1014 struct cs35l41_gpio_cfg *gpio1 = &hw_cfg->gpio1; in cs35l41_handle_pdata()
1015 struct cs35l41_gpio_cfg *gpio2 = &hw_cfg->gpio2; in cs35l41_handle_pdata()
1021 * To correctly configure those systems add shared-boost-active and shared-boost-passive in cs35l41_handle_pdata()
1022 * properties mapped to the correct value in boost-type. in cs35l41_handle_pdata()
1025 if (device_property_read_bool(dev, "cirrus,shared-boost-active")) { in cs35l41_handle_pdata()
1026 hw_cfg->bst_type = CS35L41_SHD_BOOST_ACTV; in cs35l41_handle_pdata()
1027 } else if (device_property_read_bool(dev, "cirrus,shared-boost-passive")) { in cs35l41_handle_pdata()
1028 hw_cfg->bst_type = CS35L41_SHD_BOOST_PASS; in cs35l41_handle_pdata()
1030 ret = device_property_read_u32(dev, "cirrus,boost-type", &val); in cs35l41_handle_pdata()
1031 if (ret >= 0) in cs35l41_handle_pdata()
1032 hw_cfg->bst_type = val; in cs35l41_handle_pdata()
1035 ret = device_property_read_u32(dev, "cirrus,boost-peak-milliamp", &val); in cs35l41_handle_pdata()
1036 if (ret >= 0) in cs35l41_handle_pdata()
1037 hw_cfg->bst_ipk = val; in cs35l41_handle_pdata()
1039 hw_cfg->bst_ipk = -1; in cs35l41_handle_pdata()
1041 ret = device_property_read_u32(dev, "cirrus,boost-ind-nanohenry", &val); in cs35l41_handle_pdata()
1042 if (ret >= 0) in cs35l41_handle_pdata()
1043 hw_cfg->bst_ind = val; in cs35l41_handle_pdata()
1045 hw_cfg->bst_ind = -1; in cs35l41_handle_pdata()
1047 ret = device_property_read_u32(dev, "cirrus,boost-cap-microfarad", &val); in cs35l41_handle_pdata()
1048 if (ret >= 0) in cs35l41_handle_pdata()
1049 hw_cfg->bst_cap = val; in cs35l41_handle_pdata()
1051 hw_cfg->bst_cap = -1; in cs35l41_handle_pdata()
1053 ret = device_property_read_u32(dev, "cirrus,asp-sdout-hiz", &val); in cs35l41_handle_pdata()
1054 if (ret >= 0) in cs35l41_handle_pdata()
1055 hw_cfg->dout_hiz = val; in cs35l41_handle_pdata()
1057 hw_cfg->dout_hiz = -1; in cs35l41_handle_pdata()
1060 gpio1->pol_inv = device_property_read_bool(dev, "cirrus,gpio1-polarity-invert"); in cs35l41_handle_pdata()
1061 gpio1->out_en = device_property_read_bool(dev, "cirrus,gpio1-output-enable"); in cs35l41_handle_pdata()
1062 ret = device_property_read_u32(dev, "cirrus,gpio1-src-select", &val); in cs35l41_handle_pdata()
1063 if (ret >= 0) { in cs35l41_handle_pdata()
1064 gpio1->func = val; in cs35l41_handle_pdata()
1065 gpio1->valid = true; in cs35l41_handle_pdata()
1069 gpio2->pol_inv = device_property_read_bool(dev, "cirrus,gpio2-polarity-invert"); in cs35l41_handle_pdata()
1070 gpio2->out_en = device_property_read_bool(dev, "cirrus,gpio2-output-enable"); in cs35l41_handle_pdata()
1071 ret = device_property_read_u32(dev, "cirrus,gpio2-src-select", &val); in cs35l41_handle_pdata()
1072 if (ret >= 0) { in cs35l41_handle_pdata()
1073 gpio2->func = val; in cs35l41_handle_pdata()
1074 gpio2->valid = true; in cs35l41_handle_pdata()
1077 hw_cfg->valid = true; in cs35l41_handle_pdata()
1079 return 0; in cs35l41_handle_pdata()
1088 dsp = &cs35l41->dsp; in cs35l41_dsp_init()
1089 dsp->part = "cs35l41"; in cs35l41_dsp_init()
1090 dsp->fw = 9; /* 9 is WM_ADSP_FW_SPK_PROT in wm_adsp.c */ in cs35l41_dsp_init()
1091 dsp->toggle_preload = true; in cs35l41_dsp_init()
1093 cs35l41_configure_cs_dsp(cs35l41->dev, cs35l41->regmap, &dsp->cs_dsp); in cs35l41_dsp_init()
1095 ret = cs35l41_write_fs_errata(cs35l41->dev, cs35l41->regmap); in cs35l41_dsp_init()
1096 if (ret < 0) in cs35l41_dsp_init()
1101 dev_err(cs35l41->dev, "wm_halo_init failed: %d\n", ret); in cs35l41_dsp_init()
1105 switch (cs35l41->hw_cfg.bst_type) { in cs35l41_dsp_init()
1115 dev_err(cs35l41->dev, "wm_halo_init failed - Invalid Boost Type: %d\n", in cs35l41_dsp_init()
1116 cs35l41->hw_cfg.bst_type); in cs35l41_dsp_init()
1120 ret = regmap_write(cs35l41->regmap, CS35L41_DSP1_RX5_SRC, dsp1rx5_src); in cs35l41_dsp_init()
1121 if (ret < 0) { in cs35l41_dsp_init()
1122 dev_err(cs35l41->dev, "Write DSP1RX5_SRC: %d failed: %d\n", dsp1rx5_src, ret); in cs35l41_dsp_init()
1125 ret = regmap_write(cs35l41->regmap, CS35L41_DSP1_RX6_SRC, CS35L41_INPUT_SRC_VBSTMON); in cs35l41_dsp_init()
1126 if (ret < 0) { in cs35l41_dsp_init()
1127 dev_err(cs35l41->dev, "Write CS35L41_INPUT_SRC_VBSTMON failed: %d\n", ret); in cs35l41_dsp_init()
1130 ret = regmap_write(cs35l41->regmap, CS35L41_DSP1_RX7_SRC, in cs35l41_dsp_init()
1132 if (ret < 0) { in cs35l41_dsp_init()
1133 dev_err(cs35l41->dev, "Write INPUT_SRC_TEMPMON failed: %d\n", ret); in cs35l41_dsp_init()
1136 ret = regmap_write(cs35l41->regmap, CS35L41_DSP1_RX8_SRC, in cs35l41_dsp_init()
1138 if (ret < 0) { in cs35l41_dsp_init()
1139 dev_err(cs35l41->dev, "Write INPUT_SRC_RSVD failed: %d\n", ret); in cs35l41_dsp_init()
1143 return 0; in cs35l41_dsp_init()
1153 acpi_handle handle = ACPI_HANDLE(cs35l41->dev); in cs35l41_acpi_get_name()
1156 /* If there is no ACPI_HANDLE, there is no ACPI for this system, return 0 */ in cs35l41_acpi_get_name()
1158 return 0; in cs35l41_acpi_get_name()
1162 /* If bad ACPI, return 0 and fallback to legacy firmware path, otherwise fail */ in cs35l41_acpi_get_name()
1163 if (PTR_ERR(sub) == -ENODATA) in cs35l41_acpi_get_name()
1164 return 0; in cs35l41_acpi_get_name()
1169 cs35l41->dsp.system_name = sub; in cs35l41_acpi_get_name()
1170 dev_dbg(cs35l41->dev, "Subsystem ID: %s\n", cs35l41->dsp.system_name); in cs35l41_acpi_get_name()
1172 return 0; in cs35l41_acpi_get_name()
1178 int irq_pol = 0; in cs35l41_probe()
1182 cs35l41->hw_cfg = *hw_cfg; in cs35l41_probe()
1184 ret = cs35l41_handle_pdata(cs35l41->dev, &cs35l41->hw_cfg); in cs35l41_probe()
1185 if (ret != 0) in cs35l41_probe()
1189 for (i = 0; i < CS35L41_NUM_SUPPLIES; i++) in cs35l41_probe()
1190 cs35l41->supplies[i].supply = cs35l41_supplies[i]; in cs35l41_probe()
1192 ret = devm_regulator_bulk_get(cs35l41->dev, CS35L41_NUM_SUPPLIES, in cs35l41_probe()
1193 cs35l41->supplies); in cs35l41_probe()
1194 if (ret != 0) in cs35l41_probe()
1195 return dev_err_probe(cs35l41->dev, ret, in cs35l41_probe()
1198 ret = regulator_bulk_enable(CS35L41_NUM_SUPPLIES, cs35l41->supplies); in cs35l41_probe()
1199 if (ret != 0) in cs35l41_probe()
1200 return dev_err_probe(cs35l41->dev, ret, in cs35l41_probe()
1204 cs35l41->reset_gpio = devm_gpiod_get_optional(cs35l41->dev, "reset", in cs35l41_probe()
1206 if (IS_ERR(cs35l41->reset_gpio)) { in cs35l41_probe()
1207 ret = PTR_ERR(cs35l41->reset_gpio); in cs35l41_probe()
1208 cs35l41->reset_gpio = NULL; in cs35l41_probe()
1209 if (ret == -EBUSY) { in cs35l41_probe()
1210 dev_info(cs35l41->dev, in cs35l41_probe()
1213 dev_err_probe(cs35l41->dev, ret, in cs35l41_probe()
1218 if (cs35l41->reset_gpio) { in cs35l41_probe()
1221 gpiod_set_value_cansleep(cs35l41->reset_gpio, 1); in cs35l41_probe()
1226 ret = regmap_read_poll_timeout(cs35l41->regmap, CS35L41_IRQ1_STATUS4, in cs35l41_probe()
1230 dev_err_probe(cs35l41->dev, ret, in cs35l41_probe()
1235 regmap_read(cs35l41->regmap, CS35L41_IRQ1_STATUS3, &int_status); in cs35l41_probe()
1237 dev_err(cs35l41->dev, "OTP Boot error\n"); in cs35l41_probe()
1238 ret = -EINVAL; in cs35l41_probe()
1242 ret = regmap_read(cs35l41->regmap, CS35L41_DEVID, ®id); in cs35l41_probe()
1243 if (ret < 0) { in cs35l41_probe()
1244 dev_err_probe(cs35l41->dev, ret, "Get Device ID failed\n"); in cs35l41_probe()
1248 ret = regmap_read(cs35l41->regmap, CS35L41_REVID, ®_revid); in cs35l41_probe()
1249 if (ret < 0) { in cs35l41_probe()
1250 dev_err_probe(cs35l41->dev, ret, "Get Revision ID failed\n"); in cs35l41_probe()
1261 dev_err(cs35l41->dev, "CS35L41 Device ID (%X). Expected ID %X\n", in cs35l41_probe()
1263 ret = -ENODEV; in cs35l41_probe()
1267 cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap); in cs35l41_probe()
1269 ret = cs35l41_register_errata_patch(cs35l41->dev, cs35l41->regmap, reg_revid); in cs35l41_probe()
1273 ret = cs35l41_otp_unpack(cs35l41->dev, cs35l41->regmap); in cs35l41_probe()
1274 if (ret < 0) { in cs35l41_probe()
1275 dev_err_probe(cs35l41->dev, ret, "OTP Unpack failed\n"); in cs35l41_probe()
1279 cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap); in cs35l41_probe()
1281 irq_pol = cs35l41_gpio_config(cs35l41->regmap, &cs35l41->hw_cfg); in cs35l41_probe()
1284 regmap_write(cs35l41->regmap, CS35L41_IRQ1_MASK1, in cs35l41_probe()
1286 if (cs35l41->hw_cfg.bst_type == CS35L41_SHD_BOOST_PASS || in cs35l41_probe()
1287 cs35l41->hw_cfg.bst_type == CS35L41_SHD_BOOST_ACTV) in cs35l41_probe()
1288 regmap_update_bits(cs35l41->regmap, CS35L41_IRQ1_MASK3, CS35L41_INT3_PLL_LOCK_MASK, in cs35l41_probe()
1289 0 << CS35L41_INT3_PLL_LOCK_SHIFT); in cs35l41_probe()
1291 ret = devm_request_threaded_irq(cs35l41->dev, cs35l41->irq, NULL, cs35l41_irq, in cs35l41_probe()
1294 if (ret != 0) { in cs35l41_probe()
1295 dev_err_probe(cs35l41->dev, ret, "Failed to request IRQ\n"); in cs35l41_probe()
1300 if (ret < 0) { in cs35l41_probe()
1301 dev_err_probe(cs35l41->dev, ret, "Set pdata failed\n"); in cs35l41_probe()
1306 if (ret < 0) in cs35l41_probe()
1310 if (ret < 0) in cs35l41_probe()
1313 pm_runtime_set_autosuspend_delay(cs35l41->dev, 3000); in cs35l41_probe()
1314 pm_runtime_use_autosuspend(cs35l41->dev); in cs35l41_probe()
1315 pm_runtime_mark_last_busy(cs35l41->dev); in cs35l41_probe()
1316 pm_runtime_set_active(cs35l41->dev); in cs35l41_probe()
1317 pm_runtime_get_noresume(cs35l41->dev); in cs35l41_probe()
1318 pm_runtime_enable(cs35l41->dev); in cs35l41_probe()
1320 ret = devm_snd_soc_register_component(cs35l41->dev, in cs35l41_probe()
1323 if (ret < 0) { in cs35l41_probe()
1324 dev_err_probe(cs35l41->dev, ret, "Register codec failed\n"); in cs35l41_probe()
1328 pm_runtime_put_autosuspend(cs35l41->dev); in cs35l41_probe()
1330 dev_info(cs35l41->dev, "Cirrus Logic CS35L41 (%x), Revision: %02X\n", in cs35l41_probe()
1333 return 0; in cs35l41_probe()
1336 pm_runtime_dont_use_autosuspend(cs35l41->dev); in cs35l41_probe()
1337 pm_runtime_disable(cs35l41->dev); in cs35l41_probe()
1338 pm_runtime_put_noidle(cs35l41->dev); in cs35l41_probe()
1340 wm_adsp2_remove(&cs35l41->dsp); in cs35l41_probe()
1342 cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type); in cs35l41_probe()
1343 regulator_bulk_disable(CS35L41_NUM_SUPPLIES, cs35l41->supplies); in cs35l41_probe()
1344 gpiod_set_value_cansleep(cs35l41->reset_gpio, 0); in cs35l41_probe()
1352 pm_runtime_get_sync(cs35l41->dev); in cs35l41_remove()
1353 pm_runtime_dont_use_autosuspend(cs35l41->dev); in cs35l41_remove()
1354 pm_runtime_disable(cs35l41->dev); in cs35l41_remove()
1356 regmap_write(cs35l41->regmap, CS35L41_IRQ1_MASK1, 0xFFFFFFFF); in cs35l41_remove()
1357 if (cs35l41->hw_cfg.bst_type == CS35L41_SHD_BOOST_PASS || in cs35l41_remove()
1358 cs35l41->hw_cfg.bst_type == CS35L41_SHD_BOOST_ACTV) in cs35l41_remove()
1359 regmap_update_bits(cs35l41->regmap, CS35L41_IRQ1_MASK3, CS35L41_INT3_PLL_LOCK_MASK, in cs35l41_remove()
1361 kfree(cs35l41->dsp.system_name); in cs35l41_remove()
1362 wm_adsp2_remove(&cs35l41->dsp); in cs35l41_remove()
1363 cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type); in cs35l41_remove()
1365 pm_runtime_put_noidle(cs35l41->dev); in cs35l41_remove()
1367 regulator_bulk_disable(CS35L41_NUM_SUPPLIES, cs35l41->supplies); in cs35l41_remove()
1368 gpiod_set_value_cansleep(cs35l41->reset_gpio, 0); in cs35l41_remove()
1376 dev_dbg(cs35l41->dev, "Runtime suspend\n"); in cs35l41_runtime_suspend()
1378 if (!cs35l41->dsp.preloaded || !cs35l41->dsp.cs_dsp.running) in cs35l41_runtime_suspend()
1379 return 0; in cs35l41_runtime_suspend()
1381 cs35l41_enter_hibernate(dev, cs35l41->regmap, cs35l41->hw_cfg.bst_type); in cs35l41_runtime_suspend()
1383 regcache_cache_only(cs35l41->regmap, true); in cs35l41_runtime_suspend()
1384 regcache_mark_dirty(cs35l41->regmap); in cs35l41_runtime_suspend()
1386 return 0; in cs35l41_runtime_suspend()
1394 dev_dbg(cs35l41->dev, "Runtime resume\n"); in cs35l41_runtime_resume()
1396 if (!cs35l41->dsp.preloaded || !cs35l41->dsp.cs_dsp.running) in cs35l41_runtime_resume()
1397 return 0; in cs35l41_runtime_resume()
1399 regcache_cache_only(cs35l41->regmap, false); in cs35l41_runtime_resume()
1401 ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap); in cs35l41_runtime_resume()
1405 /* Test key needs to be unlocked to allow the OTP settings to re-apply */ in cs35l41_runtime_resume()
1406 cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap); in cs35l41_runtime_resume()
1407 ret = regcache_sync(cs35l41->regmap); in cs35l41_runtime_resume()
1408 cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap); in cs35l41_runtime_resume()
1410 dev_err(cs35l41->dev, "Failed to restore register cache: %d\n", ret); in cs35l41_runtime_resume()
1413 cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, &cs35l41->hw_cfg); in cs35l41_runtime_resume()
1415 return 0; in cs35l41_runtime_resume()
1422 dev_dbg(cs35l41->dev, "System suspend, disabling IRQ\n"); in cs35l41_sys_suspend()
1423 disable_irq(cs35l41->irq); in cs35l41_sys_suspend()
1425 return 0; in cs35l41_sys_suspend()
1432 dev_dbg(cs35l41->dev, "Late system suspend, reenabling IRQ\n"); in cs35l41_sys_suspend_noirq()
1433 enable_irq(cs35l41->irq); in cs35l41_sys_suspend_noirq()
1435 return 0; in cs35l41_sys_suspend_noirq()
1442 dev_dbg(cs35l41->dev, "Early system resume, disabling IRQ\n"); in cs35l41_sys_resume_noirq()
1443 disable_irq(cs35l41->irq); in cs35l41_sys_resume_noirq()
1445 return 0; in cs35l41_sys_resume_noirq()
1452 dev_dbg(cs35l41->dev, "System resume, reenabling IRQ\n"); in cs35l41_sys_resume()
1453 enable_irq(cs35l41->irq); in cs35l41_sys_resume()
1455 return 0; in cs35l41_sys_resume()