adau1781-spi.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Driver for ADAU1381/ADAU1781 CODEC
  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 "adau1781.h"
  15. static void adau1781_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 adau1781_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 = adau1781_regmap_config;
  33. config.val_bits = 8;
  34. config.reg_bits = 24;
  35. config.read_flag_mask = 0x1;
  36. return adau1781_probe(&spi->dev,
  37. devm_regmap_init_spi(spi, &config),
  38. id->driver_data, adau1781_spi_switch_mode);
  39. }
  40. static int adau1781_spi_remove(struct spi_device *spi)
  41. {
  42. adau17x1_remove(&spi->dev);
  43. return 0;
  44. }
  45. static const struct spi_device_id adau1781_spi_id[] = {
  46. { "adau1381", ADAU1381 },
  47. { "adau1781", ADAU1781 },
  48. { }
  49. };
  50. MODULE_DEVICE_TABLE(spi, adau1781_spi_id);
  51. #if defined(CONFIG_OF)
  52. static const struct of_device_id adau1781_spi_dt_ids[] = {
  53. { .compatible = "adi,adau1381", },
  54. { .compatible = "adi,adau1781", },
  55. { },
  56. };
  57. MODULE_DEVICE_TABLE(of, adau1781_spi_dt_ids);
  58. #endif
  59. static struct spi_driver adau1781_spi_driver = {
  60. .driver = {
  61. .name = "adau1781",
  62. .of_match_table = of_match_ptr(adau1781_spi_dt_ids),
  63. },
  64. .probe = adau1781_spi_probe,
  65. .remove = adau1781_spi_remove,
  66. .id_table = adau1781_spi_id,
  67. };
  68. module_spi_driver(adau1781_spi_driver);
  69. MODULE_DESCRIPTION("ASoC ADAU1381/ADAU1781 CODEC SPI driver");
  70. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  71. MODULE_LICENSE("GPL");