me8100.c
changeset 15 b9baa645576a
parent 14 c3f6d5e9713a
child 18 d1686272f84d
equal deleted inserted replaced
14:c3f6d5e9713a 15:b9baa645576a
   472   PDEBUG("me8100_init_board():int_line = %d\n", info->int_line);
   472   PDEBUG("me8100_init_board():int_line = %d\n", info->int_line);
   473 
   473 
   474   info->file_ptr = NULL;
   474   info->file_ptr = NULL;
   475   info->board_in_use = 0;
   475   info->board_in_use = 0;
   476 
   476 
       
   477 
       
   478   /* Set default values for the subinfo. */
   477   info->subinfo[0].regbase = info->me8100_regbase;
   479   info->subinfo[0].regbase = info->me8100_regbase;
   478   info->subinfo[1].regbase = info->me8100_regbase + 0x0C;
   480   info->subinfo[1].regbase = info->me8100_regbase + 0x0C;
   479 
   481 
   480   for (i = 0; i <= 1; ++i) {
   482   for (i = 0; i <= 1; ++i) {
   481     info->subinfo[i].int_seen = jiffies;    /* suppose we got just the first irq */
   483     info->subinfo[i].int_seen = jiffies;    /* suppose we got just the first irq */
   482     info->subinfo[i].int_count = 0;
       
   483     info->subinfo[i].fasync_ptr = NULL;
   484     info->subinfo[i].fasync_ptr = NULL;
   484     init_waitqueue_head(&info->subinfo[i].readq);
   485     init_waitqueue_head(&info->subinfo[i].readq);
   485   }
   486   }
   486   
   487   
   487   
   488   
   526  *--------------------------------------------------------------------------
   527  *--------------------------------------------------------------------------
   527  * Author: GG                                                               
   528  * Author: GG                                                               
   528  * Modification:                                                            
   529  * Modification:                                                            
   529  */
   530  */
   530 static int me8100_reset_board(me8100_info_type *info){
   531 static int me8100_reset_board(me8100_info_type *info){
       
   532   int i;
   531   unsigned char icsr = 0x12;
   533   unsigned char icsr = 0x12;
   532 
   534 
   533   PDEBUG("me8100_reset_board() is executed\n");
   535   PDEBUG("me8100_reset_board() is executed\n");
   534 
   536 
   535   /* Disable the Interrupt logic of the plx */
   537   /* Disable the Interrupt logic of the plx */
   536   PDEBUG("me8100_reset_board(): plx_mode = 0x%X\n", icsr);
   538   PDEBUG("me8100_reset_board(): plx_mode = 0x%X\n", icsr);
   537   outb(icsr, info->plx_regbase + PLX_ICSR);
   539   outb(icsr, info->plx_regbase + PLX_ICSR);
   538   
   540   
   539   /* Ports to high impedance, interrupts deactivated */
   541   for (i = 0; i <= 1; ++i) {
   540   outw(0x00, info->me8100_regbase + ME8100_CTRL_REG_A);
   542     /* Ports to high impedance, interrupts deactivated */
   541   outw(0x0000, info->me8100_regbase + ME8100_CTRL_REG_B);
   543     outw(0x00, info->subinfo[i].regbase + ME8100_CTRL_REG);
   542 
   544     /* Reset any pending interrupt */
   543   /* Reset any pending interrupt */
   545     inw(info->subinfo[i].regbase + ME8100_RES_INT_REG);
   544   inw(info->me8100_regbase + ME8100_RES_INT_REG_A);
   546   }
   545   inw(info->me8100_regbase + ME8100_RES_INT_REG_B);
   547 
   546 
   548   return 0;
   547   return 0;
   549 }
   548 }
       
   549 
       
   550 
       
   551 
   550 
   552 /*
   551 /*
   553  * Routine:                                                                 
   552  * Routine:                                                                 
   554  *   me8100_open                                                              
   553  *   me8100_open                                                              
   555  *                                                                          
   554  *                                                                          
   579 
   578 
   580   PDEBUG("*** me8100_open() is executed\n");
   579   PDEBUG("*** me8100_open() is executed\n");
   581 
   580 
   582   device = DEVICE(MINOR(inode_ptr->i_rdev));
   581   device = DEVICE(MINOR(inode_ptr->i_rdev));
   583   subdevice = SUBDEVICE(MINOR(inode_ptr->i_rdev));
   582   subdevice = SUBDEVICE(MINOR(inode_ptr->i_rdev));
   584   PDEBUG("*** device: %d, subdevice %d\n", device, subdevice);
   583   PDEBUG("*** device: %d, subdevice %d with flags %0x\n", device, subdevice, file_ptr->f_flags);
   585 
   584 
   586   if(device >= me8100_board_count){
   585   if(device >= me8100_board_count){
   587     printk(KERN_ERR"ME8100:me8100_open():Board %d doesn't exist\n", device);
   586     printk(KERN_ERR"ME8100:me8100_open():Board %d doesn't exist\n", device);
   588     return -ENODEV;
   587     return -ENODEV;
   589   }
   588   }
  2203  */
  2202  */
  2204 ssize_t me8100_read(struct file * file_ptr, char *buffer, size_t len, loff_t *offset) 
  2203 ssize_t me8100_read(struct file * file_ptr, char *buffer, size_t len, loff_t *offset) 
  2205 {
  2204 {
  2206   int err;
  2205   int err;
  2207   unsigned short val;
  2206   unsigned short val;
  2208   struct me8100_private_data *priv = file_ptr->private_data;
       
  2209   int minor;
  2207   int minor;
       
  2208   struct me8100_private_data *priv;
  2210   struct me8100_subinfo *subinfo;
  2209   struct me8100_subinfo *subinfo;
  2211 
  2210 
  2212   PDEBUG("me8100_read(%d) called\n", len);
  2211   PDEBUG("me8100_read() called\n");
  2213 
  2212 
  2214   minor = MINOR(file_ptr->f_dentry->d_inode->i_rdev);
  2213   minor = MINOR(file_ptr->f_dentry->d_inode->i_rdev);
  2215   subinfo = &info_vec[DEVICE(minor)].subinfo[SUBDEVICE(minor)];
  2214   subinfo = &info_vec[DEVICE(minor)].subinfo[SUBDEVICE(minor)];
       
  2215   priv = file_ptr->private_data;
  2216   
  2216   
  2217   if (len == 0) return 0;	/* do we really need this check? */
  2217   if (len == 0) return 0;	/* do we really need this check? */
  2218   if (len < 0) return -EINVAL;	/* do we really need this check? */
  2218   if (len < 0) return -EINVAL;	/* do we really need this check? */
  2219 
  2219 
  2220   if (priv->last_read >= subinfo->int_seen) {	/* alread seen, sleep */
  2220   /* If the time we did the last read operation is more recent than the
  2221     PDEBUG("*** going to sleep\n");
  2221    * last interupt, we have to go to sleep (or return -EAGAIN in non blockin
  2222     if (wait_event_interruptible(subinfo->readq, (priv->last_read != subinfo->int_seen))) {
  2222    * mode).  Then, if we're awoken, we return the value that triggered the
  2223       PDEBUG("** awoken on signal?\n");
  2223    * interrupt.  (If awoken from a signal, we return -ERESTARTSYS.)
       
  2224    *
       
  2225    * If we haven't read any data since the last irq occured, we return
       
  2226    * the current(!) value visible on the port!
       
  2227    *
       
  2228    * Is this some inconsistency?  What does happen if somebody changes the
       
  2229    * interrupt behaviour.  What, if intterupts are disabled at all?  Should
       
  2230    * we check this an return the current value visible at the port then?
       
  2231    */
       
  2232   if (priv->last_read >= subinfo->int_seen) {
       
  2233     if (file_ptr->f_flags & O_NONBLOCK) return -EAGAIN;
       
  2234 
       
  2235     if (wait_event_interruptible(subinfo->readq, (priv->last_read != subinfo->int_seen))) 
  2224       return -ERESTARTSYS;
  2236       return -ERESTARTSYS;
  2225     }
  2237     val = subinfo->int_di;	
  2226     val = subinfo->int_di;	/* the value that caused the interrupt */
  2238 
  2227   } else {					/* not yet seen ... */
  2239   } else val = inw(subinfo->regbase + ME8100_DI_REG);
  2228     val = inw(subinfo->regbase + ME8100_DI_REG);
  2240 
  2229     PDEBUG("me8100_read: val=0x%04x\n", val);
  2241   PDEBUG("me8100_read: val=0x%04x\n", val);
  2230   }
  2242 
  2231 
  2243   /* Remember the time of the last interrupt we've seen.  (It might be 
       
  2244    * 0 if there was no interrupt yet.  This doesn't hurt, since the next
       
  2245    * read will see this (see above) and will wait until an irq raises.)
       
  2246    */
  2232   priv->last_read = subinfo->int_seen;
  2247   priv->last_read = subinfo->int_seen;
  2233 
  2248 
       
  2249   /* Return at most 2 byte, but check if the read want's them both! */
  2234   if (len >= sizeof(val)) {
  2250   if (len >= sizeof(val)) {
  2235     err = put_user(val, (unsigned short*) buffer);
  2251     err = put_user(val, (unsigned short*) buffer);
  2236     len = sizeof(val);
  2252     len = sizeof(val);
  2237   } else {
  2253   } else err = put_user(val, (char*) buffer);
  2238     err = put_user(val, (char*) buffer);
  2254 
  2239   }
  2255   return err ? err : len;
  2240 
       
  2241   return len;
       
  2242 }
  2256 }
  2243 
  2257 
  2244 /* Writing: we do only write one word (an unsigned short) and return immediatly.  Yes,
  2258 /* Writing: we do only write one word (an unsigned short) and return immediatly.  Yes,
  2245  * we could loop over the complete buffer, but it's not expected to get more data
  2259  * we could loop over the complete buffer, but it's not expected to get more data
  2246  * than one word.  If there's more output, the responsibility is transferred back
  2260  * than one word.  If there's more output, the responsibility is transferred back