tps65910-regulator.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /*
  2. * tps65910.c -- TI tps65910
  3. *
  4. * Copyright 2010 Texas Instruments Inc.
  5. *
  6. * Author: Graeme Gregory <gg@slimlogic.co.uk>
  7. * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/err.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/regulator/driver.h>
  21. #include <linux/regulator/machine.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/gpio.h>
  25. #include <linux/mfd/tps65910.h>
  26. #define TPS65910_REG_VRTC 0
  27. #define TPS65910_REG_VIO 1
  28. #define TPS65910_REG_VDD1 2
  29. #define TPS65910_REG_VDD2 3
  30. #define TPS65910_REG_VDD3 4
  31. #define TPS65910_REG_VDIG1 5
  32. #define TPS65910_REG_VDIG2 6
  33. #define TPS65910_REG_VPLL 7
  34. #define TPS65910_REG_VDAC 8
  35. #define TPS65910_REG_VAUX1 9
  36. #define TPS65910_REG_VAUX2 10
  37. #define TPS65910_REG_VAUX33 11
  38. #define TPS65910_REG_VMMC 12
  39. #define TPS65911_REG_VDDCTRL 4
  40. #define TPS65911_REG_LDO1 5
  41. #define TPS65911_REG_LDO2 6
  42. #define TPS65911_REG_LDO3 7
  43. #define TPS65911_REG_LDO4 8
  44. #define TPS65911_REG_LDO5 9
  45. #define TPS65911_REG_LDO6 10
  46. #define TPS65911_REG_LDO7 11
  47. #define TPS65911_REG_LDO8 12
  48. #define TPS65910_NUM_REGULATOR 13
  49. #define TPS65910_SUPPLY_STATE_ENABLED 0x1
  50. /* supported VIO voltages in milivolts */
  51. static const u16 VIO_VSEL_table[] = {
  52. 1500, 1800, 2500, 3300,
  53. };
  54. /* VSEL tables for TPS65910 specific LDOs and dcdc's */
  55. /* supported VDD3 voltages in milivolts */
  56. static const u16 VDD3_VSEL_table[] = {
  57. 5000,
  58. };
  59. /* supported VDIG1 voltages in milivolts */
  60. static const u16 VDIG1_VSEL_table[] = {
  61. 1200, 1500, 1800, 2700,
  62. };
  63. /* supported VDIG2 voltages in milivolts */
  64. static const u16 VDIG2_VSEL_table[] = {
  65. 1000, 1100, 1200, 1800,
  66. };
  67. /* supported VPLL voltages in milivolts */
  68. static const u16 VPLL_VSEL_table[] = {
  69. 1000, 1100, 1800, 2500,
  70. };
  71. /* supported VDAC voltages in milivolts */
  72. static const u16 VDAC_VSEL_table[] = {
  73. 1800, 2600, 2800, 2850,
  74. };
  75. /* supported VAUX1 voltages in milivolts */
  76. static const u16 VAUX1_VSEL_table[] = {
  77. 1800, 2500, 2800, 2850,
  78. };
  79. /* supported VAUX2 voltages in milivolts */
  80. static const u16 VAUX2_VSEL_table[] = {
  81. 1800, 2800, 2900, 3300,
  82. };
  83. /* supported VAUX33 voltages in milivolts */
  84. static const u16 VAUX33_VSEL_table[] = {
  85. 1800, 2000, 2800, 3300,
  86. };
  87. /* supported VMMC voltages in milivolts */
  88. static const u16 VMMC_VSEL_table[] = {
  89. 1800, 2800, 3000, 3300,
  90. };
  91. struct tps_info {
  92. const char *name;
  93. unsigned min_uV;
  94. unsigned max_uV;
  95. u8 table_len;
  96. const u16 *table;
  97. };
  98. static struct tps_info tps65910_regs[] = {
  99. {
  100. .name = "VRTC",
  101. },
  102. {
  103. .name = "VIO",
  104. .min_uV = 1500000,
  105. .max_uV = 3300000,
  106. .table_len = ARRAY_SIZE(VIO_VSEL_table),
  107. .table = VIO_VSEL_table,
  108. },
  109. {
  110. .name = "VDD1",
  111. .min_uV = 600000,
  112. .max_uV = 4500000,
  113. },
  114. {
  115. .name = "VDD2",
  116. .min_uV = 600000,
  117. .max_uV = 4500000,
  118. },
  119. {
  120. .name = "VDD3",
  121. .min_uV = 5000000,
  122. .max_uV = 5000000,
  123. .table_len = ARRAY_SIZE(VDD3_VSEL_table),
  124. .table = VDD3_VSEL_table,
  125. },
  126. {
  127. .name = "VDIG1",
  128. .min_uV = 1200000,
  129. .max_uV = 2700000,
  130. .table_len = ARRAY_SIZE(VDIG1_VSEL_table),
  131. .table = VDIG1_VSEL_table,
  132. },
  133. {
  134. .name = "VDIG2",
  135. .min_uV = 1000000,
  136. .max_uV = 1800000,
  137. .table_len = ARRAY_SIZE(VDIG2_VSEL_table),
  138. .table = VDIG2_VSEL_table,
  139. },
  140. {
  141. .name = "VPLL",
  142. .min_uV = 1000000,
  143. .max_uV = 2500000,
  144. .table_len = ARRAY_SIZE(VPLL_VSEL_table),
  145. .table = VPLL_VSEL_table,
  146. },
  147. {
  148. .name = "VDAC",
  149. .min_uV = 1800000,
  150. .max_uV = 2850000,
  151. .table_len = ARRAY_SIZE(VDAC_VSEL_table),
  152. .table = VDAC_VSEL_table,
  153. },
  154. {
  155. .name = "VAUX1",
  156. .min_uV = 1800000,
  157. .max_uV = 2850000,
  158. .table_len = ARRAY_SIZE(VAUX1_VSEL_table),
  159. .table = VAUX1_VSEL_table,
  160. },
  161. {
  162. .name = "VAUX2",
  163. .min_uV = 1800000,
  164. .max_uV = 3300000,
  165. .table_len = ARRAY_SIZE(VAUX2_VSEL_table),
  166. .table = VAUX2_VSEL_table,
  167. },
  168. {
  169. .name = "VAUX33",
  170. .min_uV = 1800000,
  171. .max_uV = 3300000,
  172. .table_len = ARRAY_SIZE(VAUX33_VSEL_table),
  173. .table = VAUX33_VSEL_table,
  174. },
  175. {
  176. .name = "VMMC",
  177. .min_uV = 1800000,
  178. .max_uV = 3300000,
  179. .table_len = ARRAY_SIZE(VMMC_VSEL_table),
  180. .table = VMMC_VSEL_table,
  181. },
  182. };
  183. static struct tps_info tps65911_regs[] = {
  184. {
  185. .name = "VIO",
  186. .min_uV = 1500000,
  187. .max_uV = 3300000,
  188. .table_len = ARRAY_SIZE(VIO_VSEL_table),
  189. .table = VIO_VSEL_table,
  190. },
  191. {
  192. .name = "VDD1",
  193. .min_uV = 600000,
  194. .max_uV = 4500000,
  195. },
  196. {
  197. .name = "VDD2",
  198. .min_uV = 600000,
  199. .max_uV = 4500000,
  200. },
  201. {
  202. .name = "VDDCTRL",
  203. .min_uV = 600000,
  204. .max_uV = 1400000,
  205. },
  206. {
  207. .name = "LDO1",
  208. .min_uV = 1000000,
  209. .max_uV = 3300000,
  210. },
  211. {
  212. .name = "LDO2",
  213. .min_uV = 1000000,
  214. .max_uV = 3300000,
  215. },
  216. {
  217. .name = "LDO3",
  218. .min_uV = 1000000,
  219. .max_uV = 3300000,
  220. },
  221. {
  222. .name = "LDO4",
  223. .min_uV = 1000000,
  224. .max_uV = 3300000,
  225. },
  226. {
  227. .name = "LDO5",
  228. .min_uV = 1000000,
  229. .max_uV = 3300000,
  230. },
  231. {
  232. .name = "LDO6",
  233. .min_uV = 1000000,
  234. .max_uV = 3300000,
  235. },
  236. {
  237. .name = "LDO7",
  238. .min_uV = 1000000,
  239. .max_uV = 3300000,
  240. },
  241. {
  242. .name = "LDO8",
  243. .min_uV = 1000000,
  244. .max_uV = 3300000,
  245. },
  246. };
  247. struct tps65910_reg {
  248. struct regulator_desc desc[TPS65910_NUM_REGULATOR];
  249. struct tps65910 *mfd;
  250. struct regulator_dev *rdev[TPS65910_NUM_REGULATOR];
  251. struct tps_info *info[TPS65910_NUM_REGULATOR];
  252. struct mutex mutex;
  253. int mode;
  254. int (*get_ctrl_reg)(int);
  255. };
  256. static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
  257. {
  258. u8 val;
  259. int err;
  260. err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
  261. if (err)
  262. return err;
  263. return val;
  264. }
  265. static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
  266. {
  267. return pmic->mfd->write(pmic->mfd, reg, 1, &val);
  268. }
  269. static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
  270. u8 set_mask, u8 clear_mask)
  271. {
  272. int err, data;
  273. mutex_lock(&pmic->mutex);
  274. data = tps65910_read(pmic, reg);
  275. if (data < 0) {
  276. dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
  277. err = data;
  278. goto out;
  279. }
  280. data &= ~clear_mask;
  281. data |= set_mask;
  282. err = tps65910_write(pmic, reg, data);
  283. if (err)
  284. dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
  285. out:
  286. mutex_unlock(&pmic->mutex);
  287. return err;
  288. }
  289. static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
  290. {
  291. int data;
  292. mutex_lock(&pmic->mutex);
  293. data = tps65910_read(pmic, reg);
  294. if (data < 0)
  295. dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
  296. mutex_unlock(&pmic->mutex);
  297. return data;
  298. }
  299. static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
  300. {
  301. int err;
  302. mutex_lock(&pmic->mutex);
  303. err = tps65910_write(pmic, reg, val);
  304. if (err < 0)
  305. dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
  306. mutex_unlock(&pmic->mutex);
  307. return err;
  308. }
  309. static int tps65910_get_ctrl_register(int id)
  310. {
  311. switch (id) {
  312. case TPS65910_REG_VRTC:
  313. return TPS65910_VRTC;
  314. case TPS65910_REG_VIO:
  315. return TPS65910_VIO;
  316. case TPS65910_REG_VDD1:
  317. return TPS65910_VDD1;
  318. case TPS65910_REG_VDD2:
  319. return TPS65910_VDD2;
  320. case TPS65910_REG_VDD3:
  321. return TPS65910_VDD3;
  322. case TPS65910_REG_VDIG1:
  323. return TPS65910_VDIG1;
  324. case TPS65910_REG_VDIG2:
  325. return TPS65910_VDIG2;
  326. case TPS65910_REG_VPLL:
  327. return TPS65910_VPLL;
  328. case TPS65910_REG_VDAC:
  329. return TPS65910_VDAC;
  330. case TPS65910_REG_VAUX1:
  331. return TPS65910_VAUX1;
  332. case TPS65910_REG_VAUX2:
  333. return TPS65910_VAUX2;
  334. case TPS65910_REG_VAUX33:
  335. return TPS65910_VAUX33;
  336. case TPS65910_REG_VMMC:
  337. return TPS65910_VMMC;
  338. default:
  339. return -EINVAL;
  340. }
  341. }
  342. static int tps65911_get_ctrl_register(int id)
  343. {
  344. switch (id) {
  345. case TPS65910_REG_VRTC:
  346. return TPS65910_VRTC;
  347. case TPS65910_REG_VIO:
  348. return TPS65910_VIO;
  349. case TPS65910_REG_VDD1:
  350. return TPS65910_VDD1;
  351. case TPS65910_REG_VDD2:
  352. return TPS65910_VDD2;
  353. case TPS65911_REG_VDDCTRL:
  354. return TPS65911_VDDCTRL;
  355. case TPS65911_REG_LDO1:
  356. return TPS65911_LDO1;
  357. case TPS65911_REG_LDO2:
  358. return TPS65911_LDO2;
  359. case TPS65911_REG_LDO3:
  360. return TPS65911_LDO3;
  361. case TPS65911_REG_LDO4:
  362. return TPS65911_LDO4;
  363. case TPS65911_REG_LDO5:
  364. return TPS65911_LDO5;
  365. case TPS65911_REG_LDO6:
  366. return TPS65911_LDO6;
  367. case TPS65911_REG_LDO7:
  368. return TPS65911_LDO7;
  369. case TPS65911_REG_LDO8:
  370. return TPS65911_LDO8;
  371. default:
  372. return -EINVAL;
  373. }
  374. }
  375. static int tps65910_is_enabled(struct regulator_dev *dev)
  376. {
  377. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  378. int reg, value, id = rdev_get_id(dev);
  379. reg = pmic->get_ctrl_reg(id);
  380. if (reg < 0)
  381. return reg;
  382. value = tps65910_reg_read(pmic, reg);
  383. if (value < 0)
  384. return value;
  385. return value & TPS65910_SUPPLY_STATE_ENABLED;
  386. }
  387. static int tps65910_enable(struct regulator_dev *dev)
  388. {
  389. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  390. struct tps65910 *mfd = pmic->mfd;
  391. int reg, id = rdev_get_id(dev);
  392. reg = pmic->get_ctrl_reg(id);
  393. if (reg < 0)
  394. return reg;
  395. return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
  396. }
  397. static int tps65910_disable(struct regulator_dev *dev)
  398. {
  399. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  400. struct tps65910 *mfd = pmic->mfd;
  401. int reg, id = rdev_get_id(dev);
  402. reg = pmic->get_ctrl_reg(id);
  403. if (reg < 0)
  404. return reg;
  405. return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
  406. }
  407. static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
  408. {
  409. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  410. struct tps65910 *mfd = pmic->mfd;
  411. int reg, value, id = rdev_get_id(dev);
  412. reg = pmic->get_ctrl_reg(id);
  413. if (reg < 0)
  414. return reg;
  415. switch (mode) {
  416. case REGULATOR_MODE_NORMAL:
  417. return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
  418. LDO_ST_MODE_BIT);
  419. case REGULATOR_MODE_IDLE:
  420. value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
  421. return tps65910_set_bits(mfd, reg, value);
  422. case REGULATOR_MODE_STANDBY:
  423. return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
  424. }
  425. return -EINVAL;
  426. }
  427. static unsigned int tps65910_get_mode(struct regulator_dev *dev)
  428. {
  429. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  430. int reg, value, id = rdev_get_id(dev);
  431. reg = pmic->get_ctrl_reg(id);
  432. if (reg < 0)
  433. return reg;
  434. value = tps65910_reg_read(pmic, reg);
  435. if (value < 0)
  436. return value;
  437. if (value & LDO_ST_ON_BIT)
  438. return REGULATOR_MODE_STANDBY;
  439. else if (value & LDO_ST_MODE_BIT)
  440. return REGULATOR_MODE_IDLE;
  441. else
  442. return REGULATOR_MODE_NORMAL;
  443. }
  444. static int tps65910_get_voltage_dcdc(struct regulator_dev *dev)
  445. {
  446. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  447. int id = rdev_get_id(dev), voltage = 0;
  448. int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
  449. switch (id) {
  450. case TPS65910_REG_VDD1:
  451. opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
  452. mult = tps65910_reg_read(pmic, TPS65910_VDD1);
  453. mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
  454. srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
  455. sr = opvsel & VDD1_OP_CMD_MASK;
  456. opvsel &= VDD1_OP_SEL_MASK;
  457. srvsel &= VDD1_SR_SEL_MASK;
  458. vselmax = 75;
  459. break;
  460. case TPS65910_REG_VDD2:
  461. opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
  462. mult = tps65910_reg_read(pmic, TPS65910_VDD2);
  463. mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
  464. srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
  465. sr = opvsel & VDD2_OP_CMD_MASK;
  466. opvsel &= VDD2_OP_SEL_MASK;
  467. srvsel &= VDD2_SR_SEL_MASK;
  468. vselmax = 75;
  469. break;
  470. case TPS65911_REG_VDDCTRL:
  471. opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
  472. srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
  473. sr = opvsel & VDDCTRL_OP_CMD_MASK;
  474. opvsel &= VDDCTRL_OP_SEL_MASK;
  475. srvsel &= VDDCTRL_SR_SEL_MASK;
  476. vselmax = 64;
  477. break;
  478. }
  479. /* multiplier 0 == 1 but 2,3 normal */
  480. if (!mult)
  481. mult=1;
  482. if (sr) {
  483. /* normalise to valid range */
  484. if (srvsel < 3)
  485. srvsel = 3;
  486. if (srvsel > vselmax)
  487. srvsel = vselmax;
  488. srvsel -= 3;
  489. voltage = (srvsel * VDD1_2_OFFSET + VDD1_2_MIN_VOLT) * 100;
  490. } else {
  491. /* normalise to valid range*/
  492. if (opvsel < 3)
  493. opvsel = 3;
  494. if (opvsel > vselmax)
  495. opvsel = vselmax;
  496. opvsel -= 3;
  497. voltage = (opvsel * VDD1_2_OFFSET + VDD1_2_MIN_VOLT) * 100;
  498. }
  499. voltage *= mult;
  500. return voltage;
  501. }
  502. static int tps65910_get_voltage(struct regulator_dev *dev)
  503. {
  504. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  505. int reg, value, id = rdev_get_id(dev), voltage = 0;
  506. reg = pmic->get_ctrl_reg(id);
  507. if (reg < 0)
  508. return reg;
  509. value = tps65910_reg_read(pmic, reg);
  510. if (value < 0)
  511. return value;
  512. switch (id) {
  513. case TPS65910_REG_VIO:
  514. case TPS65910_REG_VDIG1:
  515. case TPS65910_REG_VDIG2:
  516. case TPS65910_REG_VPLL:
  517. case TPS65910_REG_VDAC:
  518. case TPS65910_REG_VAUX1:
  519. case TPS65910_REG_VAUX2:
  520. case TPS65910_REG_VAUX33:
  521. case TPS65910_REG_VMMC:
  522. value &= LDO_SEL_MASK;
  523. value >>= LDO_SEL_SHIFT;
  524. break;
  525. default:
  526. return -EINVAL;
  527. }
  528. voltage = pmic->info[id]->table[value] * 1000;
  529. return voltage;
  530. }
  531. static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
  532. {
  533. return 5 * 1000 * 1000;
  534. }
  535. static int tps65911_get_voltage(struct regulator_dev *dev)
  536. {
  537. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  538. int step_mv, id = rdev_get_id(dev);
  539. u8 value, reg;
  540. reg = pmic->get_ctrl_reg(id);
  541. value = tps65910_reg_read(pmic, reg);
  542. switch (id) {
  543. case TPS65911_REG_LDO1:
  544. case TPS65911_REG_LDO2:
  545. case TPS65911_REG_LDO4:
  546. value &= LDO1_SEL_MASK;
  547. value >>= LDO_SEL_SHIFT;
  548. /* The first 5 values of the selector correspond to 1V */
  549. if (value < 5)
  550. value = 0;
  551. else
  552. value -= 4;
  553. step_mv = 50;
  554. break;
  555. case TPS65911_REG_LDO3:
  556. case TPS65911_REG_LDO5:
  557. case TPS65911_REG_LDO6:
  558. case TPS65911_REG_LDO7:
  559. case TPS65911_REG_LDO8:
  560. value &= LDO3_SEL_MASK;
  561. value >>= LDO_SEL_SHIFT;
  562. /* The first 3 values of the selector correspond to 1V */
  563. if (value < 3)
  564. value = 0;
  565. else
  566. value -= 2;
  567. step_mv = 100;
  568. break;
  569. case TPS65910_REG_VIO:
  570. return pmic->info[id]->table[value] * 1000;
  571. break;
  572. default:
  573. return -EINVAL;
  574. }
  575. return (LDO_MIN_VOLT + value * step_mv) * 1000;
  576. }
  577. static int tps65910_set_voltage_dcdc(struct regulator_dev *dev,
  578. unsigned selector)
  579. {
  580. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  581. int id = rdev_get_id(dev), vsel;
  582. int dcdc_mult = 0;
  583. switch (id) {
  584. case TPS65910_REG_VDD1:
  585. dcdc_mult = (selector / VDD1_2_NUM_VOLTS) + 1;
  586. if (dcdc_mult == 1)
  587. dcdc_mult--;
  588. vsel = (selector % VDD1_2_NUM_VOLTS) + 3;
  589. tps65910_modify_bits(pmic, TPS65910_VDD1,
  590. (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
  591. VDD1_VGAIN_SEL_MASK);
  592. tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
  593. break;
  594. case TPS65910_REG_VDD2:
  595. dcdc_mult = (selector / VDD1_2_NUM_VOLTS) + 1;
  596. if (dcdc_mult == 1)
  597. dcdc_mult--;
  598. vsel = (selector % VDD1_2_NUM_VOLTS) + 3;
  599. tps65910_modify_bits(pmic, TPS65910_VDD2,
  600. (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
  601. VDD1_VGAIN_SEL_MASK);
  602. tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
  603. break;
  604. case TPS65911_REG_VDDCTRL:
  605. vsel = selector;
  606. tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
  607. }
  608. return 0;
  609. }
  610. static int tps65910_set_voltage(struct regulator_dev *dev, unsigned selector)
  611. {
  612. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  613. int reg, id = rdev_get_id(dev);
  614. reg = pmic->get_ctrl_reg(id);
  615. if (reg < 0)
  616. return reg;
  617. switch (id) {
  618. case TPS65910_REG_VIO:
  619. case TPS65910_REG_VDIG1:
  620. case TPS65910_REG_VDIG2:
  621. case TPS65910_REG_VPLL:
  622. case TPS65910_REG_VDAC:
  623. case TPS65910_REG_VAUX1:
  624. case TPS65910_REG_VAUX2:
  625. case TPS65910_REG_VAUX33:
  626. case TPS65910_REG_VMMC:
  627. return tps65910_modify_bits(pmic, reg,
  628. (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
  629. }
  630. return -EINVAL;
  631. }
  632. static int tps65911_set_voltage(struct regulator_dev *dev, unsigned selector)
  633. {
  634. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  635. int reg, id = rdev_get_id(dev);
  636. reg = pmic->get_ctrl_reg(id);
  637. if (reg < 0)
  638. return reg;
  639. switch (id) {
  640. case TPS65911_REG_LDO1:
  641. case TPS65911_REG_LDO2:
  642. case TPS65911_REG_LDO4:
  643. return tps65910_modify_bits(pmic, reg,
  644. (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
  645. case TPS65911_REG_LDO3:
  646. case TPS65911_REG_LDO5:
  647. case TPS65911_REG_LDO6:
  648. case TPS65911_REG_LDO7:
  649. case TPS65911_REG_LDO8:
  650. case TPS65910_REG_VIO:
  651. return tps65910_modify_bits(pmic, reg,
  652. (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
  653. }
  654. return -EINVAL;
  655. }
  656. static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
  657. unsigned selector)
  658. {
  659. int volt, mult = 1, id = rdev_get_id(dev);
  660. switch (id) {
  661. case TPS65910_REG_VDD1:
  662. case TPS65910_REG_VDD2:
  663. mult = (selector / VDD1_2_NUM_VOLTS) + 1;
  664. volt = VDD1_2_MIN_VOLT +
  665. (selector % VDD1_2_NUM_VOLTS) * VDD1_2_OFFSET;
  666. case TPS65911_REG_VDDCTRL:
  667. volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
  668. }
  669. return volt * 100 * mult;
  670. }
  671. static int tps65910_list_voltage(struct regulator_dev *dev,
  672. unsigned selector)
  673. {
  674. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  675. int id = rdev_get_id(dev), voltage;
  676. if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
  677. return -EINVAL;
  678. if (selector >= pmic->info[id]->table_len)
  679. return -EINVAL;
  680. else
  681. voltage = pmic->info[id]->table[selector] * 1000;
  682. return voltage;
  683. }
  684. static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
  685. {
  686. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  687. int step_mv = 0, id = rdev_get_id(dev);
  688. switch(id) {
  689. case TPS65911_REG_LDO1:
  690. case TPS65911_REG_LDO2:
  691. case TPS65911_REG_LDO4:
  692. /* The first 5 values of the selector correspond to 1V */
  693. if (selector < 5)
  694. selector = 0;
  695. else
  696. selector -= 4;
  697. step_mv = 50;
  698. break;
  699. case TPS65911_REG_LDO3:
  700. case TPS65911_REG_LDO5:
  701. case TPS65911_REG_LDO6:
  702. case TPS65911_REG_LDO7:
  703. case TPS65911_REG_LDO8:
  704. /* The first 3 values of the selector correspond to 1V */
  705. if (selector < 3)
  706. selector = 0;
  707. else
  708. selector -= 2;
  709. step_mv = 100;
  710. break;
  711. case TPS65910_REG_VIO:
  712. return pmic->info[id]->table[selector] * 1000;
  713. default:
  714. return -EINVAL;
  715. }
  716. return (LDO_MIN_VOLT + selector * step_mv) * 1000;
  717. }
  718. /* Regulator ops (except VRTC) */
  719. static struct regulator_ops tps65910_ops_dcdc = {
  720. .is_enabled = tps65910_is_enabled,
  721. .enable = tps65910_enable,
  722. .disable = tps65910_disable,
  723. .set_mode = tps65910_set_mode,
  724. .get_mode = tps65910_get_mode,
  725. .get_voltage = tps65910_get_voltage_dcdc,
  726. .set_voltage_sel = tps65910_set_voltage_dcdc,
  727. .list_voltage = tps65910_list_voltage_dcdc,
  728. };
  729. static struct regulator_ops tps65910_ops_vdd3 = {
  730. .is_enabled = tps65910_is_enabled,
  731. .enable = tps65910_enable,
  732. .disable = tps65910_disable,
  733. .set_mode = tps65910_set_mode,
  734. .get_mode = tps65910_get_mode,
  735. .get_voltage = tps65910_get_voltage_vdd3,
  736. .list_voltage = tps65910_list_voltage,
  737. };
  738. static struct regulator_ops tps65910_ops = {
  739. .is_enabled = tps65910_is_enabled,
  740. .enable = tps65910_enable,
  741. .disable = tps65910_disable,
  742. .set_mode = tps65910_set_mode,
  743. .get_mode = tps65910_get_mode,
  744. .get_voltage = tps65910_get_voltage,
  745. .set_voltage_sel = tps65910_set_voltage,
  746. .list_voltage = tps65910_list_voltage,
  747. };
  748. static struct regulator_ops tps65911_ops = {
  749. .is_enabled = tps65910_is_enabled,
  750. .enable = tps65910_enable,
  751. .disable = tps65910_disable,
  752. .set_mode = tps65910_set_mode,
  753. .get_mode = tps65910_get_mode,
  754. .get_voltage = tps65911_get_voltage,
  755. .set_voltage_sel = tps65911_set_voltage,
  756. .list_voltage = tps65911_list_voltage,
  757. };
  758. static __devinit int tps65910_probe(struct platform_device *pdev)
  759. {
  760. struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
  761. struct tps_info *info;
  762. struct regulator_init_data *reg_data;
  763. struct regulator_dev *rdev;
  764. struct tps65910_reg *pmic;
  765. struct tps65910_board *pmic_plat_data;
  766. int i, err;
  767. pmic_plat_data = dev_get_platdata(tps65910->dev);
  768. if (!pmic_plat_data)
  769. return -EINVAL;
  770. reg_data = pmic_plat_data->tps65910_pmic_init_data;
  771. pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
  772. if (!pmic)
  773. return -ENOMEM;
  774. mutex_init(&pmic->mutex);
  775. pmic->mfd = tps65910;
  776. platform_set_drvdata(pdev, pmic);
  777. /* Give control of all register to control port */
  778. tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
  779. DEVCTRL_SR_CTL_I2C_SEL_MASK);
  780. switch(tps65910_chip_id(tps65910)) {
  781. case TPS65910:
  782. pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
  783. info = tps65910_regs;
  784. case TPS65911:
  785. pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
  786. info = tps65911_regs;
  787. default:
  788. pr_err("Invalid tps chip version\n");
  789. kfree(pmic);
  790. return -ENODEV;
  791. }
  792. for (i = 0; i < TPS65910_NUM_REGULATOR; i++, info++, reg_data++) {
  793. /* Register the regulators */
  794. pmic->info[i] = info;
  795. pmic->desc[i].name = info->name;
  796. pmic->desc[i].id = i;
  797. pmic->desc[i].n_voltages = info->table_len;
  798. if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
  799. pmic->desc[i].ops = &tps65910_ops_dcdc;
  800. } else if (i == TPS65910_REG_VDD3) {
  801. if (tps65910_chip_id(tps65910) == TPS65910)
  802. pmic->desc[i].ops = &tps65910_ops_vdd3;
  803. else
  804. pmic->desc[i].ops = &tps65910_ops_dcdc;
  805. } else {
  806. if (tps65910_chip_id(tps65910) == TPS65910)
  807. pmic->desc[i].ops = &tps65910_ops;
  808. else
  809. pmic->desc[i].ops = &tps65911_ops;
  810. }
  811. pmic->desc[i].type = REGULATOR_VOLTAGE;
  812. pmic->desc[i].owner = THIS_MODULE;
  813. rdev = regulator_register(&pmic->desc[i],
  814. tps65910->dev, reg_data, pmic);
  815. if (IS_ERR(rdev)) {
  816. dev_err(tps65910->dev,
  817. "failed to register %s regulator\n",
  818. pdev->name);
  819. err = PTR_ERR(rdev);
  820. goto err;
  821. }
  822. /* Save regulator for cleanup */
  823. pmic->rdev[i] = rdev;
  824. }
  825. return 0;
  826. err:
  827. while (--i >= 0)
  828. regulator_unregister(pmic->rdev[i]);
  829. kfree(pmic);
  830. return err;
  831. }
  832. static int __devexit tps65910_remove(struct platform_device *pdev)
  833. {
  834. struct tps65910_reg *tps65910_reg = platform_get_drvdata(pdev);
  835. int i;
  836. for (i = 0; i < TPS65910_NUM_REGULATOR; i++)
  837. regulator_unregister(tps65910_reg->rdev[i]);
  838. kfree(tps65910_reg);
  839. return 0;
  840. }
  841. static struct platform_driver tps65910_driver = {
  842. .driver = {
  843. .name = "tps65910-pmic",
  844. .owner = THIS_MODULE,
  845. },
  846. .probe = tps65910_probe,
  847. .remove = __devexit_p(tps65910_remove),
  848. };
  849. static int __init tps65910_init(void)
  850. {
  851. return platform_driver_register(&tps65910_driver);
  852. }
  853. subsys_initcall(tps65910_init);
  854. static void __exit tps65910_cleanup(void)
  855. {
  856. platform_driver_unregister(&tps65910_driver);
  857. }
  858. module_exit(tps65910_cleanup);
  859. MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
  860. MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
  861. MODULE_LICENSE("GPL v2");
  862. MODULE_ALIAS("platform:tps65910-pmic");