Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Aug 1995 13:04:27 -0700 (PDT)
From:      Julian Elischer <julian@ref.tfs.com>
To:        gatliff@cel.cummins.com (William A. Gatliff)
Cc:        questions@freebsd.org, faq@freebsd.org
Subject:    Re: Driver creation.; [FAQ ENTRY]
Message-ID:  <199508312004.NAA00449@ref.tfs.com>
In-Reply-To: <9508311806.AA01512@cel.cummins.com> from "William A. Gatliff" at Aug 31, 95 01:06:50 pm

next in thread | previous in thread | raw e-mail | index | archive | help

well the easiest way to go is to
copy an existing driver that
does something similar to what you want..



first you need to get your driver included in the kernel:

RUN THIS SCRIPT :)

-------cut here------------------
#!/bin/sh 
cd /sys/i386/conf
cat >>files.i386 <<DONE
i386/isa/dohicky.c	optinal dohicky
DONE
cp GENERIC DOHICKY
cat >>DOHICKY <<DONE
device dohicky at isa? port 234 bio irq 5 vector dhintr
DONE
cat >>../isa/dohicky.c <<DONE
/*
 * Copyright BG
 *
 * Dohicky driver
 */
#include dohicky.h  /* generated file.. defines NDOHICKY */
#include <sys/param.h>
#include <sys/systm.h>

#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>
#include <sys/dhio.h>
int dohickyprobe (struct isa_device *), dohickyattach (struct isa_device *);

struct isa_driver dohickydriver = {dohickyprobe, dohickyattach, "dohicky"};

struct dh_softc {
	struct isa_device *dev;
	}

static struct kern_devconf kdc_dohicky[NLPT] = { {
        0, 0, 0,                /* filled in by dev_attach */
        "dohicky", 0, { MDDT_ISA, 0, "tty" },
        isa_generic_externalize, 0, 0, ISA_EXTERNALLEN,
        &kdc_isa0,              /* parent */
        0,                      /* parentdata */
        DC_UNCONFIGURED,        /* state */
        "Parallel printer adapter",
        DC_CLS_PARALLEL | DC_CLS_NETIF /* class */
} };

static inline void
dohicky_registerdev(struct isa_device *id)
{
        if(id->id_unit)
                kdc_dohicky[id->id_unit] = kdc_dohicky[0];
        kdc_dohicky[id->id_unit].kdc_unit = id->id_unit;
        kdc_dohicky[id->id_unit].kdc_isa = id;
        dev_attach(&kdc_dohicky[id->id_unit]);
}

#define NUMPORTS 4
/* add your own test to see if it exists */
/* should return the number of ports needed */
dohickyprobe (struct isa_device *dev)
{
    outb (dev->id_iobase, 0xff);
    DELAY (10000); /*  10 ms delay */
    return ((inb (dev->id_iobase) & 0x0f) == 0x0f)? NUMPORTS : 0 ;
#endif
}

/* called if the probe succeeded */
int
dohickyattach (struct isa_device *dev)
{
  int unit = dev->id_unit;

  if (unit > 1) {printf("bad unit for dohicky\n");return;}
  /*set up your sown softc structures etc.*/
  dh_softc[unit].dev = dev;
  /* this might be supposed to occur in the probe */
  dohicky_registerdev(dev);
  return 1;
}

void dhintr(int unit)
{
  if (unit > 1) {printf("bad unit for dohicky\n");return;}
  return 0
}

int dohickyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
{
    int unit = UNIT (dev);
    int x; 
    
    switch (cmd) {
    case DHIOCRESET:
	outb(dh_softc[unit]->id_iobase,0xff); /*  whatever resets it */
        break;
    default:
        return ENXIO;
    }
    return 0;
}   
/*
 * you also nead read,write, open, close routines
 * but this should get you started
 */

DONE
cat >>../../sys/dhio.h <<DONE
/*
 * Definitions needed to access the dohicky device (ioctls etc)
 * see mtio.h , ioctl.h as examples
 */
#ifndef SYS_DHIO_H
#define SYS_DHIO_H
/*
 * define an ioctl here
 */
#define DHIOCRESET _IO('D',0)	/* reset the dohicky device */
#endif
DONE

config DOHICKY
cd ../../compile/DOHICKY
make depend
make
exit

--------------end of script---------------

you also need to add an entry into the cdevsw[]
array in conf.c, but it's too hard to do in a script..

edit to your taste..

> 
> I'm planning to write a driver for a do-hickey that connects
> to my PC's printer port or uses an i/o card (ISA).
> 
> Can anyone point me to some tutorial info on how to write
> drivers for FreeBSD?
> 
> Thanks!
> 
> b.g.
> 
> 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199508312004.NAA00449>