Skip to content

Commit ce2eadc

Browse files
MrVanbroonie
authored andcommitted
regulator: s5m8767: Convert to GPIO descriptors
Update the driver to fetch buck_gpio and buck_ds as GPIO descriptors. Then drop the usage of 'of_gpio.h' which should be deprecated. Based on commit 84618d5 ("regulator: max8997: Convert to GPIO descriptors") as a reference to make the changes. With the quirk fix for s5m8767 in of_gpio_try_fixup_polarity, the polarity will be active-high, even if exynos5250 spring DTS wrongly use active-low polarity. So using GPIO descriptors, it should work as before. Signed-off-by: Peng Fan <[email protected]> Acked-by: Mark Brown <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Acked-by: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 4e31062 commit ce2eadc

File tree

1 file changed

+38
-108
lines changed

1 file changed

+38
-108
lines changed

drivers/regulator/s5m8767.c

Lines changed: 38 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <linux/cleanup.h>
77
#include <linux/err.h>
8-
#include <linux/of_gpio.h>
8+
#include <linux/of.h>
99
#include <linux/gpio/consumer.h>
1010
#include <linux/module.h>
1111
#include <linux/platform_device.h>
@@ -35,8 +35,8 @@ struct s5m8767_info {
3535
u8 buck2_vol[8];
3636
u8 buck3_vol[8];
3737
u8 buck4_vol[8];
38-
int buck_gpios[3];
39-
int buck_ds[3];
38+
struct gpio_desc *buck_gpios[3];
39+
struct gpio_desc *buck_ds[3];
4040
int buck_gpioindex;
4141
};
4242

@@ -272,9 +272,9 @@ static inline int s5m8767_set_high(struct s5m8767_info *s5m8767)
272272
{
273273
int temp_index = s5m8767->buck_gpioindex;
274274

275-
gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
276-
gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
277-
gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
275+
gpiod_set_value(s5m8767->buck_gpios[0], !!(temp_index & BIT(2)));
276+
gpiod_set_value(s5m8767->buck_gpios[1], !!(temp_index & BIT(1)));
277+
gpiod_set_value(s5m8767->buck_gpios[2], !!(temp_index & BIT(0)));
278278

279279
return 0;
280280
}
@@ -283,9 +283,9 @@ static inline int s5m8767_set_low(struct s5m8767_info *s5m8767)
283283
{
284284
int temp_index = s5m8767->buck_gpioindex;
285285

286-
gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1);
287-
gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1);
288-
gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1);
286+
gpiod_set_value(s5m8767->buck_gpios[2], !!(temp_index & BIT(0)));
287+
gpiod_set_value(s5m8767->buck_gpios[1], !!(temp_index & BIT(1)));
288+
gpiod_set_value(s5m8767->buck_gpios[0], !!(temp_index & BIT(2)));
289289

290290
return 0;
291291
}
@@ -482,50 +482,14 @@ static int s5m8767_enable_ext_control(struct s5m8767_info *s5m8767,
482482

483483

484484
#ifdef CONFIG_OF
485-
static int s5m8767_pmic_dt_parse_dvs_gpio(struct sec_pmic_dev *iodev,
486-
struct sec_platform_data *pdata,
487-
struct device_node *pmic_np)
488-
{
489-
int i, gpio;
490-
491-
for (i = 0; i < 3; i++) {
492-
gpio = of_get_named_gpio(pmic_np,
493-
"s5m8767,pmic-buck-dvs-gpios", i);
494-
if (!gpio_is_valid(gpio)) {
495-
dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
496-
return -EINVAL;
497-
}
498-
pdata->buck_gpios[i] = gpio;
499-
}
500-
return 0;
501-
}
502-
503-
static int s5m8767_pmic_dt_parse_ds_gpio(struct sec_pmic_dev *iodev,
504-
struct sec_platform_data *pdata,
505-
struct device_node *pmic_np)
506-
{
507-
int i, gpio;
508-
509-
for (i = 0; i < 3; i++) {
510-
gpio = of_get_named_gpio(pmic_np,
511-
"s5m8767,pmic-buck-ds-gpios", i);
512-
if (!gpio_is_valid(gpio)) {
513-
dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
514-
return -EINVAL;
515-
}
516-
pdata->buck_ds[i] = gpio;
517-
}
518-
return 0;
519-
}
520-
521485
static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
522486
struct sec_platform_data *pdata)
523487
{
524488
struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
525489
struct device_node *pmic_np, *reg_np;
526490
struct sec_regulator_data *rdata;
527491
struct sec_opmode_data *rmode;
528-
unsigned int i, dvs_voltage_nr = 8, ret;
492+
unsigned int i, dvs_voltage_nr = 8;
529493

530494
pmic_np = iodev->dev->of_node;
531495
if (!pmic_np) {
@@ -635,10 +599,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
635599

636600
if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
637601
pdata->buck4_gpiodvs) {
638-
ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
639-
if (ret)
640-
return -EINVAL;
641-
642602
if (of_property_read_u32(pmic_np,
643603
"s5m8767,pmic-buck-default-dvs-idx",
644604
&pdata->buck_default_idx)) {
@@ -652,10 +612,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
652612
}
653613
}
654614

655-
ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np);
656-
if (ret)
657-
return -EINVAL;
658-
659615
pdata->buck2_ramp_enable = of_property_read_bool(pmic_np, "s5m8767,pmic-buck2-ramp-enable");
660616
pdata->buck3_ramp_enable = of_property_read_bool(pmic_np, "s5m8767,pmic-buck3-ramp-enable");
661617
pdata->buck4_ramp_enable = of_property_read_bool(pmic_np, "s5m8767,pmic-buck4-ramp-enable");
@@ -684,6 +640,8 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
684640
struct regulator_config config = { };
685641
struct s5m8767_info *s5m8767;
686642
int i, ret, buck_init;
643+
const char *gpiods_names[3] = { "S5M8767 DS2", "S5M8767 DS3", "S5M8767 DS4" };
644+
const char *gpiodvs_names[3] = { "S5M8767 SET1", "S5M8767 SET2", "S5M8767 SET3" };
687645

688646
if (!pdata) {
689647
dev_err(pdev->dev.parent, "Platform data not supplied\n");
@@ -731,12 +689,6 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
731689
s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs;
732690
s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs;
733691
s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs;
734-
s5m8767->buck_gpios[0] = pdata->buck_gpios[0];
735-
s5m8767->buck_gpios[1] = pdata->buck_gpios[1];
736-
s5m8767->buck_gpios[2] = pdata->buck_gpios[2];
737-
s5m8767->buck_ds[0] = pdata->buck_ds[0];
738-
s5m8767->buck_ds[1] = pdata->buck_ds[1];
739-
s5m8767->buck_ds[2] = pdata->buck_ds[2];
740692

741693
s5m8767->ramp_delay = pdata->buck_ramp_delay;
742694
s5m8767->buck2_ramp = pdata->buck2_ramp_enable;
@@ -787,58 +739,36 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
787739

788740
if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
789741
pdata->buck4_gpiodvs) {
742+
for (i = 0; i < 3; i++) {
743+
enum gpiod_flags flags;
790744

791-
if (!gpio_is_valid(pdata->buck_gpios[0]) ||
792-
!gpio_is_valid(pdata->buck_gpios[1]) ||
793-
!gpio_is_valid(pdata->buck_gpios[2])) {
794-
dev_err(&pdev->dev, "GPIO NOT VALID\n");
795-
return -EINVAL;
796-
}
797-
798-
ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0],
799-
"S5M8767 SET1");
800-
if (ret)
801-
return ret;
802-
803-
ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1],
804-
"S5M8767 SET2");
805-
if (ret)
806-
return ret;
807-
808-
ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2],
809-
"S5M8767 SET3");
810-
if (ret)
811-
return ret;
745+
if (s5m8767->buck_gpioindex & BIT(2 - i))
746+
flags = GPIOD_OUT_HIGH;
747+
else
748+
flags = GPIOD_OUT_LOW;
749+
750+
s5m8767->buck_gpios[i] = devm_gpiod_get_index(iodev->dev,
751+
"s5m8767,pmic-buck-dvs", i,
752+
flags);
753+
if (IS_ERR(s5m8767->buck_gpios[i])) {
754+
return dev_err_probe(iodev->dev, PTR_ERR(s5m8767->buck_gpios[i]),
755+
"invalid gpio[%d]\n", i);
756+
}
812757

813-
/* SET1 GPIO */
814-
gpio_direction_output(pdata->buck_gpios[0],
815-
(s5m8767->buck_gpioindex >> 2) & 0x1);
816-
/* SET2 GPIO */
817-
gpio_direction_output(pdata->buck_gpios[1],
818-
(s5m8767->buck_gpioindex >> 1) & 0x1);
819-
/* SET3 GPIO */
820-
gpio_direction_output(pdata->buck_gpios[2],
821-
(s5m8767->buck_gpioindex >> 0) & 0x1);
758+
gpiod_set_consumer_name(s5m8767->buck_gpios[i], gpiodvs_names[i]);
759+
}
822760
}
823761

824-
ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2");
825-
if (ret)
826-
return ret;
827-
828-
ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3");
829-
if (ret)
830-
return ret;
831-
832-
ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4");
833-
if (ret)
834-
return ret;
835-
836-
/* DS2 GPIO */
837-
gpio_direction_output(pdata->buck_ds[0], 0x0);
838-
/* DS3 GPIO */
839-
gpio_direction_output(pdata->buck_ds[1], 0x0);
840-
/* DS4 GPIO */
841-
gpio_direction_output(pdata->buck_ds[2], 0x0);
762+
for (i = 0; i < 3; i++) {
763+
s5m8767->buck_ds[i] = devm_gpiod_get_index(iodev->dev,
764+
"s5m8767,pmic-buck-ds", i,
765+
GPIOD_OUT_LOW);
766+
if (IS_ERR(s5m8767->buck_ds[i])) {
767+
return dev_err_probe(iodev->dev, PTR_ERR(s5m8767->buck_ds[i]),
768+
"can't get GPIO %d\n", i);
769+
}
770+
gpiod_set_consumer_name(s5m8767->buck_ds[i], gpiods_names[i]);
771+
}
842772

843773
regmap_update_bits(s5m8767->iodev->regmap_pmic,
844774
S5M8767_REG_BUCK2CTRL, 1 << 1,

0 commit comments

Comments
 (0)