snappercl15.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <sound/soc-dapm.h>
  18. #include <asm/mach-types.h>
  19. #include <mach/hardware.h>
  20. #include "../codecs/tlv320aic23.h"
  21. #include "ep93xx-pcm.h"
  22. #include "ep93xx-i2s.h"
  23. #define CODEC_CLOCK 5644800
  24. static int snappercl15_hw_params(struct snd_pcm_substream *substream,
  25. struct snd_pcm_hw_params *params)
  26. {
  27. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  28. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  29. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  30. int err;
  31. err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  32. SND_SOC_DAIFMT_NB_IF |
  33. SND_SOC_DAIFMT_CBS_CFS);
  34. err = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  35. SND_SOC_DAIFMT_NB_IF |
  36. SND_SOC_DAIFMT_CBS_CFS);
  37. if (err)
  38. return err;
  39. err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
  40. SND_SOC_CLOCK_IN);
  41. if (err)
  42. return err;
  43. err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
  44. SND_SOC_CLOCK_OUT);
  45. if (err)
  46. return err;
  47. return 0;
  48. }
  49. static struct snd_soc_ops snappercl15_ops = {
  50. .hw_params = snappercl15_hw_params,
  51. };
  52. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  53. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  54. SND_SOC_DAPM_LINE("Line In", NULL),
  55. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  56. };
  57. static const struct snd_soc_dapm_route audio_map[] = {
  58. {"Headphone Jack", NULL, "LHPOUT"},
  59. {"Headphone Jack", NULL, "RHPOUT"},
  60. {"LLINEIN", NULL, "Line In"},
  61. {"RLINEIN", NULL, "Line In"},
  62. {"MICIN", NULL, "Mic Jack"},
  63. };
  64. static int snappercl15_tlv320aic23_init(struct snd_soc_codec *codec)
  65. {
  66. snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets,
  67. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  68. snd_soc_dapm_add_routes(codec, 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 = &ep93xx_i2s_dai,
  75. .codec_dai = &tlv320aic23_dai,
  76. .init = snappercl15_tlv320aic23_init,
  77. .ops = &snappercl15_ops,
  78. };
  79. static struct snd_soc_card snd_soc_snappercl15 = {
  80. .name = "Snapper CL15",
  81. .platform = &ep93xx_soc_platform,
  82. .dai_link = &snappercl15_dai,
  83. .num_links = 1,
  84. };
  85. static struct snd_soc_device snappercl15_snd_devdata = {
  86. .card = &snd_soc_snappercl15,
  87. .codec_dev = &soc_codec_dev_tlv320aic23,
  88. };
  89. static struct platform_device *snappercl15_snd_device;
  90. static int __init snappercl15_init(void)
  91. {
  92. int ret;
  93. if (!machine_is_snapper_cl15())
  94. return -ENODEV;
  95. ret = ep93xx_i2s_acquire(EP93XX_SYSCON_DEVCFG_I2SONAC97,
  96. EP93XX_SYSCON_I2SCLKDIV_ORIDE |
  97. EP93XX_SYSCON_I2SCLKDIV_SPOL);
  98. if (ret)
  99. return ret;
  100. snappercl15_snd_device = platform_device_alloc("soc-audio", -1);
  101. if (!snappercl15_snd_device)
  102. return -ENOMEM;
  103. platform_set_drvdata(snappercl15_snd_device, &snappercl15_snd_devdata);
  104. snappercl15_snd_devdata.dev = &snappercl15_snd_device->dev;
  105. ret = platform_device_add(snappercl15_snd_device);
  106. if (ret)
  107. platform_device_put(snappercl15_snd_device);
  108. return ret;
  109. }
  110. static void __exit snappercl15_exit(void)
  111. {
  112. platform_device_unregister(snappercl15_snd_device);
  113. ep93xx_i2s_release();
  114. }
  115. module_init(snappercl15_init);
  116. module_exit(snappercl15_exit);
  117. MODULE_AUTHOR("Ryan Mallon <ryan@bluewatersys.com>");
  118. MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
  119. MODULE_LICENSE("GPL");