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

Convert some regulator drivers to GPIO descriptors

Merge series from Linus Walleij <linus.walleij@linaro.org>:

Despite the work to convert the regulator core to GPIO
descriptors, there are some outliers that use legacy GPIO
numbers in various ways. Convert them all over.

+140 -272
+24 -24
drivers/regulator/da9055-regulator.c
··· 9 9 #include <linux/module.h> 10 10 #include <linux/init.h> 11 11 #include <linux/err.h> 12 - #include <linux/gpio.h> 13 12 #include <linux/gpio/consumer.h> 14 13 #include <linux/platform_device.h> 15 14 #include <linux/regulator/driver.h> ··· 412 413 * GPIO can control regulator state and/or select the regulator register 413 414 * set A/B for voltage ramping. 414 415 */ 415 - static int da9055_gpio_init(struct da9055_regulator *regulator, 416 + static int da9055_gpio_init(struct device *dev, 417 + struct da9055_regulator *regulator, 416 418 struct regulator_config *config, 417 419 struct da9055_pdata *pdata, int id) 418 420 { 419 421 struct da9055_regulator_info *info = regulator->info; 422 + struct gpio_desc *ren; 423 + struct gpio_desc *ena; 424 + struct gpio_desc *rsel; 420 425 int ret = 0; 421 426 422 - if (!pdata) 423 - return 0; 427 + /* Look for "regulator-enable-gpios" GPIOs in the regulator node */ 428 + ren = devm_gpiod_get_optional(dev, "regulator-enable", GPIOD_IN); 429 + if (IS_ERR(ren)) 430 + return PTR_ERR(ren); 424 431 425 - if (pdata->gpio_ren && pdata->gpio_ren[id]) { 426 - char name[18]; 427 - int gpio_mux = pdata->gpio_ren[id]; 432 + if (ren) { 433 + /* This GPIO is not optional at this point */ 434 + ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH); 435 + if (IS_ERR(ena)) 436 + return PTR_ERR(ena); 428 437 429 - config->ena_gpiod = pdata->ena_gpiods[id]; 438 + config->ena_gpiod = ena; 430 439 431 440 /* 432 441 * GPI pin is muxed with regulator to control the 433 442 * regulator state. 434 443 */ 435 - sprintf(name, "DA9055 GPI %d", gpio_mux); 436 - ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, 437 - name); 438 - if (ret < 0) 439 - goto err; 444 + gpiod_set_consumer_name(ren, "DA9055 ren GPI"); 440 445 441 446 /* 442 447 * Let the regulator know that its state is controlled ··· 451 448 pdata->reg_ren[id] 452 449 << DA9055_E_GPI_SHIFT); 453 450 if (ret < 0) 454 - goto err; 451 + return ret; 455 452 } 456 453 457 - if (pdata->gpio_rsel && pdata->gpio_rsel[id]) { 458 - char name[18]; 459 - int gpio_mux = pdata->gpio_rsel[id]; 454 + /* Look for "regulator-select-gpios" GPIOs in the regulator node */ 455 + rsel = devm_gpiod_get_optional(dev, "regulator-select", GPIOD_IN); 456 + if (IS_ERR(rsel)) 457 + return PTR_ERR(rsel); 460 458 459 + if (rsel) { 461 460 regulator->reg_rselect = pdata->reg_rsel[id]; 462 461 463 462 /* 464 463 * GPI pin is muxed with regulator to select the 465 464 * regulator register set A/B for voltage ramping. 466 465 */ 467 - sprintf(name, "DA9055 GPI %d", gpio_mux); 468 - ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, 469 - name); 470 - if (ret < 0) 471 - goto err; 466 + gpiod_set_consumer_name(rsel, "DA9055 rsel GPI"); 472 467 473 468 /* 474 469 * Let the regulator know that its register set A/B ··· 478 477 << DA9055_V_GPI_SHIFT); 479 478 } 480 479 481 - err: 482 480 return ret; 483 481 } 484 482 ··· 532 532 if (pdata) 533 533 config.init_data = pdata->regulators[pdev->id]; 534 534 535 - ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); 535 + ret = da9055_gpio_init(&pdev->dev, regulator, &config, pdata, pdev->id); 536 536 if (ret < 0) 537 537 return ret; 538 538
+26 -38
drivers/regulator/lp8788-buck.c
··· 13 13 #include <linux/platform_device.h> 14 14 #include <linux/regulator/driver.h> 15 15 #include <linux/mfd/lp8788.h> 16 - #include <linux/gpio.h> 16 + #include <linux/gpio/consumer.h> 17 17 18 18 /* register address */ 19 19 #define LP8788_EN_BUCK 0x0C ··· 69 69 #define BUCK_FPWM_SHIFT(x) (x) 70 70 71 71 enum lp8788_dvs_state { 72 - DVS_LOW = GPIOF_OUT_INIT_LOW, 73 - DVS_HIGH = GPIOF_OUT_INIT_HIGH, 72 + DVS_LOW = 0, 73 + DVS_HIGH = 1, 74 74 }; 75 75 76 76 enum lp8788_dvs_mode { ··· 89 89 struct lp8788 *lp; 90 90 struct regulator_dev *regulator; 91 91 void *dvs; 92 + struct gpio_desc *gpio1; 93 + struct gpio_desc *gpio2; /* Only used on BUCK2 */ 92 94 }; 93 95 94 96 /* BUCK 1 ~ 4 voltage ranges */ ··· 108 106 return; 109 107 110 108 pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH; 111 - if (gpio_is_valid(dvs->gpio)) 112 - gpio_set_value(dvs->gpio, pinstate); 109 + gpiod_set_value(buck->gpio1, pinstate); 113 110 } 114 111 115 112 static void lp8788_buck2_set_dvs(struct lp8788_buck *buck) ··· 140 139 return; 141 140 } 142 141 143 - if (gpio_is_valid(dvs->gpio[0])) 144 - gpio_set_value(dvs->gpio[0], pin1); 145 - 146 - if (gpio_is_valid(dvs->gpio[1])) 147 - gpio_set_value(dvs->gpio[1], pin2); 142 + gpiod_set_value(buck->gpio1, pin1); 143 + gpiod_set_value(buck->gpio2, pin2); 148 144 } 149 145 150 146 static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) ··· 200 202 enum lp8788_buck_id id) 201 203 { 202 204 enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id); 203 - struct lp8788_buck1_dvs *b1_dvs; 204 - struct lp8788_buck2_dvs *b2_dvs; 205 205 u8 val, idx, addr; 206 206 int pin1, pin2; 207 207 208 208 switch (id) { 209 209 case BUCK1: 210 210 if (mode == EXTPIN) { 211 - b1_dvs = (struct lp8788_buck1_dvs *)buck->dvs; 212 - if (!b1_dvs) 213 - goto err; 214 - 215 - idx = gpio_get_value(b1_dvs->gpio) ? 1 : 0; 211 + idx = gpiod_get_value(buck->gpio1); 216 212 } else { 217 213 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); 218 214 idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S; ··· 215 223 break; 216 224 case BUCK2: 217 225 if (mode == EXTPIN) { 218 - b2_dvs = (struct lp8788_buck2_dvs *)buck->dvs; 219 - if (!b2_dvs) 220 - goto err; 221 - 222 - pin1 = gpio_get_value(b2_dvs->gpio[0]); 223 - pin2 = gpio_get_value(b2_dvs->gpio[1]); 226 + pin1 = gpiod_get_value(buck->gpio1); 227 + pin2 = gpiod_get_value(buck->gpio2); 224 228 225 229 if (pin1 == PIN_LOW && pin2 == PIN_LOW) 226 230 idx = 0; ··· 412 424 enum lp8788_buck_id id) 413 425 { 414 426 struct lp8788_platform_data *pdata = buck->lp->pdata; 415 - char *b1_name = "LP8788_B1_DVS"; 416 - char *b2_name[] = { "LP8788_B2_DVS1", "LP8788_B2_DVS2" }; 417 - int i, gpio, ret; 427 + struct device *dev = &pdev->dev; 418 428 419 429 switch (id) { 420 430 case BUCK1: 421 - gpio = pdata->buck1_dvs->gpio; 422 - ret = devm_gpio_request_one(&pdev->dev, gpio, DVS_LOW, 423 - b1_name); 424 - if (ret) 425 - return ret; 431 + buck->gpio1 = devm_gpiod_get(dev, "dvs", GPIOD_OUT_LOW); 432 + if (IS_ERR(buck->gpio1)) 433 + return PTR_ERR(buck->gpio1); 434 + gpiod_set_consumer_name(buck->gpio1, "LP8788_B1_DVS"); 426 435 427 436 buck->dvs = pdata->buck1_dvs; 428 437 break; 429 438 case BUCK2: 430 - for (i = 0; i < LP8788_NUM_BUCK2_DVS; i++) { 431 - gpio = pdata->buck2_dvs->gpio[i]; 432 - ret = devm_gpio_request_one(&pdev->dev, gpio, 433 - DVS_LOW, b2_name[i]); 434 - if (ret) 435 - return ret; 436 - } 439 + buck->gpio1 = devm_gpiod_get_index(dev, "dvs", 0, GPIOD_OUT_LOW); 440 + if (IS_ERR(buck->gpio1)) 441 + return PTR_ERR(buck->gpio1); 442 + gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS1"); 443 + 444 + buck->gpio2 = devm_gpiod_get_index(dev, "dvs", 1, GPIOD_OUT_LOW); 445 + if (IS_ERR(buck->gpio1)) 446 + return PTR_ERR(buck->gpio1); 447 + gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS2"); 448 + 437 449 buck->dvs = pdata->buck2_dvs; 438 450 break; 439 451 default:
+12 -24
drivers/regulator/max8973-regulator.c
··· 20 20 #include <linux/regulator/machine.h> 21 21 #include <linux/regulator/max8973-regulator.h> 22 22 #include <linux/regulator/of_regulator.h> 23 - #include <linux/gpio.h> 24 23 #include <linux/gpio/consumer.h> 25 - #include <linux/of_gpio.h> 26 24 #include <linux/i2c.h> 27 25 #include <linux/slab.h> 28 26 #include <linux/regmap.h> ··· 100 102 struct regulator_desc desc; 101 103 struct regmap *regmap; 102 104 bool enable_external_control; 103 - int dvs_gpio; 105 + struct gpio_desc *dvs_gpiod; 104 106 int lru_index[MAX8973_MAX_VOUT_REG]; 105 107 int curr_vout_val[MAX8973_MAX_VOUT_REG]; 106 108 int curr_vout_reg; ··· 182 184 * If gpios are available to select the VOUT register then least 183 185 * recently used register for new configuration. 184 186 */ 185 - if (gpio_is_valid(max->dvs_gpio)) 187 + if (max->dvs_gpiod) 186 188 found = find_voltage_set_register(max, vsel, 187 189 &vout_reg, &gpio_val); 188 190 ··· 199 201 } 200 202 201 203 /* Select proper VOUT register vio gpios */ 202 - if (gpio_is_valid(max->dvs_gpio)) { 203 - gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1); 204 + if (max->dvs_gpiod) { 205 + gpiod_set_value_cansleep(max->dvs_gpiod, gpio_val & 0x1); 204 206 max->curr_gpio_val = gpio_val; 205 207 } 206 208 return 0; ··· 529 531 530 532 pdata->enable_ext_control = of_property_read_bool(np, 531 533 "maxim,externally-enable"); 532 - pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); 533 534 534 535 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); 535 536 if (!ret) ··· 609 612 return -EIO; 610 613 } 611 614 612 - if (pdata->dvs_gpio == -EPROBE_DEFER) 613 - return -EPROBE_DEFER; 614 - 615 615 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); 616 616 if (!max) 617 617 return -ENOMEM; 618 + 619 + max->dvs_gpiod = devm_gpiod_get_optional(&client->dev, "maxim,dvs", 620 + (pdata->dvs_def_state) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW); 621 + if (IS_ERR(max->dvs_gpiod)) 622 + return dev_err_probe(&client->dev, PTR_ERR(max->dvs_gpiod), 623 + "failed to obtain dvs gpio\n"); 624 + gpiod_set_consumer_name(max->dvs_gpiod, "max8973-dvs"); 618 625 619 626 max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config); 620 627 if (IS_ERR(max->regmap)) { ··· 664 663 max->desc.ramp_delay_table = max8973_buck_ramp_table; 665 664 max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table); 666 665 667 - max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL; 668 666 max->enable_external_control = pdata->enable_ext_control; 669 667 max->curr_gpio_val = pdata->dvs_def_state; 670 668 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; ··· 671 671 672 672 max->lru_index[0] = max->curr_vout_reg; 673 673 674 - if (gpio_is_valid(max->dvs_gpio)) { 675 - int gpio_flags; 674 + if (max->dvs_gpiod) { 676 675 int i; 677 - 678 - gpio_flags = (pdata->dvs_def_state) ? 679 - GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 680 - ret = devm_gpio_request_one(&client->dev, max->dvs_gpio, 681 - gpio_flags, "max8973-dvs"); 682 - if (ret) { 683 - dev_err(&client->dev, 684 - "gpio_request for gpio %d failed, err = %d\n", 685 - max->dvs_gpio, ret); 686 - return ret; 687 - } 688 676 689 677 /* 690 678 * Initialize the lru index with vout_reg id
+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 */
+51 -93
drivers/regulator/max8998.c
··· 10 10 #include <linux/init.h> 11 11 #include <linux/i2c.h> 12 12 #include <linux/err.h> 13 - #include <linux/gpio.h> 13 + #include <linux/bits.h> 14 + #include <linux/gpio/consumer.h> 14 15 #include <linux/slab.h> 15 16 #include <linux/interrupt.h> 16 17 #include <linux/mutex.h> 17 18 #include <linux/of.h> 18 - #include <linux/of_gpio.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/regulator/driver.h> 21 21 #include <linux/regulator/of_regulator.h> ··· 31 31 unsigned int buck1_idx; /* index to last changed voltage */ 32 32 /* value in a set */ 33 33 unsigned int buck2_idx; 34 + struct gpio_desc *buck1_gpio1; 35 + struct gpio_desc *buck1_gpio2; 36 + struct gpio_desc *buck2_gpio; 34 37 }; 35 38 36 39 static const unsigned int charger_current_table[] = { ··· 230 227 return ret; 231 228 } 232 229 233 - static inline void buck1_gpio_set(int gpio1, int gpio2, int v) 230 + static inline void buck1_gpio_set(struct gpio_desc *gpio1, struct gpio_desc *gpio2, int v) 234 231 { 235 - gpio_set_value(gpio1, v & 0x1); 236 - gpio_set_value(gpio2, (v >> 1) & 0x1); 232 + gpiod_set_value(gpio1, v & 0x1); 233 + gpiod_set_value(gpio2, (v >> 1) & 0x1); 237 234 } 238 235 239 - static inline void buck2_gpio_set(int gpio, int v) 236 + static inline void buck2_gpio_set(struct gpio_desc *gpio, int v) 240 237 { 241 - gpio_set_value(gpio, v & 0x1); 238 + gpiod_set_value(gpio, v & 0x1); 242 239 } 243 240 244 241 static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, ··· 263 260 selector, max8998->buck1_vol[0], max8998->buck1_vol[1], 264 261 max8998->buck1_vol[2], max8998->buck1_vol[3]); 265 262 266 - if (gpio_is_valid(pdata->buck1_set1) && 267 - gpio_is_valid(pdata->buck1_set2)) { 263 + if (max8998->buck1_gpio1 && max8998->buck1_gpio2) { 268 264 269 265 /* check if requested voltage */ 270 266 /* value is already defined */ 271 267 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { 272 268 if (max8998->buck1_vol[j] == selector) { 273 269 max8998->buck1_idx = j; 274 - buck1_gpio_set(pdata->buck1_set1, 275 - pdata->buck1_set2, j); 270 + buck1_gpio_set(max8998->buck1_gpio1, 271 + max8998->buck1_gpio2, j); 276 272 goto buck1_exit; 277 273 } 278 274 } ··· 288 286 &shift, 289 287 &mask); 290 288 ret = max8998_write_reg(i2c, reg, selector); 291 - buck1_gpio_set(pdata->buck1_set1, 292 - pdata->buck1_set2, max8998->buck1_idx); 289 + buck1_gpio_set(max8998->buck1_gpio1, 290 + max8998->buck1_gpio2, max8998->buck1_idx); 293 291 buck1_last_val++; 294 292 buck1_exit: 295 293 dev_dbg(max8998->dev, "%s: SET1:%d, SET2:%d\n", 296 - i2c->name, gpio_get_value(pdata->buck1_set1), 297 - gpio_get_value(pdata->buck1_set2)); 294 + i2c->name, gpiod_get_value(max8998->buck1_gpio1), 295 + gpiod_get_value(max8998->buck1_gpio2)); 298 296 break; 299 297 } else { 300 298 ret = max8998_write_reg(i2c, reg, selector); ··· 305 303 dev_dbg(max8998->dev, 306 304 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n", 307 305 selector, max8998->buck2_vol[0], max8998->buck2_vol[1]); 308 - if (gpio_is_valid(pdata->buck2_set3)) { 309 - 306 + if (max8998->buck2_gpio) { 310 307 /* check if requested voltage */ 311 308 /* value is already defined */ 312 309 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { 313 310 if (max8998->buck2_vol[j] == selector) { 314 311 max8998->buck2_idx = j; 315 - buck2_gpio_set(pdata->buck2_set3, j); 312 + buck2_gpio_set(max8998->buck2_gpio, j); 316 313 goto buck2_exit; 317 314 } 318 315 } ··· 323 322 &reg, &shift, &mask); 324 323 ret = max8998_write_reg(i2c, reg, selector); 325 324 max8998->buck2_vol[max8998->buck2_idx] = selector; 326 - buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); 325 + buck2_gpio_set(max8998->buck2_gpio, max8998->buck2_idx); 327 326 buck2_exit: 328 327 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, 329 - gpio_get_value(pdata->buck2_set3)); 328 + gpiod_get_value(max8998->buck2_gpio)); 330 329 } else { 331 330 ret = max8998_write_reg(i2c, reg, selector); 332 331 } ··· 540 539 charger_current_table, MAX8998_REG_CHGR1, 0x7), 541 540 }; 542 541 543 - static int max8998_pmic_dt_parse_dvs_gpio(struct max8998_dev *iodev, 544 - struct max8998_platform_data *pdata, 545 - struct device_node *pmic_np) 546 - { 547 - int gpio; 548 - 549 - gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck1-dvs-gpios", 0); 550 - if (!gpio_is_valid(gpio)) { 551 - dev_err(iodev->dev, "invalid buck1 gpio[0]: %d\n", gpio); 552 - return -EINVAL; 553 - } 554 - pdata->buck1_set1 = gpio; 555 - 556 - gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck1-dvs-gpios", 1); 557 - if (!gpio_is_valid(gpio)) { 558 - dev_err(iodev->dev, "invalid buck1 gpio[1]: %d\n", gpio); 559 - return -EINVAL; 560 - } 561 - pdata->buck1_set2 = gpio; 562 - 563 - gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck2-dvs-gpio", 0); 564 - if (!gpio_is_valid(gpio)) { 565 - dev_err(iodev->dev, "invalid buck 2 gpio: %d\n", gpio); 566 - return -EINVAL; 567 - } 568 - pdata->buck2_set3 = gpio; 569 - 570 - return 0; 571 - } 572 - 573 542 static int max8998_pmic_dt_parse_pdata(struct max8998_dev *iodev, 574 543 struct max8998_platform_data *pdata) 575 544 { ··· 584 613 585 614 of_node_put(reg_np); 586 615 of_node_put(regulators_np); 587 - 588 - ret = max8998_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); 589 - if (ret) 590 - return -EINVAL; 591 616 592 617 pdata->buck_voltage_lock = of_property_read_bool(pmic_np, "max8998,pmic-buck-voltage-lock"); 593 618 ··· 632 665 struct regulator_dev *rdev; 633 666 struct max8998_data *max8998; 634 667 struct i2c_client *i2c; 668 + enum gpiod_flags flags; 635 669 int i, ret; 636 670 unsigned int v; 637 671 ··· 661 693 max8998->buck1_idx = pdata->buck1_default_idx; 662 694 max8998->buck2_idx = pdata->buck2_default_idx; 663 695 664 - /* NOTE: */ 665 - /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */ 666 - /* will be displayed */ 667 - 668 696 /* Check if MAX8998 voltage selection GPIOs are defined */ 669 - if (gpio_is_valid(pdata->buck1_set1) && 670 - gpio_is_valid(pdata->buck1_set2)) { 671 - /* Check if SET1 is not equal to 0 */ 672 - if (!pdata->buck1_set1) { 673 - dev_err(&pdev->dev, 674 - "MAX8998 SET1 GPIO defined as 0 !\n"); 675 - WARN_ON(!pdata->buck1_set1); 676 - return -EIO; 677 - } 678 - /* Check if SET2 is not equal to 0 */ 679 - if (!pdata->buck1_set2) { 680 - dev_err(&pdev->dev, 681 - "MAX8998 SET2 GPIO defined as 0 !\n"); 682 - WARN_ON(!pdata->buck1_set2); 683 - return -EIO; 684 - } 697 + flags = (max8998->buck1_idx & BIT(0)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 698 + max8998->buck1_gpio1 = devm_gpiod_get_index_optional(iodev->dev, 699 + "max8998,pmic-buck1-dvs", 700 + 0, 701 + flags); 702 + if (IS_ERR(max8998->buck1_gpio1)) 703 + return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck1_gpio1), 704 + "could not get BUCK1 GPIO1\n"); 705 + gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK1_SET1"); 685 706 686 - gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); 687 - gpio_direction_output(pdata->buck1_set1, 688 - max8998->buck1_idx & 0x1); 707 + flags = (max8998->buck1_idx & BIT(1)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 708 + max8998->buck1_gpio2 = devm_gpiod_get_index_optional(iodev->dev, 709 + "max8998,pmic-buck1-dvs", 710 + 1, 711 + flags); 712 + if (IS_ERR(max8998->buck1_gpio2)) 713 + return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck1_gpio2), 714 + "could not get BUCK1 GPIO2\n"); 715 + gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK1_SET2"); 689 716 717 + flags = (max8998->buck2_idx & BIT(0)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 718 + max8998->buck2_gpio = devm_gpiod_get_index_optional(iodev->dev, 719 + "max8998,pmic-buck2-dvs", 720 + 0, 721 + flags); 722 + if (IS_ERR(max8998->buck2_gpio)) 723 + return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck2_gpio), 724 + "could not get BUCK2 GPIO\n"); 725 + gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK2_SET3"); 690 726 691 - gpio_request(pdata->buck1_set2, "MAX8998 BUCK1_SET2"); 692 - gpio_direction_output(pdata->buck1_set2, 693 - (max8998->buck1_idx >> 1) & 0x1); 694 - 727 + if (max8998->buck1_gpio1 && max8998->buck1_gpio2) { 695 728 /* Set predefined values for BUCK1 registers */ 696 729 for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) { 697 730 int index = MAX8998_BUCK1 - MAX8998_LDO2; ··· 711 742 } 712 743 } 713 744 714 - if (gpio_is_valid(pdata->buck2_set3)) { 715 - /* Check if SET3 is not equal to 0 */ 716 - if (!pdata->buck2_set3) { 717 - dev_err(&pdev->dev, 718 - "MAX8998 SET3 GPIO defined as 0 !\n"); 719 - WARN_ON(!pdata->buck2_set3); 720 - return -EIO; 721 - } 722 - gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); 723 - gpio_direction_output(pdata->buck2_set3, 724 - max8998->buck2_idx & 0x1); 725 - 745 + if (max8998->buck2_gpio) { 726 746 /* Set predefined values for BUCK2 registers */ 727 747 for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) { 728 748 int index = MAX8998_BUCK2 - MAX8998_LDO2;
-13
include/linux/mfd/da9055/pdata.h
··· 7 7 #define DA9055_MAX_REGULATORS 8 8 8 9 9 struct da9055; 10 - struct gpio_desc; 11 10 12 11 enum gpio_select { 13 12 NO_GPIO = 0, ··· 23 24 /* Enable RTC in RESET Mode */ 24 25 bool reset_enable; 25 26 /* 26 - * GPI muxed pin to control 27 - * regulator state A/B, 0 if not available. 28 - */ 29 - int *gpio_ren; 30 - /* 31 - * GPI muxed pin to control 32 - * regulator set, 0 if not available. 33 - */ 34 - int *gpio_rsel; 35 - /* 36 27 * Regulator mode control bits value (GPI offset) that 37 28 * controls the regulator state, 0 if not available. 38 29 */ ··· 32 43 * controls the regulator set A/B, 0 if not available. 33 44 */ 34 45 enum gpio_select *reg_rsel; 35 - /* GPIO descriptors to enable regulator, NULL if not available */ 36 - struct gpio_desc **ena_gpiods; 37 46 }; 38 47 #endif /* __DA9055_PDATA_H */
+2 -7
include/linux/mfd/lp8788.h
··· 10 10 #ifndef __MFD_LP8788_H__ 11 11 #define __MFD_LP8788_H__ 12 12 13 - #include <linux/gpio.h> 14 13 #include <linux/irqdomain.h> 15 14 #include <linux/pwm.h> 16 15 #include <linux/regmap.h> ··· 158 159 159 160 /* 160 161 * lp8788_buck1_dvs 161 - * @gpio : gpio pin number for dvs control 162 162 * @vsel : dvs selector for buck v1 register 163 163 */ 164 164 struct lp8788_buck1_dvs { 165 - int gpio; 166 165 enum lp8788_dvs_sel vsel; 167 166 }; 168 167 169 168 /* 170 169 * lp8788_buck2_dvs 171 - * @gpio : two gpio pin numbers are used for dvs 172 170 * @vsel : dvs selector for buck v2 register 173 171 */ 174 172 struct lp8788_buck2_dvs { 175 - int gpio[LP8788_NUM_BUCK2_DVS]; 176 173 enum lp8788_dvs_sel vsel; 177 174 }; 178 175 ··· 263 268 * @buck_data : regulator initial data for buck 264 269 * @dldo_data : regulator initial data for digital ldo 265 270 * @aldo_data : regulator initial data for analog ldo 266 - * @buck1_dvs : gpio configurations for buck1 dvs 267 - * @buck2_dvs : gpio configurations for buck2 dvs 271 + * @buck1_dvs : configurations for buck1 dvs 272 + * @buck2_dvs : configurations for buck2 dvs 268 273 * @chg_pdata : platform data for charger driver 269 274 * @alarm_sel : rtc alarm selection (1 or 2) 270 275 * @bl_pdata : configurable data for backlight driver
-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;
-6
include/linux/mfd/max8998.h
··· 65 65 * be other than the preset values. 66 66 * @buck1_voltage: BUCK1 DVS mode 1 voltage registers 67 67 * @buck2_voltage: BUCK2 DVS mode 2 voltage registers 68 - * @buck1_set1: BUCK1 gpio pin 1 to set output voltage 69 - * @buck1_set2: BUCK1 gpio pin 2 to set output voltage 70 68 * @buck1_default_idx: Default for BUCK1 gpio pin 1, 2 71 - * @buck2_set3: BUCK2 gpio pin to set output voltage 72 69 * @buck2_default_idx: Default for BUCK2 gpio pin. 73 70 * @wakeup: Allow to wake up from suspend 74 71 * @rtc_delay: LP3974 RTC chip bug that requires delay after a register ··· 88 91 bool buck_voltage_lock; 89 92 int buck1_voltage[4]; 90 93 int buck2_voltage[2]; 91 - int buck1_set1; 92 - int buck1_set2; 93 94 int buck1_default_idx; 94 - int buck2_set3; 95 95 int buck2_default_idx; 96 96 bool wakeup; 97 97 bool rtc_delay;
-6
include/linux/regulator/max8973-regulator.h
··· 48 48 * control signal from EN input pin. If it is false then 49 49 * voltage output will be enabled/disabled through EN bit of 50 50 * device register. 51 - * @enable_gpio: Enable GPIO. If EN pin is controlled through GPIO from host 52 - * then GPIO number can be provided. If no GPIO controlled then 53 - * it should be -1. 54 - * @dvs_gpio: GPIO for dvs. It should be -1 if this is tied with fixed logic. 55 51 * @dvs_def_state: Default state of dvs. 1 if it is high else 0. 56 52 */ 57 53 struct max8973_regulator_platform_data { ··· 55 59 unsigned long control_flags; 56 60 unsigned long junction_temp_warning; 57 61 bool enable_ext_control; 58 - int enable_gpio; 59 - int dvs_gpio; 60 62 unsigned dvs_def_state:1; 61 63 }; 62 64