da9055-i2c.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/mfd/da9055/core.h>
  18. static int da9055_i2c_probe(struct i2c_client *i2c,
  19. const struct i2c_device_id *id)
  20. {
  21. struct da9055 *da9055;
  22. int ret;
  23. da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
  24. if (!da9055)
  25. return -ENOMEM;
  26. da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
  27. if (IS_ERR(da9055->regmap)) {
  28. ret = PTR_ERR(da9055->regmap);
  29. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  30. ret);
  31. return ret;
  32. }
  33. da9055->dev = &i2c->dev;
  34. da9055->chip_irq = i2c->irq;
  35. i2c_set_clientdata(i2c, da9055);
  36. return da9055_device_init(da9055);
  37. }
  38. static int da9055_i2c_remove(struct i2c_client *i2c)
  39. {
  40. struct da9055 *da9055 = i2c_get_clientdata(i2c);
  41. da9055_device_exit(da9055);
  42. return 0;
  43. }
  44. static struct i2c_device_id da9055_i2c_id[] = {
  45. {"da9055-pmic", 0},
  46. { }
  47. };
  48. static struct i2c_driver da9055_i2c_driver = {
  49. .probe = da9055_i2c_probe,
  50. .remove = da9055_i2c_remove,
  51. .id_table = da9055_i2c_id,
  52. .driver = {
  53. .name = "da9055",
  54. .owner = THIS_MODULE,
  55. },
  56. };
  57. static int __init da9055_i2c_init(void)
  58. {
  59. int ret;
  60. ret = i2c_add_driver(&da9055_i2c_driver);
  61. if (ret != 0) {
  62. pr_err("DA9055 I2C registration failed %d\n", ret);
  63. return ret;
  64. }
  65. return 0;
  66. }
  67. subsys_initcall(da9055_i2c_init);
  68. static void __exit da9055_i2c_exit(void)
  69. {
  70. i2c_del_driver(&da9055_i2c_driver);
  71. }
  72. module_exit(da9055_i2c_exit);
  73. MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
  74. MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
  75. MODULE_LICENSE("GPL");