act8945a.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. .of_compatible = "active-semi,act8945a-charger",
  25. },
  26. };
  27. static const struct regmap_config act8945a_regmap_config = {
  28. .reg_bits = 8,
  29. .val_bits = 8,
  30. };
  31. static int act8945a_i2c_probe(struct i2c_client *i2c,
  32. const struct i2c_device_id *id)
  33. {
  34. int ret;
  35. struct regmap *regmap;
  36. regmap = devm_regmap_init_i2c(i2c, &act8945a_regmap_config);
  37. if (IS_ERR(regmap)) {
  38. ret = PTR_ERR(regmap);
  39. dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
  40. return ret;
  41. }
  42. i2c_set_clientdata(i2c, regmap);
  43. ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE,
  44. act8945a_devs, ARRAY_SIZE(act8945a_devs),
  45. NULL, 0, NULL);
  46. if (ret) {
  47. dev_err(&i2c->dev, "Failed to add sub devices\n");
  48. return ret;
  49. }
  50. return 0;
  51. }
  52. static const struct i2c_device_id act8945a_i2c_id[] = {
  53. { "act8945a", 0 },
  54. {}
  55. };
  56. MODULE_DEVICE_TABLE(i2c, act8945a_i2c_id);
  57. static const struct of_device_id act8945a_of_match[] = {
  58. { .compatible = "active-semi,act8945a", },
  59. {},
  60. };
  61. MODULE_DEVICE_TABLE(of, act8945a_of_match);
  62. static struct i2c_driver act8945a_i2c_driver = {
  63. .driver = {
  64. .name = "act8945a",
  65. .of_match_table = of_match_ptr(act8945a_of_match),
  66. },
  67. .probe = act8945a_i2c_probe,
  68. .id_table = act8945a_i2c_id,
  69. };
  70. static int __init act8945a_i2c_init(void)
  71. {
  72. return i2c_add_driver(&act8945a_i2c_driver);
  73. }
  74. subsys_initcall(act8945a_i2c_init);
  75. static void __exit act8945a_i2c_exit(void)
  76. {
  77. i2c_del_driver(&act8945a_i2c_driver);
  78. }
  79. module_exit(act8945a_i2c_exit);
  80. MODULE_DESCRIPTION("ACT8945A PMIC multi-function driver");
  81. MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>");
  82. MODULE_LICENSE("GPL");