jive_wm8750.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 <linux/module.h>
  14. #include <sound/soc.h>
  15. #include <asm/mach-types.h>
  16. #include "s3c2412-i2s.h"
  17. #include "../codecs/wm8750.h"
  18. static const struct snd_soc_dapm_route audio_map[] = {
  19. { "Headphone Jack", NULL, "LOUT1" },
  20. { "Headphone Jack", NULL, "ROUT1" },
  21. { "Internal Speaker", NULL, "LOUT2" },
  22. { "Internal Speaker", NULL, "ROUT2" },
  23. { "LINPUT1", NULL, "Line Input" },
  24. { "RINPUT1", NULL, "Line Input" },
  25. };
  26. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  27. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  28. SND_SOC_DAPM_SPK("Internal Speaker", NULL),
  29. SND_SOC_DAPM_LINE("Line In", NULL),
  30. };
  31. static int jive_hw_params(struct snd_pcm_substream *substream,
  32. struct snd_pcm_hw_params *params)
  33. {
  34. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  35. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  36. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  37. struct s3c_i2sv2_rate_calc div;
  38. unsigned int clk = 0;
  39. int ret = 0;
  40. switch (params_rate(params)) {
  41. case 8000:
  42. case 16000:
  43. case 48000:
  44. case 96000:
  45. clk = 12288000;
  46. break;
  47. case 11025:
  48. case 22050:
  49. case 44100:
  50. clk = 11289600;
  51. break;
  52. }
  53. s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
  54. s3c_i2sv2_get_clock(cpu_dai));
  55. /* set codec DAI configuration */
  56. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  57. SND_SOC_DAIFMT_NB_NF |
  58. SND_SOC_DAIFMT_CBS_CFS);
  59. if (ret < 0)
  60. return ret;
  61. /* set cpu DAI configuration */
  62. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  63. SND_SOC_DAIFMT_NB_NF |
  64. SND_SOC_DAIFMT_CBS_CFS);
  65. if (ret < 0)
  66. return ret;
  67. /* set the codec system clock for DAC and ADC */
  68. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  69. SND_SOC_CLOCK_IN);
  70. if (ret < 0)
  71. return ret;
  72. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
  73. if (ret < 0)
  74. return ret;
  75. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
  76. div.clk_div - 1);
  77. if (ret < 0)
  78. return ret;
  79. return 0;
  80. }
  81. static struct snd_soc_ops jive_ops = {
  82. .hw_params = jive_hw_params,
  83. };
  84. static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
  85. {
  86. struct snd_soc_codec *codec = rtd->codec;
  87. struct snd_soc_dapm_context *dapm = &codec->dapm;
  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. .owner = THIS_MODULE,
  111. .dai_link = &jive_dai,
  112. .num_links = 1,
  113. .dapm_widgets = wm8750_dapm_widgets,
  114. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  115. .dapm_routes = audio_map,
  116. .num_dapm_routes = ARRAY_SIZE(audio_map),
  117. };
  118. static struct platform_device *jive_snd_device;
  119. static int __init jive_init(void)
  120. {
  121. int ret;
  122. if (!machine_is_jive())
  123. return 0;
  124. printk("JIVE WM8750 Audio support\n");
  125. jive_snd_device = platform_device_alloc("soc-audio", -1);
  126. if (!jive_snd_device)
  127. return -ENOMEM;
  128. platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
  129. ret = platform_device_add(jive_snd_device);
  130. if (ret)
  131. platform_device_put(jive_snd_device);
  132. return ret;
  133. }
  134. static void __exit jive_exit(void)
  135. {
  136. platform_device_unregister(jive_snd_device);
  137. }
  138. module_init(jive_init);
  139. module_exit(jive_exit);
  140. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  141. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  142. MODULE_LICENSE("GPL");