twl-regulator.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * twl-regulator.c -- support regulators in twl4030/twl6030 family chips
  3. *
  4. * Copyright (C) 2008 David Brownell
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/err.h>
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/regulator/machine.h>
  18. #include <linux/i2c/twl.h>
  19. /*
  20. * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
  21. * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
  22. * include an audio codec, battery charger, and more voltage regulators.
  23. * These chips are often used in OMAP-based systems.
  24. *
  25. * This driver implements software-based resource control for various
  26. * voltage regulators. This is usually augmented with state machine
  27. * based control.
  28. */
  29. struct twlreg_info {
  30. /* start of regulator's PM_RECEIVER control register bank */
  31. u8 base;
  32. /* twl resource ID, for resource control state machine */
  33. u8 id;
  34. /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
  35. u8 table_len;
  36. const u16 *table;
  37. /* regulator specific turn-on delay */
  38. u16 delay;
  39. /* State REMAP default configuration */
  40. u8 remap;
  41. /* chip constraints on regulator behavior */
  42. u16 min_mV;
  43. u16 max_mV;
  44. /* used by regulator core */
  45. struct regulator_desc desc;
  46. };
  47. /* LDO control registers ... offset is from the base of its register bank.
  48. * The first three registers of all power resource banks help hardware to
  49. * manage the various resource groups.
  50. */
  51. /* Common offset in TWL4030/6030 */
  52. #define VREG_GRP 0
  53. /* TWL4030 register offsets */
  54. #define VREG_TYPE 1
  55. #define VREG_REMAP 2
  56. #define VREG_DEDICATED 3 /* LDO control */
  57. /* TWL6030 register offsets */
  58. #define VREG_TRANS 1
  59. #define VREG_STATE 2
  60. #define VREG_VOLTAGE 3
  61. /* TWL6030 Misc register offsets */
  62. #define VREG_BC_ALL 1
  63. #define VREG_BC_REF 2
  64. #define VREG_BC_PROC 3
  65. #define VREG_BC_CLK_RST 4
  66. /* TWL6030 LDO register values for CFG_STATE */
  67. #define TWL6030_CFG_STATE_OFF 0x00
  68. #define TWL6030_CFG_STATE_ON 0x01
  69. #define TWL6030_CFG_STATE_GRP_SHIFT 5
  70. static inline int
  71. twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
  72. {
  73. u8 value;
  74. int status;
  75. status = twl_i2c_read_u8(slave_subgp,
  76. &value, info->base + offset);
  77. return (status < 0) ? status : value;
  78. }
  79. static inline int
  80. twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
  81. u8 value)
  82. {
  83. return twl_i2c_write_u8(slave_subgp,
  84. value, info->base + offset);
  85. }
  86. /*----------------------------------------------------------------------*/
  87. /* generic power resource operations, which work on all regulators */
  88. static int twlreg_grp(struct regulator_dev *rdev)
  89. {
  90. return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
  91. VREG_GRP);
  92. }
  93. /*
  94. * Enable/disable regulators by joining/leaving the P1 (processor) group.
  95. * We assume nobody else is updating the DEV_GRP registers.
  96. */
  97. /* definition for 4030 family */
  98. #define P3_GRP_4030 BIT(7) /* "peripherals" */
  99. #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
  100. #define P1_GRP_4030 BIT(5) /* CPU/Linux */
  101. /* definition for 6030 family */
  102. #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
  103. #define P2_GRP_6030 BIT(1) /* "peripherals" */
  104. #define P1_GRP_6030 BIT(0) /* CPU/Linux */
  105. static int twlreg_is_enabled(struct regulator_dev *rdev)
  106. {
  107. int state = twlreg_grp(rdev);
  108. if (state < 0)
  109. return state;
  110. if (twl_class_is_4030())
  111. state &= P1_GRP_4030;
  112. else
  113. state &= P1_GRP_6030;
  114. return state;
  115. }
  116. static int twlreg_enable(struct regulator_dev *rdev)
  117. {
  118. struct twlreg_info *info = rdev_get_drvdata(rdev);
  119. int grp;
  120. int ret;
  121. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  122. if (grp < 0)
  123. return grp;
  124. if (twl_class_is_4030())
  125. grp |= P1_GRP_4030;
  126. else
  127. grp |= P1_GRP_6030;
  128. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
  129. if (!ret && twl_class_is_6030())
  130. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
  131. grp << TWL6030_CFG_STATE_GRP_SHIFT |
  132. TWL6030_CFG_STATE_ON);
  133. udelay(info->delay);
  134. return ret;
  135. }
  136. static int twlreg_disable(struct regulator_dev *rdev)
  137. {
  138. struct twlreg_info *info = rdev_get_drvdata(rdev);
  139. int grp;
  140. int ret;
  141. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  142. if (grp < 0)
  143. return grp;
  144. /* For 6030, set the off state for all grps enabled */
  145. if (twl_class_is_6030()) {
  146. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
  147. (grp & (P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030)) <<
  148. TWL6030_CFG_STATE_GRP_SHIFT |
  149. TWL6030_CFG_STATE_OFF);
  150. if (ret)
  151. return ret;
  152. }
  153. if (twl_class_is_4030())
  154. grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
  155. else
  156. grp &= ~(P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030);
  157. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
  158. /* Next, associate cleared grp in state register */
  159. if (!ret && twl_class_is_6030())
  160. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
  161. grp << TWL6030_CFG_STATE_GRP_SHIFT |
  162. TWL6030_CFG_STATE_OFF);
  163. return ret;
  164. }
  165. static int twlreg_get_status(struct regulator_dev *rdev)
  166. {
  167. int state = twlreg_grp(rdev);
  168. if (twl_class_is_6030())
  169. return 0; /* FIXME return for 6030 regulator */
  170. if (state < 0)
  171. return state;
  172. state &= 0x0f;
  173. /* assume state != WARM_RESET; we'd not be running... */
  174. if (!state)
  175. return REGULATOR_STATUS_OFF;
  176. return (state & BIT(3))
  177. ? REGULATOR_STATUS_NORMAL
  178. : REGULATOR_STATUS_STANDBY;
  179. }
  180. static int twlreg_set_mode(struct regulator_dev *rdev, unsigned mode)
  181. {
  182. struct twlreg_info *info = rdev_get_drvdata(rdev);
  183. unsigned message;
  184. int status;
  185. if (twl_class_is_6030())
  186. return 0; /* FIXME return for 6030 regulator */
  187. /* We can only set the mode through state machine commands... */
  188. switch (mode) {
  189. case REGULATOR_MODE_NORMAL:
  190. message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
  191. break;
  192. case REGULATOR_MODE_STANDBY:
  193. message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
  194. break;
  195. default:
  196. return -EINVAL;
  197. }
  198. /* Ensure the resource is associated with some group */
  199. status = twlreg_grp(rdev);
  200. if (status < 0)
  201. return status;
  202. if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
  203. return -EACCES;
  204. status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
  205. message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
  206. if (status < 0)
  207. return status;
  208. return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
  209. message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
  210. }
  211. /*----------------------------------------------------------------------*/
  212. /*
  213. * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
  214. * select field in its control register. We use tables indexed by VSEL
  215. * to record voltages in milliVolts. (Accuracy is about three percent.)
  216. *
  217. * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
  218. * currently handled by listing two slightly different VAUX2 regulators,
  219. * only one of which will be configured.
  220. *
  221. * VSEL values documented as "TI cannot support these values" are flagged
  222. * in these tables as UNSUP() values; we normally won't assign them.
  223. *
  224. * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
  225. * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
  226. */
  227. #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
  228. #define UNSUP_MASK 0x0000
  229. #else
  230. #define UNSUP_MASK 0x8000
  231. #endif
  232. #define UNSUP(x) (UNSUP_MASK | (x))
  233. #define IS_UNSUP(x) (UNSUP_MASK & (x))
  234. #define LDO_MV(x) (~UNSUP_MASK & (x))
  235. static const u16 VAUX1_VSEL_table[] = {
  236. UNSUP(1500), UNSUP(1800), 2500, 2800,
  237. 3000, 3000, 3000, 3000,
  238. };
  239. static const u16 VAUX2_4030_VSEL_table[] = {
  240. UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
  241. 1500, 1800, UNSUP(1850), 2500,
  242. UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
  243. UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
  244. };
  245. static const u16 VAUX2_VSEL_table[] = {
  246. 1700, 1700, 1900, 1300,
  247. 1500, 1800, 2000, 2500,
  248. 2100, 2800, 2200, 2300,
  249. 2400, 2400, 2400, 2400,
  250. };
  251. static const u16 VAUX3_VSEL_table[] = {
  252. 1500, 1800, 2500, 2800,
  253. 3000, 3000, 3000, 3000,
  254. };
  255. static const u16 VAUX4_VSEL_table[] = {
  256. 700, 1000, 1200, UNSUP(1300),
  257. 1500, 1800, UNSUP(1850), 2500,
  258. UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
  259. UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
  260. };
  261. static const u16 VMMC1_VSEL_table[] = {
  262. 1850, 2850, 3000, 3150,
  263. };
  264. static const u16 VMMC2_VSEL_table[] = {
  265. UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
  266. UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
  267. 2600, 2800, 2850, 3000,
  268. 3150, 3150, 3150, 3150,
  269. };
  270. static const u16 VPLL1_VSEL_table[] = {
  271. 1000, 1200, 1300, 1800,
  272. UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
  273. };
  274. static const u16 VPLL2_VSEL_table[] = {
  275. 700, 1000, 1200, 1300,
  276. UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
  277. UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
  278. UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
  279. };
  280. static const u16 VSIM_VSEL_table[] = {
  281. UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
  282. 2800, 3000, 3000, 3000,
  283. };
  284. static const u16 VDAC_VSEL_table[] = {
  285. 1200, 1300, 1800, 1800,
  286. };
  287. static const u16 VDD1_VSEL_table[] = {
  288. 800, 1450,
  289. };
  290. static const u16 VDD2_VSEL_table[] = {
  291. 800, 1450, 1500,
  292. };
  293. static const u16 VIO_VSEL_table[] = {
  294. 1800, 1850,
  295. };
  296. static const u16 VINTANA2_VSEL_table[] = {
  297. 2500, 2750,
  298. };
  299. static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
  300. {
  301. struct twlreg_info *info = rdev_get_drvdata(rdev);
  302. int mV = info->table[index];
  303. return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
  304. }
  305. static int
  306. twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  307. unsigned *selector)
  308. {
  309. struct twlreg_info *info = rdev_get_drvdata(rdev);
  310. int vsel;
  311. for (vsel = 0; vsel < info->table_len; vsel++) {
  312. int mV = info->table[vsel];
  313. int uV;
  314. if (IS_UNSUP(mV))
  315. continue;
  316. uV = LDO_MV(mV) * 1000;
  317. /* REVISIT for VAUX2, first match may not be best/lowest */
  318. /* use the first in-range value */
  319. if (min_uV <= uV && uV <= max_uV) {
  320. *selector = vsel;
  321. return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
  322. VREG_VOLTAGE, vsel);
  323. }
  324. }
  325. return -EDOM;
  326. }
  327. static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
  328. {
  329. struct twlreg_info *info = rdev_get_drvdata(rdev);
  330. int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
  331. VREG_VOLTAGE);
  332. if (vsel < 0)
  333. return vsel;
  334. vsel &= info->table_len - 1;
  335. return LDO_MV(info->table[vsel]) * 1000;
  336. }
  337. static struct regulator_ops twl4030ldo_ops = {
  338. .list_voltage = twl4030ldo_list_voltage,
  339. .set_voltage = twl4030ldo_set_voltage,
  340. .get_voltage = twl4030ldo_get_voltage,
  341. .enable = twlreg_enable,
  342. .disable = twlreg_disable,
  343. .is_enabled = twlreg_is_enabled,
  344. .set_mode = twlreg_set_mode,
  345. .get_status = twlreg_get_status,
  346. };
  347. static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
  348. {
  349. struct twlreg_info *info = rdev_get_drvdata(rdev);
  350. return ((info->min_mV + (index * 100)) * 1000);
  351. }
  352. static int
  353. twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  354. unsigned *selector)
  355. {
  356. struct twlreg_info *info = rdev_get_drvdata(rdev);
  357. int vsel;
  358. if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
  359. return -EDOM;
  360. /*
  361. * Use the below formula to calculate vsel
  362. * mV = 1000mv + 100mv * (vsel - 1)
  363. */
  364. vsel = (min_uV/1000 - 1000)/100 + 1;
  365. *selector = vsel;
  366. return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
  367. }
  368. static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
  369. {
  370. struct twlreg_info *info = rdev_get_drvdata(rdev);
  371. int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
  372. VREG_VOLTAGE);
  373. if (vsel < 0)
  374. return vsel;
  375. /*
  376. * Use the below formula to calculate vsel
  377. * mV = 1000mv + 100mv * (vsel - 1)
  378. */
  379. return (1000 + (100 * (vsel - 1))) * 1000;
  380. }
  381. static struct regulator_ops twl6030ldo_ops = {
  382. .list_voltage = twl6030ldo_list_voltage,
  383. .set_voltage = twl6030ldo_set_voltage,
  384. .get_voltage = twl6030ldo_get_voltage,
  385. .enable = twlreg_enable,
  386. .disable = twlreg_disable,
  387. .is_enabled = twlreg_is_enabled,
  388. .set_mode = twlreg_set_mode,
  389. .get_status = twlreg_get_status,
  390. };
  391. /*----------------------------------------------------------------------*/
  392. /*
  393. * Fixed voltage LDOs don't have a VSEL field to update.
  394. */
  395. static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
  396. {
  397. struct twlreg_info *info = rdev_get_drvdata(rdev);
  398. return info->min_mV * 1000;
  399. }
  400. static int twlfixed_get_voltage(struct regulator_dev *rdev)
  401. {
  402. struct twlreg_info *info = rdev_get_drvdata(rdev);
  403. return info->min_mV * 1000;
  404. }
  405. static struct regulator_ops twlfixed_ops = {
  406. .list_voltage = twlfixed_list_voltage,
  407. .get_voltage = twlfixed_get_voltage,
  408. .enable = twlreg_enable,
  409. .disable = twlreg_disable,
  410. .is_enabled = twlreg_is_enabled,
  411. .set_mode = twlreg_set_mode,
  412. .get_status = twlreg_get_status,
  413. };
  414. static struct regulator_ops twl6030_fixed_resource = {
  415. .enable = twlreg_enable,
  416. .disable = twlreg_disable,
  417. .is_enabled = twlreg_is_enabled,
  418. .get_status = twlreg_get_status,
  419. };
  420. /*----------------------------------------------------------------------*/
  421. #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
  422. remap_conf) \
  423. TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
  424. remap_conf, TWL4030)
  425. #define TWL6030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
  426. remap_conf) \
  427. TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
  428. remap_conf, TWL6030)
  429. #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
  430. .base = offset, \
  431. .id = num, \
  432. .table_len = ARRAY_SIZE(label##_VSEL_table), \
  433. .table = label##_VSEL_table, \
  434. .delay = turnon_delay, \
  435. .remap = remap_conf, \
  436. .desc = { \
  437. .name = #label, \
  438. .id = TWL4030_REG_##label, \
  439. .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
  440. .ops = &twl4030ldo_ops, \
  441. .type = REGULATOR_VOLTAGE, \
  442. .owner = THIS_MODULE, \
  443. }, \
  444. }
  445. #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts, num, \
  446. remap_conf) { \
  447. .base = offset, \
  448. .id = num, \
  449. .min_mV = min_mVolts, \
  450. .max_mV = max_mVolts, \
  451. .remap = remap_conf, \
  452. .desc = { \
  453. .name = #label, \
  454. .id = TWL6030_REG_##label, \
  455. .n_voltages = (max_mVolts - min_mVolts)/100, \
  456. .ops = &twl6030ldo_ops, \
  457. .type = REGULATOR_VOLTAGE, \
  458. .owner = THIS_MODULE, \
  459. }, \
  460. }
  461. #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
  462. family) { \
  463. .base = offset, \
  464. .id = num, \
  465. .min_mV = mVolts, \
  466. .delay = turnon_delay, \
  467. .remap = remap_conf, \
  468. .desc = { \
  469. .name = #label, \
  470. .id = family##_REG_##label, \
  471. .n_voltages = 1, \
  472. .ops = &twlfixed_ops, \
  473. .type = REGULATOR_VOLTAGE, \
  474. .owner = THIS_MODULE, \
  475. }, \
  476. }
  477. #define TWL6030_FIXED_RESOURCE(label, offset, num, turnon_delay, remap_conf) { \
  478. .base = offset, \
  479. .id = num, \
  480. .delay = turnon_delay, \
  481. .remap = remap_conf, \
  482. .desc = { \
  483. .name = #label, \
  484. .id = TWL6030_REG_##label, \
  485. .ops = &twl6030_fixed_resource, \
  486. .type = REGULATOR_VOLTAGE, \
  487. .owner = THIS_MODULE, \
  488. }, \
  489. }
  490. /*
  491. * We list regulators here if systems need some level of
  492. * software control over them after boot.
  493. */
  494. static struct twlreg_info twl_regs[] = {
  495. TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
  496. TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
  497. TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
  498. TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
  499. TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
  500. TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
  501. TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
  502. TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
  503. TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
  504. TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
  505. TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
  506. TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
  507. TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
  508. TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
  509. TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
  510. TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
  511. TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
  512. TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
  513. TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
  514. TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
  515. /* VUSBCP is managed *only* by the USB subchip */
  516. /* 6030 REG with base as PMC Slave Misc : 0x0030 */
  517. /* Turnon-delay and remap configuration values for 6030 are not
  518. verified since the specification is not public */
  519. TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300, 1, 0x21),
  520. TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300, 2, 0x21),
  521. TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300, 3, 0x21),
  522. TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300, 4, 0x21),
  523. TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300, 5, 0x21),
  524. TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300, 7, 0x21),
  525. TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0, 0x21),
  526. TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0, 0x21),
  527. TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0, 0x21),
  528. TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0, 0x21),
  529. TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 48, 0, 0x21),
  530. };
  531. static int __devinit twlreg_probe(struct platform_device *pdev)
  532. {
  533. int i;
  534. struct twlreg_info *info;
  535. struct regulator_init_data *initdata;
  536. struct regulation_constraints *c;
  537. struct regulator_dev *rdev;
  538. for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
  539. if (twl_regs[i].desc.id != pdev->id)
  540. continue;
  541. info = twl_regs + i;
  542. break;
  543. }
  544. if (!info)
  545. return -ENODEV;
  546. initdata = pdev->dev.platform_data;
  547. if (!initdata)
  548. return -EINVAL;
  549. /* Constrain board-specific capabilities according to what
  550. * this driver and the chip itself can actually do.
  551. */
  552. c = &initdata->constraints;
  553. c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
  554. c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
  555. | REGULATOR_CHANGE_MODE
  556. | REGULATOR_CHANGE_STATUS;
  557. switch (pdev->id) {
  558. case TWL4030_REG_VIO:
  559. case TWL4030_REG_VDD1:
  560. case TWL4030_REG_VDD2:
  561. case TWL4030_REG_VPLL1:
  562. case TWL4030_REG_VINTANA1:
  563. case TWL4030_REG_VINTANA2:
  564. case TWL4030_REG_VINTDIG:
  565. c->always_on = true;
  566. break;
  567. default:
  568. break;
  569. }
  570. rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
  571. if (IS_ERR(rdev)) {
  572. dev_err(&pdev->dev, "can't register %s, %ld\n",
  573. info->desc.name, PTR_ERR(rdev));
  574. return PTR_ERR(rdev);
  575. }
  576. platform_set_drvdata(pdev, rdev);
  577. twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
  578. info->remap);
  579. /* NOTE: many regulators support short-circuit IRQs (presentable
  580. * as REGULATOR_OVER_CURRENT notifications?) configured via:
  581. * - SC_CONFIG
  582. * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
  583. * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
  584. * - IT_CONFIG
  585. */
  586. return 0;
  587. }
  588. static int __devexit twlreg_remove(struct platform_device *pdev)
  589. {
  590. regulator_unregister(platform_get_drvdata(pdev));
  591. return 0;
  592. }
  593. MODULE_ALIAS("platform:twl_reg");
  594. static struct platform_driver twlreg_driver = {
  595. .probe = twlreg_probe,
  596. .remove = __devexit_p(twlreg_remove),
  597. /* NOTE: short name, to work around driver model truncation of
  598. * "twl_regulator.12" (and friends) to "twl_regulator.1".
  599. */
  600. .driver.name = "twl_reg",
  601. .driver.owner = THIS_MODULE,
  602. };
  603. static int __init twlreg_init(void)
  604. {
  605. return platform_driver_register(&twlreg_driver);
  606. }
  607. subsys_initcall(twlreg_init);
  608. static void __exit twlreg_exit(void)
  609. {
  610. platform_driver_unregister(&twlreg_driver);
  611. }
  612. module_exit(twlreg_exit)
  613. MODULE_DESCRIPTION("TWL regulator driver");
  614. MODULE_LICENSE("GPL");