tm6000.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. #include <linux/videodev2.h>
  19. #include <media/v4l2-common.h>
  20. #include <media/videobuf-vmalloc.h>
  21. #include "tm6000-usb-isoc.h"
  22. #include <linux/i2c.h>
  23. #include <linux/mutex.h>
  24. #include <media/v4l2-device.h>
  25. #include <media/v4l2-ctrls.h>
  26. #include <media/v4l2-fh.h>
  27. #include <linux/dvb/frontend.h>
  28. #include "dvb_demux.h"
  29. #include "dvb_frontend.h"
  30. #include "dmxdev.h"
  31. /* Inputs */
  32. enum tm6000_itype {
  33. TM6000_INPUT_TV = 1,
  34. TM6000_INPUT_COMPOSITE1,
  35. TM6000_INPUT_COMPOSITE2,
  36. TM6000_INPUT_SVIDEO,
  37. TM6000_INPUT_DVB,
  38. TM6000_INPUT_RADIO,
  39. };
  40. enum tm6000_mux {
  41. TM6000_VMUX_VIDEO_A = 1,
  42. TM6000_VMUX_VIDEO_B,
  43. TM6000_VMUX_VIDEO_AB,
  44. TM6000_AMUX_ADC1,
  45. TM6000_AMUX_ADC2,
  46. TM6000_AMUX_SIF1,
  47. TM6000_AMUX_SIF2,
  48. TM6000_AMUX_I2S,
  49. };
  50. enum tm6000_devtype {
  51. TM6000 = 0,
  52. TM5600,
  53. TM6010,
  54. };
  55. struct tm6000_input {
  56. enum tm6000_itype type;
  57. enum tm6000_mux vmux;
  58. enum tm6000_mux amux;
  59. unsigned int v_gpio;
  60. unsigned int a_gpio;
  61. };
  62. /* ------------------------------------------------------------------
  63. * Basic structures
  64. * ------------------------------------------------------------------
  65. */
  66. struct tm6000_fmt {
  67. char *name;
  68. u32 fourcc; /* v4l2 format id */
  69. int depth;
  70. };
  71. /* buffer for one video frame */
  72. struct tm6000_buffer {
  73. /* common v4l buffer stuff -- must be first */
  74. struct videobuf_buffer vb;
  75. struct tm6000_fmt *fmt;
  76. };
  77. struct tm6000_dmaqueue {
  78. struct list_head active;
  79. struct list_head queued;
  80. /* thread for generating video stream*/
  81. struct task_struct *kthread;
  82. wait_queue_head_t wq;
  83. /* Counters to control fps rate */
  84. int frame;
  85. int ini_jiffies;
  86. };
  87. /* device states */
  88. enum tm6000_core_state {
  89. DEV_INITIALIZED = 0x01,
  90. DEV_DISCONNECTED = 0x02,
  91. DEV_MISCONFIGURED = 0x04,
  92. };
  93. /* io methods */
  94. enum tm6000_io_method {
  95. IO_NONE,
  96. IO_READ,
  97. IO_MMAP,
  98. };
  99. enum tm6000_mode {
  100. TM6000_MODE_UNKNOWN = 0,
  101. TM6000_MODE_ANALOG,
  102. TM6000_MODE_DIGITAL,
  103. };
  104. struct tm6000_gpio {
  105. int tuner_reset;
  106. int tuner_on;
  107. int demod_reset;
  108. int demod_on;
  109. int power_led;
  110. int dvb_led;
  111. int ir;
  112. };
  113. struct tm6000_capabilities {
  114. unsigned int has_tuner:1;
  115. unsigned int has_tda9874:1;
  116. unsigned int has_dvb:1;
  117. unsigned int has_zl10353:1;
  118. unsigned int has_eeprom:1;
  119. unsigned int has_remote:1;
  120. unsigned int has_radio:1;
  121. };
  122. struct tm6000_dvb {
  123. struct dvb_adapter adapter;
  124. struct dvb_demux demux;
  125. struct dvb_frontend *frontend;
  126. struct dmxdev dmxdev;
  127. unsigned int streams;
  128. struct urb *bulk_urb;
  129. struct mutex mutex;
  130. };
  131. struct snd_tm6000_card {
  132. struct snd_card *card;
  133. spinlock_t reg_lock;
  134. struct tm6000_core *core;
  135. struct snd_pcm_substream *substream;
  136. /* temporary data for buffer fill processing */
  137. unsigned buf_pos;
  138. unsigned period_pos;
  139. };
  140. struct tm6000_endpoint {
  141. struct usb_host_endpoint *endp;
  142. __u8 bInterfaceNumber;
  143. __u8 bAlternateSetting;
  144. unsigned maxsize;
  145. };
  146. #define TM6000_QUIRK_NO_USB_DELAY (1 << 0)
  147. struct tm6000_core {
  148. /* generic device properties */
  149. char name[30]; /* name (including minor) of the device */
  150. int model; /* index in the device_data struct */
  151. int devno; /* marks the number of this device */
  152. enum tm6000_devtype dev_type; /* type of device */
  153. unsigned char eedata[256]; /* Eeprom data */
  154. unsigned eedata_size; /* Size of the eeprom info */
  155. v4l2_std_id norm; /* Current norm */
  156. int width, height; /* Selected resolution */
  157. enum tm6000_core_state state;
  158. /* Device Capabilities*/
  159. struct tm6000_capabilities caps;
  160. /* Used to load alsa/dvb */
  161. struct work_struct request_module_wk;
  162. /* Tuner configuration */
  163. int tuner_type; /* type of the tuner */
  164. int tuner_addr; /* tuner address */
  165. struct tm6000_gpio gpio;
  166. char *ir_codes;
  167. __u8 radio;
  168. /* Demodulator configuration */
  169. int demod_addr; /* demodulator address */
  170. int audio_bitrate;
  171. /* i2c i/o */
  172. struct i2c_adapter i2c_adap;
  173. struct i2c_client i2c_client;
  174. /* extension */
  175. struct list_head devlist;
  176. /* video for linux */
  177. int users;
  178. /* various device info */
  179. struct tm6000_fh *resources; /* Points to fh that is streaming */
  180. bool is_res_read;
  181. struct video_device vfd;
  182. struct video_device radio_dev;
  183. struct tm6000_dmaqueue vidq;
  184. struct v4l2_device v4l2_dev;
  185. struct v4l2_ctrl_handler ctrl_handler;
  186. struct v4l2_ctrl_handler radio_ctrl_handler;
  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. /* urb dma buffers */
  216. char **urb_buffer;
  217. dma_addr_t *urb_dma;
  218. unsigned int urb_size;
  219. unsigned long quirks;
  220. };
  221. enum tm6000_ops_type {
  222. TM6000_AUDIO = 0x10,
  223. TM6000_DVB = 0x20,
  224. };
  225. struct tm6000_ops {
  226. struct list_head next;
  227. char *name;
  228. enum tm6000_ops_type type;
  229. int (*init)(struct tm6000_core *);
  230. int (*fini)(struct tm6000_core *);
  231. int (*fillbuf)(struct tm6000_core *, char *buf, int size);
  232. };
  233. struct tm6000_fh {
  234. struct v4l2_fh fh;
  235. struct tm6000_core *dev;
  236. unsigned int radio;
  237. /* video capture */
  238. struct tm6000_fmt *fmt;
  239. unsigned int width, height;
  240. struct videobuf_queue vb_vidq;
  241. enum v4l2_buf_type type;
  242. };
  243. #define TM6000_STD (V4L2_STD_PAL|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc| \
  244. V4L2_STD_PAL_M|V4L2_STD_PAL_60|V4L2_STD_NTSC_M| \
  245. V4L2_STD_NTSC_M_JP|V4L2_STD_SECAM)
  246. /* In tm6000-cards.c */
  247. int tm6000_tuner_callback(void *ptr, int component, int command, int arg);
  248. int tm6000_xc5000_callback(void *ptr, int component, int command, int arg);
  249. int tm6000_cards_setup(struct tm6000_core *dev);
  250. void tm6000_flash_led(struct tm6000_core *dev, u8 state);
  251. /* In tm6000-core.c */
  252. int tm6000_read_write_usb(struct tm6000_core *dev, u8 reqtype, u8 req,
  253. u16 value, u16 index, u8 *buf, u16 len);
  254. int tm6000_get_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  255. int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  256. int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  257. int tm6000_set_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
  258. int tm6000_set_reg_mask(struct tm6000_core *dev, u8 req, u16 value,
  259. u16 index, u16 mask);
  260. int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep);
  261. int tm6000_init(struct tm6000_core *dev);
  262. int tm6000_reset(struct tm6000_core *dev);
  263. int tm6000_init_analog_mode(struct tm6000_core *dev);
  264. int tm6000_init_digital_mode(struct tm6000_core *dev);
  265. int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate);
  266. int tm6000_set_audio_rinput(struct tm6000_core *dev);
  267. int tm6000_tvaudio_set_mute(struct tm6000_core *dev, u8 mute);
  268. void tm6000_set_volume(struct tm6000_core *dev, int vol);
  269. int tm6000_v4l2_register(struct tm6000_core *dev);
  270. int tm6000_v4l2_unregister(struct tm6000_core *dev);
  271. int tm6000_v4l2_exit(void);
  272. void tm6000_set_fourcc_format(struct tm6000_core *dev);
  273. void tm6000_remove_from_devlist(struct tm6000_core *dev);
  274. void tm6000_add_into_devlist(struct tm6000_core *dev);
  275. int tm6000_register_extension(struct tm6000_ops *ops);
  276. void tm6000_unregister_extension(struct tm6000_ops *ops);
  277. void tm6000_init_extension(struct tm6000_core *dev);
  278. void tm6000_close_extension(struct tm6000_core *dev);
  279. int tm6000_call_fillbuf(struct tm6000_core *dev, enum tm6000_ops_type type,
  280. char *buf, int size);
  281. /* In tm6000-stds.c */
  282. void tm6000_get_std_res(struct tm6000_core *dev);
  283. int tm6000_set_standard(struct tm6000_core *dev);
  284. /* In tm6000-i2c.c */
  285. int tm6000_i2c_register(struct tm6000_core *dev);
  286. int tm6000_i2c_unregister(struct tm6000_core *dev);
  287. /* In tm6000-queue.c */
  288. int tm6000_v4l2_mmap(struct file *filp, struct vm_area_struct *vma);
  289. int tm6000_vidioc_streamon(struct file *file, void *priv,
  290. enum v4l2_buf_type i);
  291. int tm6000_vidioc_streamoff(struct file *file, void *priv,
  292. enum v4l2_buf_type i);
  293. int tm6000_vidioc_reqbufs(struct file *file, void *priv,
  294. struct v4l2_requestbuffers *rb);
  295. int tm6000_vidioc_querybuf(struct file *file, void *priv,
  296. struct v4l2_buffer *b);
  297. int tm6000_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b);
  298. int tm6000_vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b);
  299. ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
  300. loff_t *f_pos);
  301. unsigned int tm6000_v4l2_poll(struct file *file,
  302. struct poll_table_struct *wait);
  303. int tm6000_queue_init(struct tm6000_core *dev);
  304. /* In tm6000-alsa.c */
  305. /*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/
  306. /* In tm6000-input.c */
  307. int tm6000_ir_init(struct tm6000_core *dev);
  308. int tm6000_ir_fini(struct tm6000_core *dev);
  309. void tm6000_ir_wait(struct tm6000_core *dev, u8 state);
  310. int tm6000_ir_int_start(struct tm6000_core *dev);
  311. void tm6000_ir_int_stop(struct tm6000_core *dev);
  312. /* Debug stuff */
  313. extern int tm6000_debug;
  314. #define dprintk(dev, level, fmt, arg...) do {\
  315. if (tm6000_debug & level) \
  316. printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \
  317. dev->name, __func__ , ##arg); } while (0)
  318. #define V4L2_DEBUG_REG 0x0004
  319. #define V4L2_DEBUG_I2C 0x0008
  320. #define V4L2_DEBUG_QUEUE 0x0010
  321. #define V4L2_DEBUG_ISOC 0x0020
  322. #define V4L2_DEBUG_RES_LOCK 0x0040 /* Resource locking */
  323. #define V4L2_DEBUG_OPEN 0x0080 /* video open/close debug */
  324. #define tm6000_err(fmt, arg...) do {\
  325. printk(KERN_ERR "tm6000 %s :"fmt, \
  326. __func__ , ##arg); } while (0)