arndale.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Copyright (c) 2014, Insignal Co., Ltd.
  4. //
  5. // Author: Claude <[email protected]>
  6. #include <linux/module.h>
  7. #include <linux/of_device.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/clk.h>
  10. #include <sound/soc.h>
  11. #include <sound/soc-dapm.h>
  12. #include <sound/pcm.h>
  13. #include <sound/pcm_params.h>
  14. #include "../codecs/wm8994.h"
  15. #include "i2s.h"
  16. static int arndale_rt5631_hw_params(struct snd_pcm_substream *substream,
  17. struct snd_pcm_hw_params *params)
  18. {
  19. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  20. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  21. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  22. int rfs, ret;
  23. unsigned long rclk;
  24. rfs = 256;
  25. rclk = params_rate(params) * rfs;
  26. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
  27. 0, SND_SOC_CLOCK_OUT);
  28. if (ret < 0)
  29. return ret;
  30. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
  31. 0, SND_SOC_CLOCK_OUT);
  32. if (ret < 0)
  33. return ret;
  34. ret = snd_soc_dai_set_sysclk(codec_dai, 0, rclk, SND_SOC_CLOCK_OUT);
  35. if (ret < 0)
  36. return ret;
  37. return 0;
  38. }
  39. static const struct snd_soc_ops arndale_rt5631_ops = {
  40. .hw_params = arndale_rt5631_hw_params,
  41. };
  42. static int arndale_wm1811_hw_params(struct snd_pcm_substream *substream,
  43. struct snd_pcm_hw_params *params)
  44. {
  45. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  46. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  47. unsigned int rfs, rclk;
  48. /* Ensure AIF1CLK is >= 3 MHz for optimal performance */
  49. if (params_width(params) == 24)
  50. rfs = 384;
  51. else if (params_rate(params) == 8000 || params_rate(params) == 11025)
  52. rfs = 512;
  53. else
  54. rfs = 256;
  55. rclk = params_rate(params) * rfs;
  56. /*
  57. * We add 1 to the frequency value to ensure proper EPLL setting
  58. * for each audio sampling rate (see epll_24mhz_tbl in drivers/clk/
  59. * samsung/clk-exynos5250.c for list of available EPLL rates).
  60. * The CODEC uses clk API and the value will be rounded hence the MCLK1
  61. * clock's frequency will still be exact multiple of the sample rate.
  62. */
  63. return snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1,
  64. rclk + 1, SND_SOC_CLOCK_IN);
  65. }
  66. static const struct snd_soc_ops arndale_wm1811_ops = {
  67. .hw_params = arndale_wm1811_hw_params,
  68. };
  69. SND_SOC_DAILINK_DEFS(rt5631_hifi,
  70. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  71. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5631-aif1")),
  72. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  73. static struct snd_soc_dai_link arndale_rt5631_dai[] = {
  74. {
  75. .name = "RT5631 HiFi",
  76. .stream_name = "Primary",
  77. .dai_fmt = SND_SOC_DAIFMT_I2S
  78. | SND_SOC_DAIFMT_NB_NF
  79. | SND_SOC_DAIFMT_CBS_CFS,
  80. .ops = &arndale_rt5631_ops,
  81. SND_SOC_DAILINK_REG(rt5631_hifi),
  82. },
  83. };
  84. SND_SOC_DAILINK_DEFS(wm1811_hifi,
  85. DAILINK_COMP_ARRAY(COMP_EMPTY()),
  86. DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8994-aif1")),
  87. DAILINK_COMP_ARRAY(COMP_EMPTY()));
  88. static struct snd_soc_dai_link arndale_wm1811_dai[] = {
  89. {
  90. .name = "WM1811 HiFi",
  91. .stream_name = "Primary",
  92. .dai_fmt = SND_SOC_DAIFMT_I2S
  93. | SND_SOC_DAIFMT_NB_NF
  94. | SND_SOC_DAIFMT_CBM_CFM,
  95. .ops = &arndale_wm1811_ops,
  96. SND_SOC_DAILINK_REG(wm1811_hifi),
  97. },
  98. };
  99. static struct snd_soc_card arndale_rt5631 = {
  100. .name = "Arndale RT5631",
  101. .owner = THIS_MODULE,
  102. .dai_link = arndale_rt5631_dai,
  103. .num_links = ARRAY_SIZE(arndale_rt5631_dai),
  104. };
  105. static struct snd_soc_card arndale_wm1811 = {
  106. .name = "Arndale WM1811",
  107. .owner = THIS_MODULE,
  108. .dai_link = arndale_wm1811_dai,
  109. .num_links = ARRAY_SIZE(arndale_wm1811_dai),
  110. };
  111. static void arndale_put_of_nodes(struct snd_soc_card *card)
  112. {
  113. struct snd_soc_dai_link *dai_link;
  114. int i;
  115. for_each_card_prelinks(card, i, dai_link) {
  116. of_node_put(dai_link->cpus->of_node);
  117. of_node_put(dai_link->codecs->of_node);
  118. }
  119. }
  120. static int arndale_audio_probe(struct platform_device *pdev)
  121. {
  122. struct device_node *np = pdev->dev.of_node;
  123. struct snd_soc_card *card;
  124. struct snd_soc_dai_link *dai_link;
  125. int ret;
  126. card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
  127. card->dev = &pdev->dev;
  128. dai_link = card->dai_link;
  129. dai_link->cpus->of_node = of_parse_phandle(np, "samsung,audio-cpu", 0);
  130. if (!dai_link->cpus->of_node) {
  131. dev_err(&pdev->dev,
  132. "Property 'samsung,audio-cpu' missing or invalid\n");
  133. return -EINVAL;
  134. }
  135. if (!dai_link->platforms->name)
  136. dai_link->platforms->of_node = dai_link->cpus->of_node;
  137. dai_link->codecs->of_node = of_parse_phandle(np, "samsung,audio-codec", 0);
  138. if (!dai_link->codecs->of_node) {
  139. dev_err(&pdev->dev,
  140. "Property 'samsung,audio-codec' missing or invalid\n");
  141. ret = -EINVAL;
  142. goto err_put_of_nodes;
  143. }
  144. ret = devm_snd_soc_register_card(card->dev, card);
  145. if (ret) {
  146. dev_err_probe(&pdev->dev, ret,
  147. "snd_soc_register_card() failed\n");
  148. goto err_put_of_nodes;
  149. }
  150. return 0;
  151. err_put_of_nodes:
  152. arndale_put_of_nodes(card);
  153. return ret;
  154. }
  155. static int arndale_audio_remove(struct platform_device *pdev)
  156. {
  157. struct snd_soc_card *card = platform_get_drvdata(pdev);
  158. arndale_put_of_nodes(card);
  159. return 0;
  160. }
  161. static const struct of_device_id arndale_audio_of_match[] = {
  162. { .compatible = "samsung,arndale-rt5631", .data = &arndale_rt5631 },
  163. { .compatible = "samsung,arndale-alc5631", .data = &arndale_rt5631 },
  164. { .compatible = "samsung,arndale-wm1811", .data = &arndale_wm1811 },
  165. {},
  166. };
  167. MODULE_DEVICE_TABLE(of, arndale_audio_of_match);
  168. static struct platform_driver arndale_audio_driver = {
  169. .driver = {
  170. .name = "arndale-audio",
  171. .pm = &snd_soc_pm_ops,
  172. .of_match_table = arndale_audio_of_match,
  173. },
  174. .probe = arndale_audio_probe,
  175. .remove = arndale_audio_remove,
  176. };
  177. module_platform_driver(arndale_audio_driver);
  178. MODULE_AUTHOR("Claude <[email protected]>");
  179. MODULE_DESCRIPTION("ALSA SoC Driver for Arndale Board");
  180. MODULE_LICENSE("GPL");