blob: 0284120ce246b011cd1d4272091dd9039cc2dbe6 [file] [log] [blame]
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -03001/*
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.
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -030016 */
17
18#ifndef STKWEBCAM_H
19#define STKWEBCAM_H
20
21#include <linux/usb.h>
Hans Verkuil968c60f62013-02-04 08:17:42 -030022#include <media/v4l2-device.h>
Hans Verkuildc0fb282013-02-04 08:53:11 -030023#include <media/v4l2-ctrls.h>
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -030024#include <media/v4l2-common.h>
25
26#define DRIVER_VERSION "v0.0.1"
27#define DRIVER_VERSION_NUM 0x000001
28
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
34
35#define PREFIX "stkwebcam: "
36#define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
37#define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
38#define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
39
40struct stk_iso_buf {
41 void *data;
42 int length;
43 int read;
44 struct urb *urb;
45};
46
47/* Streaming IO buffers */
48struct stk_sio_buffer {
49 struct v4l2_buffer v4lbuf;
50 char *buffer;
51 int mapcount;
52 struct stk_camera *dev;
53 struct list_head list;
54};
55
56enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};
57
58struct stk_video {
59 enum stk_mode mode;
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -030060 __u32 palette;
61 int hflip;
62 int vflip;
63};
64
65enum stk_status {
66 S_PRESENT = 1,
67 S_INITIALISED = 2,
68 S_MEMALLOCD = 4,
69 S_STREAMING = 8,
70};
71#define is_present(dev) ((dev)->status & S_PRESENT)
72#define is_initialised(dev) ((dev)->status & S_INITIALISED)
73#define is_streaming(dev) ((dev)->status & S_STREAMING)
74#define is_memallocd(dev) ((dev)->status & S_MEMALLOCD)
75#define set_present(dev) ((dev)->status = S_PRESENT)
76#define unset_present(dev) ((dev)->status &= \
77 ~(S_PRESENT|S_INITIALISED|S_STREAMING))
78#define set_initialised(dev) ((dev)->status |= S_INITIALISED)
Jaime Velasco Juan1fdd61c2008-01-27 12:24:59 -030079#define unset_initialised(dev) ((dev)->status &= ~S_INITIALISED)
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -030080#define set_memallocd(dev) ((dev)->status |= S_MEMALLOCD)
81#define unset_memallocd(dev) ((dev)->status &= ~S_MEMALLOCD)
82#define set_streaming(dev) ((dev)->status |= S_STREAMING)
83#define unset_streaming(dev) ((dev)->status &= ~S_STREAMING)
84
85struct regval {
86 unsigned reg;
87 unsigned val;
88};
89
90struct stk_camera {
Hans Verkuil968c60f62013-02-04 08:17:42 -030091 struct v4l2_device v4l2_dev;
Hans Verkuildc0fb282013-02-04 08:53:11 -030092 struct v4l2_ctrl_handler hdl;
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -030093 struct video_device vdev;
94 struct usb_device *udev;
95 struct usb_interface *interface;
96 int webcam_model;
97 struct file *owner;
Hans Verkuilf80daa22013-02-04 09:27:32 -030098 struct mutex lock;
Hans Verkuil89ea4702013-02-04 09:08:41 -030099 int first_init;
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300100
101 u8 isoc_ep;
102
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300103 /* Not sure if this is right */
104 atomic_t urbs_used;
105
106 struct stk_video vsettings;
107
108 enum stk_status status;
109
110 spinlock_t spinlock;
111 wait_queue_head_t wait_frame;
112
113 struct stk_iso_buf *isobufs;
114
115 int frame_size;
116 /* Streaming buffers */
Hans Verkuil1b499fe2013-02-06 04:23:01 -0300117 int reading;
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300118 unsigned int n_sbufs;
119 struct stk_sio_buffer *sio_bufs;
120 struct list_head sio_avail;
121 struct list_head sio_full;
122 unsigned sequence;
123};
124
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300125#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)
126
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300127int stk_camera_write_reg(struct stk_camera *, u16, u8);
Dan Carpenterd08876f2016-11-16 09:11:54 -0200128int stk_camera_read_reg(struct stk_camera *, u16, u8 *);
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300129
Jaime Velasco Juanec16dae2008-01-12 06:48:14 -0300130int stk_sensor_init(struct stk_camera *);
131int stk_sensor_configure(struct stk_camera *);
132int stk_sensor_sleep(struct stk_camera *dev);
133int stk_sensor_wakeup(struct stk_camera *dev);
134int stk_sensor_set_brightness(struct stk_camera *dev, int br);
135
136#endif