cq93vc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. switch (freq) {
  59. case 22579200:
  60. case 27000000:
  61. case 33868800:
  62. return 0;
  63. }
  64. return -EINVAL;
  65. }
  66. static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
  67. enum snd_soc_bias_level level)
  68. {
  69. switch (level) {
  70. case SND_SOC_BIAS_ON:
  71. snd_soc_write(codec, DAVINCI_VC_REG12,
  72. DAVINCI_VC_REG12_POWER_ALL_ON);
  73. break;
  74. case SND_SOC_BIAS_PREPARE:
  75. break;
  76. case SND_SOC_BIAS_STANDBY:
  77. snd_soc_write(codec, DAVINCI_VC_REG12,
  78. DAVINCI_VC_REG12_POWER_ALL_OFF);
  79. break;
  80. case SND_SOC_BIAS_OFF:
  81. /* force all power off */
  82. snd_soc_write(codec, DAVINCI_VC_REG12,
  83. DAVINCI_VC_REG12_POWER_ALL_OFF);
  84. break;
  85. }
  86. return 0;
  87. }
  88. #define CQ93VC_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
  89. #define CQ93VC_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
  90. static const struct snd_soc_dai_ops cq93vc_dai_ops = {
  91. .digital_mute = cq93vc_mute,
  92. .set_sysclk = cq93vc_set_dai_sysclk,
  93. };
  94. static struct snd_soc_dai_driver cq93vc_dai = {
  95. .name = "cq93vc-hifi",
  96. .playback = {
  97. .stream_name = "Playback",
  98. .channels_min = 1,
  99. .channels_max = 2,
  100. .rates = CQ93VC_RATES,
  101. .formats = CQ93VC_FORMATS,},
  102. .capture = {
  103. .stream_name = "Capture",
  104. .channels_min = 1,
  105. .channels_max = 2,
  106. .rates = CQ93VC_RATES,
  107. .formats = CQ93VC_FORMATS,},
  108. .ops = &cq93vc_dai_ops,
  109. };
  110. static struct regmap *cq93vc_get_regmap(struct device *dev)
  111. {
  112. struct davinci_vc *davinci_vc = dev->platform_data;
  113. return davinci_vc->regmap;
  114. }
  115. static struct snd_soc_codec_driver soc_codec_dev_cq93vc = {
  116. .set_bias_level = cq93vc_set_bias_level,
  117. .get_regmap = cq93vc_get_regmap,
  118. .component_driver = {
  119. .controls = cq93vc_snd_controls,
  120. .num_controls = ARRAY_SIZE(cq93vc_snd_controls),
  121. },
  122. };
  123. static int cq93vc_platform_probe(struct platform_device *pdev)
  124. {
  125. return snd_soc_register_codec(&pdev->dev,
  126. &soc_codec_dev_cq93vc, &cq93vc_dai, 1);
  127. }
  128. static int cq93vc_platform_remove(struct platform_device *pdev)
  129. {
  130. snd_soc_unregister_codec(&pdev->dev);
  131. return 0;
  132. }
  133. static struct platform_driver cq93vc_codec_driver = {
  134. .driver = {
  135. .name = "cq93vc-codec",
  136. },
  137. .probe = cq93vc_platform_probe,
  138. .remove = cq93vc_platform_remove,
  139. };
  140. module_platform_driver(cq93vc_codec_driver);
  141. MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
  142. MODULE_AUTHOR("Miguel Aguilar");
  143. MODULE_LICENSE("GPL");