tps65912-spi.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SPI access driver for TI TPS65912x PMICs
  3. *
  4. * Copyright (C) 2015 Texas Instruments Incorporated - http://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/module.h>
  20. #include <linux/regmap.h>
  21. #include <linux/spi/spi.h>
  22. #include <linux/mfd/tps65912.h>
  23. static const struct of_device_id tps65912_spi_of_match_table[] = {
  24. { .compatible = "ti,tps65912", },
  25. { /* sentinel */ }
  26. };
  27. static int tps65912_spi_probe(struct spi_device *spi)
  28. {
  29. struct tps65912 *tps;
  30. tps = devm_kzalloc(&spi->dev, sizeof(*tps), GFP_KERNEL);
  31. if (!tps)
  32. return -ENOMEM;
  33. spi_set_drvdata(spi, tps);
  34. tps->dev = &spi->dev;
  35. tps->irq = spi->irq;
  36. tps->regmap = devm_regmap_init_spi(spi, &tps65912_regmap_config);
  37. if (IS_ERR(tps->regmap)) {
  38. dev_err(tps->dev, "Failed to initialize register map\n");
  39. return PTR_ERR(tps->regmap);
  40. }
  41. return tps65912_device_init(tps);
  42. }
  43. static int tps65912_spi_remove(struct spi_device *client)
  44. {
  45. struct tps65912 *tps = spi_get_drvdata(client);
  46. return tps65912_device_exit(tps);
  47. }
  48. static const struct spi_device_id tps65912_spi_id_table[] = {
  49. { "tps65912", 0 },
  50. { /* sentinel */ }
  51. };
  52. MODULE_DEVICE_TABLE(spi, tps65912_spi_id_table);
  53. static struct spi_driver tps65912_spi_driver = {
  54. .driver = {
  55. .name = "tps65912",
  56. .of_match_table = tps65912_spi_of_match_table,
  57. },
  58. .probe = tps65912_spi_probe,
  59. .remove = tps65912_spi_remove,
  60. .id_table = tps65912_spi_id_table,
  61. };
  62. module_spi_driver(tps65912_spi_driver);
  63. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  64. MODULE_DESCRIPTION("TPS65912x SPI Interface Driver");
  65. MODULE_LICENSE("GPL v2");