Merge remote-tracking branches 'asoc/fix/arizona', 'asoc/fix/rt5514' and 'asoc/fix...
[deliverable/linux.git] / sound / soc / jz4740 / qi_lb60.c
CommitLineData
5898dd9e
LPC
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
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/timer.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
218e18a3 22#include <linux/gpio/consumer.h>
5898dd9e 23
218e18a3
LPC
24struct qi_lb60 {
25 struct gpio_desc *snd_gpio;
26 struct gpio_desc *amp_gpio;
27};
5898dd9e
LPC
28
29static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
30 struct snd_kcontrol *ctrl, int event)
31{
218e18a3 32 struct qi_lb60 *qi_lb60 = snd_soc_card_get_drvdata(widget->dapm->card);
621206b7 33 int on = !SND_SOC_DAPM_EVENT_OFF(event);
5898dd9e 34
218e18a3
LPC
35 gpiod_set_value_cansleep(qi_lb60->snd_gpio, on);
36 gpiod_set_value_cansleep(qi_lb60->amp_gpio, on);
5898dd9e
LPC
37
38 return 0;
39}
40
41static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
42 SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
43 SND_SOC_DAPM_MIC("Mic", NULL),
44};
45
46static const struct snd_soc_dapm_route qi_lb60_routes[] = {
47 {"Mic", NULL, "MIC"},
48 {"Speaker", NULL, "LOUT"},
49 {"Speaker", NULL, "ROUT"},
50};
51
5898dd9e
LPC
52static struct snd_soc_dai_link qi_lb60_dai = {
53 .name = "jz4740",
54 .stream_name = "jz4740",
f0fba2ad 55 .cpu_dai_name = "jz4740-i2s",
0406a40a 56 .platform_name = "jz4740-i2s",
f0fba2ad
LG
57 .codec_dai_name = "jz4740-hifi",
58 .codec_name = "jz4740-codec",
0e746d7b
LPC
59 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
60 SND_SOC_DAIFMT_CBM_CFM,
5898dd9e
LPC
61};
62
218e18a3 63static struct snd_soc_card qi_lb60_card = {
5898dd9e 64 .name = "QI LB60",
1d9d25b3 65 .owner = THIS_MODULE,
5898dd9e
LPC
66 .dai_link = &qi_lb60_dai,
67 .num_links = 1,
13319699
LPC
68
69 .dapm_widgets = qi_lb60_widgets,
70 .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
71 .dapm_routes = qi_lb60_routes,
72 .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
b8fb837b 73 .fully_routed = true,
5898dd9e
LPC
74};
75
d6a29e3d 76static int qi_lb60_probe(struct platform_device *pdev)
5898dd9e 77{
218e18a3
LPC
78 struct qi_lb60 *qi_lb60;
79 struct snd_soc_card *card = &qi_lb60_card;
5898dd9e 80
218e18a3
LPC
81 qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL);
82 if (!qi_lb60)
83 return -ENOMEM;
84
69b93607 85 qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd", GPIOD_OUT_LOW);
218e18a3
LPC
86 if (IS_ERR(qi_lb60->snd_gpio))
87 return PTR_ERR(qi_lb60->snd_gpio);
218e18a3 88
69b93607 89 qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp", GPIOD_OUT_LOW);
218e18a3
LPC
90 if (IS_ERR(qi_lb60->amp_gpio))
91 return PTR_ERR(qi_lb60->amp_gpio);
5898dd9e 92
b33005f3 93 card->dev = &pdev->dev;
5898dd9e 94
218e18a3 95 snd_soc_card_set_drvdata(card, qi_lb60);
5898dd9e 96
218e18a3 97 return devm_snd_soc_register_card(&pdev->dev, card);
5898dd9e 98}
b33005f3
AL
99
100static struct platform_driver qi_lb60_driver = {
101 .driver = {
102 .name = "qi-lb60-audio",
b33005f3
AL
103 },
104 .probe = qi_lb60_probe,
b33005f3
AL
105};
106
107module_platform_driver(qi_lb60_driver);
5898dd9e
LPC
108
109MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
110MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
111MODULE_LICENSE("GPL v2");
b33005f3 112MODULE_ALIAS("platform:qi-lb60-audio");
This page took 0.25829 seconds and 5 git commands to generate.