regulator: max8997: skip gpio dvs setup if not used
Subsystems (2)
PATCH 1/1 regulator: max8997: skip gpio dvs setup if not used
If gpio based voltage selection for buck 1/2/5 are not used, then the execution of gpio dvs setup code during probe can be skipped completly.
--- drivers/regulator/max8997.c | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 deletions(-)
drivers/regulator/max8997.c +18 -13
@@ -973,6 +973,10 @@ static int max8997_pmic_probe(struct platform_device *pdev)memcpy (max8997->buck125_gpios, pdata->buck125_gpios,sizeof (int ) *3 ); max8997->ignore_gpiodvs_side_effect = pdata->ignore_gpiodvs_side_effect; +if (!pdata->buck1_gpiodvs && !pdata->buck2_gpiodvs && + !pdata->buck5_gpiodvs) + goto skip_gpiodvs; +for (i =0 ; i <8 ; i++) { max8997->buck1_vol[i] = ret = max8997_get_voltage_proper_val(
@@ -1019,6 +1023,19 @@ static int max8997_pmic_probe(struct platform_device *pdev) max_buck5, 0x3f); } +/* Initialize all the DVS related BUCK registers */ +for (i =0 ; i <8 ; i++) { +max8997_update_reg (i2c,MAX8997_REG_BUCK1DVS1 + i, + max8997->buck1_vol[i], +0x3f ); +max8997_update_reg (i2c,MAX8997_REG_BUCK2DVS1 + i, + max8997->buck2_vol[i], +0x3f ); +max8997_update_reg (i2c,MAX8997_REG_BUCK5DVS1 + i, + max8997->buck5_vol[i], +0x3f ); + } +/* * If buck 1, 2, and 5 do not care DVS GPIO settings, ignore them. * If at least one of them cares, set gpios.
@@ -1060,6 +1077,7 @@ static int max8997_pmic_probe(struct platform_device *pdev) & 0x1); /* SET3 */ } +skip_gpiodvs:/* DVS-GPIO disabled */ max8997_update_reg (i2c,MAX8997_REG_BUCK1CTRL , (pdata->buck1_gpiodvs) ? (1 <<1 ) : (0 <<1 ),1 <<1 );
@@ -1068,19 +1086,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)max8997_update_reg (i2c,MAX8997_REG_BUCK5CTRL , (pdata->buck5_gpiodvs) ? (1 <<1 ) : (0 <<1 ),1 <<1 ); -/* Initialize all the DVS related BUCK registers */ -for (i =0 ; i <8 ; i++) { -max8997_update_reg (i2c,MAX8997_REG_BUCK1DVS1 + i, - max8997->buck1_vol[i], -0x3f ); -max8997_update_reg (i2c,MAX8997_REG_BUCK2DVS1 + i, - max8997->buck2_vol[i], -0x3f ); -max8997_update_reg (i2c,MAX8997_REG_BUCK5DVS1 + i, - max8997->buck5_vol[i], -0x3f ); - } -/* Misc Settings */ max8997->ramp_delay =10 ;/* set 10mV/us, which is the default */ max8997_write_reg (i2c,MAX8997_REG_BUCKRAMP , (0xf <<4 ) |0x9 );
Signature · 1 line
1.6.6.rc2
Quoted 2 lines · Thomas Abraham
If gpio based voltage selection for buck 1/2/5 are not used, then the execution of gpio dvs setup code during probe can be skipped completly.
Even if GPIO-DVS feature is turned off, you need to setup BUCKxDVS1 anyway. Otherwise, you may get "unspecified" behavior from the BUCK1/2/5, which may incur unstable system.
Cheers,
MyungJoo
Signature · 2 lines
MyungJoo Ham, Ph.D. Mobile Software Platform Lab, DMC Business, Samsung Electronics
Dear Mr. Ham,
Thanks for your comments.
Quoted 8 lines · MyungJoo Ham
Quoted 2 lines · Thomas Abraham
If gpio based voltage selection for buck 1/2/5 are not used, then the execution of gpio dvs setup code during probe can be skipped completly.
Even if GPIO-DVS feature is turned off, you need to setup BUCKxDVS1 anyway. Otherwise, you may get "unspecified" behavior from the BUCK1/2/5, which may incur unstable system.
I was looking into the documents but I did not find that this condition being documented. Anyways, based on your comments, I have tested two changes in the max8997 driver.
The first change moves the programming of the DVS related BUCK registers above the programming of the BUCKxCTRL register. This is required because by the time the BUCKxCTRL register is configured, the corresponding voltage levels should already be programmed in BUCKxDVSx registers.
drivers/regulator/max8997.c +0 -0
@@ -1019,6 +1019,19 @@ static int max8997_pmic_probe(struct
platform_device *pdev)
max_buck5, 0x3f);
}+ /* Initialize all the DVS related BUCK registers */
+ for (i = 0; i < 8; i++) {
+ max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
+ max8997->buck1_vol[i],
+ 0x3f);
+ max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i,
+ max8997->buck2_vol[i],
+ 0x3f);
+ max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i,
+ max8997->buck5_vol[i],
+ 0x3f);
+ }
+
/*
* If buck 1, 2, and 5 do not care DVS GPIO settings, ignore them.
* If at least one of them cares, set gpios.
@@ -1068,19 +1081,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)
max8997_update_reg(i2c, MAX8997_REG_BUCK5CTRL, (pdata->buck5_gpiodvs) ?
(1 << 1) : (0 << 1), 1 << 1);- /* Initialize all the DVS related BUCK registers */
- for (i = 0; i < 8; i++) {
- max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
- max8997->buck1_vol[i],
- 0x3f);
- max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i,
- max8997->buck2_vol[i],
- 0x3f);
- max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i,
- max8997->buck5_vol[i],
- 0x3f);
- }
-
/* Misc Settings */
max8997->ramp_delay = 10; /* set 10mV/us, which is the default */
max8997_write_reg(i2c, MAX8997_REG_BUCKRAMP, (0xf << 4) | 0x9);In the second change, if the DVS feature is used, all the 8 BUCKxDVSx registers are programmed. If DVS feature is not used, only BUCKxDVS1 register is programmed.
drivers/regulator/max8997.c +5 -2
@@ -941,7 +941,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)struct regulator_dev **rdev;struct max8997_data *max8997;struct i2c_client *i2c; -int i, ret, size; +int i, ret, size, nr_dvs;u8 max_buck1 =0 , max_buck2 =0 , max_buck5 =0 ;if (!pdata) {
@@ -973,7 +973,10 @@ static int max8997_pmic_probe(struct platform_device *pdev)memcpy (max8997->buck125_gpios, pdata->buck125_gpios,sizeof (int ) *3 ); max8997->ignore_gpiodvs_side_effect = pdata->ignore_gpiodvs_side_effect; -for (i =0 ; i <8 ; i++) { + nr_dvs = (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || + pdata->buck5_gpiodvs) ?8 :1 ; + +for (i =0 ; i < nr_dvs; i++) { max8997->buck1_vol[i] = ret = max8997_get_voltage_proper_val( &buck1245_voltage_map_desc,
@@ -1020,7 +1023,7 @@ static int max8997_pmic_probe(struct
platform_device *pdev)
}
/* Initialize all the DVS related BUCK registers */
- for (i = 0; i < 8; i++) {
+ for (i = 0; i < nr_dvs; i++) {
max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i,
max8997->buck1_vol[i],
0x3f);If these changes are correct, could you please let me know. I will submit patches for these changes.
Thanks for your time.
Regards,
Thomas.
Quoted 7 lines
Cheers,
MyungJoo--
MyungJoo Ham, Ph.D.
Mobile Software Platform Lab, DMC Business, Samsung Electronics