au0828.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Driver for the Auvitek AU0828 USB bridge
  3. *
  4. * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/usb.h>
  22. #include <linux/i2c.h>
  23. #include <linux/i2c-algo-bit.h>
  24. #include <media/tveeprom.h>
  25. /* Analog */
  26. #include <linux/videodev2.h>
  27. #include <media/videobuf-vmalloc.h>
  28. /* DVB */
  29. #include "demux.h"
  30. #include "dmxdev.h"
  31. #include "dvb_demux.h"
  32. #include "dvb_frontend.h"
  33. #include "dvb_net.h"
  34. #include "dvbdev.h"
  35. #include "au0828-reg.h"
  36. #include "au0828-cards.h"
  37. #define DRIVER_NAME "au0828"
  38. #define URB_COUNT 16
  39. #define URB_BUFSIZE (0xe522)
  40. /* Analog constants */
  41. #define NTSC_STD_W 720
  42. #define NTSC_STD_H 480
  43. #define AU0828_INTERLACED_DEFAULT 1
  44. #define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
  45. /* Defination for AU0828 USB transfer */
  46. #define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
  47. #define AU0828_ISO_PACKETS_PER_URB 10
  48. #define AU0828_ISO_MAX_FRAME_SIZE (3 * 1024)
  49. #define AU0828_ISO_BUFFER_SIZE (AU0828_ISO_PACKETS_PER_URB * AU0828_ISO_MAX_FRAME_SIZE)
  50. #define AU0828_MIN_BUF 4
  51. #define AU0828_DEF_BUF 8
  52. #define AU0828_MAX_IMAGES 10
  53. #define AU0828_FRAME_SIZE (1028 * 1024 * 4)
  54. #define AU0828_URB_TIMEOUT msecs_to_jiffies(AU0828_MAX_ISO_BUFS * AU0828_ISO_PACKETS_PER_URB)
  55. #define AU0828_MAX_INPUT 4
  56. enum au0828_itype {
  57. AU0828_VMUX_COMPOSITE = 1,
  58. AU0828_VMUX_SVIDEO,
  59. AU0828_VMUX_CABLE,
  60. AU0828_VMUX_TELEVISION,
  61. AU0828_VMUX_DVB,
  62. AU0828_VMUX_DEBUG
  63. };
  64. struct au0828_input {
  65. enum au0828_itype type;
  66. unsigned int vmux;
  67. unsigned int amux;
  68. void (*audio_setup) (void *priv, int enable);
  69. };
  70. struct au0828_board {
  71. char *name;
  72. struct au0828_input input[AU0828_MAX_INPUT];
  73. };
  74. struct au0828_dvb {
  75. struct mutex lock;
  76. struct dvb_adapter adapter;
  77. struct dvb_frontend *frontend;
  78. struct dvb_demux demux;
  79. struct dmxdev dmxdev;
  80. struct dmx_frontend fe_hw;
  81. struct dmx_frontend fe_mem;
  82. struct dvb_net net;
  83. int feeding;
  84. };
  85. enum au0828_stream_state {
  86. STREAM_OFF,
  87. STREAM_INTERRUPT,
  88. STREAM_ON
  89. };
  90. #define AUVI_INPUT(nr) (&au0828_boards[dev->board].input[nr])
  91. /* device state */
  92. enum au0828_dev_state {
  93. DEV_INITIALIZED = 0x01,
  94. DEV_DISCONNECTED = 0x02,
  95. DEV_MISCONFIGURED = 0x04
  96. };
  97. struct au0828_fh {
  98. struct au0828_dev *dev;
  99. unsigned int stream_on:1; /* Locks streams */
  100. struct videobuf_queue vb_vidq;
  101. enum v4l2_buf_type type;
  102. };
  103. struct au0828_usb_isoc_ctl {
  104. /* max packet size of isoc transaction */
  105. int max_pkt_size;
  106. /* number of allocated urbs */
  107. int num_bufs;
  108. /* urb for isoc transfers */
  109. struct urb **urb;
  110. /* transfer buffers for isoc transfer */
  111. char **transfer_buffer;
  112. /* Last buffer command and region */
  113. u8 cmd;
  114. int pos, size, pktsize;
  115. /* Last field: ODD or EVEN? */
  116. int field;
  117. /* Stores incomplete commands */
  118. u32 tmp_buf;
  119. int tmp_buf_len;
  120. /* Stores already requested buffers */
  121. struct au0828_buffer *buf;
  122. /* Stores the number of received fields */
  123. int nfields;
  124. /* isoc urb callback */
  125. int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
  126. };
  127. /* buffer for one video frame */
  128. struct au0828_buffer {
  129. /* common v4l buffer stuff -- must be first */
  130. struct videobuf_buffer vb;
  131. struct list_head frame;
  132. int top_field;
  133. int receiving;
  134. };
  135. struct au0828_dmaqueue {
  136. struct list_head active;
  137. struct list_head queued;
  138. wait_queue_head_t wq;
  139. /* Counters to control buffer fill */
  140. int pos;
  141. };
  142. struct au0828_dev {
  143. struct mutex mutex;
  144. struct usb_device *usbdev;
  145. int board;
  146. u8 ctrlmsg[64];
  147. /* I2C */
  148. struct i2c_adapter i2c_adap;
  149. struct i2c_algo_bit_data i2c_algo;
  150. struct i2c_client i2c_client;
  151. u32 i2c_rc;
  152. /* Digital */
  153. struct au0828_dvb dvb;
  154. /* Analog */
  155. struct list_head au0828list;
  156. int users;
  157. unsigned int stream_on:1; /* Locks streams */
  158. struct video_device *vdev;
  159. struct video_device *vbi_dev;
  160. int width;
  161. int height;
  162. u32 field_size;
  163. u32 frame_size;
  164. u32 bytesperline;
  165. int type;
  166. u8 ctrl_ainput;
  167. __u8 isoc_in_endpointaddr;
  168. u8 isoc_init_ok;
  169. int greenscreen_detected;
  170. unsigned int frame_count;
  171. int ctrl_freq;
  172. int input_type;
  173. unsigned int ctrl_input;
  174. enum au0828_dev_state dev_state;
  175. enum au0828_stream_state stream_state;
  176. wait_queue_head_t open;
  177. struct mutex lock;
  178. /* Isoc control struct */
  179. struct au0828_dmaqueue vidq;
  180. struct au0828_usb_isoc_ctl isoc_ctl;
  181. spinlock_t slock;
  182. /* usb transfer */
  183. int alt; /* alternate */
  184. int max_pkt_size; /* max packet size of isoc transaction */
  185. int num_alt; /* Number of alternative settings */
  186. unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
  187. struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */
  188. char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
  189. transfer */
  190. /* USB / URB Related */
  191. int urb_streaming;
  192. struct urb *urbs[URB_COUNT];
  193. };
  194. /* ----------------------------------------------------------- */
  195. #define au0828_read(dev, reg) au0828_readreg(dev, reg)
  196. #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
  197. #define au0828_andor(dev, reg, mask, value) \
  198. au0828_writereg(dev, reg, \
  199. (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
  200. #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
  201. #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
  202. /* ----------------------------------------------------------- */
  203. /* au0828-core.c */
  204. extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
  205. extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
  206. extern int au0828_debug;
  207. /* ----------------------------------------------------------- */
  208. /* au0828-cards.c */
  209. extern struct au0828_board au0828_boards[];
  210. extern struct usb_device_id au0828_usb_id_table[];
  211. extern void au0828_gpio_setup(struct au0828_dev *dev);
  212. extern int au0828_tuner_callback(void *priv, int component,
  213. int command, int arg);
  214. extern void au0828_card_setup(struct au0828_dev *dev);
  215. /* ----------------------------------------------------------- */
  216. /* au0828-i2c.c */
  217. extern int au0828_i2c_register(struct au0828_dev *dev);
  218. extern int au0828_i2c_unregister(struct au0828_dev *dev);
  219. extern void au0828_call_i2c_clients(struct au0828_dev *dev,
  220. unsigned int cmd, void *arg);
  221. /* ----------------------------------------------------------- */
  222. /* au0828-video.c */
  223. int au0828_analog_register(struct au0828_dev *dev);
  224. int au0828_analog_stream_disable(struct au0828_dev *d);
  225. void au0828_analog_unregister(struct au0828_dev *dev);
  226. /* ----------------------------------------------------------- */
  227. /* au0828-dvb.c */
  228. extern int au0828_dvb_register(struct au0828_dev *dev);
  229. extern void au0828_dvb_unregister(struct au0828_dev *dev);
  230. #define dprintk(level, fmt, arg...)\
  231. do { if (au0828_debug & level)\
  232. printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
  233. } while (0)