qi_lb60.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/consumer.h>
  22. struct qi_lb60 {
  23. struct gpio_desc *snd_gpio;
  24. struct gpio_desc *amp_gpio;
  25. };
  26. static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
  27. struct snd_kcontrol *ctrl, int event)
  28. {
  29. struct qi_lb60 *qi_lb60 = snd_soc_card_get_drvdata(widget->dapm->card);
  30. int on = !SND_SOC_DAPM_EVENT_OFF(event);
  31. gpiod_set_value_cansleep(qi_lb60->snd_gpio, on);
  32. gpiod_set_value_cansleep(qi_lb60->amp_gpio, on);
  33. return 0;
  34. }
  35. static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
  36. SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
  37. SND_SOC_DAPM_MIC("Mic", NULL),
  38. };
  39. static const struct snd_soc_dapm_route qi_lb60_routes[] = {
  40. {"Mic", NULL, "MIC"},
  41. {"Speaker", NULL, "LOUT"},
  42. {"Speaker", NULL, "ROUT"},
  43. };
  44. static struct snd_soc_dai_link qi_lb60_dai = {
  45. .name = "jz4740",
  46. .stream_name = "jz4740",
  47. .cpu_dai_name = "jz4740-i2s",
  48. .platform_name = "jz4740-i2s",
  49. .codec_dai_name = "jz4740-hifi",
  50. .codec_name = "jz4740-codec",
  51. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  52. SND_SOC_DAIFMT_CBM_CFM,
  53. };
  54. static struct snd_soc_card qi_lb60_card = {
  55. .name = "QI LB60",
  56. .owner = THIS_MODULE,
  57. .dai_link = &qi_lb60_dai,
  58. .num_links = 1,
  59. .dapm_widgets = qi_lb60_widgets,
  60. .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
  61. .dapm_routes = qi_lb60_routes,
  62. .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
  63. .fully_routed = true,
  64. };
  65. static int qi_lb60_probe(struct platform_device *pdev)
  66. {
  67. struct qi_lb60 *qi_lb60;
  68. struct snd_soc_card *card = &qi_lb60_card;
  69. int ret;
  70. qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL);
  71. if (!qi_lb60)
  72. return -ENOMEM;
  73. qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd");
  74. if (IS_ERR(qi_lb60->snd_gpio))
  75. return PTR_ERR(qi_lb60->snd_gpio);
  76. ret = gpiod_direction_output(qi_lb60->snd_gpio, 0);
  77. if (ret)
  78. return ret;
  79. qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp");
  80. if (IS_ERR(qi_lb60->amp_gpio))
  81. return PTR_ERR(qi_lb60->amp_gpio);
  82. ret = gpiod_direction_output(qi_lb60->amp_gpio, 0);
  83. if (ret)
  84. return ret;
  85. card->dev = &pdev->dev;
  86. snd_soc_card_set_drvdata(card, qi_lb60);
  87. return devm_snd_soc_register_card(&pdev->dev, card);
  88. }
  89. static struct platform_driver qi_lb60_driver = {
  90. .driver = {
  91. .name = "qi-lb60-audio",
  92. .owner = THIS_MODULE,
  93. },
  94. .probe = qi_lb60_probe,
  95. };
  96. module_platform_driver(qi_lb60_driver);
  97. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  98. MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
  99. MODULE_LICENSE("GPL v2");
  100. MODULE_ALIAS("platform:qi-lb60-audio");