From dc7e2b8d6f742587d44f299d5fe570c8472b21c3 Mon Sep 17 00:00:00 2001 From: Jason Wright Date: Tue, 9 Jul 2002 15:28:00 +0000 Subject: allow getting and setting of the ADC, DAC, and PIO ports on the daadio (this has been sitting in my tree for awhile) --- sys/arch/sparc/conf/files.sparc | 4 +- sys/arch/sparc/dev/daadio.c | 187 +++++++++++++++++++++++++++++++++++++- sys/arch/sparc/include/conf.h | 9 +- sys/arch/sparc/include/daadioio.h | 59 ++++++++++++ sys/arch/sparc/sparc/conf.c | 7 +- 5 files changed, 258 insertions(+), 8 deletions(-) create mode 100644 sys/arch/sparc/include/daadioio.h diff --git a/sys/arch/sparc/conf/files.sparc b/sys/arch/sparc/conf/files.sparc index 7186fa6f37f..996867421eb 100644 --- a/sys/arch/sparc/conf/files.sparc +++ b/sys/arch/sparc/conf/files.sparc @@ -1,4 +1,4 @@ -# $OpenBSD: files.sparc,v 1.41 2002/03/23 14:14:25 deraadt Exp $ +# $OpenBSD: files.sparc,v 1.42 2002/07/09 15:27:59 jason Exp $ # $NetBSD: files.sparc,v 1.44 1997/08/31 21:29:16 pk Exp $ # @(#)files.sparc 8.1 (Berkeley) 7/19/93 @@ -325,7 +325,7 @@ file arch/sparc/dev/fga.c fga needs-flag device daadio {} attach daadio at fvme -file arch/sparc/dev/daadio.c daadio +file arch/sparc/dev/daadio.c daadio needs-flag device tctrl {} attach tctrl at obio diff --git a/sys/arch/sparc/dev/daadio.c b/sys/arch/sparc/dev/daadio.c index 7d125a97e59..8c349a0e653 100644 --- a/sys/arch/sparc/dev/daadio.c +++ b/sys/arch/sparc/dev/daadio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: daadio.c,v 1.2 2002/03/14 01:26:42 millert Exp $ */ +/* $OpenBSD: daadio.c,v 1.3 2002/07/09 15:27:59 jason Exp $ */ /* * Copyright (c) 1999 Jason L. Wright (jason@thought.net) @@ -48,12 +48,15 @@ #include #include #include +#include +#include #include #include #include #include #include /* for SBUS_BURST_* */ +#include #include #include @@ -81,6 +84,10 @@ struct cfdriver daadio_cd = { void daadio_ier_setbit(struct daadio_softc *, u_int8_t); void daadio_ier_clearbit(struct daadio_softc *, u_int8_t); +int daadioopen(dev_t, int, int, struct proc *); +int daadioclose(dev_t, int, int, struct proc *); +int daadioioctl(dev_t, u_long, caddr_t, int, struct proc *); + int daadiomatch(parent, vcf, aux) struct device *parent; @@ -144,10 +151,18 @@ daadiointr(vsc) if (regs->isr & ISR_PIOEVENT) { val = regs->pio_porta; printf("pio value: %x\n", val); - r |= 1; + r = 1; regs->pio_pattern = val; } + if (regs->isr & ISR_PIPELINE) { + r = 1; + } + + if (regs->isr & ISR_CONVERSION) { + r = 1; + } + return (r); } @@ -168,3 +183,171 @@ daadio_ier_clearbit(sc, v) sc->sc_ier &= ~v; sc->sc_regs->ier = sc->sc_ier; } + +#define DAADIO_CARD(d) ((minor(d) >> 6) & 3) + +int +daadioopen(dev, flags, mode, p) + dev_t dev; + int flags, mode; + struct proc *p; +{ + struct daadio_softc *sc; + int card = DAADIO_CARD(dev); + + if (card >= daadio_cd.cd_ndevs) + return (ENXIO); + sc = daadio_cd.cd_devs[card]; + if (sc == NULL) + return (ENXIO); + return (0); +} + +int +daadioclose(dev, flags, mode, p) + dev_t dev; + int flags, mode; + struct proc *p; +{ + return (0); +} + +int +daadioioctl(dev, cmd, data, flags, p) + dev_t dev; + u_long cmd; + caddr_t data; + int flags; + struct proc *p; +{ + struct daadio_softc *sc = daadio_cd.cd_devs[DAADIO_CARD(dev)]; + struct daadio_adc *adc = (struct daadio_adc *)data; + struct daadio_dac *dac = (struct daadio_dac *)data; + struct daadio_pio *pio = (struct daadio_pio *)data; + int error = 0; + u_int8_t reg, val; + + switch (cmd) { + case DIOGADC: + if (adc->dad_reg >= 32) { + error = EINVAL; + break; + } + adc->dad_val = sc->sc_regs->adc12bit[adc->dad_reg]; + break; + case DIOSADC: + if ((flags & FWRITE) == 0) { + error = EPERM; + break; + } + if (adc->dad_reg >= 32) { + error = EINVAL; + break; + } + sc->sc_regs->adc12bit[adc->dad_reg] = adc->dad_val; + break; + case DIOGPIO: + switch (pio->dap_reg) { + case 0: + pio->dap_val = sc->sc_regs->pio_porta; + break; + case 1: + pio->dap_val = sc->sc_regs->pio_portb; + break; + case 2: + pio->dap_val = sc->sc_regs->pio_portc; + break; + case 3: + pio->dap_val = sc->sc_regs->pio_portd; + break; + case 4: + pio->dap_val = sc->sc_regs->pio_porte; + break; + case 5: + pio->dap_val = sc->sc_regs->pio_portf; + break; + default: + error = EINVAL; + break; + } + break; + case DIOSPIO: + if ((flags & FWRITE) == 0) { + error = EPERM; + break; + } + switch (pio->dap_reg) { + case 0: + sc->sc_regs->pio_porta = pio->dap_val; + break; + case 1: + sc->sc_regs->pio_portb = pio->dap_val; + break; + case 2: + sc->sc_regs->pio_portc = pio->dap_val; + break; + case 3: + sc->sc_regs->pio_portd = pio->dap_val; + break; + case 4: + sc->sc_regs->pio_porte = pio->dap_val; + break; + case 5: + sc->sc_regs->pio_portf = pio->dap_val; + break; + default: + error = EINVAL; + break; + } + break; + case DIOSOPIO: + if ((flags & FWRITE) == 0) { + error = EPERM; + break; + } + if (pio->dap_reg >= 6) { + error = EINVAL; + break; + } + + reg = sc->sc_regs->pio_oc; + val = (1 << pio->dap_reg); + + if (pio->dap_val) + reg |= val; + else + reg &= ~val; + + sc->sc_regs->pio_oc = reg; + break; + case DIOGOPIO: + if (pio->dap_reg >= 6) { + error = EINVAL; + break; + } + + reg = sc->sc_regs->pio_oc; + val = (1 << pio->dap_reg); + + if ((reg & val) != 0) + pio->dap_val = 1; + else + pio->dap_val = 0; + break; + case DIOSDAC: + if ((flags & FWRITE) == 0) { + error = EPERM; + break; + } + if (dac->dac_reg >= 8) { + error = EINVAL; + break; + } + sc->sc_regs->dac_channel[dac->dac_reg] = dac->dac_val; + break; + default: + error = ENOTTY; + } + + return (error); +} diff --git a/sys/arch/sparc/include/conf.h b/sys/arch/sparc/include/conf.h index 322831f53f8..d9b695013ec 100644 --- a/sys/arch/sparc/include/conf.h +++ b/sys/arch/sparc/include/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.13 2001/12/11 23:19:02 miod Exp $ */ +/* $OpenBSD: conf.h,v 1.14 2002/07/09 15:27:59 jason Exp $ */ /* $NetBSD: conf.h,v 1.8 1996/12/31 07:12:43 mrg Exp $ */ /* @@ -120,4 +120,11 @@ cdev_decl(flash); (dev_type_mmap((*))) enodev } cdev_decl(fga); +#define cdev_daadio_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, seltrue, \ + (dev_type_mmap((*))) enodev } +cdev_decl(daadio); + cdev_decl(ksyms); diff --git a/sys/arch/sparc/include/daadioio.h b/sys/arch/sparc/include/daadioio.h new file mode 100644 index 00000000000..c34c23525a6 --- /dev/null +++ b/sys/arch/sparc/include/daadioio.h @@ -0,0 +1,59 @@ +/* $OpenBSD: daadioio.h,v 1.1 2002/07/09 15:27:59 jason Exp $ */ + +/* + * Copyright (c) 2002 Jason L. Wright (jason@thought.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jason L. Wright + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ioctls and flags for DAADIO. + */ + +struct daadio_pio { + u_int8_t dap_reg; + u_int8_t dap_val; +}; + +struct daadio_adc { + u_int8_t dad_reg; + u_int16_t dad_val; +}; + +struct daadio_dac { + u_int8_t dac_reg; + u_int16_t dac_val; +}; + +#define DIOGPIO _IOWR('D', 0x01, struct daadio_pio) /* get pio val */ +#define DIOSPIO _IOW('D', 0x01, struct daadio_pio) /* set pio val */ +#define DIOGOPIO _IOWR('D', 0x02, struct daadio_pio) /* get outp sts */ +#define DIOSOPIO _IOW('D', 0x02, struct daadio_pio) /* set to outp */ +#define DIOGADC _IOWR('D', 0x03, struct daadio_adc) /* get adc val */ +#define DIOSADC _IOW('D', 0x03, struct daadio_adc) /* set adc val */ +#define DIOSDAC _IOW('D', 0x04, struct daadio_dac) /* set dac val */ diff --git a/sys/arch/sparc/sparc/conf.c b/sys/arch/sparc/sparc/conf.c index 372382f52be..233517f161a 100644 --- a/sys/arch/sparc/sparc/conf.c +++ b/sys/arch/sparc/sparc/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.32 2002/05/16 21:11:17 miod Exp $ */ +/* $OpenBSD: conf.c,v 1.33 2002/07/09 15:27:59 jason Exp $ */ /* $NetBSD: conf.c,v 1.40 1996/04/11 19:20:03 thorpej Exp $ */ /* @@ -90,6 +90,7 @@ #include "scf.h" #include "flash.h" #include "fga.h" +#include "daadio.h" #ifdef XFS #include @@ -241,8 +242,8 @@ struct cdevsw cdevsw[] = cdev_notdef(), /* 94 */ cdev_notdef(), /* 95 */ cdev_notdef(), /* 96 */ - cdev_notdef(), /* 97 */ - cdev_fga_init(NFGA,fga), /* 98 */ + cdev_daadio_init(NDAADIO,daadio), /* 97: daadio */ + cdev_fga_init(NFGA,fga), /* 98: fga */ cdev_fb_init(NCGFOURTEEN,cgfourteen), /* 99: /dev/cgfourteen */ cdev_tty_init(NMTTY,mtty), /* 100: magma */ cdev_gen_init(NMBPP,mbpp), /* 101: magma */ -- cgit v1.2.3