adau7002.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADAU7002 Stereo PDM-to-I2S/TDM converter driver
  4. *
  5. * Copyright 2014-2016 Analog Devices
  6. * Author: Lars-Peter Clausen <[email protected]>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/delay.h>
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include <sound/soc.h>
  15. struct adau7002_priv {
  16. int wakeup_delay;
  17. };
  18. static int adau7002_aif_event(struct snd_soc_dapm_widget *w,
  19. struct snd_kcontrol *kcontrol, int event)
  20. {
  21. struct snd_soc_component *component =
  22. snd_soc_dapm_to_component(w->dapm);
  23. struct adau7002_priv *adau7002 =
  24. snd_soc_component_get_drvdata(component);
  25. switch (event) {
  26. case SND_SOC_DAPM_POST_PMU:
  27. if (adau7002->wakeup_delay)
  28. msleep(adau7002->wakeup_delay);
  29. break;
  30. }
  31. return 0;
  32. }
  33. static int adau7002_component_probe(struct snd_soc_component *component)
  34. {
  35. struct adau7002_priv *adau7002;
  36. adau7002 = devm_kzalloc(component->dev, sizeof(*adau7002),
  37. GFP_KERNEL);
  38. if (!adau7002)
  39. return -ENOMEM;
  40. device_property_read_u32(component->dev, "wakeup-delay-ms",
  41. &adau7002->wakeup_delay);
  42. snd_soc_component_set_drvdata(component, adau7002);
  43. return 0;
  44. }
  45. static const struct snd_soc_dapm_widget adau7002_widgets[] = {
  46. SND_SOC_DAPM_AIF_OUT_E("ADAU AIF", "Capture", 0,
  47. SND_SOC_NOPM, 0, 0, adau7002_aif_event,
  48. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  49. SND_SOC_DAPM_INPUT("PDM_DAT"),
  50. SND_SOC_DAPM_REGULATOR_SUPPLY("IOVDD", 0, 0),
  51. };
  52. static const struct snd_soc_dapm_route adau7002_routes[] = {
  53. { "ADAU AIF", NULL, "PDM_DAT"},
  54. { "Capture", NULL, "PDM_DAT" },
  55. { "Capture", NULL, "IOVDD" },
  56. };
  57. static struct snd_soc_dai_driver adau7002_dai = {
  58. .name = "adau7002-hifi",
  59. .capture = {
  60. .stream_name = "Capture",
  61. .channels_min = 2,
  62. .channels_max = 2,
  63. .rates = SNDRV_PCM_RATE_8000_96000,
  64. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S18_3LE |
  65. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |
  66. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE,
  67. .sig_bits = 20,
  68. },
  69. };
  70. static const struct snd_soc_component_driver adau7002_component_driver = {
  71. .probe = adau7002_component_probe,
  72. .dapm_widgets = adau7002_widgets,
  73. .num_dapm_widgets = ARRAY_SIZE(adau7002_widgets),
  74. .dapm_routes = adau7002_routes,
  75. .num_dapm_routes = ARRAY_SIZE(adau7002_routes),
  76. .idle_bias_on = 1,
  77. .use_pmdown_time = 1,
  78. .endianness = 1,
  79. };
  80. static int adau7002_probe(struct platform_device *pdev)
  81. {
  82. return devm_snd_soc_register_component(&pdev->dev,
  83. &adau7002_component_driver,
  84. &adau7002_dai, 1);
  85. }
  86. static int adau7002_remove(struct platform_device *pdev)
  87. {
  88. return 0;
  89. }
  90. #ifdef CONFIG_OF
  91. static const struct of_device_id adau7002_dt_ids[] = {
  92. { .compatible = "adi,adau7002", },
  93. { }
  94. };
  95. MODULE_DEVICE_TABLE(of, adau7002_dt_ids);
  96. #endif
  97. #ifdef CONFIG_ACPI
  98. static const struct acpi_device_id adau7002_acpi_match[] = {
  99. { "ADAU7002", 0 },
  100. {},
  101. };
  102. MODULE_DEVICE_TABLE(acpi, adau7002_acpi_match);
  103. #endif
  104. static struct platform_driver adau7002_driver = {
  105. .driver = {
  106. .name = "adau7002",
  107. .of_match_table = of_match_ptr(adau7002_dt_ids),
  108. .acpi_match_table = ACPI_PTR(adau7002_acpi_match),
  109. },
  110. .probe = adau7002_probe,
  111. .remove = adau7002_remove,
  112. };
  113. module_platform_driver(adau7002_driver);
  114. MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
  115. MODULE_DESCRIPTION("ADAU7002 Stereo PDM-to-I2S/TDM Converter driver");
  116. MODULE_LICENSE("GPL v2");