sn9c102.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /***************************************************************************
  2. * V4L2 driver for SN9C10x PC Camera Controllers *
  3. * *
  4. * Copyright (C) 2004-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 _SN9C102_H_
  21. #define _SN9C102_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 "sn9c102_sensor.h"
  36. /*****************************************************************************/
  37. #define SN9C102_DEBUG
  38. #define SN9C102_DEBUG_LEVEL 2
  39. #define SN9C102_MAX_DEVICES 64
  40. #define SN9C102_PRESERVE_IMGSCALE 0
  41. #define SN9C102_FORCE_MUNMAP 0
  42. #define SN9C102_MAX_FRAMES 32
  43. #define SN9C102_URBS 2
  44. #define SN9C102_ISO_PACKETS 7
  45. #define SN9C102_ALTERNATE_SETTING 8
  46. #define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS)
  47. #define SN9C102_CTRL_TIMEOUT 300
  48. /*****************************************************************************/
  49. enum sn9c102_bridge {
  50. BRIDGE_SN9C101 = 0x01,
  51. BRIDGE_SN9C102 = 0x02,
  52. BRIDGE_SN9C103 = 0x04,
  53. };
  54. SN9C102_ID_TABLE
  55. SN9C102_SENSOR_TABLE
  56. enum sn9c102_frame_state {
  57. F_UNUSED,
  58. F_QUEUED,
  59. F_GRABBING,
  60. F_DONE,
  61. F_ERROR,
  62. };
  63. struct sn9c102_frame_t {
  64. void* bufmem;
  65. struct v4l2_buffer buf;
  66. enum sn9c102_frame_state state;
  67. struct list_head frame;
  68. unsigned long vma_use_count;
  69. };
  70. enum sn9c102_dev_state {
  71. DEV_INITIALIZED = 0x01,
  72. DEV_DISCONNECTED = 0x02,
  73. DEV_MISCONFIGURED = 0x04,
  74. };
  75. enum sn9c102_io_method {
  76. IO_NONE,
  77. IO_READ,
  78. IO_MMAP,
  79. };
  80. enum sn9c102_stream_state {
  81. STREAM_OFF,
  82. STREAM_INTERRUPT,
  83. STREAM_ON,
  84. };
  85. typedef char sn9c103_sof_header_t[18];
  86. typedef char sn9c102_sof_header_t[12];
  87. typedef char sn9c102_eof_header_t[4];
  88. struct sn9c102_sysfs_attr {
  89. u8 reg, i2c_reg;
  90. sn9c103_sof_header_t frame_header;
  91. };
  92. struct sn9c102_module_param {
  93. u8 force_munmap;
  94. };
  95. static DECLARE_MUTEX(sn9c102_sysfs_lock);
  96. static DECLARE_RWSEM(sn9c102_disconnect);
  97. struct sn9c102_device {
  98. struct video_device* v4ldev;
  99. enum sn9c102_bridge bridge;
  100. struct sn9c102_sensor* sensor;
  101. struct usb_device* usbdev;
  102. struct urb* urb[SN9C102_URBS];
  103. void* transfer_buffer[SN9C102_URBS];
  104. u8* control_buffer;
  105. struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
  106. struct list_head inqueue, outqueue;
  107. u32 frame_count, nbuffers, nreadbuffers;
  108. enum sn9c102_io_method io;
  109. enum sn9c102_stream_state stream;
  110. struct v4l2_jpegcompression compression;
  111. struct sn9c102_sysfs_attr sysfs;
  112. sn9c103_sof_header_t sof_header;
  113. u16 reg[63];
  114. struct sn9c102_module_param module_param;
  115. enum sn9c102_dev_state state;
  116. u8 users;
  117. struct semaphore dev_sem, fileop_sem;
  118. spinlock_t queue_lock;
  119. wait_queue_head_t open, wait_frame, wait_stream;
  120. };
  121. /*****************************************************************************/
  122. void
  123. sn9c102_attach_sensor(struct sn9c102_device* cam,
  124. struct sn9c102_sensor* sensor)
  125. {
  126. cam->sensor = sensor;
  127. cam->sensor->usbdev = cam->usbdev;
  128. }
  129. /*****************************************************************************/
  130. #undef DBG
  131. #undef KDBG
  132. #ifdef SN9C102_DEBUG
  133. # define DBG(level, fmt, args...) \
  134. do { \
  135. if (debug >= (level)) { \
  136. if ((level) == 1) \
  137. dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
  138. else if ((level) == 2) \
  139. dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
  140. else if ((level) >= 3) \
  141. dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
  142. __FUNCTION__, __LINE__ , ## args); \
  143. } \
  144. } while (0)
  145. # define V4LDBG(level, name, cmd) \
  146. do { \
  147. if (debug >= (level)) \
  148. v4l_print_ioctl(name, cmd); \
  149. } while (0)
  150. # define KDBG(level, fmt, args...) \
  151. do { \
  152. if (debug >= (level)) { \
  153. if ((level) == 1 || (level) == 2) \
  154. pr_info("sn9c102: " fmt "\n", ## args); \
  155. else if ((level) == 3) \
  156. pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
  157. __LINE__ , ## args); \
  158. } \
  159. } while (0)
  160. #else
  161. # define DBG(level, fmt, args...) do {;} while(0)
  162. # define V4LDBG(level, name, cmd) do {;} while(0)
  163. # define KDBG(level, fmt, args...) do {;} while(0)
  164. #endif
  165. #undef PDBG
  166. #define PDBG(fmt, args...) \
  167. dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args)
  168. #undef PDBGG
  169. #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
  170. #endif /* _SN9C102_H_ */