smdk6410_wm8580_pcmif.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * smdk6400_wm8580_pcmif.c
  3. *
  4. * Copyright (C) 2007, Ryu Euiyoul
  5. * <steven,ryu@samsung.com, ryu.real@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/timer.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/i2c.h>
  18. #include <sound/driver.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/soc.h>
  23. #include <sound/soc-dapm.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/hardware.h>
  26. #include <asm/arch/audio.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/regs-s3c6410-clock.h>
  29. #include "../codecs/wm8580.h"
  30. #include "s3c-pcm.h"
  31. #include "s3c6410-pcmif.h"
  32. #ifdef CONFIG_SND_DEBUG
  33. #define s3cdbg(x...) printk(x)
  34. #else
  35. #define s3cdbg(x...)
  36. #endif
  37. static int smdk6410_hifi_hw_params(struct snd_pcm_substream *substream,
  38. struct snd_pcm_hw_params *params)
  39. {
  40. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  41. //struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
  42. struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
  43. int ret = 0;
  44. int fs = params_rate(params);
  45. /*PCLK & SCLK gating enable*/
  46. writel(readl(S3C_PCLK_GATE)|S3C_CLKCON_PCLK_PCM0|S3C_CLKCON_PCLK_PCM1, S3C_PCLK_GATE);
  47. writel(readl(S3C_SCLK_GATE)|S3C_CLKCON_SCLK_AUDIO0|S3C_CLKCON_SCLK_AUDIO1, S3C_SCLK_GATE);
  48. /* set prescaler division for sample rate */
  49. ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, 0, fs);
  50. if (ret < 0)
  51. return ret;
  52. return 0;
  53. }
  54. /*
  55. * WM8580 HiFi DAI opserations.
  56. */
  57. static struct snd_soc_ops smdk6410_hifi_ops = {
  58. .hw_params = smdk6410_hifi_hw_params,
  59. };
  60. static const struct snd_soc_dapm_widget wm8580_dapm_widgets[] = {
  61. SND_SOC_DAPM_LINE("I2S Front Jack", NULL),
  62. SND_SOC_DAPM_LINE("I2S Center Jack", NULL),
  63. SND_SOC_DAPM_LINE("I2S Rear Jack", NULL),
  64. SND_SOC_DAPM_LINE("Line In Jack", NULL),
  65. };
  66. /* example machine audio_mapnections */
  67. static const char* audio_map[][3] = {
  68. { "I2S Front Jack", NULL, "VOUT1L" },
  69. { "I2S Front Jack", NULL, "VOUT1R" },
  70. { "I2S Center Jack", NULL, "VOUT2L" },
  71. { "I2S Center Jack", NULL, "VOUT2R" },
  72. { "I2S Rear Jack", NULL, "VOUT3L" },
  73. { "I2S Rear Jack", NULL, "VOUT3R" },
  74. { "AINL", NULL, "Line In Jack" },
  75. { "AINR", NULL, "Line In Jack" },
  76. {NULL, NULL, NULL},
  77. };
  78. static int smdk6410_wm8580_init(struct snd_soc_codec *codec)
  79. {
  80. int i;
  81. /* Add smdk6410 specific widgets */
  82. for (i = 0; i < ARRAY_SIZE(wm8580_dapm_widgets); i++)
  83. snd_soc_dapm_new_control(codec, &wm8580_dapm_widgets[i]);
  84. /* set up smdk6410 specific audio paths */
  85. for (i = 0; audio_map[i][0] != NULL; i++) {
  86. snd_soc_dapm_connect_input(codec, audio_map[i][0],
  87. audio_map[i][1], audio_map[i][2]);
  88. }
  89. /* No jack detect - mark all jacks as enabled */
  90. for (i = 0; i < ARRAY_SIZE(wm8580_dapm_widgets); i++)
  91. snd_soc_dapm_set_endpoint(codec,
  92. wm8580_dapm_widgets[i].name, 1);
  93. return 0;
  94. }
  95. static struct snd_soc_dai_link smdk6410_dai[] = {
  96. {
  97. .name = "WM8580",
  98. .stream_name = "WM8580 HiFi Playback",
  99. .cpu_dai = &s3c_pcmif_dai,
  100. .codec_dai = &wm8580_dai[1],
  101. .init = smdk6410_wm8580_init,
  102. .ops = &smdk6410_hifi_ops,
  103. },
  104. };
  105. static struct snd_soc_machine smdk6410 = {
  106. .name = "smdk6410",
  107. .dai_link = smdk6410_dai,
  108. .num_links = ARRAY_SIZE(smdk6410_dai),
  109. };
  110. static struct wm8580_setup_data smdk6410_wm8580_setup = {
  111. .i2c_address = 0x1b,
  112. };
  113. static struct snd_soc_device smdk6410_snd_devdata = {
  114. .machine = &smdk6410,
  115. .platform = &s3c24xx_soc_platform,
  116. .codec_dev = &soc_codec_dev_wm8580,
  117. .codec_data = &smdk6410_wm8580_setup,
  118. };
  119. static struct platform_device *smdk6410_snd_device;
  120. static int __init smdk6410_pcmif_init(void)
  121. {
  122. int ret;
  123. smdk6410_snd_device = platform_device_alloc("soc-audio", -1);
  124. if (!smdk6410_snd_device)
  125. return -ENOMEM;
  126. platform_set_drvdata(smdk6410_snd_device, &smdk6410_snd_devdata);
  127. smdk6410_snd_devdata.dev = &smdk6410_snd_device->dev;
  128. ret = platform_device_add(smdk6410_snd_device);
  129. if (ret)
  130. platform_device_put(smdk6410_snd_device);
  131. return ret;
  132. }
  133. static void __exit smdk6410_pcmif_exit(void)
  134. {
  135. platform_device_unregister(smdk6410_snd_device);
  136. }
  137. module_init(smdk6410_pcmif_init);
  138. module_exit(smdk6410_pcmif_exit);
  139. /* Module information */
  140. MODULE_AUTHOR("Ryu Euiyoul");
  141. MODULE_DESCRIPTION("ALSA SoC SMDK6410 WM8580");
  142. MODULE_LICENSE("GPL");