2 * linux/sound/oss/dmasound/dmasound_awacs.c
4 * PowerMac `AWACS' and `Burgundy' DMA Sound Driver
5 * with some limited support for DACA & Tumbler
7 * See linux/sound/oss/dmasound/dmasound_core.c for copyright and
8 * history prior to 2001/01/26.
10 * 26/01/2001 ed 0.1 Iain Sandoe
11 * - added version info.
12 * - moved dbdma command buffer allocation to PMacXXXSqSetup()
13 * - fixed up beep dbdma cmd buffers
16 * - make SNDCTL_DSP_GETFMTS return the correct info for the h/w
17 * - move soft format translations to a separate file
18 * - [0.3] make SNDCTL_DSP_GETCAPS return correct info.
19 * - [0.4] more informative machine name strings.
22 * - made the default_hard/soft entries.
24 * - minor correction to bit assignments in awacs_defs.h
25 * - incorporate mixer changes from 2.2.x back-port.
26 * - take out passthru as a rec input (it isn't).
27 * - make Input Gain slider work the 'right way up'.
28 * - try to make the mixer sliders more logical - so now the
29 * input selectors are just two-state (>50% == ON) and the
30 * Input Gain slider handles the rest of the gain issues.
31 * - try to pick slider representations that most closely match
32 * the actual use - e.g. IGain for input gain...
33 * - first stab at over/under-run detection.
34 * - minor cosmetic changes to IRQ identification.
35 * - fix bug where rates > max would be reported as supported.
36 * - first stab at over/under-run detection.
37 * - make use of i2c for mixer settings conditional on perch
38 * rather than cuda (some machines without perch have cuda).
39 * - fix bug where TX stops when dbdma status comes up "DEAD"
40 * so far only reported on PowerComputing clones ... but.
41 * - put in AWACS/Screamer register write timeouts.
42 * - part way to partitioning the init() stuff
43 * - first pass at 'tumbler' stuff (not support - just an attempt
44 * to allow the driver to load on new G4s).
45 * 01/02/2002 [0.7] - BenH
46 * - all sort of minor bits went in since the latest update, I
47 * bumped the version number for that reason
49 * 07/26/2002 [0.8] - BenH
50 * - More minor bits since last changelog (I should be more careful
52 * - Support for snapper & better tumbler integration by Toby Sargeant
53 * - Headphone detect for scremer by Julien Blache
54 * - More tumbler fixed by Andreas Schwab
55 * 11/29/2003 [0.8.1] - Renzo Davoli (King Enzo)
56 * - Support for Snapper line in
57 * - snapper input resampling (for rates < 44100)
58 * - software line gain control
61 /* GENERAL FIXME/TODO: check that the assumptions about what is written to
62 mac-io is valid for DACA & Tumbler.
64 This driver is in bad need of a rewrite. The dbdma code has to be split,
65 some proper device-tree parsing code has to be written, etc...
68 #include <linux/types.h>
69 #include <linux/module.h>
70 #include <linux/config.h>
71 #include <linux/slab.h>
72 #include <linux/init.h>
73 #include <linux/delay.h>
74 #include <linux/soundcard.h>
75 #include <linux/adb.h>
76 #include <linux/nvram.h>
77 #include <linux/tty.h>
78 #include <linux/vt_kern.h>
79 #include <linux/irq.h>
80 #include <linux/spinlock.h>
81 #include <linux/kmod.h>
82 #include <linux/interrupt.h>
83 #include <linux/input.h>
84 #include <asm/semaphore.h>
85 #ifdef CONFIG_ADB_CUDA
86 #include <linux/cuda.h>
89 #include <linux/pmu.h>
92 #include <linux/i2c-dev.h>
94 #include <asm/uaccess.h>
96 #include <asm/machdep.h>
98 #include <asm/dbdma.h>
99 #include <asm/pmac_feature.h>
101 #include <asm/nvram.h>
103 #include "awacs_defs.h"
104 #include "dmasound.h"
105 #include "tas3001c.h"
107 #include "tas_common.h"
109 #define DMASOUND_AWACS_REVISION 0
110 #define DMASOUND_AWACS_EDITION 7
112 #define AWACS_SNAPPER 110 /* fake revision # for snapper */
113 #define AWACS_BURGUNDY 100 /* fake revision # for burgundy */
114 #define AWACS_TUMBLER 90 /* fake revision # for tumbler */
115 #define AWACS_DACA 80 /* fake revision # for daca (ibook) */
116 #define AWACS_AWACS 2 /* holding revision for AWACS */
117 #define AWACS_SCREAMER 3 /* holding revision for Screamer */
119 * Interrupt numbers and addresses, & info obtained from the device tree.
121 static int awacs_irq, awacs_tx_irq, awacs_rx_irq;
122 static volatile struct awacs_regs *awacs;
123 static volatile u32 *i2s;
124 static volatile struct dbdma_regs *awacs_txdma, *awacs_rxdma;
125 static int awacs_rate_index;
126 static int awacs_subframe;
127 static struct device_node* awacs_node;
128 static struct device_node* i2s_node;
130 static char awacs_name[64];
131 static int awacs_revision;
132 static int awacs_sleeping;
133 static DECLARE_MUTEX(dmasound_sem);
135 static int sound_device_id; /* exists after iMac revA */
136 static int hw_can_byteswap = 1 ; /* most pmac sound h/w can */
139 /* To be replaced with better interaction with pmac_feature.c */
140 static int is_pbook_3X00;
141 static int is_pbook_g3;
144 static int has_perch;
147 /* for earlier powerbooks which need fiddling with mac-io to enable
150 static unsigned char *latch_base;
151 static unsigned char *macio_base;
154 * Space for the DBDMA command blocks.
156 static void *awacs_tx_cmd_space;
157 static volatile struct dbdma_cmd *awacs_tx_cmds;
158 static int number_of_tx_cmd_buffers;
160 static void *awacs_rx_cmd_space;
161 static volatile struct dbdma_cmd *awacs_rx_cmds;
162 static int number_of_rx_cmd_buffers;
165 * Cached values of AWACS registers (we can't read them).
166 * Except on the burgundy (and screamer). XXX
172 /* tracking values for the mixer contents
177 static int passthru_vol;
179 static int ip_gain; /* mic preamp settings */
180 static int rec_lev = 0x4545 ; /* default CD gain 69 % */
182 static int cd_lev = 0x6363 ; /* 99 % */
185 static int hdp_connected;
188 * Stuff for outputting a beep. The values range from -327 to +327
189 * so we can multiply by an amplitude in the range 0..100 to get a
190 * signed short value to put in the output buffer.
192 static short beep_wform[256] = {
193 0, 40, 79, 117, 153, 187, 218, 245,
194 269, 288, 304, 316, 323, 327, 327, 324,
195 318, 310, 299, 288, 275, 262, 249, 236,
196 224, 213, 204, 196, 190, 186, 183, 182,
197 182, 183, 186, 189, 192, 196, 200, 203,
198 206, 208, 209, 209, 209, 207, 204, 201,
199 197, 193, 188, 183, 179, 174, 170, 166,
200 163, 161, 160, 159, 159, 160, 161, 162,
201 164, 166, 168, 169, 171, 171, 171, 170,
202 169, 167, 163, 159, 155, 150, 144, 139,
203 133, 128, 122, 117, 113, 110, 107, 105,
204 103, 103, 103, 103, 104, 104, 105, 105,
205 105, 103, 101, 97, 92, 86, 78, 68,
206 58, 45, 32, 18, 3, -11, -26, -41,
207 -55, -68, -79, -88, -95, -100, -102, -102,
208 -99, -93, -85, -75, -62, -48, -33, -16,
209 0, 16, 33, 48, 62, 75, 85, 93,
210 99, 102, 102, 100, 95, 88, 79, 68,
211 55, 41, 26, 11, -3, -18, -32, -45,
212 -58, -68, -78, -86, -92, -97, -101, -103,
213 -105, -105, -105, -104, -104, -103, -103, -103,
214 -103, -105, -107, -110, -113, -117, -122, -128,
215 -133, -139, -144, -150, -155, -159, -163, -167,
216 -169, -170, -171, -171, -171, -169, -168, -166,
217 -164, -162, -161, -160, -159, -159, -160, -161,
218 -163, -166, -170, -174, -179, -183, -188, -193,
219 -197, -201, -204, -207, -209, -209, -209, -208,
220 -206, -203, -200, -196, -192, -189, -186, -183,
221 -182, -182, -183, -186, -190, -196, -204, -213,
222 -224, -236, -249, -262, -275, -288, -299, -310,
223 -318, -324, -327, -327, -323, -316, -304, -288,
224 -269, -245, -218, -187, -153, -117, -79, -40,
228 #define BEEP_SRATE 22050 /* 22050 Hz sample rate */
229 #define BEEP_BUFLEN 512
230 #define BEEP_VOLUME 15 /* 0 - 100 */
232 static int beep_vol = BEEP_VOLUME;
233 static int beep_playing;
234 static int awacs_beep_state;
235 static short *beep_buf;
236 static void *beep_dbdma_cmd_space;
237 static volatile struct dbdma_cmd *beep_dbdma_cmd;
239 /* Burgundy functions */
240 static void awacs_burgundy_wcw(unsigned addr,unsigned newval);
241 static unsigned awacs_burgundy_rcw(unsigned addr);
242 static void awacs_burgundy_write_volume(unsigned address, int volume);
243 static int awacs_burgundy_read_volume(unsigned address);
244 static void awacs_burgundy_write_mvolume(unsigned address, int volume);
245 static int awacs_burgundy_read_mvolume(unsigned address);
247 /* we will allocate a single 'emergency' dbdma cmd block to use if the
248 tx status comes up "DEAD". This happens on some PowerComputing Pmac
249 clones, either owing to a bug in dbdma or some interaction between
250 IDE and sound. However, this measure would deal with DEAD status if
251 if appeared elsewhere.
253 for the sake of memory efficiency we'll allocate this cmd as part of
257 static volatile struct dbdma_cmd *emergency_dbdma_cmd;
259 #ifdef CONFIG_PMAC_PBOOK
261 * Stuff for restoring after a sleep.
263 static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
264 struct pmu_sleep_notifier awacs_sleep_notifier = {
265 awacs_sleep_notify, SLEEP_LEVEL_SOUND,
267 #endif /* CONFIG_PMAC_PBOOK */
269 /* for (soft) sample rate translations */
270 int expand_bal; /* Balance factor for expanding (not volume!) */
271 int expand_read_bal; /* Balance factor for expanding reads (not volume!) */
273 /*** Low level stuff *********************************************************/
275 static void *PMacAlloc(unsigned int size, int flags);
276 static void PMacFree(void *ptr, unsigned int size);
277 static int PMacIrqInit(void);
279 static void PMacIrqCleanup(void);
281 static void PMacSilence(void);
282 static void PMacInit(void);
283 static int PMacSetFormat(int format);
284 static int PMacSetVolume(int volume);
285 static void PMacPlay(void);
286 static void PMacRecord(void);
287 static irqreturn_t pmac_awacs_tx_intr(int irq, void *devid, struct pt_regs *regs);
288 static irqreturn_t pmac_awacs_rx_intr(int irq, void *devid, struct pt_regs *regs);
289 static irqreturn_t pmac_awacs_intr(int irq, void *devid, struct pt_regs *regs);
290 static void awacs_write(int val);
291 static int awacs_get_volume(int reg, int lshift);
292 static int awacs_volume_setter(int volume, int n, int mute, int lshift);
295 /*** Mid level stuff **********************************************************/
297 static int PMacMixerIoctl(u_int cmd, u_long arg);
298 static int PMacWriteSqSetup(void);
299 static int PMacReadSqSetup(void);
300 static void PMacAbortRead(void);
302 extern TRANS transAwacsNormal ;
303 extern TRANS transAwacsExpand ;
304 extern TRANS transAwacsNormalRead ;
305 extern TRANS transAwacsExpandRead ;
307 extern int daca_init(void);
308 extern void daca_cleanup(void);
309 extern int daca_set_volume(uint left_vol, uint right_vol);
310 extern void daca_get_volume(uint * left_vol, uint *right_vol);
311 extern int daca_enter_sleep(void);
312 extern int daca_leave_sleep(void);
315 if ((rc = down_interruptible(&dmasound_sem)) != 0) \
317 #define LOCK() down(&dmasound_sem);
319 #define UNLOCK() up(&dmasound_sem);
321 /* We use different versions that the ones provided in dmasound.h
323 * FIXME: Use different names ;)
328 #define IOCTL_IN(arg, ret) \
329 rc = get_user(ret, (int __user *)(arg)); \
331 #define IOCTL_OUT(arg, ret) \
332 ioctl_return2((int __user *)(arg), ret)
334 static inline int ioctl_return2(int __user *addr, int value)
336 return value < 0 ? value : put_user(value, addr);
340 /*** AE - TUMBLER / SNAPPER START ************************************************/
343 int gpio_audio_reset, gpio_audio_reset_pol;
344 int gpio_amp_mute, gpio_amp_mute_pol;
345 int gpio_headphone_mute, gpio_headphone_mute_pol;
346 int gpio_headphone_detect, gpio_headphone_detect_pol;
347 int gpio_headphone_irq;
350 setup_audio_gpio(const char *name, const char* compatible, int *gpio_addr, int* gpio_pol)
352 struct device_node *np;
355 np = find_devices("gpio");
362 char *property = get_property(np,"audio-gpio",NULL);
363 if (property != 0 && strcmp(property,name) == 0)
365 } else if (compatible && device_is_compatible(np, compatible))
371 pp = (u32 *)get_property(np, "AAPL,address", NULL);
374 *gpio_addr = (*pp) & 0x0000ffff;
375 pp = (u32 *)get_property(np, "audio-gpio-active-state", NULL);
381 return np->intrs[0].line;
387 write_audio_gpio(int gpio_addr, int data)
391 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_addr, data ? 0x05 : 0x04);
395 read_audio_gpio(int gpio_addr)
399 return ((pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_addr, 0) & 0x02) !=0);
403 * Headphone interrupt via GPIO (Tumbler, Snapper, DACA)
406 headphone_intr(int irq, void *devid, struct pt_regs *regs)
410 spin_lock_irqsave(&dmasound.lock, flags);
411 if (read_audio_gpio(gpio_headphone_detect) == gpio_headphone_detect_pol) {
412 printk(KERN_INFO "Audio jack plugged, muting speakers.\n");
413 write_audio_gpio(gpio_headphone_mute, !gpio_headphone_mute_pol);
414 write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
415 tas_output_device_change(sound_device_id,TAS_OUTPUT_HEADPHONES,0);
417 printk(KERN_INFO "Audio jack unplugged, enabling speakers.\n");
418 write_audio_gpio(gpio_amp_mute, !gpio_amp_mute_pol);
419 write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
420 tas_output_device_change(sound_device_id,TAS_OUTPUT_INTERNAL_SPKR,0);
422 spin_unlock_irqrestore(&dmasound.lock, flags);
427 /* Initialize tumbler */
430 tas_dmasound_init(void)
436 &gpio_audio_reset_pol);
442 setup_audio_gpio("headphone-mute",
444 &gpio_headphone_mute,
445 &gpio_headphone_mute_pol);
446 gpio_headphone_irq = setup_audio_gpio(
449 &gpio_headphone_detect,
450 &gpio_headphone_detect_pol);
451 /* Fix some broken OF entries in desktop machines */
452 if (!gpio_headphone_irq)
453 gpio_headphone_irq = setup_audio_gpio(
456 &gpio_headphone_detect,
457 &gpio_headphone_detect_pol);
459 write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
461 write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
463 if (gpio_headphone_irq) {
464 if (request_irq(gpio_headphone_irq,headphone_intr,0,"Headphone detect",NULL) < 0) {
465 printk(KERN_ERR "tumbler: Can't request headphone interrupt\n");
466 gpio_headphone_irq = 0;
469 /* Activate headphone status interrupts */
470 val = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_headphone_detect, 0);
471 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_headphone_detect, val | 0x80);
473 headphone_intr(0,NULL,NULL);
476 if (!gpio_headphone_irq) {
477 /* Some machine enter this case ? */
478 printk(KERN_WARNING "tumbler: Headphone detect IRQ not found, enabling all outputs !\n");
479 write_audio_gpio(gpio_amp_mute, !gpio_amp_mute_pol);
480 write_audio_gpio(gpio_headphone_mute, !gpio_headphone_mute_pol);
487 tas_dmasound_cleanup(void)
489 if (gpio_headphone_irq)
490 free_irq(gpio_headphone_irq, NULL);
494 /* We don't support 48k yet */
495 static int tas_freqs[1] = { 44100 } ;
496 static int tas_freqs_ok[1] = { 1 } ;
498 /* don't know what to do really - just have to leave it where
503 tas_set_frame_rate(void)
506 out_le32(i2s + (I2S_REG_SERIAL_FORMAT >> 2), 0x41190000);
507 out_le32(i2s + (I2S_REG_DATAWORD_SIZES >> 2), 0x02000200);
509 dmasound.hard.speed = 44100 ;
510 awacs_rate_index = 0 ;
515 tas_mixer_ioctl(u_int cmd, u_long arg)
517 int __user *argp = (int __user *)arg;
521 rc=tas_device_ioctl(cmd, arg);
526 if ((cmd & ~0xff) == MIXER_WRITE(0) &&
527 tas_supported_mixers() & (1<<(cmd & 0xff))) {
528 rc = get_user(data, argp);
530 tas_set_mixer_level(cmd & 0xff, data);
531 tas_get_mixer_level(cmd & 0xff, &data);
532 return ioctl_return2(argp, data);
534 if ((cmd & ~0xff) == MIXER_READ(0) &&
535 tas_supported_mixers() & (1<<(cmd & 0xff))) {
536 tas_get_mixer_level(cmd & 0xff, &data);
537 return ioctl_return2(argp, data);
541 case SOUND_MIXER_READ_DEVMASK:
542 data = tas_supported_mixers() | SOUND_MASK_SPEAKER;
543 rc = IOCTL_OUT(arg, data);
545 case SOUND_MIXER_READ_STEREODEVS:
546 data = tas_stereo_mixers();
547 rc = IOCTL_OUT(arg, data);
549 case SOUND_MIXER_READ_CAPS:
550 rc = IOCTL_OUT(arg, 0);
552 case SOUND_MIXER_READ_RECMASK:
553 // XXX FIXME: find a way to check what is really available */
554 data = SOUND_MASK_LINE | SOUND_MASK_MIC;
555 rc = IOCTL_OUT(arg, data);
557 case SOUND_MIXER_READ_RECSRC:
558 if (awacs_reg[0] & MASK_MUX_AUDIN)
559 data |= SOUND_MASK_LINE;
560 if (awacs_reg[0] & MASK_MUX_MIC)
561 data |= SOUND_MASK_MIC;
562 rc = IOCTL_OUT(arg, data);
564 case SOUND_MIXER_WRITE_RECSRC:
567 rc = IOCTL_OUT(arg, data);
569 case SOUND_MIXER_WRITE_SPEAKER: /* really bell volume */
571 beep_vol = data & 0xff;
573 case SOUND_MIXER_READ_SPEAKER:
574 rc = IOCTL_OUT(arg, (beep_vol<<8) | beep_vol);
576 case SOUND_MIXER_OUTMASK:
577 case SOUND_MIXER_OUTSRC:
586 tas_init_frame_rates(unsigned int *prop, unsigned int l)
592 for (l /= sizeof(int); l > 0; --l) {
593 unsigned int r = *prop++;
594 /* Apple 'Fixed' format */
597 for (i = 0; i < 1; ++i) {
598 if (r == tas_freqs[i]) {
605 /* else we assume that all the rates are available */
609 /*** AE - TUMBLER / SNAPPER END ************************************************/
613 /*** Low level stuff *********************************************************/
616 * PCI PowerMac, with AWACS, Screamer, Burgundy, DACA or Tumbler and DBDMA.
618 static void *PMacAlloc(unsigned int size, int flags)
620 return kmalloc(size, flags);
623 static void PMacFree(void *ptr, unsigned int size)
628 static int __init PMacIrqInit(void)
631 if (request_irq(awacs_irq, pmac_awacs_intr, 0, "Built-in Sound misc", NULL))
633 if (request_irq(awacs_tx_irq, pmac_awacs_tx_intr, 0, "Built-in Sound out", NULL)
634 || request_irq(awacs_rx_irq, pmac_awacs_rx_intr, 0, "Built-in Sound in", NULL))
640 static void PMacIrqCleanup(void)
642 /* turn off input & output dma */
643 DBDMA_DO_STOP(awacs_txdma);
644 DBDMA_DO_STOP(awacs_rxdma);
647 /* disable interrupts from awacs interface */
648 out_le32(&awacs->control, in_le32(&awacs->control) & 0xfff);
650 /* Switch off the sound clock */
651 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 0);
652 /* Make sure proper bits are set on pismo & tipb */
653 if ((machine_is_compatible("PowerBook3,1") ||
654 machine_is_compatible("PowerBook3,2")) && awacs) {
655 awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
656 awacs_write(MASK_ADDR1 | awacs_reg[1]);
660 free_irq(awacs_irq, NULL);
661 free_irq(awacs_tx_irq, NULL);
662 free_irq(awacs_rx_irq, NULL);
665 iounmap((void *)awacs);
667 iounmap((void *)i2s);
668 iounmap((void *)awacs_txdma);
669 iounmap((void *)awacs_rxdma);
671 release_OF_resource(awacs_node, 0);
672 release_OF_resource(awacs_node, 1);
673 release_OF_resource(awacs_node, 2);
675 if (awacs_tx_cmd_space)
676 kfree(awacs_tx_cmd_space);
677 if (awacs_rx_cmd_space)
678 kfree(awacs_rx_cmd_space);
679 if (beep_dbdma_cmd_space)
680 kfree(beep_dbdma_cmd_space);
683 #ifdef CONFIG_PMAC_PBOOK
684 pmu_unregister_sleep_notifier(&awacs_sleep_notifier);
689 static void PMacSilence(void)
691 /* turn off output dma */
692 DBDMA_DO_STOP(awacs_txdma);
695 /* don't know what to do really - just have to leave it where
699 static int daca_set_frame_rate(void)
702 out_le32(i2s + (I2S_REG_SERIAL_FORMAT >> 2), 0x41190000);
703 out_le32(i2s + (I2S_REG_DATAWORD_SIZES >> 2), 0x02000200);
705 dmasound.hard.speed = 44100 ;
706 awacs_rate_index = 0 ;
710 static int awacs_freqs[8] = {
711 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
713 static int awacs_freqs_ok[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
716 awacs_set_frame_rate(int desired, int catch_r)
718 int tolerance, i = 8 ;
720 * If we have a sample rate which is within catchRadius percent
721 * of the requested value, we don't have to expand the samples.
722 * Otherwise choose the next higher rate.
723 * N.B.: burgundy awacs only works at 44100 Hz.
726 tolerance = catch_r * awacs_freqs[--i] / 100;
727 if (awacs_freqs_ok[i]
728 && dmasound.soft.speed <= awacs_freqs[i] + tolerance)
731 dmasound.hard.speed = awacs_freqs[i];
732 awacs_rate_index = i;
734 out_le32(&awacs->control, MASK_IEPC | (i << 8) | 0x11 );
735 awacs_reg[1] = (awacs_reg[1] & ~MASK_SAMPLERATE) | (i << 3);
736 awacs_write(awacs_reg[1] | MASK_ADDR1);
737 return dmasound.hard.speed;
741 burgundy_set_frame_rate(void)
743 awacs_rate_index = 0 ;
744 awacs_reg[1] = (awacs_reg[1] & ~MASK_SAMPLERATE) ;
745 /* XXX disable error interrupt on burgundy for now */
746 out_le32(&awacs->control, MASK_IEPC | 0 | 0x11 | MASK_IEE);
751 set_frame_rate(int desired, int catch_r)
753 switch (awacs_revision) {
755 dmasound.hard.speed = burgundy_set_frame_rate();
759 dmasound.hard.speed = tas_set_frame_rate();
762 dmasound.hard.speed =
763 daca_set_frame_rate();
766 dmasound.hard.speed = awacs_set_frame_rate(desired,
770 return dmasound.hard.speed ;
774 awacs_recalibrate(void)
776 /* Sorry for the horrible delays... I hope to get that improved
777 * by making the whole PM process asynchronous in a future version
780 awacs_reg[1] |= MASK_CMUTE | MASK_AMUTE;
781 awacs_write(awacs_reg[1] | MASK_RECALIBRATE | MASK_ADDR1);
783 awacs_write(awacs_reg[1] | MASK_ADDR1);
786 static void PMacInit(void)
790 switch (dmasound.soft.format) {
794 dmasound.hard.format = AFMT_S16_LE;
796 dmasound.hard.format = AFMT_S16_BE;
799 dmasound.hard.format = AFMT_S16_BE;
802 dmasound.hard.stereo = 1;
803 dmasound.hard.size = 16;
805 /* set dmasound.hard.speed - on the basis of what we want (soft)
806 * and the tolerance we'll allow.
808 set_frame_rate(dmasound.soft.speed, catchRadius) ;
810 tolerance = (catchRadius * dmasound.hard.speed) / 100;
811 if (dmasound.soft.speed >= dmasound.hard.speed - tolerance) {
812 dmasound.trans_write = &transAwacsNormal;
813 dmasound.trans_read = &transAwacsNormalRead;
815 dmasound.trans_write = &transAwacsExpand;
816 dmasound.trans_read = &transAwacsExpandRead;
820 if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE))
821 out_le32(&awacs->byteswap, BS_VAL);
823 out_le32(&awacs->byteswap, 0);
826 expand_bal = -dmasound.soft.speed;
827 expand_read_bal = -dmasound.soft.speed;
830 static int PMacSetFormat(int format)
833 int req_format = format;
837 return dmasound.soft.format;
846 format = AFMT_S16_BE;
852 format = AFMT_U16_BE;
857 printk(KERN_ERR "dmasound: unknown format 0x%x, using AFMT_U8\n",
863 if (req_format == format) {
864 dmasound.soft.format = format;
865 dmasound.soft.size = size;
866 if (dmasound.minDev == SND_DEV_DSP) {
867 dmasound.dsp.format = format;
868 dmasound.dsp.size = size;
875 #define AWACS_VOLUME_TO_MASK(x) (15 - ((((x) - 1) * 15) / 99))
876 #define AWACS_MASK_TO_VOLUME(y) (100 - ((y) * 99 / 15))
878 static int awacs_get_volume(int reg, int lshift)
882 volume = AWACS_MASK_TO_VOLUME((reg >> lshift) & 0xf);
883 volume |= AWACS_MASK_TO_VOLUME(reg & 0xf) << 8;
887 static int awacs_volume_setter(int volume, int n, int mute, int lshift)
891 if (mute && volume == 0) {
892 r1 = awacs_reg[1] | mute;
894 r1 = awacs_reg[1] & ~mute;
895 rn = awacs_reg[n] & ~(0xf | (0xf << lshift));
896 rn |= ((AWACS_VOLUME_TO_MASK(volume & 0xff) & 0xf) << lshift);
897 rn |= AWACS_VOLUME_TO_MASK((volume >> 8) & 0xff) & 0xf;
899 awacs_write((n << 12) | rn);
900 volume = awacs_get_volume(rn, lshift);
902 if (r1 != awacs_reg[1]) {
904 awacs_write(r1 | MASK_ADDR1);
909 static int PMacSetVolume(int volume)
911 printk(KERN_WARNING "Bogus call to PMacSetVolume !\n");
915 static void awacs_setup_for_beep(int speed)
917 out_le32(&awacs->control,
918 (in_le32(&awacs->control) & ~0x1f00)
919 | ((speed > 0 ? speed : awacs_rate_index) << 8));
921 if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE) && speed == -1)
922 out_le32(&awacs->byteswap, BS_VAL);
924 out_le32(&awacs->byteswap, 0);
927 /* CHECK: how much of this *really* needs IRQs masked? */
928 static void __PMacPlay(void)
930 volatile struct dbdma_cmd *cp;
933 count = 300 ; /* > two cycles at the lowest sample rate */
935 /* what we want to send next */
936 next_frg = (write_sq.front + write_sq.active) % write_sq.max_count;
938 if (awacs_beep_state) {
939 /* sound takes precedence over beeps */
940 /* stop the dma channel */
941 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
942 while ( (in_le32(&awacs_txdma->status) & RUN) && count--)
945 awacs_setup_for_beep(-1);
946 out_le32(&awacs_txdma->cmdptr,
947 virt_to_bus(&(awacs_tx_cmds[next_frg])));
950 awacs_beep_state = 0;
952 /* this won't allow more than two frags to be in the output queue at
953 once. (or one, if the max frags is 2 - because count can't exceed
956 while (write_sq.active < 2 && write_sq.active < write_sq.count) {
957 count = (write_sq.count == write_sq.active + 1) ?
958 write_sq.rear_size:write_sq.block_size ;
959 if (count < write_sq.block_size) {
960 if (!write_sq.syncing) /* last block not yet filled,*/
961 break; /* and we're not syncing or POST-ed */
963 /* pretend the block is full to force a new
964 block to be started on the next write */
965 write_sq.rear_size = write_sq.block_size ;
966 write_sq.syncing &= ~2 ; /* clear POST */
969 cp = &awacs_tx_cmds[next_frg];
970 st_le16(&cp->req_count, count);
971 st_le16(&cp->xfer_status, 0);
972 st_le16(&cp->command, OUTPUT_MORE + INTR_ALWAYS);
973 /* put a STOP at the end of the queue - but only if we have
974 space for it. This means that, if we under-run and we only
975 have two fragments, we might re-play sound from an existing
976 queued frag. I guess the solution to that is not to set two
977 frags if you are likely to under-run...
979 if (write_sq.count < write_sq.max_count) {
980 if (++next_frg >= write_sq.max_count)
981 next_frg = 0 ; /* wrap */
982 /* if we get here then we've underrun so we will stop*/
983 st_le16(&awacs_tx_cmds[next_frg].command, DBDMA_STOP);
985 /* set the dbdma controller going, if it is not already */
986 if (write_sq.active == 0)
987 out_le32(&awacs_txdma->cmdptr, virt_to_bus(cp));
988 (void)in_le32(&awacs_txdma->status);
989 out_le32(&awacs_txdma->control, ((RUN|WAKE) << 16) + (RUN|WAKE));
994 static void PMacPlay(void)
997 if (!awacs_sleeping) {
1000 spin_lock_irqsave(&dmasound.lock, flags);
1002 spin_unlock_irqrestore(&dmasound.lock, flags);
1007 static void PMacRecord(void)
1009 unsigned long flags;
1014 spin_lock_irqsave(&dmasound.lock, flags);
1016 /* This is all we have to do......Just start it up.
1018 out_le32(&awacs_rxdma->control, ((RUN|WAKE) << 16) + (RUN|WAKE));
1021 spin_unlock_irqrestore(&dmasound.lock, flags);
1024 /* if the TX status comes up "DEAD" - reported on some Power Computing machines
1025 we need to re-start the dbdma - but from a different physical start address
1026 and with a different transfer length. It would get very messy to do this
1027 with the normal dbdma_cmd blocks - we would have to re-write the buffer start
1028 addresses each time. So, we will keep a single dbdma_cmd block which can be
1030 When DEAD status is first reported the content of the faulted dbdma block is
1031 copied into the emergency buffer and we note that the buffer is in use.
1032 we then bump the start physical address by the amount that was successfully
1033 output before it died.
1034 On any subsequent DEAD result we just do the bump-ups (we know that we are
1035 already using the emergency dbdma_cmd).
1036 CHECK: this just tries to "do it". It is possible that we should abandon
1037 xfers when the number of residual bytes gets below a certain value - I can
1038 see that this might cause a loop-forever if too small a transfer causes
1039 DEAD status. However this is a TODO for now - we'll see what gets reported.
1040 When we get a successful transfer result with the emergency buffer we just
1041 pretend that it completed using the original dmdma_cmd and carry on. The
1042 'next_cmd' field will already point back to the original loop of blocks.
1046 pmac_awacs_tx_intr(int irq, void *devid, struct pt_regs *regs)
1048 int i = write_sq.front;
1050 int i_nowrap = write_sq.front;
1051 volatile struct dbdma_cmd *cp;
1052 /* != 0 when we are dealing with a DEAD xfer */
1053 static int emergency_in_use;
1055 spin_lock(&dmasound.lock);
1056 while (write_sq.active > 0) { /* we expect to have done something*/
1057 if (emergency_in_use) /* we are dealing with DEAD xfer */
1058 cp = emergency_dbdma_cmd ;
1060 cp = &awacs_tx_cmds[i];
1061 stat = ld_le16(&cp->xfer_status);
1063 unsigned short req, res ;
1065 #ifdef DEBUG_DMASOUND
1066 printk("dmasound_pmac: tx-irq: xfer died - patching it up...\n") ;
1068 /* to clear DEAD status we must first clear RUN
1069 set it to quiescent to be on the safe side */
1070 (void)in_le32(&awacs_txdma->status);
1071 out_le32(&awacs_txdma->control,
1072 (RUN|PAUSE|FLUSH|WAKE) << 16);
1074 if (!emergency_in_use) { /* new problem */
1075 memcpy((void *)emergency_dbdma_cmd, (void *)cp,
1076 sizeof(struct dbdma_cmd));
1077 emergency_in_use = 1;
1078 cp = emergency_dbdma_cmd;
1080 /* now bump the values to reflect the amount
1081 we haven't yet shifted */
1082 req = ld_le16(&cp->req_count);
1083 res = ld_le16(&cp->res_count);
1084 phy = ld_le32(&cp->phy_addr);
1086 st_le16(&cp->req_count, res);
1087 st_le16(&cp->res_count, 0);
1088 st_le16(&cp->xfer_status, 0);
1089 st_le32(&cp->phy_addr, phy);
1090 st_le32(&cp->cmd_dep, virt_to_bus(&awacs_tx_cmds[(i+1)%write_sq.max_count]));
1091 st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS);
1093 /* point at our patched up command block */
1094 out_le32(&awacs_txdma->cmdptr, virt_to_bus(cp));
1095 /* we must re-start the controller */
1096 (void)in_le32(&awacs_txdma->status);
1097 /* should complete clearing the DEAD status */
1098 out_le32(&awacs_txdma->control,
1099 ((RUN|WAKE) << 16) + (RUN|WAKE));
1100 break; /* this block is still going */
1102 if ((stat & ACTIVE) == 0)
1103 break; /* this frame is still going */
1104 if (emergency_in_use)
1105 emergency_in_use = 0 ; /* done that */
1109 if (++i >= write_sq.max_count)
1113 /* if we stopped and we were not sync-ing - then we under-ran */
1114 if( write_sq.syncing == 0 ){
1115 stat = in_le32(&awacs_txdma->status) ;
1116 /* we hit the dbdma_stop */
1117 if( (stat & ACTIVE) == 0 ) write_sq.xruns++ ;
1120 /* if we used some data up then wake the writer to supply some more*/
1121 if (i_nowrap != write_sq.front)
1122 WAKE_UP(write_sq.action_queue);
1125 /* but make sure we funnel what we've already got */\
1126 if (!awacs_sleeping)
1129 /* make the wake-on-empty conditional on syncing */
1130 if (!write_sq.active && (write_sq.syncing & 1))
1131 WAKE_UP(write_sq.sync_queue); /* any time we're empty */
1132 spin_unlock(&dmasound.lock);
1138 pmac_awacs_rx_intr(int irq, void *devid, struct pt_regs *regs)
1141 /* For some reason on my PowerBook G3, I get one interrupt
1142 * when the interrupt vector is installed (like something is
1143 * pending). This happens before the dbdma is initialized by
1144 * us, so I just check the command pointer and if it is zero,
1147 if (in_le32(&awacs_rxdma->cmdptr) == 0)
1150 /* We also want to blow 'em off when shutting down.
1152 if (read_sq.active == 0)
1155 spin_lock(&dmasound.lock);
1156 /* Check multiple buffers in case we were held off from
1157 * interrupt processing for a long time. Geeze, I really hope
1158 * this doesn't happen.
1160 while ((stat=awacs_rx_cmds[read_sq.rear].xfer_status)) {
1162 /* if we got a "DEAD" status then just log it for now.
1163 and try to restart dma.
1164 TODO: figure out how best to fix it up
1167 #ifdef DEBUG_DMASOUND
1168 printk("dmasound_pmac: rx-irq: DIED - attempting resurection\n");
1170 /* to clear DEAD status we must first clear RUN
1171 set it to quiescent to be on the safe side */
1172 (void)in_le32(&awacs_txdma->status);
1173 out_le32(&awacs_txdma->control,
1174 (RUN|PAUSE|FLUSH|WAKE) << 16);
1175 awacs_rx_cmds[read_sq.rear].xfer_status = 0;
1176 awacs_rx_cmds[read_sq.rear].res_count = 0;
1178 (void)in_le32(&awacs_txdma->status);
1179 /* re-start the same block */
1180 out_le32(&awacs_rxdma->cmdptr,
1181 virt_to_bus(&awacs_rx_cmds[read_sq.rear]));
1182 /* we must re-start the controller */
1183 (void)in_le32(&awacs_rxdma->status);
1184 /* should complete clearing the DEAD status */
1185 out_le32(&awacs_rxdma->control,
1186 ((RUN|WAKE) << 16) + (RUN|WAKE));
1187 spin_unlock(&dmasound.lock);
1188 return IRQ_HANDLED; /* try this block again */
1190 /* Clear status and move on to next buffer.
1192 awacs_rx_cmds[read_sq.rear].xfer_status = 0;
1195 /* Wrap the buffer ring.
1197 if (read_sq.rear >= read_sq.max_active)
1200 /* If we have caught up to the front buffer, bump it.
1201 * This will cause weird (but not fatal) results if the
1202 * read loop is currently using this buffer. The user is
1203 * behind in this case anyway, so weird things are going
1206 if (read_sq.rear == read_sq.front) {
1208 read_sq.xruns++ ; /* we overan */
1209 if (read_sq.front >= read_sq.max_active)
1214 WAKE_UP(read_sq.action_queue);
1215 spin_unlock(&dmasound.lock);
1221 pmac_awacs_intr(int irq, void *devid, struct pt_regs *regs)
1227 spin_lock(&dmasound.lock);
1228 ctrl = in_le32(&awacs->control);
1229 status = in_le32(&awacs->codec_stat);
1231 if (ctrl & MASK_PORTCHG) {
1232 /* tested on Screamer, should work on others too */
1233 if (awacs_revision == AWACS_SCREAMER) {
1234 if (((status & MASK_HDPCONN) >> 3) && (hdp_connected == 0)) {
1237 r1 = awacs_reg[1] | MASK_SPKMUTE;
1239 awacs_write(r1 | MASK_ADDR_MUTE);
1240 } else if (((status & MASK_HDPCONN) >> 3 == 0) && (hdp_connected == 1)) {
1243 r1 = awacs_reg[1] & ~MASK_SPKMUTE;
1245 awacs_write(r1 | MASK_ADDR_MUTE);
1249 if (ctrl & MASK_CNTLERR) {
1250 int err = (in_le32(&awacs->codec_stat) & MASK_ERRCODE) >> 16;
1251 /* CHECK: we just swallow burgundy errors at the moment..*/
1252 if (err != 0 && awacs_revision != AWACS_BURGUNDY)
1253 printk(KERN_ERR "dmasound_pmac: error %x\n", err);
1255 /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */
1256 out_le32(&awacs->control, ctrl);
1257 spin_unlock(&dmasound.lock);
1262 awacs_write(int val)
1265 if (awacs_revision >= AWACS_DACA || !awacs)
1268 while ((in_le32(&awacs->codec_ctrl) & MASK_NEWECMD) && count--)
1269 udelay(1) ; /* timeout is > 2 samples at lowest rate */
1270 out_le32(&awacs->codec_ctrl, val | (awacs_subframe << 22));
1271 (void)in_le32(&awacs->byteswap);
1274 /* this is called when the beep timer expires... it will be called even
1275 if the beep has been overidden by other sound output.
1277 static void awacs_nosound(unsigned long xx)
1279 unsigned long flags;
1280 int count = 600 ; /* > four samples at lowest rate */
1282 spin_lock_irqsave(&dmasound.lock, flags);
1284 st_le16(&beep_dbdma_cmd->command, DBDMA_STOP);
1285 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
1286 while ((in_le32(&awacs_txdma->status) & RUN) && count--)
1289 awacs_setup_for_beep(-1);
1292 spin_unlock_irqrestore(&dmasound.lock, flags);
1296 * We generate the beep with a single dbdma command that loops a buffer
1297 * forever - without generating interrupts.
1299 * So, to stop it you have to stop dma output as per awacs_nosound.
1301 static int awacs_beep_event(struct input_dev *dev, unsigned int type,
1302 unsigned int code, int hz)
1304 unsigned long flags;
1307 int period, ncycles, nsamples;
1310 static int beep_hz_cache;
1311 static int beep_nsamples_cache;
1312 static int beep_volume_cache;
1327 if (beep_buf == NULL)
1330 /* quick-hack fix for DACA, Burgundy & Tumbler */
1332 if (awacs_revision >= AWACS_DACA){
1335 for (i = 0; i < 8 && awacs_freqs[i] >= BEEP_SRATE; ++i)
1336 if (awacs_freqs_ok[i])
1338 srate = awacs_freqs[beep_speed];
1341 if (hz <= srate / BEEP_BUFLEN || hz > srate / 2) {
1342 /* cancel beep currently playing */
1347 spin_lock_irqsave(&dmasound.lock, flags);
1348 if (beep_playing || write_sq.active || beep_buf == NULL) {
1349 spin_unlock_irqrestore(&dmasound.lock, flags);
1350 return -1; /* too hard, sorry :-( */
1353 st_le16(&beep_dbdma_cmd->command, OUTPUT_MORE + BR_ALWAYS);
1354 spin_unlock_irqrestore(&dmasound.lock, flags);
1356 if (hz == beep_hz_cache && beep_vol == beep_volume_cache) {
1357 nsamples = beep_nsamples_cache;
1359 period = srate * 256 / hz; /* fixed point */
1360 ncycles = BEEP_BUFLEN * 256 / period;
1361 nsamples = (period * ncycles) >> 8;
1362 f = ncycles * 65536 / nsamples;
1365 for (i = 0; i < nsamples; ++i, p += 2) {
1366 p[0] = p[1] = beep_wform[j >> 8] * beep_vol;
1367 j = (j + f) & 0xffff;
1370 beep_volume_cache = beep_vol;
1371 beep_nsamples_cache = nsamples;
1374 st_le16(&beep_dbdma_cmd->req_count, nsamples*4);
1375 st_le16(&beep_dbdma_cmd->xfer_status, 0);
1376 st_le32(&beep_dbdma_cmd->cmd_dep, virt_to_bus(beep_dbdma_cmd));
1377 st_le32(&beep_dbdma_cmd->phy_addr, virt_to_bus(beep_buf));
1378 awacs_beep_state = 1;
1380 spin_lock_irqsave(&dmasound.lock, flags);
1381 if (beep_playing) { /* i.e. haven't been terminated already */
1383 out_le32(&awacs_txdma->control, (RUN|WAKE|FLUSH|PAUSE) << 16);
1384 while ((in_le32(&awacs_txdma->status) & RUN) && count--)
1385 udelay(1); /* timeout > 2 samples at lowest rate*/
1387 awacs_setup_for_beep(beep_speed);
1388 out_le32(&awacs_txdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
1389 (void)in_le32(&awacs_txdma->status);
1390 out_le32(&awacs_txdma->control, RUN | (RUN << 16));
1392 spin_unlock_irqrestore(&dmasound.lock, flags);
1397 /* used in init and for wake-up */
1402 awacs_write(awacs_reg[0] + MASK_ADDR0);
1403 awacs_write(awacs_reg[1] + MASK_ADDR1);
1404 awacs_write(awacs_reg[2] + MASK_ADDR2);
1405 awacs_write(awacs_reg[4] + MASK_ADDR4);
1407 if (awacs_revision == AWACS_SCREAMER) {
1408 awacs_write(awacs_reg[5] + MASK_ADDR5);
1410 awacs_write(awacs_reg[6] + MASK_ADDR6);
1412 awacs_write(awacs_reg[1] + MASK_ADDR1);
1413 awacs_write(awacs_reg[7] + MASK_ADDR7);
1416 if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE))
1417 out_le32(&awacs->byteswap, BS_VAL);
1419 out_le32(&awacs->byteswap, 0);
1423 #ifdef CONFIG_PMAC_PBOOK
1425 * Save state when going to sleep, restore it afterwards.
1427 /* FIXME: sort out disabling/re-enabling of read stuff as well */
1428 static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
1430 unsigned long flags;
1433 case PBOOK_SLEEP_NOW:
1436 /* Tell the rest of the driver we are now going to sleep */
1438 if (awacs_revision == AWACS_SCREAMER ||
1439 awacs_revision == AWACS_AWACS) {
1440 awacs_reg1_save = awacs_reg[1];
1441 awacs_reg[1] |= MASK_AMUTE | MASK_CMUTE;
1442 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1446 /* stop rx - if going - a bit of a daft user... but */
1447 out_le32(&awacs_rxdma->control, (RUN|WAKE|FLUSH << 16));
1448 /* deny interrupts */
1450 disable_irq(awacs_irq);
1451 disable_irq(awacs_tx_irq);
1452 disable_irq(awacs_rx_irq);
1453 /* Chip specific sleep code */
1454 switch (awacs_revision) {
1457 write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
1458 write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
1460 write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
1465 case AWACS_BURGUNDY:
1467 case AWACS_SCREAMER:
1470 out_le32(&awacs->control, 0x11) ;
1473 /* Disable sound clock */
1474 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 0);
1475 /* According to Darwin, we do that after turning off the sound
1476 * chip clock. All this will have to be cleaned up once we properly
1477 * parse the OF sound-objects
1479 if ((machine_is_compatible("PowerBook3,1") ||
1480 machine_is_compatible("PowerBook3,2")) && awacs) {
1481 awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
1482 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1487 /* Enable sound clock */
1488 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 1);
1489 if ((machine_is_compatible("PowerBook3,1") ||
1490 machine_is_compatible("PowerBook3,2")) && awacs) {
1492 awacs_reg[1] &= ~(MASK_PAROUT0 | MASK_PAROUT1);
1493 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1497 /* restore settings */
1498 switch (awacs_revision) {
1501 write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
1502 write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
1503 write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
1505 write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
1507 tas_leave_sleep(); /* Stub for now */
1508 headphone_intr(0,NULL,NULL);
1511 msleep(10); /* Check this !!! */
1513 break ; /* dont know how yet */
1514 case AWACS_BURGUNDY:
1516 case AWACS_SCREAMER:
1522 /* Recalibrate chip */
1523 if (awacs_revision == AWACS_SCREAMER && awacs)
1524 awacs_recalibrate();
1525 /* Make sure dma is stopped */
1528 enable_irq(awacs_irq);
1529 enable_irq(awacs_tx_irq);
1530 enable_irq(awacs_rx_irq);
1532 /* OK, allow ints back again */
1533 out_le32(&awacs->control, MASK_IEPC
1534 | (awacs_rate_index << 8) | 0x11
1535 | (awacs_revision < AWACS_DACA ? MASK_IEE: 0));
1537 if (macio_base && is_pbook_g3) {
1538 /* FIXME: should restore the setup we had...*/
1539 out_8(macio_base + 0x37, 3);
1540 } else if (is_pbook_3X00) {
1541 in_8(latch_base + 0x190);
1544 if (awacs_revision == AWACS_SCREAMER ||
1545 awacs_revision == AWACS_AWACS) {
1546 awacs_reg[1] = awacs_reg1_save;
1547 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1550 /* Resume pending sounds. */
1551 /* we don't try to restart input... */
1552 spin_lock_irqsave(&dmasound.lock, flags);
1554 spin_unlock_irqrestore(&dmasound.lock, flags);
1557 return PBOOK_SLEEP_OK;
1559 #endif /* CONFIG_PMAC_PBOOK */
1562 /* All the burgundy functions: */
1564 /* Waits for busy flag to clear */
1566 awacs_burgundy_busy_wait(void)
1568 int count = 50; /* > 2 samples at 44k1 */
1569 while ((in_le32(&awacs->codec_ctrl) & MASK_NEWECMD) && count--)
1574 awacs_burgundy_extend_wait(void)
1576 int count = 50 ; /* > 2 samples at 44k1 */
1577 while ((!(in_le32(&awacs->codec_stat) & MASK_EXTEND)) && count--)
1580 while ((in_le32(&awacs->codec_stat) & MASK_EXTEND) && count--)
1585 awacs_burgundy_wcw(unsigned addr, unsigned val)
1587 out_le32(&awacs->codec_ctrl, addr + 0x200c00 + (val & 0xff));
1588 awacs_burgundy_busy_wait();
1589 out_le32(&awacs->codec_ctrl, addr + 0x200d00 +((val>>8) & 0xff));
1590 awacs_burgundy_busy_wait();
1591 out_le32(&awacs->codec_ctrl, addr + 0x200e00 +((val>>16) & 0xff));
1592 awacs_burgundy_busy_wait();
1593 out_le32(&awacs->codec_ctrl, addr + 0x200f00 +((val>>24) & 0xff));
1594 awacs_burgundy_busy_wait();
1598 awacs_burgundy_rcw(unsigned addr)
1601 unsigned long flags;
1603 /* should have timeouts here */
1604 spin_lock_irqsave(&dmasound.lock, flags);
1606 out_le32(&awacs->codec_ctrl, addr + 0x100000);
1607 awacs_burgundy_busy_wait();
1608 awacs_burgundy_extend_wait();
1609 val += (in_le32(&awacs->codec_stat) >> 4) & 0xff;
1611 out_le32(&awacs->codec_ctrl, addr + 0x100100);
1612 awacs_burgundy_busy_wait();
1613 awacs_burgundy_extend_wait();
1614 val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<8;
1616 out_le32(&awacs->codec_ctrl, addr + 0x100200);
1617 awacs_burgundy_busy_wait();
1618 awacs_burgundy_extend_wait();
1619 val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<16;
1621 out_le32(&awacs->codec_ctrl, addr + 0x100300);
1622 awacs_burgundy_busy_wait();
1623 awacs_burgundy_extend_wait();
1624 val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<24;
1626 spin_unlock_irqrestore(&dmasound.lock, flags);
1633 awacs_burgundy_wcb(unsigned addr, unsigned val)
1635 out_le32(&awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
1636 awacs_burgundy_busy_wait();
1640 awacs_burgundy_rcb(unsigned addr)
1643 unsigned long flags;
1645 /* should have timeouts here */
1646 spin_lock_irqsave(&dmasound.lock, flags);
1648 out_le32(&awacs->codec_ctrl, addr + 0x100000);
1649 awacs_burgundy_busy_wait();
1650 awacs_burgundy_extend_wait();
1651 val += (in_le32(&awacs->codec_stat) >> 4) & 0xff;
1653 spin_unlock_irqrestore(&dmasound.lock, flags);
1659 awacs_burgundy_check(void)
1661 /* Checks to see the chip is alive and kicking */
1662 int error = in_le32(&awacs->codec_ctrl) & MASK_ERRCODE;
1664 return error == 0xf0000;
1668 awacs_burgundy_init(void)
1670 if (awacs_burgundy_check()) {
1671 printk(KERN_WARNING "dmasound_pmac: burgundy not working :-(\n");
1675 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_OUTPUTENABLES,
1676 DEF_BURGUNDY_OUTPUTENABLES);
1677 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
1678 DEF_BURGUNDY_MORE_OUTPUTENABLES);
1679 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_OUTPUTSELECTS,
1680 DEF_BURGUNDY_OUTPUTSELECTS);
1682 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL21,
1683 DEF_BURGUNDY_INPSEL21);
1684 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL3,
1685 DEF_BURGUNDY_INPSEL3);
1686 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINCD,
1687 DEF_BURGUNDY_GAINCD);
1688 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINLINE,
1689 DEF_BURGUNDY_GAINLINE);
1690 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMIC,
1691 DEF_BURGUNDY_GAINMIC);
1692 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMODEM,
1693 DEF_BURGUNDY_GAINMODEM);
1695 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER,
1696 DEF_BURGUNDY_ATTENSPEAKER);
1697 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENLINEOUT,
1698 DEF_BURGUNDY_ATTENLINEOUT);
1699 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENHP,
1700 DEF_BURGUNDY_ATTENHP);
1702 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_MASTER_VOLUME,
1703 DEF_BURGUNDY_MASTER_VOLUME);
1704 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLCD,
1705 DEF_BURGUNDY_VOLCD);
1706 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLLINE,
1707 DEF_BURGUNDY_VOLLINE);
1708 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLMIC,
1709 DEF_BURGUNDY_VOLMIC);
1714 awacs_burgundy_write_volume(unsigned address, int volume)
1716 int hardvolume,lvolume,rvolume;
1718 lvolume = (volume & 0xff) ? (volume & 0xff) + 155 : 0;
1719 rvolume = ((volume >>8)&0xff) ? ((volume >> 8)&0xff ) + 155 : 0;
1721 hardvolume = lvolume + (rvolume << 16);
1723 awacs_burgundy_wcw(address, hardvolume);
1727 awacs_burgundy_read_volume(unsigned address)
1729 int softvolume,wvolume;
1731 wvolume = awacs_burgundy_rcw(address);
1733 softvolume = (wvolume & 0xff) - 155;
1734 softvolume += (((wvolume >> 16) & 0xff) - 155)<<8;
1736 return softvolume > 0 ? softvolume : 0;
1740 awacs_burgundy_read_mvolume(unsigned address)
1742 int lvolume,rvolume,wvolume;
1744 wvolume = awacs_burgundy_rcw(address);
1748 rvolume = (wvolume & 0xff) - 155;
1749 lvolume = ((wvolume & 0xff00)>>8) - 155;
1751 return lvolume + (rvolume << 8);
1755 awacs_burgundy_write_mvolume(unsigned address, int volume)
1757 int lvolume,rvolume,hardvolume;
1759 lvolume = (volume &0xff) ? (volume & 0xff) + 155 :0;
1760 rvolume = ((volume >>8) & 0xff) ? (volume >> 8) + 155 :0;
1762 hardvolume = lvolume + (rvolume << 8);
1763 hardvolume += (hardvolume << 16);
1765 awacs_burgundy_wcw(address, hardvolume);
1768 /* End burgundy functions */
1770 /* Set up output volumes on machines with the 'perch/whisper' extension card.
1771 * this has an SGS i2c chip (7433) which is accessed using the cuda.
1773 * TODO: split this out and make use of the other parts of the SGS chip to
1774 * do Bass, Treble etc.
1778 awacs_enable_amp(int spkr_vol)
1780 #ifdef CONFIG_ADB_CUDA
1781 struct adb_request req;
1783 if (sys_ctrler != SYS_CTRLER_CUDA)
1786 /* turn on headphones */
1787 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1789 while (!req.complete) cuda_poll();
1790 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1792 while (!req.complete) cuda_poll();
1794 /* turn on speaker */
1795 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1796 0x8a, 3, (100 - (spkr_vol & 0xff)) * 32 / 100);
1797 while (!req.complete) cuda_poll();
1798 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1799 0x8a, 5, (100 - ((spkr_vol >> 8) & 0xff)) * 32 / 100);
1800 while (!req.complete) cuda_poll();
1802 cuda_request(&req, NULL, 5, CUDA_PACKET,
1803 CUDA_GET_SET_IIC, 0x8a, 1, 0x29);
1804 while (!req.complete) cuda_poll();
1805 #endif /* CONFIG_ADB_CUDA */
1809 /*** Mid level stuff *********************************************************/
1813 * /dev/mixer abstraction
1816 static void do_line_lev(int data)
1819 awacs_reg[0] &= ~MASK_MUX_AUDIN;
1820 if ((data & 0xff) >= 50)
1821 awacs_reg[0] |= MASK_MUX_AUDIN;
1822 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1825 static void do_ip_gain(int data)
1829 awacs_reg[0] &= ~MASK_GAINLINE;
1830 if (awacs_revision == AWACS_SCREAMER) {
1831 awacs_reg[6] &= ~MASK_MIC_BOOST ;
1833 awacs_reg[0] |= MASK_GAINLINE;
1835 awacs_reg[6] |= MASK_MIC_BOOST ;
1837 awacs_write(MASK_ADDR6 | awacs_reg[6]) ;
1840 awacs_reg[0] |= MASK_GAINLINE;
1842 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1845 static void do_mic_lev(int data)
1849 awacs_reg[0] &= ~MASK_MUX_MIC;
1851 awacs_reg[0] |= MASK_MUX_MIC;
1852 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1855 static void do_cd_lev(int data)
1858 awacs_reg[0] &= ~MASK_MUX_CD;
1859 if ((data & 0xff) >= 50)
1860 awacs_reg[0] |= MASK_MUX_CD;
1861 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1864 static void do_rec_lev(int data)
1868 /* need to fudge this to use the volume setter routine */
1869 left = 100 - (data & 0xff) ; if( left < 0 ) left = 0 ;
1870 right = 100 - ((data >> 8) & 0xff) ; if( right < 0 ) right = 0 ;
1871 left |= (right << 8 );
1872 left = awacs_volume_setter(left, 0, 0, 4);
1875 static void do_passthru_vol(int data)
1877 passthru_vol = data ;
1878 awacs_reg[1] &= ~MASK_LOOPTHRU;
1879 if (awacs_revision == AWACS_SCREAMER) {
1880 if( data ) { /* switch it on for non-zero */
1881 awacs_reg[1] |= MASK_LOOPTHRU;
1882 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1884 data = awacs_volume_setter(data, 5, 0, 6) ;
1886 if ((data & 0xff) >= 50)
1887 awacs_reg[1] |= MASK_LOOPTHRU;
1888 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1889 data = (awacs_reg[1] & MASK_LOOPTHRU)? 100: 0;
1893 static int awacs_mixer_ioctl(u_int cmd, u_long arg)
1899 case SOUND_MIXER_READ_CAPS:
1900 /* say we will allow multiple inputs? prob. wrong
1901 so I'm switching it to single */
1902 return IOCTL_OUT(arg, 1);
1903 case SOUND_MIXER_READ_DEVMASK:
1904 data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER
1905 | SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD
1906 | SOUND_MASK_IGAIN | SOUND_MASK_RECLEV
1908 | SOUND_MASK_MONITOR;
1909 rc = IOCTL_OUT(arg, data);
1911 case SOUND_MIXER_READ_RECMASK:
1912 data = SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD;
1913 rc = IOCTL_OUT(arg, data);
1915 case SOUND_MIXER_READ_RECSRC:
1917 if (awacs_reg[0] & MASK_MUX_AUDIN)
1918 data |= SOUND_MASK_LINE;
1919 if (awacs_reg[0] & MASK_MUX_MIC)
1920 data |= SOUND_MASK_MIC;
1921 if (awacs_reg[0] & MASK_MUX_CD)
1922 data |= SOUND_MASK_CD;
1923 rc = IOCTL_OUT(arg, data);
1925 case SOUND_MIXER_WRITE_RECSRC:
1926 IOCTL_IN(arg, data);
1927 data &= (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD);
1928 awacs_reg[0] &= ~(MASK_MUX_CD | MASK_MUX_MIC
1930 if (data & SOUND_MASK_LINE)
1931 awacs_reg[0] |= MASK_MUX_AUDIN;
1932 if (data & SOUND_MASK_MIC)
1933 awacs_reg[0] |= MASK_MUX_MIC;
1934 if (data & SOUND_MASK_CD)
1935 awacs_reg[0] |= MASK_MUX_CD;
1936 awacs_write(awacs_reg[0] | MASK_ADDR0);
1937 rc = IOCTL_OUT(arg, data);
1939 case SOUND_MIXER_READ_STEREODEVS:
1940 data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER| SOUND_MASK_RECLEV ;
1941 if (awacs_revision == AWACS_SCREAMER)
1942 data |= SOUND_MASK_MONITOR ;
1943 rc = IOCTL_OUT(arg, data);
1945 case SOUND_MIXER_WRITE_VOLUME:
1946 IOCTL_IN(arg, data);
1948 awacs_volume_setter(data, 2, 0, 6);
1950 case SOUND_MIXER_READ_VOLUME:
1951 rc = IOCTL_OUT(arg, line_vol);
1953 case SOUND_MIXER_WRITE_SPEAKER:
1954 IOCTL_IN(arg, data);
1957 awacs_enable_amp(data);
1959 (void)awacs_volume_setter(data, 4, MASK_CMUTE, 6);
1961 case SOUND_MIXER_READ_SPEAKER:
1962 rc = IOCTL_OUT(arg, spk_vol);
1964 case SOUND_MIXER_WRITE_ALTPCM: /* really bell volume */
1965 IOCTL_IN(arg, data);
1966 beep_vol = data & 0xff;
1968 case SOUND_MIXER_READ_ALTPCM:
1969 rc = IOCTL_OUT(arg, beep_vol);
1971 case SOUND_MIXER_WRITE_LINE:
1972 IOCTL_IN(arg, data);
1975 case SOUND_MIXER_READ_LINE:
1976 rc = IOCTL_OUT(arg, line_lev);
1978 case SOUND_MIXER_WRITE_IGAIN:
1979 IOCTL_IN(arg, data);
1982 case SOUND_MIXER_READ_IGAIN:
1983 rc = IOCTL_OUT(arg, ip_gain);
1985 case SOUND_MIXER_WRITE_MIC:
1986 IOCTL_IN(arg, data);
1989 case SOUND_MIXER_READ_MIC:
1990 rc = IOCTL_OUT(arg, mic_lev);
1992 case SOUND_MIXER_WRITE_CD:
1993 IOCTL_IN(arg, data);
1996 case SOUND_MIXER_READ_CD:
1997 rc = IOCTL_OUT(arg, cd_lev);
1999 case SOUND_MIXER_WRITE_RECLEV:
2000 IOCTL_IN(arg, data);
2003 case SOUND_MIXER_READ_RECLEV:
2004 rc = IOCTL_OUT(arg, rec_lev);
2006 case MIXER_WRITE(SOUND_MIXER_MONITOR):
2007 IOCTL_IN(arg, data);
2008 do_passthru_vol(data) ;
2010 case MIXER_READ(SOUND_MIXER_MONITOR):
2011 rc = IOCTL_OUT(arg, passthru_vol);
2020 static void awacs_mixer_init(void)
2022 awacs_volume_setter(line_vol, 2, 0, 6);
2024 awacs_enable_amp(spk_vol);
2026 (void)awacs_volume_setter(spk_vol, 4, MASK_CMUTE, 6);
2027 do_line_lev(line_lev) ;
2028 do_ip_gain(ip_gain) ;
2029 do_mic_lev(mic_lev) ;
2031 do_rec_lev(rec_lev) ;
2032 do_passthru_vol(passthru_vol) ;
2035 static int burgundy_mixer_ioctl(u_int cmd, u_long arg)
2040 /* We are, we are, we are... Burgundy or better */
2042 case SOUND_MIXER_READ_DEVMASK:
2043 data = SOUND_MASK_VOLUME | SOUND_MASK_CD |
2044 SOUND_MASK_LINE | SOUND_MASK_MIC |
2045 SOUND_MASK_SPEAKER | SOUND_MASK_ALTPCM;
2046 rc = IOCTL_OUT(arg, data);
2048 case SOUND_MIXER_READ_RECMASK:
2049 data = SOUND_MASK_LINE | SOUND_MASK_MIC
2051 rc = IOCTL_OUT(arg, data);
2053 case SOUND_MIXER_READ_RECSRC:
2055 if (awacs_reg[0] & MASK_MUX_AUDIN)
2056 data |= SOUND_MASK_LINE;
2057 if (awacs_reg[0] & MASK_MUX_MIC)
2058 data |= SOUND_MASK_MIC;
2059 if (awacs_reg[0] & MASK_MUX_CD)
2060 data |= SOUND_MASK_CD;
2061 rc = IOCTL_OUT(arg, data);
2063 case SOUND_MIXER_WRITE_RECSRC:
2064 IOCTL_IN(arg, data);
2065 data &= (SOUND_MASK_LINE
2066 | SOUND_MASK_MIC | SOUND_MASK_CD);
2067 awacs_reg[0] &= ~(MASK_MUX_CD | MASK_MUX_MIC
2069 if (data & SOUND_MASK_LINE)
2070 awacs_reg[0] |= MASK_MUX_AUDIN;
2071 if (data & SOUND_MASK_MIC)
2072 awacs_reg[0] |= MASK_MUX_MIC;
2073 if (data & SOUND_MASK_CD)
2074 awacs_reg[0] |= MASK_MUX_CD;
2075 awacs_write(awacs_reg[0] | MASK_ADDR0);
2076 rc = IOCTL_OUT(arg, data);
2078 case SOUND_MIXER_READ_STEREODEVS:
2079 data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER
2080 | SOUND_MASK_RECLEV | SOUND_MASK_CD
2082 rc = IOCTL_OUT(arg, data);
2084 case SOUND_MIXER_READ_CAPS:
2085 rc = IOCTL_OUT(arg, 0);
2087 case SOUND_MIXER_WRITE_VOLUME:
2088 IOCTL_IN(arg, data);
2089 awacs_burgundy_write_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME, data);
2091 case SOUND_MIXER_READ_VOLUME:
2092 rc = IOCTL_OUT(arg, awacs_burgundy_read_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME));
2094 case SOUND_MIXER_WRITE_SPEAKER:
2095 IOCTL_IN(arg, data);
2096 if (!(data & 0xff)) {
2097 /* Mute the left speaker */
2098 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2099 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) & ~0x2);
2101 /* Unmute the left speaker */
2102 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2103 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) | 0x2);
2105 if (!(data & 0xff00)) {
2106 /* Mute the right speaker */
2107 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2108 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) & ~0x4);
2110 /* Unmute the right speaker */
2111 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2112 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) | 0x4);
2115 data = (((data&0xff)*16)/100 > 0xf ? 0xf :
2116 (((data&0xff)*16)/100)) +
2117 ((((data>>8)*16)/100 > 0xf ? 0xf :
2118 ((((data>>8)*16)/100)))<<4);
2120 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER, ~data);
2122 case SOUND_MIXER_READ_SPEAKER:
2123 data = awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER);
2124 data = (((data & 0xf)*100)/16) + ((((data>>4)*100)/16)<<8);
2125 rc = IOCTL_OUT(arg, (~data) & 0x0000ffff);
2127 case SOUND_MIXER_WRITE_ALTPCM: /* really bell volume */
2128 IOCTL_IN(arg, data);
2129 beep_vol = data & 0xff;
2131 case SOUND_MIXER_READ_ALTPCM:
2132 rc = IOCTL_OUT(arg, beep_vol);
2134 case SOUND_MIXER_WRITE_LINE:
2135 IOCTL_IN(arg, data);
2136 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLLINE, data);
2139 case SOUND_MIXER_READ_LINE:
2140 data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLLINE);
2141 rc = IOCTL_OUT(arg, data);
2143 case SOUND_MIXER_WRITE_MIC:
2144 IOCTL_IN(arg, data);
2145 /* Mic is mono device */
2146 data = (data << 8) + (data << 24);
2147 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLMIC, data);
2149 case SOUND_MIXER_READ_MIC:
2150 data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLMIC);
2152 rc = IOCTL_OUT(arg, data);
2154 case SOUND_MIXER_WRITE_CD:
2155 IOCTL_IN(arg, data);
2156 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLCD, data);
2158 case SOUND_MIXER_READ_CD:
2159 data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLCD);
2160 rc = IOCTL_OUT(arg, data);
2162 case SOUND_MIXER_WRITE_RECLEV:
2163 IOCTL_IN(arg, data);
2164 data = awacs_volume_setter(data, 0, 0, 4);
2165 rc = IOCTL_OUT(arg, data);
2167 case SOUND_MIXER_READ_RECLEV:
2168 data = awacs_get_volume(awacs_reg[0], 4);
2169 rc = IOCTL_OUT(arg, data);
2171 case SOUND_MIXER_OUTMASK:
2172 case SOUND_MIXER_OUTSRC:
2180 static int daca_mixer_ioctl(u_int cmd, u_long arg)
2185 /* And the DACA's no genius either! */
2188 case SOUND_MIXER_READ_DEVMASK:
2189 data = SOUND_MASK_VOLUME;
2190 rc = IOCTL_OUT(arg, data);
2192 case SOUND_MIXER_READ_RECMASK:
2194 rc = IOCTL_OUT(arg, data);
2196 case SOUND_MIXER_READ_RECSRC:
2198 rc = IOCTL_OUT(arg, data);
2200 case SOUND_MIXER_WRITE_RECSRC:
2201 IOCTL_IN(arg, data);
2203 rc = IOCTL_OUT(arg, data);
2205 case SOUND_MIXER_READ_STEREODEVS:
2206 data = SOUND_MASK_VOLUME;
2207 rc = IOCTL_OUT(arg, data);
2209 case SOUND_MIXER_READ_CAPS:
2210 rc = IOCTL_OUT(arg, 0);
2212 case SOUND_MIXER_WRITE_VOLUME:
2213 IOCTL_IN(arg, data);
2214 daca_set_volume(data, data);
2216 case SOUND_MIXER_READ_VOLUME:
2217 daca_get_volume(& data, &data);
2218 rc = IOCTL_OUT(arg, data);
2220 case SOUND_MIXER_OUTMASK:
2221 case SOUND_MIXER_OUTSRC:
2228 static int PMacMixerIoctl(u_int cmd, u_long arg)
2232 /* Different IOCTLS for burgundy and, eventually, DACA & Tumbler */
2236 switch (awacs_revision){
2237 case AWACS_BURGUNDY:
2238 rc = burgundy_mixer_ioctl(cmd, arg);
2241 rc = daca_mixer_ioctl(cmd, arg);
2245 rc = tas_mixer_ioctl(cmd, arg);
2248 rc = awacs_mixer_ioctl(cmd, arg);
2256 static void PMacMixerInit(void)
2258 switch (awacs_revision) {
2260 printk("AE-Init tumbler mixer\n");
2263 printk("AE-Init snapper mixer\n");
2266 case AWACS_BURGUNDY:
2267 break ; /* don't know yet */
2269 case AWACS_SCREAMER:
2271 awacs_mixer_init() ;
2276 /* Write/Read sq setup functions:
2277 Check to see if we have enough (or any) dbdma cmd buffers for the
2278 user's fragment settings. If not, allocate some. If this fails we will
2279 point at the beep buffer - as an emergency provision - to stop dma tromping
2280 on some random bit of memory (if someone lets it go anyway).
2281 The command buffers are then set up to point to the fragment buffers
2282 (allocated elsewhere). We need n+1 commands the last of which holds
2283 a NOP + loop to start.
2286 static int PMacWriteSqSetup(void)
2288 int i, count = 600 ;
2289 volatile struct dbdma_cmd *cp;
2293 /* stop the controller from doing any output - if it isn't already.
2294 it _should_ be before this is called anyway */
2296 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
2297 while ((in_le32(&awacs_txdma->status) & RUN) && count--)
2299 #ifdef DEBUG_DMASOUND
2301 printk("dmasound_pmac: write sq setup: timeout waiting for dma to stop\n");
2304 if ((write_sq.max_count + 1) > number_of_tx_cmd_buffers) {
2305 if (awacs_tx_cmd_space)
2306 kfree(awacs_tx_cmd_space);
2307 number_of_tx_cmd_buffers = 0;
2309 /* we need nbufs + 1 (for the loop) and we should request + 1
2310 again because the DBDMA_ALIGN might pull the start up by up
2311 to sizeof(struct dbdma_cmd) - 4.
2314 awacs_tx_cmd_space = kmalloc
2315 ((write_sq.max_count + 1 + 1) * sizeof(struct dbdma_cmd),
2317 if (awacs_tx_cmd_space == NULL) {
2318 /* don't leave it dangling - nasty but better than a
2320 out_le32(&awacs_txdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
2322 "dmasound_pmac: can't allocate dbdma cmd buffers"
2323 ", driver disabled\n");
2327 awacs_tx_cmds = (volatile struct dbdma_cmd *)
2328 DBDMA_ALIGN(awacs_tx_cmd_space);
2329 number_of_tx_cmd_buffers = write_sq.max_count + 1;
2333 memset((void *)cp, 0, (write_sq.max_count+1) * sizeof(struct dbdma_cmd));
2334 for (i = 0; i < write_sq.max_count; ++i, ++cp) {
2335 st_le32(&cp->phy_addr, virt_to_bus(write_sq.buffers[i]));
2337 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
2338 st_le32(&cp->cmd_dep, virt_to_bus(awacs_tx_cmds));
2339 /* point the controller at the command stack - ready to go */
2340 out_le32(&awacs_txdma->cmdptr, virt_to_bus(awacs_tx_cmds));
2345 static int PMacReadSqSetup(void)
2348 volatile struct dbdma_cmd *cp;
2352 /* stop the controller from doing any input - if it isn't already.
2353 it _should_ be before this is called anyway */
2355 out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
2356 while ((in_le32(&awacs_rxdma->status) & RUN) && count--)
2358 #ifdef DEBUG_DMASOUND
2360 printk("dmasound_pmac: read sq setup: timeout waiting for dma to stop\n");
2363 if ((read_sq.max_count+1) > number_of_rx_cmd_buffers ) {
2364 if (awacs_rx_cmd_space)
2365 kfree(awacs_rx_cmd_space);
2366 number_of_rx_cmd_buffers = 0;
2368 /* we need nbufs + 1 (for the loop) and we should request + 1 again
2369 because the DBDMA_ALIGN might pull the start up by up to
2370 sizeof(struct dbdma_cmd) - 4 (assuming kmalloc aligns 32 bits).
2373 awacs_rx_cmd_space = kmalloc
2374 ((read_sq.max_count + 1 + 1) * sizeof(struct dbdma_cmd),
2376 if (awacs_rx_cmd_space == NULL) {
2377 /* don't leave it dangling - nasty but better than a
2379 out_le32(&awacs_rxdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
2381 "dmasound_pmac: can't allocate dbdma cmd buffers"
2382 ", driver disabled\n");
2386 awacs_rx_cmds = (volatile struct dbdma_cmd *)
2387 DBDMA_ALIGN(awacs_rx_cmd_space);
2388 number_of_rx_cmd_buffers = read_sq.max_count + 1 ;
2391 memset((void *)cp, 0, (read_sq.max_count+1) * sizeof(struct dbdma_cmd));
2393 /* Set dma buffers up in a loop */
2394 for (i = 0; i < read_sq.max_count; i++,cp++) {
2395 st_le32(&cp->phy_addr, virt_to_bus(read_sq.buffers[i]));
2396 st_le16(&cp->command, INPUT_MORE + INTR_ALWAYS);
2397 st_le16(&cp->req_count, read_sq.block_size);
2398 st_le16(&cp->xfer_status, 0);
2401 /* The next two lines make the thing loop around.
2403 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
2404 st_le32(&cp->cmd_dep, virt_to_bus(awacs_rx_cmds));
2405 /* point the controller at the command stack - ready to go */
2406 out_le32(&awacs_rxdma->cmdptr, virt_to_bus(awacs_rx_cmds));
2412 /* TODO: this needs work to guarantee that when it returns DMA has stopped
2413 but in a more elegant way than is done here....
2416 static void PMacAbortRead(void)
2419 volatile struct dbdma_cmd *cp;
2422 /* give it a chance to update the output and provide the IRQ
2426 out_le32(&awacs_rxdma->control, ((FLUSH) << 16) + FLUSH );
2429 for (i = 0; i < read_sq.max_count; i++,cp++)
2430 st_le16(&cp->command, DBDMA_STOP);
2432 * We should probably wait for the thing to stop before we
2433 * release the memory.
2436 msleep(100) ; /* give it a (small) chance to act */
2438 /* apply the sledgehammer approach - just stop it now */
2440 out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
2444 extern char *get_afmt_string(int);
2445 static int PMacStateInfo(char *b, size_t sp)
2448 len = sprintf(b,"HW rates: ");
2449 switch (awacs_revision){
2451 case AWACS_BURGUNDY:
2452 len += sprintf(b,"44100 ") ;
2456 for (i=0; i<1; i++){
2457 if (tas_freqs_ok[i])
2458 len += sprintf(b+len,"%d ", tas_freqs[i]) ;
2462 case AWACS_SCREAMER:
2464 for (i=0; i<8; i++){
2465 if (awacs_freqs_ok[i])
2466 len += sprintf(b+len,"%d ", awacs_freqs[i]) ;
2470 len += sprintf(b+len,"s/sec\n") ;
2472 len += sprintf(b+len,"HW AFMTS: ");
2475 if (i & dmasound.mach.hardware_afmts)
2476 len += sprintf(b+len,"%s ",
2477 get_afmt_string(i & dmasound.mach.hardware_afmts));
2480 len += sprintf(b+len,"\n") ;
2485 /*** Machine definitions *****************************************************/
2487 static SETTINGS def_hard = {
2488 .format = AFMT_S16_BE,
2494 static SETTINGS def_soft = {
2495 .format = AFMT_S16_BE,
2501 static MACHINE machPMac = {
2503 .name2 = "PowerMac Built-in Sound",
2504 .owner = THIS_MODULE,
2505 .dma_alloc = PMacAlloc,
2506 .dma_free = PMacFree,
2507 .irqinit = PMacIrqInit,
2509 .irqcleanup = PMacIrqCleanup,
2512 .silence = PMacSilence,
2513 .setFormat = PMacSetFormat,
2514 .setVolume = PMacSetVolume,
2516 .record = NULL, /* default to no record */
2517 .mixer_init = PMacMixerInit,
2518 .mixer_ioctl = PMacMixerIoctl,
2519 .write_sq_setup = PMacWriteSqSetup,
2520 .read_sq_setup = PMacReadSqSetup,
2521 .state_info = PMacStateInfo,
2522 .abort_read = PMacAbortRead,
2523 .min_dsp_speed = 7350,
2524 .max_dsp_speed = 44100,
2525 .version = ((DMASOUND_AWACS_REVISION<<8) + DMASOUND_AWACS_EDITION)
2529 /*** Config & Setup **********************************************************/
2531 /* Check for pmac models that we care about in terms of special actions.
2537 /* portables/lap-tops */
2539 if (machine_is_compatible("AAPL,3400/2400") ||
2540 machine_is_compatible("AAPL,3500")) {
2543 if (machine_is_compatible("PowerBook1,1") || /* lombard */
2544 machine_is_compatible("AAPL,PowerBook1998")){ /* wallstreet */
2550 /* Get the OF node that tells us about the registers, interrupts etc. to use
2553 On most machines the sound IO OF node is the 'davbus' node. On newer pmacs
2554 with DACA (& Tumbler) the node to use is i2s-a. On much older machines i.e.
2555 before 9500 there is no davbus node and we have to use the 'awacs' property.
2557 In the latter case we signal this by setting the codec value - so that the
2558 code that looks for chip properties knows how to go about it.
2561 static struct device_node* __init
2562 get_snd_io_node(void)
2564 struct device_node *np = NULL;
2566 /* set up awacs_node for early OF which doesn't have a full set of
2567 * properties on davbus
2570 awacs_node = find_devices("awacs");
2572 awacs_revision = AWACS_AWACS;
2574 /* powermac models after 9500 (other than those which use DACA or
2575 * Tumbler) have a node called "davbus".
2577 np = find_devices("davbus");
2579 * if we didn't find a davbus device, try 'i2s-a' since
2580 * this seems to be what iBooks (& Tumbler) have.
2583 np = i2s_node = find_devices("i2s-a");
2585 /* if we didn't find this - perhaps we are on an early model
2586 * which _only_ has an 'awacs' node
2588 if (np == NULL && awacs_node)
2591 /* if we failed all these return null - this will cause the
2592 * driver to give up...
2597 /* Get the OF node that contains the info about the sound chip, inputs s-rates
2599 This node does not exist (or contains much reduced info) on earlier machines
2600 we have to deduce the info other ways for these.
2603 static struct device_node* __init
2604 get_snd_info_node(struct device_node *io)
2606 struct device_node *info;
2608 info = find_devices("sound");
2609 while (info && info->parent != io)
2614 /* Find out what type of codec we have.
2618 get_codec_type(struct device_node *info)
2620 /* already set if pre-davbus model and info will be NULL */
2621 int codec = awacs_revision ;
2624 /* must do awacs first to allow screamer to overide it */
2625 if (device_is_compatible(info, "awacs"))
2626 codec = AWACS_AWACS ;
2627 if (device_is_compatible(info, "screamer"))
2628 codec = AWACS_SCREAMER;
2629 if (device_is_compatible(info, "burgundy"))
2630 codec = AWACS_BURGUNDY ;
2631 if (device_is_compatible(info, "daca"))
2633 if (device_is_compatible(info, "tumbler"))
2634 codec = AWACS_TUMBLER;
2635 if (device_is_compatible(info, "snapper"))
2636 codec = AWACS_SNAPPER;
2641 /* find out what type, if any, of expansion card we have
2644 get_expansion_type(void)
2646 if (find_devices("perch") != NULL)
2649 if (find_devices("pb-ziva-pc") != NULL)
2651 /* need to work out how we deal with iMac SRS module */
2654 /* set up frame rates.
2655 * I suspect that these routines don't quite go about it the right way:
2656 * - where there is more than one rate - I think that the first property
2657 * value is the number of rates.
2658 * TODO: check some more device trees and modify accordingly
2659 * Set dmasound.mach.max_dsp_rate on the basis of these routines.
2663 awacs_init_frame_rates(unsigned int *prop, unsigned int l)
2668 awacs_freqs_ok[i] = 0 ;
2669 for (l /= sizeof(int); l > 0; --l) {
2670 unsigned int r = *prop++;
2671 /* Apple 'Fixed' format */
2674 for (i = 0; i < 8; ++i) {
2675 if (r == awacs_freqs[i]) {
2676 awacs_freqs_ok[i] = 1;
2682 /* else we assume that all the rates are available */
2686 burgundy_init_frame_rates(unsigned int *prop, unsigned int l)
2691 for (l /= sizeof(int); l > 0; --l) {
2692 unsigned int r = *prop++;
2693 /* Apple 'Fixed' format */
2700 #ifdef DEBUG_DMASOUND
2703 printk("dmasound_pmac: burgundy with multiple frame rates\n");
2705 printk("%d ", temp[j]) ;
2712 daca_init_frame_rates(unsigned int *prop, unsigned int l)
2717 for (l /= sizeof(int); l > 0; --l) {
2718 unsigned int r = *prop++;
2719 /* Apple 'Fixed' format */
2727 #ifdef DEBUG_DMASOUND
2730 printk("dmasound_pmac: DACA with multiple frame rates\n");
2732 printk("%d ", temp[j]) ;
2739 init_frame_rates(unsigned int *prop, unsigned int l)
2741 switch (awacs_revision) {
2744 tas_init_frame_rates(prop, l);
2747 daca_init_frame_rates(prop, l);
2749 case AWACS_BURGUNDY:
2750 burgundy_init_frame_rates(prop, l);
2753 awacs_init_frame_rates(prop, l);
2758 /* find things/machines that can't do mac-io byteswap
2762 set_hw_byteswap(struct device_node *io)
2764 struct device_node *mio ;
2765 unsigned int kl = 0 ;
2767 /* if seems that Keylargo can't byte-swap */
2769 for (mio = io->parent; mio ; mio = mio->parent) {
2770 if (strcmp(mio->name, "mac-io") == 0) {
2771 if (device_is_compatible(mio, "Keylargo"))
2776 hw_can_byteswap = !kl;
2779 /* Allocate the resources necessary for beep generation. This cannot be (quite)
2780 done statically (yet) because we cannot do virt_to_bus() on static vars when
2781 the code is loaded as a module.
2783 for the sake of saving the possibility that two allocations will incur the
2784 overhead of two pull-ups in DBDMA_ALIGN() we allocate the 'emergency' dmdma
2785 command here as well... even tho' it is not part of the beep process.
2789 __init setup_beep(void)
2791 /* Initialize beep stuff */
2792 /* want one cmd buffer for beeps, and a second one for emergencies
2793 - i.e. dbdma error conditions.
2794 ask for three to allow for pull up in DBDMA_ALIGN().
2796 beep_dbdma_cmd_space =
2797 kmalloc((2 + 1) * sizeof(struct dbdma_cmd), GFP_KERNEL);
2798 if(beep_dbdma_cmd_space == NULL) {
2799 printk(KERN_ERR "dmasound_pmac: no beep dbdma cmd space\n") ;
2802 beep_dbdma_cmd = (volatile struct dbdma_cmd *)
2803 DBDMA_ALIGN(beep_dbdma_cmd_space);
2804 /* set up emergency dbdma cmd */
2805 emergency_dbdma_cmd = beep_dbdma_cmd+1 ;
2806 beep_buf = (short *) kmalloc(BEEP_BUFLEN * 4, GFP_KERNEL);
2807 if (beep_buf == NULL) {
2808 printk(KERN_ERR "dmasound_pmac: no memory for beep buffer\n");
2809 if( beep_dbdma_cmd_space ) kfree(beep_dbdma_cmd_space) ;
2815 static struct input_dev awacs_beep_dev = {
2816 .evbit = { BIT(EV_SND) },
2817 .sndbit = { BIT(SND_BELL) | BIT(SND_TONE) },
2818 .event = awacs_beep_event,
2819 .name = "dmasound beeper",
2820 .phys = "macio/input0", /* what the heck is this?? */
2822 .bustype = BUS_HOST,
2826 int __init dmasound_awacs_init(void)
2828 struct device_node *io = NULL, *info = NULL;
2831 if (_machine != _MACH_Pmac)
2836 hw_can_byteswap = 1 ; /* most can */
2838 /* look for models we need to handle specially */
2841 /* find the OF node that tells us about the dbdma stuff
2843 io = get_snd_io_node();
2845 #ifdef DEBUG_DMASOUND
2846 printk("dmasound_pmac: couldn't find sound io OF node\n");
2851 /* find the OF node that tells us about the sound sub-system
2852 * this doesn't exist on pre-davbus machines (earlier than 9500)
2854 if (awacs_revision != AWACS_AWACS) { /* set for pre-davbus */
2855 info = get_snd_info_node(io) ;
2857 #ifdef DEBUG_DMASOUND
2858 printk("dmasound_pmac: couldn't find 'sound' OF node\n");
2864 awacs_revision = get_codec_type(info) ;
2865 if (awacs_revision == 0) {
2866 #ifdef DEBUG_DMASOUND
2867 printk("dmasound_pmac: couldn't find a Codec we can handle\n");
2869 return -ENODEV ; /* we don't know this type of h/w */
2872 /* set up perch, ziva, SRS or whatever else we have as sound
2875 get_expansion_type();
2877 /* we've now got enough information to make up the audio topology.
2878 * we will map the sound part of mac-io now so that we can probe for
2879 * other info if necessary (early AWACS we want to read chip ids)
2882 if (io->n_addrs < 3 || io->n_intrs < 3) {
2883 /* OK - maybe we need to use the 'awacs' node (on earlier
2888 if (io->n_addrs < 3 || io->n_intrs < 3) {
2889 printk("dmasound_pmac: can't use %s"
2890 " (%d addrs, %d intrs)\n",
2891 io->full_name, io->n_addrs, io->n_intrs);
2895 printk("dmasound_pmac: can't use %s (%d addrs, %d intrs)\n",
2896 io->full_name, io->n_addrs, io->n_intrs);
2900 if (!request_OF_resource(io, 0, NULL)) {
2901 printk(KERN_ERR "dmasound: can't request IO resource !\n");
2904 if (!request_OF_resource(io, 1, " (tx dma)")) {
2905 release_OF_resource(io, 0);
2906 printk(KERN_ERR "dmasound: can't request TX DMA resource !\n");
2910 if (!request_OF_resource(io, 2, " (rx dma)")) {
2911 release_OF_resource(io, 0);
2912 release_OF_resource(io, 1);
2913 printk(KERN_ERR "dmasound: can't request RX DMA resource !\n");
2917 /* all OF versions I've seen use this value */
2919 i2s = (u32 *)ioremap(io->addrs[0].address, 0x1000);
2921 awacs = (volatile struct awacs_regs *)
2922 ioremap(io->addrs[0].address, 0x1000);
2923 awacs_txdma = (volatile struct dbdma_regs *)
2924 ioremap(io->addrs[1].address, 0x100);
2925 awacs_rxdma = (volatile struct dbdma_regs *)
2926 ioremap(io->addrs[2].address, 0x100);
2928 /* first of all make sure that the chip is powered up....*/
2929 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, io, 0, 1);
2930 if (awacs_revision == AWACS_SCREAMER && awacs)
2931 awacs_recalibrate();
2933 awacs_irq = io->intrs[0].line;
2934 awacs_tx_irq = io->intrs[1].line;
2935 awacs_rx_irq = io->intrs[2].line;
2937 /* Hack for legacy crap that will be killed someday */
2940 /* if we have an awacs or screamer - probe the chip to make
2941 * sure we have the right revision.
2944 if (awacs_revision <= AWACS_SCREAMER){
2945 uint32_t temp, rev, mfg ;
2946 /* find out the awacs revision from the chip */
2947 temp = in_le32(&awacs->codec_stat);
2948 rev = (temp >> 12) & 0xf;
2949 mfg = (temp >> 8) & 0xf;
2950 #ifdef DEBUG_DMASOUND
2951 printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
2953 if (rev >= AWACS_SCREAMER)
2954 awacs_revision = AWACS_SCREAMER ;
2956 awacs_revision = rev ;
2959 dmasound.mach = machPMac;
2961 /* find out other bits & pieces from OF, these may be present
2962 only on some models ... so be careful.
2965 /* in the absence of a frame rates property we will use the defaults
2969 unsigned int *prop, l;
2971 sound_device_id = 0;
2972 /* device ID appears post g3 b&w */
2973 prop = (unsigned int *)get_property(info, "device-id", NULL);
2975 sound_device_id = *prop;
2977 /* look for a property saying what sample rates
2980 prop = (unsigned int *)get_property(info, "sample-rates", &l);
2982 prop = (unsigned int *) get_property
2983 (info, "output-frame-rates", &l);
2985 /* if it's there use it to set up frame rates */
2986 init_frame_rates(prop, l) ;
2990 out_le32(&awacs->control, 0x11); /* set everything quiesent */
2992 set_hw_byteswap(io) ; /* figure out if the h/w can do it */
2994 /* get default volume from nvram
2995 * vol = (~nvram_read_byte(0x1308) & 7) << 1;
2997 vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
2998 /* set up tracking values */
2999 spk_vol = vol * 100 ;
3000 spk_vol /= 7 ; /* get set value to a percentage */
3001 spk_vol |= (spk_vol << 8) ; /* equal left & right */
3002 line_vol = passthru_vol = spk_vol ;
3004 /* fill regs that are shared between AWACS & Burgundy */
3006 awacs_reg[2] = vol + (vol << 6);
3007 awacs_reg[4] = vol + (vol << 6);
3008 awacs_reg[5] = vol + (vol << 6); /* screamer has loopthru vol control */
3009 awacs_reg[6] = 0; /* maybe should be vol << 3 for PCMCIA speaker */
3012 awacs_reg[0] = MASK_MUX_CD;
3013 awacs_reg[1] = MASK_LOOPTHRU;
3015 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
3016 if (has_perch || sound_device_id == 0x5
3017 || /*sound_device_id == 0x8 ||*/ sound_device_id == 0xb)
3018 awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
3020 switch (awacs_revision) {
3022 tas_register_driver(&tas3001c_hooks);
3023 tas_init(I2C_DRIVERID_TAS3001C, I2C_DRIVERNAME_TAS3001C);
3024 tas_dmasound_init();
3028 tas_register_driver(&tas3004_hooks);
3029 tas_init(I2C_DRIVERID_TAS3004,I2C_DRIVERNAME_TAS3004);
3030 tas_dmasound_init();
3036 case AWACS_BURGUNDY:
3037 awacs_burgundy_init();
3039 case AWACS_SCREAMER:
3046 /* enable/set-up external modules - when we know how */
3049 awacs_enable_amp(100 * 0x101);
3051 /* Reset dbdma channels */
3052 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
3053 while (in_le32(&awacs_txdma->status) & RUN)
3055 out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
3056 while (in_le32(&awacs_rxdma->status) & RUN)
3059 /* Initialize beep stuff */
3060 if ((res=setup_beep()))
3063 #ifdef CONFIG_PMAC_PBOOK
3064 pmu_register_sleep_notifier(&awacs_sleep_notifier);
3065 #endif /* CONFIG_PMAC_PBOOK */
3067 /* Powerbooks have odd ways of enabling inputs such as
3068 an expansion-bay CD or sound from an internal modem
3069 or a PC-card modem. */
3070 if (is_pbook_3X00) {
3072 * Enable CD and PC-card sound inputs.
3073 * This is done by reading from address
3074 * f301a000, + 0x10 to enable the expansion-bay
3075 * CD sound input, + 0x80 to enable the PC-card
3076 * sound input. The 0x100 enables the SCSI bus
3079 latch_base = (unsigned char *) ioremap (0xf301a000, 0x1000);
3080 in_8(latch_base + 0x190);
3082 } else if (is_pbook_g3) {
3083 struct device_node* mio;
3085 for (mio = io->parent; mio; mio = mio->parent) {
3086 if (strcmp(mio->name, "mac-io") == 0
3087 && mio->n_addrs > 0) {
3088 macio_base = (unsigned char *) ioremap
3089 (mio->addrs[0].address, 0x40);
3094 * Enable CD sound input.
3095 * The relevant bits for writing to this byte are 0x8f.
3096 * I haven't found out what the 0x80 bit does.
3097 * For the 0xf bits, writing 3 or 7 enables the CD
3098 * input, any other value disables it. Values
3099 * 1, 3, 5, 7 enable the microphone. Values 0, 2,
3100 * 4, 6, 8 - f enable the input from the modem.
3104 out_8(macio_base + 0x37, 3);
3107 if (hw_can_byteswap)
3108 dmasound.mach.hardware_afmts = (AFMT_S16_BE | AFMT_S16_LE) ;
3110 dmasound.mach.hardware_afmts = AFMT_S16_BE ;
3112 /* shut out chips that do output only.
3113 * may need to extend this to machines which have no inputs - even tho'
3114 * they use screamer - IIRC one of the powerbooks is like this.
3117 if (awacs_revision != AWACS_DACA) {
3118 dmasound.mach.capabilities = DSP_CAP_DUPLEX ;
3119 dmasound.mach.record = PMacRecord ;
3122 dmasound.mach.default_hard = def_hard ;
3123 dmasound.mach.default_soft = def_soft ;
3125 switch (awacs_revision) {
3126 case AWACS_BURGUNDY:
3127 sprintf(awacs_name, "PowerMac Burgundy ") ;
3130 sprintf(awacs_name, "PowerMac DACA ") ;
3133 sprintf(awacs_name, "PowerMac Tumbler ") ;
3136 sprintf(awacs_name, "PowerMac Snapper ") ;
3138 case AWACS_SCREAMER:
3139 sprintf(awacs_name, "PowerMac Screamer ") ;
3143 sprintf(awacs_name, "PowerMac AWACS rev %d ", awacs_revision) ;
3148 * XXX: we should handle errors here, but that would mean
3149 * rewriting the whole init code. later..
3151 input_register_device(&awacs_beep_dev);
3153 return dmasound_init();
3156 static void __exit dmasound_awacs_cleanup(void)
3158 input_unregister_device(&awacs_beep_dev);
3160 switch (awacs_revision) {
3163 tas_dmasound_cleanup();
3174 MODULE_DESCRIPTION("PowerMac built-in audio driver.");
3175 MODULE_LICENSE("GPL");
3177 module_init(dmasound_awacs_init);
3178 module_exit(dmasound_awacs_cleanup);