Date:2011-03-05 15:09:08 (11 years 7 months ago)
Author:Maarten ter Huurne
Commit:333e10e0450b4111b23cd28f2e4642e8b64c0455
Message:MIPS: A320: Properly named audio channels and added switches on them.

There are two audio output channels: the internal speakers and the headphones + TV-out.
The only difference between headphones and TV-out is that plugging something into the headphones connector will disable the speakers in hardware.
Thanks to Paul Cercueil for the original patch.
Files: sound/soc/jz4740/a320.c (5 diffs)

Change Details

sound/soc/jz4740/a320.c
2323#include <sound/soc-dapm.h>
2424#include <linux/gpio.h>
2525
26// TODO(MtH): These GPIOs are related to audio according to booboo's notes,
27// but what they do exactly is not clear at the moment.
28#define A320_SND_GPIO JZ_GPIO_PORTC(27)
29#define A320_AMP_GPIO JZ_GPIO_PORTD(7)
26#define A320_SPK_GPIO JZ_GPIO_PORTC(27)
27#define A320_HPTV_GPIO JZ_GPIO_PORTD(7)
3028
3129static int a320_spk_event(struct snd_soc_dapm_widget *widget,
3230              struct snd_kcontrol *ctrl, int event)
3331{
34    int on = 0;
35    if (event & SND_SOC_DAPM_POST_PMU)
36        on = 1;
37    else if (event & SND_SOC_DAPM_PRE_PMD)
38        on = 0;
39
40    gpio_set_value(A320_SND_GPIO, on);
41    gpio_set_value(A320_AMP_GPIO, on);
32    gpio_set_value(A320_SPK_GPIO, SND_SOC_DAPM_EVENT_ON(event));
33    return 0;
34}
4235
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));
4341    return 0;
4442}
4543
44static const struct snd_kcontrol_new a320_controls[] = {
45    SOC_DAPM_PIN_SWITCH("Speaker"),
46    SOC_DAPM_PIN_SWITCH("Headphones + TV-out"),
47};
48
4649static const struct snd_soc_dapm_widget a320_widgets[] = {
47    SND_SOC_DAPM_SPK("Speaker", a320_spk_event),
4850    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),
4953};
5054
5155static const struct snd_soc_dapm_route a320_routes[] = {
5256    {"Mic", NULL, "MIC"},
5357    {"Speaker", NULL, "LOUT"},
5458    {"Speaker", NULL, "ROUT"},
59    {"Headphones + TV-out", NULL, "LOUT"},
60    {"Headphones + TV-out", NULL, "ROUT"},
5561};
5662
5763#define A320_DAIFMT (SND_SOC_DAIFMT_I2S | \
...... 
7379        return ret;
7480    }
7581
82    snd_soc_add_controls(codec, a320_controls, ARRAY_SIZE(a320_controls));
83
7684    snd_soc_dapm_new_controls(codec, a320_widgets, ARRAY_SIZE(a320_widgets));
7785    snd_soc_dapm_add_routes(codec, a320_routes, ARRAY_SIZE(a320_routes));
7886    snd_soc_dapm_sync(codec);
...... 
107115    if (!a320_snd_device)
108116        return -ENOMEM;
109117
110    ret = gpio_request(A320_SND_GPIO, "SND");
118    ret = gpio_request(A320_SPK_GPIO, "SPK");
111119    if (ret) {
112        pr_err("a320 snd: Failed to request SND GPIO(%d): %d\n",
113                A320_SND_GPIO, ret);
120        pr_err("a320 snd: Failed to request SPK GPIO(%d): %d\n",
121                A320_SPK_GPIO, ret);
114122        goto err_device_put;
115123    }
116124
117    ret = gpio_request(A320_AMP_GPIO, "AMP");
125    ret = gpio_request(A320_HPTV_GPIO, "HPTV");
118126    if (ret) {
119        pr_err("a320 snd: Failed to request AMP GPIO(%d): %d\n",
120                A320_AMP_GPIO, ret);
121        goto err_gpio_free_snd;
127        pr_err("a320 snd: Failed to request HPTV GPIO(%d): %d\n",
128                A320_HPTV_GPIO, ret);
129        goto err_gpio_free_spk;
122130    }
123131
124    gpio_direction_output(A320_SND_GPIO, 0);
125    gpio_direction_output(A320_AMP_GPIO, 0);
132    gpio_direction_output(A320_SPK_GPIO, 0);
133    gpio_direction_output(A320_HPTV_GPIO, 0);
126134
127135    platform_set_drvdata(a320_snd_device, &a320);
128136
...... 
136144
137145err_unset_pdata:
138146    platform_set_drvdata(a320_snd_device, NULL);
139/*err_gpio_free_amp:*/
140    gpio_free(A320_AMP_GPIO);
141err_gpio_free_snd:
142    gpio_free(A320_SND_GPIO);
147/*err_gpio_free_hptv:*/
148    gpio_free(A320_HPTV_GPIO);
149err_gpio_free_spk:
150    gpio_free(A320_SPK_GPIO);
143151err_device_put:
144152    platform_device_put(a320_snd_device);
145153
...... 
149157
150158static void __exit a320_exit(void)
151159{
152    gpio_free(A320_AMP_GPIO);
153    gpio_free(A320_SND_GPIO);
160    gpio_free(A320_HPTV_GPIO);
161    gpio_free(A320_SPK_GPIO);
154162    platform_device_unregister(a320_snd_device);
155163}
156164module_exit(a320_exit);
157165
158MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>");
166MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>, Maarten ter Huurne <maarten@treewalker.org>, Paul Cercueil <paul@crapouillou.net>");
159167MODULE_DESCRIPTION("ALSA SoC Dingoo A320 Audio support");
160168MODULE_LICENSE("GPL v2");

Archive Download the corresponding diff file



interactive