pcm3008.c 4.4 KB

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