et61x251.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <asm/semaphore.h>
  35. #include "et61x251_sensor.h"
  36. /*****************************************************************************/
  37. #define ET61X251_DEBUG
  38. #define ET61X251_DEBUG_LEVEL 2
  39. #define ET61X251_MAX_DEVICES 64
  40. #define ET61X251_PRESERVE_IMGSCALE 0
  41. #define ET61X251_FORCE_MUNMAP 0
  42. #define ET61X251_MAX_FRAMES 32
  43. #define ET61X251_COMPRESSION_QUALITY 0
  44. #define ET61X251_URBS 2
  45. #define ET61X251_ISO_PACKETS 7
  46. #define ET61X251_ALTERNATE_SETTING 13
  47. #define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS)
  48. #define ET61X251_CTRL_TIMEOUT 100
  49. /*****************************************************************************/
  50. static const struct usb_device_id et61x251_id_table[] = {
  51. { USB_DEVICE(0x102c, 0x6151), },
  52. { USB_DEVICE(0x102c, 0x6251), },
  53. { USB_DEVICE(0x102c, 0x6253), },
  54. { USB_DEVICE(0x102c, 0x6254), },
  55. { USB_DEVICE(0x102c, 0x6255), },
  56. { USB_DEVICE(0x102c, 0x6256), },
  57. { USB_DEVICE(0x102c, 0x6257), },
  58. { USB_DEVICE(0x102c, 0x6258), },
  59. { USB_DEVICE(0x102c, 0x6259), },
  60. { USB_DEVICE(0x102c, 0x625a), },
  61. { USB_DEVICE(0x102c, 0x625b), },
  62. { USB_DEVICE(0x102c, 0x625c), },
  63. { USB_DEVICE(0x102c, 0x625d), },
  64. { USB_DEVICE(0x102c, 0x625e), },
  65. { USB_DEVICE(0x102c, 0x625f), },
  66. { USB_DEVICE(0x102c, 0x6260), },
  67. { USB_DEVICE(0x102c, 0x6261), },
  68. { USB_DEVICE(0x102c, 0x6262), },
  69. { USB_DEVICE(0x102c, 0x6263), },
  70. { USB_DEVICE(0x102c, 0x6264), },
  71. { USB_DEVICE(0x102c, 0x6265), },
  72. { USB_DEVICE(0x102c, 0x6266), },
  73. { USB_DEVICE(0x102c, 0x6267), },
  74. { USB_DEVICE(0x102c, 0x6268), },
  75. { USB_DEVICE(0x102c, 0x6269), },
  76. { }
  77. };
  78. ET61X251_SENSOR_TABLE
  79. /*****************************************************************************/
  80. enum et61x251_frame_state {
  81. F_UNUSED,
  82. F_QUEUED,
  83. F_GRABBING,
  84. F_DONE,
  85. F_ERROR,
  86. };
  87. struct et61x251_frame_t {
  88. void* bufmem;
  89. struct v4l2_buffer buf;
  90. enum et61x251_frame_state state;
  91. struct list_head frame;
  92. unsigned long vma_use_count;
  93. };
  94. enum et61x251_dev_state {
  95. DEV_INITIALIZED = 0x01,
  96. DEV_DISCONNECTED = 0x02,
  97. DEV_MISCONFIGURED = 0x04,
  98. };
  99. enum et61x251_io_method {
  100. IO_NONE,
  101. IO_READ,
  102. IO_MMAP,
  103. };
  104. enum et61x251_stream_state {
  105. STREAM_OFF,
  106. STREAM_INTERRUPT,
  107. STREAM_ON,
  108. };
  109. struct et61x251_sysfs_attr {
  110. u8 reg, i2c_reg;
  111. };
  112. struct et61x251_module_param {
  113. u8 force_munmap;
  114. };
  115. static DECLARE_MUTEX(et61x251_sysfs_lock);
  116. static DECLARE_RWSEM(et61x251_disconnect);
  117. struct et61x251_device {
  118. struct video_device* v4ldev;
  119. struct et61x251_sensor* sensor;
  120. struct usb_device* usbdev;
  121. struct urb* urb[ET61X251_URBS];
  122. void* transfer_buffer[ET61X251_URBS];
  123. u8* control_buffer;
  124. struct et61x251_frame_t *frame_current, frame[ET61X251_MAX_FRAMES];
  125. struct list_head inqueue, outqueue;
  126. u32 frame_count, nbuffers, nreadbuffers;
  127. enum et61x251_io_method io;
  128. enum et61x251_stream_state stream;
  129. struct v4l2_jpegcompression compression;
  130. struct et61x251_sysfs_attr sysfs;
  131. struct et61x251_module_param module_param;
  132. enum et61x251_dev_state state;
  133. u8 users;
  134. struct semaphore dev_sem, fileop_sem;
  135. spinlock_t queue_lock;
  136. wait_queue_head_t open, wait_frame, wait_stream;
  137. };
  138. /*****************************************************************************/
  139. void
  140. et61x251_attach_sensor(struct et61x251_device* cam,
  141. struct et61x251_sensor* sensor)
  142. {
  143. cam->sensor = sensor;
  144. cam->sensor->usbdev = cam->usbdev;
  145. }
  146. /*****************************************************************************/
  147. #undef DBG
  148. #undef KDBG
  149. #ifdef ET61X251_DEBUG
  150. # define DBG(level, fmt, args...) \
  151. do { \
  152. if (debug >= (level)) { \
  153. if ((level) == 1) \
  154. dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
  155. else if ((level) == 2) \
  156. dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
  157. else if ((level) >= 3) \
  158. dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
  159. __FUNCTION__, __LINE__ , ## args); \
  160. } \
  161. } while (0)
  162. # define KDBG(level, fmt, args...) \
  163. do { \
  164. if (debug >= (level)) { \
  165. if ((level) == 1 || (level) == 2) \
  166. pr_info("et61x251: " fmt "\n", ## args); \
  167. else if ((level) == 3) \
  168. pr_debug("et61x251: [%s:%d] " fmt "\n", __FUNCTION__, \
  169. __LINE__ , ## args); \
  170. } \
  171. } while (0)
  172. # define V4LDBG(level, name, cmd) \
  173. do { \
  174. if (debug >= (level)) \
  175. v4l_print_ioctl(name, cmd); \
  176. } while (0)
  177. #else
  178. # define DBG(level, fmt, args...) do {;} while(0)
  179. # define KDBG(level, fmt, args...) do {;} while(0)
  180. # define V4LDBG(level, name, cmd) do {;} while(0)
  181. #endif
  182. #undef PDBG
  183. #define PDBG(fmt, args...) \
  184. dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args)
  185. #undef PDBGG
  186. #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
  187. #endif /* _ET61X251_H_ */