1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * CS42L43 CODEC driver internal data 3 * CS42L43 CODEC driver internal data 4 * 4 * 5 * Copyright (C) 2022-2023 Cirrus Logic, Inc. 5 * Copyright (C) 2022-2023 Cirrus Logic, Inc. and 6 * Cirrus Logic Intern 6 * Cirrus Logic International Semiconductor Ltd. 7 */ 7 */ 8 8 9 #ifndef CS42L43_ASOC_INT_H 9 #ifndef CS42L43_ASOC_INT_H 10 #define CS42L43_ASOC_INT_H 10 #define CS42L43_ASOC_INT_H 11 11 12 #include <linux/completion.h> 12 #include <linux/completion.h> 13 #include <linux/mutex.h> 13 #include <linux/mutex.h> 14 #include <linux/types.h> 14 #include <linux/types.h> 15 #include <linux/workqueue.h> 15 #include <linux/workqueue.h> 16 #include <sound/pcm.h> 16 #include <sound/pcm.h> 17 17 18 #define CS42L43_INTERNAL_SYSCLK 245760 18 #define CS42L43_INTERNAL_SYSCLK 24576000 19 #define CS42L43_DEFAULT_SLOTS 0x3F 19 #define CS42L43_DEFAULT_SLOTS 0x3F 20 20 21 #define CS42L43_PLL_TIMEOUT_MS 200 21 #define CS42L43_PLL_TIMEOUT_MS 200 22 #define CS42L43_SPK_TIMEOUT_MS 100 22 #define CS42L43_SPK_TIMEOUT_MS 100 23 #define CS42L43_HP_TIMEOUT_MS 2000 23 #define CS42L43_HP_TIMEOUT_MS 2000 24 #define CS42L43_LOAD_TIMEOUT_MS 1000 24 #define CS42L43_LOAD_TIMEOUT_MS 1000 25 25 26 #define CS42L43_HP_ILIMIT_BACKOFF_MS 1000 26 #define CS42L43_HP_ILIMIT_BACKOFF_MS 1000 27 #define CS42L43_HP_ILIMIT_DECAY_MS 300 27 #define CS42L43_HP_ILIMIT_DECAY_MS 300 28 #define CS42L43_HP_ILIMIT_MAX_COUNT 4 28 #define CS42L43_HP_ILIMIT_MAX_COUNT 4 29 29 30 #define CS42L43_ASP_MAX_CHANNELS 6 30 #define CS42L43_ASP_MAX_CHANNELS 6 31 #define CS42L43_N_EQ_COEFFS 15 31 #define CS42L43_N_EQ_COEFFS 15 32 32 33 #define CS42L43_N_BUTTONS 6 33 #define CS42L43_N_BUTTONS 6 34 34 35 struct clk; 35 struct clk; 36 struct device; 36 struct device; 37 37 38 struct snd_soc_component; 38 struct snd_soc_component; 39 struct snd_soc_jack; 39 struct snd_soc_jack; 40 40 41 struct cs42l43; 41 struct cs42l43; 42 42 43 struct cs42l43_codec { 43 struct cs42l43_codec { 44 struct device *dev; 44 struct device *dev; 45 struct cs42l43 *core; 45 struct cs42l43 *core; 46 struct snd_soc_component *component; 46 struct snd_soc_component *component; 47 47 48 struct clk *mclk; 48 struct clk *mclk; 49 49 50 int n_slots; 50 int n_slots; 51 int slot_width; 51 int slot_width; 52 int tx_slots[CS42L43_ASP_MAX_CHANNELS] 52 int tx_slots[CS42L43_ASP_MAX_CHANNELS]; 53 int rx_slots[CS42L43_ASP_MAX_CHANNELS] 53 int rx_slots[CS42L43_ASP_MAX_CHANNELS]; 54 struct snd_pcm_hw_constraint_list cons 54 struct snd_pcm_hw_constraint_list constraint; 55 55 56 u32 eq_coeffs[CS42L43_N_EQ_COEFFS]; 56 u32 eq_coeffs[CS42L43_N_EQ_COEFFS]; 57 57 58 unsigned int refclk_src; 58 unsigned int refclk_src; 59 unsigned int refclk_freq; 59 unsigned int refclk_freq; 60 struct completion pll_ready; 60 struct completion pll_ready; 61 61 62 unsigned int decim_cache[4]; 62 unsigned int decim_cache[4]; 63 unsigned int adc_ena; 63 unsigned int adc_ena; 64 unsigned int hp_ena; 64 unsigned int hp_ena; 65 65 66 struct completion hp_startup; 66 struct completion hp_startup; 67 struct completion hp_shutdown; 67 struct completion hp_shutdown; 68 struct completion spkr_shutdown; 68 struct completion spkr_shutdown; 69 struct completion spkl_shutdown; 69 struct completion spkl_shutdown; 70 struct completion spkr_startup; 70 struct completion spkr_startup; 71 struct completion spkl_startup; 71 struct completion spkl_startup; 72 // Lock to ensure speaker VU updates d 72 // Lock to ensure speaker VU updates don't clash 73 struct mutex spk_vu_lock; 73 struct mutex spk_vu_lock; 74 74 75 // Lock for all jack detect operations 75 // Lock for all jack detect operations 76 struct mutex jack_lock; 76 struct mutex jack_lock; 77 struct snd_soc_jack *jack_hp; 77 struct snd_soc_jack *jack_hp; 78 78 79 bool use_ring_sense; 79 bool use_ring_sense; 80 unsigned int tip_debounce_ms; 80 unsigned int tip_debounce_ms; 81 unsigned int bias_low; 81 unsigned int bias_low; 82 unsigned int bias_sense_ua; 82 unsigned int bias_sense_ua; 83 unsigned int bias_ramp_ms; 83 unsigned int bias_ramp_ms; 84 unsigned int detect_us; 84 unsigned int detect_us; 85 unsigned int buttons[CS42L43_N_BUTTONS 85 unsigned int buttons[CS42L43_N_BUTTONS]; 86 86 87 struct delayed_work tip_sense_work; 87 struct delayed_work tip_sense_work; 88 struct delayed_work bias_sense_timeout 88 struct delayed_work bias_sense_timeout; 89 struct delayed_work button_press_work; 89 struct delayed_work button_press_work; 90 struct work_struct button_release_work 90 struct work_struct button_release_work; 91 struct completion type_detect; 91 struct completion type_detect; 92 struct completion load_detect; 92 struct completion load_detect; 93 93 94 bool load_detect_running; 94 bool load_detect_running; 95 bool button_detect_running; 95 bool button_detect_running; 96 bool jack_present; 96 bool jack_present; 97 int jack_override; 97 int jack_override; 98 98 99 struct work_struct hp_ilimit_work; 99 struct work_struct hp_ilimit_work; 100 struct delayed_work hp_ilimit_clear_wo 100 struct delayed_work hp_ilimit_clear_work; 101 bool hp_ilimited; 101 bool hp_ilimited; 102 int hp_ilimit_count; 102 int hp_ilimit_count; 103 103 104 struct snd_kcontrol *kctl[5]; 104 struct snd_kcontrol *kctl[5]; 105 }; 105 }; 106 106 107 #if IS_REACHABLE(CONFIG_SND_SOC_CS42L43_SDW) 107 #if IS_REACHABLE(CONFIG_SND_SOC_CS42L43_SDW) 108 108 109 int cs42l43_sdw_add_peripheral(struct snd_pcm_ 109 int cs42l43_sdw_add_peripheral(struct snd_pcm_substream *substream, 110 struct snd_pcm_ 110 struct snd_pcm_hw_params *params, 111 struct snd_soc_ 111 struct snd_soc_dai *dai); 112 int cs42l43_sdw_remove_peripheral(struct snd_p 112 int cs42l43_sdw_remove_peripheral(struct snd_pcm_substream *substream, 113 struct snd_s 113 struct snd_soc_dai *dai); 114 int cs42l43_sdw_set_stream(struct snd_soc_dai 114 int cs42l43_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction); 115 115 116 #else 116 #else 117 117 118 static inline int cs42l43_sdw_add_peripheral(s 118 static inline int cs42l43_sdw_add_peripheral(struct snd_pcm_substream *substream, 119 s 119 struct snd_pcm_hw_params *params, 120 s 120 struct snd_soc_dai *dai) 121 { 121 { 122 return -EINVAL; 122 return -EINVAL; 123 } 123 } 124 124 125 #define cs42l43_sdw_remove_peripheral NULL 125 #define cs42l43_sdw_remove_peripheral NULL 126 #define cs42l43_sdw_set_stream NULL 126 #define cs42l43_sdw_set_stream NULL 127 127 128 #endif 128 #endif 129 129 130 int cs42l43_set_jack(struct snd_soc_component 130 int cs42l43_set_jack(struct snd_soc_component *component, 131 struct snd_soc_jack *jack 131 struct snd_soc_jack *jack, void *d); 132 void cs42l43_bias_sense_timeout(struct work_st 132 void cs42l43_bias_sense_timeout(struct work_struct *work); 133 void cs42l43_tip_sense_work(struct work_struct 133 void cs42l43_tip_sense_work(struct work_struct *work); 134 void cs42l43_button_press_work(struct work_str 134 void cs42l43_button_press_work(struct work_struct *work); 135 void cs42l43_button_release_work(struct work_s 135 void cs42l43_button_release_work(struct work_struct *work); 136 irqreturn_t cs42l43_bias_detect_clamp(int irq, 136 irqreturn_t cs42l43_bias_detect_clamp(int irq, void *data); 137 irqreturn_t cs42l43_button_press(int irq, void 137 irqreturn_t cs42l43_button_press(int irq, void *data); 138 irqreturn_t cs42l43_button_release(int irq, vo 138 irqreturn_t cs42l43_button_release(int irq, void *data); 139 irqreturn_t cs42l43_tip_sense(int irq, void *d 139 irqreturn_t cs42l43_tip_sense(int irq, void *data); 140 int cs42l43_jack_get(struct snd_kcontrol *kcon 140 int cs42l43_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 141 int cs42l43_jack_put(struct snd_kcontrol *kcon 141 int cs42l43_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); 142 142 143 extern const struct soc_enum cs42l43_jack_enum 143 extern const struct soc_enum cs42l43_jack_enum; 144 144 145 #endif /* CS42L43_ASOC_INT_H */ 145 #endif /* CS42L43_ASOC_INT_H */ 146 146
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.