forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/regulator/s2mps11.c
....@@ -5,7 +5,7 @@
55
66 #include <linux/bug.h>
77 #include <linux/err.h>
8
-#include <linux/gpio.h>
8
+#include <linux/gpio/consumer.h>
99 #include <linux/slab.h>
1010 #include <linux/module.h>
1111 #include <linux/of.h>
....@@ -14,7 +14,6 @@
1414 #include <linux/regulator/driver.h>
1515 #include <linux/regulator/machine.h>
1616 #include <linux/regulator/of_regulator.h>
17
-#include <linux/of_gpio.h>
1817 #include <linux/mfd/samsung/core.h>
1918 #include <linux/mfd/samsung/s2mps11.h>
2019 #include <linux/mfd/samsung/s2mps13.h>
....@@ -35,7 +34,7 @@
3534 enum sec_device_type dev_type;
3635
3736 /*
38
- * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
37
+ * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
3938 * the suspend mode was enabled.
4039 */
4140 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
....@@ -44,7 +43,7 @@
4443 * Array (size: number of regulators) with GPIO-s for external
4544 * sleep control.
4645 */
47
- int *ext_control_gpio;
46
+ struct gpio_desc **ext_control_gpiod;
4847 };
4948
5049 static int get_ramp_delay(int ramp_delay)
....@@ -71,10 +70,11 @@
7170 unsigned int new_selector)
7271 {
7372 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
73
+ int rdev_id = rdev_get_id(rdev);
7474 unsigned int ramp_delay = 0;
7575 int old_volt, new_volt;
7676
77
- switch (rdev_get_id(rdev)) {
77
+ switch (rdev_id) {
7878 case S2MPS11_BUCK2:
7979 ramp_delay = s2mps11->ramp_delay2;
8080 break;
....@@ -112,9 +112,10 @@
112112 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
113113 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
114114 unsigned int ramp_enable = 1, enable_shift = 0;
115
+ int rdev_id = rdev_get_id(rdev);
115116 int ret;
116117
117
- switch (rdev_get_id(rdev)) {
118
+ switch (rdev_id) {
118119 case S2MPS11_BUCK1:
119120 if (ramp_delay > s2mps11->ramp_delay16)
120121 s2mps11->ramp_delay16 = ramp_delay;
....@@ -204,9 +205,8 @@
204205 goto ramp_disable;
205206
206207 /* Ramp delay can be enabled/disabled only for buck[2346] */
207
- if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 &&
208
- rdev_get_id(rdev) <= S2MPS11_BUCK4) ||
209
- rdev_get_id(rdev) == S2MPS11_BUCK6) {
208
+ if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
209
+ rdev_id == S2MPS11_BUCK6) {
210210 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
211211 1 << enable_shift, 1 << enable_shift);
212212 if (ret) {
....@@ -225,27 +225,133 @@
225225 1 << enable_shift, 0);
226226 }
227227
228
+static int s2mps11_regulator_enable(struct regulator_dev *rdev)
229
+{
230
+ struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
231
+ int rdev_id = rdev_get_id(rdev);
232
+ unsigned int val;
233
+
234
+ switch (s2mps11->dev_type) {
235
+ case S2MPS11X:
236
+ if (test_bit(rdev_id, s2mps11->suspend_state))
237
+ val = S2MPS14_ENABLE_SUSPEND;
238
+ else
239
+ val = rdev->desc->enable_mask;
240
+ break;
241
+ case S2MPS13X:
242
+ case S2MPS14X:
243
+ if (test_bit(rdev_id, s2mps11->suspend_state))
244
+ val = S2MPS14_ENABLE_SUSPEND;
245
+ else if (s2mps11->ext_control_gpiod[rdev_id])
246
+ val = S2MPS14_ENABLE_EXT_CONTROL;
247
+ else
248
+ val = rdev->desc->enable_mask;
249
+ break;
250
+ case S2MPU02:
251
+ if (test_bit(rdev_id, s2mps11->suspend_state))
252
+ val = S2MPU02_ENABLE_SUSPEND;
253
+ else
254
+ val = rdev->desc->enable_mask;
255
+ break;
256
+ default:
257
+ return -EINVAL;
258
+ }
259
+
260
+ return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
261
+ rdev->desc->enable_mask, val);
262
+}
263
+
264
+static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
265
+{
266
+ int ret;
267
+ unsigned int val, state;
268
+ struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
269
+ int rdev_id = rdev_get_id(rdev);
270
+
271
+ /* Below LDO should be always on or does not support suspend mode. */
272
+ switch (s2mps11->dev_type) {
273
+ case S2MPS11X:
274
+ switch (rdev_id) {
275
+ case S2MPS11_LDO2:
276
+ case S2MPS11_LDO36:
277
+ case S2MPS11_LDO37:
278
+ case S2MPS11_LDO38:
279
+ return 0;
280
+ default:
281
+ state = S2MPS14_ENABLE_SUSPEND;
282
+ break;
283
+ }
284
+ break;
285
+ case S2MPS13X:
286
+ case S2MPS14X:
287
+ switch (rdev_id) {
288
+ case S2MPS14_LDO3:
289
+ return 0;
290
+ default:
291
+ state = S2MPS14_ENABLE_SUSPEND;
292
+ break;
293
+ }
294
+ break;
295
+ case S2MPU02:
296
+ switch (rdev_id) {
297
+ case S2MPU02_LDO13:
298
+ case S2MPU02_LDO14:
299
+ case S2MPU02_LDO15:
300
+ case S2MPU02_LDO17:
301
+ case S2MPU02_BUCK7:
302
+ state = S2MPU02_DISABLE_SUSPEND;
303
+ break;
304
+ default:
305
+ state = S2MPU02_ENABLE_SUSPEND;
306
+ break;
307
+ }
308
+ break;
309
+ default:
310
+ return -EINVAL;
311
+ }
312
+
313
+ ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
314
+ if (ret < 0)
315
+ return ret;
316
+
317
+ set_bit(rdev_id, s2mps11->suspend_state);
318
+ /*
319
+ * Don't enable suspend mode if regulator is already disabled because
320
+ * this would effectively for a short time turn on the regulator after
321
+ * resuming.
322
+ * However we still want to toggle the suspend_state bit for regulator
323
+ * in case if it got enabled before suspending the system.
324
+ */
325
+ if (!(val & rdev->desc->enable_mask))
326
+ return 0;
327
+
328
+ return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
329
+ rdev->desc->enable_mask, state);
330
+}
331
+
228332 static const struct regulator_ops s2mps11_ldo_ops = {
229333 .list_voltage = regulator_list_voltage_linear,
230334 .map_voltage = regulator_map_voltage_linear,
231335 .is_enabled = regulator_is_enabled_regmap,
232
- .enable = regulator_enable_regmap,
336
+ .enable = s2mps11_regulator_enable,
233337 .disable = regulator_disable_regmap,
234338 .get_voltage_sel = regulator_get_voltage_sel_regmap,
235339 .set_voltage_sel = regulator_set_voltage_sel_regmap,
236340 .set_voltage_time_sel = regulator_set_voltage_time_sel,
341
+ .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
237342 };
238343
239344 static const struct regulator_ops s2mps11_buck_ops = {
240345 .list_voltage = regulator_list_voltage_linear,
241346 .map_voltage = regulator_map_voltage_linear,
242347 .is_enabled = regulator_is_enabled_regmap,
243
- .enable = regulator_enable_regmap,
348
+ .enable = s2mps11_regulator_enable,
244349 .disable = regulator_disable_regmap,
245350 .get_voltage_sel = regulator_get_voltage_sel_regmap,
246351 .set_voltage_sel = regulator_set_voltage_sel_regmap,
247352 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
248353 .set_ramp_delay = s2mps11_set_ramp_delay,
354
+ .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
249355 };
250356
251357 #define regulator_desc_s2mps11_ldo(num, step) { \
....@@ -270,9 +376,10 @@
270376 .ops = &s2mps11_buck_ops, \
271377 .type = REGULATOR_VOLTAGE, \
272378 .owner = THIS_MODULE, \
273
- .min_uV = MIN_600_MV, \
379
+ .min_uV = MIN_650_MV, \
274380 .uV_step = STEP_6_25_MV, \
275
- .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
381
+ .linear_min_sel = 8, \
382
+ .n_voltages = S2MPS11_BUCK12346_N_VOLTAGES, \
276383 .ramp_delay = S2MPS11_RAMP_DELAY, \
277384 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
278385 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
....@@ -286,9 +393,10 @@
286393 .ops = &s2mps11_buck_ops, \
287394 .type = REGULATOR_VOLTAGE, \
288395 .owner = THIS_MODULE, \
289
- .min_uV = MIN_600_MV, \
396
+ .min_uV = MIN_650_MV, \
290397 .uV_step = STEP_6_25_MV, \
291
- .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
398
+ .linear_min_sel = 8, \
399
+ .n_voltages = S2MPS11_BUCK5_N_VOLTAGES, \
292400 .ramp_delay = S2MPS11_RAMP_DELAY, \
293401 .vsel_reg = S2MPS11_REG_B5CTRL2, \
294402 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
....@@ -296,7 +404,7 @@
296404 .enable_mask = S2MPS11_ENABLE_MASK \
297405 }
298406
299
-#define regulator_desc_s2mps11_buck67810(num, min, step) { \
407
+#define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) { \
300408 .name = "BUCK"#num, \
301409 .id = S2MPS11_BUCK##num, \
302410 .ops = &s2mps11_buck_ops, \
....@@ -304,7 +412,8 @@
304412 .owner = THIS_MODULE, \
305413 .min_uV = min, \
306414 .uV_step = step, \
307
- .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \
415
+ .linear_min_sel = min_sel, \
416
+ .n_voltages = voltages, \
308417 .ramp_delay = S2MPS11_RAMP_DELAY, \
309418 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
310419 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
....@@ -372,11 +481,15 @@
372481 regulator_desc_s2mps11_buck1_4(3),
373482 regulator_desc_s2mps11_buck1_4(4),
374483 regulator_desc_s2mps11_buck5,
375
- regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV),
376
- regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV),
377
- regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV),
484
+ regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
485
+ S2MPS11_BUCK12346_N_VOLTAGES),
486
+ regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
487
+ S2MPS11_BUCK7810_N_VOLTAGES),
488
+ regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
489
+ S2MPS11_BUCK7810_N_VOLTAGES),
378490 regulator_desc_s2mps11_buck9,
379
- regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV),
491
+ regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
492
+ S2MPS11_BUCK7810_N_VOLTAGES),
380493 };
381494
382495 static const struct regulator_ops s2mps14_reg_ops;
....@@ -501,101 +614,16 @@
501614 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
502615 };
503616
504
-static int s2mps14_regulator_enable(struct regulator_dev *rdev)
505
-{
506
- struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
507
- unsigned int val;
508
-
509
- switch (s2mps11->dev_type) {
510
- case S2MPS13X:
511
- case S2MPS14X:
512
- if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
513
- val = S2MPS14_ENABLE_SUSPEND;
514
- else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
515
- val = S2MPS14_ENABLE_EXT_CONTROL;
516
- else
517
- val = rdev->desc->enable_mask;
518
- break;
519
- case S2MPU02:
520
- if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
521
- val = S2MPU02_ENABLE_SUSPEND;
522
- else
523
- val = rdev->desc->enable_mask;
524
- break;
525
- default:
526
- return -EINVAL;
527
- }
528
-
529
- return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
530
- rdev->desc->enable_mask, val);
531
-}
532
-
533
-static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
534
-{
535
- int ret;
536
- unsigned int val, state;
537
- struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
538
- int rdev_id = rdev_get_id(rdev);
539
-
540
- /* Below LDO should be always on or does not support suspend mode. */
541
- switch (s2mps11->dev_type) {
542
- case S2MPS13X:
543
- case S2MPS14X:
544
- switch (rdev_id) {
545
- case S2MPS14_LDO3:
546
- return 0;
547
- default:
548
- state = S2MPS14_ENABLE_SUSPEND;
549
- break;
550
- }
551
- break;
552
- case S2MPU02:
553
- switch (rdev_id) {
554
- case S2MPU02_LDO13:
555
- case S2MPU02_LDO14:
556
- case S2MPU02_LDO15:
557
- case S2MPU02_LDO17:
558
- case S2MPU02_BUCK7:
559
- state = S2MPU02_DISABLE_SUSPEND;
560
- break;
561
- default:
562
- state = S2MPU02_ENABLE_SUSPEND;
563
- break;
564
- }
565
- break;
566
- default:
567
- return -EINVAL;
568
- }
569
-
570
- ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
571
- if (ret < 0)
572
- return ret;
573
-
574
- set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
575
- /*
576
- * Don't enable suspend mode if regulator is already disabled because
577
- * this would effectively for a short time turn on the regulator after
578
- * resuming.
579
- * However we still want to toggle the suspend_state bit for regulator
580
- * in case if it got enabled before suspending the system.
581
- */
582
- if (!(val & rdev->desc->enable_mask))
583
- return 0;
584
-
585
- return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
586
- rdev->desc->enable_mask, state);
587
-}
588
-
589617 static const struct regulator_ops s2mps14_reg_ops = {
590618 .list_voltage = regulator_list_voltage_linear,
591619 .map_voltage = regulator_map_voltage_linear,
592620 .is_enabled = regulator_is_enabled_regmap,
593
- .enable = s2mps14_regulator_enable,
621
+ .enable = s2mps11_regulator_enable,
594622 .disable = regulator_disable_regmap,
595623 .get_voltage_sel = regulator_get_voltage_sel_regmap,
596624 .set_voltage_sel = regulator_set_voltage_sel_regmap,
597625 .set_voltage_time_sel = regulator_set_voltage_time_sel,
598
- .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
626
+ .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
599627 };
600628
601629 #define regulator_desc_s2mps14_ldo(num, min, step) { \
....@@ -721,37 +749,37 @@
721749 }
722750
723751 /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
724
-static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
752
+static const struct linear_range s2mps15_ldo_voltage_ranges1[] = {
725753 REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
726754 };
727755
728756 /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
729
-static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
757
+static const struct linear_range s2mps15_ldo_voltage_ranges2[] = {
730758 REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
731759 };
732760
733761 /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
734
-static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
762
+static const struct linear_range s2mps15_ldo_voltage_ranges3[] = {
735763 REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
736764 };
737765
738766 /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
739
-static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
767
+static const struct linear_range s2mps15_ldo_voltage_ranges4[] = {
740768 REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
741769 };
742770
743771 /* voltage range for s2mps15 LDO 1 */
744
-static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
772
+static const struct linear_range s2mps15_ldo_voltage_ranges5[] = {
745773 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
746774 };
747775
748776 /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
749
-static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
777
+static const struct linear_range s2mps15_buck_voltage_ranges1[] = {
750778 REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
751779 };
752780
753781 /* voltage range for s2mps15 BUCK 8, 9 and 10 */
754
-static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
782
+static const struct linear_range s2mps15_buck_voltage_ranges2[] = {
755783 REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
756784 };
757785
....@@ -805,7 +833,7 @@
805833 static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
806834 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
807835 {
808
- int *gpio = s2mps11->ext_control_gpio;
836
+ struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
809837 unsigned int i;
810838 unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
811839 S2MPS14_LDO12 };
....@@ -816,11 +844,22 @@
816844 if (!rdata[reg].init_data || !rdata[reg].of_node)
817845 continue;
818846
819
- gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
820
- "samsung,ext-control-gpios", 0);
821
- if (gpio_is_valid(gpio[reg]))
822
- dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
823
- gpio[reg], reg, rdata[reg].name);
847
+ gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev,
848
+ of_fwnode_handle(rdata[reg].of_node),
849
+ "samsung,ext-control",
850
+ GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
851
+ "s2mps11-regulator");
852
+ if (PTR_ERR(gpio[reg]) == -ENOENT)
853
+ gpio[reg] = NULL;
854
+ else if (IS_ERR(gpio[reg])) {
855
+ dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
856
+ reg, rdata[reg].name);
857
+ gpio[reg] = NULL;
858
+ continue;
859
+ }
860
+ if (gpio[reg])
861
+ dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
862
+ reg, rdata[reg].name);
824863 }
825864 }
826865
....@@ -848,8 +887,9 @@
848887 static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
849888 {
850889 unsigned int ramp_val, ramp_shift, ramp_reg;
890
+ int rdev_id = rdev_get_id(rdev);
851891
852
- switch (rdev_get_id(rdev)) {
892
+ switch (rdev_id) {
853893 case S2MPU02_BUCK1:
854894 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
855895 break;
....@@ -877,24 +917,24 @@
877917 .list_voltage = regulator_list_voltage_linear,
878918 .map_voltage = regulator_map_voltage_linear,
879919 .is_enabled = regulator_is_enabled_regmap,
880
- .enable = s2mps14_regulator_enable,
920
+ .enable = s2mps11_regulator_enable,
881921 .disable = regulator_disable_regmap,
882922 .get_voltage_sel = regulator_get_voltage_sel_regmap,
883923 .set_voltage_sel = regulator_set_voltage_sel_regmap,
884924 .set_voltage_time_sel = regulator_set_voltage_time_sel,
885
- .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
925
+ .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
886926 };
887927
888928 static const struct regulator_ops s2mpu02_buck_ops = {
889929 .list_voltage = regulator_list_voltage_linear,
890930 .map_voltage = regulator_map_voltage_linear,
891931 .is_enabled = regulator_is_enabled_regmap,
892
- .enable = s2mps14_regulator_enable,
932
+ .enable = s2mps11_regulator_enable,
893933 .disable = regulator_disable_regmap,
894934 .get_voltage_sel = regulator_get_voltage_sel_regmap,
895935 .set_voltage_sel = regulator_set_voltage_sel_regmap,
896936 .set_voltage_time_sel = regulator_set_voltage_time_sel,
897
- .set_suspend_disable = s2mps14_regulator_set_suspend_disable,
937
+ .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
898938 .set_ramp_delay = s2mpu02_set_ramp_delay,
899939 };
900940
....@@ -1126,17 +1166,10 @@
11261166 return -EINVAL;
11271167 }
11281168
1129
- s2mps11->ext_control_gpio = devm_kmalloc_array(&pdev->dev,
1130
- rdev_num, sizeof(*s2mps11->ext_control_gpio),
1131
- GFP_KERNEL);
1132
- if (!s2mps11->ext_control_gpio)
1169
+ s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
1170
+ sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
1171
+ if (!s2mps11->ext_control_gpiod)
11331172 return -ENOMEM;
1134
- /*
1135
- * 0 is a valid GPIO so initialize all GPIO-s to negative value
1136
- * to indicate that external control won't be used for this regulator.
1137
- */
1138
- for (i = 0; i < rdev_num; i++)
1139
- s2mps11->ext_control_gpio[i] = -EINVAL;
11401173
11411174 if (!iodev->dev->of_node) {
11421175 if (iodev->pdata) {
....@@ -1166,8 +1199,6 @@
11661199 config.dev = &pdev->dev;
11671200 config.regmap = iodev->regmap_pmic;
11681201 config.driver_data = s2mps11;
1169
- config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
1170
- config.ena_gpio_initialized = true;
11711202 for (i = 0; i < rdev_num; i++) {
11721203 struct regulator_dev *regulator;
11731204
....@@ -1178,8 +1209,13 @@
11781209 config.init_data = rdata[i].init_data;
11791210 config.of_node = rdata[i].of_node;
11801211 }
1181
- config.ena_gpio = s2mps11->ext_control_gpio[i];
1182
-
1212
+ config.ena_gpiod = s2mps11->ext_control_gpiod[i];
1213
+ /*
1214
+ * Hand the GPIO descriptor management over to the regulator
1215
+ * core, remove it from devres management.
1216
+ */
1217
+ if (config.ena_gpiod)
1218
+ devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
11831219 regulator = devm_regulator_register(&pdev->dev,
11841220 &regulators[i], &config);
11851221 if (IS_ERR(regulator)) {
....@@ -1189,7 +1225,7 @@
11891225 goto out;
11901226 }
11911227
1192
- if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
1228
+ if (config.ena_gpiod) {
11931229 ret = s2mps14_pmic_enable_ext_control(s2mps11,
11941230 regulator);
11951231 if (ret < 0) {
....@@ -1229,5 +1265,5 @@
12291265
12301266 /* Module information */
12311267 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1232
-MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
1268
+MODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
12331269 MODULE_LICENSE("GPL");