summaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorsmart <smart@cvs.openbsd.org>2001-08-20 04:41:40 +0000
committersmart <smart@cvs.openbsd.org>2001-08-20 04:41:40 +0000
commit7910f09fd6fad4008fe999de0d01ad855b2a386b (patch)
treea3462c05fb4bec6b268b856031520b8e7b820bff /sys/dev/pci
parentd9bf3f8295bf4b2983561258d7e4e682174b9b27 (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/dev/pci')
-rw-r--r--sys/dev/pci/cy_pci.c215
1 files changed, 109 insertions, 106 deletions
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);
}