cpcap-regulator.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. * Motorola CPCAP PMIC regulator driver
  3. *
  4. * Based on cpcap-regulator.c from Motorola Linux kernel tree
  5. * Copyright (C) 2009-2011 Motorola, Inc.
  6. *
  7. * Rewritten for mainline kernel to use device tree and regmap
  8. * Copyright (C) 2017 Tony Lindgren <tony@atomide.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation version 2.
  13. *
  14. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  15. * kind, whether express or implied; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/err.h>
  20. #include <linux/module.h>
  21. #include <linux/of.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/regmap.h>
  24. #include <linux/regulator/driver.h>
  25. #include <linux/regulator/machine.h>
  26. #include <linux/regulator/of_regulator.h>
  27. #include <linux/mfd/motorola-cpcap.h>
  28. /*
  29. * Resource assignment register bits. These seem to control the state
  30. * idle modes adn are used at least for omap4.
  31. */
  32. /* CPCAP_REG_ASSIGN2 bits - Resource Assignment 2 */
  33. #define CPCAP_BIT_VSDIO_SEL BIT(15)
  34. #define CPCAP_BIT_VDIG_SEL BIT(14)
  35. #define CPCAP_BIT_VCAM_SEL BIT(13)
  36. #define CPCAP_BIT_SW6_SEL BIT(12)
  37. #define CPCAP_BIT_SW5_SEL BIT(11)
  38. #define CPCAP_BIT_SW4_SEL BIT(10)
  39. #define CPCAP_BIT_SW3_SEL BIT(9)
  40. #define CPCAP_BIT_SW2_SEL BIT(8)
  41. #define CPCAP_BIT_SW1_SEL BIT(7)
  42. /* CPCAP_REG_ASSIGN3 bits - Resource Assignment 3 */
  43. #define CPCAP_BIT_VUSBINT2_SEL BIT(15)
  44. #define CPCAP_BIT_VUSBINT1_SEL BIT(14)
  45. #define CPCAP_BIT_VVIB_SEL BIT(13)
  46. #define CPCAP_BIT_VWLAN1_SEL BIT(12)
  47. #define CPCAP_BIT_VRF1_SEL BIT(11)
  48. #define CPCAP_BIT_VHVIO_SEL BIT(10)
  49. #define CPCAP_BIT_VDAC_SEL BIT(9)
  50. #define CPCAP_BIT_VUSB_SEL BIT(8)
  51. #define CPCAP_BIT_VSIM_SEL BIT(7)
  52. #define CPCAP_BIT_VRFREF_SEL BIT(6)
  53. #define CPCAP_BIT_VPLL_SEL BIT(5)
  54. #define CPCAP_BIT_VFUSE_SEL BIT(4)
  55. #define CPCAP_BIT_VCSI_SEL BIT(3)
  56. #define CPCAP_BIT_SPARE_14_2 BIT(2)
  57. #define CPCAP_BIT_VWLAN2_SEL BIT(1)
  58. #define CPCAP_BIT_VRF2_SEL BIT(0)
  59. /* CPCAP_REG_ASSIGN4 bits - Resource Assignment 4 */
  60. #define CPCAP_BIT_VAUDIO_SEL BIT(0)
  61. /*
  62. * Enable register bits. At least CPCAP_BIT_AUDIO_LOW_PWR is generic,
  63. * and not limited to audio regulator. Let's use the Motorola kernel
  64. * naming for now until we have a better understanding of the other
  65. * enable register bits. No idea why BIT(3) is not defined.
  66. */
  67. #define CPCAP_BIT_AUDIO_LOW_PWR BIT(6)
  68. #define CPCAP_BIT_AUD_LOWPWR_SPEED BIT(5)
  69. #define CPCAP_BIT_VAUDIOPRISTBY BIT(4)
  70. #define CPCAP_BIT_VAUDIO_MODE1 BIT(2)
  71. #define CPCAP_BIT_VAUDIO_MODE0 BIT(1)
  72. #define CPCAP_BIT_V_AUDIO_EN BIT(0)
  73. #define CPCAP_BIT_AUDIO_NORMAL_MODE 0x00
  74. /*
  75. * Off mode configuration bit. Used currently only by SW5 on omap4. There's
  76. * the following comment in Motorola Linux kernel tree for it:
  77. *
  78. * When set in the regulator mode, the regulator assignment will be changed
  79. * to secondary when the regulator is disabled. The mode will be set back to
  80. * primary when the regulator is turned on.
  81. */
  82. #define CPCAP_REG_OFF_MODE_SEC BIT(15)
  83. /**
  84. * SoC specific configuration for CPCAP regulator. There are at least three
  85. * different SoCs each with their own parameters: omap3, omap4 and tegra2.
  86. *
  87. * The assign_reg and assign_mask seem to allow toggling between primary
  88. * and secondary mode that at least omap4 uses for off mode.
  89. */
  90. struct cpcap_regulator {
  91. struct regulator_desc rdesc;
  92. const u16 assign_reg;
  93. const u16 assign_mask;
  94. };
  95. #define CPCAP_REG(_ID, reg, assignment_reg, assignment_mask, val_tbl, \
  96. mode_mask, volt_mask, mode_val, off_val, \
  97. volt_trans_time) { \
  98. .rdesc = { \
  99. .name = #_ID, \
  100. .of_match = of_match_ptr(#_ID), \
  101. .ops = &cpcap_regulator_ops, \
  102. .regulators_node = of_match_ptr("regulators"), \
  103. .type = REGULATOR_VOLTAGE, \
  104. .id = CPCAP_##_ID, \
  105. .owner = THIS_MODULE, \
  106. .n_voltages = ARRAY_SIZE(val_tbl), \
  107. .volt_table = (val_tbl), \
  108. .vsel_reg = (reg), \
  109. .vsel_mask = (volt_mask), \
  110. .enable_reg = (reg), \
  111. .enable_mask = (mode_mask), \
  112. .enable_val = (mode_val), \
  113. .disable_val = (off_val), \
  114. .ramp_delay = (volt_trans_time), \
  115. .of_map_mode = cpcap_map_mode, \
  116. }, \
  117. .assign_reg = (assignment_reg), \
  118. .assign_mask = (assignment_mask), \
  119. }
  120. struct cpcap_ddata {
  121. struct regmap *reg;
  122. struct device *dev;
  123. const struct cpcap_regulator *soc;
  124. };
  125. enum cpcap_regulator_id {
  126. CPCAP_SW1,
  127. CPCAP_SW2,
  128. CPCAP_SW3,
  129. CPCAP_SW4,
  130. CPCAP_SW5,
  131. CPCAP_SW6,
  132. CPCAP_VCAM,
  133. CPCAP_VCSI,
  134. CPCAP_VDAC,
  135. CPCAP_VDIG,
  136. CPCAP_VFUSE,
  137. CPCAP_VHVIO,
  138. CPCAP_VSDIO,
  139. CPCAP_VPLL,
  140. CPCAP_VRF1,
  141. CPCAP_VRF2,
  142. CPCAP_VRFREF,
  143. CPCAP_VWLAN1,
  144. CPCAP_VWLAN2,
  145. CPCAP_VSIM,
  146. CPCAP_VSIMCARD,
  147. CPCAP_VVIB,
  148. CPCAP_VUSB,
  149. CPCAP_VAUDIO,
  150. CPCAP_NR_REGULATORS,
  151. };
  152. /*
  153. * We need to also configure regulator idle mode for SoC off mode if
  154. * CPCAP_REG_OFF_MODE_SEC is set.
  155. */
  156. static int cpcap_regulator_enable(struct regulator_dev *rdev)
  157. {
  158. struct cpcap_regulator *regulator = rdev_get_drvdata(rdev);
  159. int error, ignore;
  160. error = regulator_enable_regmap(rdev);
  161. if (error)
  162. return error;
  163. if (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC) {
  164. error = regmap_update_bits(rdev->regmap, regulator->assign_reg,
  165. regulator->assign_mask,
  166. regulator->assign_mask);
  167. if (error)
  168. ignore = regulator_disable_regmap(rdev);
  169. }
  170. return error;
  171. }
  172. /*
  173. * We need to also configure regulator idle mode for SoC off mode if
  174. * CPCAP_REG_OFF_MODE_SEC is set.
  175. */
  176. static int cpcap_regulator_disable(struct regulator_dev *rdev)
  177. {
  178. struct cpcap_regulator *regulator = rdev_get_drvdata(rdev);
  179. int error, ignore;
  180. if (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC) {
  181. error = regmap_update_bits(rdev->regmap, regulator->assign_reg,
  182. regulator->assign_mask, 0);
  183. if (error)
  184. return error;
  185. }
  186. error = regulator_disable_regmap(rdev);
  187. if (error && (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC)) {
  188. ignore = regmap_update_bits(rdev->regmap, regulator->assign_reg,
  189. regulator->assign_mask,
  190. regulator->assign_mask);
  191. }
  192. return error;
  193. }
  194. static unsigned int cpcap_map_mode(unsigned int mode)
  195. {
  196. switch (mode) {
  197. case CPCAP_BIT_AUDIO_NORMAL_MODE:
  198. return REGULATOR_MODE_NORMAL;
  199. case CPCAP_BIT_AUDIO_LOW_PWR:
  200. return REGULATOR_MODE_STANDBY;
  201. default:
  202. return REGULATOR_MODE_INVALID;
  203. }
  204. }
  205. static unsigned int cpcap_regulator_get_mode(struct regulator_dev *rdev)
  206. {
  207. int value;
  208. regmap_read(rdev->regmap, rdev->desc->enable_reg, &value);
  209. if (value & CPCAP_BIT_AUDIO_LOW_PWR)
  210. return REGULATOR_MODE_STANDBY;
  211. return REGULATOR_MODE_NORMAL;
  212. }
  213. static int cpcap_regulator_set_mode(struct regulator_dev *rdev,
  214. unsigned int mode)
  215. {
  216. int value;
  217. switch (mode) {
  218. case REGULATOR_MODE_NORMAL:
  219. value = CPCAP_BIT_AUDIO_NORMAL_MODE;
  220. break;
  221. case REGULATOR_MODE_STANDBY:
  222. value = CPCAP_BIT_AUDIO_LOW_PWR;
  223. break;
  224. default:
  225. return -EINVAL;
  226. }
  227. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  228. CPCAP_BIT_AUDIO_LOW_PWR, value);
  229. }
  230. static struct regulator_ops cpcap_regulator_ops = {
  231. .enable = cpcap_regulator_enable,
  232. .disable = cpcap_regulator_disable,
  233. .is_enabled = regulator_is_enabled_regmap,
  234. .list_voltage = regulator_list_voltage_table,
  235. .map_voltage = regulator_map_voltage_iterate,
  236. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  237. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  238. .get_mode = cpcap_regulator_get_mode,
  239. .set_mode = cpcap_regulator_set_mode,
  240. };
  241. static const unsigned int unknown_val_tbl[] = { 0, };
  242. static const unsigned int sw2_sw4_val_tbl[] = { 612500, 625000, 637500,
  243. 650000, 662500, 675000,
  244. 687500, 700000, 712500,
  245. 725000, 737500, 750000,
  246. 762500, 775000, 787500,
  247. 800000, 812500, 825000,
  248. 837500, 850000, 862500,
  249. 875000, 887500, 900000,
  250. 912500, 925000, 937500,
  251. 950000, 962500, 975000,
  252. 987500, 1000000, 1012500,
  253. 1025000, 1037500, 1050000,
  254. 1062500, 1075000, 1087500,
  255. 1100000, 1112500, 1125000,
  256. 1137500, 1150000, 1162500,
  257. 1175000, 1187500, 1200000,
  258. 1212500, 1225000, 1237500,
  259. 1250000, 1262500, 1275000,
  260. 1287500, 1300000, 1312500,
  261. 1325000, 1337500, 1350000,
  262. 1362500, 1375000, 1387500,
  263. 1400000, 1412500, 1425000,
  264. 1437500, 1450000, 1462500, };
  265. static const unsigned int sw5_val_tbl[] = { 0, 5050000, };
  266. static const unsigned int vcam_val_tbl[] = { 2600000, 2700000, 2800000,
  267. 2900000, };
  268. static const unsigned int vcsi_val_tbl[] = { 1200000, 1800000, };
  269. static const unsigned int vdac_val_tbl[] = { 1200000, 1500000, 1800000,
  270. 2500000,};
  271. static const unsigned int vdig_val_tbl[] = { 1200000, 1350000, 1500000,
  272. 1875000, };
  273. static const unsigned int vfuse_val_tbl[] = { 1500000, 1600000, 1700000,
  274. 1800000, 1900000, 2000000,
  275. 2100000, 2200000, 2300000,
  276. 2400000, 2500000, 2600000,
  277. 2700000, 3150000, };
  278. static const unsigned int vhvio_val_tbl[] = { 2775000, };
  279. static const unsigned int vsdio_val_tbl[] = { 1500000, 1600000, 1800000,
  280. 2600000, 2700000, 2800000,
  281. 2900000, 3000000, };
  282. static const unsigned int vpll_val_tbl[] = { 1200000, 1300000, 1400000,
  283. 1800000, };
  284. /* Quirk: 2775000 is before 2500000 for vrf1 regulator */
  285. static const unsigned int vrf1_val_tbl[] = { 2775000, 2500000, };
  286. static const unsigned int vrf2_val_tbl[] = { 0, 2775000, };
  287. static const unsigned int vrfref_val_tbl[] = { 2500000, 2775000, };
  288. static const unsigned int vwlan1_val_tbl[] = { 1800000, 1900000, };
  289. static const unsigned int vwlan2_val_tbl[] = { 2775000, 3000000, 3300000,
  290. 3300000, };
  291. static const unsigned int vsim_val_tbl[] = { 1800000, 2900000, };
  292. static const unsigned int vsimcard_val_tbl[] = { 1800000, 2900000, };
  293. static const unsigned int vvib_val_tbl[] = { 1300000, 1800000, 2000000,
  294. 3000000, };
  295. static const unsigned int vusb_val_tbl[] = { 0, 3300000, };
  296. static const unsigned int vaudio_val_tbl[] = { 0, 2775000, };
  297. /**
  298. * SoC specific configuration for omap4. The data below is comes from Motorola
  299. * Linux kernel tree. It's basically the values of cpcap_regltr_data,
  300. * cpcap_regulator_mode_values and cpcap_regulator_off_mode_values, see
  301. * CPCAP_REG macro above.
  302. *
  303. * SW1 to SW4 and SW6 seems to be unused for mapphone. Note that VSIM and
  304. * VSIMCARD have a shared resource assignment bit.
  305. */
  306. static const struct cpcap_regulator omap4_regulators[] = {
  307. CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2,
  308. CPCAP_BIT_SW1_SEL, unknown_val_tbl,
  309. 0, 0, 0, 0, 0),
  310. CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2,
  311. CPCAP_BIT_SW2_SEL, unknown_val_tbl,
  312. 0, 0, 0, 0, 0),
  313. CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2,
  314. CPCAP_BIT_SW3_SEL, unknown_val_tbl,
  315. 0, 0, 0, 0, 0),
  316. CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2,
  317. CPCAP_BIT_SW4_SEL, unknown_val_tbl,
  318. 0, 0, 0, 0, 0),
  319. CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2,
  320. CPCAP_BIT_SW5_SEL, sw5_val_tbl,
  321. 0x28, 0, 0x20 | CPCAP_REG_OFF_MODE_SEC, 0, 0),
  322. CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2,
  323. CPCAP_BIT_SW6_SEL, unknown_val_tbl,
  324. 0, 0, 0, 0, 0),
  325. CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2,
  326. CPCAP_BIT_VCAM_SEL, vcam_val_tbl,
  327. 0x87, 0x30, 0x3, 0, 420),
  328. CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3,
  329. CPCAP_BIT_VCSI_SEL, vcsi_val_tbl,
  330. 0x47, 0x10, 0x43, 0x41, 350),
  331. CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3,
  332. CPCAP_BIT_VDAC_SEL, vdac_val_tbl,
  333. 0x87, 0x30, 0x3, 0, 420),
  334. CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2,
  335. CPCAP_BIT_VDIG_SEL, vdig_val_tbl,
  336. 0x87, 0x30, 0x82, 0, 420),
  337. CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3,
  338. CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl,
  339. 0x80, 0xf, 0x80, 0, 420),
  340. CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3,
  341. CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl,
  342. 0x17, 0, 0, 0x12, 0),
  343. CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2,
  344. CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl,
  345. 0x87, 0x38, 0x82, 0, 420),
  346. CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3,
  347. CPCAP_BIT_VPLL_SEL, vpll_val_tbl,
  348. 0x43, 0x18, 0x2, 0, 420),
  349. CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3,
  350. CPCAP_BIT_VRF1_SEL, vrf1_val_tbl,
  351. 0xac, 0x2, 0x4, 0, 10),
  352. CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3,
  353. CPCAP_BIT_VRF2_SEL, vrf2_val_tbl,
  354. 0x23, 0x8, 0, 0, 10),
  355. CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3,
  356. CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl,
  357. 0x23, 0x8, 0, 0, 420),
  358. CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3,
  359. CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl,
  360. 0x47, 0x10, 0, 0, 420),
  361. CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3,
  362. CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl,
  363. 0x20c, 0xc0, 0x20c, 0, 420),
  364. CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
  365. 0xffff, vsim_val_tbl,
  366. 0x23, 0x8, 0x3, 0, 420),
  367. CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
  368. 0xffff, vsimcard_val_tbl,
  369. 0x1e80, 0x8, 0x1e00, 0, 420),
  370. CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3,
  371. CPCAP_BIT_VVIB_SEL, vvib_val_tbl,
  372. 0x1, 0xc, 0x1, 0, 500),
  373. CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3,
  374. CPCAP_BIT_VUSB_SEL, vusb_val_tbl,
  375. 0x11c, 0x40, 0xc, 0, 0),
  376. CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4,
  377. CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl,
  378. 0x16, 0x1, 0x4, 0, 0),
  379. { /* sentinel */ },
  380. };
  381. static const struct cpcap_regulator xoom_regulators[] = {
  382. CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2,
  383. CPCAP_BIT_SW1_SEL, unknown_val_tbl,
  384. 0, 0, 0, 0, 0),
  385. CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2,
  386. CPCAP_BIT_SW2_SEL, sw2_sw4_val_tbl,
  387. 0xf00, 0x7f, 0x800, 0, 120),
  388. CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2,
  389. CPCAP_BIT_SW3_SEL, unknown_val_tbl,
  390. 0, 0, 0, 0, 0),
  391. CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2,
  392. CPCAP_BIT_SW4_SEL, sw2_sw4_val_tbl,
  393. 0xf00, 0x7f, 0x900, 0, 100),
  394. CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2,
  395. CPCAP_BIT_SW5_SEL, sw5_val_tbl,
  396. 0x2a, 0, 0x22, 0, 0),
  397. CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2,
  398. CPCAP_BIT_SW6_SEL, unknown_val_tbl,
  399. 0, 0, 0, 0, 0),
  400. CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2,
  401. CPCAP_BIT_VCAM_SEL, vcam_val_tbl,
  402. 0x87, 0x30, 0x7, 0, 420),
  403. CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3,
  404. CPCAP_BIT_VCSI_SEL, vcsi_val_tbl,
  405. 0x47, 0x10, 0x7, 0, 350),
  406. CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3,
  407. CPCAP_BIT_VDAC_SEL, vdac_val_tbl,
  408. 0x87, 0x30, 0x3, 0, 420),
  409. CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2,
  410. CPCAP_BIT_VDIG_SEL, vdig_val_tbl,
  411. 0x87, 0x30, 0x5, 0, 420),
  412. CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3,
  413. CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl,
  414. 0x80, 0xf, 0x80, 0, 420),
  415. CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3,
  416. CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl,
  417. 0x17, 0, 0x2, 0, 0),
  418. CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2,
  419. CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl,
  420. 0x87, 0x38, 0x2, 0, 420),
  421. CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3,
  422. CPCAP_BIT_VPLL_SEL, vpll_val_tbl,
  423. 0x43, 0x18, 0x1, 0, 420),
  424. CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3,
  425. CPCAP_BIT_VRF1_SEL, vrf1_val_tbl,
  426. 0xac, 0x2, 0xc, 0, 10),
  427. CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3,
  428. CPCAP_BIT_VRF2_SEL, vrf2_val_tbl,
  429. 0x23, 0x8, 0x3, 0, 10),
  430. CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3,
  431. CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl,
  432. 0x23, 0x8, 0x3, 0, 420),
  433. CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3,
  434. CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl,
  435. 0x47, 0x10, 0x5, 0, 420),
  436. CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3,
  437. CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl,
  438. 0x20c, 0xc0, 0x8, 0, 420),
  439. CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
  440. 0xffff, vsim_val_tbl,
  441. 0x23, 0x8, 0x3, 0, 420),
  442. CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
  443. 0xffff, vsimcard_val_tbl,
  444. 0x1e80, 0x8, 0x1e00, 0, 420),
  445. CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3,
  446. CPCAP_BIT_VVIB_SEL, vvib_val_tbl,
  447. 0x1, 0xc, 0, 0x1, 500),
  448. CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3,
  449. CPCAP_BIT_VUSB_SEL, vusb_val_tbl,
  450. 0x11c, 0x40, 0xc, 0, 0),
  451. CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4,
  452. CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl,
  453. 0x16, 0x1, 0x4, 0, 0),
  454. { /* sentinel */ },
  455. };
  456. static const struct of_device_id cpcap_regulator_id_table[] = {
  457. {
  458. .compatible = "motorola,cpcap-regulator",
  459. },
  460. {
  461. .compatible = "motorola,mapphone-cpcap-regulator",
  462. .data = omap4_regulators,
  463. },
  464. {
  465. .compatible = "motorola,xoom-cpcap-regulator",
  466. .data = xoom_regulators,
  467. },
  468. {},
  469. };
  470. MODULE_DEVICE_TABLE(of, cpcap_regulator_id_table);
  471. static int cpcap_regulator_probe(struct platform_device *pdev)
  472. {
  473. struct cpcap_ddata *ddata;
  474. const struct cpcap_regulator *match_data;
  475. struct regulator_config config;
  476. int i;
  477. match_data = of_device_get_match_data(&pdev->dev);
  478. if (!match_data) {
  479. dev_err(&pdev->dev, "no configuration data found\n");
  480. return -ENODEV;
  481. }
  482. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  483. if (!ddata)
  484. return -ENOMEM;
  485. ddata->reg = dev_get_regmap(pdev->dev.parent, NULL);
  486. if (!ddata->reg)
  487. return -ENODEV;
  488. ddata->dev = &pdev->dev;
  489. ddata->soc = match_data;
  490. platform_set_drvdata(pdev, ddata);
  491. memset(&config, 0, sizeof(config));
  492. config.dev = &pdev->dev;
  493. config.regmap = ddata->reg;
  494. for (i = 0; i < CPCAP_NR_REGULATORS; i++) {
  495. const struct cpcap_regulator *regulator = &ddata->soc[i];
  496. struct regulator_dev *rdev;
  497. if (!regulator->rdesc.name)
  498. break;
  499. if (regulator->rdesc.volt_table == unknown_val_tbl)
  500. continue;
  501. config.driver_data = (void *)regulator;
  502. rdev = devm_regulator_register(&pdev->dev,
  503. &regulator->rdesc,
  504. &config);
  505. if (IS_ERR(rdev)) {
  506. dev_err(&pdev->dev, "failed to register regulator %s\n",
  507. regulator->rdesc.name);
  508. return PTR_ERR(rdev);
  509. }
  510. }
  511. return 0;
  512. }
  513. static struct platform_driver cpcap_regulator_driver = {
  514. .probe = cpcap_regulator_probe,
  515. .driver = {
  516. .name = "cpcap-regulator",
  517. .of_match_table = of_match_ptr(cpcap_regulator_id_table),
  518. },
  519. };
  520. module_platform_driver(cpcap_regulator_driver);
  521. MODULE_ALIAS("platform:cpcap-regulator");
  522. MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
  523. MODULE_DESCRIPTION("CPCAP regulator driver");
  524. MODULE_LICENSE("GPL v2");