adau1372-spi.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for ADAU1372 codec
  4. *
  5. * Copyright 2016 Analog Devices Inc.
  6. * Author: Lars-Peter Clausen <[email protected]>
  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 "adau1372.h"
  14. static void adau1372_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 adau1372_spi_probe(struct spi_device *spi)
  26. {
  27. struct regmap_config config;
  28. config = adau1372_regmap_config;
  29. config.read_flag_mask = 0x1;
  30. return adau1372_probe(&spi->dev,
  31. devm_regmap_init_spi(spi, &config), adau1372_spi_switch_mode);
  32. }
  33. static const struct spi_device_id adau1372_spi_id[] = {
  34. { "adau1372", 0 },
  35. { }
  36. };
  37. MODULE_DEVICE_TABLE(spi, adau1372_spi_id);
  38. static struct spi_driver adau1372_spi_driver = {
  39. .driver = {
  40. .name = "adau1372",
  41. },
  42. .probe = adau1372_spi_probe,
  43. .id_table = adau1372_spi_id,
  44. };
  45. module_spi_driver(adau1372_spi_driver);
  46. MODULE_DESCRIPTION("ASoC ADAU1372 CODEC SPI driver");
  47. MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
  48. MODULE_LICENSE("GPL v2");