@@ -37,7 +37,6 @@ struct vctrl_voltage_table {
3737struct  vctrl_data  {
3838	struct  regulator_dev  * rdev ;
3939	struct  regulator_desc  desc ;
40- 	struct  regulator  * ctrl_reg ;
4140	bool  enabled ;
4241	unsigned int   min_slew_down_rate ;
4342	unsigned int   ovp_threshold ;
@@ -82,7 +81,12 @@ static int vctrl_calc_output_voltage(struct vctrl_data *vctrl, int ctrl_uV)
8281static  int  vctrl_get_voltage (struct  regulator_dev  * rdev )
8382{
8483	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 );
8690
8791	return  vctrl_calc_output_voltage (vctrl , ctrl_uV );
8892}
@@ -92,14 +96,19 @@ static int vctrl_set_voltage(struct regulator_dev *rdev,
9296			     unsigned int   * selector )
9397{
9498	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 ;
98101	int  ret ;
99102
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+ 
100109	if  (req_min_uV  >= uV  ||  !vctrl -> ovp_threshold )
101110		/* voltage rising or no OVP */ 
102- 		return  regulator_set_voltage_rdev (ctrl_reg -> rdev ,
111+ 		return  regulator_set_voltage_rdev (rdev -> supply -> rdev ,
103112			vctrl_calc_ctrl_voltage (vctrl , req_min_uV ),
104113			vctrl_calc_ctrl_voltage (vctrl , req_max_uV ),
105114			PM_SUSPEND_ON );
@@ -117,7 +126,7 @@ static int vctrl_set_voltage(struct regulator_dev *rdev,
117126		next_uV  =  max_t (int , req_min_uV , uV  -  max_drop_uV );
118127		next_ctrl_uV  =  vctrl_calc_ctrl_voltage (vctrl , next_uV );
119128
120- 		ret  =  regulator_set_voltage_rdev (ctrl_reg -> rdev ,
129+ 		ret  =  regulator_set_voltage_rdev (rdev -> supply -> rdev ,
121130					    next_ctrl_uV ,
122131					    next_ctrl_uV ,
123132					    PM_SUSPEND_ON );
@@ -134,7 +143,7 @@ static int vctrl_set_voltage(struct regulator_dev *rdev,
134143
135144err :
136145	/* 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 ,
138147				   PM_SUSPEND_ON );
139148
140149	return  ret ;
@@ -151,16 +160,18 @@ static int vctrl_set_voltage_sel(struct regulator_dev *rdev,
151160				 unsigned int   selector )
152161{
153162	struct  vctrl_data  * vctrl  =  rdev_get_drvdata (rdev );
154- 	struct  regulator  * ctrl_reg  =  vctrl -> ctrl_reg ;
155163	unsigned int   orig_sel  =  vctrl -> sel ;
156164	int  ret ;
157165
166+ 	if  (!rdev -> supply )
167+ 		return  - EPROBE_DEFER ;
168+ 
158169	if  (selector  >= rdev -> desc -> n_voltages )
159170		return  - EINVAL ;
160171
161172	if  (selector  >= vctrl -> sel  ||  !vctrl -> ovp_threshold ) {
162173		/* voltage rising or no OVP */ 
163- 		ret  =  regulator_set_voltage_rdev (ctrl_reg -> rdev ,
174+ 		ret  =  regulator_set_voltage_rdev (rdev -> supply -> rdev ,
164175					    vctrl -> vtable [selector ].ctrl ,
165176					    vctrl -> vtable [selector ].ctrl ,
166177					    PM_SUSPEND_ON );
@@ -179,7 +190,7 @@ static int vctrl_set_voltage_sel(struct regulator_dev *rdev,
179190		else 
180191			next_sel  =  vctrl -> vtable [vctrl -> sel ].ovp_min_sel ;
181192
182- 		ret  =  regulator_set_voltage_rdev (ctrl_reg -> rdev ,
193+ 		ret  =  regulator_set_voltage_rdev (rdev -> supply -> rdev ,
183194					    vctrl -> vtable [next_sel ].ctrl ,
184195					    vctrl -> vtable [next_sel ].ctrl ,
185196					    PM_SUSPEND_ON );
@@ -202,7 +213,7 @@ static int vctrl_set_voltage_sel(struct regulator_dev *rdev,
202213err :
203214	if  (vctrl -> sel  !=  orig_sel ) {
204215		/* 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 ,
206217					   vctrl -> vtable [orig_sel ].ctrl ,
207218					   vctrl -> vtable [orig_sel ].ctrl ,
208219					   PM_SUSPEND_ON ))
@@ -234,10 +245,6 @@ static int vctrl_parse_dt(struct platform_device *pdev,
234245	u32  pval ;
235246	u32  vrange_ctrl [2 ];
236247
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- 
241248	ret  =  of_property_read_u32 (np , "ovp-threshold-percent" , & pval );
242249	if  (!ret ) {
243250		vctrl -> ovp_threshold  =  pval ;
@@ -315,11 +322,11 @@ static int vctrl_cmp_ctrl_uV(const void *a, const void *b)
315322	return  at -> ctrl  -  bt -> ctrl ;
316323}
317324
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 )
319327{
320328	struct  vctrl_data  * vctrl  =  platform_get_drvdata (pdev );
321329	struct  regulator_desc  * rdesc  =  & vctrl -> desc ;
322- 	struct  regulator  * ctrl_reg  =  vctrl -> ctrl_reg ;
323330	struct  vctrl_voltage_range  * vrange_ctrl  =  & vctrl -> vrange .ctrl ;
324331	int  n_voltages ;
325332	int  ctrl_uV ;
@@ -395,23 +402,19 @@ static int vctrl_init_vtable(struct platform_device *pdev)
395402static  int  vctrl_enable (struct  regulator_dev  * rdev )
396403{
397404	struct  vctrl_data  * vctrl  =  rdev_get_drvdata (rdev );
398- 	int  ret  =  regulator_enable (vctrl -> ctrl_reg );
399405
400- 	if  (!ret )
401- 		vctrl -> enabled  =  true;
406+ 	vctrl -> enabled  =  true;
402407
403- 	return  ret ;
408+ 	return  0 ;
404409}
405410
406411static  int  vctrl_disable (struct  regulator_dev  * rdev )
407412{
408413	struct  vctrl_data  * vctrl  =  rdev_get_drvdata (rdev );
409- 	int  ret  =  regulator_disable (vctrl -> ctrl_reg );
410414
411- 	if  (!ret )
412- 		vctrl -> enabled  =  false;
415+ 	vctrl -> enabled  =  false;
413416
414- 	return  ret ;
417+ 	return  0 ;
415418}
416419
417420static  int  vctrl_is_enabled (struct  regulator_dev  * rdev )
@@ -447,6 +450,7 @@ static int vctrl_probe(struct platform_device *pdev)
447450	struct  regulator_desc  * rdesc ;
448451	struct  regulator_config  cfg  =  { };
449452	struct  vctrl_voltage_range  * vrange_ctrl ;
453+ 	struct  regulator  * ctrl_reg ;
450454	int  ctrl_uV ;
451455	int  ret ;
452456
@@ -461,15 +465,20 @@ static int vctrl_probe(struct platform_device *pdev)
461465	if  (ret )
462466		return  ret ;
463467
468+ 	ctrl_reg  =  devm_regulator_get (& pdev -> dev , "ctrl" );
469+ 	if  (IS_ERR (ctrl_reg ))
470+ 		return  PTR_ERR (ctrl_reg );
471+ 
464472	vrange_ctrl  =  & vctrl -> vrange .ctrl ;
465473
466474	rdesc  =  & vctrl -> desc ;
467475	rdesc -> name  =  "vctrl" ;
468476	rdesc -> type  =  REGULATOR_VOLTAGE ;
469477	rdesc -> owner  =  THIS_MODULE ;
478+ 	rdesc -> supply_name  =  "ctrl" ;
470479
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 )) {
473482		rdesc -> continuous_voltage_range  =  true;
474483		rdesc -> ops  =  & vctrl_ops_cont ;
475484	} else  {
@@ -486,12 +495,12 @@ static int vctrl_probe(struct platform_device *pdev)
486495	cfg .init_data  =  init_data ;
487496
488497	if  (!rdesc -> continuous_voltage_range ) {
489- 		ret  =  vctrl_init_vtable (pdev );
498+ 		ret  =  vctrl_init_vtable (pdev ,  ctrl_reg );
490499		if  (ret )
491500			return  ret ;
492501
493502		/* 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 );
495504		if  (ctrl_uV  <  0 ) {
496505			dev_err (& pdev -> dev , "failed to get control voltage\n" );
497506			return  ctrl_uV ;
@@ -514,6 +523,9 @@ static int vctrl_probe(struct platform_device *pdev)
514523		}
515524	}
516525
526+ 	/* Drop ctrl-supply here in favor of regulator core managed supply */ 
527+ 	devm_regulator_put (ctrl_reg );
528+ 
517529	vctrl -> rdev  =  devm_regulator_register (& pdev -> dev , rdesc , & cfg );
518530	if  (IS_ERR (vctrl -> rdev )) {
519531		ret  =  PTR_ERR (vctrl -> rdev );
0 commit comments