axp20x-rsb.c 2.2 KB

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