cpcap-regulator.c 18 KB

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