forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/regulator/core.c
....@@ -1,17 +1,11 @@
1
-/*
2
- * core.c -- Voltage/Current Regulator framework.
3
- *
4
- * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5
- * Copyright 2008 SlimLogic Ltd.
6
- *
7
- * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the
11
- * Free Software Foundation; either version 2 of the License, or (at your
12
- * option) any later version.
13
- *
14
- */
1
+// SPDX-License-Identifier: GPL-2.0-or-later
2
+//
3
+// core.c -- Voltage/Current Regulator framework.
4
+//
5
+// Copyright 2007, 2008 Wolfson Microelectronics PLC.
6
+// Copyright 2008 SlimLogic Ltd.
7
+//
8
+// Author: Liam Girdwood <lrg@slimlogic.co.uk>
159
1610 #include <linux/kernel.h>
1711 #include <linux/init.h>
....@@ -23,14 +17,12 @@
2317 #include <linux/mutex.h>
2418 #include <linux/suspend.h>
2519 #include <linux/delay.h>
26
-#include <linux/gpio.h>
2720 #include <linux/gpio/consumer.h>
2821 #include <linux/of.h>
2922 #include <linux/regmap.h>
30
-#include <linux/seq_file.h>
31
-#include <linux/uaccess.h>
3223 #include <linux/regulator/of_regulator.h>
3324 #include <linux/regulator/consumer.h>
25
+#include <linux/regulator/coupler.h>
3426 #include <linux/regulator/driver.h>
3527 #include <linux/regulator/machine.h>
3628 #include <linux/module.h>
....@@ -52,12 +44,14 @@
5244 #define rdev_dbg(rdev, fmt, ...) \
5345 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
5446
47
+static DEFINE_WW_CLASS(regulator_ww_class);
48
+static DEFINE_MUTEX(regulator_nesting_mutex);
5549 static DEFINE_MUTEX(regulator_list_mutex);
5650 static LIST_HEAD(regulator_map_list);
5751 static LIST_HEAD(regulator_ena_gpio_list);
5852 static LIST_HEAD(regulator_supply_alias_list);
53
+static LIST_HEAD(regulator_coupler_list);
5954 static LIST_HEAD(regulator_debug_list);
60
-static LIST_HEAD(regulator_early_min_volt_list);
6155 static bool has_full_constraints;
6256
6357 static struct dentry *debugfs_root;
....@@ -84,7 +78,6 @@
8478 struct gpio_desc *gpiod;
8579 u32 enable_count; /* a number of enabled shared GPIO */
8680 u32 request_count; /* a number of requested shared GPIO */
87
- unsigned int ena_gpio_invert:1;
8881 };
8982
9083 /*
....@@ -106,20 +99,22 @@
10699 };
107100
108101 static int _regulator_is_enabled(struct regulator_dev *rdev);
109
-static int _regulator_disable(struct regulator_dev *rdev);
110
-static int _regulator_get_voltage(struct regulator_dev *rdev);
102
+static int _regulator_disable(struct regulator *regulator);
111103 static int _regulator_get_current_limit(struct regulator_dev *rdev);
112104 static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
113105 static int _notifier_call_chain(struct regulator_dev *rdev,
114106 unsigned long event, void *data);
115107 static int _regulator_do_set_voltage(struct regulator_dev *rdev,
116108 int min_uV, int max_uV);
109
+static int regulator_balance_voltage(struct regulator_dev *rdev,
110
+ suspend_state_t state);
117111 static struct regulator *create_regulator(struct regulator_dev *rdev,
118112 struct device *dev,
119113 const char *supply_name);
114
+static void destroy_regulator(struct regulator *regulator);
120115 static void _regulator_put(struct regulator *regulator);
121116
122
-static const char *rdev_get_name(struct regulator_dev *rdev)
117
+const char *rdev_get_name(struct regulator_dev *rdev)
123118 {
124119 if (rdev->constraints && rdev->constraints->name)
125120 return rdev->constraints->name;
....@@ -147,18 +142,10 @@
147142 return false;
148143 }
149144
150
-static inline struct regulator_dev *rdev_get_supply(struct regulator_dev *rdev)
151
-{
152
- if (rdev && rdev->supply)
153
- return rdev->supply->rdev;
154
-
155
- return NULL;
156
-}
157
-
158145 /**
159146 * regulator_lock_nested - lock a single regulator
160147 * @rdev: regulator source
161
- * @subclass: mutex subclass used for lockdep
148
+ * @ww_ctx: w/w mutex acquire context
162149 *
163150 * This function can be called many times by one task on
164151 * a single regulator and its mutex will be locked only
....@@ -166,24 +153,52 @@
166153 * than the one, which initially locked the mutex, it will
167154 * wait on mutex.
168155 */
169
-static void regulator_lock_nested(struct regulator_dev *rdev,
170
- unsigned int subclass)
156
+static inline int regulator_lock_nested(struct regulator_dev *rdev,
157
+ struct ww_acquire_ctx *ww_ctx)
171158 {
172
- if (!mutex_trylock(&rdev->mutex)) {
173
- if (rdev->mutex_owner == current) {
159
+ bool lock = false;
160
+ int ret = 0;
161
+
162
+ mutex_lock(&regulator_nesting_mutex);
163
+
164
+ if (ww_ctx || !ww_mutex_trylock(&rdev->mutex)) {
165
+ if (rdev->mutex_owner == current)
174166 rdev->ref_cnt++;
175
- return;
167
+ else
168
+ lock = true;
169
+
170
+ if (lock) {
171
+ mutex_unlock(&regulator_nesting_mutex);
172
+ ret = ww_mutex_lock(&rdev->mutex, ww_ctx);
173
+ mutex_lock(&regulator_nesting_mutex);
176174 }
177
- mutex_lock_nested(&rdev->mutex, subclass);
175
+ } else {
176
+ lock = true;
178177 }
179178
180
- rdev->ref_cnt = 1;
181
- rdev->mutex_owner = current;
179
+ if (lock && ret != -EDEADLK) {
180
+ rdev->ref_cnt++;
181
+ rdev->mutex_owner = current;
182
+ }
183
+
184
+ mutex_unlock(&regulator_nesting_mutex);
185
+
186
+ return ret;
182187 }
183188
184
-static inline void regulator_lock(struct regulator_dev *rdev)
189
+/**
190
+ * regulator_lock - lock a single regulator
191
+ * @rdev: regulator source
192
+ *
193
+ * This function can be called many times by one task on
194
+ * a single regulator and its mutex will be locked only
195
+ * once. If a task, which is calling this function is other
196
+ * than the one, which initially locked the mutex, it will
197
+ * wait on mutex.
198
+ */
199
+static void regulator_lock(struct regulator_dev *rdev)
185200 {
186
- regulator_lock_nested(rdev, 0);
201
+ regulator_lock_nested(rdev, NULL);
187202 }
188203
189204 /**
....@@ -195,45 +210,160 @@
195210 */
196211 static void regulator_unlock(struct regulator_dev *rdev)
197212 {
198
- if (rdev->ref_cnt != 0) {
199
- rdev->ref_cnt--;
213
+ mutex_lock(&regulator_nesting_mutex);
200214
201
- if (!rdev->ref_cnt) {
202
- rdev->mutex_owner = NULL;
203
- mutex_unlock(&rdev->mutex);
204
- }
215
+ if (--rdev->ref_cnt == 0) {
216
+ rdev->mutex_owner = NULL;
217
+ ww_mutex_unlock(&rdev->mutex);
205218 }
219
+
220
+ WARN_ON_ONCE(rdev->ref_cnt < 0);
221
+
222
+ mutex_unlock(&regulator_nesting_mutex);
206223 }
207224
208
-/**
209
- * regulator_lock_supply - lock a regulator and its supplies
210
- * @rdev: regulator source
211
- */
212
-static void regulator_lock_supply(struct regulator_dev *rdev)
225
+static bool regulator_supply_is_couple(struct regulator_dev *rdev)
213226 {
227
+ struct regulator_dev *c_rdev;
214228 int i;
215229
216
- for (i = 0; rdev; rdev = rdev_get_supply(rdev), i++)
217
- regulator_lock_nested(rdev, i);
230
+ for (i = 1; i < rdev->coupling_desc.n_coupled; i++) {
231
+ c_rdev = rdev->coupling_desc.coupled_rdevs[i];
232
+
233
+ if (rdev->supply->rdev == c_rdev)
234
+ return true;
235
+ }
236
+
237
+ return false;
238
+}
239
+
240
+static void regulator_unlock_recursive(struct regulator_dev *rdev,
241
+ unsigned int n_coupled)
242
+{
243
+ struct regulator_dev *c_rdev, *supply_rdev;
244
+ int i, supply_n_coupled;
245
+
246
+ for (i = n_coupled; i > 0; i--) {
247
+ c_rdev = rdev->coupling_desc.coupled_rdevs[i - 1];
248
+
249
+ if (!c_rdev)
250
+ continue;
251
+
252
+ if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) {
253
+ supply_rdev = c_rdev->supply->rdev;
254
+ supply_n_coupled = supply_rdev->coupling_desc.n_coupled;
255
+
256
+ regulator_unlock_recursive(supply_rdev,
257
+ supply_n_coupled);
258
+ }
259
+
260
+ regulator_unlock(c_rdev);
261
+ }
262
+}
263
+
264
+static int regulator_lock_recursive(struct regulator_dev *rdev,
265
+ struct regulator_dev **new_contended_rdev,
266
+ struct regulator_dev **old_contended_rdev,
267
+ struct ww_acquire_ctx *ww_ctx)
268
+{
269
+ struct regulator_dev *c_rdev;
270
+ int i, err;
271
+
272
+ for (i = 0; i < rdev->coupling_desc.n_coupled; i++) {
273
+ c_rdev = rdev->coupling_desc.coupled_rdevs[i];
274
+
275
+ if (!c_rdev)
276
+ continue;
277
+
278
+ if (c_rdev != *old_contended_rdev) {
279
+ err = regulator_lock_nested(c_rdev, ww_ctx);
280
+ if (err) {
281
+ if (err == -EDEADLK) {
282
+ *new_contended_rdev = c_rdev;
283
+ goto err_unlock;
284
+ }
285
+
286
+ /* shouldn't happen */
287
+ WARN_ON_ONCE(err != -EALREADY);
288
+ }
289
+ } else {
290
+ *old_contended_rdev = NULL;
291
+ }
292
+
293
+ if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) {
294
+ err = regulator_lock_recursive(c_rdev->supply->rdev,
295
+ new_contended_rdev,
296
+ old_contended_rdev,
297
+ ww_ctx);
298
+ if (err) {
299
+ regulator_unlock(c_rdev);
300
+ goto err_unlock;
301
+ }
302
+ }
303
+ }
304
+
305
+ return 0;
306
+
307
+err_unlock:
308
+ regulator_unlock_recursive(rdev, i);
309
+
310
+ return err;
218311 }
219312
220313 /**
221
- * regulator_unlock_supply - unlock a regulator and its supplies
222
- * @rdev: regulator source
314
+ * regulator_unlock_dependent - unlock regulator's suppliers and coupled
315
+ * regulators
316
+ * @rdev: regulator source
317
+ * @ww_ctx: w/w mutex acquire context
318
+ *
319
+ * Unlock all regulators related with rdev by coupling or supplying.
223320 */
224
-static void regulator_unlock_supply(struct regulator_dev *rdev)
321
+static void regulator_unlock_dependent(struct regulator_dev *rdev,
322
+ struct ww_acquire_ctx *ww_ctx)
225323 {
226
- struct regulator *supply;
324
+ regulator_unlock_recursive(rdev, rdev->coupling_desc.n_coupled);
325
+ ww_acquire_fini(ww_ctx);
326
+}
227327
228
- while (1) {
229
- regulator_unlock(rdev);
230
- supply = rdev->supply;
328
+/**
329
+ * regulator_lock_dependent - lock regulator's suppliers and coupled regulators
330
+ * @rdev: regulator source
331
+ * @ww_ctx: w/w mutex acquire context
332
+ *
333
+ * This function as a wrapper on regulator_lock_recursive(), which locks
334
+ * all regulators related with rdev by coupling or supplying.
335
+ */
336
+static void regulator_lock_dependent(struct regulator_dev *rdev,
337
+ struct ww_acquire_ctx *ww_ctx)
338
+{
339
+ struct regulator_dev *new_contended_rdev = NULL;
340
+ struct regulator_dev *old_contended_rdev = NULL;
341
+ int err;
231342
232
- if (!rdev->supply)
233
- return;
343
+ mutex_lock(&regulator_list_mutex);
234344
235
- rdev = supply->rdev;
236
- }
345
+ ww_acquire_init(ww_ctx, &regulator_ww_class);
346
+
347
+ do {
348
+ if (new_contended_rdev) {
349
+ ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx);
350
+ old_contended_rdev = new_contended_rdev;
351
+ old_contended_rdev->ref_cnt++;
352
+ }
353
+
354
+ err = regulator_lock_recursive(rdev,
355
+ &new_contended_rdev,
356
+ &old_contended_rdev,
357
+ ww_ctx);
358
+
359
+ if (old_contended_rdev)
360
+ regulator_unlock(old_contended_rdev);
361
+
362
+ } while (err == -EDEADLK);
363
+
364
+ ww_acquire_done(ww_ctx);
365
+
366
+ mutex_unlock(&regulator_list_mutex);
237367 }
238368
239369 /**
....@@ -259,12 +389,16 @@
259389 if (!regnode) {
260390 regnode = of_get_child_regulator(child, prop_name);
261391 if (regnode)
262
- return regnode;
392
+ goto err_node_put;
263393 } else {
264
- return regnode;
394
+ goto err_node_put;
265395 }
266396 }
267397 return NULL;
398
+
399
+err_node_put:
400
+ of_node_put(child);
401
+ return regnode;
268402 }
269403
270404 /**
....@@ -279,11 +413,11 @@
279413 static struct device_node *of_get_regulator(struct device *dev, const char *supply)
280414 {
281415 struct device_node *regnode = NULL;
282
- char prop_name[256];
416
+ char prop_name[64]; /* 64 is max size of property name */
283417
284418 dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);
285419
286
- snprintf(prop_name, sizeof(prop_name), "%s-supply", supply);
420
+ snprintf(prop_name, 64, "%s-supply", supply);
287421 regnode = of_parse_phandle(dev->of_node, prop_name, 0);
288422
289423 if (!regnode) {
....@@ -299,8 +433,8 @@
299433 }
300434
301435 /* Platform voltage constraint check */
302
-static int regulator_check_voltage(struct regulator_dev *rdev,
303
- int *min_uV, int *max_uV)
436
+int regulator_check_voltage(struct regulator_dev *rdev,
437
+ int *min_uV, int *max_uV)
304438 {
305439 BUG_ON(*min_uV > *max_uV);
306440
....@@ -332,9 +466,9 @@
332466 /* Make sure we select a voltage that suits the needs of all
333467 * regulator consumers
334468 */
335
-static int regulator_check_consumers(struct regulator_dev *rdev,
336
- int *min_uV, int *max_uV,
337
- suspend_state_t state)
469
+int regulator_check_consumers(struct regulator_dev *rdev,
470
+ int *min_uV, int *max_uV,
471
+ suspend_state_t state)
338472 {
339473 struct regulator *regulator;
340474 struct regulator_voltage *voltage;
....@@ -438,17 +572,43 @@
438572 }
439573 }
440574
575
+static const struct regulator_state *
576
+regulator_get_suspend_state_check(struct regulator_dev *rdev, suspend_state_t state)
577
+{
578
+ const struct regulator_state *rstate;
579
+
580
+ rstate = regulator_get_suspend_state(rdev, state);
581
+ if (rstate == NULL)
582
+ return NULL;
583
+
584
+ /* If we have no suspend mode configuration don't set anything;
585
+ * only warn if the driver implements set_suspend_voltage or
586
+ * set_suspend_mode callback.
587
+ */
588
+ if (rstate->enabled != ENABLE_IN_SUSPEND &&
589
+ rstate->enabled != DISABLE_IN_SUSPEND) {
590
+ if (rdev->desc->ops->set_suspend_voltage ||
591
+ rdev->desc->ops->set_suspend_mode)
592
+ rdev_warn(rdev, "No configuration\n");
593
+ return NULL;
594
+ }
595
+
596
+ return rstate;
597
+}
598
+
441599 static ssize_t regulator_uV_show(struct device *dev,
442600 struct device_attribute *attr, char *buf)
443601 {
444602 struct regulator_dev *rdev = dev_get_drvdata(dev);
445
- ssize_t ret;
603
+ int uV;
446604
447605 regulator_lock(rdev);
448
- ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev));
606
+ uV = regulator_get_voltage_rdev(rdev);
449607 regulator_unlock(rdev);
450608
451
- return ret;
609
+ if (uV < 0)
610
+ return uV;
611
+ return sprintf(buf, "%d\n", uV);
452612 }
453613 static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
454614
....@@ -470,19 +630,24 @@
470630 }
471631 static DEVICE_ATTR_RO(name);
472632
473
-static ssize_t regulator_print_opmode(char *buf, int mode)
633
+static const char *regulator_opmode_to_str(int mode)
474634 {
475635 switch (mode) {
476636 case REGULATOR_MODE_FAST:
477
- return sprintf(buf, "fast\n");
637
+ return "fast";
478638 case REGULATOR_MODE_NORMAL:
479
- return sprintf(buf, "normal\n");
639
+ return "normal";
480640 case REGULATOR_MODE_IDLE:
481
- return sprintf(buf, "idle\n");
641
+ return "idle";
482642 case REGULATOR_MODE_STANDBY:
483
- return sprintf(buf, "standby\n");
643
+ return "standby";
484644 }
485
- return sprintf(buf, "unknown\n");
645
+ return "unknown";
646
+}
647
+
648
+static ssize_t regulator_print_opmode(char *buf, int mode)
649
+{
650
+ return sprintf(buf, "%s\n", regulator_opmode_to_str(mode));
486651 }
487652
488653 static ssize_t regulator_opmode_show(struct device *dev,
....@@ -621,8 +786,10 @@
621786 int uA = 0;
622787
623788 regulator_lock(rdev);
624
- list_for_each_entry(regulator, &rdev->consumer_list, list)
625
- uA += regulator->uA_load;
789
+ list_for_each_entry(regulator, &rdev->consumer_list, list) {
790
+ if (regulator->enable_count)
791
+ uA += regulator->uA_load;
792
+ }
626793 regulator_unlock(rdev);
627794 return sprintf(buf, "%d\n", uA);
628795 }
....@@ -775,16 +942,16 @@
775942 {
776943 struct regulator *sibling;
777944 int current_uA = 0, output_uV, input_uV, err;
778
- unsigned int regulator_curr_mode, mode;
779
-
780
- lockdep_assert_held_once(&rdev->mutex);
945
+ unsigned int mode;
781946
782947 /*
783948 * first check to see if we can set modes at all, otherwise just
784949 * tell the consumer everything is OK.
785950 */
786
- if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS))
951
+ if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS)) {
952
+ rdev_dbg(rdev, "DRMS operation not allowed\n");
787953 return 0;
954
+ }
788955
789956 if (!rdev->desc->ops->get_optimum_mode &&
790957 !rdev->desc->ops->set_load)
....@@ -795,8 +962,10 @@
795962 return -EINVAL;
796963
797964 /* calc total requested load */
798
- list_for_each_entry(sibling, &rdev->consumer_list, list)
799
- current_uA += sibling->uA_load;
965
+ list_for_each_entry(sibling, &rdev->consumer_list, list) {
966
+ if (sibling->enable_count)
967
+ current_uA += sibling->uA_load;
968
+ }
800969
801970 current_uA += rdev->constraints->system_load;
802971
....@@ -804,10 +973,11 @@
804973 /* set the optimum mode for our new total regulator load */
805974 err = rdev->desc->ops->set_load(rdev, current_uA);
806975 if (err < 0)
807
- rdev_err(rdev, "failed to set load %d\n", current_uA);
976
+ rdev_err(rdev, "failed to set load %d: %pe\n",
977
+ current_uA, ERR_PTR(err));
808978 } else {
809979 /* get output voltage */
810
- output_uV = _regulator_get_voltage(rdev);
980
+ output_uV = regulator_get_voltage_rdev(rdev);
811981 if (output_uV <= 0) {
812982 rdev_err(rdev, "invalid output voltage found\n");
813983 return -EINVAL;
....@@ -831,48 +1001,24 @@
8311001 /* check the new mode is allowed */
8321002 err = regulator_mode_constrain(rdev, &mode);
8331003 if (err < 0) {
834
- rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n",
835
- current_uA, input_uV, output_uV);
1004
+ rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV: %pe\n",
1005
+ current_uA, input_uV, output_uV, ERR_PTR(err));
8361006 return err;
837
- }
838
- /* return if the same mode is requested */
839
- if (rdev->desc->ops->get_mode) {
840
- regulator_curr_mode = rdev->desc->ops->get_mode(rdev);
841
- if (regulator_curr_mode == mode)
842
- return 0;
843
- } else {
844
- return 0;
8451007 }
8461008
8471009 err = rdev->desc->ops->set_mode(rdev, mode);
8481010 if (err < 0)
849
- rdev_err(rdev, "failed to set optimum mode %x\n", mode);
1011
+ rdev_err(rdev, "failed to set optimum mode %x: %pe\n",
1012
+ mode, ERR_PTR(err));
8501013 }
8511014
8521015 return err;
8531016 }
8541017
855
-static int suspend_set_state(struct regulator_dev *rdev,
856
- suspend_state_t state)
1018
+static int __suspend_set_state(struct regulator_dev *rdev,
1019
+ const struct regulator_state *rstate)
8571020 {
8581021 int ret = 0;
859
- struct regulator_state *rstate;
860
-
861
- rstate = regulator_get_suspend_state(rdev, state);
862
- if (rstate == NULL)
863
- return 0;
864
-
865
- /* If we have no suspend mode configration don't set anything;
866
- * only warn if the driver implements set_suspend_voltage or
867
- * set_suspend_mode callback.
868
- */
869
- if (rstate->enabled != ENABLE_IN_SUSPEND &&
870
- rstate->enabled != DISABLE_IN_SUSPEND) {
871
- if (rdev->desc->ops->set_suspend_voltage ||
872
- rdev->desc->ops->set_suspend_mode)
873
- rdev_warn(rdev, "No configuration\n");
874
- return 0;
875
- }
8761022
8771023 if (rstate->enabled == ENABLE_IN_SUSPEND &&
8781024 rdev->desc->ops->set_suspend_enable)
....@@ -884,14 +1030,14 @@
8841030 ret = 0;
8851031
8861032 if (ret < 0) {
887
- rdev_err(rdev, "failed to enabled/disable\n");
1033
+ rdev_err(rdev, "failed to enabled/disable: %pe\n", ERR_PTR(ret));
8881034 return ret;
8891035 }
8901036
8911037 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
8921038 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
8931039 if (ret < 0) {
894
- rdev_err(rdev, "failed to set voltage\n");
1040
+ rdev_err(rdev, "failed to set voltage: %pe\n", ERR_PTR(ret));
8951041 return ret;
8961042 }
8971043 }
....@@ -899,7 +1045,7 @@
8991045 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
9001046 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
9011047 if (ret < 0) {
902
- rdev_err(rdev, "failed to set mode\n");
1048
+ rdev_err(rdev, "failed to set mode: %pe\n", ERR_PTR(ret));
9031049 return ret;
9041050 }
9051051 }
....@@ -907,7 +1053,20 @@
9071053 return ret;
9081054 }
9091055
910
-static void print_constraints(struct regulator_dev *rdev)
1056
+static int suspend_set_initial_state(struct regulator_dev *rdev)
1057
+{
1058
+ const struct regulator_state *rstate;
1059
+
1060
+ rstate = regulator_get_suspend_state_check(rdev,
1061
+ rdev->constraints->initial_state);
1062
+ if (!rstate)
1063
+ return 0;
1064
+
1065
+ return __suspend_set_state(rdev, rstate);
1066
+}
1067
+
1068
+#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
1069
+static void print_constraints_debug(struct regulator_dev *rdev)
9111070 {
9121071 struct regulation_constraints *constraints = rdev->constraints;
9131072 char buf[160] = "";
....@@ -928,7 +1087,7 @@
9281087
9291088 if (!constraints->min_uV ||
9301089 constraints->min_uV != constraints->max_uV) {
931
- ret = _regulator_get_voltage(rdev);
1090
+ ret = regulator_get_voltage_rdev(rdev);
9321091 if (ret > 0)
9331092 count += scnprintf(buf + count, len - count,
9341093 "at %d mV ", ret / 1000);
....@@ -964,12 +1123,27 @@
9641123 if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE)
9651124 count += scnprintf(buf + count, len - count, "idle ");
9661125 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
967
- count += scnprintf(buf + count, len - count, "standby");
1126
+ count += scnprintf(buf + count, len - count, "standby ");
9681127
9691128 if (!count)
970
- scnprintf(buf, len, "no parameters");
1129
+ count = scnprintf(buf, len, "no parameters");
1130
+ else
1131
+ --count;
1132
+
1133
+ count += scnprintf(buf + count, len - count, ", %s",
1134
+ _regulator_is_enabled(rdev) ? "enabled" : "disabled");
9711135
9721136 rdev_dbg(rdev, "%s\n", buf);
1137
+}
1138
+#else /* !DEBUG && !CONFIG_DYNAMIC_DEBUG */
1139
+static inline void print_constraints_debug(struct regulator_dev *rdev) {}
1140
+#endif /* !DEBUG && !CONFIG_DYNAMIC_DEBUG */
1141
+
1142
+static void print_constraints(struct regulator_dev *rdev)
1143
+{
1144
+ struct regulation_constraints *constraints = rdev->constraints;
1145
+
1146
+ print_constraints_debug(rdev);
9731147
9741148 if ((constraints->min_uV != constraints->max_uV) &&
9751149 !regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE))
....@@ -987,23 +1161,23 @@
9871161 if (rdev->constraints->apply_uV &&
9881162 rdev->constraints->min_uV && rdev->constraints->max_uV) {
9891163 int target_min, target_max;
990
- int current_uV = _regulator_get_voltage(rdev);
1164
+ int current_uV = regulator_get_voltage_rdev(rdev);
9911165
9921166 if (current_uV == -ENOTRECOVERABLE) {
993
- /* This regulator can't be read and must be initted */
1167
+ /* This regulator can't be read and must be initialized */
9941168 rdev_info(rdev, "Setting %d-%duV\n",
9951169 rdev->constraints->min_uV,
9961170 rdev->constraints->max_uV);
9971171 _regulator_do_set_voltage(rdev,
9981172 rdev->constraints->min_uV,
9991173 rdev->constraints->max_uV);
1000
- current_uV = _regulator_get_voltage(rdev);
1174
+ current_uV = regulator_get_voltage_rdev(rdev);
10011175 }
10021176
10031177 if (current_uV < 0) {
10041178 rdev_err(rdev,
1005
- "failed to get the current voltage(%d)\n",
1006
- current_uV);
1179
+ "failed to get the current voltage: %pe\n",
1180
+ ERR_PTR(current_uV));
10071181 return current_uV;
10081182 }
10091183
....@@ -1032,8 +1206,8 @@
10321206 rdev, target_min, target_max);
10331207 if (ret < 0) {
10341208 rdev_err(rdev,
1035
- "failed to apply %d-%duV constraint(%d)\n",
1036
- target_min, target_max, ret);
1209
+ "failed to apply %d-%duV constraint: %pe\n",
1210
+ target_min, target_max, ERR_PTR(ret));
10371211 return ret;
10381212 }
10391213 }
....@@ -1068,6 +1242,10 @@
10681242 rdev_err(rdev, "invalid voltage constraints\n");
10691243 return -EINVAL;
10701244 }
1245
+
1246
+ /* no need to loop voltages if range is continuous */
1247
+ if (rdev->desc->continuous_voltage_range)
1248
+ return 0;
10711249
10721250 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
10731251 for (i = 0; i < count; i++) {
....@@ -1167,16 +1345,16 @@
11671345 ret = ops->set_input_current_limit(rdev,
11681346 rdev->constraints->ilim_uA);
11691347 if (ret < 0) {
1170
- rdev_err(rdev, "failed to set input limit\n");
1348
+ rdev_err(rdev, "failed to set input limit: %pe\n", ERR_PTR(ret));
11711349 return ret;
11721350 }
11731351 }
11741352
11751353 /* do we need to setup our suspend state */
11761354 if (rdev->constraints->initial_state) {
1177
- ret = suspend_set_state(rdev, rdev->constraints->initial_state);
1355
+ ret = suspend_set_initial_state(rdev);
11781356 if (ret < 0) {
1179
- rdev_err(rdev, "failed to set suspend state\n");
1357
+ rdev_err(rdev, "failed to set suspend state: %pe\n", ERR_PTR(ret));
11801358 return ret;
11811359 }
11821360 }
....@@ -1189,16 +1367,22 @@
11891367
11901368 ret = ops->set_mode(rdev, rdev->constraints->initial_mode);
11911369 if (ret < 0) {
1192
- rdev_err(rdev, "failed to set initial mode: %d\n", ret);
1370
+ rdev_err(rdev, "failed to set initial mode: %pe\n", ERR_PTR(ret));
11931371 return ret;
11941372 }
1373
+ } else if (rdev->constraints->system_load) {
1374
+ /*
1375
+ * We'll only apply the initial system load if an
1376
+ * initial mode wasn't specified.
1377
+ */
1378
+ drms_uA_update(rdev);
11951379 }
11961380
11971381 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable)
11981382 && ops->set_ramp_delay) {
11991383 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay);
12001384 if (ret < 0) {
1201
- rdev_err(rdev, "failed to set ramp_delay\n");
1385
+ rdev_err(rdev, "failed to set ramp_delay: %pe\n", ERR_PTR(ret));
12021386 return ret;
12031387 }
12041388 }
....@@ -1206,7 +1390,7 @@
12061390 if (rdev->constraints->pull_down && ops->set_pull_down) {
12071391 ret = ops->set_pull_down(rdev);
12081392 if (ret < 0) {
1209
- rdev_err(rdev, "failed to set pull down\n");
1393
+ rdev_err(rdev, "failed to set pull down: %pe\n", ERR_PTR(ret));
12101394 return ret;
12111395 }
12121396 }
....@@ -1214,7 +1398,7 @@
12141398 if (rdev->constraints->soft_start && ops->set_soft_start) {
12151399 ret = ops->set_soft_start(rdev);
12161400 if (ret < 0) {
1217
- rdev_err(rdev, "failed to set soft start\n");
1401
+ rdev_err(rdev, "failed to set soft start: %pe\n", ERR_PTR(ret));
12181402 return ret;
12191403 }
12201404 }
....@@ -1223,7 +1407,8 @@
12231407 && ops->set_over_current_protection) {
12241408 ret = ops->set_over_current_protection(rdev);
12251409 if (ret < 0) {
1226
- rdev_err(rdev, "failed to set over current protection\n");
1410
+ rdev_err(rdev, "failed to set over current protection: %pe\n",
1411
+ ERR_PTR(ret));
12271412 return ret;
12281413 }
12291414 }
....@@ -1234,7 +1419,7 @@
12341419
12351420 ret = ops->set_active_discharge(rdev, ad_state);
12361421 if (ret < 0) {
1237
- rdev_err(rdev, "failed to set active discharge\n");
1422
+ rdev_err(rdev, "failed to set active discharge: %pe\n", ERR_PTR(ret));
12381423 return ret;
12391424 }
12401425 }
....@@ -1249,7 +1434,7 @@
12491434 if (rdev->supply_name && !rdev->supply)
12501435 return -EPROBE_DEFER;
12511436
1252
- if (rdev->supply && !_regulator_is_enabled(rdev->supply->rdev)) {
1437
+ if (rdev->supply) {
12531438 ret = regulator_enable(rdev->supply);
12541439 if (ret < 0) {
12551440 _regulator_put(rdev->supply);
....@@ -1258,13 +1443,10 @@
12581443 }
12591444 }
12601445
1261
- /* The regulator may on if it's not switchable or left on */
1262
- if (!_regulator_is_enabled(rdev)) {
1263
- ret = _regulator_do_enable(rdev);
1264
- if (ret < 0 && ret != -EINVAL) {
1265
- rdev_err(rdev, "failed to enable\n");
1266
- return ret;
1267
- }
1446
+ ret = _regulator_do_enable(rdev);
1447
+ if (ret < 0 && ret != -EINVAL) {
1448
+ rdev_err(rdev, "failed to enable: %pe\n", ERR_PTR(ret));
1449
+ return ret;
12681450 }
12691451
12701452 if (rdev->constraints->always_on)
....@@ -1447,48 +1629,54 @@
14471629 const char *supply_name)
14481630 {
14491631 struct regulator *regulator;
1450
- char buf[REG_STR_SIZE];
1451
- int err, size;
1632
+ int err = 0;
1633
+
1634
+ if (dev) {
1635
+ char buf[REG_STR_SIZE];
1636
+ int size;
1637
+
1638
+ size = snprintf(buf, REG_STR_SIZE, "%s-%s",
1639
+ dev->kobj.name, supply_name);
1640
+ if (size >= REG_STR_SIZE)
1641
+ return NULL;
1642
+
1643
+ supply_name = kstrdup(buf, GFP_KERNEL);
1644
+ if (supply_name == NULL)
1645
+ return NULL;
1646
+ } else {
1647
+ supply_name = kstrdup_const(supply_name, GFP_KERNEL);
1648
+ if (supply_name == NULL)
1649
+ return NULL;
1650
+ }
14521651
14531652 regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
1454
- if (regulator == NULL)
1653
+ if (regulator == NULL) {
1654
+ kfree(supply_name);
14551655 return NULL;
1656
+ }
1657
+
1658
+ regulator->rdev = rdev;
1659
+ regulator->supply_name = supply_name;
14561660
14571661 regulator_lock(rdev);
1458
- regulator->rdev = rdev;
14591662 list_add(&regulator->list, &rdev->consumer_list);
1663
+ regulator_unlock(rdev);
14601664
14611665 if (dev) {
14621666 regulator->dev = dev;
14631667
14641668 /* Add a link to the device sysfs entry */
1465
- size = snprintf(buf, REG_STR_SIZE, "%s-%s",
1466
- dev->kobj.name, supply_name);
1467
- if (size >= REG_STR_SIZE)
1468
- goto overflow_err;
1469
-
1470
- regulator->supply_name = kstrdup(buf, GFP_KERNEL);
1471
- if (regulator->supply_name == NULL)
1472
- goto overflow_err;
1473
-
1474
- if (device_is_registered(dev)) {
1475
- err = sysfs_create_link_nowarn(&rdev->dev.kobj,
1476
- &dev->kobj, buf);
1477
- if (err) {
1478
- rdev_dbg(rdev,
1479
- "could not add device link %s err %d\n",
1480
- dev->kobj.name, err);
1481
- /* non-fatal */
1482
- }
1669
+ err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj,
1670
+ supply_name);
1671
+ if (err) {
1672
+ rdev_dbg(rdev, "could not add device link %s: %pe\n",
1673
+ dev->kobj.name, ERR_PTR(err));
1674
+ /* non-fatal */
14831675 }
1484
- } else {
1485
- regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL);
1486
- if (regulator->supply_name == NULL)
1487
- goto overflow_err;
14881676 }
14891677
1490
- regulator->debugfs = debugfs_create_dir(regulator->supply_name,
1491
- rdev->debugfs);
1678
+ if (err != -EEXIST)
1679
+ regulator->debugfs = debugfs_create_dir(supply_name, rdev->debugfs);
14921680 if (!regulator->debugfs) {
14931681 rdev_dbg(rdev, "Failed to create debugfs directory\n");
14941682 } else {
....@@ -1512,22 +1700,16 @@
15121700 _regulator_is_enabled(rdev))
15131701 regulator->always_on = true;
15141702
1515
- regulator_unlock(rdev);
15161703 return regulator;
1517
-overflow_err:
1518
- list_del(&regulator->list);
1519
- kfree(regulator);
1520
- regulator_unlock(rdev);
1521
- return NULL;
15221704 }
15231705
15241706 static int _regulator_get_enable_time(struct regulator_dev *rdev)
15251707 {
15261708 if (rdev->constraints && rdev->constraints->enable_time)
15271709 return rdev->constraints->enable_time;
1528
- if (!rdev->desc->ops->enable_time)
1529
- return rdev->desc->enable_time;
1530
- return rdev->desc->ops->enable_time(rdev);
1710
+ if (rdev->desc->ops->enable_time)
1711
+ return rdev->desc->ops->enable_time(rdev);
1712
+ return rdev->desc->enable_time;
15311713 }
15321714
15331715 static struct regulator_supply_alias *regulator_find_supply_alias(
....@@ -1645,7 +1827,7 @@
16451827 struct device *dev = rdev->dev.parent;
16461828 int ret = 0;
16471829
1648
- /* No supply to resovle? */
1830
+ /* No supply to resolve? */
16491831 if (!rdev->supply_name)
16501832 return 0;
16511833
....@@ -1751,7 +1933,7 @@
17511933 {
17521934 struct regulator_dev *rdev;
17531935 struct regulator *regulator;
1754
- const char *devname = dev ? dev_name(dev) : "deviceless";
1936
+ struct device_link *link;
17551937 int ret;
17561938
17571939 if (get_type >= MAX_GET_TYPE) {
....@@ -1788,9 +1970,7 @@
17881970 * enabled, even if it isn't hooked up, and just
17891971 * provide a dummy.
17901972 */
1791
- dev_warn(dev,
1792
- "%s supply %s not found, using dummy regulator\n",
1793
- devname, id);
1973
+ dev_warn(dev, "supply %s not found, using dummy regulator\n", id);
17941974 rdev = dummy_regulator_rdev;
17951975 get_device(&rdev->dev);
17961976 break;
....@@ -1798,7 +1978,7 @@
17981978 case EXCLUSIVE_GET:
17991979 dev_warn(dev,
18001980 "dummy supplies not allowed for exclusive requests\n");
1801
- /* fall through */
1981
+ fallthrough;
18021982
18031983 default:
18041984 return ERR_PTR(-ENODEV);
....@@ -1813,6 +1993,16 @@
18131993
18141994 if (get_type == EXCLUSIVE_GET && rdev->open_count) {
18151995 regulator = ERR_PTR(-EBUSY);
1996
+ put_device(&rdev->dev);
1997
+ return regulator;
1998
+ }
1999
+
2000
+ mutex_lock(&regulator_list_mutex);
2001
+ ret = (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled);
2002
+ mutex_unlock(&regulator_list_mutex);
2003
+
2004
+ if (ret != 0) {
2005
+ regulator = ERR_PTR(-EPROBE_DEFER);
18162006 put_device(&rdev->dev);
18172007 return regulator;
18182008 }
....@@ -1843,13 +2033,18 @@
18432033 rdev->exclusive = 1;
18442034
18452035 ret = _regulator_is_enabled(rdev);
1846
- if (ret > 0)
2036
+ if (ret > 0) {
18472037 rdev->use_count = 1;
1848
- else
2038
+ regulator->enable_count = 1;
2039
+ } else {
18492040 rdev->use_count = 0;
2041
+ regulator->enable_count = 0;
2042
+ }
18502043 }
18512044
1852
- device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS);
2045
+ link = device_link_add(dev, &rdev->dev, DL_FLAG_STATELESS);
2046
+ if (!IS_ERR_OR_NULL(link))
2047
+ regulator->device_link = true;
18532048
18542049 return regulator;
18552050 }
....@@ -1926,29 +2121,14 @@
19262121 }
19272122 EXPORT_SYMBOL_GPL(regulator_get_optional);
19282123
1929
-/* regulator_list_mutex lock held by regulator_put() */
1930
-static void _regulator_put(struct regulator *regulator)
2124
+static void destroy_regulator(struct regulator *regulator)
19312125 {
1932
- struct regulator_dev *rdev;
1933
-
1934
- if (IS_ERR_OR_NULL(regulator))
1935
- return;
1936
-
1937
- lockdep_assert_held_once(&regulator_list_mutex);
1938
-
1939
- rdev = regulator->rdev;
2126
+ struct regulator_dev *rdev = regulator->rdev;
19402127
19412128 debugfs_remove_recursive(regulator->debugfs);
19422129
19432130 if (regulator->dev) {
1944
- int count = 0;
1945
- struct regulator *r;
1946
-
1947
- list_for_each_entry(r, &rdev->consumer_list, list)
1948
- if (r->dev == regulator->dev)
1949
- count++;
1950
-
1951
- if (count == 1)
2131
+ if (regulator->device_link)
19522132 device_link_remove(regulator->dev, &rdev->dev);
19532133
19542134 /* remove any sysfs entries */
....@@ -1964,6 +2144,24 @@
19642144
19652145 kfree_const(regulator->supply_name);
19662146 kfree(regulator);
2147
+}
2148
+
2149
+/* regulator_list_mutex lock held by regulator_put() */
2150
+static void _regulator_put(struct regulator *regulator)
2151
+{
2152
+ struct regulator_dev *rdev;
2153
+
2154
+ if (IS_ERR_OR_NULL(regulator))
2155
+ return;
2156
+
2157
+ lockdep_assert_held_once(&regulator_list_mutex);
2158
+
2159
+ /* Docs say you must disable before calling regulator_put() */
2160
+ WARN_ON(regulator->enable_count);
2161
+
2162
+ rdev = regulator->rdev;
2163
+
2164
+ destroy_regulator(regulator);
19672165
19682166 module_put(rdev->owner);
19692167 put_device(&rdev->dev);
....@@ -2118,45 +2316,39 @@
21182316 static int regulator_ena_gpio_request(struct regulator_dev *rdev,
21192317 const struct regulator_config *config)
21202318 {
2121
- struct regulator_enable_gpio *pin;
2319
+ struct regulator_enable_gpio *pin, *new_pin;
21222320 struct gpio_desc *gpiod;
2123
- int ret;
21242321
2125
- if (config->ena_gpiod)
2126
- gpiod = config->ena_gpiod;
2127
- else
2128
- gpiod = gpio_to_desc(config->ena_gpio);
2322
+ gpiod = config->ena_gpiod;
2323
+ new_pin = kzalloc(sizeof(*new_pin), GFP_KERNEL);
2324
+
2325
+ mutex_lock(&regulator_list_mutex);
21292326
21302327 list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
21312328 if (pin->gpiod == gpiod) {
2132
- rdev_dbg(rdev, "GPIO %d is already used\n",
2133
- config->ena_gpio);
2329
+ rdev_dbg(rdev, "GPIO is already used\n");
21342330 goto update_ena_gpio_to_rdev;
21352331 }
21362332 }
21372333
2138
- if (!config->ena_gpiod) {
2139
- ret = gpio_request_one(config->ena_gpio,
2140
- GPIOF_DIR_OUT | config->ena_gpio_flags,
2141
- rdev_get_name(rdev));
2142
- if (ret)
2143
- return ret;
2144
- }
2145
-
2146
- pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
2147
- if (pin == NULL) {
2148
- if (!config->ena_gpiod)
2149
- gpio_free(config->ena_gpio);
2334
+ if (new_pin == NULL) {
2335
+ mutex_unlock(&regulator_list_mutex);
21502336 return -ENOMEM;
21512337 }
21522338
2339
+ pin = new_pin;
2340
+ new_pin = NULL;
2341
+
21532342 pin->gpiod = gpiod;
2154
- pin->ena_gpio_invert = config->ena_gpio_invert;
21552343 list_add(&pin->list, &regulator_ena_gpio_list);
21562344
21572345 update_ena_gpio_to_rdev:
21582346 pin->request_count++;
21592347 rdev->ena_pin = pin;
2348
+
2349
+ mutex_unlock(&regulator_list_mutex);
2350
+ kfree(new_pin);
2351
+
21602352 return 0;
21612353 }
21622354
....@@ -2169,19 +2361,19 @@
21692361
21702362 /* Free the GPIO only in case of no use */
21712363 list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) {
2172
- if (pin->gpiod == rdev->ena_pin->gpiod) {
2173
- if (pin->request_count <= 1) {
2174
- pin->request_count = 0;
2175
- gpiod_put(pin->gpiod);
2176
- list_del(&pin->list);
2177
- kfree(pin);
2178
- rdev->ena_pin = NULL;
2179
- return;
2180
- } else {
2181
- pin->request_count--;
2182
- }
2183
- }
2364
+ if (pin != rdev->ena_pin)
2365
+ continue;
2366
+
2367
+ if (--pin->request_count)
2368
+ break;
2369
+
2370
+ gpiod_put(pin->gpiod);
2371
+ list_del(&pin->list);
2372
+ kfree(pin);
2373
+ break;
21842374 }
2375
+
2376
+ rdev->ena_pin = NULL;
21852377 }
21862378
21872379 /**
....@@ -2202,8 +2394,7 @@
22022394 if (enable) {
22032395 /* Enable GPIO at initial use */
22042396 if (pin->enable_count == 0)
2205
- gpiod_set_value_cansleep(pin->gpiod,
2206
- !pin->ena_gpio_invert);
2397
+ gpiod_set_value_cansleep(pin->gpiod, 1);
22072398
22082399 pin->enable_count++;
22092400 } else {
....@@ -2214,8 +2405,7 @@
22142405
22152406 /* Disable GPIO if not used */
22162407 if (pin->enable_count <= 1) {
2217
- gpiod_set_value_cansleep(pin->gpiod,
2218
- pin->ena_gpio_invert);
2408
+ gpiod_set_value_cansleep(pin->gpiod, 0);
22192409 pin->enable_count = 0;
22202410 }
22212411 }
....@@ -2229,7 +2419,7 @@
22292419 *
22302420 * Delay for the requested amount of time as per the guidelines in:
22312421 *
2232
- * Documentation/timers/timers-howto.txt
2422
+ * Documentation/timers/timers-howto.rst
22332423 *
22342424 * The assumption here is that regulators will never be enabled in
22352425 * atomic context and therefore sleeping functions can be used.
....@@ -2262,6 +2452,37 @@
22622452 udelay(us);
22632453 }
22642454
2455
+/**
2456
+ * _regulator_check_status_enabled
2457
+ *
2458
+ * A helper function to check if the regulator status can be interpreted
2459
+ * as 'regulator is enabled'.
2460
+ * @rdev: the regulator device to check
2461
+ *
2462
+ * Return:
2463
+ * * 1 - if status shows regulator is in enabled state
2464
+ * * 0 - if not enabled state
2465
+ * * Error Value - as received from ops->get_status()
2466
+ */
2467
+static inline int _regulator_check_status_enabled(struct regulator_dev *rdev)
2468
+{
2469
+ int ret = rdev->desc->ops->get_status(rdev);
2470
+
2471
+ if (ret < 0) {
2472
+ rdev_info(rdev, "get_status returned error: %d\n", ret);
2473
+ return ret;
2474
+ }
2475
+
2476
+ switch (ret) {
2477
+ case REGULATOR_STATUS_OFF:
2478
+ case REGULATOR_STATUS_ERROR:
2479
+ case REGULATOR_STATUS_UNDEFINED:
2480
+ return 0;
2481
+ default:
2482
+ return 1;
2483
+ }
2484
+}
2485
+
22652486 static int _regulator_do_enable(struct regulator_dev *rdev)
22662487 {
22672488 int ret, delay;
....@@ -2271,7 +2492,7 @@
22712492 if (ret >= 0) {
22722493 delay = ret;
22732494 } else {
2274
- rdev_warn(rdev, "enable_time() failed: %d\n", ret);
2495
+ rdev_warn(rdev, "enable_time() failed: %pe\n", ERR_PTR(ret));
22752496 delay = 0;
22762497 }
22772498
....@@ -2292,7 +2513,7 @@
22922513 * timer wrapping.
22932514 * in case of multiple timer wrapping, either it can be
22942515 * detected by out-of-range remaining, or it cannot be
2295
- * detected and we gets a panelty of
2516
+ * detected and we get a penalty of
22962517 * _regulator_enable_delay().
22972518 */
22982519 remaining = intended - start_jiffy;
....@@ -2322,47 +2543,151 @@
23222543 * together. */
23232544 trace_regulator_enable_delay(rdev_get_name(rdev));
23242545
2325
- _regulator_enable_delay(delay);
2546
+ /* If poll_enabled_time is set, poll upto the delay calculated
2547
+ * above, delaying poll_enabled_time uS to check if the regulator
2548
+ * actually got enabled.
2549
+ * If the regulator isn't enabled after enable_delay has
2550
+ * expired, return -ETIMEDOUT.
2551
+ */
2552
+ if (rdev->desc->poll_enabled_time) {
2553
+ int time_remaining = delay;
2554
+
2555
+ while (time_remaining > 0) {
2556
+ _regulator_enable_delay(rdev->desc->poll_enabled_time);
2557
+
2558
+ if (rdev->desc->ops->get_status) {
2559
+ ret = _regulator_check_status_enabled(rdev);
2560
+ if (ret < 0)
2561
+ return ret;
2562
+ else if (ret)
2563
+ break;
2564
+ } else if (rdev->desc->ops->is_enabled(rdev))
2565
+ break;
2566
+
2567
+ time_remaining -= rdev->desc->poll_enabled_time;
2568
+ }
2569
+
2570
+ if (time_remaining <= 0) {
2571
+ rdev_err(rdev, "Enabled check timed out\n");
2572
+ return -ETIMEDOUT;
2573
+ }
2574
+ } else {
2575
+ _regulator_enable_delay(delay);
2576
+ }
23262577
23272578 trace_regulator_enable_complete(rdev_get_name(rdev));
23282579
23292580 return 0;
23302581 }
23312582
2332
-/* locks held by regulator_enable() */
2333
-static int _regulator_enable(struct regulator_dev *rdev)
2583
+/**
2584
+ * _regulator_handle_consumer_enable - handle that a consumer enabled
2585
+ * @regulator: regulator source
2586
+ *
2587
+ * Some things on a regulator consumer (like the contribution towards total
2588
+ * load on the regulator) only have an effect when the consumer wants the
2589
+ * regulator enabled. Explained in example with two consumers of the same
2590
+ * regulator:
2591
+ * consumer A: set_load(100); => total load = 0
2592
+ * consumer A: regulator_enable(); => total load = 100
2593
+ * consumer B: set_load(1000); => total load = 100
2594
+ * consumer B: regulator_enable(); => total load = 1100
2595
+ * consumer A: regulator_disable(); => total_load = 1000
2596
+ *
2597
+ * This function (together with _regulator_handle_consumer_disable) is
2598
+ * responsible for keeping track of the refcount for a given regulator consumer
2599
+ * and applying / unapplying these things.
2600
+ *
2601
+ * Returns 0 upon no error; -error upon error.
2602
+ */
2603
+static int _regulator_handle_consumer_enable(struct regulator *regulator)
23342604 {
23352605 int ret;
2606
+ struct regulator_dev *rdev = regulator->rdev;
23362607
2337
- lockdep_assert_held_once(&rdev->mutex);
2608
+ lockdep_assert_held_once(&rdev->mutex.base);
23382609
2339
- /* check voltage and requested load before enabling */
2340
- if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS))
2341
- drms_uA_update(rdev);
2610
+ regulator->enable_count++;
2611
+ if (regulator->uA_load && regulator->enable_count == 1) {
2612
+ ret = drms_uA_update(rdev);
2613
+ if (ret)
2614
+ regulator->enable_count--;
2615
+ return ret;
2616
+ }
2617
+
2618
+ return 0;
2619
+}
2620
+
2621
+/**
2622
+ * _regulator_handle_consumer_disable - handle that a consumer disabled
2623
+ * @regulator: regulator source
2624
+ *
2625
+ * The opposite of _regulator_handle_consumer_enable().
2626
+ *
2627
+ * Returns 0 upon no error; -error upon error.
2628
+ */
2629
+static int _regulator_handle_consumer_disable(struct regulator *regulator)
2630
+{
2631
+ struct regulator_dev *rdev = regulator->rdev;
2632
+
2633
+ lockdep_assert_held_once(&rdev->mutex.base);
2634
+
2635
+ if (!regulator->enable_count) {
2636
+ rdev_err(rdev, "Underflow of regulator enable count\n");
2637
+ return -EINVAL;
2638
+ }
2639
+
2640
+ regulator->enable_count--;
2641
+ if (regulator->uA_load && regulator->enable_count == 0)
2642
+ return drms_uA_update(rdev);
2643
+
2644
+ return 0;
2645
+}
2646
+
2647
+/* locks held by regulator_enable() */
2648
+static int _regulator_enable(struct regulator *regulator)
2649
+{
2650
+ struct regulator_dev *rdev = regulator->rdev;
2651
+ int ret;
2652
+
2653
+ lockdep_assert_held_once(&rdev->mutex.base);
2654
+
2655
+ if (rdev->use_count == 0 && rdev->supply) {
2656
+ ret = _regulator_enable(rdev->supply);
2657
+ if (ret < 0)
2658
+ return ret;
2659
+ }
2660
+
2661
+ /* balance only if there are regulators coupled */
2662
+ if (rdev->coupling_desc.n_coupled > 1) {
2663
+ ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON);
2664
+ if (ret < 0)
2665
+ goto err_disable_supply;
2666
+ }
2667
+
2668
+ ret = _regulator_handle_consumer_enable(regulator);
2669
+ if (ret < 0)
2670
+ goto err_disable_supply;
23422671
23432672 if (rdev->use_count == 0) {
23442673 /* The regulator may on if it's not switchable or left on */
23452674 ret = _regulator_is_enabled(rdev);
23462675 if (ret == -EINVAL || ret == 0) {
23472676 if (!regulator_ops_is_valid(rdev,
2348
- REGULATOR_CHANGE_STATUS))
2349
- return -EPERM;
2677
+ REGULATOR_CHANGE_STATUS)) {
2678
+ ret = -EPERM;
2679
+ goto err_consumer_disable;
2680
+ }
23502681
23512682 ret = _regulator_do_enable(rdev);
23522683 if (ret < 0)
2353
- return ret;
2684
+ goto err_consumer_disable;
23542685
2355
- if (IS_ENABLED(CONFIG_CPU_RV1126)) {
2356
- ret = _regulator_get_voltage(rdev);
2357
- _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,
2358
- &ret);
2359
- } else {
2360
- _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,
2361
- NULL);
2362
- }
2686
+ _notifier_call_chain(rdev, REGULATOR_EVENT_ENABLE,
2687
+ NULL);
23632688 } else if (ret < 0) {
2364
- rdev_err(rdev, "is_enabled() failed: %d\n", ret);
2365
- return ret;
2689
+ rdev_err(rdev, "is_enabled() failed: %pe\n", ERR_PTR(ret));
2690
+ goto err_consumer_disable;
23662691 }
23672692 /* Fallthrough on positive return values - already enabled */
23682693 }
....@@ -2370,6 +2695,15 @@
23702695 rdev->use_count++;
23712696
23722697 return 0;
2698
+
2699
+err_consumer_disable:
2700
+ _regulator_handle_consumer_disable(regulator);
2701
+
2702
+err_disable_supply:
2703
+ if (rdev->use_count == 0 && rdev->supply)
2704
+ _regulator_disable(rdev->supply);
2705
+
2706
+ return ret;
23732707 }
23742708
23752709 /**
....@@ -2386,23 +2720,12 @@
23862720 int regulator_enable(struct regulator *regulator)
23872721 {
23882722 struct regulator_dev *rdev = regulator->rdev;
2389
- int ret = 0;
2723
+ struct ww_acquire_ctx ww_ctx;
2724
+ int ret;
23902725
2391
- if (regulator->always_on)
2392
- return 0;
2393
-
2394
- if (rdev->supply) {
2395
- ret = regulator_enable(rdev->supply);
2396
- if (ret != 0)
2397
- return ret;
2398
- }
2399
-
2400
- mutex_lock(&rdev->mutex);
2401
- ret = _regulator_enable(rdev);
2402
- mutex_unlock(&rdev->mutex);
2403
-
2404
- if (ret != 0 && rdev->supply)
2405
- regulator_disable(rdev->supply);
2726
+ regulator_lock_dependent(rdev, &ww_ctx);
2727
+ ret = _regulator_enable(regulator);
2728
+ regulator_unlock_dependent(rdev, &ww_ctx);
24062729
24072730 return ret;
24082731 }
....@@ -2440,11 +2763,12 @@
24402763 }
24412764
24422765 /* locks held by regulator_disable() */
2443
-static int _regulator_disable(struct regulator_dev *rdev)
2766
+static int _regulator_disable(struct regulator *regulator)
24442767 {
2768
+ struct regulator_dev *rdev = regulator->rdev;
24452769 int ret = 0;
24462770
2447
- lockdep_assert_held_once(&rdev->mutex);
2771
+ lockdep_assert_held_once(&rdev->mutex.base);
24482772
24492773 if (WARN(rdev->use_count <= 0,
24502774 "unbalanced disables for %s\n", rdev_get_name(rdev)))
....@@ -2464,7 +2788,7 @@
24642788
24652789 ret = _regulator_do_disable(rdev);
24662790 if (ret < 0) {
2467
- rdev_err(rdev, "failed to disable\n");
2791
+ rdev_err(rdev, "failed to disable: %pe\n", ERR_PTR(ret));
24682792 _notifier_call_chain(rdev,
24692793 REGULATOR_EVENT_ABORT_DISABLE,
24702794 NULL);
....@@ -2476,11 +2800,17 @@
24762800
24772801 rdev->use_count = 0;
24782802 } else if (rdev->use_count > 1) {
2479
- if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS))
2480
- drms_uA_update(rdev);
2481
-
24822803 rdev->use_count--;
24832804 }
2805
+
2806
+ if (ret == 0)
2807
+ ret = _regulator_handle_consumer_disable(regulator);
2808
+
2809
+ if (ret == 0 && rdev->coupling_desc.n_coupled > 1)
2810
+ ret = regulator_balance_voltage(rdev, PM_SUSPEND_ON);
2811
+
2812
+ if (ret == 0 && rdev->use_count == 0 && rdev->supply)
2813
+ ret = _regulator_disable(rdev->supply);
24842814
24852815 return ret;
24862816 }
....@@ -2500,17 +2830,12 @@
25002830 int regulator_disable(struct regulator *regulator)
25012831 {
25022832 struct regulator_dev *rdev = regulator->rdev;
2503
- int ret = 0;
2833
+ struct ww_acquire_ctx ww_ctx;
2834
+ int ret;
25042835
2505
- if (regulator->always_on)
2506
- return 0;
2507
-
2508
- mutex_lock(&rdev->mutex);
2509
- ret = _regulator_disable(rdev);
2510
- mutex_unlock(&rdev->mutex);
2511
-
2512
- if (ret == 0 && rdev->supply)
2513
- regulator_disable(rdev->supply);
2836
+ regulator_lock_dependent(rdev, &ww_ctx);
2837
+ ret = _regulator_disable(regulator);
2838
+ regulator_unlock_dependent(rdev, &ww_ctx);
25142839
25152840 return ret;
25162841 }
....@@ -2521,7 +2846,7 @@
25212846 {
25222847 int ret = 0;
25232848
2524
- lockdep_assert_held_once(&rdev->mutex);
2849
+ lockdep_assert_held_once(&rdev->mutex.base);
25252850
25262851 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
25272852 REGULATOR_EVENT_PRE_DISABLE, NULL);
....@@ -2530,7 +2855,7 @@
25302855
25312856 ret = _regulator_do_disable(rdev);
25322857 if (ret < 0) {
2533
- rdev_err(rdev, "failed to force disable\n");
2858
+ rdev_err(rdev, "failed to force disable: %pe\n", ERR_PTR(ret));
25342859 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
25352860 REGULATOR_EVENT_ABORT_DISABLE, NULL);
25362861 return ret;
....@@ -2554,16 +2879,25 @@
25542879 int regulator_force_disable(struct regulator *regulator)
25552880 {
25562881 struct regulator_dev *rdev = regulator->rdev;
2882
+ struct ww_acquire_ctx ww_ctx;
25572883 int ret;
25582884
2559
- mutex_lock(&rdev->mutex);
2560
- regulator->uA_load = 0;
2561
- ret = _regulator_force_disable(regulator->rdev);
2562
- mutex_unlock(&rdev->mutex);
2885
+ regulator_lock_dependent(rdev, &ww_ctx);
25632886
2564
- if (rdev->supply)
2565
- while (rdev->open_count--)
2566
- regulator_disable(rdev->supply);
2887
+ ret = _regulator_force_disable(regulator->rdev);
2888
+
2889
+ if (rdev->coupling_desc.n_coupled > 1)
2890
+ regulator_balance_voltage(rdev, PM_SUSPEND_ON);
2891
+
2892
+ if (regulator->uA_load) {
2893
+ regulator->uA_load = 0;
2894
+ ret = drms_uA_update(rdev);
2895
+ }
2896
+
2897
+ if (rdev->use_count != 0 && rdev->supply)
2898
+ _regulator_disable(rdev->supply);
2899
+
2900
+ regulator_unlock_dependent(rdev, &ww_ctx);
25672901
25682902 return ret;
25692903 }
....@@ -2573,14 +2907,12 @@
25732907 {
25742908 struct regulator_dev *rdev = container_of(work, struct regulator_dev,
25752909 disable_work.work);
2910
+ struct ww_acquire_ctx ww_ctx;
25762911 int count, i, ret;
2912
+ struct regulator *regulator;
2913
+ int total_count = 0;
25772914
2578
- regulator_lock(rdev);
2579
-
2580
- BUG_ON(!rdev->deferred_disables);
2581
-
2582
- count = rdev->deferred_disables;
2583
- rdev->deferred_disables = 0;
2915
+ regulator_lock_dependent(rdev, &ww_ctx);
25842916
25852917 /*
25862918 * Workqueue functions queue the new work instance while the previous
....@@ -2590,29 +2922,34 @@
25902922 */
25912923 cancel_delayed_work(&rdev->disable_work);
25922924
2593
- for (i = 0; i < count; i++) {
2594
- ret = _regulator_disable(rdev);
2595
- if (ret != 0)
2596
- rdev_err(rdev, "Deferred disable failed: %d\n", ret);
2597
- }
2925
+ list_for_each_entry(regulator, &rdev->consumer_list, list) {
2926
+ count = regulator->deferred_disables;
25982927
2599
- regulator_unlock(rdev);
2928
+ if (!count)
2929
+ continue;
26002930
2601
- if (rdev->supply) {
2931
+ total_count += count;
2932
+ regulator->deferred_disables = 0;
2933
+
26022934 for (i = 0; i < count; i++) {
2603
- ret = regulator_disable(rdev->supply);
2604
- if (ret != 0) {
2605
- rdev_err(rdev,
2606
- "Supply disable failed: %d\n", ret);
2607
- }
2935
+ ret = _regulator_disable(regulator);
2936
+ if (ret != 0)
2937
+ rdev_err(rdev, "Deferred disable failed: %pe\n",
2938
+ ERR_PTR(ret));
26082939 }
26092940 }
2941
+ WARN_ON(!total_count);
2942
+
2943
+ if (rdev->coupling_desc.n_coupled > 1)
2944
+ regulator_balance_voltage(rdev, PM_SUSPEND_ON);
2945
+
2946
+ regulator_unlock_dependent(rdev, &ww_ctx);
26102947 }
26112948
26122949 /**
26132950 * regulator_disable_deferred - disable regulator output with delay
26142951 * @regulator: regulator source
2615
- * @ms: miliseconds until the regulator is disabled
2952
+ * @ms: milliseconds until the regulator is disabled
26162953 *
26172954 * Execute regulator_disable() on the regulator after a delay. This
26182955 * is intended for use with devices that require some time to quiesce.
....@@ -2625,14 +2962,11 @@
26252962 {
26262963 struct regulator_dev *rdev = regulator->rdev;
26272964
2628
- if (regulator->always_on)
2629
- return 0;
2630
-
26312965 if (!ms)
26322966 return regulator_disable(regulator);
26332967
26342968 regulator_lock(rdev);
2635
- rdev->deferred_disables++;
2969
+ regulator->deferred_disables++;
26362970 mod_delayed_work(system_power_efficient_wq, &rdev->disable_work,
26372971 msecs_to_jiffies(ms));
26382972 regulator_unlock(rdev);
....@@ -2707,9 +3041,9 @@
27073041 if (regulator->always_on)
27083042 return 1;
27093043
2710
- mutex_lock(&regulator->rdev->mutex);
3044
+ regulator_lock(regulator->rdev);
27113045 ret = _regulator_is_enabled(regulator->rdev);
2712
- mutex_unlock(&regulator->rdev->mutex);
3046
+ regulator_unlock(regulator->rdev);
27133047
27143048 return ret;
27153049 }
....@@ -2794,7 +3128,7 @@
27943128 *vsel_reg = rdev->desc->vsel_reg;
27953129 *vsel_mask = rdev->desc->vsel_mask;
27963130
2797
- return 0;
3131
+ return 0;
27983132 }
27993133 EXPORT_SYMBOL_GPL(regulator_get_hardware_vsel_register);
28003134
....@@ -2846,7 +3180,7 @@
28463180 * @min_uV: Minimum required voltage in uV.
28473181 * @max_uV: Maximum required voltage in uV.
28483182 *
2849
- * Returns a boolean or a negative error code.
3183
+ * Returns a boolean.
28503184 */
28513185 int regulator_is_supported_voltage(struct regulator *regulator,
28523186 int min_uV, int max_uV)
....@@ -2870,7 +3204,7 @@
28703204
28713205 ret = regulator_count_voltages(regulator);
28723206 if (ret < 0)
2873
- return ret;
3207
+ return 0;
28743208 voltages = ret;
28753209
28763210 for (i = 0; i < voltages; i++) {
....@@ -2898,6 +3232,11 @@
28983232 if (desc->ops->list_voltage == regulator_list_voltage_linear_range)
28993233 return regulator_map_voltage_linear_range(rdev, min_uV, max_uV);
29003234
3235
+ if (desc->ops->list_voltage ==
3236
+ regulator_list_voltage_pickable_linear_range)
3237
+ return regulator_map_voltage_pickable_linear_range(rdev,
3238
+ min_uV, max_uV);
3239
+
29013240 return regulator_map_voltage_iterate(rdev, min_uV, max_uV);
29023241 }
29033242
....@@ -2908,7 +3247,7 @@
29083247 struct pre_voltage_change_data data;
29093248 int ret;
29103249
2911
- data.old_uV = _regulator_get_voltage(rdev);
3250
+ data.old_uV = regulator_get_voltage_rdev(rdev);
29123251 data.min_uV = min_uV;
29133252 data.max_uV = max_uV;
29143253 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
....@@ -2932,7 +3271,7 @@
29323271 struct pre_voltage_change_data data;
29333272 int ret;
29343273
2935
- data.old_uV = _regulator_get_voltage(rdev);
3274
+ data.old_uV = regulator_get_voltage_rdev(rdev);
29363275 data.min_uV = uV;
29373276 data.max_uV = uV;
29383277 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
....@@ -2947,6 +3286,66 @@
29473286 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE,
29483287 (void *)data.old_uV);
29493288
3289
+ return ret;
3290
+}
3291
+
3292
+static int _regulator_set_voltage_sel_step(struct regulator_dev *rdev,
3293
+ int uV, int new_selector)
3294
+{
3295
+ const struct regulator_ops *ops = rdev->desc->ops;
3296
+ int diff, old_sel, curr_sel, ret;
3297
+
3298
+ /* Stepping is only needed if the regulator is enabled. */
3299
+ if (!_regulator_is_enabled(rdev))
3300
+ goto final_set;
3301
+
3302
+ if (!ops->get_voltage_sel)
3303
+ return -EINVAL;
3304
+
3305
+ old_sel = ops->get_voltage_sel(rdev);
3306
+ if (old_sel < 0)
3307
+ return old_sel;
3308
+
3309
+ diff = new_selector - old_sel;
3310
+ if (diff == 0)
3311
+ return 0; /* No change needed. */
3312
+
3313
+ if (diff > 0) {
3314
+ /* Stepping up. */
3315
+ for (curr_sel = old_sel + rdev->desc->vsel_step;
3316
+ curr_sel < new_selector;
3317
+ curr_sel += rdev->desc->vsel_step) {
3318
+ /*
3319
+ * Call the callback directly instead of using
3320
+ * _regulator_call_set_voltage_sel() as we don't
3321
+ * want to notify anyone yet. Same in the branch
3322
+ * below.
3323
+ */
3324
+ ret = ops->set_voltage_sel(rdev, curr_sel);
3325
+ if (ret)
3326
+ goto try_revert;
3327
+ }
3328
+ } else {
3329
+ /* Stepping down. */
3330
+ for (curr_sel = old_sel - rdev->desc->vsel_step;
3331
+ curr_sel > new_selector;
3332
+ curr_sel -= rdev->desc->vsel_step) {
3333
+ ret = ops->set_voltage_sel(rdev, curr_sel);
3334
+ if (ret)
3335
+ goto try_revert;
3336
+ }
3337
+ }
3338
+
3339
+final_set:
3340
+ /* The final selector will trigger the notifiers. */
3341
+ return _regulator_call_set_voltage_sel(rdev, uV, new_selector);
3342
+
3343
+try_revert:
3344
+ /*
3345
+ * At least try to return to the previous voltage if setting a new
3346
+ * one failed.
3347
+ */
3348
+ (void)ops->set_voltage_sel(rdev, old_sel);
29503349 return ret;
29513350 }
29523351
....@@ -2985,7 +3384,7 @@
29853384 unsigned int selector;
29863385 int old_selector = -1;
29873386 const struct regulator_ops *ops = rdev->desc->ops;
2988
- int old_uV = _regulator_get_voltage(rdev);
3387
+ int old_uV = regulator_get_voltage_rdev(rdev);
29893388
29903389 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
29913390
....@@ -3012,7 +3411,7 @@
30123411 best_val = ops->list_voltage(rdev,
30133412 selector);
30143413 else
3015
- best_val = _regulator_get_voltage(rdev);
3414
+ best_val = regulator_get_voltage_rdev(rdev);
30163415 }
30173416
30183417 } else if (ops->set_voltage_sel) {
....@@ -3023,6 +3422,9 @@
30233422 selector = ret;
30243423 if (old_selector == selector)
30253424 ret = 0;
3425
+ else if (rdev->desc->vsel_step)
3426
+ ret = _regulator_set_voltage_sel_step(
3427
+ rdev, best_val, selector);
30263428 else
30273429 ret = _regulator_call_set_voltage_sel(
30283430 rdev, best_val, selector);
....@@ -3058,7 +3460,7 @@
30583460 }
30593461
30603462 if (delay < 0) {
3061
- rdev_warn(rdev, "failed to get delay: %d\n", delay);
3463
+ rdev_warn(rdev, "failed to get delay: %pe\n", ERR_PTR(delay));
30623464 delay = 0;
30633465 }
30643466
....@@ -3118,8 +3520,6 @@
31183520 int ret = 0;
31193521 int old_min_uV, old_max_uV;
31203522 int current_uV;
3121
- int best_supply_uV = 0;
3122
- int supply_change_uV = 0;
31233523
31243524 /* If we're setting the same range as last time the change
31253525 * should be a noop (some cpufreq implementations use the same
....@@ -3133,7 +3533,7 @@
31333533 * changing the voltage.
31343534 */
31353535 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
3136
- current_uV = _regulator_get_voltage(rdev);
3536
+ current_uV = regulator_get_voltage_rdev(rdev);
31373537 if (min_uV <= current_uV && current_uV <= max_uV) {
31383538 voltage->min_uV = min_uV;
31393539 voltage->max_uV = max_uV;
....@@ -3159,9 +3559,23 @@
31593559 voltage->min_uV = min_uV;
31603560 voltage->max_uV = max_uV;
31613561
3162
- ret = regulator_check_consumers(rdev, &min_uV, &max_uV, state);
3163
- if (ret < 0)
3164
- goto out2;
3562
+ /* for not coupled regulators this will just set the voltage */
3563
+ ret = regulator_balance_voltage(rdev, state);
3564
+ if (ret < 0) {
3565
+ voltage->min_uV = old_min_uV;
3566
+ voltage->max_uV = old_max_uV;
3567
+ }
3568
+
3569
+out:
3570
+ return ret;
3571
+}
3572
+
3573
+int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV,
3574
+ int max_uV, suspend_state_t state)
3575
+{
3576
+ int best_supply_uV = 0;
3577
+ int supply_change_uV = 0;
3578
+ int ret;
31653579
31663580 if (rdev->supply &&
31673581 regulator_ops_is_valid(rdev->supply->rdev,
....@@ -3174,21 +3588,21 @@
31743588 selector = regulator_map_voltage(rdev, min_uV, max_uV);
31753589 if (selector < 0) {
31763590 ret = selector;
3177
- goto out2;
3591
+ goto out;
31783592 }
31793593
31803594 best_supply_uV = _regulator_list_voltage(rdev, selector, 0);
31813595 if (best_supply_uV < 0) {
31823596 ret = best_supply_uV;
3183
- goto out2;
3597
+ goto out;
31843598 }
31853599
31863600 best_supply_uV += rdev->desc->min_dropout_uV;
31873601
3188
- current_supply_uV = _regulator_get_voltage(rdev->supply->rdev);
3602
+ current_supply_uV = regulator_get_voltage_rdev(rdev->supply->rdev);
31893603 if (current_supply_uV < 0) {
31903604 ret = current_supply_uV;
3191
- goto out2;
3605
+ goto out;
31923606 }
31933607
31943608 supply_change_uV = best_supply_uV - current_supply_uV;
....@@ -3198,9 +3612,9 @@
31983612 ret = regulator_set_voltage_unlocked(rdev->supply,
31993613 best_supply_uV, INT_MAX, state);
32003614 if (ret) {
3201
- dev_err(&rdev->dev, "Failed to increase supply voltage: %d\n",
3202
- ret);
3203
- goto out2;
3615
+ dev_err(&rdev->dev, "Failed to increase supply voltage: %pe\n",
3616
+ ERR_PTR(ret));
3617
+ goto out;
32043618 }
32053619 }
32063620
....@@ -3210,25 +3624,303 @@
32103624 ret = _regulator_do_set_suspend_voltage(rdev, min_uV,
32113625 max_uV, state);
32123626 if (ret < 0)
3213
- goto out2;
3627
+ goto out;
32143628
32153629 if (supply_change_uV < 0) {
32163630 ret = regulator_set_voltage_unlocked(rdev->supply,
32173631 best_supply_uV, INT_MAX, state);
32183632 if (ret)
3219
- dev_warn(&rdev->dev, "Failed to decrease supply voltage: %d\n",
3220
- ret);
3633
+ dev_warn(&rdev->dev, "Failed to decrease supply voltage: %pe\n",
3634
+ ERR_PTR(ret));
32213635 /* No need to fail here */
32223636 ret = 0;
32233637 }
32243638
32253639 out:
32263640 return ret;
3227
-out2:
3228
- voltage->min_uV = old_min_uV;
3229
- voltage->max_uV = old_max_uV;
3641
+}
3642
+EXPORT_SYMBOL_GPL(regulator_set_voltage_rdev);
32303643
3644
+static int regulator_limit_voltage_step(struct regulator_dev *rdev,
3645
+ int *current_uV, int *min_uV)
3646
+{
3647
+ struct regulation_constraints *constraints = rdev->constraints;
3648
+
3649
+ /* Limit voltage change only if necessary */
3650
+ if (!constraints->max_uV_step || !_regulator_is_enabled(rdev))
3651
+ return 1;
3652
+
3653
+ if (*current_uV < 0) {
3654
+ *current_uV = regulator_get_voltage_rdev(rdev);
3655
+
3656
+ if (*current_uV < 0)
3657
+ return *current_uV;
3658
+ }
3659
+
3660
+ if (abs(*current_uV - *min_uV) <= constraints->max_uV_step)
3661
+ return 1;
3662
+
3663
+ /* Clamp target voltage within the given step */
3664
+ if (*current_uV < *min_uV)
3665
+ *min_uV = min(*current_uV + constraints->max_uV_step,
3666
+ *min_uV);
3667
+ else
3668
+ *min_uV = max(*current_uV - constraints->max_uV_step,
3669
+ *min_uV);
3670
+
3671
+ return 0;
3672
+}
3673
+
3674
+static int regulator_get_optimal_voltage(struct regulator_dev *rdev,
3675
+ int *current_uV,
3676
+ int *min_uV, int *max_uV,
3677
+ suspend_state_t state,
3678
+ int n_coupled)
3679
+{
3680
+ struct coupling_desc *c_desc = &rdev->coupling_desc;
3681
+ struct regulator_dev **c_rdevs = c_desc->coupled_rdevs;
3682
+ struct regulation_constraints *constraints = rdev->constraints;
3683
+ int desired_min_uV = 0, desired_max_uV = INT_MAX;
3684
+ int max_current_uV = 0, min_current_uV = INT_MAX;
3685
+ int highest_min_uV = 0, target_uV, possible_uV;
3686
+ int i, ret, max_spread;
3687
+ bool done;
3688
+
3689
+ *current_uV = -1;
3690
+
3691
+ /*
3692
+ * If there are no coupled regulators, simply set the voltage
3693
+ * demanded by consumers.
3694
+ */
3695
+ if (n_coupled == 1) {
3696
+ /*
3697
+ * If consumers don't provide any demands, set voltage
3698
+ * to min_uV
3699
+ */
3700
+ desired_min_uV = constraints->min_uV;
3701
+ desired_max_uV = constraints->max_uV;
3702
+
3703
+ ret = regulator_check_consumers(rdev,
3704
+ &desired_min_uV,
3705
+ &desired_max_uV, state);
3706
+ if (ret < 0)
3707
+ return ret;
3708
+
3709
+ possible_uV = desired_min_uV;
3710
+ done = true;
3711
+
3712
+ goto finish;
3713
+ }
3714
+
3715
+ /* Find highest min desired voltage */
3716
+ for (i = 0; i < n_coupled; i++) {
3717
+ int tmp_min = 0;
3718
+ int tmp_max = INT_MAX;
3719
+
3720
+ lockdep_assert_held_once(&c_rdevs[i]->mutex.base);
3721
+
3722
+ ret = regulator_check_consumers(c_rdevs[i],
3723
+ &tmp_min,
3724
+ &tmp_max, state);
3725
+ if (ret < 0)
3726
+ return ret;
3727
+
3728
+ ret = regulator_check_voltage(c_rdevs[i], &tmp_min, &tmp_max);
3729
+ if (ret < 0)
3730
+ return ret;
3731
+
3732
+ highest_min_uV = max(highest_min_uV, tmp_min);
3733
+
3734
+ if (i == 0) {
3735
+ desired_min_uV = tmp_min;
3736
+ desired_max_uV = tmp_max;
3737
+ }
3738
+ }
3739
+
3740
+ max_spread = constraints->max_spread[0];
3741
+
3742
+ /*
3743
+ * Let target_uV be equal to the desired one if possible.
3744
+ * If not, set it to minimum voltage, allowed by other coupled
3745
+ * regulators.
3746
+ */
3747
+ target_uV = max(desired_min_uV, highest_min_uV - max_spread);
3748
+
3749
+ /*
3750
+ * Find min and max voltages, which currently aren't violating
3751
+ * max_spread.
3752
+ */
3753
+ for (i = 1; i < n_coupled; i++) {
3754
+ int tmp_act;
3755
+
3756
+ if (!_regulator_is_enabled(c_rdevs[i]))
3757
+ continue;
3758
+
3759
+ tmp_act = regulator_get_voltage_rdev(c_rdevs[i]);
3760
+ if (tmp_act < 0)
3761
+ return tmp_act;
3762
+
3763
+ min_current_uV = min(tmp_act, min_current_uV);
3764
+ max_current_uV = max(tmp_act, max_current_uV);
3765
+ }
3766
+
3767
+ /* There aren't any other regulators enabled */
3768
+ if (max_current_uV == 0) {
3769
+ possible_uV = target_uV;
3770
+ } else {
3771
+ /*
3772
+ * Correct target voltage, so as it currently isn't
3773
+ * violating max_spread
3774
+ */
3775
+ possible_uV = max(target_uV, max_current_uV - max_spread);
3776
+ possible_uV = min(possible_uV, min_current_uV + max_spread);
3777
+ }
3778
+
3779
+ if (possible_uV > desired_max_uV)
3780
+ return -EINVAL;
3781
+
3782
+ done = (possible_uV == target_uV);
3783
+ desired_min_uV = possible_uV;
3784
+
3785
+finish:
3786
+ /* Apply max_uV_step constraint if necessary */
3787
+ if (state == PM_SUSPEND_ON) {
3788
+ ret = regulator_limit_voltage_step(rdev, current_uV,
3789
+ &desired_min_uV);
3790
+ if (ret < 0)
3791
+ return ret;
3792
+
3793
+ if (ret == 0)
3794
+ done = false;
3795
+ }
3796
+
3797
+ /* Set current_uV if wasn't done earlier in the code and if necessary */
3798
+ if (n_coupled > 1 && *current_uV == -1) {
3799
+
3800
+ if (_regulator_is_enabled(rdev)) {
3801
+ ret = regulator_get_voltage_rdev(rdev);
3802
+ if (ret < 0)
3803
+ return ret;
3804
+
3805
+ *current_uV = ret;
3806
+ } else {
3807
+ *current_uV = desired_min_uV;
3808
+ }
3809
+ }
3810
+
3811
+ *min_uV = desired_min_uV;
3812
+ *max_uV = desired_max_uV;
3813
+
3814
+ return done;
3815
+}
3816
+
3817
+int regulator_do_balance_voltage(struct regulator_dev *rdev,
3818
+ suspend_state_t state, bool skip_coupled)
3819
+{
3820
+ struct regulator_dev **c_rdevs;
3821
+ struct regulator_dev *best_rdev;
3822
+ struct coupling_desc *c_desc = &rdev->coupling_desc;
3823
+ int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev;
3824
+ unsigned int delta, best_delta;
3825
+ unsigned long c_rdev_done = 0;
3826
+ bool best_c_rdev_done;
3827
+
3828
+ c_rdevs = c_desc->coupled_rdevs;
3829
+ n_coupled = skip_coupled ? 1 : c_desc->n_coupled;
3830
+
3831
+ /*
3832
+ * Find the best possible voltage change on each loop. Leave the loop
3833
+ * if there isn't any possible change.
3834
+ */
3835
+ do {
3836
+ best_c_rdev_done = false;
3837
+ best_delta = 0;
3838
+ best_min_uV = 0;
3839
+ best_max_uV = 0;
3840
+ best_c_rdev = 0;
3841
+ best_rdev = NULL;
3842
+
3843
+ /*
3844
+ * Find highest difference between optimal voltage
3845
+ * and current voltage.
3846
+ */
3847
+ for (i = 0; i < n_coupled; i++) {
3848
+ /*
3849
+ * optimal_uV is the best voltage that can be set for
3850
+ * i-th regulator at the moment without violating
3851
+ * max_spread constraint in order to balance
3852
+ * the coupled voltages.
3853
+ */
3854
+ int optimal_uV = 0, optimal_max_uV = 0, current_uV = 0;
3855
+
3856
+ if (test_bit(i, &c_rdev_done))
3857
+ continue;
3858
+
3859
+ ret = regulator_get_optimal_voltage(c_rdevs[i],
3860
+ &current_uV,
3861
+ &optimal_uV,
3862
+ &optimal_max_uV,
3863
+ state, n_coupled);
3864
+ if (ret < 0)
3865
+ goto out;
3866
+
3867
+ delta = abs(optimal_uV - current_uV);
3868
+
3869
+ if (delta && best_delta <= delta) {
3870
+ best_c_rdev_done = ret;
3871
+ best_delta = delta;
3872
+ best_rdev = c_rdevs[i];
3873
+ best_min_uV = optimal_uV;
3874
+ best_max_uV = optimal_max_uV;
3875
+ best_c_rdev = i;
3876
+ }
3877
+ }
3878
+
3879
+ /* Nothing to change, return successfully */
3880
+ if (!best_rdev) {
3881
+ ret = 0;
3882
+ goto out;
3883
+ }
3884
+
3885
+ ret = regulator_set_voltage_rdev(best_rdev, best_min_uV,
3886
+ best_max_uV, state);
3887
+
3888
+ if (ret < 0)
3889
+ goto out;
3890
+
3891
+ if (best_c_rdev_done)
3892
+ set_bit(best_c_rdev, &c_rdev_done);
3893
+
3894
+ } while (n_coupled > 1);
3895
+
3896
+out:
32313897 return ret;
3898
+}
3899
+
3900
+static int regulator_balance_voltage(struct regulator_dev *rdev,
3901
+ suspend_state_t state)
3902
+{
3903
+ struct coupling_desc *c_desc = &rdev->coupling_desc;
3904
+ struct regulator_coupler *coupler = c_desc->coupler;
3905
+ bool skip_coupled = false;
3906
+
3907
+ /*
3908
+ * If system is in a state other than PM_SUSPEND_ON, don't check
3909
+ * other coupled regulators.
3910
+ */
3911
+ if (state != PM_SUSPEND_ON)
3912
+ skip_coupled = true;
3913
+
3914
+ if (c_desc->n_resolved < c_desc->n_coupled) {
3915
+ rdev_err(rdev, "Not all coupled regulators registered\n");
3916
+ return -EPERM;
3917
+ }
3918
+
3919
+ /* Invoke custom balancer for customized couplers */
3920
+ if (coupler && coupler->balance_voltage)
3921
+ return coupler->balance_voltage(coupler, rdev, state);
3922
+
3923
+ return regulator_do_balance_voltage(rdev, state, skip_coupled);
32323924 }
32333925
32343926 /**
....@@ -3251,14 +3943,15 @@
32513943 */
32523944 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
32533945 {
3254
- int ret = 0;
3946
+ struct ww_acquire_ctx ww_ctx;
3947
+ int ret;
32553948
3256
- regulator_lock_supply(regulator->rdev);
3949
+ regulator_lock_dependent(regulator->rdev, &ww_ctx);
32573950
32583951 ret = regulator_set_voltage_unlocked(regulator, min_uV, max_uV,
32593952 PM_SUSPEND_ON);
32603953
3261
- regulator_unlock_supply(regulator->rdev);
3954
+ regulator_unlock_dependent(regulator->rdev, &ww_ctx);
32623955
32633956 return ret;
32643957 }
....@@ -3330,18 +4023,19 @@
33304023 int regulator_set_suspend_voltage(struct regulator *regulator, int min_uV,
33314024 int max_uV, suspend_state_t state)
33324025 {
3333
- int ret = 0;
4026
+ struct ww_acquire_ctx ww_ctx;
4027
+ int ret;
33344028
33354029 /* PM_SUSPEND_ON is handled by regulator_set_voltage() */
33364030 if (regulator_check_states(state) || state == PM_SUSPEND_ON)
33374031 return -EINVAL;
33384032
3339
- regulator_lock_supply(regulator->rdev);
4033
+ regulator_lock_dependent(regulator->rdev, &ww_ctx);
33404034
33414035 ret = _regulator_set_suspend_voltage(regulator, min_uV,
33424036 max_uV, state);
33434037
3344
- regulator_unlock_supply(regulator->rdev);
4038
+ regulator_unlock_dependent(regulator->rdev, &ww_ctx);
33454039
33464040 return ret;
33474041 }
....@@ -3477,7 +4171,7 @@
34774171 }
34784172 EXPORT_SYMBOL_GPL(regulator_sync_voltage);
34794173
3480
-static int _regulator_get_voltage(struct regulator_dev *rdev)
4174
+int regulator_get_voltage_rdev(struct regulator_dev *rdev)
34814175 {
34824176 int sel, ret;
34834177 bool bypassed;
....@@ -3494,7 +4188,7 @@
34944188 return -EPROBE_DEFER;
34954189 }
34964190
3497
- return _regulator_get_voltage(rdev->supply->rdev);
4191
+ return regulator_get_voltage_rdev(rdev->supply->rdev);
34984192 }
34994193 }
35004194
....@@ -3510,7 +4204,7 @@
35104204 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) {
35114205 ret = rdev->desc->fixed_uV;
35124206 } else if (rdev->supply) {
3513
- ret = _regulator_get_voltage(rdev->supply->rdev);
4207
+ ret = regulator_get_voltage_rdev(rdev->supply->rdev);
35144208 } else if (rdev->supply_name) {
35154209 return -EPROBE_DEFER;
35164210 } else {
....@@ -3521,6 +4215,7 @@
35214215 return ret;
35224216 return ret - rdev->constraints->uV_offset;
35234217 }
4218
+EXPORT_SYMBOL_GPL(regulator_get_voltage_rdev);
35244219
35254220 /**
35264221 * regulator_get_voltage - get regulator output voltage
....@@ -3533,13 +4228,12 @@
35334228 */
35344229 int regulator_get_voltage(struct regulator *regulator)
35354230 {
4231
+ struct ww_acquire_ctx ww_ctx;
35364232 int ret;
35374233
3538
- regulator_lock_supply(regulator->rdev);
3539
-
3540
- ret = _regulator_get_voltage(regulator->rdev);
3541
-
3542
- regulator_unlock_supply(regulator->rdev);
4234
+ regulator_lock_dependent(regulator->rdev, &ww_ctx);
4235
+ ret = regulator_get_voltage_rdev(regulator->rdev);
4236
+ regulator_unlock_dependent(regulator->rdev, &ww_ctx);
35434237
35444238 return ret;
35454239 }
....@@ -3587,21 +4281,23 @@
35874281 }
35884282 EXPORT_SYMBOL_GPL(regulator_set_current_limit);
35894283
4284
+static int _regulator_get_current_limit_unlocked(struct regulator_dev *rdev)
4285
+{
4286
+ /* sanity check */
4287
+ if (!rdev->desc->ops->get_current_limit)
4288
+ return -EINVAL;
4289
+
4290
+ return rdev->desc->ops->get_current_limit(rdev);
4291
+}
4292
+
35904293 static int _regulator_get_current_limit(struct regulator_dev *rdev)
35914294 {
35924295 int ret;
35934296
35944297 regulator_lock(rdev);
3595
-
3596
- /* sanity check */
3597
- if (!rdev->desc->ops->get_current_limit) {
3598
- ret = -EINVAL;
3599
- goto out;
3600
- }
3601
-
3602
- ret = rdev->desc->ops->get_current_limit(rdev);
3603
-out:
4298
+ ret = _regulator_get_current_limit_unlocked(rdev);
36044299 regulator_unlock(rdev);
4300
+
36054301 return ret;
36064302 }
36074303
....@@ -3666,21 +4362,23 @@
36664362 }
36674363 EXPORT_SYMBOL_GPL(regulator_set_mode);
36684364
4365
+static unsigned int _regulator_get_mode_unlocked(struct regulator_dev *rdev)
4366
+{
4367
+ /* sanity check */
4368
+ if (!rdev->desc->ops->get_mode)
4369
+ return -EINVAL;
4370
+
4371
+ return rdev->desc->ops->get_mode(rdev);
4372
+}
4373
+
36694374 static unsigned int _regulator_get_mode(struct regulator_dev *rdev)
36704375 {
36714376 int ret;
36724377
36734378 regulator_lock(rdev);
3674
-
3675
- /* sanity check */
3676
- if (!rdev->desc->ops->get_mode) {
3677
- ret = -EINVAL;
3678
- goto out;
3679
- }
3680
-
3681
- ret = rdev->desc->ops->get_mode(rdev);
3682
-out:
4379
+ ret = _regulator_get_mode_unlocked(rdev);
36834380 regulator_unlock(rdev);
4381
+
36844382 return ret;
36854383 }
36864384
....@@ -3753,16 +4451,30 @@
37534451 * DRMS will sum the total requested load on the regulator and change
37544452 * to the most efficient operating mode if platform constraints allow.
37554453 *
4454
+ * NOTE: when a regulator consumer requests to have a regulator
4455
+ * disabled then any load that consumer requested no longer counts
4456
+ * toward the total requested load. If the regulator is re-enabled
4457
+ * then the previously requested load will start counting again.
4458
+ *
4459
+ * If a regulator is an always-on regulator then an individual consumer's
4460
+ * load will still be removed if that consumer is fully disabled.
4461
+ *
37564462 * On error a negative errno is returned.
37574463 */
37584464 int regulator_set_load(struct regulator *regulator, int uA_load)
37594465 {
37604466 struct regulator_dev *rdev = regulator->rdev;
3761
- int ret;
4467
+ int old_uA_load;
4468
+ int ret = 0;
37624469
37634470 regulator_lock(rdev);
4471
+ old_uA_load = regulator->uA_load;
37644472 regulator->uA_load = uA_load;
3765
- ret = drms_uA_update(rdev);
4473
+ if (regulator->enable_count && old_uA_load != uA_load) {
4474
+ ret = drms_uA_update(rdev);
4475
+ if (ret < 0)
4476
+ regulator->uA_load = old_uA_load;
4477
+ }
37664478 regulator_unlock(rdev);
37674479
37684480 return ret;
....@@ -3783,6 +4495,7 @@
37834495 int regulator_allow_bypass(struct regulator *regulator, bool enable)
37844496 {
37854497 struct regulator_dev *rdev = regulator->rdev;
4498
+ const char *name = rdev_get_name(rdev);
37864499 int ret = 0;
37874500
37884501 if (!rdev->desc->ops->set_bypass)
....@@ -3797,18 +4510,26 @@
37974510 rdev->bypass_count++;
37984511
37994512 if (rdev->bypass_count == rdev->open_count) {
4513
+ trace_regulator_bypass_enable(name);
4514
+
38004515 ret = rdev->desc->ops->set_bypass(rdev, enable);
38014516 if (ret != 0)
38024517 rdev->bypass_count--;
4518
+ else
4519
+ trace_regulator_bypass_enable_complete(name);
38034520 }
38044521
38054522 } else if (!enable && regulator->bypass) {
38064523 rdev->bypass_count--;
38074524
38084525 if (rdev->bypass_count != rdev->open_count) {
4526
+ trace_regulator_bypass_disable(name);
4527
+
38094528 ret = rdev->desc->ops->set_bypass(rdev, enable);
38104529 if (ret != 0)
38114530 rdev->bypass_count++;
4531
+ else
4532
+ trace_regulator_bypass_disable_complete(name);
38124533 }
38134534 }
38144535
....@@ -3889,8 +4610,6 @@
38894610 consumers[i].supply);
38904611 if (IS_ERR(consumers[i].consumer)) {
38914612 ret = PTR_ERR(consumers[i].consumer);
3892
- dev_err(dev, "Failed to get supply '%s': %d\n",
3893
- consumers[i].supply, ret);
38944613 consumers[i].consumer = NULL;
38954614 goto err;
38964615 }
....@@ -3899,6 +4618,13 @@
38994618 return 0;
39004619
39014620 err:
4621
+ if (ret != -EPROBE_DEFER)
4622
+ dev_err(dev, "Failed to get supply '%s': %pe\n",
4623
+ consumers[i].supply, ERR_PTR(ret));
4624
+ else
4625
+ dev_dbg(dev, "Failed to get supply '%s', deferring\n",
4626
+ consumers[i].supply);
4627
+
39024628 while (--i >= 0)
39034629 regulator_put(consumers[i].consumer);
39044630
....@@ -3933,11 +4659,8 @@
39334659 int ret = 0;
39344660
39354661 for (i = 0; i < num_consumers; i++) {
3936
- if (consumers[i].consumer->always_on)
3937
- consumers[i].ret = 0;
3938
- else
3939
- async_schedule_domain(regulator_bulk_enable_async,
3940
- &consumers[i], &async_domain);
4662
+ async_schedule_domain(regulator_bulk_enable_async,
4663
+ &consumers[i], &async_domain);
39414664 }
39424665
39434666 async_synchronize_full_domain(&async_domain);
....@@ -3955,8 +4678,8 @@
39554678 err:
39564679 for (i = 0; i < num_consumers; i++) {
39574680 if (consumers[i].ret < 0)
3958
- pr_err("Failed to enable %s: %d\n", consumers[i].supply,
3959
- consumers[i].ret);
4681
+ pr_err("Failed to enable %s: %pe\n", consumers[i].supply,
4682
+ ERR_PTR(consumers[i].ret));
39604683 else
39614684 regulator_disable(consumers[i].consumer);
39624685 }
....@@ -3992,12 +4715,12 @@
39924715 return 0;
39934716
39944717 err:
3995
- pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret);
4718
+ pr_err("Failed to disable %s: %pe\n", consumers[i].supply, ERR_PTR(ret));
39964719 for (++i; i < num_consumers; ++i) {
39974720 r = regulator_enable(consumers[i].consumer);
39984721 if (r != 0)
3999
- pr_err("Failed to re-enable %s: %d\n",
4000
- consumers[i].supply, r);
4722
+ pr_err("Failed to re-enable %s: %pe\n",
4723
+ consumers[i].supply, ERR_PTR(r));
40014724 }
40024725
40034726 return ret;
....@@ -4065,14 +4788,11 @@
40654788 * @data: callback-specific data.
40664789 *
40674790 * Called by regulator drivers to notify clients a regulator event has
4068
- * occurred. We also notify regulator clients downstream.
4069
- * Note lock must be held by caller.
4791
+ * occurred.
40704792 */
40714793 int regulator_notifier_call_chain(struct regulator_dev *rdev,
40724794 unsigned long event, void *data)
40734795 {
4074
- lockdep_assert_held_once(&rdev->mutex);
4075
-
40764796 _notifier_call_chain(rdev, event, data);
40774797 return NOTIFY_DONE;
40784798
....@@ -4173,10 +4893,6 @@
41734893 if (attr == &dev_attr_bypass.attr)
41744894 return ops->get_bypass ? mode : 0;
41754895
4176
- /* some attributes are type-specific */
4177
- if (attr == &dev_attr_requested_microamps.attr)
4178
- return rdev->desc->type == REGULATOR_CURRENT ? mode : 0;
4179
-
41804896 /* constraints need specific supporting methods */
41814897 if (attr == &dev_attr_min_microvolts.attr ||
41824898 attr == &dev_attr_max_microvolts.attr)
....@@ -4214,16 +4930,31 @@
42144930 NULL
42154931 };
42164932
4933
+#ifdef CONFIG_DEBUG_FS
4934
+static void rdev_deinit_debugfs(struct regulator_dev *rdev);
4935
+#else
4936
+static inline void rdev_deinit_debugfs(struct regulator_dev *rdev)
4937
+{
4938
+}
4939
+#endif
4940
+
42174941 static void regulator_dev_release(struct device *dev)
42184942 {
42194943 struct regulator_dev *rdev = dev_get_drvdata(dev);
42204944
4945
+ rdev_deinit_debugfs(rdev);
42214946 kfree(rdev->constraints);
42224947 of_node_put(rdev->dev.of_node);
42234948 kfree(rdev);
42244949 }
42254950
42264951 #ifdef CONFIG_DEBUG_FS
4952
+
4953
+#define MAX_DEBUG_BUF_LEN 50
4954
+#define REGULATOR_ALLOW_WRITE_DEBUGFS
4955
+
4956
+#ifdef REGULATOR_ALLOW_WRITE_DEBUGFS
4957
+
42274958 static int reg_debug_enable_set(void *data, u64 val)
42284959 {
42294960 struct regulator *regulator = data;
....@@ -4244,17 +4975,6 @@
42444975 return ret;
42454976 }
42464977
4247
-static int reg_debug_enable_get(void *data, u64 *val)
4248
-{
4249
- struct regulator *regulator = data;
4250
-
4251
- *val = regulator_is_enabled(regulator);
4252
-
4253
- return 0;
4254
-}
4255
-DEFINE_DEBUGFS_ATTRIBUTE(reg_enable_fops, reg_debug_enable_get,
4256
- reg_debug_enable_set, "%llu\n");
4257
-
42584978 static int reg_debug_force_disable_set(void *data, u64 val)
42594979 {
42604980 struct regulator *regulator = data;
....@@ -4269,10 +4989,7 @@
42694989
42704990 return ret;
42714991 }
4272
-DEFINE_DEBUGFS_ATTRIBUTE(reg_force_disable_fops, reg_debug_enable_get,
4273
- reg_debug_force_disable_set, "%llu\n");
42744992
4275
-#define MAX_DEBUG_BUF_LEN 50
42764993
42774994 static ssize_t reg_debug_voltage_write(struct file *file,
42784995 const char __user *ubuf,
....@@ -4325,6 +5042,57 @@
43255042 return count;
43265043 }
43275044
5045
+static int reg_debug_mode_set(void *data, u64 val)
5046
+{
5047
+ struct regulator *regulator = data;
5048
+ unsigned int mode = val;
5049
+ int ret;
5050
+
5051
+ ret = regulator_set_mode(regulator, mode);
5052
+ if (ret)
5053
+ rdev_err(regulator->rdev, "set mode=%u failed, ret=%d\n",
5054
+ mode, ret);
5055
+
5056
+ return ret;
5057
+}
5058
+
5059
+static int reg_debug_set_load(void *data, u64 val)
5060
+{
5061
+ struct regulator *regulator = data;
5062
+ int load = val;
5063
+ int ret;
5064
+
5065
+ ret = regulator_set_load(regulator, load);
5066
+ if (ret)
5067
+ rdev_err(regulator->rdev, "set load=%d failed, ret=%d\n",
5068
+ load, ret);
5069
+
5070
+ return ret;
5071
+}
5072
+
5073
+#else
5074
+#define reg_debug_enable_set NULL
5075
+#define reg_debug_force_disable_set NULL
5076
+#define reg_debug_voltage_write NULL
5077
+#define reg_debug_mode_set NULL
5078
+#define reg_debug_set_load NULL
5079
+#endif
5080
+
5081
+static int reg_debug_enable_get(void *data, u64 *val)
5082
+{
5083
+ struct regulator *regulator = data;
5084
+
5085
+ *val = regulator_is_enabled(regulator);
5086
+
5087
+ return 0;
5088
+}
5089
+DEFINE_DEBUGFS_ATTRIBUTE(reg_enable_fops, reg_debug_enable_get,
5090
+ reg_debug_enable_set, "%llu\n");
5091
+
5092
+
5093
+DEFINE_DEBUGFS_ATTRIBUTE(reg_force_disable_fops, reg_debug_enable_get,
5094
+ reg_debug_force_disable_set, "%llu\n");
5095
+
43285096 static ssize_t reg_debug_voltage_read(struct file *file, char __user *ubuf,
43295097 size_t count, loff_t *ppos)
43305098 {
....@@ -4352,20 +5120,6 @@
43525120 .read = reg_debug_voltage_read,
43535121 };
43545122
4355
-static int reg_debug_mode_set(void *data, u64 val)
4356
-{
4357
- struct regulator *regulator = data;
4358
- unsigned int mode = val;
4359
- int ret;
4360
-
4361
- ret = regulator_set_mode(regulator, mode);
4362
- if (ret)
4363
- rdev_err(regulator->rdev, "set mode=%u failed, ret=%d\n",
4364
- mode, ret);
4365
-
4366
- return ret;
4367
-}
4368
-
43695123 static int reg_debug_mode_get(void *data, u64 *val)
43705124 {
43715125 struct regulator *regulator = data;
....@@ -4384,19 +5138,6 @@
43845138 DEFINE_DEBUGFS_ATTRIBUTE(reg_mode_fops, reg_debug_mode_get, reg_debug_mode_set,
43855139 "%llu\n");
43865140
4387
-static int reg_debug_set_load(void *data, u64 val)
4388
-{
4389
- struct regulator *regulator = data;
4390
- int load = val;
4391
- int ret;
4392
-
4393
- ret = regulator_set_load(regulator, load);
4394
- if (ret)
4395
- rdev_err(regulator->rdev, "set load=%d failed, ret=%d\n",
4396
- load, ret);
4397
-
4398
- return ret;
4399
-}
44005141 DEFINE_DEBUGFS_ATTRIBUTE(reg_set_load_fops, reg_debug_mode_get,
44015142 reg_debug_set_load, "%llu\n");
44025143
....@@ -4444,9 +5185,6 @@
44445185 static void rdev_deinit_debugfs(struct regulator_dev *rdev)
44455186 {
44465187 struct regulator_limit_volt *reg_debug, *n;
4447
-
4448
- if (IS_ERR_OR_NULL(rdev))
4449
- return;
44505188
44515189 debugfs_remove_recursive(rdev->debugfs);
44525190
....@@ -4509,14 +5247,20 @@
45095247
45105248 ops = rdev->desc->ops;
45115249
4512
- debugfs_create_file("enable", 0644, rdev->debugfs, regulator,
5250
+ mode = 0444;
5251
+#ifdef REGULATOR_ALLOW_WRITE_DEBUGFS
5252
+ mode |= 0200;
5253
+#endif
5254
+ debugfs_create_file("enable", mode, rdev->debugfs, regulator,
45135255 &reg_enable_fops);
45145256
45155257 mode = 0;
45165258 if (ops->is_enabled)
45175259 mode |= 0444;
5260
+#ifdef REGULATOR_ALLOW_WRITE_DEBUGFS
45185261 if (ops->disable)
45195262 mode |= 0200;
5263
+#endif
45205264 if (mode)
45215265 debugfs_create_file("force_disable", mode, rdev->debugfs,
45225266 regulator, &reg_force_disable_fops);
....@@ -4524,8 +5268,10 @@
45245268 mode = 0;
45255269 if (ops->get_voltage || ops->get_voltage_sel)
45265270 mode |= 0444;
5271
+#ifdef REGULATOR_ALLOW_WRITE_DEBUGFS
45275272 if (ops->set_voltage || ops->set_voltage_sel)
45285273 mode |= 0200;
5274
+#endif
45295275 if (mode)
45305276 debugfs_create_file("voltage", mode, rdev->debugfs, regulator,
45315277 &reg_voltage_fops);
....@@ -4533,8 +5279,10 @@
45335279 mode = 0;
45345280 if (ops->get_mode)
45355281 mode |= 0444;
5282
+#ifdef REGULATOR_ALLOW_WRITE_DEBUGFS
45365283 if (ops->set_mode)
45375284 mode |= 0200;
5285
+#endif
45385286 if (mode)
45395287 debugfs_create_file("mode", mode, rdev->debugfs, regulator,
45405288 &reg_mode_fops);
....@@ -4542,53 +5290,20 @@
45425290 mode = 0;
45435291 if (ops->get_mode)
45445292 mode |= 0444;
5293
+#ifdef REGULATOR_ALLOW_WRITE_DEBUGFS
45455294 if (ops->set_load || (ops->get_optimum_mode && ops->set_mode))
45465295 mode |= 0200;
5296
+#endif
45475297 if (mode)
45485298 debugfs_create_file("load", mode, rdev->debugfs, regulator,
45495299 &reg_set_load_fops);
45505300 }
45515301
45525302 #else
4553
-static inline void rdev_deinit_debugfs(struct regulator_dev *rdev)
4554
-{
4555
-}
4556
-
45575303 static inline void rdev_init_debugfs(struct regulator_dev *rdev)
45585304 {
45595305 }
45605306 #endif
4561
-
4562
-static void rdev_init_early_min_volt(struct regulator_dev *rdev)
4563
-{
4564
- struct device_node *np = rdev->dev.of_node;
4565
- struct regulator_limit_volt *reg_early;
4566
- u32 pval;
4567
-
4568
- /*
4569
- * Minimum voltage during system startup, make sure we select a
4570
- * voltage that suits the needs of all regulator consumers
4571
- */
4572
- if (of_property_read_u32(np, "regulator-early-min-microvolt", &pval))
4573
- return;
4574
-
4575
- reg_early = kzalloc(sizeof(*reg_early), GFP_KERNEL);
4576
- if (reg_early == NULL)
4577
- return;
4578
-
4579
- reg_early->reg = regulator_get(NULL, rdev_get_name(rdev));
4580
- if (IS_ERR(reg_early->reg)) {
4581
- rdev_err(rdev, "regulator get failed, ret=%ld\n",
4582
- PTR_ERR(reg_early->reg));
4583
- return;
4584
- }
4585
-
4586
- reg_early->reg->voltage[PM_SUSPEND_ON].min_uV = pval;
4587
- reg_early->reg->voltage[PM_SUSPEND_ON].max_uV =
4588
- rdev->constraints->max_uV;
4589
-
4590
- list_add(&reg_early->list, &regulator_early_min_volt_list);
4591
-}
45925307
45935308 static int regulator_register_resolve_supply(struct device *dev, void *data)
45945309 {
....@@ -4600,8 +5315,60 @@
46005315 return 0;
46015316 }
46025317
4603
-static int regulator_fill_coupling_array(struct regulator_dev *rdev)
5318
+int regulator_coupler_register(struct regulator_coupler *coupler)
46045319 {
5320
+ mutex_lock(&regulator_list_mutex);
5321
+ list_add_tail(&coupler->list, &regulator_coupler_list);
5322
+ mutex_unlock(&regulator_list_mutex);
5323
+
5324
+ return 0;
5325
+}
5326
+
5327
+static struct regulator_coupler *
5328
+regulator_find_coupler(struct regulator_dev *rdev)
5329
+{
5330
+ struct regulator_coupler *coupler;
5331
+ int err;
5332
+
5333
+ /*
5334
+ * Note that regulators are appended to the list and the generic
5335
+ * coupler is registered first, hence it will be attached at last
5336
+ * if nobody cared.
5337
+ */
5338
+ list_for_each_entry_reverse(coupler, &regulator_coupler_list, list) {
5339
+ err = coupler->attach_regulator(coupler, rdev);
5340
+ if (!err) {
5341
+ if (!coupler->balance_voltage &&
5342
+ rdev->coupling_desc.n_coupled > 2)
5343
+ goto err_unsupported;
5344
+
5345
+ return coupler;
5346
+ }
5347
+
5348
+ if (err < 0)
5349
+ return ERR_PTR(err);
5350
+
5351
+ if (err == 1)
5352
+ continue;
5353
+
5354
+ break;
5355
+ }
5356
+
5357
+ return ERR_PTR(-EINVAL);
5358
+
5359
+err_unsupported:
5360
+ if (coupler->detach_regulator)
5361
+ coupler->detach_regulator(coupler, rdev);
5362
+
5363
+ rdev_err(rdev,
5364
+ "Voltage balancing for multiple regulator couples is unimplemented\n");
5365
+
5366
+ return ERR_PTR(-EPERM);
5367
+}
5368
+
5369
+static void regulator_resolve_coupling(struct regulator_dev *rdev)
5370
+{
5371
+ struct regulator_coupler *coupler = rdev->coupling_desc.coupler;
46055372 struct coupling_desc *c_desc = &rdev->coupling_desc;
46065373 int n_coupled = c_desc->n_coupled;
46075374 struct regulator_dev *c_rdev;
....@@ -4614,45 +5381,86 @@
46145381
46155382 c_rdev = of_parse_coupled_regulator(rdev, i - 1);
46165383
4617
- if (c_rdev) {
4618
- c_desc->coupled_rdevs[i] = c_rdev;
4619
- c_desc->n_resolved++;
5384
+ if (!c_rdev)
5385
+ continue;
5386
+
5387
+ if (c_rdev->coupling_desc.coupler != coupler) {
5388
+ rdev_err(rdev, "coupler mismatch with %s\n",
5389
+ rdev_get_name(c_rdev));
5390
+ return;
46205391 }
5392
+
5393
+ c_desc->coupled_rdevs[i] = c_rdev;
5394
+ c_desc->n_resolved++;
5395
+
5396
+ regulator_resolve_coupling(c_rdev);
5397
+ }
5398
+}
5399
+
5400
+static void regulator_remove_coupling(struct regulator_dev *rdev)
5401
+{
5402
+ struct regulator_coupler *coupler = rdev->coupling_desc.coupler;
5403
+ struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc;
5404
+ struct regulator_dev *__c_rdev, *c_rdev;
5405
+ unsigned int __n_coupled, n_coupled;
5406
+ int i, k;
5407
+ int err;
5408
+
5409
+ n_coupled = c_desc->n_coupled;
5410
+
5411
+ for (i = 1; i < n_coupled; i++) {
5412
+ c_rdev = c_desc->coupled_rdevs[i];
5413
+
5414
+ if (!c_rdev)
5415
+ continue;
5416
+
5417
+ regulator_lock(c_rdev);
5418
+
5419
+ __c_desc = &c_rdev->coupling_desc;
5420
+ __n_coupled = __c_desc->n_coupled;
5421
+
5422
+ for (k = 1; k < __n_coupled; k++) {
5423
+ __c_rdev = __c_desc->coupled_rdevs[k];
5424
+
5425
+ if (__c_rdev == rdev) {
5426
+ __c_desc->coupled_rdevs[k] = NULL;
5427
+ __c_desc->n_resolved--;
5428
+ break;
5429
+ }
5430
+ }
5431
+
5432
+ regulator_unlock(c_rdev);
5433
+
5434
+ c_desc->coupled_rdevs[i] = NULL;
5435
+ c_desc->n_resolved--;
46215436 }
46225437
4623
- if (rdev->coupling_desc.n_resolved < n_coupled)
4624
- return -1;
4625
- else
4626
- return 0;
5438
+ if (coupler && coupler->detach_regulator) {
5439
+ err = coupler->detach_regulator(coupler, rdev);
5440
+ if (err)
5441
+ rdev_err(rdev, "failed to detach from coupler: %pe\n",
5442
+ ERR_PTR(err));
5443
+ }
5444
+
5445
+ kfree(rdev->coupling_desc.coupled_rdevs);
5446
+ rdev->coupling_desc.coupled_rdevs = NULL;
46275447 }
46285448
4629
-static int regulator_register_fill_coupling_array(struct device *dev,
4630
- void *data)
5449
+static int regulator_init_coupling(struct regulator_dev *rdev)
46315450 {
4632
- struct regulator_dev *rdev = dev_to_rdev(dev);
4633
-
4634
- if (!IS_ENABLED(CONFIG_OF))
4635
- return 0;
4636
-
4637
- if (regulator_fill_coupling_array(rdev))
4638
- rdev_dbg(rdev, "unable to resolve coupling\n");
4639
-
4640
- return 0;
4641
-}
4642
-
4643
-static int regulator_resolve_coupling(struct regulator_dev *rdev)
4644
-{
4645
- int n_phandles;
5451
+ struct regulator_dev **coupled;
5452
+ int err, n_phandles;
46465453
46475454 if (!IS_ENABLED(CONFIG_OF))
46485455 n_phandles = 0;
46495456 else
46505457 n_phandles = of_get_n_coupled(rdev);
46515458
4652
- if (n_phandles + 1 > MAX_COUPLED) {
4653
- rdev_err(rdev, "too many regulators coupled\n");
4654
- return -EPERM;
4655
- }
5459
+ coupled = kcalloc(n_phandles + 1, sizeof(*coupled), GFP_KERNEL);
5460
+ if (!coupled)
5461
+ return -ENOMEM;
5462
+
5463
+ rdev->coupling_desc.coupled_rdevs = coupled;
46565464
46575465 /*
46585466 * Every regulator should always have coupling descriptor filled with
....@@ -4666,29 +5474,43 @@
46665474 if (n_phandles == 0)
46675475 return 0;
46685476
4669
- /* regulator, which can't change its voltage, can't be coupled */
4670
- if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
4671
- rdev_err(rdev, "voltage operation not allowed\n");
4672
- return -EPERM;
4673
- }
4674
-
4675
- if (rdev->constraints->max_spread <= 0) {
4676
- rdev_err(rdev, "wrong max_spread value\n");
4677
- return -EPERM;
4678
- }
4679
-
46805477 if (!of_check_coupling_data(rdev))
46815478 return -EPERM;
46825479
4683
- /*
4684
- * After everything has been checked, try to fill rdevs array
4685
- * with pointers to regulators parsed from device tree. If some
4686
- * regulators are not registered yet, retry in late init call
4687
- */
4688
- regulator_fill_coupling_array(rdev);
5480
+ mutex_lock(&regulator_list_mutex);
5481
+ rdev->coupling_desc.coupler = regulator_find_coupler(rdev);
5482
+ mutex_unlock(&regulator_list_mutex);
5483
+
5484
+ if (IS_ERR(rdev->coupling_desc.coupler)) {
5485
+ err = PTR_ERR(rdev->coupling_desc.coupler);
5486
+ rdev_err(rdev, "failed to get coupler: %pe\n", ERR_PTR(err));
5487
+ return err;
5488
+ }
46895489
46905490 return 0;
46915491 }
5492
+
5493
+static int generic_coupler_attach(struct regulator_coupler *coupler,
5494
+ struct regulator_dev *rdev)
5495
+{
5496
+ if (rdev->coupling_desc.n_coupled > 2) {
5497
+ rdev_err(rdev,
5498
+ "Voltage balancing for multiple regulator couples is unimplemented\n");
5499
+ return -EPERM;
5500
+ }
5501
+
5502
+ if (!rdev->constraints->always_on) {
5503
+ rdev_err(rdev,
5504
+ "Coupling of a non always-on regulator is unimplemented\n");
5505
+ return -ENOTSUPP;
5506
+ }
5507
+
5508
+ return 0;
5509
+}
5510
+
5511
+static struct regulator_coupler generic_regulator_coupler = {
5512
+ .attach_regulator = generic_coupler_attach,
5513
+};
46925514
46935515 /**
46945516 * regulator_register - register regulator
....@@ -4707,21 +5529,33 @@
47075529 struct regulator_config *config = NULL;
47085530 static atomic_t regulator_no = ATOMIC_INIT(-1);
47095531 struct regulator_dev *rdev;
5532
+ bool dangling_cfg_gpiod = false;
5533
+ bool dangling_of_gpiod = false;
47105534 struct device *dev;
47115535 int ret, i;
47125536
4713
- if (regulator_desc == NULL || cfg == NULL)
5537
+ if (cfg == NULL)
47145538 return ERR_PTR(-EINVAL);
5539
+ if (cfg->ena_gpiod)
5540
+ dangling_cfg_gpiod = true;
5541
+ if (regulator_desc == NULL) {
5542
+ ret = -EINVAL;
5543
+ goto rinse;
5544
+ }
47155545
47165546 dev = cfg->dev;
47175547 WARN_ON(!dev);
47185548
4719
- if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
4720
- return ERR_PTR(-EINVAL);
5549
+ if (regulator_desc->name == NULL || regulator_desc->ops == NULL) {
5550
+ ret = -EINVAL;
5551
+ goto rinse;
5552
+ }
47215553
47225554 if (regulator_desc->type != REGULATOR_VOLTAGE &&
4723
- regulator_desc->type != REGULATOR_CURRENT)
4724
- return ERR_PTR(-EINVAL);
5555
+ regulator_desc->type != REGULATOR_CURRENT) {
5556
+ ret = -EINVAL;
5557
+ goto rinse;
5558
+ }
47255559
47265560 /* Only one of each should be implemented */
47275561 WARN_ON(regulator_desc->ops->get_voltage &&
....@@ -4732,16 +5566,21 @@
47325566 /* If we're using selectors we must implement list_voltage. */
47335567 if (regulator_desc->ops->get_voltage_sel &&
47345568 !regulator_desc->ops->list_voltage) {
4735
- return ERR_PTR(-EINVAL);
5569
+ ret = -EINVAL;
5570
+ goto rinse;
47365571 }
47375572 if (regulator_desc->ops->set_voltage_sel &&
47385573 !regulator_desc->ops->list_voltage) {
4739
- return ERR_PTR(-EINVAL);
5574
+ ret = -EINVAL;
5575
+ goto rinse;
47405576 }
47415577
47425578 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
4743
- if (rdev == NULL)
4744
- return ERR_PTR(-ENOMEM);
5579
+ if (rdev == NULL) {
5580
+ ret = -ENOMEM;
5581
+ goto rinse;
5582
+ }
5583
+ device_initialize(&rdev->dev);
47455584
47465585 /*
47475586 * Duplicate the config so the driver could override it after
....@@ -4749,18 +5588,39 @@
47495588 */
47505589 config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL);
47515590 if (config == NULL) {
4752
- kfree(rdev);
4753
- return ERR_PTR(-ENOMEM);
5591
+ ret = -ENOMEM;
5592
+ goto clean;
47545593 }
47555594
47565595 init_data = regulator_of_get_init_data(dev, regulator_desc, config,
47575596 &rdev->dev.of_node);
5597
+
5598
+ /*
5599
+ * Sometimes not all resources are probed already so we need to take
5600
+ * that into account. This happens most the time if the ena_gpiod comes
5601
+ * from a gpio extender or something else.
5602
+ */
5603
+ if (PTR_ERR(init_data) == -EPROBE_DEFER) {
5604
+ ret = -EPROBE_DEFER;
5605
+ goto clean;
5606
+ }
5607
+
5608
+ /*
5609
+ * We need to keep track of any GPIO descriptor coming from the
5610
+ * device tree until we have handled it over to the core. If the
5611
+ * config that was passed in to this function DOES NOT contain
5612
+ * a descriptor, and the config after this call DOES contain
5613
+ * a descriptor, we definitely got one from parsing the device
5614
+ * tree.
5615
+ */
5616
+ if (!cfg->ena_gpiod && config->ena_gpiod)
5617
+ dangling_of_gpiod = true;
47585618 if (!init_data) {
47595619 init_data = config->init_data;
47605620 rdev->dev.of_node = of_node_get(config->of_node);
47615621 }
47625622
4763
- mutex_init(&rdev->mutex);
5623
+ ww_mutex_init(&rdev->mutex, &regulator_ww_class);
47645624 rdev->reg_data = config->driver_data;
47655625 rdev->owner = regulator_desc->owner;
47665626 rdev->desc = regulator_desc;
....@@ -4782,17 +5642,16 @@
47825642 goto clean;
47835643 }
47845644
4785
- if (config->ena_gpiod ||
4786
- ((config->ena_gpio || config->ena_gpio_initialized) &&
4787
- gpio_is_valid(config->ena_gpio))) {
4788
- mutex_lock(&regulator_list_mutex);
5645
+ if (config->ena_gpiod) {
47895646 ret = regulator_ena_gpio_request(rdev, config);
4790
- mutex_unlock(&regulator_list_mutex);
47915647 if (ret != 0) {
4792
- rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
4793
- config->ena_gpio, ret);
5648
+ rdev_err(rdev, "Failed to request enable GPIO: %pe\n",
5649
+ ERR_PTR(ret));
47945650 goto clean;
47955651 }
5652
+ /* The regulator core took over the GPIO descriptor */
5653
+ dangling_cfg_gpiod = false;
5654
+ dangling_of_gpiod = false;
47965655 }
47975656
47985657 /* register with sysfs */
....@@ -4800,6 +5659,7 @@
48005659 rdev->dev.parent = dev;
48015660 dev_set_name(&rdev->dev, "regulator.%lu",
48025661 (unsigned long) atomic_inc_return(&regulator_no));
5662
+ dev_set_drvdata(&rdev->dev, rdev);
48035663
48045664 /* set regulator constraints */
48055665 if (init_data)
....@@ -4836,11 +5696,8 @@
48365696 if (ret < 0)
48375697 goto wash;
48385698
4839
- mutex_lock(&regulator_list_mutex);
4840
- ret = regulator_resolve_coupling(rdev);
4841
- mutex_unlock(&regulator_list_mutex);
4842
-
4843
- if (ret != 0)
5699
+ ret = regulator_init_coupling(rdev);
5700
+ if (ret < 0)
48445701 goto wash;
48455702
48465703 /* add consumers devices */
....@@ -4862,29 +5719,16 @@
48625719 !rdev->desc->fixed_uV)
48635720 rdev->is_switch = true;
48645721
4865
- dev_set_drvdata(&rdev->dev, rdev);
4866
- ret = device_register(&rdev->dev);
4867
- if (ret != 0) {
4868
- put_device(&rdev->dev);
5722
+ ret = device_add(&rdev->dev);
5723
+ if (ret != 0)
48695724 goto unset_supplies;
4870
- }
4871
-
4872
- /* Add a link to the device sysfs entry */
4873
- if (rdev->supply && rdev->supply->dev) {
4874
- ret = sysfs_create_link_nowarn(&rdev->supply->dev->kobj,
4875
- &rdev->dev.kobj,
4876
- rdev->supply->supply_name);
4877
- if (ret) {
4878
- rdev_dbg(rdev, "could not add device link %s err %d\n",
4879
- rdev->dev.kobj.name, ret);
4880
- /* non-fatal */
4881
- }
4882
- }
48835725
48845726 rdev_init_debugfs(rdev);
4885
- rdev_init_early_min_volt(rdev);
4886
- rdev->proxy_consumer = regulator_proxy_consumer_register(dev,
4887
- config->of_node);
5727
+
5728
+ /* try to resolve regulators coupling since a new one was registered */
5729
+ mutex_lock(&regulator_list_mutex);
5730
+ regulator_resolve_coupling(rdev);
5731
+ mutex_unlock(&regulator_list_mutex);
48885732
48895733 /* try to resolve regulators supply since a new one was registered */
48905734 class_for_each_device(&regulator_class, NULL, NULL,
....@@ -4895,15 +5739,25 @@
48955739 unset_supplies:
48965740 mutex_lock(&regulator_list_mutex);
48975741 unset_regulator_supplies(rdev);
5742
+ regulator_remove_coupling(rdev);
48985743 mutex_unlock(&regulator_list_mutex);
48995744 wash:
4900
- kfree(rdev->constraints);
5745
+ kfree(rdev->coupling_desc.coupled_rdevs);
49015746 mutex_lock(&regulator_list_mutex);
49025747 regulator_ena_gpio_free(rdev);
49035748 mutex_unlock(&regulator_list_mutex);
5749
+ put_device(&rdev->dev);
5750
+ rdev = NULL;
49045751 clean:
5752
+ if (dangling_of_gpiod)
5753
+ gpiod_put(config->ena_gpiod);
5754
+ if (rdev && rdev->dev.of_node)
5755
+ of_node_put(rdev->dev.of_node);
49055756 kfree(rdev);
49065757 kfree(config);
5758
+rinse:
5759
+ if (dangling_cfg_gpiod)
5760
+ gpiod_put(cfg->ena_gpiod);
49075761 return ERR_PTR(ret);
49085762 }
49095763 EXPORT_SYMBOL_GPL(regulator_register);
....@@ -4924,89 +5778,42 @@
49245778 regulator_disable(rdev->supply);
49255779 regulator_put(rdev->supply);
49265780 }
4927
- rdev_deinit_debugfs(rdev);
4928
- regulator_proxy_consumer_unregister(rdev->proxy_consumer);
4929
- mutex_lock(&regulator_list_mutex);
5781
+
49305782 flush_work(&rdev->disable_work.work);
5783
+
5784
+ mutex_lock(&regulator_list_mutex);
5785
+
49315786 WARN_ON(rdev->open_count);
5787
+ regulator_remove_coupling(rdev);
49325788 unset_regulator_supplies(rdev);
49335789 list_del(&rdev->list);
49345790 regulator_ena_gpio_free(rdev);
4935
- mutex_unlock(&regulator_list_mutex);
49365791 device_unregister(&rdev->dev);
5792
+
5793
+ mutex_unlock(&regulator_list_mutex);
49375794 }
49385795 EXPORT_SYMBOL_GPL(regulator_unregister);
49395796
4940
-static int regulator_sync_supply(struct device *dev, void *data)
4941
-{
4942
- struct regulator_dev *rdev = dev_to_rdev(dev);
4943
-
4944
- if (rdev->dev.parent != data)
4945
- return 0;
4946
-
4947
- if (!rdev->proxy_consumer)
4948
- return 0;
4949
-
4950
- dev_dbg(data, "Removing regulator proxy consumer requests\n");
4951
- regulator_proxy_consumer_unregister(rdev->proxy_consumer);
4952
- rdev->proxy_consumer = NULL;
4953
-
4954
- return 0;
4955
-}
4956
-
4957
-void regulator_sync_state(struct device *dev)
4958
-{
4959
- class_for_each_device(&regulator_class, NULL, dev,
4960
- regulator_sync_supply);
4961
-}
4962
-EXPORT_SYMBOL_GPL(regulator_sync_state);
4963
-
49645797 #ifdef CONFIG_SUSPEND
4965
-static int _regulator_suspend(struct device *dev, void *data)
4966
-{
4967
- struct regulator_dev *rdev = dev_to_rdev(dev);
4968
- suspend_state_t *state = data;
4969
- int ret;
4970
-
4971
- regulator_lock(rdev);
4972
- ret = suspend_set_state(rdev, *state);
4973
- regulator_unlock(rdev);
4974
-
4975
- return ret;
4976
-}
4977
-
49785798 /**
49795799 * regulator_suspend - prepare regulators for system wide suspend
4980
- * @state: system suspend state
5800
+ * @dev: ``&struct device`` pointer that is passed to _regulator_suspend()
49815801 *
49825802 * Configure each regulator with it's suspend operating parameters for state.
49835803 */
49845804 static int regulator_suspend(struct device *dev)
49855805 {
4986
- suspend_state_t state = pm_suspend_target_state;
4987
-
4988
- return class_for_each_device(&regulator_class, NULL, &state,
4989
- _regulator_suspend);
4990
-}
4991
-
4992
-static int _regulator_resume(struct device *dev, void *data)
4993
-{
4994
- int ret = 0;
49955806 struct regulator_dev *rdev = dev_to_rdev(dev);
4996
- suspend_state_t *state = data;
4997
- struct regulator_state *rstate;
5807
+ suspend_state_t state = pm_suspend_target_state;
5808
+ int ret;
5809
+ const struct regulator_state *rstate;
49985810
4999
- rstate = regulator_get_suspend_state(rdev, *state);
5000
- if (rstate == NULL)
5811
+ rstate = regulator_get_suspend_state_check(rdev, state);
5812
+ if (!rstate)
50015813 return 0;
50025814
50035815 regulator_lock(rdev);
5004
-
5005
- if (rdev->desc->ops->resume &&
5006
- (rstate->enabled == ENABLE_IN_SUSPEND ||
5007
- rstate->enabled == DISABLE_IN_SUSPEND))
5008
- ret = rdev->desc->ops->resume(rdev);
5009
-
5816
+ ret = __suspend_set_state(rdev, rstate);
50105817 regulator_unlock(rdev);
50115818
50125819 return ret;
....@@ -5015,11 +5822,28 @@
50155822 static int regulator_resume(struct device *dev)
50165823 {
50175824 suspend_state_t state = pm_suspend_target_state;
5825
+ struct regulator_dev *rdev = dev_to_rdev(dev);
5826
+ struct regulator_state *rstate;
5827
+ int ret = 0;
50185828
5019
- return class_for_each_device(&regulator_class, NULL, &state,
5020
- _regulator_resume);
5829
+ rstate = regulator_get_suspend_state(rdev, state);
5830
+ if (rstate == NULL)
5831
+ return 0;
5832
+
5833
+ /* Avoid grabbing the lock if we don't need to */
5834
+ if (!rdev->desc->ops->resume)
5835
+ return 0;
5836
+
5837
+ regulator_lock(rdev);
5838
+
5839
+ if (rstate->enabled == ENABLE_IN_SUSPEND ||
5840
+ rstate->enabled == DISABLE_IN_SUSPEND)
5841
+ ret = rdev->desc->ops->resume(rdev);
5842
+
5843
+ regulator_unlock(rdev);
5844
+
5845
+ return ret;
50215846 }
5022
-
50235847 #else /* !CONFIG_SUSPEND */
50245848
50255849 #define regulator_suspend NULL
....@@ -5112,6 +5936,12 @@
51125936 }
51135937 EXPORT_SYMBOL_GPL(rdev_get_dev);
51145938
5939
+struct regmap *rdev_get_regmap(struct regulator_dev *rdev)
5940
+{
5941
+ return rdev->regmap;
5942
+}
5943
+EXPORT_SYMBOL_GPL(rdev_get_regmap);
5944
+
51155945 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
51165946 {
51175947 return reg_init_data->driver_data;
....@@ -5131,23 +5961,8 @@
51315961
51325962 return 0;
51335963 }
5964
+DEFINE_SHOW_ATTRIBUTE(supply_map);
51345965
5135
-static int supply_map_open(struct inode *inode, struct file *file)
5136
-{
5137
- return single_open(file, supply_map_show, inode->i_private);
5138
-}
5139
-#endif
5140
-
5141
-static const struct file_operations supply_map_fops = {
5142
-#ifdef CONFIG_DEBUG_FS
5143
- .open = supply_map_open,
5144
- .read = seq_read,
5145
- .llseek = seq_lseek,
5146
- .release = single_release,
5147
-#endif
5148
-};
5149
-
5150
-#ifdef CONFIG_DEBUG_FS
51515966 struct summary_data {
51525967 struct seq_file *s;
51535968 struct regulator_dev *parent;
....@@ -5177,17 +5992,21 @@
51775992 struct regulation_constraints *c;
51785993 struct regulator *consumer;
51795994 struct summary_data summary_data;
5995
+ unsigned int opmode;
51805996
51815997 if (!rdev)
51825998 return;
51835999
5184
- seq_printf(s, "%*s%-*s %3d %4d %6d ",
6000
+ opmode = _regulator_get_mode_unlocked(rdev);
6001
+ seq_printf(s, "%*s%-*s %3d %4d %6d %7s ",
51856002 level * 3 + 1, "",
51866003 30 - level * 3, rdev_get_name(rdev),
5187
- rdev->use_count, rdev->open_count, rdev->bypass_count);
6004
+ rdev->use_count, rdev->open_count, rdev->bypass_count,
6005
+ regulator_opmode_to_str(opmode));
51886006
5189
- seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000);
5190
- seq_printf(s, "%5dmA ", _regulator_get_current_limit(rdev) / 1000);
6007
+ seq_printf(s, "%5dmV ", regulator_get_voltage_rdev(rdev) / 1000);
6008
+ seq_printf(s, "%5dmA ",
6009
+ _regulator_get_current_limit_unlocked(rdev) / 1000);
51916010
51926011 c = rdev->constraints;
51936012 if (c) {
....@@ -5217,7 +6036,11 @@
52176036
52186037 switch (rdev->desc->type) {
52196038 case REGULATOR_VOLTAGE:
5220
- seq_printf(s, "%37dmV %5dmV",
6039
+ seq_printf(s, "%3d %33dmA%c%5dmV %5dmV",
6040
+ consumer->enable_count,
6041
+ consumer->uA_load / 1000,
6042
+ consumer->uA_load && !consumer->enable_count ?
6043
+ '*' : ' ',
52216044 consumer->voltage[PM_SUSPEND_ON].min_uV / 1000,
52226045 consumer->voltage[PM_SUSPEND_ON].max_uV / 1000);
52236046 break;
....@@ -5236,6 +6059,105 @@
52366059 regulator_summary_show_children);
52376060 }
52386061
6062
+struct summary_lock_data {
6063
+ struct ww_acquire_ctx *ww_ctx;
6064
+ struct regulator_dev **new_contended_rdev;
6065
+ struct regulator_dev **old_contended_rdev;
6066
+};
6067
+
6068
+static int regulator_summary_lock_one(struct device *dev, void *data)
6069
+{
6070
+ struct regulator_dev *rdev = dev_to_rdev(dev);
6071
+ struct summary_lock_data *lock_data = data;
6072
+ int ret = 0;
6073
+
6074
+ if (rdev != *lock_data->old_contended_rdev) {
6075
+ ret = regulator_lock_nested(rdev, lock_data->ww_ctx);
6076
+
6077
+ if (ret == -EDEADLK)
6078
+ *lock_data->new_contended_rdev = rdev;
6079
+ else
6080
+ WARN_ON_ONCE(ret);
6081
+ } else {
6082
+ *lock_data->old_contended_rdev = NULL;
6083
+ }
6084
+
6085
+ return ret;
6086
+}
6087
+
6088
+static int regulator_summary_unlock_one(struct device *dev, void *data)
6089
+{
6090
+ struct regulator_dev *rdev = dev_to_rdev(dev);
6091
+ struct summary_lock_data *lock_data = data;
6092
+
6093
+ if (lock_data) {
6094
+ if (rdev == *lock_data->new_contended_rdev)
6095
+ return -EDEADLK;
6096
+ }
6097
+
6098
+ regulator_unlock(rdev);
6099
+
6100
+ return 0;
6101
+}
6102
+
6103
+static int regulator_summary_lock_all(struct ww_acquire_ctx *ww_ctx,
6104
+ struct regulator_dev **new_contended_rdev,
6105
+ struct regulator_dev **old_contended_rdev)
6106
+{
6107
+ struct summary_lock_data lock_data;
6108
+ int ret;
6109
+
6110
+ lock_data.ww_ctx = ww_ctx;
6111
+ lock_data.new_contended_rdev = new_contended_rdev;
6112
+ lock_data.old_contended_rdev = old_contended_rdev;
6113
+
6114
+ ret = class_for_each_device(&regulator_class, NULL, &lock_data,
6115
+ regulator_summary_lock_one);
6116
+ if (ret)
6117
+ class_for_each_device(&regulator_class, NULL, &lock_data,
6118
+ regulator_summary_unlock_one);
6119
+
6120
+ return ret;
6121
+}
6122
+
6123
+static void regulator_summary_lock(struct ww_acquire_ctx *ww_ctx)
6124
+{
6125
+ struct regulator_dev *new_contended_rdev = NULL;
6126
+ struct regulator_dev *old_contended_rdev = NULL;
6127
+ int err;
6128
+
6129
+ mutex_lock(&regulator_list_mutex);
6130
+
6131
+ ww_acquire_init(ww_ctx, &regulator_ww_class);
6132
+
6133
+ do {
6134
+ if (new_contended_rdev) {
6135
+ ww_mutex_lock_slow(&new_contended_rdev->mutex, ww_ctx);
6136
+ old_contended_rdev = new_contended_rdev;
6137
+ old_contended_rdev->ref_cnt++;
6138
+ }
6139
+
6140
+ err = regulator_summary_lock_all(ww_ctx,
6141
+ &new_contended_rdev,
6142
+ &old_contended_rdev);
6143
+
6144
+ if (old_contended_rdev)
6145
+ regulator_unlock(old_contended_rdev);
6146
+
6147
+ } while (err == -EDEADLK);
6148
+
6149
+ ww_acquire_done(ww_ctx);
6150
+}
6151
+
6152
+static void regulator_summary_unlock(struct ww_acquire_ctx *ww_ctx)
6153
+{
6154
+ class_for_each_device(&regulator_class, NULL, NULL,
6155
+ regulator_summary_unlock_one);
6156
+ ww_acquire_fini(ww_ctx);
6157
+
6158
+ mutex_unlock(&regulator_list_mutex);
6159
+}
6160
+
52396161 static int regulator_summary_show_roots(struct device *dev, void *data)
52406162 {
52416163 struct regulator_dev *rdev = dev_to_rdev(dev);
....@@ -5249,29 +6171,22 @@
52496171
52506172 static int regulator_summary_show(struct seq_file *s, void *data)
52516173 {
5252
- seq_puts(s, " regulator use open bypass voltage current min max\n");
5253
- seq_puts(s, "-------------------------------------------------------------------------------\n");
6174
+ struct ww_acquire_ctx ww_ctx;
6175
+
6176
+ seq_puts(s, " regulator use open bypass opmode voltage current min max\n");
6177
+ seq_puts(s, "---------------------------------------------------------------------------------------\n");
6178
+
6179
+ regulator_summary_lock(&ww_ctx);
52546180
52556181 class_for_each_device(&regulator_class, NULL, s,
52566182 regulator_summary_show_roots);
52576183
6184
+ regulator_summary_unlock(&ww_ctx);
6185
+
52586186 return 0;
52596187 }
5260
-
5261
-static int regulator_summary_open(struct inode *inode, struct file *file)
5262
-{
5263
- return single_open(file, regulator_summary_show, inode->i_private);
5264
-}
5265
-#endif
5266
-
5267
-static const struct file_operations regulator_summary_fops = {
5268
-#ifdef CONFIG_DEBUG_FS
5269
- .open = regulator_summary_open,
5270
- .read = seq_read,
5271
- .llseek = seq_lseek,
5272
- .release = single_release,
5273
-#endif
5274
-};
6188
+DEFINE_SHOW_ATTRIBUTE(regulator_summary);
6189
+#endif /* CONFIG_DEBUG_FS */
52756190
52766191 static int __init regulator_init(void)
52776192 {
....@@ -5283,13 +6198,16 @@
52836198 if (!debugfs_root)
52846199 pr_warn("regulator: Failed to create debugfs directory\n");
52856200
6201
+#ifdef CONFIG_DEBUG_FS
52866202 debugfs_create_file("supply_map", 0444, debugfs_root, NULL,
52876203 &supply_map_fops);
52886204
52896205 debugfs_create_file("regulator_summary", 0444, debugfs_root,
52906206 NULL, &regulator_summary_fops);
5291
-
6207
+#endif
52926208 regulator_dummy_init();
6209
+
6210
+ regulator_coupler_register(&generic_regulator_coupler);
52936211
52946212 return ret;
52956213 }
....@@ -5304,9 +6222,8 @@
53046222 static int regulator_late_cleanup(struct device *dev, void *data)
53056223 {
53066224 struct regulator_dev *rdev = dev_to_rdev(dev);
5307
- const struct regulator_ops *ops = rdev->desc->ops;
53086225 struct regulation_constraints *c = rdev->constraints;
5309
- int enabled, ret;
6226
+ int ret;
53106227
53116228 if (c && c->always_on)
53126229 return 0;
....@@ -5319,13 +6236,8 @@
53196236 if (rdev->use_count)
53206237 goto unlock;
53216238
5322
- /* If we can't read the status assume it's on. */
5323
- if (ops->is_enabled)
5324
- enabled = ops->is_enabled(rdev);
5325
- else
5326
- enabled = 1;
5327
-
5328
- if (!enabled)
6239
+ /* If reading the status failed, assume that it's off. */
6240
+ if (_regulator_is_enabled(rdev) <= 0)
53296241 goto unlock;
53306242
53316243 if (have_full_constraints()) {
....@@ -5334,7 +6246,7 @@
53346246 rdev_info(rdev, "disabling\n");
53356247 ret = _regulator_do_disable(rdev);
53366248 if (ret != 0)
5337
- rdev_err(rdev, "couldn't disable: %d\n", ret);
6249
+ rdev_err(rdev, "couldn't disable: %pe\n", ERR_PTR(ret));
53386250 } else {
53396251 /* The intention is that in future we will
53406252 * assume that full constraints are provided
....@@ -5374,49 +6286,6 @@
53746286 static DECLARE_DELAYED_WORK(regulator_init_complete_work,
53756287 regulator_init_complete_work_function);
53766288
5377
-static void __init regulator_release_early_min_volt(void)
5378
-{
5379
- struct regulator_limit_volt *reg_early, *n;
5380
- struct regulator *reg;
5381
- struct regulator_dev *rdev;
5382
- int min_uV = 0, max_uV = 0, ret = 0;
5383
-
5384
- if (list_empty(&regulator_early_min_volt_list))
5385
- return;
5386
-
5387
- list_for_each_entry_safe(reg_early, n, &regulator_early_min_volt_list,
5388
- list) {
5389
- rdev = reg_early->reg->rdev;
5390
-
5391
- regulator_lock_supply(rdev);
5392
-
5393
- reg_early->reg->voltage[PM_SUSPEND_ON].min_uV = 0;
5394
- reg_early->reg->voltage[PM_SUSPEND_ON].max_uV = 0;
5395
- min_uV = rdev->constraints->min_uV;
5396
- max_uV = rdev->constraints->max_uV;
5397
-
5398
- list_for_each_entry(reg, &rdev->consumer_list, list) {
5399
- if (!reg->voltage[PM_SUSPEND_ON].min_uV &&
5400
- !reg->voltage[PM_SUSPEND_ON].max_uV)
5401
- continue;
5402
- ret = regulator_set_voltage_unlocked(reg_early->reg,
5403
- min_uV,
5404
- max_uV,
5405
- PM_SUSPEND_ON);
5406
- if (ret)
5407
- rdev_err(rdev, "set voltage(%d, %d) failed\n",
5408
- min_uV, max_uV);
5409
- break;
5410
- }
5411
-
5412
- regulator_unlock_supply(rdev);
5413
-
5414
- list_del(&reg_early->list);
5415
- regulator_put(reg_early->reg);
5416
- kfree(reg_early);
5417
- }
5418
-}
5419
-
54206289 static int __init regulator_init_complete(void)
54216290 {
54226291 /*
....@@ -5441,11 +6310,6 @@
54416310 */
54426311 schedule_delayed_work(&regulator_init_complete_work,
54436312 msecs_to_jiffies(30000));
5444
-
5445
- class_for_each_device(&regulator_class, NULL, NULL,
5446
- regulator_register_fill_coupling_array);
5447
-
5448
- regulator_release_early_min_volt();
54496313
54506314 return 0;
54516315 }