cpcap-regulator.c 18 KB

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