arndale_rt5631.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * arndale_rt5631.c
  3. *
  4. * Copyright (c) 2014, Insignal Co., Ltd.
  5. *
  6. * Author: Claude <claude@insginal.co.kr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/clk.h>
  16. #include <sound/soc.h>
  17. #include <sound/soc-dapm.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include "i2s.h"
  21. static int arndale_hw_params(struct snd_pcm_substream *substream,
  22. struct snd_pcm_hw_params *params)
  23. {
  24. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  25. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  26. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  27. int rfs, ret;
  28. unsigned long rclk;
  29. rfs = 256;
  30. rclk = params_rate(params) * rfs;
  31. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
  32. 0, SND_SOC_CLOCK_OUT);
  33. if (ret < 0)
  34. return ret;
  35. ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
  36. 0, SND_SOC_CLOCK_OUT);
  37. if (ret < 0)
  38. return ret;
  39. ret = snd_soc_dai_set_sysclk(codec_dai, 0, rclk, SND_SOC_CLOCK_OUT);
  40. if (ret < 0)
  41. return ret;
  42. return 0;
  43. }
  44. static struct snd_soc_ops arndale_ops = {
  45. .hw_params = arndale_hw_params,
  46. };
  47. static struct snd_soc_dai_link arndale_rt5631_dai[] = {
  48. {
  49. .name = "RT5631 HiFi",
  50. .stream_name = "Primary",
  51. .codec_dai_name = "rt5631-hifi",
  52. .dai_fmt = SND_SOC_DAIFMT_I2S
  53. | SND_SOC_DAIFMT_NB_NF
  54. | SND_SOC_DAIFMT_CBS_CFS,
  55. .ops = &arndale_ops,
  56. },
  57. };
  58. static struct snd_soc_card arndale_rt5631 = {
  59. .name = "Arndale RT5631",
  60. .owner = THIS_MODULE,
  61. .dai_link = arndale_rt5631_dai,
  62. .num_links = ARRAY_SIZE(arndale_rt5631_dai),
  63. };
  64. static int arndale_audio_probe(struct platform_device *pdev)
  65. {
  66. int n, ret;
  67. struct device_node *np = pdev->dev.of_node;
  68. struct snd_soc_card *card = &arndale_rt5631;
  69. card->dev = &pdev->dev;
  70. for (n = 0; np && n < ARRAY_SIZE(arndale_rt5631_dai); n++) {
  71. if (!arndale_rt5631_dai[n].cpu_dai_name) {
  72. arndale_rt5631_dai[n].cpu_of_node = of_parse_phandle(np,
  73. "samsung,audio-cpu", n);
  74. if (!arndale_rt5631_dai[n].cpu_of_node) {
  75. dev_err(&pdev->dev,
  76. "Property 'samsung,audio-cpu' missing or invalid\n");
  77. return -EINVAL;
  78. }
  79. }
  80. if (!arndale_rt5631_dai[n].platform_name)
  81. arndale_rt5631_dai[n].platform_of_node =
  82. arndale_rt5631_dai[n].cpu_of_node;
  83. arndale_rt5631_dai[n].codec_name = NULL;
  84. arndale_rt5631_dai[n].codec_of_node = of_parse_phandle(np,
  85. "samsung,audio-codec", n);
  86. if (!arndale_rt5631_dai[0].codec_of_node) {
  87. dev_err(&pdev->dev,
  88. "Property 'samsung,audio-codec' missing or invalid\n");
  89. return -EINVAL;
  90. }
  91. }
  92. ret = devm_snd_soc_register_card(card->dev, card);
  93. if (ret)
  94. dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
  95. return ret;
  96. }
  97. static const struct of_device_id samsung_arndale_rt5631_of_match[] __maybe_unused = {
  98. { .compatible = "samsung,arndale-rt5631", },
  99. { .compatible = "samsung,arndale-alc5631", },
  100. {},
  101. };
  102. MODULE_DEVICE_TABLE(of, samsung_arndale_rt5631_of_match);
  103. static struct platform_driver arndale_audio_driver = {
  104. .driver = {
  105. .name = "arndale-audio",
  106. .pm = &snd_soc_pm_ops,
  107. .of_match_table = of_match_ptr(samsung_arndale_rt5631_of_match),
  108. },
  109. .probe = arndale_audio_probe,
  110. };
  111. module_platform_driver(arndale_audio_driver);
  112. MODULE_AUTHOR("Claude <claude@insignal.co.kr>");
  113. MODULE_DESCRIPTION("ALSA SoC Driver for Arndale Board");
  114. MODULE_LICENSE("GPL");