1 /***************************************************************************** 3 * ESS Maestro/Maestro-2/Maestro-2E driver for Linux 2.2.x 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * (c) Copyright 1999 Alan Cox <alan.cox@linux.org> 21 * Based heavily on SonicVibes.c: 22 * Copyright (C) 1998-1999 Thomas Sailer (sailer@ife.ee.ethz.ch) 24 * Heavily modified by Zach Brown <zab@redhat.com> based on lunch 25 * with ESS engineers. Many thanks to Howard Kim for providing 26 * contacts and hardware. Honorable mention goes to Eric 27 * Brombaugh for the BOB routines and nice hacking in general. 30 * /dev/dsp0-7 standard /dev/dsp device, (mostly) OSS compatible 31 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible 33 * Hardware Description 35 * A working Maestro setup contains the Maestro chip wired to a 36 * codec or 2. In the Maestro we have the APUs, the ASP, and the 37 * Wavecache. The APUs can be though of as virtual audio routing 38 * channels. They can take data from a number of sources and perform 39 * basic encodings of the data. The wavecache is a storehouse for 40 * PCM data. Typically it deals with PCI and interracts with the 41 * APUs. The ASP is a wacky DSP like device that ESS is loathe 42 * to release docs on. Thankfully it isn't required on the Maestro 43 * until you start doing insane things like FM emulation and surround 44 * encoding. The codecs are almost always AC-97 compliant codecs, 45 * but it appears that early Maestros may have had PT101 (an ESS 46 * part?) wired to them. The only real difference in the Maestro 47 * families is external goop like docking capability, memory for 48 * the ASP, and trivial initialization differences. 52 * We only drive the APU/Wavecache as typical DACs and drive the 53 * mixers in the codecs. There are 64 APUs. We assign 4 to each 54 * /dev/dsp? device. 2 channels for both in and out. 56 * For output we maintain a ring buffer of data that we are dmaing 57 * to the card. In mono operation this is nice and easy. When 58 * we receive data we tack it onto the ring buffer and make sure 59 * the APU assigned to it is playing over the data. When we fill 60 * the ring buffer we put the client to sleep until there is 63 * However, this starts to stink when we use stereo. The APUs 64 * supposedly can decode LRLR packed stereo data, but it 65 * doesn't work. So we're forced to use dual mono APUs walking over 66 * mono encoded data. This requires us to split the input from 67 * the client and complicates the buffer maths tremendously. Ick. 69 * Once input is actually written, it will be worth pointing out 70 * that only 44/16 input actually works. 73 * v0.04 - Sep 01 1999 - Zach Brown <zab@redhat.com> 74 * copied memory leak fix from sonicvibes driver 75 * different ac97 reset, play with 2.0 ac97, simplify ring bus setup 76 * bob freq code, region sanity, jitter sync fix; all from eric 79 * recording is horribly broken 80 * codec timeouts (we're way under the example source's 20ms(!?)) 81 * some people get indir reg timeouts? 82 * mixer interface broken? 83 * anyone have a pt101 codec? 84 * ess's ac97 codec (es1921) doesn't work 85 * mmap(), but beware stereo encoding nastiness. 86 * actually post pci writes 87 * check for bogon bios set irq/io windows 88 * compare our pci setup to the dos one, explains register timeouts? 89 * look really hard at the apu/bob/dma buffer code paths. 91 * the entire issue of smp safety needs to be looked at. cli() needs 92 * to be replaced with spinlock_irqsave, being very careful of call 93 * paths avoiding deadlock. if lock hold times are quick just 94 * use one big ass per device spinlock.. 97 /*****************************************************************************/ 101 #include <linux/module.h> 103 #include <linux/modversions.h> 107 #include <linux/version.h> 108 #include <linux/string.h> 109 #include <linux/ctype.h> 110 #include <linux/ioport.h> 111 #include <linux/sched.h> 112 #include <linux/delay.h> 113 #include <linux/sound.h> 114 #include <linux/malloc.h> 115 #include <linux/soundcard.h> 116 #include <linux/pci.h> 119 #include <linux/init.h> 120 #include <linux/poll.h> 121 #include <linux/spinlock.h> 122 #include <asm/uaccess.h> 123 #include <asm/hardirq.h> 126 #include"maestro_tables.h" 128 /* --------------------------------------------------------------------- */ 134 #define M_printk(args...) {if (debug) printk(args);} 139 /* --------------------------------------------------------------------- */ 141 #define DRIVER_VERSION"0.04" 143 #ifndef PCI_VENDOR_ESS 144 #define PCI_VENDOR_ESS 0x125D 145 #define PCI_DEVICE_ID_ESS_ESS1968 0x1968/* Maestro 2 */ 146 #define PCI_DEVICE_ID_ESS_ESS1978 0x1978/* Maestro 2E */ 148 #define PCI_VENDOR_ESS_OLD 0x1285/* vendor id for maestro 1 */ 149 #define PCI_DEVICE_ID_ESS_ESS0100 0x0100/* maestro 1 */ 150 #endif/* PCI_VENDOR_ESS */ 152 #define ESS_CHAN_HARD 0x100 154 #define ESS_CFMT_STEREO 0x01 155 #define ESS_CFMT_16BIT 0x02 156 #define ESS_CFMT_MASK 0x03 157 #define ESS_CFMT_ASHIFT 0 158 #define ESS_CFMT_CSHIFT 4 160 #define ESS_ENABLE_PE 1 161 #define ESS_ENABLE_RE 2 163 #define ESS_STATE_MAGIC 0x125D1968 164 #define ESS_CARD_MAGIC 0x19283746 166 #define DAC_RUNNING 1 167 #define ADC_RUNNING 2 169 static const unsigned sample_size
[] = {1,2,2,4}; 170 static const unsigned sample_shift
[] = {0,1,1,2}; 178 static const char*card_names
[]={ 179 [TYPE_MAESTRO
] ="ESS Maestro", 180 [TYPE_MAESTRO2
] ="ESS Maestro 2", 181 [TYPE_MAESTRO2E
] ="ESS Maestro 2E" 184 #define SND_DEV_DSP16 5 186 /* --------------------------------------------------------------------- */ 190 /* FIXME: we probably want submixers in here, but only one record pair */ 191 u8 apu
[4];/* Left, Right, Left In, Right In */ 192 u8 apu_mode
[4];/* Running mode for this APU */ 193 u8 apu_pan
[4];/* Panning setup for this APU */ 194 struct ess_card
*card
;/* Card info */ 196 unsigned int rateadc
, ratedac
; 197 unsigned char fmt
, enable
; 200 struct semaphore open_sem
; 202 wait_queue_head_t open_wait
; 204 /* soundcore stuff */ 212 unsigned hwptr
, swptr
; 213 unsigned total_bytes
; 215 unsigned error
;/* over/underrun */ 216 wait_queue_head_t wait
; 217 /* redundant, but makes calculations easier */ 220 unsigned fragsamples
; 224 unsigned endcleared
:1; 225 unsigned ossfragshift
; 227 unsigned subdivision
; 228 u16 base
;/* Offset for ptr */ 235 /* We keep maestro cards in a linked list */ 236 struct ess_card
*next
; 242 /* as most of this is static, 243 perhaps it should be a pointer to a global struct */ 246 int supported_mixers
; 249 /* the caller must guarantee arg sanity before calling these */ 250 int(*read_mixer
)(struct ess_card
*card
,int index
); 251 void(*write_mixer
)(struct ess_card
*card
,int mixer
,int vol
); 252 int(*recmask_io
)(struct ess_card
*card
,int rw
,int mask
); 255 struct ess_state channels
[8]; 256 u16 maestro_map
[32];/* Register map */ 258 /* hardware resources */ 264 extern __inline__
unsignedld2(unsigned int x
) 290 /* --------------------------------------------------------------------- */ 292 static struct ess_card
*devs
= NULL
; 294 /* --------------------------------------------------------------------- */ 298 * ESS Maestro AC97 codec programming interface. 301 static voidmaestro_ac97_set(int io
, u8 cmd
, u16 val
) 305 * Wait for the codec bus to be free 310 if(!(inb(io
+ESS_AC97_INDEX
)&1)) 316 outw(val
, io
+ESS_AC97_DATA
); 318 outb(cmd
, io
+ESS_AC97_INDEX
); 322 static u16
maestro_ac97_get(int io
, u8 cmd
) 329 * Wait for the codec bus to be free 334 if(!(inb(io
+ESS_AC97_INDEX
)&1)) 338 outb(cmd
|0x80, io
+ESS_AC97_INDEX
); 341 while(inb(io
+ESS_AC97_INDEX
)&1) 346 printk(KERN_ERR
"maestro: ac97 codec read timeout.\n"); 350 data
=inw(io
+ESS_AC97_DATA
); 356 * The Maestro can be wired to a standard AC97 compliant codec 357 * (see www.intel.com for the pdf's on this), or to a PT101 codec 358 * which appears to be the ES1918 (data sheet on the esstech.com.tw site) 360 * The PT101 setup is untested. 363 static u16
maestro_ac97_init(int iobase
) 368 #if 0/* this needs to be thought about harder */ 369 /* aim at the second codec */ 370 outw(0x21, iobase
+0x38); 371 outw(0x5555, iobase
+0x3a); 372 outw(0x5555, iobase
+0x3c); 374 vend1
=maestro_ac97_get(iobase
,0x7c); 375 vend2
=maestro_ac97_get(iobase
,0x7e); 376 if(vend1
!=0xffff|| vend2
!=0xffff) { 377 printk("maestro: second codec 0x%4x%4x found, enabling both. please report this.\n", 379 /* enable them both */ 380 outw(0x00, iobase
+0x38); 381 outw(0xFFFC, iobase
+0x3a); 382 outw(0x000C, iobase
+0x3c); 384 /* back to the first only */ 385 outw(0x0, iobase
+0x38); 386 outw(0x0, iobase
+0x3a); 387 outw(0x0, iobase
+0x3c); 392 /* perform codec reset */ 393 maestro_ac97_set(iobase
,0x00,0x0000); 395 /* should make sure we're ac97 2.1? */ 396 vend1
=maestro_ac97_get(iobase
,0x7c); 397 vend2
=maestro_ac97_get(iobase
,0x7e); 399 val
=maestro_ac97_get(iobase
,0x00); 403 printk(KERN_INFO
"maestro: AC97 Codec detected: v: 0x%2x%2x 3d: 0x%x caps: 0x%x\n", 404 vend1
,vend2
,seid
, caps
); 406 /* XXX endianness, dork head. */ 407 /* magic vendor specifc init code, _no_ idea what these do */ 408 switch((long)(vend1
<<16) | vend2
) { 409 case0x545200ff:/* TriTech */ 411 maestro_ac97_set(iobase
,0x2a,0x0001); 412 maestro_ac97_set(iobase
,0x2c,0x0000); 413 maestro_ac97_set(iobase
,0x2c,0xffff); 415 case0x83847609:/* ESS 1921 */ 416 maestro_ac97_set(iobase
,0x76,0xABBA);/* o/~ Take a chance on me o/~ */ 418 maestro_ac97_set(iobase
,0x78,0x3002); 420 maestro_ac97_set(iobase
,0x78,0x3802); 426 /* set master, headphone, master mono */ 427 maestro_ac97_set(iobase
,0x02,0x0000); 428 /* always set headphones to max unmuted, OSS won't 429 let us change it :( */ 430 maestro_ac97_set(iobase
,0x04,0x0000); 431 maestro_ac97_set(iobase
,0x06,0x0000); 432 maestro_ac97_set(iobase
,0x08,0x0606); 433 /* beep, phone, mic, line, cd video, aux */ 434 maestro_ac97_set(iobase
,0x0A,0x1F1F); 435 maestro_ac97_set(iobase
,0x0C,0x1F1F); 436 maestro_ac97_set(iobase
,0x0E,0x1F1F); 437 maestro_ac97_set(iobase
,0x10,0x1F1F); 438 maestro_ac97_set(iobase
,0x12,0x1F1F); 439 maestro_ac97_set(iobase
,0x14,0x1F1F); 440 maestro_ac97_set(iobase
,0x16,0x1F1F); 441 /* unmute, but set pcm out to 1/2 */ 442 maestro_ac97_set(iobase
,0x18,0x0808); 443 /* null record select */ 444 maestro_ac97_set(iobase
,0x1A,0x0000); 445 /* record gain, record gain mic.. */ 446 maestro_ac97_set(iobase
,0x1C,0x0404); 447 maestro_ac97_set(iobase
,0x1E,0x0404); 448 /* null misc stuff */ 449 maestro_ac97_set(iobase
,0x20,0x0000); 450 /* power up various units? */ 451 maestro_ac97_set(iobase
,0x26,0x000F); 453 /* lets see if they actually default to the spec :) */ 454 if(maestro_ac97_get(iobase
,0x36) ==0x8080) { 456 printk("maestro: your ac97 might be 2.0, see if this makes sense:\n"); 457 for(reg
=0x28; reg
<=0x58; reg
+=2) { 458 printk(" 0x%2x: %4x\n",reg
,maestro_ac97_get(iobase
,reg
)); 465 static u16
maestro_pt101_init(int iobase
) 467 printk(KERN_INFO
"maestro: PT101 Codec detected, initializing but _not_ installing mixer device.\n"); 469 maestro_ac97_set(iobase
,0x2A,0x0001); 470 maestro_ac97_set(iobase
,0x2C,0x0000); 471 maestro_ac97_set(iobase
,0x2C,0xFFFF); 472 maestro_ac97_set(iobase
,0x10,0x9F1F); 473 maestro_ac97_set(iobase
,0x12,0x0808); 474 maestro_ac97_set(iobase
,0x14,0x9F1F); 475 maestro_ac97_set(iobase
,0x16,0x9F1F); 476 maestro_ac97_set(iobase
,0x18,0x0404); 477 maestro_ac97_set(iobase
,0x1A,0x0000); 478 maestro_ac97_set(iobase
,0x1C,0x0000); 479 maestro_ac97_set(iobase
,0x02,0x0404); 480 maestro_ac97_set(iobase
,0x04,0x0808); 481 maestro_ac97_set(iobase
,0x0C,0x801F); 482 maestro_ac97_set(iobase
,0x0E,0x801F); 486 static voidmaestro_ac97_reset(int ioaddr
) 488 /* outw(0x2000, ioaddr+0x36); 491 outw(0x0000, ioaddr+0x36); 495 /* well this seems to work a little 497 /* this screws around with the gpio 498 mask/input/direction.. */ 499 outw(0x0000, ioaddr
+0x36); 501 outw(0xFFFE, ioaddr
+0x64); 502 outw(0x1, ioaddr
+0x68); 503 outw(0x0, ioaddr
+0x60); 505 outw(0x1, ioaddr
+0x60); 506 udelay(20);/* other source says 500ms.. INSANE */ 507 outw(0x2000, ioaddr
+0x36); 509 outw(0x3000, ioaddr
+0x36); 511 outw(0x0001, ioaddr
+0x68); 512 outw(0xFFFF, ioaddr
+0x64); 514 /* strange strange reset tickling the ring bus */ 515 outw(0x0, ioaddr
+0x36); 517 outw(0x200, ioaddr
+0x36);/* first codec only */ 519 outw(0x0, ioaddr
+0x36); 521 outw(0x2000, ioaddr
+0x36); 523 outw(0x3000, ioaddr
+0x36); 528 * Indirect register access. Not all registers are readable so we 529 * need to keep register state ourselves 532 #define WRITEABLE_MAP 0xEFFFFF 533 #define READABLE_MAP 0x64003F 536 * The Maestro engineers were a little indirection happy. These indirected 537 * registers themselves include indirect registers at another layer 540 static voidmaestro_write(struct ess_state
*ess
, u16 reg
, u16 data
) 542 long ioaddr
= ess
->card
->iobase
; 546 outw(reg
, ioaddr
+0x02); 547 outw(data
, ioaddr
+0x00); 548 ess
->card
->maestro_map
[reg
]=data
; 549 restore_flags(flags
); 552 static u16
maestro_read(struct ess_state
*ess
, u16 reg
) 554 long ioaddr
= ess
->card
->iobase
; 555 if(READABLE_MAP
& (1<<reg
)) 560 outw(reg
, ioaddr
+0x02); 561 ess
->card
->maestro_map
[reg
]=inw(ioaddr
+0x00); 562 restore_flags(flags
); 564 return ess
->card
->maestro_map
[reg
]; 568 * These routines handle accessing the second level indirections to the 573 * The register names are the ones ESS uses (see 104T31.ZIP) 576 #define IDR0_DATA_PORT 0x00 577 #define IDR1_CRAM_POINTER 0x01 578 #define IDR2_CRAM_DATA 0x02 579 #define IDR3_WAVE_DATA 0x03 580 #define IDR4_WAVE_PTR_LOW 0x04 581 #define IDR5_WAVE_PTR_HI 0x05 582 #define IDR6_TIMER_CTRL 0x06 583 #define IDR7_WAVE_ROMRAM 0x07 585 static voidapu_index_set(struct ess_state
*ess
, u16 index
) 588 maestro_write(ess
, IDR1_CRAM_POINTER
, index
); 590 if(maestro_read(ess
, IDR1_CRAM_POINTER
)==index
) 592 printk(KERN_WARNING
"maestro: APU register select failed.\n"); 595 static voidapu_data_set(struct ess_state
*ess
, u16 data
) 600 if(maestro_read(ess
, IDR0_DATA_PORT
)==data
) 602 maestro_write(ess
, IDR0_DATA_PORT
, data
); 607 * This is the public interface for APU manipulation. It handles the 608 * interlock to avoid two APU writes in parallel etc. Don't diddle 609 * directly with the stuff above. 612 static voidapu_set_register(struct ess_state
*ess
, u16 channel
, u8 reg
, u16 data
) 616 if(channel
&ESS_CHAN_HARD
) 617 channel
&=~ESS_CHAN_HARD
; 621 printk("BAD CHANNEL %d.\n",channel
); 623 channel
= ess
->apu
[channel
]; 630 apu_index_set(ess
, reg
); 631 apu_data_set(ess
, data
); 632 restore_flags(flags
); 635 static u16
apu_get_register(struct ess_state
*ess
, u16 channel
, u8 reg
) 640 if(channel
&ESS_CHAN_HARD
) 641 channel
&=~ESS_CHAN_HARD
; 643 channel
= ess
->apu
[channel
]; 649 apu_index_set(ess
, reg
); 650 v
=maestro_read(ess
, IDR0_DATA_PORT
); 651 restore_flags(flags
); 657 * The wavecache does pci fetches for us and feeds 659 * XXX describe interface 662 static voidwave_set_register(struct ess_state
*ess
, u16 reg
, u16 value
) 664 long ioaddr
= ess
->card
->iobase
; 669 outw(reg
, ioaddr
+0x10); 670 outw(value
, ioaddr
+0x12); 671 restore_flags(flags
); 674 static u16
wave_get_register(struct ess_state
*ess
, u16 reg
) 676 long ioaddr
= ess
->card
->iobase
; 682 outw(reg
, ioaddr
+0x10); 683 value
=inw(ioaddr
+0x12); 684 restore_flags(flags
); 689 static voidsound_reset(int ioaddr
) 691 outw(0x2000,0x18+ioaddr
); 693 outw(0x0000,0x18+ioaddr
); 697 static voidset_apu_fmt(struct ess_state
*s
,int apu
,int mode
) 699 if(mode
&ESS_CFMT_16BIT
) { 700 s
->apu_mode
[apu
] =0x10; 701 s
->apu_mode
[apu
+1] =0x10; 703 s
->apu_mode
[apu
] =0x30; 704 s
->apu_mode
[apu
+1] =0x30; 708 static voidset_fmt(struct ess_state
*s
,unsigned char mask
,unsigned char data
) 710 s
->fmt
= (s
->fmt
& mask
) | data
; 711 set_apu_fmt(s
,0, s
->fmt
& ESS_CFMT_MASK
); 712 set_apu_fmt(s
,2, (s
->fmt
>> ESS_CFMT_CSHIFT
) & ESS_CFMT_MASK
); 715 static u16
compute_rate(u32 freq
) 724 static voidset_dac_rate(struct ess_state
*s
,unsigned rate
) 735 if(!(s
->fmt
& ESS_CFMT_16BIT
)) 736 rate
>>=1;/* who knows */ 738 /* M_printk("computing dac rate %d with mode %d\n",rate,s->fmt);*/ 740 freq
=compute_rate(rate
); 742 /* Load the frequency, turn on 6dB, turn off the effects */ 743 apu_set_register(s
,0,2, (freq
&0xFF)<<8|0x10); 744 apu_set_register(s
,0,3, freq
>>8); 745 apu_set_register(s
,1,2, (freq
&0xFF)<<8|0x10); 746 apu_set_register(s
,1,3, freq
>>8); 749 static voidset_adc_rate(struct ess_state
*s
,unsigned rate
) 760 freq
=compute_rate(rate
); 762 /* Load the frequency, turn on 6dB, turn off the effects */ 763 apu_set_register(s
,2,2, (freq
&0xFF)<<8|0x10); 764 apu_set_register(s
,2,3, freq
>>8); 765 apu_set_register(s
,3,2, (freq
&0xFF)<<8|0x10); 766 apu_set_register(s
,3,3, freq
>>8); 771 * Native play back driver 774 static voidess_play_setup(struct ess_state
*ess
,int mode
, u32 rate
,void*buffer
,int size
) 781 M_printk("mode=%d rate=%d buf=%p len=%d.\n", 782 mode
, rate
, buffer
, size
); 784 /* all maestro sizes are in 16bit words */ 787 /* we're given the full size of the buffer, but 788 in stereo each channel will only play its half */ 789 if(mode
&ESS_CFMT_STEREO
) { 794 for(channel
=0; channel
<= high_apu
; channel
++) 799 * To understand this it helps to know how the 800 * wave cache works. There are 4 DSP wavecache 801 * blocks which are 0x1FC->0x1FF. They are selected 802 * by setting bits 22,21,20 of the address to 803 * 1 X Y where X Y select the block. 805 * In addition stereo pairing is supported. This is 806 * set in the wave cache control for the channel as is 809 * Note that this causes a problem. With our limit of 810 * about 12 full duplex pairs (48 channels active) we 811 * will need to do a lot of juggling to get all the 812 * memory we want sufficiently close together. 814 * Even with 64K blocks that means 818 * 10K per channel pair = 5000 samples. 822 pa
=virt_to_bus(buffer
); 824 /* right channel plays its split half. 825 *2 accomodates for rampant shifting earlier */ 826 pa
=virt_to_bus(buffer
+ size
*2); 828 M_printk("sending pa %x to %d\n",pa
,channel
); 830 wave_set_register(ess
,0x01FC, (pa
&0xFFE00000)>>12); 832 /* set the wavecache control reg */ 833 tmpval
= (pa
-0x10) &0xFFF8; 835 if(mode
&1) tmpval
|=2;/* stereo */ 837 if(!(mode
&2)) tmpval
|=4;/* 8bit */ 838 wave_set_register(ess
, ess
->apu
[channel
]<<3, tmpval
); 840 pa
&=0x1FFFFF;/* Low 21 bits */ 843 /* base offset of dma calcs when reading the pointer 845 if(!channel
) ess
->dma_dac
.base
= pa
&0xFFFF; 848 if(mode
&ESS_CFMT_STEREO
)/* Enable stereo */ 851 pa
|=0x00400000;/* System RAM */ 853 /* Begin loading the APU */ 854 for(i
=0;i
<15;i
++)/* clear all PBRs */ 855 apu_set_register(ess
, channel
, i
,0x0000); 857 /* Load the frequency, turn on 6dB, turn off the effects */ 858 /* apu_set_register(ess, channel, 2, (rate&0xFF)<<8|0x10); 859 apu_set_register(ess, channel, 3, rate>>8);*/ 861 /* XXX think about endianess when writing these registers */ 862 /* Load the buffer into the wave engine */ 863 apu_set_register(ess
, channel
,4, ((pa
>>16)&0xFF)<<8); 864 apu_set_register(ess
, channel
,5, pa
&0xFFFF); 865 apu_set_register(ess
, channel
,6, (pa
+size
)&0xFFFF); 866 /* setting loop == sample len */ 867 apu_set_register(ess
, channel
,7, size
); 869 /* clear effects/env.. */ 870 apu_set_register(ess
, channel
,8,0x0000); 871 /* aplitudeNow to 0xd0? */ 872 apu_set_register(ess
, channel
,9,0xD000); 874 /* set the panning reg of the apu to left/right/mid.. */ 876 /* clear routing stuff */ 877 apu_set_register(ess
, channel
,11,0x0000); 878 /* mark dma and turn on filter stuff? */ 879 apu_set_register(ess
, channel
,0,0x400F); 881 if(mode
&ESS_CFMT_STEREO
) 882 /* set panning: left or right */ 883 apu_set_register(ess
, channel
,10,0x8F00| (channel
?0x10:0)); 885 apu_set_register(ess
, channel
,10,0x8F08); 889 /* clear WP interupts */ 890 outw(1, ess
->card
->iobase
+0x04); 892 outw(inw(ess
->card
->iobase
+0x18)|4, ess
->card
->iobase
+0x18); 894 set_dac_rate(ess
,rate
); 896 for(channel
=0; channel
<=high_apu
; channel
++) 898 /* Turn on the DMA */ 899 if(mode
&ESS_CFMT_16BIT
) 901 apu_set_register(ess
, channel
,0, 902 (apu_get_register(ess
, channel
,0)&0xFF0F)|0x10); 903 ess
->apu_mode
[channel
]=0x10; 907 apu_set_register(ess
, channel
,0, 908 (apu_get_register(ess
, channel
,0)&0xFF0F)|0x30); 909 ess
->apu_mode
[channel
]=0x30; 914 /* --------------------------------------------------------------------- */ 916 static voidset_dmaa(struct ess_state
*s
,unsigned int addr
,unsigned int count
) 920 static voidset_dmac(struct ess_state
*s
,unsigned int addr
,unsigned int count
) 924 /* Playback pointer */ 925 extern __inline__
unsignedget_dmaa(struct ess_state
*s
) 927 long ioport
= s
->card
->iobase
; 931 outw(s
->apu
[0]<<4|5, ioport
); 935 /* M_printk("dmaa: offset: %d, base: %d\n",offset,s->dma_dac.base);*/ 937 offset
-=s
->dma_dac
.base
; 939 return(offset
&0xFFFE)/*<<1*/;/* XXX printk didn't have it */ 943 extern __inline__
unsignedget_dmac(struct ess_state
*s
) 945 long ioport
= s
->card
->iobase
; 949 outw(s
->apu
[2]<<4|5, ioport
); 953 /* The offset is an address not a position relative to base */ 955 return(offset
&0xFFFE)<<1;/* hardware is in words */ 959 * Meet Bob, the timer... 962 static voidess_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
); 968 /* old kernel timer based timer ints, should BOB prove flakey */ 970 static struct timer_list tmp_timer
; 972 static int bob_stopped
; 974 static voidess_interrupt_fake(unsigned long v
) 976 ess_interrupt(5, (void*)v
, NULL
); 977 del_timer(&tmp_timer
); 980 tmp_timer
.expires
=jiffies
+1; 981 add_timer(&tmp_timer
); 984 M_printk("Stopping bob (SW)\n"); 987 static voidstop_bob(struct ess_state
*s
) 992 static voidkill_bob(struct ess_state
*s
) 994 del_timer(&tmp_timer
); 995 M_printk("Killing bob (SW)\n"); 998 static voidstart_bob(struct ess_state
*s
) 1004 init_timer(&tmp_timer
); 1005 tmp_timer
.function
= ess_interrupt_fake
; 1008 if(!timer_pending(&tmp_timer
)) 1010 del_timer(&tmp_timer
); 1011 tmp_timer
.expires
= jiffies
+1; 1012 tmp_timer
.data
= (unsigned long)s
->card
; 1013 add_timer(&tmp_timer
); 1014 M_printk("Starting bob (SW)\n"); 1020 /* nice HW BOB implementation. */ 1022 static voidstop_bob(struct ess_state
*s
) 1024 /* Mask IDR 11,17 */ 1025 maestro_write(s
,0x11,maestro_read(s
,0x11)&~1); 1026 maestro_write(s
,0x17,maestro_read(s
,0x17)&~1); 1029 /* eventually we could be clever and limit bob ints 1030 to the frequency at which our smallest duration 1031 chunks may expire */ 1032 #define ESS_SYSCLK 50000000 1033 static voidstart_bob(struct ess_state
*s
) 1038 int freq
=200;/* requested frequency - calculate what we want here. */ 1040 stop_bob(s
);/* make sure bob's not already running */ 1042 /* compute ideal interrupt frequency for buffer size & play rate */ 1043 /* first, find best prescaler value to match freq */ 1044 for(prescale
=5;prescale
<12;prescale
++) 1045 if(freq
> (ESS_SYSCLK
>>(prescale
+9))) 1048 /* next, back off prescaler whilst getting divider into optimum range */ 1050 while((prescale
>5) && (divide
<32)) 1057 /* now fine-tune the divider for best match */ 1058 for(;divide
<31;divide
++) 1059 if(freq
>= ((ESS_SYSCLK
>>(prescale
+9))/(divide
+1))) 1062 /* divide = 0 is illegal, but don't let prescale = 4! */ 1070 maestro_write(s
,6,0x9000| (prescale
<<5) | divide
);/* set reg */ 1072 /* Now set IDR 11/17 */ 1073 maestro_write(s
,0x11,maestro_read(s
,0x11)|1); 1074 maestro_write(s
,0x17,maestro_read(s
,0x17)|1); 1076 #endif/* ESS_HW_TIMER */ 1077 /* --------------------------------------------------------------------- */ 1079 static int adc_active
=0; 1081 extern inlinevoidstop_adc(struct ess_state
*s
) 1083 unsigned long flags
; 1085 spin_lock_irqsave(&s
->lock
, flags
); 1086 /* Stop left and right recording APU */ 1087 s
->enable
&= ~ADC_RUNNING
; 1088 apu_set_register(s
,2,0,apu_get_register(s
,2,0)&0xFF0F); 1089 apu_set_register(s
,3,0,apu_get_register(s
,3,0)&0xFF0F); 1093 spin_unlock_irqrestore(&s
->lock
, flags
); 1096 extern inlinevoidstop_dac(struct ess_state
*s
) 1098 unsigned long flags
; 1100 spin_lock_irqsave(&s
->lock
, flags
); 1101 s
->enable
&= ~DAC_RUNNING
; 1102 apu_set_register(s
,0,0,apu_get_register(s
,0,0)&0xFF0F); 1103 apu_set_register(s
,1,0,apu_get_register(s
,1,0)&0xFF0F); 1107 spin_unlock_irqrestore(&s
->lock
, flags
); 1110 static voidstart_dac(struct ess_state
*s
) 1112 unsigned long flags
; 1114 spin_lock_irqsave(&s
->lock
, flags
); 1115 if((s
->dma_dac
.mapped
|| s
->dma_dac
.count
>0) && s
->dma_dac
.ready
) { 1116 s
->enable
|= DAC_RUNNING
; 1118 apu_set_register(s
,0,0, 1119 (apu_get_register(s
,0,0)&0xFF0F)|s
->apu_mode
[0]); 1121 if(s
->fmt
& ESS_CFMT_STEREO
) 1122 apu_set_register(s
,1,0, 1123 (apu_get_register(s
,1,0)&0xFF0F)|s
->apu_mode
[1]); 1128 spin_unlock_irqrestore(&s
->lock
, flags
); 1131 static voidstart_adc(struct ess_state
*s
) 1133 unsigned long flags
; 1135 spin_lock_irqsave(&s
->lock
, flags
); 1136 if((s
->dma_adc
.mapped
|| s
->dma_adc
.count
< (signed)(s
->dma_adc
.dmasize
-2*s
->dma_adc
.fragsize
)) 1137 && s
->dma_adc
.ready
) { 1138 s
->enable
|= ADC_RUNNING
; 1139 apu_set_register(s
,2,0, 1140 (apu_get_register(s
,2,0)&0xFF0F)|s
->apu_mode
[2]); 1141 apu_set_register(s
,3,0, 1142 (apu_get_register(s
,3,0)&0xFF0F)|s
->apu_mode
[3]); 1147 spin_unlock_irqrestore(&s
->lock
, flags
); 1150 /* --------------------------------------------------------------------- */ 1152 #define DMABUF_DEFAULTORDER (15-PAGE_SHIFT) 1153 #define DMABUF_MINORDER 1 1155 static voiddealloc_dmabuf(struct dmabuf
*db
) 1157 unsigned long map
, mapend
; 1160 /* undo marking the pages as reserved */ 1161 mapend
=MAP_NR(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) -1); 1162 for(map
=MAP_NR(db
->rawbuf
); map
<= mapend
; map
++) 1163 clear_bit(PG_reserved
, &mem_map
[map
].flags
); 1164 free_pages((unsigned long)db
->rawbuf
, db
->buforder
); 1167 db
->mapped
= db
->ready
=0; 1171 static intprog_dmabuf(struct ess_state
*s
,unsigned rec
) 1173 struct dmabuf
*db
= rec
? &s
->dma_adc
: &s
->dma_dac
; 1174 unsigned rate
= rec
? s
->rateadc
: s
->ratedac
; 1176 unsigned bytepersec
; 1178 unsigned long map
, mapend
; 1180 unsigned long flags
; 1182 spin_lock_irqsave(&s
->lock
, flags
); 1185 s
->enable
&= ~ESS_ENABLE_RE
; 1186 fmt
>>= ESS_CFMT_CSHIFT
; 1188 s
->enable
&= ~ESS_ENABLE_PE
; 1189 fmt
>>= ESS_CFMT_ASHIFT
; 1191 spin_unlock_irqrestore(&s
->lock
, flags
); 1193 db
->hwptr
= db
->swptr
= db
->total_bytes
= db
->count
= db
->error
= db
->endcleared
=0; 1196 db
->ready
= db
->mapped
=0; 1198 /* alloc as big a chunk as we can */ 1199 for(order
= DMABUF_DEFAULTORDER
; order
>= DMABUF_MINORDER
; order
--) 1200 if((db
->rawbuf
= (void*)__get_free_pages(GFP_KERNEL
|GFP_DMA
, order
))) 1206 db
->buforder
= order
; 1208 if((virt_to_bus(db
->rawbuf
) ^ (virt_to_bus(db
->rawbuf
) + (PAGE_SIZE
<< db
->buforder
) -1)) & ~0xffff) 1209 printk(KERN_DEBUG
"maestro: DMA buffer crosses 64k boundary: busaddr 0x%lx size %ld\n", 1210 virt_to_bus(db
->rawbuf
), PAGE_SIZE
<< db
->buforder
); 1212 if((virt_to_bus(db
->rawbuf
) + (PAGE_SIZE
<< db
->buforder
) -1) & ~0xffffff) 1213 printk(KERN_DEBUG
"maestro: DMA buffer beyond 16MB: busaddr 0x%lx size %ld\n", 1214 virt_to_bus(db
->rawbuf
), PAGE_SIZE
<< db
->buforder
); 1216 /* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */ 1217 mapend
=MAP_NR(db
->rawbuf
+ (PAGE_SIZE
<< db
->buforder
) -1); 1218 for(map
=MAP_NR(db
->rawbuf
); map
<= mapend
; map
++) 1219 set_bit(PG_reserved
, &mem_map
[map
].flags
); 1221 bytepersec
= rate
<< sample_shift
[fmt
]; 1222 bufs
= PAGE_SIZE
<< db
->buforder
; 1223 if(db
->ossfragshift
) { 1224 if((1000<< db
->ossfragshift
) < bytepersec
) 1225 db
->fragshift
=ld2(bytepersec
/1000); 1227 db
->fragshift
= db
->ossfragshift
; 1229 db
->fragshift
=ld2(bytepersec
/100/(db
->subdivision
? db
->subdivision
:1)); 1230 if(db
->fragshift
<3) 1233 db
->numfrag
= bufs
>> db
->fragshift
; 1234 while(db
->numfrag
<4&& db
->fragshift
>3) { 1236 db
->numfrag
= bufs
>> db
->fragshift
; 1238 db
->fragsize
=1<< db
->fragshift
; 1239 if(db
->ossmaxfrags
>=4&& db
->ossmaxfrags
< db
->numfrag
) 1240 db
->numfrag
= db
->ossmaxfrags
; 1241 db
->fragsamples
= db
->fragsize
>> sample_shift
[fmt
]; 1242 db
->dmasize
= db
->numfrag
<< db
->fragshift
; 1243 memset(db
->rawbuf
, (fmt
& ESS_CFMT_16BIT
) ?0:0x80, db
->dmasize
); 1244 spin_lock_irqsave(&s
->lock
, flags
); 1246 set_dmac(s
,virt_to_bus(db
->rawbuf
), db
->numfrag
<< db
->fragshift
); 1247 /* program enhanced mode registers */ 1250 /* set_dmaa(s, virt_to_bus(db->rawbuf), db->numfrag << db->fragshift); */ 1251 /* program enhanced mode registers */ 1253 /*set_dac_rate(s, s->ratedac); redundant */ 1254 ess_play_setup(s
, fmt
, s
->ratedac
, 1255 db
->rawbuf
, db
->numfrag
<< db
->fragshift
); 1257 spin_unlock_irqrestore(&s
->lock
, flags
); 1262 /* XXX haha, way broken with our split stereo setup. giggle. */ 1263 extern __inline__
voidclear_advance(struct ess_state
*s
) 1265 unsigned char c
= (s
->fmt
& (ESS_CFMT_16BIT
<< ESS_CFMT_ASHIFT
)) ?0:0x80; 1266 unsigned char*buf
= s
->dma_dac
.rawbuf
; 1267 unsigned bsize
= s
->dma_dac
.dmasize
; 1268 unsigned bptr
= s
->dma_dac
.swptr
; 1269 unsigned len
= s
->dma_dac
.fragsize
; 1271 if(bptr
+ len
> bsize
) { 1272 unsigned x
= bsize
- bptr
; 1273 memset(buf
+ bptr
, c
, x
); 1274 /* account for wrapping? */ 1278 memset(buf
+ bptr
, c
, len
); 1281 /* call with spinlock held! */ 1282 static voidess_update_ptr(struct ess_state
*s
) 1287 /* ADC is way broken. compare to DAC.. */ 1288 /* update ADC pointer */ 1289 if(s
->dma_adc
.ready
) { 1290 hwptr
= (/*s->dma_adc.dmasize - */get_dmac(s
)) % s
->dma_adc
.dmasize
; 1291 diff
= (s
->dma_adc
.dmasize
+ hwptr
- s
->dma_adc
.hwptr
) % s
->dma_adc
.dmasize
; 1292 s
->dma_adc
.hwptr
= hwptr
; 1293 s
->dma_adc
.total_bytes
+= diff
; 1294 s
->dma_adc
.count
+= diff
; 1295 if(s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
) 1296 wake_up(&s
->dma_adc
.wait
); 1297 if(!s
->dma_adc
.mapped
) { 1298 if(s
->dma_adc
.count
> (signed)(s
->dma_adc
.dmasize
- ((3* s
->dma_adc
.fragsize
) >>1))) { 1299 s
->enable
&= ~ESS_ENABLE_RE
; 1301 wrindir(s, SV_CIENABLE, s->enable); */ 1307 /* update DAC pointer */ 1308 if(s
->dma_dac
.ready
) { 1309 /* this is so gross. */ 1310 hwptr
= (/*s->dma_dac.dmasize -*/get_dmaa(s
)) % s
->dma_dac
.dmasize
; 1311 diff
= (s
->dma_dac
.dmasize
+ hwptr
- s
->dma_dac
.hwptr
) % s
->dma_dac
.dmasize
; 1312 /* M_printk("updating dac: hwptr: %d diff: %d\n",hwptr,diff);*/ 1313 s
->dma_dac
.hwptr
= hwptr
; 1314 s
->dma_dac
.total_bytes
+= diff
; 1315 if(s
->dma_dac
.mapped
) { 1316 s
->dma_dac
.count
+= diff
; 1317 if(s
->dma_dac
.count
>= (signed)s
->dma_dac
.fragsize
) 1318 wake_up(&s
->dma_dac
.wait
); 1320 s
->dma_dac
.count
-= diff
; 1321 /* M_printk("maestro: ess_update_ptr: diff: %d, count: %d\n", diff, s->dma_dac.count); */ 1322 if(s
->dma_dac
.count
<=0) { 1323 s
->enable
&= ~ESS_ENABLE_PE
; 1325 wrindir(s, SV_CIENABLE, s->enable); */ 1326 /* XXX how on earth can calling this with the lock held work.. */ 1328 /* brute force everyone back in sync, sigh */ 1329 s
->dma_dac
.count
=0; 1330 s
->dma_dac
.swptr
=0; 1331 s
->dma_dac
.hwptr
=0; 1333 }else if(s
->dma_dac
.count
<= (signed)s
->dma_dac
.fragsize
&& !s
->dma_dac
.endcleared
) { 1335 s
->dma_dac
.endcleared
=1; 1337 if(s
->dma_dac
.count
+ (signed)s
->dma_dac
.fragsize
<= (signed)s
->dma_dac
.dmasize
) 1338 wake_up(&s
->dma_dac
.wait
); 1343 static voidess_interrupt(int irq
,void*dev_id
,struct pt_regs
*regs
) 1345 struct ess_state
*s
; 1346 struct ess_card
*c
= (struct ess_card
*)dev_id
; 1350 event
=inb(c
->iobase
+0x1A); 1352 outw(inw(c
->iobase
+4)&1, c
->iobase
+4); 1354 /* M_printk("maestro int: %x\n",event);*/ 1358 /* XXX if we have a hw volume control int enable 1359 all the ints? doesn't make sense.. */ 1360 event
=inw(c
->iobase
+0x18); 1361 outb(0xFF, c
->iobase
+0x1A); 1365 /* else ack 'em all, i imagine */ 1366 outb(0xFF, c
->iobase
+0x1A); 1370 * Update the pointers for all APU's we are running. 1375 if(s
->dev_audio
== -1) 1377 spin_lock(&s
->lock
); 1379 spin_unlock(&s
->lock
); 1384 /* --------------------------------------------------------------------- */ 1386 static const char invalid_magic
[] = KERN_CRIT
"maestro: invalid magic value in %s\n"; 1388 #define VALIDATE_MAGIC(FOO,MAG) \ 1390 if (!(FOO) || (FOO)->magic != MAG) { \ 1391 printk(invalid_magic,__FUNCTION__); \ 1396 #define VALIDATE_STATE(a) VALIDATE_MAGIC(a,ESS_STATE_MAGIC) 1397 #define VALIDATE_CARD(a) VALIDATE_MAGIC(a,ESS_CARD_MAGIC) 1399 /* --------------------------------------------------------------------- */ 1401 /* ac97 mixer routines. */ 1403 #define AC97_STEREO_MASK (SOUND_MASK_VOLUME|\ 1404 SOUND_MASK_PCM|SOUND_MASK_LINE|SOUND_MASK_CD|\ 1405 SOUND_MASK_VIDEO|SOUND_MASK_LINE1|SOUND_MASK_IGAIN) 1407 #define AC97_SUPPORTED_MASK (AC97_STEREO_MASK | \ 1408 SOUND_MASK_BASS|SOUND_MASK_TREBLE|SOUND_MASK_MIC|\ 1411 #define AC97_RECORD_MASK (SOUND_MASK_MIC|\ 1412 SOUND_MASK_CD| SOUND_MASK_VIDEO| SOUND_MASK_LINE1| SOUND_MASK_LINE|\ 1415 #define supported_mixer(CARD,FOO) ( CARD->mix.supported_mixers & (1<<FOO) ) 1417 static struct ac97_mixer_hw
{ 1418 unsigned char offset
; 1420 } ac97_hw
[SOUND_MIXER_NRDEVICES
]= { 1421 [SOUND_MIXER_VOLUME
] = {0x02,63}, 1422 [SOUND_MIXER_BASS
] = {0x08,15}, 1423 [SOUND_MIXER_TREBLE
] = {0x08,15}, 1424 [SOUND_MIXER_SPEAKER
] = {0x0a,15}, 1425 [SOUND_MIXER_MIC
] = {0x0e,31}, 1426 [SOUND_MIXER_LINE
] = {0x10,31}, 1427 [SOUND_MIXER_CD
] = {0x12,31}, 1428 [SOUND_MIXER_VIDEO
] = {0x14,31}, 1429 [SOUND_MIXER_LINE1
] = {0x16,31}, 1430 [SOUND_MIXER_PCM
] = {0x18,31}, 1431 [SOUND_MIXER_IGAIN
] = {0x1c,31} 1434 /* reads the given OSS mixer from the ac97 1435 the caller must have insured that the ac97 knows 1436 about that given mixer, and should be holding a 1437 spinlock for the card */ 1438 static intac97_read_mixer(struct ess_card
*card
,int mixer
) 1442 struct ac97_mixer_hw
*mh
= &ac97_hw
[mixer
]; 1444 val
=maestro_ac97_get(card
->iobase
, mh
->offset
); 1446 if(AC97_STEREO_MASK
& (1<<mixer
)) { 1447 /* nice stereo mixers .. */ 1450 left
= (val
>>8) &0x7f; 1453 right
=100- ((right
*100) / mh
->scale
); 1454 left
=100- ((left
*100) / mh
->scale
); 1455 ret
= left
| (right
<<8); 1456 }else if(mixer
== SOUND_MIXER_SPEAKER
) { 1457 ret
=100- ((((val
&0x1e)>>1) *100) / mh
->scale
); 1458 }else if(mixer
== SOUND_MIXER_MIC
) { 1459 ret
=100- (((val
&0x1f) *100) / mh
->scale
); 1460 /* the low bit is optional in the tone sliders and masking 1461 it lets is avoid the 0xf 'bypass'.. */ 1462 }else if(mixer
== SOUND_MIXER_BASS
) { 1463 ret
=100- ((((val
>>8) &0xe) *100) / mh
->scale
); 1464 }else if(mixer
== SOUND_MIXER_TREBLE
) { 1465 ret
=100- (((val
&0xe) *100) / mh
->scale
); 1468 M_printk("read mixer %d (0x%x) %x -> %x\n",mixer
,mh
->offset
,val
,ret
); 1473 /* write the OSS encoded volume to the given OSS encoded mixer, 1474 again caller's job to make sure all is well in arg land, 1475 call with spinlock held */ 1476 static voidac97_write_mixer(struct ess_card
*card
,int mixer
,int vol
) 1479 unsigned left
, right
; 1480 struct ac97_mixer_hw
*mh
= &ac97_hw
[mixer
]; 1482 /* cleanse input a little */ 1483 right
= ((vol
>>8) &0x7f) ; 1484 left
= (vol
&0x7f) ; 1486 if(right
>100) right
=100; 1487 if(left
>100) left
=100; 1489 M_printk("wrote mixer %d (0x%x) %d,%d",mixer
,mh
->offset
,left
,right
); 1491 if(AC97_STEREO_MASK
& (1<<mixer
)) { 1494 right
= ((100- right
) * mh
->scale
) /100; 1495 left
= ((100- left
) * mh
->scale
) /100; 1497 val
= (left
<<8) | right
; 1498 }else if(mixer
== SOUND_MIXER_SPEAKER
) { 1499 val
= (((100- left
) * mh
->scale
) /100) <<1; 1500 }else if(mixer
== SOUND_MIXER_MIC
) { 1501 val
=maestro_ac97_get(card
->iobase
, mh
->offset
) & ~0x001f; 1502 val
|= (((100- left
) * mh
->scale
) /100); 1503 /* the low bit is optional in the tone sliders and masking 1504 it lets is avoid the 0xf 'bypass'.. */ 1505 }else if(mixer
== SOUND_MIXER_BASS
) { 1506 val
=maestro_ac97_get(card
->iobase
, mh
->offset
) & ~0x0f00; 1507 val
|= ((((100- left
) * mh
->scale
) /100) <<8) &0xe0; 1508 }else if(mixer
== SOUND_MIXER_TREBLE
) { 1509 val
=maestro_ac97_get(card
->iobase
, mh
->offset
) & ~0x000f; 1510 val
|= (((100- left
) * mh
->scale
) /100) &0xe; 1513 maestro_ac97_set(card
->iobase
, mh
->offset
, val
); 1515 M_printk(" -> %x\n",val
); 1518 enum ac97_recsettings
{ 1524 AC97_REC_STEREO
,/* combination of all enabled outputs.. */ 1525 AC97_REC_MONO
,/*.. or the mono equivalent */ 1528 static unsigned int ac97_rm2oss
[] = { 1529 [AC97_REC_MIC
] = SOUND_MASK_MIC
, 1530 [AC97_REC_CD
] = SOUND_MASK_CD
, 1531 [AC97_REC_VIDEO
] = SOUND_MASK_VIDEO
, 1532 [AC97_REC_AUX
] = SOUND_MASK_LINE1
, 1533 [AC97_REC_LINE
] = SOUND_MASK_LINE
, 1534 [AC97_REC_PHONE
] = SOUND_MASK_PHONEIN
1537 /* indexed by bit position, XXX dependant on OSS header internals */ 1538 static unsigned int ac97_oss_rm
[] = { 1539 [SOUND_MIXER_MIC
] = AC97_REC_MIC
, 1540 [SOUND_MIXER_CD
] = AC97_REC_CD
, 1541 [SOUND_MIXER_VIDEO
] = AC97_REC_VIDEO
, 1542 [SOUND_MIXER_LINE1
] = AC97_REC_AUX
, 1543 [SOUND_MIXER_LINE
] = AC97_REC_LINE
, 1544 [SOUND_MIXER_PHONEIN
] = AC97_REC_PHONE
1547 /* read or write the recmask 1548 the ac97 can really have left and right recording 1549 inputs independantly set, but OSS doesn't seem to 1550 want us to express that to the user. 1551 the caller guarantees that we have a supported bit set, 1552 and they must be holding the card's spinlock */ 1553 static intac97_recmask_io(struct ess_card
*card
,int rw
,int mask
) 1558 /* read it from the card */ 1559 val
=maestro_ac97_get(card
->iobase
,0x1a) &0x7; 1560 return ac97_rm2oss
[val
]; 1563 /* else, write the first set in the mask as the 1567 val
= ac97_oss_rm
[val
-1]; 1568 val
|= val
<<8;/* set both channels */ 1570 maestro_ac97_set(card
->iobase
,0x1a,val
); 1575 static intac97_mixer_ioctl(struct ess_card
*card
,unsigned int cmd
,unsigned long arg
) 1577 unsigned long flags
; 1579 struct ess_state
*s
= &card
->channels
[0]; 1581 VALIDATE_CARD(card
); 1582 if(cmd
== SOUND_MIXER_INFO
) { 1584 strncpy(info
.id
, card_names
[card
->card_type
],sizeof(info
.id
)); 1585 strncpy(info
.name
,card_names
[card
->card_type
],sizeof(info
.name
)); 1586 info
.modify_counter
= card
->mix
.modcnt
; 1587 if(copy_to_user((void*)arg
, &info
,sizeof(info
))) 1591 if(cmd
== SOUND_OLD_MIXER_INFO
) { 1592 _old_mixer_info info
; 1593 strncpy(info
.id
, card_names
[card
->card_type
],sizeof(info
.id
)); 1594 strncpy(info
.name
,card_names
[card
->card_type
],sizeof(info
.name
)); 1595 if(copy_to_user((void*)arg
, &info
,sizeof(info
))) 1599 if(cmd
== OSS_GETVERSION
) 1600 returnput_user(SOUND_VERSION
, (int*)arg
); 1602 if(_IOC_TYPE(cmd
) !='M'||_IOC_SIZE(cmd
) !=sizeof(int)) 1605 if(_IOC_DIR(cmd
) == _IOC_READ
) { 1606 switch(_IOC_NR(cmd
)) { 1607 case SOUND_MIXER_RECSRC
:/* give them the current record source */ 1608 spin_lock_irqsave(&s
->lock
, flags
); 1609 val
= card
->mix
.recmask_io(card
,1,0); 1610 spin_unlock_irqrestore(&s
->lock
, flags
); 1613 case SOUND_MIXER_DEVMASK
:/* give them the supported mixers */ 1614 val
= card
->mix
.supported_mixers
; 1617 case SOUND_MIXER_RECMASK
:/* Arg contains a bit for each supported recording source */ 1618 val
= card
->mix
.record_sources
; 1621 case SOUND_MIXER_STEREODEVS
:/* Mixer channels supporting stereo */ 1622 val
= card
->mix
.stereo_mixers
; 1625 case SOUND_MIXER_CAPS
: 1626 val
= SOUND_CAP_EXCL_INPUT
; 1629 default:/* read a specific mixer */ 1632 if( !supported_mixer(card
,i
)) 1635 spin_lock_irqsave(&s
->lock
, flags
); 1636 val
= card
->mix
.read_mixer(card
,i
); 1637 spin_unlock_irqrestore(&s
->lock
, flags
); 1641 returnput_user(val
,(int*)arg
); 1644 if(_IOC_DIR(cmd
) != (_IOC_WRITE
|_IOC_READ
)) 1649 get_user_ret(val
, (int*)arg
, -EFAULT
); 1651 switch(_IOC_NR(cmd
)) { 1652 case SOUND_MIXER_RECSRC
:/* Arg contains a bit for each recording source */ 1654 if(! (val
&= card
->mix
.record_sources
))return-EINVAL
; 1656 spin_lock_irqsave(&s
->lock
, flags
); 1657 card
->mix
.recmask_io(card
,0,val
); 1658 spin_unlock_irqrestore(&s
->lock
, flags
); 1664 if( !supported_mixer(card
,i
)) 1667 spin_lock_irqsave(&s
->lock
, flags
); 1668 card
->mix
.write_mixer(card
,i
,val
); 1669 spin_unlock_irqrestore(&s
->lock
, flags
); 1675 /* --------------------------------------------------------------------- */ 1677 static loff_t
ess_llseek(struct file
*file
, loff_t offset
,int origin
) 1682 /* --------------------------------------------------------------------- */ 1684 static intess_open_mixdev(struct inode
*inode
,struct file
*file
) 1686 int minor
=MINOR(inode
->i_rdev
); 1687 struct ess_card
*card
= devs
; 1689 while(card
&& card
->dev_mixer
!= minor
) 1694 file
->private_data
= card
; 1699 static intess_release_mixdev(struct inode
*inode
,struct file
*file
) 1701 struct ess_card
*card
= (struct ess_card
*)file
->private_data
; 1703 VALIDATE_CARD(card
); 1709 static intess_ioctl_mixdev(struct inode
*inode
,struct file
*file
,unsigned int cmd
,unsigned long arg
) 1711 struct ess_card
*card
= (struct ess_card
*)file
->private_data
; 1713 VALIDATE_CARD(card
); 1715 returnac97_mixer_ioctl(card
, cmd
, arg
); 1718 static/*const*/struct file_operations ess_mixer_fops
= { 1728 &ess_release_mixdev
, 1731 NULL
,/* check_media_change */ 1732 NULL
,/* revalidate */ 1736 /* --------------------------------------------------------------------- */ 1738 static intdrain_dac(struct ess_state
*s
,int nonblock
) 1740 DECLARE_WAITQUEUE(wait
,current
); 1741 unsigned long flags
; 1744 if(s
->dma_dac
.mapped
|| !s
->dma_dac
.ready
) 1746 current
->state
= TASK_INTERRUPTIBLE
; 1747 add_wait_queue(&s
->dma_dac
.wait
, &wait
); 1749 spin_lock_irqsave(&s
->lock
, flags
); 1750 count
= s
->dma_dac
.count
; 1751 spin_unlock_irqrestore(&s
->lock
, flags
); 1754 if(signal_pending(current
)) 1757 remove_wait_queue(&s
->dma_dac
.wait
, &wait
); 1758 current
->state
= TASK_RUNNING
; 1761 tmo
= (count
* HZ
) / s
->ratedac
; 1762 tmo
>>= sample_shift
[(s
->fmt
>> ESS_CFMT_ASHIFT
) & ESS_CFMT_MASK
]; 1763 if(!schedule_timeout(tmo
? :1) && tmo
) 1764 printk(KERN_DEBUG
"maestro: dma timed out??\n"); 1766 remove_wait_queue(&s
->dma_dac
.wait
, &wait
); 1767 current
->state
= TASK_RUNNING
; 1768 if(signal_pending(current
)) 1773 /* --------------------------------------------------------------------- */ 1775 static ssize_t
ess_read(struct file
*file
,char*buffer
,size_t count
, loff_t
*ppos
) 1777 struct ess_state
*s
= (struct ess_state
*)file
->private_data
; 1779 unsigned long flags
; 1781 /* for damned dual players */ 1785 if(ppos
!= &file
->f_pos
) 1787 if(s
->dma_adc
.mapped
) 1789 if(!s
->dma_adc
.ready
&& (ret
=prog_dmabuf(s
,1))) 1791 if(!access_ok(VERIFY_WRITE
, buffer
, count
)) 1795 spin_lock_irqsave(&s
->lock
, flags
); 1797 spin_unlock_irqrestore(&s
->lock
, flags
); 1800 spin_lock_irqsave(&s
->lock
, flags
); 1801 swptr
= s
->dma_adc
.swptr
; 1802 cnt
= s
->dma_adc
.dmasize
-swptr
; 1803 if(s
->dma_adc
.count
< cnt
) 1804 cnt
= s
->dma_adc
.count
; 1805 spin_unlock_irqrestore(&s
->lock
, flags
); 1810 if(file
->f_flags
& O_NONBLOCK
) 1811 return ret
? ret
: -EAGAIN
; 1812 if(!interruptible_sleep_on_timeout(&s
->dma_adc
.wait
, HZ
)) { 1813 printk(KERN_DEBUG
"maestro: read: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n", 1814 s
->dma_adc
.dmasize
, s
->dma_adc
.fragsize
, s
->dma_adc
.count
, 1815 s
->dma_adc
.hwptr
, s
->dma_adc
.swptr
); 1817 spin_lock_irqsave(&s
->lock
, flags
); 1818 set_dmac(s
,virt_to_bus(s
->dma_adc
.rawbuf
), s
->dma_adc
.numfrag
<< s
->dma_adc
.fragshift
); 1819 /* program enhanced mode registers */ 1821 /* wrindir(s, SV_CIDMACBASECOUNT1, (s->dma_adc.fragsamples-1) >> 8); 1822 wrindir(s, SV_CIDMACBASECOUNT0, s->dma_adc.fragsamples-1); */ 1823 s
->dma_adc
.count
= s
->dma_adc
.hwptr
= s
->dma_adc
.swptr
=0; 1824 spin_unlock_irqrestore(&s
->lock
, flags
); 1826 if(signal_pending(current
)) 1827 return ret
? ret
: -ERESTARTSYS
; 1830 if(copy_to_user(buffer
, s
->dma_adc
.rawbuf
+ swptr
, cnt
)) 1831 return ret
? ret
: -EFAULT
; 1832 swptr
= (swptr
+ cnt
) % s
->dma_adc
.dmasize
; 1833 spin_lock_irqsave(&s
->lock
, flags
); 1834 s
->dma_adc
.swptr
= swptr
; 1835 s
->dma_adc
.count
-= cnt
; 1836 spin_unlock_irqrestore(&s
->lock
, flags
); 1846 /* god this is gross..*/ 1847 intsplit_stereo(unsigned char*real_buffer
,unsigned char*tmp_buffer
,int offset
, 1848 int count
,int bufsize
,int mode
) 1850 /* oh, bother. stereo decoding APU's don't work in 16bit so we 1851 use dual linear decoders. which means we have to hack up stereo 1852 buffer's we're given. yuck. */ 1854 unsigned char*so
,*left
,*right
; 1858 left
= real_buffer
+ offset
; 1859 right
= real_buffer
+ bufsize
/2+ offset
; 1861 M_printk("writing %d to %p and %p from %p:%d bufs: %d\n",count
/2, left
,right
,real_buffer
,offset
,bufsize
); 1863 if(mode
& ESS_CFMT_16BIT
) { 1864 for(i
=count
/4; i
; i
--) { 1865 *(right
++) = (*(so
+2)); 1866 *(right
++) = (*(so
+3)); 1868 *(left
++) = (*(so
+1)); 1872 for(i
=count
/2; i
; i
--) { 1873 *(right
++) = (*(so
+1)); 1882 static ssize_t
ess_write(struct file
*file
,const char*buffer
,size_t count
, loff_t
*ppos
) 1884 struct ess_state
*s
= (struct ess_state
*)file
->private_data
; 1886 unsigned long flags
; 1888 unsigned char*splitbuf
= NULL
; 1891 /* printk("maestro: ess_write: count %d\n", count);*/ 1894 if(ppos
!= &file
->f_pos
) 1896 if(s
->dma_dac
.mapped
) 1898 if(!s
->dma_dac
.ready
&& (ret
=prog_dmabuf(s
,0))) 1900 if(!access_ok(VERIFY_READ
, buffer
, count
)) 1902 /* XXX be more clever than this.. */ 1903 if(!(splitbuf
=kmalloc(count
,GFP_KERNEL
))) 1907 spin_lock_irqsave(&s
->lock
, flags
); 1909 spin_unlock_irqrestore(&s
->lock
, flags
); 1912 spin_lock_irqsave(&s
->lock
, flags
); 1914 if(s
->dma_dac
.count
<0) { 1915 s
->dma_dac
.count
=0; 1916 s
->dma_dac
.swptr
= s
->dma_dac
.hwptr
; 1918 swptr
= s
->dma_dac
.swptr
; 1920 if(s
->fmt
& ESS_CFMT_STEREO
) { 1921 /* in stereo we have the 'dual' buffers.. */ 1922 cnt
= ((s
->dma_dac
.dmasize
/2)-swptr
)*2; 1924 cnt
= s
->dma_dac
.dmasize
-swptr
; 1926 if(s
->dma_dac
.count
+ cnt
> s
->dma_dac
.dmasize
) 1927 cnt
= s
->dma_dac
.dmasize
- s
->dma_dac
.count
; 1929 spin_unlock_irqrestore(&s
->lock
, flags
); 1934 /* our goofball stereo splitter can only deal in mults of 4 */ 1939 /* buffer is full, wait for it to be played */ 1941 if(file
->f_flags
& O_NONBLOCK
) { 1942 if(!ret
) ret
= -EAGAIN
; 1945 if(!interruptible_sleep_on_timeout(&s
->dma_dac
.wait
, HZ
)) { 1946 printk(KERN_DEBUG
"maestro: write: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n", 1947 s
->dma_dac
.dmasize
, s
->dma_dac
.fragsize
, s
->dma_dac
.count
, 1948 s
->dma_dac
.hwptr
, s
->dma_dac
.swptr
); 1950 spin_lock_irqsave(&s
->lock
, flags
); 1951 set_dmaa(s
,virt_to_bus(s
->dma_dac
.rawbuf
), s
->dma_dac
.numfrag
<< s
->dma_dac
.fragshift
); 1952 /* program enhanced mode registers */ 1953 /* wrindir(s, SV_CIDMAABASECOUNT1, (s->dma_dac.fragsamples-1) >> 8); 1954 wrindir(s, SV_CIDMAABASECOUNT0, s->dma_dac.fragsamples-1); */ 1956 s
->dma_dac
.count
= s
->dma_dac
.hwptr
= s
->dma_dac
.swptr
=0; 1957 spin_unlock_irqrestore(&s
->lock
, flags
); 1959 if(signal_pending(current
)) { 1960 if(!ret
) ret
= -ERESTARTSYS
; 1965 if(s
->fmt
& ESS_CFMT_STEREO
) { 1966 if(copy_from_user(splitbuf
, buffer
, cnt
)) { 1967 if(!ret
) ret
= -EFAULT
; 1970 split_stereo(s
->dma_dac
.rawbuf
,splitbuf
,swptr
,cnt
,s
->dma_dac
.dmasize
,s
->fmt
); 1972 if(copy_from_user(s
->dma_dac
.rawbuf
+ swptr
, buffer
, cnt
)) { 1973 if(!ret
) ret
= -EFAULT
; 1978 if(s
->fmt
& ESS_CFMT_STEREO
) { 1979 /* again with the weird pointer magic*/ 1980 swptr
= (swptr
+ (cnt
/2)) % (s
->dma_dac
.dmasize
/2); 1982 swptr
= (swptr
+ cnt
) % s
->dma_dac
.dmasize
; 1984 spin_lock_irqsave(&s
->lock
, flags
); 1985 s
->dma_dac
.swptr
= swptr
; 1986 s
->dma_dac
.count
+= cnt
; 1987 s
->dma_dac
.endcleared
=0; 1988 spin_unlock_irqrestore(&s
->lock
, flags
); 1995 if(splitbuf
)kfree(splitbuf
); 1999 static unsigned intess_poll(struct file
*file
,struct poll_table_struct
*wait
) 2001 struct ess_state
*s
= (struct ess_state
*)file
->private_data
; 2002 unsigned long flags
; 2003 unsigned int mask
=0; 2006 if(file
->f_mode
& FMODE_WRITE
) 2007 poll_wait(file
, &s
->dma_dac
.wait
, wait
); 2008 if(file
->f_mode
& FMODE_READ
) 2009 poll_wait(file
, &s
->dma_adc
.wait
, wait
); 2010 spin_lock_irqsave(&s
->lock
, flags
); 2012 if(file
->f_mode
& FMODE_READ
) { 2013 if(s
->dma_adc
.count
>= (signed)s
->dma_adc
.fragsize
) 2014 mask
|= POLLIN
| POLLRDNORM
; 2016 if(file
->f_mode
& FMODE_WRITE
) { 2017 if(s
->dma_dac
.mapped
) { 2018 if(s
->dma_dac
.count
>= (signed)s
->dma_dac
.fragsize
) 2019 mask
|= POLLOUT
| POLLWRNORM
; 2021 if((signed)s
->dma_dac
.dmasize
>= s
->dma_dac
.count
+ (signed)s
->dma_dac
.fragsize
) 2022 mask
|= POLLOUT
| POLLWRNORM
; 2025 spin_unlock_irqrestore(&s
->lock
, flags
); 2029 /* this needs to be fixed to deal with the dualing apus/buffers */ 2031 static intess_mmap(struct file
*file
,struct vm_area_struct
*vma
) 2033 struct ess_state
*s
= (struct ess_state
*)file
->private_data
; 2039 if(vma
->vm_flags
& VM_WRITE
) { 2040 if((ret
=prog_dmabuf(s
,1)) !=0) 2043 }else if(vma
->vm_flags
& VM_READ
) { 2044 if((ret
=prog_dmabuf(s
,0)) !=0) 2049 if(vma
->vm_offset
!=0) 2051 size
= vma
->vm_end
- vma
->vm_start
; 2052 if(size
> (PAGE_SIZE
<< db
->buforder
)) 2054 if(remap_page_range(vma
->vm_start
,virt_to_phys(db
->rawbuf
), size
, vma
->vm_page_prot
)) 2061 static intess_ioctl(struct inode
*inode
,struct file
*file
,unsigned int cmd
,unsigned long arg
) 2063 struct ess_state
*s
= (struct ess_state
*)file
->private_data
; 2064 unsigned long flags
; 2065 audio_buf_info abinfo
; 2067 int val
, mapped
, ret
; 2068 unsigned char fmtm
, fmtd
; 2070 /* printk("maestro: ess_ioctl: cmd %d\n", cmd);*/ 2073 mapped
= ((file
->f_mode
& FMODE_WRITE
) && s
->dma_dac
.mapped
) || 2074 ((file
->f_mode
& FMODE_READ
) && s
->dma_adc
.mapped
); 2076 case OSS_GETVERSION
: 2077 returnput_user(SOUND_VERSION
, (int*)arg
); 2079 case SNDCTL_DSP_SYNC
: 2080 if(file
->f_mode
& FMODE_WRITE
) 2081 returndrain_dac(s
,0/*file->f_flags & O_NONBLOCK*/); 2084 case SNDCTL_DSP_SETDUPLEX
: 2087 case SNDCTL_DSP_GETCAPS
: 2088 returnput_user(0/*DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP*/, (int*)arg
); 2090 case SNDCTL_DSP_RESET
: 2091 if(file
->f_mode
& FMODE_WRITE
) { 2094 s
->dma_dac
.swptr
= s
->dma_dac
.hwptr
= s
->dma_dac
.count
= s
->dma_dac
.total_bytes
=0; 2096 if(file
->f_mode
& FMODE_READ
) { 2099 s
->dma_adc
.swptr
= s
->dma_adc
.hwptr
= s
->dma_adc
.count
= s
->dma_adc
.total_bytes
=0; 2103 case SNDCTL_DSP_SPEED
: 2104 get_user_ret(val
, (int*)arg
, -EFAULT
); 2106 if(file
->f_mode
& FMODE_READ
) { 2108 s
->dma_adc
.ready
=0; 2109 set_adc_rate(s
, val
); 2111 if(file
->f_mode
& FMODE_WRITE
) { 2113 s
->dma_dac
.ready
=0; 2114 set_dac_rate(s
, val
); 2117 returnput_user((file
->f_mode
& FMODE_READ
) ? s
->rateadc
: s
->ratedac
, (int*)arg
); 2119 case SNDCTL_DSP_STEREO
: 2120 get_user_ret(val
, (int*)arg
, -EFAULT
); 2123 if(file
->f_mode
& FMODE_READ
) { 2125 s
->dma_adc
.ready
=0; 2127 fmtd
|= ESS_CFMT_STEREO
<< ESS_CFMT_CSHIFT
; 2129 fmtm
&= ~(ESS_CFMT_STEREO
<< ESS_CFMT_CSHIFT
); 2131 if(file
->f_mode
& FMODE_WRITE
) { 2133 s
->dma_dac
.ready
=0; 2135 fmtd
|= ESS_CFMT_STEREO
<< ESS_CFMT_ASHIFT
; 2137 fmtm
&= ~(ESS_CFMT_STEREO
<< ESS_CFMT_ASHIFT
); 2139 set_fmt(s
, fmtm
, fmtd
); 2142 case SNDCTL_DSP_CHANNELS
: 2143 get_user_ret(val
, (int*)arg
, -EFAULT
); 2147 if(file
->f_mode
& FMODE_READ
) { 2149 s
->dma_adc
.ready
=0; 2151 fmtd
|= ESS_CFMT_STEREO
<< ESS_CFMT_CSHIFT
; 2153 fmtm
&= ~(ESS_CFMT_STEREO
<< ESS_CFMT_CSHIFT
); 2155 if(file
->f_mode
& FMODE_WRITE
) { 2157 s
->dma_dac
.ready
=0; 2159 fmtd
|= ESS_CFMT_STEREO
<< ESS_CFMT_ASHIFT
; 2161 fmtm
&= ~(ESS_CFMT_STEREO
<< ESS_CFMT_ASHIFT
); 2163 set_fmt(s
, fmtm
, fmtd
); 2165 returnput_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ? (ESS_CFMT_STEREO
<< ESS_CFMT_CSHIFT
) 2166 : (ESS_CFMT_STEREO
<< ESS_CFMT_ASHIFT
))) ?2:1, (int*)arg
); 2168 case SNDCTL_DSP_GETFMTS
:/* Returns a mask */ 2169 returnput_user(AFMT_S8
|AFMT_S16_LE
, (int*)arg
); 2171 case SNDCTL_DSP_SETFMT
:/* Selects ONE fmt*/ 2172 get_user_ret(val
, (int*)arg
, -EFAULT
); 2173 if(val
!= AFMT_QUERY
) { 2176 if(file
->f_mode
& FMODE_READ
) { 2178 s
->dma_adc
.ready
=0; 2179 if(val
== AFMT_S16_LE
) 2180 fmtd
|= ESS_CFMT_16BIT
<< ESS_CFMT_CSHIFT
; 2182 fmtm
&= ~(ESS_CFMT_16BIT
<< ESS_CFMT_CSHIFT
); 2184 if(file
->f_mode
& FMODE_WRITE
) { 2186 s
->dma_dac
.ready
=0; 2187 if(val
== AFMT_S16_LE
) 2188 fmtd
|= ESS_CFMT_16BIT
<< ESS_CFMT_ASHIFT
; 2190 fmtm
&= ~(ESS_CFMT_16BIT
<< ESS_CFMT_ASHIFT
); 2192 set_fmt(s
, fmtm
, fmtd
); 2194 returnput_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ? 2195 (ESS_CFMT_16BIT
<< ESS_CFMT_CSHIFT
) 2196 : (ESS_CFMT_16BIT
<< ESS_CFMT_ASHIFT
))) ? 2201 case SNDCTL_DSP_POST
: 2204 case SNDCTL_DSP_GETTRIGGER
: 2206 if(file
->f_mode
& FMODE_READ
&& s
->enable
& ESS_ENABLE_RE
) 2207 val
|= PCM_ENABLE_INPUT
; 2208 if(file
->f_mode
& FMODE_WRITE
&& s
->enable
& ESS_ENABLE_PE
) 2209 val
|= PCM_ENABLE_OUTPUT
; 2210 returnput_user(val
, (int*)arg
); 2212 case SNDCTL_DSP_SETTRIGGER
: 2213 get_user_ret(val
, (int*)arg
, -EFAULT
); 2214 if(file
->f_mode
& FMODE_READ
) { 2215 if(val
& PCM_ENABLE_INPUT
) { 2216 if(!s
->dma_adc
.ready
&& (ret
=prog_dmabuf(s
,1))) 2222 if(file
->f_mode
& FMODE_WRITE
) { 2223 if(val
& PCM_ENABLE_OUTPUT
) { 2224 if(!s
->dma_dac
.ready
&& (ret
=prog_dmabuf(s
,0))) 2232 case SNDCTL_DSP_GETOSPACE
: 2233 if(!(file
->f_mode
& FMODE_WRITE
)) 2235 if(!(s
->enable
& ESS_ENABLE_PE
) && (val
=prog_dmabuf(s
,0)) !=0) 2237 spin_lock_irqsave(&s
->lock
, flags
); 2239 abinfo
.fragsize
= s
->dma_dac
.fragsize
; 2240 abinfo
.bytes
= s
->dma_dac
.dmasize
- s
->dma_dac
.count
; 2241 abinfo
.fragstotal
= s
->dma_dac
.numfrag
; 2242 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_dac
.fragshift
; 2243 spin_unlock_irqrestore(&s
->lock
, flags
); 2244 returncopy_to_user((void*)arg
, &abinfo
,sizeof(abinfo
)) ? -EFAULT
:0; 2246 case SNDCTL_DSP_GETISPACE
: 2247 if(!(file
->f_mode
& FMODE_READ
)) 2249 if(!(s
->enable
& ESS_ENABLE_RE
) && (val
=prog_dmabuf(s
,1)) !=0) 2251 spin_lock_irqsave(&s
->lock
, flags
); 2253 abinfo
.fragsize
= s
->dma_adc
.fragsize
; 2254 abinfo
.bytes
= s
->dma_adc
.count
; 2255 abinfo
.fragstotal
= s
->dma_adc
.numfrag
; 2256 abinfo
.fragments
= abinfo
.bytes
>> s
->dma_adc
.fragshift
; 2257 spin_unlock_irqrestore(&s
->lock
, flags
); 2258 returncopy_to_user((void*)arg
, &abinfo
,sizeof(abinfo
)) ? -EFAULT
:0; 2260 case SNDCTL_DSP_NONBLOCK
: 2261 file
->f_flags
|= O_NONBLOCK
; 2264 case SNDCTL_DSP_GETODELAY
: 2265 if(!(file
->f_mode
& FMODE_WRITE
)) 2267 spin_lock_irqsave(&s
->lock
, flags
); 2269 val
= s
->dma_dac
.count
; 2270 spin_unlock_irqrestore(&s
->lock
, flags
); 2271 returnput_user(val
, (int*)arg
); 2273 case SNDCTL_DSP_GETIPTR
: 2274 if(!(file
->f_mode
& FMODE_READ
)) 2276 spin_lock_irqsave(&s
->lock
, flags
); 2278 cinfo
.bytes
= s
->dma_adc
.total_bytes
; 2279 cinfo
.blocks
= s
->dma_adc
.count
>> s
->dma_adc
.fragshift
; 2280 cinfo
.ptr
= s
->dma_adc
.hwptr
; 2281 if(s
->dma_adc
.mapped
) 2282 s
->dma_adc
.count
&= s
->dma_adc
.fragsize
-1; 2283 spin_unlock_irqrestore(&s
->lock
, flags
); 2284 returncopy_to_user((void*)arg
, &cinfo
,sizeof(cinfo
)); 2286 case SNDCTL_DSP_GETOPTR
: 2287 if(!(file
->f_mode
& FMODE_WRITE
)) 2289 spin_lock_irqsave(&s
->lock
, flags
); 2291 cinfo
.bytes
= s
->dma_dac
.total_bytes
; 2292 cinfo
.blocks
= s
->dma_dac
.count
>> s
->dma_dac
.fragshift
; 2293 cinfo
.ptr
= s
->dma_dac
.hwptr
; 2294 if(s
->dma_dac
.mapped
) 2295 s
->dma_dac
.count
&= s
->dma_dac
.fragsize
-1; 2296 spin_unlock_irqrestore(&s
->lock
, flags
); 2297 returncopy_to_user((void*)arg
, &cinfo
,sizeof(cinfo
)); 2299 case SNDCTL_DSP_GETBLKSIZE
: 2300 if(file
->f_mode
& FMODE_WRITE
) { 2301 if((val
=prog_dmabuf(s
,0))) 2303 returnput_user(s
->dma_dac
.fragsize
, (int*)arg
); 2305 if((val
=prog_dmabuf(s
,1))) 2307 returnput_user(s
->dma_adc
.fragsize
, (int*)arg
); 2309 case SNDCTL_DSP_SETFRAGMENT
: 2310 get_user_ret(val
, (int*)arg
, -EFAULT
); 2311 if(file
->f_mode
& FMODE_READ
) { 2312 s
->dma_adc
.ossfragshift
= val
&0xffff; 2313 s
->dma_adc
.ossmaxfrags
= (val
>>16) &0xffff; 2314 if(s
->dma_adc
.ossfragshift
<4) 2315 s
->dma_adc
.ossfragshift
=4; 2316 if(s
->dma_adc
.ossfragshift
>15) 2317 s
->dma_adc
.ossfragshift
=15; 2318 if(s
->dma_adc
.ossmaxfrags
<4) 2319 s
->dma_adc
.ossmaxfrags
=4; 2321 if(file
->f_mode
& FMODE_WRITE
) { 2322 s
->dma_dac
.ossfragshift
= val
&0xffff; 2323 s
->dma_dac
.ossmaxfrags
= (val
>>16) &0xffff; 2324 if(s
->dma_dac
.ossfragshift
<4) 2325 s
->dma_dac
.ossfragshift
=4; 2326 if(s
->dma_dac
.ossfragshift
>15) 2327 s
->dma_dac
.ossfragshift
=15; 2328 if(s
->dma_dac
.ossmaxfrags
<4) 2329 s
->dma_dac
.ossmaxfrags
=4; 2333 case SNDCTL_DSP_SUBDIVIDE
: 2334 if((file
->f_mode
& FMODE_READ
&& s
->dma_adc
.subdivision
) || 2335 (file
->f_mode
& FMODE_WRITE
&& s
->dma_dac
.subdivision
)) 2337 get_user_ret(val
, (int*)arg
, -EFAULT
); 2338 if(val
!=1&& val
!=2&& val
!=4) 2340 if(file
->f_mode
& FMODE_READ
) 2341 s
->dma_adc
.subdivision
= val
; 2342 if(file
->f_mode
& FMODE_WRITE
) 2343 s
->dma_dac
.subdivision
= val
; 2346 case SOUND_PCM_READ_RATE
: 2347 returnput_user((file
->f_mode
& FMODE_READ
) ? s
->rateadc
: s
->ratedac
, (int*)arg
); 2349 case SOUND_PCM_READ_CHANNELS
: 2350 returnput_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ? (ESS_CFMT_STEREO
<< ESS_CFMT_CSHIFT
) 2351 : (ESS_CFMT_STEREO
<< ESS_CFMT_ASHIFT
))) ?2:1, (int*)arg
); 2353 case SOUND_PCM_READ_BITS
: 2354 returnput_user((s
->fmt
& ((file
->f_mode
& FMODE_READ
) ? (ESS_CFMT_16BIT
<< ESS_CFMT_CSHIFT
) 2355 : (ESS_CFMT_16BIT
<< ESS_CFMT_ASHIFT
))) ?16:8, (int*)arg
); 2357 case SOUND_PCM_WRITE_FILTER
: 2358 case SNDCTL_DSP_SETSYNCRO
: 2359 case SOUND_PCM_READ_FILTER
: 2366 static intess_open(struct inode
*inode
,struct file
*file
) 2368 int minor
=MINOR(inode
->i_rdev
); 2369 struct ess_card
*c
= devs
; 2370 struct ess_state
*s
= NULL
, *sp
; 2372 unsigned char fmtm
= ~0, fmts
=0; 2375 * Scan the cards and find the channel. We only 2376 * do this at open time so it is ok 2384 if(sp
->dev_audio
<0) 2386 if((sp
->dev_audio
^ minor
) & ~0xf) 2397 file
->private_data
= s
; 2398 /* wait for device to become free */ 2400 while(s
->open_mode
& file
->f_mode
) { 2401 if(file
->f_flags
& O_NONBLOCK
) { 2406 interruptible_sleep_on(&s
->open_wait
); 2407 if(signal_pending(current
)) 2411 if(file
->f_mode
& FMODE_READ
) { 2412 fmtm
&= ~((ESS_CFMT_STEREO
| ESS_CFMT_16BIT
) << ESS_CFMT_CSHIFT
); 2413 if((minor
&0xf) == SND_DEV_DSP16
) 2414 fmts
|= ESS_CFMT_16BIT
<< ESS_CFMT_CSHIFT
; 2415 s
->dma_adc
.ossfragshift
= s
->dma_adc
.ossmaxfrags
= s
->dma_adc
.subdivision
=0; 2416 set_adc_rate(s
,8000); 2418 if(file
->f_mode
& FMODE_WRITE
) { 2419 fmtm
&= ~((ESS_CFMT_STEREO
| ESS_CFMT_16BIT
) << ESS_CFMT_ASHIFT
); 2420 if((minor
&0xf) == SND_DEV_DSP16
) 2421 fmts
|= ESS_CFMT_16BIT
<< ESS_CFMT_ASHIFT
; 2422 s
->dma_dac
.ossfragshift
= s
->dma_dac
.ossmaxfrags
= s
->dma_dac
.subdivision
=0; 2423 set_dac_rate(s
,8000); 2425 set_fmt(s
, fmtm
, fmts
); 2426 s
->open_mode
|= file
->f_mode
& (FMODE_READ
| FMODE_WRITE
); 2433 static intess_release(struct inode
*inode
,struct file
*file
) 2435 struct ess_state
*s
= (struct ess_state
*)file
->private_data
; 2438 if(file
->f_mode
& FMODE_WRITE
) 2439 drain_dac(s
, file
->f_flags
& O_NONBLOCK
); 2441 if(file
->f_mode
& FMODE_WRITE
) { 2443 dealloc_dmabuf(&s
->dma_dac
); 2445 if(file
->f_mode
& FMODE_READ
) { 2447 dealloc_dmabuf(&s
->dma_adc
); 2449 s
->open_mode
&= (~file
->f_mode
) & (FMODE_READ
|FMODE_WRITE
); 2452 wake_up(&s
->open_wait
); 2457 static/*const*/struct file_operations ess_audio_fops
= { 2464 NULL
,/* XXX &ess_mmap, */ 2470 NULL
,/* check_media_change */ 2471 NULL
,/* revalidate */ 2476 /* --------------------------------------------------------------------- */ 2478 /* XXX get rid of this 2479 * maximum number of devices 2483 /* --------------------------------------------------------------------- */ 2485 static intmaestro_install(struct pci_dev
*pcidev
,int card_type
,int index
) 2491 struct ess_card
*card
; 2492 struct ess_state
*ess
; 2496 iobase
= pcidev
->resource
[0].start
; 2498 if(check_region(iobase
,256)) 2500 printk(KERN_WARNING
"maestro: can't allocate 256 bytes I/O at 0x%4.4x\n", iobase
); 2504 card
=kmalloc(sizeof(struct ess_card
), GFP_KERNEL
); 2507 printk(KERN_WARNING
"maestro: out of memory\n"); 2511 memset(card
,0,sizeof(*card
)); 2513 card
->iobase
= iobase
; 2514 card
->card_type
= card_type
; 2515 card
->irq
= pcidev
->irq
; 2517 card
->magic
= ESS_CARD_MAGIC
; 2520 /* init our 8 groups of 4 apus */ 2523 struct ess_state
*s
=&card
->channels
[i
]; 2526 init_waitqueue_head(&s
->dma_adc
.wait
); 2527 init_waitqueue_head(&s
->dma_dac
.wait
); 2528 init_waitqueue_head(&s
->open_wait
); 2529 init_MUTEX(&s
->open_sem
); 2530 s
->magic
= ESS_STATE_MAGIC
; 2533 s
->apu
[1] = (4*i
)+1; 2534 s
->apu
[2] = (4*i
)+2; 2535 s
->apu
[3] = (4*i
)+3; 2537 if(s
->dma_adc
.ready
|| s
->dma_dac
.ready
|| s
->dma_adc
.rawbuf
) 2539 /* register devices */ 2540 if((s
->dev_audio
=register_sound_dsp(&ess_audio_fops
, -1)) <0) 2546 /* clear the rest if we ran out of slots to register */ 2549 struct ess_state
*s
=&card
->channels
[i
]; 2553 ess
= &card
->channels
[0]; 2556 * Ok card ready. Begin setup proper 2559 printk(KERN_INFO
"maestro: Configuring %s at 0x%04X\n", card_names
[card_type
], iobase
); 2565 pci_write_config_dword(pcidev
,0x54,0x00000000); 2566 pci_write_config_dword(pcidev
,0x56,0x00000000); 2569 * Use TDMA for now. TDMA works on all boards, so while its 2570 * not the most efficient its the simplest. 2573 pci_read_config_word(pcidev
,0x50, &w
); 2575 /* Clear DMA bits */ 2576 w
&=~(1<<10|1<<9|1<<8); 2581 /* XXX do we care about these two ? */ 2586 w
&=~((1<<4)|(1<<3)); 2594 #if 0/* huh? its sub decode.. */ 2597 * Reserved write as 0 2604 * Some of these are undocumented bits 2607 w
&=~(1<<13)|(1<<14);/* PIC Snoop mode bits */ 2608 w
&=~(1<<11);/* Safeguard off */ 2609 w
|= (1<<7);/* Posted write */ 2610 w
|= (1<<6);/* ISA timing on */ 2611 w
&=~(1<<1);/* Subtractive decode off */ 2612 /* XXX huh? claims to be reserved.. */ 2613 w
&=~(1<<5);/* Don't swap left/right */ 2615 pci_write_config_word(pcidev
,0x50, w
); 2617 pci_read_config_word(pcidev
,0x52, &w
); 2618 w
&=~(1<<15);/* Turn off internal clock multiplier */ 2619 /* XXX how do we know which to use? */ 2620 w
&=~(1<<14);/* External clock */ 2622 w
&=~(1<<7);/* HWV off */ 2623 w
&=~(1<<6);/* Debounce off */ 2624 w
&=~(1<<5);/* GPIO 4:5 */ 2625 w
&=~(1<<4);/* Disconnect from the CHI */ 2626 w
&=~(1<<3);/* IDMA off (undocumented) */ 2627 w
&=~(1<<2);/* MIDI fix off (undoc) */ 2628 w
&=~(1<<1);/* reserved, always write 0 */ 2629 w
&=~(1<<0);/* IRQ to ISA off (undoc) */ 2630 pci_write_config_word(pcidev
,0x52, w
); 2636 pci_read_config_word(pcidev
,0x60, &w
); 2638 pci_write_config_word(pcidev
,0x60, w
); 2644 pci_read_config_word(pcidev
,0x40, &w
); 2645 w
|=(1<<15);/* legacy decode off */ 2646 w
&=~(1<<14);/* Disable SIRQ */ 2647 w
&=~(0x1f);/* disable mpu irq/io, game port, fm, SB */ 2649 pci_write_config_word(pcidev
,0x40, w
); 2651 /* stake our claim on the iospace */ 2652 request_region(iobase
,256, card_names
[card_type
]); 2654 sound_reset(iobase
); 2657 /* reset the ring bus */ 2659 outw(inw(iobase
+0x36) &0xdfff, iobase
+0x36);/* disable */ 2660 outw(0xC090, iobase
+0x34); 2662 outw(inw(iobase
+0x36) |0x2000, iobase
+0x36);/* enable */ 2668 /* setup usual 0x34 stuff.. 0x36 may be chip specific */ 2669 outw(0xC090, iobase
+0x34);/* direct sound, stereo */ 2671 outw(0x3000, iobase
+0x36);/* direct sound, stereo */ 2679 maestro_ac97_reset(iobase
); 2688 n
|=12<<12;/* Direct Sound, Stereo */ 2689 outl(n
, iobase
+0x34); 2692 n
&=~0x0F00;/* Modem off */ 2693 outl(n
, iobase
+0x34); 2697 n
|=9<<4;/* DAC, Stereo */ 2698 outl(n
, iobase
+0x34); 2701 n
&=~0x000F;/* ASSP off */ 2702 outl(n
, iobase
+0x34); 2706 n
|=(1<<29);/* Enable ring bus */ 2707 outl(n
, iobase
+0x34); 2711 n
|=(1<<28);/* Enable serial bus */ 2712 outl(n
, iobase
+0x34); 2715 n
&=~0x00F00000;/* MIC off */ 2716 outl(n
, iobase
+0x34); 2719 n
&=~0x000F0000;/* I2S off */ 2720 outl(n
, iobase
+0x34); 2723 w
&=~(1<<7);/* ClkRun off */ 2724 outw(w
, iobase
+0x18); 2727 w
&=~(1<<6);/* Harpo off */ 2728 outw(w
, iobase
+0x18); 2731 w
&=~(1<<4);/* ASSP irq off */ 2732 outw(w
, iobase
+0x18); 2735 w
&=~(1<<3);/* ISDN irq off */ 2736 outw(w
, iobase
+0x18); 2739 w
|=(1<<2);/* Direct Sound IRQ on */ 2740 outw(w
, iobase
+0x18); 2743 w
&=~(1<<1);/* MPU401 IRQ off */ 2744 outw(w
, iobase
+0x18); 2747 w
|=(1<<0);/* SB IRQ on */ 2748 outw(w
, iobase
+0x18); 2754 outb(0, iobase
+0xA4); 2755 outb(3, iobase
+0xA2); 2756 outb(0, iobase
+0xA6); 2759 for(apu
=0;apu
<16;apu
++) 2761 /* Write 0 into the buffer area 0x1E0->1EF */ 2762 outw(0x01E0+apu
,0x10+iobase
); 2763 outw(0x0000,0x12+iobase
); 2766 * The 1.10 test program seem to write 0 into the buffer area 2769 outw(0x01D0+apu
,0x10+iobase
); 2770 outw(0x0000,0x12+iobase
); 2774 wave_set_register(ess
, IDR7_WAVE_ROMRAM
, 2775 (wave_get_register(ess
, IDR7_WAVE_ROMRAM
)&0xFF00)); 2776 wave_set_register(ess
, IDR7_WAVE_ROMRAM
, 2777 wave_get_register(ess
, IDR7_WAVE_ROMRAM
)|0x100); 2778 wave_set_register(ess
, IDR7_WAVE_ROMRAM
, 2779 wave_get_register(ess
, IDR7_WAVE_ROMRAM
)&~0x200); 2780 wave_set_register(ess
, IDR7_WAVE_ROMRAM
, 2781 wave_get_register(ess
, IDR7_WAVE_ROMRAM
)|~0x400); 2783 maestro_write(ess
, IDR7_WAVE_ROMRAM
, 2784 (maestro_read(ess
, IDR7_WAVE_ROMRAM
)&0xFF00)); 2785 maestro_write(ess
, IDR7_WAVE_ROMRAM
, 2786 maestro_read(ess
, IDR7_WAVE_ROMRAM
)|0x100); 2787 maestro_write(ess
, IDR7_WAVE_ROMRAM
, 2788 maestro_read(ess
, IDR7_WAVE_ROMRAM
)&~0x200); 2789 maestro_write(ess
, IDR7_WAVE_ROMRAM
, 2790 maestro_read(ess
, IDR7_WAVE_ROMRAM
)|0x400); 2793 maestro_write(ess
, IDR2_CRAM_DATA
,0x0000); 2794 maestro_write(ess
,0x08,0xB004); 2795 /* Now back to the DirectSound stuff */ 2796 maestro_write(ess
,0x09,0x001B); 2797 maestro_write(ess
,0x0A,0x8000); 2798 maestro_write(ess
,0x0B,0x3F37); 2799 maestro_write(ess
,0x0C,0x0098); 2801 maestro_write(ess
,0x0C, 2802 (maestro_read(ess
,0x0C)&~0xF000)|0x8000); 2803 maestro_write(ess
,0x0C, 2804 (maestro_read(ess
,0x0C)&~0x0F00)|0x0500); 2806 maestro_write(ess
,0x0D,0x7632); 2808 /* Wave cache control on - test off, sg off, 2809 enable, enable extra chans 1Mb */ 2811 outw(inw(0x14+iobase
)|(1<<8),0x14+iobase
); 2812 outw(inw(0x14+iobase
)&0xFE03,0x14+iobase
); 2813 outw((inw(0x14+iobase
)&0xFFFC),0x14+iobase
); 2814 outw(inw(0x14+iobase
)|(1<<7),0x14+iobase
); 2816 outw(0xA1A0,0x14+iobase
);/* 0300 ? */ 2818 if(maestro_ac97_get(iobase
,0x00)==0x0080) 2820 maestro_pt101_init(iobase
); 2824 maestro_ac97_init(iobase
); 2825 card
->mix
.supported_mixers
= AC97_SUPPORTED_MASK
; 2826 card
->mix
.stereo_mixers
= AC97_STEREO_MASK
; 2827 card
->mix
.record_sources
= AC97_RECORD_MASK
; 2828 card
->mix
.read_mixer
= ac97_read_mixer
; 2829 card
->mix
.write_mixer
= ac97_write_mixer
; 2830 card
->mix
.recmask_io
= ac97_recmask_io
; 2832 if((card
->dev_mixer
=register_sound_mixer(&ess_mixer_fops
, -1)) <0) 2833 printk("maestro: couldn't register mixer!\n"); 2836 /* Now clear the channel data */ 2837 for(apu
=0;apu
<64;apu
++) 2840 apu_set_register(ess
, apu
|ESS_CHAN_HARD
, w
,0); 2843 if(request_irq(card
->irq
, ess_interrupt
, SA_SHIRQ
, card_names
[card_type
], card
)) 2845 printk(KERN_ERR
"maestro: unable to allocate irq %d,\n", card
->irq
); 2846 unregister_sound_mixer(card
->dev_mixer
); 2849 struct ess_state
*s
= &card
->channels
[i
]; 2850 if(s
->dev_audio
!= -1) 2851 unregister_sound_dsp(s
->dev_audio
); 2853 release_region(card
->iobase
,256); 2858 printk("maestro: %d channels configured.\n", num
); 2864 int __init
init_module(void) 2866 int __init
init_maestro(void) 2869 struct pci_dev
*pcidev
= NULL
; 2872 if(!pci_present())/* No PCI bus in this machine! */ 2874 printk(KERN_INFO
"maestro: version " DRIVER_VERSION
" time " __TIME__
" " __DATE__
"\n"); 2879 * Find the ESS Maestro 2. 2882 while((pcidev
=pci_find_device(PCI_VENDOR_ESS
, PCI_DEVICE_ID_ESS_ESS1968
, pcidev
))!=NULL
) 2884 index
+=maestro_install(pcidev
, TYPE_MAESTRO2
, index
); 2885 if(index
== NR_DEVICE
) 2890 * Find the ESS Maestro 2E 2893 while((pcidev
=pci_find_device(PCI_VENDOR_ESS
, PCI_DEVICE_ID_ESS_ESS1978
, pcidev
))!=NULL
) 2895 index
+=maestro_install(pcidev
, TYPE_MAESTRO2E
, index
); 2896 if(index
== NR_DEVICE
) 2904 while((pcidev
=pci_find_device(PCI_VENDOR_ESS_OLD
, PCI_DEVICE_ID_ESS_ESS0100
, pcidev
))!=NULL
) 2906 index
+=maestro_install(pcidev
, TYPE_MAESTRO
, index
); 2907 if(index
== NR_DEVICE
) 2915 /* --------------------------------------------------------------------- */ 2919 MODULE_AUTHOR("Alan Cox <alan@redhat.com>"); 2920 MODULE_DESCRIPTION("ESS Maestro Driver"); 2922 MODULE_PARM(debug
,"i"); 2925 voidcleanup_module(void) 2932 #ifndef ESS_HW_TIMER 2933 kill_bob(&s
->channels
[0]); 2935 stop_bob(&s
->channels
[0]); 2937 free_irq(s
->irq
, s
); 2938 unregister_sound_mixer(s
->dev_mixer
); 2941 struct ess_state
*ess
= &s
->channels
[i
]; 2942 if(ess
->dev_audio
!= -1) 2943 unregister_sound_dsp(ess
->dev_audio
); 2945 release_region(s
->iobase
,256); 2948 M_printk("maestro: unloading\n"); 2954 /*============================================================================ 2955 * ex-code that we're not using anymore.. 2956 *============================================================================ 2960 * The ASSP is fortunately not double indexed 2963 static voidassp_set_register(int ioaddr
, u32 reg
, u32 value
) 2965 unsigned long flags
; 2969 outl(reg
, ioaddr
+0x80); 2970 outl(value
, ioaddr
+0x84); 2971 restore_flags(flags
); 2974 static u32
assp_get_register(int ioaddr
, u32 reg
) 2976 unsigned long flags
; 2981 outl(reg
, ioaddr
+0x80); 2982 value
=inl(ioaddr
+0x84); 2983 restore_flags(flags
); 2988 /* the ASP is basically a DSP that one can dma instructions 2989 into. it can do things like surround encoding or 2990 fm synth in sb emul mode. It is highly proprietary 2991 and the ESS dudes are none too excited about telling 2992 us about it. so screw it, we'll just turn it off and 2993 not bother with it. Its not needed for apu/dac work. */ 2996 static voidasp_load(int ioaddr
, u16 l
, u16 h
, u16
*data
,int len
) 2999 outw(l
, ioaddr
+0x80); 3000 outw(h
, ioaddr
+0x82); 3002 outw(*data
++, ioaddr
+0x84); 3005 static voidasp_memset(int ioaddr
, u16 l
, u16 h
, u16 v
,int len
) 3008 outw(l
, ioaddr
+0x80); 3009 outw(h
, ioaddr
+0x82); 3011 outw(v
, ioaddr
+0x84); 3015 * Load a code table into the ASP. 3018 #define ASSP_LOAD_PROGRAM 0x02 3019 #define ASSP_LOAD_DATA 0x03 3021 static voidload_tables(int iobase
) 3023 outb(0x00, ESS_SETUP_A4
+iobase
);/* start ASSP programming */ 3025 asp_load(iobase
,0x0, ASSP_LOAD_PROGRAM
, asp_block_0
, 3026 sizeof(asp_block_0
)/2); 3028 asp_load(iobase
,0x0800, ASSP_LOAD_PROGRAM
, 3029 asp_block_1
,sizeof(asp_block_1
)/2); 3031 asp_memset(iobase
,0x1000, ASSP_LOAD_DATA
,0,1024); 3034 * At page 25 of the Maestro-2E data sheet, Table 7, there is a layout of the 3035 * ASSP memory mapping that describe the 0x2000-0x23FF as a data area. 3036 * The 1.10 version of the test code load 0x3B4 words of data into this area. 3037 * I have grabbed the data with hexdump and inserted them into this code. 3039 asp_load(iobase
,0x2000, ASSP_LOAD_DATA
, asp_block_4
, 3040 sizeof(asp_block_4
)/2); 3042 asp_memset(iobase
,0x11BC, ASSP_LOAD_DATA
,0x18,36); 3044 asp_load(iobase
,0x13DC, ASSP_LOAD_DATA
, asp_block_2
, 3045 sizeof(asp_block_2
)/2); 3047 asp_load(iobase
,0x1300, ASSP_LOAD_DATA
, asp_block_3
, 3048 sizeof(asp_block_3
)/2); 3050 outb(0x41, ESS_SETUP_A4
+iobase
);/* stop programming and run ASSP */ 3053 * Do not use the main maestro_reset. it is known 3054 * to leave certain chips in an unstable state. 3055 * best to just reset the direct sound (apus) and 3056 * assp pieces seperately. 3059 static voidmaestro_reset(int ioaddr
) 3061 outw(0x8000,0x18+ioaddr
); 3063 outw(0x0000,0x18+ioaddr
);