tmc18c30_pccard.c revision 113205
1/*	$FreeBSD: head/sys/dev/stg/tmc18c30_pccard.c 113205 2003-04-07 10:13:25Z mdodd $	*/
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		device_set_desc(dev, pp->pp_name);
91		return(0);
92	}
93	return(EIO);
94}
95
96static int
97stg_pccard_probe(DEVPORT_PDEVICE dev)
98{
99	struct stg_softc	*sc = device_get_softc(dev);
100	int			error;
101
102	sc->port_rid = 0;
103	sc->irq_rid = 0;
104	error = stg_alloc_resource(dev);
105	if (error) {
106		return(error);
107	}
108
109	if (stg_probe(dev) == 0) {
110		stg_release_resource(dev);
111		return(ENXIO);
112	}
113
114	stg_release_resource(dev);
115
116	return(0);
117}
118
119static int
120stg_pccard_attach(DEVPORT_PDEVICE dev)
121{
122	struct stg_softc	*sc = device_get_softc(dev);
123	int			error;
124
125	sc->port_rid = 0;
126	sc->irq_rid = 0;
127	error = stg_alloc_resource(dev);
128	if (error) {
129		return(error);
130	}
131
132	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
133			       stg_intr, (void *)sc, &sc->stg_intrhand);
134	if (error) {
135		stg_release_resource(dev);
136		return(error);
137	}
138
139	if (stg_attach(dev) == 0) {
140		stg_release_resource(dev);
141		return(ENXIO);
142	}
143
144	return(0);
145}
146
147static device_method_t stg_pccard_methods[] = {
148	/* Device interface */
149	DEVMETHOD(device_probe,		pccard_compat_probe),
150	DEVMETHOD(device_attach,	pccard_compat_attach),
151	DEVMETHOD(device_detach,	stg_detach),
152
153	/* Card interface */
154	DEVMETHOD(card_compat_match,	stg_pccard_match),
155	DEVMETHOD(card_compat_probe,	stg_pccard_probe),
156	DEVMETHOD(card_compat_attach,	stg_pccard_attach),
157
158	{ 0, 0 }
159};
160
161static driver_t stg_pccard_driver = {
162	"stg",
163	stg_pccard_methods,
164	sizeof(struct stg_softc),
165};
166
167DRIVER_MODULE(stg, pccard, stg_pccard_driver, stg_devclass, 0, 0);
168MODULE_DEPEND(stg, scsi_low, 1, 1, 1);
169