tlv320aic32x4-spi.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright 2011-2019 NW Digital Radio
  4. *
  5. * Author: Annaliese McDermond <[email protected]>
  6. *
  7. * Based on sound/soc/codecs/wm8974 and TI driver for kernel 2.6.27.
  8. *
  9. */
  10. #include <linux/spi/spi.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include <sound/soc.h>
  15. #include "tlv320aic32x4.h"
  16. static const struct of_device_id aic32x4_of_id[];
  17. static int aic32x4_spi_probe(struct spi_device *spi)
  18. {
  19. struct regmap *regmap;
  20. struct regmap_config config;
  21. config = aic32x4_regmap_config;
  22. config.reg_bits = 7;
  23. config.pad_bits = 1;
  24. config.val_bits = 8;
  25. config.read_flag_mask = 0x01;
  26. regmap = devm_regmap_init_spi(spi, &config);
  27. if (spi->dev.of_node) {
  28. const struct of_device_id *oid;
  29. oid = of_match_node(aic32x4_of_id, spi->dev.of_node);
  30. dev_set_drvdata(&spi->dev, (void *)oid->data);
  31. } else {
  32. const struct spi_device_id *id_entry;
  33. id_entry = spi_get_device_id(spi);
  34. dev_set_drvdata(&spi->dev, (void *)id_entry->driver_data);
  35. }
  36. return aic32x4_probe(&spi->dev, regmap);
  37. }
  38. static void aic32x4_spi_remove(struct spi_device *spi)
  39. {
  40. aic32x4_remove(&spi->dev);
  41. }
  42. static const struct spi_device_id aic32x4_spi_id[] = {
  43. { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 },
  44. { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 },
  45. { /* sentinel */ }
  46. };
  47. MODULE_DEVICE_TABLE(spi, aic32x4_spi_id);
  48. static const struct of_device_id aic32x4_of_id[] = {
  49. { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 },
  50. { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 },
  51. { /* senitel */ }
  52. };
  53. MODULE_DEVICE_TABLE(of, aic32x4_of_id);
  54. static struct spi_driver aic32x4_spi_driver = {
  55. .driver = {
  56. .name = "tlv320aic32x4",
  57. .owner = THIS_MODULE,
  58. .of_match_table = aic32x4_of_id,
  59. },
  60. .probe = aic32x4_spi_probe,
  61. .remove = aic32x4_spi_remove,
  62. .id_table = aic32x4_spi_id,
  63. };
  64. module_spi_driver(aic32x4_spi_driver);
  65. MODULE_DESCRIPTION("ASoC TLV320AIC32x4 codec driver SPI");
  66. MODULE_AUTHOR("Annaliese McDermond <[email protected]>");
  67. MODULE_LICENSE("GPL");