qi_lb60.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * You should have received a copy of the GNU General Public License along
  9. * with this program; if not, write to the Free Software Foundation, Inc.,
  10. * 675 Mass Ave, Cambridge, MA 02139, USA.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/timer.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/platform_device.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/soc.h>
  21. #include <sound/soc-dapm.h>
  22. #include <linux/gpio.h>
  23. #include "../codecs/jz4740.h"
  24. #include "jz4740-pcm.h"
  25. #include "jz4740-i2s.h"
  26. #define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
  27. #define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
  28. static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
  29. struct snd_kcontrol *ctrl, int event)
  30. {
  31. int on = 0;
  32. if (event & SND_SOC_DAPM_POST_PMU)
  33. on = 1;
  34. else if (event & SND_SOC_DAPM_PRE_PMD)
  35. on = 0;
  36. gpio_set_value(QI_LB60_SND_GPIO, on);
  37. gpio_set_value(QI_LB60_AMP_GPIO, on);
  38. return 0;
  39. }
  40. static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
  41. SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
  42. SND_SOC_DAPM_MIC("Mic", NULL),
  43. };
  44. static const struct snd_soc_dapm_route qi_lb60_routes[] = {
  45. {"Mic", NULL, "MIC"},
  46. {"Speaker", NULL, "LOUT"},
  47. {"Speaker", NULL, "ROUT"},
  48. };
  49. #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
  50. SND_SOC_DAIFMT_NB_NF | \
  51. SND_SOC_DAIFMT_CBM_CFM)
  52. static int qi_lb60_codec_init(struct snd_soc_codec *codec)
  53. {
  54. int ret;
  55. struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai;
  56. snd_soc_dapm_nc_pin(codec, "LIN");
  57. snd_soc_dapm_nc_pin(codec, "RIN");
  58. ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
  59. if (ret < 0) {
  60. dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
  61. return ret;
  62. }
  63. snd_soc_dapm_new_controls(codec, qi_lb60_widgets, ARRAY_SIZE(qi_lb60_widgets));
  64. snd_soc_dapm_add_routes(codec, qi_lb60_routes, ARRAY_SIZE(qi_lb60_routes));
  65. snd_soc_dapm_sync(codec);
  66. return 0;
  67. }
  68. static struct snd_soc_dai_link qi_lb60_dai = {
  69. .name = "jz4740",
  70. .stream_name = "jz4740",
  71. .cpu_dai = &jz4740_i2s_dai,
  72. .codec_dai = &jz4740_codec_dai,
  73. .init = qi_lb60_codec_init,
  74. };
  75. static struct snd_soc_card qi_lb60 = {
  76. .name = "QI LB60",
  77. .dai_link = &qi_lb60_dai,
  78. .num_links = 1,
  79. .platform = &jz4740_soc_platform,
  80. };
  81. static struct snd_soc_device qi_lb60_snd_devdata = {
  82. .card = &qi_lb60,
  83. .codec_dev = &soc_codec_dev_jz4740_codec,
  84. };
  85. static struct platform_device *qi_lb60_snd_device;
  86. static int __init qi_lb60_init(void)
  87. {
  88. int ret;
  89. qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
  90. if (!qi_lb60_snd_device)
  91. return -ENOMEM;
  92. ret = gpio_request(QI_LB60_SND_GPIO, "SND");
  93. if (ret) {
  94. pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
  95. QI_LB60_SND_GPIO, ret);
  96. goto err_device_put;
  97. }
  98. ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
  99. if (ret) {
  100. pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
  101. QI_LB60_AMP_GPIO, ret);
  102. goto err_gpio_free_snd;
  103. }
  104. gpio_direction_output(QI_LB60_SND_GPIO, 0);
  105. gpio_direction_output(QI_LB60_AMP_GPIO, 0);
  106. platform_set_drvdata(qi_lb60_snd_device, &qi_lb60_snd_devdata);
  107. qi_lb60_snd_devdata.dev = &qi_lb60_snd_device->dev;
  108. ret = platform_device_add(qi_lb60_snd_device);
  109. if (ret) {
  110. pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
  111. goto err_unset_pdata;
  112. }
  113. return 0;
  114. err_unset_pdata:
  115. platform_set_drvdata(qi_lb60_snd_device, NULL);
  116. /*err_gpio_free_amp:*/
  117. gpio_free(QI_LB60_AMP_GPIO);
  118. err_gpio_free_snd:
  119. gpio_free(QI_LB60_SND_GPIO);
  120. err_device_put:
  121. platform_device_put(qi_lb60_snd_device);
  122. return ret;
  123. }
  124. module_init(qi_lb60_init);
  125. static void __exit qi_lb60_exit(void)
  126. {
  127. gpio_free(QI_LB60_AMP_GPIO);
  128. gpio_free(QI_LB60_SND_GPIO);
  129. platform_device_unregister(qi_lb60_snd_device);
  130. }
  131. module_exit(qi_lb60_exit);
  132. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  133. MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
  134. MODULE_LICENSE("GPL v2");