tmc18c30_pccard.c revision 113315
160107Sobrien/*	$FreeBSD: head/sys/dev/stg/tmc18c30_pccard.c 113315 2003-04-10 04:36:02Z imp $	*/
22786Ssos/*	$NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $	*/
32786Ssos/*	$NetBSD$	*/
42786Ssos
52786Ssos/*
62786Ssos * [Ported for FreeBSD]
72786Ssos *  Copyright (c) 2000
82786Ssos *      Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
96851Ssos *      All rights reserved.
102786Ssos * [NetBSD for NEC PC-98 series]
112786Ssos *  Copyright (c) 1996, 1997, 1998
122786Ssos *	NetBSD/pc98 porting staff. All rights reserved.
132786Ssos *  Copyright (c) 1996, 1997, 1998
142786Ssos *	Naofumi HONDA. All rights reserved.
152786Ssos *  Copyright (c) 1996, 1997, 1998
162786Ssos *	Kouichi Matsuda. All rights reserved.
172786Ssos *
182786Ssos *  Redistribution and use in source and binary forms, with or without
192786Ssos *  modification, are permitted provided that the following conditions
207420Ssos *  are met:
214686Sache *  1. Redistributions of source code must retain the above copyright
222786Ssos *     notice, this list of conditions and the following disclaimer.
232786Ssos *  2. Redistributions in binary form must reproduce the above copyright
242786Ssos *     notice, this list of conditions and the following disclaimer in the
252786Ssos *     documentation and/or other materials provided with the distribution.
262786Ssos *  3. The name of the author may not be used to endorse or promote products
272786Ssos *     derived from this software without specific prior written permission.
282786Ssos *
292786Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
302786Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
312786Ssos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
322786Ssos * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
332786Ssos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
342786Ssos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
352786Ssos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
362786Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
372786Ssos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
382786Ssos * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
392786Ssos * POSSIBILITY OF SUCH DAMAGE.
402786Ssos */
412786Ssos
422786Ssos#include <sys/param.h>
432786Ssos#include <sys/systm.h>
442786Ssos#include <sys/malloc.h>
452786Ssos#include <sys/errno.h>
462786Ssos
472786Ssos#include <machine/bus.h>
482786Ssos#include <machine/bus_pio.h>
492786Ssos#include <machine/dvcfg.h>
502786Ssos
512786Ssos#include <sys/device_port.h>
522786Ssos
532786Ssos#include <dev/pccard/pccarddevs.h>
542786Ssos#include <dev/pccard/pccardvar.h>
552786Ssos
562786Ssos#include <cam/scsi/scsi_low.h>
572786Ssos#include <cam/scsi/scsi_low_pisa.h>
582786Ssos
5938140Syokota#include <dev/stg/tmc18c30reg.h>
602786Ssos#include <dev/stg/tmc18c30var.h>
612786Ssos#include <dev/stg/tmc18c30.h>
622786Ssos
6332822Syokota#include	<sys/kernel.h>
642786Ssos#include	<sys/module.h>
652786Ssos#if !defined(__FreeBSD__) || __FreeBSD_version < 500014
662786Ssos#include	<sys/select.h>
672786Ssos#endif
682786Ssos#include	<pccard/cardinfo.h>
692786Ssos#include	<pccard/slot.h>
702786Ssos
712786Ssosstatic const struct pccard_product stg_products[] = {
722786Ssos	PCMCIA_CARD(FUTUREDOMAIN, SCSI2GO, 0),
732786Ssos	PCMCIA_CARD(IBM, SCSICARD, 0),
742786Ssos	PCMCIA_CARD(RATOC, REX5536, 0),
752786Ssos	PCMCIA_CARD(RATOC, REX5536AM, 0),
762786Ssos	PCMCIA_CARD(RATOC, REX5536M, 0),
772786Ssos	{ NULL }
782786Ssos};
792786Ssos
802786Ssos/*
812786Ssos * Additional code for FreeBSD new-bus PCCard frontend
825994Ssos */
832786Ssos
842786Ssosstatic int stg_pccard_match(device_t dev)
852786Ssos{
862786Ssos  	const struct pccard_product *pp;
872786Ssos
882786Ssos	if ((pp = pccard_product_lookup(dev, stg_products,
896045Ssos	    sizeof(stg_products[0]), NULL)) != NULL) {
902786Ssos		if (pp->pp_name != NULL)
912786Ssos			device_set_desc(dev, pp->pp_name);
922786Ssos		return(0);
932786Ssos	}
942786Ssos	return(EIO);
9518194Ssos}
962786Ssos
972786Ssosstatic int
9843334Syokotastg_pccard_probe(DEVPORT_PDEVICE dev)
992786Ssos{
1002786Ssos	struct stg_softc	*sc = device_get_softc(dev);
1012786Ssos	int			error;
1022786Ssos
1032786Ssos	sc->port_rid = 0;
1042786Ssos	sc->irq_rid = 0;
1052786Ssos	error = stg_alloc_resource(dev);
1062786Ssos	if (error) {
1072786Ssos		return(error);
1082786Ssos	}
1096851Ssos
11043334Syokota	if (stg_probe(dev) == 0) {
11143334Syokota		stg_release_resource(dev);
11243334Syokota		return(ENXIO);
11343334Syokota	}
11443334Syokota
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