V4L/DVB (12773): tm6000: fix module unregister
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / tm6000 / tm6000.h
CommitLineData
9701dc94
MCC
1/*
2 tm6000.h - driver for TM5600/TM6000 USB video capture devices
3
4 Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
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 version 2
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20// Use the tm6000-hack, instead of the proper initialization code
21//#define HACK 1
22
23#include <linux/videodev2.h>
24#include <media/v4l2-common.h>
25#include <media/videobuf-vmalloc.h>
26#include "tm6000-usb-isoc.h"
27#include <linux/i2c.h>
28#include <linux/mutex.h>
29
30#define TM6000_VERSION KERNEL_VERSION(0, 0, 1)
31
32/* Inputs */
33#define TM6000_INPUT_TV 0
34#define TM6000_INPUT_COMPOSITE 1
35#define TM6000_INPUT_SVIDEO 2
36
37/* ------------------------------------------------------------------
38 Basic structures
39 ------------------------------------------------------------------*/
40
41struct tm6000_fmt {
42 char *name;
43 u32 fourcc; /* v4l2 format id */
44 int depth;
45};
46
47/* buffer for one video frame */
48struct tm6000_buffer {
49 /* common v4l buffer stuff -- must be first */
50 struct videobuf_buffer vb;
51
52 struct tm6000_fmt *fmt;
53};
54
55struct tm6000_dmaqueue {
56 struct list_head active;
57 struct list_head queued;
58 struct timer_list timeout;
59
60 /* thread for generating video stream*/
61 struct task_struct *kthread;
62 wait_queue_head_t wq;
63 /* Counters to control fps rate */
64 int frame;
65 int ini_jiffies;
66};
67
68/* device states */
69enum tm6000_core_state {
70 DEV_INITIALIZED = 0x01,
71 DEV_DISCONNECTED = 0x02,
72 DEV_MISCONFIGURED = 0x04,
73};
74
75/* io methods */
76enum tm6000_io_method {
77 IO_NONE,
78 IO_READ,
79 IO_MMAP,
80};
81
82enum tm6000_mode {
83 TM6000_MODE_UNKNOWN=0,
84 TM6000_MODE_ANALOG,
85 TM6000_MODE_DIGITAL,
86};
87
88struct tm6000_capabilities {
89 unsigned int has_tuner:1;
90 unsigned int has_tda9874:1;
91 unsigned int has_dvb:1;
92 unsigned int has_zl10353:1;
93 unsigned int has_eeprom:1;
94};
95
96struct tm6000_core {
97 /* generic device properties */
98 char name[30]; /* name (including minor) of the device */
99 int model; /* index in the device_data struct */
100 int devno; /* marks the number of this device */
101 v4l2_std_id norm; /* Current norm */
102
103 enum tm6000_core_state state;
104
105 /* Device Capabilities*/
106 struct tm6000_capabilities caps;
107
108 /* Tuner configuration */
109 int tuner_type; /* type of the tuner */
110 int tuner_addr; /* tuner address */
111
112 /* i2c i/o */
113 struct i2c_adapter i2c_adap;
114 struct i2c_client i2c_client;
115
116 /* video for linux */
117 struct list_head tm6000_corelist;
118 int users;
119
120 /* various device info */
121 unsigned int resources;
122 struct video_device vfd;
123 struct tm6000_dmaqueue vidq;
124
125 int input;
126 int freq;
127 unsigned int fourcc;
128
129 enum tm6000_mode mode;
130
131 /* locks */
132 struct mutex lock;
133
134 /* usb transfer */
135 struct usb_device *udev; /* the usb device */
136
137 struct usb_host_endpoint *bulk_in, *bulk_out, *isoc_in, *isoc_out;
138 unsigned int max_bulk_in, max_bulk_out;
139 unsigned int max_isoc_in, max_isoc_out;
140
141 /* scaler!=0 if scaler is active*/
142 int scaler;
143
144 /* Isoc control struct */
145 struct usb_isoc_ctl isoc_ctl;
146
147 spinlock_t slock;
148};
149
150struct tm6000_fh {
151 struct tm6000_core *dev;
152
153 /* video capture */
154 struct tm6000_fmt *fmt;
155 unsigned int width,height;
156 struct videobuf_queue vb_vidq;
157
158 enum v4l2_buf_type type;
159};
160
161#define TM6000_STD V4L2_STD_PAL|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc| \
162 V4L2_STD_PAL_M|V4L2_STD_PAL_60|V4L2_STD_NTSC_M| \
163 V4L2_STD_NTSC_M_JP|V4L2_STD_SECAM
164
165/* In tm6000-core.c */
166extern unsigned long tm6000_devused;
167
168int tm6000_read_write_usb (struct tm6000_core *dev, u8 reqtype, u8 req,
169 u16 value, u16 index, u8 *buf, u16 len);
170int tm6000_get_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index);
171int tm6000_set_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index);
172int tm6000_init (struct tm6000_core *dev);
173int tm6000_init_after_firmware (struct tm6000_core *dev);
174
175int tm6000_init_analog_mode (struct tm6000_core *dev);
176int tm6000_set_standard (struct tm6000_core *dev, v4l2_std_id *norm);
177int tm6000_set_audio_bitrate (struct tm6000_core *dev, int bitrate);
178
179int tm6000_v4l2_register(struct tm6000_core *dev);
180int tm6000_v4l2_unregister(struct tm6000_core *dev);
181int tm6000_v4l2_exit(void);
182void tm6000_set_fourcc_format(struct tm6000_core *dev);
183
184/* In tm6000-i2c.c */
185int tm6000_i2c_register(struct tm6000_core *dev);
186int tm6000_i2c_unregister(struct tm6000_core *dev);
187void tm6000_i2c_call_clients(struct tm6000_core *dev, unsigned int cmd,
188 void *arg);
189
190/* In tm6000-queue.c */
191
192int tm6000_v4l2_mmap(struct file *filp, struct vm_area_struct *vma);
193
194int tm6000_vidioc_streamon(struct file *file, void *priv,
195 enum v4l2_buf_type i);
196int tm6000_vidioc_streamoff(struct file *file, void *priv,
197 enum v4l2_buf_type i);
198int tm6000_vidioc_reqbufs (struct file *file, void *priv,
199 struct v4l2_requestbuffers *rb);
200int tm6000_vidioc_querybuf (struct file *file, void *priv,
201 struct v4l2_buffer *b);
202int tm6000_vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *b);
203int tm6000_vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *b);
204ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
205 loff_t * f_pos);
206unsigned int tm6000_v4l2_poll(struct file *file,
207 struct poll_table_struct *wait);
208int tm6000_queue_init(struct tm6000_core *dev);
209
210/* Debug stuff */
211
212extern int tm6000_debug;
213
214#define dprintk(dev, level, fmt, arg...) do {\
215 if (tm6000_debug & level) \
216 printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \
217 dev->name, __FUNCTION__ , ##arg); } while (0)
218
219#define V4L2_DEBUG_REG 0x0004
220#define V4L2_DEBUG_I2C 0x0008
221#define V4L2_DEBUG_QUEUE 0x0010
222#define V4L2_DEBUG_ISOC 0x0020
223#define V4L2_DEBUG_RES_LOCK 0x0040 /* Resource locking */
224#define V4L2_DEBUG_OPEN 0x0080 /* video open/close debug */
225
226#define tm6000_err(fmt, arg...) do {\
227 printk(KERN_ERR "tm6000 %s :"fmt, \
228 __FUNCTION__ , ##arg); } while (0)
229
230