ppi.c revision 183053
128219Smsmith/*-
255939Snsouch * Copyright (c) 1997, 1998, 1999 Nicolas Souchu, Michael Smith
328219Smsmith * All rights reserved.
428219Smsmith *
528219Smsmith * Redistribution and use in source and binary forms, with or without
628219Smsmith * modification, are permitted provided that the following conditions
728219Smsmith * are met:
828219Smsmith * 1. Redistributions of source code must retain the above copyright
928219Smsmith *    notice, this list of conditions and the following disclaimer.
1028219Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1128219Smsmith *    notice, this list of conditions and the following disclaimer in the
1228219Smsmith *    documentation and/or other materials provided with the distribution.
1328219Smsmith *
1428219Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1528219Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1628219Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1728219Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1828219Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1928219Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2028219Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2128219Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2228219Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2328219Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2428219Smsmith * SUCH DAMAGE.
2528219Smsmith *
2628219Smsmith *
2728219Smsmith */
28119418Sobrien
29119418Sobrien#include <sys/cdefs.h>
30119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/ppbus/ppi.c 183053 2008-09-15 22:26:32Z jhb $");
3155939Snsouch#include "opt_ppb_1284.h"
3255939Snsouch
3328219Smsmith#include <sys/param.h>
3428219Smsmith#include <sys/systm.h>
3555939Snsouch#include <sys/module.h>
3655939Snsouch#include <sys/bus.h>
3728219Smsmith#include <sys/conf.h>
3828219Smsmith#include <sys/kernel.h>
3942475Snsouch#include <sys/uio.h>
4032178Smsmith#include <sys/fcntl.h>
4128219Smsmith
4255939Snsouch#include <machine/bus.h>
4355939Snsouch#include <machine/resource.h>
4455939Snsouch#include <sys/rman.h>
4542475Snsouch
4628219Smsmith#include <dev/ppbus/ppbconf.h>
4742475Snsouch#include <dev/ppbus/ppb_msq.h>
4842475Snsouch
4942475Snsouch#ifdef PERIPH_1284
5042475Snsouch#include <dev/ppbus/ppb_1284.h>
5142475Snsouch#endif
5242475Snsouch
5332178Smsmith#include <dev/ppbus/ppi.h>
5428219Smsmith
5555939Snsouch#include "ppbus_if.h"
5655939Snsouch
5755939Snsouch#include <dev/ppbus/ppbio.h>
5855939Snsouch
5942475Snsouch#define BUFSIZE		512
6032178Smsmith
6128257Smsmithstruct ppi_data {
6228257Smsmith
6332178Smsmith    int		ppi_unit;
6432178Smsmith    int		ppi_flags;
6532178Smsmith#define HAVE_PPBUS	(1<<0)
6642475Snsouch#define HAD_PPBUS	(1<<1)
6728257Smsmith
6842475Snsouch    int		ppi_count;
6942475Snsouch    int		ppi_mode;			/* IEEE1284 mode */
7042475Snsouch    char	ppi_buffer[BUFSIZE];
7142475Snsouch
7260194Sn_hibma#ifdef PERIPH_1284
7355939Snsouch    struct resource *intr_resource;	/* interrupt resource */
7455939Snsouch    void *intr_cookie;			/* interrupt registration cookie */
7560194Sn_hibma#endif /* PERIPH_1284 */
7628257Smsmith};
7728257Smsmith
7855939Snsouch#define DEVTOSOFTC(dev) \
7955939Snsouch	((struct ppi_data *)device_get_softc(dev))
8055939Snsouch#define UNITOSOFTC(unit) \
8155939Snsouch	((struct ppi_data *)devclass_get_softc(ppi_devclass, (unit)))
8255939Snsouch#define UNITODEVICE(unit) \
8355939Snsouch	(devclass_get_device(ppi_devclass, (unit)))
8428219Smsmith
8555939Snsouchstatic devclass_t ppi_devclass;
8628219Smsmith
8728219Smsmithstatic	d_open_t	ppiopen;
8828219Smsmithstatic	d_close_t	ppiclose;
8928219Smsmithstatic	d_ioctl_t	ppiioctl;
9042475Snsouchstatic	d_write_t	ppiwrite;
9142475Snsouchstatic	d_read_t	ppiread;
9228219Smsmith
9347625Sphkstatic struct cdevsw ppi_cdevsw = {
94126080Sphk	.d_version =	D_VERSION,
95126080Sphk	.d_flags =	D_NEEDGIANT,
96111815Sphk	.d_open =	ppiopen,
97111815Sphk	.d_close =	ppiclose,
98111815Sphk	.d_read =	ppiread,
99111815Sphk	.d_write =	ppiwrite,
100111815Sphk	.d_ioctl =	ppiioctl,
101111815Sphk	.d_name =	"ppi",
10247625Sphk};
10328219Smsmith
10442475Snsouch#ifdef PERIPH_1284
10542475Snsouch
10642475Snsouchstatic void
10755939Snsouchppi_enable_intr(device_t ppidev)
10842475Snsouch{
10942475Snsouch	char r;
11055939Snsouch	device_t ppbus = device_get_parent(ppidev);
11142475Snsouch
11255939Snsouch	r = ppb_rctr(ppbus);
11355939Snsouch	ppb_wctr(ppbus, r | IRQENABLE);
11442475Snsouch
11542475Snsouch	return;
11642475Snsouch}
11742475Snsouch
11842475Snsouchstatic void
11955939Snsouchppi_disable_intr(device_t ppidev)
12042475Snsouch{
12142475Snsouch	char r;
12255939Snsouch        device_t ppbus = device_get_parent(ppidev);
12342475Snsouch
12455939Snsouch	r = ppb_rctr(ppbus);
12555939Snsouch	ppb_wctr(ppbus, r & ~IRQENABLE);
12642475Snsouch
12742475Snsouch	return;
12842475Snsouch}
12942475Snsouch
13042475Snsouch#endif /* PERIPH_1284 */
13142475Snsouch
13256455Speterstatic void
13356455Speterppi_identify(driver_t *driver, device_t parent)
13456455Speter{
13556455Speter
136127189Sguido	device_t dev;
137127189Sguido
138155921Sjhb	dev = device_find_child(parent, "ppi", -1);
139127189Sguido	if (!dev)
140127189Sguido		BUS_ADD_CHILD(parent, 0, "ppi", -1);
14156455Speter}
14256455Speter
14328219Smsmith/*
14455939Snsouch * ppi_probe()
14528219Smsmith */
14655939Snsouchstatic int
14755939Snsouchppi_probe(device_t dev)
14828219Smsmith{
14928219Smsmith	struct ppi_data *ppi;
15028219Smsmith
15155939Snsouch	/* probe is always ok */
15255939Snsouch	device_set_desc(dev, "Parallel I/O");
15355939Snsouch
15455939Snsouch	ppi = DEVTOSOFTC(dev);
15528219Smsmith
15655939Snsouch	return (0);
15755939Snsouch}
15828219Smsmith
15955939Snsouch/*
16055939Snsouch * ppi_attach()
16155939Snsouch */
16255939Snsouchstatic int
16355939Snsouchppi_attach(device_t dev)
16455939Snsouch{
16560194Sn_hibma#ifdef PERIPH_1284
166183053Sjhb	int rid = 0;
16755939Snsouch	struct ppi_data *ppi = DEVTOSOFTC(dev);
16828219Smsmith
16955939Snsouch	/* declare our interrupt handler */
170183053Sjhb	ppi->intr_resource = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
171183053Sjhb	    RF_ACTIVE);
17260194Sn_hibma#endif /* PERIPH_1284 */
17328219Smsmith
17455939Snsouch	make_dev(&ppi_cdevsw, device_get_unit(dev),	/* XXX cleanup */
17555939Snsouch		 UID_ROOT, GID_WHEEL,
17655939Snsouch		 0600, "ppi%d", device_get_unit(dev));
17728219Smsmith
17855939Snsouch	return (0);
17928219Smsmith}
18028219Smsmith
18160194Sn_hibma#ifdef PERIPH_1284
18242475Snsouch/*
18342475Snsouch * Cable
18442475Snsouch * -----
18542475Snsouch *
18642475Snsouch * Use an IEEE1284 compliant (DB25/DB25) cable with the following tricks:
18742475Snsouch *
18842475Snsouch * nStrobe   <-> nAck		1  <-> 10
18942475Snsouch * nAutofd   <-> Busy		11 <-> 14
19042475Snsouch * nSelectin <-> Select		17 <-> 13
19142475Snsouch * nInit     <-> nFault		15 <-> 16
19242475Snsouch *
19342475Snsouch */
19428219Smsmithstatic void
19555939Snsouchppiintr(void *arg)
19628219Smsmith{
19755939Snsouch	device_t ppidev = (device_t)arg;
19855939Snsouch        device_t ppbus = device_get_parent(ppidev);
19955939Snsouch	struct ppi_data *ppi = DEVTOSOFTC(ppidev);
20042475Snsouch
20155939Snsouch	ppi_disable_intr(ppidev);
20242475Snsouch
20355939Snsouch	switch (ppb_1284_get_state(ppbus)) {
20442475Snsouch
205108470Sschweikh	/* accept IEEE1284 negotiation then wakeup a waiting process to
206108470Sschweikh	 * continue negotiation at process level */
20742475Snsouch	case PPB_FORWARD_IDLE:
20842475Snsouch		/* Event 1 */
20955939Snsouch		if ((ppb_rstr(ppbus) & (SELECT | nBUSY)) ==
21042475Snsouch							(SELECT | nBUSY)) {
211108470Sschweikh			/* IEEE1284 negotiation */
21242475Snsouch#ifdef DEBUG_1284
21342475Snsouch			printf("N");
21442475Snsouch#endif
21542475Snsouch
21642475Snsouch			/* Event 2 - prepare for reading the ext. value */
21755939Snsouch			ppb_wctr(ppbus, (PCD | STROBE | nINIT) & ~SELECTIN);
21842475Snsouch
21955939Snsouch			ppb_1284_set_state(ppbus, PPB_NEGOCIATION);
22042475Snsouch
22142475Snsouch		} else {
22242475Snsouch#ifdef DEBUG_1284
22355939Snsouch			printf("0x%x", ppb_rstr(ppbus));
22442475Snsouch#endif
22555939Snsouch			ppb_peripheral_terminate(ppbus, PPB_DONTWAIT);
22642475Snsouch			break;
22742475Snsouch		}
22842475Snsouch
229108470Sschweikh		/* wake up any process waiting for negotiation from
23042475Snsouch		 * remote master host */
23142475Snsouch
23242475Snsouch		/* XXX should set a variable to warn the process about
23342475Snsouch		 * the interrupt */
23442475Snsouch
23542475Snsouch		wakeup(ppi);
23642475Snsouch		break;
23742475Snsouch	default:
23842475Snsouch#ifdef DEBUG_1284
23955977Speter		printf("?%d", ppb_1284_get_state(ppbus));
24042475Snsouch#endif
24155939Snsouch		ppb_1284_set_state(ppbus, PPB_FORWARD_IDLE);
24255939Snsouch		ppb_set_mode(ppbus, PPB_COMPATIBLE);
24342475Snsouch		break;
24442475Snsouch	}
24542475Snsouch
24655939Snsouch	ppi_enable_intr(ppidev);
24742475Snsouch
24828219Smsmith	return;
24928219Smsmith}
25060194Sn_hibma#endif /* PERIPH_1284 */
25128219Smsmith
25228219Smsmithstatic int
253130585Sphkppiopen(struct cdev *dev, int flags, int fmt, struct thread *td)
25428219Smsmith{
25528257Smsmith	u_int unit = minor(dev);
25655939Snsouch	struct ppi_data *ppi = UNITOSOFTC(unit);
25755939Snsouch	device_t ppidev = UNITODEVICE(unit);
25855939Snsouch        device_t ppbus = device_get_parent(ppidev);
25932178Smsmith	int res;
26028257Smsmith
26155939Snsouch	if (!ppi)
26228257Smsmith		return (ENXIO);
26328257Smsmith
26442475Snsouch	if (!(ppi->ppi_flags & HAVE_PPBUS)) {
26555939Snsouch		if ((res = ppb_request_bus(ppbus, ppidev,
26642475Snsouch			(flags & O_NONBLOCK) ? PPB_DONTWAIT :
26742475Snsouch						(PPB_WAIT | PPB_INTR))))
26832178Smsmith			return (res);
26928257Smsmith
27042475Snsouch		ppi->ppi_flags |= HAVE_PPBUS;
27155939Snsouch
27260194Sn_hibma#ifdef PERIPH_1284
27360194Sn_hibma		if (ppi->intr_resource) {
27460194Sn_hibma			/* register our interrupt handler */
275166914Simp			bus_setup_intr(ppidev, ppi->intr_resource,
276166914Simp				       INTR_TYPE_TTY, NULL, ppiintr, dev,
277166914Simp				       &ppi->intr_cookie);
27860194Sn_hibma		}
27960194Sn_hibma#endif /* PERIPH_1284 */
28042475Snsouch	}
28142475Snsouch	ppi->ppi_count += 1;
28242475Snsouch
28332178Smsmith	return (0);
28428219Smsmith}
28528219Smsmith
28628219Smsmithstatic int
287130585Sphkppiclose(struct cdev *dev, int flags, int fmt, struct thread *td)
28828219Smsmith{
28932178Smsmith	u_int unit = minor(dev);
29055939Snsouch	struct ppi_data *ppi = UNITOSOFTC(unit);
29155939Snsouch	device_t ppidev = UNITODEVICE(unit);
29255939Snsouch        device_t ppbus = device_get_parent(ppidev);
29332178Smsmith
29442475Snsouch	ppi->ppi_count --;
29542475Snsouch	if (!ppi->ppi_count) {
29642475Snsouch
29742475Snsouch#ifdef PERIPH_1284
29855939Snsouch		switch (ppb_1284_get_state(ppbus)) {
29942475Snsouch		case PPB_PERIPHERAL_IDLE:
30055939Snsouch			ppb_peripheral_terminate(ppbus, 0);
30142475Snsouch			break;
30242475Snsouch		case PPB_REVERSE_IDLE:
30342475Snsouch		case PPB_EPP_IDLE:
30442475Snsouch		case PPB_ECP_FORWARD_IDLE:
30542475Snsouch		default:
30655939Snsouch			ppb_1284_terminate(ppbus);
30742475Snsouch			break;
30842475Snsouch		}
30942475Snsouch#endif /* PERIPH_1284 */
31042475Snsouch
31155939Snsouch		/* unregistration of interrupt forced by release */
31255939Snsouch		ppb_release_bus(ppbus, ppidev);
31355939Snsouch
31442475Snsouch		ppi->ppi_flags &= ~HAVE_PPBUS;
31542475Snsouch	}
31642475Snsouch
31732178Smsmith	return (0);
31828219Smsmith}
31928219Smsmith
32042475Snsouch/*
32142475Snsouch * ppiread()
32242475Snsouch *
32342475Snsouch * IEEE1284 compliant read.
32442475Snsouch *
325108470Sschweikh * First, try negotiation to BYTE then NIBBLE mode
32642475Snsouch * If no data is available, wait for it otherwise transfer as much as possible
32742475Snsouch */
32828219Smsmithstatic int
329130585Sphkppiread(struct cdev *dev, struct uio *uio, int ioflag)
33042475Snsouch{
33142475Snsouch#ifdef PERIPH_1284
33242475Snsouch	u_int unit = minor(dev);
33355939Snsouch	struct ppi_data *ppi = UNITOSOFTC(unit);
33455939Snsouch	device_t ppidev = UNITODEVICE(unit);
33555939Snsouch        device_t ppbus = device_get_parent(ppidev);
33642475Snsouch	int len, error = 0;
33742475Snsouch
33855939Snsouch	switch (ppb_1284_get_state(ppbus)) {
33942475Snsouch	case PPB_PERIPHERAL_IDLE:
34055939Snsouch		ppb_peripheral_terminate(ppbus, 0);
341102412Scharnier		/* FALLTHROUGH */
34242475Snsouch
34342475Snsouch	case PPB_FORWARD_IDLE:
344108470Sschweikh		/* if can't negotiate NIBBLE mode then try BYTE mode,
34542475Snsouch		 * the peripheral may be a computer
34642475Snsouch		 */
34755939Snsouch		if ((ppb_1284_negociate(ppbus,
34842475Snsouch			ppi->ppi_mode = PPB_NIBBLE, 0))) {
34942475Snsouch
35042475Snsouch			/* XXX Wait 2 seconds to let the remote host some
35142475Snsouch			 * time to terminate its interrupt
35242475Snsouch			 */
35342475Snsouch			tsleep(ppi, PPBPRI, "ppiread", 2*hz);
35442475Snsouch
35555939Snsouch			if ((error = ppb_1284_negociate(ppbus,
35642475Snsouch				ppi->ppi_mode = PPB_BYTE, 0)))
35742475Snsouch				return (error);
35842475Snsouch		}
35942475Snsouch		break;
36042475Snsouch
36142475Snsouch	case PPB_REVERSE_IDLE:
36242475Snsouch	case PPB_EPP_IDLE:
36342475Snsouch	case PPB_ECP_FORWARD_IDLE:
36442475Snsouch	default:
36542475Snsouch		break;
36642475Snsouch	}
36742475Snsouch
36842475Snsouch#ifdef DEBUG_1284
36942475Snsouch	printf("N");
37042475Snsouch#endif
37142475Snsouch	/* read data */
37242475Snsouch	len = 0;
37342475Snsouch	while (uio->uio_resid) {
37455939Snsouch		if ((error = ppb_1284_read(ppbus, ppi->ppi_mode,
37542475Snsouch			ppi->ppi_buffer, min(BUFSIZE, uio->uio_resid),
37642475Snsouch			&len))) {
37742475Snsouch			goto error;
37842475Snsouch		}
37942475Snsouch
38042475Snsouch		if (!len)
38142475Snsouch			goto error;		/* no more data */
38242475Snsouch
38342475Snsouch#ifdef DEBUG_1284
38442475Snsouch		printf("d");
38542475Snsouch#endif
38642475Snsouch		if ((error = uiomove(ppi->ppi_buffer, len, uio)))
38742475Snsouch			goto error;
38842475Snsouch	}
38942475Snsouch
39042475Snsoucherror:
39142475Snsouch
39242475Snsouch#else /* PERIPH_1284 */
39342475Snsouch	int error = ENODEV;
39442475Snsouch#endif
39542475Snsouch
39642475Snsouch	return (error);
39742475Snsouch}
39842475Snsouch
39942475Snsouch/*
40042475Snsouch * ppiwrite()
40142475Snsouch *
40242475Snsouch * IEEE1284 compliant write
40342475Snsouch *
40442475Snsouch * Actually, this is the peripheral side of a remote IEEE1284 read
40542475Snsouch *
406108470Sschweikh * The first part of the negotiation (IEEE1284 device detection) is
40742475Snsouch * done at interrupt level, then the remaining is done by the writing
40842475Snsouch * process
40942475Snsouch *
410108470Sschweikh * Once negotiation done, transfer data
41142475Snsouch */
41242475Snsouchstatic int
413130585Sphkppiwrite(struct cdev *dev, struct uio *uio, int ioflag)
41442475Snsouch{
41542475Snsouch#ifdef PERIPH_1284
41642475Snsouch	u_int unit = minor(dev);
41755939Snsouch	struct ppi_data *ppi = UNITOSOFTC(unit);
41855939Snsouch	device_t ppidev = UNITODEVICE(unit);
41955939Snsouch        device_t ppbus = device_get_parent(ppidev);
42042475Snsouch	int len, error = 0, sent;
42142475Snsouch
42242475Snsouch#if 0
42342475Snsouch	int ret;
42442475Snsouch
42542475Snsouch	#define ADDRESS		MS_PARAM(0, 0, MS_TYP_PTR)
42642475Snsouch	#define LENGTH		MS_PARAM(0, 1, MS_TYP_INT)
42742475Snsouch
42842475Snsouch	struct ppb_microseq msq[] = {
42942475Snsouch		  { MS_OP_PUT, { MS_UNKNOWN, MS_UNKNOWN, MS_UNKNOWN } },
43042475Snsouch		  MS_RET(0)
43142475Snsouch	};
43242475Snsouch
433108470Sschweikh	/* negotiate ECP mode */
43455939Snsouch	if (ppb_1284_negociate(ppbus, PPB_ECP, 0)) {
435108470Sschweikh		printf("ppiwrite: ECP negotiation failed\n");
43642475Snsouch	}
43742475Snsouch
43842475Snsouch	while (!error && (len = min(uio->uio_resid, BUFSIZE))) {
43942475Snsouch		uiomove(ppi->ppi_buffer, len, uio);
44042475Snsouch
44142475Snsouch		ppb_MS_init_msq(msq, 2, ADDRESS, ppi->ppi_buffer, LENGTH, len);
44242475Snsouch
44355939Snsouch		error = ppb_MS_microseq(ppbus, msq, &ret);
44442475Snsouch	}
44542475Snsouch#endif
44642475Snsouch
44742475Snsouch	/* we have to be peripheral to be able to send data, so
44842475Snsouch	 * wait for the appropriate state
44942475Snsouch	 */
45055957Snsouch 	if (ppb_1284_get_state(ppbus) < PPB_PERIPHERAL_NEGOCIATION)
45155939Snsouch		ppb_1284_terminate(ppbus);
45242475Snsouch
45355957Snsouch 	while (ppb_1284_get_state(ppbus) != PPB_PERIPHERAL_IDLE) {
45442475Snsouch		/* XXX should check a variable before sleeping */
45542475Snsouch#ifdef DEBUG_1284
45642475Snsouch		printf("s");
45742475Snsouch#endif
45842475Snsouch
45955939Snsouch		ppi_enable_intr(ppidev);
46042475Snsouch
461108470Sschweikh		/* sleep until IEEE1284 negotiation starts */
46242475Snsouch		error = tsleep(ppi, PCATCH | PPBPRI, "ppiwrite", 0);
46342475Snsouch
46442475Snsouch		switch (error) {
46542475Snsouch		case 0:
466108470Sschweikh			/* negotiate peripheral side with BYTE mode */
46755939Snsouch			ppb_peripheral_negociate(ppbus, PPB_BYTE, 0);
46842475Snsouch			break;
46942475Snsouch		case EWOULDBLOCK:
47042475Snsouch			break;
47142475Snsouch		default:
47242475Snsouch			goto error;
47342475Snsouch		}
47442475Snsouch	}
47542475Snsouch#ifdef DEBUG_1284
47642475Snsouch	printf("N");
47742475Snsouch#endif
47842475Snsouch
479108470Sschweikh	/* negotiation done, write bytes to master host */
48043301Sdillon	while ((len = min(uio->uio_resid, BUFSIZE)) != 0) {
48142475Snsouch		uiomove(ppi->ppi_buffer, len, uio);
48255939Snsouch		if ((error = byte_peripheral_write(ppbus,
48342475Snsouch						ppi->ppi_buffer, len, &sent)))
48442475Snsouch			goto error;
48542475Snsouch#ifdef DEBUG_1284
48642475Snsouch		printf("d");
48742475Snsouch#endif
48842475Snsouch	}
48942475Snsouch
49042475Snsoucherror:
49142475Snsouch
49242475Snsouch#else /* PERIPH_1284 */
49342475Snsouch	int error = ENODEV;
49442475Snsouch#endif
49542475Snsouch
49642475Snsouch	return (error);
49742475Snsouch}
49842475Snsouch
49942475Snsouchstatic int
500130585Sphkppiioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
50128219Smsmith{
50232178Smsmith	u_int unit = minor(dev);
50355939Snsouch	device_t ppidev = UNITODEVICE(unit);
50455939Snsouch        device_t ppbus = device_get_parent(ppidev);
50532178Smsmith	int error = 0;
50632178Smsmith	u_int8_t *val = (u_int8_t *)data;
50732178Smsmith
50832178Smsmith	switch (cmd) {
50932178Smsmith
51032178Smsmith	case PPIGDATA:			/* get data register */
51155939Snsouch		*val = ppb_rdtr(ppbus);
51232178Smsmith		break;
51332178Smsmith	case PPIGSTATUS:		/* get status bits */
51455939Snsouch		*val = ppb_rstr(ppbus);
51532178Smsmith		break;
51632178Smsmith	case PPIGCTRL:			/* get control bits */
51755939Snsouch		*val = ppb_rctr(ppbus);
51832178Smsmith		break;
51943433Snsouch	case PPIGEPPD:			/* get EPP data bits */
52055939Snsouch		*val = ppb_repp_D(ppbus);
52132178Smsmith		break;
52232178Smsmith	case PPIGECR:			/* get ECP bits */
52355939Snsouch		*val = ppb_recr(ppbus);
52432178Smsmith		break;
52532178Smsmith	case PPIGFIFO:			/* read FIFO */
52655939Snsouch		*val = ppb_rfifo(ppbus);
52732178Smsmith		break;
52832178Smsmith	case PPISDATA:			/* set data register */
52955939Snsouch		ppb_wdtr(ppbus, *val);
53032178Smsmith		break;
53132178Smsmith	case PPISSTATUS:		/* set status bits */
53255939Snsouch		ppb_wstr(ppbus, *val);
53332178Smsmith		break;
53432178Smsmith	case PPISCTRL:			/* set control bits */
53555939Snsouch		ppb_wctr(ppbus, *val);
53632178Smsmith		break;
53743433Snsouch	case PPISEPPD:			/* set EPP data bits */
53855939Snsouch		ppb_wepp_D(ppbus, *val);
53932178Smsmith		break;
54032178Smsmith	case PPISECR:			/* set ECP bits */
54155939Snsouch		ppb_wecr(ppbus, *val);
54232178Smsmith		break;
54332178Smsmith	case PPISFIFO:			/* write FIFO */
54455939Snsouch		ppb_wfifo(ppbus, *val);
54532178Smsmith		break;
54643433Snsouch	case PPIGEPPA:			/* get EPP address bits */
54755939Snsouch		*val = ppb_repp_A(ppbus);
54843433Snsouch		break;
54943433Snsouch	case PPISEPPA:			/* set EPP address bits */
55055939Snsouch		ppb_wepp_A(ppbus, *val);
55143433Snsouch		break;
55232178Smsmith	default:
55332178Smsmith		error = ENOTTY;
55432178Smsmith		break;
55532178Smsmith	}
55632178Smsmith
55732178Smsmith	return (error);
55828219Smsmith}
55928219Smsmith
56056455Speterstatic device_method_t ppi_methods[] = {
56156455Speter	/* device interface */
56256455Speter	DEVMETHOD(device_identify,	ppi_identify),
56356455Speter	DEVMETHOD(device_probe,		ppi_probe),
56456455Speter	DEVMETHOD(device_attach,	ppi_attach),
56556455Speter
56656455Speter	{ 0, 0 }
56756455Speter};
56856455Speter
56956455Speterstatic driver_t ppi_driver = {
57056455Speter	"ppi",
57156455Speter	ppi_methods,
57256455Speter	sizeof(struct ppi_data),
57356455Speter};
57455939SnsouchDRIVER_MODULE(ppi, ppbus, ppi_driver, ppi_devclass, 0, 0);
575153610SruMODULE_DEPEND(ppi, ppbus, 1, 1, 1);
576