/drivers/media/video/et61x251/et61x251.h

https://bitbucket.org/abioy/linux · C Header · 234 lines · 175 code · 35 blank · 24 comment · 24 complexity · bc1cdba7f66c65a170c8c9eac9fbb267 MD5 · raw file

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