Linux 3.11-rc3
[cris-mirror.git] / drivers / media / usb / sn9c102 / sn9c102.h
blob8a917f0605035bd3c61b278b02df955ba8484c08
1 /***************************************************************************
2 * V4L2 driver for SN9C1xx PC Camera Controllers *
3 * *
4 * Copyright (C) 2004-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 ***************************************************************************/
21 #ifndef _SN9C102_H_
22 #define _SN9C102_H_
24 #include <linux/usb.h>
25 #include <linux/videodev2.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-ioctl.h>
28 #include <media/v4l2-device.h>
29 #include <linux/device.h>
30 #include <linux/list.h>
31 #include <linux/spinlock.h>
32 #include <linux/time.h>
33 #include <linux/wait.h>
34 #include <linux/types.h>
35 #include <linux/param.h>
36 #include <linux/rwsem.h>
37 #include <linux/mutex.h>
38 #include <linux/string.h>
39 #include <linux/stddef.h>
40 #include <linux/kref.h>
42 #include "sn9c102_config.h"
43 #include "sn9c102_sensor.h"
44 #include "sn9c102_devtable.h"
47 enum sn9c102_frame_state {
48 F_UNUSED,
49 F_QUEUED,
50 F_GRABBING,
51 F_DONE,
52 F_ERROR,
55 struct sn9c102_frame_t {
56 void* bufmem;
57 struct v4l2_buffer buf;
58 enum sn9c102_frame_state state;
59 struct list_head frame;
60 unsigned long vma_use_count;
63 enum sn9c102_dev_state {
64 DEV_INITIALIZED = 0x01,
65 DEV_DISCONNECTED = 0x02,
66 DEV_MISCONFIGURED = 0x04,
69 enum sn9c102_io_method {
70 IO_NONE,
71 IO_READ,
72 IO_MMAP,
75 enum sn9c102_stream_state {
76 STREAM_OFF,
77 STREAM_INTERRUPT,
78 STREAM_ON,
81 typedef char sn9c102_sof_header_t[62];
83 struct sn9c102_sof_t {
84 sn9c102_sof_header_t header;
85 u16 bytesread;
88 struct sn9c102_sysfs_attr {
89 u16 reg, i2c_reg;
90 sn9c102_sof_header_t frame_header;
93 struct sn9c102_module_param {
94 u8 force_munmap;
95 u16 frame_timeout;
98 static DEFINE_MUTEX(sn9c102_sysfs_lock);
99 static DECLARE_RWSEM(sn9c102_dev_lock);
101 struct sn9c102_device {
102 struct video_device* v4ldev;
104 struct v4l2_device v4l2_dev;
106 enum sn9c102_bridge bridge;
107 struct sn9c102_sensor sensor;
109 struct usb_device* usbdev;
110 struct urb* urb[SN9C102_URBS];
111 void* transfer_buffer[SN9C102_URBS];
112 u8* control_buffer;
114 struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
115 struct list_head inqueue, outqueue;
116 u32 frame_count, nbuffers, nreadbuffers;
118 enum sn9c102_io_method io;
119 enum sn9c102_stream_state stream;
121 struct v4l2_jpegcompression compression;
123 struct sn9c102_sysfs_attr sysfs;
124 struct sn9c102_sof_t sof;
125 u16 reg[384];
127 struct sn9c102_module_param module_param;
129 struct kref kref;
130 enum sn9c102_dev_state state;
131 u8 users;
133 struct completion probe;
134 struct mutex open_mutex, fileop_mutex;
135 spinlock_t queue_lock;
136 wait_queue_head_t wait_open, wait_frame, wait_stream;
139 /*****************************************************************************/
141 struct sn9c102_device*
142 sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
144 return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
148 void
149 sn9c102_attach_sensor(struct sn9c102_device* cam,
150 const struct sn9c102_sensor* sensor)
152 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
156 enum sn9c102_bridge
157 sn9c102_get_bridge(struct sn9c102_device* cam)
159 return cam->bridge;
163 struct sn9c102_sensor* sn9c102_get_sensor(struct sn9c102_device* cam)
165 return &cam->sensor;
168 /*****************************************************************************/
170 #undef DBG
171 #undef KDBG
172 #ifdef SN9C102_DEBUG
173 # define DBG(level, fmt, args...) \
174 do { \
175 if (debug >= (level)) { \
176 if ((level) == 1) \
177 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
178 else if ((level) == 2) \
179 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
180 else if ((level) >= 3) \
181 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
182 __func__, __LINE__ , ## args); \
184 } while (0)
185 # define V4LDBG(level, name, cmd) \
186 do { \
187 if (debug >= (level)) \
188 v4l_printk_ioctl(name, cmd); \
189 } while (0)
190 # define KDBG(level, fmt, args...) \
191 do { \
192 if (debug >= (level)) { \
193 if ((level) == 1 || (level) == 2) \
194 pr_info("sn9c102: " fmt "\n", ## args); \
195 else if ((level) == 3) \
196 pr_debug("sn9c102: [%s:%d] " fmt "\n", \
197 __func__, __LINE__ , ## args); \
199 } while (0)
200 #else
201 # define DBG(level, fmt, args...) do {;} while(0)
202 # define V4LDBG(level, name, cmd) do {;} while(0)
203 # define KDBG(level, fmt, args...) do {;} while(0)
204 #endif
206 #undef PDBG
207 #define PDBG(fmt, args...) \
208 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \
209 __LINE__ , ## args)
211 #undef PDBGG
212 #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
214 #endif /* _SN9C102_H_ */