tm6000.h 11 KB

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