sn9c102.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /***************************************************************************
  2. * V4L2 driver for SN9C1xx 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 <linux/mutex.h>
  35. #include <linux/string.h>
  36. #include <linux/stddef.h>
  37. #include "sn9c102_config.h"
  38. #include "sn9c102_sensor.h"
  39. #include "sn9c102_devtable.h"
  40. enum sn9c102_frame_state {
  41. F_UNUSED,
  42. F_QUEUED,
  43. F_GRABBING,
  44. F_DONE,
  45. F_ERROR,
  46. };
  47. struct sn9c102_frame_t {
  48. void* bufmem;
  49. struct v4l2_buffer buf;
  50. enum sn9c102_frame_state state;
  51. struct list_head frame;
  52. unsigned long vma_use_count;
  53. };
  54. enum sn9c102_dev_state {
  55. DEV_INITIALIZED = 0x01,
  56. DEV_DISCONNECTED = 0x02,
  57. DEV_MISCONFIGURED = 0x04,
  58. };
  59. enum sn9c102_io_method {
  60. IO_NONE,
  61. IO_READ,
  62. IO_MMAP,
  63. };
  64. enum sn9c102_stream_state {
  65. STREAM_OFF,
  66. STREAM_INTERRUPT,
  67. STREAM_ON,
  68. };
  69. typedef char sn9c102_sof_header_t[62];
  70. struct sn9c102_sof_t {
  71. sn9c102_sof_header_t header;
  72. u16 bytesread;
  73. };
  74. struct sn9c102_sysfs_attr {
  75. u16 reg, i2c_reg;
  76. sn9c102_sof_header_t frame_header;
  77. };
  78. struct sn9c102_module_param {
  79. u8 force_munmap;
  80. u16 frame_timeout;
  81. };
  82. static DEFINE_MUTEX(sn9c102_sysfs_lock);
  83. static DECLARE_RWSEM(sn9c102_disconnect);
  84. struct sn9c102_device {
  85. struct video_device* v4ldev;
  86. enum sn9c102_bridge bridge;
  87. struct sn9c102_sensor sensor;
  88. struct usb_device* usbdev;
  89. struct urb* urb[SN9C102_URBS];
  90. void* transfer_buffer[SN9C102_URBS];
  91. u8* control_buffer;
  92. struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
  93. struct list_head inqueue, outqueue;
  94. u32 frame_count, nbuffers, nreadbuffers;
  95. enum sn9c102_io_method io;
  96. enum sn9c102_stream_state stream;
  97. struct v4l2_jpegcompression compression;
  98. struct sn9c102_sysfs_attr sysfs;
  99. struct sn9c102_sof_t sof;
  100. u16 reg[384];
  101. struct sn9c102_module_param module_param;
  102. enum sn9c102_dev_state state;
  103. u8 users;
  104. struct mutex dev_mutex, fileop_mutex;
  105. spinlock_t queue_lock;
  106. wait_queue_head_t open, wait_frame, wait_stream;
  107. };
  108. /*****************************************************************************/
  109. struct sn9c102_device*
  110. sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
  111. {
  112. return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
  113. }
  114. void
  115. sn9c102_attach_sensor(struct sn9c102_device* cam,
  116. const struct sn9c102_sensor* sensor)
  117. {
  118. memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
  119. }
  120. enum sn9c102_bridge
  121. sn9c102_get_bridge(struct sn9c102_device* cam)
  122. {
  123. return cam->bridge;
  124. }
  125. struct sn9c102_sensor* sn9c102_get_sensor(struct sn9c102_device* cam)
  126. {
  127. return &cam->sensor;
  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", \
  157. __FUNCTION__, __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->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __FUNCTION__, \
  168. __LINE__ , ## args)
  169. #undef PDBGG
  170. #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
  171. #endif /* _SN9C102_H_ */