V4L/DVB (7494): videobuf-dma-sg.c: Avoid NULL dereference and add comment about backw...
[deliverable/linux.git] / include / media / soc_camera.h
CommitLineData
e55222ef
GL
1/*
2 * camera image capture (abstract) bus driver header
3 *
4 * Copyright (C) 2006, Sascha Hauer, Pengutronix
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
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 version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef SOC_CAMERA_H
13#define SOC_CAMERA_H
14
15#include <linux/videodev2.h>
16#include <media/videobuf-dma-sg.h>
17
18struct soc_camera_device {
19 struct list_head list;
20 struct device dev;
21 struct device *control;
22 unsigned short width; /* Current window */
23 unsigned short height; /* sizes */
24 unsigned short x_min; /* Camera capabilities */
25 unsigned short y_min;
26 unsigned short x_current; /* Current window location */
27 unsigned short y_current;
28 unsigned short width_min;
29 unsigned short width_max;
30 unsigned short height_min;
31 unsigned short height_max;
32 unsigned short y_skip_top; /* Lines to skip at the top */
33 unsigned short gain;
34 unsigned short exposure;
35 unsigned char iface; /* Host number */
36 unsigned char devnum; /* Device number per host */
ad5f2e85 37 unsigned char buswidth; /* See comment in .c */
e55222ef
GL
38 struct soc_camera_ops *ops;
39 struct video_device *vdev;
40 const struct soc_camera_data_format *current_fmt;
26f1b942
GL
41 const struct soc_camera_data_format *formats;
42 int num_formats;
e55222ef 43 struct module *owner;
9dc4e48f
GL
44 /* soc_camera.c private count. Only accessed with video_lock held */
45 int use_count;
e55222ef
GL
46};
47
48struct soc_camera_file {
49 struct soc_camera_device *icd;
50 struct videobuf_queue vb_vidq;
51};
52
53struct soc_camera_host {
54 struct list_head list;
55 struct device dev;
56 unsigned char nr; /* Host number */
57 size_t msize;
58 struct videobuf_queue_ops *vbq_ops;
59 struct module *owner;
60 void *priv;
61 char *drv_name;
62 int (*add)(struct soc_camera_device *);
63 void (*remove)(struct soc_camera_device *);
ad5f2e85
GL
64 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
65 struct v4l2_rect *);
66 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
e55222ef
GL
67 int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
68 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
ad5f2e85
GL
69 int (*try_bus_param)(struct soc_camera_device *, __u32);
70 int (*set_bus_param)(struct soc_camera_device *, __u32);
e55222ef
GL
71 unsigned int (*poll)(struct file *, poll_table *);
72};
73
74struct soc_camera_link {
75 /* Camera bus id, used to match a camera and a bus */
76 int bus_id;
77 /* GPIO number to switch between 8 and 10 bit modes */
78 unsigned int gpio;
79};
80
81static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
82{
83 return container_of(dev, struct soc_camera_device, dev);
84}
85
86static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
87{
88 return container_of(dev, struct soc_camera_host, dev);
89}
90
91extern int soc_camera_host_register(struct soc_camera_host *ici,
92 struct module *owner);
93extern void soc_camera_host_unregister(struct soc_camera_host *ici);
94extern int soc_camera_device_register(struct soc_camera_device *icd);
95extern void soc_camera_device_unregister(struct soc_camera_device *icd);
96
97extern int soc_camera_video_start(struct soc_camera_device *icd);
98extern void soc_camera_video_stop(struct soc_camera_device *icd);
99
100struct soc_camera_data_format {
101 char *name;
102 unsigned int depth;
103 __u32 fourcc;
104 enum v4l2_colorspace colorspace;
105};
106
107struct soc_camera_ops {
108 struct module *owner;
26f1b942
GL
109 int (*probe)(struct soc_camera_device *);
110 void (*remove)(struct soc_camera_device *);
e55222ef
GL
111 int (*init)(struct soc_camera_device *);
112 int (*release)(struct soc_camera_device *);
113 int (*start_capture)(struct soc_camera_device *);
114 int (*stop_capture)(struct soc_camera_device *);
ad5f2e85
GL
115 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
116 struct v4l2_rect *);
e55222ef 117 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
ad5f2e85
GL
118 unsigned long (*query_bus_param)(struct soc_camera_device *);
119 int (*set_bus_param)(struct soc_camera_device *, unsigned long);
e55222ef
GL
120 int (*get_chip_id)(struct soc_camera_device *,
121 struct v4l2_chip_ident *);
122#ifdef CONFIG_VIDEO_ADV_DEBUG
123 int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
124 int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
125#endif
e55222ef
GL
126 int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
127 int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
128 const struct v4l2_queryctrl *controls;
129 int num_controls;
e55222ef
GL
130};
131
132static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
133 struct soc_camera_ops *ops, int id)
134{
135 int i;
136
137 for (i = 0; i < ops->num_controls; i++)
138 if (ops->controls[i].id == id)
139 return &ops->controls[i];
140
141 return NULL;
142}
143
ad5f2e85
GL
144#define SOCAM_MASTER (1 << 0)
145#define SOCAM_SLAVE (1 << 1)
146#define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
147#define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
148#define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
149#define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
150#define SOCAM_DATAWIDTH_8 (1 << 6)
151#define SOCAM_DATAWIDTH_9 (1 << 7)
152#define SOCAM_DATAWIDTH_10 (1 << 8)
153#define SOCAM_PCLK_SAMPLE_RISING (1 << 9)
154#define SOCAM_PCLK_SAMPLE_FALLING (1 << 10)
155
156#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
157 SOCAM_DATAWIDTH_10)
158
159static inline unsigned long soc_camera_bus_param_compatible(
160 unsigned long camera_flags, unsigned long bus_flags)
161{
162 unsigned long common_flags, hsync, vsync, pclk;
163
164 common_flags = camera_flags & bus_flags;
165
166 hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
167 vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
168 pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
169
170 return (!hsync || !vsync || !pclk) ? 0 : common_flags;
171}
e55222ef
GL
172
173#endif
This page took 0.037383 seconds and 5 git commands to generate.