Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * copyright (C) 1999/2000 by Henning Zabel <henning@uni-paderborn.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *	USB-Kernel Driver for the Mustek MDC800 Digital Camera
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *	(c) 1999/2000 Henning Zabel <henning@uni-paderborn.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * The driver brings the USB functions of the MDC800 to Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * To use the Camera you must support the USB Protocol of the camera
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * to the Kernel Node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * The Driver uses a misc device Node. Create it with :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * mknod /dev/mustek c 180 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * The driver supports only one camera.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * Fix: mdc800 used sleep_on and slept with io_lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * Converted sleep_on to waitqueues with schedule_timeout and made io_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * a semaphore from a spinlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * by Oliver Neukum <oliver@neukum.name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * (02/12/2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * Identify version on module load.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * (08/04/2001) gb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * version 0.7.5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * Fixed potential SMP races with Spinlocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * Thanks to Oliver Neukum <oliver@neukum.name> who 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * noticed the race conditions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * (30/10/2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * Fixed: Setting urb->dev before submitting urb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * by Greg KH <greg@kroah.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * (13/10/2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  * version 0.7.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  * bugfix : The mdc800->state field gets set to READY after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * the disconnect function sets it to NOT_CONNECTED. This makes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * driver running like the camera is connected and causes some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * hang ups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  * version 0.7.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  * MOD_INC and MOD_DEC are changed in usb_probe to prevent load/unload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  * problems when compiled as Module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * (04/04/2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  * The mdc800 driver gets assigned the USB Minor 32-47. The Registration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  * was updated to use these values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  * (26/03/2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  * The Init und Exit Module Function are updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  * (01/03/2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * version 0.7.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * Rewrite of the driver : The driver now uses URB's. The old stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  * has been removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  * version 0.6.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  * Rewrite of this driver: The Emulation of the rs232 protocoll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  * has been removed from the driver. A special executeCommand function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  * for this driver is included to gphoto.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  * The driver supports two kind of communication to bulk endpoints.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  * Either with the dev->bus->ops->bulk... or with callback function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * (09/11/1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * version 0.5.0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * first Version that gets a version number. Most of the needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  * functions work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  * (20/10/1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * Version Information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define DRIVER_VERSION "v0.7.5 (30/10/2000)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define DRIVER_AUTHOR "Henning Zabel <henning@uni-paderborn.de>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define DRIVER_DESC "USB Driver for Mustek MDC800 Digital Camera"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) /* Vendor and Product Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define MDC800_VENDOR_ID 	0x055f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) #define MDC800_PRODUCT_ID	0xa800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) /* Timeouts (msec) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define TO_DOWNLOAD_GET_READY		1500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define TO_DOWNLOAD_GET_BUSY		1500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #define TO_WRITE_GET_READY		1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define TO_DEFAULT_COMMAND		5000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #define TO_READ_FROM_IRQ 		TO_DEFAULT_COMMAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #define TO_GET_READY			TO_DEFAULT_COMMAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) /* Minor Number of the device (create with mknod /dev/mustek c 180 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #define MDC800_DEVICE_MINOR_BASE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	Data and structs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) typedef enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	NOT_CONNECTED, READY, WORKING, DOWNLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) } mdc800_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) /* Data for the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) struct mdc800_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	struct usb_device *	dev;			// Device Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	mdc800_state 		state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	unsigned int		endpoint [4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	struct urb *		irq_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	wait_queue_head_t	irq_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	int			irq_woken;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	char*			irq_urb_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	int			camera_busy;          // is camera busy ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	int 			camera_request_ready; // Status to synchronize with irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	char 			camera_response [8];  // last Bytes send after busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	struct urb *   		write_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	char*			write_urb_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	wait_queue_head_t	write_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	int			written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	struct urb *   		download_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	char*			download_urb_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	wait_queue_head_t	download_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	int			downloaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	int			download_left;		// Bytes left to download ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	/* Device Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	char			out [64];	// Answer Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	int 			out_ptr;	// Index to the first not readen byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	int			out_count;	// Bytes in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	int			open;		// Camera device open ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	struct mutex		io_lock;	// IO -lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	char 			in [8];		// Command Input Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	int  			in_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	int			pic_index;	// Cache for the Imagesize (-1 for nothing cached )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	int			pic_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	int			minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) /* Specification of the Endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) static struct usb_endpoint_descriptor mdc800_ed [4] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	{ 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		.bLength = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		.bDescriptorType =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		.bEndpointAddress =	0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		.bmAttributes = 	0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		.wMaxPacketSize =	cpu_to_le16(8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		.bInterval = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		.bRefresh = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		.bSynchAddress = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		.bLength = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		.bDescriptorType = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		.bEndpointAddress = 	0x82,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		.bmAttributes = 	0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		.wMaxPacketSize = 	cpu_to_le16(8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		.bInterval = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		.bRefresh = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		.bSynchAddress = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		.bLength = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		.bDescriptorType = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		.bEndpointAddress = 	0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		.bmAttributes = 	0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		.wMaxPacketSize = 	cpu_to_le16(64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		.bInterval = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		.bRefresh = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		.bSynchAddress = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		.bLength = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		.bDescriptorType = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		.bEndpointAddress = 	0x84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		.bmAttributes = 	0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		.wMaxPacketSize = 	cpu_to_le16(64),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		.bInterval = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		.bRefresh = 		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		.bSynchAddress = 	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) /* The Variable used by the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) static struct mdc800_data* mdc800;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	The USB Part of the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static int mdc800_endpoint_equals (struct usb_endpoint_descriptor *a,struct usb_endpoint_descriptor *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	return (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		   ( a->bEndpointAddress == b->bEndpointAddress )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		&& ( a->bmAttributes     == b->bmAttributes     )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		&& ( a->wMaxPacketSize   == b->wMaxPacketSize   )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  * Checks whether the camera responds busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) static int mdc800_isBusy (char* ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	int i=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	while (i<8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		if (ch [i] != (char)0x99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)  * Checks whether the Camera is ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) static int mdc800_isReady (char *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	int i=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	while (i<8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		if (ch [i] != (char)0xbb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)  * USB IRQ Handler for InputLine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) static void mdc800_usb_irq (struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	int data_received=0, wake_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	unsigned char* b=urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	struct mdc800_data* mdc800=urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	struct device *dev = &mdc800->dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	if (status >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		if (mdc800_isBusy (b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 			if (!mdc800->camera_busy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 				mdc800->camera_busy=1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 				dev_dbg(dev, "gets busy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			if (mdc800->camera_busy && mdc800_isReady (b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 				mdc800->camera_busy=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 				dev_dbg(dev, "gets ready\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		if (!(mdc800_isBusy (b) || mdc800_isReady (b)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			/* Store Data in camera_answer field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			dev_dbg(dev, "%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			memcpy (mdc800->camera_response,b,8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			data_received=1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	wake_up= ( mdc800->camera_request_ready > 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		&&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			((mdc800->camera_request_ready == 1) && (!mdc800->camera_busy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			((mdc800->camera_request_ready == 2) && data_received)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			((mdc800->camera_request_ready == 3) && (mdc800->camera_busy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 			(status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	if (wake_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		mdc800->camera_request_ready=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		mdc800->irq_woken=1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		wake_up (&mdc800->irq_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325)  * Waits a while until the irq responds that camera is ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327)  *  mode : 0: Wait for camera gets ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328)  *         1: Wait for receiving data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329)  *         2: Wait for camera gets busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331)  * msec: Time to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) static int mdc800_usb_waitForIRQ (int mode, int msec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	mdc800->camera_request_ready=1+mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	wait_event_timeout(mdc800->irq_wait, mdc800->irq_woken,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			   msecs_to_jiffies(msec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	mdc800->irq_woken = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if (mdc800->camera_request_ready>0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		mdc800->camera_request_ready=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		dev_err(&mdc800->dev->dev, "timeout waiting for camera.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	if (mdc800->state == NOT_CONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		printk(KERN_WARNING "mdc800: Camera gets disconnected "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		       "during waiting for irq.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		mdc800->camera_request_ready=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		return -2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  * The write_urb callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) static void mdc800_usb_write_notify (struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	struct mdc800_data* mdc800=urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			"writing command fails (status=%i)\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		mdc800->state=READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	mdc800->written = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	wake_up (&mdc800->write_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  * The download_urb callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) static void mdc800_usb_download_notify (struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	struct mdc800_data* mdc800=urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	if (status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		/* Fill output buffer with these data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		memcpy (mdc800->out,  urb->transfer_buffer, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		mdc800->out_count=64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		mdc800->out_ptr=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		mdc800->download_left-=64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		if (mdc800->download_left == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			mdc800->state=READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			"request bytes fails (status:%i)\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	mdc800->downloaded = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	wake_up (&mdc800->download_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	Probing for the Camera
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) static struct usb_driver mdc800_usb_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) static const struct file_operations mdc800_device_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) static struct usb_class_driver mdc800_class = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	.name =		"mdc800%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	.fops =		&mdc800_device_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	.minor_base =	MDC800_DEVICE_MINOR_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  * Callback to search the Mustek MDC800 on the USB Bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) static int mdc800_usb_probe (struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			       const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	int i,j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct usb_host_interface *intf_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	struct usb_device *dev = interface_to_usbdev (intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	int irq_interval=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	dev_dbg(&intf->dev, "(%s) called.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	if (mdc800->dev != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		dev_warn(&intf->dev, "only one Mustek MDC800 is supported.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	if (dev->descriptor.bNumConfigurations != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 			"probe fails -> wrong Number of Configuration\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	intf_desc = intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	if (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			( intf_desc->desc.bInterfaceClass != 0xff )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		||	( intf_desc->desc.bInterfaceSubClass != 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		|| ( intf_desc->desc.bInterfaceProtocol != 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		|| ( intf_desc->desc.bNumEndpoints != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		dev_err(&intf->dev, "probe fails -> wrong Interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	/* Check the Endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	for (i=0; i<4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		mdc800->endpoint[i]=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		for (j=0; j<4; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			if (mdc800_endpoint_equals (&intf_desc->endpoint [j].desc,&mdc800_ed [i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 				mdc800->endpoint[i]=intf_desc->endpoint [j].desc.bEndpointAddress ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				if (i==1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 				{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 					irq_interval=intf_desc->endpoint [j].desc.bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		if (mdc800->endpoint[i] == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			dev_err(&intf->dev, "probe fails -> Wrong Endpoints.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	dev_info(&intf->dev, "Found Mustek MDC800 on USB.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	mutex_lock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	retval = usb_register_dev(intf, &mdc800_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		dev_err(&intf->dev, "Not able to get a minor for this device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	mdc800->dev=dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	mdc800->open=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	/* Setup URB Structs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	usb_fill_int_urb (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		mdc800->irq_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		mdc800->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		usb_rcvintpipe (mdc800->dev,mdc800->endpoint [1]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		mdc800->irq_urb_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		mdc800_usb_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		mdc800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		irq_interval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	usb_fill_bulk_urb (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		mdc800->write_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		mdc800->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		usb_sndbulkpipe (mdc800->dev, mdc800->endpoint[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		mdc800->write_urb_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		mdc800_usb_write_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		mdc800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	usb_fill_bulk_urb (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		mdc800->download_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		mdc800->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		usb_rcvbulkpipe (mdc800->dev, mdc800->endpoint [3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		mdc800->download_urb_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		mdc800_usb_download_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		mdc800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	mdc800->state=READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	usb_set_intfdata(intf, mdc800);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)  * Disconnect USB device (maybe the MDC800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) static void mdc800_usb_disconnect (struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	struct mdc800_data* mdc800 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	dev_dbg(&intf->dev, "(%s) called\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	if (mdc800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		if (mdc800->state == NOT_CONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		usb_deregister_dev(intf, &mdc800_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		/* must be under lock to make sure no URB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		   is submitted after usb_kill_urb() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		mutex_lock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		mdc800->state=NOT_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		usb_kill_urb(mdc800->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		usb_kill_urb(mdc800->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		usb_kill_urb(mdc800->download_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		mdc800->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	dev_info(&intf->dev, "Mustek MDC800 disconnected from USB.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	The Misc device Part (file_operations)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)  * This Function calc the Answersize for a command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static int mdc800_getAnswerSize (char command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	switch ((unsigned char) command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		case 0x2a:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		case 0x49:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		case 0x51:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		case 0x0d:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		case 0x07:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		case 0x01:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		case 0x25:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 			return 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		case 0x05:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		case 0x3e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			return mdc800->pic_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		case 0x09:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			return 4096;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604)  * Init the device: (1) alloc mem (2) Increase MOD Count ..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) static int mdc800_device_open (struct inode* inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	int retval=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	int errn=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	mutex_lock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	if (mdc800->state == NOT_CONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		errn=-EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	if (mdc800->open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		errn=-EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	mdc800->in_count=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	mdc800->out_count=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	mdc800->out_ptr=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	mdc800->pic_index=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	mdc800->pic_len=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	mdc800->download_left=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	mdc800->camera_busy=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	mdc800->camera_request_ready=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	retval=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	mdc800->irq_urb->dev = mdc800->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	retval = usb_submit_urb (mdc800->irq_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			"request USB irq fails (submit_retval=%i).\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		errn = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	mdc800->open=1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	dev_dbg(&mdc800->dev->dev, "Mustek MDC800 device opened.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) error_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	return errn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654)  * Close the Camera and release Memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) static int mdc800_device_release (struct inode* inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	int retval=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	mutex_lock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	if (mdc800->open && (mdc800->state != NOT_CONNECTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		usb_kill_urb(mdc800->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		usb_kill_urb(mdc800->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		usb_kill_urb(mdc800->download_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		mdc800->open=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		retval=-EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679)  * The Device read callback Function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t len, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	size_t left=len, sts=len; /* single transfer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	char __user *ptr = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	mutex_lock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	if (mdc800->state == NOT_CONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	if (mdc800->state == WORKING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		printk(KERN_WARNING "mdc800: Illegal State \"working\""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		       "reached during read ?!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	if (!mdc800->open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	while (left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		if (signal_pending (current)) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 			return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		sts=left > (mdc800->out_count-mdc800->out_ptr)?mdc800->out_count-mdc800->out_ptr:left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		if (sts <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			/* Too less Data in buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			if (mdc800->state == DOWNLOAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 				mdc800->out_count=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 				mdc800->out_ptr=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 				/* Download -> Request new bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 				mdc800->download_urb->dev = mdc800->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 				retval = usb_submit_urb (mdc800->download_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 				if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 					dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 						"Can't submit download urb "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 						"(retval=%i)\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 					mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 					return len-left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				wait_event_timeout(mdc800->download_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 				     mdc800->downloaded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				     msecs_to_jiffies(TO_DOWNLOAD_GET_READY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				mdc800->downloaded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 				if (mdc800->download_urb->status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 					dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 						"request download-bytes fails "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 						"(status=%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 						mdc800->download_urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 					mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 					return len-left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				/* No more bytes -> that's an error*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 				mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			/* Copy Bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 						sts)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 				mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 			ptr+=sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 			left-=sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 			mdc800->out_ptr+=sts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	return len-left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)  * The Device write callback Function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)  * If a 8Byte Command is received, it will be send to the camera.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)  * After this the driver initiates the request for the answer or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)  * just waits until the camera becomes ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) static ssize_t mdc800_device_write (struct file *file, const char __user *buf, size_t len, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	size_t i=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	mutex_lock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (mdc800->state != READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (!mdc800->open )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	while (i<len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		unsigned char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		if (signal_pending (current)) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		if(get_user(c, buf+i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		/* check for command start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		if (c == 0x55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			mdc800->in_count=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			mdc800->out_count=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			mdc800->out_ptr=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			mdc800->download_left=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		/* save command byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		if (mdc800->in_count < 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 			mdc800->in[mdc800->in_count] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			mdc800->in_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		/* Command Buffer full ? -> send it to camera */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		if (mdc800->in_count == 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			int answersize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 				dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 					"Camera didn't get ready.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 				mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			answersize=mdc800_getAnswerSize (mdc800->in[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			mdc800->state=WORKING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 			mdc800->write_urb->dev = mdc800->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			retval = usb_submit_urb (mdc800->write_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 				dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 					"submitting write urb fails "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 					"(retval=%i)\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 				mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			wait_event_timeout(mdc800->write_wait, mdc800->written,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 					msecs_to_jiffies(TO_WRITE_GET_READY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 			mdc800->written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			if (mdc800->state == WORKING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 				usb_kill_urb(mdc800->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 				mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			switch ((unsigned char) mdc800->in[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 				case 0x05: /* Download Image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 				case 0x3e: /* Take shot in Fine Mode (WCam Mode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 					if (mdc800->pic_len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 					{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 						dev_err(&mdc800->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 							"call 0x07 before "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 							"0x05,0x3e\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 						mdc800->state=READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 						mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 						return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 					mdc800->pic_len=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 					fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 				case 0x09: /* Download Thumbnail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 					mdc800->download_left=answersize+64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 					mdc800->state=DOWNLOAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 					mdc800_usb_waitForIRQ (0,TO_DOWNLOAD_GET_BUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 				default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 					if (answersize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 					{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 						if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 						{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 							dev_err(&mdc800->dev->dev, "requesting answer from irq fails\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 							mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 							return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 						/* Write dummy data, (this is ugly but part of the USB Protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 						/* if you use endpoint 1 as bulk and not as irq) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 						memcpy (mdc800->out, mdc800->camera_response,8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 						/* This is the interpreted answer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 						memcpy (&mdc800->out[8], mdc800->camera_response,8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 						mdc800->out_ptr=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 						mdc800->out_count=16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 						/* Cache the Imagesize, if command was getImageSize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 						if (mdc800->in [1] == (char) 0x07)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 						{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 							mdc800->pic_len=(int) 65536*(unsigned char) mdc800->camera_response[0]+256*(unsigned char) mdc800->camera_response[1]+(unsigned char) mdc800->camera_response[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 							dev_dbg(&mdc800->dev->dev, "cached imagesize = %i\n", mdc800->pic_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 					else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 					{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 						if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 						{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 							dev_err(&mdc800->dev->dev, "Command Timeout.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 							mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 							return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 					mdc800->state=READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	mutex_unlock(&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	Init and Cleanup this driver (Structs and types)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) /* File Operations of this drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) static const struct file_operations mdc800_device_ops =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	.owner =	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	.read =		mdc800_device_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	.write =	mdc800_device_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	.open =		mdc800_device_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	.release =	mdc800_device_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	.llseek =	noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) static const struct usb_device_id mdc800_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	{ USB_DEVICE(MDC800_VENDOR_ID, MDC800_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	{ }						/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) MODULE_DEVICE_TABLE (usb, mdc800_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)  * USB Driver Struct for this device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) static struct usb_driver mdc800_usb_driver =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	.name =		"mdc800",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	.probe =	mdc800_usb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	.disconnect =	mdc800_usb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	.id_table =	mdc800_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	Init and Cleanup this driver (Main Functions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) static int __init usb_mdc800_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	int retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	/* Allocate Memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	mdc800=kzalloc (sizeof (struct mdc800_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	if (!mdc800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	mdc800->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	mdc800->state=NOT_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	mutex_init (&mdc800->io_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	init_waitqueue_head (&mdc800->irq_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	init_waitqueue_head (&mdc800->write_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	init_waitqueue_head (&mdc800->download_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	mdc800->irq_woken = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	mdc800->downloaded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	mdc800->written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	mdc800->irq_urb_buffer=kmalloc (8, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if (!mdc800->irq_urb_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	mdc800->write_urb_buffer=kmalloc (8, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	if (!mdc800->write_urb_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	mdc800->download_urb_buffer=kmalloc (64, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	if (!mdc800->download_urb_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	mdc800->irq_urb=usb_alloc_urb (0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (!mdc800->irq_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	mdc800->download_urb=usb_alloc_urb (0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	if (!mdc800->download_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	mdc800->write_urb=usb_alloc_urb (0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	if (!mdc800->write_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	/* Register the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	retval = usb_register(&mdc800_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		goto cleanup_on_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	       DRIVER_DESC "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	/* Clean driver up, when something fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) cleanup_on_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	if (mdc800 != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		printk(KERN_ERR "mdc800: can't alloc memory!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		kfree(mdc800->download_urb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		kfree(mdc800->write_urb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		kfree(mdc800->irq_urb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		usb_free_urb(mdc800->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		usb_free_urb(mdc800->download_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		usb_free_urb(mdc800->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		kfree (mdc800);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	mdc800 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) static void __exit usb_mdc800_cleanup (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	usb_deregister (&mdc800_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	usb_free_urb (mdc800->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	usb_free_urb (mdc800->download_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	usb_free_urb (mdc800->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	kfree (mdc800->irq_urb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	kfree (mdc800->write_urb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	kfree (mdc800->download_urb_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	kfree (mdc800);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	mdc800 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) module_init (usb_mdc800_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) module_exit (usb_mdc800_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) MODULE_AUTHOR( DRIVER_AUTHOR );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) MODULE_DESCRIPTION( DRIVER_DESC );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)