cq93vc.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
  3. *
  4. * Copyright (C) 2010 Texas Instruments, Inc
  5. *
  6. * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/module.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/init.h>
  25. #include <linux/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/pm.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/device.h>
  30. #include <linux/slab.h>
  31. #include <linux/clk.h>
  32. #include <linux/mfd/davinci_voicecodec.h>
  33. #include <linux/spi/spi.h>
  34. #include <sound/core.h>
  35. #include <sound/pcm.h>
  36. #include <sound/pcm_params.h>
  37. #include <sound/soc.h>
  38. #include <sound/initval.h>
  39. static const struct snd_kcontrol_new cq93vc_snd_controls[] = {
  40. SOC_SINGLE("PGA Capture Volume", DAVINCI_VC_REG05, 0, 0x03, 0),
  41. SOC_SINGLE("Mono DAC Playback Volume", DAVINCI_VC_REG09, 0, 0x3f, 0),
  42. };
  43. static int cq93vc_mute(struct snd_soc_dai *dai, int mute)
  44. {
  45. struct snd_soc_codec *codec = dai->codec;
  46. u8 reg;
  47. if (mute)
  48. reg = DAVINCI_VC_REG09_MUTE;
  49. else
  50. reg = 0;
  51. snd_soc_update_bits(codec, DAVINCI_VC_REG09, DAVINCI_VC_REG09_MUTE,
  52. reg);
  53. return 0;
  54. }
  55. static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  56. int clk_id, unsigned int freq, int dir)
  57. {
  58. struct snd_soc_codec *codec = codec_dai->codec;
  59. struct davinci_vc *davinci_vc = codec->dev->platform_data;
  60. switch (freq) {
  61. case 22579200:
  62. case 27000000:
  63. case 33868800:
  64. davinci_vc->cq93vc.sysclk = freq;
  65. return 0;
  66. }
  67. return -EINVAL;
  68. }
  69. static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
  70. enum snd_soc_bias_level level)
  71. {
  72. switch (level) {
  73. case SND_SOC_BIAS_ON:
  74. snd_soc_write(codec, DAVINCI_VC_REG12,
  75. DAVINCI_VC_REG12_POWER_ALL_ON);
  76. break;
  77. case SND_SOC_BIAS_PREPARE:
  78. break;
  79. case SND_SOC_BIAS_STANDBY:
  80. snd_soc_write(codec, DAVINCI_VC_REG12,
  81. DAVINCI_VC_REG12_POWER_ALL_OFF);
  82. break;
  83. case SND_SOC_BIAS_OFF:
  84. /* force all power off */
  85. snd_soc_write(codec, DAVINCI_VC_REG12,
  86. DAVINCI_VC_REG12_POWER_ALL_OFF);
  87. break;
  88. }
  89. codec->dapm.bias_level = level;
  90. return 0;
  91. }
  92. #define CQ93VC_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
  93. #define CQ93VC_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
  94. static const struct snd_soc_dai_ops cq93vc_dai_ops = {
  95. .digital_mute = cq93vc_mute,
  96. .set_sysclk = cq93vc_set_dai_sysclk,
  97. };
  98. static struct snd_soc_dai_driver cq93vc_dai = {
  99. .name = "cq93vc-hifi",
  100. .playback = {
  101. .stream_name = "Playback",
  102. .channels_min = 1,
  103. .channels_max = 2,
  104. .rates = CQ93VC_RATES,
  105. .formats = CQ93VC_FORMATS,},
  106. .capture = {
  107. .stream_name = "Capture",
  108. .channels_min = 1,
  109. .channels_max = 2,
  110. .rates = CQ93VC_RATES,
  111. .formats = CQ93VC_FORMATS,},
  112. .ops = &cq93vc_dai_ops,
  113. };
  114. static int cq93vc_resume(struct snd_soc_codec *codec)
  115. {
  116. cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  117. return 0;
  118. }
  119. static int cq93vc_probe(struct snd_soc_codec *codec)
  120. {
  121. struct davinci_vc *davinci_vc = codec->dev->platform_data;
  122. davinci_vc->cq93vc.codec = codec;
  123. codec->control_data = davinci_vc->regmap;
  124. snd_soc_codec_set_cache_io(codec, 32, 32, SND_SOC_REGMAP);
  125. /* Off, with power on */
  126. cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  127. return 0;
  128. }
  129. static int cq93vc_remove(struct snd_soc_codec *codec)
  130. {
  131. cq93vc_set_bias_level(codec, SND_SOC_BIAS_OFF);
  132. return 0;
  133. }
  134. static struct snd_soc_codec_driver soc_codec_dev_cq93vc = {
  135. .set_bias_level = cq93vc_set_bias_level,
  136. .probe = cq93vc_probe,
  137. .remove = cq93vc_remove,
  138. .resume = cq93vc_resume,
  139. .controls = cq93vc_snd_controls,
  140. .num_controls = ARRAY_SIZE(cq93vc_snd_controls),
  141. };
  142. static int cq93vc_platform_probe(struct platform_device *pdev)
  143. {
  144. return snd_soc_register_codec(&pdev->dev,
  145. &soc_codec_dev_cq93vc, &cq93vc_dai, 1);
  146. }
  147. static int cq93vc_platform_remove(struct platform_device *pdev)
  148. {
  149. snd_soc_unregister_codec(&pdev->dev);
  150. return 0;
  151. }
  152. static struct platform_driver cq93vc_codec_driver = {
  153. .driver = {
  154. .name = "cq93vc-codec",
  155. .owner = THIS_MODULE,
  156. },
  157. .probe = cq93vc_platform_probe,
  158. .remove = cq93vc_platform_remove,
  159. };
  160. module_platform_driver(cq93vc_codec_driver);
  161. MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
  162. MODULE_AUTHOR("Miguel Aguilar");
  163. MODULE_LICENSE("GPL");