tps65912-i2c.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * I2C access driver for TI TPS65912x PMICs
  3. *
  4. * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
  5. * Andrew F. Davis <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  12. * kind, whether expressed or implied; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License version 2 for more details.
  15. *
  16. * Based on the TPS65218 driver and the previous TPS65912 driver by
  17. * Margarita Olaya Cabrera <[email protected]>
  18. */
  19. #include <linux/i2c.h>
  20. #include <linux/module.h>
  21. #include <linux/regmap.h>
  22. #include <linux/mfd/tps65912.h>
  23. static const struct of_device_id tps65912_i2c_of_match_table[] = {
  24. { .compatible = "ti,tps65912", },
  25. { /* sentinel */ }
  26. };
  27. static int tps65912_i2c_probe(struct i2c_client *client,
  28. const struct i2c_device_id *ids)
  29. {
  30. struct tps65912 *tps;
  31. tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
  32. if (!tps)
  33. return -ENOMEM;
  34. i2c_set_clientdata(client, tps);
  35. tps->dev = &client->dev;
  36. tps->irq = client->irq;
  37. tps->regmap = devm_regmap_init_i2c(client, &tps65912_regmap_config);
  38. if (IS_ERR(tps->regmap)) {
  39. dev_err(tps->dev, "Failed to initialize register map\n");
  40. return PTR_ERR(tps->regmap);
  41. }
  42. return tps65912_device_init(tps);
  43. }
  44. static int tps65912_i2c_remove(struct i2c_client *client)
  45. {
  46. struct tps65912 *tps = i2c_get_clientdata(client);
  47. return tps65912_device_exit(tps);
  48. }
  49. static const struct i2c_device_id tps65912_i2c_id_table[] = {
  50. { "tps65912", 0 },
  51. { /* sentinel */ }
  52. };
  53. MODULE_DEVICE_TABLE(i2c, tps65912_i2c_id_table);
  54. static struct i2c_driver tps65912_i2c_driver = {
  55. .driver = {
  56. .name = "tps65912",
  57. .of_match_table = tps65912_i2c_of_match_table,
  58. },
  59. .probe = tps65912_i2c_probe,
  60. .remove = tps65912_i2c_remove,
  61. .id_table = tps65912_i2c_id_table,
  62. };
  63. module_i2c_driver(tps65912_i2c_driver);
  64. MODULE_AUTHOR("Andrew F. Davis <[email protected]>");
  65. MODULE_DESCRIPTION("TPS65912x I2C Interface Driver");
  66. MODULE_LICENSE("GPL v2");