twl-regulator.c 18 KB

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