Prechádzať zdrojové kódy

asoc: codecs: Add codec supply to enable mic bias pin

Add interface to initialize and enable/disable
wcd codec supply.

Change-Id: If2b2a3120f7f0c87dc6ebe1c1e6c9062b7f2891e
Signed-off-by: Karthikeyan Mani <[email protected]>
Karthikeyan Mani 5 rokov pred
rodič
commit
669b885ac7
2 zmenil súbory, kde vykonal 81 pridanie a 2 odobranie
  1. 70 1
      asoc/codecs/msm-cdc-supply.c
  2. 11 1
      include/asoc/msm-cdc-supply.h

+ 70 - 1
asoc/codecs/msm-cdc-supply.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/kernel.h>
@@ -10,6 +10,7 @@
 #include <linux/slab.h>
 #include <linux/regulator/consumer.h>
 #include <asoc/msm-cdc-supply.h>
+#include <sound/soc.h>
 
 #define CODEC_DT_MAX_PROP_SIZE 40
 
@@ -564,3 +565,71 @@ err_mem_alloc:
 	return rc;
 }
 EXPORT_SYMBOL(msm_cdc_get_power_supplies);
+
+/*
+ * msm_cdc_init_wcd_supply:
+ *	Initialize wcd supply parameters.
+ *
+ * @np: device node pointer to codec device
+ * @name: power supply name
+ * @cdc_supply: codec supply struct to hold wcd params
+ *
+ * Return error code if init failed
+ */
+int msm_cdc_init_wcd_supply(struct device_node *np, const char *name,
+			    struct cdc_wcd_supply *cdc_supply)
+{
+	struct platform_device *pdev = NULL;
+
+	if (!np || !cdc_supply)
+		return -EINVAL;
+
+	pdev = of_find_device_by_node(np);
+	if (!pdev)
+		return -EINVAL;
+
+	cdc_supply->dev = &pdev->dev;
+	cdc_supply->name = name;
+	cdc_supply->component = snd_soc_lookup_component(&pdev->dev, NULL);
+
+	return 0;
+}
+EXPORT_SYMBOL(msm_cdc_init_wcd_supply);
+
+/*
+ * msm_cdc_enable_wcd_supply:
+ *	Enable/Disable wcd supply.
+ *
+ * @cdc_supply: codec supply struct to hold wcd params
+ * @enable: bool to inform whether to enable or disable
+ *
+ * Return error code if enable/disable failed
+ */
+int msm_cdc_enable_wcd_supply(struct cdc_wcd_supply *cdc_supply, bool enable)
+{
+	struct snd_soc_component *component = cdc_supply->component;
+	int rc;
+
+	if (!component) {
+		pr_err("%s: Component memory is NULL\n", __func__);
+		return -EINVAL;
+	}
+
+	if (enable)
+		rc = snd_soc_dapm_force_enable_pin(
+					snd_soc_component_get_dapm(component),
+					cdc_supply->name);
+	else
+		rc = snd_soc_dapm_disable_pin(
+					snd_soc_component_get_dapm(component),
+					cdc_supply->name);
+
+	if (!rc)
+		snd_soc_dapm_sync(snd_soc_component_get_dapm(component));
+	else
+		dev_err(component->dev, "%s: micbias %s force %s pin failed\n",
+			__func__, cdc_supply->name, (enable ? "enable" : "disable"));
+
+	return rc;
+}
+EXPORT_SYMBOL(msm_cdc_enable_wcd_supply);

+ 11 - 1
include/asoc/msm-cdc-supply.h

@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-/* Copyright (c) 2016, 2018-2019 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2016, 2018-2020 The Linux Foundation. All rights reserved.
  */
 
 #ifndef __CODEC_POWER_SUPPLY_H__
@@ -18,6 +18,12 @@ struct cdc_regulator {
 	struct regulator *regulator;
 };
 
+struct cdc_wcd_supply {
+	const char *name;
+	struct device *dev;
+	struct snd_soc_component *component;
+};
+
 extern int msm_cdc_get_power_supplies(struct device *dev,
 				      struct cdc_regulator **cdc_vreg,
 				      int *total_num_supplies);
@@ -50,4 +56,8 @@ extern int msm_cdc_init_supplies_v2(struct device *dev,
 				 struct cdc_regulator *cdc_vreg,
 				 int num_supplies,
 				 u32 vote_regulator_on_demand);
+int msm_cdc_init_wcd_supply(struct device_node *np, const char *name,
+			    struct cdc_wcd_supply *cdc_supply);
+int msm_cdc_enable_wcd_supply(struct cdc_wcd_supply *cdc_supply, bool enable);
+
 #endif