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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: codecs: wcd93xxx: remove code duplication

Merge series from Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>:

All the Qualcomm WCD codecs and WCD based codecs have lots of code in
common, resulting in lot of duplicate code.
This series is an attempt to clean some of this by moving the common
code to wcd-common library or to soundwire helper functions.

Currently I have done cleanups for 4 codecs wcd934x, wcd937x, wcd938x
and wcd939x, however any new Qualcomm codecs can avoid this duplication
by using the wcd-common library.

I have also added two helpers of_sdw_find_device_by_node() and
sdw_slave_get_current_bank() in soundwire layer for the codecs to use them,
this series was already acked by Soundwire maintainer Vinod.

As original cleanup series was depending on the new soundwire interfaces
I have combined both the series as they are cleaning up code
duplications.

As am touching the same codec drivers, 2 bug fixes are also added at the
start of the series.

There is still lot of code that is duplicate, but this is just a
starting point for such cleanups.

I have tested this on T14s, any testing is appreciated.

+359 -582
+12
drivers/soundwire/bus.c
··· 1360 1360 } 1361 1361 EXPORT_SYMBOL(sdw_slave_get_scale_index); 1362 1362 1363 + int sdw_slave_get_current_bank(struct sdw_slave *slave) 1364 + { 1365 + int tmp; 1366 + 1367 + tmp = sdw_read(slave, SDW_SCP_CTRL); 1368 + if (tmp < 0) 1369 + return tmp; 1370 + 1371 + return FIELD_GET(SDW_SCP_STAT_CURR_BANK, tmp); 1372 + } 1373 + EXPORT_SYMBOL_GPL(sdw_slave_get_current_bank); 1374 + 1363 1375 static int sdw_slave_set_frequency(struct sdw_slave *slave) 1364 1376 { 1365 1377 int scale_index;
+6
drivers/soundwire/slave.c
··· 273 273 return 0; 274 274 } 275 275 276 + struct device *of_sdw_find_device_by_node(struct device_node *np) 277 + { 278 + return bus_find_device_by_of_node(&sdw_bus_type, np); 279 + } 280 + EXPORT_SYMBOL_GPL(of_sdw_find_device_by_node); 281 + 276 282 MODULE_IMPORT_NS("SND_SOC_SDCA");
+17
include/linux/soundwire/sdw.h
··· 19 19 20 20 struct dentry; 21 21 struct fwnode_handle; 22 + struct device_node; 22 23 23 24 struct sdw_bus; 24 25 struct sdw_slave; ··· 1087 1086 int sdw_stream_remove_slave(struct sdw_slave *slave, 1088 1087 struct sdw_stream_runtime *stream); 1089 1088 1089 + struct device *of_sdw_find_device_by_node(struct device_node *np); 1090 + 1091 + int sdw_slave_get_current_bank(struct sdw_slave *sdev); 1092 + 1090 1093 int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base); 1091 1094 1092 1095 /* messaging and data APIs */ ··· 1119 1114 1120 1115 static inline int sdw_stream_remove_slave(struct sdw_slave *slave, 1121 1116 struct sdw_stream_runtime *stream) 1117 + { 1118 + WARN_ONCE(1, "SoundWire API is disabled"); 1119 + return -EINVAL; 1120 + } 1121 + 1122 + static inline struct device *of_sdw_find_device_by_node(struct device_node *np) 1123 + { 1124 + WARN_ONCE(1, "SoundWire API is disabled"); 1125 + return NULL; 1126 + } 1127 + 1128 + static inline int sdw_slave_get_current_bank(struct sdw_slave *sdev) 1122 1129 { 1123 1130 WARN_ONCE(1, "SoundWire API is disabled"); 1124 1131 return -EINVAL;
+7
sound/soc/codecs/Kconfig
··· 2274 2274 config SND_SOC_WCD_CLASSH 2275 2275 tristate 2276 2276 2277 + config SND_SOC_WCD_COMMON 2278 + tristate 2279 + 2277 2280 config SND_SOC_WCD9335 2278 2281 tristate "WCD9335 Codec" 2279 2282 depends on SLIMBUS ··· 2298 2295 select REGMAP_IRQ 2299 2296 select REGMAP_SLIMBUS 2300 2297 select SND_SOC_WCD_CLASSH 2298 + select SND_SOC_WCD_COMMON 2301 2299 select SND_SOC_WCD_MBHC 2302 2300 depends on MFD_WCD934X || COMPILE_TEST 2303 2301 help ··· 2310 2306 tristate 2311 2307 depends on SOUNDWIRE || !SOUNDWIRE 2312 2308 select SND_SOC_WCD_CLASSH 2309 + select SND_SOC_WCD_COMMON 2313 2310 2314 2311 config SND_SOC_WCD937X_SDW 2315 2312 tristate "WCD9370/WCD9375 Codec - SDW" ··· 2330 2325 tristate 2331 2326 depends on SOUNDWIRE || !SOUNDWIRE 2332 2327 select SND_SOC_WCD_CLASSH 2328 + select SND_SOC_WCD_COMMON 2333 2329 select MULTIPLEXER 2334 2330 2335 2331 config SND_SOC_WCD938X_SDW ··· 2350 2344 depends on SOUNDWIRE || !SOUNDWIRE 2351 2345 depends on TYPEC || !TYPEC 2352 2346 select SND_SOC_WCD_CLASSH 2347 + select SND_SOC_WCD_COMMON 2353 2348 2354 2349 config SND_SOC_WCD939X_SDW 2355 2350 tristate "WCD9390/WCD9395 Codec - SDW"
+2
sound/soc/codecs/Makefile
··· 344 344 snd-soc-uda1342-y := uda1342.o 345 345 snd-soc-uda1380-y := uda1380.o 346 346 snd-soc-wcd-classh-y := wcd-clsh-v2.o 347 + snd-soc-wcd-common-y := wcd-common.o 347 348 snd-soc-wcd-mbhc-y := wcd-mbhc-v2.o 348 349 snd-soc-wcd9335-y := wcd9335.o 349 350 snd-soc-wcd934x-y := wcd934x.o ··· 775 774 obj-$(CONFIG_SND_SOC_UDA1342) += snd-soc-uda1342.o 776 775 obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o 777 776 obj-$(CONFIG_SND_SOC_WCD_CLASSH) += snd-soc-wcd-classh.o 777 + obj-$(CONFIG_SND_SOC_WCD_COMMON) += snd-soc-wcd-common.o 778 778 obj-$(CONFIG_SND_SOC_WCD_MBHC) += snd-soc-wcd-mbhc.o 779 779 obj-$(CONFIG_SND_SOC_WCD9335) += snd-soc-wcd9335.o 780 780 obj-$(CONFIG_SND_SOC_WCD934X) += snd-soc-wcd934x.o
+143
sound/soc/codecs/wcd-common.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // Copyright (c) 2025, Qualcomm Technologies, Inc. and/or its subsidiaries. 3 + 4 + #include <linux/export.h> 5 + #include <linux/module.h> 6 + #include <linux/init.h> 7 + #include <linux/device.h> 8 + #include <linux/of.h> 9 + #include <linux/printk.h> 10 + #include <linux/component.h> 11 + #include <linux/pm_runtime.h> 12 + #include <linux/soundwire/sdw.h> 13 + #include <linux/soundwire/sdw_type.h> 14 + #include <linux/regmap.h> 15 + 16 + #include "wcd-common.h" 17 + 18 + #define WCD_MIN_MICBIAS_MV 1000 19 + #define WCD_DEF_MICBIAS_MV 1800 20 + #define WCD_MAX_MICBIAS_MV 2850 21 + 22 + #define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m)) 23 + 24 + int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv) 25 + { 26 + /* min micbias voltage is 1V and maximum is 2.85V */ 27 + if (micb_mv < WCD_MIN_MICBIAS_MV || micb_mv > WCD_MAX_MICBIAS_MV) { 28 + dev_err(dev, "Unsupported micbias voltage (%u mV)\n", micb_mv); 29 + return -EINVAL; 30 + } 31 + 32 + return (micb_mv - WCD_MIN_MICBIAS_MV) / 50; 33 + } 34 + EXPORT_SYMBOL_GPL(wcd_get_micb_vout_ctl_val); 35 + 36 + static int wcd_get_micbias_val(struct device *dev, int micb_num, u32 *micb_mv) 37 + { 38 + char micbias[64]; 39 + int mv; 40 + 41 + sprintf(micbias, "qcom,micbias%d-microvolt", micb_num); 42 + 43 + if (of_property_read_u32(dev->of_node, micbias, &mv)) { 44 + dev_err(dev, "%s value not found, using default\n", micbias); 45 + mv = WCD_DEF_MICBIAS_MV; 46 + } else { 47 + /* convert it to milli volts */ 48 + mv = mv/1000; 49 + } 50 + if (micb_mv) 51 + *micb_mv = mv; 52 + 53 + mv = wcd_get_micb_vout_ctl_val(dev, mv); 54 + if (mv < 0) { 55 + dev_err(dev, "Unsupported %s voltage (%d mV), falling back to default (%d mV)\n", 56 + micbias, mv, WCD_DEF_MICBIAS_MV); 57 + return wcd_get_micb_vout_ctl_val(dev, WCD_DEF_MICBIAS_MV); 58 + } 59 + 60 + return mv; 61 + } 62 + 63 + int wcd_dt_parse_micbias_info(struct wcd_common *common) 64 + { 65 + int i; 66 + 67 + for (i = 0; i < common->max_bias; i++) { 68 + common->micb_vout[i] = wcd_get_micbias_val(common->dev, i + 1, &common->micb_mv[i]); 69 + if (common->micb_vout[i] < 0) 70 + return -EINVAL; 71 + } 72 + 73 + return 0; 74 + } 75 + EXPORT_SYMBOL_GPL(wcd_dt_parse_micbias_info); 76 + 77 + static int wcd_sdw_component_bind(struct device *dev, struct device *master, void *data) 78 + { 79 + pm_runtime_set_autosuspend_delay(dev, 3000); 80 + pm_runtime_use_autosuspend(dev); 81 + pm_runtime_mark_last_busy(dev); 82 + pm_runtime_set_active(dev); 83 + pm_runtime_enable(dev); 84 + 85 + return 0; 86 + } 87 + 88 + static void wcd_sdw_component_unbind(struct device *dev, struct device *master, void *data) 89 + { 90 + pm_runtime_disable(dev); 91 + pm_runtime_set_suspended(dev); 92 + pm_runtime_dont_use_autosuspend(dev); 93 + } 94 + 95 + const struct component_ops wcd_sdw_component_ops = { 96 + .bind = wcd_sdw_component_bind, 97 + .unbind = wcd_sdw_component_unbind, 98 + }; 99 + EXPORT_SYMBOL_GPL(wcd_sdw_component_ops); 100 + 101 + int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status) 102 + { 103 + struct regmap *regmap = dev_get_regmap(&slave->dev, NULL); 104 + 105 + if (regmap && status == SDW_SLAVE_ATTACHED) { 106 + /* Write out any cached changes that happened between probe and attach */ 107 + regcache_cache_only(regmap, false); 108 + return regcache_sync(regmap); 109 + } 110 + 111 + return 0; 112 + } 113 + EXPORT_SYMBOL_GPL(wcd_update_status); 114 + 115 + int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params) 116 + { 117 + sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01); 118 + 119 + return 0; 120 + } 121 + EXPORT_SYMBOL_GPL(wcd_bus_config); 122 + 123 + int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq, 124 + unsigned int wcd_intr_status0, unsigned int wcd_intr_status1, 125 + unsigned int wcd_intr_status2) 126 + { 127 + struct regmap *regmap = dev_get_regmap(&slave->dev, NULL); 128 + u32 sts1, sts2, sts3; 129 + 130 + do { 131 + handle_nested_irq(irq_find_mapping(slave_irq, 0)); 132 + regmap_read(regmap, wcd_intr_status0, &sts1); 133 + regmap_read(regmap, wcd_intr_status1, &sts2); 134 + regmap_read(regmap, wcd_intr_status2, &sts3); 135 + 136 + } while (sts1 || sts2 || sts3); 137 + 138 + return IRQ_HANDLED; 139 + } 140 + EXPORT_SYMBOL_GPL(wcd_interrupt_callback); 141 + 142 + MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver"); 143 + MODULE_LICENSE("GPL");
+46
sound/soc/codecs/wcd-common.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (c) 2025, Qualcomm Technologies, Inc. and/or its subsidiaries. 4 + */ 5 + 6 + #ifndef __WCD_COMMON_H__ 7 + #define __WCD_COMMON_H__ 8 + 9 + struct device; 10 + struct sdw_slave; 11 + struct sdw_bus_params; 12 + struct irq_domain; 13 + enum sdw_slave_status; 14 + 15 + #define WCD_MAX_MICBIAS 4 16 + 17 + struct wcd_sdw_ch_info { 18 + int port_num; 19 + unsigned int ch_mask; 20 + unsigned int master_ch_mask; 21 + }; 22 + 23 + #define WCD_SDW_CH(id, pn, cmask) \ 24 + [id] = { \ 25 + .port_num = pn, \ 26 + .ch_mask = cmask, \ 27 + .master_ch_mask = cmask, \ 28 + } 29 + 30 + struct wcd_common { 31 + struct device *dev; 32 + int max_bias; 33 + u32 micb_mv[WCD_MAX_MICBIAS]; 34 + u32 micb_vout[WCD_MAX_MICBIAS]; 35 + }; 36 + 37 + extern const struct component_ops wcd_sdw_component_ops; 38 + int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv); 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); 45 + 46 + #endif /* __WCD_COMMON_H__ */
+23 -59
sound/soc/codecs/wcd934x.c
··· 21 21 #include <sound/soc-dapm.h> 22 22 #include <sound/tlv.h> 23 23 #include "wcd-clsh-v2.h" 24 + #include "wcd-common.h" 24 25 #include "wcd-mbhc-v2.h" 25 26 26 27 #include <dt-bindings/sound/qcom,wcd934x.h> ··· 116 115 #define WCD934X_DEC_PWR_LVL_HP 0x04 117 116 #define WCD934X_DEC_PWR_LVL_DF 0x00 118 117 #define WCD934X_DEC_PWR_LVL_HYBRID WCD934X_DEC_PWR_LVL_DF 119 - 120 - #define WCD934X_DEF_MICBIAS_MV 1800 121 - #define WCD934X_MAX_MICBIAS_MV 2850 122 118 123 119 #define WCD_IIR_FILTER_SIZE (sizeof(u32) * BAND_MAX) 124 120 ··· 528 530 struct slim_device *sdev; 529 531 struct slim_device *sidev; 530 532 struct wcd_clsh_ctrl *clsh_ctrl; 533 + struct wcd_common common; 531 534 struct snd_soc_component *component; 532 535 struct wcd934x_slim_ch rx_chs[WCD934X_RX_MAX]; 533 536 struct wcd934x_slim_ch tx_chs[WCD934X_TX_MAX]; ··· 554 555 struct mutex micb_lock; 555 556 u32 micb_ref[WCD934X_MAX_MICBIAS]; 556 557 u32 pullup_ref[WCD934X_MAX_MICBIAS]; 557 - u32 micb2_mv; 558 558 }; 559 559 560 560 #define to_wcd934x_codec(_hw) container_of(_hw, struct wcd934x_codec, hw) ··· 2166 2168 return NULL; 2167 2169 } 2168 2170 2169 - static int wcd934x_get_micbias_val(struct device *dev, const char *micbias, 2170 - u32 *micb_mv) 2171 - { 2172 - int mv; 2173 - 2174 - if (of_property_read_u32(dev->parent->of_node, micbias, &mv)) { 2175 - dev_err(dev, "%s value not found, using default\n", micbias); 2176 - mv = WCD934X_DEF_MICBIAS_MV; 2177 - } else { 2178 - /* convert it to milli volts */ 2179 - mv = mv/1000; 2180 - } 2181 - 2182 - if (mv < 1000 || mv > 2850) { 2183 - dev_err(dev, "%s value not in valid range, using default\n", 2184 - micbias); 2185 - mv = WCD934X_DEF_MICBIAS_MV; 2186 - } 2187 - 2188 - if (micb_mv) 2189 - *micb_mv = mv; 2190 - 2191 - return (mv - 1000) / 50; 2192 - } 2193 - 2194 2171 static int wcd934x_init_dmic(struct snd_soc_component *comp) 2195 2172 { 2196 - int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; 2197 2173 struct wcd934x_codec *wcd = dev_get_drvdata(comp->dev); 2198 2174 u32 def_dmic_rate, dmic_clk_drv; 2175 + int ret; 2199 2176 2200 - vout_ctl_1 = wcd934x_get_micbias_val(comp->dev, 2201 - "qcom,micbias1-microvolt", NULL); 2202 - vout_ctl_2 = wcd934x_get_micbias_val(comp->dev, 2203 - "qcom,micbias2-microvolt", 2204 - &wcd->micb2_mv); 2205 - vout_ctl_3 = wcd934x_get_micbias_val(comp->dev, 2206 - "qcom,micbias3-microvolt", NULL); 2207 - vout_ctl_4 = wcd934x_get_micbias_val(comp->dev, 2208 - "qcom,micbias4-microvolt", NULL); 2177 + ret = wcd_dt_parse_mbhc_data(comp->dev, &wcd->mbhc_cfg); 2178 + if (ret) 2179 + return ret; 2209 2180 2210 2181 snd_soc_component_update_bits(comp, WCD934X_ANA_MICB1, 2211 - WCD934X_MICB_VAL_MASK, vout_ctl_1); 2182 + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[0]); 2212 2183 snd_soc_component_update_bits(comp, WCD934X_ANA_MICB2, 2213 - WCD934X_MICB_VAL_MASK, vout_ctl_2); 2184 + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[1]); 2214 2185 snd_soc_component_update_bits(comp, WCD934X_ANA_MICB3, 2215 - WCD934X_MICB_VAL_MASK, vout_ctl_3); 2186 + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[2]); 2216 2187 snd_soc_component_update_bits(comp, WCD934X_ANA_MICB4, 2217 - WCD934X_MICB_VAL_MASK, vout_ctl_4); 2188 + WCD934X_MICB_VAL_MASK, wcd->common.micb_vout[3]); 2218 2189 2219 2190 if (wcd->rate == WCD934X_MCLK_CLK_9P6MHZ) 2220 2191 def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ; ··· 2484 2517 } 2485 2518 } 2486 2519 2487 - static int wcd934x_get_micb_vout_ctl_val(u32 micb_mv) 2488 - { 2489 - /* min micbias voltage is 1V and maximum is 2.85V */ 2490 - if (micb_mv < 1000 || micb_mv > 2850) 2491 - return -EINVAL; 2492 - 2493 - return (micb_mv - 1000) / 50; 2494 - } 2495 - 2496 2520 static int wcd934x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, 2497 2521 int req_volt, int micb_num) 2498 2522 { ··· 2520 2562 cur_vout_ctl = snd_soc_component_read_field(component, micb_reg, 2521 2563 WCD934X_MICB_VAL_MASK); 2522 2564 2523 - req_vout_ctl = wcd934x_get_micb_vout_ctl_val(req_volt); 2565 + req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt); 2524 2566 if (req_vout_ctl < 0) { 2525 2567 ret = -EINVAL; 2526 2568 goto exit; ··· 2568 2610 * voltage needed to detect threshold microphone, then do 2569 2611 * not change the micbias, just return. 2570 2612 */ 2571 - if (wcd934x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) 2613 + if (wcd934x->common.micb_mv[1] >= WCD_MBHC_THR_HS_MICB_MV) 2572 2614 return 0; 2573 2615 2574 - micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd934x->micb2_mv; 2616 + micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd934x->common.micb_mv[1]; 2575 2617 2576 2618 rc = wcd934x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); 2577 2619 ··· 2994 3036 static int wcd934x_comp_probe(struct snd_soc_component *component) 2995 3037 { 2996 3038 struct wcd934x_codec *wcd = dev_get_drvdata(component->dev); 2997 - int i; 3039 + int i, ret; 2998 3040 2999 3041 snd_soc_component_init_regmap(component, wcd->regmap); 3000 3042 wcd->component = component; ··· 3012 3054 for (i = 0; i < NUM_CODEC_DAIS; i++) 3013 3055 INIT_LIST_HEAD(&wcd->dai[i].slim_ch_list); 3014 3056 3015 - wcd934x_init_dmic(component); 3057 + 3058 + ret = wcd934x_init_dmic(component); 3059 + if (ret) { 3060 + dev_err(component->dev, "Failed to Initialize micbias\n"); 3061 + return ret; 3062 + } 3016 3063 3017 3064 if (wcd934x_mbhc_init(component)) 3018 3065 dev_err(component->dev, "Failed to Initialize MBHC\n"); ··· 5823 5860 cfg->anc_micbias = MIC_BIAS_2; 5824 5861 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 5825 5862 cfg->num_btn = WCD934X_MBHC_MAX_BUTTONS; 5826 - cfg->micb_mv = wcd->micb2_mv; 5863 + cfg->micb_mv = wcd->common.micb_mv[1]; 5827 5864 cfg->linein_th = 5000; 5828 5865 cfg->hs_thr = 1700; 5829 5866 cfg->hph_thr = 50; 5830 5867 5831 5868 wcd_dt_parse_mbhc_data(dev, cfg); 5832 - 5833 5869 5834 5870 return 0; 5835 5871 } ··· 5850 5888 wcd->sdev = to_slim_device(data->dev); 5851 5889 mutex_init(&wcd->sysclk_mutex); 5852 5890 mutex_init(&wcd->micb_lock); 5891 + wcd->common.dev = dev->parent; 5892 + wcd->common.max_bias = 4; 5853 5893 5854 5894 ret = wcd934x_codec_parse_data(wcd); 5855 5895 if (ret)
+7 -60
sound/soc/codecs/wcd937x-sdw.c
··· 19 19 #include <sound/soc.h> 20 20 #include "wcd937x.h" 21 21 22 - static struct wcd937x_sdw_ch_info wcd937x_sdw_rx_ch_info[] = { 22 + static struct wcd_sdw_ch_info wcd937x_sdw_rx_ch_info[] = { 23 23 WCD_SDW_CH(WCD937X_HPH_L, WCD937X_HPH_PORT, BIT(0)), 24 24 WCD_SDW_CH(WCD937X_HPH_R, WCD937X_HPH_PORT, BIT(1)), 25 25 WCD_SDW_CH(WCD937X_CLSH, WCD937X_CLSH_PORT, BIT(0)), ··· 30 30 WCD_SDW_CH(WCD937X_DSD_R, WCD937X_DSD_PORT, BIT(1)), 31 31 }; 32 32 33 - static struct wcd937x_sdw_ch_info wcd937x_sdw_tx_ch_info[] = { 33 + static struct wcd_sdw_ch_info wcd937x_sdw_tx_ch_info[] = { 34 34 WCD_SDW_CH(WCD937X_ADC1, WCD937X_ADC_1_PORT, BIT(0)), 35 35 WCD_SDW_CH(WCD937X_ADC2, WCD937X_ADC_2_3_PORT, BIT(0)), 36 36 WCD_SDW_CH(WCD937X_ADC3, WCD937X_ADC_2_3_PORT, BIT(0)), ··· 78 78 } 79 79 }; 80 80 81 - struct device *wcd937x_sdw_device_get(struct device_node *np) 82 - { 83 - return bus_find_device_by_of_node(&sdw_bus_type, np); 84 - } 85 - EXPORT_SYMBOL_GPL(wcd937x_sdw_device_get); 86 - 87 81 int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, 88 82 struct snd_pcm_substream *substream, 89 83 struct snd_pcm_hw_params *params, ··· 112 118 } 113 119 EXPORT_SYMBOL_GPL(wcd937x_sdw_hw_params); 114 120 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 121 /* 129 122 * Handle Soundwire out-of-band interrupt event by triggering 130 123 * the first irq of the slave_irq irq domain, which then will ··· 122 141 struct sdw_slave_intr_status *status) 123 142 { 124 143 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 144 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; 145 + return wcd_interrupt_callback(slave, wcd->slave_irq, WCD937X_DIGITAL_INTR_STATUS_0, 146 + WCD937X_DIGITAL_INTR_STATUS_1, WCD937X_DIGITAL_INTR_STATUS_2); 137 147 } 138 148 139 149 static const struct reg_default wcd937x_defaults[] = { ··· 957 985 }; 958 986 959 987 static const struct sdw_slave_ops wcd9370_slave_ops = { 960 - .update_status = wcd9370_update_status, 988 + .update_status = wcd_update_status, 961 989 .interrupt_callback = wcd9370_interrupt_callback, 962 - }; 963 - 964 - static int wcd937x_sdw_component_bind(struct device *dev, 965 - struct device *master, void *data) 966 - { 967 - pm_runtime_set_autosuspend_delay(dev, 3000); 968 - pm_runtime_use_autosuspend(dev); 969 - pm_runtime_mark_last_busy(dev); 970 - pm_runtime_set_active(dev); 971 - pm_runtime_enable(dev); 972 - 973 - return 0; 974 - } 975 - 976 - static void wcd937x_sdw_component_unbind(struct device *dev, 977 - struct device *master, void *data) 978 - { 979 - pm_runtime_disable(dev); 980 - pm_runtime_set_suspended(dev); 981 - pm_runtime_dont_use_autosuspend(dev); 982 - } 983 - 984 - static const struct component_ops wcd937x_sdw_component_ops = { 985 - .bind = wcd937x_sdw_component_bind, 986 - .unbind = wcd937x_sdw_component_unbind, 987 990 }; 988 991 989 992 static int wcd9370_probe(struct sdw_slave *pdev, ··· 1046 1099 } 1047 1100 1048 1101 1049 - ret = component_add(dev, &wcd937x_sdw_component_ops); 1102 + ret = component_add(dev, &wcd_sdw_component_ops); 1050 1103 if (ret) 1051 1104 return ret; 1052 1105 ··· 1060 1113 { 1061 1114 struct device *dev = &pdev->dev; 1062 1115 1063 - component_del(dev, &wcd937x_sdw_component_ops); 1116 + component_del(dev, &wcd_sdw_component_ops); 1064 1117 1065 1118 return 0; 1066 1119 }
+25 -68
sound/soc/codecs/wcd937x.c
··· 21 21 #include <sound/tlv.h> 22 22 23 23 #include "wcd-clsh-v2.h" 24 + #include "wcd-common.h" 24 25 #include "wcd-mbhc-v2.h" 25 26 #include "wcd937x.h" 26 27 ··· 86 85 struct wcd_mbhc_config mbhc_cfg; 87 86 struct wcd_mbhc_intr intr_ids; 88 87 struct wcd_clsh_ctrl *clsh_info; 88 + struct wcd_common common; 89 89 struct irq_domain *virq; 90 90 struct regmap_irq_chip_data *irq_chip; 91 91 struct snd_soc_jack *jack; ··· 95 93 s32 pullup_ref[WCD937X_MAX_MICBIAS]; 96 94 u32 hph_mode; 97 95 int ear_rx_path; 98 - u32 micb1_mv; 99 - u32 micb2_mv; 100 - u32 micb3_mv; 101 96 int hphr_pdm_wd_int; 102 97 int hphl_pdm_wd_int; 103 98 int aux_pdm_wd_int; ··· 871 872 return 0; 872 873 } 873 874 874 - static int wcd937x_get_micb_vout_ctl_val(u32 micb_mv) 875 - { 876 - if (micb_mv < 1000 || micb_mv > 2850) { 877 - pr_err("Unsupported micbias voltage (%u mV)\n", micb_mv); 878 - return -EINVAL; 879 - } 880 - 881 - return (micb_mv - 1000) / 50; 882 - } 883 875 884 876 static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w, 885 877 struct snd_kcontrol *kcontrol, int event) ··· 1183 1193 static int wcd937x_connect_port(struct wcd937x_sdw_priv *wcd, u8 port_idx, u8 ch_id, bool enable) 1184 1194 { 1185 1195 struct sdw_port_config *port_config = &wcd->port_config[port_idx - 1]; 1186 - const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id]; 1196 + const struct wcd_sdw_ch_info *ch_info = &wcd->ch_info[ch_id]; 1187 1197 u8 port_num = ch_info->port_num; 1188 1198 u8 ch_mask = ch_info->ch_mask; 1189 1199 u8 mstr_port_num, mstr_ch_mask; ··· 1471 1481 cur_vout_ctl = snd_soc_component_read_field(component, micb_reg, 1472 1482 WCD937X_MICB_VOUT_MASK); 1473 1483 1474 - req_vout_ctl = wcd937x_get_micb_vout_ctl_val(req_volt); 1484 + req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt); 1475 1485 if (req_vout_ctl < 0) { 1476 1486 ret = -EINVAL; 1477 1487 goto exit; ··· 1519 1529 * voltage needed to detect threshold microphone, then do 1520 1530 * not change the micbias, just return. 1521 1531 */ 1522 - if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) 1532 + if (wcd937x->common.micb_mv[2] >= WCD_MBHC_THR_HS_MICB_MV) 1523 1533 return 0; 1524 1534 1525 - micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv; 1535 + micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->common.micb_mv[2]; 1526 1536 1527 1537 return wcd937x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); 1528 1538 } ··· 2036 2046 SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum, 2037 2047 wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put), 2038 2048 2039 - SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0, 2049 + SOC_SINGLE_EXT("HPHL_COMP Switch", WCD937X_COMP_L, 0, 1, 0, 2040 2050 wcd937x_get_compander, wcd937x_set_compander), 2041 - SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0, 2051 + SOC_SINGLE_EXT("HPHR_COMP Switch", WCD937X_COMP_R, 1, 1, 0, 2042 2052 wcd937x_get_compander, wcd937x_set_compander), 2043 2053 2044 2054 SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain), ··· 2426 2436 { "DMIC6_MIXER", "Switch", "DMIC6" }, 2427 2437 }; 2428 2438 2429 - static int wcd937x_set_micbias_data(struct wcd937x_priv *wcd937x) 2439 + static void wcd937x_set_micbias_data(struct device *dev, struct wcd937x_priv *wcd937x) 2430 2440 { 2431 - int vout_ctl[3]; 2432 - 2433 - /* Set micbias voltage */ 2434 - vout_ctl[0] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb1_mv); 2435 - vout_ctl[1] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb2_mv); 2436 - vout_ctl[2] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb3_mv); 2437 - if ((vout_ctl[0] | vout_ctl[1] | vout_ctl[2]) < 0) 2438 - return -EINVAL; 2439 - 2440 - regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT, vout_ctl[0]); 2441 - regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT, vout_ctl[1]); 2442 - regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT, vout_ctl[2]); 2443 - 2444 - return 0; 2441 + regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT, 2442 + wcd937x->common.micb_vout[0]); 2443 + regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT, 2444 + wcd937x->common.micb_vout[1]); 2445 + regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT, 2446 + wcd937x->common.micb_vout[2]); 2445 2447 } 2446 2448 2447 2449 static irqreturn_t wcd937x_wd_handle_irq(int irq, void *data) ··· 2612 2630 .endianness = 1, 2613 2631 }; 2614 2632 2615 - static void wcd937x_dt_parse_micbias_info(struct device *dev, struct wcd937x_priv *wcd) 2616 - { 2617 - struct device_node *np = dev->of_node; 2618 - u32 prop_val = 0; 2619 - int ret = 0; 2620 - 2621 - ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); 2622 - if (!ret) 2623 - wcd->micb1_mv = prop_val / 1000; 2624 - else 2625 - dev_warn(dev, "Micbias1 DT property not found\n"); 2626 - 2627 - ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); 2628 - if (!ret) 2629 - wcd->micb2_mv = prop_val / 1000; 2630 - else 2631 - dev_warn(dev, "Micbias2 DT property not found\n"); 2632 - 2633 - ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); 2634 - if (!ret) 2635 - wcd->micb3_mv = prop_val / 1000; 2636 - else 2637 - dev_warn(dev, "Micbias3 DT property not found\n"); 2638 - } 2639 - 2640 2633 static bool wcd937x_swap_gnd_mic(struct snd_soc_component *component) 2641 2634 { 2642 2635 int value; ··· 2745 2788 return ret; 2746 2789 } 2747 2790 2748 - wcd937x->rxdev = wcd937x_sdw_device_get(wcd937x->rxnode); 2791 + wcd937x->rxdev = of_sdw_find_device_by_node(wcd937x->rxnode); 2749 2792 if (!wcd937x->rxdev) { 2750 2793 dev_err(dev, "could not find slave with matching of node\n"); 2751 2794 return -EINVAL; ··· 2754 2797 wcd937x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd937x->rxdev); 2755 2798 wcd937x->sdw_priv[AIF1_PB]->wcd937x = wcd937x; 2756 2799 2757 - wcd937x->txdev = wcd937x_sdw_device_get(wcd937x->txnode); 2800 + wcd937x->txdev = of_sdw_find_device_by_node(wcd937x->txnode); 2758 2801 if (!wcd937x->txdev) { 2759 2802 dev_err(dev, "could not find txslave with matching of node\n"); 2760 2803 return -EINVAL; ··· 2790 2833 return -EINVAL; 2791 2834 } 2792 2835 2793 - wcd937x->regmap = dev_get_regmap(&wcd937x->tx_sdw_dev->dev, NULL); 2836 + wcd937x->regmap = wcd937x->sdw_priv[AIF1_CAP]->regmap; 2794 2837 if (!wcd937x->regmap) { 2795 2838 dev_err(dev, "could not get TX device regmap\n"); 2796 2839 return -EINVAL; ··· 2805 2848 wcd937x->sdw_priv[AIF1_PB]->slave_irq = wcd937x->virq; 2806 2849 wcd937x->sdw_priv[AIF1_CAP]->slave_irq = wcd937x->virq; 2807 2850 2808 - ret = wcd937x_set_micbias_data(wcd937x); 2809 - if (ret < 0) { 2810 - dev_err(dev, "Bad micbias pdata\n"); 2811 - return ret; 2812 - } 2851 + wcd937x_set_micbias_data(dev, wcd937x); 2813 2852 2814 2853 ret = snd_soc_register_component(dev, &soc_codec_dev_wcd937x, 2815 2854 wcd937x_dais, ARRAY_SIZE(wcd937x_dais)); ··· 2873 2920 2874 2921 dev_set_drvdata(dev, wcd937x); 2875 2922 mutex_init(&wcd937x->micb_lock); 2923 + wcd937x->common.dev = dev; 2924 + wcd937x->common.max_bias = 3; 2876 2925 2877 2926 wcd937x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); 2878 2927 if (IS_ERR(wcd937x->reset_gpio)) ··· 2894 2939 if (ret) 2895 2940 return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); 2896 2941 2897 - wcd937x_dt_parse_micbias_info(dev, wcd937x); 2942 + ret = wcd_dt_parse_micbias_info(&wcd937x->common); 2943 + if (ret) 2944 + return dev_err_probe(dev, ret, "Failed to get micbias\n"); 2898 2945 2899 2946 cfg->mbhc_micbias = MIC_BIAS_2; 2900 2947 cfg->anc_micbias = MIC_BIAS_2; 2901 2948 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 2902 2949 cfg->num_btn = WCD937X_MBHC_MAX_BUTTONS; 2903 - cfg->micb_mv = wcd937x->micb2_mv; 2950 + cfg->micb_mv = wcd937x->common.micb_mv[2]; 2904 2951 cfg->linein_th = 5000; 2905 2952 cfg->hs_thr = 1700; 2906 2953 cfg->hph_thr = 50;
+5 -19
sound/soc/codecs/wcd937x.h
··· 7 7 8 8 #include <linux/soundwire/sdw.h> 9 9 #include <linux/soundwire/sdw_type.h> 10 + #include "wcd-common.h" 10 11 11 12 #define WCD937X_BASE_ADDRESS 0x3000 12 13 #define WCD937X_ANA_BIAS 0x3001 ··· 508 507 WCD937X_MAX_SWR_PORTS = WCD937X_DSD_PORT, 509 508 }; 510 509 511 - struct wcd937x_sdw_ch_info { 512 - int port_num; 513 - unsigned int ch_mask; 514 - unsigned int master_ch_mask; 515 - }; 516 - 517 - #define WCD_SDW_CH(id, pn, cmask) \ 518 - [id] = { \ 519 - .port_num = pn, \ 520 - .ch_mask = cmask, \ 521 - .master_ch_mask = cmask, \ 522 - } 523 - 524 510 struct wcd937x_priv; 525 511 struct wcd937x_sdw_priv { 526 512 struct sdw_slave *sdev; 527 513 struct sdw_stream_config sconfig; 528 514 struct sdw_stream_runtime *sruntime; 529 515 struct sdw_port_config port_config[WCD937X_MAX_SWR_PORTS]; 530 - struct wcd937x_sdw_ch_info *ch_info; 516 + struct wcd_sdw_ch_info *ch_info; 531 517 bool port_enable[WCD937X_MAX_SWR_CH_IDS]; 532 518 unsigned int master_channel_map[SDW_MAX_PORTS]; 533 519 int active_ports; ··· 537 549 struct snd_pcm_hw_params *params, 538 550 struct snd_soc_dai *dai); 539 551 540 - struct device *wcd937x_sdw_device_get(struct device_node *np); 541 - 542 552 #else 543 - int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd, 553 + static inline int wcd937x_sdw_free(struct wcd937x_sdw_priv *wcd, 544 554 struct snd_pcm_substream *substream, 545 555 struct snd_soc_dai *dai) 546 556 { 547 557 return -EOPNOTSUPP; 548 558 } 549 559 550 - int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd, 560 + static inline int wcd937x_sdw_set_sdw_stream(struct wcd937x_sdw_priv *wcd, 551 561 struct snd_soc_dai *dai, 552 562 void *stream, int direction) 553 563 { 554 564 return -EOPNOTSUPP; 555 565 } 556 566 557 - int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, 567 + static inline int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd, 558 568 struct snd_pcm_substream *substream, 559 569 struct snd_pcm_hw_params *params, 560 570 struct snd_soc_dai *dai)
+9 -74
sound/soc/codecs/wcd938x-sdw.c
··· 18 18 #include <sound/soc.h> 19 19 #include <sound/soc-dapm.h> 20 20 #include "wcd938x.h" 21 + #include "wcd-common.h" 21 22 22 - #define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m)) 23 - 24 - static const struct wcd938x_sdw_ch_info wcd938x_sdw_rx_ch_info[] = { 23 + static const struct wcd_sdw_ch_info wcd938x_sdw_rx_ch_info[] = { 25 24 WCD_SDW_CH(WCD938X_HPH_L, WCD938X_HPH_PORT, BIT(0)), 26 25 WCD_SDW_CH(WCD938X_HPH_R, WCD938X_HPH_PORT, BIT(1)), 27 26 WCD_SDW_CH(WCD938X_CLSH, WCD938X_CLSH_PORT, BIT(0)), ··· 31 32 WCD_SDW_CH(WCD938X_DSD_R, WCD938X_DSD_PORT, BIT(1)), 32 33 }; 33 34 34 - static const struct wcd938x_sdw_ch_info wcd938x_sdw_tx_ch_info[] = { 35 + static const struct wcd_sdw_ch_info wcd938x_sdw_tx_ch_info[] = { 35 36 WCD_SDW_CH(WCD938X_ADC1, WCD938X_ADC_1_2_PORT, BIT(0)), 36 37 WCD_SDW_CH(WCD938X_ADC2, WCD938X_ADC_1_2_PORT, BIT(1)), 37 38 WCD_SDW_CH(WCD938X_ADC3, WCD938X_ADC_3_4_PORT, BIT(0)), ··· 80 81 .simple_ch_prep_sm = true, 81 82 } 82 83 }; 83 - 84 - struct device *wcd938x_sdw_device_get(struct device_node *np) 85 - { 86 - return bus_find_device_by_of_node(&sdw_bus_type, np); 87 - 88 - } 89 - EXPORT_SYMBOL_GPL(wcd938x_sdw_device_get); 90 - 91 - int wcd938x_swr_get_current_bank(struct sdw_slave *sdev) 92 - { 93 - int bank; 94 - 95 - bank = sdw_read(sdev, SDW_SCP_CTRL); 96 - 97 - return ((bank & 0x40) ? 1 : 0); 98 - } 99 - EXPORT_SYMBOL_GPL(wcd938x_swr_get_current_bank); 100 84 101 85 int wcd938x_sdw_hw_params(struct wcd938x_sdw_priv *wcd, 102 86 struct snd_pcm_substream *substream, ··· 140 158 } 141 159 EXPORT_SYMBOL_GPL(wcd938x_sdw_set_sdw_stream); 142 160 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 161 static int wcd9380_interrupt_callback(struct sdw_slave *slave, 166 162 struct sdw_slave_intr_status *status) 167 163 { 168 164 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 165 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; 166 + return wcd_interrupt_callback(slave, wcd->slave_irq, WCD938X_DIGITAL_INTR_STATUS_0, 167 + WCD938X_DIGITAL_INTR_STATUS_1, WCD938X_DIGITAL_INTR_STATUS_2); 181 168 } 182 169 183 170 static const struct reg_default wcd938x_defaults[] = { ··· 1144 1193 }; 1145 1194 1146 1195 static const struct sdw_slave_ops wcd9380_slave_ops = { 1147 - .update_status = wcd9380_update_status, 1196 + .update_status = wcd_update_status, 1148 1197 .interrupt_callback = wcd9380_interrupt_callback, 1149 - .bus_config = wcd9380_bus_config, 1150 - }; 1151 - 1152 - static int wcd938x_sdw_component_bind(struct device *dev, 1153 - struct device *master, void *data) 1154 - { 1155 - return 0; 1156 - } 1157 - 1158 - static void wcd938x_sdw_component_unbind(struct device *dev, 1159 - struct device *master, void *data) 1160 - { 1161 - } 1162 - 1163 - static const struct component_ops wcd938x_sdw_component_ops = { 1164 - .bind = wcd938x_sdw_component_bind, 1165 - .unbind = wcd938x_sdw_component_unbind, 1198 + .bus_config = wcd_bus_config, 1166 1199 }; 1167 1200 1168 1201 static int wcd9380_probe(struct sdw_slave *pdev, ··· 1213 1278 pm_runtime_set_active(dev); 1214 1279 pm_runtime_enable(dev); 1215 1280 1216 - ret = component_add(dev, &wcd938x_sdw_component_ops); 1281 + ret = component_add(dev, &wcd_sdw_component_ops); 1217 1282 if (ret) 1218 1283 goto err_disable_rpm; 1219 1284 ··· 1231 1296 { 1232 1297 struct device *dev = &pdev->dev; 1233 1298 1234 - component_del(dev, &wcd938x_sdw_component_ops); 1299 + component_del(dev, &wcd_sdw_component_ops); 1235 1300 1236 1301 pm_runtime_disable(dev); 1237 1302 pm_runtime_set_suspended(dev);
+22 -77
sound/soc/codecs/wcd938x.c
··· 22 22 #include <linux/regulator/consumer.h> 23 23 24 24 #include "wcd-clsh-v2.h" 25 + #include "wcd-common.h" 25 26 #include "wcd-mbhc-v2.h" 26 27 #include "wcd938x.h" 27 28 ··· 156 155 struct wcd_mbhc_config mbhc_cfg; 157 156 struct wcd_mbhc_intr intr_ids; 158 157 struct wcd_clsh_ctrl *clsh_info; 158 + struct wcd_common common; 159 159 struct irq_domain *virq; 160 160 struct regmap_irq_chip_data *irq_chip; 161 161 struct snd_soc_jack *jack; ··· 171 169 struct gpio_desc *us_euro_gpio; 172 170 struct mux_control *us_euro_mux; 173 171 unsigned int mux_state; 174 - u32 micb1_mv; 175 - u32 micb2_mv; 176 - u32 micb3_mv; 177 - u32 micb4_mv; 178 172 int hphr_pdm_wd_int; 179 173 int hphl_pdm_wd_int; 180 174 int aux_pdm_wd_int; ··· 394 396 395 397 } 396 398 397 - static int wcd938x_sdw_connect_port(const struct wcd938x_sdw_ch_info *ch_info, 399 + static int wcd938x_sdw_connect_port(const struct wcd_sdw_ch_info *ch_info, 398 400 struct sdw_port_config *port_config, 399 401 u8 enable) 400 402 { ··· 1092 1094 int bank; 1093 1095 int rate; 1094 1096 1095 - bank = (wcd938x_swr_get_current_bank(wcd938x->sdw_priv[AIF1_CAP]->sdev)) ? 0 : 1; 1096 - bank = bank ? 0 : 1; 1097 + bank = sdw_slave_get_current_bank(wcd938x->sdw_priv[AIF1_CAP]->sdev); 1097 1098 1098 1099 switch (event) { 1099 1100 case SND_SOC_DAPM_PRE_PMU: ··· 1972 1975 } 1973 1976 } 1974 1977 1975 - static int wcd938x_get_micb_vout_ctl_val(u32 micb_mv) 1976 - { 1977 - /* min micbias voltage is 1V and maximum is 2.85V */ 1978 - if (micb_mv < 1000 || micb_mv > 2850) 1979 - return -EINVAL; 1980 - 1981 - return (micb_mv - 1000) / 50; 1982 - } 1983 - 1984 1978 static int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, 1985 1979 int req_volt, int micb_num) 1986 1980 { ··· 2008 2020 cur_vout_ctl = snd_soc_component_read_field(component, micb_reg, 2009 2021 WCD938X_MICB_VOUT_MASK); 2010 2022 2011 - req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt); 2023 + req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt); 2012 2024 if (req_vout_ctl < 0) { 2013 2025 ret = -EINVAL; 2014 2026 goto exit; ··· 2056 2068 * voltage needed to detect threshold microphone, then do 2057 2069 * not change the micbias, just return. 2058 2070 */ 2059 - if (wcd938x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) 2071 + if (wcd938x->common.micb_mv[2] >= WCD_MBHC_THR_HS_MICB_MV) 2060 2072 return 0; 2061 2073 2062 - micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->micb2_mv; 2074 + micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->common.micb_mv[2]; 2063 2075 2064 2076 return wcd938x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); 2065 2077 } ··· 2964 2976 {"EAR", NULL, "EAR PGA"}, 2965 2977 }; 2966 2978 2967 - static int wcd938x_set_micbias_data(struct wcd938x_priv *wcd938x) 2979 + static void wcd938x_set_micbias_data(struct device *dev, struct wcd938x_priv *wcd938x) 2968 2980 { 2969 - int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; 2970 - 2971 - /* set micbias voltage */ 2972 - vout_ctl_1 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb1_mv); 2973 - vout_ctl_2 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb2_mv); 2974 - vout_ctl_3 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb3_mv); 2975 - vout_ctl_4 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb4_mv); 2976 - if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0) 2977 - return -EINVAL; 2978 - 2979 2981 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1, 2980 - WCD938X_MICB_VOUT_MASK, vout_ctl_1); 2982 + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[0]); 2981 2983 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2, 2982 - WCD938X_MICB_VOUT_MASK, vout_ctl_2); 2984 + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[1]); 2983 2985 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3, 2984 - WCD938X_MICB_VOUT_MASK, vout_ctl_3); 2986 + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[2]); 2985 2987 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4, 2986 - WCD938X_MICB_VOUT_MASK, vout_ctl_4); 2987 - 2988 - return 0; 2988 + WCD938X_MICB_VOUT_MASK, wcd938x->common.micb_vout[3]); 2989 2989 } 2990 2990 2991 2991 static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data) ··· 3177 3201 .endianness = 1, 3178 3202 }; 3179 3203 3180 - static void wcd938x_dt_parse_micbias_info(struct device *dev, struct wcd938x_priv *wcd) 3181 - { 3182 - struct device_node *np = dev->of_node; 3183 - u32 prop_val = 0; 3184 - int rc = 0; 3185 - 3186 - rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); 3187 - if (!rc) 3188 - wcd->micb1_mv = prop_val/1000; 3189 - else 3190 - dev_info(dev, "%s: Micbias1 DT property not found\n", __func__); 3191 - 3192 - rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); 3193 - if (!rc) 3194 - wcd->micb2_mv = prop_val/1000; 3195 - else 3196 - dev_info(dev, "%s: Micbias2 DT property not found\n", __func__); 3197 - 3198 - rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); 3199 - if (!rc) 3200 - wcd->micb3_mv = prop_val/1000; 3201 - else 3202 - dev_info(dev, "%s: Micbias3 DT property not found\n", __func__); 3203 - 3204 - rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); 3205 - if (!rc) 3206 - wcd->micb4_mv = prop_val/1000; 3207 - else 3208 - dev_info(dev, "%s: Micbias4 DT property not found\n", __func__); 3209 - } 3210 - 3211 3204 static bool wcd938x_swap_gnd_mic(struct snd_soc_component *component) 3212 3205 { 3213 3206 struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); ··· 3241 3296 if (ret) 3242 3297 return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); 3243 3298 3244 - wcd938x_dt_parse_micbias_info(dev, wcd938x); 3299 + ret = wcd_dt_parse_micbias_info(&wcd938x->common); 3300 + if (ret) 3301 + return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); 3245 3302 3246 3303 cfg->mbhc_micbias = MIC_BIAS_2; 3247 3304 cfg->anc_micbias = MIC_BIAS_2; 3248 3305 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 3249 3306 cfg->num_btn = WCD938X_MBHC_MAX_BUTTONS; 3250 - cfg->micb_mv = wcd938x->micb2_mv; 3307 + cfg->micb_mv = wcd938x->common.micb_mv[2]; 3251 3308 cfg->linein_th = 5000; 3252 3309 cfg->hs_thr = 1700; 3253 3310 cfg->hph_thr = 50; ··· 3347 3400 return ret; 3348 3401 } 3349 3402 3350 - wcd938x->rxdev = wcd938x_sdw_device_get(wcd938x->rxnode); 3403 + wcd938x->rxdev = of_sdw_find_device_by_node(wcd938x->rxnode); 3351 3404 if (!wcd938x->rxdev) { 3352 3405 dev_err(dev, "could not find slave with matching of node\n"); 3353 3406 ret = -EINVAL; ··· 3356 3409 wcd938x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd938x->rxdev); 3357 3410 wcd938x->sdw_priv[AIF1_PB]->wcd938x = wcd938x; 3358 3411 3359 - wcd938x->txdev = wcd938x_sdw_device_get(wcd938x->txnode); 3412 + wcd938x->txdev = of_sdw_find_device_by_node(wcd938x->txnode); 3360 3413 if (!wcd938x->txdev) { 3361 3414 dev_err(dev, "could not find txslave with matching of node\n"); 3362 3415 ret = -EINVAL; ··· 3389 3442 goto err_remove_tx_link; 3390 3443 } 3391 3444 3392 - wcd938x->regmap = dev_get_regmap(&wcd938x->tx_sdw_dev->dev, NULL); 3445 + wcd938x->regmap = wcd938x->sdw_priv[AIF1_CAP]->regmap; 3393 3446 if (!wcd938x->regmap) { 3394 3447 dev_err(dev, "could not get TX device regmap\n"); 3395 3448 ret = -EINVAL; ··· 3405 3458 wcd938x->sdw_priv[AIF1_PB]->slave_irq = wcd938x->virq; 3406 3459 wcd938x->sdw_priv[AIF1_CAP]->slave_irq = wcd938x->virq; 3407 3460 3408 - ret = wcd938x_set_micbias_data(wcd938x); 3409 - if (ret < 0) { 3410 - dev_err(dev, "%s: bad micbias pdata\n", __func__); 3411 - goto err_remove_rx_link; 3412 - } 3461 + wcd938x_set_micbias_data(dev, wcd938x); 3413 3462 3414 3463 ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x, 3415 3464 wcd938x_dais, ARRAY_SIZE(wcd938x_dais)); ··· 3494 3551 3495 3552 dev_set_drvdata(dev, wcd938x); 3496 3553 mutex_init(&wcd938x->micb_lock); 3554 + wcd938x->common.dev = dev; 3555 + wcd938x->common.max_bias = 4; 3497 3556 3498 3557 ret = wcd938x_populate_dt_data(wcd938x, dev); 3499 3558 if (ret)
+1 -25
sound/soc/codecs/wcd938x.h
··· 587 587 588 588 #define WCD938X_MAX_SWR_CH_IDS 15 589 589 590 - struct wcd938x_sdw_ch_info { 591 - int port_num; 592 - unsigned int ch_mask; 593 - }; 594 - 595 - #define WCD_SDW_CH(id, pn, cmask) \ 596 - [id] = { \ 597 - .port_num = pn, \ 598 - .ch_mask = cmask, \ 599 - } 600 - 601 590 enum wcd938x_tx_sdw_ports { 602 591 WCD938X_ADC_1_2_PORT = 1, 603 592 WCD938X_ADC_3_4_PORT, ··· 638 649 struct sdw_stream_config sconfig; 639 650 struct sdw_stream_runtime *sruntime; 640 651 struct sdw_port_config port_config[WCD938X_MAX_SWR_PORTS]; 641 - const struct wcd938x_sdw_ch_info *ch_info; 652 + const struct wcd_sdw_ch_info *ch_info; 642 653 bool port_enable[WCD938X_MAX_SWR_CH_IDS]; 643 654 int active_ports; 644 655 bool is_tx; ··· 658 669 struct snd_pcm_substream *substream, 659 670 struct snd_pcm_hw_params *params, 660 671 struct snd_soc_dai *dai); 661 - 662 - struct device *wcd938x_sdw_device_get(struct device_node *np); 663 - int wcd938x_swr_get_current_bank(struct sdw_slave *sdev); 664 - 665 672 #else 666 673 667 674 static inline int wcd938x_sdw_free(struct wcd938x_sdw_priv *wcd, ··· 682 697 return -EOPNOTSUPP; 683 698 } 684 699 685 - static inline struct device *wcd938x_sdw_device_get(struct device_node *np) 686 - { 687 - return NULL; 688 - } 689 - 690 - static inline int wcd938x_swr_get_current_bank(struct sdw_slave *sdev) 691 - { 692 - return 0; 693 - } 694 700 #endif /* CONFIG_SND_SOC_WCD938X_SDW */ 695 701 #endif /* __WCD938X_H__ */
+9 -89
sound/soc/codecs/wcd939x-sdw.c
··· 20 20 #include <sound/soc.h> 21 21 #include <sound/soc-dapm.h> 22 22 #include "wcd939x.h" 23 + #include "wcd-common.h" 23 24 24 - #define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m)) 25 - 26 - static const struct wcd939x_sdw_ch_info wcd939x_sdw_rx_ch_info[] = { 25 + static const struct wcd_sdw_ch_info wcd939x_sdw_rx_ch_info[] = { 27 26 WCD_SDW_CH(WCD939X_HPH_L, WCD939X_HPH_PORT, BIT(0)), 28 27 WCD_SDW_CH(WCD939X_HPH_R, WCD939X_HPH_PORT, BIT(1)), 29 28 WCD_SDW_CH(WCD939X_CLSH, WCD939X_CLSH_PORT, BIT(0)), ··· 35 36 WCD_SDW_CH(WCD939X_HIFI_PCM_R, WCD939X_HIFI_PCM_PORT, BIT(1)), 36 37 }; 37 38 38 - static const struct wcd939x_sdw_ch_info wcd939x_sdw_tx_ch_info[] = { 39 + static const struct wcd_sdw_ch_info wcd939x_sdw_tx_ch_info[] = { 39 40 WCD_SDW_CH(WCD939X_ADC1, WCD939X_ADC_1_4_PORT, BIT(0)), 40 41 WCD_SDW_CH(WCD939X_ADC2, WCD939X_ADC_1_4_PORT, BIT(1)), 41 42 WCD_SDW_CH(WCD939X_ADC3, WCD939X_ADC_1_4_PORT, BIT(2)), ··· 127 128 } 128 129 }; 129 130 130 - struct device *wcd939x_sdw_device_get(struct device_node *np) 131 - { 132 - return bus_find_device_by_of_node(&sdw_bus_type, np); 133 - } 134 - EXPORT_SYMBOL_GPL(wcd939x_sdw_device_get); 135 - 136 - unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev) 137 - { 138 - return FIELD_GET(SDW_SCP_STAT_CURR_BANK, 139 - sdw_read(sdev, SDW_SCP_CTRL)); 140 - } 141 - EXPORT_SYMBOL_GPL(wcd939x_swr_get_current_bank); 142 - 143 131 int wcd939x_sdw_hw_params(struct wcd939x_sdw_priv *wcd, 144 132 struct snd_pcm_substream *substream, 145 133 struct snd_pcm_hw_params *params, ··· 185 199 } 186 200 EXPORT_SYMBOL_GPL(wcd939x_sdw_set_sdw_stream); 187 201 188 - struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd) 189 - { 190 - if (wcd->regmap) 191 - return wcd->regmap; 192 - 193 - return ERR_PTR(-EINVAL); 194 - } 195 - EXPORT_SYMBOL_GPL(wcd939x_swr_get_regmap); 196 - 197 - static int wcd9390_update_status(struct sdw_slave *slave, 198 - enum sdw_slave_status status) 199 - { 200 - struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev); 201 - 202 - if (wcd->regmap && status == SDW_SLAVE_ATTACHED) { 203 - /* Write out any cached changes that happened between probe and attach */ 204 - regcache_cache_only(wcd->regmap, false); 205 - return regcache_sync(wcd->regmap); 206 - } 207 - 208 - return 0; 209 - } 210 - 211 - static int wcd9390_bus_config(struct sdw_slave *slave, 212 - struct sdw_bus_params *params) 213 - { 214 - sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 215 - 0x01); 216 - 217 - return 0; 218 - } 219 - 220 202 /* 221 203 * Handle Soundwire out-of-band interrupt event by triggering 222 204 * the first irq of the slave_irq irq domain, which then will ··· 195 241 struct sdw_slave_intr_status *status) 196 242 { 197 243 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 244 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; 245 + return wcd_interrupt_callback(slave, wcd->slave_irq, WCD939X_DIGITAL_INTR_STATUS_0, 246 + WCD939X_DIGITAL_INTR_STATUS_1, WCD939X_DIGITAL_INTR_STATUS_2); 210 247 } 211 248 212 249 static const struct reg_default wcd939x_defaults[] = { ··· 1330 1385 }; 1331 1386 1332 1387 static const struct sdw_slave_ops wcd9390_slave_ops = { 1333 - .update_status = wcd9390_update_status, 1388 + .update_status = wcd_update_status, 1334 1389 .interrupt_callback = wcd9390_interrupt_callback, 1335 - .bus_config = wcd9390_bus_config, 1336 - }; 1337 - 1338 - static int wcd939x_sdw_component_bind(struct device *dev, struct device *master, 1339 - void *data) 1340 - { 1341 - pm_runtime_set_autosuspend_delay(dev, 3000); 1342 - pm_runtime_use_autosuspend(dev); 1343 - pm_runtime_mark_last_busy(dev); 1344 - pm_runtime_set_active(dev); 1345 - pm_runtime_enable(dev); 1346 - 1347 - return 0; 1348 - } 1349 - 1350 - static void wcd939x_sdw_component_unbind(struct device *dev, 1351 - struct device *master, void *data) 1352 - { 1353 - pm_runtime_disable(dev); 1354 - pm_runtime_set_suspended(dev); 1355 - pm_runtime_dont_use_autosuspend(dev); 1356 - } 1357 - 1358 - static const struct component_ops wcd939x_sdw_component_ops = { 1359 - .bind = wcd939x_sdw_component_bind, 1360 - .unbind = wcd939x_sdw_component_unbind, 1390 + .bus_config = wcd_bus_config, 1361 1391 }; 1362 1392 1363 1393 static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id) ··· 1398 1478 regcache_cache_only(wcd->regmap, true); 1399 1479 } 1400 1480 1401 - ret = component_add(dev, &wcd939x_sdw_component_ops); 1481 + ret = component_add(dev, &wcd_sdw_component_ops); 1402 1482 if (ret) 1403 1483 return ret; 1404 1484 ··· 1413 1493 struct device *dev = &pdev->dev; 1414 1494 struct wcd939x_sdw_priv *wcd = dev_get_drvdata(dev); 1415 1495 1416 - component_del(dev, &wcd939x_sdw_component_ops); 1496 + component_del(dev, &wcd_sdw_component_ops); 1417 1497 1418 1498 if (wcd->regmap) 1419 1499 regmap_exit(wcd->regmap);
+24 -80
sound/soc/codecs/wcd939x.c
··· 28 28 #include <linux/usb/typec_altmode.h> 29 29 30 30 #include "wcd-clsh-v2.h" 31 + #include "wcd-common.h" 31 32 #include "wcd-mbhc-v2.h" 32 33 #include "wcd939x.h" 33 34 ··· 192 191 struct wcd_mbhc_config mbhc_cfg; 193 192 struct wcd_mbhc_intr intr_ids; 194 193 struct wcd_clsh_ctrl *clsh_info; 194 + struct wcd_common common; 195 195 struct irq_domain *virq; 196 196 struct regmap_irq_chip_data *irq_chip; 197 197 struct snd_soc_jack *jack; ··· 203 201 u32 tx_mode[TX_ADC_MAX]; 204 202 int variant; 205 203 struct gpio_desc *reset_gpio; 206 - u32 micb1_mv; 207 - u32 micb2_mv; 208 - u32 micb3_mv; 209 - u32 micb4_mv; 210 204 int hphr_pdm_wd_int; 211 205 int hphl_pdm_wd_int; 212 206 int ear_pdm_wd_int; ··· 413 415 return 0; 414 416 } 415 417 416 - static int wcd939x_sdw_connect_port(const struct wcd939x_sdw_ch_info *ch_info, 418 + static int wcd939x_sdw_connect_port(const struct wcd_sdw_ch_info *ch_info, 417 419 struct sdw_port_config *port_config, 418 420 u8 enable) 419 421 { ··· 1015 1017 int bank; 1016 1018 int rate; 1017 1019 1018 - bank = wcd939x_swr_get_current_bank(wcd939x->sdw_priv[AIF1_CAP]->sdev); 1020 + bank = sdw_slave_get_current_bank(wcd939x->sdw_priv[AIF1_CAP]->sdev); 1019 1021 1020 1022 switch (event) { 1021 1023 case SND_SOC_DAPM_PRE_PMU: ··· 1917 1919 } 1918 1920 } 1919 1921 1920 - static int wcd939x_get_micb_vout_ctl_val(u32 micb_mv) 1921 - { 1922 - /* min micbias voltage is 1V and maximum is 2.85V */ 1923 - if (micb_mv < 1000 || micb_mv > 2850) { 1924 - pr_err("%s: unsupported micbias voltage\n", __func__); 1925 - return -EINVAL; 1926 - } 1927 - 1928 - return (micb_mv - 1000) / 50; 1929 - } 1930 - 1931 1922 static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, 1932 1923 int req_volt, int micb_num) 1933 1924 { ··· 1956 1969 cur_vout_ctl = snd_soc_component_read_field(component, micb_reg, 1957 1970 WCD939X_MICB_VOUT_CTL); 1958 1971 1959 - req_vout_ctl = wcd939x_get_micb_vout_ctl_val(req_volt); 1972 + req_vout_ctl = wcd_get_micb_vout_ctl_val(component->dev, req_volt); 1960 1973 if (req_vout_ctl < 0) { 1961 1974 ret = req_vout_ctl; 1962 1975 goto exit; ··· 2008 2021 * voltage needed to detect threshold microphone, then do 2009 2022 * not change the micbias, just return. 2010 2023 */ 2011 - if (wcd939x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) 2024 + if (wcd939x->common.micb_mv[1] >= WCD_MBHC_THR_HS_MICB_MV) 2012 2025 return 0; 2013 2026 2014 - micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->micb2_mv; 2027 + micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->common.micb_mv[1]; 2015 2028 2016 2029 return wcd939x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); 2017 2030 } ··· 2882 2895 {"EAR", NULL, "EAR PGA"}, 2883 2896 }; 2884 2897 2885 - static int wcd939x_set_micbias_data(struct wcd939x_priv *wcd939x) 2898 + static void wcd939x_set_micbias_data(struct device *dev, struct wcd939x_priv *wcd939x) 2886 2899 { 2887 - int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; 2888 - 2889 - /* set micbias voltage */ 2890 - vout_ctl_1 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb1_mv); 2891 - vout_ctl_2 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb2_mv); 2892 - vout_ctl_3 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb3_mv); 2893 - vout_ctl_4 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb4_mv); 2894 - if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0) 2895 - return -EINVAL; 2896 - 2897 2900 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB1, 2898 - WCD939X_MICB_VOUT_CTL, vout_ctl_1); 2901 + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[0]); 2899 2902 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB2, 2900 - WCD939X_MICB_VOUT_CTL, vout_ctl_2); 2903 + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[1]); 2901 2904 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB3, 2902 - WCD939X_MICB_VOUT_CTL, vout_ctl_3); 2905 + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[2]); 2903 2906 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB4, 2904 - WCD939X_MICB_VOUT_CTL, vout_ctl_4); 2905 - 2906 - return 0; 2907 + WCD939X_MICB_VOUT_CTL, wcd939x->common.micb_vout[3]); 2907 2908 } 2908 2909 2909 2910 static irqreturn_t wcd939x_wd_handle_irq(int irq, void *data) ··· 3161 3186 } 3162 3187 #endif /* CONFIG_TYPEC */ 3163 3188 3164 - static void wcd939x_dt_parse_micbias_info(struct device *dev, struct wcd939x_priv *wcd) 3165 - { 3166 - struct device_node *np = dev->of_node; 3167 - u32 prop_val = 0; 3168 - int rc = 0; 3169 - 3170 - rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); 3171 - if (!rc) 3172 - wcd->micb1_mv = prop_val / 1000; 3173 - else 3174 - dev_info(dev, "%s: Micbias1 DT property not found\n", __func__); 3175 - 3176 - rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); 3177 - if (!rc) 3178 - wcd->micb2_mv = prop_val / 1000; 3179 - else 3180 - dev_info(dev, "%s: Micbias2 DT property not found\n", __func__); 3181 - 3182 - rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); 3183 - if (!rc) 3184 - wcd->micb3_mv = prop_val / 1000; 3185 - else 3186 - dev_info(dev, "%s: Micbias3 DT property not found\n", __func__); 3187 - 3188 - rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); 3189 - if (!rc) 3190 - wcd->micb4_mv = prop_val / 1000; 3191 - else 3192 - dev_info(dev, "%s: Micbias4 DT property not found\n", __func__); 3193 - } 3194 - 3195 3189 #if IS_ENABLED(CONFIG_TYPEC) 3196 3190 static bool wcd939x_swap_gnd_mic(struct snd_soc_component *component) 3197 3191 { ··· 3196 3252 if (ret) 3197 3253 return dev_err_probe(dev, ret, "Failed to get and enable supplies\n"); 3198 3254 3199 - wcd939x_dt_parse_micbias_info(dev, wcd939x); 3255 + ret = wcd_dt_parse_micbias_info(&wcd939x->common); 3256 + if (ret) 3257 + return dev_err_probe(dev, ret, "Failed to get micbias\n"); 3200 3258 3201 3259 cfg->mbhc_micbias = MIC_BIAS_2; 3202 3260 cfg->anc_micbias = MIC_BIAS_2; 3203 3261 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 3204 3262 cfg->num_btn = WCD939X_MBHC_MAX_BUTTONS; 3205 - cfg->micb_mv = wcd939x->micb2_mv; 3263 + cfg->micb_mv = wcd939x->common.micb_mv[1]; 3206 3264 cfg->linein_th = 5000; 3207 3265 cfg->hs_thr = 1700; 3208 3266 cfg->hph_thr = 50; ··· 3329 3383 goto err_put_typec_switch; 3330 3384 } 3331 3385 3332 - wcd939x->rxdev = wcd939x_sdw_device_get(wcd939x->rxnode); 3386 + wcd939x->rxdev = of_sdw_find_device_by_node(wcd939x->rxnode); 3333 3387 if (!wcd939x->rxdev) { 3334 3388 dev_err(dev, "could not find slave with matching of node\n"); 3335 3389 ret = -EINVAL; ··· 3338 3392 wcd939x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd939x->rxdev); 3339 3393 wcd939x->sdw_priv[AIF1_PB]->wcd939x = wcd939x; 3340 3394 3341 - wcd939x->txdev = wcd939x_sdw_device_get(wcd939x->txnode); 3395 + wcd939x->txdev = of_sdw_find_device_by_node(wcd939x->txnode); 3342 3396 if (!wcd939x->txdev) { 3343 3397 dev_err(dev, "could not find txslave with matching of node\n"); 3344 3398 ret = -EINVAL; ··· 3374 3428 } 3375 3429 3376 3430 /* Get regmap from TX SoundWire device */ 3377 - wcd939x->regmap = wcd939x_swr_get_regmap(wcd939x->sdw_priv[AIF1_CAP]); 3378 - if (IS_ERR(wcd939x->regmap)) { 3431 + wcd939x->regmap = wcd939x->sdw_priv[AIF1_CAP]->regmap; 3432 + if (!wcd939x->regmap) { 3379 3433 dev_err(dev, "could not get TX device regmap\n"); 3380 - ret = PTR_ERR(wcd939x->regmap); 3434 + ret = -ENODEV; 3381 3435 goto err_remove_rx_link; 3382 3436 } 3383 3437 ··· 3390 3444 wcd939x->sdw_priv[AIF1_PB]->slave_irq = wcd939x->virq; 3391 3445 wcd939x->sdw_priv[AIF1_CAP]->slave_irq = wcd939x->virq; 3392 3446 3393 - ret = wcd939x_set_micbias_data(wcd939x); 3394 - if (ret < 0) { 3395 - dev_err(dev, "%s: bad micbias pdata\n", __func__); 3396 - goto err_remove_rx_link; 3397 - } 3447 + wcd939x_set_micbias_data(dev, wcd939x); 3398 3448 3399 3449 /* Check WCD9395 version */ 3400 3450 regmap_read(wcd939x->regmap, WCD939X_DIGITAL_CHIP_ID1, &id1); ··· 3555 3613 3556 3614 dev_set_drvdata(dev, wcd939x); 3557 3615 mutex_init(&wcd939x->micb_lock); 3616 + wcd939x->common.dev = dev; 3617 + wcd939x->common.max_bias = 4; 3558 3618 3559 3619 ret = wcd939x_populate_dt_data(wcd939x, dev); 3560 3620 if (ret) {
+1 -31
sound/soc/codecs/wcd939x.h
··· 844 844 845 845 #define WCD939X_MAX_SWR_CH_IDS (15) 846 846 847 - struct wcd939x_sdw_ch_info { 848 - int port_num; 849 - unsigned int ch_mask; 850 - }; 851 - 852 - #define WCD_SDW_CH(id, pn, cmask) \ 853 - [id] = { \ 854 - .port_num = pn, \ 855 - .ch_mask = cmask, \ 856 - } 857 - 858 847 enum wcd939x_tx_sdw_ports { 859 848 WCD939X_ADC_1_4_PORT = 1, 860 849 WCD939X_ADC_DMIC_1_2_PORT, ··· 898 909 struct sdw_stream_config sconfig; 899 910 struct sdw_stream_runtime *sruntime; 900 911 struct sdw_port_config port_config[WCD939X_MAX_SWR_PORTS]; 901 - const struct wcd939x_sdw_ch_info *ch_info; 912 + const struct wcd_sdw_ch_info *ch_info; 902 913 bool port_enable[WCD939X_MAX_SWR_CH_IDS]; 903 914 int active_ports; 904 915 bool is_tx; ··· 918 929 struct snd_pcm_substream *substream, 919 930 struct snd_pcm_hw_params *params, 920 931 struct snd_soc_dai *dai); 921 - 922 - struct device *wcd939x_sdw_device_get(struct device_node *np); 923 - unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev); 924 - 925 - struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd); 926 932 #else 927 933 928 934 static inline int wcd939x_sdw_free(struct wcd939x_sdw_priv *wcd, ··· 942 958 return -EOPNOTSUPP; 943 959 } 944 960 945 - static inline struct device *wcd939x_sdw_device_get(struct device_node *np) 946 - { 947 - return NULL; 948 - } 949 - 950 - static inline unsigned int wcd939x_swr_get_current_bank(struct sdw_slave *sdev) 951 - { 952 - return 0; 953 - } 954 - 955 - struct regmap *wcd939x_swr_get_regmap(struct wcd939x_sdw_priv *wcd) 956 - { 957 - return PTR_ERR(-EINVAL); 958 - } 959 961 #endif /* CONFIG_SND_SOC_WCD939X_SDW */ 960 962 961 963 #endif /* __WCD939X_H__ */