db8500-prcmu.c 14 KB

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