tmc18c30_pccard.c revision 119420
1/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */ 2/* $NetBSD$ */ 3 4/* 5 * [Ported for FreeBSD] 6 * Copyright (c) 2000 7 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. 8 * All rights reserved. 9 * [NetBSD for NEC PC-98 series] 10 * Copyright (c) 1996, 1997, 1998 11 * NetBSD/pc98 porting staff. All rights reserved. 12 * Copyright (c) 1996, 1997, 1998 13 * Naofumi HONDA. All rights reserved. 14 * Copyright (c) 1996, 1997, 1998 15 * Kouichi Matsuda. All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 3. The name of the author may not be used to endorse or promote products 26 * derived from this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 32 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 */ 40 41#include <sys/cdefs.h> 42__FBSDID("$FreeBSD: head/sys/dev/stg/tmc18c30_pccard.c 119420 2003-08-24 18:17:24Z obrien $"); 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/malloc.h> 47#include <sys/errno.h> 48 49#include <machine/bus.h> 50#include <machine/bus_pio.h> 51#include <machine/dvcfg.h> 52 53#include <sys/device_port.h> 54 55#include <dev/pccard/pccarddevs.h> 56#include <dev/pccard/pccardvar.h> 57 58#include <cam/scsi/scsi_low.h> 59#include <cam/scsi/scsi_low_pisa.h> 60 61#include <dev/stg/tmc18c30reg.h> 62#include <dev/stg/tmc18c30var.h> 63#include <dev/stg/tmc18c30.h> 64 65#include <sys/kernel.h> 66#include <sys/module.h> 67#if !defined(__FreeBSD__) || __FreeBSD_version < 500014 68#include <sys/select.h> 69#endif 70#include <pccard/cardinfo.h> 71#include <pccard/slot.h> 72 73static const struct pccard_product stg_products[] = { 74 PCMCIA_CARD(FUTUREDOMAIN, SCSI2GO, 0), 75 PCMCIA_CARD(IBM, SCSICARD, 0), 76 PCMCIA_CARD(RATOC, REX5536, 0), 77 PCMCIA_CARD(RATOC, REX5536AM, 0), 78 PCMCIA_CARD(RATOC, REX5536M, 0), 79 { NULL } 80}; 81 82/* 83 * Additional code for FreeBSD new-bus PCCard frontend 84 */ 85 86static int stg_pccard_match(device_t dev) 87{ 88 const struct pccard_product *pp; 89 90 if ((pp = pccard_product_lookup(dev, stg_products, 91 sizeof(stg_products[0]), NULL)) != NULL) { 92 if (pp->pp_name != NULL) 93 device_set_desc(dev, pp->pp_name); 94 return(0); 95 } 96 return(EIO); 97} 98 99static int 100stg_pccard_probe(DEVPORT_PDEVICE dev) 101{ 102 struct stg_softc *sc = device_get_softc(dev); 103 int error; 104 105 sc->port_rid = 0; 106 sc->irq_rid = 0; 107 error = stg_alloc_resource(dev); 108 if (error) { 109 return(error); 110 } 111 112 if (stg_probe(dev) == 0) { 113 stg_release_resource(dev); 114 return(ENXIO); 115 } 116 117 stg_release_resource(dev); 118 119 return(0); 120} 121 122static int 123stg_pccard_attach(DEVPORT_PDEVICE dev) 124{ 125 struct stg_softc *sc = device_get_softc(dev); 126 int error; 127 128 sc->port_rid = 0; 129 sc->irq_rid = 0; 130 error = stg_alloc_resource(dev); 131 if (error) { 132 return(error); 133 } 134 135 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, 136 stg_intr, (void *)sc, &sc->stg_intrhand); 137 if (error) { 138 stg_release_resource(dev); 139 return(error); 140 } 141 142 if (stg_attach(dev) == 0) { 143 stg_release_resource(dev); 144 return(ENXIO); 145 } 146 147 return(0); 148} 149 150static device_method_t stg_pccard_methods[] = { 151 /* Device interface */ 152 DEVMETHOD(device_probe, pccard_compat_probe), 153 DEVMETHOD(device_attach, pccard_compat_attach), 154 DEVMETHOD(device_detach, stg_detach), 155 156 /* Card interface */ 157 DEVMETHOD(card_compat_match, stg_pccard_match), 158 DEVMETHOD(card_compat_probe, stg_pccard_probe), 159 DEVMETHOD(card_compat_attach, stg_pccard_attach), 160 161 { 0, 0 } 162}; 163 164static driver_t stg_pccard_driver = { 165 "stg", 166 stg_pccard_methods, 167 sizeof(struct stg_softc), 168}; 169 170DRIVER_MODULE(stg, pccard, stg_pccard_driver, stg_devclass, 0, 0); 171MODULE_DEPEND(stg, scsi_low, 1, 1, 1); 172