tm6000.h 10 KB

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