et61x251.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/usb.h>
  23. #include <linux/videodev2.h>
  24. #include <media/v4l2-common.h>
  25. #include <linux/device.h>
  26. #include <linux/list.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/time.h>
  29. #include <linux/wait.h>
  30. #include <linux/types.h>
  31. #include <linux/param.h>
  32. #include <linux/rwsem.h>
  33. #include <linux/mutex.h>
  34. #include <linux/stddef.h>
  35. #include <linux/string.h>
  36. #include <linux/kref.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, 0x6251), },
  55. { }
  56. };
  57. ET61X251_SENSOR_TABLE
  58. /*****************************************************************************/
  59. enum et61x251_frame_state {
  60. F_UNUSED,
  61. F_QUEUED,
  62. F_GRABBING,
  63. F_DONE,
  64. F_ERROR,
  65. };
  66. struct et61x251_frame_t {
  67. void* bufmem;
  68. struct v4l2_buffer buf;
  69. enum et61x251_frame_state state;
  70. struct list_head frame;
  71. unsigned long vma_use_count;
  72. };
  73. enum et61x251_dev_state {
  74. DEV_INITIALIZED = 0x01,
  75. DEV_DISCONNECTED = 0x02,
  76. DEV_MISCONFIGURED = 0x04,
  77. };
  78. enum et61x251_io_method {
  79. IO_NONE,
  80. IO_READ,
  81. IO_MMAP,
  82. };
  83. enum et61x251_stream_state {
  84. STREAM_OFF,
  85. STREAM_INTERRUPT,
  86. STREAM_ON,
  87. };
  88. struct et61x251_sysfs_attr {
  89. u8 reg, i2c_reg;
  90. };
  91. struct et61x251_module_param {
  92. u8 force_munmap;
  93. u16 frame_timeout;
  94. };
  95. static DEFINE_MUTEX(et61x251_sysfs_lock);
  96. static DECLARE_RWSEM(et61x251_dev_lock);
  97. struct et61x251_device {
  98. struct video_device* v4ldev;
  99. struct et61x251_sensor sensor;
  100. struct usb_device* usbdev;
  101. struct urb* urb[ET61X251_URBS];
  102. void* transfer_buffer[ET61X251_URBS];
  103. u8* control_buffer;
  104. struct et61x251_frame_t *frame_current, frame[ET61X251_MAX_FRAMES];
  105. struct list_head inqueue, outqueue;
  106. u32 frame_count, nbuffers, nreadbuffers;
  107. enum et61x251_io_method io;
  108. enum et61x251_stream_state stream;
  109. struct v4l2_jpegcompression compression;
  110. struct et61x251_sysfs_attr sysfs;
  111. struct et61x251_module_param module_param;
  112. struct kref kref;
  113. enum et61x251_dev_state state;
  114. u8 users;
  115. struct completion probe;
  116. struct mutex open_mutex, fileop_mutex;
  117. spinlock_t queue_lock;
  118. wait_queue_head_t wait_open, wait_frame, wait_stream;
  119. };
  120. /*****************************************************************************/
  121. struct et61x251_device*
  122. et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id)
  123. {
  124. return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
  125. }
  126. void
  127. et61x251_attach_sensor(struct et61x251_device* cam,
  128. const struct et61x251_sensor* sensor)
  129. {
  130. memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor));
  131. }
  132. /*****************************************************************************/
  133. #undef DBG
  134. #undef KDBG
  135. #ifdef ET61X251_DEBUG
  136. #define DBG(level, fmt, ...) \
  137. do { \
  138. if (debug >= (level)) { \
  139. if ((level) == 1) \
  140. dev_err(&cam->usbdev->dev, fmt "\n", \
  141. ##__VA_ARGS__); \
  142. else if ((level) == 2) \
  143. dev_info(&cam->usbdev->dev, fmt "\n", \
  144. ##__VA_ARGS__); \
  145. else if ((level) >= 3) \
  146. dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
  147. __FILE__, __func__, __LINE__, \
  148. ##__VA_ARGS__); \
  149. } \
  150. } while (0)
  151. #define KDBG(level, fmt, ...) \
  152. do { \
  153. if (debug >= (level)) { \
  154. if ((level) == 1 || (level) == 2) \
  155. pr_info(fmt "\n", ##__VA_ARGS__); \
  156. else if ((level) == 3) \
  157. pr_debug("[%s:%s:%d] " fmt "\n", \
  158. __FILE__, __func__, __LINE__, \
  159. ##__VA_ARGS__); \
  160. } \
  161. } while (0)
  162. #define V4LDBG(level, name, cmd) \
  163. do { \
  164. if (debug >= (level)) \
  165. v4l_print_ioctl(name, cmd); \
  166. } while (0)
  167. #else
  168. #define DBG(level, fmt, ...) do {;} while(0)
  169. #define KDBG(level, fmt, ...) do {;} while(0)
  170. #define V4LDBG(level, name, cmd) do {;} while(0)
  171. #endif
  172. #undef PDBG
  173. #define PDBG(fmt, ...) \
  174. dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
  175. __FILE__, __func__, __LINE__, ##__VA_ARGS__)
  176. #undef PDBGG
  177. #define PDBGG(fmt, args...) do {;} while (0) /* placeholder */
  178. #endif /* _ET61X251_H_ */