88pm8607.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Regulators driver for Marvell 88PM8607
  4. *
  5. * Copyright (C) 2009 Marvell International Ltd.
  6. * Haojian Zhuang <haojian.zhuang@marvell.com>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/err.h>
  11. #include <linux/of.h>
  12. #include <linux/regulator/of_regulator.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regulator/driver.h>
  15. #include <linux/regulator/machine.h>
  16. #include <linux/mfd/88pm860x.h>
  17. #include <linux/module.h>
  18. struct pm8607_regulator_info {
  19. struct regulator_desc desc;
  20. unsigned int *vol_suspend;
  21. int slope_double;
  22. };
  23. static const unsigned int BUCK1_table[] = {
  24. 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000,
  25. 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000,
  26. 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
  27. 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
  28. 0, 25000, 50000, 75000, 100000, 125000, 150000, 175000,
  29. 200000, 225000, 250000, 275000, 300000, 325000, 350000, 375000,
  30. 400000, 425000, 450000, 475000, 500000, 525000, 550000, 575000,
  31. 600000, 625000, 650000, 675000, 700000, 725000, 750000, 775000,
  32. };
  33. static const unsigned int BUCK1_suspend_table[] = {
  34. 0, 25000, 50000, 75000, 100000, 125000, 150000, 175000,
  35. 200000, 225000, 250000, 275000, 300000, 325000, 350000, 375000,
  36. 400000, 425000, 450000, 475000, 500000, 525000, 550000, 575000,
  37. 600000, 625000, 650000, 675000, 700000, 725000, 750000, 775000,
  38. 800000, 825000, 850000, 875000, 900000, 925000, 950000, 975000,
  39. 1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
  40. 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000,
  41. 1400000, 1425000, 1450000, 1475000, 1500000, 1500000, 1500000, 1500000,
  42. };
  43. static const unsigned int BUCK2_table[] = {
  44. 0, 50000, 100000, 150000, 200000, 250000, 300000, 350000,
  45. 400000, 450000, 500000, 550000, 600000, 650000, 700000, 750000,
  46. 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000,
  47. 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000,
  48. 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 1950000,
  49. 2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000, 2350000,
  50. 2400000, 2450000, 2500000, 2550000, 2600000, 2650000, 2700000, 2750000,
  51. 2800000, 2850000, 2900000, 2950000, 3000000, 3000000, 3000000, 3000000,
  52. };
  53. static const unsigned int BUCK2_suspend_table[] = {
  54. 0, 50000, 100000, 150000, 200000, 250000, 300000, 350000,
  55. 400000, 450000, 500000, 550000, 600000, 650000, 700000, 750000,
  56. 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000,
  57. 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000,
  58. 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 1950000,
  59. 2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000, 2350000,
  60. 2400000, 2450000, 2500000, 2550000, 2600000, 2650000, 2700000, 2750000,
  61. 2800000, 2850000, 2900000, 2950000, 3000000, 3000000, 3000000, 3000000,
  62. };
  63. static const unsigned int BUCK3_table[] = {
  64. 0, 25000, 50000, 75000, 100000, 125000, 150000, 175000,
  65. 200000, 225000, 250000, 275000, 300000, 325000, 350000, 375000,
  66. 400000, 425000, 450000, 475000, 500000, 525000, 550000, 575000,
  67. 600000, 625000, 650000, 675000, 700000, 725000, 750000, 775000,
  68. 800000, 825000, 850000, 875000, 900000, 925000, 950000, 975000,
  69. 1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
  70. 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000,
  71. 1400000, 1425000, 1450000, 1475000, 1500000, 1500000, 1500000, 1500000,
  72. };
  73. static const unsigned int BUCK3_suspend_table[] = {
  74. 0, 25000, 50000, 75000, 100000, 125000, 150000, 175000,
  75. 200000, 225000, 250000, 275000, 300000, 325000, 350000, 375000,
  76. 400000, 425000, 450000, 475000, 500000, 525000, 550000, 575000,
  77. 600000, 625000, 650000, 675000, 700000, 725000, 750000, 775000,
  78. 800000, 825000, 850000, 875000, 900000, 925000, 950000, 975000,
  79. 1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
  80. 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000,
  81. 1400000, 1425000, 1450000, 1475000, 1500000, 1500000, 1500000, 1500000,
  82. };
  83. static const unsigned int LDO1_table[] = {
  84. 1800000, 1200000, 2800000, 0,
  85. };
  86. static const unsigned int LDO1_suspend_table[] = {
  87. 1800000, 1200000, 0, 0,
  88. };
  89. static const unsigned int LDO2_table[] = {
  90. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
  91. };
  92. static const unsigned int LDO2_suspend_table[] = {
  93. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  94. };
  95. static const unsigned int LDO3_table[] = {
  96. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
  97. };
  98. static const unsigned int LDO3_suspend_table[] = {
  99. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  100. };
  101. static const unsigned int LDO4_table[] = {
  102. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2900000, 3300000,
  103. };
  104. static const unsigned int LDO4_suspend_table[] = {
  105. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2900000, 2900000,
  106. };
  107. static const unsigned int LDO5_table[] = {
  108. 2900000, 3000000, 3100000, 3300000,
  109. };
  110. static const unsigned int LDO5_suspend_table[] = {
  111. 2900000, 0, 0, 0,
  112. };
  113. static const unsigned int LDO6_table[] = {
  114. 1800000, 1850000, 2600000, 2650000, 2700000, 2750000, 2800000, 3300000,
  115. };
  116. static const unsigned int LDO6_suspend_table[] = {
  117. 1800000, 1850000, 2600000, 2650000, 2700000, 2750000, 2800000, 2900000,
  118. };
  119. static const unsigned int LDO7_table[] = {
  120. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  121. };
  122. static const unsigned int LDO7_suspend_table[] = {
  123. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  124. };
  125. static const unsigned int LDO8_table[] = {
  126. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  127. };
  128. static const unsigned int LDO8_suspend_table[] = {
  129. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  130. };
  131. static const unsigned int LDO9_table[] = {
  132. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
  133. };
  134. static const unsigned int LDO9_suspend_table[] = {
  135. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  136. };
  137. static const unsigned int LDO10_table[] = {
  138. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
  139. 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
  140. };
  141. static const unsigned int LDO10_suspend_table[] = {
  142. 1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
  143. 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
  144. };
  145. static const unsigned int LDO12_table[] = {
  146. 1800000, 1900000, 2700000, 2800000, 2900000, 3000000, 3100000, 3300000,
  147. 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
  148. };
  149. static const unsigned int LDO12_suspend_table[] = {
  150. 1800000, 1900000, 2700000, 2800000, 2900000, 2900000, 2900000, 2900000,
  151. 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
  152. };
  153. static const unsigned int LDO13_table[] = {
  154. 1200000, 1300000, 1800000, 2000000, 2500000, 2800000, 3000000, 0,
  155. };
  156. static const unsigned int LDO13_suspend_table[] = {
  157. 0,
  158. };
  159. static const unsigned int LDO14_table[] = {
  160. 1800000, 1850000, 2700000, 2750000, 2800000, 2850000, 2900000, 3300000,
  161. };
  162. static const unsigned int LDO14_suspend_table[] = {
  163. 1800000, 1850000, 2700000, 2750000, 2800000, 2850000, 2900000, 2900000,
  164. };
  165. static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
  166. {
  167. struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
  168. int ret;
  169. ret = regulator_list_voltage_table(rdev, index);
  170. if (ret < 0)
  171. return ret;
  172. if (info->slope_double)
  173. ret <<= 1;
  174. return ret;
  175. }
  176. static const struct regulator_ops pm8607_regulator_ops = {
  177. .list_voltage = pm8607_list_voltage,
  178. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  179. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  180. .enable = regulator_enable_regmap,
  181. .disable = regulator_disable_regmap,
  182. .is_enabled = regulator_is_enabled_regmap,
  183. };
  184. static const struct regulator_ops pm8606_preg_ops = {
  185. .enable = regulator_enable_regmap,
  186. .disable = regulator_disable_regmap,
  187. .is_enabled = regulator_is_enabled_regmap,
  188. };
  189. #define PM8606_PREG(ereg, ebit) \
  190. { \
  191. .desc = { \
  192. .name = "PREG", \
  193. .of_match = of_match_ptr("PREG"), \
  194. .regulators_node = of_match_ptr("regulators"), \
  195. .ops = &pm8606_preg_ops, \
  196. .type = REGULATOR_CURRENT, \
  197. .id = PM8606_ID_PREG, \
  198. .owner = THIS_MODULE, \
  199. .enable_reg = PM8606_##ereg, \
  200. .enable_mask = (ebit), \
  201. .enable_is_inverted = true, \
  202. }, \
  203. }
  204. #define PM8607_DVC(vreg, ureg, ubit, ereg, ebit) \
  205. { \
  206. .desc = { \
  207. .name = #vreg, \
  208. .of_match = of_match_ptr(#vreg), \
  209. .regulators_node = of_match_ptr("regulators"), \
  210. .ops = &pm8607_regulator_ops, \
  211. .type = REGULATOR_VOLTAGE, \
  212. .id = PM8607_ID_##vreg, \
  213. .owner = THIS_MODULE, \
  214. .volt_table = vreg##_table, \
  215. .n_voltages = ARRAY_SIZE(vreg##_table), \
  216. .vsel_reg = PM8607_##vreg, \
  217. .vsel_mask = ARRAY_SIZE(vreg##_table) - 1, \
  218. .apply_reg = PM8607_##ureg, \
  219. .apply_bit = (ubit), \
  220. .enable_reg = PM8607_##ereg, \
  221. .enable_mask = 1 << (ebit), \
  222. }, \
  223. .slope_double = (0), \
  224. .vol_suspend = (unsigned int *)&vreg##_suspend_table, \
  225. }
  226. #define PM8607_LDO(_id, vreg, shift, ereg, ebit) \
  227. { \
  228. .desc = { \
  229. .name = "LDO" #_id, \
  230. .of_match = of_match_ptr("LDO" #_id), \
  231. .regulators_node = of_match_ptr("regulators"), \
  232. .ops = &pm8607_regulator_ops, \
  233. .type = REGULATOR_VOLTAGE, \
  234. .id = PM8607_ID_LDO##_id, \
  235. .owner = THIS_MODULE, \
  236. .volt_table = LDO##_id##_table, \
  237. .n_voltages = ARRAY_SIZE(LDO##_id##_table), \
  238. .vsel_reg = PM8607_##vreg, \
  239. .vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \
  240. .enable_reg = PM8607_##ereg, \
  241. .enable_mask = 1 << (ebit), \
  242. }, \
  243. .slope_double = (0), \
  244. .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \
  245. }
  246. static struct pm8607_regulator_info pm8607_regulator_info[] = {
  247. PM8607_DVC(BUCK1, GO, BIT(0), SUPPLIES_EN11, 0),
  248. PM8607_DVC(BUCK2, GO, BIT(1), SUPPLIES_EN11, 1),
  249. PM8607_DVC(BUCK3, GO, BIT(2), SUPPLIES_EN11, 2),
  250. PM8607_LDO(1, LDO1, 0, SUPPLIES_EN11, 3),
  251. PM8607_LDO(2, LDO2, 0, SUPPLIES_EN11, 4),
  252. PM8607_LDO(3, LDO3, 0, SUPPLIES_EN11, 5),
  253. PM8607_LDO(4, LDO4, 0, SUPPLIES_EN11, 6),
  254. PM8607_LDO(5, LDO5, 0, SUPPLIES_EN11, 7),
  255. PM8607_LDO(6, LDO6, 0, SUPPLIES_EN12, 0),
  256. PM8607_LDO(7, LDO7, 0, SUPPLIES_EN12, 1),
  257. PM8607_LDO(8, LDO8, 0, SUPPLIES_EN12, 2),
  258. PM8607_LDO(9, LDO9, 0, SUPPLIES_EN12, 3),
  259. PM8607_LDO(10, LDO10, 0, SUPPLIES_EN12, 4),
  260. PM8607_LDO(12, LDO12, 0, SUPPLIES_EN12, 5),
  261. PM8607_LDO(13, VIBRATOR_SET, 1, VIBRATOR_SET, 0),
  262. PM8607_LDO(14, LDO14, 0, SUPPLIES_EN12, 6),
  263. };
  264. static struct pm8607_regulator_info pm8606_regulator_info[] = {
  265. PM8606_PREG(PREREGULATORB, 5),
  266. };
  267. static int pm8607_regulator_probe(struct platform_device *pdev)
  268. {
  269. struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
  270. struct pm8607_regulator_info *info = NULL;
  271. struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
  272. struct regulator_config config = { };
  273. struct regulator_dev *rdev;
  274. struct resource *res;
  275. int i;
  276. res = platform_get_resource(pdev, IORESOURCE_REG, 0);
  277. if (res) {
  278. /* There're resources in 88PM8607 regulator driver */
  279. for (i = 0; i < ARRAY_SIZE(pm8607_regulator_info); i++) {
  280. info = &pm8607_regulator_info[i];
  281. if (info->desc.vsel_reg == res->start)
  282. break;
  283. }
  284. if (i == ARRAY_SIZE(pm8607_regulator_info)) {
  285. dev_err(&pdev->dev, "Failed to find regulator %llu\n",
  286. (unsigned long long)res->start);
  287. return -EINVAL;
  288. }
  289. } else {
  290. /* There's no resource in 88PM8606 PREG regulator driver */
  291. info = &pm8606_regulator_info[0];
  292. /* i is used to check regulator ID */
  293. i = -1;
  294. }
  295. /* check DVC ramp slope double */
  296. if ((i == PM8607_ID_BUCK3) && chip->buck3_double)
  297. info->slope_double = 1;
  298. config.dev = chip->dev;
  299. config.driver_data = info;
  300. if (pdata)
  301. config.init_data = pdata;
  302. if (chip->id == CHIP_PM8607)
  303. config.regmap = chip->regmap;
  304. else
  305. config.regmap = chip->regmap_companion;
  306. rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
  307. if (IS_ERR(rdev)) {
  308. dev_err(&pdev->dev, "failed to register regulator %s\n",
  309. info->desc.name);
  310. return PTR_ERR(rdev);
  311. }
  312. platform_set_drvdata(pdev, info);
  313. return 0;
  314. }
  315. static const struct platform_device_id pm8607_regulator_driver_ids[] = {
  316. {
  317. .name = "88pm860x-regulator",
  318. .driver_data = 0,
  319. }, {
  320. .name = "88pm860x-preg",
  321. .driver_data = 0,
  322. },
  323. { },
  324. };
  325. MODULE_DEVICE_TABLE(platform, pm8607_regulator_driver_ids);
  326. static struct platform_driver pm8607_regulator_driver = {
  327. .driver = {
  328. .name = "88pm860x-regulator",
  329. },
  330. .probe = pm8607_regulator_probe,
  331. .id_table = pm8607_regulator_driver_ids,
  332. };
  333. static int __init pm8607_regulator_init(void)
  334. {
  335. return platform_driver_register(&pm8607_regulator_driver);
  336. }
  337. subsys_initcall(pm8607_regulator_init);
  338. static void __exit pm8607_regulator_exit(void)
  339. {
  340. platform_driver_unregister(&pm8607_regulator_driver);
  341. }
  342. module_exit(pm8607_regulator_exit);
  343. MODULE_LICENSE("GPL");
  344. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  345. MODULE_DESCRIPTION("Regulator Driver for Marvell 88PM8607 PMIC");
  346. MODULE_ALIAS("platform:88pm8607-regulator");