X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fmedia%2Fvideo%2Fcpia_pp.c;h=b12cec94f4cc917af762dd93d459587b80804240;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=74cff626e044375a467000ae57a64846af4d7e58;hpb=76828883507a47dae78837ab5dec5a5b4513c667;p=linux-2.6.git diff --git a/drivers/media/video/cpia_pp.c b/drivers/media/video/cpia_pp.c index 74cff626e..b12cec94f 100644 --- a/drivers/media/video/cpia_pp.c +++ b/drivers/media/video/cpia_pp.c @@ -23,9 +23,8 @@ */ /* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */ -/* #define _CPIA_DEBUG_ 1 */ +/* #define _CPIA_DEBUG_ 1 */ -#include #include #include @@ -45,7 +44,7 @@ static int cpia_pp_open(void *privdata); static int cpia_pp_registerCallback(void *privdata, void (*cb) (void *cbdata), - void *cbdata); + void *cbdata); static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data); static int cpia_pp_streamStart(void *privdata); static int cpia_pp_streamStop(void *privdata); @@ -83,6 +82,8 @@ struct pp_cam_entry { struct pardevice *pdev; struct parport *port; struct work_struct cb_task; + void (*cb_func)(void *cbdata); + void *cb_data; int open_count; wait_queue_head_t wq_stream; /* image state flags */ @@ -93,7 +94,7 @@ struct pp_cam_entry { int stream_irq; }; -static struct cpia_camera_ops cpia_pp_ops = +static struct cpia_camera_ops cpia_pp_ops = { cpia_pp_open, cpia_pp_registerCallback, @@ -123,7 +124,7 @@ static void cpia_parport_disable_irq( struct parport *port ) { } /* Special CPiA PPC modes: These are invoked by using the 1284 Extensibility - * Link Flag during negotiation */ + * Link Flag during negotiation */ #define UPLOAD_FLAG 0x08 #define NIBBLE_TRANSFER 0x01 #define ECP_TRANSFER 0x03 @@ -131,6 +132,20 @@ static void cpia_parport_disable_irq( struct parport *port ) { #define PARPORT_CHUNK_SIZE PAGE_SIZE +static void cpia_pp_run_callback(struct work_struct *work) +{ + void (*cb_func)(void *cbdata); + void *cb_data; + struct pp_cam_entry *cam; + + cam = container_of(work, struct pp_cam_entry, cb_task); + cb_func = cam->cb_func; + cb_data = cam->cb_data; + work_release(work); + + cb_func(cb_data); +} + /**************************************************************************** * * CPiA-specific low-level parport functions for nibble uploads @@ -139,17 +154,17 @@ static void cpia_parport_disable_irq( struct parport *port ) { /* CPiA nonstandard "Nibble" mode (no nDataAvail signal after each byte). */ /* The standard kernel parport_ieee1284_read_nibble() fails with the CPiA... */ -static size_t cpia_read_nibble (struct parport *port, - void *buffer, size_t len, +static size_t cpia_read_nibble (struct parport *port, + void *buffer, size_t len, int flags) { - /* adapted verbatim, with one change, from + /* adapted verbatim, with one change, from parport_ieee1284_read_nibble() in drivers/parport/ieee1284-ops.c */ unsigned char *buf = buffer; int i; unsigned char byte = 0; - + len *= 2; /* in nibbles */ for (i=0; i < len; i++) { unsigned char nibble; @@ -158,12 +173,12 @@ static size_t cpia_read_nibble (struct parport *port, * after every second nibble to signal that more * data is available. (the total number of Bytes that * should be sent is known; if too few are received, an error - * will be recorded after a timeout). + * will be recorded after a timeout). * This is incompatible with parport_ieee1284_read_nibble(), * which expects to find nFault LO after every second nibble. */ - /* Solution: modify cpia_read_nibble to only check for + /* Solution: modify cpia_read_nibble to only check for * nDataAvail before the first nibble is sent. */ @@ -216,7 +231,7 @@ static size_t cpia_read_nibble (struct parport *port, /* Second nibble */ byte |= nibble << 4; *buf++ = byte; - } else + } else byte = nibble; } @@ -238,18 +253,18 @@ static size_t cpia_read_nibble (struct parport *port, } /* CPiA nonstandard "Nibble Stream" mode (2 nibbles per cycle, instead of 1) - * (See CPiA Data sheet p. 31) - * - * "Nibble Stream" mode used by CPiA for uploads to non-ECP ports is a - * nonstandard variant of nibble mode which allows the same (mediocre) - * data flow of 8 bits per cycle as software-enabled ECP by TRISTATE-capable + * (See CPiA Data sheet p. 31) + * + * "Nibble Stream" mode used by CPiA for uploads to non-ECP ports is a + * nonstandard variant of nibble mode which allows the same (mediocre) + * data flow of 8 bits per cycle as software-enabled ECP by TRISTATE-capable * parallel ports, but works also for non-TRISTATE-capable ports. * (Standard nibble mode only send 4 bits per cycle) * */ -static size_t cpia_read_nibble_stream(struct parport *port, - void *buffer, size_t len, +static size_t cpia_read_nibble_stream(struct parport *port, + void *buffer, size_t len, int flags) { int i; @@ -260,7 +275,7 @@ static size_t cpia_read_nibble_stream(struct parport *port, unsigned char nibble[2], byte = 0; int j; - /* Image Data is complete when 4 consecutive EOI bytes (0xff) are seen */ + /* Image Data is complete when 4 consecutive EOI bytes (0xff) are seen */ if (endseen > 3 ) break; @@ -268,7 +283,7 @@ static size_t cpia_read_nibble_stream(struct parport *port, parport_frob_control (port, PARPORT_CONTROL_AUTOFD, PARPORT_CONTROL_AUTOFD); - + /* Event 9: nAck goes low. */ port->ieee1284.phase = IEEE1284_PH_REV_DATA; if (parport_wait_peripheral (port, @@ -282,7 +297,7 @@ static size_t cpia_read_nibble_stream(struct parport *port, /* Read lower nibble */ nibble[0] = parport_read_status (port) >>3; - + /* Event 10: Set nAutoFd high. */ parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); @@ -295,10 +310,10 @@ static size_t cpia_read_nibble_stream(struct parport *port, port->name); break; } - + /* Read upper nibble */ nibble[1] = parport_read_status (port) >>3; - + /* reassemble the byte */ for (j = 0; j < 2 ; j++ ) { nibble[j] &= ~8; @@ -335,8 +350,8 @@ static void EndTransferMode(struct pp_cam_entry *cam) static int ForwardSetup(struct pp_cam_entry *cam) { int retry; - - /* The CPiA uses ECP protocol for Downloads from the Host to the camera. + + /* The CPiA uses ECP protocol for Downloads from the Host to the camera. * This will be software-emulated if ECP hardware is not present */ @@ -375,9 +390,9 @@ static int ReverseSetup(struct pp_cam_entry *cam, int extensibility) upload_mode = mode; if(extensibility) mode = UPLOAD_FLAG|transfer_mode|IEEE1284_EXT_LINK; - /* the usual camera maximum response time is 10ms, but after + /* the usual camera maximum response time is 10ms, but after * receiving some commands, it needs up to 40ms. */ - + for(retry = 0; retry < 4; ++retry) { if(!parport_negotiate(cam->port, mode)) { break; @@ -439,10 +454,10 @@ static int ReadPacket(struct pp_cam_entry *cam, u8 *packet, size_t size) /* support for CPiA variant nibble reads */ if(cam->port->ieee1284.mode == IEEE1284_MODE_NIBBLE) { - if(cpia_read_nibble(cam->port, packet, size, 0) != size) - retval = -EIO; + if(cpia_read_nibble(cam->port, packet, size, 0) != size) + retval = -EIO; } else { - if(parport_read(cam->port, packet, size) != size) + if(parport_read(cam->port, packet, size) != size) retval = -EIO; } EndTransferMode(cam); @@ -542,18 +557,18 @@ static int cpia_pp_streamRead(void *privdata, u8 *buffer, int noblock) block_size = PARPORT_CHUNK_SIZE; while( !cam->image_complete ) { cond_resched(); - + new_bytes = cpia_pp_read(cam->port, buffer, block_size ); if( new_bytes <= 0 ) { break; } i=-1; while(++iopen_count == 0) { if (parport_claim(cam->pdev)) { DBG("failed to claim the port\n"); @@ -645,12 +660,12 @@ static int cpia_pp_open(void *privdata) parport_write_control(cam->port, PARPORT_CONTROL_SELECT); udelay(50); parport_write_control(cam->port, - PARPORT_CONTROL_SELECT - | PARPORT_CONTROL_INIT); + PARPORT_CONTROL_SELECT + | PARPORT_CONTROL_INIT); } - + ++cam->open_count; - + return 0; } @@ -663,9 +678,11 @@ static int cpia_pp_registerCallback(void *privdata, void (*cb)(void *cbdata), vo { struct pp_cam_entry *cam = privdata; int retval = 0; - + if(cam->port->irq != PARPORT_IRQ_NONE) { - INIT_WORK(&cam->cb_task, cb, cbdata); + cam->cb_func = cb; + cam->cb_data = cbdata; + INIT_WORK_NAR(&cam->cb_task, cpia_pp_run_callback); } else { retval = -1; } @@ -707,9 +724,9 @@ static int cpia_pp_register(struct parport *port) LOG("failed to allocate camera structure\n"); return -ENOMEM; } - + pdev = parport_register_device(port, "cpia_pp", NULL, NULL, - NULL, 0, cam); + NULL, 0, cam); if (!pdev) { LOG("failed to parport_register_device\n"); @@ -753,19 +770,19 @@ static void cpia_pp_detach (struct parport *port) } cpia = NULL; } - spin_unlock( &cam_list_lock_pp ); + spin_unlock( &cam_list_lock_pp ); if (!cpia) { DBG("cpia_pp_detach failed to find cam_data in cam_list\n"); return; } - - cam = (struct pp_cam_entry *) cpia->lowlevel_data; + + cam = (struct pp_cam_entry *) cpia->lowlevel_data; cpia_unregister_camera(cpia); - if(cam->open_count > 0) + if(cam->open_count > 0) cpia_pp_close(cam); parport_unregister_device(cam->pdev); - cpia->lowlevel_data = NULL; + cpia->lowlevel_data = NULL; kfree(cam); } @@ -803,16 +820,16 @@ static struct parport_driver cpia_pp_driver = { .detach = cpia_pp_detach, }; -int cpia_pp_init(void) +static int cpia_pp_init(void) { - printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT, + printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT, CPIA_PP_MAJ_VER,CPIA_PP_MIN_VER,CPIA_PP_PATCH_VER); if(parport_nr[0] == PPCPIA_PARPORT_OFF) { printk(" disabled\n"); return 0; } - + spin_lock_init( &cam_list_lock_pp ); if (parport_register_driver (&cpia_pp_driver)) { @@ -860,6 +877,8 @@ void cleanup_module(void) static int __init cpia_pp_setup(char *str) { + int err; + if (!strncmp(str, "parport", 7)) { int n = simple_strtoul(str + 7, NULL, 10); if (parport_ptr < PARPORT_MAX) { @@ -873,7 +892,11 @@ static int __init cpia_pp_setup(char *str) parport_nr[parport_ptr++] = PPCPIA_PARPORT_NONE; } - return 0; + err=cpia_pp_init(); + if (err) + return err; + + return 1; } __setup("cpia_pp=", cpia_pp_setup);