Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / sound / soc / jz4740 / qi_lb60.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
4  */
5
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>
15
16 struct qi_lb60 {
17         struct gpio_desc *snd_gpio;
18         struct gpio_desc *amp_gpio;
19 };
20
21 static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
22                              struct snd_kcontrol *ctrl, int event)
23 {
24         struct qi_lb60 *qi_lb60 = snd_soc_card_get_drvdata(widget->dapm->card);
25         int on = !SND_SOC_DAPM_EVENT_OFF(event);
26
27         gpiod_set_value_cansleep(qi_lb60->snd_gpio, on);
28         gpiod_set_value_cansleep(qi_lb60->amp_gpio, on);
29
30         return 0;
31 }
32
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),
36 };
37
38 static const struct snd_soc_dapm_route qi_lb60_routes[] = {
39         {"Mic", NULL, "MIC"},
40         {"Speaker", NULL, "LOUT"},
41         {"Speaker", NULL, "ROUT"},
42 };
43
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")));
48
49 static struct snd_soc_dai_link qi_lb60_dai = {
50         .name = "jz4740",
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),
55 };
56
57 static struct snd_soc_card qi_lb60_card = {
58         .name = "QI LB60",
59         .owner = THIS_MODULE,
60         .dai_link = &qi_lb60_dai,
61         .num_links = 1,
62
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),
67         .fully_routed = true,
68 };
69
70 static int qi_lb60_probe(struct platform_device *pdev)
71 {
72         struct qi_lb60 *qi_lb60;
73         struct snd_soc_card *card = &qi_lb60_card;
74
75         qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL);
76         if (!qi_lb60)
77                 return -ENOMEM;
78
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);
82
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);
86
87         card->dev = &pdev->dev;
88
89         snd_soc_card_set_drvdata(card, qi_lb60);
90
91         return devm_snd_soc_register_card(&pdev->dev, card);
92 }
93
94 static struct platform_driver qi_lb60_driver = {
95         .driver         = {
96                 .name   = "qi-lb60-audio",
97         },
98         .probe          = qi_lb60_probe,
99 };
100
101 module_platform_driver(qi_lb60_driver);
102
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");