tps65910-regulator.c 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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. break;
  667. case TPS65911_REG_VDDCTRL:
  668. volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
  669. break;
  670. default:
  671. BUG();
  672. return -EINVAL;
  673. }
  674. return volt * 100 * mult;
  675. }
  676. static int tps65910_list_voltage(struct regulator_dev *dev,
  677. unsigned selector)
  678. {
  679. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  680. int id = rdev_get_id(dev), voltage;
  681. if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
  682. return -EINVAL;
  683. if (selector >= pmic->info[id]->table_len)
  684. return -EINVAL;
  685. else
  686. voltage = pmic->info[id]->table[selector] * 1000;
  687. return voltage;
  688. }
  689. static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
  690. {
  691. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  692. int step_mv = 0, id = rdev_get_id(dev);
  693. switch(id) {
  694. case TPS65911_REG_LDO1:
  695. case TPS65911_REG_LDO2:
  696. case TPS65911_REG_LDO4:
  697. /* The first 5 values of the selector correspond to 1V */
  698. if (selector < 5)
  699. selector = 0;
  700. else
  701. selector -= 4;
  702. step_mv = 50;
  703. break;
  704. case TPS65911_REG_LDO3:
  705. case TPS65911_REG_LDO5:
  706. case TPS65911_REG_LDO6:
  707. case TPS65911_REG_LDO7:
  708. case TPS65911_REG_LDO8:
  709. /* The first 3 values of the selector correspond to 1V */
  710. if (selector < 3)
  711. selector = 0;
  712. else
  713. selector -= 2;
  714. step_mv = 100;
  715. break;
  716. case TPS65910_REG_VIO:
  717. return pmic->info[id]->table[selector] * 1000;
  718. default:
  719. return -EINVAL;
  720. }
  721. return (LDO_MIN_VOLT + selector * step_mv) * 1000;
  722. }
  723. /* Regulator ops (except VRTC) */
  724. static struct regulator_ops tps65910_ops_dcdc = {
  725. .is_enabled = tps65910_is_enabled,
  726. .enable = tps65910_enable,
  727. .disable = tps65910_disable,
  728. .set_mode = tps65910_set_mode,
  729. .get_mode = tps65910_get_mode,
  730. .get_voltage = tps65910_get_voltage_dcdc,
  731. .set_voltage_sel = tps65910_set_voltage_dcdc,
  732. .list_voltage = tps65910_list_voltage_dcdc,
  733. };
  734. static struct regulator_ops tps65910_ops_vdd3 = {
  735. .is_enabled = tps65910_is_enabled,
  736. .enable = tps65910_enable,
  737. .disable = tps65910_disable,
  738. .set_mode = tps65910_set_mode,
  739. .get_mode = tps65910_get_mode,
  740. .get_voltage = tps65910_get_voltage_vdd3,
  741. .list_voltage = tps65910_list_voltage,
  742. };
  743. static struct regulator_ops tps65910_ops = {
  744. .is_enabled = tps65910_is_enabled,
  745. .enable = tps65910_enable,
  746. .disable = tps65910_disable,
  747. .set_mode = tps65910_set_mode,
  748. .get_mode = tps65910_get_mode,
  749. .get_voltage = tps65910_get_voltage,
  750. .set_voltage_sel = tps65910_set_voltage,
  751. .list_voltage = tps65910_list_voltage,
  752. };
  753. static struct regulator_ops tps65911_ops = {
  754. .is_enabled = tps65910_is_enabled,
  755. .enable = tps65910_enable,
  756. .disable = tps65910_disable,
  757. .set_mode = tps65910_set_mode,
  758. .get_mode = tps65910_get_mode,
  759. .get_voltage = tps65911_get_voltage,
  760. .set_voltage_sel = tps65911_set_voltage,
  761. .list_voltage = tps65911_list_voltage,
  762. };
  763. static __devinit int tps65910_probe(struct platform_device *pdev)
  764. {
  765. struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
  766. struct tps_info *info;
  767. struct regulator_init_data *reg_data;
  768. struct regulator_dev *rdev;
  769. struct tps65910_reg *pmic;
  770. struct tps65910_board *pmic_plat_data;
  771. int i, err;
  772. pmic_plat_data = dev_get_platdata(tps65910->dev);
  773. if (!pmic_plat_data)
  774. return -EINVAL;
  775. reg_data = pmic_plat_data->tps65910_pmic_init_data;
  776. pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
  777. if (!pmic)
  778. return -ENOMEM;
  779. mutex_init(&pmic->mutex);
  780. pmic->mfd = tps65910;
  781. platform_set_drvdata(pdev, pmic);
  782. /* Give control of all register to control port */
  783. tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
  784. DEVCTRL_SR_CTL_I2C_SEL_MASK);
  785. switch(tps65910_chip_id(tps65910)) {
  786. case TPS65910:
  787. pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
  788. info = tps65910_regs;
  789. break;
  790. case TPS65911:
  791. pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
  792. info = tps65911_regs;
  793. break;
  794. default:
  795. pr_err("Invalid tps chip version\n");
  796. kfree(pmic);
  797. return -ENODEV;
  798. }
  799. for (i = 0; i < TPS65910_NUM_REGULATOR; i++, info++, reg_data++) {
  800. /* Register the regulators */
  801. pmic->info[i] = info;
  802. pmic->desc[i].name = info->name;
  803. pmic->desc[i].id = i;
  804. pmic->desc[i].n_voltages = info->table_len;
  805. if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
  806. pmic->desc[i].ops = &tps65910_ops_dcdc;
  807. } else if (i == TPS65910_REG_VDD3) {
  808. if (tps65910_chip_id(tps65910) == TPS65910)
  809. pmic->desc[i].ops = &tps65910_ops_vdd3;
  810. else
  811. pmic->desc[i].ops = &tps65910_ops_dcdc;
  812. } else {
  813. if (tps65910_chip_id(tps65910) == TPS65910)
  814. pmic->desc[i].ops = &tps65910_ops;
  815. else
  816. pmic->desc[i].ops = &tps65911_ops;
  817. }
  818. pmic->desc[i].type = REGULATOR_VOLTAGE;
  819. pmic->desc[i].owner = THIS_MODULE;
  820. rdev = regulator_register(&pmic->desc[i],
  821. tps65910->dev, reg_data, pmic);
  822. if (IS_ERR(rdev)) {
  823. dev_err(tps65910->dev,
  824. "failed to register %s regulator\n",
  825. pdev->name);
  826. err = PTR_ERR(rdev);
  827. goto err;
  828. }
  829. /* Save regulator for cleanup */
  830. pmic->rdev[i] = rdev;
  831. }
  832. return 0;
  833. err:
  834. while (--i >= 0)
  835. regulator_unregister(pmic->rdev[i]);
  836. kfree(pmic);
  837. return err;
  838. }
  839. static int __devexit tps65910_remove(struct platform_device *pdev)
  840. {
  841. struct tps65910_reg *tps65910_reg = platform_get_drvdata(pdev);
  842. int i;
  843. for (i = 0; i < TPS65910_NUM_REGULATOR; i++)
  844. regulator_unregister(tps65910_reg->rdev[i]);
  845. kfree(tps65910_reg);
  846. return 0;
  847. }
  848. static struct platform_driver tps65910_driver = {
  849. .driver = {
  850. .name = "tps65910-pmic",
  851. .owner = THIS_MODULE,
  852. },
  853. .probe = tps65910_probe,
  854. .remove = __devexit_p(tps65910_remove),
  855. };
  856. static int __init tps65910_init(void)
  857. {
  858. return platform_driver_register(&tps65910_driver);
  859. }
  860. subsys_initcall(tps65910_init);
  861. static void __exit tps65910_cleanup(void)
  862. {
  863. platform_driver_unregister(&tps65910_driver);
  864. }
  865. module_exit(tps65910_cleanup);
  866. MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
  867. MODULE_DESCRIPTION("TPS6507x voltage regulator driver");
  868. MODULE_LICENSE("GPL v2");
  869. MODULE_ALIAS("platform:tps65910-pmic");