tps65912-i2c.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * I2C access driver for TI TPS65912x PMICs
  4. *
  5. * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
  6. * Andrew F. Davis <[email protected]>
  7. *
  8. * Based on the TPS65218 driver and the previous TPS65912 driver by
  9. * Margarita Olaya Cabrera <[email protected]>
  10. */
  11. #include <linux/i2c.h>
  12. #include <linux/module.h>
  13. #include <linux/regmap.h>
  14. #include <linux/mfd/tps65912.h>
  15. static const struct of_device_id tps65912_i2c_of_match_table[] = {
  16. { .compatible = "ti,tps65912", },
  17. { /* sentinel */ }
  18. };
  19. MODULE_DEVICE_TABLE(of, tps65912_i2c_of_match_table);
  20. static int tps65912_i2c_probe(struct i2c_client *client,
  21. const struct i2c_device_id *ids)
  22. {
  23. struct tps65912 *tps;
  24. tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
  25. if (!tps)
  26. return -ENOMEM;
  27. i2c_set_clientdata(client, tps);
  28. tps->dev = &client->dev;
  29. tps->irq = client->irq;
  30. tps->regmap = devm_regmap_init_i2c(client, &tps65912_regmap_config);
  31. if (IS_ERR(tps->regmap)) {
  32. dev_err(tps->dev, "Failed to initialize register map\n");
  33. return PTR_ERR(tps->regmap);
  34. }
  35. return tps65912_device_init(tps);
  36. }
  37. static void tps65912_i2c_remove(struct i2c_client *client)
  38. {
  39. struct tps65912 *tps = i2c_get_clientdata(client);
  40. tps65912_device_exit(tps);
  41. }
  42. static const struct i2c_device_id tps65912_i2c_id_table[] = {
  43. { "tps65912", 0 },
  44. { /* sentinel */ }
  45. };
  46. MODULE_DEVICE_TABLE(i2c, tps65912_i2c_id_table);
  47. static struct i2c_driver tps65912_i2c_driver = {
  48. .driver = {
  49. .name = "tps65912",
  50. .of_match_table = tps65912_i2c_of_match_table,
  51. },
  52. .probe = tps65912_i2c_probe,
  53. .remove = tps65912_i2c_remove,
  54. .id_table = tps65912_i2c_id_table,
  55. };
  56. module_i2c_driver(tps65912_i2c_driver);
  57. MODULE_AUTHOR("Andrew F. Davis <[email protected]>");
  58. MODULE_DESCRIPTION("TPS65912x I2C Interface Driver");
  59. MODULE_LICENSE("GPL v2");