Skip to content

Commit 4d52f57

Browse files
linuswbroonie
authored andcommitted
regulator: max8973: Finalize switch to GPIO descriptors
The dvs gpio was still using a legacy number passed from the platform data. There are no in-tree users of the platform data so just switch it to a gpio descriptor and obtain it in probe(), the device tree users will work just as fine with this. Drop the entirely unused enable_gpio from the platform data as well. The device tree bindings mentions this but the driver does not look for it and makes no use of it: it should probably be implemented properly in a separate patch. Signed-off-by: Linus Walleij <[email protected]> Link: https://msgid.link/r/[email protected] Acked-by: Lee Jones <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 132a85f commit 4d52f57

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

drivers/regulator/max8973-regulator.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
#include <linux/regulator/machine.h>
2121
#include <linux/regulator/max8973-regulator.h>
2222
#include <linux/regulator/of_regulator.h>
23-
#include <linux/gpio.h>
2423
#include <linux/gpio/consumer.h>
25-
#include <linux/of_gpio.h>
2624
#include <linux/i2c.h>
2725
#include <linux/slab.h>
2826
#include <linux/regmap.h>
@@ -102,7 +100,7 @@ struct max8973_chip {
102100
struct regulator_desc desc;
103101
struct regmap *regmap;
104102
bool enable_external_control;
105-
int dvs_gpio;
103+
struct gpio_desc *dvs_gpiod;
106104
int lru_index[MAX8973_MAX_VOUT_REG];
107105
int curr_vout_val[MAX8973_MAX_VOUT_REG];
108106
int curr_vout_reg;
@@ -184,7 +182,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
184182
* If gpios are available to select the VOUT register then least
185183
* recently used register for new configuration.
186184
*/
187-
if (gpio_is_valid(max->dvs_gpio))
185+
if (max->dvs_gpiod)
188186
found = find_voltage_set_register(max, vsel,
189187
&vout_reg, &gpio_val);
190188

@@ -201,8 +199,8 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
201199
}
202200

203201
/* Select proper VOUT register vio gpios */
204-
if (gpio_is_valid(max->dvs_gpio)) {
205-
gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
202+
if (max->dvs_gpiod) {
203+
gpiod_set_value_cansleep(max->dvs_gpiod, gpio_val & 0x1);
206204
max->curr_gpio_val = gpio_val;
207205
}
208206
return 0;
@@ -531,7 +529,6 @@ static struct max8973_regulator_platform_data *max8973_parse_dt(
531529

532530
pdata->enable_ext_control = of_property_read_bool(np,
533531
"maxim,externally-enable");
534-
pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
535532

536533
ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
537534
if (!ret)
@@ -612,13 +609,17 @@ static int max8973_probe(struct i2c_client *client)
612609
return -EIO;
613610
}
614611

615-
if (pdata->dvs_gpio == -EPROBE_DEFER)
616-
return -EPROBE_DEFER;
617-
618612
max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
619613
if (!max)
620614
return -ENOMEM;
621615

616+
max->dvs_gpiod = devm_gpiod_get_optional(&client->dev, "maxim,dvs",
617+
(pdata->dvs_def_state) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
618+
if (IS_ERR(max->dvs_gpiod))
619+
return dev_err_probe(&client->dev, PTR_ERR(max->dvs_gpiod),
620+
"failed to obtain dvs gpio\n");
621+
gpiod_set_consumer_name(max->dvs_gpiod, "max8973-dvs");
622+
622623
max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config);
623624
if (IS_ERR(max->regmap)) {
624625
ret = PTR_ERR(max->regmap);
@@ -663,29 +664,16 @@ static int max8973_probe(struct i2c_client *client)
663664
max->desc.ramp_delay_table = max8973_buck_ramp_table;
664665
max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table);
665666

666-
max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
667667
max->enable_external_control = pdata->enable_ext_control;
668668
max->curr_gpio_val = pdata->dvs_def_state;
669669
max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
670670
max->junction_temp_warning = pdata->junction_temp_warning;
671671

672672
max->lru_index[0] = max->curr_vout_reg;
673673

674-
if (gpio_is_valid(max->dvs_gpio)) {
675-
int gpio_flags;
674+
if (max->dvs_gpiod) {
676675
int i;
677676

678-
gpio_flags = (pdata->dvs_def_state) ?
679-
GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
680-
ret = devm_gpio_request_one(&client->dev, max->dvs_gpio,
681-
gpio_flags, "max8973-dvs");
682-
if (ret) {
683-
dev_err(&client->dev,
684-
"gpio_request for gpio %d failed, err = %d\n",
685-
max->dvs_gpio, ret);
686-
return ret;
687-
}
688-
689677
/*
690678
* Initialize the lru index with vout_reg id
691679
* The index 0 will be most recently used and

include/linux/regulator/max8973-regulator.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@
4848
* control signal from EN input pin. If it is false then
4949
* voltage output will be enabled/disabled through EN bit of
5050
* device register.
51-
* @enable_gpio: Enable GPIO. If EN pin is controlled through GPIO from host
52-
* then GPIO number can be provided. If no GPIO controlled then
53-
* it should be -1.
54-
* @dvs_gpio: GPIO for dvs. It should be -1 if this is tied with fixed logic.
5551
* @dvs_def_state: Default state of dvs. 1 if it is high else 0.
5652
*/
5753
struct max8973_regulator_platform_data {
5854
struct regulator_init_data *reg_init_data;
5955
unsigned long control_flags;
6056
unsigned long junction_temp_warning;
6157
bool enable_ext_control;
62-
int enable_gpio;
63-
int dvs_gpio;
6458
unsigned dvs_def_state:1;
6559
};
6660

0 commit comments

Comments
 (0)