snappercl15.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module
  3. *
  4. * Copyright (C) 2008 Bluewater Systems Ltd
  5. * Author: Ryan Mallon <ryan@bluewatersys.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/platform_device.h>
  14. #include <sound/core.h>
  15. #include <sound/pcm.h>
  16. #include <sound/soc.h>
  17. #include <asm/mach-types.h>
  18. #include <mach/hardware.h>
  19. #include "../codecs/tlv320aic23.h"
  20. #include "ep93xx-pcm.h"
  21. #define CODEC_CLOCK 5644800
  22. static int snappercl15_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 err;
  29. err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  30. SND_SOC_DAIFMT_NB_IF |
  31. SND_SOC_DAIFMT_CBS_CFS);
  32. err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  33. SND_SOC_DAIFMT_NB_IF |
  34. SND_SOC_DAIFMT_CBS_CFS);
  35. if (err)
  36. return err;
  37. err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
  38. SND_SOC_CLOCK_IN);
  39. if (err)
  40. return err;
  41. err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
  42. SND_SOC_CLOCK_OUT);
  43. if (err)
  44. return err;
  45. return 0;
  46. }
  47. static struct snd_soc_ops snappercl15_ops = {
  48. .hw_params = snappercl15_hw_params,
  49. };
  50. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  51. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  52. SND_SOC_DAPM_LINE("Line In", NULL),
  53. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  54. };
  55. static const struct snd_soc_dapm_route audio_map[] = {
  56. {"Headphone Jack", NULL, "LHPOUT"},
  57. {"Headphone Jack", NULL, "RHPOUT"},
  58. {"LLINEIN", NULL, "Line In"},
  59. {"RLINEIN", NULL, "Line In"},
  60. {"MICIN", NULL, "Mic Jack"},
  61. };
  62. static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
  63. {
  64. struct snd_soc_codec *codec = rtd->codec;
  65. struct snd_soc_dapm_context *dapm = &codec->dapm;
  66. snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
  67. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  68. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  69. return 0;
  70. }
  71. static struct snd_soc_dai_link snappercl15_dai = {
  72. .name = "tlv320aic23",
  73. .stream_name = "AIC23",
  74. .cpu_dai_name = "ep93xx-i2s",
  75. .codec_dai_name = "tlv320aic23-hifi",
  76. .codec_name = "tlv320aic23-codec.0-001a",
  77. .platform_name = "ep93xx-pcm-audio",
  78. .init = snappercl15_tlv320aic23_init,
  79. .ops = &snappercl15_ops,
  80. };
  81. static struct snd_soc_card snd_soc_snappercl15 = {
  82. .name = "Snapper CL15",
  83. .dai_link = &snappercl15_dai,
  84. .num_links = 1,
  85. };
  86. static struct platform_device *snappercl15_snd_device;
  87. static int __init snappercl15_init(void)
  88. {
  89. int ret;
  90. if (!machine_is_snapper_cl15())
  91. return -ENODEV;
  92. ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
  93. EP93XX_SYSCON_I2SCLKDIV_ORIDE |
  94. EP93XX_SYSCON_I2SCLKDIV_SPOL);
  95. if (ret)
  96. return ret;
  97. snappercl15_snd_device = platform_device_alloc("soc-audio", -1);
  98. if (!snappercl15_snd_device)
  99. return -ENOMEM;
  100. platform_set_drvdata(snappercl15_snd_device, &snd_soc_snappercl15);
  101. ret = platform_device_add(snappercl15_snd_device);
  102. if (ret)
  103. platform_device_put(snappercl15_snd_device);
  104. return ret;
  105. }
  106. static void __exit snappercl15_exit(void)
  107. {
  108. platform_device_unregister(snappercl15_snd_device);
  109. ep93xx_i2s_release();
  110. }
  111. module_init(snappercl15_init);
  112. module_exit(snappercl15_exit);
  113. MODULE_AUTHOR("Ryan Mallon <ryan@bluewatersys.com>");
  114. MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
  115. MODULE_LICENSE("GPL");