aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorPhilipp Zabel <philipp.zabel@gmail.com>2009-05-28 01:15:16 -0400
committerLiam Girdwood <lrg@slimlogic.co.uk>2009-06-15 06:18:26 -0400
commitb110a8fb242bc34e4b7686252899ce0fca956e2c (patch)
tree45a07fe5d288d269ddcdad7786bae1efe063cb6d /drivers/regulator
parent6113c3a5a63b8f0d5613b2a71cd1f5335a37b89a (diff)
regulator/max1586: support increased V3 voltage range
The V3 regulator can be configured with an external resistor connected to the feedback pin (R24 in the data sheet) to increase the voltage range. For example, hx4700 has R24 = 3.32 kOhm to achieve a maximum V3 voltage of 1.55 V which is needed for 624 MHz CPU frequency. Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/max1586.c71
1 files changed, 52 insertions, 19 deletions
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index bbbb55fcfe8c..92799f40c864 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -29,7 +29,6 @@
29 29
30#define MAX1586_V3_MIN_UV 700000 30#define MAX1586_V3_MIN_UV 700000
31#define MAX1586_V3_MAX_UV 1475000 31#define MAX1586_V3_MAX_UV 1475000
32#define MAX1586_V3_STEP_UV 25000
33 32
34#define MAX1586_V6_MIN_UV 0 33#define MAX1586_V6_MIN_UV 0
35#define MAX1586_V6_MAX_UV 3000000 34#define MAX1586_V6_MAX_UV 3000000
@@ -37,33 +36,52 @@
37#define I2C_V3_SELECT (0 << 5) 36#define I2C_V3_SELECT (0 << 5)
38#define I2C_V6_SELECT (1 << 5) 37#define I2C_V6_SELECT (1 << 5)
39 38
39struct max1586_data {
40 struct i2c_client *client;
41
42 /* min/max V3 voltage */
43 int min_uV;
44 int max_uV;
45
46 struct regulator_dev *rdev[0];
47};
48
40/* 49/*
41 * V3 voltage 50 * V3 voltage
42 * On I2C bus, sending a "x" byte to the max1586 means : 51 * On I2C bus, sending a "x" byte to the max1586 means :
43 * set V3 to 0.700V + (x & 0x1f) * 0.025V 52 * set V3 to 0.700V + (x & 0x1f) * 0.025V
53 * This voltage can be increased by external resistors
54 * R24 and R25=100kOhm as described in the data sheet.
55 * The gain is approximately: 1 + R24/R25 + R24/185.5kOhm
44 */ 56 */
45static int max1586_v3_calc_voltage(unsigned selector) 57static int max1586_v3_calc_voltage(struct max1586_data *max1586,
58 unsigned selector)
46{ 59{
47 return MAX1586_V3_MIN_UV + (MAX1586_V3_STEP_UV * selector); 60 unsigned range_uV = max1586->max_uV - max1586->min_uV;
61
62 return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL);
48} 63}
49 64
50static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV) 65static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV)
51{ 66{
52 struct i2c_client *client = rdev_get_drvdata(rdev); 67 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
68 struct i2c_client *client = max1586->client;
69 unsigned range_uV = max1586->max_uV - max1586->min_uV;
53 unsigned selector; 70 unsigned selector;
54 u8 v3_prog; 71 u8 v3_prog;
55 72
56 if (min_uV < MAX1586_V3_MIN_UV || min_uV > MAX1586_V3_MAX_UV) 73 if (min_uV > max1586->max_uV || max_uV < max1586->min_uV)
57 return -EINVAL;
58 if (max_uV < MAX1586_V3_MIN_UV || max_uV > MAX1586_V3_MAX_UV)
59 return -EINVAL; 74 return -EINVAL;
75 if (min_uV < max1586->min_uV)
76 min_uV = max1586->min_uV;
60 77
61 selector = (min_uV - MAX1586_V3_MIN_UV) / MAX1586_V3_STEP_UV; 78 selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL +
62 if (max1586_v3_calc_voltage(selector) > max_uV) 79 range_uV - 1) / range_uV;
80 if (max1586_v3_calc_voltage(max1586, selector) > max_uV)
63 return -EINVAL; 81 return -EINVAL;
64 82
65 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", 83 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
66 max1586_v3_calc_voltage(selector) / 1000); 84 max1586_v3_calc_voltage(max1586, selector) / 1000);
67 85
68 v3_prog = I2C_V3_SELECT | (u8) selector; 86 v3_prog = I2C_V3_SELECT | (u8) selector;
69 return i2c_smbus_write_byte(client, v3_prog); 87 return i2c_smbus_write_byte(client, v3_prog);
@@ -71,9 +89,11 @@ static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV)
71 89
72static int max1586_v3_list(struct regulator_dev *rdev, unsigned selector) 90static int max1586_v3_list(struct regulator_dev *rdev, unsigned selector)
73{ 91{
92 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
93
74 if (selector > MAX1586_V3_MAX_VSEL) 94 if (selector > MAX1586_V3_MAX_VSEL)
75 return -EINVAL; 95 return -EINVAL;
76 return max1586_v3_calc_voltage(selector); 96 return max1586_v3_calc_voltage(max1586, selector);
77} 97}
78 98
79/* 99/*
@@ -164,14 +184,25 @@ static int max1586_pmic_probe(struct i2c_client *client,
164{ 184{
165 struct regulator_dev **rdev; 185 struct regulator_dev **rdev;
166 struct max1586_platform_data *pdata = client->dev.platform_data; 186 struct max1586_platform_data *pdata = client->dev.platform_data;
167 int i, id, ret = 0; 187 struct max1586_data *max1586;
188 int i, id, ret = -ENOMEM;
189
190 max1586 = kzalloc(sizeof(struct max1586_data) +
191 sizeof(struct regulator_dev *) * (MAX1586_V6 + 1),
192 GFP_KERNEL);
193 if (!max1586)
194 goto out;
168 195
169 rdev = kzalloc(sizeof(struct regulator_dev *) * (MAX1586_V6 + 1), 196 max1586->client = client;
170 GFP_KERNEL);
171 if (!rdev)
172 return -ENOMEM;
173 197
174 ret = -EINVAL; 198 if (!pdata->v3_gain) {
199 ret = -EINVAL;
200 goto out_unmap;
201 }
202 max1586->min_uV = MAX1586_V3_MIN_UV * pdata->v3_gain / 1000000;
203 max1586->max_uV = MAX1586_V3_MAX_UV * pdata->v3_gain / 1000000;
204
205 rdev = max1586->rdev;
175 for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) { 206 for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) {
176 id = pdata->subdevs[i].id; 207 id = pdata->subdevs[i].id;
177 if (!pdata->subdevs[i].platform_data) 208 if (!pdata->subdevs[i].platform_data)
@@ -182,7 +213,7 @@ static int max1586_pmic_probe(struct i2c_client *client,
182 } 213 }
183 rdev[i] = regulator_register(&max1586_reg[id], &client->dev, 214 rdev[i] = regulator_register(&max1586_reg[id], &client->dev,
184 pdata->subdevs[i].platform_data, 215 pdata->subdevs[i].platform_data,
185 client); 216 max1586);
186 if (IS_ERR(rdev[i])) { 217 if (IS_ERR(rdev[i])) {
187 ret = PTR_ERR(rdev[i]); 218 ret = PTR_ERR(rdev[i]);
188 dev_err(&client->dev, "failed to register %s\n", 219 dev_err(&client->dev, "failed to register %s\n",
@@ -198,7 +229,9 @@ static int max1586_pmic_probe(struct i2c_client *client,
198err: 229err:
199 while (--i >= 0) 230 while (--i >= 0)
200 regulator_unregister(rdev[i]); 231 regulator_unregister(rdev[i]);
201 kfree(rdev); 232out_unmap:
233 kfree(max1586);
234out:
202 return ret; 235 return ret;
203} 236}
204 237