blob: 967c6b6bc0fa273351515148c9343ada98fb2327 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/***************************************************************************
2 * V4L2 driver for SN9C10x PC Camera Controllers *
3 * *
Luca Risoliaa966f3e2006-01-05 18:14:04 +00004 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * *
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 Risoliaa966f3e2006-01-05 18:14:04 +000056#define SN9C102_MODULE_AUTHOR "(C) 2004-2006 Luca Risolia"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
58#define SN9C102_MODULE_LICENSE "GPL"
Luca Risoliaa966f3e2006-01-05 18:14:04 +000059#define SN9C102_MODULE_VERSION "1:1.25"
60#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 25)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62enum sn9c102_bridge {
63 BRIDGE_SN9C101 = 0x01,
64 BRIDGE_SN9C102 = 0x02,
65 BRIDGE_SN9C103 = 0x04,
66};
67
68SN9C102_ID_TABLE
69SN9C102_SENSOR_TABLE
70
71enum sn9c102_frame_state {
72 F_UNUSED,
73 F_QUEUED,
74 F_GRABBING,
75 F_DONE,
76 F_ERROR,
77};
78
79struct 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
87enum sn9c102_dev_state {
88 DEV_INITIALIZED = 0x01,
89 DEV_DISCONNECTED = 0x02,
90 DEV_MISCONFIGURED = 0x04,
91};
92
93enum sn9c102_io_method {
94 IO_NONE,
95 IO_READ,
96 IO_MMAP,
97};
98
99enum sn9c102_stream_state {
100 STREAM_OFF,
101 STREAM_INTERRUPT,
102 STREAM_ON,
103};
104
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000105typedef char sn9c103_sof_header_t[18];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106typedef char sn9c102_sof_header_t[12];
107typedef char sn9c102_eof_header_t[4];
108
109struct sn9c102_sysfs_attr {
110 u8 reg, i2c_reg;
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000111 sn9c103_sof_header_t frame_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
114struct sn9c102_module_param {
115 u8 force_munmap;
116};
117
118static DECLARE_MUTEX(sn9c102_sysfs_lock);
119static DECLARE_RWSEM(sn9c102_disconnect);
120
121struct 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 Risoliaa966f3e2006-01-05 18:14:04 +0000144 sn9c103_sof_header_t sof_header;
145 u16 reg[63];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
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
159void
160sn9c102_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 Risoliaa966f3e2006-01-05 18:14:04 +0000174do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 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 Risoliaa966f3e2006-01-05 18:14:04 +0000184} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185# define KDBG(level, fmt, args...) \
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000186do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 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 Risoliaa966f3e2006-01-05 18:14:04 +0000194} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#else
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000196# define KDBG(level, fmt, args...) do {;} while(0)
197# define DBG(level, fmt, args...) do {;} while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif
199
200#undef PDBG
201#define PDBG(fmt, args...) \
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000202dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204#undef PDBGG
Luca Risoliaa966f3e2006-01-05 18:14:04 +0000205#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207#endif /* _SN9C102_H_ */