ASoC: JZ4740: qi_lb60: Use gpio_request_array to request and setup gpios
[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>
5898dd9e
LPC
22#include <linux/gpio.h>
23
5898dd9e
LPC
24#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
25#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
26
27static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
28 struct snd_kcontrol *ctrl, int event)
29{
30 int on = 0;
31 if (event & SND_SOC_DAPM_POST_PMU)
32 on = 1;
33 else if (event & SND_SOC_DAPM_PRE_PMD)
34 on = 0;
35
36 gpio_set_value(QI_LB60_SND_GPIO, on);
37 gpio_set_value(QI_LB60_AMP_GPIO, on);
38
39 return 0;
40}
41
42static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
43 SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
44 SND_SOC_DAPM_MIC("Mic", NULL),
45};
46
47static const struct snd_soc_dapm_route qi_lb60_routes[] = {
48 {"Mic", NULL, "MIC"},
49 {"Speaker", NULL, "LOUT"},
50 {"Speaker", NULL, "ROUT"},
51};
52
53#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
54 SND_SOC_DAIFMT_NB_NF | \
55 SND_SOC_DAIFMT_CBM_CFM)
56
f0fba2ad 57static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
5898dd9e 58{
f0fba2ad
LG
59 struct snd_soc_codec *codec = rtd->codec;
60 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
ce6120cc 61 struct snd_soc_dapm_context *dapm = &codec->dapm;
5898dd9e 62 int ret;
5898dd9e 63
ce6120cc
LG
64 snd_soc_dapm_nc_pin(dapm, "LIN");
65 snd_soc_dapm_nc_pin(dapm, "RIN");
5898dd9e
LPC
66
67 ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
68 if (ret < 0) {
69 dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
70 return ret;
71 }
72
5898dd9e
LPC
73 return 0;
74}
75
76static struct snd_soc_dai_link qi_lb60_dai = {
77 .name = "jz4740",
78 .stream_name = "jz4740",
f0fba2ad 79 .cpu_dai_name = "jz4740-i2s",
3ca2ecd9 80 .platform_name = "jz4740-pcm-audio",
f0fba2ad
LG
81 .codec_dai_name = "jz4740-hifi",
82 .codec_name = "jz4740-codec",
5898dd9e
LPC
83 .init = qi_lb60_codec_init,
84};
85
86static struct snd_soc_card qi_lb60 = {
87 .name = "QI LB60",
88 .dai_link = &qi_lb60_dai,
89 .num_links = 1,
13319699
LPC
90
91 .dapm_widgets = qi_lb60_widgets,
92 .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
93 .dapm_routes = qi_lb60_routes,
94 .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
5898dd9e
LPC
95};
96
97static struct platform_device *qi_lb60_snd_device;
98
c6f0ede7
LPC
99static const struct gpio qi_lb60_gpios[] = {
100 { QI_LB60_SND_GPIO, GPIOF_OUT_INIT_LOW, "SND" },
101 { QI_LB60_AMP_GPIO, GPIOF_OUT_INIT_LOW, "AMP" },
102};
103
5898dd9e
LPC
104static int __init qi_lb60_init(void)
105{
106 int ret;
107
108 qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
109
110 if (!qi_lb60_snd_device)
111 return -ENOMEM;
112
c6f0ede7 113 ret = gpio_request_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
5898dd9e 114 if (ret) {
c6f0ede7 115 pr_err("qi_lb60 snd: Failed to request gpios: %d\n", ret);
5898dd9e
LPC
116 goto err_device_put;
117 }
118
f0fba2ad 119 platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
5898dd9e
LPC
120
121 ret = platform_device_add(qi_lb60_snd_device);
122 if (ret) {
123 pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
124 goto err_unset_pdata;
125 }
126
127 return 0;
128
129err_unset_pdata:
130 platform_set_drvdata(qi_lb60_snd_device, NULL);
c6f0ede7
LPC
131/*err_gpio_free_array:*/
132 gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
5898dd9e
LPC
133err_device_put:
134 platform_device_put(qi_lb60_snd_device);
135
136 return ret;
137}
138module_init(qi_lb60_init);
139
140static void __exit qi_lb60_exit(void)
141{
5898dd9e 142 platform_device_unregister(qi_lb60_snd_device);
c6f0ede7 143 gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
5898dd9e
LPC
144}
145module_exit(qi_lb60_exit);
146
147MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
148MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
149MODULE_LICENSE("GPL v2");
This page took 0.056349 seconds and 5 git commands to generate.