twl-regulator.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  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/of.h>
  17. #include <linux/of_device.h>
  18. #include <linux/regulator/driver.h>
  19. #include <linux/regulator/machine.h>
  20. #include <linux/regulator/of_regulator.h>
  21. #include <linux/i2c/twl.h>
  22. /*
  23. * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
  24. * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
  25. * include an audio codec, battery charger, and more voltage regulators.
  26. * These chips are often used in OMAP-based systems.
  27. *
  28. * This driver implements software-based resource control for various
  29. * voltage regulators. This is usually augmented with state machine
  30. * based control.
  31. */
  32. struct twlreg_info {
  33. /* start of regulator's PM_RECEIVER control register bank */
  34. u8 base;
  35. /* twl resource ID, for resource control state machine */
  36. u8 id;
  37. /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
  38. u8 table_len;
  39. const u16 *table;
  40. /* regulator specific turn-on delay */
  41. u16 delay;
  42. /* State REMAP default configuration */
  43. u8 remap;
  44. /* chip constraints on regulator behavior */
  45. u16 min_mV;
  46. u16 max_mV;
  47. u8 flags;
  48. /* used by regulator core */
  49. struct regulator_desc desc;
  50. /* chip specific features */
  51. unsigned long features;
  52. /*
  53. * optional override functions for voltage set/get
  54. * these are currently only used for SMPS regulators
  55. */
  56. int (*get_voltage)(void *data);
  57. int (*set_voltage)(void *data, int target_uV);
  58. /* data passed from board for external get/set voltage */
  59. void *data;
  60. };
  61. /* LDO control registers ... offset is from the base of its register bank.
  62. * The first three registers of all power resource banks help hardware to
  63. * manage the various resource groups.
  64. */
  65. /* Common offset in TWL4030/6030 */
  66. #define VREG_GRP 0
  67. /* TWL4030 register offsets */
  68. #define VREG_TYPE 1
  69. #define VREG_REMAP 2
  70. #define VREG_DEDICATED 3 /* LDO control */
  71. #define VREG_VOLTAGE_SMPS_4030 9
  72. /* TWL6030 register offsets */
  73. #define VREG_TRANS 1
  74. #define VREG_STATE 2
  75. #define VREG_VOLTAGE 3
  76. #define VREG_VOLTAGE_SMPS 4
  77. /* TWL6030 Misc register offsets */
  78. #define VREG_BC_ALL 1
  79. #define VREG_BC_REF 2
  80. #define VREG_BC_PROC 3
  81. #define VREG_BC_CLK_RST 4
  82. /* TWL6030 LDO register values for CFG_STATE */
  83. #define TWL6030_CFG_STATE_OFF 0x00
  84. #define TWL6030_CFG_STATE_ON 0x01
  85. #define TWL6030_CFG_STATE_OFF2 0x02
  86. #define TWL6030_CFG_STATE_SLEEP 0x03
  87. #define TWL6030_CFG_STATE_GRP_SHIFT 5
  88. #define TWL6030_CFG_STATE_APP_SHIFT 2
  89. #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
  90. #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
  91. TWL6030_CFG_STATE_APP_SHIFT)
  92. /* Flags for SMPS Voltage reading */
  93. #define SMPS_OFFSET_EN BIT(0)
  94. #define SMPS_EXTENDED_EN BIT(1)
  95. /* twl6025 SMPS EPROM values */
  96. #define TWL6030_SMPS_OFFSET 0xB0
  97. #define TWL6030_SMPS_MULT 0xB3
  98. #define SMPS_MULTOFFSET_SMPS4 BIT(0)
  99. #define SMPS_MULTOFFSET_VIO BIT(1)
  100. #define SMPS_MULTOFFSET_SMPS3 BIT(6)
  101. static inline int
  102. twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
  103. {
  104. u8 value;
  105. int status;
  106. status = twl_i2c_read_u8(slave_subgp,
  107. &value, info->base + offset);
  108. return (status < 0) ? status : value;
  109. }
  110. static inline int
  111. twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
  112. u8 value)
  113. {
  114. return twl_i2c_write_u8(slave_subgp,
  115. value, info->base + offset);
  116. }
  117. /*----------------------------------------------------------------------*/
  118. /* generic power resource operations, which work on all regulators */
  119. static int twlreg_grp(struct regulator_dev *rdev)
  120. {
  121. return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
  122. VREG_GRP);
  123. }
  124. /*
  125. * Enable/disable regulators by joining/leaving the P1 (processor) group.
  126. * We assume nobody else is updating the DEV_GRP registers.
  127. */
  128. /* definition for 4030 family */
  129. #define P3_GRP_4030 BIT(7) /* "peripherals" */
  130. #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
  131. #define P1_GRP_4030 BIT(5) /* CPU/Linux */
  132. /* definition for 6030 family */
  133. #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
  134. #define P2_GRP_6030 BIT(1) /* "peripherals" */
  135. #define P1_GRP_6030 BIT(0) /* CPU/Linux */
  136. static int twl4030reg_is_enabled(struct regulator_dev *rdev)
  137. {
  138. int state = twlreg_grp(rdev);
  139. if (state < 0)
  140. return state;
  141. return state & P1_GRP_4030;
  142. }
  143. static int twl6030reg_is_enabled(struct regulator_dev *rdev)
  144. {
  145. struct twlreg_info *info = rdev_get_drvdata(rdev);
  146. int grp = 0, val;
  147. if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
  148. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  149. if (grp < 0)
  150. return grp;
  151. if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
  152. grp &= P1_GRP_6030;
  153. else
  154. grp = 1;
  155. val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
  156. val = TWL6030_CFG_STATE_APP(val);
  157. return grp && (val == TWL6030_CFG_STATE_ON);
  158. }
  159. static int twl4030reg_enable(struct regulator_dev *rdev)
  160. {
  161. struct twlreg_info *info = rdev_get_drvdata(rdev);
  162. int grp;
  163. int ret;
  164. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  165. if (grp < 0)
  166. return grp;
  167. grp |= P1_GRP_4030;
  168. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
  169. udelay(info->delay);
  170. return ret;
  171. }
  172. static int twl6030reg_enable(struct regulator_dev *rdev)
  173. {
  174. struct twlreg_info *info = rdev_get_drvdata(rdev);
  175. int grp = 0;
  176. int ret;
  177. if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
  178. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  179. if (grp < 0)
  180. return grp;
  181. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
  182. grp << TWL6030_CFG_STATE_GRP_SHIFT |
  183. TWL6030_CFG_STATE_ON);
  184. udelay(info->delay);
  185. return ret;
  186. }
  187. static int twl4030reg_disable(struct regulator_dev *rdev)
  188. {
  189. struct twlreg_info *info = rdev_get_drvdata(rdev);
  190. int grp;
  191. int ret;
  192. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  193. if (grp < 0)
  194. return grp;
  195. grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
  196. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
  197. return ret;
  198. }
  199. static int twl6030reg_disable(struct regulator_dev *rdev)
  200. {
  201. struct twlreg_info *info = rdev_get_drvdata(rdev);
  202. int grp = 0;
  203. int ret;
  204. if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
  205. grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
  206. /* For 6030, set the off state for all grps enabled */
  207. ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
  208. (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
  209. TWL6030_CFG_STATE_OFF);
  210. return ret;
  211. }
  212. static int twl4030reg_get_status(struct regulator_dev *rdev)
  213. {
  214. int state = twlreg_grp(rdev);
  215. if (state < 0)
  216. return state;
  217. state &= 0x0f;
  218. /* assume state != WARM_RESET; we'd not be running... */
  219. if (!state)
  220. return REGULATOR_STATUS_OFF;
  221. return (state & BIT(3))
  222. ? REGULATOR_STATUS_NORMAL
  223. : REGULATOR_STATUS_STANDBY;
  224. }
  225. static int twl6030reg_get_status(struct regulator_dev *rdev)
  226. {
  227. struct twlreg_info *info = rdev_get_drvdata(rdev);
  228. int val;
  229. val = twlreg_grp(rdev);
  230. if (val < 0)
  231. return val;
  232. val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
  233. switch (TWL6030_CFG_STATE_APP(val)) {
  234. case TWL6030_CFG_STATE_ON:
  235. return REGULATOR_STATUS_NORMAL;
  236. case TWL6030_CFG_STATE_SLEEP:
  237. return REGULATOR_STATUS_STANDBY;
  238. case TWL6030_CFG_STATE_OFF:
  239. case TWL6030_CFG_STATE_OFF2:
  240. default:
  241. break;
  242. }
  243. return REGULATOR_STATUS_OFF;
  244. }
  245. static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
  246. {
  247. struct twlreg_info *info = rdev_get_drvdata(rdev);
  248. unsigned message;
  249. int status;
  250. /* We can only set the mode through state machine commands... */
  251. switch (mode) {
  252. case REGULATOR_MODE_NORMAL:
  253. message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
  254. break;
  255. case REGULATOR_MODE_STANDBY:
  256. message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
  257. break;
  258. default:
  259. return -EINVAL;
  260. }
  261. /* Ensure the resource is associated with some group */
  262. status = twlreg_grp(rdev);
  263. if (status < 0)
  264. return status;
  265. if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
  266. return -EACCES;
  267. status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
  268. message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
  269. if (status < 0)
  270. return status;
  271. return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
  272. message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
  273. }
  274. static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
  275. {
  276. struct twlreg_info *info = rdev_get_drvdata(rdev);
  277. int grp = 0;
  278. int val;
  279. if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
  280. grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
  281. if (grp < 0)
  282. return grp;
  283. /* Compose the state register settings */
  284. val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
  285. /* We can only set the mode through state machine commands... */
  286. switch (mode) {
  287. case REGULATOR_MODE_NORMAL:
  288. val |= TWL6030_CFG_STATE_ON;
  289. break;
  290. case REGULATOR_MODE_STANDBY:
  291. val |= TWL6030_CFG_STATE_SLEEP;
  292. break;
  293. default:
  294. return -EINVAL;
  295. }
  296. return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
  297. }
  298. /*----------------------------------------------------------------------*/
  299. /*
  300. * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
  301. * select field in its control register. We use tables indexed by VSEL
  302. * to record voltages in milliVolts. (Accuracy is about three percent.)
  303. *
  304. * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
  305. * currently handled by listing two slightly different VAUX2 regulators,
  306. * only one of which will be configured.
  307. *
  308. * VSEL values documented as "TI cannot support these values" are flagged
  309. * in these tables as UNSUP() values; we normally won't assign them.
  310. *
  311. * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
  312. * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
  313. */
  314. #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
  315. #define UNSUP_MASK 0x0000
  316. #else
  317. #define UNSUP_MASK 0x8000
  318. #endif
  319. #define UNSUP(x) (UNSUP_MASK | (x))
  320. #define IS_UNSUP(x) (UNSUP_MASK & (x))
  321. #define LDO_MV(x) (~UNSUP_MASK & (x))
  322. static const u16 VAUX1_VSEL_table[] = {
  323. UNSUP(1500), UNSUP(1800), 2500, 2800,
  324. 3000, 3000, 3000, 3000,
  325. };
  326. static const u16 VAUX2_4030_VSEL_table[] = {
  327. UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
  328. 1500, 1800, UNSUP(1850), 2500,
  329. UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
  330. UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
  331. };
  332. static const u16 VAUX2_VSEL_table[] = {
  333. 1700, 1700, 1900, 1300,
  334. 1500, 1800, 2000, 2500,
  335. 2100, 2800, 2200, 2300,
  336. 2400, 2400, 2400, 2400,
  337. };
  338. static const u16 VAUX3_VSEL_table[] = {
  339. 1500, 1800, 2500, 2800,
  340. 3000, 3000, 3000, 3000,
  341. };
  342. static const u16 VAUX4_VSEL_table[] = {
  343. 700, 1000, 1200, UNSUP(1300),
  344. 1500, 1800, UNSUP(1850), 2500,
  345. UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
  346. UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
  347. };
  348. static const u16 VMMC1_VSEL_table[] = {
  349. 1850, 2850, 3000, 3150,
  350. };
  351. static const u16 VMMC2_VSEL_table[] = {
  352. UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
  353. UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
  354. 2600, 2800, 2850, 3000,
  355. 3150, 3150, 3150, 3150,
  356. };
  357. static const u16 VPLL1_VSEL_table[] = {
  358. 1000, 1200, 1300, 1800,
  359. UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
  360. };
  361. static const u16 VPLL2_VSEL_table[] = {
  362. 700, 1000, 1200, 1300,
  363. UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
  364. UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
  365. UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
  366. };
  367. static const u16 VSIM_VSEL_table[] = {
  368. UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
  369. 2800, 3000, 3000, 3000,
  370. };
  371. static const u16 VDAC_VSEL_table[] = {
  372. 1200, 1300, 1800, 1800,
  373. };
  374. static const u16 VDD1_VSEL_table[] = {
  375. 800, 1450,
  376. };
  377. static const u16 VDD2_VSEL_table[] = {
  378. 800, 1450, 1500,
  379. };
  380. static const u16 VIO_VSEL_table[] = {
  381. 1800, 1850,
  382. };
  383. static const u16 VINTANA2_VSEL_table[] = {
  384. 2500, 2750,
  385. };
  386. static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
  387. {
  388. struct twlreg_info *info = rdev_get_drvdata(rdev);
  389. int mV = info->table[index];
  390. return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
  391. }
  392. static int
  393. twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  394. unsigned *selector)
  395. {
  396. struct twlreg_info *info = rdev_get_drvdata(rdev);
  397. int vsel;
  398. for (vsel = 0; vsel < info->table_len; vsel++) {
  399. int mV = info->table[vsel];
  400. int uV;
  401. if (IS_UNSUP(mV))
  402. continue;
  403. uV = LDO_MV(mV) * 1000;
  404. /* REVISIT for VAUX2, first match may not be best/lowest */
  405. /* use the first in-range value */
  406. if (min_uV <= uV && uV <= max_uV) {
  407. *selector = vsel;
  408. return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
  409. VREG_VOLTAGE, vsel);
  410. }
  411. }
  412. return -EDOM;
  413. }
  414. static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
  415. {
  416. struct twlreg_info *info = rdev_get_drvdata(rdev);
  417. int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
  418. VREG_VOLTAGE);
  419. if (vsel < 0)
  420. return vsel;
  421. vsel &= info->table_len - 1;
  422. return LDO_MV(info->table[vsel]) * 1000;
  423. }
  424. static struct regulator_ops twl4030ldo_ops = {
  425. .list_voltage = twl4030ldo_list_voltage,
  426. .set_voltage = twl4030ldo_set_voltage,
  427. .get_voltage = twl4030ldo_get_voltage,
  428. .enable = twl4030reg_enable,
  429. .disable = twl4030reg_disable,
  430. .is_enabled = twl4030reg_is_enabled,
  431. .set_mode = twl4030reg_set_mode,
  432. .get_status = twl4030reg_get_status,
  433. };
  434. static int
  435. twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  436. unsigned *selector)
  437. {
  438. struct twlreg_info *info = rdev_get_drvdata(rdev);
  439. int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
  440. if (info->set_voltage) {
  441. return info->set_voltage(info->data, min_uV);
  442. } else {
  443. twlreg_write(info, TWL_MODULE_PM_RECEIVER,
  444. VREG_VOLTAGE_SMPS_4030, vsel);
  445. }
  446. return 0;
  447. }
  448. static int twl4030smps_get_voltage(struct regulator_dev *rdev)
  449. {
  450. struct twlreg_info *info = rdev_get_drvdata(rdev);
  451. int vsel;
  452. if (info->get_voltage)
  453. return info->get_voltage(info->data);
  454. vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
  455. VREG_VOLTAGE_SMPS_4030);
  456. return vsel * 12500 + 600000;
  457. }
  458. static struct regulator_ops twl4030smps_ops = {
  459. .set_voltage = twl4030smps_set_voltage,
  460. .get_voltage = twl4030smps_get_voltage,
  461. };
  462. static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV,
  463. int max_uV, unsigned *selector)
  464. {
  465. struct twlreg_info *info = rdev_get_drvdata(rdev);
  466. if (info->set_voltage)
  467. return info->set_voltage(info->data, min_uV);
  468. return -ENODEV;
  469. }
  470. static int twl6030coresmps_get_voltage(struct regulator_dev *rdev)
  471. {
  472. struct twlreg_info *info = rdev_get_drvdata(rdev);
  473. if (info->get_voltage)
  474. return info->get_voltage(info->data);
  475. return -ENODEV;
  476. }
  477. static struct regulator_ops twl6030coresmps_ops = {
  478. .set_voltage = twl6030coresmps_set_voltage,
  479. .get_voltage = twl6030coresmps_get_voltage,
  480. };
  481. static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
  482. {
  483. struct twlreg_info *info = rdev_get_drvdata(rdev);
  484. return ((info->min_mV + (index * 100)) * 1000);
  485. }
  486. static int
  487. twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  488. unsigned *selector)
  489. {
  490. struct twlreg_info *info = rdev_get_drvdata(rdev);
  491. int vsel;
  492. if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
  493. return -EDOM;
  494. /*
  495. * Use the below formula to calculate vsel
  496. * mV = 1000mv + 100mv * (vsel - 1)
  497. */
  498. vsel = (min_uV/1000 - 1000)/100 + 1;
  499. *selector = vsel;
  500. return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
  501. }
  502. static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
  503. {
  504. struct twlreg_info *info = rdev_get_drvdata(rdev);
  505. int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
  506. VREG_VOLTAGE);
  507. if (vsel < 0)
  508. return vsel;
  509. /*
  510. * Use the below formula to calculate vsel
  511. * mV = 1000mv + 100mv * (vsel - 1)
  512. */
  513. return (1000 + (100 * (vsel - 1))) * 1000;
  514. }
  515. static struct regulator_ops twl6030ldo_ops = {
  516. .list_voltage = twl6030ldo_list_voltage,
  517. .set_voltage = twl6030ldo_set_voltage,
  518. .get_voltage = twl6030ldo_get_voltage,
  519. .enable = twl6030reg_enable,
  520. .disable = twl6030reg_disable,
  521. .is_enabled = twl6030reg_is_enabled,
  522. .set_mode = twl6030reg_set_mode,
  523. .get_status = twl6030reg_get_status,
  524. };
  525. /*----------------------------------------------------------------------*/
  526. /*
  527. * Fixed voltage LDOs don't have a VSEL field to update.
  528. */
  529. static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
  530. {
  531. struct twlreg_info *info = rdev_get_drvdata(rdev);
  532. return info->min_mV * 1000;
  533. }
  534. static int twlfixed_get_voltage(struct regulator_dev *rdev)
  535. {
  536. struct twlreg_info *info = rdev_get_drvdata(rdev);
  537. return info->min_mV * 1000;
  538. }
  539. static struct regulator_ops twl4030fixed_ops = {
  540. .list_voltage = twlfixed_list_voltage,
  541. .get_voltage = twlfixed_get_voltage,
  542. .enable = twl4030reg_enable,
  543. .disable = twl4030reg_disable,
  544. .is_enabled = twl4030reg_is_enabled,
  545. .set_mode = twl4030reg_set_mode,
  546. .get_status = twl4030reg_get_status,
  547. };
  548. static struct regulator_ops twl6030fixed_ops = {
  549. .list_voltage = twlfixed_list_voltage,
  550. .get_voltage = twlfixed_get_voltage,
  551. .enable = twl6030reg_enable,
  552. .disable = twl6030reg_disable,
  553. .is_enabled = twl6030reg_is_enabled,
  554. .set_mode = twl6030reg_set_mode,
  555. .get_status = twl6030reg_get_status,
  556. };
  557. static struct regulator_ops twl6030_fixed_resource = {
  558. .enable = twl6030reg_enable,
  559. .disable = twl6030reg_disable,
  560. .is_enabled = twl6030reg_is_enabled,
  561. .get_status = twl6030reg_get_status,
  562. };
  563. /*
  564. * SMPS status and control
  565. */
  566. static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
  567. {
  568. struct twlreg_info *info = rdev_get_drvdata(rdev);
  569. int voltage = 0;
  570. switch (info->flags) {
  571. case SMPS_OFFSET_EN:
  572. voltage = 100000;
  573. /* fall through */
  574. case 0:
  575. switch (index) {
  576. case 0:
  577. voltage = 0;
  578. break;
  579. case 58:
  580. voltage = 1350 * 1000;
  581. break;
  582. case 59:
  583. voltage = 1500 * 1000;
  584. break;
  585. case 60:
  586. voltage = 1800 * 1000;
  587. break;
  588. case 61:
  589. voltage = 1900 * 1000;
  590. break;
  591. case 62:
  592. voltage = 2100 * 1000;
  593. break;
  594. default:
  595. voltage += (600000 + (12500 * (index - 1)));
  596. }
  597. break;
  598. case SMPS_EXTENDED_EN:
  599. switch (index) {
  600. case 0:
  601. voltage = 0;
  602. break;
  603. case 58:
  604. voltage = 2084 * 1000;
  605. break;
  606. case 59:
  607. voltage = 2315 * 1000;
  608. break;
  609. case 60:
  610. voltage = 2778 * 1000;
  611. break;
  612. case 61:
  613. voltage = 2932 * 1000;
  614. break;
  615. case 62:
  616. voltage = 3241 * 1000;
  617. break;
  618. default:
  619. voltage = (1852000 + (38600 * (index - 1)));
  620. }
  621. break;
  622. case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
  623. switch (index) {
  624. case 0:
  625. voltage = 0;
  626. break;
  627. case 58:
  628. voltage = 4167 * 1000;
  629. break;
  630. case 59:
  631. voltage = 2315 * 1000;
  632. break;
  633. case 60:
  634. voltage = 2778 * 1000;
  635. break;
  636. case 61:
  637. voltage = 2932 * 1000;
  638. break;
  639. case 62:
  640. voltage = 3241 * 1000;
  641. break;
  642. default:
  643. voltage = (2161000 + (38600 * (index - 1)));
  644. }
  645. break;
  646. }
  647. return voltage;
  648. }
  649. static int
  650. twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
  651. unsigned int *selector)
  652. {
  653. struct twlreg_info *info = rdev_get_drvdata(rdev);
  654. int vsel = 0;
  655. switch (info->flags) {
  656. case 0:
  657. if (min_uV == 0)
  658. vsel = 0;
  659. else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
  660. int calc_uV;
  661. vsel = (min_uV - 600000) / 125;
  662. if (vsel % 100)
  663. vsel += 100;
  664. vsel /= 100;
  665. vsel++;
  666. calc_uV = twl6030smps_list_voltage(rdev, vsel);
  667. if (calc_uV > max_uV)
  668. return -EINVAL;
  669. }
  670. /* Values 1..57 for vsel are linear and can be calculated
  671. * values 58..62 are non linear.
  672. */
  673. else if ((min_uV > 1900000) && (max_uV >= 2100000))
  674. vsel = 62;
  675. else if ((min_uV > 1800000) && (max_uV >= 1900000))
  676. vsel = 61;
  677. else if ((min_uV > 1500000) && (max_uV >= 1800000))
  678. vsel = 60;
  679. else if ((min_uV > 1350000) && (max_uV >= 1500000))
  680. vsel = 59;
  681. else if ((min_uV > 1300000) && (max_uV >= 1350000))
  682. vsel = 58;
  683. else
  684. return -EINVAL;
  685. break;
  686. case SMPS_OFFSET_EN:
  687. if (min_uV == 0)
  688. vsel = 0;
  689. else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
  690. int calc_uV;
  691. vsel = (min_uV - 700000) / 125;
  692. if (vsel % 100)
  693. vsel += 100;
  694. vsel /= 100;
  695. vsel++;
  696. calc_uV = twl6030smps_list_voltage(rdev, vsel);
  697. if (calc_uV > max_uV)
  698. return -EINVAL;
  699. }
  700. /* Values 1..57 for vsel are linear and can be calculated
  701. * values 58..62 are non linear.
  702. */
  703. else if ((min_uV > 1900000) && (max_uV >= 2100000))
  704. vsel = 62;
  705. else if ((min_uV > 1800000) && (max_uV >= 1900000))
  706. vsel = 61;
  707. else if ((min_uV > 1350000) && (max_uV >= 1800000))
  708. vsel = 60;
  709. else if ((min_uV > 1350000) && (max_uV >= 1500000))
  710. vsel = 59;
  711. else if ((min_uV > 1300000) && (max_uV >= 1350000))
  712. vsel = 58;
  713. else
  714. return -EINVAL;
  715. break;
  716. case SMPS_EXTENDED_EN:
  717. if (min_uV == 0)
  718. vsel = 0;
  719. else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
  720. vsel = (min_uV - 1852000) / 386;
  721. if (vsel % 100)
  722. vsel += 100;
  723. vsel /= 100;
  724. vsel++;
  725. }
  726. break;
  727. case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
  728. if (min_uV == 0)
  729. vsel = 0;
  730. else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
  731. vsel = (min_uV - 2161000) / 386;
  732. if (vsel % 100)
  733. vsel += 100;
  734. vsel /= 100;
  735. vsel++;
  736. }
  737. break;
  738. }
  739. *selector = vsel;
  740. return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
  741. vsel);
  742. }
  743. static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
  744. {
  745. struct twlreg_info *info = rdev_get_drvdata(rdev);
  746. return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
  747. }
  748. static struct regulator_ops twlsmps_ops = {
  749. .list_voltage = twl6030smps_list_voltage,
  750. .set_voltage = twl6030smps_set_voltage,
  751. .get_voltage_sel = twl6030smps_get_voltage_sel,
  752. .enable = twl6030reg_enable,
  753. .disable = twl6030reg_disable,
  754. .is_enabled = twl6030reg_is_enabled,
  755. .set_mode = twl6030reg_set_mode,
  756. .get_status = twl6030reg_get_status,
  757. };
  758. /*----------------------------------------------------------------------*/
  759. #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
  760. remap_conf) \
  761. TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
  762. remap_conf, TWL4030, twl4030fixed_ops)
  763. #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
  764. TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
  765. 0x0, TWL6030, twl6030fixed_ops)
  766. #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
  767. static struct twlreg_info TWL4030_INFO_##label = { \
  768. .base = offset, \
  769. .id = num, \
  770. .table_len = ARRAY_SIZE(label##_VSEL_table), \
  771. .table = label##_VSEL_table, \
  772. .delay = turnon_delay, \
  773. .remap = remap_conf, \
  774. .desc = { \
  775. .name = #label, \
  776. .id = TWL4030_REG_##label, \
  777. .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
  778. .ops = &twl4030ldo_ops, \
  779. .type = REGULATOR_VOLTAGE, \
  780. .owner = THIS_MODULE, \
  781. }, \
  782. }
  783. #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
  784. static struct twlreg_info TWL4030_INFO_##label = { \
  785. .base = offset, \
  786. .id = num, \
  787. .delay = turnon_delay, \
  788. .remap = remap_conf, \
  789. .desc = { \
  790. .name = #label, \
  791. .id = TWL4030_REG_##label, \
  792. .ops = &twl4030smps_ops, \
  793. .type = REGULATOR_VOLTAGE, \
  794. .owner = THIS_MODULE, \
  795. }, \
  796. }
  797. #define TWL6030_ADJUSTABLE_SMPS(label) \
  798. static struct twlreg_info TWL6030_INFO_##label = { \
  799. .desc = { \
  800. .name = #label, \
  801. .id = TWL6030_REG_##label, \
  802. .ops = &twl6030coresmps_ops, \
  803. .type = REGULATOR_VOLTAGE, \
  804. .owner = THIS_MODULE, \
  805. }, \
  806. }
  807. #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
  808. static struct twlreg_info TWL6030_INFO_##label = { \
  809. .base = offset, \
  810. .min_mV = min_mVolts, \
  811. .max_mV = max_mVolts, \
  812. .desc = { \
  813. .name = #label, \
  814. .id = TWL6030_REG_##label, \
  815. .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \
  816. .ops = &twl6030ldo_ops, \
  817. .type = REGULATOR_VOLTAGE, \
  818. .owner = THIS_MODULE, \
  819. }, \
  820. }
  821. #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
  822. static struct twlreg_info TWL6025_INFO_##label = { \
  823. .base = offset, \
  824. .min_mV = min_mVolts, \
  825. .max_mV = max_mVolts, \
  826. .desc = { \
  827. .name = #label, \
  828. .id = TWL6025_REG_##label, \
  829. .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \
  830. .ops = &twl6030ldo_ops, \
  831. .type = REGULATOR_VOLTAGE, \
  832. .owner = THIS_MODULE, \
  833. }, \
  834. }
  835. #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
  836. family, operations) \
  837. static struct twlreg_info TWLFIXED_INFO_##label = { \
  838. .base = offset, \
  839. .id = num, \
  840. .min_mV = mVolts, \
  841. .delay = turnon_delay, \
  842. .remap = remap_conf, \
  843. .desc = { \
  844. .name = #label, \
  845. .id = family##_REG_##label, \
  846. .n_voltages = 1, \
  847. .ops = &operations, \
  848. .type = REGULATOR_VOLTAGE, \
  849. .owner = THIS_MODULE, \
  850. }, \
  851. }
  852. #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
  853. static struct twlreg_info TWLRES_INFO_##label = { \
  854. .base = offset, \
  855. .delay = turnon_delay, \
  856. .desc = { \
  857. .name = #label, \
  858. .id = TWL6030_REG_##label, \
  859. .ops = &twl6030_fixed_resource, \
  860. .type = REGULATOR_VOLTAGE, \
  861. .owner = THIS_MODULE, \
  862. }, \
  863. }
  864. #define TWL6025_ADJUSTABLE_SMPS(label, offset) \
  865. static struct twlreg_info TWLSMPS_INFO_##label = { \
  866. .base = offset, \
  867. .min_mV = 600, \
  868. .max_mV = 2100, \
  869. .desc = { \
  870. .name = #label, \
  871. .id = TWL6025_REG_##label, \
  872. .n_voltages = 63, \
  873. .ops = &twlsmps_ops, \
  874. .type = REGULATOR_VOLTAGE, \
  875. .owner = THIS_MODULE, \
  876. }, \
  877. }
  878. /*
  879. * We list regulators here if systems need some level of
  880. * software control over them after boot.
  881. */
  882. TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08);
  883. TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08);
  884. TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08);
  885. TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08);
  886. TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08);
  887. TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08);
  888. TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08);
  889. TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00);
  890. TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08);
  891. TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00);
  892. TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08);
  893. TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08);
  894. TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08);
  895. TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08);
  896. TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08);
  897. /* VUSBCP is managed *only* by the USB subchip */
  898. /* 6030 REG with base as PMC Slave Misc : 0x0030 */
  899. /* Turnon-delay and remap configuration values for 6030 are not
  900. verified since the specification is not public */
  901. TWL6030_ADJUSTABLE_SMPS(VDD1);
  902. TWL6030_ADJUSTABLE_SMPS(VDD2);
  903. TWL6030_ADJUSTABLE_SMPS(VDD3);
  904. TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300);
  905. TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300);
  906. TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300);
  907. TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300);
  908. TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300);
  909. TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300);
  910. /* 6025 are renamed compared to 6030 versions */
  911. TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300);
  912. TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300);
  913. TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300);
  914. TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300);
  915. TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300);
  916. TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300);
  917. TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300);
  918. TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300);
  919. TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300);
  920. TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08);
  921. TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08);
  922. TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08);
  923. TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08);
  924. TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08);
  925. TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0);
  926. TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0);
  927. TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
  928. TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0);
  929. TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0);
  930. TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0);
  931. TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0);
  932. TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34);
  933. TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10);
  934. TWL6025_ADJUSTABLE_SMPS(VIO, 0x16);
  935. static u8 twl_get_smps_offset(void)
  936. {
  937. u8 value;
  938. twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
  939. TWL6030_SMPS_OFFSET);
  940. return value;
  941. }
  942. static u8 twl_get_smps_mult(void)
  943. {
  944. u8 value;
  945. twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
  946. TWL6030_SMPS_MULT);
  947. return value;
  948. }
  949. #define TWL_OF_MATCH(comp, family, label) \
  950. { \
  951. .compatible = comp, \
  952. .data = &family##_INFO_##label, \
  953. }
  954. #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
  955. #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
  956. #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
  957. #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
  958. #define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label)
  959. #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
  960. static const struct of_device_id twl_of_match[] __devinitconst = {
  961. TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1),
  962. TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030),
  963. TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2),
  964. TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3),
  965. TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4),
  966. TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1),
  967. TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2),
  968. TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1),
  969. TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2),
  970. TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM),
  971. TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC),
  972. TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2),
  973. TWL4030_OF_MATCH("ti,twl4030-vio", VIO),
  974. TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1),
  975. TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2),
  976. TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1),
  977. TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2),
  978. TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3),
  979. TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030),
  980. TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030),
  981. TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030),
  982. TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC),
  983. TWL6030_OF_MATCH("ti,twl6030-vpp", VPP),
  984. TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM),
  985. TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2),
  986. TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4),
  987. TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3),
  988. TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5),
  989. TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1),
  990. TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7),
  991. TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6),
  992. TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN),
  993. TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB),
  994. TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1),
  995. TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG),
  996. TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5),
  997. TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8),
  998. TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1),
  999. TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA),
  1000. TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO),
  1001. TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC),
  1002. TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
  1003. TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
  1004. TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
  1005. TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG),
  1006. TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3),
  1007. TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4),
  1008. TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO),
  1009. {},
  1010. };
  1011. MODULE_DEVICE_TABLE(of, twl_of_match);
  1012. static int __devinit twlreg_probe(struct platform_device *pdev)
  1013. {
  1014. int i, id;
  1015. struct twlreg_info *info;
  1016. struct regulator_init_data *initdata;
  1017. struct regulation_constraints *c;
  1018. struct regulator_dev *rdev;
  1019. struct twl_regulator_driver_data *drvdata;
  1020. const struct of_device_id *match;
  1021. match = of_match_device(twl_of_match, &pdev->dev);
  1022. if (match) {
  1023. info = match->data;
  1024. id = info->desc.id;
  1025. initdata = of_get_regulator_init_data(&pdev->dev,
  1026. pdev->dev.of_node);
  1027. drvdata = NULL;
  1028. } else {
  1029. id = pdev->id;
  1030. initdata = pdev->dev.platform_data;
  1031. for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
  1032. info = twl_of_match[i].data;
  1033. if (!info || info->desc.id != id)
  1034. continue;
  1035. break;
  1036. }
  1037. drvdata = initdata->driver_data;
  1038. if (!drvdata)
  1039. return -EINVAL;
  1040. }
  1041. if (!info)
  1042. return -ENODEV;
  1043. if (!initdata)
  1044. return -EINVAL;
  1045. if (drvdata) {
  1046. /* copy the driver data into regulator data */
  1047. info->features = drvdata->features;
  1048. info->data = drvdata->data;
  1049. info->set_voltage = drvdata->set_voltage;
  1050. info->get_voltage = drvdata->get_voltage;
  1051. }
  1052. /* Constrain board-specific capabilities according to what
  1053. * this driver and the chip itself can actually do.
  1054. */
  1055. c = &initdata->constraints;
  1056. c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
  1057. c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
  1058. | REGULATOR_CHANGE_MODE
  1059. | REGULATOR_CHANGE_STATUS;
  1060. switch (id) {
  1061. case TWL4030_REG_VIO:
  1062. case TWL4030_REG_VDD1:
  1063. case TWL4030_REG_VDD2:
  1064. case TWL4030_REG_VPLL1:
  1065. case TWL4030_REG_VINTANA1:
  1066. case TWL4030_REG_VINTANA2:
  1067. case TWL4030_REG_VINTDIG:
  1068. c->always_on = true;
  1069. break;
  1070. default:
  1071. break;
  1072. }
  1073. switch (id) {
  1074. case TWL6025_REG_SMPS3:
  1075. if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
  1076. info->flags |= SMPS_EXTENDED_EN;
  1077. if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
  1078. info->flags |= SMPS_OFFSET_EN;
  1079. break;
  1080. case TWL6025_REG_SMPS4:
  1081. if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
  1082. info->flags |= SMPS_EXTENDED_EN;
  1083. if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
  1084. info->flags |= SMPS_OFFSET_EN;
  1085. break;
  1086. case TWL6025_REG_VIO:
  1087. if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
  1088. info->flags |= SMPS_EXTENDED_EN;
  1089. if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
  1090. info->flags |= SMPS_OFFSET_EN;
  1091. break;
  1092. }
  1093. rdev = regulator_register(&info->desc, &pdev->dev, initdata, info,
  1094. pdev->dev.of_node);
  1095. if (IS_ERR(rdev)) {
  1096. dev_err(&pdev->dev, "can't register %s, %ld\n",
  1097. info->desc.name, PTR_ERR(rdev));
  1098. return PTR_ERR(rdev);
  1099. }
  1100. platform_set_drvdata(pdev, rdev);
  1101. if (twl_class_is_4030())
  1102. twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
  1103. info->remap);
  1104. /* NOTE: many regulators support short-circuit IRQs (presentable
  1105. * as REGULATOR_OVER_CURRENT notifications?) configured via:
  1106. * - SC_CONFIG
  1107. * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
  1108. * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
  1109. * - IT_CONFIG
  1110. */
  1111. return 0;
  1112. }
  1113. static int __devexit twlreg_remove(struct platform_device *pdev)
  1114. {
  1115. regulator_unregister(platform_get_drvdata(pdev));
  1116. return 0;
  1117. }
  1118. MODULE_ALIAS("platform:twl_reg");
  1119. static struct platform_driver twlreg_driver = {
  1120. .probe = twlreg_probe,
  1121. .remove = __devexit_p(twlreg_remove),
  1122. /* NOTE: short name, to work around driver model truncation of
  1123. * "twl_regulator.12" (and friends) to "twl_regulator.1".
  1124. */
  1125. .driver = {
  1126. .name = "twl_reg",
  1127. .owner = THIS_MODULE,
  1128. .of_match_table = of_match_ptr(twl_of_match),
  1129. },
  1130. };
  1131. static int __init twlreg_init(void)
  1132. {
  1133. return platform_driver_register(&twlreg_driver);
  1134. }
  1135. subsys_initcall(twlreg_init);
  1136. static void __exit twlreg_exit(void)
  1137. {
  1138. platform_driver_unregister(&twlreg_driver);
  1139. }
  1140. module_exit(twlreg_exit)
  1141. MODULE_DESCRIPTION("TWL regulator driver");
  1142. MODULE_LICENSE("GPL");