wm8782.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * sound/soc/codecs/wm8782.c
  4. * simple, strap-pin configured 24bit 2ch ADC
  5. *
  6. * Copyright: 2011 Raumfeld GmbH
  7. * Author: Johannes Stezenbach <js@sig21.net>
  8. *
  9. * based on ad73311.c
  10. * Copyright: Analog Devices Inc.
  11. * Author: Cliff Cai <cliff.cai@analog.com>
  12. */
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/device.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/ac97_codec.h>
  22. #include <sound/initval.h>
  23. #include <sound/soc.h>
  24. static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
  25. SND_SOC_DAPM_INPUT("AINL"),
  26. SND_SOC_DAPM_INPUT("AINR"),
  27. };
  28. static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
  29. { "Capture", NULL, "AINL" },
  30. { "Capture", NULL, "AINR" },
  31. };
  32. static struct snd_soc_dai_driver wm8782_dai = {
  33. .name = "wm8782",
  34. .capture = {
  35. .stream_name = "Capture",
  36. .channels_min = 2,
  37. .channels_max = 2,
  38. /* For configurations with FSAMPEN=0 */
  39. .rates = SNDRV_PCM_RATE_8000_48000,
  40. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  41. SNDRV_PCM_FMTBIT_S20_3LE |
  42. SNDRV_PCM_FMTBIT_S24_LE,
  43. },
  44. };
  45. /* regulator power supply names */
  46. static const char *supply_names[] = {
  47. "Vdda", /* analog supply, 2.7V - 3.6V */
  48. "Vdd", /* digital supply, 2.7V - 5.5V */
  49. };
  50. struct wm8782_priv {
  51. struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
  52. };
  53. static int wm8782_soc_probe(struct snd_soc_component *component)
  54. {
  55. struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
  56. return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
  57. }
  58. static void wm8782_soc_remove(struct snd_soc_component *component)
  59. {
  60. struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
  61. regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
  62. }
  63. #ifdef CONFIG_PM
  64. static int wm8782_soc_suspend(struct snd_soc_component *component)
  65. {
  66. struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
  67. regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
  68. return 0;
  69. }
  70. static int wm8782_soc_resume(struct snd_soc_component *component)
  71. {
  72. struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
  73. return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
  74. }
  75. #else
  76. #define wm8782_soc_suspend NULL
  77. #define wm8782_soc_resume NULL
  78. #endif /* CONFIG_PM */
  79. static const struct snd_soc_component_driver soc_component_dev_wm8782 = {
  80. .probe = wm8782_soc_probe,
  81. .remove = wm8782_soc_remove,
  82. .suspend = wm8782_soc_suspend,
  83. .resume = wm8782_soc_resume,
  84. .dapm_widgets = wm8782_dapm_widgets,
  85. .num_dapm_widgets = ARRAY_SIZE(wm8782_dapm_widgets),
  86. .dapm_routes = wm8782_dapm_routes,
  87. .num_dapm_routes = ARRAY_SIZE(wm8782_dapm_routes),
  88. .idle_bias_on = 1,
  89. .use_pmdown_time = 1,
  90. .endianness = 1,
  91. .non_legacy_dai_naming = 1,
  92. };
  93. static int wm8782_probe(struct platform_device *pdev)
  94. {
  95. struct device *dev = &pdev->dev;
  96. struct wm8782_priv *priv;
  97. int ret, i;
  98. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  99. if (!priv)
  100. return -ENOMEM;
  101. dev_set_drvdata(dev, priv);
  102. for (i = 0; i < ARRAY_SIZE(supply_names); i++)
  103. priv->supplies[i].supply = supply_names[i];
  104. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
  105. priv->supplies);
  106. if (ret < 0)
  107. return ret;
  108. return devm_snd_soc_register_component(&pdev->dev,
  109. &soc_component_dev_wm8782, &wm8782_dai, 1);
  110. }
  111. #ifdef CONFIG_OF
  112. static const struct of_device_id wm8782_of_match[] = {
  113. { .compatible = "wlf,wm8782", },
  114. { }
  115. };
  116. MODULE_DEVICE_TABLE(of, wm8782_of_match);
  117. #endif
  118. static struct platform_driver wm8782_codec_driver = {
  119. .driver = {
  120. .name = "wm8782",
  121. .of_match_table = of_match_ptr(wm8782_of_match),
  122. },
  123. .probe = wm8782_probe,
  124. };
  125. module_platform_driver(wm8782_codec_driver);
  126. MODULE_DESCRIPTION("ASoC WM8782 driver");
  127. MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>");
  128. MODULE_LICENSE("GPL");