tps6507x-regulator.c 17 KB

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