adau1977-spi.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADAU1977/ADAU1978/ADAU1979 driver
  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/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/spi/spi.h>
  14. #include <sound/soc.h>
  15. #include "adau1977.h"
  16. static void adau1977_spi_switch_mode(struct device *dev)
  17. {
  18. struct spi_device *spi = to_spi_device(dev);
  19. /*
  20. * To get the device into SPI mode CLATCH has to be pulled low three
  21. * times. Do this by issuing three dummy reads.
  22. */
  23. spi_w8r8(spi, 0x00);
  24. spi_w8r8(spi, 0x00);
  25. spi_w8r8(spi, 0x00);
  26. }
  27. static int adau1977_spi_probe(struct spi_device *spi)
  28. {
  29. const struct spi_device_id *id = spi_get_device_id(spi);
  30. struct regmap_config config;
  31. if (!id)
  32. return -EINVAL;
  33. config = adau1977_regmap_config;
  34. config.val_bits = 8;
  35. config.reg_bits = 16;
  36. config.read_flag_mask = 0x1;
  37. return adau1977_probe(&spi->dev,
  38. devm_regmap_init_spi(spi, &config),
  39. id->driver_data, adau1977_spi_switch_mode);
  40. }
  41. static const struct spi_device_id adau1977_spi_ids[] = {
  42. { "adau1977", ADAU1977 },
  43. { "adau1978", ADAU1978 },
  44. { "adau1979", ADAU1978 },
  45. { }
  46. };
  47. MODULE_DEVICE_TABLE(spi, adau1977_spi_ids);
  48. static const struct of_device_id adau1977_spi_of_match[] = {
  49. { .compatible = "adi,adau1977" },
  50. { .compatible = "adi,adau1978" },
  51. { .compatible = "adi,adau1979" },
  52. { },
  53. };
  54. MODULE_DEVICE_TABLE(of, adau1977_spi_of_match);
  55. static struct spi_driver adau1977_spi_driver = {
  56. .driver = {
  57. .name = "adau1977",
  58. .of_match_table = of_match_ptr(adau1977_spi_of_match),
  59. },
  60. .probe = adau1977_spi_probe,
  61. .id_table = adau1977_spi_ids,
  62. };
  63. module_spi_driver(adau1977_spi_driver);
  64. MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver");
  65. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  66. MODULE_LICENSE("GPL");