aboutsummaryrefslogtreecommitdiffstats
path: root/sound/ppc
diff options
context:
space:
mode:
Diffstat (limited to 'sound/ppc')
-rw-r--r--sound/ppc/Makefile2
-rw-r--r--sound/ppc/pmac.c44
-rw-r--r--sound/ppc/pmac.h3
-rw-r--r--sound/ppc/powermac.c21
-rw-r--r--sound/ppc/toonie.c378
5 files changed, 19 insertions, 429 deletions
diff --git a/sound/ppc/Makefile b/sound/ppc/Makefile
index d6ba995909..4d95c652c8 100644
--- a/sound/ppc/Makefile
+++ b/sound/ppc/Makefile
@@ -3,7 +3,7 @@
3# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz> 3# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
4# 4#
5 5
6snd-powermac-objs := powermac.o pmac.o awacs.o burgundy.o daca.o tumbler.o toonie.o keywest.o beep.o 6snd-powermac-objs := powermac.o pmac.o awacs.o burgundy.o daca.o tumbler.o keywest.o beep.o
7 7
8# Toplevel Module Dependency 8# Toplevel Module Dependency
9obj-$(CONFIG_SND_POWERMAC) += snd-powermac.o 9obj-$(CONFIG_SND_POWERMAC) += snd-powermac.o
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index f0794ef9d1..b678814975 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -867,8 +867,6 @@ static int __init snd_pmac_detect(struct snd_pmac *chip)
867 unsigned int *prop, l; 867 unsigned int *prop, l;
868 struct macio_chip* macio; 868 struct macio_chip* macio;
869 869
870 u32 layout_id = 0;
871
872 if (!machine_is(powermac)) 870 if (!machine_is(powermac))
873 return -ENODEV; 871 return -ENODEV;
874 872
@@ -929,8 +927,14 @@ static int __init snd_pmac_detect(struct snd_pmac *chip)
929 if (prop && *prop < 16) 927 if (prop && *prop < 16)
930 chip->subframe = *prop; 928 chip->subframe = *prop;
931 prop = (unsigned int *) get_property(sound, "layout-id", NULL); 929 prop = (unsigned int *) get_property(sound, "layout-id", NULL);
932 if (prop) 930 if (prop) {
933 layout_id = *prop; 931 /* partly deprecate snd-powermac, for those machines
932 * that have a layout-id property for now */
933 printk(KERN_INFO "snd-powermac no longer handles any "
934 "machines with a layout-id property "
935 "in the device-tree, use snd-aoa.\n");
936 return -ENODEV;
937 }
934 /* This should be verified on older screamers */ 938 /* This should be verified on older screamers */
935 if (device_is_compatible(sound, "screamer")) { 939 if (device_is_compatible(sound, "screamer")) {
936 chip->model = PMAC_SCREAMER; 940 chip->model = PMAC_SCREAMER;
@@ -963,38 +967,6 @@ static int __init snd_pmac_detect(struct snd_pmac *chip)
963 chip->freq_table = tumbler_freqs; 967 chip->freq_table = tumbler_freqs;
964 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ 968 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */
965 } 969 }
966 if (device_is_compatible(sound, "AOAKeylargo") ||
967 device_is_compatible(sound, "AOAbase") ||
968 device_is_compatible(sound, "AOAK2")) {
969 /* For now, only support very basic TAS3004 based machines with
970 * single frequency until proper i2s control is implemented
971 */
972 switch(layout_id) {
973 case 0x24:
974 case 0x29:
975 case 0x33:
976 case 0x46:
977 case 0x48:
978 case 0x50:
979 case 0x5c:
980 chip->num_freqs = ARRAY_SIZE(tumbler_freqs);
981 chip->model = PMAC_SNAPPER;
982 chip->can_byte_swap = 0; /* FIXME: check this */
983 chip->control_mask = MASK_IEPC | 0x11;/* disable IEE */
984 break;
985 case 0x3a:
986 chip->num_freqs = ARRAY_SIZE(tumbler_freqs);
987 chip->model = PMAC_TOONIE;
988 chip->can_byte_swap = 0; /* FIXME: check this */
989 chip->control_mask = MASK_IEPC | 0x11;/* disable IEE */
990 break;
991 default:
992 printk(KERN_ERR "snd: Unknown layout ID 0x%x\n",
993 layout_id);
994 return -ENODEV;
995
996 }
997 }
998 prop = (unsigned int *)get_property(sound, "device-id", NULL); 970 prop = (unsigned int *)get_property(sound, "device-id", NULL);
999 if (prop) 971 if (prop)
1000 chip->device_id = *prop; 972 chip->device_id = *prop;
diff --git a/sound/ppc/pmac.h b/sound/ppc/pmac.h
index 3a9bd4dbb9..8394e66ceb 100644
--- a/sound/ppc/pmac.h
+++ b/sound/ppc/pmac.h
@@ -85,7 +85,7 @@ struct pmac_stream {
85 85
86enum snd_pmac_model { 86enum snd_pmac_model {
87 PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER, 87 PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER,
88 PMAC_SNAPPER, PMAC_TOONIE 88 PMAC_SNAPPER
89}; 89};
90 90
91struct snd_pmac { 91struct snd_pmac {
@@ -188,7 +188,6 @@ int snd_pmac_burgundy_init(struct snd_pmac *chip);
188int snd_pmac_daca_init(struct snd_pmac *chip); 188int snd_pmac_daca_init(struct snd_pmac *chip);
189int snd_pmac_tumbler_init(struct snd_pmac *chip); 189int snd_pmac_tumbler_init(struct snd_pmac *chip);
190int snd_pmac_tumbler_post_init(void); 190int snd_pmac_tumbler_post_init(void);
191int snd_pmac_toonie_init(struct snd_pmac *chip);
192 191
193/* i2c functions */ 192/* i2c functions */
194struct pmac_keywest { 193struct pmac_keywest {
diff --git a/sound/ppc/powermac.c b/sound/ppc/powermac.c
index f4902a219e..fa9a44ab48 100644
--- a/sound/ppc/powermac.c
+++ b/sound/ppc/powermac.c
@@ -94,13 +94,6 @@ static int __init snd_pmac_probe(struct platform_device *devptr)
94 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0) 94 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
95 goto __error; 95 goto __error;
96 break; 96 break;
97 case PMAC_TOONIE:
98 strcpy(card->driver, "PMac Toonie");
99 strcpy(card->shortname, "PowerMac Toonie");
100 strcpy(card->longname, card->shortname);
101 if ((err = snd_pmac_toonie_init(chip)) < 0)
102 goto __error;
103 break;
104 case PMAC_AWACS: 97 case PMAC_AWACS:
105 case PMAC_SCREAMER: 98 case PMAC_SCREAMER:
106 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS"; 99 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
@@ -188,11 +181,15 @@ static int __init alsa_card_pmac_init(void)
188 if ((err = platform_driver_register(&snd_pmac_driver)) < 0) 181 if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
189 return err; 182 return err;
190 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0); 183 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
191 if (IS_ERR(device)) { 184 if (!IS_ERR(device)) {
192 platform_driver_unregister(&snd_pmac_driver); 185 if (platform_get_drvdata(device))
193 return PTR_ERR(device); 186 return 0;
194 } 187 platform_device_unregister(device);
195 return 0; 188 err = -ENODEV;
189 } else
190 err = PTR_ERR(device);
191 platform_driver_unregister(&snd_pmac_driver);
192 return err;
196 193
197} 194}
198 195
diff --git a/sound/ppc/toonie.c b/sound/ppc/toonie.c
index 1ac7c8552f..e69de29bb2 100644
--- a/sound/ppc/toonie.c
+++ b/sound/ppc/toonie.c
@@ -1,378 +0,0 @@
1/*
2 * Mac Mini "toonie" mixer control
3 *
4 * Copyright (c) 2005 by Benjamin Herrenschmidt <benh@kernel.crashing.org>
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/i2c.h>
25#include <linux/kmod.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <sound/core.h>
29#include <asm/io.h>
30#include <asm/irq.h>
31#include <asm/machdep.h>
32#include <asm/pmac_feature.h>
33#include "pmac.h"
34
35#undef DEBUG
36
37#ifdef DEBUG
38#define DBG(fmt...) printk(fmt)
39#else
40#define DBG(fmt...)
41#endif
42
43struct pmac_gpio {
44 unsigned int addr;
45 u8 active_val;
46 u8 inactive_val;
47 u8 active_state;
48};
49
50struct pmac_toonie
51{
52 struct pmac_gpio hp_detect_gpio;
53 struct pmac_gpio hp_mute_gpio;
54 struct pmac_gpio amp_mute_gpio;
55 int hp_detect_irq;
56 int auto_mute_notify;
57 struct work_struct detect_work;
58};
59
60
61/*
62 * gpio access
63 */
64#define do_gpio_write(gp, val) \
65 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, (gp)->addr, val)
66#define do_gpio_read(gp) \
67 pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, (gp)->addr, 0)
68#define tumbler_gpio_free(gp) /* NOP */
69
70static void write_audio_gpio(struct pmac_gpio *gp, int active)
71{
72 if (! gp->addr)
73 return;
74 active = active ? gp->active_val : gp->inactive_val;
75 do_gpio_write(gp, active);
76 DBG("(I) gpio %x write %d\n", gp->addr, active);
77}
78
79static int check_audio_gpio(struct pmac_gpio *gp)
80{
81 int ret;
82
83 if (! gp->addr)
84 return 0;
85
86 ret = do_gpio_read(gp);
87
88 return (ret & 0xd) == (gp->active_val & 0xd);
89}
90
91static int read_audio_gpio(struct pmac_gpio *gp)
92{
93 int ret;
94 if (! gp->addr)
95 return 0;
96 ret = ((do_gpio_read(gp) & 0x02) !=0);
97 return ret == gp->active_state;
98}
99
100
101enum { TOONIE_MUTE_HP, TOONIE_MUTE_AMP };
102
103static int toonie_get_mute_switch(struct snd_kcontrol *kcontrol,
104 struct snd_ctl_elem_value *ucontrol)
105{
106 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
107 struct pmac_toonie *mix = chip->mixer_data;
108 struct pmac_gpio *gp;
109
110 if (mix == NULL)
111 return -ENODEV;
112 switch(kcontrol->private_value) {
113 case TOONIE_MUTE_HP:
114 gp = &mix->hp_mute_gpio;
115 break;
116 case TOONIE_MUTE_AMP:
117 gp = &mix->amp_mute_gpio;
118 break;
119 default:
120 return -EINVAL;
121 }
122 ucontrol->value.integer.value[0] = !check_audio_gpio(gp);
123 return 0;
124}
125
126static int toonie_put_mute_switch(struct snd_kcontrol *kcontrol,
127 struct snd_ctl_elem_value *ucontrol)
128{
129 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
130 struct pmac_toonie *mix = chip->mixer_data;
131 struct pmac_gpio *gp;
132 int val;
133
134 if (chip->update_automute && chip->auto_mute)
135 return 0; /* don't touch in the auto-mute mode */
136
137 if (mix == NULL)
138 return -ENODEV;
139
140 switch(kcontrol->private_value) {
141 case TOONIE_MUTE_HP:
142 gp = &mix->hp_mute_gpio;
143 break;
144 case TOONIE_MUTE_AMP:
145 gp = &mix->amp_mute_gpio;
146 break;
147 default:
148 return -EINVAL;
149 }
150 val = ! check_audio_gpio(gp);
151 if (val != ucontrol->value.integer.value[0]) {
152 write_audio_gpio(gp, ! ucontrol->value.integer.value[0]);
153 return 1;
154 }
155 return 0;
156}
157
158static struct snd_kcontrol_new toonie_hp_sw __initdata = {
159 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
160 .name = "Headphone Playback Switch",
161 .info = snd_pmac_boolean_mono_info,
162 .get = toonie_get_mute_switch,
163 .put = toonie_put_mute_switch,
164 .private_value = TOONIE_MUTE_HP,
165};
166static struct snd_kcontrol_new toonie_speaker_sw __initdata = {
167 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
168 .name = "PC Speaker Playback Switch",
169 .info = snd_pmac_boolean_mono_info,
170 .get = toonie_get_mute_switch,
171 .put = toonie_put_mute_switch,
172 .private_value = TOONIE_MUTE_AMP,
173};
174
175/*
176 * auto-mute stuffs
177 */
178static int toonie_detect_headphone(struct snd_pmac *chip)
179{
180 struct pmac_toonie *mix = chip->mixer_data;
181 int detect = 0;
182
183 if (mix->hp_detect_gpio.addr)
184 detect |= read_audio_gpio(&mix->hp_detect_gpio);
185 return detect;
186}
187
188static void toonie_check_mute(struct snd_pmac *chip, struct pmac_gpio *gp, int val,
189 int do_notify, struct snd_kcontrol *sw)
190{
191 if (check_audio_gpio(gp) != val) {
192 write_audio_gpio(gp, val);
193 if (do_notify)
194 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
195 &sw->id);
196 }
197}
198
199static void toonie_detect_handler(void *self)
200{
201 struct snd_pmac *chip = (struct snd_pmac *) self;
202 struct pmac_toonie *mix;
203 int headphone;
204
205 if (!chip)
206 return;
207
208 mix = chip->mixer_data;
209 snd_assert(mix, return);
210
211 headphone = toonie_detect_headphone(chip);
212
213 DBG("headphone: %d, lineout: %d\n", headphone, lineout);
214
215 if (headphone) {
216 /* unmute headphone/lineout & mute speaker */
217 toonie_check_mute(chip, &mix->hp_mute_gpio, 0,
218 mix->auto_mute_notify, chip->master_sw_ctl);
219 toonie_check_mute(chip, &mix->amp_mute_gpio, 1,
220 mix->auto_mute_notify, chip->speaker_sw_ctl);
221 } else {
222 /* unmute speaker, mute others */
223 toonie_check_mute(chip, &mix->amp_mute_gpio, 0,
224 mix->auto_mute_notify, chip->speaker_sw_ctl);
225 toonie_check_mute(chip, &mix->hp_mute_gpio, 1,
226 mix->auto_mute_notify, chip->master_sw_ctl);
227 }
228 if (mix->auto_mute_notify) {
229 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
230 &chip->hp_detect_ctl->id);
231 }
232}
233
234static void toonie_update_automute(struct snd_pmac *chip, int do_notify)
235{
236 if (chip->auto_mute) {
237 struct pmac_toonie *mix;
238 mix = chip->mixer_data;
239 snd_assert(mix, return);
240 mix->auto_mute_notify = do_notify;
241 schedule_work(&mix->detect_work);
242 }
243}
244
245/* interrupt - headphone plug changed */
246static irqreturn_t toonie_hp_intr(int irq, void *devid, struct pt_regs *regs)
247{
248 struct snd_pmac *chip = devid;
249
250 if (chip->update_automute && chip->initialized) {
251 chip->update_automute(chip, 1);
252 return IRQ_HANDLED;
253 }
254 return IRQ_NONE;
255}
256
257/* look for audio gpio device */
258static int find_audio_gpio(const char *name, const char *platform,
259 struct pmac_gpio *gp)
260{
261 struct device_node *np;
262 u32 *base, addr;
263
264 if (! (np = find_devices("gpio")))
265 return -ENODEV;
266
267 for (np = np->child; np; np = np->sibling) {
268 char *property = get_property(np, "audio-gpio", NULL);
269 if (property && strcmp(property, name) == 0)
270 break;
271 if (device_is_compatible(np, name))
272 break;
273 }
274 if (np == NULL)
275 return -ENODEV;
276
277 base = (u32 *)get_property(np, "AAPL,address", NULL);
278 if (! base) {
279 base = (u32 *)get_property(np, "reg", NULL);
280 if (!base) {
281 DBG("(E) cannot find address for device %s !\n", name);
282 return -ENODEV;
283 }
284 addr = *base;
285 if (addr < 0x50)
286 addr += 0x50;
287 } else
288 addr = *base;
289
290 gp->addr = addr & 0x0000ffff;
291
292 /* Try to find the active state, default to 0 ! */
293 base = (u32 *)get_property(np, "audio-gpio-active-state", NULL);
294 if (base) {
295 gp->active_state = *base;
296 gp->active_val = (*base) ? 0x5 : 0x4;
297 gp->inactive_val = (*base) ? 0x4 : 0x5;
298 } else {
299 u32 *prop = NULL;
300 gp->active_state = 0;
301 gp->active_val = 0x4;
302 gp->inactive_val = 0x5;
303 /* Here are some crude hacks to extract the GPIO polarity and
304 * open collector informations out of the do-platform script
305 * as we don't yet have an interpreter for these things
306 */
307 if (platform)
308 prop = (u32 *)get_property(np, platform, NULL);
309 if (prop) {
310 if (prop[3] == 0x9 && prop[4] == 0x9) {
311 gp->active_val = 0xd;
312 gp->inactive_val = 0xc;
313 }
314 if (prop[3] == 0x1 && prop[4] == 0x1) {
315 gp->active_val = 0x5;
316 gp->inactive_val = 0x4;
317 }
318 }
319 }
320
321 DBG("(I) GPIO device %s found, offset: %x, active state: %d !\n",
322 name, gp->addr, gp->active_state);
323
324 return (np->n_intrs > 0) ? np->intrs[0].line : 0;
325}
326
327static void toonie_cleanup(struct snd_pmac *chip)
328{
329 struct pmac_toonie *mix = chip->mixer_data;
330 if (! mix)
331 return;
332 if (mix->hp_detect_irq >= 0)
333 free_irq(mix->hp_detect_irq, chip);
334 kfree(mix);
335 chip->mixer_data = NULL;
336}
337
338int __init snd_pmac_toonie_init(struct snd_pmac *chip)
339{
340 struct pmac_toonie *mix;
341
342 mix = kmalloc(sizeof(*mix), GFP_KERNEL);
343 if (! mix)
344 return -ENOMEM;
345
346 chip->mixer_data = mix;
347 chip->mixer_free = toonie_cleanup;
348
349 find_audio_gpio("headphone-mute", NULL, &mix->hp_mute_gpio);
350 find_audio_gpio("amp-mute", NULL, &mix->amp_mute_gpio);
351 mix->hp_detect_irq = find_audio_gpio("headphone-detect",
352 NULL, &mix->hp_detect_gpio);
353
354 strcpy(chip->card->mixername, "PowerMac Toonie");
355
356 chip->master_sw_ctl = snd_ctl_new1(&toonie_hp_sw, chip);
357 snd_ctl_add(chip->card, chip->master_sw_ctl);
358
359 chip->speaker_sw_ctl = snd_ctl_new1(&toonie_speaker_sw, chip);
360 snd_ctl_add(chip->card, chip->speaker_sw_ctl);
361
362 INIT_WORK(&mix->detect_work, toonie_detect_handler, (void *)chip);
363
364 if (mix->hp_detect_irq >= 0) {
365 snd_pmac_add_automute(chip);
366
367 chip->detect_headphone = toonie_detect_headphone;
368 chip->update_automute = toonie_update_automute;
369 toonie_update_automute(chip, 0);
370
371 if (request_irq(mix->hp_detect_irq, toonie_hp_intr, 0,
372 "Sound Headphone Detection", chip) < 0)
373 mix->hp_detect_irq = -1;
374 }
375
376 return 0;
377}
378