da9055-i2c.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* I2C access for DA9055 PMICs.
  3. *
  4. * Copyright(c) 2012 Dialog Semiconductor Ltd.
  5. *
  6. * Author: David Dajun Chen <dchen@diasemi.com>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/device.h>
  10. #include <linux/i2c.h>
  11. #include <linux/err.h>
  12. #include <linux/of.h>
  13. #include <linux/of_device.h>
  14. #include <linux/mfd/da9055/core.h>
  15. static int da9055_i2c_probe(struct i2c_client *i2c,
  16. const struct i2c_device_id *id)
  17. {
  18. struct da9055 *da9055;
  19. int ret;
  20. da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
  21. if (!da9055)
  22. return -ENOMEM;
  23. da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
  24. if (IS_ERR(da9055->regmap)) {
  25. ret = PTR_ERR(da9055->regmap);
  26. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  27. ret);
  28. return ret;
  29. }
  30. da9055->dev = &i2c->dev;
  31. da9055->chip_irq = i2c->irq;
  32. i2c_set_clientdata(i2c, da9055);
  33. return da9055_device_init(da9055);
  34. }
  35. static int da9055_i2c_remove(struct i2c_client *i2c)
  36. {
  37. struct da9055 *da9055 = i2c_get_clientdata(i2c);
  38. da9055_device_exit(da9055);
  39. return 0;
  40. }
  41. /*
  42. * DO NOT change the device Ids. The naming is intentionally specific as both
  43. * the PMIC and CODEC parts of this chip are instantiated separately as I2C
  44. * devices (both have configurable I2C addresses, and are to all intents and
  45. * purposes separate). As a result there are specific DA9055 ids for PMIC
  46. * and CODEC, which must be different to operate together.
  47. */
  48. static const struct i2c_device_id da9055_i2c_id[] = {
  49. {"da9055-pmic", 0},
  50. { }
  51. };
  52. MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
  53. static const struct of_device_id da9055_of_match[] = {
  54. { .compatible = "dlg,da9055-pmic", },
  55. { }
  56. };
  57. static struct i2c_driver da9055_i2c_driver = {
  58. .probe = da9055_i2c_probe,
  59. .remove = da9055_i2c_remove,
  60. .id_table = da9055_i2c_id,
  61. .driver = {
  62. .name = "da9055-pmic",
  63. .of_match_table = of_match_ptr(da9055_of_match),
  64. },
  65. };
  66. static int __init da9055_i2c_init(void)
  67. {
  68. int ret;
  69. ret = i2c_add_driver(&da9055_i2c_driver);
  70. if (ret != 0) {
  71. pr_err("DA9055 I2C registration failed %d\n", ret);
  72. return ret;
  73. }
  74. return 0;
  75. }
  76. subsys_initcall(da9055_i2c_init);
  77. static void __exit da9055_i2c_exit(void)
  78. {
  79. i2c_del_driver(&da9055_i2c_driver);
  80. }
  81. module_exit(da9055_i2c_exit);
  82. MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
  83. MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
  84. MODULE_LICENSE("GPL");