blob: 0097c3b13a1a31a1e1d48c99d71d62d3db72281d [file] [log] [blame]
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +02001/*
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>
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020022#include <linux/gpio.h>
23
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020024#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{
Lars-Peter Clausen621206b2011-04-12 19:31:05 +020030 int on = !SND_SOC_DAPM_EVENT_OFF(event);
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020031
32 gpio_set_value(QI_LB60_SND_GPIO, on);
33 gpio_set_value(QI_LB60_AMP_GPIO, on);
34
35 return 0;
36}
37
38static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
39 SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
40 SND_SOC_DAPM_MIC("Mic", NULL),
41};
42
43static const struct snd_soc_dapm_route qi_lb60_routes[] = {
44 {"Mic", NULL, "MIC"},
45 {"Speaker", NULL, "LOUT"},
46 {"Speaker", NULL, "ROUT"},
47};
48
49#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
50 SND_SOC_DAIFMT_NB_NF | \
51 SND_SOC_DAIFMT_CBM_CFM)
52
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000053static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020054{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000055 struct snd_soc_codec *codec = rtd->codec;
56 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020057 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020058 int ret;
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020059
Liam Girdwoodce6120c2010-11-05 15:53:46 +020060 snd_soc_dapm_nc_pin(dapm, "LIN");
61 snd_soc_dapm_nc_pin(dapm, "RIN");
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020062
63 ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
64 if (ret < 0) {
65 dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
66 return ret;
67 }
68
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020069 return 0;
70}
71
72static struct snd_soc_dai_link qi_lb60_dai = {
73 .name = "jz4740",
74 .stream_name = "jz4740",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000075 .cpu_dai_name = "jz4740-i2s",
Lars-Peter Clausen3ca2ecd2010-08-15 17:48:47 +020076 .platform_name = "jz4740-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000077 .codec_dai_name = "jz4740-hifi",
78 .codec_name = "jz4740-codec",
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020079 .init = qi_lb60_codec_init,
80};
81
82static struct snd_soc_card qi_lb60 = {
83 .name = "QI LB60",
Axel Lin1d9d25b2011-12-23 14:48:19 +080084 .owner = THIS_MODULE,
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020085 .dai_link = &qi_lb60_dai,
86 .num_links = 1,
Lars-Peter Clausen13319692011-04-12 19:31:03 +020087
88 .dapm_widgets = qi_lb60_widgets,
89 .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
90 .dapm_routes = qi_lb60_routes,
91 .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020092};
93
94static struct platform_device *qi_lb60_snd_device;
95
Lars-Peter Clausenc6f0ede2011-04-12 19:31:04 +020096static const struct gpio qi_lb60_gpios[] = {
97 { QI_LB60_SND_GPIO, GPIOF_OUT_INIT_LOW, "SND" },
98 { QI_LB60_AMP_GPIO, GPIOF_OUT_INIT_LOW, "AMP" },
99};
100
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200101static int __init qi_lb60_init(void)
102{
103 int ret;
104
105 qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
106
107 if (!qi_lb60_snd_device)
108 return -ENOMEM;
109
Lars-Peter Clausenc6f0ede2011-04-12 19:31:04 +0200110 ret = gpio_request_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200111 if (ret) {
Lars-Peter Clausenc6f0ede2011-04-12 19:31:04 +0200112 pr_err("qi_lb60 snd: Failed to request gpios: %d\n", ret);
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200113 goto err_device_put;
114 }
115
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000116 platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200117
118 ret = platform_device_add(qi_lb60_snd_device);
119 if (ret) {
120 pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
121 goto err_unset_pdata;
122 }
123
124 return 0;
125
126err_unset_pdata:
127 platform_set_drvdata(qi_lb60_snd_device, NULL);
Lars-Peter Clausenc6f0ede2011-04-12 19:31:04 +0200128/*err_gpio_free_array:*/
129 gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200130err_device_put:
131 platform_device_put(qi_lb60_snd_device);
132
133 return ret;
134}
135module_init(qi_lb60_init);
136
137static void __exit qi_lb60_exit(void)
138{
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200139 platform_device_unregister(qi_lb60_snd_device);
Lars-Peter Clausenc6f0ede2011-04-12 19:31:04 +0200140 gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200141}
142module_exit(qi_lb60_exit);
143
144MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
145MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
146MODULE_LICENSE("GPL v2");