hi6421-pmic-core.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Device driver for Hi6421 IC
  3. *
  4. * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.
  5. * http://www.hisilicon.com
  6. * Copyright (c) <2013-2014> Linaro Ltd.
  7. * http://www.linaro.org
  8. *
  9. * Author: Guodong Xu <guodong.xu@linaro.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  19. * more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #include <linux/device.h>
  25. #include <linux/err.h>
  26. #include <linux/mfd/core.h>
  27. #include <linux/module.h>
  28. #include <linux/of.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/regmap.h>
  31. #include <linux/mfd/hi6421-pmic.h>
  32. static const struct mfd_cell hi6421_devs[] = {
  33. { .name = "hi6421-regulator", },
  34. };
  35. static const struct regmap_config hi6421_regmap_config = {
  36. .reg_bits = 32,
  37. .reg_stride = 4,
  38. .val_bits = 8,
  39. .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX),
  40. };
  41. static int hi6421_pmic_probe(struct platform_device *pdev)
  42. {
  43. struct hi6421_pmic *pmic;
  44. struct resource *res;
  45. void __iomem *base;
  46. int ret;
  47. pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
  48. if (!pmic)
  49. return -ENOMEM;
  50. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  51. base = devm_ioremap_resource(&pdev->dev, res);
  52. if (IS_ERR(base))
  53. return PTR_ERR(base);
  54. pmic->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base,
  55. &hi6421_regmap_config);
  56. if (IS_ERR(pmic->regmap)) {
  57. dev_err(&pdev->dev,
  58. "regmap init failed: %ld\n", PTR_ERR(pmic->regmap));
  59. return PTR_ERR(pmic->regmap);
  60. }
  61. /* set over-current protection debounce 8ms */
  62. regmap_update_bits(pmic->regmap, HI6421_OCP_DEB_CTRL_REG,
  63. (HI6421_OCP_DEB_SEL_MASK
  64. | HI6421_OCP_EN_DEBOUNCE_MASK
  65. | HI6421_OCP_AUTO_STOP_MASK),
  66. (HI6421_OCP_DEB_SEL_8MS
  67. | HI6421_OCP_EN_DEBOUNCE_ENABLE));
  68. platform_set_drvdata(pdev, pmic);
  69. ret = mfd_add_devices(&pdev->dev, 0, hi6421_devs,
  70. ARRAY_SIZE(hi6421_devs), NULL, 0, NULL);
  71. if (ret) {
  72. dev_err(&pdev->dev, "add mfd devices failed: %d\n", ret);
  73. return ret;
  74. }
  75. return 0;
  76. }
  77. static int hi6421_pmic_remove(struct platform_device *pdev)
  78. {
  79. mfd_remove_devices(&pdev->dev);
  80. return 0;
  81. }
  82. static const struct of_device_id of_hi6421_pmic_match_tbl[] = {
  83. { .compatible = "hisilicon,hi6421-pmic", },
  84. { },
  85. };
  86. MODULE_DEVICE_TABLE(of, of_hi6421_pmic_match_tbl);
  87. static struct platform_driver hi6421_pmic_driver = {
  88. .driver = {
  89. .name = "hi6421_pmic",
  90. .of_match_table = of_hi6421_pmic_match_tbl,
  91. },
  92. .probe = hi6421_pmic_probe,
  93. .remove = hi6421_pmic_remove,
  94. };
  95. module_platform_driver(hi6421_pmic_driver);
  96. MODULE_AUTHOR("Guodong Xu <guodong.xu@linaro.org>");
  97. MODULE_DESCRIPTION("Hi6421 PMIC driver");
  98. MODULE_LICENSE("GPL v2");