diff options
author | smart <smart@cvs.openbsd.org> | 2001-08-20 04:41:40 +0000 |
---|---|---|
committer | smart <smart@cvs.openbsd.org> | 2001-08-20 04:41:40 +0000 |
commit | 7910f09fd6fad4008fe999de0d01ad855b2a386b (patch) | |
tree | a3462c05fb4bec6b268b856031520b8e7b820bff /sys | |
parent | d9bf3f8295bf4b2983561258d7e4e682174b9b27 (diff) |
Allow driver to recognize Cyclades 4Y and 8Y cards.
Not finished yet, but cleaned up and moved around code for
better organization. Inspired by NetBSD and other PCI drivers.
From my dmesg:
cy1 at pci0 dev 10 function 0 "Cyclades Cyclom-8Y" rev 0x01
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ic/cy.c | 61 | ||||
-rw-r--r-- | sys/dev/ic/cyreg.h | 75 | ||||
-rw-r--r-- | sys/dev/isa/cy_isa.c | 55 | ||||
-rw-r--r-- | sys/dev/pci/cy_pci.c | 215 |
4 files changed, 190 insertions, 216 deletions
diff --git a/sys/dev/ic/cy.c b/sys/dev/ic/cy.c index 1e4fcd14382..9117d0870ad 100644 --- a/sys/dev/ic/cy.c +++ b/sys/dev/ic/cy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cy.c,v 1.14 2001/08/19 19:58:56 smart Exp $ */ +/* $OpenBSD: cy.c,v 1.15 2001/08/20 04:41:39 smart Exp $ */ /* * cy.c @@ -22,9 +22,6 @@ * */ -#undef CY_DEBUG -#undef CY_DEBUG1 - /* NCY is the number of Cyclom cards in the machine */ #include "cy.h" #if NCY > 0 @@ -66,9 +63,9 @@ #define ISSET(t, f) ((t) & (f)) -void cyattach __P((struct device *, struct device *, void *)); +void cy_attach __P((struct device *, struct device *, void *)); int cy_probe_common __P((int, bus_space_tag_t, bus_space_handle_t, int)); -int cyintr __P((void *)); +int cy_intr __P((void *)); int cyparam __P((struct tty *, struct termios *)); void cystart __P((struct tty *)); void cy_poll __P((void *)); @@ -114,13 +111,13 @@ cy_probe_common(card, memt, memh, bustype) for (cy_chip = 0, chip_offs = 0; cy_chip < CY_MAX_CD1400s; - cy_chip++, chip_offs += (CY_CD1400_MEMSPACING<<bustype)) { + cy_chip++, chip_offs += (CY_CD1400_MEMSPACING << bustype)) { int i; /* the last 4 cd1400s are 'interleaved' with the first 4 on 32-port boards */ if (cy_chip == 4) - chip_offs -= (CY32_ADDR_FIX<<bustype); + chip_offs -= (CY32_ADDR_FIX << bustype); #ifdef CY_DEBUG printf("cy%d probe chip %d offset 0x%lx ... ", @@ -130,7 +127,7 @@ cy_probe_common(card, memt, memh, bustype) /* wait until the chip is ready for command */ DELAY(1000); if (bus_space_read_1(memt, memh, chip_offs + - ((CD1400_CCR<<1) << bustype)) != 0) { + ((CD1400_CCR << 1) << bustype)) != 0) { #ifdef CY_DEBUG printf("not ready for command\n"); #endif @@ -139,7 +136,7 @@ cy_probe_common(card, memt, memh, bustype) /* clear the firmware version reg. */ bus_space_write_1(memt, memh, chip_offs + - ((CD1400_GFRCR<<1) << bustype), 0); + ((CD1400_GFRCR << 1) << bustype), 0); /* * On Cyclom-16 references to non-existent chip 4 @@ -149,19 +146,19 @@ cy_probe_common(card, memt, memh, bustype) */ if (cy_chip == 4 && bus_space_read_1(memt, memh, chip_offs + - ((CD1400_GFRCR<<1) << bustype)) == 0) + ((CD1400_GFRCR << 1) << bustype)) == 0) break; /* reset the chip */ bus_space_write_1(memt, memh, chip_offs + - ((CD1400_CCR<<1) << bustype), + ((CD1400_CCR << 1) << bustype), CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET); /* wait for the chip to initialize itself */ for (i = 0; i < 200; i++) { DELAY(50); firmware_ver = bus_space_read_1(memt, memh, chip_offs + - ((CD1400_GFRCR<<1) << bustype)); + ((CD1400_GFRCR << 1) << bustype)); if ((firmware_ver & 0xf0) == 0x40) /* found a CD1400 */ break; } @@ -193,16 +190,13 @@ cy_probe_common(card, memt, memh, bustype) return (1); } -/* - * Attach (ISA/PCI) - */ void -cyattach(parent, self, aux) +cy_attach(parent, self, aux) struct device *parent, *self; void *aux; { - struct cy_softc *sc = (void *)self; int card, port, cy_chip, num_chips, cdu, chip_offs, cy_clock; + struct cy_softc *sc = (void *)self; card = sc->sc_dev.dv_unit; num_chips = cy_nr_cd1400s[card]; @@ -269,7 +263,9 @@ cyattach(parent, self, aux) } /* for(each CD1400 on a card... ) */ - printf(" (%d ports)\n", port); +#if CY_DEBUG + printf("cy: %d ports\n", port); +#endif /* ensure an edge for the next interrupt */ bus_space_write_1(sc->sc_memt, sc->sc_memh, @@ -282,33 +278,18 @@ cyattach(parent, self, aux) struct isa_attach_args *ia = aux; sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, - IST_EDGE, IPL_TTY, cyintr, sc, sc->sc_dev.dv_xname); + IST_EDGE, IPL_TTY, cy_intr, sc, sc->sc_dev.dv_xname); + + if (sc->sc_ih == NULL) + panic("cy: couldn't establish interrupt"); } break; #endif /* NCY_ISA > 0 */ -#if NCY_PCI > 0 case CY_BUSTYPE_PCI: - { - pci_intr_handle_t intrhandle; - struct pci_attach_args *pa = aux; - - if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, - pa->pa_intrline, &intrhandle) != 0) - panic("cy: couldn't map PCI interrupt"); - - sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, - IPL_TTY, cyintr, sc, sc->sc_dev.dv_xname); - } - break; -#endif /* NCY_PCI > 0 */ + break; } - - if (sc->sc_ih == NULL) - panic("cy: couldn't establish interrupt"); } -#undef CY_DEBUG /*!!*/ - /* * open routine. returns zero if successfull, else error code */ @@ -1167,7 +1148,7 @@ out: * hardware interrupt routine */ int -cyintr(arg) +cy_intr(arg) void *arg; { struct cy_softc *sc = arg; diff --git a/sys/dev/ic/cyreg.h b/sys/dev/ic/cyreg.h index a364c8a8610..ea4c82b52d0 100644 --- a/sys/dev/ic/cyreg.h +++ b/sys/dev/ic/cyreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cyreg.h,v 1.5 2001/03/25 11:54:00 art Exp $ */ +/* $OpenBSD: cyreg.h,v 1.6 2001/08/20 04:41:39 smart Exp $ */ /* $FreeBSD: cyreg.h,v 1.1 1995/07/05 12:15:51 bde Exp $ */ /*- @@ -32,6 +32,9 @@ * SUCH DAMAGE. */ +#ifndef _DEV_IC_CYREG_H_ +#define _DEV_IC_CYREG_H_ + #include <sys/timeout.h> /* @@ -99,8 +102,8 @@ /* * read/write cd1400 registers (when cy_port-structure is available) */ -#define cd_read_reg(cy,reg) bus_space_read_1(cy->cy_memt, cy->cy_memh, \ - cy->cy_chip_offs+(((reg<<1))<<cy->cy_bustype)) +#define cd_read_reg(cy,reg) bus_space_read_1(cy->cy_memt, cy->cy_memh, \ + cy->cy_chip_offs+(((reg<<1))<<cy->cy_bustype)) #define cd_write_reg(cy,reg,val) bus_space_write_1(cy->cy_memt, cy->cy_memh, \ cy->cy_chip_offs+(((reg<<1))<<cy->cy_bustype), \ @@ -128,26 +131,28 @@ /* software state for one port */ struct cy_port { - int cy_port_num; - bus_space_tag_t cy_memt; - bus_space_handle_t cy_memh; - int cy_chip_offs; - int cy_bustype; - int cy_clock; - struct tty *cy_tty; - int cy_openflags; - int cy_fifo_overruns; - int cy_ibuf_overruns; - u_char cy_channel_control; /* last CCR channel control command bits */ - u_char cy_carrier_stat; /* copied from MSVR2 */ - u_char cy_flags; - u_char *cy_ibuf, *cy_ibuf_end; - u_char *cy_ibuf_rd_ptr, *cy_ibuf_wr_ptr; + int cy_port_num; + bus_space_tag_t cy_memt; + bus_space_handle_t cy_memh; + int cy_chip_offs; + int cy_bustype; + int cy_clock; + struct tty *cy_tty; + int cy_openflags; + int cy_fifo_overruns; + int cy_ibuf_overruns; + u_char cy_channel_control; /* last CCR channel + * control command + * bits */ + u_char cy_carrier_stat; /* copied from MSVR2 */ + u_char cy_flags; + u_char *cy_ibuf, *cy_ibuf_end; + u_char *cy_ibuf_rd_ptr, *cy_ibuf_wr_ptr; #ifdef CY_DEBUG1 - int cy_rx_int_count; - int cy_tx_int_count; - int cy_modem_int_count; - int cy_start_count; + int cy_rx_int_count; + int cy_tx_int_count; + int cy_modem_int_count; + int cy_start_count; #endif /* CY_DEBUG1 */ }; @@ -160,16 +165,22 @@ struct cy_port { /* software state for one card */ struct cy_softc { - struct device sc_dev; - void *sc_ih; - bus_space_tag_t sc_memt; - bus_space_handle_t sc_memh; - int sc_bustype; - int sc_nports; /* number of ports on this card */ - int sc_cd1400_offs[CY_MAX_CD1400s]; - struct cy_port sc_ports[CY_MAX_PORTS]; + struct device sc_dev; + void *sc_ih; + bus_space_tag_t sc_memt; + bus_space_handle_t sc_memh; + int sc_bustype; + int sc_nports; /* number of ports on this card */ + int sc_cd1400_offs[CY_MAX_CD1400s]; + struct cy_port sc_ports[CY_MAX_PORTS]; #ifdef CY_DEBUG1 - int sc_poll_count1; - int sc_poll_count2; + int sc_poll_count1; + int sc_poll_count2; #endif }; + +int cy_probe_common __P((int, bus_space_tag_t, bus_space_handle_t, int)); +void cy_attach __P((struct device *, struct device *, void *)); +int cy_intr __P((void *)); + +#endif /* _DEV_IC_CYREG_H_ */ diff --git a/sys/dev/isa/cy_isa.c b/sys/dev/isa/cy_isa.c index 926fb9d996d..363e883215a 100644 --- a/sys/dev/isa/cy_isa.c +++ b/sys/dev/isa/cy_isa.c @@ -1,64 +1,35 @@ -/* $OpenBSD: cy_isa.c,v 1.5 2001/08/19 19:58:56 smart Exp $ */ +/* $OpenBSD: cy_isa.c,v 1.6 2001/08/20 04:41:39 smart Exp $ */ /* - * cy.c + * cy_isa.c * * Driver for Cyclades Cyclom-8/16/32 multiport serial cards * (currently not tested with Cyclom-32 cards) * * Timo Rossi, 1996 - * - * Supports both ISA and PCI Cyclom cards - * - * Uses CD1400 automatic CTS flow control, and - * if CY_HW_RTS is defined, uses CD1400 automatic input flow control. - * This requires a special cable that exchanges the RTS and DTR lines. - * - * Lots of debug output can be enabled by defining CY_DEBUG - * Some debugging counters (number of receive/transmit interrupts etc.) - * can be enabled by defining CY_DEBUG1 - * - * This version uses the bus_mem/io_??() stuff - * - * NOT TESTED !!! - * */ -#include <sys/types.h> #include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/syslog.h> -#include <sys/fcntl.h> -#include <sys/tty.h> -#include <sys/proc.h> -#include <sys/conf.h> -#include <sys/user.h> -#include <sys/select.h> -#include <sys/device.h> -#include <sys/malloc.h> #include <sys/systm.h> +#include <sys/device.h> + #include <machine/bus.h> + #include <dev/isa/isavar.h> #include <dev/isa/isareg.h> #include <dev/ic/cd1400reg.h> #include <dev/ic/cyreg.h> -int cy_probe_isa __P((struct device *, void *, void *)); -int cy_probe_common __P((int card, bus_space_tag_t, - bus_space_handle_t, int bustype)); - -void cyattach __P((struct device *, struct device *, void *)); +static int cy_isa_probe __P((struct device *, void *, void *)); +void cy_isa_attach __P((struct device *, struct device *, void *)); struct cfattach cy_isa_ca = { - sizeof(struct cy_softc), cy_probe_isa, cyattach + sizeof(struct cy_softc), cy_isa_probe, cy_isa_attach }; -/* - * ISA probe - */ int -cy_probe_isa(parent, match, aux) +cy_isa_probe(parent, match, aux) struct device *parent; void *match, *aux; { @@ -85,3 +56,11 @@ cy_probe_isa(parent, match, aux) ia->ia_msize = 0x2000; return (1); } + +void +cy_isa_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + cy_attach(parent, self, aux); +} diff --git a/sys/dev/pci/cy_pci.c b/sys/dev/pci/cy_pci.c index 1ffb003d35b..b516b26cdfc 100644 --- a/sys/dev/pci/cy_pci.c +++ b/sys/dev/pci/cy_pci.c @@ -1,47 +1,20 @@ -/* $OpenBSD: cy_pci.c,v 1.6 2001/06/29 00:16:32 smart Exp $ */ +/* $OpenBSD: cy_pci.c,v 1.7 2001/08/20 04:41:39 smart Exp $ */ /* - * cy.c + * cy_pci.c * * Driver for Cyclades Cyclom-8/16/32 multiport serial cards * (currently not tested with Cyclom-32 cards) * * Timo Rossi, 1996 - * - * Supports both ISA and PCI Cyclom cards - * - * Uses CD1400 automatic CTS flow control, and - * if CY_HW_RTS is defined, uses CD1400 automatic input flow control. - * This requires a special cable that exchanges the RTS and DTR lines. - * - * Lots of debug output can be enabled by defining CY_DEBUG - * Some debugging counters (number of receive/transmit interrupts etc.) - * can be enabled by defining CY_DEBUG1 - * - * This version uses the bus_mem/io_??() stuff - * - * NOT TESTED !!! - * */ -#undef CY_DEBUG -#undef CY_DEBUG1 - -#include <sys/types.h> #include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/syslog.h> -#include <sys/fcntl.h> -#include <sys/tty.h> -#include <sys/proc.h> -#include <sys/conf.h> -#include <sys/user.h> -#include <sys/ioctl.h> -#include <sys/select.h> -#include <sys/device.h> -#include <sys/malloc.h> #include <sys/systm.h> +#include <sys/device.h> + #include <machine/bus.h> + #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> #include <dev/pci/pcidevs.h> @@ -49,31 +22,50 @@ #include <dev/ic/cd1400reg.h> #include <dev/ic/cyreg.h> -/* Macros to clear/set/test flags. */ -#define SET(t, f) (t) |= (f) -#define CLR(t, f) (t) &= ~(f) -#define ISSET(t, f) ((t) & (f)) - -int cy_probe_pci __P((struct device *, void *, void *)); -int cy_probe_common __P((int card, bus_space_tag_t, - bus_space_handle_t, int bustype)); - -void cyattach __P((struct device *, struct device *, void *)); +int cy_pci_match __P((struct device *, void *, void *)); +void cy_pci_attach __P((struct device *, struct device *, void *)); struct cfattach cy_pci_ca = { - sizeof(struct cy_softc), cy_probe_pci, cyattach + sizeof(struct cy_softc), cy_pci_match, cy_pci_attach }; -/* - * PCI probe - */ int -cy_probe_pci(parent, match, aux) +cy_pci_match(parent, match, aux) struct device *parent; void *match, *aux; { - int card = ((struct device *)match)->dv_unit; struct pci_attach_args *pa = aux; + + if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CYCLADES) + return (0); + + switch (PCI_PRODUCT(pa->pa_id)) { + case PCI_PRODUCT_CYCLADES_CYCLOMY_1: + case PCI_PRODUCT_CYCLADES_CYCLOMY_2: + case PCI_PRODUCT_CYCLADES_CYCLOM4Y_1: + case PCI_PRODUCT_CYCLADES_CYCLOM4Y_2: + case PCI_PRODUCT_CYCLADES_CYCLOM8Y_1: + case PCI_PRODUCT_CYCLADES_CYCLOM8Y_2: + break; + default: + return (0); + } + +#ifdef CY_DEBUG + printf("cy: Found Cyclades PCI device, id = 0x%x\n", pa->pa_id); +#endif + + return (1); +} + +void +cy_pci_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct cy_softc *sc = (struct cy_softc *)self; + struct pci_attach_args *pa = aux; + pci_intr_handle_t ih; bus_space_tag_t memt; bus_space_handle_t memh; bus_addr_t memaddr; @@ -82,72 +74,83 @@ cy_probe_pci(parent, match, aux) bus_space_handle_t ioh; bus_addr_t iobase; bus_size_t iosize; - int cacheable; int plx_ver; + int cacheable; - if (!(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CYCLADES && - (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CYCLADES_CYCLOMY_1 || - PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CYCLADES_CYCLOMY_2))) - return (0); + memt = pa->pa_memt; + iot = pa->pa_iot; + + if (pci_mem_find(pa->pa_pc, pa->pa_tag, 0x18, + &memaddr, &memsize, &cacheable) != 0) { + printf("%s: can't find PCI card memory", + sc->sc_dev.dv_xname); + return; + } + + /* map the memory (non-cacheable) */ + if (bus_space_map(memt, memaddr, memsize, 0, &memh) != 0) { + printf("%s: couldn't map PCI memory region\n", + sc->sc_dev.dv_xname); + return; + } + + /* the PCI Cyclom IO space is only used for enabling interrupts */ + if (pci_io_find(pa->pa_pc, pa->pa_tag, 0x14, &iobase, &iosize) != 0) { + bus_space_unmap(memt, memh, memsize); + printf("%s: couldn't find PCI io region\n", + sc->sc_dev.dv_xname); + return; + } + + if (bus_space_map(iot, iobase, iosize, 0, &ioh) != 0) { + bus_space_unmap(memt, memh, memsize); + printf("%s: couldn't map PCI io region\n", + sc->sc_dev.dv_xname); + return; + } #ifdef CY_DEBUG - printf("cy: Found Cyclades PCI device, id = 0x%x\n", pa->pa_id); + printf("%s: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n", + sc->sc_dev.dv_xname, memaddr, memsize, iobase, iosize); #endif - memt = pa->pa_memt; - iot = pa->pa_iot; + if (cy_probe_common(sc->sc_dev.dv_unit, memt, memh, + CY_BUSTYPE_PCI) == 0) { + bus_space_unmap(memt, memh, memsize); + bus_space_unmap(iot, ioh, iosize); + printf("%s: PCI Cyclom card with no CD1400s!?\n", + sc->sc_dev.dv_xname); + return; + } - if (pci_mem_find(pa->pa_pc, pa->pa_tag, 0x18, - &memaddr, &memsize, &cacheable) != 0) { - printf("cy%d: can't find PCI card memory", card); - return (0); - } - - /* map the memory (non-cacheable) */ - if (bus_space_map(memt, memaddr, memsize, 0, &memh) != 0) { - printf("cy%d: couldn't map PCI memory region\n", card); - return (0); - } - - /* the PCI Cyclom IO space is only used for enabling interrupts */ - if (pci_io_find(pa->pa_pc, pa->pa_tag, 0x14, &iobase, &iosize) != 0) { - bus_space_unmap(memt, memh, memsize); - printf("cy%d: couldn't find PCI io region\n", card); - return (0); - } + cy_attach(parent, self, aux); - if (bus_space_map(iot, iobase, iosize, 0, &ioh) != 0) { - bus_space_unmap(memt, memh, memsize); - printf("cy%d: couldn't map PCI io region\n", card); - return (0); - } - -#ifdef CY_DEBUG - printf("cy%d: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n", - card, memaddr, memsize, iobase, iosize); -#endif - - if (cy_probe_common(card, memt, memh, CY_BUSTYPE_PCI) == 0) { - bus_space_unmap(memt, memh, memsize); - bus_space_unmap(iot, ioh, iosize); - printf("cy%d: PCI Cyclom card with no CD1400s!?\n", card); - return (0); - } + /* Get PLX version */ + memt = pa->pa_memt; + iot = pa->pa_iot; + plx_ver = bus_space_read_1(memt, memh, CY_PLX_VER) & 0x0f; + + /* Enable PCI card interrupts */ + switch (plx_ver) { + case CY_PLX_9050: + bus_space_write_2(iot, ioh, CY_PCI_INTENA_9050, + bus_space_read_2(iot, ioh, CY_PCI_INTENA_9050) | 0x40); + break; + case CY_PLX_9060: + case CY_PLX_9080: + default: + bus_space_write_2(iot, ioh, CY_PCI_INTENA, + bus_space_read_2(iot, ioh, CY_PCI_INTENA) | 0x900); + } + + /* Enable PCI card interrupts */ + if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, + pa->pa_intrline, &ih) != 0) + panic("%s: couldn't map PCI interrupt", sc->sc_dev.dv_xname); - /* Get PLX version */ - plx_ver = bus_space_read_1(memt, memh, CY_PLX_VER) & 0x0f; + sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_TTY, cy_intr, + sc, sc->sc_dev.dv_xname); - /* Enable PCI card interrupts */ - switch (plx_ver) { - case CY_PLX_9050: - bus_space_write_2(iot, ioh, CY_PCI_INTENA_9050, - bus_space_read_2(iot, ioh, CY_PCI_INTENA_9050) | 0x40); - break; - case CY_PLX_9060: - case CY_PLX_9080: - default: - bus_space_write_2(iot, ioh, CY_PCI_INTENA, - bus_space_read_2(iot, ioh, CY_PCI_INTENA) | 0x900); - } - return (1); + if (sc->sc_ih == NULL) + panic("%s: couldn't establish interrupt", sc->sc_dev.dv_xname); } |