jive_wm8750.c 4.2 KB

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