adau1761-spi.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for ADAU1361/ADAU1461/ADAU1761/ADAU1961 codec
  4. *
  5. * Copyright 2014 Analog Devices Inc.
  6. * Author: Lars-Peter Clausen <lars@metafoo.de>
  7. */
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/module.h>
  10. #include <linux/regmap.h>
  11. #include <linux/spi/spi.h>
  12. #include <sound/soc.h>
  13. #include "adau1761.h"
  14. static void adau1761_spi_switch_mode(struct device *dev)
  15. {
  16. struct spi_device *spi = to_spi_device(dev);
  17. /*
  18. * To get the device into SPI mode CLATCH has to be pulled low three
  19. * times. Do this by issuing three dummy reads.
  20. */
  21. spi_w8r8(spi, 0x00);
  22. spi_w8r8(spi, 0x00);
  23. spi_w8r8(spi, 0x00);
  24. }
  25. static int adau1761_spi_probe(struct spi_device *spi)
  26. {
  27. const struct spi_device_id *id = spi_get_device_id(spi);
  28. struct regmap_config config;
  29. if (!id)
  30. return -EINVAL;
  31. config = adau1761_regmap_config;
  32. config.val_bits = 8;
  33. config.reg_bits = 24;
  34. config.read_flag_mask = 0x1;
  35. return adau1761_probe(&spi->dev,
  36. devm_regmap_init_spi(spi, &config),
  37. id->driver_data, adau1761_spi_switch_mode);
  38. }
  39. static int adau1761_spi_remove(struct spi_device *spi)
  40. {
  41. adau17x1_remove(&spi->dev);
  42. return 0;
  43. }
  44. static const struct spi_device_id adau1761_spi_id[] = {
  45. { "adau1361", ADAU1361 },
  46. { "adau1461", ADAU1761 },
  47. { "adau1761", ADAU1761 },
  48. { "adau1961", ADAU1361 },
  49. { }
  50. };
  51. MODULE_DEVICE_TABLE(spi, adau1761_spi_id);
  52. #if defined(CONFIG_OF)
  53. static const struct of_device_id adau1761_spi_dt_ids[] = {
  54. { .compatible = "adi,adau1361", },
  55. { .compatible = "adi,adau1461", },
  56. { .compatible = "adi,adau1761", },
  57. { .compatible = "adi,adau1961", },
  58. { },
  59. };
  60. MODULE_DEVICE_TABLE(of, adau1761_spi_dt_ids);
  61. #endif
  62. static struct spi_driver adau1761_spi_driver = {
  63. .driver = {
  64. .name = "adau1761",
  65. .of_match_table = of_match_ptr(adau1761_spi_dt_ids),
  66. },
  67. .probe = adau1761_spi_probe,
  68. .remove = adau1761_spi_remove,
  69. .id_table = adau1761_spi_id,
  70. };
  71. module_spi_driver(adau1761_spi_driver);
  72. MODULE_DESCRIPTION("ASoC ADAU1361/ADAU1461/ADAU1761/ADAU1961 CODEC SPI driver");
  73. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  74. MODULE_LICENSE("GPL");