axp20x-i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * I2C 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 I2C variants.
  10. *
  11. * Copyright (C) 2014 Carlo Caione
  12. *
  13. * Author: Carlo Caione <[email protected]>
  14. */
  15. #include <linux/acpi.h>
  16. #include <linux/err.h>
  17. #include <linux/i2c.h>
  18. #include <linux/module.h>
  19. #include <linux/mfd/axp20x.h>
  20. #include <linux/of.h>
  21. #include <linux/regmap.h>
  22. #include <linux/slab.h>
  23. static int axp20x_i2c_probe(struct i2c_client *i2c,
  24. const struct i2c_device_id *id)
  25. {
  26. struct axp20x_dev *axp20x;
  27. int ret;
  28. axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
  29. if (!axp20x)
  30. return -ENOMEM;
  31. axp20x->dev = &i2c->dev;
  32. axp20x->irq = i2c->irq;
  33. dev_set_drvdata(axp20x->dev, axp20x);
  34. ret = axp20x_match_device(axp20x);
  35. if (ret)
  36. return ret;
  37. axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
  38. if (IS_ERR(axp20x->regmap)) {
  39. ret = PTR_ERR(axp20x->regmap);
  40. dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
  41. return ret;
  42. }
  43. return axp20x_device_probe(axp20x);
  44. }
  45. static void axp20x_i2c_remove(struct i2c_client *i2c)
  46. {
  47. struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);
  48. axp20x_device_remove(axp20x);
  49. }
  50. #ifdef CONFIG_OF
  51. static const struct of_device_id axp20x_i2c_of_match[] = {
  52. { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID },
  53. { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID },
  54. { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
  55. { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
  56. { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
  57. { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
  58. { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
  59. { },
  60. };
  61. MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match);
  62. #endif
  63. static const struct i2c_device_id axp20x_i2c_id[] = {
  64. { "axp152", 0 },
  65. { "axp202", 0 },
  66. { "axp209", 0 },
  67. { "axp221", 0 },
  68. { "axp223", 0 },
  69. { "axp803", 0 },
  70. { "axp806", 0 },
  71. { },
  72. };
  73. MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
  74. #ifdef CONFIG_ACPI
  75. static const struct acpi_device_id axp20x_i2c_acpi_match[] = {
  76. {
  77. .id = "INT33F4",
  78. .driver_data = AXP288_ID,
  79. },
  80. { },
  81. };
  82. MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match);
  83. #endif
  84. static struct i2c_driver axp20x_i2c_driver = {
  85. .driver = {
  86. .name = "axp20x-i2c",
  87. .of_match_table = of_match_ptr(axp20x_i2c_of_match),
  88. .acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match),
  89. },
  90. .probe = axp20x_i2c_probe,
  91. .remove = axp20x_i2c_remove,
  92. .id_table = axp20x_i2c_id,
  93. };
  94. module_i2c_driver(axp20x_i2c_driver);
  95. MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X");
  96. MODULE_AUTHOR("Carlo Caione <[email protected]>");
  97. MODULE_LICENSE("GPL");