1 /* $NetBSD: fwohci_cardbus.c,v 1.10 2003/03/22 11:32:38 nakayama Exp $ */ 2 3 /*- 4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matt Thomas of 3am Software Foundry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: fwohci_cardbus.c,v 1.10 2003/03/22 11:32:38 nakayama Exp $"); 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/socket.h> 45 #include <sys/device.h> 46 #include <sys/select.h> 47 48 #include <machine/bus.h> 49 50 #if defined pciinc 51 #include <dev/pci/pcidevs.h> 52 #endif 53 54 #include <dev/cardbus/cardbusvar.h> 55 #include <dev/cardbus/cardbusdevs.h> 56 57 #include <dev/ieee1394/ieee1394reg.h> 58 #include <dev/ieee1394/ieee1394var.h> 59 #include <dev/ieee1394/fwohcireg.h> 60 #include <dev/ieee1394/fwohcivar.h> 61 62 struct fwohci_cardbus_softc { 63 struct fwohci_softc sc_sc; 64 cardbus_chipset_tag_t sc_cc; 65 cardbus_function_tag_t sc_cf; 66 cardbus_devfunc_t sc_ct; 67 void *sc_ih; 68 }; 69 70 static int fwohci_cardbus_match(struct device *, struct cfdata *, void *); 71 static void fwohci_cardbus_attach(struct device *, struct device *, void *); 72 static int fwohci_cardbus_detach(struct device *, int); 73 74 CFATTACH_DECL(fwohci_cardbus, sizeof(struct fwohci_cardbus_softc), 75 fwohci_cardbus_match, fwohci_cardbus_attach, 76 fwohci_cardbus_detach, fwohci_activate); 77 78 #define CARDBUS_INTERFACE_OHCI PCI_INTERFACE_OHCI 79 #define CARDBUS_OHCI_MAP_REGISTER PCI_OHCI_MAP_REGISTER 80 #define CARDBUS_OHCI_CONTROL_REGISTER PCI_OHCI_CONTROL_REGISTER 81 #define CARDBUS_GLOBAL_SWAP_BE PCI_GLOBAL_SWAP_BE 82 #define cardbus_devinfo pci_devinfo 83 84 static int 85 fwohci_cardbus_match(struct device *parent, struct cfdata *match, void *aux) 86 { 87 struct cardbus_attach_args *ca = (struct cardbus_attach_args *)aux; 88 89 if (CARDBUS_CLASS(ca->ca_class) == CARDBUS_CLASS_SERIALBUS && 90 CARDBUS_SUBCLASS(ca->ca_class) == 91 CARDBUS_SUBCLASS_SERIALBUS_FIREWIRE && 92 CARDBUS_INTERFACE(ca->ca_class) == CARDBUS_INTERFACE_OHCI) 93 return 1; 94 95 return 0; 96 } 97 98 static void 99 fwohci_cardbus_attach(struct device *parent, struct device *self, void *aux) 100 { 101 struct cardbus_attach_args *ca = aux; 102 struct fwohci_cardbus_softc *sc = (struct fwohci_cardbus_softc *)self; 103 cardbus_devfunc_t ct = ca->ca_ct; 104 cardbus_chipset_tag_t cc = ct->ct_cc; 105 cardbus_function_tag_t cf = ct->ct_cf; 106 cardbusreg_t csr; 107 char devinfo[256]; 108 const char *devname = self->dv_xname; 109 110 cardbus_devinfo(ca->ca_id, ca->ca_class, 0, devinfo); 111 printf(": %s (rev. 0x%02x)\n", devinfo, 112 CARDBUS_REVISION(ca->ca_class)); 113 114 /* Map I/O registers */ 115 if (Cardbus_mapreg_map(ct, CARDBUS_OHCI_MAP_REGISTER, 116 CARDBUS_MAPREG_TYPE_MEM, 0, 117 &sc->sc_sc.sc_memt, &sc->sc_sc.sc_memh, 118 NULL, &sc->sc_sc.sc_memsize)) { 119 printf("%s: can't map OHCI register space\n", devname); 120 return; 121 } 122 123 sc->sc_cc = cc; 124 sc->sc_cf = cf; 125 sc->sc_ct = ct; 126 sc->sc_sc.sc_dmat = ca->ca_dmat; 127 128 #if rbus 129 #else 130 XXX (ct->ct_cf->cardbus_mem_open)(cc, 0, iob, iob + 0x40); 131 #endif 132 (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE); 133 (ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE); 134 135 /* Disable interrupts, so we don't get any spurious ones. */ 136 OHCI_CSR_WRITE(&sc->sc_sc, OHCI_REG_IntMaskClear, 137 OHCI_Int_MasterEnable); 138 139 /* Enable the device. */ 140 csr = cardbus_conf_read(cc, cf, ca->ca_tag, 141 CARDBUS_COMMAND_STATUS_REG); 142 cardbus_conf_write(cc, cf, ca->ca_tag, CARDBUS_COMMAND_STATUS_REG, 143 csr | CARDBUS_COMMAND_MASTER_ENABLE | CARDBUS_COMMAND_MEM_ENABLE); 144 145 #if BYTE_ORDER == BIG_ENDIAN 146 csr = cardbus_conf_read(cc, cf, ca->ca_tag, 147 CARDBUS_OHCI_CONTROL_REGISTER); 148 cardbus_conf_write(cc, cf, ca->ca_tag, CARDBUS_OHCI_CONTROL_REGISTER, 149 csr | CARDBUS_GLOBAL_SWAP_BE); 150 #endif 151 152 sc->sc_ih = cardbus_intr_establish(cc, cf, ca->ca_intrline, 153 IPL_BIO, fwohci_intr, sc); 154 if (sc->sc_ih == NULL) { 155 printf("%s: couldn't establish interrupt\n", devname); 156 return; 157 } 158 printf("%s: interrupting at %d\n", devname, ca->ca_intrline); 159 160 /* XXX NULL should be replaced by some call to Cardbus coed */ 161 if (fwohci_init(&sc->sc_sc, NULL) != 0) { 162 cardbus_intr_disestablish(cc, cf, sc->sc_ih); 163 bus_space_unmap(sc->sc_sc.sc_memt, sc->sc_sc.sc_memh, 164 sc->sc_sc.sc_memsize); 165 } 166 } 167 168 int 169 fwohci_cardbus_detach(struct device *self, int flags) 170 { 171 struct fwohci_cardbus_softc *sc = (struct fwohci_cardbus_softc *)self; 172 cardbus_devfunc_t ct = sc->sc_ct; 173 int rv; 174 175 rv = fwohci_detach(&sc->sc_sc, flags); 176 177 if (rv) 178 return (rv); 179 if (sc->sc_ih != NULL) { 180 cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih); 181 sc->sc_ih = NULL; 182 } 183 if (sc->sc_sc.sc_memsize) { 184 Cardbus_mapreg_unmap(ct, CARDBUS_OHCI_MAP_REGISTER, 185 sc->sc_sc.sc_memt, sc->sc_sc.sc_memh, 186 sc->sc_sc.sc_memsize); 187 sc->sc_sc.sc_memsize = 0; 188 } 189 return (0); 190 } 191