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 22#ifndef STKWEBCAM_H 23#define STKWEBCAM_H 24 25#include <linux/usb.h> 26#include <media/v4l2-device.h> 27#include <media/v4l2-ctrls.h> 28#include <media/v4l2-common.h> 29 30#define DRIVER_VERSION "v0.0.1" 31#define DRIVER_VERSION_NUM 0x000001 32 33#define MAX_ISO_BUFS 3 34#define ISO_FRAMES_PER_DESC 16 35#define ISO_MAX_FRAME_SIZE 3 * 1024 36#define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE) 37 38 39#define PREFIX "stkwebcam: " 40#define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args) 41#define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args) 42#define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args) 43 44struct stk_iso_buf { 45 void *data; 46 int length; 47 int read; 48 struct urb *urb; 49}; 50 51/* Streaming IO buffers */ 52struct stk_sio_buffer { 53 struct v4l2_buffer v4lbuf; 54 char *buffer; 55 int mapcount; 56 struct stk_camera *dev; 57 struct list_head list; 58}; 59 60enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF}; 61 62struct stk_video { 63 enum stk_mode mode; 64 __u32 palette; 65 int hflip; 66 int vflip; 67}; 68 69enum stk_status { 70 S_PRESENT = 1, 71 S_INITIALISED = 2, 72 S_MEMALLOCD = 4, 73 S_STREAMING = 8, 74}; 75#define is_present(dev) ((dev)->status & S_PRESENT) 76#define is_initialised(dev) ((dev)->status & S_INITIALISED) 77#define is_streaming(dev) ((dev)->status & S_STREAMING) 78#define is_memallocd(dev) ((dev)->status & S_MEMALLOCD) 79#define set_present(dev) ((dev)->status = S_PRESENT) 80#define unset_present(dev) ((dev)->status &= \ 81 ~(S_PRESENT|S_INITIALISED|S_STREAMING)) 82#define set_initialised(dev) ((dev)->status |= S_INITIALISED) 83#define unset_initialised(dev) ((dev)->status &= ~S_INITIALISED) 84#define set_memallocd(dev) ((dev)->status |= S_MEMALLOCD) 85#define unset_memallocd(dev) ((dev)->status &= ~S_MEMALLOCD) 86#define set_streaming(dev) ((dev)->status |= S_STREAMING) 87#define unset_streaming(dev) ((dev)->status &= ~S_STREAMING) 88 89struct regval { 90 unsigned reg; 91 unsigned val; 92}; 93 94struct stk_camera { 95 struct v4l2_device v4l2_dev; 96 struct v4l2_ctrl_handler hdl; 97 struct video_device vdev; 98 struct usb_device *udev; 99 struct usb_interface *interface; 100 int webcam_model; 101 struct file *owner; 102 struct mutex lock; 103 int first_init; 104 105 u8 isoc_ep; 106 107 /* Not sure if this is right */ 108 atomic_t urbs_used; 109 110 struct stk_video vsettings; 111 112 enum stk_status status; 113 114 spinlock_t spinlock; 115 wait_queue_head_t wait_frame; 116 117 struct stk_iso_buf *isobufs; 118 119 int frame_size; 120 /* Streaming buffers */ 121 int reading; 122 unsigned int n_sbufs; 123 struct stk_sio_buffer *sio_bufs; 124 struct list_head sio_avail; 125 struct list_head sio_full; 126 unsigned sequence; 127}; 128 129#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev) 130 131int stk_camera_write_reg(struct stk_camera *, u16, u8); 132int stk_camera_read_reg(struct stk_camera *, u16, int *); 133 134int stk_sensor_init(struct stk_camera *); 135int stk_sensor_configure(struct stk_camera *); 136int stk_sensor_sleep(struct stk_camera *dev); 137int stk_sensor_wakeup(struct stk_camera *dev); 138int stk_sensor_set_brightness(struct stk_camera *dev, int br); 139 140#endif 141