root/drivers/cdrom/optcd_isp16.h

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. isp16_detect
  2. isp16_c928__detect
  3. isp16_c929__detect
  4. isp16_cdi_config
  5. isp16_sound_config

   1 /* linux/drivers/cdrom/optcd_isp16.h - ISP16 CDROM interface configuration
   2    $Id: optcd_isp16.h,v 1.3 1996/01/15 18:43:11 root Exp root $
   3 
   4    Extracts from linux/drivers/cdrom/sjcd.c
   5    For copyrights see linux/drivers/cdrom/optcd.c
   6 */
   7 
   8 
   9 /* Some (Media)Magic */
  10 /* define types of drive the interface on an ISP16 card may be looking at */
  11 #define ISP16_DRIVE_X 0x00
  12 #define ISP16_SONY  0x02
  13 #define ISP16_PANASONIC0 0x02
  14 #define ISP16_SANYO0 0x02
  15 #define ISP16_MITSUMI  0x04
  16 #define ISP16_PANASONIC1 0x06
  17 #define ISP16_SANYO1 0x06
  18 #define ISP16_DRIVE_NOT_USED 0x08  /* not used */
  19 #define ISP16_DRIVE_SET_MASK 0xF1  /* don't change 0-bit or 4-7-bits*/
  20 /* ...for port */
  21 #define ISP16_DRIVE_SET_PORT 0xF8D
  22 /* set io parameters */
  23 #define ISP16_BASE_340  0x00
  24 #define ISP16_BASE_330  0x40
  25 #define ISP16_BASE_360  0x80
  26 #define ISP16_BASE_320  0xC0
  27 #define ISP16_IRQ_X  0x00
  28 #define ISP16_IRQ_5  0x04  /* shouldn't be used due to soundcard conflicts */
  29 #define ISP16_IRQ_7  0x08  /* shouldn't be used due to soundcard conflicts */
  30 #define ISP16_IRQ_3  0x0C
  31 #define ISP16_IRQ_9  0x10
  32 #define ISP16_IRQ_10  0x14
  33 #define ISP16_IRQ_11  0x18
  34 #define ISP16_DMA_X  0x03
  35 #define ISP16_DMA_3  0x00
  36 #define ISP16_DMA_5  0x00
  37 #define ISP16_DMA_6  0x01
  38 #define ISP16_DMA_7  0x02
  39 #define ISP16_IO_SET_MASK  0x20  /* don't change 5-bit */
  40 /* ...for port */
  41 #define ISP16_IO_SET_PORT  0xF8E
  42 /* enable the card */
  43 #define ISP16_C928__ENABLE_PORT  0xF90  /* ISP16 with OPTi 82C928 chip */
  44 #define ISP16_C929__ENABLE_PORT  0xF91  /* ISP16 with OPTi 82C929 chip */
  45 #define ISP16_ENABLE_CDROM  0x80  /* seven bit */
  46 
  47 /* the magic stuff */
  48 #define ISP16_CTRL_PORT  0xF8F
  49 #define ISP16_C928__CTRL  0xE2  /* ISP16 with OPTi 82C928 chip */
  50 #define ISP16_C929__CTRL  0xE3  /* ISP16 with OPTi 82C929 chip */
  51 
  52 static short isp16_detect(void);
  53 static short isp16_c928__detect(void);
  54 static short isp16_c929__detect(void);
  55 static short isp16_cdi_config( int base, u_char drive_type, int irq, int dma );
  56 static void isp16_sound_config( void );
  57 static short isp16_type; /* dependent on type of interface card */
  58 static u_char isp16_ctrl;
  59 static u_short isp16_enable_port;
  60 
  61 /*static int sjcd_present = 0;*/
  62 static u_char special_mask = 0;
  63 
  64 static unsigned char defaults[ 16 ] = {
  65   0xA8, 0xA8, 0x18, 0x18, 0x18, 0x18, 0x8E, 0x8E,
  66   0x03, 0x00, 0x02, 0x00, 0x0A, 0x00, 0x00, 0x00
  67 };
  68 /* ------------- */
  69 /*
  70  * -- ISP16 detection and configuration
  71  *
  72  *    Copyright (c) 1995, Eric van der Maarel <maarel@marin.nl>
  73  *
  74  *    Version 0.5
  75  *
  76  *    Detect cdrom interface on ISP16 soundcard.
  77  *    Configure cdrom interface.
  78  *    Configure sound interface.
  79  *
  80  *    Algorithm for the card with OPTi 82C928 taken
  81  *    from the CDSETUP.SYS driver for MSDOS,
  82  *    by OPTi Computers, version 2.03.
  83  *    Algorithm for the card with OPTi 82C929 as communicated
  84  *    to me by Vadim Model and Leo Spiekman.
  85  *
  86  *    Use, modifification or redistribution of this software is
  87  *    allowed under the terms of the GPL.
  88  *
  89  */
  90 
  91 
  92 #define ISP16_IN(p) (outb(isp16_ctrl,ISP16_CTRL_PORT), inb(p))
  93 #define ISP16_OUT(p,b) (outb(isp16_ctrl,ISP16_CTRL_PORT), outb(b,p))
  94 
  95 static short
  96 isp16_detect(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  97 {
  98 
  99   if ( !( isp16_c929__detect() < 0 ) )
 100     return(2);
 101   else
 102     return( isp16_c928__detect() );
 103 }
 104 
 105 static short
 106 isp16_c928__detect(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 107 {
 108   u_char ctrl;
 109   u_char enable_cdrom;
 110   u_char io;
 111   short i = -1;
 112 
 113   isp16_ctrl = ISP16_C928__CTRL;
 114   isp16_enable_port = ISP16_C928__ENABLE_PORT;
 115 
 116   /* read' and write' are a special read and write, respectively */
 117 
 118   /* read' ISP16_CTRL_PORT, clear last two bits and write' back the result */
 119   ctrl = ISP16_IN( ISP16_CTRL_PORT ) & 0xFC;
 120   ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 121 
 122   /* read' 3,4 and 5-bit from the cdrom enable port */
 123   enable_cdrom = ISP16_IN( ISP16_C928__ENABLE_PORT ) & 0x38;
 124 
 125   if ( !(enable_cdrom & 0x20) ) {  /* 5-bit not set */
 126     /* read' last 2 bits of ISP16_IO_SET_PORT */
 127     io = ISP16_IN( ISP16_IO_SET_PORT ) & 0x03;
 128     if ( ((io&0x01)<<1) == (io&0x02) ) {  /* bits are the same */
 129       if ( io == 0 ) {  /* ...the same and 0 */
 130         i = 0;
 131         enable_cdrom |= 0x20;
 132       }
 133       else {  /* ...the same and 1 */  /* my card, first time 'round */
 134         i = 1;
 135         enable_cdrom |= 0x28;
 136       }
 137       ISP16_OUT( ISP16_C928__ENABLE_PORT, enable_cdrom );
 138     }
 139     else {  /* bits are not the same */
 140       ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 141       return(i); /* -> not detected: possibly incorrect conclusion */
 142     }
 143   }
 144   else if ( enable_cdrom == 0x20 )
 145     i = 0;
 146   else if ( enable_cdrom == 0x28 )  /* my card, already initialised */
 147     i = 1;
 148 
 149   ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 150 
 151   return(i);
 152 }
 153 
 154 static short
 155 isp16_c929__detect(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 156 {
 157   u_char ctrl;
 158   u_char tmp;
 159 
 160   isp16_ctrl = ISP16_C929__CTRL;
 161   isp16_enable_port = ISP16_C929__ENABLE_PORT;
 162 
 163   /* read' and write' are a special read and write, respectively */
 164 
 165   /* read' ISP16_CTRL_PORT and save */
 166   ctrl = ISP16_IN( ISP16_CTRL_PORT );
 167 
 168   /* write' zero to the ctrl port and get response */
 169   ISP16_OUT( ISP16_CTRL_PORT, 0 );
 170   tmp = ISP16_IN( ISP16_CTRL_PORT );
 171 
 172   if ( tmp != 2 )  /* isp16 with 82C929 not detected */
 173     return(-1);
 174 
 175   /* restore ctrl port value */
 176   ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 177   
 178   return(2);
 179 }
 180 
 181 static short
 182 isp16_cdi_config( int base, u_char drive_type, int irq, int dma )
     /* [previous][next][first][last][top][bottom][index][help] */
 183 {
 184   u_char base_code;
 185   u_char irq_code;
 186   u_char dma_code;
 187   u_char i;
 188 
 189   if ( (drive_type == ISP16_MITSUMI) && (dma != 0) )
 190     printk( "Mitsumi cdrom drive has no dma support.\n" );
 191 
 192   switch (base) {
 193   case 0x340: base_code = ISP16_BASE_340; break;
 194   case 0x330: base_code = ISP16_BASE_330; break;
 195   case 0x360: base_code = ISP16_BASE_360; break;
 196   case 0x320: base_code = ISP16_BASE_320; break;
 197   default:
 198     printk( "Base address 0x%03X not supported by cdrom interface on ISP16.\n", base );
 199     return(-1);
 200   }
 201   switch (irq) {
 202   case 0: irq_code = ISP16_IRQ_X; break; /* disable irq */
 203   case 5: irq_code = ISP16_IRQ_5;
 204           printk( "Irq 5 shouldn't be used by cdrom interface on ISP16,"
 205             " due to possible conflicts with the soundcard.\n");
 206           break;
 207   case 7: irq_code = ISP16_IRQ_7;
 208           printk( "Irq 7 shouldn't be used by cdrom interface on ISP16,"
 209             " due to possible conflicts with the soundcard.\n");
 210           break;
 211   case 3: irq_code = ISP16_IRQ_3; break;
 212   case 9: irq_code = ISP16_IRQ_9; break;
 213   case 10: irq_code = ISP16_IRQ_10; break;
 214   case 11: irq_code = ISP16_IRQ_11; break;
 215   default:
 216     printk( "Irq %d not supported by cdrom interface on ISP16.\n", irq );
 217     return(-1);
 218   }
 219   switch (dma) {
 220   case 0: dma_code = ISP16_DMA_X; break;  /* disable dma */
 221   case 1: printk( "Dma 1 cannot be used by cdrom interface on ISP16,"
 222             " due to conflict with the soundcard.\n");
 223           return(-1); break;
 224   case 3: dma_code = ISP16_DMA_3; break;
 225   case 5: dma_code = ISP16_DMA_5; break;
 226   case 6: dma_code = ISP16_DMA_6; break;
 227   case 7: dma_code = ISP16_DMA_7; break;
 228   default:
 229     printk( "Dma %d not supported by cdrom interface on ISP16.\n", dma );
 230     return(-1);
 231   }
 232 
 233   if ( drive_type != ISP16_SONY && drive_type != ISP16_PANASONIC0 &&
 234     drive_type != ISP16_PANASONIC1 && drive_type != ISP16_SANYO0 &&
 235     drive_type != ISP16_SANYO1 && drive_type != ISP16_MITSUMI &&
 236     drive_type != ISP16_DRIVE_X ) {
 237     printk( "Drive type (code 0x%02X) not supported by cdrom"
 238      " interface on ISP16.\n", drive_type );
 239     return(-1);
 240   }
 241 
 242   /* set type of interface */
 243   i = ISP16_IN(ISP16_DRIVE_SET_PORT) & ISP16_DRIVE_SET_MASK;  /* clear some bits */
 244   ISP16_OUT( ISP16_DRIVE_SET_PORT, i|drive_type );
 245 
 246   /* enable cdrom on interface with 82C929 chip */
 247   if ( isp16_type > 1 )
 248     ISP16_OUT( isp16_enable_port, ISP16_ENABLE_CDROM );
 249 
 250   /* set base address, irq and dma */
 251   i = ISP16_IN(ISP16_IO_SET_PORT) & ISP16_IO_SET_MASK;  /* keep some bits */
 252   ISP16_OUT( ISP16_IO_SET_PORT, i|base_code|irq_code|dma_code );
 253 
 254   return(0);
 255 }
 256 
 257 static void isp16_sound_config( void )
     /* [previous][next][first][last][top][bottom][index][help] */
 258 {
 259   int i;
 260   u_char saved;
 261 
 262   saved = ISP16_IN( 0xF8D ) & 0x8F;
 263     
 264   ISP16_OUT( 0xF8D, 0x40 );
 265 
 266   /*
 267    * Now we should wait for a while...
 268    */
 269   for( i = 16*1024; i--; );
 270   
 271   ISP16_OUT( 0xF8D, saved );
 272 
 273   ISP16_OUT( 0xF91, 0x1B );
 274 
 275   for( i = 5*64*1024; i != 0; i-- )
 276     if( !( inb( 0x534 ) & 0x80 ) ) break;
 277 
 278   if( i > 0 ) {
 279     saved = ( inb( 0x534 ) & 0xE0 ) | 0x0A;
 280     outb( saved, 0x534 );
 281 
 282     special_mask = ( inb( 0x535 ) >> 4 ) & 0x08;
 283 
 284     saved = ( inb( 0x534 ) & 0xE0 ) | 0x0C;
 285     outb( saved, 0x534 );
 286 
 287     switch( inb( 0x535 ) ) {
 288       case 0x09:
 289       case 0x0A:
 290         special_mask |= 0x05;
 291         break;
 292       case 0x8A:
 293         special_mask = 0x0F;
 294         break;
 295       default:
 296         i = 0;
 297     }
 298   }
 299   if ( i == 0 ) {
 300     printk( "Strange MediaMagic, but\n" );
 301   }
 302   else {
 303     printk( "Conf:" );
 304     saved = inb( 0x534 ) & 0xE0;
 305     for( i = 0; i < 16; i++ ) {
 306       outb( 0x20 | ( u_char )i, 0x534 );
 307       outb( defaults[i], 0x535 );
 308     }
 309     for ( i = 0; i < 16; i++ ) {
 310       outb( 0x20 | ( u_char )i, 0x534 );
 311       saved = inb( 0x535 );
 312       printk( " %02X", saved );
 313     }
 314     printk( "\n" );
 315   }
 316 
 317   ISP16_OUT( 0xF91, 0xA0 | special_mask );
 318 
 319   /*
 320    * The following have no explaination yet.
 321    */
 322   ISP16_OUT( 0xF90, 0xA2 );
 323   ISP16_OUT( 0xF92, 0x03 );
 324 
 325   /*
 326    * Turn general sound on and set total volume.
 327    */
 328   ISP16_OUT( 0xF93, 0x0A );
 329 
 330 /*
 331   outb( 0x04, 0x224 );
 332   saved = inb( 0x225 );
 333   outb( 0x04, 0x224 );
 334   outb( saved, 0x225 );
 335 */
 336 
 337 }

/* [previous][next][first][last][top][bottom][index][help] */