@@ -37,7 +37,6 @@ struct vctrl_voltage_table {
37
37
struct vctrl_data {
38
38
struct regulator_dev * rdev ;
39
39
struct regulator_desc desc ;
40
- struct regulator * ctrl_reg ;
41
40
bool enabled ;
42
41
unsigned int min_slew_down_rate ;
43
42
unsigned int ovp_threshold ;
@@ -82,7 +81,12 @@ static int vctrl_calc_output_voltage(struct vctrl_data *vctrl, int ctrl_uV)
82
81
static int vctrl_get_voltage (struct regulator_dev * rdev )
83
82
{
84
83
struct vctrl_data * vctrl = rdev_get_drvdata (rdev );
85
- int ctrl_uV = regulator_get_voltage_rdev (vctrl -> ctrl_reg -> rdev );
84
+ int ctrl_uV ;
85
+
86
+ if (!rdev -> supply )
87
+ return - EPROBE_DEFER ;
88
+
89
+ ctrl_uV = regulator_get_voltage_rdev (rdev -> supply -> rdev );
86
90
87
91
return vctrl_calc_output_voltage (vctrl , ctrl_uV );
88
92
}
@@ -92,14 +96,19 @@ static int vctrl_set_voltage(struct regulator_dev *rdev,
92
96
unsigned int * selector )
93
97
{
94
98
struct vctrl_data * vctrl = rdev_get_drvdata (rdev );
95
- struct regulator * ctrl_reg = vctrl -> ctrl_reg ;
96
- int orig_ctrl_uV = regulator_get_voltage_rdev (ctrl_reg -> rdev );
97
- int uV = vctrl_calc_output_voltage (vctrl , orig_ctrl_uV );
99
+ int orig_ctrl_uV ;
100
+ int uV ;
98
101
int ret ;
99
102
103
+ if (!rdev -> supply )
104
+ return - EPROBE_DEFER ;
105
+
106
+ orig_ctrl_uV = regulator_get_voltage_rdev (rdev -> supply -> rdev );
107
+ uV = vctrl_calc_output_voltage (vctrl , orig_ctrl_uV );
108
+
100
109
if (req_min_uV >= uV || !vctrl -> ovp_threshold )
101
110
/* voltage rising or no OVP */
102
- return regulator_set_voltage_rdev (ctrl_reg -> rdev ,
111
+ return regulator_set_voltage_rdev (rdev -> supply -> rdev ,
103
112
vctrl_calc_ctrl_voltage (vctrl , req_min_uV ),
104
113
vctrl_calc_ctrl_voltage (vctrl , req_max_uV ),
105
114
PM_SUSPEND_ON );
@@ -117,7 +126,7 @@ static int vctrl_set_voltage(struct regulator_dev *rdev,
117
126
next_uV = max_t (int , req_min_uV , uV - max_drop_uV );
118
127
next_ctrl_uV = vctrl_calc_ctrl_voltage (vctrl , next_uV );
119
128
120
- ret = regulator_set_voltage_rdev (ctrl_reg -> rdev ,
129
+ ret = regulator_set_voltage_rdev (rdev -> supply -> rdev ,
121
130
next_ctrl_uV ,
122
131
next_ctrl_uV ,
123
132
PM_SUSPEND_ON );
@@ -134,7 +143,7 @@ static int vctrl_set_voltage(struct regulator_dev *rdev,
134
143
135
144
err :
136
145
/* Try to go back to original voltage */
137
- regulator_set_voltage_rdev (ctrl_reg -> rdev , orig_ctrl_uV , orig_ctrl_uV ,
146
+ regulator_set_voltage_rdev (rdev -> supply -> rdev , orig_ctrl_uV , orig_ctrl_uV ,
138
147
PM_SUSPEND_ON );
139
148
140
149
return ret ;
@@ -151,16 +160,18 @@ static int vctrl_set_voltage_sel(struct regulator_dev *rdev,
151
160
unsigned int selector )
152
161
{
153
162
struct vctrl_data * vctrl = rdev_get_drvdata (rdev );
154
- struct regulator * ctrl_reg = vctrl -> ctrl_reg ;
155
163
unsigned int orig_sel = vctrl -> sel ;
156
164
int ret ;
157
165
166
+ if (!rdev -> supply )
167
+ return - EPROBE_DEFER ;
168
+
158
169
if (selector >= rdev -> desc -> n_voltages )
159
170
return - EINVAL ;
160
171
161
172
if (selector >= vctrl -> sel || !vctrl -> ovp_threshold ) {
162
173
/* voltage rising or no OVP */
163
- ret = regulator_set_voltage_rdev (ctrl_reg -> rdev ,
174
+ ret = regulator_set_voltage_rdev (rdev -> supply -> rdev ,
164
175
vctrl -> vtable [selector ].ctrl ,
165
176
vctrl -> vtable [selector ].ctrl ,
166
177
PM_SUSPEND_ON );
@@ -179,7 +190,7 @@ static int vctrl_set_voltage_sel(struct regulator_dev *rdev,
179
190
else
180
191
next_sel = vctrl -> vtable [vctrl -> sel ].ovp_min_sel ;
181
192
182
- ret = regulator_set_voltage_rdev (ctrl_reg -> rdev ,
193
+ ret = regulator_set_voltage_rdev (rdev -> supply -> rdev ,
183
194
vctrl -> vtable [next_sel ].ctrl ,
184
195
vctrl -> vtable [next_sel ].ctrl ,
185
196
PM_SUSPEND_ON );
@@ -202,7 +213,7 @@ static int vctrl_set_voltage_sel(struct regulator_dev *rdev,
202
213
err :
203
214
if (vctrl -> sel != orig_sel ) {
204
215
/* Try to go back to original voltage */
205
- if (!regulator_set_voltage_rdev (ctrl_reg -> rdev ,
216
+ if (!regulator_set_voltage_rdev (rdev -> supply -> rdev ,
206
217
vctrl -> vtable [orig_sel ].ctrl ,
207
218
vctrl -> vtable [orig_sel ].ctrl ,
208
219
PM_SUSPEND_ON ))
@@ -234,10 +245,6 @@ static int vctrl_parse_dt(struct platform_device *pdev,
234
245
u32 pval ;
235
246
u32 vrange_ctrl [2 ];
236
247
237
- vctrl -> ctrl_reg = devm_regulator_get (& pdev -> dev , "ctrl" );
238
- if (IS_ERR (vctrl -> ctrl_reg ))
239
- return PTR_ERR (vctrl -> ctrl_reg );
240
-
241
248
ret = of_property_read_u32 (np , "ovp-threshold-percent" , & pval );
242
249
if (!ret ) {
243
250
vctrl -> ovp_threshold = pval ;
@@ -315,11 +322,11 @@ static int vctrl_cmp_ctrl_uV(const void *a, const void *b)
315
322
return at -> ctrl - bt -> ctrl ;
316
323
}
317
324
318
- static int vctrl_init_vtable (struct platform_device * pdev )
325
+ static int vctrl_init_vtable (struct platform_device * pdev ,
326
+ struct regulator * ctrl_reg )
319
327
{
320
328
struct vctrl_data * vctrl = platform_get_drvdata (pdev );
321
329
struct regulator_desc * rdesc = & vctrl -> desc ;
322
- struct regulator * ctrl_reg = vctrl -> ctrl_reg ;
323
330
struct vctrl_voltage_range * vrange_ctrl = & vctrl -> vrange .ctrl ;
324
331
int n_voltages ;
325
332
int ctrl_uV ;
@@ -395,23 +402,19 @@ static int vctrl_init_vtable(struct platform_device *pdev)
395
402
static int vctrl_enable (struct regulator_dev * rdev )
396
403
{
397
404
struct vctrl_data * vctrl = rdev_get_drvdata (rdev );
398
- int ret = regulator_enable (vctrl -> ctrl_reg );
399
405
400
- if (!ret )
401
- vctrl -> enabled = true;
406
+ vctrl -> enabled = true;
402
407
403
- return ret ;
408
+ return 0 ;
404
409
}
405
410
406
411
static int vctrl_disable (struct regulator_dev * rdev )
407
412
{
408
413
struct vctrl_data * vctrl = rdev_get_drvdata (rdev );
409
- int ret = regulator_disable (vctrl -> ctrl_reg );
410
414
411
- if (!ret )
412
- vctrl -> enabled = false;
415
+ vctrl -> enabled = false;
413
416
414
- return ret ;
417
+ return 0 ;
415
418
}
416
419
417
420
static int vctrl_is_enabled (struct regulator_dev * rdev )
@@ -447,6 +450,7 @@ static int vctrl_probe(struct platform_device *pdev)
447
450
struct regulator_desc * rdesc ;
448
451
struct regulator_config cfg = { };
449
452
struct vctrl_voltage_range * vrange_ctrl ;
453
+ struct regulator * ctrl_reg ;
450
454
int ctrl_uV ;
451
455
int ret ;
452
456
@@ -461,15 +465,20 @@ static int vctrl_probe(struct platform_device *pdev)
461
465
if (ret )
462
466
return ret ;
463
467
468
+ ctrl_reg = devm_regulator_get (& pdev -> dev , "ctrl" );
469
+ if (IS_ERR (ctrl_reg ))
470
+ return PTR_ERR (ctrl_reg );
471
+
464
472
vrange_ctrl = & vctrl -> vrange .ctrl ;
465
473
466
474
rdesc = & vctrl -> desc ;
467
475
rdesc -> name = "vctrl" ;
468
476
rdesc -> type = REGULATOR_VOLTAGE ;
469
477
rdesc -> owner = THIS_MODULE ;
478
+ rdesc -> supply_name = "ctrl" ;
470
479
471
- if ((regulator_get_linear_step (vctrl -> ctrl_reg ) == 1 ) ||
472
- (regulator_count_voltages (vctrl -> ctrl_reg ) == - EINVAL )) {
480
+ if ((regulator_get_linear_step (ctrl_reg ) == 1 ) ||
481
+ (regulator_count_voltages (ctrl_reg ) == - EINVAL )) {
473
482
rdesc -> continuous_voltage_range = true;
474
483
rdesc -> ops = & vctrl_ops_cont ;
475
484
} else {
@@ -486,12 +495,12 @@ static int vctrl_probe(struct platform_device *pdev)
486
495
cfg .init_data = init_data ;
487
496
488
497
if (!rdesc -> continuous_voltage_range ) {
489
- ret = vctrl_init_vtable (pdev );
498
+ ret = vctrl_init_vtable (pdev , ctrl_reg );
490
499
if (ret )
491
500
return ret ;
492
501
493
502
/* Use locked consumer API when not in regulator framework */
494
- ctrl_uV = regulator_get_voltage (vctrl -> ctrl_reg );
503
+ ctrl_uV = regulator_get_voltage (ctrl_reg );
495
504
if (ctrl_uV < 0 ) {
496
505
dev_err (& pdev -> dev , "failed to get control voltage\n" );
497
506
return ctrl_uV ;
@@ -514,6 +523,9 @@ static int vctrl_probe(struct platform_device *pdev)
514
523
}
515
524
}
516
525
526
+ /* Drop ctrl-supply here in favor of regulator core managed supply */
527
+ devm_regulator_put (ctrl_reg );
528
+
517
529
vctrl -> rdev = devm_regulator_register (& pdev -> dev , rdesc , & cfg );
518
530
if (IS_ERR (vctrl -> rdev )) {
519
531
ret = PTR_ERR (vctrl -> rdev );
0 commit comments