Skip to content

Commit 6a8b5bb

Browse files
mairacanalbroonie
authored andcommitted
regulator: tps62360: 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]> Link: https://lore.kernel.org/r/YWxmL2baF5AdzyHv@fedora Signed-off-by: Mark Brown <[email protected]>
1 parent 061514d commit 6a8b5bb

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

drivers/regulator/tps62360-regulator.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@
2828
#include <linux/err.h>
2929
#include <linux/of.h>
3030
#include <linux/of_device.h>
31-
#include <linux/of_gpio.h>
3231
#include <linux/regulator/of_regulator.h>
3332
#include <linux/platform_device.h>
3433
#include <linux/regulator/driver.h>
3534
#include <linux/regulator/machine.h>
3635
#include <linux/regulator/tps62360.h>
37-
#include <linux/gpio.h>
36+
#include <linux/gpio/consumer.h>
3837
#include <linux/i2c.h>
3938
#include <linux/slab.h>
4039
#include <linux/regmap.h>
@@ -65,8 +64,8 @@ struct tps62360_chip {
6564
struct regulator_desc desc;
6665
struct regulator_dev *rdev;
6766
struct regmap *regmap;
68-
int vsel0_gpio;
69-
int vsel1_gpio;
67+
struct gpio_desc *vsel0_gpio;
68+
struct gpio_desc *vsel1_gpio;
7069
u8 voltage_reg_mask;
7170
bool en_internal_pulldn;
7271
bool en_discharge;
@@ -165,8 +164,8 @@ static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
165164

166165
/* Select proper VSET register vio gpios */
167166
if (tps->valid_gpios) {
168-
gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
169-
gpio_set_value_cansleep(tps->vsel1_gpio,
167+
gpiod_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
168+
gpiod_set_value_cansleep(tps->vsel1_gpio,
170169
(new_vset_id >> 1) & 0x1);
171170
}
172171
return 0;
@@ -310,9 +309,6 @@ static struct tps62360_regulator_platform_data *
310309
return NULL;
311310
}
312311

313-
pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
314-
pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
315-
316312
if (of_find_property(np, "ti,vsel0-state-high", NULL))
317313
pdata->vsel0_def_state = 1;
318314

@@ -349,6 +345,7 @@ static int tps62360_probe(struct i2c_client *client,
349345
int ret;
350346
int i;
351347
int chip_id;
348+
int gpio_flags;
352349

353350
pdata = dev_get_platdata(&client->dev);
354351

@@ -390,8 +387,6 @@ static int tps62360_probe(struct i2c_client *client,
390387

391388
tps->en_discharge = pdata->en_discharge;
392389
tps->en_internal_pulldn = pdata->en_internal_pulldn;
393-
tps->vsel0_gpio = pdata->vsel0_gpio;
394-
tps->vsel1_gpio = pdata->vsel1_gpio;
395390
tps->dev = &client->dev;
396391

397392
switch (chip_id) {
@@ -426,29 +421,27 @@ static int tps62360_probe(struct i2c_client *client,
426421
tps->lru_index[0] = tps->curr_vset_id;
427422
tps->valid_gpios = false;
428423

429-
if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
430-
int gpio_flags;
431-
gpio_flags = (pdata->vsel0_def_state) ?
432-
GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
433-
ret = devm_gpio_request_one(&client->dev, tps->vsel0_gpio,
434-
gpio_flags, "tps62360-vsel0");
435-
if (ret) {
436-
dev_err(&client->dev,
437-
"%s(): Could not obtain vsel0 GPIO %d: %d\n",
438-
__func__, tps->vsel0_gpio, ret);
439-
return ret;
440-
}
424+
gpio_flags = (pdata->vsel0_def_state) ?
425+
GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
426+
tps->vsel0_gpio = devm_gpiod_get_optional(&client->dev, "vsel0", gpio_flags);
427+
if (IS_ERR(tps->vsel0_gpio)) {
428+
dev_err(&client->dev,
429+
"%s(): Could not obtain vsel0 GPIO: %ld\n",
430+
__func__, PTR_ERR(tps->vsel0_gpio));
431+
return PTR_ERR(tps->vsel0_gpio);
432+
}
441433

442-
gpio_flags = (pdata->vsel1_def_state) ?
443-
GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
444-
ret = devm_gpio_request_one(&client->dev, tps->vsel1_gpio,
445-
gpio_flags, "tps62360-vsel1");
446-
if (ret) {
447-
dev_err(&client->dev,
448-
"%s(): Could not obtain vsel1 GPIO %d: %d\n",
449-
__func__, tps->vsel1_gpio, ret);
450-
return ret;
451-
}
434+
gpio_flags = (pdata->vsel1_def_state) ?
435+
GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
436+
tps->vsel1_gpio = devm_gpiod_get_optional(&client->dev, "vsel1", gpio_flags);
437+
if (IS_ERR(tps->vsel1_gpio)) {
438+
dev_err(&client->dev,
439+
"%s(): Could not obtain vsel1 GPIO: %ld\n",
440+
__func__, PTR_ERR(tps->vsel1_gpio));
441+
return PTR_ERR(tps->vsel1_gpio);
442+
}
443+
444+
if (tps->vsel0_gpio != NULL && tps->vsel1_gpio != NULL) {
452445
tps->valid_gpios = true;
453446

454447
/*

include/linux/regulator/tps62360.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@
1919
* @en_discharge: Enable discharge the output capacitor via internal
2020
* register.
2121
* @en_internal_pulldn: internal pull down enable or not.
22-
* @vsel0_gpio: Gpio number for vsel0. It should be -1 if this is tied with
23-
* fixed logic.
24-
* @vsel1_gpio: Gpio number for vsel1. It should be -1 if this is tied with
25-
* fixed logic.
2622
* @vsel0_def_state: Default state of vsel0. 1 if it is high else 0.
2723
* @vsel1_def_state: Default state of vsel1. 1 if it is high else 0.
2824
*/
2925
struct tps62360_regulator_platform_data {
3026
struct regulator_init_data *reg_init_data;
3127
bool en_discharge;
3228
bool en_internal_pulldn;
33-
int vsel0_gpio;
34-
int vsel1_gpio;
3529
int vsel0_def_state;
3630
int vsel1_def_state;
3731
};

0 commit comments

Comments
 (0)