adau1761-spi.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for ADAU1361/ADAU1461/ADAU1761/ADAU1961 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 "adau1761.h"
  14. static void adau1761_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 adau1761_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 = adau1761_regmap_config;
  32. config.val_bits = 8;
  33. config.reg_bits = 24;
  34. config.read_flag_mask = 0x1;
  35. return adau1761_probe(&spi->dev,
  36. devm_regmap_init_spi(spi, &config),
  37. id->driver_data, adau1761_spi_switch_mode);
  38. }
  39. static void adau1761_spi_remove(struct spi_device *spi)
  40. {
  41. adau17x1_remove(&spi->dev);
  42. }
  43. static const struct spi_device_id adau1761_spi_id[] = {
  44. { "adau1361", ADAU1361 },
  45. { "adau1461", ADAU1761 },
  46. { "adau1761", ADAU1761 },
  47. { "adau1961", ADAU1361 },
  48. { }
  49. };
  50. MODULE_DEVICE_TABLE(spi, adau1761_spi_id);
  51. #if defined(CONFIG_OF)
  52. static const struct of_device_id adau1761_spi_dt_ids[] = {
  53. { .compatible = "adi,adau1361", },
  54. { .compatible = "adi,adau1461", },
  55. { .compatible = "adi,adau1761", },
  56. { .compatible = "adi,adau1961", },
  57. { },
  58. };
  59. MODULE_DEVICE_TABLE(of, adau1761_spi_dt_ids);
  60. #endif
  61. static struct spi_driver adau1761_spi_driver = {
  62. .driver = {
  63. .name = "adau1761",
  64. .of_match_table = of_match_ptr(adau1761_spi_dt_ids),
  65. },
  66. .probe = adau1761_spi_probe,
  67. .remove = adau1761_spi_remove,
  68. .id_table = adau1761_spi_id,
  69. };
  70. module_spi_driver(adau1761_spi_driver);
  71. MODULE_DESCRIPTION("ASoC ADAU1361/ADAU1461/ADAU1761/ADAU1961 CODEC SPI driver");
  72. MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
  73. MODULE_LICENSE("GPL");