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 <linux/gpio.h>
24 #define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
25 #define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
27 static int qi_lb60_spk_event(struct snd_soc_dapm_widget
*widget
,
28 struct snd_kcontrol
*ctrl
, int event
)
30 int on
= !SND_SOC_DAPM_EVENT_OFF(event
);
32 gpio_set_value(QI_LB60_SND_GPIO
, on
);
33 gpio_set_value(QI_LB60_AMP_GPIO
, on
);
38 static 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
),
43 static const struct snd_soc_dapm_route qi_lb60_routes
[] = {
45 {"Speaker", NULL
, "LOUT"},
46 {"Speaker", NULL
, "ROUT"},
49 #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
50 SND_SOC_DAIFMT_NB_NF | \
51 SND_SOC_DAIFMT_CBM_CFM)
53 static int qi_lb60_codec_init(struct snd_soc_pcm_runtime
*rtd
)
55 struct snd_soc_codec
*codec
= rtd
->codec
;
56 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
57 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
60 snd_soc_dapm_nc_pin(dapm
, "LIN");
61 snd_soc_dapm_nc_pin(dapm
, "RIN");
63 ret
= snd_soc_dai_set_fmt(cpu_dai
, QI_LB60_DAIFMT
);
65 dev_err(codec
->dev
, "Failed to set cpu dai format: %d\n", ret
);
72 static struct snd_soc_dai_link qi_lb60_dai
= {
74 .stream_name
= "jz4740",
75 .cpu_dai_name
= "jz4740-i2s",
76 .platform_name
= "jz4740-pcm-audio",
77 .codec_dai_name
= "jz4740-hifi",
78 .codec_name
= "jz4740-codec",
79 .init
= qi_lb60_codec_init
,
82 static struct snd_soc_card qi_lb60
= {
85 .dai_link
= &qi_lb60_dai
,
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
),
94 static const struct gpio qi_lb60_gpios
[] = {
95 { QI_LB60_SND_GPIO
, GPIOF_OUT_INIT_LOW
, "SND" },
96 { QI_LB60_AMP_GPIO
, GPIOF_OUT_INIT_LOW
, "AMP" },
99 static int qi_lb60_probe(struct platform_device
*pdev
)
101 struct snd_soc_card
*card
= &qi_lb60
;
104 ret
= gpio_request_array(qi_lb60_gpios
, ARRAY_SIZE(qi_lb60_gpios
));
108 card
->dev
= &pdev
->dev
;
110 ret
= snd_soc_register_card(card
);
112 dev_err(&pdev
->dev
, "snd_soc_register_card() failed: %d\n",
114 gpio_free_array(qi_lb60_gpios
, ARRAY_SIZE(qi_lb60_gpios
));
119 static int qi_lb60_remove(struct platform_device
*pdev
)
121 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
123 snd_soc_unregister_card(card
);
124 gpio_free_array(qi_lb60_gpios
, ARRAY_SIZE(qi_lb60_gpios
));
128 static struct platform_driver qi_lb60_driver
= {
130 .name
= "qi-lb60-audio",
131 .owner
= THIS_MODULE
,
133 .probe
= qi_lb60_probe
,
134 .remove
= qi_lb60_remove
,
137 module_platform_driver(qi_lb60_driver
);
139 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
140 MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
141 MODULE_LICENSE("GPL v2");
142 MODULE_ALIAS("platform:qi-lb60-audio");