sn9c102.h 6.5 KB

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