ppbconf.c (183053) | ppbconf.c (184130) |
---|---|
1/*- 2 * Copyright (c) 1997, 1998, 1999 Nicolas Souchu 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1997, 1998, 1999 Nicolas Souchu 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/ppbus/ppbconf.c 183053 2008-09-15 22:26:32Z jhb $"); | 30__FBSDID("$FreeBSD: head/sys/dev/ppbus/ppbconf.c 184130 2008-10-21 18:30:10Z jhb $"); |
31#include "opt_ppb_1284.h" 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36#include <sys/module.h> 37#include <sys/bus.h> 38#include <sys/malloc.h> --- 10 unchanged lines hidden (view full) --- 49 50static MALLOC_DEFINE(M_PPBUSDEV, "ppbusdev", "Parallel Port bus device"); 51 52 53/* 54 * Device methods 55 */ 56 | 31#include "opt_ppb_1284.h" 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36#include <sys/module.h> 37#include <sys/bus.h> 38#include <sys/malloc.h> --- 10 unchanged lines hidden (view full) --- 49 50static MALLOC_DEFINE(M_PPBUSDEV, "ppbusdev", "Parallel Port bus device"); 51 52 53/* 54 * Device methods 55 */ 56 |
57static void | 57static int |
58ppbus_print_child(device_t bus, device_t dev) 59{ 60 struct ppb_device *ppbdev; | 58ppbus_print_child(device_t bus, device_t dev) 59{ 60 struct ppb_device *ppbdev; |
61 int retval; |
|
61 | 62 |
62 bus_print_child_header(bus, dev); | 63 retval = bus_print_child_header(bus, dev); |
63 64 ppbdev = (struct ppb_device *)device_get_ivars(dev); 65 66 if (ppbdev->flags != 0) | 64 65 ppbdev = (struct ppb_device *)device_get_ivars(dev); 66 67 if (ppbdev->flags != 0) |
67 printf(" flags 0x%x", ppbdev->flags); | 68 retval += printf(" flags 0x%x", ppbdev->flags); |
68 | 69 |
69 printf(" on %s%d\n", device_get_name(bus), device_get_unit(bus)); | 70 retval += bus_print_child_footer(bus, dev); |
70 | 71 |
71 return; | 72 return (retval); |
72} 73 74static int 75ppbus_probe(device_t dev) 76{ 77 device_set_desc(dev, "Parallel port bus"); 78 79 return (0); --- 25 unchanged lines hidden (view full) --- 105 device_set_ivars(child, ppbdev); 106 107 return child; 108} 109 110static int 111ppbus_read_ivar(device_t bus, device_t dev, int index, uintptr_t* val) 112{ | 73} 74 75static int 76ppbus_probe(device_t dev) 77{ 78 device_set_desc(dev, "Parallel port bus"); 79 80 return (0); --- 25 unchanged lines hidden (view full) --- 106 device_set_ivars(child, ppbdev); 107 108 return child; 109} 110 111static int 112ppbus_read_ivar(device_t bus, device_t dev, int index, uintptr_t* val) 113{ |
113 struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev); | |
114 115 switch (index) { 116 case PPBUS_IVAR_MODE: 117 /* XXX yet device mode = ppbus mode = chipset mode */ 118 *val = (u_long)ppb_get_mode(bus); | 114 115 switch (index) { 116 case PPBUS_IVAR_MODE: 117 /* XXX yet device mode = ppbus mode = chipset mode */ 118 *val = (u_long)ppb_get_mode(bus); |
119 ppbdev->mode = (u_short)*val; | |
120 break; | 119 break; |
121 case PPBUS_IVAR_AVM: 122 *val = (u_long)ppbdev->avm; 123 break; | |
124 default: 125 return (ENOENT); 126 } 127 128 return (0); 129} 130 131static int 132ppbus_write_ivar(device_t bus, device_t dev, int index, u_long val) 133{ | 120 default: 121 return (ENOENT); 122 } 123 124 return (0); 125} 126 127static int 128ppbus_write_ivar(device_t bus, device_t dev, int index, u_long val) 129{ |
134 struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev); | |
135 136 switch (index) { 137 case PPBUS_IVAR_MODE: 138 /* XXX yet device mode = ppbus mode = chipset mode */ | 130 131 switch (index) { 132 case PPBUS_IVAR_MODE: 133 /* XXX yet device mode = ppbus mode = chipset mode */ |
139 ppb_set_mode(bus,val); 140 ppbdev->mode = ppb_get_mode(bus); | 134 ppb_set_mode(bus, val); |
141 break; 142 default: 143 return (ENOENT); 144 } 145 146 return (0); 147} 148 --- 58 unchanged lines hidden (view full) --- 207 */ 208static int 209ppb_pnp_detect(device_t bus) 210{ 211 char *token, *class = 0; 212 int i, len, error; 213 int class_id = -1; 214 char str[PPB_PnP_STRING_SIZE+1]; | 135 break; 136 default: 137 return (ENOENT); 138 } 139 140 return (0); 141} 142 --- 58 unchanged lines hidden (view full) --- 201 */ 202static int 203ppb_pnp_detect(device_t bus) 204{ 205 char *token, *class = 0; 206 int i, len, error; 207 int class_id = -1; 208 char str[PPB_PnP_STRING_SIZE+1]; |
215 int unit = device_get_unit(bus); | |
216 | 209 |
217 printf("Probing for PnP devices on ppbus%d:\n", unit); | 210 device_printf(bus, "Probing for PnP devices:\n"); |
218 219 if ((error = ppb_1284_read_id(bus, PPB_NIBBLE, str, 220 PPB_PnP_STRING_SIZE, &len))) 221 goto end_detect; 222 223#ifdef DEBUG_1284 | 211 212 if ((error = ppb_1284_read_id(bus, PPB_NIBBLE, str, 213 PPB_PnP_STRING_SIZE, &len))) 214 goto end_detect; 215 216#ifdef DEBUG_1284 |
224 printf("ppb: <PnP> %d characters: ", len); | 217 device_printf(bus, "<PnP> %d characters: ", len); |
225 for (i = 0; i < len; i++) 226 printf("%c(0x%x) ", str[i], str[i]); 227 printf("\n"); 228#endif 229 230 /* replace ';' characters by '\0' */ 231 for (i = 0; i < len; i++) 232 str[i] = (str[i] == ';') ? '\0' : str[i]; 233 234 if ((token = search_token(str, len, "MFG")) != NULL || 235 (token = search_token(str, len, "MANUFACTURER")) != NULL) | 218 for (i = 0; i < len; i++) 219 printf("%c(0x%x) ", str[i], str[i]); 220 printf("\n"); 221#endif 222 223 /* replace ';' characters by '\0' */ 224 for (i = 0; i < len; i++) 225 str[i] = (str[i] == ';') ? '\0' : str[i]; 226 227 if ((token = search_token(str, len, "MFG")) != NULL || 228 (token = search_token(str, len, "MANUFACTURER")) != NULL) |
236 printf("ppbus%d: <%s", unit, | 229 device_printf(bus, "<%s", |
237 search_token(token, UNKNOWN_LENGTH, ":") + 1); 238 else | 230 search_token(token, UNKNOWN_LENGTH, ":") + 1); 231 else |
239 printf("ppbus%d: <unknown", unit); | 232 device_printf(bus, "<unknown"); |
240 241 if ((token = search_token(str, len, "MDL")) != NULL || 242 (token = search_token(str, len, "MODEL")) != NULL) 243 printf(" %s", 244 search_token(token, UNKNOWN_LENGTH, ":") + 1); 245 else 246 printf(" unknown"); 247 --- 39 unchanged lines hidden (view full) --- 287 * 288 * Scan the ppbus for IEEE1284 compliant devices 289 */ 290static int 291ppb_scan_bus(device_t bus) 292{ 293 struct ppb_data * ppb = (struct ppb_data *)device_get_softc(bus); 294 int error = 0; | 233 234 if ((token = search_token(str, len, "MDL")) != NULL || 235 (token = search_token(str, len, "MODEL")) != NULL) 236 printf(" %s", 237 search_token(token, UNKNOWN_LENGTH, ":") + 1); 238 else 239 printf(" unknown"); 240 --- 39 unchanged lines hidden (view full) --- 280 * 281 * Scan the ppbus for IEEE1284 compliant devices 282 */ 283static int 284ppb_scan_bus(device_t bus) 285{ 286 struct ppb_data * ppb = (struct ppb_data *)device_get_softc(bus); 287 int error = 0; |
295 int unit = device_get_unit(bus); | |
296 297 /* try all IEEE1284 modes, for one device only 298 * 299 * XXX We should implement the IEEE1284.3 standard to detect 300 * daisy chained devices 301 */ 302 303 error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID); 304 305 if ((ppb->state == PPB_ERROR) && (ppb->error == PPB_NOT_IEEE1284)) 306 goto end_scan; 307 308 ppb_1284_terminate(bus); 309 | 288 289 /* try all IEEE1284 modes, for one device only 290 * 291 * XXX We should implement the IEEE1284.3 standard to detect 292 * daisy chained devices 293 */ 294 295 error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID); 296 297 if ((ppb->state == PPB_ERROR) && (ppb->error == PPB_NOT_IEEE1284)) 298 goto end_scan; 299 300 ppb_1284_terminate(bus); 301 |
310 printf("ppbus%d: IEEE1284 device found ", unit); | 302 device_printf(bus, "IEEE1284 device found "); |
311 312 if (!(error = ppb_1284_negociate(bus, PPB_NIBBLE, 0))) { 313 printf("/NIBBLE"); 314 ppb_1284_terminate(bus); 315 } 316 317 if (!(error = ppb_1284_negociate(bus, PPB_PS2, 0))) { 318 printf("/PS2"); --- 71 unchanged lines hidden (view full) --- 390#ifndef DONTPROBE_1284 391 /* detect IEEE1284 compliant devices */ 392 ppb_scan_bus(dev); 393#endif /* !DONTPROBE_1284 */ 394 395 /* launch attachement of the added children */ 396 bus_generic_attach(dev); 397 | 303 304 if (!(error = ppb_1284_negociate(bus, PPB_NIBBLE, 0))) { 305 printf("/NIBBLE"); 306 ppb_1284_terminate(bus); 307 } 308 309 if (!(error = ppb_1284_negociate(bus, PPB_PS2, 0))) { 310 printf("/PS2"); --- 71 unchanged lines hidden (view full) --- 382#ifndef DONTPROBE_1284 383 /* detect IEEE1284 compliant devices */ 384 ppb_scan_bus(dev); 385#endif /* !DONTPROBE_1284 */ 386 387 /* launch attachement of the added children */ 388 bus_generic_attach(dev); 389 |
398 return 0; | 390 return (0); |
399} 400 401static int 402ppbus_detach(device_t dev) 403{ 404 device_t *children; | 391} 392 393static int 394ppbus_detach(device_t dev) 395{ 396 device_t *children; |
405 int nchildren, i; | 397 int error, nchildren, i; |
406 | 398 |
399 error = bus_generic_detach(dev); 400 if (error) 401 return (error); 402 |
|
407 /* detach & delete all children */ 408 if (!device_get_children(dev, &children, &nchildren)) { 409 for (i = 0; i < nchildren; i++) 410 if (children[i]) 411 device_delete_child(dev, children[i]); 412 free(children, M_TEMP); 413 } 414 --- 165 unchanged lines hidden --- | 403 /* detach & delete all children */ 404 if (!device_get_children(dev, &children, &nchildren)) { 405 for (i = 0; i < nchildren; i++) 406 if (children[i]) 407 device_delete_child(dev, children[i]); 408 free(children, M_TEMP); 409 } 410 --- 165 unchanged lines hidden --- |