db8500-prcmu.c 11 KB

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