2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
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.
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.
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>
22 #include <sound/soc-dapm.h>
23 #include <linux/gpio.h>
25 #define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
26 #define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
28 static int qi_lb60_spk_event(struct snd_soc_dapm_widget
*widget
,
29 struct snd_kcontrol
*ctrl
, int event
)
32 if (event
& SND_SOC_DAPM_POST_PMU
)
34 else if (event
& SND_SOC_DAPM_PRE_PMD
)
37 gpio_set_value(QI_LB60_SND_GPIO
, on
);
38 gpio_set_value(QI_LB60_AMP_GPIO
, on
);
43 static const struct snd_soc_dapm_widget qi_lb60_widgets
[] = {
44 SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event
),
45 SND_SOC_DAPM_MIC("Mic", NULL
),
48 static const struct snd_soc_dapm_route qi_lb60_routes
[] = {
50 {"Speaker", NULL
, "LOUT"},
51 {"Speaker", NULL
, "ROUT"},
54 #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
55 SND_SOC_DAIFMT_NB_NF | \
56 SND_SOC_DAIFMT_CBM_CFM)
58 static int qi_lb60_codec_init(struct snd_soc_pcm_runtime
*rtd
)
60 struct snd_soc_codec
*codec
= rtd
->codec
;
61 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
64 snd_soc_dapm_nc_pin(codec
, "LIN");
65 snd_soc_dapm_nc_pin(codec
, "RIN");
67 ret
= snd_soc_dai_set_fmt(cpu_dai
, QI_LB60_DAIFMT
);
69 dev_err(codec
->dev
, "Failed to set cpu dai format: %d\n", ret
);
73 snd_soc_dapm_new_controls(codec
, qi_lb60_widgets
, ARRAY_SIZE(qi_lb60_widgets
));
74 snd_soc_dapm_add_routes(codec
, qi_lb60_routes
, ARRAY_SIZE(qi_lb60_routes
));
75 snd_soc_dapm_sync(codec
);
80 static struct snd_soc_dai_link qi_lb60_dai
= {
82 .stream_name
= "jz4740",
83 .cpu_dai_name
= "jz4740-i2s",
84 .platform_name
= "jz4740-pcm-audio",
85 .codec_dai_name
= "jz4740-hifi",
86 .codec_name
= "jz4740-codec",
87 .init
= qi_lb60_codec_init
,
90 static struct snd_soc_card qi_lb60
= {
92 .dai_link
= &qi_lb60_dai
,
96 static struct platform_device
*qi_lb60_snd_device
;
98 static int __init
qi_lb60_init(void)
102 qi_lb60_snd_device
= platform_device_alloc("soc-audio", -1);
104 if (!qi_lb60_snd_device
)
107 ret
= gpio_request(QI_LB60_SND_GPIO
, "SND");
109 pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
110 QI_LB60_SND_GPIO
, ret
);
114 ret
= gpio_request(QI_LB60_AMP_GPIO
, "AMP");
116 pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
117 QI_LB60_AMP_GPIO
, ret
);
118 goto err_gpio_free_snd
;
121 gpio_direction_output(QI_LB60_SND_GPIO
, 0);
122 gpio_direction_output(QI_LB60_AMP_GPIO
, 0);
124 platform_set_drvdata(qi_lb60_snd_device
, &qi_lb60
);
126 ret
= platform_device_add(qi_lb60_snd_device
);
128 pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret
);
129 goto err_unset_pdata
;
135 platform_set_drvdata(qi_lb60_snd_device
, NULL
);
136 /*err_gpio_free_amp:*/
137 gpio_free(QI_LB60_AMP_GPIO
);
139 gpio_free(QI_LB60_SND_GPIO
);
141 platform_device_put(qi_lb60_snd_device
);
145 module_init(qi_lb60_init
);
147 static void __exit
qi_lb60_exit(void)
149 gpio_free(QI_LB60_AMP_GPIO
);
150 gpio_free(QI_LB60_SND_GPIO
);
151 platform_device_unregister(qi_lb60_snd_device
);
153 module_exit(qi_lb60_exit
);
155 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
156 MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
157 MODULE_LICENSE("GPL v2");