pcm3008.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * ALSA Soc PCM3008 codec support
  3. *
  4. * Author: Hugo Villeneuve
  5. * Copyright (C) 2008 Lyrtech inc
  6. *
  7. * Based on AC97 Soc codec, original copyright follow:
  8. * Copyright 2005 Wolfson Microelectronics PLC.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * Generic PCM3008 support.
  16. */
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/device.h>
  20. #include <linux/gpio.h>
  21. #include <linux/slab.h>
  22. #include <linux/module.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/initval.h>
  26. #include <sound/soc.h>
  27. #include "pcm3008.h"
  28. static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
  29. struct snd_kcontrol *kcontrol,
  30. int event)
  31. {
  32. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  33. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  34. gpio_set_value_cansleep(setup->pdda_pin,
  35. SND_SOC_DAPM_EVENT_ON(event));
  36. return 0;
  37. }
  38. static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
  39. struct snd_kcontrol *kcontrol,
  40. int event)
  41. {
  42. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  43. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  44. gpio_set_value_cansleep(setup->pdad_pin,
  45. SND_SOC_DAPM_EVENT_ON(event));
  46. return 0;
  47. }
  48. static const struct snd_soc_dapm_widget pcm3008_dapm_widgets[] = {
  49. SND_SOC_DAPM_INPUT("VINL"),
  50. SND_SOC_DAPM_INPUT("VINR"),
  51. SND_SOC_DAPM_DAC_E("DAC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_dac_ev,
  52. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  53. SND_SOC_DAPM_ADC_E("ADC", NULL, SND_SOC_NOPM, 0, 0, pcm3008_adc_ev,
  54. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  55. SND_SOC_DAPM_OUTPUT("VOUTL"),
  56. SND_SOC_DAPM_OUTPUT("VOUTR"),
  57. };
  58. static const struct snd_soc_dapm_route pcm3008_dapm_routes[] = {
  59. { "PCM3008 Capture", NULL, "ADC" },
  60. { "ADC", NULL, "VINL" },
  61. { "ADC", NULL, "VINR" },
  62. { "DAC", NULL, "PCM3008 Playback" },
  63. { "VOUTL", NULL, "DAC" },
  64. { "VOUTR", NULL, "DAC" },
  65. };
  66. #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  67. SNDRV_PCM_RATE_48000)
  68. static struct snd_soc_dai_driver pcm3008_dai = {
  69. .name = "pcm3008-hifi",
  70. .playback = {
  71. .stream_name = "PCM3008 Playback",
  72. .channels_min = 1,
  73. .channels_max = 2,
  74. .rates = PCM3008_RATES,
  75. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  76. },
  77. .capture = {
  78. .stream_name = "PCM3008 Capture",
  79. .channels_min = 1,
  80. .channels_max = 2,
  81. .rates = PCM3008_RATES,
  82. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  83. },
  84. };
  85. static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = {
  86. .component_driver = {
  87. .dapm_widgets = pcm3008_dapm_widgets,
  88. .num_dapm_widgets = ARRAY_SIZE(pcm3008_dapm_widgets),
  89. .dapm_routes = pcm3008_dapm_routes,
  90. .num_dapm_routes = ARRAY_SIZE(pcm3008_dapm_routes),
  91. },
  92. };
  93. static int pcm3008_codec_probe(struct platform_device *pdev)
  94. {
  95. struct pcm3008_setup_data *setup = pdev->dev.platform_data;
  96. int ret;
  97. if (!setup)
  98. return -EINVAL;
  99. /* DEM1 DEM0 DE-EMPHASIS_MODE
  100. * Low Low De-emphasis 44.1 kHz ON
  101. * Low High De-emphasis OFF
  102. * High Low De-emphasis 48 kHz ON
  103. * High High De-emphasis 32 kHz ON
  104. */
  105. /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
  106. ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
  107. GPIOF_OUT_INIT_HIGH, "codec_dem0");
  108. if (ret != 0)
  109. return ret;
  110. /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
  111. ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
  112. GPIOF_OUT_INIT_LOW, "codec_dem1");
  113. if (ret != 0)
  114. return ret;
  115. /* Configure PDAD GPIO. */
  116. ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
  117. GPIOF_OUT_INIT_LOW, "codec_pdad");
  118. if (ret != 0)
  119. return ret;
  120. /* Configure PDDA GPIO. */
  121. ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
  122. GPIOF_OUT_INIT_LOW, "codec_pdda");
  123. if (ret != 0)
  124. return ret;
  125. return snd_soc_register_codec(&pdev->dev,
  126. &soc_codec_dev_pcm3008, &pcm3008_dai, 1);
  127. }
  128. static int pcm3008_codec_remove(struct platform_device *pdev)
  129. {
  130. snd_soc_unregister_codec(&pdev->dev);
  131. return 0;
  132. }
  133. MODULE_ALIAS("platform:pcm3008-codec");
  134. static struct platform_driver pcm3008_codec_driver = {
  135. .probe = pcm3008_codec_probe,
  136. .remove = pcm3008_codec_remove,
  137. .driver = {
  138. .name = "pcm3008-codec",
  139. },
  140. };
  141. module_platform_driver(pcm3008_codec_driver);
  142. MODULE_DESCRIPTION("Soc PCM3008 driver");
  143. MODULE_AUTHOR("Hugo Villeneuve");
  144. MODULE_LICENSE("GPL");