stk1160.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_AC97_TIMEOUT 50
  45. #define STK1160_I2C_TIMEOUT 100
  46. /* TODO: Print helpers
  47. * I could use dev_xxx, pr_xxx, v4l2_xxx or printk.
  48. * However, there isn't a solid consensus on which
  49. * new drivers should use.
  50. *
  51. */
  52. #ifdef DEBUG
  53. #define stk1160_dbg(fmt, args...) \
  54. printk(KERN_DEBUG "stk1160: " fmt, ## args)
  55. #else
  56. #define stk1160_dbg(fmt, args...)
  57. #endif
  58. #define stk1160_info(fmt, args...) \
  59. pr_info("stk1160: " fmt, ## args)
  60. #define stk1160_warn(fmt, args...) \
  61. pr_warn("stk1160: " fmt, ## args)
  62. #define stk1160_err(fmt, args...) \
  63. pr_err("stk1160: " fmt, ## args)
  64. /* Buffer for one video frame */
  65. struct stk1160_buffer {
  66. /* common v4l buffer stuff -- must be first */
  67. struct vb2_v4l2_buffer vb;
  68. struct list_head list;
  69. void *mem;
  70. unsigned int length; /* buffer length */
  71. unsigned int bytesused; /* bytes written */
  72. int odd; /* current oddity */
  73. /*
  74. * Since we interlace two fields per frame,
  75. * this is different from bytesused.
  76. */
  77. unsigned int pos; /* current pos inside buffer */
  78. };
  79. struct stk1160_isoc_ctl {
  80. /* max packet size of isoc transaction */
  81. int max_pkt_size;
  82. /* number of allocated urbs */
  83. int num_bufs;
  84. /* urb for isoc transfers */
  85. struct urb **urb;
  86. /* transfer buffers for isoc transfer */
  87. char **transfer_buffer;
  88. /* current buffer */
  89. struct stk1160_buffer *buf;
  90. };
  91. struct stk1160_fmt {
  92. char *name;
  93. u32 fourcc; /* v4l2 format id */
  94. int depth;
  95. };
  96. struct stk1160 {
  97. struct v4l2_device v4l2_dev;
  98. struct video_device vdev;
  99. struct v4l2_ctrl_handler ctrl_handler;
  100. struct device *dev;
  101. struct usb_device *udev;
  102. /* saa7115 subdev */
  103. struct v4l2_subdev *sd_saa7115;
  104. /* isoc control struct */
  105. struct list_head avail_bufs;
  106. /* video capture */
  107. struct vb2_queue vb_vidq;
  108. /* max packet size of isoc transaction */
  109. int max_pkt_size;
  110. /* array of wMaxPacketSize */
  111. unsigned int *alt_max_pkt_size;
  112. /* alternate */
  113. int alt;
  114. /* Number of alternative settings */
  115. int num_alt;
  116. struct stk1160_isoc_ctl isoc_ctl;
  117. /* frame properties */
  118. int width; /* current frame width */
  119. int height; /* current frame height */
  120. unsigned int ctl_input; /* selected input */
  121. v4l2_std_id norm; /* current norm */
  122. struct stk1160_fmt *fmt; /* selected format */
  123. unsigned int sequence;
  124. /* i2c i/o */
  125. struct i2c_adapter i2c_adap;
  126. struct i2c_client i2c_client;
  127. struct mutex v4l_lock;
  128. struct mutex vb_queue_lock;
  129. spinlock_t buf_lock;
  130. struct file *fh_owner; /* filehandle ownership */
  131. /* EXPERIMENTAL */
  132. struct snd_card *snd_card;
  133. };
  134. struct regval {
  135. u16 reg;
  136. u16 val;
  137. };
  138. /* Provided by stk1160-v4l.c */
  139. int stk1160_vb2_setup(struct stk1160 *dev);
  140. int stk1160_video_register(struct stk1160 *dev);
  141. void stk1160_video_unregister(struct stk1160 *dev);
  142. void stk1160_clear_queue(struct stk1160 *dev);
  143. /* Provided by stk1160-video.c */
  144. int stk1160_alloc_isoc(struct stk1160 *dev);
  145. void stk1160_free_isoc(struct stk1160 *dev);
  146. void stk1160_cancel_isoc(struct stk1160 *dev);
  147. void stk1160_uninit_isoc(struct stk1160 *dev);
  148. /* Provided by stk1160-i2c.c */
  149. int stk1160_i2c_register(struct stk1160 *dev);
  150. int stk1160_i2c_unregister(struct stk1160 *dev);
  151. /* Provided by stk1160-core.c */
  152. int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value);
  153. int stk1160_write_reg(struct stk1160 *dev, u16 reg, u16 value);
  154. int stk1160_write_regs_req(struct stk1160 *dev, u8 req, u16 reg,
  155. char *buf, int len);
  156. int stk1160_read_reg_req_len(struct stk1160 *dev, u8 req, u16 reg,
  157. char *buf, int len);
  158. void stk1160_select_input(struct stk1160 *dev);
  159. /* Provided by stk1160-ac97.c */
  160. void stk1160_ac97_setup(struct stk1160 *dev);