Date:2011-08-02 10:55:56 (11 years 2 months ago)
Author:Maarten ter Huurne
Commit:d899115bb6f713ab28b34fdeadd9f8a448abbc68
Message:MIPS: A320: Add SoC sound support for Dingoo A320.

This is a squashed version of the development done in the jz-2.6.37 branch,
updated with necessary changes for mainline 2.6.38.
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
2121    help
2222      Say Y if you want to add support for ASoC audio on the Qi LB60 board
2323      a.k.a Qi Ben NanoNote.
24
25config SND_JZ4740_SOC_A320
26    bool "SoC Audio support for Dingoo A320"
27    depends on SND_JZ4740_SOC && JZ4740_A320
28    select SND_JZ4740_SOC_I2S
29    select SND_SOC_JZ4740_CODEC
30    help
31      Say Y if you want to add support for SoC audio on the Dingoo A320
32      game and media player.
sound/soc/jz4740/Makefile
99
1010# Jz4740 Machine Support
1111snd-soc-qi-lb60-objs := qi_lb60.o
12snd-soc-a320-objs := a320.o
1213
1314obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o
15obj-$(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    snd_soc_dapm_nc_pin(dapm, "LIN");
75    snd_soc_dapm_nc_pin(dapm, "RIN");
76
77    ret = snd_soc_dai_set_fmt(cpu_dai, A320_DAIFMT);
78    if (ret < 0) {
79        dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
80        return ret;
81    }
82
83    snd_soc_add_controls(codec, a320_controls, ARRAY_SIZE(a320_controls));
84
85    snd_soc_dapm_new_controls(dapm, a320_widgets, ARRAY_SIZE(a320_widgets));
86    snd_soc_dapm_add_routes(dapm, a320_routes, ARRAY_SIZE(a320_routes));
87    snd_soc_dapm_sync(dapm);
88
89    return 0;
90}
91
92static struct snd_soc_dai_link a320_dai = {
93    .name = "jz4740",
94    .stream_name = "jz4740",
95    .cpu_dai_name = "jz4740-i2s",
96    .platform_name = "jz4740-pcm-audio",
97    .codec_dai_name = "jz4740-hifi",
98    .codec_name = "jz4740-codec",
99    .init = a320_codec_init,
100};
101
102static struct snd_soc_card a320 = {
103    .name = "Dingoo A320",
104    .dai_link = &a320_dai,
105    .num_links = 1,
106};
107
108static struct platform_device *a320_snd_device;
109
110static int __init a320_init(void)
111{
112    int ret;
113
114    a320_snd_device = platform_device_alloc("soc-audio", -1);
115
116    if (!a320_snd_device)
117        return -ENOMEM;
118
119    ret = gpio_request(A320_SPK_GPIO, "SPK");
120    if (ret) {
121        pr_err("a320 snd: Failed to request SPK GPIO(%d): %d\n",
122                A320_SPK_GPIO, ret);
123        goto err_device_put;
124    }
125
126    ret = gpio_request(A320_HPTV_GPIO, "HPTV");
127    if (ret) {
128        pr_err("a320 snd: Failed to request HPTV GPIO(%d): %d\n",
129                A320_HPTV_GPIO, ret);
130        goto err_gpio_free_spk;
131    }
132
133    gpio_direction_output(A320_SPK_GPIO, 0);
134    gpio_direction_output(A320_HPTV_GPIO, 0);
135
136    platform_set_drvdata(a320_snd_device, &a320);
137
138    ret = platform_device_add(a320_snd_device);
139    if (ret) {
140        pr_err("a320 snd: Failed to add snd soc device: %d\n", ret);
141        goto err_unset_pdata;
142    }
143
144     return 0;
145
146err_unset_pdata:
147    platform_set_drvdata(a320_snd_device, NULL);
148/*err_gpio_free_hptv:*/
149    gpio_free(A320_HPTV_GPIO);
150err_gpio_free_spk:
151    gpio_free(A320_SPK_GPIO);
152err_device_put:
153    platform_device_put(a320_snd_device);
154
155    return ret;
156}
157module_init(a320_init);
158
159static void __exit a320_exit(void)
160{
161    gpio_free(A320_HPTV_GPIO);
162    gpio_free(A320_SPK_GPIO);
163    platform_device_unregister(a320_snd_device);
164}
165module_exit(a320_exit);
166
167MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>, Paul Cercueil <paul@crapouillou.net>");
168MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support");
169MODULE_LICENSE("GPL v2");

Archive Download the corresponding diff file



interactive