kirkwood-t5325.c 3.4 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 <sound/soc-dapm.h>
  18. #include <mach/kirkwood.h>
  19. #include <plat/audio.h>
  20. #include <asm/mach-types.h>
  21. #include "../codecs/alc5623.h"
  22. static int t5325_hw_params(struct snd_pcm_substream *substream,
  23. struct snd_pcm_hw_params *params)
  24. {
  25. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  26. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  27. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  28. int ret;
  29. unsigned int freq, fmt;
  30. fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
  31. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  32. if (ret < 0)
  33. return ret;
  34. ret = snd_soc_dai_set_fmt(codec_dai, fmt);
  35. if (ret < 0)
  36. return ret;
  37. freq = params_rate(params) * 256;
  38. return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
  39. }
  40. static struct snd_soc_ops t5325_ops = {
  41. .hw_params = t5325_hw_params,
  42. };
  43. static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = {
  44. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  45. SND_SOC_DAPM_SPK("Speaker", NULL),
  46. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  47. };
  48. static const struct snd_soc_dapm_route t5325_route[] = {
  49. { "Headphone Jack", NULL, "HPL" },
  50. { "Headphone Jack", NULL, "HPR" },
  51. {"Speaker", NULL, "SPKOUT"},
  52. {"Speaker", NULL, "SPKOUTN"},
  53. { "MIC1", NULL, "Mic Jack" },
  54. { "MIC2", NULL, "Mic Jack" },
  55. };
  56. static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)
  57. {
  58. struct snd_soc_codec *codec = rtd->codec;
  59. struct snd_soc_dapm_context *dapm = &codec->dapm;
  60. snd_soc_dapm_new_controls(dapm, t5325_dapm_widgets,
  61. ARRAY_SIZE(t5325_dapm_widgets));
  62. snd_soc_dapm_add_routes(dapm, t5325_route, ARRAY_SIZE(t5325_route));
  63. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  64. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  65. snd_soc_dapm_enable_pin(dapm, "Speaker");
  66. snd_soc_dapm_sync(dapm);
  67. return 0;
  68. }
  69. static struct snd_soc_dai_link t5325_dai[] = {
  70. {
  71. .name = "ALC5621",
  72. .stream_name = "ALC5621 HiFi",
  73. .cpu_dai_name = "kirkwood-i2s",
  74. .platform_name = "kirkwood-pcm-audio",
  75. .codec_dai_name = "alc5621-hifi",
  76. .codec_name = "alc562x-codec.0-001a",
  77. .ops = &t5325_ops,
  78. .init = t5325_dai_init,
  79. },
  80. };
  81. static struct snd_soc_card t5325 = {
  82. .name = "t5325",
  83. .dai_link = t5325_dai,
  84. .num_links = ARRAY_SIZE(t5325_dai),
  85. };
  86. static struct platform_device *t5325_snd_device;
  87. static int __init t5325_init(void)
  88. {
  89. int ret;
  90. if (!machine_is_t5325())
  91. return 0;
  92. t5325_snd_device = platform_device_alloc("soc-audio", -1);
  93. if (!t5325_snd_device)
  94. return -ENOMEM;
  95. platform_set_drvdata(t5325_snd_device,
  96. &t5325);
  97. ret = platform_device_add(t5325_snd_device);
  98. if (ret) {
  99. printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
  100. platform_device_put(t5325_snd_device);
  101. }
  102. return ret;
  103. }
  104. module_init(t5325_init);
  105. static void __exit t5325_exit(void)
  106. {
  107. platform_device_unregister(t5325_snd_device);
  108. }
  109. module_exit(t5325_exit);
  110. MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
  111. MODULE_DESCRIPTION("ALSA SoC t5325 audio client");
  112. MODULE_LICENSE("GPL");