1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
6 #include <linux/module.h>
7 #include <linux/moduleparam.h>
8 #include <linux/timer.h>
9 #include <linux/interrupt.h>
10 #include <linux/platform_device.h>
11 #include <sound/core.h>
12 #include <sound/pcm.h>
13 #include <sound/soc.h>
14 #include <linux/gpio/consumer.h>
17 struct gpio_desc *snd_gpio;
18 struct gpio_desc *amp_gpio;
21 static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
22 struct snd_kcontrol *ctrl, int event)
24 struct qi_lb60 *qi_lb60 = snd_soc_card_get_drvdata(widget->dapm->card);
25 int on = !SND_SOC_DAPM_EVENT_OFF(event);
27 gpiod_set_value_cansleep(qi_lb60->snd_gpio, on);
28 gpiod_set_value_cansleep(qi_lb60->amp_gpio, on);
33 static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
34 SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
35 SND_SOC_DAPM_MIC("Mic", NULL),
38 static const struct snd_soc_dapm_route qi_lb60_routes[] = {
40 {"Speaker", NULL, "LOUT"},
41 {"Speaker", NULL, "ROUT"},
44 SND_SOC_DAILINK_DEFS(hifi,
45 DAILINK_COMP_ARRAY(COMP_CPU("jz4740-i2s")),
46 DAILINK_COMP_ARRAY(COMP_CODEC("jz4740-codec", "jz4740-hifi")),
47 DAILINK_COMP_ARRAY(COMP_PLATFORM("jz4740-i2s")));
49 static struct snd_soc_dai_link qi_lb60_dai = {
51 .stream_name = "jz4740",
52 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
53 SND_SOC_DAIFMT_CBM_CFM,
54 SND_SOC_DAILINK_REG(hifi),
57 static struct snd_soc_card qi_lb60_card = {
60 .dai_link = &qi_lb60_dai,
63 .dapm_widgets = qi_lb60_widgets,
64 .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
65 .dapm_routes = qi_lb60_routes,
66 .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
70 static int qi_lb60_probe(struct platform_device *pdev)
72 struct qi_lb60 *qi_lb60;
73 struct snd_soc_card *card = &qi_lb60_card;
75 qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL);
79 qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd", GPIOD_OUT_LOW);
80 if (IS_ERR(qi_lb60->snd_gpio))
81 return PTR_ERR(qi_lb60->snd_gpio);
83 qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp", GPIOD_OUT_LOW);
84 if (IS_ERR(qi_lb60->amp_gpio))
85 return PTR_ERR(qi_lb60->amp_gpio);
87 card->dev = &pdev->dev;
89 snd_soc_card_set_drvdata(card, qi_lb60);
91 return devm_snd_soc_register_card(&pdev->dev, card);
94 static struct platform_driver qi_lb60_driver = {
96 .name = "qi-lb60-audio",
98 .probe = qi_lb60_probe,
101 module_platform_driver(qi_lb60_driver);
103 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
104 MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
105 MODULE_LICENSE("GPL v2");
106 MODULE_ALIAS("platform:qi-lb60-audio");