Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * V4L2 driver for SN9C10x PC Camera Controllers * |
| 3 | * * |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 4 | * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 _SN9C102_H_ |
| 22 | #define _SN9C102_H_ |
| 23 | |
| 24 | #include <linux/version.h> |
| 25 | #include <linux/usb.h> |
| 26 | #include <linux/videodev.h> |
| 27 | #include <linux/device.h> |
| 28 | #include <linux/list.h> |
| 29 | #include <linux/spinlock.h> |
| 30 | #include <linux/time.h> |
| 31 | #include <linux/wait.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/param.h> |
| 34 | #include <linux/rwsem.h> |
| 35 | #include <asm/semaphore.h> |
| 36 | |
| 37 | #include "sn9c102_sensor.h" |
| 38 | |
| 39 | /*****************************************************************************/ |
| 40 | |
| 41 | #define SN9C102_DEBUG |
| 42 | #define SN9C102_DEBUG_LEVEL 2 |
| 43 | #define SN9C102_MAX_DEVICES 64 |
| 44 | #define SN9C102_PRESERVE_IMGSCALE 0 |
| 45 | #define SN9C102_FORCE_MUNMAP 0 |
| 46 | #define SN9C102_MAX_FRAMES 32 |
| 47 | #define SN9C102_URBS 2 |
| 48 | #define SN9C102_ISO_PACKETS 7 |
| 49 | #define SN9C102_ALTERNATE_SETTING 8 |
| 50 | #define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS) |
| 51 | #define SN9C102_CTRL_TIMEOUT 300 |
| 52 | |
| 53 | /*****************************************************************************/ |
| 54 | |
| 55 | #define SN9C102_MODULE_NAME "V4L2 driver for SN9C10x PC Camera Controllers" |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 56 | #define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" |
| 58 | #define SN9C102_MODULE_LICENSE "GPL" |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 59 | #define SN9C102_MODULE_VERSION "1:1.25" |
| 60 | #define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 25) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | enum sn9c102_bridge { |
| 63 | BRIDGE_SN9C101 = 0x01, |
| 64 | BRIDGE_SN9C102 = 0x02, |
| 65 | BRIDGE_SN9C103 = 0x04, |
| 66 | }; |
| 67 | |
| 68 | SN9C102_ID_TABLE |
| 69 | SN9C102_SENSOR_TABLE |
| 70 | |
| 71 | enum sn9c102_frame_state { |
| 72 | F_UNUSED, |
| 73 | F_QUEUED, |
| 74 | F_GRABBING, |
| 75 | F_DONE, |
| 76 | F_ERROR, |
| 77 | }; |
| 78 | |
| 79 | struct sn9c102_frame_t { |
| 80 | void* bufmem; |
| 81 | struct v4l2_buffer buf; |
| 82 | enum sn9c102_frame_state state; |
| 83 | struct list_head frame; |
| 84 | unsigned long vma_use_count; |
| 85 | }; |
| 86 | |
| 87 | enum sn9c102_dev_state { |
| 88 | DEV_INITIALIZED = 0x01, |
| 89 | DEV_DISCONNECTED = 0x02, |
| 90 | DEV_MISCONFIGURED = 0x04, |
| 91 | }; |
| 92 | |
| 93 | enum sn9c102_io_method { |
| 94 | IO_NONE, |
| 95 | IO_READ, |
| 96 | IO_MMAP, |
| 97 | }; |
| 98 | |
| 99 | enum sn9c102_stream_state { |
| 100 | STREAM_OFF, |
| 101 | STREAM_INTERRUPT, |
| 102 | STREAM_ON, |
| 103 | }; |
| 104 | |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 105 | typedef char sn9c103_sof_header_t[18]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | typedef char sn9c102_sof_header_t[12]; |
| 107 | typedef char sn9c102_eof_header_t[4]; |
| 108 | |
| 109 | struct sn9c102_sysfs_attr { |
| 110 | u8 reg, i2c_reg; |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 111 | sn9c103_sof_header_t frame_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct sn9c102_module_param { |
| 115 | u8 force_munmap; |
| 116 | }; |
| 117 | |
| 118 | static DECLARE_MUTEX(sn9c102_sysfs_lock); |
| 119 | static DECLARE_RWSEM(sn9c102_disconnect); |
| 120 | |
| 121 | struct sn9c102_device { |
| 122 | struct device dev; |
| 123 | |
| 124 | struct video_device* v4ldev; |
| 125 | |
| 126 | enum sn9c102_bridge bridge; |
| 127 | struct sn9c102_sensor* sensor; |
| 128 | |
| 129 | struct usb_device* usbdev; |
| 130 | struct urb* urb[SN9C102_URBS]; |
| 131 | void* transfer_buffer[SN9C102_URBS]; |
| 132 | u8* control_buffer; |
| 133 | |
| 134 | struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES]; |
| 135 | struct list_head inqueue, outqueue; |
| 136 | u32 frame_count, nbuffers, nreadbuffers; |
| 137 | |
| 138 | enum sn9c102_io_method io; |
| 139 | enum sn9c102_stream_state stream; |
| 140 | |
| 141 | struct v4l2_jpegcompression compression; |
| 142 | |
| 143 | struct sn9c102_sysfs_attr sysfs; |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 144 | sn9c103_sof_header_t sof_header; |
| 145 | u16 reg[63]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | struct sn9c102_module_param module_param; |
| 148 | |
| 149 | enum sn9c102_dev_state state; |
| 150 | u8 users; |
| 151 | |
| 152 | struct semaphore dev_sem, fileop_sem; |
| 153 | spinlock_t queue_lock; |
| 154 | wait_queue_head_t open, wait_frame, wait_stream; |
| 155 | }; |
| 156 | |
| 157 | /*****************************************************************************/ |
| 158 | |
| 159 | void |
| 160 | sn9c102_attach_sensor(struct sn9c102_device* cam, |
| 161 | struct sn9c102_sensor* sensor) |
| 162 | { |
| 163 | cam->sensor = sensor; |
| 164 | cam->sensor->dev = &cam->dev; |
| 165 | cam->sensor->usbdev = cam->usbdev; |
| 166 | } |
| 167 | |
| 168 | /*****************************************************************************/ |
| 169 | |
| 170 | #undef DBG |
| 171 | #undef KDBG |
| 172 | #ifdef SN9C102_DEBUG |
| 173 | # define DBG(level, fmt, args...) \ |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 174 | do { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (debug >= (level)) { \ |
| 176 | if ((level) == 1) \ |
| 177 | dev_err(&cam->dev, fmt "\n", ## args); \ |
| 178 | else if ((level) == 2) \ |
| 179 | dev_info(&cam->dev, fmt "\n", ## args); \ |
| 180 | else if ((level) >= 3) \ |
| 181 | dev_info(&cam->dev, "[%s:%d] " fmt "\n", \ |
| 182 | __FUNCTION__, __LINE__ , ## args); \ |
| 183 | } \ |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 184 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | # define KDBG(level, fmt, args...) \ |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 186 | do { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (debug >= (level)) { \ |
| 188 | if ((level) == 1 || (level) == 2) \ |
| 189 | pr_info("sn9c102: " fmt "\n", ## args); \ |
| 190 | else if ((level) == 3) \ |
| 191 | pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \ |
| 192 | __LINE__ , ## args); \ |
| 193 | } \ |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 194 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #else |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 196 | # define KDBG(level, fmt, args...) do {;} while(0) |
| 197 | # define DBG(level, fmt, args...) do {;} while(0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | #endif |
| 199 | |
| 200 | #undef PDBG |
| 201 | #define PDBG(fmt, args...) \ |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 202 | dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | #undef PDBGG |
Luca Risolia | a966f3e | 2006-01-05 18:14:04 +0000 | [diff] [blame^] | 205 | #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | #endif /* _SN9C102_H_ */ |