17
17
#include <linux/regulator/machine.h>
18
18
#include <linux/regulator/of_regulator.h>
19
19
#include <linux/regulator/pca9450.h>
20
+ #include <dt-bindings/regulator/nxp,pca9450-regulator.h>
21
+
22
+ static unsigned int pca9450_buck_get_mode (struct regulator_dev * rdev );
23
+ static int pca9450_buck_set_mode (struct regulator_dev * rdev , unsigned int mode );
20
24
21
25
struct pc9450_dvs_config {
22
26
unsigned int run_reg ; /* dvs0 */
23
27
unsigned int run_mask ;
24
28
unsigned int standby_reg ; /* dvs1 */
25
29
unsigned int standby_mask ;
30
+ unsigned int mode_reg ; /* ctrl */
31
+ unsigned int mode_mask ;
26
32
};
27
33
28
34
struct pca9450_regulator_desc {
@@ -80,6 +86,8 @@ static const struct regulator_ops pca9450_dvs_buck_regulator_ops = {
80
86
.get_voltage_sel = regulator_get_voltage_sel_regmap ,
81
87
.set_voltage_time_sel = regulator_set_voltage_time_sel ,
82
88
.set_ramp_delay = regulator_set_ramp_delay_regmap ,
89
+ .set_mode = pca9450_buck_set_mode ,
90
+ .get_mode = pca9450_buck_get_mode ,
83
91
};
84
92
85
93
static const struct regulator_ops pca9450_buck_regulator_ops = {
@@ -90,6 +98,8 @@ static const struct regulator_ops pca9450_buck_regulator_ops = {
90
98
.set_voltage_sel = regulator_set_voltage_sel_regmap ,
91
99
.get_voltage_sel = regulator_get_voltage_sel_regmap ,
92
100
.set_voltage_time_sel = regulator_set_voltage_time_sel ,
101
+ .set_mode = pca9450_buck_set_mode ,
102
+ .get_mode = pca9450_buck_get_mode ,
93
103
};
94
104
95
105
static const struct regulator_ops pca9450_ldo_regulator_ops = {
@@ -285,7 +295,64 @@ static int pca9450_set_dvs_levels(struct device_node *np,
285
295
return ret ;
286
296
}
287
297
288
- static const struct pca9450_regulator_desc pca9450a_regulators [] = {
298
+ static inline unsigned int pca9450_map_mode (unsigned int mode )
299
+ {
300
+ switch (mode ) {
301
+ case PCA9450_BUCK_MODE_AUTO :
302
+ return REGULATOR_MODE_NORMAL ;
303
+ case PCA9450_BUCK_MODE_FORCE_PWM :
304
+ return REGULATOR_MODE_FAST ;
305
+ default :
306
+ return REGULATOR_MODE_INVALID ;
307
+ }
308
+ }
309
+
310
+ static int pca9450_buck_set_mode (struct regulator_dev * rdev , unsigned int mode )
311
+ {
312
+ struct pca9450_regulator_desc * desc = container_of (rdev -> desc ,
313
+ struct pca9450_regulator_desc , desc );
314
+ const struct pc9450_dvs_config * dvs = & desc -> dvs ;
315
+ int val ;
316
+
317
+ switch (mode ) {
318
+ case REGULATOR_MODE_FAST :
319
+ val = dvs -> mode_mask ;
320
+ break ;
321
+ case REGULATOR_MODE_NORMAL :
322
+ val = 0 ;
323
+ break ;
324
+ default :
325
+ return - EINVAL ;
326
+ }
327
+
328
+ dev_dbg (& rdev -> dev , "pca9450 buck set_mode %#x, %#x, %#x\n" ,
329
+ dvs -> mode_reg , dvs -> mode_mask , val );
330
+
331
+ return regmap_update_bits (rdev -> regmap , dvs -> mode_reg ,
332
+ dvs -> mode_mask , val );
333
+ }
334
+
335
+ static unsigned int pca9450_buck_get_mode (struct regulator_dev * rdev )
336
+ {
337
+ struct pca9450_regulator_desc * desc = container_of (rdev -> desc ,
338
+ struct pca9450_regulator_desc , desc );
339
+ const struct pc9450_dvs_config * dvs = & desc -> dvs ;
340
+ int ret = 0 , regval ;
341
+
342
+ ret = regmap_read (rdev -> regmap , dvs -> mode_reg , & regval );
343
+ if (ret != 0 ) {
344
+ dev_err (& rdev -> dev ,
345
+ "Failed to get pca9450 buck mode: %d\n" , ret );
346
+ return ret ;
347
+ }
348
+
349
+ if ((regval & dvs -> mode_mask ) == dvs -> mode_mask )
350
+ return REGULATOR_MODE_FAST ;
351
+
352
+ return REGULATOR_MODE_NORMAL ;
353
+ }
354
+
355
+ static struct pca9450_regulator_desc pca9450a_regulators [] = {
289
356
{
290
357
.desc = {
291
358
.name = "buck1" ,
@@ -308,12 +375,15 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
308
375
.enable_val = BUCK_ENMODE_ONREQ ,
309
376
.owner = THIS_MODULE ,
310
377
.of_parse_cb = pca9450_set_dvs_levels ,
378
+ .of_map_mode = pca9450_map_mode ,
311
379
},
312
380
.dvs = {
313
381
.run_reg = PCA9450_REG_BUCK1OUT_DVS0 ,
314
382
.run_mask = BUCK1OUT_DVS0_MASK ,
315
383
.standby_reg = PCA9450_REG_BUCK1OUT_DVS1 ,
316
384
.standby_mask = BUCK1OUT_DVS1_MASK ,
385
+ .mode_reg = PCA9450_REG_BUCK1CTRL ,
386
+ .mode_mask = BUCK1_FPWM ,
317
387
},
318
388
},
319
389
{
@@ -338,12 +408,15 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
338
408
.n_ramp_values = ARRAY_SIZE (pca9450_dvs_buck_ramp_table ),
339
409
.owner = THIS_MODULE ,
340
410
.of_parse_cb = pca9450_set_dvs_levels ,
411
+ .of_map_mode = pca9450_map_mode ,
341
412
},
342
413
.dvs = {
343
414
.run_reg = PCA9450_REG_BUCK2OUT_DVS0 ,
344
415
.run_mask = BUCK2OUT_DVS0_MASK ,
345
416
.standby_reg = PCA9450_REG_BUCK2OUT_DVS1 ,
346
417
.standby_mask = BUCK2OUT_DVS1_MASK ,
418
+ .mode_reg = PCA9450_REG_BUCK2CTRL ,
419
+ .mode_mask = BUCK2_FPWM ,
347
420
},
348
421
},
349
422
{
@@ -368,12 +441,15 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
368
441
.n_ramp_values = ARRAY_SIZE (pca9450_dvs_buck_ramp_table ),
369
442
.owner = THIS_MODULE ,
370
443
.of_parse_cb = pca9450_set_dvs_levels ,
444
+ .of_map_mode = pca9450_map_mode ,
371
445
},
372
446
.dvs = {
373
447
.run_reg = PCA9450_REG_BUCK3OUT_DVS0 ,
374
448
.run_mask = BUCK3OUT_DVS0_MASK ,
375
449
.standby_reg = PCA9450_REG_BUCK3OUT_DVS1 ,
376
450
.standby_mask = BUCK3OUT_DVS1_MASK ,
451
+ .mode_reg = PCA9450_REG_BUCK3CTRL ,
452
+ .mode_mask = BUCK3_FPWM ,
377
453
},
378
454
},
379
455
{
@@ -393,6 +469,11 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
393
469
.enable_mask = BUCK4_ENMODE_MASK ,
394
470
.enable_val = BUCK_ENMODE_ONREQ ,
395
471
.owner = THIS_MODULE ,
472
+ .of_map_mode = pca9450_map_mode ,
473
+ },
474
+ .dvs = {
475
+ .mode_reg = PCA9450_REG_BUCK4CTRL ,
476
+ .mode_mask = BUCK4_FPWM ,
396
477
},
397
478
},
398
479
{
@@ -412,6 +493,11 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
412
493
.enable_mask = BUCK5_ENMODE_MASK ,
413
494
.enable_val = BUCK_ENMODE_ONREQ ,
414
495
.owner = THIS_MODULE ,
496
+ .of_map_mode = pca9450_map_mode ,
497
+ },
498
+ .dvs = {
499
+ .mode_reg = PCA9450_REG_BUCK5CTRL ,
500
+ .mode_mask = BUCK5_FPWM ,
415
501
},
416
502
},
417
503
{
@@ -431,6 +517,11 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
431
517
.enable_mask = BUCK6_ENMODE_MASK ,
432
518
.enable_val = BUCK_ENMODE_ONREQ ,
433
519
.owner = THIS_MODULE ,
520
+ .of_map_mode = pca9450_map_mode ,
521
+ },
522
+ .dvs = {
523
+ .mode_reg = PCA9450_REG_BUCK6CTRL ,
524
+ .mode_mask = BUCK6_FPWM ,
434
525
},
435
526
},
436
527
{
@@ -529,7 +620,7 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
529
620
* Buck3 removed on PCA9450B and connected with Buck1 internal for dual phase
530
621
* on PCA9450C as no Buck3.
531
622
*/
532
- static const struct pca9450_regulator_desc pca9450bc_regulators [] = {
623
+ static struct pca9450_regulator_desc pca9450bc_regulators [] = {
533
624
{
534
625
.desc = {
535
626
.name = "buck1" ,
@@ -552,12 +643,15 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
552
643
.n_ramp_values = ARRAY_SIZE (pca9450_dvs_buck_ramp_table ),
553
644
.owner = THIS_MODULE ,
554
645
.of_parse_cb = pca9450_set_dvs_levels ,
646
+ .of_map_mode = pca9450_map_mode ,
555
647
},
556
648
.dvs = {
557
649
.run_reg = PCA9450_REG_BUCK1OUT_DVS0 ,
558
650
.run_mask = BUCK1OUT_DVS0_MASK ,
559
651
.standby_reg = PCA9450_REG_BUCK1OUT_DVS1 ,
560
652
.standby_mask = BUCK1OUT_DVS1_MASK ,
653
+ .mode_reg = PCA9450_REG_BUCK1CTRL ,
654
+ .mode_mask = BUCK1_FPWM ,
561
655
},
562
656
},
563
657
{
@@ -582,12 +676,15 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
582
676
.n_ramp_values = ARRAY_SIZE (pca9450_dvs_buck_ramp_table ),
583
677
.owner = THIS_MODULE ,
584
678
.of_parse_cb = pca9450_set_dvs_levels ,
679
+ .of_map_mode = pca9450_map_mode ,
585
680
},
586
681
.dvs = {
587
682
.run_reg = PCA9450_REG_BUCK2OUT_DVS0 ,
588
683
.run_mask = BUCK2OUT_DVS0_MASK ,
589
684
.standby_reg = PCA9450_REG_BUCK2OUT_DVS1 ,
590
685
.standby_mask = BUCK2OUT_DVS1_MASK ,
686
+ .mode_reg = PCA9450_REG_BUCK2CTRL ,
687
+ .mode_mask = BUCK2_FPWM ,
591
688
},
592
689
},
593
690
{
@@ -607,6 +704,11 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
607
704
.enable_mask = BUCK4_ENMODE_MASK ,
608
705
.enable_val = BUCK_ENMODE_ONREQ ,
609
706
.owner = THIS_MODULE ,
707
+ .of_map_mode = pca9450_map_mode ,
708
+ },
709
+ .dvs = {
710
+ .mode_reg = PCA9450_REG_BUCK4CTRL ,
711
+ .mode_mask = BUCK4_FPWM ,
610
712
},
611
713
},
612
714
{
@@ -626,6 +728,11 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
626
728
.enable_mask = BUCK5_ENMODE_MASK ,
627
729
.enable_val = BUCK_ENMODE_ONREQ ,
628
730
.owner = THIS_MODULE ,
731
+ .of_map_mode = pca9450_map_mode ,
732
+ },
733
+ .dvs = {
734
+ .mode_reg = PCA9450_REG_BUCK5CTRL ,
735
+ .mode_mask = BUCK5_FPWM ,
629
736
},
630
737
},
631
738
{
@@ -645,6 +752,11 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
645
752
.enable_mask = BUCK6_ENMODE_MASK ,
646
753
.enable_val = BUCK_ENMODE_ONREQ ,
647
754
.owner = THIS_MODULE ,
755
+ .of_map_mode = pca9450_map_mode ,
756
+ },
757
+ .dvs = {
758
+ .mode_reg = PCA9450_REG_BUCK6CTRL ,
759
+ .mode_mask = BUCK6_FPWM ,
648
760
},
649
761
},
650
762
{
@@ -739,7 +851,7 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
739
851
},
740
852
};
741
853
742
- static const struct pca9450_regulator_desc pca9451a_regulators [] = {
854
+ static struct pca9450_regulator_desc pca9451a_regulators [] = {
743
855
{
744
856
.desc = {
745
857
.name = "buck1" ,
@@ -990,7 +1102,7 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
990
1102
{
991
1103
enum pca9450_chip_type type = (unsigned int )(uintptr_t )
992
1104
of_device_get_match_data (& i2c -> dev );
993
- const struct pca9450_regulator_desc * regulator_desc ;
1105
+ const struct pca9450_regulator_desc * regulator_desc ;
994
1106
struct regulator_config config = { };
995
1107
struct regulator_dev * ldo5 ;
996
1108
struct pca9450 * pca9450 ;
0 commit comments