Skip to content

Commit fd742ea

Browse files
linuswbroonie
authored andcommitted
regulator: max8952: Convert to use GPIO descriptors
This finalizes the descriptor conversion of the MAX8952 driver by letting the VID0 and VID1 GPIOs be fetched from descriptors. Both VID0 and VID1 must be supplied for the VID selection to work, I add some code to preserve the semantics that if only one of the two VID gpios is supplied, it will be initialized to low. This might be a bit overzealous, but I want to preserve any implicit semantics. This is currently only used by device tree in-kernel but it is still also possible to supply the same GPIOs using a machine descriptor table if a board file is used. Ideally this should be phased over to using gpio-regulator.c that does the same thing, but it might require some refactoring and needs testing on real hardware. Cc: Tomasz Figa <[email protected]> Cc: MyungJoo Ham <[email protected]> Cc: Marek Szyprowski <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 6f10419 commit fd742ea

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

drivers/regulator/max8952.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
#include <linux/platform_device.h>
2727
#include <linux/regulator/driver.h>
2828
#include <linux/regulator/max8952.h>
29-
#include <linux/gpio.h>
3029
#include <linux/gpio/consumer.h>
3130
#include <linux/io.h>
3231
#include <linux/of.h>
33-
#include <linux/of_gpio.h>
3432
#include <linux/regulator/of_regulator.h>
3533
#include <linux/slab.h>
3634

@@ -50,7 +48,8 @@ enum {
5048
struct max8952_data {
5149
struct i2c_client *client;
5250
struct max8952_platform_data *pdata;
53-
51+
struct gpio_desc *vid0_gpiod;
52+
struct gpio_desc *vid1_gpiod;
5453
bool vid0;
5554
bool vid1;
5655
};
@@ -100,16 +99,15 @@ static int max8952_set_voltage_sel(struct regulator_dev *rdev,
10099
{
101100
struct max8952_data *max8952 = rdev_get_drvdata(rdev);
102101

103-
if (!gpio_is_valid(max8952->pdata->gpio_vid0) ||
104-
!gpio_is_valid(max8952->pdata->gpio_vid1)) {
102+
if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) {
105103
/* DVS not supported */
106104
return -EPERM;
107105
}
108106

109107
max8952->vid0 = selector & 0x1;
110108
max8952->vid1 = (selector >> 1) & 0x1;
111-
gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0);
112-
gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1);
109+
gpiod_set_value(max8952->vid0_gpiod, max8952->vid0);
110+
gpiod_set_value(max8952->vid1_gpiod, max8952->vid1);
113111

114112
return 0;
115113
}
@@ -147,9 +145,6 @@ static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
147145
if (!pd)
148146
return NULL;
149147

150-
pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0);
151-
pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1);
152-
153148
if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode))
154149
dev_warn(dev, "Default mode not specified, assuming 0\n");
155150

@@ -200,7 +195,7 @@ static int max8952_pmic_probe(struct i2c_client *client,
200195
struct gpio_desc *gpiod;
201196
enum gpiod_flags gflags;
202197

203-
int ret = 0, err = 0;
198+
int ret = 0;
204199

205200
if (client->dev.of_node)
206201
pdata = max8952_parse_dt(&client->dev);
@@ -253,32 +248,31 @@ static int max8952_pmic_probe(struct i2c_client *client,
253248
max8952->vid0 = pdata->default_mode & 0x1;
254249
max8952->vid1 = (pdata->default_mode >> 1) & 0x1;
255250

256-
if (gpio_is_valid(pdata->gpio_vid0) &&
257-
gpio_is_valid(pdata->gpio_vid1)) {
258-
unsigned long gpio_flags;
259-
260-
gpio_flags = max8952->vid0 ?
261-
GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
262-
if (devm_gpio_request_one(&client->dev, pdata->gpio_vid0,
263-
gpio_flags, "MAX8952 VID0"))
264-
err = 1;
265-
266-
gpio_flags = max8952->vid1 ?
267-
GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
268-
if (devm_gpio_request_one(&client->dev, pdata->gpio_vid1,
269-
gpio_flags, "MAX8952 VID1"))
270-
err = 2;
271-
} else
272-
err = 3;
273-
274-
if (err) {
251+
/* Fetch vid0 and vid1 GPIOs if available */
252+
gflags = max8952->vid0 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
253+
max8952->vid0_gpiod = devm_gpiod_get_index_optional(&client->dev,
254+
"max8952,vid",
255+
0, gflags);
256+
if (IS_ERR(max8952->vid0_gpiod))
257+
return PTR_ERR(max8952->vid0_gpiod);
258+
gflags = max8952->vid1 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
259+
max8952->vid1_gpiod = devm_gpiod_get_index_optional(&client->dev,
260+
"max8952,vid",
261+
1, gflags);
262+
if (IS_ERR(max8952->vid1_gpiod))
263+
return PTR_ERR(max8952->vid1_gpiod);
264+
265+
/* If either VID GPIO is missing just disable this */
266+
if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) {
275267
dev_warn(&client->dev, "VID0/1 gpio invalid: "
276-
"DVS not available.\n");
268+
"DVS not available.\n");
277269
max8952->vid0 = 0;
278270
max8952->vid1 = 0;
279-
/* Mark invalid */
280-
pdata->gpio_vid0 = -1;
281-
pdata->gpio_vid1 = -1;
271+
/* Make sure if we have any descriptors they get set to low */
272+
if (max8952->vid0_gpiod)
273+
gpiod_set_value(max8952->vid0_gpiod, 0);
274+
if (max8952->vid1_gpiod)
275+
gpiod_set_value(max8952->vid1_gpiod, 0);
282276

283277
/* Disable Pulldown of EN only */
284278
max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60);

include/linux/regulator/max8952.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ enum {
118118
#define MAX8952_NUM_DVS_MODE 4
119119

120120
struct max8952_platform_data {
121-
int gpio_vid0;
122-
int gpio_vid1;
123-
124121
u32 default_mode;
125122
u32 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */
126123

0 commit comments

Comments
 (0)