cs40l26-spi.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // cs40l26-spi.c -- CS40L26 SPI Driver
  4. //
  5. // Copyright 2022 Cirrus Logic, Inc.
  6. //
  7. // Author: Fred Treven <[email protected]>
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License version 2 as
  11. // published by the Free Software Foundation.
  12. #ifdef CONFIG_CS40L26_SAMSUNG_FEATURE
  13. #include <linux/vibrator/cs40l26.h>
  14. #else
  15. #include <linux/mfd/cs40l26.h>
  16. #endif
  17. static const struct spi_device_id cs40l26_id_spi[] = {
  18. {"cs40l26a", 0},
  19. {"cs40l26b", 1},
  20. {"cs40l27a", 2},
  21. {"cs40l27b", 3},
  22. {}
  23. };
  24. MODULE_DEVICE_TABLE(spi, cs40l26_id_spi);
  25. static const struct of_device_id cs40l26_of_match[CS40L26_NUM_DEVS + 1] = {
  26. { .compatible = "cirrus,cs40l26a" },
  27. { .compatible = "cirrus,cs40l26b" },
  28. { .compatible = "cirrus,cs40l27a" },
  29. { .compatible = "cirrus,cs40l27b" },
  30. {}
  31. };
  32. MODULE_DEVICE_TABLE(of, cs40l26_of_match);
  33. static int cs40l26_spi_probe(struct spi_device *spi)
  34. {
  35. struct cs40l26_private *cs40l26;
  36. int error;
  37. cs40l26 = devm_kzalloc(&spi->dev, sizeof(struct cs40l26_private), GFP_KERNEL);
  38. if (!cs40l26)
  39. return -ENOMEM;
  40. spi_set_drvdata(spi, cs40l26);
  41. cs40l26->regmap = devm_regmap_init_spi(spi, &cs40l26_regmap);
  42. if (IS_ERR(cs40l26->regmap)) {
  43. error = PTR_ERR(cs40l26->regmap);
  44. dev_err(&spi->dev, "Failed to allocate register map: %d\n", error);
  45. return error;
  46. }
  47. cs40l26->dev = &spi->dev;
  48. cs40l26->irq = spi->irq;
  49. return cs40l26_probe(cs40l26);
  50. }
  51. static void cs40l26_spi_remove(struct spi_device *spi)
  52. {
  53. struct cs40l26_private *cs40l26 = spi_get_drvdata(spi);
  54. cs40l26_remove(cs40l26);
  55. }
  56. static struct spi_driver cs40l26_spi_driver = {
  57. .driver = {
  58. .name = "cs40l26",
  59. .of_match_table = cs40l26_of_match,
  60. .pm = &cs40l26_pm_ops,
  61. },
  62. .id_table = cs40l26_id_spi,
  63. .probe = cs40l26_spi_probe,
  64. .remove = cs40l26_spi_remove,
  65. };
  66. module_spi_driver(cs40l26_spi_driver);
  67. MODULE_DESCRIPTION("CS40L26 SPI Driver");
  68. MODULE_AUTHOR("Fred Treven, Cirrus Logic Inc. <[email protected]>");
  69. MODULE_LICENSE("GPL");