root/net/drv/we8003/main.c

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

DEFINITIONS

This source file includes following definitions.
  1. we_getconf
  2. we_setconf
  3. we_open
  4. we_close
  5. we_ioctl
  6. we8003_init

   1 /*
   2  * we8003.c     A generic WD8003 driver for LINUX.
   3  *
   4  * Version:     @(#)we8003.c    1.0.0   04/22/93
   5  *
   6  * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
   7  */
   8 #include <linux/config.h>
   9 #include <linux/kernel.h>
  10 #include <linux/sched.h>
  11 #include <linux/fs.h>
  12 #include <linux/tty.h>
  13 #include <linux/types.h>
  14 #include <linux/ptrace.h>
  15 #include <linux/string.h>
  16 #include <linux/ddi.h>
  17 #include <asm/system.h>
  18 #include <asm/segment.h>
  19 #include <asm/io.h>
  20 #include <errno.h>
  21 #include <linux/fcntl.h>
  22 #include <netinet/in.h>
  23 #include "we8003.h"
  24 
  25 
  26 #define VERSION         "1.0.0"         /* current version ID           */
  27 
  28 
  29 struct ddi_device *we_ptrs[NR_WE8003];  /* pointers to DDI blocks       */
  30 
  31 
  32 static int
  33 we_getconf(struct ddi_device *dev, struct ddconf *cp)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35   cp->ioaddr = dev->config.ioaddr;      /* I/O base address             */
  36   cp->ioaux = 0;                        /* not used                     */
  37   cp->irq = dev->config.irq;            /* IRQ channel                  */
  38   cp->dma = 0;                          /* not used                     */
  39   cp->memaddr = dev->config.memaddr;    /* RAM base address             */
  40   cp->memsize = dev->config.memsize;    /* RAM size                     */
  41   return(0);
  42 }
  43 
  44 
  45 static int
  46 we_setconf(struct ddi_device *dev, struct ddconf *cp)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48   dev->config.ioaddr = cp->ioaddr;      /* I/O base address             */
  49   dev->config.irq = cp->irq;            /* IRQ channel                  */
  50   dev->config.memaddr = cp->memaddr;    /* RAM base address             */
  51   dev->config.memsize = cp->memsize;    /* RAM size                     */
  52   PRINTK (("%s: IO=0x%X IRQ=%d MEM=0x%X(%d)\n",
  53         dev->name, dev->config.ioaddr, dev->config.irq,
  54         dev->config.memaddr, dev->config.memsize));
  55 
  56   /* FIXME: request the IRQ line and initialize HW here! */
  57 
  58   return(0);
  59 }
  60 
  61 
  62 static int
  63 we_open(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65   int minor;
  66   struct ddi_device *dev;
  67 
  68   minor = MINOR(inode->i_rdev);
  69   if (minor < 0 || minor >= NR_WE8003) return(-ENODEV);
  70   dev = we_ptrs[minor];
  71   if (dev == NULL || (dev->flags & DDI_FREADY) == 0) return(-ENODEV);
  72 
  73   return(0);
  74 }
  75 
  76 
  77 static void
  78 we_close(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80   int minor;
  81   struct ddi_device *dev;
  82 
  83   minor = MINOR(inode->i_rdev);
  84   if (minor < 0 || minor >= NR_WE8003) return;
  85   dev = we_ptrs[minor];
  86   if (dev == NULL || (dev->flags & DDI_FREADY) == 0) return;
  87 }
  88 
  89 
  90 static int
  91 we_ioctl(struct inode *inode, struct file *file,
     /* [previous][next][first][last][top][bottom][index][help] */
  92          unsigned int cmd, unsigned long arg)
  93 {
  94   int minor, ret;
  95   struct ddi_device *dev;
  96   struct ddconf conf;
  97 
  98   minor = MINOR(inode->i_rdev);
  99   if (minor < 0 || minor >= NR_WE8003) return(-ENODEV);
 100   dev = we_ptrs[minor];
 101   if (dev == NULL || (dev->flags & DDI_FREADY) == 0) return(-ENODEV);
 102 
 103   ret = -EINVAL;
 104   switch(cmd) {
 105         case DDIOCGNAME:
 106                 memcpy_tofs((void *)arg, dev->name, DDI_MAXNAME);
 107                 ret = 0;
 108                 break;
 109         case DDIOCGCONF:
 110                 ret = we_getconf(dev, &conf);
 111                 memcpy_tofs((void *)arg, &conf, sizeof(conf));
 112                 break;
 113         case DDIOCSCONF:
 114                 memcpy_fromfs(&conf, (void *)arg, sizeof(conf));
 115                 ret = we_setconf(dev, &conf);
 116                 break;
 117         default:
 118                 break;
 119   }
 120   return(ret);
 121 }
 122 
 123 
 124 static struct file_operations we_fops = {
 125   NULL,         /* LSEEK        */
 126   NULL,         /* READ         */
 127   NULL,         /* WRITE        */
 128   NULL,         /* READDIR      */
 129   NULL,         /* SELECT       */
 130   we_ioctl,     /* IOCTL        */
 131   NULL,         /* MMAP         */
 132   we_open,      /* OPEN         */
 133   we_close      /* CLOSE        */
 134 };
 135 
 136 
 137 /* This is the main entry point of this driver. */
 138 int
 139 we8003_init(struct ddi_device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 140 {
 141   static int unit_nr = 0;
 142   int i;
 143 
 144   /* Initialize the driver if this is the first call. */
 145   if (unit_nr == 0) {
 146         for(i = 0; i < NR_WE8003; i++) we_ptrs[i] = NULL;
 147   }
 148 
 149   /* Initialize the local control block pointer. */
 150   we_ptrs[unit_nr] = dev;
 151   dev->unit = unit_nr++;
 152   sprintf(dev->name, WE_NAME, dev->unit);
 153   dev->flags |= DDI_FREADY;
 154 
 155   /* Say hello to our viewers. */
 156   PRINTK (("%s: version %s: ", dev->title, VERSION));
 157   (void) we_setconf(dev, &dev->config);
 158 
 159   /* First of all, setup a VFS major device handler if needed. */
 160   if (dev->major != 0) {
 161         if (dev->flags & DDI_FBLKDEV) {
 162                 if (register_blkdev(dev->major, "WE8003", &we_fops) < 0) {
 163                         printk("%s: cannot register block device %d!\n",
 164                                         dev->name, dev->major);
 165                         return(-EINVAL);
 166                 }
 167         }
 168         if (dev->flags & DDI_FCHRDEV) {
 169                 if (register_chrdev(dev->major, "WE8003", &we_fops) < 0) {
 170                         printk("%s: cannot register character device %d!\n",
 171                                         dev->name, dev->major);
 172                         return(-EINVAL);
 173                 }
 174         }
 175   }
 176 
 177   /* All done... */
 178   return(0);
 179 }

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