Date:2011-08-02 10:55:56 (12 years 7 months ago)
Author:Maarten ter Huurne
Commit:653678783eaceabb6bc7461a1411f2264b8219eb
Message:MIPS: A320: Add SoC sound support for Dingoo A320

Files: sound/soc/jz4740/Kconfig (1 diff)
sound/soc/jz4740/Makefile (1 diff)
sound/soc/jz4740/a320.c (1 diff)

Change Details

sound/soc/jz4740/Kconfig
2626      Say Y if you want to add support for ASoC audio on the Qi LB60 board
2727      a.k.a Qi Ben NanoNote.
2828
29config SND_JZ4740_SOC_A320
30    bool "SoC Audio support for Dingoo A320"
31    depends on SND_JZ4740_SOC && JZ4740_A320
32    select SND_JZ4740_SOC_I2S
33    select SND_SOC_JZ4740_CODEC
34    help
35      Say Y if you want to add support for SoC audio on the Dingoo A320
36      game and media player.
37
2938endif
39
sound/soc/jz4740/Makefile
77
88# Jz4740 Machine Support
99snd-soc-qi-lb60-objs := qi_lb60.o
10snd-soc-a320-objs := a320.o
1011
1112obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
13obj-$(CONFIG_SND_JZ4740_SOC_A320) += snd-soc-a320.o
sound/soc/jz4740/a320.c
1/*
2 * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3 * Copyright (C) 2010-2011, Maarten ter Huurne <maarten@treewalker.org>
4 * Copyright (C) 2011, Paul Cercueil <paul@crapouillou.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/timer.h>
19#include <linux/interrupt.h>
20#include <linux/platform_device.h>
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
24#include <linux/gpio.h>
25
26#define A320_SPK_GPIO JZ_GPIO_PORTC(27)
27#define A320_HPTV_GPIO JZ_GPIO_PORTD(7)
28
29static int a320_spk_event(struct snd_soc_dapm_widget *widget,
30              struct snd_kcontrol *ctrl, int event)
31{
32    gpio_set_value(A320_SPK_GPIO, SND_SOC_DAPM_EVENT_ON(event));
33    return 0;
34}
35
36static int a320_hptv_event(
37            struct snd_soc_dapm_widget *widget,
38            struct snd_kcontrol *ctrl, int event)
39{
40    gpio_set_value(A320_HPTV_GPIO, SND_SOC_DAPM_EVENT_ON(event));
41    return 0;
42}
43
44static const struct snd_kcontrol_new a320_controls[] = {
45    SOC_DAPM_PIN_SWITCH("Speaker"),
46    SOC_DAPM_PIN_SWITCH("Headphones + TV-out"),
47};
48
49static const struct snd_soc_dapm_widget a320_widgets[] = {
50    SND_SOC_DAPM_MIC("Mic", NULL),
51    SND_SOC_DAPM_SPK("Speaker", a320_spk_event),
52    SND_SOC_DAPM_LINE("Headphones + TV-out", a320_hptv_event),
53};
54
55static const struct snd_soc_dapm_route a320_routes[] = {
56    {"Mic", NULL, "MIC"},
57    {"Speaker", NULL, "LOUT"},
58    {"Speaker", NULL, "ROUT"},
59    {"Headphones + TV-out", NULL, "LOUT"},
60    {"Headphones + TV-out", NULL, "ROUT"},
61};
62
63#define A320_DAIFMT (SND_SOC_DAIFMT_I2S | \
64             SND_SOC_DAIFMT_NB_NF | \
65             SND_SOC_DAIFMT_CBM_CFM)
66
67static int a320_codec_init(struct snd_soc_pcm_runtime *rtd)
68{
69    struct snd_soc_codec *codec = rtd->codec;
70    struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
71    struct snd_soc_dapm_context *dapm = &codec->dapm;
72    int ret;
73
74    ret = snd_soc_dai_set_fmt(cpu_dai, A320_DAIFMT);
75    if (ret < 0) {
76        dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
77        return ret;
78    }
79
80    snd_soc_add_card_controls(rtd->card, a320_controls,
81                  ARRAY_SIZE(a320_controls));
82
83    snd_soc_dapm_new_controls(dapm, a320_widgets, ARRAY_SIZE(a320_widgets));
84    snd_soc_dapm_add_routes(dapm, a320_routes, ARRAY_SIZE(a320_routes));
85    snd_soc_dapm_sync(dapm);
86
87    return 0;
88}
89
90static struct snd_soc_dai_link a320_dai = {
91    .name = "jz4740",
92    .stream_name = "jz4740",
93    .cpu_dai_name = "jz4740-i2s",
94    .platform_name = "jz4740-pcm-audio",
95    .codec_dai_name = "jz4740-hifi",
96    .codec_name = "jz4740-codec",
97    .init = a320_codec_init,
98};
99
100static struct snd_soc_card a320 = {
101    .name = "Dingoo A320",
102    .owner = THIS_MODULE,
103    .dai_link = &a320_dai,
104    .num_links = 1,
105};
106
107static int __devinit a320_probe(struct platform_device *pdev)
108{
109    struct snd_soc_card *card = &a320;
110    int ret;
111
112    ret = gpio_request(A320_SPK_GPIO, "SPK");
113    if (ret) {
114        dev_err(&pdev->dev, "Failed to request SPK GPIO(%d): %d\n",
115            A320_SPK_GPIO, ret);
116        return ret;
117    }
118
119    ret = gpio_request(A320_HPTV_GPIO, "HPTV");
120    if (ret) {
121        dev_err(&pdev->dev, "Failed to request HPTV GPIO(%d): %d\n",
122            A320_HPTV_GPIO, ret);
123        goto err_gpio_free_spk;
124    }
125
126    gpio_direction_output(A320_SPK_GPIO, 0);
127    gpio_direction_output(A320_HPTV_GPIO, 0);
128
129    card->dev = &pdev->dev;
130
131    ret = snd_soc_register_card(card);
132    if (ret) {
133        dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
134            ret);
135        goto err_gpio_free_hptv;
136    }
137
138    return 0;
139
140err_gpio_free_hptv:
141    gpio_free(A320_HPTV_GPIO);
142err_gpio_free_spk:
143    gpio_free(A320_SPK_GPIO);
144
145    return ret;
146}
147
148static int __devexit a320_remove(struct platform_device *pdev)
149{
150    struct snd_soc_card *card = platform_get_drvdata(pdev);
151
152    snd_soc_unregister_card(card);
153    gpio_free(A320_HPTV_GPIO);
154    gpio_free(A320_SPK_GPIO);
155    return 0;
156}
157
158static struct platform_driver a320_driver = {
159    .driver = {
160        .name = "a320-audio",
161        .owner = THIS_MODULE,
162    },
163    .probe = a320_probe,
164    .remove = __devexit_p(a320_remove),
165};
166
167module_platform_driver(a320_driver);
168
169MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>, Paul Cercueil <paul@crapouillou.net>");
170MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support");
171MODULE_LICENSE("GPL v2");
172MODULE_ALIAS("platform:a320-audio");

Archive Download the corresponding diff file



interactive