Skip to content

Commit 4280e0b

Browse files
Tomasz FigaSamuel Ortiz
authored andcommitted
regulator: max8998: Use arrays for specifying voltages in platform data
This patch modifies the platform data of max8998 to use arrays for specifying predefined voltages of buck1 and buck2 instead of separate field for each voltage. This allows to simplify the code a bit and will help in adding support for Device Tree, which will be introduced in further patch. Signed-off-by: Tomasz Figa <t.figa@samsung.com> Acked-by: Mark Brown <broonie@linaro.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 443c6ae commit 4280e0b

5 files changed

Lines changed: 39 additions & 97 deletions

File tree

‎arch/arm/mach-exynos/mach-universal_c210.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,11 @@ static struct max8998_regulator_data lp3974_regulators[] = {
540540
static struct max8998_platform_data universal_lp3974_pdata = {
541541
.num_regulators = ARRAY_SIZE(lp3974_regulators),
542542
.regulators = lp3974_regulators,
543-
.buck1_voltage1 = 1100000, /* INT */
544-
.buck1_voltage2 = 1000000,
545-
.buck1_voltage3 = 1100000,
546-
.buck1_voltage4 = 1000000,
543+
.buck1_voltage = { 1100000, 1000000, 1100000, 1000000 },
547544
.buck1_set1 = EXYNOS4_GPX0(5),
548545
.buck1_set2 = EXYNOS4_GPX0(6),
549-
.buck2_voltage1 = 1200000, /* G3D */
550-
.buck2_voltage2 = 1100000,
551546
.buck1_default_idx = 0,
547+
.buck2_voltage = { 1200000, 1100000 },
552548
.buck2_set3 = EXYNOS4_GPE2(0),
553549
.buck2_default_idx = 0,
554550
.wakeup = true,

‎arch/arm/mach-s5pv210/mach-aquila.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,8 @@ static struct max8998_platform_data aquila_max8998_pdata = {
377377
.buck1_set1 = S5PV210_GPH0(3),
378378
.buck1_set2 = S5PV210_GPH0(4),
379379
.buck2_set3 = S5PV210_GPH0(5),
380-
.buck1_voltage1 = 1200000,
381-
.buck1_voltage2 = 1200000,
382-
.buck1_voltage3 = 1200000,
383-
.buck1_voltage4 = 1200000,
384-
.buck2_voltage1 = 1200000,
385-
.buck2_voltage2 = 1200000,
380+
.buck1_voltage = { 1200000, 1200000, 1200000, 1200000 },
381+
.buck2_voltage = { 1200000, 1200000 },
386382
};
387383
#endif
388384

‎arch/arm/mach-s5pv210/mach-goni.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,8 @@ static struct max8998_platform_data goni_max8998_pdata = {
580580
.buck1_set1 = S5PV210_GPH0(3),
581581
.buck1_set2 = S5PV210_GPH0(4),
582582
.buck2_set3 = S5PV210_GPH0(5),
583-
.buck1_voltage1 = 1200000,
584-
.buck1_voltage2 = 1200000,
585-
.buck1_voltage3 = 1200000,
586-
.buck1_voltage4 = 1200000,
587-
.buck2_voltage1 = 1200000,
588-
.buck2_voltage2 = 1200000,
583+
.buck1_voltage = { 1200000, 1200000, 1200000, 1200000 },
584+
.buck2_voltage = { 1200000, 1200000 },
589585
};
590586
#endif
591587

‎drivers/regulator/max8998.c‎

Lines changed: 29 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
630630
struct max8998_data *max8998;
631631
struct i2c_client *i2c;
632632
int i, ret, size;
633+
unsigned int v;
633634

634635
if (!pdata) {
635636
dev_err(pdev->dev.parent, "No platform init data supplied\n");
@@ -688,53 +689,21 @@ static int max8998_pmic_probe(struct platform_device *pdev)
688689
gpio_request(pdata->buck1_set2, "MAX8998 BUCK1_SET2");
689690
gpio_direction_output(pdata->buck1_set2,
690691
(max8998->buck1_idx >> 1) & 0x1);
691-
/* Set predefined value for BUCK1 register 1 */
692-
i = 0;
693-
while (buck12_voltage_map_desc.min +
694-
buck12_voltage_map_desc.step*i
695-
< pdata->buck1_voltage1)
696-
i++;
697-
max8998->buck1_vol[0] = i;
698-
ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i);
699-
if (ret)
700-
goto err_out;
701-
702-
/* Set predefined value for BUCK1 register 2 */
703-
i = 0;
704-
while (buck12_voltage_map_desc.min +
705-
buck12_voltage_map_desc.step*i
706-
< pdata->buck1_voltage2)
707-
i++;
708-
709-
max8998->buck1_vol[1] = i;
710-
ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i);
711-
if (ret)
712-
goto err_out;
713-
714-
/* Set predefined value for BUCK1 register 3 */
715-
i = 0;
716-
while (buck12_voltage_map_desc.min +
717-
buck12_voltage_map_desc.step*i
718-
< pdata->buck1_voltage3)
719-
i++;
720-
721-
max8998->buck1_vol[2] = i;
722-
ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i);
723-
if (ret)
724-
goto err_out;
725-
726-
/* Set predefined value for BUCK1 register 4 */
727-
i = 0;
728-
while (buck12_voltage_map_desc.min +
729-
buck12_voltage_map_desc.step*i
730-
< pdata->buck1_voltage4)
731-
i++;
732-
733-
max8998->buck1_vol[3] = i;
734-
ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i);
735-
if (ret)
736-
goto err_out;
737692

693+
/* Set predefined values for BUCK1 registers */
694+
for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) {
695+
i = 0;
696+
while (buck12_voltage_map_desc.min +
697+
buck12_voltage_map_desc.step*i
698+
< pdata->buck1_voltage[v])
699+
i++;
700+
701+
max8998->buck1_vol[v] = i;
702+
ret = max8998_write_reg(i2c,
703+
MAX8998_REG_BUCK1_VOLTAGE1 + v, i);
704+
if (ret)
705+
goto err_out;
706+
}
738707
}
739708

740709
if (gpio_is_valid(pdata->buck2_set3)) {
@@ -750,27 +719,20 @@ static int max8998_pmic_probe(struct platform_device *pdev)
750719
gpio_direction_output(pdata->buck2_set3,
751720
max8998->buck2_idx & 0x1);
752721

753-
/* BUCK2 register 1 */
754-
i = 0;
755-
while (buck12_voltage_map_desc.min +
756-
buck12_voltage_map_desc.step*i
757-
< pdata->buck2_voltage1)
758-
i++;
759-
max8998->buck2_vol[0] = i;
760-
ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i);
761-
if (ret)
762-
goto err_out;
763-
764-
/* BUCK2 register 2 */
765-
i = 0;
766-
while (buck12_voltage_map_desc.min +
767-
buck12_voltage_map_desc.step*i
768-
< pdata->buck2_voltage2)
769-
i++;
770-
max8998->buck2_vol[1] = i;
771-
ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i);
772-
if (ret)
773-
goto err_out;
722+
/* Set predefined values for BUCK2 registers */
723+
for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) {
724+
i = 0;
725+
while (buck12_voltage_map_desc.min +
726+
buck12_voltage_map_desc.step*i
727+
< pdata->buck2_voltage[v])
728+
i++;
729+
730+
max8998->buck2_vol[v] = i;
731+
ret = max8998_write_reg(i2c,
732+
MAX8998_REG_BUCK2_VOLTAGE1 + v, i);
733+
if (ret)
734+
goto err_out;
735+
}
774736
}
775737

776738
for (i = 0; i < pdata->num_regulators; i++) {

‎include/linux/mfd/max8998.h‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ struct max8998_regulator_data {
7373
* @buck_voltage_lock: Do NOT change the values of the following six
7474
* registers set by buck?_voltage?. The voltage of BUCK1/2 cannot
7575
* be other than the preset values.
76-
* @buck1_voltage1: BUCK1 DVS mode 1 voltage register
77-
* @buck1_voltage2: BUCK1 DVS mode 2 voltage register
78-
* @buck1_voltage3: BUCK1 DVS mode 3 voltage register
79-
* @buck1_voltage4: BUCK1 DVS mode 4 voltage register
80-
* @buck2_voltage1: BUCK2 DVS mode 1 voltage register
81-
* @buck2_voltage2: BUCK2 DVS mode 2 voltage register
76+
* @buck1_voltage: BUCK1 DVS mode 1 voltage registers
77+
* @buck2_voltage: BUCK2 DVS mode 2 voltage registers
8278
* @buck1_set1: BUCK1 gpio pin 1 to set output voltage
8379
* @buck1_set2: BUCK1 gpio pin 2 to set output voltage
8480
* @buck1_default_idx: Default for BUCK1 gpio pin 1, 2
@@ -103,12 +99,8 @@ struct max8998_platform_data {
10399
unsigned int irq_base;
104100
int ono;
105101
bool buck_voltage_lock;
106-
int buck1_voltage1;
107-
int buck1_voltage2;
108-
int buck1_voltage3;
109-
int buck1_voltage4;
110-
int buck2_voltage1;
111-
int buck2_voltage2;
102+
int buck1_voltage[4];
103+
int buck2_voltage[2];
112104
int buck1_set1;
113105
int buck1_set2;
114106
int buck1_default_idx;

0 commit comments

Comments
 (0)