adau1781-spi.c 1.9 KB

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