summaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wcd939x.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-07 13:17:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-07 13:17:46 +0000
commit7f3a4257159dea8e7ef66d1a539dc6df708b8ed3 (patch)
treebcc69b5f4609f348fac49e2f59e210b29eaea783 /sound/soc/codecs/wcd939x.c
parentAdding upstream version 6.9.12. (diff)
downloadlinux-7f3a4257159dea8e7ef66d1a539dc6df708b8ed3.tar.xz
linux-7f3a4257159dea8e7ef66d1a539dc6df708b8ed3.zip
Adding upstream version 6.10.3.upstream/6.10.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sound/soc/codecs/wcd939x.c')
-rw-r--r--sound/soc/codecs/wcd939x.c113
1 files changed, 66 insertions, 47 deletions
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index c49894aad8..97fd75a935 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -182,8 +182,6 @@ struct wcd939x_priv {
/* typec handling */
bool typec_analog_mux;
#if IS_ENABLED(CONFIG_TYPEC)
- struct typec_mux_dev *typec_mux;
- struct typec_switch_dev *typec_sw;
enum typec_orientation typec_orientation;
unsigned long typec_mode;
struct typec_switch *typec_switch;
@@ -3528,6 +3526,68 @@ static const struct component_master_ops wcd939x_comp_ops = {
.unbind = wcd939x_unbind,
};
+static void __maybe_unused wcd939x_typec_mux_unregister(void *data)
+{
+ struct typec_mux_dev *typec_mux = data;
+
+ typec_mux_unregister(typec_mux);
+}
+
+static void __maybe_unused wcd939x_typec_switch_unregister(void *data)
+{
+ struct typec_switch_dev *typec_sw = data;
+
+ typec_switch_unregister(typec_sw);
+}
+
+static int wcd939x_add_typec(struct wcd939x_priv *wcd939x, struct device *dev)
+{
+#if IS_ENABLED(CONFIG_TYPEC)
+ int ret;
+ struct typec_mux_dev *typec_mux;
+ struct typec_switch_dev *typec_sw;
+ struct typec_mux_desc mux_desc = {
+ .drvdata = wcd939x,
+ .fwnode = dev_fwnode(dev),
+ .set = wcd939x_typec_mux_set,
+ };
+ struct typec_switch_desc sw_desc = {
+ .drvdata = wcd939x,
+ .fwnode = dev_fwnode(dev),
+ .set = wcd939x_typec_switch_set,
+ };
+
+ /*
+ * Is USBSS is used to mux analog lines,
+ * register a typec mux/switch to get typec events
+ */
+ if (!wcd939x->typec_analog_mux)
+ return 0;
+
+ typec_mux = typec_mux_register(dev, &mux_desc);
+ if (IS_ERR(typec_mux))
+ return dev_err_probe(dev, PTR_ERR(typec_mux),
+ "failed to register typec mux\n");
+
+ ret = devm_add_action_or_reset(dev, wcd939x_typec_mux_unregister,
+ typec_mux);
+ if (ret)
+ return ret;
+
+ typec_sw = typec_switch_register(dev, &sw_desc);
+ if (IS_ERR(typec_sw))
+ return dev_err_probe(dev, PTR_ERR(typec_sw),
+ "failed to register typec switch\n");
+
+ ret = devm_add_action_or_reset(dev, wcd939x_typec_switch_unregister,
+ typec_sw);
+ if (ret)
+ return ret;
+#endif
+
+ return 0;
+}
+
static int wcd939x_add_slave_components(struct wcd939x_priv *wcd939x,
struct device *dev,
struct component_match **matchptr)
@@ -3576,42 +3636,13 @@ static int wcd939x_probe(struct platform_device *pdev)
return -EINVAL;
}
-#if IS_ENABLED(CONFIG_TYPEC)
- /*
- * Is USBSS is used to mux analog lines,
- * register a typec mux/switch to get typec events
- */
- if (wcd939x->typec_analog_mux) {
- struct typec_mux_desc mux_desc = {
- .drvdata = wcd939x,
- .fwnode = dev_fwnode(dev),
- .set = wcd939x_typec_mux_set,
- };
- struct typec_switch_desc sw_desc = {
- .drvdata = wcd939x,
- .fwnode = dev_fwnode(dev),
- .set = wcd939x_typec_switch_set,
- };
-
- wcd939x->typec_mux = typec_mux_register(dev, &mux_desc);
- if (IS_ERR(wcd939x->typec_mux)) {
- ret = dev_err_probe(dev, PTR_ERR(wcd939x->typec_mux),
- "failed to register typec mux\n");
- goto err_disable_regulators;
- }
-
- wcd939x->typec_sw = typec_switch_register(dev, &sw_desc);
- if (IS_ERR(wcd939x->typec_sw)) {
- ret = dev_err_probe(dev, PTR_ERR(wcd939x->typec_sw),
- "failed to register typec switch\n");
- goto err_unregister_typec_mux;
- }
- }
-#endif /* CONFIG_TYPEC */
+ ret = wcd939x_add_typec(wcd939x, dev);
+ if (ret)
+ goto err_disable_regulators;
ret = wcd939x_add_slave_components(wcd939x, dev, &match);
if (ret)
- goto err_unregister_typec_switch;
+ goto err_disable_regulators;
wcd939x_reset(wcd939x);
@@ -3628,18 +3659,6 @@ static int wcd939x_probe(struct platform_device *pdev)
return 0;
-#if IS_ENABLED(CONFIG_TYPEC)
-err_unregister_typec_mux:
- if (wcd939x->typec_analog_mux)
- typec_mux_unregister(wcd939x->typec_mux);
-#endif /* CONFIG_TYPEC */
-
-err_unregister_typec_switch:
-#if IS_ENABLED(CONFIG_TYPEC)
- if (wcd939x->typec_analog_mux)
- typec_switch_unregister(wcd939x->typec_sw);
-#endif /* CONFIG_TYPEC */
-
err_disable_regulators:
regulator_bulk_disable(WCD939X_MAX_SUPPLY, wcd939x->supplies);
regulator_bulk_free(WCD939X_MAX_SUPPLY, wcd939x->supplies);