ppbus_conf.c revision 1.4.4.2 1 1.4.4.2 skrll /* $NetBSD: ppbus_conf.c,v 1.4.4.2 2004/08/03 10:50:27 skrll Exp $ */
2 1.4.4.2 skrll
3 1.4.4.2 skrll /*-
4 1.4.4.2 skrll * Copyright (c) 1997, 1998, 1999 Nicolas Souchu
5 1.4.4.2 skrll * All rights reserved.
6 1.4.4.2 skrll *
7 1.4.4.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.4.4.2 skrll * modification, are permitted provided that the following conditions
9 1.4.4.2 skrll * are met:
10 1.4.4.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.4.4.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.4.4.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.4.4.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.4.4.2 skrll * documentation and/or other materials provided with the distribution.
15 1.4.4.2 skrll *
16 1.4.4.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.4.4.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.4.4.2 skrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.4.4.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.4.4.2 skrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.4.4.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.4.4.2 skrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.4.4.2 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.4.4.2 skrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.4.4.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.4.4.2 skrll * SUCH DAMAGE.
27 1.4.4.2 skrll *
28 1.4.4.2 skrll * FreeBSD: src/sys/dev/ppbus/ppbconf.c,v 1.17.2.1 2000/05/24 00:20:57 n_hibma Exp
29 1.4.4.2 skrll *
30 1.4.4.2 skrll */
31 1.4.4.2 skrll
32 1.4.4.2 skrll #include <sys/cdefs.h>
33 1.4.4.2 skrll __KERNEL_RCSID(0, "$NetBSD: ppbus_conf.c,v 1.4.4.2 2004/08/03 10:50:27 skrll Exp $");
34 1.4.4.2 skrll
35 1.4.4.2 skrll #include "opt_ppbus.h"
36 1.4.4.2 skrll #include "opt_ppbus_1284.h"
37 1.4.4.2 skrll
38 1.4.4.2 skrll #include <sys/param.h>
39 1.4.4.2 skrll #include <sys/systm.h>
40 1.4.4.2 skrll #include <sys/kernel.h>
41 1.4.4.2 skrll #include <sys/device.h>
42 1.4.4.2 skrll #include <sys/proc.h>
43 1.4.4.2 skrll
44 1.4.4.2 skrll #include <dev/ppbus/ppbus_1284.h>
45 1.4.4.2 skrll #include <dev/ppbus/ppbus_base.h>
46 1.4.4.2 skrll #include <dev/ppbus/ppbus_conf.h>
47 1.4.4.2 skrll #include <dev/ppbus/ppbus_device.h>
48 1.4.4.2 skrll #include <dev/ppbus/ppbus_var.h>
49 1.4.4.2 skrll
50 1.4.4.2 skrll /* Probe, attach, and detach functions for ppbus. */
51 1.4.4.2 skrll static int ppbus_probe __P((struct device *, struct cfdata *, void *));
52 1.4.4.2 skrll static void ppbus_attach __P((struct device *, struct device *, void *));
53 1.4.4.2 skrll static int ppbus_detach __P((struct device *, int));
54 1.4.4.2 skrll
55 1.4.4.2 skrll /* Utility function prototypes */
56 1.4.4.2 skrll static int ppbus_print_child(void *, const char *);
57 1.4.4.2 skrll static int ppbus_search_children(struct device *, struct cfdata *, void *);
58 1.4.4.2 skrll
59 1.4.4.2 skrll
60 1.4.4.2 skrll CFATTACH_DECL(ppbus, sizeof(struct ppbus_softc), ppbus_probe, ppbus_attach,
61 1.4.4.2 skrll ppbus_detach, NULL);
62 1.4.4.2 skrll
63 1.4.4.2 skrll /* Probe function for ppbus. */
64 1.4.4.2 skrll static int
65 1.4.4.2 skrll ppbus_probe(struct device * parent, struct cfdata * cf, void * aux)
66 1.4.4.2 skrll {
67 1.4.4.2 skrll struct parport_adapter * sc_link = aux;
68 1.4.4.2 skrll
69 1.4.4.2 skrll /* Check adapter for consistency */
70 1.4.4.2 skrll if(
71 1.4.4.2 skrll /* Required methods for all parports */
72 1.4.4.2 skrll sc_link->parport_io == NULL ||
73 1.4.4.2 skrll sc_link->parport_exec_microseq == NULL ||
74 1.4.4.2 skrll sc_link->parport_setmode == NULL ||
75 1.4.4.2 skrll sc_link->parport_getmode == NULL ||
76 1.4.4.2 skrll sc_link->parport_read == NULL ||
77 1.4.4.2 skrll sc_link->parport_write == NULL ||
78 1.4.4.2 skrll sc_link->parport_read_ivar == NULL ||
79 1.4.4.2 skrll sc_link->parport_write_ivar == NULL ||
80 1.4.4.2 skrll /* Methods which conditional exist based on capabilities */
81 1.4.4.2 skrll ((sc_link->capabilities & PPBUS_HAS_EPP) &&
82 1.4.4.2 skrll (sc_link->parport_reset_epp_timeout == NULL)) ||
83 1.4.4.2 skrll ((sc_link->capabilities & PPBUS_HAS_ECP) &&
84 1.4.4.2 skrll (sc_link->parport_ecp_sync == NULL)) ||
85 1.4.4.2 skrll ((sc_link->capabilities & PPBUS_HAS_DMA) &&
86 1.4.4.2 skrll (sc_link->parport_dma_malloc == NULL ||
87 1.4.4.2 skrll sc_link->parport_dma_free == NULL)) ||
88 1.4.4.2 skrll ((sc_link->capabilities & PPBUS_HAS_INTR) &&
89 1.4.4.2 skrll (sc_link->parport_add_handler == NULL ||
90 1.4.4.2 skrll sc_link->parport_remove_handler == NULL))
91 1.4.4.2 skrll ) {
92 1.4.4.2 skrll
93 1.4.4.2 skrll #ifdef PPBUS_DEBUG
94 1.4.4.2 skrll printf("%s(%s): parport_adaptor is incomplete. Child device "
95 1.4.4.2 skrll "probe failed.\n", __func__, parent->dv_xname);
96 1.4.4.2 skrll #endif
97 1.4.4.2 skrll return 0;
98 1.4.4.2 skrll }
99 1.4.4.2 skrll else {
100 1.4.4.2 skrll return 1;
101 1.4.4.2 skrll }
102 1.4.4.2 skrll }
103 1.4.4.2 skrll
104 1.4.4.2 skrll /* Attach function for ppbus. */
105 1.4.4.2 skrll static void
106 1.4.4.2 skrll ppbus_attach(struct device * parent, struct device * self, void * aux)
107 1.4.4.2 skrll {
108 1.4.4.2 skrll struct ppbus_softc * ppbus = (struct ppbus_softc *) self;
109 1.4.4.2 skrll struct parport_adapter * sc_link = aux;
110 1.4.4.2 skrll struct ppbus_attach_args args;
111 1.4.4.2 skrll
112 1.4.4.2 skrll printf("\n");
113 1.4.4.2 skrll
114 1.4.4.2 skrll /* Initialize config data from adapter (bus + device methods) */
115 1.4.4.2 skrll args.capabilities = ppbus->sc_capabilities = sc_link->capabilities;
116 1.4.4.2 skrll ppbus->ppbus_io = sc_link->parport_io;
117 1.4.4.2 skrll ppbus->ppbus_exec_microseq = sc_link->parport_exec_microseq;
118 1.4.4.2 skrll ppbus->ppbus_reset_epp_timeout = sc_link->
119 1.4.4.2 skrll parport_reset_epp_timeout;
120 1.4.4.2 skrll ppbus->ppbus_setmode = sc_link->parport_setmode;
121 1.4.4.2 skrll ppbus->ppbus_getmode = sc_link->parport_getmode;
122 1.4.4.2 skrll ppbus->ppbus_ecp_sync = sc_link->parport_ecp_sync;
123 1.4.4.2 skrll ppbus->ppbus_read = sc_link->parport_read;
124 1.4.4.2 skrll ppbus->ppbus_write = sc_link->parport_write;
125 1.4.4.2 skrll ppbus->ppbus_read_ivar = sc_link->parport_read_ivar;
126 1.4.4.2 skrll ppbus->ppbus_write_ivar = sc_link->parport_write_ivar;
127 1.4.4.2 skrll ppbus->ppbus_dma_malloc = sc_link->parport_dma_malloc;
128 1.4.4.2 skrll ppbus->ppbus_dma_free = sc_link->parport_dma_free;
129 1.4.4.2 skrll ppbus->ppbus_add_handler = sc_link->parport_add_handler;
130 1.4.4.2 skrll ppbus->ppbus_remove_handler = sc_link->parport_remove_handler;
131 1.4.4.2 skrll
132 1.4.4.2 skrll /* Initially there is no device owning the bus */
133 1.4.4.2 skrll ppbus->ppbus_owner = NULL;
134 1.4.4.2 skrll
135 1.4.4.2 skrll /* Initialize locking structures */
136 1.4.4.2 skrll lockinit(&(ppbus->sc_lock), PPBUSPRI | PCATCH, "ppbuslock", 0,
137 1.4.4.2 skrll LK_NOWAIT);
138 1.4.4.2 skrll
139 1.4.4.2 skrll /* Set up bus mode and ieee state */
140 1.4.4.2 skrll ppbus->sc_mode = ppbus->ppbus_getmode(self->dv_parent);
141 1.4.4.2 skrll ppbus->sc_use_ieee = 1;
142 1.4.4.2 skrll ppbus->sc_1284_state = PPBUS_FORWARD_IDLE;
143 1.4.4.2 skrll ppbus->sc_1284_error = PPBUS_NO_ERROR;
144 1.4.4.2 skrll
145 1.4.4.2 skrll /* Record device's sucessful attachment */
146 1.4.4.2 skrll ppbus->sc_dev_ok = PPBUS_OK;
147 1.4.4.2 skrll
148 1.4.4.2 skrll #ifndef DONTPROBE_1284
149 1.4.4.2 skrll /* detect IEEE1284 compliant devices */
150 1.4.4.2 skrll if(ppbus_scan_bus(self)) {
151 1.4.4.2 skrll printf("%s: No IEEE1284 device found.\n", self->dv_xname);
152 1.4.4.2 skrll }
153 1.4.4.2 skrll else {
154 1.4.4.2 skrll printf("%s: IEEE1284 device found.\n", self->dv_xname);
155 1.4.4.2 skrll /*
156 1.4.4.2 skrll * Detect device ID (interrupts must be disabled because we
157 1.4.4.2 skrll * cannot do a ltsleep() to wait for it - no context)
158 1.4.4.2 skrll */
159 1.4.4.2 skrll if(args.capabilities & PPBUS_HAS_INTR) {
160 1.4.4.2 skrll int val = 0;
161 1.4.4.2 skrll if(ppbus_write_ivar(self, PPBUS_IVAR_INTR, &val) != 0) {
162 1.4.4.2 skrll printf(" <problem initializing interrupt "
163 1.4.4.2 skrll "usage>");
164 1.4.4.2 skrll }
165 1.4.4.2 skrll }
166 1.4.4.2 skrll ppbus_pnp_detect(self);
167 1.4.4.2 skrll }
168 1.4.4.2 skrll #endif /* !DONTPROBE_1284 */
169 1.4.4.2 skrll
170 1.4.4.2 skrll /* Configure child devices */
171 1.4.4.2 skrll SLIST_INIT(&(ppbus->sc_childlist_head));
172 1.4.4.2 skrll config_search(ppbus_search_children, self, &args);
173 1.4.4.2 skrll
174 1.4.4.2 skrll return;
175 1.4.4.2 skrll }
176 1.4.4.2 skrll
177 1.4.4.2 skrll /* Detach function for ppbus. */
178 1.4.4.2 skrll static int
179 1.4.4.2 skrll ppbus_detach(struct device * self, int flag)
180 1.4.4.2 skrll {
181 1.4.4.2 skrll struct ppbus_softc * ppbus = (struct ppbus_softc *) self;
182 1.4.4.2 skrll struct ppbus_device_softc * child;
183 1.4.4.2 skrll
184 1.4.4.2 skrll if(ppbus->sc_dev_ok != PPBUS_OK) {
185 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
186 1.4.4.2 skrll printf("%s: detach called on unattached device.\n",
187 1.4.4.2 skrll ppbus->sc_dev.dv_xname);
188 1.4.4.2 skrll if(!(flag & DETACH_FORCE))
189 1.4.4.2 skrll return 0;
190 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
191 1.4.4.2 skrll printf("%s: continuing detach (DETACH_FORCE).\n",
192 1.4.4.2 skrll ppbus->sc_dev.dv_xname);
193 1.4.4.2 skrll }
194 1.4.4.2 skrll
195 1.4.4.2 skrll if(lockmgr(&(ppbus->sc_lock), LK_DRAIN, NULL)) {
196 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
197 1.4.4.2 skrll printf("%s: error while waiting for lock activity to "
198 1.4.4.2 skrll "end.\n", ppbus->sc_dev.dv_xname);
199 1.4.4.2 skrll if(!(flag & DETACH_FORCE))
200 1.4.4.2 skrll return 0;
201 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
202 1.4.4.2 skrll printf("%s: continuing detach (DETACH_FORCE).\n",
203 1.4.4.2 skrll ppbus->sc_dev.dv_xname);
204 1.4.4.2 skrll }
205 1.4.4.2 skrll
206 1.4.4.2 skrll /* Detach children devices */
207 1.4.4.2 skrll while(!SLIST_EMPTY(&(ppbus->sc_childlist_head))) {
208 1.4.4.2 skrll child = SLIST_FIRST(&(ppbus->sc_childlist_head));
209 1.4.4.2 skrll config_deactivate((struct device *)child);
210 1.4.4.2 skrll if(config_detach((struct device *)child, flag)) {
211 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
212 1.4.4.2 skrll printf("%s: error detaching %s.",
213 1.4.4.2 skrll ppbus->sc_dev.dv_xname,
214 1.4.4.2 skrll child->sc_dev.dv_xname);
215 1.4.4.2 skrll if(!(flag & DETACH_FORCE))
216 1.4.4.2 skrll return 0;
217 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
218 1.4.4.2 skrll printf("%s: continuing (DETACH_FORCE).\n",
219 1.4.4.2 skrll ppbus->sc_dev.dv_xname);
220 1.4.4.2 skrll }
221 1.4.4.2 skrll SLIST_REMOVE_HEAD(&(ppbus->sc_childlist_head), entries);
222 1.4.4.2 skrll }
223 1.4.4.2 skrll
224 1.4.4.2 skrll if(!(flag & DETACH_QUIET))
225 1.4.4.2 skrll printf("%s: detached.\n", ppbus->sc_dev.dv_xname);
226 1.4.4.2 skrll
227 1.4.4.2 skrll return 1;
228 1.4.4.2 skrll }
229 1.4.4.2 skrll
230 1.4.4.2 skrll
231 1.4.4.2 skrll /* Utility functions */
232 1.4.4.2 skrll
233 1.4.4.2 skrll /* Used by config_found_sm() to print out result of child probe */
234 1.4.4.2 skrll static int
235 1.4.4.2 skrll ppbus_print_child(void * aux, const char * name)
236 1.4.4.2 skrll {
237 1.4.4.2 skrll if(name != NULL) {
238 1.4.4.2 skrll printf("%s: child devices", name);
239 1.4.4.2 skrll return UNCONF;
240 1.4.4.2 skrll }
241 1.4.4.2 skrll else {
242 1.4.4.2 skrll return QUIET;
243 1.4.4.2 skrll }
244 1.4.4.2 skrll }
245 1.4.4.2 skrll
246 1.4.4.2 skrll /* Search for children device and add to list */
247 1.4.4.2 skrll static int
248 1.4.4.2 skrll ppbus_search_children(struct device * parent, struct cfdata * cf, void * aux)
249 1.4.4.2 skrll {
250 1.4.4.2 skrll struct ppbus_softc * ppbus = (struct ppbus_softc *) parent;
251 1.4.4.2 skrll struct ppbus_device_softc * child;
252 1.4.4.2 skrll int rval = 0;
253 1.4.4.2 skrll
254 1.4.4.2 skrll if(config_match(parent, cf, aux) > 0) {
255 1.4.4.2 skrll child = (struct ppbus_device_softc *) config_attach(parent,
256 1.4.4.2 skrll cf, aux, ppbus_print_child);
257 1.4.4.2 skrll if(child) {
258 1.4.4.2 skrll SLIST_INSERT_HEAD(&(ppbus->sc_childlist_head), child,
259 1.4.4.2 skrll entries);
260 1.4.4.2 skrll rval = 1;
261 1.4.4.2 skrll }
262 1.4.4.2 skrll }
263 1.4.4.2 skrll
264 1.4.4.2 skrll return rval;
265 1.4.4.2 skrll }
266 1.4.4.2 skrll
267