tps6507x-regulator.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. {
  315. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  316. int data, vsel, dcdc = rdev_get_id(dev);
  317. u8 reg;
  318. switch (dcdc) {
  319. case TPS6507X_DCDC_1:
  320. reg = TPS6507X_REG_DEFDCDC1;
  321. break;
  322. case TPS6507X_DCDC_2:
  323. if (tps->info[dcdc]->defdcdc_default)
  324. reg = TPS6507X_REG_DEFDCDC2_HIGH;
  325. else
  326. reg = TPS6507X_REG_DEFDCDC2_LOW;
  327. break;
  328. case TPS6507X_DCDC_3:
  329. if (tps->info[dcdc]->defdcdc_default)
  330. reg = TPS6507X_REG_DEFDCDC3_HIGH;
  331. else
  332. reg = TPS6507X_REG_DEFDCDC3_LOW;
  333. break;
  334. default:
  335. return -EINVAL;
  336. }
  337. if (min_uV < tps->info[dcdc]->min_uV
  338. || min_uV > tps->info[dcdc]->max_uV)
  339. return -EINVAL;
  340. if (max_uV < tps->info[dcdc]->min_uV
  341. || max_uV > tps->info[dcdc]->max_uV)
  342. return -EINVAL;
  343. for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) {
  344. int mV = tps->info[dcdc]->table[vsel];
  345. int uV = mV * 1000;
  346. /* Break at the first in-range value */
  347. if (min_uV <= uV && uV <= max_uV)
  348. break;
  349. }
  350. /* write to the register in case we found a match */
  351. if (vsel == tps->info[dcdc]->table_len)
  352. return -EINVAL;
  353. data = tps6507x_pmic_reg_read(tps, reg);
  354. if (data < 0)
  355. return data;
  356. data &= ~TPS6507X_DEFDCDCX_DCDC_MASK;
  357. data |= vsel;
  358. return tps6507x_pmic_reg_write(tps, reg, data);
  359. }
  360. static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev)
  361. {
  362. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  363. int data, ldo = rdev_get_id(dev);
  364. u8 reg, mask;
  365. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  366. return -EINVAL;
  367. else {
  368. reg = (ldo == TPS6507X_LDO_1 ?
  369. TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2);
  370. mask = (ldo == TPS6507X_LDO_1 ?
  371. TPS6507X_REG_LDO_CTRL1_LDO1_MASK :
  372. TPS6507X_REG_DEFLDO2_LDO2_MASK);
  373. }
  374. data = tps6507x_pmic_reg_read(tps, reg);
  375. if (data < 0)
  376. return data;
  377. data &= mask;
  378. return tps->info[ldo]->table[data] * 1000;
  379. }
  380. static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
  381. int min_uV, int max_uV)
  382. {
  383. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  384. int data, vsel, ldo = rdev_get_id(dev);
  385. u8 reg, mask;
  386. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  387. return -EINVAL;
  388. else {
  389. reg = (ldo == TPS6507X_LDO_1 ?
  390. TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2);
  391. mask = (ldo == TPS6507X_LDO_1 ?
  392. TPS6507X_REG_LDO_CTRL1_LDO1_MASK :
  393. TPS6507X_REG_DEFLDO2_LDO2_MASK);
  394. }
  395. if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV)
  396. return -EINVAL;
  397. if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV)
  398. return -EINVAL;
  399. for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) {
  400. int mV = tps->info[ldo]->table[vsel];
  401. int uV = mV * 1000;
  402. /* Break at the first in-range value */
  403. if (min_uV <= uV && uV <= max_uV)
  404. break;
  405. }
  406. if (vsel == tps->info[ldo]->table_len)
  407. return -EINVAL;
  408. data = tps6507x_pmic_reg_read(tps, reg);
  409. if (data < 0)
  410. return data;
  411. data &= ~mask;
  412. data |= vsel;
  413. return tps6507x_pmic_reg_write(tps, reg, data);
  414. }
  415. static int tps6507x_pmic_dcdc_list_voltage(struct regulator_dev *dev,
  416. unsigned selector)
  417. {
  418. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  419. int dcdc = rdev_get_id(dev);
  420. if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3)
  421. return -EINVAL;
  422. if (selector >= tps->info[dcdc]->table_len)
  423. return -EINVAL;
  424. else
  425. return tps->info[dcdc]->table[selector] * 1000;
  426. }
  427. static int tps6507x_pmic_ldo_list_voltage(struct regulator_dev *dev,
  428. unsigned selector)
  429. {
  430. struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
  431. int ldo = rdev_get_id(dev);
  432. if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2)
  433. return -EINVAL;
  434. if (selector >= tps->info[ldo]->table_len)
  435. return -EINVAL;
  436. else
  437. return tps->info[ldo]->table[selector] * 1000;
  438. }
  439. /* Operations permitted on VDCDCx */
  440. static struct regulator_ops tps6507x_pmic_dcdc_ops = {
  441. .is_enabled = tps6507x_pmic_dcdc_is_enabled,
  442. .enable = tps6507x_pmic_dcdc_enable,
  443. .disable = tps6507x_pmic_dcdc_disable,
  444. .get_voltage = tps6507x_pmic_dcdc_get_voltage,
  445. .set_voltage = tps6507x_pmic_dcdc_set_voltage,
  446. .list_voltage = tps6507x_pmic_dcdc_list_voltage,
  447. };
  448. /* Operations permitted on LDOx */
  449. static struct regulator_ops tps6507x_pmic_ldo_ops = {
  450. .is_enabled = tps6507x_pmic_ldo_is_enabled,
  451. .enable = tps6507x_pmic_ldo_enable,
  452. .disable = tps6507x_pmic_ldo_disable,
  453. .get_voltage = tps6507x_pmic_ldo_get_voltage,
  454. .set_voltage = tps6507x_pmic_ldo_set_voltage,
  455. .list_voltage = tps6507x_pmic_ldo_list_voltage,
  456. };
  457. static __devinit
  458. int tps6507x_pmic_probe(struct platform_device *pdev)
  459. {
  460. struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
  461. static int desc_id;
  462. struct tps_info *info = &tps6507x_pmic_regs[0];
  463. struct regulator_init_data *init_data;
  464. struct regulator_dev *rdev;
  465. struct tps6507x_pmic *tps;
  466. struct tps6507x_board *tps_board;
  467. int i;
  468. int error;
  469. /**
  470. * tps_board points to pmic related constants
  471. * coming from the board-evm file.
  472. */
  473. tps_board = dev_get_platdata(tps6507x_dev->dev);
  474. if (!tps_board)
  475. return -EINVAL;
  476. /**
  477. * init_data points to array of regulator_init structures
  478. * coming from the board-evm file.
  479. */
  480. init_data = tps_board->tps6507x_pmic_init_data;
  481. if (!init_data)
  482. return -EINVAL;
  483. tps = kzalloc(sizeof(*tps), GFP_KERNEL);
  484. if (!tps)
  485. return -ENOMEM;
  486. mutex_init(&tps->io_lock);
  487. /* common for all regulators */
  488. tps->mfd = tps6507x_dev;
  489. for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
  490. /* Register the regulators */
  491. tps->info[i] = info;
  492. if (init_data->driver_data) {
  493. struct tps6507x_reg_platform_data *data =
  494. init_data->driver_data;
  495. tps->info[i]->defdcdc_default = data->defdcdc_default;
  496. }
  497. tps->desc[i].name = info->name;
  498. tps->desc[i].id = desc_id++;
  499. tps->desc[i].n_voltages = num_voltages[i];
  500. tps->desc[i].ops = (i > TPS6507X_DCDC_3 ?
  501. &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops);
  502. tps->desc[i].type = REGULATOR_VOLTAGE;
  503. tps->desc[i].owner = THIS_MODULE;
  504. rdev = regulator_register(&tps->desc[i],
  505. tps6507x_dev->dev, init_data, tps);
  506. if (IS_ERR(rdev)) {
  507. dev_err(tps6507x_dev->dev,
  508. "failed to register %s regulator\n",
  509. pdev->name);
  510. error = PTR_ERR(rdev);
  511. goto fail;
  512. }
  513. /* Save regulator for cleanup */
  514. tps->rdev[i] = rdev;
  515. }
  516. tps6507x_dev->pmic = tps;
  517. platform_set_drvdata(pdev, tps6507x_dev);
  518. return 0;
  519. fail:
  520. while (--i >= 0)
  521. regulator_unregister(tps->rdev[i]);
  522. kfree(tps);
  523. return error;
  524. }
  525. static int __devexit tps6507x_pmic_remove(struct platform_device *pdev)
  526. {
  527. struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
  528. struct tps6507x_pmic *tps = tps6507x_dev->pmic;
  529. int i;
  530. for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
  531. regulator_unregister(tps->rdev[i]);
  532. kfree(tps);
  533. return 0;
  534. }
  535. static struct platform_driver tps6507x_pmic_driver = {
  536. .driver = {
  537. .name = "tps6507x-pmic",
  538. .owner = THIS_MODULE,
  539. },
  540. .probe = tps6507x_pmic_probe,
  541. .remove = __devexit_p(tps6507x_pmic_remove),
  542. };
  543. /**
  544. * tps6507x_pmic_init
  545. *
  546. * Module init function
  547. */
  548. static int __init tps6507x_pmic_init(void)
  549. {
  550. return platform_driver_register(&tps6507x_pmic_driver);
  551. }
  552. subsys_initcall(tps6507x_pmic_init);
  553. /**
  554. * tps6507x_pmic_cleanup
  555. *
  556. * Module exit function
  557. */
  558. static void __exit tps6507x_pmic_cleanup(void)
  559. {
  560. platform_driver_unregister(&tps6507x_pmic_driver);
  561. }
  562. module_exit(tps6507x_pmic_cleanup);
  563. MODULE_AUTHOR("Texas Instruments");
  564. MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
  565. MODULE_LICENSE("GPL v2");
  566. MODULE_ALIAS("platform:tps6507x-pmic");