pcm3008.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_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. #ifdef CONFIG_PM
  48. static int pcm3008_soc_suspend(struct snd_soc_codec *codec)
  49. {
  50. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  51. gpio_set_value_cansleep(setup->pdad_pin, 0);
  52. gpio_set_value_cansleep(setup->pdda_pin, 0);
  53. return 0;
  54. }
  55. static int pcm3008_soc_resume(struct snd_soc_codec *codec)
  56. {
  57. struct pcm3008_setup_data *setup = codec->dev->platform_data;
  58. gpio_set_value_cansleep(setup->pdad_pin, 1);
  59. gpio_set_value_cansleep(setup->pdda_pin, 1);
  60. return 0;
  61. }
  62. #else
  63. #define pcm3008_soc_suspend NULL
  64. #define pcm3008_soc_resume NULL
  65. #endif
  66. static struct snd_soc_codec_driver soc_codec_dev_pcm3008 = {
  67. .suspend = pcm3008_soc_suspend,
  68. .resume = pcm3008_soc_resume,
  69. };
  70. static int pcm3008_codec_probe(struct platform_device *pdev)
  71. {
  72. struct pcm3008_setup_data *setup = pdev->dev.platform_data;
  73. int ret;
  74. if (!setup)
  75. return -EINVAL;
  76. /* DEM1 DEM0 DE-EMPHASIS_MODE
  77. * Low Low De-emphasis 44.1 kHz ON
  78. * Low High De-emphasis OFF
  79. * High Low De-emphasis 48 kHz ON
  80. * High High De-emphasis 32 kHz ON
  81. */
  82. /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
  83. ret = devm_gpio_request_one(&pdev->dev, setup->dem0_pin,
  84. GPIOF_OUT_INIT_HIGH, "codec_dem0");
  85. if (ret != 0)
  86. return ret;
  87. /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
  88. ret = devm_gpio_request_one(&pdev->dev, setup->dem1_pin,
  89. GPIOF_OUT_INIT_LOW, "codec_dem1");
  90. if (ret != 0)
  91. return ret;
  92. /* Configure PDAD GPIO. */
  93. ret = devm_gpio_request_one(&pdev->dev, setup->pdad_pin,
  94. GPIOF_OUT_INIT_HIGH, "codec_pdad");
  95. if (ret != 0)
  96. return ret;
  97. /* Configure PDDA GPIO. */
  98. ret = devm_gpio_request_one(&pdev->dev, setup->pdda_pin,
  99. GPIOF_OUT_INIT_HIGH, "codec_pdda");
  100. if (ret != 0)
  101. return ret;
  102. return snd_soc_register_codec(&pdev->dev,
  103. &soc_codec_dev_pcm3008, &pcm3008_dai, 1);
  104. }
  105. static int pcm3008_codec_remove(struct platform_device *pdev)
  106. {
  107. snd_soc_unregister_codec(&pdev->dev);
  108. return 0;
  109. }
  110. MODULE_ALIAS("platform:pcm3008-codec");
  111. static struct platform_driver pcm3008_codec_driver = {
  112. .probe = pcm3008_codec_probe,
  113. .remove = pcm3008_codec_remove,
  114. .driver = {
  115. .name = "pcm3008-codec",
  116. .owner = THIS_MODULE,
  117. },
  118. };
  119. module_platform_driver(pcm3008_codec_driver);
  120. MODULE_DESCRIPTION("Soc PCM3008 driver");
  121. MODULE_AUTHOR("Hugo Villeneuve");
  122. MODULE_LICENSE("GPL");