adau1761-spi.c 2.0 KB

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