qi_lb60.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 = !SND_SOC_DAPM_EVENT_OFF(event);
  28. gpio_set_value(QI_LB60_SND_GPIO, on);
  29. gpio_set_value(QI_LB60_AMP_GPIO, on);
  30. return 0;
  31. }
  32. static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
  33. SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
  34. SND_SOC_DAPM_MIC("Mic", NULL),
  35. };
  36. static const struct snd_soc_dapm_route qi_lb60_routes[] = {
  37. {"Mic", NULL, "MIC"},
  38. {"Speaker", NULL, "LOUT"},
  39. {"Speaker", NULL, "ROUT"},
  40. };
  41. #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
  42. SND_SOC_DAIFMT_NB_NF | \
  43. SND_SOC_DAIFMT_CBM_CFM)
  44. static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
  45. {
  46. struct snd_soc_codec *codec = rtd->codec;
  47. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  48. struct snd_soc_dapm_context *dapm = &codec->dapm;
  49. int ret;
  50. snd_soc_dapm_nc_pin(dapm, "LIN");
  51. snd_soc_dapm_nc_pin(dapm, "RIN");
  52. ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
  53. if (ret < 0) {
  54. dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
  55. return ret;
  56. }
  57. return 0;
  58. }
  59. static struct snd_soc_dai_link qi_lb60_dai = {
  60. .name = "jz4740",
  61. .stream_name = "jz4740",
  62. .cpu_dai_name = "jz4740-i2s",
  63. .platform_name = "jz4740-pcm-audio",
  64. .codec_dai_name = "jz4740-hifi",
  65. .codec_name = "jz4740-codec",
  66. .init = qi_lb60_codec_init,
  67. };
  68. static struct snd_soc_card qi_lb60 = {
  69. .name = "QI LB60",
  70. .owner = THIS_MODULE,
  71. .dai_link = &qi_lb60_dai,
  72. .num_links = 1,
  73. .dapm_widgets = qi_lb60_widgets,
  74. .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
  75. .dapm_routes = qi_lb60_routes,
  76. .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
  77. };
  78. static const struct gpio qi_lb60_gpios[] = {
  79. { QI_LB60_SND_GPIO, GPIOF_OUT_INIT_LOW, "SND" },
  80. { QI_LB60_AMP_GPIO, GPIOF_OUT_INIT_LOW, "AMP" },
  81. };
  82. static int __devinit qi_lb60_probe(struct platform_device *pdev)
  83. {
  84. struct snd_soc_card *card = &qi_lb60;
  85. int ret;
  86. ret = gpio_request_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
  87. if (ret)
  88. return ret;
  89. card->dev = &pdev->dev;
  90. ret = snd_soc_register_card(card);
  91. if (ret) {
  92. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  93. ret);
  94. gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
  95. }
  96. return ret;
  97. }
  98. static int __devexit qi_lb60_remove(struct platform_device *pdev)
  99. {
  100. struct snd_soc_card *card = platform_get_drvdata(pdev);
  101. snd_soc_unregister_card(card);
  102. gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
  103. return 0;
  104. }
  105. static struct platform_driver qi_lb60_driver = {
  106. .driver = {
  107. .name = "qi-lb60-audio",
  108. .owner = THIS_MODULE,
  109. },
  110. .probe = qi_lb60_probe,
  111. .remove = __devexit_p(qi_lb60_remove),
  112. };
  113. module_platform_driver(qi_lb60_driver);
  114. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  115. MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
  116. MODULE_LICENSE("GPL v2");
  117. MODULE_ALIAS("platform:qi-lb60-audio");