hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/regulator/max77686-regulator.c
....@@ -11,8 +11,7 @@
1111 #include <linux/kernel.h>
1212 #include <linux/bug.h>
1313 #include <linux/err.h>
14
-#include <linux/gpio.h>
15
-#include <linux/of_gpio.h>
14
+#include <linux/gpio/consumer.h>
1615 #include <linux/slab.h>
1716 #include <linux/platform_device.h>
1817 #include <linux/regulator/driver.h>
....@@ -76,6 +75,7 @@
7675 };
7776
7877 struct max77686_data {
78
+ struct device *dev;
7979 DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
8080
8181 /* Array indexed by regulator id */
....@@ -250,26 +250,35 @@
250250 struct regulator_config *config)
251251 {
252252 struct max77686_data *max77686 = config->driver_data;
253
+ int ret;
253254
254255 switch (desc->id) {
255256 case MAX77686_BUCK8:
256257 case MAX77686_BUCK9:
257258 case MAX77686_LDO20 ... MAX77686_LDO22:
258
- config->ena_gpio = of_get_named_gpio(np,
259
- "maxim,ena-gpios", 0);
260
- config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
261
- config->ena_gpio_initialized = true;
259
+ config->ena_gpiod = fwnode_gpiod_get_index(
260
+ of_fwnode_handle(np),
261
+ "maxim,ena",
262
+ 0,
263
+ GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
264
+ "max77686-regulator");
265
+ if (IS_ERR(config->ena_gpiod))
266
+ config->ena_gpiod = NULL;
262267 break;
263268 default:
264269 return 0;
265270 }
266271
267
- if (gpio_is_valid(config->ena_gpio)) {
272
+ if (config->ena_gpiod) {
268273 set_bit(desc->id, max77686->gpio_enabled);
269274
270
- return regmap_update_bits(config->regmap, desc->enable_reg,
271
- desc->enable_mask,
272
- MAX77686_GPIO_CONTROL);
275
+ ret = regmap_update_bits(config->regmap, desc->enable_reg,
276
+ desc->enable_mask,
277
+ MAX77686_GPIO_CONTROL);
278
+ if (ret) {
279
+ gpiod_put(config->ena_gpiod);
280
+ config->ena_gpiod = NULL;
281
+ }
273282 }
274283
275284 return 0;
....@@ -507,6 +516,7 @@
507516 if (!max77686)
508517 return -ENOMEM;
509518
519
+ max77686->dev = &pdev->dev;
510520 config.dev = iodev->dev;
511521 config.regmap = iodev->regmap;
512522 config.driver_data = max77686;