act8945a.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * MFD driver for Active-semi ACT8945a PMIC
  3. *
  4. * Copyright (C) 2015 Atmel Corporation.
  5. *
  6. * Author: Wenyou Yang <wenyou.yang@atmel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/i2c.h>
  14. #include <linux/mfd/core.h>
  15. #include <linux/module.h>
  16. #include <linux/of_device.h>
  17. #include <linux/regmap.h>
  18. static const struct mfd_cell act8945a_devs[] = {
  19. {
  20. .name = "act8945a-regulator",
  21. },
  22. {
  23. .name = "act8945a-charger",
  24. },
  25. };
  26. static const struct regmap_config act8945a_regmap_config = {
  27. .reg_bits = 8,
  28. .val_bits = 8,
  29. };
  30. static int act8945a_i2c_probe(struct i2c_client *i2c,
  31. const struct i2c_device_id *id)
  32. {
  33. int ret;
  34. struct regmap *regmap;
  35. regmap = devm_regmap_init_i2c(i2c, &act8945a_regmap_config);
  36. if (IS_ERR(regmap)) {
  37. ret = PTR_ERR(regmap);
  38. dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
  39. return ret;
  40. }
  41. i2c_set_clientdata(i2c, regmap);
  42. ret = mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE, act8945a_devs,
  43. ARRAY_SIZE(act8945a_devs), NULL, 0, NULL);
  44. if (ret) {
  45. dev_err(&i2c->dev, "Failed to add sub devices\n");
  46. return ret;
  47. }
  48. return 0;
  49. }
  50. static int act8945a_i2c_remove(struct i2c_client *i2c)
  51. {
  52. mfd_remove_devices(&i2c->dev);
  53. return 0;
  54. }
  55. static const struct i2c_device_id act8945a_i2c_id[] = {
  56. { "act8945a", 0 },
  57. {}
  58. };
  59. MODULE_DEVICE_TABLE(i2c, act8945a_i2c_id);
  60. static const struct of_device_id act8945a_of_match[] = {
  61. { .compatible = "active-semi,act8945a", },
  62. {},
  63. };
  64. MODULE_DEVICE_TABLE(of, act8945a_of_match);
  65. static struct i2c_driver act8945a_i2c_driver = {
  66. .driver = {
  67. .name = "act8945a",
  68. .of_match_table = of_match_ptr(act8945a_of_match),
  69. },
  70. .probe = act8945a_i2c_probe,
  71. .remove = act8945a_i2c_remove,
  72. .id_table = act8945a_i2c_id,
  73. };
  74. static int __init act8945a_i2c_init(void)
  75. {
  76. return i2c_add_driver(&act8945a_i2c_driver);
  77. }
  78. subsys_initcall(act8945a_i2c_init);
  79. static void __exit act8945a_i2c_exit(void)
  80. {
  81. i2c_del_driver(&act8945a_i2c_driver);
  82. }
  83. module_exit(act8945a_i2c_exit);
  84. MODULE_DESCRIPTION("ACT8945A PMIC multi-function driver");
  85. MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>");
  86. MODULE_LICENSE("GPL");