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