tm6000.h 11 KB

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