Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: codecs: wcd-common: move status_update callback to common

Soundwire update_status, bus_config and interrupt callbacks for wcd937x,
wcd938x, wcd939x soundwire codecs are exactly identlical, move them to
common driver to remove this duplicate code.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Link: https://patch.msgid.link/20250909121954.225833-12-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Srinivas Kandagatla and committed by
Mark Brown
59aebbbb 45f2c5e1

+62 -100
+46
sound/soc/codecs/wcd-common.c
··· 9 9 #include <linux/printk.h> 10 10 #include <linux/component.h> 11 11 #include <linux/pm_runtime.h> 12 + #include <linux/soundwire/sdw.h> 13 + #include <linux/soundwire/sdw_type.h> 14 + #include <linux/regmap.h> 12 15 13 16 #include "wcd-common.h" 14 17 15 18 #define WCD_MIN_MICBIAS_MV 1000 16 19 #define WCD_DEF_MICBIAS_MV 1800 17 20 #define WCD_MAX_MICBIAS_MV 2850 21 + 22 + #define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m)) 18 23 19 24 int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv) 20 25 { ··· 97 92 .unbind = wcd_sdw_component_unbind, 98 93 }; 99 94 EXPORT_SYMBOL_GPL(wcd_sdw_component_ops); 95 + 96 + int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status) 97 + { 98 + struct regmap *regmap = dev_get_regmap(&slave->dev, NULL); 99 + 100 + if (regmap && status == SDW_SLAVE_ATTACHED) { 101 + /* Write out any cached changes that happened between probe and attach */ 102 + regcache_cache_only(regmap, false); 103 + return regcache_sync(regmap); 104 + } 105 + 106 + return 0; 107 + } 108 + EXPORT_SYMBOL_GPL(wcd_update_status); 109 + 110 + int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params) 111 + { 112 + sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01); 113 + 114 + return 0; 115 + } 116 + EXPORT_SYMBOL_GPL(wcd_bus_config); 117 + 118 + int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq, 119 + unsigned int wcd_intr_status0, unsigned int wcd_intr_status1, 120 + unsigned int wcd_intr_status2) 121 + { 122 + struct regmap *regmap = dev_get_regmap(&slave->dev, NULL); 123 + u32 sts1, sts2, sts3; 124 + 125 + do { 126 + handle_nested_irq(irq_find_mapping(slave_irq, 0)); 127 + regmap_read(regmap, wcd_intr_status0, &sts1); 128 + regmap_read(regmap, wcd_intr_status1, &sts2); 129 + regmap_read(regmap, wcd_intr_status2, &sts3); 130 + 131 + } while (sts1 || sts2 || sts3); 132 + 133 + return IRQ_HANDLED; 134 + } 135 + EXPORT_SYMBOL_GPL(wcd_interrupt_callback); 100 136 101 137 MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver"); 102 138 MODULE_LICENSE("GPL");
+5
sound/soc/codecs/wcd-common.h
··· 37 37 extern const struct component_ops wcd_sdw_component_ops; 38 38 int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv); 39 39 int wcd_dt_parse_micbias_info(struct wcd_common *common); 40 + int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status); 41 + int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params); 42 + int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq, 43 + unsigned int wcd_intr_status0, unsigned int wcd_intr_status1, 44 + unsigned int wcd_intr_status2); 40 45 41 46 #endif /* __WCD_COMMON_H__ */
+3 -25
sound/soc/codecs/wcd937x-sdw.c
··· 112 112 } 113 113 EXPORT_SYMBOL_GPL(wcd937x_sdw_hw_params); 114 114 115 - static int wcd9370_update_status(struct sdw_slave *slave, enum sdw_slave_status status) 116 - { 117 - struct wcd937x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 118 - 119 - if (wcd->regmap && status == SDW_SLAVE_ATTACHED) { 120 - /* Write out any cached changes that happened between probe and attach */ 121 - regcache_cache_only(wcd->regmap, false); 122 - return regcache_sync(wcd->regmap); 123 - } 124 - 125 - return 0; 126 - } 127 - 128 115 /* 129 116 * Handle Soundwire out-of-band interrupt event by triggering 130 117 * the first irq of the slave_irq irq domain, which then will ··· 122 135 struct sdw_slave_intr_status *status) 123 136 { 124 137 struct wcd937x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 125 - struct irq_domain *slave_irq = wcd->slave_irq; 126 - u32 sts1, sts2, sts3; 127 138 128 - do { 129 - handle_nested_irq(irq_find_mapping(slave_irq, 0)); 130 - regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_0, &sts1); 131 - regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_1, &sts2); 132 - regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_2, &sts3); 133 - 134 - } while (sts1 || sts2 || sts3); 135 - 136 - return IRQ_HANDLED; 139 + return wcd_interrupt_callback(slave, wcd->slave_irq, WCD937X_DIGITAL_INTR_STATUS_0, 140 + WCD937X_DIGITAL_INTR_STATUS_1, WCD937X_DIGITAL_INTR_STATUS_2); 137 141 } 138 142 139 143 static const struct reg_default wcd937x_defaults[] = { ··· 957 979 }; 958 980 959 981 static const struct sdw_slave_ops wcd9370_slave_ops = { 960 - .update_status = wcd9370_update_status, 982 + .update_status = wcd_update_status, 961 983 .interrupt_callback = wcd9370_interrupt_callback, 962 984 }; 963 985
+4 -37
sound/soc/codecs/wcd938x-sdw.c
··· 20 20 #include "wcd938x.h" 21 21 #include "wcd-common.h" 22 22 23 - #define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m)) 24 - 25 23 static const struct wcd_sdw_ch_info wcd938x_sdw_rx_ch_info[] = { 26 24 WCD_SDW_CH(WCD938X_HPH_L, WCD938X_HPH_PORT, BIT(0)), 27 25 WCD_SDW_CH(WCD938X_HPH_R, WCD938X_HPH_PORT, BIT(1)), ··· 140 142 } 141 143 EXPORT_SYMBOL_GPL(wcd938x_sdw_set_sdw_stream); 142 144 143 - static int wcd9380_update_status(struct sdw_slave *slave, 144 - enum sdw_slave_status status) 145 - { 146 - struct wcd938x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 147 - 148 - if (wcd->regmap && (status == SDW_SLAVE_ATTACHED)) { 149 - /* Write out any cached changes that happened between probe and attach */ 150 - regcache_cache_only(wcd->regmap, false); 151 - return regcache_sync(wcd->regmap); 152 - } 153 - 154 - return 0; 155 - } 156 - 157 - static int wcd9380_bus_config(struct sdw_slave *slave, 158 - struct sdw_bus_params *params) 159 - { 160 - sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01); 161 - 162 - return 0; 163 - } 164 - 165 145 static int wcd9380_interrupt_callback(struct sdw_slave *slave, 166 146 struct sdw_slave_intr_status *status) 167 147 { 168 148 struct wcd938x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 169 - struct irq_domain *slave_irq = wcd->slave_irq; 170 - u32 sts1, sts2, sts3; 171 149 172 - do { 173 - handle_nested_irq(irq_find_mapping(slave_irq, 0)); 174 - regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1); 175 - regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2); 176 - regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3); 177 - 178 - } while (sts1 || sts2 || sts3); 179 - 180 - return IRQ_HANDLED; 150 + return wcd_interrupt_callback(slave, wcd->slave_irq, WCD938X_DIGITAL_INTR_STATUS_0, 151 + WCD938X_DIGITAL_INTR_STATUS_1, WCD938X_DIGITAL_INTR_STATUS_2); 181 152 } 182 153 183 154 static const struct reg_default wcd938x_defaults[] = { ··· 1144 1177 }; 1145 1178 1146 1179 static const struct sdw_slave_ops wcd9380_slave_ops = { 1147 - .update_status = wcd9380_update_status, 1180 + .update_status = wcd_update_status, 1148 1181 .interrupt_callback = wcd9380_interrupt_callback, 1149 - .bus_config = wcd9380_bus_config, 1182 + .bus_config = wcd_bus_config, 1150 1183 }; 1151 1184 1152 1185 static int wcd9380_probe(struct sdw_slave *pdev,
+4 -38
sound/soc/codecs/wcd939x-sdw.c
··· 22 22 #include "wcd939x.h" 23 23 #include "wcd-common.h" 24 24 25 - #define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m)) 26 - 27 25 static const struct wcd_sdw_ch_info wcd939x_sdw_rx_ch_info[] = { 28 26 WCD_SDW_CH(WCD939X_HPH_L, WCD939X_HPH_PORT, BIT(0)), 29 27 WCD_SDW_CH(WCD939X_HPH_R, WCD939X_HPH_PORT, BIT(1)), ··· 185 187 } 186 188 EXPORT_SYMBOL_GPL(wcd939x_sdw_set_sdw_stream); 187 189 188 - static int wcd9390_update_status(struct sdw_slave *slave, 189 - enum sdw_slave_status status) 190 - { 191 - struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 192 - 193 - if (wcd->regmap && status == SDW_SLAVE_ATTACHED) { 194 - /* Write out any cached changes that happened between probe and attach */ 195 - regcache_cache_only(wcd->regmap, false); 196 - return regcache_sync(wcd->regmap); 197 - } 198 - 199 - return 0; 200 - } 201 - 202 - static int wcd9390_bus_config(struct sdw_slave *slave, 203 - struct sdw_bus_params *params) 204 - { 205 - sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 206 - 0x01); 207 - 208 - return 0; 209 - } 210 - 211 190 /* 212 191 * Handle Soundwire out-of-band interrupt event by triggering 213 192 * the first irq of the slave_irq irq domain, which then will ··· 195 220 struct sdw_slave_intr_status *status) 196 221 { 197 222 struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 198 - struct irq_domain *slave_irq = wcd->slave_irq; 199 - u32 sts1, sts2, sts3; 200 223 201 - do { 202 - handle_nested_irq(irq_find_mapping(slave_irq, 0)); 203 - regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_0, &sts1); 204 - regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_1, &sts2); 205 - regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_2, &sts3); 206 - 207 - } while (sts1 || sts2 || sts3); 208 - 209 - return IRQ_HANDLED; 224 + return wcd_interrupt_callback(slave, wcd->slave_irq, WCD939X_DIGITAL_INTR_STATUS_0, 225 + WCD939X_DIGITAL_INTR_STATUS_1, WCD939X_DIGITAL_INTR_STATUS_2); 210 226 } 211 227 212 228 static const struct reg_default wcd939x_defaults[] = { ··· 1330 1364 }; 1331 1365 1332 1366 static const struct sdw_slave_ops wcd9390_slave_ops = { 1333 - .update_status = wcd9390_update_status, 1367 + .update_status = wcd_update_status, 1334 1368 .interrupt_callback = wcd9390_interrupt_callback, 1335 - .bus_config = wcd9390_bus_config, 1369 + .bus_config = wcd_bus_config, 1336 1370 }; 1337 1371 1338 1372 static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)