Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pcmcia add pcmcia frontend for cs driver.



details:   https://anonhg.NetBSD.org/src/rev/30196514a5d9
branches:  trunk
changeset: 518212:30196514a5d9
user:      yamt <yamt%NetBSD.org@localhost>
date:      Mon Nov 26 11:17:34 2001 +0000

description:
add pcmcia frontend for cs driver.

diffstat:

 sys/dev/pcmcia/files.pcmcia   |   11 +-
 sys/dev/pcmcia/if_cs_pcmcia.c |  247 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 257 insertions(+), 1 deletions(-)

diffs (287 lines):

diff -r a7ef0bb59b72 -r 30196514a5d9 sys/dev/pcmcia/files.pcmcia
--- a/sys/dev/pcmcia/files.pcmcia       Mon Nov 26 11:14:50 2001 +0000
+++ b/sys/dev/pcmcia/files.pcmcia       Mon Nov 26 11:17:34 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pcmcia,v 1.40 2001/09/29 18:46:16 augustss Exp $
+#      $NetBSD: files.pcmcia,v 1.41 2001/11/26 11:17:34 yamt Exp $
 #
 # Config.new file and device description for machine-independent PCMCIA code.
 # Included by ports that need it.
@@ -102,6 +102,10 @@
 attach tr at pcmcia with tr_pcmcia
 file   dev/pcmcia/if_tr_pcmcia.c               tr_pcmcia
 
+# Crystal Semiconductor CS8920 based cards
+attach cs at pcmcia with cs_pcmcia
+file   dev/pcmcia/if_cs_pcmcia.c               cs_pcmcia
+
 # Aironet PC4500/PC4800
 attach an at pcmcia with an_pcmcia
 file   dev/pcmcia/if_an_pcmcia.c               an_pcmcia
@@ -110,6 +114,10 @@
 attach isic at pcmcia with isic_pcmcia
 file   dev/pcmcia/isic_pcmcia.c                isic_pcmcia
 
+# TMC18C30/18C50
+attach stg at pcmcia with stg_pcmcia
+file   dev/pcmcia/tmc18c30_pcmcia.c    stg_pcmcia
+
 defopt opt_isicpcmcia.h        ISICPCMCIA_AVM_A1 ISICPCMCIA_ELSA_ISDNMC
                                ISICPCMCIA_ELSA_MCALL ISICPCMCIA_SBSPEEDSTAR2
 
@@ -127,3 +135,4 @@
 
 attach opl at esl with opl_esl
 file   dev/pcmcia/opl_esl.c                    opl_esl
+
diff -r a7ef0bb59b72 -r 30196514a5d9 sys/dev/pcmcia/if_cs_pcmcia.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pcmcia/if_cs_pcmcia.c     Mon Nov 26 11:17:34 2001 +0000
@@ -0,0 +1,247 @@
+/* $NetBSD: if_cs_pcmcia.c,v 1.1 2001/11/26 11:17:34 yamt Exp $ */
+
+/*-
+ * Copyright (c)2001 YAMAMOTO Takashi,
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_cs_pcmcia.c,v 1.1 2001/11/26 11:17:34 yamt Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+#include <sys/queue.h>
+
+#include "rnd.h"
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
+#include <net/if.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/pcmcia/pcmciareg.h>
+#include <dev/pcmcia/pcmciavar.h>
+#include <dev/pcmcia/pcmciadevs.h>
+
+#include <dev/isa/isavar.h> /*XXX*/
+
+#include <dev/isa/cs89x0reg.h>
+#include <dev/isa/cs89x0var.h>
+
+#define DEVNAME(sc) ((sc)->sc_dev.dv_xname)
+
+struct cs_pcmcia_softc;
+
+static int cs_pcmcia_match(struct device *, struct cfdata *, void *);
+static void cs_pcmcia_attach(struct device *, struct device *, void *);
+static int cs_pcmcia_detach(struct device *, int);
+static int cs_pcmcia_enable(struct cs_softc *);
+static void cs_pcmcia_disable(struct cs_softc *);
+
+struct cs_pcmcia_softc {
+       struct cs_softc sc_cs; /* real "cs" softc */
+
+       struct pcmcia_io_handle sc_pcioh;
+       struct pcmcia_function *sc_pf;
+       int sc_io_window;
+       int sc_flags;
+};
+
+#define CS_PCMCIA_FLAGS_IO_ALLOCATED 1
+#define CS_PCMCIA_FLAGS_IO_MAPPED 2
+
+struct cfattach cs_pcmcia_ca = {
+       sizeof(struct cs_pcmcia_softc),
+       cs_pcmcia_match,
+       cs_pcmcia_attach,
+       cs_pcmcia_detach,
+       cs_activate
+};
+
+static int
+cs_pcmcia_match(struct device *parent, struct cfdata *match, void *aux)
+{
+       struct pcmcia_attach_args *pa = aux;
+
+       if (pa->card->manufacturer == PCMCIA_VENDOR_IBM
+               && pa->card->product == PCMCIA_PRODUCT_IBM_ETHERJET)
+               return 1;
+
+       return 0;
+}
+
+static void
+cs_pcmcia_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct cs_pcmcia_softc *psc = (void *)self;
+       struct cs_softc *sc = (void *)&psc->sc_cs;
+       struct pcmcia_attach_args *pa = aux;
+       struct pcmcia_config_entry *cfe;
+       struct pcmcia_function *pf;
+       char devinfo[256];
+
+       /* Print out what we are. */
+       pcmcia_devinfo(&pa->pf->sc->card, 0, devinfo, sizeof(devinfo));
+       printf(": %s\n", devinfo);
+
+       pf = psc->sc_pf = pa->pf;
+
+       cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head);
+
+       if (cfe->num_iospace != 1) {
+               printf("%s: unexpected number of iospace(%d)\n",
+                       DEVNAME(sc), cfe->num_iospace);
+               goto fail;
+       }
+
+       if (cfe->iospace[0].length < CS8900_IOSIZE) {
+               printf("%s: unexpected iosize(%lu)\n",
+                       DEVNAME(sc), cfe->iospace[0].length);
+               goto fail;
+       }
+
+       if (cfe->num_memspace != 0) {
+               printf("%s: unexpected number of memspace(%d)\n",
+                       DEVNAME(sc), cfe->num_memspace);
+               goto fail;
+       }
+
+       if (pcmcia_io_alloc(pf, cfe->iospace[0].start,
+               cfe->iospace[0].length, cfe->iospace[0].length,
+               &psc->sc_pcioh) != 0) {
+               printf("%s: can't allocate i/o space %lx:%lx\n", DEVNAME(sc),
+                       cfe->iospace[0].start, cfe->iospace[0].length);
+               goto fail;
+       }
+       psc->sc_flags |= CS_PCMCIA_FLAGS_IO_ALLOCATED;
+
+       sc->sc_iot = psc->sc_pcioh.iot;
+       sc->sc_ioh = psc->sc_pcioh.ioh;
+       sc->sc_drq = ISACF_DRQ_DEFAULT;
+       sc->sc_irq = -1;
+#define CS_PCMCIA_HACK_FOR_CARDBUS
+#ifdef CS_PCMCIA_HACK_FOR_CARDBUS
+       /*
+        * XXX is there a generic way to know if it's a cardbus or not?
+        */
+       sc->sc_cfgflags |= CFGFLG_CARDBUS_HACK;
+#endif
+       sc->sc_enable = cs_pcmcia_enable;
+       sc->sc_disable = cs_pcmcia_disable;
+
+       pcmcia_function_init(pa->pf, cfe);
+       if (cs_pcmcia_enable(sc))
+               goto fail;
+
+       /* chip attach */
+       if (cs_attach(sc, 0, 0, 0, 0))
+               goto fail;
+
+       cs_pcmcia_disable(sc);
+
+       return;
+
+fail:
+       cs_pcmcia_detach((struct device *)psc, 0);
+
+       return;
+}
+
+static int
+cs_pcmcia_detach(struct device *self, int flags)
+{
+       struct cs_pcmcia_softc *psc = (void *)self;
+       struct cs_softc *sc = &psc->sc_cs;
+       struct pcmcia_function *pf = psc->sc_pf;
+       int rv;
+
+       rv = cs_detach(sc);
+       if (rv)
+               return rv;
+       
+       cs_pcmcia_disable(sc);
+
+       if (psc->sc_flags & CS_PCMCIA_FLAGS_IO_ALLOCATED) {
+               pcmcia_io_free(pf, &psc->sc_pcioh);
+               psc->sc_flags &= ~CS_PCMCIA_FLAGS_IO_ALLOCATED;
+       }
+
+       return 0;
+}
+
+static int
+cs_pcmcia_enable(struct cs_softc *sc)
+{
+       struct cs_pcmcia_softc *psc = (void *)sc;
+       struct pcmcia_function *pf = psc->sc_pf;
+
+       if (pcmcia_io_map(pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
+               &psc->sc_pcioh, &psc->sc_io_window) != 0) {
+               printf("%s: can't map i/o space\n", DEVNAME(sc));
+               goto fail;
+       }
+       psc->sc_flags |= CS_PCMCIA_FLAGS_IO_MAPPED;
+
+       if (pcmcia_function_enable(pf)) {
+               printf("%s: can't enable function\n", DEVNAME(sc));
+               goto fail;
+       }
+
+       sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, cs_intr, sc);
+       if (sc->sc_ih == 0) {
+               printf("%s: can't establish interrupt\n", DEVNAME(sc));
+               goto fail;
+       }
+
+       return 0;
+
+fail:
+       return EIO;
+}
+
+static void
+cs_pcmcia_disable(struct cs_softc *sc)
+{
+       struct cs_pcmcia_softc *psc = (void *)sc;
+       struct pcmcia_function *pf = psc->sc_pf;
+
+       if (sc->sc_ih != 0) {
+               pcmcia_intr_disestablish(pf, sc->sc_ih);
+               sc->sc_ih = 0;
+       }
+
+       pcmcia_function_disable(pf);
+       
+       if (psc->sc_flags & CS_PCMCIA_FLAGS_IO_MAPPED) {
+               pcmcia_io_unmap(pf, psc->sc_io_window);
+               psc->sc_flags &= ~CS_PCMCIA_FLAGS_IO_MAPPED;
+       }
+}



Home | Main Index | Thread Index | Old Index