jive_wm8750.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. return 0;
  96. }
  97. static struct snd_soc_dai_link jive_dai = {
  98. .name = "wm8750",
  99. .stream_name = "WM8750",
  100. .cpu_dai_name = "s3c2412-i2s",
  101. .codec_dai_name = "wm8750-hifi",
  102. .platform_name = "samsung-audio",
  103. .codec_name = "wm8750.0-001a",
  104. .init = jive_wm8750_init,
  105. .ops = &jive_ops,
  106. };
  107. /* jive audio machine driver */
  108. static struct snd_soc_card snd_soc_machine_jive = {
  109. .name = "Jive",
  110. .dai_link = &jive_dai,
  111. .num_links = 1,
  112. .dapm_widgtets = wm8750_dapm_widgets,
  113. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  114. .dapm_routes = audio_map,
  115. .num_dapm_routes = ARRAY_SIZE(audio_map),
  116. };
  117. static struct platform_device *jive_snd_device;
  118. static int __init jive_init(void)
  119. {
  120. int ret;
  121. if (!machine_is_jive())
  122. return 0;
  123. printk("JIVE WM8750 Audio support\n");
  124. jive_snd_device = platform_device_alloc("soc-audio", -1);
  125. if (!jive_snd_device)
  126. return -ENOMEM;
  127. platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
  128. ret = platform_device_add(jive_snd_device);
  129. if (ret)
  130. platform_device_put(jive_snd_device);
  131. return ret;
  132. }
  133. static void __exit jive_exit(void)
  134. {
  135. platform_device_unregister(jive_snd_device);
  136. }
  137. module_init(jive_init);
  138. module_exit(jive_exit);
  139. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  140. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  141. MODULE_LICENSE("GPL");