cs35l41-spi.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // cs35l41-spi.c -- CS35l41 SPI driver
  4. //
  5. // Copyright 2017-2021 Cirrus Logic, Inc.
  6. //
  7. // Author: David Rhodes <[email protected]>
  8. #include <linux/acpi.h>
  9. #include <linux/delay.h>
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/spi/spi.h>
  16. #include "cs35l41.h"
  17. static const struct spi_device_id cs35l41_id_spi[] = {
  18. { "cs35l40", 0 },
  19. { "cs35l41", 0 },
  20. { "cs35l51", 0 },
  21. { "cs35l53", 0 },
  22. {}
  23. };
  24. MODULE_DEVICE_TABLE(spi, cs35l41_id_spi);
  25. static int cs35l41_spi_probe(struct spi_device *spi)
  26. {
  27. const struct regmap_config *regmap_config = &cs35l41_regmap_spi;
  28. struct cs35l41_hw_cfg *hw_cfg = dev_get_platdata(&spi->dev);
  29. struct cs35l41_private *cs35l41;
  30. int ret;
  31. cs35l41 = devm_kzalloc(&spi->dev, sizeof(struct cs35l41_private), GFP_KERNEL);
  32. if (!cs35l41)
  33. return -ENOMEM;
  34. spi->max_speed_hz = CS35L41_SPI_MAX_FREQ;
  35. spi_setup(spi);
  36. spi_set_drvdata(spi, cs35l41);
  37. cs35l41->regmap = devm_regmap_init_spi(spi, regmap_config);
  38. if (IS_ERR(cs35l41->regmap)) {
  39. ret = PTR_ERR(cs35l41->regmap);
  40. dev_err(&spi->dev, "Failed to allocate register map: %d\n", ret);
  41. return ret;
  42. }
  43. cs35l41->dev = &spi->dev;
  44. cs35l41->irq = spi->irq;
  45. return cs35l41_probe(cs35l41, hw_cfg);
  46. }
  47. static void cs35l41_spi_remove(struct spi_device *spi)
  48. {
  49. struct cs35l41_private *cs35l41 = spi_get_drvdata(spi);
  50. cs35l41_remove(cs35l41);
  51. }
  52. #ifdef CONFIG_OF
  53. static const struct of_device_id cs35l41_of_match[] = {
  54. { .compatible = "cirrus,cs35l40" },
  55. { .compatible = "cirrus,cs35l41" },
  56. {},
  57. };
  58. MODULE_DEVICE_TABLE(of, cs35l41_of_match);
  59. #endif
  60. #ifdef CONFIG_ACPI
  61. static const struct acpi_device_id cs35l41_acpi_match[] = {
  62. { "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
  63. { "CLSA3541", 0 }, /* Cirrus Logic PnP ID + part ID */
  64. {},
  65. };
  66. MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
  67. #endif
  68. static struct spi_driver cs35l41_spi_driver = {
  69. .driver = {
  70. .name = "cs35l41",
  71. .pm = &cs35l41_pm_ops,
  72. .of_match_table = of_match_ptr(cs35l41_of_match),
  73. .acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
  74. },
  75. .id_table = cs35l41_id_spi,
  76. .probe = cs35l41_spi_probe,
  77. .remove = cs35l41_spi_remove,
  78. };
  79. module_spi_driver(cs35l41_spi_driver);
  80. MODULE_DESCRIPTION("SPI CS35L41 driver");
  81. MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <[email protected]>");
  82. MODULE_LICENSE("GPL");