Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 84618d5e31cf ("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 <peng.fan@nxp.com>
Acked-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20250327004945.563765-2-peng.fan@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Peng Fan and committed by
Mark Brown
ce2eadc6 4e310626

+38 -108
+38 -108
drivers/regulator/s5m8767.c
··· 5 5 6 6 #include <linux/cleanup.h> 7 7 #include <linux/err.h> 8 - #include <linux/of_gpio.h> 8 + #include <linux/of.h> 9 9 #include <linux/gpio/consumer.h> 10 10 #include <linux/module.h> 11 11 #include <linux/platform_device.h> ··· 35 35 u8 buck2_vol[8]; 36 36 u8 buck3_vol[8]; 37 37 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]; 40 40 int buck_gpioindex; 41 41 }; 42 42 ··· 272 272 { 273 273 int temp_index = s5m8767->buck_gpioindex; 274 274 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))); 278 278 279 279 return 0; 280 280 } ··· 283 283 { 284 284 int temp_index = s5m8767->buck_gpioindex; 285 285 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))); 289 289 290 290 return 0; 291 291 } ··· 482 482 483 483 484 484 #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 - 521 485 static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, 522 486 struct sec_platform_data *pdata) 523 487 { ··· 489 525 struct device_node *pmic_np, *reg_np; 490 526 struct sec_regulator_data *rdata; 491 527 struct sec_opmode_data *rmode; 492 - unsigned int i, dvs_voltage_nr = 8, ret; 528 + unsigned int i, dvs_voltage_nr = 8; 493 529 494 530 pmic_np = iodev->dev->of_node; 495 531 if (!pmic_np) { ··· 599 635 600 636 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || 601 637 pdata->buck4_gpiodvs) { 602 - ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); 603 - if (ret) 604 - return -EINVAL; 605 - 606 638 if (of_property_read_u32(pmic_np, 607 639 "s5m8767,pmic-buck-default-dvs-idx", 608 640 &pdata->buck_default_idx)) { ··· 611 651 } 612 652 } 613 653 } 614 - 615 - ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np); 616 - if (ret) 617 - return -EINVAL; 618 654 619 655 pdata->buck2_ramp_enable = of_property_read_bool(pmic_np, "s5m8767,pmic-buck2-ramp-enable"); 620 656 pdata->buck3_ramp_enable = of_property_read_bool(pmic_np, "s5m8767,pmic-buck3-ramp-enable"); ··· 640 684 struct regulator_config config = { }; 641 685 struct s5m8767_info *s5m8767; 642 686 int i, ret, buck_init; 687 + const char *gpiods_names[3] = { "S5M8767 DS2", "S5M8767 DS3", "S5M8767 DS4" }; 688 + const char *gpiodvs_names[3] = { "S5M8767 SET1", "S5M8767 SET2", "S5M8767 SET3" }; 643 689 644 690 if (!pdata) { 645 691 dev_err(pdev->dev.parent, "Platform data not supplied\n"); ··· 689 731 s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; 690 732 s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; 691 733 s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; 692 - s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; 693 - s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; 694 - s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; 695 - s5m8767->buck_ds[0] = pdata->buck_ds[0]; 696 - s5m8767->buck_ds[1] = pdata->buck_ds[1]; 697 - s5m8767->buck_ds[2] = pdata->buck_ds[2]; 698 734 699 735 s5m8767->ramp_delay = pdata->buck_ramp_delay; 700 736 s5m8767->buck2_ramp = pdata->buck2_ramp_enable; ··· 739 787 740 788 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || 741 789 pdata->buck4_gpiodvs) { 790 + for (i = 0; i < 3; i++) { 791 + enum gpiod_flags flags; 742 792 743 - if (!gpio_is_valid(pdata->buck_gpios[0]) || 744 - !gpio_is_valid(pdata->buck_gpios[1]) || 745 - !gpio_is_valid(pdata->buck_gpios[2])) { 746 - dev_err(&pdev->dev, "GPIO NOT VALID\n"); 747 - return -EINVAL; 793 + if (s5m8767->buck_gpioindex & BIT(2 - i)) 794 + flags = GPIOD_OUT_HIGH; 795 + else 796 + flags = GPIOD_OUT_LOW; 797 + 798 + s5m8767->buck_gpios[i] = devm_gpiod_get_index(iodev->dev, 799 + "s5m8767,pmic-buck-dvs", i, 800 + flags); 801 + if (IS_ERR(s5m8767->buck_gpios[i])) { 802 + return dev_err_probe(iodev->dev, PTR_ERR(s5m8767->buck_gpios[i]), 803 + "invalid gpio[%d]\n", i); 804 + } 805 + 806 + gpiod_set_consumer_name(s5m8767->buck_gpios[i], gpiodvs_names[i]); 748 807 } 749 - 750 - ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0], 751 - "S5M8767 SET1"); 752 - if (ret) 753 - return ret; 754 - 755 - ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1], 756 - "S5M8767 SET2"); 757 - if (ret) 758 - return ret; 759 - 760 - ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2], 761 - "S5M8767 SET3"); 762 - if (ret) 763 - return ret; 764 - 765 - /* SET1 GPIO */ 766 - gpio_direction_output(pdata->buck_gpios[0], 767 - (s5m8767->buck_gpioindex >> 2) & 0x1); 768 - /* SET2 GPIO */ 769 - gpio_direction_output(pdata->buck_gpios[1], 770 - (s5m8767->buck_gpioindex >> 1) & 0x1); 771 - /* SET3 GPIO */ 772 - gpio_direction_output(pdata->buck_gpios[2], 773 - (s5m8767->buck_gpioindex >> 0) & 0x1); 774 808 } 775 809 776 - ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2"); 777 - if (ret) 778 - return ret; 779 - 780 - ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3"); 781 - if (ret) 782 - return ret; 783 - 784 - ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4"); 785 - if (ret) 786 - return ret; 787 - 788 - /* DS2 GPIO */ 789 - gpio_direction_output(pdata->buck_ds[0], 0x0); 790 - /* DS3 GPIO */ 791 - gpio_direction_output(pdata->buck_ds[1], 0x0); 792 - /* DS4 GPIO */ 793 - gpio_direction_output(pdata->buck_ds[2], 0x0); 810 + for (i = 0; i < 3; i++) { 811 + s5m8767->buck_ds[i] = devm_gpiod_get_index(iodev->dev, 812 + "s5m8767,pmic-buck-ds", i, 813 + GPIOD_OUT_LOW); 814 + if (IS_ERR(s5m8767->buck_ds[i])) { 815 + return dev_err_probe(iodev->dev, PTR_ERR(s5m8767->buck_ds[i]), 816 + "can't get GPIO %d\n", i); 817 + } 818 + gpiod_set_consumer_name(s5m8767->buck_ds[i], gpiods_names[i]); 819 + } 794 820 795 821 regmap_update_bits(s5m8767->iodev->regmap_pmic, 796 822 S5M8767_REG_BUCK2CTRL, 1 << 1,