qi_lb60.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 <linux/gpio.h>
  22. #define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
  23. #define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
  24. static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
  25. struct snd_kcontrol *ctrl, int event)
  26. {
  27. int on = 0;
  28. if (event & SND_SOC_DAPM_POST_PMU)
  29. on = 1;
  30. else if (event & SND_SOC_DAPM_PRE_PMD)
  31. on = 0;
  32. gpio_set_value(QI_LB60_SND_GPIO, on);
  33. gpio_set_value(QI_LB60_AMP_GPIO, on);
  34. return 0;
  35. }
  36. static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
  37. SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
  38. SND_SOC_DAPM_MIC("Mic", NULL),
  39. };
  40. static const struct snd_soc_dapm_route qi_lb60_routes[] = {
  41. {"Mic", NULL, "MIC"},
  42. {"Speaker", NULL, "LOUT"},
  43. {"Speaker", NULL, "ROUT"},
  44. };
  45. #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
  46. SND_SOC_DAIFMT_NB_NF | \
  47. SND_SOC_DAIFMT_CBM_CFM)
  48. static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
  49. {
  50. struct snd_soc_codec *codec = rtd->codec;
  51. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  52. struct snd_soc_dapm_context *dapm = &codec->dapm;
  53. int ret;
  54. snd_soc_dapm_nc_pin(dapm, "LIN");
  55. snd_soc_dapm_nc_pin(dapm, "RIN");
  56. ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
  57. if (ret < 0) {
  58. dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
  59. return ret;
  60. }
  61. snd_soc_dapm_new_controls(dapm, qi_lb60_widgets,
  62. ARRAY_SIZE(qi_lb60_widgets));
  63. snd_soc_dapm_add_routes(dapm, qi_lb60_routes,
  64. ARRAY_SIZE(qi_lb60_routes));
  65. snd_soc_dapm_sync(dapm);
  66. return 0;
  67. }
  68. static struct snd_soc_dai_link qi_lb60_dai = {
  69. .name = "jz4740",
  70. .stream_name = "jz4740",
  71. .cpu_dai_name = "jz4740-i2s",
  72. .platform_name = "jz4740-pcm-audio",
  73. .codec_dai_name = "jz4740-hifi",
  74. .codec_name = "jz4740-codec",
  75. .init = qi_lb60_codec_init,
  76. };
  77. static struct snd_soc_card qi_lb60 = {
  78. .name = "QI LB60",
  79. .dai_link = &qi_lb60_dai,
  80. .num_links = 1,
  81. };
  82. static struct platform_device *qi_lb60_snd_device;
  83. static int __init qi_lb60_init(void)
  84. {
  85. int ret;
  86. qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
  87. if (!qi_lb60_snd_device)
  88. return -ENOMEM;
  89. ret = gpio_request(QI_LB60_SND_GPIO, "SND");
  90. if (ret) {
  91. pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
  92. QI_LB60_SND_GPIO, ret);
  93. goto err_device_put;
  94. }
  95. ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
  96. if (ret) {
  97. pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
  98. QI_LB60_AMP_GPIO, ret);
  99. goto err_gpio_free_snd;
  100. }
  101. gpio_direction_output(QI_LB60_SND_GPIO, 0);
  102. gpio_direction_output(QI_LB60_AMP_GPIO, 0);
  103. platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
  104. ret = platform_device_add(qi_lb60_snd_device);
  105. if (ret) {
  106. pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
  107. goto err_unset_pdata;
  108. }
  109. return 0;
  110. err_unset_pdata:
  111. platform_set_drvdata(qi_lb60_snd_device, NULL);
  112. /*err_gpio_free_amp:*/
  113. gpio_free(QI_LB60_AMP_GPIO);
  114. err_gpio_free_snd:
  115. gpio_free(QI_LB60_SND_GPIO);
  116. err_device_put:
  117. platform_device_put(qi_lb60_snd_device);
  118. return ret;
  119. }
  120. module_init(qi_lb60_init);
  121. static void __exit qi_lb60_exit(void)
  122. {
  123. gpio_free(QI_LB60_AMP_GPIO);
  124. gpio_free(QI_LB60_SND_GPIO);
  125. platform_device_unregister(qi_lb60_snd_device);
  126. }
  127. module_exit(qi_lb60_exit);
  128. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  129. MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
  130. MODULE_LICENSE("GPL v2");