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