stk1160.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * STK1160 driver
  3. *
  4. * Copyright (C) 2012 Ezequiel Garcia
  5. * <elezegarcia--a.t--gmail.com>
  6. *
  7. * Based on Easycap driver by R.M. Thomas
  8. * Copyright (C) 2010 R.M. Thomas
  9. * <rmthomas--a.t--sciolus.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. */
  22. #include <linux/i2c.h>
  23. #include <sound/core.h>
  24. #include <sound/ac97_codec.h>
  25. #include <media/videobuf2-v4l2.h>
  26. #include <media/v4l2-device.h>
  27. #include <media/v4l2-ctrls.h>
  28. #define STK1160_VERSION "0.9.5"
  29. #define STK1160_VERSION_NUM 0x000905
  30. /* Decide on number of packets for each buffer */
  31. #define STK1160_NUM_PACKETS 64
  32. /* Number of buffers for isoc transfers */
  33. #define STK1160_NUM_BUFS 16
  34. #define STK1160_MIN_BUFS 1
  35. /* TODO: This endpoint address should be retrieved */
  36. #define STK1160_EP_VIDEO 0x82
  37. #define STK1160_EP_AUDIO 0x81
  38. /* Max and min video buffers */
  39. #define STK1160_MIN_VIDEO_BUFFERS 8
  40. #define STK1160_MAX_VIDEO_BUFFERS 32
  41. #define STK1160_MIN_PKT_SIZE 3072
  42. #define STK1160_MAX_INPUT 4
  43. #define STK1160_SVIDEO_INPUT 4
  44. #define STK1160_I2C_TIMEOUT 100
  45. /* TODO: Print helpers
  46. * I could use dev_xxx, pr_xxx, v4l2_xxx or printk.
  47. * However, there isn't a solid consensus on which
  48. * new drivers should use.
  49. *
  50. */
  51. #ifdef DEBUG
  52. #define stk1160_dbg(fmt, args...) \
  53. printk(KERN_DEBUG "stk1160: " fmt, ## args)
  54. #else
  55. #define stk1160_dbg(fmt, args...)
  56. #endif
  57. #define stk1160_info(fmt, args...) \
  58. pr_info("stk1160: " fmt, ## args)
  59. #define stk1160_warn(fmt, args...) \
  60. pr_warn("stk1160: " fmt, ## args)
  61. #define stk1160_err(fmt, args...) \
  62. pr_err("stk1160: " fmt, ## args)
  63. /* Buffer for one video frame */
  64. struct stk1160_buffer {
  65. /* common v4l buffer stuff -- must be first */
  66. struct vb2_v4l2_buffer vb;
  67. struct list_head list;
  68. void *mem;
  69. unsigned int length; /* buffer length */
  70. unsigned int bytesused; /* bytes written */
  71. int odd; /* current oddity */
  72. /*
  73. * Since we interlace two fields per frame,
  74. * this is different from bytesused.
  75. */
  76. unsigned int pos; /* current pos inside buffer */
  77. };
  78. struct stk1160_isoc_ctl {
  79. /* max packet size of isoc transaction */
  80. int max_pkt_size;
  81. /* number of allocated urbs */
  82. int num_bufs;
  83. /* urb for isoc transfers */
  84. struct urb **urb;
  85. /* transfer buffers for isoc transfer */
  86. char **transfer_buffer;
  87. /* current buffer */
  88. struct stk1160_buffer *buf;
  89. };
  90. struct stk1160_fmt {
  91. char *name;
  92. u32 fourcc; /* v4l2 format id */
  93. int depth;
  94. };
  95. struct stk1160 {
  96. struct v4l2_device v4l2_dev;
  97. struct video_device vdev;
  98. struct v4l2_ctrl_handler ctrl_handler;
  99. struct device *dev;
  100. struct usb_device *udev;
  101. /* saa7115 subdev */
  102. struct v4l2_subdev *sd_saa7115;
  103. /* isoc control struct */
  104. struct list_head avail_bufs;
  105. /* video capture */
  106. struct vb2_queue vb_vidq;
  107. /* max packet size of isoc transaction */
  108. int max_pkt_size;
  109. /* array of wMaxPacketSize */
  110. unsigned int *alt_max_pkt_size;
  111. /* alternate */
  112. int alt;
  113. /* Number of alternative settings */
  114. int num_alt;
  115. struct stk1160_isoc_ctl isoc_ctl;
  116. /* frame properties */
  117. int width; /* current frame width */
  118. int height; /* current frame height */
  119. unsigned int ctl_input; /* selected input */
  120. v4l2_std_id norm; /* current norm */
  121. struct stk1160_fmt *fmt; /* selected format */
  122. unsigned int sequence;
  123. /* i2c i/o */
  124. struct i2c_adapter i2c_adap;
  125. struct i2c_client i2c_client;
  126. struct mutex v4l_lock;
  127. struct mutex vb_queue_lock;
  128. spinlock_t buf_lock;
  129. struct file *fh_owner; /* filehandle ownership */
  130. /* EXPERIMENTAL */
  131. struct snd_card *snd_card;
  132. };
  133. struct regval {
  134. u16 reg;
  135. u16 val;
  136. };
  137. /* Provided by stk1160-v4l.c */
  138. int stk1160_vb2_setup(struct stk1160 *dev);
  139. int stk1160_video_register(struct stk1160 *dev);
  140. void stk1160_video_unregister(struct stk1160 *dev);
  141. void stk1160_clear_queue(struct stk1160 *dev);
  142. /* Provided by stk1160-video.c */
  143. int stk1160_alloc_isoc(struct stk1160 *dev);
  144. void stk1160_free_isoc(struct stk1160 *dev);
  145. void stk1160_cancel_isoc(struct stk1160 *dev);
  146. void stk1160_uninit_isoc(struct stk1160 *dev);
  147. /* Provided by stk1160-i2c.c */
  148. int stk1160_i2c_register(struct stk1160 *dev);
  149. int stk1160_i2c_unregister(struct stk1160 *dev);
  150. /* Provided by stk1160-core.c */
  151. int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value);
  152. int stk1160_write_reg(struct stk1160 *dev, u16 reg, u16 value);
  153. int stk1160_write_regs_req(struct stk1160 *dev, u8 req, u16 reg,
  154. char *buf, int len);
  155. int stk1160_read_reg_req_len(struct stk1160 *dev, u8 req, u16 reg,
  156. char *buf, int len);
  157. void stk1160_select_input(struct stk1160 *dev);
  158. /* Provided by stk1160-ac97.c */
  159. #ifdef CONFIG_VIDEO_STK1160_AC97
  160. int stk1160_ac97_register(struct stk1160 *dev);
  161. int stk1160_ac97_unregister(struct stk1160 *dev);
  162. #else
  163. static inline int stk1160_ac97_register(struct stk1160 *dev) { return 0; }
  164. static inline int stk1160_ac97_unregister(struct stk1160 *dev) { return 0; }
  165. #endif