tm6000.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. * tm6000.h - driver for TM5600/TM6000/TM6010 USB video capture devices
  3. *
  4. * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
  5. *
  6. * Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
  7. * - DVB-T support
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/videodev2.h>
  23. #include <media/v4l2-common.h>
  24. #include <media/videobuf-vmalloc.h>
  25. #include "tm6000-usb-isoc.h"
  26. #include <linux/i2c.h>
  27. #include <linux/mutex.h>
  28. #include <media/v4l2-device.h>
  29. #include <linux/dvb/frontend.h>
  30. #include "dvb_demux.h"
  31. #include "dvb_frontend.h"
  32. #include "dmxdev.h"
  33. /* Inputs */
  34. enum tm6000_itype {
  35. TM6000_INPUT_TV = 1,
  36. TM6000_INPUT_COMPOSITE1,
  37. TM6000_INPUT_COMPOSITE2,
  38. TM6000_INPUT_SVIDEO,
  39. TM6000_INPUT_DVB,
  40. TM6000_INPUT_RADIO,
  41. };
  42. enum tm6000_mux {
  43. TM6000_VMUX_VIDEO_A = 1,
  44. TM6000_VMUX_VIDEO_B,
  45. TM6000_VMUX_VIDEO_AB,
  46. TM6000_AMUX_ADC1,
  47. TM6000_AMUX_ADC2,
  48. TM6000_AMUX_SIF1,
  49. TM6000_AMUX_SIF2,
  50. TM6000_AMUX_I2S,
  51. };
  52. enum tm6000_devtype {
  53. TM6000 = 0,
  54. TM5600,
  55. TM6010,
  56. };
  57. struct tm6000_input {
  58. enum tm6000_itype type;
  59. enum tm6000_mux vmux;
  60. enum tm6000_mux amux;
  61. unsigned int v_gpio;
  62. unsigned int a_gpio;
  63. };
  64. /* ------------------------------------------------------------------
  65. * Basic structures
  66. * ------------------------------------------------------------------
  67. */
  68. struct tm6000_fmt {
  69. char *name;
  70. u32 fourcc; /* v4l2 format id */
  71. int depth;
  72. };
  73. /* buffer for one video frame */
  74. struct tm6000_buffer {
  75. /* common v4l buffer stuff -- must be first */
  76. struct videobuf_buffer vb;
  77. struct tm6000_fmt *fmt;
  78. };
  79. struct tm6000_dmaqueue {
  80. struct list_head active;
  81. struct list_head queued;
  82. /* thread for generating video stream*/
  83. struct task_struct *kthread;
  84. wait_queue_head_t wq;
  85. /* Counters to control fps rate */
  86. int frame;
  87. int ini_jiffies;
  88. };
  89. /* device states */
  90. enum tm6000_core_state {
  91. DEV_INITIALIZED = 0x01,
  92. DEV_DISCONNECTED = 0x02,
  93. DEV_MISCONFIGURED = 0x04,
  94. };
  95. /* io methods */
  96. enum tm6000_io_method {
  97. IO_NONE,
  98. IO_READ,
  99. IO_MMAP,
  100. };
  101. enum tm6000_mode {
  102. TM6000_MODE_UNKNOWN = 0,
  103. TM6000_MODE_ANALOG,
  104. TM6000_MODE_DIGITAL,
  105. };
  106. struct tm6000_gpio {
  107. int tuner_reset;
  108. int tuner_on;
  109. int demod_reset;
  110. int demod_on;
  111. int power_led;
  112. int dvb_led;
  113. int ir;
  114. };
  115. struct tm6000_capabilities {
  116. unsigned int has_tuner:1;
  117. unsigned int has_tda9874:1;
  118. unsigned int has_dvb:1;
  119. unsigned int has_zl10353:1;
  120. unsigned int has_eeprom:1;
  121. unsigned int has_remote:1;
  122. unsigned int has_radio:1;
  123. };
  124. struct tm6000_dvb {
  125. struct dvb_adapter adapter;
  126. struct dvb_demux demux;
  127. struct dvb_frontend *frontend;
  128. struct dmxdev dmxdev;
  129. unsigned int streams;
  130. struct urb *bulk_urb;
  131. struct mutex mutex;
  132. };
  133. struct snd_tm6000_card {
  134. struct snd_card *card;
  135. spinlock_t reg_lock;
  136. struct tm6000_core *core;
  137. struct snd_pcm_substream *substream;
  138. /* temporary data for buffer fill processing */
  139. unsigned buf_pos;
  140. unsigned period_pos;
  141. };
  142. struct tm6000_endpoint {
  143. struct usb_host_endpoint *endp;
  144. __u8 bInterfaceNumber;
  145. __u8 bAlternateSetting;
  146. unsigned maxsize;
  147. };
  148. #define TM6000_QUIRK_NO_USB_DELAY (1 << 0)
  149. struct tm6000_core {
  150. /* generic device properties */
  151. char name[30]; /* name (including minor) of the device */
  152. int model; /* index in the device_data struct */
  153. int devno; /* marks the number of this device */
  154. enum tm6000_devtype dev_type; /* type of device */
  155. unsigned char eedata[256]; /* Eeprom data */
  156. unsigned eedata_size; /* Size of the eeprom info */
  157. v4l2_std_id norm; /* Current norm */
  158. int width, height; /* Selected resolution */
  159. enum tm6000_core_state state;
  160. /* Device Capabilities*/
  161. struct tm6000_capabilities caps;
  162. /* Used to load alsa/dvb */
  163. struct work_struct request_module_wk;
  164. /* Tuner configuration */
  165. int tuner_type; /* type of the tuner */
  166. int tuner_addr; /* tuner address */
  167. struct tm6000_gpio gpio;
  168. char *ir_codes;
  169. __u8 radio;
  170. /* Demodulator configuration */
  171. int demod_addr; /* demodulator address */
  172. int audio_bitrate;
  173. /* i2c i/o */
  174. struct i2c_adapter i2c_adap;
  175. struct i2c_client i2c_client;
  176. /* extension */
  177. struct list_head devlist;
  178. /* video for linux */
  179. int users;
  180. /* various device info */
  181. struct tm6000_fh *resources; /* Points to fh that is streaming */
  182. bool is_res_read;
  183. struct video_device *vfd;
  184. struct video_device *radio_dev;
  185. struct tm6000_dmaqueue vidq;
  186. struct v4l2_device v4l2_dev;
  187. int input;
  188. struct tm6000_input vinput[3]; /* video input */
  189. struct tm6000_input rinput; /* radio input */
  190. int freq;
  191. unsigned int fourcc;
  192. enum tm6000_mode mode;
  193. int ctl_mute; /* audio */
  194. int ctl_volume;
  195. int amode;
  196. /* DVB-T support */
  197. struct tm6000_dvb *dvb;
  198. /* audio support */
  199. struct snd_tm6000_card *adev;
  200. struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
  201. atomic_t stream_started; /* stream should be running if true */
  202. struct tm6000_IR *ir;
  203. /* locks */
  204. struct mutex lock;
  205. struct mutex usb_lock;
  206. /* usb transfer */
  207. struct usb_device *udev; /* the usb device */
  208. struct tm6000_endpoint bulk_in, bulk_out, isoc_in, isoc_out;
  209. struct tm6000_endpoint int_in, int_out;
  210. /* scaler!=0 if scaler is active*/
  211. int scaler;
  212. /* Isoc control struct */
  213. struct usb_isoc_ctl isoc_ctl;
  214. spinlock_t slock;
  215. unsigned long quirks;
  216. };
  217. enum tm6000_ops_type {
  218. TM6000_AUDIO = 0x10,
  219. TM6000_DVB = 0x20,
  220. };
  221. struct tm6000_ops {
  222. struct list_head next;
  223. char *name;
  224. enum tm6000_ops_type type;
  225. int (*init)(struct tm6000_core *);
  226. int (*fini)(struct tm6000_core *);
  227. int (*fillbuf)(struct tm6000_core *, char *buf, int size);
  228. };
  229. struct tm6000_fh {
  230. struct tm6000_core *dev;
  231. unsigned int radio;
  232. /* video capture */
  233. struct tm6000_fmt *fmt;
  234. unsigned int width, height;
  235. struct videobuf_queue vb_vidq;
  236. enum v4l2_buf_type type;
  237. };
  238. #define TM6000_STD (V4L2_STD_PAL|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc| \
  239. V4L2_STD_PAL_M|V4L2_STD_PAL_60|V4L2_STD_NTSC_M| \
  240. V4L2_STD_NTSC_M_JP|V4L2_STD_SECAM)
  241. /* In tm6000-cards.c */
  242. int tm6000_tuner_callback(void *ptr, int component, int command, int arg);
  243. int tm6000_xc5000_callback(void *ptr, int component, int command, int arg);
  244. int tm6000_cards_setup(struct tm6000_core *dev);
  245. void tm6000_flash_led(struct tm6000_core *dev, u8 state);
  246. /* In tm6000-core.c */
  247. int tm6000_read_write_usb(struct tm6000_core *dev, u8 reqtype, u8 req,
  248. u16 value, u16 index, u8 *buf, u16 len);
  249. int tm6000_get_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  250. int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  251. int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  252. int tm6000_set_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  253. int tm6000_set_reg_mask(struct tm6000_core *dev, u8 req, u16 value,
  254. u16 index, u16 mask);
  255. int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep);
  256. int tm6000_init(struct tm6000_core *dev);
  257. int tm6000_reset(struct tm6000_core *dev);
  258. int tm6000_init_analog_mode(struct tm6000_core *dev);
  259. int tm6000_init_digital_mode(struct tm6000_core *dev);
  260. int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate);
  261. int tm6000_set_audio_rinput(struct tm6000_core *dev);
  262. int tm6000_tvaudio_set_mute(struct tm6000_core *dev, u8 mute);
  263. void tm6000_set_volume(struct tm6000_core *dev, int vol);
  264. int tm6000_v4l2_register(struct tm6000_core *dev);
  265. int tm6000_v4l2_unregister(struct tm6000_core *dev);
  266. int tm6000_v4l2_exit(void);
  267. void tm6000_set_fourcc_format(struct tm6000_core *dev);
  268. void tm6000_remove_from_devlist(struct tm6000_core *dev);
  269. void tm6000_add_into_devlist(struct tm6000_core *dev);
  270. int tm6000_register_extension(struct tm6000_ops *ops);
  271. void tm6000_unregister_extension(struct tm6000_ops *ops);
  272. void tm6000_init_extension(struct tm6000_core *dev);
  273. void tm6000_close_extension(struct tm6000_core *dev);
  274. int tm6000_call_fillbuf(struct tm6000_core *dev, enum tm6000_ops_type type,
  275. char *buf, int size);
  276. /* In tm6000-stds.c */
  277. void tm6000_get_std_res(struct tm6000_core *dev);
  278. int tm6000_set_standard(struct tm6000_core *dev);
  279. /* In tm6000-i2c.c */
  280. int tm6000_i2c_register(struct tm6000_core *dev);
  281. int tm6000_i2c_unregister(struct tm6000_core *dev);
  282. /* In tm6000-queue.c */
  283. int tm6000_v4l2_mmap(struct file *filp, struct vm_area_struct *vma);
  284. int tm6000_vidioc_streamon(struct file *file, void *priv,
  285. enum v4l2_buf_type i);
  286. int tm6000_vidioc_streamoff(struct file *file, void *priv,
  287. enum v4l2_buf_type i);
  288. int tm6000_vidioc_reqbufs(struct file *file, void *priv,
  289. struct v4l2_requestbuffers *rb);
  290. int tm6000_vidioc_querybuf(struct file *file, void *priv,
  291. struct v4l2_buffer *b);
  292. int tm6000_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b);
  293. int tm6000_vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b);
  294. ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
  295. loff_t *f_pos);
  296. unsigned int tm6000_v4l2_poll(struct file *file,
  297. struct poll_table_struct *wait);
  298. int tm6000_queue_init(struct tm6000_core *dev);
  299. /* In tm6000-alsa.c */
  300. /*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/
  301. /* In tm6000-input.c */
  302. int tm6000_ir_init(struct tm6000_core *dev);
  303. int tm6000_ir_fini(struct tm6000_core *dev);
  304. void tm6000_ir_wait(struct tm6000_core *dev, u8 state);
  305. int tm6000_ir_int_start(struct tm6000_core *dev);
  306. void tm6000_ir_int_stop(struct tm6000_core *dev);
  307. /* Debug stuff */
  308. extern int tm6000_debug;
  309. #define dprintk(dev, level, fmt, arg...) do {\
  310. if (tm6000_debug & level) \
  311. printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \
  312. dev->name, __func__ , ##arg); } while (0)
  313. #define V4L2_DEBUG_REG 0x0004
  314. #define V4L2_DEBUG_I2C 0x0008
  315. #define V4L2_DEBUG_QUEUE 0x0010
  316. #define V4L2_DEBUG_ISOC 0x0020
  317. #define V4L2_DEBUG_RES_LOCK 0x0040 /* Resource locking */
  318. #define V4L2_DEBUG_OPEN 0x0080 /* video open/close debug */
  319. #define tm6000_err(fmt, arg...) do {\
  320. printk(KERN_ERR "tm6000 %s :"fmt, \
  321. __func__ , ##arg); } while (0)