• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * stk-webcam.h : Driver for Syntek 1125 USB webcam controller
4  *
5  * Copyright (C) 2006 Nicolas VIVIEN
6  * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com>
7  */
8 
9 #ifndef STKWEBCAM_H
10 #define STKWEBCAM_H
11 
12 #include <linux/usb.h>
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-ctrls.h>
15 #include <media/v4l2-common.h>
16 
17 #define DRIVER_VERSION		"v0.0.1"
18 #define DRIVER_VERSION_NUM	0x000001
19 
20 #define MAX_ISO_BUFS		3
21 #define ISO_FRAMES_PER_DESC	16
22 #define ISO_MAX_FRAME_SIZE	3 * 1024
23 #define ISO_BUFFER_SIZE		(ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
24 
25 struct stk_iso_buf {
26 	void *data;
27 	int length;
28 	int read;
29 	struct urb *urb;
30 };
31 
32 /* Streaming IO buffers */
33 struct stk_sio_buffer {
34 	struct v4l2_buffer v4lbuf;
35 	char *buffer;
36 	int mapcount;
37 	struct stk_camera *dev;
38 	struct list_head list;
39 };
40 
41 enum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF};
42 
43 struct stk_video {
44 	enum stk_mode mode;
45 	__u32 palette;
46 	int hflip;
47 	int vflip;
48 };
49 
50 enum stk_status {
51 	S_PRESENT = 1,
52 	S_INITIALISED = 2,
53 	S_MEMALLOCD = 4,
54 	S_STREAMING = 8,
55 };
56 #define is_present(dev)		((dev)->status & S_PRESENT)
57 #define is_initialised(dev)	((dev)->status & S_INITIALISED)
58 #define is_streaming(dev)	((dev)->status & S_STREAMING)
59 #define is_memallocd(dev)	((dev)->status & S_MEMALLOCD)
60 #define set_present(dev)	((dev)->status = S_PRESENT)
61 #define unset_present(dev)	((dev)->status &= \
62 					~(S_PRESENT|S_INITIALISED|S_STREAMING))
63 #define set_initialised(dev)	((dev)->status |= S_INITIALISED)
64 #define unset_initialised(dev)	((dev)->status &= ~S_INITIALISED)
65 #define set_memallocd(dev)	((dev)->status |= S_MEMALLOCD)
66 #define unset_memallocd(dev)	((dev)->status &= ~S_MEMALLOCD)
67 #define set_streaming(dev)	((dev)->status |= S_STREAMING)
68 #define unset_streaming(dev)	((dev)->status &= ~S_STREAMING)
69 
70 struct regval {
71 	unsigned reg;
72 	unsigned val;
73 };
74 
75 struct stk_camera {
76 	struct v4l2_device v4l2_dev;
77 	struct v4l2_ctrl_handler hdl;
78 	struct video_device vdev;
79 	struct usb_device *udev;
80 	struct usb_interface *interface;
81 	int webcam_model;
82 	struct file *owner;
83 	struct mutex lock;
84 	int first_init;
85 
86 	u8 isoc_ep;
87 
88 	/* Not sure if this is right */
89 	atomic_t urbs_used;
90 
91 	struct stk_video vsettings;
92 
93 	enum stk_status status;
94 
95 	spinlock_t spinlock;
96 	wait_queue_head_t wait_frame;
97 
98 	struct stk_iso_buf *isobufs;
99 
100 	int frame_size;
101 	/* Streaming buffers */
102 	int reading;
103 	unsigned int n_sbufs;
104 	struct stk_sio_buffer *sio_bufs;
105 	struct list_head sio_avail;
106 	struct list_head sio_full;
107 	unsigned sequence;
108 };
109 
110 #define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)
111 
112 int stk_camera_write_reg(struct stk_camera *, u16, u8);
113 int stk_camera_read_reg(struct stk_camera *, u16, u8 *);
114 
115 int stk_sensor_init(struct stk_camera *);
116 int stk_sensor_configure(struct stk_camera *);
117 int stk_sensor_sleep(struct stk_camera *dev);
118 int stk_sensor_wakeup(struct stk_camera *dev);
119 int stk_sensor_set_brightness(struct stk_camera *dev, int br);
120 
121 #endif
122