adau1977-spi.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * ADAU1977/ADAU1978/ADAU1979 driver
  3. *
  4. * Copyright 2014 Analog Devices Inc.
  5. * Author: Lars-Peter Clausen <lars@metafoo.de>
  6. *
  7. * Licensed under the GPL-2.
  8. */
  9. #include <linux/mod_devicetable.h>
  10. #include <linux/module.h>
  11. #include <linux/regmap.h>
  12. #include <linux/spi/spi.h>
  13. #include <sound/soc.h>
  14. #include "adau1977.h"
  15. static void adau1977_spi_switch_mode(struct device *dev)
  16. {
  17. struct spi_device *spi = to_spi_device(dev);
  18. /*
  19. * To get the device into SPI mode CLATCH has to be pulled low three
  20. * times. Do this by issuing three dummy reads.
  21. */
  22. spi_w8r8(spi, 0x00);
  23. spi_w8r8(spi, 0x00);
  24. spi_w8r8(spi, 0x00);
  25. }
  26. static int adau1977_spi_probe(struct spi_device *spi)
  27. {
  28. const struct spi_device_id *id = spi_get_device_id(spi);
  29. struct regmap_config config;
  30. if (!id)
  31. return -EINVAL;
  32. config = adau1977_regmap_config;
  33. config.val_bits = 8;
  34. config.reg_bits = 16;
  35. config.read_flag_mask = 0x1;
  36. return adau1977_probe(&spi->dev,
  37. devm_regmap_init_spi(spi, &config),
  38. id->driver_data, adau1977_spi_switch_mode);
  39. }
  40. static int adau1977_spi_remove(struct spi_device *spi)
  41. {
  42. snd_soc_unregister_codec(&spi->dev);
  43. return 0;
  44. }
  45. static const struct spi_device_id adau1977_spi_ids[] = {
  46. { "adau1977", ADAU1977 },
  47. { "adau1978", ADAU1978 },
  48. { "adau1979", ADAU1978 },
  49. { }
  50. };
  51. MODULE_DEVICE_TABLE(spi, adau1977_spi_ids);
  52. static struct spi_driver adau1977_spi_driver = {
  53. .driver = {
  54. .name = "adau1977",
  55. },
  56. .probe = adau1977_spi_probe,
  57. .remove = adau1977_spi_remove,
  58. .id_table = adau1977_spi_ids,
  59. };
  60. module_spi_driver(adau1977_spi_driver);
  61. MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver");
  62. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  63. MODULE_LICENSE("GPL");