1/*-
2 *	Copyright (c) 2003 Bob Bishop
3 *      All rights reserved.
4 * [Ported for FreeBSD]
5 *  Copyright (c) 2000
6 *      Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
7 *      All rights reserved.
8 * [NetBSD for NEC PC-98 series]
9 *  Copyright (c) 1996, 1997, 1998
10 *      NetBSD/pc98 porting staff. All rights reserved.
11 *  Copyright (c) 1996, 1997, 1998
12 *      Naofumi HONDA. All rights reserved.
13 *  Copyright (c) 1996, 1997, 1998
14 *      Kouichi Matsuda. All rights reserved.
15 *
16 *  Redistribution and use in source and binary forms, with or without
17 *  modification, are permitted provided that the following conditions
18 *  are met:
19 *  1. Redistributions of source code must retain the above copyright
20 *     notice, this list of conditions and the following disclaimer.
21 *  2. Redistributions in binary form must reproduce the above copyright
22 *     notice, this list of conditions and the following disclaimer in the
23 *     documentation and/or other materials provided with the distribution.
24 *  3. The name of the author may not be used to endorse or promote products
25 *     derived from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD$");
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/kernel.h>
46#include <sys/module.h>
47#include <sys/bus.h>
48#include <sys/malloc.h>
49#include <sys/errno.h>
50
51#include <machine/bus.h>
52#include <machine/resource.h>
53#include <sys/rman.h>
54
55#include <dev/pci/pcireg.h>
56#include <dev/pci/pcivar.h>
57
58#include <cam/scsi/scsi_low.h>
59
60#include <dev/stg/tmc18c30reg.h>
61#include <dev/stg/tmc18c30var.h>
62#include <dev/stg/tmc18c30.h>
63
64static struct _pcsid
65{
66	u_int32_t	type;
67	const char	*desc;
68} pci_ids[] = {
69	{ 0x00001036, 	"Adaptec AHA-2920/A,Future Domain TMC-18XX/3260"	},
70	{ 0x00000000, 	NULL							}
71};
72
73static int
74stg_pci_probe(device_t dev)
75{
76	u_int32_t type = pci_get_devid(dev);
77	struct _pcsid *stg = pci_ids;
78
79	while (stg->type && stg->type != type)
80		++stg;
81	if (stg->desc) {
82		device_set_desc(dev, stg->desc);
83		return (BUS_PROBE_DEFAULT);
84	}
85	return (ENXIO);
86}
87
88static int
89stg_pci_attach(device_t dev)
90{
91	struct stg_softc	*sc = device_get_softc(dev);
92	int			error;
93
94	sc->port_rid = PCIR_BAR(0);
95	sc->irq_rid = 0;
96	error = stg_alloc_resource(dev);
97	if (error) {
98		return(error);
99	}
100
101	/* XXXX remove INTR_ENTROPY below for MFC */
102	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
103			       NULL, stg_intr, (void *)sc, &sc->stg_intrhand);
104	if (error) {
105		stg_release_resource(dev);
106		return(error);
107	}
108
109	if (stg_attach(dev) == 0) {
110		stg_release_resource(dev);
111		return(ENXIO);
112	}
113
114	return(0);
115}
116
117static device_method_t stg_pci_methods[] = {
118	/* Device interface */
119	DEVMETHOD(device_probe,		stg_pci_probe),
120	DEVMETHOD(device_attach,	stg_pci_attach),
121	DEVMETHOD(device_detach,	stg_detach),
122
123	{ 0, 0 }
124};
125
126static driver_t stg_pci_driver = {
127	"stg",
128	stg_pci_methods,
129	sizeof(struct stg_softc),
130};
131
132DRIVER_MODULE(stg, pci, stg_pci_driver, stg_devclass, 0, 0);
133MODULE_DEPEND(stg, scsi_low, 1, 1, 1);
134MODULE_DEPEND(stg, pci, 1, 1, 1);
135