jive_wm8750.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 the codec system clock for DAC and ADC */
  56. ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
  57. SND_SOC_CLOCK_IN);
  58. if (ret < 0)
  59. return ret;
  60. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
  61. if (ret < 0)
  62. return ret;
  63. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
  64. div.clk_div - 1);
  65. if (ret < 0)
  66. return ret;
  67. return 0;
  68. }
  69. static struct snd_soc_ops jive_ops = {
  70. .hw_params = jive_hw_params,
  71. };
  72. static struct snd_soc_dai_link jive_dai = {
  73. .name = "wm8750",
  74. .stream_name = "WM8750",
  75. .cpu_dai_name = "s3c2412-i2s",
  76. .codec_dai_name = "wm8750-hifi",
  77. .platform_name = "s3c2412-i2s",
  78. .codec_name = "wm8750.0-001a",
  79. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  80. SND_SOC_DAIFMT_CBS_CFS,
  81. .ops = &jive_ops,
  82. };
  83. /* jive audio machine driver */
  84. static struct snd_soc_card snd_soc_machine_jive = {
  85. .name = "Jive",
  86. .owner = THIS_MODULE,
  87. .dai_link = &jive_dai,
  88. .num_links = 1,
  89. .dapm_widgets = wm8750_dapm_widgets,
  90. .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
  91. .dapm_routes = audio_map,
  92. .num_dapm_routes = ARRAY_SIZE(audio_map),
  93. .fully_routed = true,
  94. };
  95. static struct platform_device *jive_snd_device;
  96. static int __init jive_init(void)
  97. {
  98. int ret;
  99. if (!machine_is_jive())
  100. return 0;
  101. printk("JIVE WM8750 Audio support\n");
  102. jive_snd_device = platform_device_alloc("soc-audio", -1);
  103. if (!jive_snd_device)
  104. return -ENOMEM;
  105. platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
  106. ret = platform_device_add(jive_snd_device);
  107. if (ret)
  108. platform_device_put(jive_snd_device);
  109. return ret;
  110. }
  111. static void __exit jive_exit(void)
  112. {
  113. platform_device_unregister(jive_snd_device);
  114. }
  115. module_init(jive_init);
  116. module_exit(jive_exit);
  117. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  118. MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
  119. MODULE_LICENSE("GPL");