jive_wm8750.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_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->dai->codec_dai;
  45. struct snd_soc_dai *cpu_dai = rtd->dai->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. s3c2412_get_iisclk());
  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_codec *codec)
  94. {
  95. int err;
  96. /* These endpoints are not being used. */
  97. snd_soc_dapm_nc_pin(codec, "LINPUT2");
  98. snd_soc_dapm_nc_pin(codec, "RINPUT2");
  99. snd_soc_dapm_nc_pin(codec, "LINPUT3");
  100. snd_soc_dapm_nc_pin(codec, "RINPUT3");
  101. snd_soc_dapm_nc_pin(codec, "OUT3");
  102. snd_soc_dapm_nc_pin(codec, "MONO");
  103. /* Add jive specific widgets */
  104. err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
  105. ARRAY_SIZE(wm8750_dapm_widgets));
  106. if (err) {
  107. printk(KERN_ERR "%s: failed to add widgets (%d)\n",
  108. __func__, err);
  109. return err;
  110. }
  111. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  112. snd_soc_dapm_sync(codec);
  113. return 0;
  114. }
  115. static struct snd_soc_dai_link jive_dai = {
  116. .name = "wm8750",
  117. .stream_name = "WM8750",
  118. .cpu_dai = &s3c2412_i2s_dai,
  119. .codec_dai = &wm8750_dai,
  120. .init = jive_wm8750_init,
  121. .ops = &jive_ops,
  122. };
  123. /* jive audio machine driver */
  124. static struct snd_soc_card snd_soc_machine_jive = {
  125. .name = "Jive",
  126. .platform = &s3c24xx_soc_platform,
  127. .dai_link = &jive_dai,
  128. .num_links = 1,
  129. };
  130. /* jive audio private data */
  131. static struct wm8750_setup_data jive_wm8750_setup = {
  132. };
  133. /* jive audio subsystem */
  134. static struct snd_soc_device jive_snd_devdata = {
  135. .card = &snd_soc_machine_jive,
  136. .codec_dev = &soc_codec_dev_wm8750,
  137. .codec_data = &jive_wm8750_setup,
  138. };
  139. static struct platform_device *jive_snd_device;
  140. static int __init jive_init(void)
  141. {
  142. int ret;
  143. if (!machine_is_jive())
  144. return 0;
  145. printk("JIVE WM8750 Audio support\n");
  146. jive_snd_device = platform_device_alloc("soc-audio", -1);
  147. if (!jive_snd_device)
  148. return -ENOMEM;
  149. platform_set_drvdata(jive_snd_device, &jive_snd_devdata);
  150. jive_snd_devdata.dev = &jive_snd_device->dev;
  151. ret = platform_device_add(jive_snd_device);
  152. if (ret)
  153. platform_device_put(jive_snd_device);
  154. return ret;
  155. }
  156. static void __exit jive_exit(void)
  157. {
  158. platform_device_unregister(jive_snd_device);
  159. }
  160. module_init(jive_init);
  161. module_exit(jive_exit);
  162. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  163. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  164. MODULE_LICENSE("GPL");