stk-webcam.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * stk-webcam.h : Driver for Syntek 1125 USB webcam controller
  3. *
  4. * Copyright (C) 2006 Nicolas VIVIEN
  5. * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef STKWEBCAM_H
  22. #define STKWEBCAM_H
  23. #include <linux/usb.h>
  24. #include <media/v4l2-device.h>
  25. #include <media/v4l2-ctrls.h>
  26. #include <media/v4l2-common.h>
  27. #define DRIVER_VERSION "v0.0.1"
  28. #define DRIVER_VERSION_NUM 0x000001
  29. #define MAX_ISO_BUFS 3
  30. #define ISO_FRAMES_PER_DESC 16
  31. #define ISO_MAX_FRAME_SIZE 3 * 1024
  32. #define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
  33. #define PREFIX "stkwebcam: "
  34. #define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
  35. #define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
  36. #define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
  37. struct stk_iso_buf {
  38. void *data;
  39. int length;
  40. int read;
  41. struct urb *urb;
  42. };
  43. /* Streaming IO buffers */
  44. struct stk_sio_buffer {
  45. struct v4l2_buffer v4lbuf;
  46. char *buffer;
  47. int mapcount;
  48. struct stk_camera *dev;
  49. struct list_head list;
  50. };
  51. enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};
  52. struct stk_video {
  53. enum stk_mode mode;
  54. __u32 palette;
  55. int hflip;
  56. int vflip;
  57. };
  58. enum stk_status {
  59. S_PRESENT = 1,
  60. S_INITIALISED = 2,
  61. S_MEMALLOCD = 4,
  62. S_STREAMING = 8,
  63. };
  64. #define is_present(dev) ((dev)->status & S_PRESENT)
  65. #define is_initialised(dev) ((dev)->status & S_INITIALISED)
  66. #define is_streaming(dev) ((dev)->status & S_STREAMING)
  67. #define is_memallocd(dev) ((dev)->status & S_MEMALLOCD)
  68. #define set_present(dev) ((dev)->status = S_PRESENT)
  69. #define unset_present(dev) ((dev)->status &= \
  70. ~(S_PRESENT|S_INITIALISED|S_STREAMING))
  71. #define set_initialised(dev) ((dev)->status |= S_INITIALISED)
  72. #define unset_initialised(dev) ((dev)->status &= ~S_INITIALISED)
  73. #define set_memallocd(dev) ((dev)->status |= S_MEMALLOCD)
  74. #define unset_memallocd(dev) ((dev)->status &= ~S_MEMALLOCD)
  75. #define set_streaming(dev) ((dev)->status |= S_STREAMING)
  76. #define unset_streaming(dev) ((dev)->status &= ~S_STREAMING)
  77. struct regval {
  78. unsigned reg;
  79. unsigned val;
  80. };
  81. struct stk_camera {
  82. struct v4l2_device v4l2_dev;
  83. struct v4l2_ctrl_handler hdl;
  84. struct video_device vdev;
  85. struct usb_device *udev;
  86. struct usb_interface *interface;
  87. int webcam_model;
  88. struct file *owner;
  89. struct mutex lock;
  90. int first_init;
  91. u8 isoc_ep;
  92. /* Not sure if this is right */
  93. atomic_t urbs_used;
  94. struct stk_video vsettings;
  95. enum stk_status status;
  96. spinlock_t spinlock;
  97. wait_queue_head_t wait_frame;
  98. struct stk_iso_buf *isobufs;
  99. int frame_size;
  100. /* Streaming buffers */
  101. int reading;
  102. unsigned int n_sbufs;
  103. struct stk_sio_buffer *sio_bufs;
  104. struct list_head sio_avail;
  105. struct list_head sio_full;
  106. unsigned sequence;
  107. };
  108. #define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)
  109. int stk_camera_write_reg(struct stk_camera *, u16, u8);
  110. int stk_camera_read_reg(struct stk_camera *, u16, int *);
  111. int stk_sensor_init(struct stk_camera *);
  112. int stk_sensor_configure(struct stk_camera *);
  113. int stk_sensor_sleep(struct stk_camera *dev);
  114. int stk_sensor_wakeup(struct stk_camera *dev);
  115. int stk_sensor_set_brightness(struct stk_camera *dev, int br);
  116. #endif