db8500-prcmu.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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/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 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 = 0;
  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 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. .id = DB8500_REGULATOR_VAPE,
  179. .ops = &db8500_regulator_ops,
  180. .type = REGULATOR_VOLTAGE,
  181. .owner = THIS_MODULE,
  182. },
  183. },
  184. [DB8500_REGULATOR_VARM] = {
  185. .desc = {
  186. .name = "db8500-varm",
  187. .id = DB8500_REGULATOR_VARM,
  188. .ops = &db8500_regulator_ops,
  189. .type = REGULATOR_VOLTAGE,
  190. .owner = THIS_MODULE,
  191. },
  192. },
  193. [DB8500_REGULATOR_VMODEM] = {
  194. .desc = {
  195. .name = "db8500-vmodem",
  196. .id = DB8500_REGULATOR_VMODEM,
  197. .ops = &db8500_regulator_ops,
  198. .type = REGULATOR_VOLTAGE,
  199. .owner = THIS_MODULE,
  200. },
  201. },
  202. [DB8500_REGULATOR_VPLL] = {
  203. .desc = {
  204. .name = "db8500-vpll",
  205. .id = DB8500_REGULATOR_VPLL,
  206. .ops = &db8500_regulator_ops,
  207. .type = REGULATOR_VOLTAGE,
  208. .owner = THIS_MODULE,
  209. },
  210. },
  211. [DB8500_REGULATOR_VSMPS1] = {
  212. .desc = {
  213. .name = "db8500-vsmps1",
  214. .id = DB8500_REGULATOR_VSMPS1,
  215. .ops = &db8500_regulator_ops,
  216. .type = REGULATOR_VOLTAGE,
  217. .owner = THIS_MODULE,
  218. },
  219. },
  220. [DB8500_REGULATOR_VSMPS2] = {
  221. .desc = {
  222. .name = "db8500-vsmps2",
  223. .id = DB8500_REGULATOR_VSMPS2,
  224. .ops = &db8500_regulator_ops,
  225. .type = REGULATOR_VOLTAGE,
  226. .owner = THIS_MODULE,
  227. },
  228. .exclude_from_power_state = true,
  229. },
  230. [DB8500_REGULATOR_VSMPS3] = {
  231. .desc = {
  232. .name = "db8500-vsmps3",
  233. .id = DB8500_REGULATOR_VSMPS3,
  234. .ops = &db8500_regulator_ops,
  235. .type = REGULATOR_VOLTAGE,
  236. .owner = THIS_MODULE,
  237. },
  238. },
  239. [DB8500_REGULATOR_VRF1] = {
  240. .desc = {
  241. .name = "db8500-vrf1",
  242. .id = DB8500_REGULATOR_VRF1,
  243. .ops = &db8500_regulator_ops,
  244. .type = REGULATOR_VOLTAGE,
  245. .owner = THIS_MODULE,
  246. },
  247. },
  248. [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
  249. .desc = {
  250. .name = "db8500-sva-mmdsp",
  251. .id = DB8500_REGULATOR_SWITCH_SVAMMDSP,
  252. .ops = &db8500_regulator_switch_ops,
  253. .type = REGULATOR_VOLTAGE,
  254. .owner = THIS_MODULE,
  255. },
  256. .epod_id = EPOD_ID_SVAMMDSP,
  257. },
  258. [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
  259. .desc = {
  260. .name = "db8500-sva-mmdsp-ret",
  261. .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET,
  262. .ops = &db8500_regulator_switch_ops,
  263. .type = REGULATOR_VOLTAGE,
  264. .owner = THIS_MODULE,
  265. },
  266. .epod_id = EPOD_ID_SVAMMDSP,
  267. .is_ramret = true,
  268. },
  269. [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
  270. .desc = {
  271. .name = "db8500-sva-pipe",
  272. .id = DB8500_REGULATOR_SWITCH_SVAPIPE,
  273. .ops = &db8500_regulator_switch_ops,
  274. .type = REGULATOR_VOLTAGE,
  275. .owner = THIS_MODULE,
  276. },
  277. .epod_id = EPOD_ID_SVAPIPE,
  278. },
  279. [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
  280. .desc = {
  281. .name = "db8500-sia-mmdsp",
  282. .id = DB8500_REGULATOR_SWITCH_SIAMMDSP,
  283. .ops = &db8500_regulator_switch_ops,
  284. .type = REGULATOR_VOLTAGE,
  285. .owner = THIS_MODULE,
  286. },
  287. .epod_id = EPOD_ID_SIAMMDSP,
  288. },
  289. [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
  290. .desc = {
  291. .name = "db8500-sia-mmdsp-ret",
  292. .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET,
  293. .ops = &db8500_regulator_switch_ops,
  294. .type = REGULATOR_VOLTAGE,
  295. .owner = THIS_MODULE,
  296. },
  297. .epod_id = EPOD_ID_SIAMMDSP,
  298. .is_ramret = true,
  299. },
  300. [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
  301. .desc = {
  302. .name = "db8500-sia-pipe",
  303. .id = DB8500_REGULATOR_SWITCH_SIAPIPE,
  304. .ops = &db8500_regulator_switch_ops,
  305. .type = REGULATOR_VOLTAGE,
  306. .owner = THIS_MODULE,
  307. },
  308. .epod_id = EPOD_ID_SIAPIPE,
  309. },
  310. [DB8500_REGULATOR_SWITCH_SGA] = {
  311. .desc = {
  312. .name = "db8500-sga",
  313. .id = DB8500_REGULATOR_SWITCH_SGA,
  314. .ops = &db8500_regulator_switch_ops,
  315. .type = REGULATOR_VOLTAGE,
  316. .owner = THIS_MODULE,
  317. },
  318. .epod_id = EPOD_ID_SGA,
  319. },
  320. [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
  321. .desc = {
  322. .name = "db8500-b2r2-mcde",
  323. .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE,
  324. .ops = &db8500_regulator_switch_ops,
  325. .type = REGULATOR_VOLTAGE,
  326. .owner = THIS_MODULE,
  327. },
  328. .epod_id = EPOD_ID_B2R2_MCDE,
  329. },
  330. [DB8500_REGULATOR_SWITCH_ESRAM12] = {
  331. .desc = {
  332. .name = "db8500-esram12",
  333. .id = DB8500_REGULATOR_SWITCH_ESRAM12,
  334. .ops = &db8500_regulator_switch_ops,
  335. .type = REGULATOR_VOLTAGE,
  336. .owner = THIS_MODULE,
  337. },
  338. .epod_id = EPOD_ID_ESRAM12,
  339. .is_enabled = true,
  340. },
  341. [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
  342. .desc = {
  343. .name = "db8500-esram12-ret",
  344. .id = DB8500_REGULATOR_SWITCH_ESRAM12RET,
  345. .ops = &db8500_regulator_switch_ops,
  346. .type = REGULATOR_VOLTAGE,
  347. .owner = THIS_MODULE,
  348. },
  349. .epod_id = EPOD_ID_ESRAM12,
  350. .is_ramret = true,
  351. },
  352. [DB8500_REGULATOR_SWITCH_ESRAM34] = {
  353. .desc = {
  354. .name = "db8500-esram34",
  355. .id = DB8500_REGULATOR_SWITCH_ESRAM34,
  356. .ops = &db8500_regulator_switch_ops,
  357. .type = REGULATOR_VOLTAGE,
  358. .owner = THIS_MODULE,
  359. },
  360. .epod_id = EPOD_ID_ESRAM34,
  361. .is_enabled = true,
  362. },
  363. [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
  364. .desc = {
  365. .name = "db8500-esram34-ret",
  366. .id = DB8500_REGULATOR_SWITCH_ESRAM34RET,
  367. .ops = &db8500_regulator_switch_ops,
  368. .type = REGULATOR_VOLTAGE,
  369. .owner = THIS_MODULE,
  370. },
  371. .epod_id = EPOD_ID_ESRAM34,
  372. .is_ramret = true,
  373. },
  374. };
  375. static int db8500_regulator_register(struct platform_device *pdev,
  376. struct regulator_init_data *init_data,
  377. int id,
  378. struct device_node *np)
  379. {
  380. struct dbx500_regulator_info *info;
  381. struct regulator_config config = { };
  382. int err;
  383. /* assign per-regulator data */
  384. info = &dbx500_regulator_info[id];
  385. info->dev = &pdev->dev;
  386. config.dev = &pdev->dev;
  387. config.init_data = init_data;
  388. config.driver_data = info;
  389. config.of_node = np;
  390. /* register with the regulator framework */
  391. info->rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
  392. if (IS_ERR(info->rdev)) {
  393. err = PTR_ERR(info->rdev);
  394. dev_err(&pdev->dev, "failed to register %s: err %i\n",
  395. info->desc.name, err);
  396. return err;
  397. }
  398. dev_dbg(rdev_get_dev(info->rdev),
  399. "regulator-%s-probed\n", info->desc.name);
  400. return 0;
  401. }
  402. static struct of_regulator_match db8500_regulator_matches[] = {
  403. { .name = "db8500_vape", .driver_data = (void *) DB8500_REGULATOR_VAPE, },
  404. { .name = "db8500_varm", .driver_data = (void *) DB8500_REGULATOR_VARM, },
  405. { .name = "db8500_vmodem", .driver_data = (void *) DB8500_REGULATOR_VMODEM, },
  406. { .name = "db8500_vpll", .driver_data = (void *) DB8500_REGULATOR_VPLL, },
  407. { .name = "db8500_vsmps1", .driver_data = (void *) DB8500_REGULATOR_VSMPS1, },
  408. { .name = "db8500_vsmps2", .driver_data = (void *) DB8500_REGULATOR_VSMPS2, },
  409. { .name = "db8500_vsmps3", .driver_data = (void *) DB8500_REGULATOR_VSMPS3, },
  410. { .name = "db8500_vrf1", .driver_data = (void *) DB8500_REGULATOR_VRF1, },
  411. { .name = "db8500_sva_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSP, },
  412. { .name = "db8500_sva_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSPRET, },
  413. { .name = "db8500_sva_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAPIPE, },
  414. { .name = "db8500_sia_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSP, },
  415. { .name = "db8500_sia_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSPRET, },
  416. { .name = "db8500_sia_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAPIPE, },
  417. { .name = "db8500_sga", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SGA, },
  418. { .name = "db8500_b2r2_mcde", .driver_data = (void *) DB8500_REGULATOR_SWITCH_B2R2_MCDE, },
  419. { .name = "db8500_esram12", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12, },
  420. { .name = "db8500_esram12_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12RET, },
  421. { .name = "db8500_esram34", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34, },
  422. { .name = "db8500_esram34_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34RET, },
  423. };
  424. static int
  425. db8500_regulator_of_probe(struct platform_device *pdev,
  426. struct device_node *np)
  427. {
  428. int i, err;
  429. for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
  430. err = db8500_regulator_register(
  431. pdev, db8500_regulator_matches[i].init_data,
  432. i, db8500_regulator_matches[i].of_node);
  433. if (err)
  434. return err;
  435. }
  436. return 0;
  437. }
  438. static int db8500_regulator_probe(struct platform_device *pdev)
  439. {
  440. struct regulator_init_data *db8500_init_data =
  441. dev_get_platdata(&pdev->dev);
  442. struct device_node *np = pdev->dev.of_node;
  443. int i, err;
  444. /* register all regulators */
  445. if (np) {
  446. err = of_regulator_match(&pdev->dev, np,
  447. db8500_regulator_matches,
  448. ARRAY_SIZE(db8500_regulator_matches));
  449. if (err < 0) {
  450. dev_err(&pdev->dev,
  451. "Error parsing regulator init data: %d\n", err);
  452. return err;
  453. }
  454. err = db8500_regulator_of_probe(pdev, np);
  455. if (err)
  456. return err;
  457. } else {
  458. for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
  459. err = db8500_regulator_register(pdev,
  460. &db8500_init_data[i],
  461. i, NULL);
  462. if (err)
  463. return err;
  464. }
  465. }
  466. err = ux500_regulator_debug_init(pdev,
  467. dbx500_regulator_info,
  468. ARRAY_SIZE(dbx500_regulator_info));
  469. return 0;
  470. }
  471. static int db8500_regulator_remove(struct platform_device *pdev)
  472. {
  473. ux500_regulator_debug_exit();
  474. return 0;
  475. }
  476. static struct platform_driver db8500_regulator_driver = {
  477. .driver = {
  478. .name = "db8500-prcmu-regulators",
  479. .owner = THIS_MODULE,
  480. },
  481. .probe = db8500_regulator_probe,
  482. .remove = db8500_regulator_remove,
  483. };
  484. static int __init db8500_regulator_init(void)
  485. {
  486. return platform_driver_register(&db8500_regulator_driver);
  487. }
  488. static void __exit db8500_regulator_exit(void)
  489. {
  490. platform_driver_unregister(&db8500_regulator_driver);
  491. }
  492. arch_initcall(db8500_regulator_init);
  493. module_exit(db8500_regulator_exit);
  494. MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
  495. MODULE_DESCRIPTION("DB8500 regulator driver");
  496. MODULE_LICENSE("GPL v2");