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