Skip to content

Commit 72bf80c

Browse files
mairacanalbroonie
authored andcommitted
regulator: lp872x: replacing legacy gpio interface for gpiod
Removing all linux/gpio.h and linux/of_gpio.h dependencies and replacing them with the gpiod interface Signed-off-by: Maíra Canal <[email protected]> Message-Id: <YWma2yTyuwS5XwhY@fedora> Signed-off-by: Mark Brown <[email protected]>
1 parent 636bdb5 commit 72bf80c

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

drivers/regulator/lp872x.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
#include <linux/i2c.h>
1111
#include <linux/regmap.h>
1212
#include <linux/err.h>
13-
#include <linux/gpio.h>
13+
#include <linux/gpio/consumer.h>
1414
#include <linux/delay.h>
1515
#include <linux/regulator/lp872x.h>
1616
#include <linux/regulator/driver.h>
1717
#include <linux/platform_device.h>
1818
#include <linux/of.h>
19-
#include <linux/of_gpio.h>
2019
#include <linux/regulator/of_regulator.h>
2120

2221
/* Registers : LP8720/8725 shared */
@@ -250,12 +249,12 @@ static int lp872x_regulator_enable_time(struct regulator_dev *rdev)
250249
}
251250

252251
static void lp872x_set_dvs(struct lp872x *lp, enum lp872x_dvs_sel dvs_sel,
253-
int gpio)
252+
struct gpio_desc *gpio)
254253
{
255254
enum lp872x_dvs_state state;
256255

257256
state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW;
258-
gpio_set_value(gpio, state);
257+
gpiod_set_value(gpio, state);
259258
lp->dvs_pin = state;
260259
}
261260

@@ -321,7 +320,7 @@ static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev,
321320
u8 addr, mask = LP872X_VOUT_M;
322321
struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
323322

324-
if (dvs && gpio_is_valid(dvs->gpio))
323+
if (dvs && dvs->gpio)
325324
lp872x_set_dvs(lp, dvs->vsel, dvs->gpio);
326325

327326
addr = lp872x_select_buck_vout_addr(lp, buck);
@@ -675,7 +674,6 @@ static const struct regulator_desc lp8725_regulator_desc[] = {
675674

676675
static int lp872x_init_dvs(struct lp872x *lp)
677676
{
678-
int ret, gpio;
679677
struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL;
680678
enum lp872x_dvs_state pinstate;
681679
u8 mask[] = { LP8720_EXT_DVS_M, LP8725_DVS1_M | LP8725_DVS2_M };
@@ -684,15 +682,15 @@ static int lp872x_init_dvs(struct lp872x *lp)
684682
if (!dvs)
685683
goto set_default_dvs_mode;
686684

687-
gpio = dvs->gpio;
688-
if (!gpio_is_valid(gpio))
685+
if (!dvs->gpio)
689686
goto set_default_dvs_mode;
690687

691688
pinstate = dvs->init_state;
692-
ret = devm_gpio_request_one(lp->dev, gpio, pinstate, "LP872X DVS");
693-
if (ret) {
694-
dev_err(lp->dev, "gpio request err: %d\n", ret);
695-
return ret;
689+
dvs->gpio = devm_gpiod_get_optional(lp->dev, "ti,dvs", pinstate);
690+
691+
if (IS_ERR(dvs->gpio)) {
692+
dev_err(lp->dev, "gpio request err: %ld\n", PTR_ERR(dvs->gpio));
693+
return PTR_ERR(dvs->gpio);
696694
}
697695

698696
lp->dvs_pin = pinstate;
@@ -706,20 +704,17 @@ static int lp872x_init_dvs(struct lp872x *lp)
706704

707705
static int lp872x_hw_enable(struct lp872x *lp)
708706
{
709-
int ret, gpio;
710-
711707
if (!lp->pdata)
712708
return -EINVAL;
713709

714-
gpio = lp->pdata->enable_gpio;
715-
if (!gpio_is_valid(gpio))
710+
if (!lp->pdata->enable_gpio)
716711
return 0;
717712

718713
/* Always set enable GPIO high. */
719-
ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN");
720-
if (ret) {
721-
dev_err(lp->dev, "gpio request err: %d\n", ret);
722-
return ret;
714+
lp->pdata->enable_gpio = devm_gpiod_get_optional(lp->dev, "enable", GPIOD_OUT_HIGH);
715+
if (IS_ERR(lp->pdata->enable_gpio)) {
716+
dev_err(lp->dev, "gpio request err: %ld\n", PTR_ERR(lp->pdata->enable_gpio));
717+
return PTR_ERR(lp->pdata->enable_gpio);
723718
}
724719

725720
/* Each chip has a different enable delay. */
@@ -844,13 +839,10 @@ static struct lp872x_platform_data
844839
if (!pdata->dvs)
845840
return ERR_PTR(-ENOMEM);
846841

847-
pdata->dvs->gpio = of_get_named_gpio(np, "ti,dvs-gpio", 0);
848842
of_property_read_u8(np, "ti,dvs-vsel", (u8 *)&pdata->dvs->vsel);
849843
of_property_read_u8(np, "ti,dvs-state", &dvs_state);
850844
pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW;
851845

852-
pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0);
853-
854846
if (of_get_child_count(np) == 0)
855847
goto out;
856848

include/linux/regulator/lp872x.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <linux/regulator/machine.h>
1212
#include <linux/platform_device.h>
13-
#include <linux/gpio.h>
13+
#include <linux/gpio/consumer.h>
1414

1515
#define LP872X_MAX_REGULATORS 9
1616

@@ -41,8 +41,8 @@ enum lp872x_regulator_id {
4141
};
4242

4343
enum lp872x_dvs_state {
44-
DVS_LOW = GPIOF_OUT_INIT_LOW,
45-
DVS_HIGH = GPIOF_OUT_INIT_HIGH,
44+
DVS_LOW = GPIOD_OUT_LOW,
45+
DVS_HIGH = GPIOD_OUT_HIGH,
4646
};
4747

4848
enum lp872x_dvs_sel {
@@ -52,12 +52,12 @@ enum lp872x_dvs_sel {
5252

5353
/**
5454
* lp872x_dvs
55-
* @gpio : gpio pin number for dvs control
55+
* @gpio : gpio descriptor for dvs control
5656
* @vsel : dvs selector for buck v1 or buck v2 register
5757
* @init_state : initial dvs pin state
5858
*/
5959
struct lp872x_dvs {
60-
int gpio;
60+
struct gpio_desc *gpio;
6161
enum lp872x_dvs_sel vsel;
6262
enum lp872x_dvs_state init_state;
6363
};
@@ -78,14 +78,14 @@ struct lp872x_regulator_data {
7878
* @update_config : if LP872X_GENERAL_CFG register is updated, set true
7979
* @regulator_data : platform regulator id and init data
8080
* @dvs : dvs data for buck voltage control
81-
* @enable_gpio : gpio pin number for enable control
81+
* @enable_gpio : gpio descriptor for enable control
8282
*/
8383
struct lp872x_platform_data {
8484
u8 general_config;
8585
bool update_config;
8686
struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS];
8787
struct lp872x_dvs *dvs;
88-
int enable_gpio;
88+
struct gpio_desc *enable_gpio;
8989
};
9090

9191
#endif

0 commit comments

Comments
 (0)