1*433d6423SLionel Sambuc #ifndef SB16_H 2*433d6423SLionel Sambuc #define SB16_H 3*433d6423SLionel Sambuc 4*433d6423SLionel Sambuc #include <minix/sound.h> 5*433d6423SLionel Sambuc #include <minix/audio_fw.h> 6*433d6423SLionel Sambuc 7*433d6423SLionel Sambuc #if DEBUG 8*433d6423SLionel Sambuc #define Dprint(args) printf args 9*433d6423SLionel Sambuc #else 10*433d6423SLionel Sambuc #define Dprint(args) 11*433d6423SLionel Sambuc #endif 12*433d6423SLionel Sambuc 13*433d6423SLionel Sambuc #define AUDIO 0 14*433d6423SLionel Sambuc #define MIXER 1 15*433d6423SLionel Sambuc 16*433d6423SLionel Sambuc #define SB_TIMEOUT 32000 /* timeout count */ 17*433d6423SLionel Sambuc 18*433d6423SLionel Sambuc /* IRQ, base address and DMA channels */ 19*433d6423SLionel Sambuc #define SB_IRQ 7 20*433d6423SLionel Sambuc #define SB_BASE_ADDR 0x220 /* 0x210, 0x220, 0x230, 0x240, 21*433d6423SLionel Sambuc * 0x250, 0x260, 0x280 22*433d6423SLionel Sambuc */ 23*433d6423SLionel Sambuc #define SB_DMA_8 1 /* 0, 1, 3 */ 24*433d6423SLionel Sambuc #define SB_DMA_16 5 /* 5, 6, 7 */ 25*433d6423SLionel Sambuc 26*433d6423SLionel Sambuc /* Some defaults for the DSP */ 27*433d6423SLionel Sambuc #define DEFAULT_SPEED 22050 /* Sample rate */ 28*433d6423SLionel Sambuc #define DEFAULT_BITS 8 /* Nr. of bits */ 29*433d6423SLionel Sambuc #define DEFAULT_SIGN 0 /* 0 = unsigned, 1 = signed */ 30*433d6423SLionel Sambuc #define DEFAULT_STEREO 0 /* 0 = mono, 1 = stereo */ 31*433d6423SLionel Sambuc 32*433d6423SLionel Sambuc /* DMA port addresses */ 33*433d6423SLionel Sambuc #define DMA8_ADDR ((SB_DMA_8 & 3) << 1) + 0x00 34*433d6423SLionel Sambuc #define DMA8_COUNT ((SB_DMA_8 & 3) << 1) + 0x01 35*433d6423SLionel Sambuc #define DMA8_MASK 0x0A 36*433d6423SLionel Sambuc #define DMA8_MODE 0x0B 37*433d6423SLionel Sambuc #define DMA8_CLEAR 0x0C 38*433d6423SLionel Sambuc 39*433d6423SLionel Sambuc 40*433d6423SLionel Sambuc /* If after this preprocessing stuff DMA8_PAGE is not defined 41*433d6423SLionel Sambuc * the 8-bit DMA channel specified is not valid 42*433d6423SLionel Sambuc */ 43*433d6423SLionel Sambuc #if SB_DMA_8 == 0 44*433d6423SLionel Sambuc # define DMA8_PAGE 0x87 45*433d6423SLionel Sambuc #else 46*433d6423SLionel Sambuc # if SB_DMA_8 == 1 47*433d6423SLionel Sambuc # define DMA8_PAGE 0x83 48*433d6423SLionel Sambuc # else 49*433d6423SLionel Sambuc # if SB_DMA_8 == 3 50*433d6423SLionel Sambuc # define DMA8_PAGE 0x82 51*433d6423SLionel Sambuc # endif 52*433d6423SLionel Sambuc # endif 53*433d6423SLionel Sambuc #endif 54*433d6423SLionel Sambuc 55*433d6423SLionel Sambuc 56*433d6423SLionel Sambuc #define DMA16_ADDR ((SB_DMA_16 & 3) << 2) + 0xC0 57*433d6423SLionel Sambuc #define DMA16_COUNT ((SB_DMA_16 & 3) << 2) + 0xC2 58*433d6423SLionel Sambuc #define DMA16_MASK 0xD4 59*433d6423SLionel Sambuc #define DMA16_MODE 0xD6 60*433d6423SLionel Sambuc #define DMA16_CLEAR 0xD8 61*433d6423SLionel Sambuc 62*433d6423SLionel Sambuc 63*433d6423SLionel Sambuc /* If after this preprocessing stuff DMA16_PAGE is not defined 64*433d6423SLionel Sambuc * the 16-bit DMA channel specified is not valid 65*433d6423SLionel Sambuc */ 66*433d6423SLionel Sambuc #if SB_DMA_16 == 5 67*433d6423SLionel Sambuc # define DMA16_PAGE 0x8B 68*433d6423SLionel Sambuc #else 69*433d6423SLionel Sambuc # if SB_DMA_16 == 6 70*433d6423SLionel Sambuc # define DMA16_PAGE 0x89 71*433d6423SLionel Sambuc # else 72*433d6423SLionel Sambuc # if SB_DMA_16 == 7 73*433d6423SLionel Sambuc # define DMA16_PAGE 0x8A 74*433d6423SLionel Sambuc # endif 75*433d6423SLionel Sambuc # endif 76*433d6423SLionel Sambuc #endif 77*433d6423SLionel Sambuc 78*433d6423SLionel Sambuc 79*433d6423SLionel Sambuc /* DMA modes */ 80*433d6423SLionel Sambuc #define DMA16_AUTO_PLAY 0x58 + (SB_DMA_16 & 3) 81*433d6423SLionel Sambuc #define DMA16_AUTO_REC 0x54 + (SB_DMA_16 & 3) 82*433d6423SLionel Sambuc #define DMA8_AUTO_PLAY 0x58 + SB_DMA_8 83*433d6423SLionel Sambuc #define DMA8_AUTO_REC 0x54 + SB_DMA_8 84*433d6423SLionel Sambuc 85*433d6423SLionel Sambuc 86*433d6423SLionel Sambuc /* IO ports for soundblaster */ 87*433d6423SLionel Sambuc #define DSP_RESET 0x6 + SB_BASE_ADDR 88*433d6423SLionel Sambuc #define DSP_READ 0xA + SB_BASE_ADDR 89*433d6423SLionel Sambuc #define DSP_WRITE 0xC + SB_BASE_ADDR 90*433d6423SLionel Sambuc #define DSP_COMMAND 0xC + SB_BASE_ADDR 91*433d6423SLionel Sambuc #define DSP_STATUS 0xC + SB_BASE_ADDR 92*433d6423SLionel Sambuc #define DSP_DATA_AVL 0xE + SB_BASE_ADDR 93*433d6423SLionel Sambuc #define DSP_DATA16_AVL 0xF + SB_BASE_ADDR 94*433d6423SLionel Sambuc #define MIXER_REG 0x4 + SB_BASE_ADDR 95*433d6423SLionel Sambuc #define MIXER_DATA 0x5 + SB_BASE_ADDR 96*433d6423SLionel Sambuc #define OPL3_LEFT 0x0 + SB_BASE_ADDR 97*433d6423SLionel Sambuc #define OPL3_RIGHT 0x2 + SB_BASE_ADDR 98*433d6423SLionel Sambuc #define OPL3_BOTH 0x8 + SB_BASE_ADDR 99*433d6423SLionel Sambuc 100*433d6423SLionel Sambuc 101*433d6423SLionel Sambuc /* DSP Commands */ 102*433d6423SLionel Sambuc #define DSP_INPUT_RATE 0x42 /* set input sample rate */ 103*433d6423SLionel Sambuc #define DSP_OUTPUT_RATE 0x41 /* set output sample rate */ 104*433d6423SLionel Sambuc #define DSP_CMD_SPKON 0xD1 /* set speaker on */ 105*433d6423SLionel Sambuc #define DSP_CMD_SPKOFF 0xD3 /* set speaker off */ 106*433d6423SLionel Sambuc #define DSP_CMD_DMA8HALT 0xD0 /* halt DMA 8-bit operation */ 107*433d6423SLionel Sambuc #define DSP_CMD_DMA8CONT 0xD4 /* continue DMA 8-bit operation */ 108*433d6423SLionel Sambuc #define DSP_CMD_DMA16HALT 0xD5 /* halt DMA 16-bit operation */ 109*433d6423SLionel Sambuc #define DSP_CMD_DMA16CONT 0xD6 /* continue DMA 16-bit operation */ 110*433d6423SLionel Sambuc #define DSP_GET_VERSION 0xE1 /* get version number of DSP */ 111*433d6423SLionel Sambuc #define DSP_CMD_8BITAUTO_IN 0xCE /* 8 bit auto-initialized input */ 112*433d6423SLionel Sambuc #define DSP_CMD_8BITAUTO_OUT 0xC6 /* 8 bit auto-initialized output */ 113*433d6423SLionel Sambuc #define DSP_CMD_16BITAUTO_IN 0xBE /* 16 bit auto-initialized input */ 114*433d6423SLionel Sambuc #define DSP_CMD_16BITAUTO_OUT 0xB6 /* 16 bit auto-initialized output */ 115*433d6423SLionel Sambuc #define DSP_CMD_IRQREQ8 0xF2 /* Interrupt request 8 bit */ 116*433d6423SLionel Sambuc #define DSP_CMD_IRQREQ16 0xF3 /* Interrupt request 16 bit */ 117*433d6423SLionel Sambuc 118*433d6423SLionel Sambuc 119*433d6423SLionel Sambuc /* DSP Modes */ 120*433d6423SLionel Sambuc #define DSP_MODE_MONO_US 0x00 /* Mono unsigned */ 121*433d6423SLionel Sambuc #define DSP_MODE_MONO_S 0x10 /* Mono signed */ 122*433d6423SLionel Sambuc #define DSP_MODE_STEREO_US 0x20 /* Stereo unsigned */ 123*433d6423SLionel Sambuc #define DSP_MODE_STEREO_S 0x30 /* Stereo signed */ 124*433d6423SLionel Sambuc 125*433d6423SLionel Sambuc 126*433d6423SLionel Sambuc /* MIXER commands */ 127*433d6423SLionel Sambuc #define MIXER_RESET 0x00 /* Reset */ 128*433d6423SLionel Sambuc #define MIXER_DAC_LEVEL 0x04 /* Used for detection only */ 129*433d6423SLionel Sambuc #define MIXER_MASTER_LEFT 0x30 /* Master volume left */ 130*433d6423SLionel Sambuc #define MIXER_MASTER_RIGHT 0x31 /* Master volume right */ 131*433d6423SLionel Sambuc #define MIXER_DAC_LEFT 0x32 /* Dac level left */ 132*433d6423SLionel Sambuc #define MIXER_DAC_RIGHT 0x33 /* Dac level right */ 133*433d6423SLionel Sambuc #define MIXER_FM_LEFT 0x34 /* Fm level left */ 134*433d6423SLionel Sambuc #define MIXER_FM_RIGHT 0x35 /* Fm level right */ 135*433d6423SLionel Sambuc #define MIXER_CD_LEFT 0x36 /* Cd audio level left */ 136*433d6423SLionel Sambuc #define MIXER_CD_RIGHT 0x37 /* Cd audio level right */ 137*433d6423SLionel Sambuc #define MIXER_LINE_LEFT 0x38 /* Line in level left */ 138*433d6423SLionel Sambuc #define MIXER_LINE_RIGHT 0x39 /* Line in level right */ 139*433d6423SLionel Sambuc #define MIXER_MIC_LEVEL 0x3A /* Microphone level */ 140*433d6423SLionel Sambuc #define MIXER_PC_LEVEL 0x3B /* Pc speaker level */ 141*433d6423SLionel Sambuc #define MIXER_OUTPUT_CTRL 0x3C /* Output control */ 142*433d6423SLionel Sambuc #define MIXER_IN_LEFT 0x3D /* Input control left */ 143*433d6423SLionel Sambuc #define MIXER_IN_RIGHT 0x3E /* Input control right */ 144*433d6423SLionel Sambuc #define MIXER_GAIN_IN_LEFT 0x3F /* Input gain control left */ 145*433d6423SLionel Sambuc #define MIXER_GAIN_IN_RIGHT 0x40 /* Input gain control right */ 146*433d6423SLionel Sambuc #define MIXER_GAIN_OUT_LEFT 0x41 /* Output gain control left */ 147*433d6423SLionel Sambuc #define MIXER_GAIN_OUT_RIGHT 0x42 /* Output gain control rigth */ 148*433d6423SLionel Sambuc #define MIXER_AGC 0x43 /* Automatic gain control */ 149*433d6423SLionel Sambuc #define MIXER_TREBLE_LEFT 0x44 /* Treble left */ 150*433d6423SLionel Sambuc #define MIXER_TREBLE_RIGHT 0x45 /* Treble right */ 151*433d6423SLionel Sambuc #define MIXER_BASS_LEFT 0x46 /* Bass left */ 152*433d6423SLionel Sambuc #define MIXER_BASS_RIGHT 0x47 /* Bass right */ 153*433d6423SLionel Sambuc #define MIXER_SET_IRQ 0x80 /* Set irq number */ 154*433d6423SLionel Sambuc #define MIXER_SET_DMA 0x81 /* Set DMA channels */ 155*433d6423SLionel Sambuc #define MIXER_IRQ_STATUS 0x82 /* Irq status */ 156*433d6423SLionel Sambuc 157*433d6423SLionel Sambuc /* Mixer constants */ 158*433d6423SLionel Sambuc #define MIC 0x01 /* Microphone */ 159*433d6423SLionel Sambuc #define CD_RIGHT 0x02 160*433d6423SLionel Sambuc #define CD_LEFT 0x04 161*433d6423SLionel Sambuc #define LINE_RIGHT 0x08 162*433d6423SLionel Sambuc #define LINE_LEFT 0x10 163*433d6423SLionel Sambuc #define FM_RIGHT 0x20 164*433d6423SLionel Sambuc #define FM_LEFT 0x40 165*433d6423SLionel Sambuc 166*433d6423SLionel Sambuc /* DSP constants */ 167*433d6423SLionel Sambuc #define DSP_MAX_SPEED 44100 /* Max sample speed in KHz */ 168*433d6423SLionel Sambuc #define DSP_MIN_SPEED 4000 /* Min sample speed in KHz */ 169*433d6423SLionel Sambuc 170*433d6423SLionel Sambuc 171*433d6423SLionel Sambuc /* Number of bytes you can DMA before hitting a 64K boundary: */ 172*433d6423SLionel Sambuc #define dma_bytes_left(phys) \ 173*433d6423SLionel Sambuc ((unsigned) (sizeof(int) == 2 ? 0 : 0x10000) - (unsigned) ((phys) & 0xFFFF)) 174*433d6423SLionel Sambuc 175*433d6423SLionel Sambuc int dsp_command(int value); 176*433d6423SLionel Sambuc int sb16_inb(int port); 177*433d6423SLionel Sambuc void sb16_outb(int port, int value); 178*433d6423SLionel Sambuc 179*433d6423SLionel Sambuc #endif /* SB16_H */ 180