et61x251.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /***************************************************************************
  2. * V4L2 driver for ET61X[12]51 PC Camera Controllers *
  3. * *
  4. * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
  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. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, write to the Free Software *
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
  19. ***************************************************************************/
  20. #ifndef _ET61X251_H_
  21. #define _ET61X251_H_
  22. #include <linux/version.h>
  23. #include <linux/usb.h>
  24. #include <linux/videodev2.h>
  25. #include <media/v4l2-common.h>
  26. #include <linux/device.h>
  27. #include <linux/list.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/time.h>
  30. #include <linux/wait.h>
  31. #include <linux/types.h>
  32. #include <linux/param.h>
  33. #include <linux/rwsem.h>
  34. #include <linux/mutex.h>
  35. #include <linux/stddef.h>
  36. #include <linux/string.h>
  37. #include "et61x251_sensor.h"
  38. /*****************************************************************************/
  39. #define ET61X251_DEBUG
  40. #define ET61X251_DEBUG_LEVEL 2
  41. #define ET61X251_MAX_DEVICES 64
  42. #define ET61X251_PRESERVE_IMGSCALE 0
  43. #define ET61X251_FORCE_MUNMAP 0
  44. #define ET61X251_MAX_FRAMES 32
  45. #define ET61X251_COMPRESSION_QUALITY 0
  46. #define ET61X251_URBS 2
  47. #define ET61X251_ISO_PACKETS 7
  48. #define ET61X251_ALTERNATE_SETTING 13
  49. #define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS)
  50. #define ET61X251_CTRL_TIMEOUT 100
  51. #define ET61X251_FRAME_TIMEOUT 2
  52. /*****************************************************************************/
  53. static const struct usb_device_id et61x251_id_table[] = {
  54. { USB_DEVICE(0x102c, 0x6151), },
  55. { USB_DEVICE(0x102c, 0x6251), },
  56. { USB_DEVICE(0x102c, 0x6253), },
  57. { USB_DEVICE(0x102c, 0x6254), },
  58. { USB_DEVICE(0x102c, 0x6255), },
  59. { USB_DEVICE(0x102c, 0x6256), },
  60. { USB_DEVICE(0x102c, 0x6257), },
  61. { USB_DEVICE(0x102c, 0x6258), },
  62. { USB_DEVICE(0x102c, 0x6259), },
  63. { USB_DEVICE(0x102c, 0x625a), },
  64. { USB_DEVICE(0x102c, 0x625b), },
  65. { USB_DEVICE(0x102c, 0x625c), },
  66. { USB_DEVICE(0x102c, 0x625d), },
  67. { USB_DEVICE(0x102c, 0x625e), },
  68. { USB_DEVICE(0x102c, 0x625f), },
  69. { USB_DEVICE(0x102c, 0x6260), },
  70. { USB_DEVICE(0x102c, 0x6261), },
  71. { USB_DEVICE(0x102c, 0x6262), },
  72. { USB_DEVICE(0x102c, 0x6263), },
  73. { USB_DEVICE(0x102c, 0x6264), },
  74. { USB_DEVICE(0x102c, 0x6265), },
  75. { USB_DEVICE(0x102c, 0x6266), },
  76. { USB_DEVICE(0x102c, 0x6267), },
  77. { USB_DEVICE(0x102c, 0x6268), },
  78. { USB_DEVICE(0x102c, 0x6269), },
  79. { }
  80. };
  81. ET61X251_SENSOR_TABLE
  82. /*****************************************************************************/
  83. enum et61x251_frame_state {
  84. F_UNUSED,
  85. F_QUEUED,
  86. F_GRABBING,
  87. F_DONE,
  88. F_ERROR,
  89. };
  90. struct et61x251_frame_t {
  91. void* bufmem;
  92. struct v4l2_buffer buf;
  93. enum et61x251_frame_state state;
  94. struct list_head frame;
  95. unsigned long vma_use_count;
  96. };
  97. enum et61x251_dev_state {
  98. DEV_INITIALIZED = 0x01,
  99. DEV_DISCONNECTED = 0x02,
  100. DEV_MISCONFIGURED = 0x04,
  101. };
  102. enum et61x251_io_method {
  103. IO_NONE,
  104. IO_READ,
  105. IO_MMAP,
  106. };
  107. enum et61x251_stream_state {
  108. STREAM_OFF,
  109. STREAM_INTERRUPT,
  110. STREAM_ON,
  111. };
  112. struct et61x251_sysfs_attr {
  113. u8 reg, i2c_reg;
  114. };
  115. struct et61x251_module_param {
  116. u8 force_munmap;
  117. u16 frame_timeout;
  118. };
  119. static DEFINE_MUTEX(et61x251_sysfs_lock);
  120. static DECLARE_RWSEM(et61x251_disconnect);
  121. struct et61x251_device {
  122. struct video_device* v4ldev;
  123. struct et61x251_sensor sensor;
  124. struct usb_device* usbdev;
  125. struct urb* urb[ET61X251_URBS];
  126. void* transfer_buffer[ET61X251_URBS];
  127. u8* control_buffer;
  128. struct et61x251_frame_t *frame_current, frame[ET61X251_MAX_FRAMES];
  129. struct list_head inqueue, outqueue;
  130. u32 frame_count, nbuffers, nreadbuffers;
  131. enum et61x251_io_method io;
  132. enum et61x251_stream_state stream;
  133. struct v4l2_jpegcompression compression;
  134. struct et61x251_sysfs_attr sysfs;
  135. struct et61x251_module_param module_param;
  136. enum et61x251_dev_state state;
  137. u8 users;
  138. struct mutex dev_mutex, fileop_mutex;
  139. spinlock_t queue_lock;
  140. wait_queue_head_t open, wait_frame, wait_stream;
  141. };
  142. /*****************************************************************************/
  143. struct et61x251_device*
  144. et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id)
  145. {
  146. return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
  147. }
  148. void
  149. et61x251_attach_sensor(struct et61x251_device* cam,
  150. struct et61x251_sensor* sensor)
  151. {
  152. memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor));
  153. }
  154. /*****************************************************************************/
  155. #undef DBG
  156. #undef KDBG
  157. #ifdef ET61X251_DEBUG
  158. # define DBG(level, fmt, args...) \
  159. do { \
  160. if (debug >= (level)) { \
  161. if ((level) == 1) \
  162. dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
  163. else if ((level) == 2) \
  164. dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
  165. else if ((level) >= 3) \
  166. dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
  167. __FUNCTION__, __LINE__ , ## args); \
  168. } \
  169. } while (0)
  170. # define KDBG(level, fmt, args...) \
  171. do { \
  172. if (debug >= (level)) { \
  173. if ((level) == 1 || (level) == 2) \
  174. pr_info("et61x251: " fmt "\n", ## args); \
  175. else if ((level) == 3) \
  176. pr_debug("et61x251: [%s:%d] " fmt "\n", __FUNCTION__, \
  177. __LINE__ , ## args); \
  178. } \
  179. } while (0)
  180. # define V4LDBG(level, name, cmd) \
  181. do { \
  182. if (debug >= (level)) \
  183. v4l_print_ioctl(name, cmd); \
  184. } while (0)
  185. #else
  186. # define DBG(level, fmt, args...) do {;} while(0)
  187. # define KDBG(level, fmt, args...) do {;} while(0)
  188. # define V4LDBG(level, name, cmd) do {;} while(0)
  189. #endif
  190. #undef PDBG
  191. #define PDBG(fmt, args...) \
  192. dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
  193. __FUNCTION__, __LINE__ , ## args)
  194. #undef PDBGG
  195. #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
  196. #endif /* _ET61X251_H_ */