tps6507x-regulator.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * tps6507x-regulator.c
  3. *
  4. * Regulator driver for TPS65073 PMIC
  5. *
  6. * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.com/
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation version 2.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  13. * whether express or implied; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/err.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regulator/driver.h>
  23. #include <linux/regulator/machine.h>
  24. #include <linux/regulator/tps6507x.h>
  25. #include <linux/delay.h>
  26. #include <linux/slab.h>
  27. #include <linux/mfd/tps6507x.h>
  28. /* DCDC's */
  29. #define TPS6507X_DCDC_1 0
  30. #define TPS6507X_DCDC_2 1
  31. #define TPS6507X_DCDC_3 2
  32. /* LDOs */
  33. #define TPS6507X_LDO_1 3
  34. #define TPS6507X_LDO_2 4
  35. #define TPS6507X_MAX_REG_ID TPS6507X_LDO_2
  36. /* Number of step-down converters available */
  37. #define TPS6507X_NUM_DCDC 3
  38. /* Number of LDO voltage regulators available */
  39. #define TPS6507X_NUM_LDO 2
  40. /* Number of total regulators available */
  41. #define TPS6507X_NUM_REGULATOR (TPS6507X_NUM_DCDC + TPS6507X_NUM_LDO)
  42. /* Supported voltage values for regulators (in milliVolts) */
  43. static const u16 VDCDCx_VSEL_table[] = {
  44. 725, 750, 775, 800,
  45. 825, 850, 875, 900,
  46. 925, 950, 975, 1000,
  47. 1025, 1050, 1075, 1100,
  48. 1125, 1150, 1175, 1200,
  49. 1225, 1250, 1275, 1300,
  50. 1325, 1350, 1375, 1400,
  51. 1425, 1450, 1475, 1500,
  52. 1550, 1600, 1650, 1700,
  53. 1750, 1800, 1850, 1900,
  54. 1950, 2000, 2050, 2100,
  55. 2150, 2200, 2250, 2300,
  56. 2350, 2400, 2450, 2500,
  57. 2550, 2600, 2650, 2700,
  58. 2750, 2800, 2850, 2900,
  59. 3000, 3100, 3200, 3300,
  60. };
  61. static const u16 LDO1_VSEL_table[] = {
  62. 1000, 1100, 1200, 1250,
  63. 1300, 1350, 1400, 1500,
  64. 1600, 1800, 2500, 2750,
  65. 2800, 3000, 3100, 3300,
  66. };
  67. static const u16 LDO2_VSEL_table[] = {
  68. 725, 750, 775, 800,
  69. 825, 850, 875, 900,
  70. 925, 950, 975, 1000,
  71. 1025, 1050, 1075, 1100,
  72. 1125, 1150, 1175, 1200,
  73. 1225, 1250, 1275, 1300,
  74. 1325, 1350, 1375, 1400,
  75. 1425, 1450, 1475, 1500,
  76. 1550, 1600, 1650, 1700,
  77. 1750, 1800, 1850, 1900,
  78. 1950, 2000, 2050, 2100,
  79. 2150, 2200, 2250, 2300,
  80. 2350, 2400, 2450, 2500,
  81. 2550, 2600, 2650, 2700,
  82. 2750, 2800, 2850, 2900,
  83. 3000, 3100, 3200, 3300,
  84. };
  85. static unsigned int num_voltages[] = {ARRAY_SIZE(VDCDCx_VSEL_table),
  86. ARRAY_SIZE(VDCDCx_VSEL_table),
  87. ARRAY_SIZE(VDCDCx_VSEL_table),
  88. ARRAY_SIZE(LDO1_VSEL_table),
  89. ARRAY_SIZE(LDO2_VSEL_table)};
  90. struct tps_info {
  91. const char *name;
  92. unsigned min_uV;
  93. unsigned max_uV;
  94. u8 table_len;
  95. const u16 *table;
  96. /* Does DCDC high or the low register defines output voltage? */
  97. bool defdcdc_default;
  98. };
  99. static struct tps_info tps6507x_pmic_regs[] = {
  100. {
  101. .name = "VDCDC1",
  102. .min_uV = 725000,
  103. .max_uV = 3300000,
  104. .table_len = ARRAY_SIZE(VDCDCx_VSEL_table),
  105. .table = VDCDCx_VSEL_table,
  106. },
  107. {
  108. .name = "VDCDC2",
  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 = "VDCDC3",
  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 = "LDO1",
  123. .min_uV = 1000000,
  124. .max_uV = 3300000,
  125. .table_len = ARRAY_SIZE(LDO1_VSEL_table),
  126. .table = LDO1_VSEL_table,
  127. },
  128. {
  129. .name = "LDO2",
  130. .min_uV = 725000,
  131. .max_uV = 3300000,
  132. .table_len = ARRAY_SIZE(LDO2_VSEL_table),
  133. .table = LDO2_VSEL_table,
  134. },
  135. };
  136. struct tps6507x_pmic {
  137. struct regulator_desc desc[TPS6507X_NUM_REGULATOR];
  138. struct tps6507x_dev *mfd;
  139. struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR];
  140. struct tps_info *info[TPS6507X_NUM_REGULATOR];
  141. struct mutex io_lock;
  142. };
  143. static inline int tps6507x_pmic_read(struct tps6507x_pmic *tps, u8 reg)
  144. {
  145. u8 val;
  146. int err;
  147. err = tps->mfd->read_dev(tps->mfd, reg, 1, &val);
  148. if (err)
  149. return err;
  150. return val;
  151. }
  152. static inline int tps6507x_pmic_write(struct tps6507x_pmic *tps, u8 reg, u8 val)
  153. {
  154. return tps->mfd->write_dev(tps->mfd, reg, 1, &val);
  155. }
  156. static int tps6507x_pmic_set_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
  157. {
  158. int err, data;
  159. mutex_lock(&tps->io_lock);
  160. data = tps6507x_pmic_read(tps, reg);
  161. if (data < 0) {
  162. dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
  163. err = data;
  164. goto out;
  165. }
  166. data |= mask;
  167. err = tps6507x_pmic_write(tps, reg, data);
  168. if (err)
  169. dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
  170. out:
  171. mutex_unlock(&tps->io_lock);
  172. return err;
  173. }
  174. static int tps6507x_pmic_clear_bits(struct tps6507x_pmic *tps, u8 reg, u8 mask)
  175. {
  176. int err, data;
  177. mutex_lock(&tps->io_lock);
  178. data = tps6507x_pmic_read(tps, reg);
  179. if (data < 0) {
  180. dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
  181. err = data;
  182. goto out;
  183. }
  184. data &= ~mask;
  185. err = tps6507x_pmic_write(tps, reg, data);
  186. if (err)
  187. dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
  188. out:
  189. mutex_unlock(&tps->io_lock);
  190. return err;
  191. }
  192. static int tps6507x_pmic_reg_read(struct tps6507x_pmic *tps, u8 reg)
  193. {
  194. int data;
  195. mutex_lock(&tps->io_lock);
  196. data = tps6507x_pmic_read(tps, reg);
  197. if (data < 0)
  198. dev_err(tps->mfd->dev, "Read from reg 0x%x failed\n", reg);
  199. mutex_unlock(&tps->io_lock);
  200. return data;
  201. }
  202. static int tps6507x_pmic_reg_write(struct tps6507x_pmic *tps, u8 reg, u8 val)
  203. {
  204. int err;
  205. mutex_lock(&tps->io_lock);
  206. err = tps6507x_pmic_write(tps, reg, val);
  207. if (err < 0)
  208. dev_err(tps->mfd->dev, "Write for reg 0x%x failed\n", reg);
  209. mutex_unlock(&tps->io_lock);
  210. return err;
  211. }
  212. static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev)
  213. {
  214. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  215. int data, dcdc = rdev_get_id(dev);
  216. u8 shift;
  217. if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3)
  218. return -EINVAL;
  219. shift = TPS6507X_MAX_REG_ID - dcdc;
  220. data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1);
  221. if (data < 0)
  222. return data;
  223. else
  224. return (data & 1<<shift) ? 1 : 0;
  225. }
  226. static int tps6507x_pmic_ldo_is_enabled(struct regulator_dev *dev)
  227. {
  228. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  229. int data, ldo = rdev_get_id(dev);
  230. u8 shift;
  231. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  232. return -EINVAL;
  233. shift = TPS6507X_MAX_REG_ID - ldo;
  234. data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1);
  235. if (data < 0)
  236. return data;
  237. else
  238. return (data & 1<<shift) ? 1 : 0;
  239. }
  240. static int tps6507x_pmic_dcdc_enable(struct regulator_dev *dev)
  241. {
  242. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  243. int dcdc = rdev_get_id(dev);
  244. u8 shift;
  245. if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3)
  246. return -EINVAL;
  247. shift = TPS6507X_MAX_REG_ID - dcdc;
  248. return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift);
  249. }
  250. static int tps6507x_pmic_dcdc_disable(struct regulator_dev *dev)
  251. {
  252. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  253. int dcdc = rdev_get_id(dev);
  254. u8 shift;
  255. if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3)
  256. return -EINVAL;
  257. shift = TPS6507X_MAX_REG_ID - dcdc;
  258. return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1,
  259. 1 << shift);
  260. }
  261. static int tps6507x_pmic_ldo_enable(struct regulator_dev *dev)
  262. {
  263. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  264. int ldo = rdev_get_id(dev);
  265. u8 shift;
  266. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  267. return -EINVAL;
  268. shift = TPS6507X_MAX_REG_ID - ldo;
  269. return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift);
  270. }
  271. static int tps6507x_pmic_ldo_disable(struct regulator_dev *dev)
  272. {
  273. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  274. int ldo = rdev_get_id(dev);
  275. u8 shift;
  276. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  277. return -EINVAL;
  278. shift = TPS6507X_MAX_REG_ID - ldo;
  279. return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1,
  280. 1 << shift);
  281. }
  282. static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev)
  283. {
  284. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  285. int data, dcdc = rdev_get_id(dev);
  286. u8 reg;
  287. switch (dcdc) {
  288. case TPS6507X_DCDC_1:
  289. reg = TPS6507X_REG_DEFDCDC1;
  290. break;
  291. case TPS6507X_DCDC_2:
  292. if (tps->info[dcdc]->defdcdc_default)
  293. reg = TPS6507X_REG_DEFDCDC2_HIGH;
  294. else
  295. reg = TPS6507X_REG_DEFDCDC2_LOW;
  296. break;
  297. case TPS6507X_DCDC_3:
  298. if (tps->info[dcdc]->defdcdc_default)
  299. reg = TPS6507X_REG_DEFDCDC3_HIGH;
  300. else
  301. reg = TPS6507X_REG_DEFDCDC3_LOW;
  302. break;
  303. default:
  304. return -EINVAL;
  305. }
  306. data = tps6507x_pmic_reg_read(tps, reg);
  307. if (data < 0)
  308. return data;
  309. data &= TPS6507X_DEFDCDCX_DCDC_MASK;
  310. return tps->info[dcdc]->table[data] * 1000;
  311. }
  312. static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev,
  313. int min_uV, int max_uV,
  314. unsigned *selector)
  315. {
  316. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  317. int data, vsel, dcdc = rdev_get_id(dev);
  318. u8 reg;
  319. switch (dcdc) {
  320. case TPS6507X_DCDC_1:
  321. reg = TPS6507X_REG_DEFDCDC1;
  322. break;
  323. case TPS6507X_DCDC_2:
  324. if (tps->info[dcdc]->defdcdc_default)
  325. reg = TPS6507X_REG_DEFDCDC2_HIGH;
  326. else
  327. reg = TPS6507X_REG_DEFDCDC2_LOW;
  328. break;
  329. case TPS6507X_DCDC_3:
  330. if (tps->info[dcdc]->defdcdc_default)
  331. reg = TPS6507X_REG_DEFDCDC3_HIGH;
  332. else
  333. reg = TPS6507X_REG_DEFDCDC3_LOW;
  334. break;
  335. default:
  336. return -EINVAL;
  337. }
  338. if (min_uV < tps->info[dcdc]->min_uV
  339. || min_uV > tps->info[dcdc]->max_uV)
  340. return -EINVAL;
  341. if (max_uV < tps->info[dcdc]->min_uV
  342. || max_uV > tps->info[dcdc]->max_uV)
  343. return -EINVAL;
  344. for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) {
  345. int mV = tps->info[dcdc]->table[vsel];
  346. int uV = mV * 1000;
  347. /* Break at the first in-range value */
  348. if (min_uV <= uV && uV <= max_uV)
  349. break;
  350. }
  351. /* write to the register in case we found a match */
  352. if (vsel == tps->info[dcdc]->table_len)
  353. return -EINVAL;
  354. *selector = vsel;
  355. data = tps6507x_pmic_reg_read(tps, reg);
  356. if (data < 0)
  357. return data;
  358. data &= ~TPS6507X_DEFDCDCX_DCDC_MASK;
  359. data |= vsel;
  360. return tps6507x_pmic_reg_write(tps, reg, data);
  361. }
  362. static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev)
  363. {
  364. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  365. int data, ldo = rdev_get_id(dev);
  366. u8 reg, mask;
  367. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  368. return -EINVAL;
  369. else {
  370. reg = (ldo == TPS6507X_LDO_1 ?
  371. TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2);
  372. mask = (ldo == TPS6507X_LDO_1 ?
  373. TPS6507X_REG_LDO_CTRL1_LDO1_MASK :
  374. TPS6507X_REG_DEFLDO2_LDO2_MASK);
  375. }
  376. data = tps6507x_pmic_reg_read(tps, reg);
  377. if (data < 0)
  378. return data;
  379. data &= mask;
  380. return tps->info[ldo]->table[data] * 1000;
  381. }
  382. static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
  383. int min_uV, int max_uV,
  384. unsigned *selector)
  385. {
  386. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  387. int data, vsel, ldo = rdev_get_id(dev);
  388. u8 reg, mask;
  389. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  390. return -EINVAL;
  391. else {
  392. reg = (ldo == TPS6507X_LDO_1 ?
  393. TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2);
  394. mask = (ldo == TPS6507X_LDO_1 ?
  395. TPS6507X_REG_LDO_CTRL1_LDO1_MASK :
  396. TPS6507X_REG_DEFLDO2_LDO2_MASK);
  397. }
  398. if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV)
  399. return -EINVAL;
  400. if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV)
  401. return -EINVAL;
  402. for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) {
  403. int mV = tps->info[ldo]->table[vsel];
  404. int uV = mV * 1000;
  405. /* Break at the first in-range value */
  406. if (min_uV <= uV && uV <= max_uV)
  407. break;
  408. }
  409. if (vsel == tps->info[ldo]->table_len)
  410. return -EINVAL;
  411. *selector = vsel;
  412. data = tps6507x_pmic_reg_read(tps, reg);
  413. if (data < 0)
  414. return data;
  415. data &= ~mask;
  416. data |= vsel;
  417. return tps6507x_pmic_reg_write(tps, reg, data);
  418. }
  419. static int tps6507x_pmic_dcdc_list_voltage(struct regulator_dev *dev,
  420. unsigned selector)
  421. {
  422. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  423. int dcdc = rdev_get_id(dev);
  424. if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3)
  425. return -EINVAL;
  426. if (selector >= tps->info[dcdc]->table_len)
  427. return -EINVAL;
  428. else
  429. return tps->info[dcdc]->table[selector] * 1000;
  430. }
  431. static int tps6507x_pmic_ldo_list_voltage(struct regulator_dev *dev,
  432. unsigned selector)
  433. {
  434. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  435. int ldo = rdev_get_id(dev);
  436. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  437. return -EINVAL;
  438. if (selector >= tps->info[ldo]->table_len)
  439. return -EINVAL;
  440. else
  441. return tps->info[ldo]->table[selector] * 1000;
  442. }
  443. /* Operations permitted on VDCDCx */
  444. static struct regulator_ops tps6507x_pmic_dcdc_ops = {
  445. .is_enabled = tps6507x_pmic_dcdc_is_enabled,
  446. .enable = tps6507x_pmic_dcdc_enable,
  447. .disable = tps6507x_pmic_dcdc_disable,
  448. .get_voltage = tps6507x_pmic_dcdc_get_voltage,
  449. .set_voltage = tps6507x_pmic_dcdc_set_voltage,
  450. .list_voltage = tps6507x_pmic_dcdc_list_voltage,
  451. };
  452. /* Operations permitted on LDOx */
  453. static struct regulator_ops tps6507x_pmic_ldo_ops = {
  454. .is_enabled = tps6507x_pmic_ldo_is_enabled,
  455. .enable = tps6507x_pmic_ldo_enable,
  456. .disable = tps6507x_pmic_ldo_disable,
  457. .get_voltage = tps6507x_pmic_ldo_get_voltage,
  458. .set_voltage = tps6507x_pmic_ldo_set_voltage,
  459. .list_voltage = tps6507x_pmic_ldo_list_voltage,
  460. };
  461. static __devinit
  462. int tps6507x_pmic_probe(struct platform_device *pdev)
  463. {
  464. struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
  465. struct tps_info *info = &tps6507x_pmic_regs[0];
  466. struct regulator_init_data *init_data;
  467. struct regulator_dev *rdev;
  468. struct tps6507x_pmic *tps;
  469. struct tps6507x_board *tps_board;
  470. int i;
  471. int error;
  472. /**
  473. * tps_board points to pmic related constants
  474. * coming from the board-evm file.
  475. */
  476. tps_board = dev_get_platdata(tps6507x_dev->dev);
  477. if (!tps_board)
  478. return -EINVAL;
  479. /**
  480. * init_data points to array of regulator_init structures
  481. * coming from the board-evm file.
  482. */
  483. init_data = tps_board->tps6507x_pmic_init_data;
  484. if (!init_data)
  485. return -EINVAL;
  486. tps = kzalloc(sizeof(*tps), GFP_KERNEL);
  487. if (!tps)
  488. return -ENOMEM;
  489. mutex_init(&tps->io_lock);
  490. /* common for all regulators */
  491. tps->mfd = tps6507x_dev;
  492. for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
  493. /* Register the regulators */
  494. tps->info[i] = info;
  495. if (init_data->driver_data) {
  496. struct tps6507x_reg_platform_data *data =
  497. init_data->driver_data;
  498. tps->info[i]->defdcdc_default = data->defdcdc_default;
  499. }
  500. tps->desc[i].name = info->name;
  501. tps->desc[i].id = i;
  502. tps->desc[i].n_voltages = num_voltages[i];
  503. tps->desc[i].ops = (i > TPS6507X_DCDC_3 ?
  504. &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops);
  505. tps->desc[i].type = REGULATOR_VOLTAGE;
  506. tps->desc[i].owner = THIS_MODULE;
  507. rdev = regulator_register(&tps->desc[i],
  508. tps6507x_dev->dev, init_data, tps);
  509. if (IS_ERR(rdev)) {
  510. dev_err(tps6507x_dev->dev,
  511. "failed to register %s regulator\n",
  512. pdev->name);
  513. error = PTR_ERR(rdev);
  514. goto fail;
  515. }
  516. /* Save regulator for cleanup */
  517. tps->rdev[i] = rdev;
  518. }
  519. tps6507x_dev->pmic = tps;
  520. platform_set_drvdata(pdev, tps6507x_dev);
  521. return 0;
  522. fail:
  523. while (--i >= 0)
  524. regulator_unregister(tps->rdev[i]);
  525. kfree(tps);
  526. return error;
  527. }
  528. static int __devexit tps6507x_pmic_remove(struct platform_device *pdev)
  529. {
  530. struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
  531. struct tps6507x_pmic *tps = tps6507x_dev->pmic;
  532. int i;
  533. for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
  534. regulator_unregister(tps->rdev[i]);
  535. kfree(tps);
  536. return 0;
  537. }
  538. static struct platform_driver tps6507x_pmic_driver = {
  539. .driver = {
  540. .name = "tps6507x-pmic",
  541. .owner = THIS_MODULE,
  542. },
  543. .probe = tps6507x_pmic_probe,
  544. .remove = __devexit_p(tps6507x_pmic_remove),
  545. };
  546. /**
  547. * tps6507x_pmic_init
  548. *
  549. * Module init function
  550. */
  551. static int __init tps6507x_pmic_init(void)
  552. {
  553. return platform_driver_register(&tps6507x_pmic_driver);
  554. }
  555. subsys_initcall(tps6507x_pmic_init);
  556. /**
  557. * tps6507x_pmic_cleanup
  558. *
  559. * Module exit function
  560. */
  561. static void __exit tps6507x_pmic_cleanup(void)
  562. {
  563. platform_driver_unregister(&tps6507x_pmic_driver);
  564. }
  565. module_exit(tps6507x_pmic_cleanup);
  566. MODULE_AUTHOR("Texas Instruments");
  567. MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
  568. MODULE_LICENSE("GPL v2");
  569. MODULE_ALIAS("platform:tps6507x-pmic");