ppi.c (184164) | ppi.c (185003) |
---|---|
1/*- 2 * Copyright (c) 1997, 1998, 1999 Nicolas Souchu, Michael Smith 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, Michael Smith 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/ppi.c 184164 2008-10-22 15:00:22Z jhb $"); | 30__FBSDID("$FreeBSD: head/sys/dev/ppbus/ppi.c 185003 2008-11-16 17:42:02Z jhb $"); |
31#include "opt_ppb_1284.h" 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <sys/conf.h> 38#include <sys/kernel.h> --- 71 unchanged lines hidden (view full) --- 110 111 return; 112} 113 114static void 115ppi_disable_intr(device_t ppidev) 116{ 117 char r; | 31#include "opt_ppb_1284.h" 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <sys/conf.h> 38#include <sys/kernel.h> --- 71 unchanged lines hidden (view full) --- 110 111 return; 112} 113 114static void 115ppi_disable_intr(device_t ppidev) 116{ 117 char r; |
118 device_t ppbus = device_get_parent(ppidev); | 118 device_t ppbus = device_get_parent(ppidev); |
119 120 r = ppb_rctr(ppbus); 121 ppb_wctr(ppbus, r & ~IRQENABLE); 122 123 return; 124} 125 126#endif /* PERIPH_1284 */ --- 65 unchanged lines hidden (view full) --- 192 * nSelectin <-> Select 17 <-> 13 193 * nInit <-> nFault 15 <-> 16 194 * 195 */ 196static void 197ppiintr(void *arg) 198{ 199 device_t ppidev = (device_t)arg; | 119 120 r = ppb_rctr(ppbus); 121 ppb_wctr(ppbus, r & ~IRQENABLE); 122 123 return; 124} 125 126#endif /* PERIPH_1284 */ --- 65 unchanged lines hidden (view full) --- 192 * nSelectin <-> Select 17 <-> 13 193 * nInit <-> nFault 15 <-> 16 194 * 195 */ 196static void 197ppiintr(void *arg) 198{ 199 device_t ppidev = (device_t)arg; |
200 device_t ppbus = device_get_parent(ppidev); | 200 device_t ppbus = device_get_parent(ppidev); |
201 struct ppi_data *ppi = DEVTOSOFTC(ppidev); 202 203 ppi_disable_intr(ppidev); 204 205 switch (ppb_1284_get_state(ppbus)) { 206 207 /* accept IEEE1284 negotiation then wakeup a waiting process to 208 * continue negotiation at process level */ --- 42 unchanged lines hidden (view full) --- 251} 252#endif /* PERIPH_1284 */ 253 254static int 255ppiopen(struct cdev *dev, int flags, int fmt, struct thread *td) 256{ 257 struct ppi_data *ppi = dev->si_drv1; 258 device_t ppidev = ppi->ppi_device; | 201 struct ppi_data *ppi = DEVTOSOFTC(ppidev); 202 203 ppi_disable_intr(ppidev); 204 205 switch (ppb_1284_get_state(ppbus)) { 206 207 /* accept IEEE1284 negotiation then wakeup a waiting process to 208 * continue negotiation at process level */ --- 42 unchanged lines hidden (view full) --- 251} 252#endif /* PERIPH_1284 */ 253 254static int 255ppiopen(struct cdev *dev, int flags, int fmt, struct thread *td) 256{ 257 struct ppi_data *ppi = dev->si_drv1; 258 device_t ppidev = ppi->ppi_device; |
259 device_t ppbus = device_get_parent(ppidev); | 259 device_t ppbus = device_get_parent(ppidev); |
260 int res; 261 262 if (!(ppi->ppi_flags & HAVE_PPBUS)) { 263 if ((res = ppb_request_bus(ppbus, ppidev, 264 (flags & O_NONBLOCK) ? PPB_DONTWAIT : 265 (PPB_WAIT | PPB_INTR)))) 266 return (res); 267 268 ppi->ppi_flags |= HAVE_PPBUS; 269 270#ifdef PERIPH_1284 271 if (ppi->intr_resource) { 272 /* register our interrupt handler */ | 260 int res; 261 262 if (!(ppi->ppi_flags & HAVE_PPBUS)) { 263 if ((res = ppb_request_bus(ppbus, ppidev, 264 (flags & O_NONBLOCK) ? PPB_DONTWAIT : 265 (PPB_WAIT | PPB_INTR)))) 266 return (res); 267 268 ppi->ppi_flags |= HAVE_PPBUS; 269 270#ifdef PERIPH_1284 271 if (ppi->intr_resource) { 272 /* register our interrupt handler */ |
273 bus_setup_intr(ppidev, ppi->intr_resource, | 273 bus_setup_intr(ppidev, ppi->intr_resource, |
274 INTR_TYPE_TTY, NULL, ppiintr, dev, 275 &ppi->intr_cookie); 276 } 277#endif /* PERIPH_1284 */ 278 } 279 ppi->ppi_count += 1; 280 281 return (0); 282} 283 284static int 285ppiclose(struct cdev *dev, int flags, int fmt, struct thread *td) 286{ 287 struct ppi_data *ppi = dev->si_drv1; 288 device_t ppidev = ppi->ppi_device; | 274 INTR_TYPE_TTY, NULL, ppiintr, dev, 275 &ppi->intr_cookie); 276 } 277#endif /* PERIPH_1284 */ 278 } 279 ppi->ppi_count += 1; 280 281 return (0); 282} 283 284static int 285ppiclose(struct cdev *dev, int flags, int fmt, struct thread *td) 286{ 287 struct ppi_data *ppi = dev->si_drv1; 288 device_t ppidev = ppi->ppi_device; |
289 device_t ppbus = device_get_parent(ppidev); | 289 device_t ppbus = device_get_parent(ppidev); |
290 291 ppi->ppi_count --; 292 if (!ppi->ppi_count) { 293 294#ifdef PERIPH_1284 295 switch (ppb_1284_get_state(ppbus)) { 296 case PPB_PERIPHERAL_IDLE: 297 ppb_peripheral_terminate(ppbus, 0); --- 25 unchanged lines hidden (view full) --- 323 * If no data is available, wait for it otherwise transfer as much as possible 324 */ 325static int 326ppiread(struct cdev *dev, struct uio *uio, int ioflag) 327{ 328#ifdef PERIPH_1284 329 struct ppi_data *ppi = dev->si_drv1; 330 device_t ppidev = ppi->ppi_device; | 290 291 ppi->ppi_count --; 292 if (!ppi->ppi_count) { 293 294#ifdef PERIPH_1284 295 switch (ppb_1284_get_state(ppbus)) { 296 case PPB_PERIPHERAL_IDLE: 297 ppb_peripheral_terminate(ppbus, 0); --- 25 unchanged lines hidden (view full) --- 323 * If no data is available, wait for it otherwise transfer as much as possible 324 */ 325static int 326ppiread(struct cdev *dev, struct uio *uio, int ioflag) 327{ 328#ifdef PERIPH_1284 329 struct ppi_data *ppi = dev->si_drv1; 330 device_t ppidev = ppi->ppi_device; |
331 device_t ppbus = device_get_parent(ppidev); | 331 device_t ppbus = device_get_parent(ppidev); |
332 int len, error = 0; 333 334 switch (ppb_1284_get_state(ppbus)) { 335 case PPB_PERIPHERAL_IDLE: 336 ppb_peripheral_terminate(ppbus, 0); 337 /* FALLTHROUGH */ 338 339 case PPB_FORWARD_IDLE: 340 /* if can't negotiate NIBBLE mode then try BYTE mode, 341 * the peripheral may be a computer 342 */ 343 if ((ppb_1284_negociate(ppbus, 344 ppi->ppi_mode = PPB_NIBBLE, 0))) { 345 346 /* XXX Wait 2 seconds to let the remote host some 347 * time to terminate its interrupt 348 */ 349 tsleep(ppi, PPBPRI, "ppiread", 2*hz); | 332 int len, error = 0; 333 334 switch (ppb_1284_get_state(ppbus)) { 335 case PPB_PERIPHERAL_IDLE: 336 ppb_peripheral_terminate(ppbus, 0); 337 /* FALLTHROUGH */ 338 339 case PPB_FORWARD_IDLE: 340 /* if can't negotiate NIBBLE mode then try BYTE mode, 341 * the peripheral may be a computer 342 */ 343 if ((ppb_1284_negociate(ppbus, 344 ppi->ppi_mode = PPB_NIBBLE, 0))) { 345 346 /* XXX Wait 2 seconds to let the remote host some 347 * time to terminate its interrupt 348 */ 349 tsleep(ppi, PPBPRI, "ppiread", 2*hz); |
350 | 350 |
351 if ((error = ppb_1284_negociate(ppbus, 352 ppi->ppi_mode = PPB_BYTE, 0))) 353 return (error); 354 } 355 break; 356 357 case PPB_REVERSE_IDLE: 358 case PPB_EPP_IDLE: --- 47 unchanged lines hidden (view full) --- 406 * Once negotiation done, transfer data 407 */ 408static int 409ppiwrite(struct cdev *dev, struct uio *uio, int ioflag) 410{ 411#ifdef PERIPH_1284 412 struct ppi_data *ppi = dev->si_drv1; 413 device_t ppidev = ppi->ppi_device; | 351 if ((error = ppb_1284_negociate(ppbus, 352 ppi->ppi_mode = PPB_BYTE, 0))) 353 return (error); 354 } 355 break; 356 357 case PPB_REVERSE_IDLE: 358 case PPB_EPP_IDLE: --- 47 unchanged lines hidden (view full) --- 406 * Once negotiation done, transfer data 407 */ 408static int 409ppiwrite(struct cdev *dev, struct uio *uio, int ioflag) 410{ 411#ifdef PERIPH_1284 412 struct ppi_data *ppi = dev->si_drv1; 413 device_t ppidev = ppi->ppi_device; |
414 device_t ppbus = device_get_parent(ppidev); | 414 device_t ppbus = device_get_parent(ppidev); |
415 int len, error = 0, sent; 416 417#if 0 418 int ret; 419 420 #define ADDRESS MS_PARAM(0, 0, MS_TYP_PTR) 421 #define LENGTH MS_PARAM(0, 1, MS_TYP_INT) 422 --- 120 unchanged lines hidden (view full) --- 543 break; 544 case PPISEPPA: /* set EPP address bits */ 545 ppb_wepp_A(ppbus, *val); 546 break; 547 default: 548 error = ENOTTY; 549 break; 550 } | 415 int len, error = 0, sent; 416 417#if 0 418 int ret; 419 420 #define ADDRESS MS_PARAM(0, 0, MS_TYP_PTR) 421 #define LENGTH MS_PARAM(0, 1, MS_TYP_INT) 422 --- 120 unchanged lines hidden (view full) --- 543 break; 544 case PPISEPPA: /* set EPP address bits */ 545 ppb_wepp_A(ppbus, *val); 546 break; 547 default: 548 error = ENOTTY; 549 break; 550 } |
551 | 551 |
552 return (error); 553} 554 555static device_method_t ppi_methods[] = { 556 /* device interface */ 557 DEVMETHOD(device_identify, ppi_identify), 558 DEVMETHOD(device_probe, ppi_probe), 559 DEVMETHOD(device_attach, ppi_attach), 560 561 { 0, 0 } 562}; 563 564static driver_t ppi_driver = { 565 "ppi", 566 ppi_methods, 567 sizeof(struct ppi_data), 568}; 569DRIVER_MODULE(ppi, ppbus, ppi_driver, ppi_devclass, 0, 0); 570MODULE_DEPEND(ppi, ppbus, 1, 1, 1); | 552 return (error); 553} 554 555static device_method_t ppi_methods[] = { 556 /* device interface */ 557 DEVMETHOD(device_identify, ppi_identify), 558 DEVMETHOD(device_probe, ppi_probe), 559 DEVMETHOD(device_attach, ppi_attach), 560 561 { 0, 0 } 562}; 563 564static driver_t ppi_driver = { 565 "ppi", 566 ppi_methods, 567 sizeof(struct ppi_data), 568}; 569DRIVER_MODULE(ppi, ppbus, ppi_driver, ppi_devclass, 0, 0); 570MODULE_DEPEND(ppi, ppbus, 1, 1, 1); |