kirkwood-t5325.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * kirkwood-t5325.c
  3. *
  4. * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/slab.h>
  16. #include <sound/soc.h>
  17. #include <mach/kirkwood.h>
  18. #include <plat/audio.h>
  19. #include <asm/mach-types.h>
  20. #include "../codecs/alc5623.h"
  21. static int t5325_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 *codec_dai = rtd->codec_dai;
  26. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  27. int ret;
  28. unsigned int freq, fmt;
  29. fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
  30. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  31. if (ret < 0)
  32. return ret;
  33. ret = snd_soc_dai_set_fmt(codec_dai, fmt);
  34. if (ret < 0)
  35. return ret;
  36. freq = params_rate(params) * 256;
  37. return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
  38. }
  39. static struct snd_soc_ops t5325_ops = {
  40. .hw_params = t5325_hw_params,
  41. };
  42. static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = {
  43. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  44. SND_SOC_DAPM_SPK("Speaker", NULL),
  45. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  46. };
  47. static const struct snd_soc_dapm_route t5325_route[] = {
  48. { "Headphone Jack", NULL, "HPL" },
  49. { "Headphone Jack", NULL, "HPR" },
  50. {"Speaker", NULL, "SPKOUT"},
  51. {"Speaker", NULL, "SPKOUTN"},
  52. { "MIC1", NULL, "Mic Jack" },
  53. { "MIC2", NULL, "Mic Jack" },
  54. };
  55. static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)
  56. {
  57. struct snd_soc_codec *codec = rtd->codec;
  58. struct snd_soc_dapm_context *dapm = &codec->dapm;
  59. snd_soc_dapm_new_controls(dapm, t5325_dapm_widgets,
  60. ARRAY_SIZE(t5325_dapm_widgets));
  61. snd_soc_dapm_add_routes(dapm, t5325_route, ARRAY_SIZE(t5325_route));
  62. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  63. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  64. snd_soc_dapm_enable_pin(dapm, "Speaker");
  65. snd_soc_dapm_sync(dapm);
  66. return 0;
  67. }
  68. static struct snd_soc_dai_link t5325_dai[] = {
  69. {
  70. .name = "ALC5621",
  71. .stream_name = "ALC5621 HiFi",
  72. .cpu_dai_name = "kirkwood-i2s",
  73. .platform_name = "kirkwood-pcm-audio",
  74. .codec_dai_name = "alc5621-hifi",
  75. .codec_name = "alc562x-codec.0-001a",
  76. .ops = &t5325_ops,
  77. .init = t5325_dai_init,
  78. },
  79. };
  80. static struct snd_soc_card t5325 = {
  81. .name = "t5325",
  82. .dai_link = t5325_dai,
  83. .num_links = ARRAY_SIZE(t5325_dai),
  84. };
  85. static struct platform_device *t5325_snd_device;
  86. static int __init t5325_init(void)
  87. {
  88. int ret;
  89. if (!machine_is_t5325())
  90. return 0;
  91. t5325_snd_device = platform_device_alloc("soc-audio", -1);
  92. if (!t5325_snd_device)
  93. return -ENOMEM;
  94. platform_set_drvdata(t5325_snd_device,
  95. &t5325);
  96. ret = platform_device_add(t5325_snd_device);
  97. if (ret) {
  98. printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
  99. platform_device_put(t5325_snd_device);
  100. }
  101. return ret;
  102. }
  103. module_init(t5325_init);
  104. static void __exit t5325_exit(void)
  105. {
  106. platform_device_unregister(t5325_snd_device);
  107. }
  108. module_exit(t5325_exit);
  109. MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
  110. MODULE_DESCRIPTION("ALSA SoC t5325 audio client");
  111. MODULE_LICENSE("GPL");