]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/matcd/matcd_isa.c
Use __FBSDID().
[FreeBSD/FreeBSD.git] / sys / dev / matcd / matcd_isa.c
1 /*- matcd_isa.c---------------------------------------------------------------
2
3         Matsushita(Panasonic) / Creative CD-ROM Driver  (matcd)
4         Authored by Frank Durda IV
5
6 Copyright 1994, 1995, 2002, 2003  Frank Durda IV.  All rights reserved.
7 "FDIV" is a trademark of Frank Durda IV.
8
9 ------------------------------------------------------------------------------
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions
13 are met:
14 1. Redistributions of source code must retain the above copyright
15    notice, this list of conditions and the following disclaimer.
16 2. Redistributions in binary form must reproduce the above copyright
17    notice, this list of conditions and the following disclaimer in the
18    documentation and/or other materials provided with the distribution.
19 3. Neither the name of the author nor the names of their contributors
20    may be used to endorse or promote products derived from this software
21    without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 SUCH DAMAGE.
34
35 -----------------------------------------------------------------------------*/
36
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/module.h>
44 #include <sys/conf.h>
45 #include <sys/fcntl.h>
46 #include <sys/bio.h>
47 #include <sys/cdio.h>
48 #include <sys/disklabel.h>
49 #include <sys/bus.h>
50
51 #include <sys/lock.h>
52 #include <sys/mutex.h>
53
54 #include <machine/bus_pio.h>
55 #include <machine/bus.h>
56 #include <machine/resource.h>
57 #include <sys/rman.h>
58
59 #include <isa/isavar.h>
60
61 #include <dev/matcd/options.h>
62 #include <dev/matcd/matcd_data.h>
63
64 extern int matcd_probe(struct matcd_softc *sc);
65 extern int matcd_attach(struct matcd_softc *sc);
66
67 static int      matcd_isa_probe (device_t);
68 static int      matcd_isa_attach        (device_t);
69 static int      matcd_isa_detach        (device_t);
70
71 static int      matcd_alloc_resources   (device_t);
72 static void     matcd_release_resources (device_t);
73
74
75 static int matcd_isa_probe (device_t dev)
76 {
77         struct matcd_softc *    sc;
78         int     error;
79
80         /*Any Plug aNd Pray Support?*/
81         if (isa_get_vendorid(dev)) {
82                 return (ENXIO);
83         }
84
85         if (bus_get_resource_start(dev,SYS_RES_IOPORT,0)==0) {
86                 return (ENXIO);
87         }
88
89         sc = device_get_softc(dev);
90         sc->dev=dev;
91         sc->port_rid=0;
92         sc->port_type=SYS_RES_IOPORT;
93
94         error=matcd_alloc_resources(dev);
95         if (error==0) {
96                 error = matcd_probe(sc);
97 #if 0
98                 if (error==0) {
99                         device_set_desc(dev, "Matsushita CR-562/CR-563");
100                 }
101 #endif /*0*/
102         }
103         matcd_release_resources(dev);
104         return (error);
105 }
106
107
108 static int matcd_isa_attach (device_t dev)
109 {
110         struct matcd_softc *    sc;
111         int error;
112
113         sc=device_get_softc(dev);
114         error=0;
115
116         sc->dev=dev;
117         sc->port_rid=0;
118         sc->port_type=SYS_RES_IOPORT;
119
120         error=matcd_alloc_resources(dev);
121         if (error==0) {
122                 error=matcd_probe(sc);          /*Redundant Probe*/
123                 if (error==0) {
124                         error=matcd_attach(sc);
125                         if (error==0) {
126                                 return(error);
127                         }
128                 }
129         }
130         matcd_release_resources(dev);
131         return (error);
132 }
133
134
135 static int matcd_isa_detach (device_t dev)
136 {
137         struct matcd_softc *    sc;
138
139         sc=device_get_softc(dev);
140         destroy_dev(sc->matcd_dev_t);
141         matcd_release_resources(dev);
142         return(0);
143 }
144
145
146 static int matcd_alloc_resources (device_t dev)
147 {
148         struct matcd_softc *    sc;
149
150         sc = device_get_softc(dev);
151         if (sc->port_type) {
152                 sc->port=bus_alloc_resource(dev, sc->port_type, &sc->port_rid,
153                                             0, ~0, 1, RF_ACTIVE);
154                 if (sc->port == NULL) {
155                         device_printf(dev,
156                                       "Port resource not available.\n");
157                         return(ENOMEM);
158                 }
159                 sc->port_bst = rman_get_bustag(sc->port);
160                 sc->port_bsh = rman_get_bushandle(sc->port);
161         }
162         return(0);
163 }
164
165
166 static void matcd_release_resources (device_t dev)
167 {
168         struct matcd_softc *    sc;
169
170         sc = device_get_softc(dev);
171         if (sc->port) {
172                 bus_release_resource(dev, sc->port_type, sc->port_rid,
173                                      sc->port);
174                 sc->port_bst=0;
175                 sc->port_bsh=0;
176         }
177         return;
178 }
179
180
181 static device_method_t matcd_isa_methods[] = {
182         DEVMETHOD(device_probe,         matcd_isa_probe),
183         DEVMETHOD(device_attach,        matcd_isa_attach),
184         DEVMETHOD(device_detach,        matcd_isa_detach),
185         { 0, 0 }
186 };
187
188 static driver_t matcd_isa_driver = {
189         "matcd",
190         matcd_isa_methods,
191         sizeof(struct matcd_softc)
192 };
193
194 static devclass_t       matcd_devclass;
195
196 DRIVER_MODULE(matcd, isa, matcd_isa_driver, matcd_devclass, NULL, 0);
197
198 /*End of matcd_isa.c*/
199