act8945a.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * MFD driver for Active-semi ACT8945a PMIC
  4. *
  5. * Copyright (C) 2015 Atmel Corporation.
  6. *
  7. * Author: Wenyou Yang <[email protected]>
  8. */
  9. #include <linux/i2c.h>
  10. #include <linux/mfd/core.h>
  11. #include <linux/module.h>
  12. #include <linux/of_device.h>
  13. #include <linux/regmap.h>
  14. static const struct mfd_cell act8945a_devs[] = {
  15. {
  16. .name = "act8945a-regulator",
  17. },
  18. {
  19. .name = "act8945a-charger",
  20. .of_compatible = "active-semi,act8945a-charger",
  21. },
  22. };
  23. static const struct regmap_config act8945a_regmap_config = {
  24. .reg_bits = 8,
  25. .val_bits = 8,
  26. };
  27. static int act8945a_i2c_probe(struct i2c_client *i2c,
  28. const struct i2c_device_id *id)
  29. {
  30. int ret;
  31. struct regmap *regmap;
  32. regmap = devm_regmap_init_i2c(i2c, &act8945a_regmap_config);
  33. if (IS_ERR(regmap)) {
  34. ret = PTR_ERR(regmap);
  35. dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
  36. return ret;
  37. }
  38. i2c_set_clientdata(i2c, regmap);
  39. ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE,
  40. act8945a_devs, ARRAY_SIZE(act8945a_devs),
  41. NULL, 0, NULL);
  42. if (ret) {
  43. dev_err(&i2c->dev, "Failed to add sub devices\n");
  44. return ret;
  45. }
  46. return 0;
  47. }
  48. static const struct i2c_device_id act8945a_i2c_id[] = {
  49. { "act8945a", 0 },
  50. {}
  51. };
  52. MODULE_DEVICE_TABLE(i2c, act8945a_i2c_id);
  53. static const struct of_device_id act8945a_of_match[] = {
  54. { .compatible = "active-semi,act8945a", },
  55. {},
  56. };
  57. MODULE_DEVICE_TABLE(of, act8945a_of_match);
  58. static struct i2c_driver act8945a_i2c_driver = {
  59. .driver = {
  60. .name = "act8945a",
  61. .of_match_table = of_match_ptr(act8945a_of_match),
  62. },
  63. .probe = act8945a_i2c_probe,
  64. .id_table = act8945a_i2c_id,
  65. };
  66. static int __init act8945a_i2c_init(void)
  67. {
  68. return i2c_add_driver(&act8945a_i2c_driver);
  69. }
  70. subsys_initcall(act8945a_i2c_init);
  71. static void __exit act8945a_i2c_exit(void)
  72. {
  73. i2c_del_driver(&act8945a_i2c_driver);
  74. }
  75. module_exit(act8945a_i2c_exit);
  76. MODULE_DESCRIPTION("ACT8945A PMIC multi-function driver");
  77. MODULE_AUTHOR("Wenyou Yang <[email protected]>");
  78. MODULE_LICENSE("GPL");