tps6507x-regulator.c 15 KB

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