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

Configure Feed

Select the types of activity you want to include in your feed.

regulator: max8997: Convert to GPIO descriptors

This rewrites the max8997 regulator driver to fetch the dvs
regulators as descriptors. This will likely mostly come from
the device tree since there are no in-tree users of the platform
data, but supplying GPIO descriptor tables from board files is
also possible if needed.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://msgid.link/r/20240220-descriptors-regulators-v1-4-097f608694be@linaro.org
Acked-by: Lee Jones <lee@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
84618d5e 95daa868

+25 -61
+25 -60
drivers/regulator/max8997-regulator.c
··· 9 9 10 10 #include <linux/bug.h> 11 11 #include <linux/err.h> 12 - #include <linux/gpio.h> 13 - #include <linux/of_gpio.h> 12 + #include <linux/gpio/consumer.h> 14 13 #include <linux/slab.h> 15 14 #include <linux/module.h> 16 15 #include <linux/platform_device.h> ··· 31 32 u8 buck1_vol[8]; 32 33 u8 buck2_vol[8]; 33 34 u8 buck5_vol[8]; 34 - int buck125_gpios[3]; 35 + struct gpio_desc *buck125_gpiods[3]; 35 36 int buck125_gpioindex; 36 37 bool ignore_gpiodvs_side_effect; 37 38 ··· 51 52 int set2 = ((max8997->buck125_gpioindex) >> 1) & 0x1; 52 53 int set1 = ((max8997->buck125_gpioindex) >> 2) & 0x1; 53 54 54 - gpio_set_value(max8997->buck125_gpios[0], set1); 55 - gpio_set_value(max8997->buck125_gpios[1], set2); 56 - gpio_set_value(max8997->buck125_gpios[2], set3); 55 + gpiod_set_value(max8997->buck125_gpiods[0], set1); 56 + gpiod_set_value(max8997->buck125_gpiods[1], set2); 57 + gpiod_set_value(max8997->buck125_gpiods[2], set3); 57 58 } 58 59 59 60 struct voltage_map_desc { ··· 872 873 }; 873 874 874 875 #ifdef CONFIG_OF 875 - static int max8997_pmic_dt_parse_dvs_gpio(struct platform_device *pdev, 876 - struct max8997_platform_data *pdata, 877 - struct device_node *pmic_np) 878 - { 879 - int i, gpio; 880 - 881 - for (i = 0; i < 3; i++) { 882 - gpio = of_get_named_gpio(pmic_np, 883 - "max8997,pmic-buck125-dvs-gpios", i); 884 - if (!gpio_is_valid(gpio)) { 885 - dev_err(&pdev->dev, "invalid gpio[%d]: %d\n", i, gpio); 886 - return -EINVAL; 887 - } 888 - pdata->buck125_gpios[i] = gpio; 889 - } 890 - return 0; 891 - } 892 - 893 876 static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev, 894 877 struct max8997_platform_data *pdata) 895 878 { 896 879 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); 897 880 struct device_node *pmic_np, *regulators_np, *reg_np; 898 881 struct max8997_regulator_data *rdata; 899 - unsigned int i, dvs_voltage_nr = 1, ret; 882 + unsigned int i, dvs_voltage_nr = 1; 900 883 901 884 pmic_np = iodev->dev->of_node; 902 885 if (!pmic_np) { ··· 930 949 931 950 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || 932 951 pdata->buck5_gpiodvs) { 933 - ret = max8997_pmic_dt_parse_dvs_gpio(pdev, pdata, pmic_np); 934 - if (ret) 935 - return -EINVAL; 936 - 937 952 if (of_property_read_u32(pmic_np, 938 953 "max8997,pmic-buck125-default-dvs-idx", 939 954 &pdata->buck125_default_idx)) { ··· 1016 1039 max8997->buck1_gpiodvs = pdata->buck1_gpiodvs; 1017 1040 max8997->buck2_gpiodvs = pdata->buck2_gpiodvs; 1018 1041 max8997->buck5_gpiodvs = pdata->buck5_gpiodvs; 1019 - memcpy(max8997->buck125_gpios, pdata->buck125_gpios, sizeof(int) * 3); 1020 1042 max8997->ignore_gpiodvs_side_effect = pdata->ignore_gpiodvs_side_effect; 1021 1043 1022 1044 nr_dvs = (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || ··· 1086 1110 */ 1087 1111 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || 1088 1112 pdata->buck5_gpiodvs) { 1113 + const char *gpio_names[3] = {"MAX8997 SET1", "MAX8997 SET2", "MAX8997 SET3"}; 1089 1114 1090 - if (!gpio_is_valid(pdata->buck125_gpios[0]) || 1091 - !gpio_is_valid(pdata->buck125_gpios[1]) || 1092 - !gpio_is_valid(pdata->buck125_gpios[2])) { 1093 - dev_err(&pdev->dev, "GPIO NOT VALID\n"); 1094 - return -EINVAL; 1115 + for (i = 0; i < 3; i++) { 1116 + enum gpiod_flags flags; 1117 + 1118 + if (max8997->buck125_gpioindex & BIT(2 - i)) 1119 + flags = GPIOD_OUT_HIGH; 1120 + else 1121 + flags = GPIOD_OUT_LOW; 1122 + 1123 + max8997->buck125_gpiods[i] = devm_gpiod_get_index(iodev->dev, 1124 + "max8997,pmic-buck125-dvs", 1125 + i, 1126 + flags); 1127 + if (IS_ERR(max8997->buck125_gpiods[i])) { 1128 + ret = PTR_ERR(max8997->buck125_gpiods[i]); 1129 + return dev_err_probe(iodev->dev, ret, "cant get GPIO %d (%d)\n", 1130 + i, ret); 1131 + } 1132 + gpiod_set_consumer_name(max8997->buck125_gpiods[i], gpio_names[i]); 1095 1133 } 1096 - 1097 - ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0], 1098 - "MAX8997 SET1"); 1099 - if (ret) 1100 - return ret; 1101 - 1102 - ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1], 1103 - "MAX8997 SET2"); 1104 - if (ret) 1105 - return ret; 1106 - 1107 - ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2], 1108 - "MAX8997 SET3"); 1109 - if (ret) 1110 - return ret; 1111 - 1112 - gpio_direction_output(pdata->buck125_gpios[0], 1113 - (max8997->buck125_gpioindex >> 2) 1114 - & 0x1); /* SET1 */ 1115 - gpio_direction_output(pdata->buck125_gpios[1], 1116 - (max8997->buck125_gpioindex >> 1) 1117 - & 0x1); /* SET2 */ 1118 - gpio_direction_output(pdata->buck125_gpios[2], 1119 - (max8997->buck125_gpioindex >> 0) 1120 - & 0x1); /* SET3 */ 1121 1134 } 1122 1135 1123 1136 /* DVS-GPIO disabled */
-1
include/linux/mfd/max8997.h
··· 178 178 * 179 179 */ 180 180 bool ignore_gpiodvs_side_effect; 181 - int buck125_gpios[3]; /* GPIO of [0]SET1, [1]SET2, [2]SET3 */ 182 181 int buck125_default_idx; /* Default value of SET1, 2, 3 */ 183 182 unsigned int buck1_voltage[8]; /* buckx_voltage in uV */ 184 183 bool buck1_gpiodvs;