aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/tps6507x-regulator.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/tps6507x-regulator.c')
-rw-r--r--drivers/regulator/tps6507x-regulator.c373
1 files changed, 161 insertions, 212 deletions
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 74841abcc9cc..14b4576281c5 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -22,68 +22,9 @@
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/regulator/driver.h> 23#include <linux/regulator/driver.h>
24#include <linux/regulator/machine.h> 24#include <linux/regulator/machine.h>
25#include <linux/i2c.h>
26#include <linux/delay.h> 25#include <linux/delay.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
28 27#include <linux/mfd/tps6507x.h>
29/* Register definitions */
30#define TPS6507X_REG_PPATH1 0X01
31#define TPS6507X_REG_INT 0X02
32#define TPS6507X_REG_CHGCONFIG0 0X03
33#define TPS6507X_REG_CHGCONFIG1 0X04
34#define TPS6507X_REG_CHGCONFIG2 0X05
35#define TPS6507X_REG_CHGCONFIG3 0X06
36#define TPS6507X_REG_REG_ADCONFIG 0X07
37#define TPS6507X_REG_TSCMODE 0X08
38#define TPS6507X_REG_ADRESULT_1 0X09
39#define TPS6507X_REG_ADRESULT_2 0X0A
40#define TPS6507X_REG_PGOOD 0X0B
41#define TPS6507X_REG_PGOODMASK 0X0C
42#define TPS6507X_REG_CON_CTRL1 0X0D
43#define TPS6507X_REG_CON_CTRL2 0X0E
44#define TPS6507X_REG_CON_CTRL3 0X0F
45#define TPS6507X_REG_DEFDCDC1 0X10
46#define TPS6507X_REG_DEFDCDC2_LOW 0X11
47#define TPS6507X_REG_DEFDCDC2_HIGH 0X12
48#define TPS6507X_REG_DEFDCDC3_LOW 0X13
49#define TPS6507X_REG_DEFDCDC3_HIGH 0X14
50#define TPS6507X_REG_DEFSLEW 0X15
51#define TPS6507X_REG_LDO_CTRL1 0X16
52#define TPS6507X_REG_DEFLDO2 0X17
53#define TPS6507X_REG_WLED_CTRL1 0X18
54#define TPS6507X_REG_WLED_CTRL2 0X19
55
56/* CON_CTRL1 bitfields */
57#define TPS6507X_CON_CTRL1_DCDC1_ENABLE BIT(4)
58#define TPS6507X_CON_CTRL1_DCDC2_ENABLE BIT(3)
59#define TPS6507X_CON_CTRL1_DCDC3_ENABLE BIT(2)
60#define TPS6507X_CON_CTRL1_LDO1_ENABLE BIT(1)
61#define TPS6507X_CON_CTRL1_LDO2_ENABLE BIT(0)
62
63/* DEFDCDC1 bitfields */
64#define TPS6507X_DEFDCDC1_DCDC1_EXT_ADJ_EN BIT(7)
65#define TPS6507X_DEFDCDC1_DCDC1_MASK 0X3F
66
67/* DEFDCDC2_LOW bitfields */
68#define TPS6507X_DEFDCDC2_LOW_DCDC2_MASK 0X3F
69
70/* DEFDCDC2_HIGH bitfields */
71#define TPS6507X_DEFDCDC2_HIGH_DCDC2_MASK 0X3F
72
73/* DEFDCDC3_LOW bitfields */
74#define TPS6507X_DEFDCDC3_LOW_DCDC3_MASK 0X3F
75
76/* DEFDCDC3_HIGH bitfields */
77#define TPS6507X_DEFDCDC3_HIGH_DCDC3_MASK 0X3F
78
79/* TPS6507X_REG_LDO_CTRL1 bitfields */
80#define TPS6507X_REG_LDO_CTRL1_LDO1_MASK 0X0F
81
82/* TPS6507X_REG_DEFLDO2 bitfields */
83#define TPS6507X_REG_DEFLDO2_LDO2_MASK 0X3F
84
85/* VDCDC MASK */
86#define TPS6507X_DEFDCDCX_DCDC_MASK 0X3F
87 28
88/* DCDC's */ 29/* DCDC's */
89#define TPS6507X_DCDC_1 0 30#define TPS6507X_DCDC_1 0
@@ -162,101 +103,146 @@ struct tps_info {
162 const u16 *table; 103 const u16 *table;
163}; 104};
164 105
165struct tps_pmic { 106static const struct tps_info tps6507x_pmic_regs[] = {
107 {
108 .name = "VDCDC1",
109 .min_uV = 725000,
110 .max_uV = 3300000,
111 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
112 .table = VDCDCx_VSEL_table,
113 },
114 {
115 .name = "VDCDC2",
116 .min_uV = 725000,
117 .max_uV = 3300000,
118 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
119 .table = VDCDCx_VSEL_table,
120 },
121 {
122 .name = "VDCDC3",
123 .min_uV = 725000,
124 .max_uV = 3300000,
125 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
126 .table = VDCDCx_VSEL_table,
127 },
128 {
129 .name = "LDO1",
130 .min_uV = 1000000,
131 .max_uV = 3300000,
132 .table_len = ARRAY_SIZE(LDO1_VSEL_table),
133 .table = LDO1_VSEL_table,
134 },
135 {
136 .name = "LDO2",
137 .min_uV = 725000,
138 .max_uV = 3300000,
139 .table_len = ARRAY_SIZE(LDO2_VSEL_table),
140 .table = LDO2_VSEL_table,
141 },
142};
143
144struct tps6507x_pmic {
166 struct regulator_desc desc[TPS6507X_NUM_REGULATOR]; 145 struct regulator_desc desc[TPS6507X_NUM_REGULATOR];
167 struct i2c_client *client; 146 struct tps6507x_dev *mfd;
168 struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR]; 147 struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR];
169 const struct tps_info *info[TPS6507X_NUM_REGULATOR]; 148 const struct tps_info *info[TPS6507X_NUM_REGULATOR];
170 struct mutex io_lock; 149 struct mutex io_lock;
171}; 150};
172 151static inline int tps6507x_pmic_read(struct tps6507x_pmic *tps, u8 reg)
173static inline int tps_6507x_read(struct tps_pmic *tps, u8 reg)
174{ 152{
175 return i2c_smbus_read_byte_data(tps->client, reg); 153 u8 val;
154 int err;
155
156 err = tps->mfd->read_dev(tps->mfd, reg, 1, &val);
157
158 if (err)
159 return err;
160
161 return val;
176} 162}
177 163
178static inline int tps_6507x_write(struct tps_pmic *tps, u8 reg, u8 val) 164static inline int tps6507x_pmic_write(struct tps6507x_pmic *tps, u8 reg, u8 val)
179{ 165{
180 return i2c_smbus_write_byte_data(tps->client, reg, val); 166 return tps->mfd->write_dev(tps->mfd, reg, 1, &val);
181} 167}
182 168
183static int tps_6507x_set_bits(struct tps_pmic *tps, u8 reg, u8 mask) 169static int tps6507x_pmic_set_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
184{ 170{
185 int err, data; 171 int err, data;
186 172
187 mutex_lock(&tps->io_lock); 173 mutex_lock(&tps->io_lock);
188 174
189 data = tps_6507x_read(tps, reg); 175 data = tps6507x_pmic_read(tps, reg);
190 if (data < 0) { 176 if (data < 0) {
191 dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 177 dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
192 err = data; 178 err = data;
193 goto out; 179 goto out;
194 } 180 }
195 181
196 data |= mask; 182 data |= mask;
197 err = tps_6507x_write(tps, reg, data); 183 err = tps6507x_pmic_write(tps, reg, data);
198 if (err) 184 if (err)
199 dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 185 dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
200 186
201out: 187out:
202 mutex_unlock(&tps->io_lock); 188 mutex_unlock(&tps->io_lock);
203 return err; 189 return err;
204} 190}
205 191
206static int tps_6507x_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask) 192static int tps6507x_pmic_clear_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
207{ 193{
208 int err, data; 194 int err, data;
209 195
210 mutex_lock(&tps->io_lock); 196 mutex_lock(&tps->io_lock);
211 197
212 data = tps_6507x_read(tps, reg); 198 data = tps6507x_pmic_read(tps, reg);
213 if (data < 0) { 199 if (data < 0) {
214 dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 200 dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
215 err = data; 201 err = data;
216 goto out; 202 goto out;
217 } 203 }
218 204
219 data &= ~mask; 205 data &= ~mask;
220 err = tps_6507x_write(tps, reg, data); 206 err = tps6507x_pmic_write(tps, reg, data);
221 if (err) 207 if (err)
222 dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 208 dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
223 209
224out: 210out:
225 mutex_unlock(&tps->io_lock); 211 mutex_unlock(&tps->io_lock);
226 return err; 212 return err;
227} 213}
228 214
229static int tps_6507x_reg_read(struct tps_pmic *tps, u8 reg) 215static int tps6507x_pmic_reg_read(struct tps6507x_pmic *tps, u8 reg)
230{ 216{
231 int data; 217 int data;
232 218
233 mutex_lock(&tps->io_lock); 219 mutex_lock(&tps->io_lock);
234 220
235 data = tps_6507x_read(tps, reg); 221 data = tps6507x_pmic_read(tps, reg);
236 if (data < 0) 222 if (data < 0)
237 dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 223 dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
238 224
239 mutex_unlock(&tps->io_lock); 225 mutex_unlock(&tps->io_lock);
240 return data; 226 return data;
241} 227}
242 228
243static int tps_6507x_reg_write(struct tps_pmic *tps, u8 reg, u8 val) 229static int tps6507x_pmic_reg_write(struct tps6507x_pmic *tps, u8 reg, u8 val)
244{ 230{
245 int err; 231 int err;
246 232
247 mutex_lock(&tps->io_lock); 233 mutex_lock(&tps->io_lock);
248 234
249 err = tps_6507x_write(tps, reg, val); 235 err = tps6507x_pmic_write(tps, reg, val);
250 if (err < 0) 236 if (err < 0)
251 dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 237 dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
252 238
253 mutex_unlock(&tps->io_lock); 239 mutex_unlock(&tps->io_lock);
254 return err; 240 return err;
255} 241}
256 242
257static int tps6507x_dcdc_is_enabled(struct regulator_dev *dev) 243static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev)
258{ 244{
259 struct tps_pmic *tps = rdev_get_drvdata(dev); 245 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
260 int data, dcdc = rdev_get_id(dev); 246 int data, dcdc = rdev_get_id(dev);
261 u8 shift; 247 u8 shift;
262 248
@@ -264,7 +250,7 @@ static int tps6507x_dcdc_is_enabled(struct regulator_dev *dev)
264 return -EINVAL; 250 return -EINVAL;
265 251
266 shift = TPS6507X_MAX_REG_ID - dcdc; 252 shift = TPS6507X_MAX_REG_ID - dcdc;
267 data = tps_6507x_reg_read(tps, TPS6507X_REG_CON_CTRL1); 253 data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1);
268 254
269 if (data < 0) 255 if (data < 0)
270 return data; 256 return data;
@@ -272,9 +258,9 @@ static int tps6507x_dcdc_is_enabled(struct regulator_dev *dev)
272 return (data & 1<<shift) ? 1 : 0; 258 return (data & 1<<shift) ? 1 : 0;
273} 259}
274 260
275static int tps6507x_ldo_is_enabled(struct regulator_dev *dev) 261static int tps6507x_pmic_ldo_is_enabled(struct regulator_dev *dev)
276{ 262{
277 struct tps_pmic *tps = rdev_get_drvdata(dev); 263 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
278 int data, ldo = rdev_get_id(dev); 264 int data, ldo = rdev_get_id(dev);
279 u8 shift; 265 u8 shift;
280 266
@@ -282,7 +268,7 @@ static int tps6507x_ldo_is_enabled(struct regulator_dev *dev)
282 return -EINVAL; 268 return -EINVAL;
283 269
284 shift = TPS6507X_MAX_REG_ID - ldo; 270 shift = TPS6507X_MAX_REG_ID - ldo;
285 data = tps_6507x_reg_read(tps, TPS6507X_REG_CON_CTRL1); 271 data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1);
286 272
287 if (data < 0) 273 if (data < 0)
288 return data; 274 return data;
@@ -290,9 +276,9 @@ static int tps6507x_ldo_is_enabled(struct regulator_dev *dev)
290 return (data & 1<<shift) ? 1 : 0; 276 return (data & 1<<shift) ? 1 : 0;
291} 277}
292 278
293static int tps6507x_dcdc_enable(struct regulator_dev *dev) 279static int tps6507x_pmic_dcdc_enable(struct regulator_dev *dev)
294{ 280{
295 struct tps_pmic *tps = rdev_get_drvdata(dev); 281 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
296 int dcdc = rdev_get_id(dev); 282 int dcdc = rdev_get_id(dev);
297 u8 shift; 283 u8 shift;
298 284
@@ -300,12 +286,12 @@ static int tps6507x_dcdc_enable(struct regulator_dev *dev)
300 return -EINVAL; 286 return -EINVAL;
301 287
302 shift = TPS6507X_MAX_REG_ID - dcdc; 288 shift = TPS6507X_MAX_REG_ID - dcdc;
303 return tps_6507x_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 289 return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift);
304} 290}
305 291
306static int tps6507x_dcdc_disable(struct regulator_dev *dev) 292static int tps6507x_pmic_dcdc_disable(struct regulator_dev *dev)
307{ 293{
308 struct tps_pmic *tps = rdev_get_drvdata(dev); 294 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
309 int dcdc = rdev_get_id(dev); 295 int dcdc = rdev_get_id(dev);
310 u8 shift; 296 u8 shift;
311 297
@@ -313,12 +299,13 @@ static int tps6507x_dcdc_disable(struct regulator_dev *dev)
313 return -EINVAL; 299 return -EINVAL;
314 300
315 shift = TPS6507X_MAX_REG_ID - dcdc; 301 shift = TPS6507X_MAX_REG_ID - dcdc;
316 return tps_6507x_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 302 return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1,
303 1 << shift);
317} 304}
318 305
319static int tps6507x_ldo_enable(struct regulator_dev *dev) 306static int tps6507x_pmic_ldo_enable(struct regulator_dev *dev)
320{ 307{
321 struct tps_pmic *tps = rdev_get_drvdata(dev); 308 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
322 int ldo = rdev_get_id(dev); 309 int ldo = rdev_get_id(dev);
323 u8 shift; 310 u8 shift;
324 311
@@ -326,12 +313,12 @@ static int tps6507x_ldo_enable(struct regulator_dev *dev)
326 return -EINVAL; 313 return -EINVAL;
327 314
328 shift = TPS6507X_MAX_REG_ID - ldo; 315 shift = TPS6507X_MAX_REG_ID - ldo;
329 return tps_6507x_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 316 return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift);
330} 317}
331 318
332static int tps6507x_ldo_disable(struct regulator_dev *dev) 319static int tps6507x_pmic_ldo_disable(struct regulator_dev *dev)
333{ 320{
334 struct tps_pmic *tps = rdev_get_drvdata(dev); 321 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
335 int ldo = rdev_get_id(dev); 322 int ldo = rdev_get_id(dev);
336 u8 shift; 323 u8 shift;
337 324
@@ -339,12 +326,13 @@ static int tps6507x_ldo_disable(struct regulator_dev *dev)
339 return -EINVAL; 326 return -EINVAL;
340 327
341 shift = TPS6507X_MAX_REG_ID - ldo; 328 shift = TPS6507X_MAX_REG_ID - ldo;
342 return tps_6507x_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 329 return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1,
330 1 << shift);
343} 331}
344 332
345static int tps6507x_dcdc_get_voltage(struct regulator_dev *dev) 333static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev)
346{ 334{
347 struct tps_pmic *tps = rdev_get_drvdata(dev); 335 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
348 int data, dcdc = rdev_get_id(dev); 336 int data, dcdc = rdev_get_id(dev);
349 u8 reg; 337 u8 reg;
350 338
@@ -362,7 +350,7 @@ static int tps6507x_dcdc_get_voltage(struct regulator_dev *dev)
362 return -EINVAL; 350 return -EINVAL;
363 } 351 }
364 352
365 data = tps_6507x_reg_read(tps, reg); 353 data = tps6507x_pmic_reg_read(tps, reg);
366 if (data < 0) 354 if (data < 0)
367 return data; 355 return data;
368 356
@@ -370,10 +358,10 @@ static int tps6507x_dcdc_get_voltage(struct regulator_dev *dev)
370 return tps->info[dcdc]->table[data] * 1000; 358 return tps->info[dcdc]->table[data] * 1000;
371} 359}
372 360
373static int tps6507x_dcdc_set_voltage(struct regulator_dev *dev, 361static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev,
374 int min_uV, int max_uV) 362 int min_uV, int max_uV)
375{ 363{
376 struct tps_pmic *tps = rdev_get_drvdata(dev); 364 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
377 int data, vsel, dcdc = rdev_get_id(dev); 365 int data, vsel, dcdc = rdev_get_id(dev);
378 u8 reg; 366 u8 reg;
379 367
@@ -411,19 +399,19 @@ static int tps6507x_dcdc_set_voltage(struct regulator_dev *dev,
411 if (vsel == tps->info[dcdc]->table_len) 399 if (vsel == tps->info[dcdc]->table_len)
412 return -EINVAL; 400 return -EINVAL;
413 401
414 data = tps_6507x_reg_read(tps, reg); 402 data = tps6507x_pmic_reg_read(tps, reg);
415 if (data < 0) 403 if (data < 0)
416 return data; 404 return data;
417 405
418 data &= ~TPS6507X_DEFDCDCX_DCDC_MASK; 406 data &= ~TPS6507X_DEFDCDCX_DCDC_MASK;
419 data |= vsel; 407 data |= vsel;
420 408
421 return tps_6507x_reg_write(tps, reg, data); 409 return tps6507x_pmic_reg_write(tps, reg, data);
422} 410}
423 411
424static int tps6507x_ldo_get_voltage(struct regulator_dev *dev) 412static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev)
425{ 413{
426 struct tps_pmic *tps = rdev_get_drvdata(dev); 414 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
427 int data, ldo = rdev_get_id(dev); 415 int data, ldo = rdev_get_id(dev);
428 u8 reg, mask; 416 u8 reg, mask;
429 417
@@ -437,7 +425,7 @@ static int tps6507x_ldo_get_voltage(struct regulator_dev *dev)
437 TPS6507X_REG_DEFLDO2_LDO2_MASK); 425 TPS6507X_REG_DEFLDO2_LDO2_MASK);
438 } 426 }
439 427
440 data = tps_6507x_reg_read(tps, reg); 428 data = tps6507x_pmic_reg_read(tps, reg);
441 if (data < 0) 429 if (data < 0)
442 return data; 430 return data;
443 431
@@ -445,10 +433,10 @@ static int tps6507x_ldo_get_voltage(struct regulator_dev *dev)
445 return tps->info[ldo]->table[data] * 1000; 433 return tps->info[ldo]->table[data] * 1000;
446} 434}
447 435
448static int tps6507x_ldo_set_voltage(struct regulator_dev *dev, 436static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
449 int min_uV, int max_uV) 437 int min_uV, int max_uV)
450{ 438{
451 struct tps_pmic *tps = rdev_get_drvdata(dev); 439 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
452 int data, vsel, ldo = rdev_get_id(dev); 440 int data, vsel, ldo = rdev_get_id(dev);
453 u8 reg, mask; 441 u8 reg, mask;
454 442
@@ -479,20 +467,20 @@ static int tps6507x_ldo_set_voltage(struct regulator_dev *dev,
479 if (vsel == tps->info[ldo]->table_len) 467 if (vsel == tps->info[ldo]->table_len)
480 return -EINVAL; 468 return -EINVAL;
481 469
482 data = tps_6507x_reg_read(tps, reg); 470 data = tps6507x_pmic_reg_read(tps, reg);
483 if (data < 0) 471 if (data < 0)
484 return data; 472 return data;
485 473
486 data &= ~mask; 474 data &= ~mask;
487 data |= vsel; 475 data |= vsel;
488 476
489 return tps_6507x_reg_write(tps, reg, data); 477 return tps6507x_pmic_reg_write(tps, reg, data);
490} 478}
491 479
492static int tps6507x_dcdc_list_voltage(struct regulator_dev *dev, 480static int tps6507x_pmic_dcdc_list_voltage(struct regulator_dev *dev,
493 unsigned selector) 481 unsigned selector)
494{ 482{
495 struct tps_pmic *tps = rdev_get_drvdata(dev); 483 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
496 int dcdc = rdev_get_id(dev); 484 int dcdc = rdev_get_id(dev);
497 485
498 if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 486 if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3)
@@ -504,10 +492,10 @@ static int tps6507x_dcdc_list_voltage(struct regulator_dev *dev,
504 return tps->info[dcdc]->table[selector] * 1000; 492 return tps->info[dcdc]->table[selector] * 1000;
505} 493}
506 494
507static int tps6507x_ldo_list_voltage(struct regulator_dev *dev, 495static int tps6507x_pmic_ldo_list_voltage(struct regulator_dev *dev,
508 unsigned selector) 496 unsigned selector)
509{ 497{
510 struct tps_pmic *tps = rdev_get_drvdata(dev); 498 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
511 int ldo = rdev_get_id(dev); 499 int ldo = rdev_get_id(dev);
512 500
513 if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 501 if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
@@ -520,47 +508,54 @@ static int tps6507x_ldo_list_voltage(struct regulator_dev *dev,
520} 508}
521 509
522/* Operations permitted on VDCDCx */ 510/* Operations permitted on VDCDCx */
523static struct regulator_ops tps6507x_dcdc_ops = { 511static struct regulator_ops tps6507x_pmic_dcdc_ops = {
524 .is_enabled = tps6507x_dcdc_is_enabled, 512 .is_enabled = tps6507x_pmic_dcdc_is_enabled,
525 .enable = tps6507x_dcdc_enable, 513 .enable = tps6507x_pmic_dcdc_enable,
526 .disable = tps6507x_dcdc_disable, 514 .disable = tps6507x_pmic_dcdc_disable,
527 .get_voltage = tps6507x_dcdc_get_voltage, 515 .get_voltage = tps6507x_pmic_dcdc_get_voltage,
528 .set_voltage = tps6507x_dcdc_set_voltage, 516 .set_voltage = tps6507x_pmic_dcdc_set_voltage,
529 .list_voltage = tps6507x_dcdc_list_voltage, 517 .list_voltage = tps6507x_pmic_dcdc_list_voltage,
530}; 518};
531 519
532/* Operations permitted on LDOx */ 520/* Operations permitted on LDOx */
533static struct regulator_ops tps6507x_ldo_ops = { 521static struct regulator_ops tps6507x_pmic_ldo_ops = {
534 .is_enabled = tps6507x_ldo_is_enabled, 522 .is_enabled = tps6507x_pmic_ldo_is_enabled,
535 .enable = tps6507x_ldo_enable, 523 .enable = tps6507x_pmic_ldo_enable,
536 .disable = tps6507x_ldo_disable, 524 .disable = tps6507x_pmic_ldo_disable,
537 .get_voltage = tps6507x_ldo_get_voltage, 525 .get_voltage = tps6507x_pmic_ldo_get_voltage,
538 .set_voltage = tps6507x_ldo_set_voltage, 526 .set_voltage = tps6507x_pmic_ldo_set_voltage,
539 .list_voltage = tps6507x_ldo_list_voltage, 527 .list_voltage = tps6507x_pmic_ldo_list_voltage,
540}; 528};
541 529
542static int __devinit tps_6507x_probe(struct i2c_client *client, 530static __devinit
543 const struct i2c_device_id *id) 531int tps6507x_pmic_probe(struct platform_device *pdev)
544{ 532{
533 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
545 static int desc_id; 534 static int desc_id;
546 const struct tps_info *info = (void *)id->driver_data; 535 const struct tps_info *info = &tps6507x_pmic_regs[0];
547 struct regulator_init_data *init_data; 536 struct regulator_init_data *init_data;
548 struct regulator_dev *rdev; 537 struct regulator_dev *rdev;
549 struct tps_pmic *tps; 538 struct tps6507x_pmic *tps;
539 struct tps6507x_board *tps_board;
550 int i; 540 int i;
551 int error; 541 int error;
552 542
553 if (!i2c_check_functionality(client->adapter, 543 /**
554 I2C_FUNC_SMBUS_BYTE_DATA)) 544 * tps_board points to pmic related constants
555 return -EIO; 545 * coming from the board-evm file.
546 */
547
548 tps_board = dev_get_platdata(tps6507x_dev->dev);
549 if (!tps_board)
550 return -EINVAL;
556 551
557 /** 552 /**
558 * init_data points to array of regulator_init structures 553 * init_data points to array of regulator_init structures
559 * coming from the board-evm file. 554 * coming from the board-evm file.
560 */ 555 */
561 init_data = client->dev.platform_data; 556 init_data = tps_board->tps6507x_pmic_init_data;
562 if (!init_data) 557 if (!init_data)
563 return -EIO; 558 return -EINVAL;
564 559
565 tps = kzalloc(sizeof(*tps), GFP_KERNEL); 560 tps = kzalloc(sizeof(*tps), GFP_KERNEL);
566 if (!tps) 561 if (!tps)
@@ -569,7 +564,7 @@ static int __devinit tps_6507x_probe(struct i2c_client *client,
569 mutex_init(&tps->io_lock); 564 mutex_init(&tps->io_lock);
570 565
571 /* common for all regulators */ 566 /* common for all regulators */
572 tps->client = client; 567 tps->mfd = tps6507x_dev;
573 568
574 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) { 569 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
575 /* Register the regulators */ 570 /* Register the regulators */
@@ -578,15 +573,16 @@ static int __devinit tps_6507x_probe(struct i2c_client *client,
578 tps->desc[i].id = desc_id++; 573 tps->desc[i].id = desc_id++;
579 tps->desc[i].n_voltages = num_voltages[i]; 574 tps->desc[i].n_voltages = num_voltages[i];
580 tps->desc[i].ops = (i > TPS6507X_DCDC_3 ? 575 tps->desc[i].ops = (i > TPS6507X_DCDC_3 ?
581 &tps6507x_ldo_ops : &tps6507x_dcdc_ops); 576 &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops);
582 tps->desc[i].type = REGULATOR_VOLTAGE; 577 tps->desc[i].type = REGULATOR_VOLTAGE;
583 tps->desc[i].owner = THIS_MODULE; 578 tps->desc[i].owner = THIS_MODULE;
584 579
585 rdev = regulator_register(&tps->desc[i], 580 rdev = regulator_register(&tps->desc[i],
586 &client->dev, init_data, tps); 581 tps6507x_dev->dev, init_data, tps);
587 if (IS_ERR(rdev)) { 582 if (IS_ERR(rdev)) {
588 dev_err(&client->dev, "failed to register %s\n", 583 dev_err(tps6507x_dev->dev,
589 id->name); 584 "failed to register %s regulator\n",
585 pdev->name);
590 error = PTR_ERR(rdev); 586 error = PTR_ERR(rdev);
591 goto fail; 587 goto fail;
592 } 588 }
@@ -595,7 +591,7 @@ static int __devinit tps_6507x_probe(struct i2c_client *client,
595 tps->rdev[i] = rdev; 591 tps->rdev[i] = rdev;
596 } 592 }
597 593
598 i2c_set_clientdata(client, tps); 594 tps6507x_dev->pmic = tps;
599 595
600 return 0; 596 return 0;
601 597
@@ -608,19 +604,17 @@ fail:
608} 604}
609 605
610/** 606/**
611 * tps_6507x_remove - TPS6507x driver i2c remove handler 607 * tps6507x_remove - TPS6507x driver i2c remove handler
612 * @client: i2c driver client device structure 608 * @client: i2c driver client device structure
613 * 609 *
614 * Unregister TPS driver as an i2c client device driver 610 * Unregister TPS driver as an i2c client device driver
615 */ 611 */
616static int __devexit tps_6507x_remove(struct i2c_client *client) 612static int __devexit tps6507x_pmic_remove(struct platform_device *pdev)
617{ 613{
618 struct tps_pmic *tps = i2c_get_clientdata(client); 614 struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
615 struct tps6507x_pmic *tps = tps6507x_dev->pmic;
619 int i; 616 int i;
620 617
621 /* clear the client data in i2c */
622 i2c_set_clientdata(client, NULL);
623
624 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) 618 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
625 regulator_unregister(tps->rdev[i]); 619 regulator_unregister(tps->rdev[i]);
626 620
@@ -629,83 +623,38 @@ static int __devexit tps_6507x_remove(struct i2c_client *client)
629 return 0; 623 return 0;
630} 624}
631 625
632static const struct tps_info tps6507x_regs[] = { 626static struct platform_driver tps6507x_pmic_driver = {
633 {
634 .name = "VDCDC1",
635 .min_uV = 725000,
636 .max_uV = 3300000,
637 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
638 .table = VDCDCx_VSEL_table,
639 },
640 {
641 .name = "VDCDC2",
642 .min_uV = 725000,
643 .max_uV = 3300000,
644 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
645 .table = VDCDCx_VSEL_table,
646 },
647 {
648 .name = "VDCDC3",
649 .min_uV = 725000,
650 .max_uV = 3300000,
651 .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
652 .table = VDCDCx_VSEL_table,
653 },
654 {
655 .name = "LDO1",
656 .min_uV = 1000000,
657 .max_uV = 3300000,
658 .table_len = ARRAY_SIZE(LDO1_VSEL_table),
659 .table = LDO1_VSEL_table,
660 },
661 {
662 .name = "LDO2",
663 .min_uV = 725000,
664 .max_uV = 3300000,
665 .table_len = ARRAY_SIZE(LDO2_VSEL_table),
666 .table = LDO2_VSEL_table,
667 },
668};
669
670static const struct i2c_device_id tps_6507x_id[] = {
671 {.name = "tps6507x",
672 .driver_data = (unsigned long) tps6507x_regs,},
673 { },
674};
675MODULE_DEVICE_TABLE(i2c, tps_6507x_id);
676
677static struct i2c_driver tps_6507x_i2c_driver = {
678 .driver = { 627 .driver = {
679 .name = "tps6507x", 628 .name = "tps6507x-pmic",
680 .owner = THIS_MODULE, 629 .owner = THIS_MODULE,
681 }, 630 },
682 .probe = tps_6507x_probe, 631 .probe = tps6507x_pmic_probe,
683 .remove = __devexit_p(tps_6507x_remove), 632 .remove = __devexit_p(tps6507x_pmic_remove),
684 .id_table = tps_6507x_id,
685}; 633};
686 634
687/** 635/**
688 * tps_6507x_init 636 * tps6507x_pmic_init
689 * 637 *
690 * Module init function 638 * Module init function
691 */ 639 */
692static int __init tps_6507x_init(void) 640static int __init tps6507x_pmic_init(void)
693{ 641{
694 return i2c_add_driver(&tps_6507x_i2c_driver); 642 return platform_driver_register(&tps6507x_pmic_driver);
695} 643}
696subsys_initcall(tps_6507x_init); 644subsys_initcall(tps6507x_pmic_init);
697 645
698/** 646/**
699 * tps_6507x_cleanup 647 * tps6507x_pmic_cleanup
700 * 648 *
701 * Module exit function 649 * Module exit function
702 */ 650 */
703static void __exit tps_6507x_cleanup(void) 651static void __exit tps6507x_pmic_cleanup(void)
704{ 652{
705 i2c_del_driver(&tps_6507x_i2c_driver); 653 platform_driver_unregister(&tps6507x_pmic_driver);
706} 654}
707module_exit(tps_6507x_cleanup); 655module_exit(tps6507x_pmic_cleanup);
708 656
709MODULE_AUTHOR("Texas Instruments"); 657MODULE_AUTHOR("Texas Instruments");
710MODULE_DESCRIPTION("TPS6507x voltage regulator driver"); 658MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
711MODULE_LICENSE("GPL v2"); 659MODULE_LICENSE("GPL v2");
660MODULE_ALIAS("platform:tps6507x-pmic");