tps6507x-regulator.c 17 KB

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