jive_wm8750.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* sound/soc/s3c24xx/jive_wm8750.c
  2. *
  3. * Copyright 2007,2008 Simtec Electronics
  4. *
  5. * Based on sound/soc/pxa/spitz.c
  6. * Copyright 2005 Wolfson Microelectronics PLC.
  7. * Copyright 2005 Openedhand Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/timer.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/clk.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/soc.h>
  22. #include <sound/soc-dapm.h>
  23. #include <asm/mach-types.h>
  24. #include "s3c-dma.h"
  25. #include "s3c2412-i2s.h"
  26. #include "../codecs/wm8750.h"
  27. static const struct snd_soc_dapm_route audio_map[] = {
  28. { "Headphone Jack", NULL, "LOUT1" },
  29. { "Headphone Jack", NULL, "ROUT1" },
  30. { "Internal Speaker", NULL, "LOUT2" },
  31. { "Internal Speaker", NULL, "ROUT2" },
  32. { "LINPUT1", NULL, "Line Input" },
  33. { "RINPUT1", NULL, "Line Input" },
  34. };
  35. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  36. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  37. SND_SOC_DAPM_SPK("Internal Speaker", NULL),
  38. SND_SOC_DAPM_LINE("Line In", NULL),
  39. };
  40. static int jive_hw_params(struct snd_pcm_substream *substream,
  41. struct snd_pcm_hw_params *params)
  42. {
  43. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  44. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  45. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  46. struct s3c_i2sv2_rate_calc div;
  47. unsigned int clk = 0;
  48. int ret = 0;
  49. switch (params_rate(params)) {
  50. case 8000:
  51. case 16000:
  52. case 48000:
  53. case 96000:
  54. clk = 12288000;
  55. break;
  56. case 11025:
  57. case 22050:
  58. case 44100:
  59. clk = 11289600;
  60. break;
  61. }
  62. s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
  63. s3c_i2sv2_get_clock(cpu_dai));
  64. /* set codec DAI configuration */
  65. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  66. SND_SOC_DAIFMT_NB_NF |
  67. SND_SOC_DAIFMT_CBS_CFS);
  68. if (ret < 0)
  69. return ret;
  70. /* set cpu DAI configuration */
  71. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  72. SND_SOC_DAIFMT_NB_NF |
  73. SND_SOC_DAIFMT_CBS_CFS);
  74. if (ret < 0)
  75. return ret;
  76. /* set the codec system clock for DAC and ADC */
  77. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  78. SND_SOC_CLOCK_IN);
  79. if (ret < 0)
  80. return ret;
  81. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
  82. if (ret < 0)
  83. return ret;
  84. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
  85. div.clk_div - 1);
  86. if (ret < 0)
  87. return ret;
  88. return 0;
  89. }
  90. static struct snd_soc_ops jive_ops = {
  91. .hw_params = jive_hw_params,
  92. };
  93. static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
  94. {
  95. struct snd_soc_codec *codec = rtd->codec;
  96. int err;
  97. /* These endpoints are not being used. */
  98. snd_soc_dapm_nc_pin(codec, "LINPUT2");
  99. snd_soc_dapm_nc_pin(codec, "RINPUT2");
  100. snd_soc_dapm_nc_pin(codec, "LINPUT3");
  101. snd_soc_dapm_nc_pin(codec, "RINPUT3");
  102. snd_soc_dapm_nc_pin(codec, "OUT3");
  103. snd_soc_dapm_nc_pin(codec, "MONO");
  104. /* Add jive specific widgets */
  105. err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
  106. ARRAY_SIZE(wm8750_dapm_widgets));
  107. if (err) {
  108. printk(KERN_ERR "%s: failed to add widgets (%d)\n",
  109. __func__, err);
  110. return err;
  111. }
  112. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  113. snd_soc_dapm_sync(codec);
  114. return 0;
  115. }
  116. static struct snd_soc_dai_link jive_dai = {
  117. .name = "wm8750",
  118. .stream_name = "WM8750",
  119. .cpu_dai_name = "s3c2412-i2s",
  120. .codec_dai_name = "wm8750-hifi",
  121. .platform_name = "s3c24xx-pcm-audio",
  122. .codec_name = "wm8750-codec.0-0x1a",
  123. .init = jive_wm8750_init,
  124. .ops = &jive_ops,
  125. };
  126. /* jive audio machine driver */
  127. static struct snd_soc_card snd_soc_machine_jive = {
  128. .name = "Jive",
  129. .dai_link = &jive_dai,
  130. .num_links = 1,
  131. };
  132. static struct platform_device *jive_snd_device;
  133. static int __init jive_init(void)
  134. {
  135. int ret;
  136. if (!machine_is_jive())
  137. return 0;
  138. printk("JIVE WM8750 Audio support\n");
  139. jive_snd_device = platform_device_alloc("soc-audio", -1);
  140. if (!jive_snd_device)
  141. return -ENOMEM;
  142. platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
  143. ret = platform_device_add(jive_snd_device);
  144. if (ret)
  145. platform_device_put(jive_snd_device);
  146. return ret;
  147. }
  148. static void __exit jive_exit(void)
  149. {
  150. platform_device_unregister(jive_snd_device);
  151. }
  152. module_init(jive_init);
  153. module_exit(jive_exit);
  154. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  155. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  156. MODULE_LICENSE("GPL");