da9055-i2c.c 2.6 KB

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