tps65912-i2c.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * I2C access driver for TI TPS65912x PMICs
  3. *
  4. * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
  5. * Andrew F. Davis <afd@ti.com>
  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 <magi@slimlogic.co.uk>
  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. MODULE_DEVICE_TABLE(of, tps65912_i2c_of_match_table);
  28. static int tps65912_i2c_probe(struct i2c_client *client,
  29. const struct i2c_device_id *ids)
  30. {
  31. struct tps65912 *tps;
  32. tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
  33. if (!tps)
  34. return -ENOMEM;
  35. i2c_set_clientdata(client, tps);
  36. tps->dev = &client->dev;
  37. tps->irq = client->irq;
  38. tps->regmap = devm_regmap_init_i2c(client, &tps65912_regmap_config);
  39. if (IS_ERR(tps->regmap)) {
  40. dev_err(tps->dev, "Failed to initialize register map\n");
  41. return PTR_ERR(tps->regmap);
  42. }
  43. return tps65912_device_init(tps);
  44. }
  45. static int tps65912_i2c_remove(struct i2c_client *client)
  46. {
  47. struct tps65912 *tps = i2c_get_clientdata(client);
  48. return tps65912_device_exit(tps);
  49. }
  50. static const struct i2c_device_id tps65912_i2c_id_table[] = {
  51. { "tps65912", 0 },
  52. { /* sentinel */ }
  53. };
  54. MODULE_DEVICE_TABLE(i2c, tps65912_i2c_id_table);
  55. static struct i2c_driver tps65912_i2c_driver = {
  56. .driver = {
  57. .name = "tps65912",
  58. .of_match_table = tps65912_i2c_of_match_table,
  59. },
  60. .probe = tps65912_i2c_probe,
  61. .remove = tps65912_i2c_remove,
  62. .id_table = tps65912_i2c_id_table,
  63. };
  64. module_i2c_driver(tps65912_i2c_driver);
  65. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  66. MODULE_DESCRIPTION("TPS65912x I2C Interface Driver");
  67. MODULE_LICENSE("GPL v2");