Merge "asoc: codecs: enable dynamic RX & TX supplies for WCD9335"

This commit is contained in:
qctecmdr 2019-04-30 10:59:58 -07:00 committed by Gerrit - the friendly Code Review server
commit 1487c6d654
8 changed files with 163 additions and 21 deletions

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
* Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
*/
#include <linux/kernel.h>
@ -357,7 +357,7 @@ EXPORT_SYMBOL(msm_cdc_enable_static_supplies);
/*
* msm_cdc_init_supplies:
* Initialize codec static supplies with regulator get
* Initialize codec static supplies
*
* @dev: pointer to codec device
* @supplies: pointer to regulator bulk data
@ -370,6 +370,29 @@ int msm_cdc_init_supplies(struct device *dev,
struct regulator_bulk_data **supplies,
struct cdc_regulator *cdc_vreg,
int num_supplies)
{
return msm_cdc_init_supplies_v2(dev, supplies, cdc_vreg,
num_supplies, false);
}
EXPORT_SYMBOL(msm_cdc_init_supplies);
/*
* msm_cdc_init_supplies_v2:
* Initialize codec static supplies.
* Initialize codec dynamic supplies based on vote_regulator_on_demand
*
* @dev: pointer to codec device
* @supplies: pointer to regulator bulk data
* @cdc_vreg: pointer to platform regulator data
* @num_supplies: number of supplies
* @vote_regulator_on_demand: initialize codec dynamic supplies at runtime
*
* Return error code if supply init is failed
*/
int msm_cdc_init_supplies_v2(struct device *dev,
struct regulator_bulk_data **supplies,
struct cdc_regulator *cdc_vreg,
int num_supplies, u32 vote_regulator_on_demand)
{
struct regulator_bulk_data *vsup;
int rc;
@ -413,6 +436,9 @@ int msm_cdc_init_supplies(struct device *dev,
if (regulator_count_voltages(vsup[i].consumer) < 0)
continue;
if (cdc_vreg[i].ondemand && vote_regulator_on_demand)
continue;
rc = regulator_set_voltage(vsup[i].consumer,
cdc_vreg[i].min_uV,
cdc_vreg[i].max_uV);
@ -437,7 +463,7 @@ int msm_cdc_init_supplies(struct device *dev,
err_supply:
return rc;
}
EXPORT_SYMBOL(msm_cdc_init_supplies);
EXPORT_SYMBOL(msm_cdc_init_supplies_v2);
/*
* msm_cdc_get_power_supplies:

View File

@ -151,6 +151,8 @@ MODULE_PARM_DESC(cpe_debug_mode, "boot cpe in debug mode");
static char on_demand_supply_name[][MAX_ON_DEMAND_SUPPLY_NAME_LENGTH] = {
"cdc-vdd-mic-bias",
"cdc-vdd-tx-h",
"cdc-vdd-rx-h"
};
enum {
@ -5634,6 +5636,9 @@ static int tasha_codec_enable_on_demand_supply(
snd_soc_dapm_to_component(w->dapm);
struct tasha_priv *tasha = snd_soc_component_get_drvdata(component);
struct on_demand_supply *supply;
struct wcd9xxx *wcd9xxx = tasha->wcd9xxx;
struct wcd9xxx_pdata *pdata = dev_get_platdata(component->dev->parent);
const char *supply_name;
if (w->shift >= ON_DEMAND_SUPPLIES_MAX) {
dev_err(component->dev, "%s: error index > MAX Demand supplies",
@ -5646,6 +5651,7 @@ static int tasha_codec_enable_on_demand_supply(
__func__, on_demand_supply_name[w->shift], event);
supply = &tasha->on_demand_list[w->shift];
supply_name = on_demand_supply_name[w->shift];
WARN_ONCE(!supply->supply, "%s isn't defined\n",
on_demand_supply_name[w->shift]);
if (!supply->supply) {
@ -5656,6 +5662,15 @@ static int tasha_codec_enable_on_demand_supply(
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
if (pdata->vote_regulator_on_demand) {
ret = wcd9xxx_vote_ondemand_regulator(wcd9xxx, pdata,
supply_name,
true);
if (ret)
dev_err(component->dev, "%s: Failed to vote %s\n",
__func__,
on_demand_supply_name[w->shift]);
}
ret = regulator_enable(supply->supply);
if (ret)
dev_err(component->dev, "%s: Failed to enable %s\n",
@ -5668,6 +5683,15 @@ static int tasha_codec_enable_on_demand_supply(
dev_err(component->dev, "%s: Failed to disable %s\n",
__func__,
on_demand_supply_name[w->shift]);
if (pdata->vote_regulator_on_demand) {
ret = wcd9xxx_vote_ondemand_regulator(wcd9xxx, pdata,
supply_name,
false);
if (ret)
dev_err(component->dev, "%s: Failed to unvote %s\n",
__func__,
on_demand_supply_name[w->shift]);
}
break;
default:
break;
@ -11130,7 +11154,14 @@ static const struct snd_soc_dapm_widget tasha_dapm_widgets[] = {
SND_SOC_DAPM_SUPPLY(DAPM_LDO_H_STANDALONE, SND_SOC_NOPM, 0, 0,
tasha_codec_force_enable_ldo_h,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_SUPPLY("tx regulator", SND_SOC_NOPM,
ON_DEMAND_TX_SUPPLY, 0,
tasha_codec_enable_on_demand_supply,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_SUPPLY("rx regulator", SND_SOC_NOPM,
ON_DEMAND_RX_SUPPLY, 0,
tasha_codec_enable_on_demand_supply,
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MUX("ANC0 FB MUX", SND_SOC_NOPM, 0, 0, &anc0_fb_mux),
SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
@ -13899,12 +13930,14 @@ static int tasha_codec_probe(struct snd_soc_component *component)
goto err;
}
supply = tasha_codec_find_ondemand_regulator(component,
on_demand_supply_name[ON_DEMAND_MICBIAS]);
if (supply) {
tasha->on_demand_list[ON_DEMAND_MICBIAS].supply = supply;
tasha->on_demand_list[ON_DEMAND_MICBIAS].ondemand_supply_count =
0;
for (i = ON_DEMAND_MICBIAS; i < ON_DEMAND_SUPPLIES_MAX; i++) {
supply = tasha_codec_find_ondemand_regulator(component,
on_demand_supply_name[i]);
if (supply) {
tasha->on_demand_list[i].supply = supply;
tasha->on_demand_list[i].ondemand_supply_count =
0;
}
}
tasha->fw_data = devm_kzalloc(component->dev,

View File

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
*/
#ifndef WCD9335_H
#define WCD9335_H
@ -81,6 +81,8 @@ enum wcd9335_codec_event {
enum tasha_on_demand_supply {
ON_DEMAND_MICBIAS = 0,
ON_DEMAND_TX_SUPPLY,
ON_DEMAND_RX_SUPPLY,
ON_DEMAND_SUPPLIES_MAX,
};

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2019, The Linux Foundation. All rights reserved.
*/
#include <linux/kernel.h>
@ -98,6 +98,65 @@ static int wcd9xxx_slim_device_down(struct slim_device *sldev);
struct wcd9xxx_i2c wcd9xxx_modules[MAX_WCD9XXX_DEVICE];
/*
* wcd9xxx_vote_ondemand_regulator: Initialize codec dynamic supplies
*
* @wcd9xxx: Pointer to wcd9xxx structure
* @wcd9xxx_pdata: Pointer to wcd9xxx_pdata structure
* @supply_name: supply parameter to initialize regulator
* @enable: flag to initialize/uninitialize supply
*
* Return error code if supply init is failed
*/
int wcd9xxx_vote_ondemand_regulator(struct wcd9xxx *wcd9xxx,
struct wcd9xxx_pdata *pdata,
const char *supply_name,
bool enable)
{
int i, rc, index = -EINVAL;
pr_debug("%s: enable %d\n", __func__, enable);
for (i = 0; i < wcd9xxx->num_of_supplies; ++i) {
if (pdata->regulator[i].ondemand &&
wcd9xxx->supplies[i].supply &&
!strcmp(wcd9xxx->supplies[i].supply, supply_name)) {
index = i;
break;
}
}
if (index < 0) {
pr_err("%s: no matching regulator found\n", __func__);
return -EINVAL;
}
if (enable) {
rc = regulator_set_voltage(wcd9xxx->supplies[index].consumer,
pdata->regulator[index].min_uV,
pdata->regulator[index].max_uV);
if (rc) {
pr_err("%s: set regulator voltage failed for %s, err:%d\n",
__func__, supply_name, rc);
return rc;
}
rc = regulator_set_load(wcd9xxx->supplies[index].consumer,
pdata->regulator[index].optimum_uA);
if (rc < 0) {
pr_err("%s: set regulator optimum mode failed for %s, err:%d\n",
__func__, supply_name, rc);
return rc;
}
} else {
regulator_set_voltage(wcd9xxx->supplies[index].consumer, 0,
pdata->regulator[index].max_uV);
regulator_set_load(wcd9xxx->supplies[index].consumer, 0);
}
return 0;
}
EXPORT_SYMBOL(wcd9xxx_vote_ondemand_regulator);
static int wcd9xxx_slim_multi_reg_write(struct wcd9xxx *wcd9xxx,
const void *data, size_t count)
{
@ -1069,9 +1128,10 @@ static int wcd9xxx_i2c_probe(struct i2c_client *client,
wcd9xxx->mclk_rate = pdata->mclk_rate;
wcd9xxx->num_of_supplies = pdata->num_supplies;
ret = msm_cdc_init_supplies(wcd9xxx->dev, &wcd9xxx->supplies,
pdata->regulator,
pdata->num_supplies);
ret = msm_cdc_init_supplies_v2(wcd9xxx->dev, &wcd9xxx->supplies,
pdata->regulator,
pdata->num_supplies,
pdata->vote_regulator_on_demand);
if (!wcd9xxx->supplies) {
dev_err(wcd9xxx->dev, "%s: Cannot init wcd supplies\n",
__func__);
@ -1327,9 +1387,10 @@ static int wcd9xxx_slim_probe(struct slim_device *slim)
}
wcd9xxx->num_of_supplies = pdata->num_supplies;
ret = msm_cdc_init_supplies(&slim->dev, &wcd9xxx->supplies,
pdata->regulator,
pdata->num_supplies);
ret = msm_cdc_init_supplies_v2(&slim->dev, &wcd9xxx->supplies,
pdata->regulator,
pdata->num_supplies,
pdata->vote_regulator_on_demand);
if (!wcd9xxx->supplies) {
dev_err(wcd9xxx->dev, "%s: Cannot init wcd supplies\n",
__func__);

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
*/
#include <linux/kernel.h>
@ -414,6 +414,14 @@ struct wcd9xxx_pdata *wcd9xxx_populate_dt_data(struct device *dev)
pdata->dmic_clk_drv = dmic_clk_drive;
rc = of_property_read_u32(dev->of_node,
"qcom,vote-dynamic-supply-on-demand",
&pdata->vote_regulator_on_demand);
if (rc)
dev_dbg(dev, "%s No entry for %s property in node %s\n",
__func__, "qcom,vote-dynamic-supply-on-demand",
dev->of_node->full_name);
return pdata;
err_parse_dt_prop:

View File

@ -10,6 +10,7 @@
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/pm_qos.h>
#include "pdata.h"
#define WCD9XXX_MAX_IRQ_REGS 4
#define WCD9XXX_MAX_NUM_IRQS (WCD9XXX_MAX_IRQ_REGS * 8)
@ -394,6 +395,11 @@ int wcd9xxx_slim_bulk_write(struct wcd9xxx *wcd9xxx,
struct wcd9xxx_reg_val *bulk_reg,
unsigned int size, bool interface);
int wcd9xxx_vote_ondemand_regulator(struct wcd9xxx *wcd9xxx,
struct wcd9xxx_pdata *pdata,
const char *supply_name,
bool enable);
extern int wcd9xxx_core_res_init(
struct wcd9xxx_core_resource *wcd9xxx_core_res,
int num_irqs, int num_irq_regs, struct regmap *wcd_regmap);

View File

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2016, 2018 The Linux Foundation. All rights reserved.
/* Copyright (c) 2016, 2018-2019 The Linux Foundation. All rights reserved.
*/
#ifndef __CODEC_POWER_SUPPLY_H__
@ -45,4 +45,9 @@ extern int msm_cdc_init_supplies(struct device *dev,
struct regulator_bulk_data **supplies,
struct cdc_regulator *cdc_vreg,
int num_supplies);
extern int msm_cdc_init_supplies_v2(struct device *dev,
struct regulator_bulk_data **supplies,
struct cdc_regulator *cdc_vreg,
int num_supplies,
u32 vote_regulator_on_demand);
#endif

View File

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2019, The Linux Foundation. All rights reserved.
*/
#ifndef __MFD_WCD9XXX_PDATA_H__
@ -193,6 +193,7 @@ struct wcd9xxx_pdata {
u32 ecpp_dmic_sample_rate;
u32 dmic_clk_drv;
u16 use_pinctrl;
u32 vote_regulator_on_demand;
};
#endif