axp20x-i2c.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * I2C 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 I2C variants.
  9. *
  10. * Copyright (C) 2014 Carlo Caione
  11. *
  12. * Author: Carlo Caione <carlo@caione.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/i2c.h>
  21. #include <linux/module.h>
  22. #include <linux/mfd/axp20x.h>
  23. #include <linux/of.h>
  24. #include <linux/regmap.h>
  25. #include <linux/slab.h>
  26. static int axp20x_i2c_probe(struct i2c_client *i2c,
  27. const struct i2c_device_id *id)
  28. {
  29. struct axp20x_dev *axp20x;
  30. int ret;
  31. axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
  32. if (!axp20x)
  33. return -ENOMEM;
  34. axp20x->dev = &i2c->dev;
  35. axp20x->irq = i2c->irq;
  36. dev_set_drvdata(axp20x->dev, axp20x);
  37. ret = axp20x_match_device(axp20x);
  38. if (ret)
  39. return ret;
  40. axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
  41. if (IS_ERR(axp20x->regmap)) {
  42. ret = PTR_ERR(axp20x->regmap);
  43. dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
  44. return ret;
  45. }
  46. return axp20x_device_probe(axp20x);
  47. }
  48. static int axp20x_i2c_remove(struct i2c_client *i2c)
  49. {
  50. struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);
  51. return axp20x_device_remove(axp20x);
  52. }
  53. static const struct of_device_id axp20x_i2c_of_match[] = {
  54. { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID },
  55. { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID },
  56. { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
  57. { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
  58. { },
  59. };
  60. MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match);
  61. /*
  62. * This is useless for OF-enabled devices, but it is needed by I2C subsystem
  63. */
  64. static const struct i2c_device_id axp20x_i2c_id[] = {
  65. { },
  66. };
  67. MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
  68. static const struct acpi_device_id axp20x_i2c_acpi_match[] = {
  69. {
  70. .id = "INT33F4",
  71. .driver_data = AXP288_ID,
  72. },
  73. { },
  74. };
  75. MODULE_DEVICE_TABLE(acpi, axp20x_i2c_acpi_match);
  76. static struct i2c_driver axp20x_i2c_driver = {
  77. .driver = {
  78. .name = "axp20x-i2c",
  79. .of_match_table = of_match_ptr(axp20x_i2c_of_match),
  80. .acpi_match_table = ACPI_PTR(axp20x_i2c_acpi_match),
  81. },
  82. .probe = axp20x_i2c_probe,
  83. .remove = axp20x_i2c_remove,
  84. .id_table = axp20x_i2c_id,
  85. };
  86. module_i2c_driver(axp20x_i2c_driver);
  87. MODULE_DESCRIPTION("PMIC MFD I2C driver for AXP20X");
  88. MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
  89. MODULE_LICENSE("GPL");