| Luca Risolia | 7ce08c9 | 2006-01-11 02:06:59 +0000 | [diff] [blame] | 1 | /*************************************************************************** | 
 | 2 |  * V4L2 driver for ET61X[12]51 PC Camera Controllers                       * | 
 | 3 |  *                                                                         * | 
 | 4 |  * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it>       * | 
 | 5 |  *                                                                         * | 
 | 6 |  * This program is free software; you can redistribute it and/or modify    * | 
 | 7 |  * it under the terms of the GNU General Public License as published by    * | 
 | 8 |  * the Free Software Foundation; either version 2 of the License, or       * | 
 | 9 |  * (at your option) any later version.                                     * | 
 | 10 |  *                                                                         * | 
 | 11 |  * This program is distributed in the hope that it will be useful,         * | 
 | 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of          * | 
 | 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           * | 
 | 14 |  * GNU General Public License for more details.                            * | 
 | 15 |  *                                                                         * | 
 | 16 |  * You should have received a copy of the GNU General Public License       * | 
 | 17 |  * along with this program; if not, write to the Free Software             * | 
 | 18 |  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               * | 
 | 19 |  ***************************************************************************/ | 
 | 20 |  | 
 | 21 | #ifndef _ET61X251_H_ | 
 | 22 | #define _ET61X251_H_ | 
 | 23 |  | 
 | 24 | #include <linux/version.h> | 
 | 25 | #include <linux/usb.h> | 
 | 26 | #include <linux/videodev2.h> | 
 | 27 | #include <media/v4l2-common.h> | 
 | 28 | #include <linux/device.h> | 
 | 29 | #include <linux/list.h> | 
 | 30 | #include <linux/spinlock.h> | 
 | 31 | #include <linux/time.h> | 
 | 32 | #include <linux/wait.h> | 
 | 33 | #include <linux/types.h> | 
 | 34 | #include <linux/param.h> | 
 | 35 | #include <linux/rwsem.h> | 
 | 36 | #include <asm/semaphore.h> | 
 | 37 |  | 
 | 38 | #include "et61x251_sensor.h" | 
 | 39 |  | 
 | 40 | /*****************************************************************************/ | 
 | 41 |  | 
 | 42 | #define ET61X251_DEBUG | 
 | 43 | #define ET61X251_DEBUG_LEVEL         2 | 
 | 44 | #define ET61X251_MAX_DEVICES         64 | 
 | 45 | #define ET61X251_PRESERVE_IMGSCALE   0 | 
 | 46 | #define ET61X251_FORCE_MUNMAP        0 | 
 | 47 | #define ET61X251_MAX_FRAMES          32 | 
 | 48 | #define ET61X251_COMPRESSION_QUALITY 0 | 
 | 49 | #define ET61X251_URBS                2 | 
 | 50 | #define ET61X251_ISO_PACKETS         7 | 
 | 51 | #define ET61X251_ALTERNATE_SETTING   13 | 
 | 52 | #define ET61X251_URB_TIMEOUT         msecs_to_jiffies(2 * ET61X251_ISO_PACKETS) | 
 | 53 | #define ET61X251_CTRL_TIMEOUT        100 | 
 | 54 |  | 
 | 55 | /*****************************************************************************/ | 
 | 56 |  | 
 | 57 | static const struct usb_device_id et61x251_id_table[] = { | 
 | 58 | 	{ USB_DEVICE(0x102c, 0x6151), }, | 
 | 59 | 	{ USB_DEVICE(0x102c, 0x6251), }, | 
 | 60 | 	{ USB_DEVICE(0x102c, 0x6253), }, | 
 | 61 | 	{ USB_DEVICE(0x102c, 0x6254), }, | 
 | 62 | 	{ USB_DEVICE(0x102c, 0x6255), }, | 
 | 63 | 	{ USB_DEVICE(0x102c, 0x6256), }, | 
 | 64 | 	{ USB_DEVICE(0x102c, 0x6257), }, | 
 | 65 | 	{ USB_DEVICE(0x102c, 0x6258), }, | 
 | 66 | 	{ USB_DEVICE(0x102c, 0x6259), }, | 
 | 67 | 	{ USB_DEVICE(0x102c, 0x625a), }, | 
 | 68 | 	{ USB_DEVICE(0x102c, 0x625b), }, | 
 | 69 | 	{ USB_DEVICE(0x102c, 0x625c), }, | 
 | 70 | 	{ USB_DEVICE(0x102c, 0x625d), }, | 
 | 71 | 	{ USB_DEVICE(0x102c, 0x625e), }, | 
 | 72 | 	{ USB_DEVICE(0x102c, 0x625f), }, | 
 | 73 | 	{ USB_DEVICE(0x102c, 0x6260), }, | 
 | 74 | 	{ USB_DEVICE(0x102c, 0x6261), }, | 
 | 75 | 	{ USB_DEVICE(0x102c, 0x6262), }, | 
 | 76 | 	{ USB_DEVICE(0x102c, 0x6263), }, | 
 | 77 | 	{ USB_DEVICE(0x102c, 0x6264), }, | 
 | 78 | 	{ USB_DEVICE(0x102c, 0x6265), }, | 
 | 79 | 	{ USB_DEVICE(0x102c, 0x6266), }, | 
 | 80 | 	{ USB_DEVICE(0x102c, 0x6267), }, | 
 | 81 | 	{ USB_DEVICE(0x102c, 0x6268), }, | 
 | 82 | 	{ USB_DEVICE(0x102c, 0x6269), }, | 
 | 83 | 	{ } | 
 | 84 | }; | 
 | 85 |  | 
 | 86 | ET61X251_SENSOR_TABLE | 
 | 87 |  | 
 | 88 | /*****************************************************************************/ | 
 | 89 |  | 
 | 90 | enum et61x251_frame_state { | 
 | 91 | 	F_UNUSED, | 
 | 92 | 	F_QUEUED, | 
 | 93 | 	F_GRABBING, | 
 | 94 | 	F_DONE, | 
 | 95 | 	F_ERROR, | 
 | 96 | }; | 
 | 97 |  | 
 | 98 | struct et61x251_frame_t { | 
 | 99 | 	void* bufmem; | 
 | 100 | 	struct v4l2_buffer buf; | 
 | 101 | 	enum et61x251_frame_state state; | 
 | 102 | 	struct list_head frame; | 
 | 103 | 	unsigned long vma_use_count; | 
 | 104 | }; | 
 | 105 |  | 
 | 106 | enum et61x251_dev_state { | 
 | 107 | 	DEV_INITIALIZED = 0x01, | 
 | 108 | 	DEV_DISCONNECTED = 0x02, | 
 | 109 | 	DEV_MISCONFIGURED = 0x04, | 
 | 110 | }; | 
 | 111 |  | 
 | 112 | enum et61x251_io_method { | 
 | 113 | 	IO_NONE, | 
 | 114 | 	IO_READ, | 
 | 115 | 	IO_MMAP, | 
 | 116 | }; | 
 | 117 |  | 
 | 118 | enum et61x251_stream_state { | 
 | 119 | 	STREAM_OFF, | 
 | 120 | 	STREAM_INTERRUPT, | 
 | 121 | 	STREAM_ON, | 
 | 122 | }; | 
 | 123 |  | 
 | 124 | struct et61x251_sysfs_attr { | 
 | 125 | 	u8 reg, i2c_reg; | 
 | 126 | }; | 
 | 127 |  | 
 | 128 | struct et61x251_module_param { | 
 | 129 | 	u8 force_munmap; | 
 | 130 | }; | 
 | 131 |  | 
 | 132 | static DECLARE_MUTEX(et61x251_sysfs_lock); | 
 | 133 | static DECLARE_RWSEM(et61x251_disconnect); | 
 | 134 |  | 
 | 135 | struct et61x251_device { | 
 | 136 | 	struct video_device* v4ldev; | 
 | 137 |  | 
 | 138 | 	struct et61x251_sensor* sensor; | 
 | 139 |  | 
 | 140 | 	struct usb_device* usbdev; | 
 | 141 | 	struct urb* urb[ET61X251_URBS]; | 
 | 142 | 	void* transfer_buffer[ET61X251_URBS]; | 
 | 143 | 	u8* control_buffer; | 
 | 144 |  | 
 | 145 | 	struct et61x251_frame_t *frame_current, frame[ET61X251_MAX_FRAMES]; | 
 | 146 | 	struct list_head inqueue, outqueue; | 
 | 147 | 	u32 frame_count, nbuffers, nreadbuffers; | 
 | 148 |  | 
 | 149 | 	enum et61x251_io_method io; | 
 | 150 | 	enum et61x251_stream_state stream; | 
 | 151 |  | 
 | 152 | 	struct v4l2_jpegcompression compression; | 
 | 153 |  | 
 | 154 | 	struct et61x251_sysfs_attr sysfs; | 
 | 155 | 	struct et61x251_module_param module_param; | 
 | 156 |  | 
 | 157 | 	enum et61x251_dev_state state; | 
 | 158 | 	u8 users; | 
 | 159 |  | 
 | 160 | 	struct semaphore dev_sem, fileop_sem; | 
 | 161 | 	spinlock_t queue_lock; | 
 | 162 | 	wait_queue_head_t open, wait_frame, wait_stream; | 
 | 163 | }; | 
 | 164 |  | 
 | 165 | /*****************************************************************************/ | 
 | 166 |  | 
 | 167 | void | 
 | 168 | et61x251_attach_sensor(struct et61x251_device* cam, | 
 | 169 |                        struct et61x251_sensor* sensor) | 
 | 170 | { | 
 | 171 | 	cam->sensor = sensor; | 
 | 172 | 	cam->sensor->usbdev = cam->usbdev; | 
 | 173 | } | 
 | 174 |  | 
 | 175 | /*****************************************************************************/ | 
 | 176 |  | 
 | 177 | #undef DBG | 
 | 178 | #undef KDBG | 
 | 179 | #ifdef ET61X251_DEBUG | 
 | 180 | #	define DBG(level, fmt, args...)                                       \ | 
 | 181 | do {                                                                          \ | 
 | 182 | 	if (debug >= (level)) {                                               \ | 
 | 183 | 		if ((level) == 1)                                             \ | 
 | 184 | 			dev_err(&cam->usbdev->dev, fmt "\n", ## args);        \ | 
 | 185 | 		else if ((level) == 2)                                        \ | 
 | 186 | 			dev_info(&cam->usbdev->dev, fmt "\n", ## args);       \ | 
 | 187 | 		else if ((level) >= 3)                                        \ | 
 | 188 | 			dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n",      \ | 
 | 189 | 			         __FUNCTION__, __LINE__ , ## args);           \ | 
 | 190 | 	}                                                                     \ | 
 | 191 | } while (0) | 
 | 192 | #	define KDBG(level, fmt, args...)                                      \ | 
 | 193 | do {                                                                          \ | 
 | 194 | 	if (debug >= (level)) {                                               \ | 
 | 195 | 		if ((level) == 1 || (level) == 2)                             \ | 
 | 196 | 			pr_info("et61x251: " fmt "\n", ## args);              \ | 
 | 197 | 		else if ((level) == 3)                                        \ | 
 | 198 | 			pr_debug("et61x251: [%s:%d] " fmt "\n", __FUNCTION__, \ | 
 | 199 | 			         __LINE__ , ## args);                         \ | 
 | 200 | 	}                                                                     \ | 
 | 201 | } while (0) | 
 | 202 | #	define V4LDBG(level, name, cmd)                                       \ | 
 | 203 | do {                                                                          \ | 
 | 204 | 	if (debug >= (level))                                                 \ | 
 | 205 | 		v4l_print_ioctl(name, cmd);                                   \ | 
 | 206 | } while (0) | 
 | 207 | #else | 
 | 208 | #	define DBG(level, fmt, args...) do {;} while(0) | 
 | 209 | #	define KDBG(level, fmt, args...) do {;} while(0) | 
 | 210 | #	define V4LDBG(level, name, cmd) do {;} while(0) | 
 | 211 | #endif | 
 | 212 |  | 
 | 213 | #undef PDBG | 
 | 214 | #define PDBG(fmt, args...)                                                    \ | 
 | 215 | dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args) | 
 | 216 |  | 
 | 217 | #undef PDBGG | 
 | 218 | #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ | 
 | 219 |  | 
 | 220 | #endif /* _ET61X251_H_ */ |