diff --git a/asoc/codecs/msm-cdc-supply.c b/asoc/codecs/msm-cdc-supply.c index 220da9dc10..e85df2ef47 100644 --- a/asoc/codecs/msm-cdc-supply.c +++ b/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 @@ -10,6 +10,7 @@ #include #include #include +#include #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); diff --git a/include/asoc/msm-cdc-supply.h b/include/asoc/msm-cdc-supply.h index c6aacf6bd8..f3fc3d53a6 100644 --- a/include/asoc/msm-cdc-supply.h +++ b/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