Migrate the olpt(4) driver to si_drv1 instead of using dev2unit().
Approved by: nyan
This commit is contained in:
parent
3f11530b79
commit
db99d0404c
@ -136,9 +136,6 @@
|
|||||||
static int volatile lptflag = 1;
|
static int volatile lptflag = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LPTUNIT(s) ((s)&0x03)
|
|
||||||
#define LPTFLAGS(s) ((s)&0xfc)
|
|
||||||
|
|
||||||
struct lpt_softc {
|
struct lpt_softc {
|
||||||
struct resource *res_port;
|
struct resource *res_port;
|
||||||
struct resource *res_irq;
|
struct resource *res_irq;
|
||||||
@ -318,6 +315,7 @@ lpt_attach(device_t dev)
|
|||||||
{
|
{
|
||||||
int rid, unit;
|
int rid, unit;
|
||||||
struct lpt_softc *sc;
|
struct lpt_softc *sc;
|
||||||
|
struct cdev *cdev;
|
||||||
|
|
||||||
unit = device_get_unit(dev);
|
unit = device_get_unit(dev);
|
||||||
sc = device_get_softc(dev);
|
sc = device_get_softc(dev);
|
||||||
@ -360,10 +358,12 @@ lpt_attach(device_t dev)
|
|||||||
device_printf(dev, "Interrupt-driven port");
|
device_printf(dev, "Interrupt-driven port");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX what to do about the flags in the minor number? */
|
cdev = make_dev(&lpt_cdevsw, 0,
|
||||||
make_dev(&lpt_cdevsw, unit, UID_ROOT, GID_WHEEL, 0600, "lpt%d", unit);
|
UID_ROOT, GID_WHEEL, 0600, "lpt%d", unit);
|
||||||
make_dev(&lpt_cdevsw, unit | LP_BYPASS,
|
cdev->si_drv1 = sc;
|
||||||
|
cdev = make_dev(&lpt_cdevsw, LP_BYPASS,
|
||||||
UID_ROOT, GID_WHEEL, 0600, "lpctl%d", unit);
|
UID_ROOT, GID_WHEEL, 0600, "lpctl%d", unit);
|
||||||
|
cdev->si_drv1 = sc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -377,11 +377,10 @@ lpt_attach(device_t dev)
|
|||||||
static int
|
static int
|
||||||
lptopen (struct cdev *dev, int flags, int fmt, struct thread *td)
|
lptopen (struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||||
{
|
{
|
||||||
struct lpt_softc *sc;
|
struct lpt_softc *sc = dev->si_drv1;
|
||||||
int s;
|
int s;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
sc = devclass_get_softc(olpt_devclass, LPTUNIT(dev2unit(dev)));
|
|
||||||
if (sc->sc_port == 0)
|
if (sc->sc_port == 0)
|
||||||
return (ENXIO);
|
return (ENXIO);
|
||||||
|
|
||||||
@ -391,7 +390,7 @@ lptopen (struct cdev *dev, int flags, int fmt, struct thread *td)
|
|||||||
} else
|
} else
|
||||||
sc->sc_state |= INIT;
|
sc->sc_state |= INIT;
|
||||||
|
|
||||||
sc->sc_flags = LPTFLAGS(dev2unit(dev));
|
sc->sc_flags = dev2unit(dev);
|
||||||
|
|
||||||
/* Check for open with BYPASS flag set. */
|
/* Check for open with BYPASS flag set. */
|
||||||
if (sc->sc_flags & LP_BYPASS) {
|
if (sc->sc_flags & LP_BYPASS) {
|
||||||
@ -467,9 +466,8 @@ lptout (void *arg)
|
|||||||
static int
|
static int
|
||||||
lptclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
lptclose(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||||
{
|
{
|
||||||
struct lpt_softc *sc;
|
struct lpt_softc *sc = dev->si_drv1;
|
||||||
|
|
||||||
sc = devclass_get_softc(olpt_devclass, LPTUNIT(dev2unit(dev)));
|
|
||||||
if(sc->sc_flags & LP_BYPASS)
|
if(sc->sc_flags & LP_BYPASS)
|
||||||
goto end_close;
|
goto end_close;
|
||||||
|
|
||||||
@ -556,9 +554,8 @@ lptwrite(struct cdev *dev, struct uio * uio, int ioflag)
|
|||||||
{
|
{
|
||||||
register unsigned n;
|
register unsigned n;
|
||||||
int pl, err;
|
int pl, err;
|
||||||
struct lpt_softc *sc;
|
struct lpt_softc *sc = dev->si_drv1;
|
||||||
|
|
||||||
sc = devclass_get_softc(olpt_devclass, LPTUNIT(dev2unit(dev)));
|
|
||||||
if(sc->sc_flags & LP_BYPASS) {
|
if(sc->sc_flags & LP_BYPASS) {
|
||||||
/* we can't do writes in bypass mode */
|
/* we can't do writes in bypass mode */
|
||||||
return(EPERM);
|
return(EPERM);
|
||||||
@ -613,12 +610,9 @@ static int
|
|||||||
lptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
|
lptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
struct lpt_softc *sc;
|
struct lpt_softc *sc = dev->si_drv1;
|
||||||
u_int unit = LPTUNIT(dev2unit(dev));
|
|
||||||
u_char old_sc_irq; /* old printer IRQ status */
|
u_char old_sc_irq; /* old printer IRQ status */
|
||||||
|
|
||||||
sc = devclass_get_softc(olpt_devclass, unit);
|
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case LPT_IRQ :
|
case LPT_IRQ :
|
||||||
if(sc->sc_irq & LP_HAS_IRQ) {
|
if(sc->sc_irq & LP_HAS_IRQ) {
|
||||||
@ -637,8 +631,8 @@ lptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *t
|
|||||||
else
|
else
|
||||||
sc->sc_irq |= LP_ENABLE_IRQ;
|
sc->sc_irq |= LP_ENABLE_IRQ;
|
||||||
if (old_sc_irq != sc->sc_irq )
|
if (old_sc_irq != sc->sc_irq )
|
||||||
log(LOG_NOTICE, "lpt%c switched to %s mode\n",
|
log(LOG_NOTICE, "%s switched to %s mode\n",
|
||||||
(char)unit+'0',
|
devtoname(dev),
|
||||||
(sc->sc_irq & LP_ENABLE_IRQ)?
|
(sc->sc_irq & LP_ENABLE_IRQ)?
|
||||||
"interrupt-driven":"polled");
|
"interrupt-driven":"polled");
|
||||||
} else /* polled port */
|
} else /* polled port */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user