[PATCH 06/12] regulator: arizona-micsupp: Don't hardcode use of ARIZONA defines

From: Richard Fitzgerald
Date: Wed Nov 09 2022 - 11:55:42 EST


When Madera support was added to this driver the code was left
using ARIZONA_* defines. This wasn't causing any problem because
those defines just happened to have the same value as the
equivalent MADERA_* defines. But it is not ideal to assume this,
and future devices that can share this driver do not have the
same register map.

Fix the code to refer to the register data in struct regulator_desc.

Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/regulator/arizona-micsupp.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index f6cfd3f6f0dd..21c36972a8e9 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -34,7 +34,7 @@ struct arizona_micsupp {
struct regulator_dev *regulator;
struct regmap *regmap;
struct snd_soc_dapm_context **dapm;
- unsigned int enable_reg;
+ const struct regulator_desc *desc;
struct device *dev;

struct regulator_consumer_supply supply;
@@ -49,10 +49,11 @@ static void arizona_micsupp_check_cp(struct work_struct *work)
container_of(work, struct arizona_micsupp, check_cp_work);
struct snd_soc_dapm_context *dapm = *micsupp->dapm;
struct snd_soc_component *component;
+ const struct regulator_desc *desc = micsupp->desc;
unsigned int val;
int ret;

- ret = regmap_read(micsupp->regmap, micsupp->enable_reg, &val);
+ ret = regmap_read(micsupp->regmap, desc->enable_reg, &val);
if (ret != 0) {
dev_err(micsupp->dev,
"Failed to read CP state: %d\n", ret);
@@ -62,8 +63,8 @@ static void arizona_micsupp_check_cp(struct work_struct *work)
if (dapm) {
component = snd_soc_dapm_to_component(dapm);

- if ((val & (ARIZONA_CPMIC_ENA | ARIZONA_CPMIC_BYPASS)) ==
- ARIZONA_CPMIC_ENA)
+ if ((val & (desc->enable_mask | desc->bypass_mask)) ==
+ desc->enable_mask)
snd_soc_component_force_enable_pin(component,
"MICSUPP");
else
@@ -209,7 +210,6 @@ static const struct regulator_desc madera_micsupp = {
.type = REGULATOR_VOLTAGE,
.n_voltages = 40,
.ops = &arizona_micsupp_ops,
-
.vsel_reg = MADERA_LDO2_CONTROL_1,
.vsel_mask = MADERA_LDO2_VSEL_MASK,
.enable_reg = MADERA_MIC_CHARGE_PUMP_1,
@@ -264,7 +264,7 @@ static int arizona_micsupp_common_init(struct platform_device *pdev,
micsupp->init_data.consumer_supplies = &micsupp->supply;
micsupp->supply.supply = "MICVDD";
micsupp->supply.dev_name = dev_name(micsupp->dev);
- micsupp->enable_reg = desc->enable_reg;
+ micsupp->desc = desc;

config.dev = micsupp->dev;
config.driver_data = micsupp;
@@ -285,8 +285,7 @@ static int arizona_micsupp_common_init(struct platform_device *pdev,
config.init_data = &micsupp->init_data;

/* Default to regulated mode */
- regmap_update_bits(micsupp->regmap, micsupp->enable_reg,
- ARIZONA_CPMIC_BYPASS, 0);
+ regmap_update_bits(micsupp->regmap, desc->enable_reg, desc->bypass_mask, 0);

micsupp->regulator = devm_regulator_register(&pdev->dev,
desc,
--
2.30.2