root/drivers/cdrom/isp16.c

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

DEFINITIONS

This source file includes following definitions.
  1. isp16_setup
  2. isp16_init
  3. isp16_detect
  4. isp16_c928__detect
  5. isp16_c929__detect
  6. isp16_cdi_config
  7. init_module
  8. cleanup_module

   1 /* -- ISP16 cdrom detection and configuration
   2  *
   3  *    Copyright (c) 1995,1996 Eric van der Maarel <H.T.M.v.d.Maarel@marin.nl>
   4  *
   5  *    Version 0.6
   6  *
   7  *    History:
   8  *    0.5 First release.
   9  *        Was included in the sjcd and optcd cdrom drivers.
  10  *    0.6 First "stand-alone" version.
  11  *        Removed sound configuration.
  12  *        Added "module" support.
  13  *
  14  *    Detect cdrom interface on ISP16 sound card.
  15  *    Configure cdrom interface.
  16  *
  17  *    Algorithm for the card with OPTi 82C928 taken
  18  *    from the CDSETUP.SYS driver for MSDOS,
  19  *    by OPTi Computers, version 2.03.
  20  *    Algorithm for the card with OPTi 82C929 as communicated
  21  *    to me by Vadim Model and Leo Spiekman.
  22  *
  23  *    This program is free software; you can redistribute it and/or modify
  24  *    it under the terms of the GNU General Public License as published by
  25  *    the Free Software Foundation; either version 2 of the License, or
  26  *    (at your option) any later version.
  27  *
  28  *    This program is distributed in the hope that it will be useful,
  29  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  30  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  31  *    GNU General Public License for more details.
  32  *
  33  *    You should have received a copy of the GNU General Public License
  34  *    along with this program; if not, write to the Free Software
  35  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  36  *
  37  */
  38 
  39 #define ISP16_VERSION_MAJOR 0
  40 #define ISP16_VERSION_MINOR 6
  41 
  42 #ifdef MODULE
  43 #include <linux/module.h>
  44 #endif  /* MODULE */
  45 
  46 #include <linux/fs.h>
  47 #include <linux/kernel.h>
  48 #include <linux/string.h>
  49 #include <linux/ioport.h>
  50 #include <linux/isp16.h>
  51 #include <asm/io.h>
  52 
  53 static short isp16_detect(void);
  54 static short isp16_c928__detect(void);
  55 static short isp16_c929__detect(void);
  56 static short isp16_cdi_config(int base, u_char drive_type, int irq, int dma);
  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 isp16_cdrom_base = ISP16_CDROM_IO_BASE;
  62 static int isp16_cdrom_irq = ISP16_CDROM_IRQ;
  63 static int isp16_cdrom_dma = ISP16_CDROM_DMA;
  64 static char *isp16_cdrom_type = ISP16_CDROM_TYPE;
  65 #ifdef MODULE
  66 int init_module(void);
  67 void cleanup_module(void);
  68 #endif
  69 
  70 #define ISP16_IN(p) (outb(isp16_ctrl,ISP16_CTRL_PORT), inb(p))
  71 #define ISP16_OUT(p,b) (outb(isp16_ctrl,ISP16_CTRL_PORT), outb(b,p))
  72 
  73 
  74 void
  75 isp16_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77   if ( ints[0] > 0 )
  78     isp16_cdrom_base = ints[1];
  79   if ( ints[0] > 1 )      
  80     isp16_cdrom_irq = ints[2];
  81   if ( ints[0] > 2 )      
  82     isp16_cdrom_dma = ints[3];
  83   if ( str )
  84     isp16_cdrom_type = str;
  85 }
  86 
  87 /*
  88  *  ISP16 initialisation.
  89  *
  90  */
  91 int
  92 isp16_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  93 {
  94   u_char expected_drive;
  95 
  96   printk(KERN_INFO "ISP16: configuration cdrom interface, version %d.%d.\n", ISP16_VERSION_MAJOR,
  97     ISP16_VERSION_MINOR);
  98 
  99   if ( !strcmp(isp16_cdrom_type, "noisp16") ) {
 100     printk("ISP16: no cdrom interface configured.\n");
 101     return(0);
 102   }
 103 
 104   if (check_region(ISP16_IO_BASE, ISP16_IO_SIZE)) {
 105     printk("ISP16: i/o ports already in use.\n");
 106     return(-EIO);
 107   }
 108 
 109   if ( (isp16_type=isp16_detect()) < 0 ) {
 110     printk("ISP16: no cdrom interface found.\n");
 111     return(-EIO);
 112   }
 113 
 114   printk(KERN_INFO "ISP16: cdrom interface (with OPTi 82C92%d chip) detected.\n",
 115     (isp16_type==2) ? 9 : 8);
 116 
 117   if ( !strcmp(isp16_cdrom_type, "Sanyo") )
 118     expected_drive = (isp16_type ? ISP16_SANYO1 : ISP16_SANYO0);
 119   else if ( !strcmp(isp16_cdrom_type, "Sony") )
 120     expected_drive = ISP16_SONY;
 121   else if ( !strcmp(isp16_cdrom_type, "Panasonic") )
 122     expected_drive = (isp16_type ? ISP16_PANASONIC1 : ISP16_PANASONIC0);
 123   else if ( !strcmp(isp16_cdrom_type, "Mitsumi") )
 124     expected_drive = ISP16_MITSUMI;
 125   else {
 126     printk("ISP16: %s not supported by cdrom interface.\n", isp16_cdrom_type);
 127     return(-EIO);
 128   }
 129 
 130   if ( isp16_cdi_config(isp16_cdrom_base, expected_drive,
 131     isp16_cdrom_irq, isp16_cdrom_dma ) < 0) {
 132     printk("ISP16: cdrom interface has not been properly configured.\n");
 133     return(-EIO);
 134   }
 135   printk(KERN_INFO "ISP16: cdrom interface set up with io base 0x%03X, irq %d, dma %d,"
 136     " type %s.\n", isp16_cdrom_base, isp16_cdrom_irq, isp16_cdrom_dma,
 137     isp16_cdrom_type);
 138   return(0);
 139 }
 140 
 141 static short
 142 isp16_detect(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144 
 145   if ( isp16_c929__detect() >= 0 )
 146     return(2);
 147   else
 148     return(isp16_c928__detect());
 149 }
 150 
 151 static short
 152 isp16_c928__detect(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154   u_char ctrl;
 155   u_char enable_cdrom;
 156   u_char io;
 157   short i = -1;
 158 
 159   isp16_ctrl = ISP16_C928__CTRL;
 160   isp16_enable_port = ISP16_C928__ENABLE_PORT;
 161 
 162   /* read' and write' are a special read and write, respectively */
 163 
 164   /* read' ISP16_CTRL_PORT, clear last two bits and write' back the result */
 165   ctrl = ISP16_IN( ISP16_CTRL_PORT ) & 0xFC;
 166   ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 167 
 168   /* read' 3,4 and 5-bit from the cdrom enable port */
 169   enable_cdrom = ISP16_IN( ISP16_C928__ENABLE_PORT ) & 0x38;
 170 
 171   if ( !(enable_cdrom & 0x20) ) {  /* 5-bit not set */
 172     /* read' last 2 bits of ISP16_IO_SET_PORT */
 173     io = ISP16_IN( ISP16_IO_SET_PORT ) & 0x03;
 174     if ( ((io&0x01)<<1) == (io&0x02) ) {  /* bits are the same */
 175       if ( io == 0 ) {  /* ...the same and 0 */
 176         i = 0;
 177         enable_cdrom |= 0x20;
 178       }
 179       else {  /* ...the same and 1 */  /* my card, first time 'round */
 180         i = 1;
 181         enable_cdrom |= 0x28;
 182       }
 183       ISP16_OUT( ISP16_C928__ENABLE_PORT, enable_cdrom );
 184     }
 185     else {  /* bits are not the same */
 186       ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 187       return(i); /* -> not detected: possibly incorrect conclusion */
 188     }
 189   }
 190   else if ( enable_cdrom == 0x20 )
 191     i = 0;
 192   else if ( enable_cdrom == 0x28 )  /* my card, already initialised */
 193     i = 1;
 194 
 195   ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 196 
 197   return(i);
 198 }
 199 
 200 static short
 201 isp16_c929__detect(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 202 {
 203   u_char ctrl;
 204   u_char tmp;
 205 
 206   isp16_ctrl = ISP16_C929__CTRL;
 207   isp16_enable_port = ISP16_C929__ENABLE_PORT;
 208 
 209   /* read' and write' are a special read and write, respectively */
 210 
 211   /* read' ISP16_CTRL_PORT and save */
 212   ctrl = ISP16_IN( ISP16_CTRL_PORT );
 213 
 214   /* write' zero to the ctrl port and get response */
 215   ISP16_OUT( ISP16_CTRL_PORT, 0 );
 216   tmp = ISP16_IN( ISP16_CTRL_PORT );
 217 
 218   if ( tmp != 2 )  /* isp16 with 82C929 not detected */
 219     return(-1);
 220 
 221   /* restore ctrl port value */
 222   ISP16_OUT( ISP16_CTRL_PORT, ctrl );
 223   
 224   return(2);
 225 }
 226 
 227 static short
 228 isp16_cdi_config(int base, u_char drive_type, int irq, int dma)
     /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230   u_char base_code;
 231   u_char irq_code;
 232   u_char dma_code;
 233   u_char i;
 234 
 235   if ( (drive_type == ISP16_MITSUMI) && (dma != 0) )
 236     printk("ISP16: Mitsumi cdrom drive has no dma support.\n");
 237 
 238   switch (base) {
 239   case 0x340: base_code = ISP16_BASE_340; break;
 240   case 0x330: base_code = ISP16_BASE_330; break;
 241   case 0x360: base_code = ISP16_BASE_360; break;
 242   case 0x320: base_code = ISP16_BASE_320; break;
 243   default:
 244     printk("ISP16: base address 0x%03X not supported by cdrom interface.\n",
 245       base);
 246     return(-1);
 247   }
 248   switch (irq) {
 249   case 0: irq_code = ISP16_IRQ_X; break; /* disable irq */
 250   case 5: irq_code = ISP16_IRQ_5;
 251           printk("ISP16: irq 5 shouldn't be used by cdrom interface,"
 252             " due to possible conflicts with the sound card.\n");
 253           break;
 254   case 7: irq_code = ISP16_IRQ_7;
 255           printk("ISP16: irq 7 shouldn't be used by cdrom interface,"
 256             " due to possible conflicts with the sound card.\n");
 257           break;
 258   case 3: irq_code = ISP16_IRQ_3; break;
 259   case 9: irq_code = ISP16_IRQ_9; break;
 260   case 10: irq_code = ISP16_IRQ_10; break;
 261   case 11: irq_code = ISP16_IRQ_11; break;
 262   default:
 263     printk("ISP16: irq %d not supported by cdrom interface.\n", irq );
 264     return(-1);
 265   }
 266   switch (dma) {
 267   case 0: dma_code = ISP16_DMA_X; break;  /* disable dma */
 268   case 1: printk("ISP16: dma 1 cannot be used by cdrom interface,"
 269             " due to conflict with the sound card.\n");
 270           return(-1); break;
 271   case 3: dma_code = ISP16_DMA_3; break;
 272   case 5: dma_code = ISP16_DMA_5; break;
 273   case 6: dma_code = ISP16_DMA_6; break;
 274   case 7: dma_code = ISP16_DMA_7; break;
 275   default:
 276     printk("ISP16: dma %d not supported by cdrom interface.\n", dma);
 277     return(-1);
 278   }
 279 
 280   if ( drive_type != ISP16_SONY && drive_type != ISP16_PANASONIC0 &&
 281     drive_type != ISP16_PANASONIC1 && drive_type != ISP16_SANYO0 &&
 282     drive_type != ISP16_SANYO1 && drive_type != ISP16_MITSUMI &&
 283     drive_type != ISP16_DRIVE_X ) {
 284     printk("ISP16: drive type (code 0x%02X) not supported by cdrom"
 285      " interface.\n", drive_type );
 286     return(-1);
 287   }
 288 
 289   /* set type of interface */
 290   i = ISP16_IN(ISP16_DRIVE_SET_PORT) & ISP16_DRIVE_SET_MASK;  /* clear some bits */
 291   ISP16_OUT( ISP16_DRIVE_SET_PORT, i|drive_type );
 292 
 293   /* enable cdrom on interface with 82C929 chip */
 294   if ( isp16_type > 1 )
 295     ISP16_OUT( isp16_enable_port, ISP16_ENABLE_CDROM );
 296 
 297   /* set base address, irq and dma */
 298   i = ISP16_IN(ISP16_IO_SET_PORT) & ISP16_IO_SET_MASK;  /* keep some bits */
 299   ISP16_OUT( ISP16_IO_SET_PORT, i|base_code|irq_code|dma_code );
 300 
 301   return(0);
 302 }
 303 
 304 #ifdef MODULE
 305 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 306 {
 307   return isp16_init();
 308 }
 309 
 310 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 311 {
 312         release_region(ISP16_IO_BASE, ISP16_IO_SIZE);
 313         printk(KERN_INFO "ISP16: module released.\n");
 314 }
 315 #endif /* MODULE */

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