jive_wm8750.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0
  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. #include <linux/module.h>
  9. #include <sound/soc.h>
  10. #include <asm/mach-types.h>
  11. #include "s3c2412-i2s.h"
  12. #include "../codecs/wm8750.h"
  13. static const struct snd_soc_dapm_route audio_map[] = {
  14. { "Headphone Jack", NULL, "LOUT1" },
  15. { "Headphone Jack", NULL, "ROUT1" },
  16. { "Internal Speaker", NULL, "LOUT2" },
  17. { "Internal Speaker", NULL, "ROUT2" },
  18. { "LINPUT1", NULL, "Line Input" },
  19. { "RINPUT1", NULL, "Line Input" },
  20. };
  21. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  22. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  23. SND_SOC_DAPM_SPK("Internal Speaker", NULL),
  24. SND_SOC_DAPM_LINE("Line In", NULL),
  25. };
  26. static int jive_hw_params(struct snd_pcm_substream *substream,
  27. struct snd_pcm_hw_params *params)
  28. {
  29. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  30. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  31. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  32. struct s3c_i2sv2_rate_calc div;
  33. unsigned int clk = 0;
  34. int ret = 0;
  35. switch (params_rate(params)) {
  36. case 8000:
  37. case 16000:
  38. case 48000:
  39. case 96000:
  40. clk = 12288000;
  41. break;
  42. case 11025:
  43. case 22050:
  44. case 44100:
  45. clk = 11289600;
  46. break;
  47. }
  48. s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
  49. s3c_i2sv2_get_clock(cpu_dai));
  50. /* set the codec system clock for DAC and ADC */
  51. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  52. SND_SOC_CLOCK_IN);
  53. if (ret < 0)
  54. return ret;
  55. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
  56. if (ret < 0)
  57. return ret;
  58. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
  59. div.clk_div - 1);
  60. if (ret < 0)
  61. return ret;
  62. return 0;
  63. }
  64. static const struct snd_soc_ops jive_ops = {
  65. .hw_params = jive_hw_params,
  66. };
  67. SND_SOC_DAILINK_DEFS(wm8750,
  68. DAILINK_COMP_ARRAY(COMP_CPU("s3c2412-i2s")),
  69. DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-001a", "wm8750-hifi")),
  70. DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c2412-i2s")));
  71. static struct snd_soc_dai_link jive_dai = {
  72. .name = "wm8750",
  73. .stream_name = "WM8750",
  74. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  75. SND_SOC_DAIFMT_CBS_CFS,
  76. .ops = &jive_ops,
  77. SND_SOC_DAILINK_REG(wm8750),
  78. };
  79. /* jive audio machine driver */
  80. static struct snd_soc_card snd_soc_machine_jive = {
  81. .name = "Jive",
  82. .owner = THIS_MODULE,
  83. .dai_link = &jive_dai,
  84. .num_links = 1,
  85. .dapm_widgets = wm8750_dapm_widgets,
  86. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  87. .dapm_routes = audio_map,
  88. .num_dapm_routes = ARRAY_SIZE(audio_map),
  89. .fully_routed = true,
  90. };
  91. static struct platform_device *jive_snd_device;
  92. static int __init jive_init(void)
  93. {
  94. int ret;
  95. if (!machine_is_jive())
  96. return 0;
  97. printk("JIVE WM8750 Audio support\n");
  98. jive_snd_device = platform_device_alloc("soc-audio", -1);
  99. if (!jive_snd_device)
  100. return -ENOMEM;
  101. platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
  102. ret = platform_device_add(jive_snd_device);
  103. if (ret)
  104. platform_device_put(jive_snd_device);
  105. return ret;
  106. }
  107. static void __exit jive_exit(void)
  108. {
  109. platform_device_unregister(jive_snd_device);
  110. }
  111. module_init(jive_init);
  112. module_exit(jive_exit);
  113. MODULE_AUTHOR("Ben Dooks <[email protected]>");
  114. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  115. MODULE_LICENSE("GPL");