jive_wm8750.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 "s3c24xx-pcm.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_startup(struct snd_pcm_substream *substream)
  41. {
  42. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  43. struct snd_soc_codec *codec = rtd->socdev->codec;
  44. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  45. snd_soc_dapm_enable_pin(codec, "Internal Speaker");
  46. snd_soc_dapm_enable_pin(codec, "Line In");
  47. snd_soc_dapm_sync(codec);
  48. return 0;
  49. }
  50. static int jive_hw_params(struct snd_pcm_substream *substream,
  51. struct snd_pcm_hw_params *params)
  52. {
  53. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  54. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  55. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  56. struct s3c2412_rate_calc div;
  57. unsigned int clk = 0;
  58. int ret = 0;
  59. switch (params_rate(params)) {
  60. case 8000:
  61. case 16000:
  62. case 48000:
  63. case 96000:
  64. clk = 12288000;
  65. break;
  66. case 11025:
  67. case 22050:
  68. case 44100:
  69. clk = 11289600;
  70. break;
  71. }
  72. s3c2412_iis_calc_rate(&div, NULL, params_rate(params),
  73. s3c2412_get_iisclk());
  74. /* set codec DAI configuration */
  75. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  76. SND_SOC_DAIFMT_NB_NF |
  77. SND_SOC_DAIFMT_CBS_CFS);
  78. if (ret < 0)
  79. return ret;
  80. /* set cpu DAI configuration */
  81. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  82. SND_SOC_DAIFMT_NB_NF |
  83. SND_SOC_DAIFMT_CBS_CFS);
  84. if (ret < 0)
  85. return ret;
  86. /* set the codec system clock for DAC and ADC */
  87. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  88. SND_SOC_CLOCK_IN);
  89. if (ret < 0)
  90. return ret;
  91. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
  92. if (ret < 0)
  93. return ret;
  94. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
  95. div.clk_div - 1);
  96. if (ret < 0)
  97. return ret;
  98. return 0;
  99. }
  100. static struct snd_soc_ops jive_ops = {
  101. .startup = jive_startup,
  102. .hw_params = jive_hw_params,
  103. };
  104. static int jive_wm8750_init(struct snd_soc_codec *codec)
  105. {
  106. int err;
  107. /* These endpoints are not being used. */
  108. snd_soc_dapm_disable_pin(codec, "LINPUT2");
  109. snd_soc_dapm_disable_pin(codec, "RINPUT2");
  110. snd_soc_dapm_disable_pin(codec, "LINPUT3");
  111. snd_soc_dapm_disable_pin(codec, "RINPUT3");
  112. snd_soc_dapm_disable_pin(codec, "OUT3");
  113. snd_soc_dapm_disable_pin(codec, "MONO");
  114. /* Add jive specific widgets */
  115. err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
  116. ARRAY_SIZE(wm8750_dapm_widgets));
  117. if (err) {
  118. printk(KERN_ERR "%s: failed to add widgets (%d)\n",
  119. __func__, err);
  120. return err;
  121. }
  122. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  123. snd_soc_dapm_sync(codec);
  124. return 0;
  125. }
  126. static struct snd_soc_dai_link jive_dai = {
  127. .name = "wm8750",
  128. .stream_name = "WM8750",
  129. .cpu_dai = &s3c2412_i2s_dai,
  130. .codec_dai = &wm8750_dai,
  131. .init = jive_wm8750_init,
  132. .ops = &jive_ops,
  133. };
  134. /* jive audio machine driver */
  135. static struct snd_soc_machine snd_soc_machine_jive = {
  136. .name = "Jive",
  137. .dai_link = &jive_dai,
  138. .num_links = 1,
  139. };
  140. /* jive audio private data */
  141. static struct wm8750_setup_data jive_wm8750_setup = {
  142. };
  143. /* jive audio subsystem */
  144. static struct snd_soc_device jive_snd_devdata = {
  145. .machine = &snd_soc_machine_jive,
  146. .platform = &s3c24xx_soc_platform,
  147. .codec_dev = &soc_codec_dev_wm8750_spi,
  148. .codec_data = &jive_wm8750_setup,
  149. };
  150. static struct platform_device *jive_snd_device;
  151. static int __init jive_init(void)
  152. {
  153. int ret;
  154. if (!machine_is_jive())
  155. return 0;
  156. printk("JIVE WM8750 Audio support\n");
  157. jive_snd_device = platform_device_alloc("soc-audio", -1);
  158. if (!jive_snd_device)
  159. return -ENOMEM;
  160. platform_set_drvdata(jive_snd_device, &jive_snd_devdata);
  161. jive_snd_devdata.dev = &jive_snd_device->dev;
  162. ret = platform_device_add(jive_snd_device);
  163. if (ret)
  164. platform_device_put(jive_snd_device);
  165. return ret;
  166. }
  167. static void __exit jive_exit(void)
  168. {
  169. platform_device_unregister(jive_snd_device);
  170. }
  171. module_init(jive_init);
  172. module_exit(jive_exit);
  173. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  174. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  175. MODULE_LICENSE("GPL");