twl-regulator.c 17 KB

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