pcm3008.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #define PCM3008_VERSION "0.2"
  29. #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  30. SNDRV_PCM_RATE_48000)
  31. static struct snd_soc_dai_driver pcm3008_dai = {
  32. .name = "pcm3008-hifi",
  33. .playback = {
  34. .stream_name = "PCM3008 Playback",
  35. .channels_min = 1,
  36. .channels_max = 2,
  37. .rates = PCM3008_RATES,
  38. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  39. },
  40. .capture = {
  41. .stream_name = "PCM3008 Capture",
  42. .channels_min = 1,
  43. .channels_max = 2,
  44. .rates = PCM3008_RATES,
  45. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  46. },
  47. };
  48. static void pcm3008_gpio_free(struct pcm3008_setup_data *setup)
  49. {
  50. gpio_free(setup->dem0_pin);
  51. gpio_free(setup->dem1_pin);
  52. gpio_free(setup->pdad_pin);
  53. gpio_free(setup->pdda_pin);
  54. }
  55. static int pcm3008_soc_probe(struct snd_soc_codec *codec)
  56. {
  57. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  58. int ret = 0;
  59. printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION);
  60. /* DEM1 DEM0 DE-EMPHASIS_MODE
  61. * Low Low De-emphasis 44.1 kHz ON
  62. * Low High De-emphasis OFF
  63. * High Low De-emphasis 48 kHz ON
  64. * High High De-emphasis 32 kHz ON
  65. */
  66. /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
  67. ret = gpio_request(setup->dem0_pin, "codec_dem0");
  68. if (ret == 0)
  69. ret = gpio_direction_output(setup->dem0_pin, 1);
  70. if (ret != 0)
  71. goto gpio_err;
  72. /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
  73. ret = gpio_request(setup->dem1_pin, "codec_dem1");
  74. if (ret == 0)
  75. ret = gpio_direction_output(setup->dem1_pin, 0);
  76. if (ret != 0)
  77. goto gpio_err;
  78. /* Configure PDAD GPIO. */
  79. ret = gpio_request(setup->pdad_pin, "codec_pdad");
  80. if (ret == 0)
  81. ret = gpio_direction_output(setup->pdad_pin, 1);
  82. if (ret != 0)
  83. goto gpio_err;
  84. /* Configure PDDA GPIO. */
  85. ret = gpio_request(setup->pdda_pin, "codec_pdda");
  86. if (ret == 0)
  87. ret = gpio_direction_output(setup->pdda_pin, 1);
  88. if (ret != 0)
  89. goto gpio_err;
  90. return ret;
  91. gpio_err:
  92. pcm3008_gpio_free(setup);
  93. return ret;
  94. }
  95. static int pcm3008_soc_remove(struct snd_soc_codec *codec)
  96. {
  97. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  98. pcm3008_gpio_free(setup);
  99. return 0;
  100. }
  101. #ifdef CONFIG_PM
  102. static int pcm3008_soc_suspend(struct snd_soc_codec *codec)
  103. {
  104. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  105. gpio_set_value(setup->pdad_pin, 0);
  106. gpio_set_value(setup->pdda_pin, 0);
  107. return 0;
  108. }
  109. static int pcm3008_soc_resume(struct snd_soc_codec *codec)
  110. {
  111. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  112. gpio_set_value(setup->pdad_pin, 1);
  113. gpio_set_value(setup->pdda_pin, 1);
  114. return 0;
  115. }
  116. #else
  117. #define pcm3008_soc_suspend NULL
  118. #define pcm3008_soc_resume NULL
  119. #endif
  120. static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = {
  121. .probe = pcm3008_soc_probe,
  122. .remove = pcm3008_soc_remove,
  123. .suspend = pcm3008_soc_suspend,
  124. .resume = pcm3008_soc_resume,
  125. };
  126. static int __devinit pcm3008_codec_probe(struct platform_device *pdev)
  127. {
  128. return snd_soc_register_codec(&pdev->dev,
  129. &soc_codec_dev_pcm3008, &pcm3008_dai, 1);
  130. }
  131. static int __devexit pcm3008_codec_remove(struct platform_device *pdev)
  132. {
  133. snd_soc_unregister_codec(&pdev->dev);
  134. return 0;
  135. }
  136. MODULE_ALIAS("platform:pcm3008-codec");
  137. static struct platform_driver pcm3008_codec_driver = {
  138. .probe = pcm3008_codec_probe,
  139. .remove = __devexit_p(pcm3008_codec_remove),
  140. .driver = {
  141. .name = "pcm3008-codec",
  142. .owner = THIS_MODULE,
  143. },
  144. };
  145. module_platform_driver(pcm3008_codec_driver);
  146. MODULE_DESCRIPTION("Soc PCM3008 driver");
  147. MODULE_AUTHOR("Hugo Villeneuve");
  148. MODULE_LICENSE("GPL");