axp20x-rsb.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * RSB driver for the X-Powers' Power Management ICs
  4. *
  5. * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
  6. * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
  7. * as well as configurable GPIOs.
  8. *
  9. * This driver supports the RSB variants.
  10. *
  11. * Copyright (C) 2015 Chen-Yu Tsai
  12. *
  13. * Author: Chen-Yu Tsai <[email protected]>
  14. */
  15. #include <linux/acpi.h>
  16. #include <linux/err.h>
  17. #include <linux/mfd/axp20x.h>
  18. #include <linux/module.h>
  19. #include <linux/of.h>
  20. #include <linux/regmap.h>
  21. #include <linux/slab.h>
  22. #include <linux/sunxi-rsb.h>
  23. static int axp20x_rsb_probe(struct sunxi_rsb_device *rdev)
  24. {
  25. struct axp20x_dev *axp20x;
  26. int ret;
  27. axp20x = devm_kzalloc(&rdev->dev, sizeof(*axp20x), GFP_KERNEL);
  28. if (!axp20x)
  29. return -ENOMEM;
  30. axp20x->dev = &rdev->dev;
  31. axp20x->irq = rdev->irq;
  32. dev_set_drvdata(&rdev->dev, axp20x);
  33. ret = axp20x_match_device(axp20x);
  34. if (ret)
  35. return ret;
  36. axp20x->regmap = devm_regmap_init_sunxi_rsb(rdev, axp20x->regmap_cfg);
  37. if (IS_ERR(axp20x->regmap)) {
  38. ret = PTR_ERR(axp20x->regmap);
  39. dev_err(&rdev->dev, "regmap init failed: %d\n", ret);
  40. return ret;
  41. }
  42. return axp20x_device_probe(axp20x);
  43. }
  44. static void axp20x_rsb_remove(struct sunxi_rsb_device *rdev)
  45. {
  46. struct axp20x_dev *axp20x = sunxi_rsb_device_get_drvdata(rdev);
  47. axp20x_device_remove(axp20x);
  48. }
  49. static const struct of_device_id axp20x_rsb_of_match[] = {
  50. { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
  51. { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
  52. { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
  53. { .compatible = "x-powers,axp809", .data = (void *)AXP809_ID },
  54. { .compatible = "x-powers,axp813", .data = (void *)AXP813_ID },
  55. { },
  56. };
  57. MODULE_DEVICE_TABLE(of, axp20x_rsb_of_match);
  58. static struct sunxi_rsb_driver axp20x_rsb_driver = {
  59. .driver = {
  60. .name = "axp20x-rsb",
  61. .of_match_table = of_match_ptr(axp20x_rsb_of_match),
  62. },
  63. .probe = axp20x_rsb_probe,
  64. .remove = axp20x_rsb_remove,
  65. };
  66. module_sunxi_rsb_driver(axp20x_rsb_driver);
  67. MODULE_DESCRIPTION("PMIC MFD sunXi RSB driver for AXP20X");
  68. MODULE_AUTHOR("Chen-Yu Tsai <[email protected]>");
  69. MODULE_LICENSE("GPL v2");