db8500-prcmu.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
  6. * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
  7. *
  8. * Power domain regulators on DB8500
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/err.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mfd/dbx500-prcmu.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/regulator/machine.h>
  18. #include <linux/regulator/db8500-prcmu.h>
  19. #include <linux/regulator/of_regulator.h>
  20. #include <linux/of.h>
  21. #include <linux/module.h>
  22. #include "dbx500-prcmu.h"
  23. static int db8500_regulator_enable(struct regulator_dev *rdev)
  24. {
  25. struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
  26. if (info == NULL)
  27. return -EINVAL;
  28. dev_vdbg(rdev_get_dev(rdev), "regulator-%s-enable\n",
  29. info->desc.name);
  30. if (!info->is_enabled) {
  31. info->is_enabled = true;
  32. if (!info->exclude_from_power_state)
  33. power_state_active_enable();
  34. }
  35. return 0;
  36. }
  37. static int db8500_regulator_disable(struct regulator_dev *rdev)
  38. {
  39. struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
  40. int ret = 0;
  41. if (info == NULL)
  42. return -EINVAL;
  43. dev_vdbg(rdev_get_dev(rdev), "regulator-%s-disable\n",
  44. info->desc.name);
  45. if (info->is_enabled) {
  46. info->is_enabled = false;
  47. if (!info->exclude_from_power_state)
  48. ret = power_state_active_disable();
  49. }
  50. return ret;
  51. }
  52. static int db8500_regulator_is_enabled(struct regulator_dev *rdev)
  53. {
  54. struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
  55. if (info == NULL)
  56. return -EINVAL;
  57. dev_vdbg(rdev_get_dev(rdev), "regulator-%s-is_enabled (is_enabled):"
  58. " %i\n", info->desc.name, info->is_enabled);
  59. return info->is_enabled;
  60. }
  61. /* db8500 regulator operations */
  62. static const struct regulator_ops db8500_regulator_ops = {
  63. .enable = db8500_regulator_enable,
  64. .disable = db8500_regulator_disable,
  65. .is_enabled = db8500_regulator_is_enabled,
  66. };
  67. /*
  68. * EPOD control
  69. */
  70. static bool epod_on[NUM_EPOD_ID];
  71. static bool epod_ramret[NUM_EPOD_ID];
  72. static int enable_epod(u16 epod_id, bool ramret)
  73. {
  74. int ret;
  75. if (ramret) {
  76. if (!epod_on[epod_id]) {
  77. ret = prcmu_set_epod(epod_id, EPOD_STATE_RAMRET);
  78. if (ret < 0)
  79. return ret;
  80. }
  81. epod_ramret[epod_id] = true;
  82. } else {
  83. ret = prcmu_set_epod(epod_id, EPOD_STATE_ON);
  84. if (ret < 0)
  85. return ret;
  86. epod_on[epod_id] = true;
  87. }
  88. return 0;
  89. }
  90. static int disable_epod(u16 epod_id, bool ramret)
  91. {
  92. int ret;
  93. if (ramret) {
  94. if (!epod_on[epod_id]) {
  95. ret = prcmu_set_epod(epod_id, EPOD_STATE_OFF);
  96. if (ret < 0)
  97. return ret;
  98. }
  99. epod_ramret[epod_id] = false;
  100. } else {
  101. if (epod_ramret[epod_id]) {
  102. ret = prcmu_set_epod(epod_id, EPOD_STATE_RAMRET);
  103. if (ret < 0)
  104. return ret;
  105. } else {
  106. ret = prcmu_set_epod(epod_id, EPOD_STATE_OFF);
  107. if (ret < 0)
  108. return ret;
  109. }
  110. epod_on[epod_id] = false;
  111. }
  112. return 0;
  113. }
  114. /*
  115. * Regulator switch
  116. */
  117. static int db8500_regulator_switch_enable(struct regulator_dev *rdev)
  118. {
  119. struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
  120. int ret;
  121. if (info == NULL)
  122. return -EINVAL;
  123. dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-enable\n",
  124. info->desc.name);
  125. ret = enable_epod(info->epod_id, info->is_ramret);
  126. if (ret < 0) {
  127. dev_err(rdev_get_dev(rdev),
  128. "regulator-switch-%s-enable: prcmu call failed\n",
  129. info->desc.name);
  130. goto out;
  131. }
  132. info->is_enabled = true;
  133. out:
  134. return ret;
  135. }
  136. static int db8500_regulator_switch_disable(struct regulator_dev *rdev)
  137. {
  138. struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
  139. int ret;
  140. if (info == NULL)
  141. return -EINVAL;
  142. dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-disable\n",
  143. info->desc.name);
  144. ret = disable_epod(info->epod_id, info->is_ramret);
  145. if (ret < 0) {
  146. dev_err(rdev_get_dev(rdev),
  147. "regulator_switch-%s-disable: prcmu call failed\n",
  148. info->desc.name);
  149. goto out;
  150. }
  151. info->is_enabled = false;
  152. out:
  153. return ret;
  154. }
  155. static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev)
  156. {
  157. struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
  158. if (info == NULL)
  159. return -EINVAL;
  160. dev_vdbg(rdev_get_dev(rdev),
  161. "regulator-switch-%s-is_enabled (is_enabled): %i\n",
  162. info->desc.name, info->is_enabled);
  163. return info->is_enabled;
  164. }
  165. static const struct regulator_ops db8500_regulator_switch_ops = {
  166. .enable = db8500_regulator_switch_enable,
  167. .disable = db8500_regulator_switch_disable,
  168. .is_enabled = db8500_regulator_switch_is_enabled,
  169. };
  170. /*
  171. * Regulator information
  172. */
  173. static struct dbx500_regulator_info
  174. dbx500_regulator_info[DB8500_NUM_REGULATORS] = {
  175. [DB8500_REGULATOR_VAPE] = {
  176. .desc = {
  177. .name = "db8500-vape",
  178. .of_match = of_match_ptr("db8500_vape"),
  179. .id = DB8500_REGULATOR_VAPE,
  180. .ops = &db8500_regulator_ops,
  181. .type = REGULATOR_VOLTAGE,
  182. .owner = THIS_MODULE,
  183. },
  184. },
  185. [DB8500_REGULATOR_VARM] = {
  186. .desc = {
  187. .name = "db8500-varm",
  188. .of_match = of_match_ptr("db8500_varm"),
  189. .id = DB8500_REGULATOR_VARM,
  190. .ops = &db8500_regulator_ops,
  191. .type = REGULATOR_VOLTAGE,
  192. .owner = THIS_MODULE,
  193. },
  194. },
  195. [DB8500_REGULATOR_VMODEM] = {
  196. .desc = {
  197. .name = "db8500-vmodem",
  198. .of_match = of_match_ptr("db8500_vmodem"),
  199. .id = DB8500_REGULATOR_VMODEM,
  200. .ops = &db8500_regulator_ops,
  201. .type = REGULATOR_VOLTAGE,
  202. .owner = THIS_MODULE,
  203. },
  204. },
  205. [DB8500_REGULATOR_VPLL] = {
  206. .desc = {
  207. .name = "db8500-vpll",
  208. .of_match = of_match_ptr("db8500_vpll"),
  209. .id = DB8500_REGULATOR_VPLL,
  210. .ops = &db8500_regulator_ops,
  211. .type = REGULATOR_VOLTAGE,
  212. .owner = THIS_MODULE,
  213. },
  214. },
  215. [DB8500_REGULATOR_VSMPS1] = {
  216. .desc = {
  217. .name = "db8500-vsmps1",
  218. .of_match = of_match_ptr("db8500_vsmps1"),
  219. .id = DB8500_REGULATOR_VSMPS1,
  220. .ops = &db8500_regulator_ops,
  221. .type = REGULATOR_VOLTAGE,
  222. .owner = THIS_MODULE,
  223. },
  224. },
  225. [DB8500_REGULATOR_VSMPS2] = {
  226. .desc = {
  227. .name = "db8500-vsmps2",
  228. .of_match = of_match_ptr("db8500_vsmps2"),
  229. .id = DB8500_REGULATOR_VSMPS2,
  230. .ops = &db8500_regulator_ops,
  231. .type = REGULATOR_VOLTAGE,
  232. .owner = THIS_MODULE,
  233. .fixed_uV = 1800000,
  234. .n_voltages = 1,
  235. },
  236. .exclude_from_power_state = true,
  237. },
  238. [DB8500_REGULATOR_VSMPS3] = {
  239. .desc = {
  240. .name = "db8500-vsmps3",
  241. .of_match = of_match_ptr("db8500_vsmps3"),
  242. .id = DB8500_REGULATOR_VSMPS3,
  243. .ops = &db8500_regulator_ops,
  244. .type = REGULATOR_VOLTAGE,
  245. .owner = THIS_MODULE,
  246. },
  247. },
  248. [DB8500_REGULATOR_VRF1] = {
  249. .desc = {
  250. .name = "db8500-vrf1",
  251. .of_match = of_match_ptr("db8500_vrf1"),
  252. .id = DB8500_REGULATOR_VRF1,
  253. .ops = &db8500_regulator_ops,
  254. .type = REGULATOR_VOLTAGE,
  255. .owner = THIS_MODULE,
  256. },
  257. },
  258. [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
  259. .desc = {
  260. .name = "db8500-sva-mmdsp",
  261. .of_match = of_match_ptr("db8500_sva_mmdsp"),
  262. .id = DB8500_REGULATOR_SWITCH_SVAMMDSP,
  263. .ops = &db8500_regulator_switch_ops,
  264. .type = REGULATOR_VOLTAGE,
  265. .owner = THIS_MODULE,
  266. },
  267. .epod_id = EPOD_ID_SVAMMDSP,
  268. },
  269. [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
  270. .desc = {
  271. .name = "db8500-sva-mmdsp-ret",
  272. .of_match = of_match_ptr("db8500_sva_mmdsp_ret"),
  273. .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET,
  274. .ops = &db8500_regulator_switch_ops,
  275. .type = REGULATOR_VOLTAGE,
  276. .owner = THIS_MODULE,
  277. },
  278. .epod_id = EPOD_ID_SVAMMDSP,
  279. .is_ramret = true,
  280. },
  281. [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
  282. .desc = {
  283. .name = "db8500-sva-pipe",
  284. .of_match = of_match_ptr("db8500_sva_pipe"),
  285. .id = DB8500_REGULATOR_SWITCH_SVAPIPE,
  286. .ops = &db8500_regulator_switch_ops,
  287. .type = REGULATOR_VOLTAGE,
  288. .owner = THIS_MODULE,
  289. },
  290. .epod_id = EPOD_ID_SVAPIPE,
  291. },
  292. [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
  293. .desc = {
  294. .name = "db8500-sia-mmdsp",
  295. .of_match = of_match_ptr("db8500_sia_mmdsp"),
  296. .id = DB8500_REGULATOR_SWITCH_SIAMMDSP,
  297. .ops = &db8500_regulator_switch_ops,
  298. .type = REGULATOR_VOLTAGE,
  299. .owner = THIS_MODULE,
  300. },
  301. .epod_id = EPOD_ID_SIAMMDSP,
  302. },
  303. [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
  304. .desc = {
  305. .name = "db8500-sia-mmdsp-ret",
  306. .of_match = of_match_ptr("db8500_sia_mmdsp_ret"),
  307. .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET,
  308. .ops = &db8500_regulator_switch_ops,
  309. .type = REGULATOR_VOLTAGE,
  310. .owner = THIS_MODULE,
  311. },
  312. .epod_id = EPOD_ID_SIAMMDSP,
  313. .is_ramret = true,
  314. },
  315. [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
  316. .desc = {
  317. .name = "db8500-sia-pipe",
  318. .of_match = of_match_ptr("db8500_sia_pipe"),
  319. .id = DB8500_REGULATOR_SWITCH_SIAPIPE,
  320. .ops = &db8500_regulator_switch_ops,
  321. .type = REGULATOR_VOLTAGE,
  322. .owner = THIS_MODULE,
  323. },
  324. .epod_id = EPOD_ID_SIAPIPE,
  325. },
  326. [DB8500_REGULATOR_SWITCH_SGA] = {
  327. .desc = {
  328. .name = "db8500-sga",
  329. .of_match = of_match_ptr("db8500_sga"),
  330. .id = DB8500_REGULATOR_SWITCH_SGA,
  331. .ops = &db8500_regulator_switch_ops,
  332. .type = REGULATOR_VOLTAGE,
  333. .owner = THIS_MODULE,
  334. },
  335. .epod_id = EPOD_ID_SGA,
  336. },
  337. [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
  338. .desc = {
  339. .name = "db8500-b2r2-mcde",
  340. .of_match = of_match_ptr("db8500_b2r2_mcde"),
  341. .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE,
  342. .ops = &db8500_regulator_switch_ops,
  343. .type = REGULATOR_VOLTAGE,
  344. .owner = THIS_MODULE,
  345. },
  346. .epod_id = EPOD_ID_B2R2_MCDE,
  347. },
  348. [DB8500_REGULATOR_SWITCH_ESRAM12] = {
  349. .desc = {
  350. .name = "db8500-esram12",
  351. .of_match = of_match_ptr("db8500_esram12"),
  352. .id = DB8500_REGULATOR_SWITCH_ESRAM12,
  353. .ops = &db8500_regulator_switch_ops,
  354. .type = REGULATOR_VOLTAGE,
  355. .owner = THIS_MODULE,
  356. },
  357. .epod_id = EPOD_ID_ESRAM12,
  358. .is_enabled = true,
  359. },
  360. [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
  361. .desc = {
  362. .name = "db8500-esram12-ret",
  363. .of_match = of_match_ptr("db8500_esram12_ret"),
  364. .id = DB8500_REGULATOR_SWITCH_ESRAM12RET,
  365. .ops = &db8500_regulator_switch_ops,
  366. .type = REGULATOR_VOLTAGE,
  367. .owner = THIS_MODULE,
  368. },
  369. .epod_id = EPOD_ID_ESRAM12,
  370. .is_ramret = true,
  371. },
  372. [DB8500_REGULATOR_SWITCH_ESRAM34] = {
  373. .desc = {
  374. .name = "db8500-esram34",
  375. .of_match = of_match_ptr("db8500_esram34"),
  376. .id = DB8500_REGULATOR_SWITCH_ESRAM34,
  377. .ops = &db8500_regulator_switch_ops,
  378. .type = REGULATOR_VOLTAGE,
  379. .owner = THIS_MODULE,
  380. },
  381. .epod_id = EPOD_ID_ESRAM34,
  382. .is_enabled = true,
  383. },
  384. [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
  385. .desc = {
  386. .name = "db8500-esram34-ret",
  387. .of_match = of_match_ptr("db8500_esram34_ret"),
  388. .id = DB8500_REGULATOR_SWITCH_ESRAM34RET,
  389. .ops = &db8500_regulator_switch_ops,
  390. .type = REGULATOR_VOLTAGE,
  391. .owner = THIS_MODULE,
  392. },
  393. .epod_id = EPOD_ID_ESRAM34,
  394. .is_ramret = true,
  395. },
  396. };
  397. static int db8500_regulator_probe(struct platform_device *pdev)
  398. {
  399. struct regulator_init_data *db8500_init_data;
  400. struct dbx500_regulator_info *info;
  401. struct regulator_config config = { };
  402. struct regulator_dev *rdev;
  403. int err, i;
  404. db8500_init_data = dev_get_platdata(&pdev->dev);
  405. for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
  406. /* assign per-regulator data */
  407. info = &dbx500_regulator_info[i];
  408. config.driver_data = info;
  409. config.dev = &pdev->dev;
  410. if (db8500_init_data)
  411. config.init_data = &db8500_init_data[i];
  412. rdev = devm_regulator_register(&pdev->dev, &info->desc,
  413. &config);
  414. if (IS_ERR(rdev)) {
  415. err = PTR_ERR(rdev);
  416. dev_err(&pdev->dev, "failed to register %s: err %i\n",
  417. info->desc.name, err);
  418. return err;
  419. }
  420. dev_dbg(&pdev->dev, "regulator-%s-probed\n", info->desc.name);
  421. }
  422. ux500_regulator_debug_init(pdev, dbx500_regulator_info,
  423. ARRAY_SIZE(dbx500_regulator_info));
  424. return 0;
  425. }
  426. static int db8500_regulator_remove(struct platform_device *pdev)
  427. {
  428. ux500_regulator_debug_exit();
  429. return 0;
  430. }
  431. static struct platform_driver db8500_regulator_driver = {
  432. .driver = {
  433. .name = "db8500-prcmu-regulators",
  434. },
  435. .probe = db8500_regulator_probe,
  436. .remove = db8500_regulator_remove,
  437. };
  438. static int __init db8500_regulator_init(void)
  439. {
  440. return platform_driver_register(&db8500_regulator_driver);
  441. }
  442. static void __exit db8500_regulator_exit(void)
  443. {
  444. platform_driver_unregister(&db8500_regulator_driver);
  445. }
  446. arch_initcall(db8500_regulator_init);
  447. module_exit(db8500_regulator_exit);
  448. MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
  449. MODULE_DESCRIPTION("DB8500 regulator driver");
  450. MODULE_LICENSE("GPL v2");