2 tm6000.h - driver for TM5600/TM6000 USB video capture devices
4 Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
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
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.
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.
20 // Use the tm6000-hack, instead of the proper initialization code
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>
30 #define TM6000_VERSION KERNEL_VERSION(0, 0, 1)
33 #define TM6000_INPUT_TV 0
34 #define TM6000_INPUT_COMPOSITE 1
35 #define TM6000_INPUT_SVIDEO 2
37 /* ------------------------------------------------------------------
39 ------------------------------------------------------------------*/
43 u32 fourcc; /* v4l2 format id */
47 /* buffer for one video frame */
48 struct tm6000_buffer {
49 /* common v4l buffer stuff -- must be first */
50 struct videobuf_buffer vb;
52 struct tm6000_fmt *fmt;
55 struct tm6000_dmaqueue {
56 struct list_head active;
57 struct list_head queued;
58 struct timer_list timeout;
60 /* thread for generating video stream*/
61 struct task_struct *kthread;
63 /* Counters to control fps rate */
69 enum tm6000_core_state {
70 DEV_INITIALIZED = 0x01,
71 DEV_DISCONNECTED = 0x02,
72 DEV_MISCONFIGURED = 0x04,
76 enum tm6000_io_method {
83 TM6000_MODE_UNKNOWN=0,
88 struct 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;
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 */
103 enum tm6000_core_state state;
105 /* Device Capabilities*/
106 struct tm6000_capabilities caps;
108 /* Tuner configuration */
109 int tuner_type; /* type of the tuner */
110 int tuner_addr; /* tuner address */
113 struct i2c_adapter i2c_adap;
114 struct i2c_client i2c_client;
116 /* video for linux */
117 struct list_head tm6000_corelist;
120 /* various device info */
121 unsigned int resources;
122 struct video_device *vfd;
123 struct tm6000_dmaqueue vidq;
129 enum tm6000_mode mode;
135 struct usb_device *udev; /* the usb device */
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;
141 /* scaler!=0 if scaler is active*/
144 /* Isoc control struct */
145 struct usb_isoc_ctl isoc_ctl;
151 struct tm6000_core *dev;
154 struct tm6000_fmt *fmt;
155 unsigned int width,height;
156 struct videobuf_queue vb_vidq;
158 enum v4l2_buf_type type;
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
165 /* In tm6000-core.c */
166 extern unsigned long tm6000_devused;
168 int tm6000_read_write_usb (struct tm6000_core *dev, u8 reqtype, u8 req,
169 u16 value, u16 index, u8 *buf, u16 len);
170 int tm6000_get_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index);
171 int tm6000_set_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index);
172 int tm6000_init (struct tm6000_core *dev);
173 int tm6000_init_after_firmware (struct tm6000_core *dev);
175 int tm6000_init_analog_mode (struct tm6000_core *dev);
176 int tm6000_set_standard (struct tm6000_core *dev, v4l2_std_id *norm);
177 int tm6000_set_audio_bitrate (struct tm6000_core *dev, int bitrate);
179 int tm6000_v4l2_register(struct tm6000_core *dev);
180 int tm6000_v4l2_unregister(struct tm6000_core *dev);
181 int tm6000_v4l2_exit(void);
182 void tm6000_set_fourcc_format(struct tm6000_core *dev);
184 /* In tm6000-i2c.c */
185 int tm6000_i2c_register(struct tm6000_core *dev);
186 int tm6000_i2c_unregister(struct tm6000_core *dev);
187 void tm6000_i2c_call_clients(struct tm6000_core *dev, unsigned int cmd,
190 /* In tm6000-queue.c */
192 int tm6000_v4l2_mmap(struct file *filp, struct vm_area_struct *vma);
194 int tm6000_vidioc_streamon(struct file *file, void *priv,
195 enum v4l2_buf_type i);
196 int tm6000_vidioc_streamoff(struct file *file, void *priv,
197 enum v4l2_buf_type i);
198 int tm6000_vidioc_reqbufs (struct file *file, void *priv,
199 struct v4l2_requestbuffers *rb);
200 int tm6000_vidioc_querybuf (struct file *file, void *priv,
201 struct v4l2_buffer *b);
202 int tm6000_vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *b);
203 int tm6000_vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *b);
204 ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
206 unsigned int tm6000_v4l2_poll(struct file *file,
207 struct poll_table_struct *wait);
208 int tm6000_queue_init(struct tm6000_core *dev);
212 extern int tm6000_debug;
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)
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 */
226 #define tm6000_err(fmt, arg...) do {\
227 printk(KERN_ERR "tm6000 %s :"fmt, \
228 __FUNCTION__ , ##arg); } while (0)