1/*************************************************************************** 2 * V4L2 driver for ZC0301[P] Image Processor and Control Chip * 3 * * 4 * Copyright (C) 2006-2007 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 _ZC0301_H_ 22#define _ZC0301_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/mutex.h> 36#include <linux/rwsem.h> 37#include <linux/stddef.h> 38#include <linux/string.h> 39 40#include "zc0301_sensor.h" 41 42/*****************************************************************************/ 43 44#define ZC0301_DEBUG 45#define ZC0301_DEBUG_LEVEL 2 46#define ZC0301_MAX_DEVICES 64 47#define ZC0301_FORCE_MUNMAP 0 48#define ZC0301_MAX_FRAMES 32 49#define ZC0301_COMPRESSION_QUALITY 0 50#define ZC0301_URBS 2 51#define ZC0301_ISO_PACKETS 7 52#define ZC0301_ALTERNATE_SETTING 7 53#define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS) 54#define ZC0301_CTRL_TIMEOUT 100 55#define ZC0301_FRAME_TIMEOUT 2 56 57/*****************************************************************************/ 58 59ZC0301_ID_TABLE 60ZC0301_SENSOR_TABLE 61 62enum zc0301_frame_state { 63 F_UNUSED, 64 F_QUEUED, 65 F_GRABBING, 66 F_DONE, 67 F_ERROR, 68}; 69 70struct zc0301_frame_t { 71 void* bufmem; 72 struct v4l2_buffer buf; 73 enum zc0301_frame_state state; 74 struct list_head frame; 75 unsigned long vma_use_count; 76}; 77 78enum zc0301_dev_state { 79 DEV_INITIALIZED = 0x01, 80 DEV_DISCONNECTED = 0x02, 81 DEV_MISCONFIGURED = 0x04, 82}; 83 84enum zc0301_io_method { 85 IO_NONE, 86 IO_READ, 87 IO_MMAP, 88}; 89 90enum zc0301_stream_state { 91 STREAM_OFF, 92 STREAM_INTERRUPT, 93 STREAM_ON, 94}; 95 96struct zc0301_module_param { 97 u8 force_munmap; 98 u16 frame_timeout; 99}; 100 101static DECLARE_RWSEM(zc0301_disconnect); 102 103struct zc0301_device { 104 struct video_device* v4ldev; 105 106 struct zc0301_sensor sensor; 107 108 struct usb_device* usbdev; 109 struct urb* urb[ZC0301_URBS]; 110 void* transfer_buffer[ZC0301_URBS]; 111 u8* control_buffer; 112 113 struct zc0301_frame_t *frame_current, frame[ZC0301_MAX_FRAMES]; 114 struct list_head inqueue, outqueue; 115 u32 frame_count, nbuffers, nreadbuffers; 116 117 enum zc0301_io_method io; 118 enum zc0301_stream_state stream; 119 120 struct v4l2_jpegcompression compression; 121 122 struct zc0301_module_param module_param; 123 124 enum zc0301_dev_state state; 125 u8 users; 126 127 struct mutex dev_mutex, fileop_mutex; 128 spinlock_t queue_lock; 129 wait_queue_head_t open, wait_frame, wait_stream; 130}; 131 132/*****************************************************************************/ 133 134struct zc0301_device* 135zc0301_match_id(struct zc0301_device* cam, const struct usb_device_id *id) 136{ 137 return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL; 138} 139 140void 141zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor) 142{ 143 memcpy(&cam->sensor, sensor, sizeof(struct zc0301_sensor)); 144} 145 146/*****************************************************************************/ 147 148#undef DBG 149#undef KDBG 150#ifdef ZC0301_DEBUG 151# define DBG(level, fmt, args...) \ 152do { \ 153 if (debug >= (level)) { \ 154 if ((level) == 1) \ 155 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \ 156 else if ((level) == 2) \ 157 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 158 else if ((level) >= 3) \ 159 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 160 __FUNCTION__, __LINE__ , ## args); \ 161 } \ 162} while (0) 163# define KDBG(level, fmt, args...) \ 164do { \ 165 if (debug >= (level)) { \ 166 if ((level) == 1 || (level) == 2) \ 167 pr_info("zc0301: " fmt "\n", ## args); \ 168 else if ((level) == 3) \ 169 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \ 170 __LINE__ , ## args); \ 171 } \ 172} while (0) 173# define V4LDBG(level, name, cmd) \ 174do { \ 175 if (debug >= (level)) \ 176 v4l_print_ioctl(name, cmd); \ 177} while (0) 178#else 179# define DBG(level, fmt, args...) do {;} while(0) 180# define KDBG(level, fmt, args...) do {;} while(0) 181# define V4LDBG(level, name, cmd) do {;} while(0) 182#endif 183 184#undef PDBG 185#define PDBG(fmt, args...) \ 186dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 187 __FUNCTION__, __LINE__ , ## args) 188 189#undef PDBGG 190#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ 191 192#endif /* _ZC0301_H_ */ 193