88pm8607.c 13 KB

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