V4L/DVB (9787): soc-camera: let camera host drivers decide upon pixel format
[GitHub/mt8127/android_kernel_alcatel_ttab.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>
092d3921 16#include <media/videobuf-core.h>
2e521061 17#include <linux/pm.h>
e55222ef
GL
18
19struct soc_camera_device {
20 struct list_head list;
21 struct device dev;
22 struct device *control;
23 unsigned short width; /* Current window */
24 unsigned short height; /* sizes */
25 unsigned short x_min; /* Camera capabilities */
26 unsigned short y_min;
27 unsigned short x_current; /* Current window location */
28 unsigned short y_current;
29 unsigned short width_min;
30 unsigned short width_max;
31 unsigned short height_min;
32 unsigned short height_max;
33 unsigned short y_skip_top; /* Lines to skip at the top */
34 unsigned short gain;
35 unsigned short exposure;
36 unsigned char iface; /* Host number */
37 unsigned char devnum; /* Device number per host */
ad5f2e85 38 unsigned char buswidth; /* See comment in .c */
e55222ef
GL
39 struct soc_camera_ops *ops;
40 struct video_device *vdev;
41 const struct soc_camera_data_format *current_fmt;
26f1b942
GL
42 const struct soc_camera_data_format *formats;
43 int num_formats;
e55222ef 44 struct module *owner;
9dc4e48f
GL
45 /* soc_camera.c private count. Only accessed with video_lock held */
46 int use_count;
e55222ef
GL
47};
48
49struct soc_camera_file {
50 struct soc_camera_device *icd;
51 struct videobuf_queue vb_vidq;
52};
53
54struct soc_camera_host {
55 struct list_head list;
56 struct device dev;
57 unsigned char nr; /* Host number */
e55222ef 58 void *priv;
af128a10 59 const char *drv_name;
b8d9904c
GL
60 struct soc_camera_host_ops *ops;
61};
62
63struct soc_camera_host_ops {
64 struct module *owner;
e55222ef
GL
65 int (*add)(struct soc_camera_device *);
66 void (*remove)(struct soc_camera_device *);
2e521061
RJ
67 int (*suspend)(struct soc_camera_device *, pm_message_t state);
68 int (*resume)(struct soc_camera_device *);
ad5f2e85
GL
69 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
70 struct v4l2_rect *);
71 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
a034d1b7 72 void (*init_videobuf)(struct videobuf_queue *,
092d3921 73 struct soc_camera_device *);
e55222ef
GL
74 int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
75 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
ad5f2e85 76 int (*set_bus_param)(struct soc_camera_device *, __u32);
e55222ef
GL
77 unsigned int (*poll)(struct file *, poll_table *);
78};
79
80struct soc_camera_link {
81 /* Camera bus id, used to match a camera and a bus */
82 int bus_id;
83 /* GPIO number to switch between 8 and 10 bit modes */
84 unsigned int gpio;
81034663
SH
85 /* Optional callbacks to power on or off and reset the sensor */
86 int (*power)(struct device *, int);
87 int (*reset)(struct device *);
e55222ef
GL
88};
89
90static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
91{
92 return container_of(dev, struct soc_camera_device, dev);
93}
94
95static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
96{
97 return container_of(dev, struct soc_camera_host, dev);
98}
99
b8d9904c 100extern int soc_camera_host_register(struct soc_camera_host *ici);
e55222ef
GL
101extern void soc_camera_host_unregister(struct soc_camera_host *ici);
102extern int soc_camera_device_register(struct soc_camera_device *icd);
103extern void soc_camera_device_unregister(struct soc_camera_device *icd);
104
105extern int soc_camera_video_start(struct soc_camera_device *icd);
106extern void soc_camera_video_stop(struct soc_camera_device *icd);
107
25c4d74e
GL
108extern const struct soc_camera_data_format *soc_camera_format_by_fourcc(
109 struct soc_camera_device *icd, unsigned int fourcc);
110
e55222ef 111struct soc_camera_data_format {
af128a10 112 const char *name;
e55222ef
GL
113 unsigned int depth;
114 __u32 fourcc;
115 enum v4l2_colorspace colorspace;
116};
117
118struct soc_camera_ops {
119 struct module *owner;
26f1b942
GL
120 int (*probe)(struct soc_camera_device *);
121 void (*remove)(struct soc_camera_device *);
2e521061
RJ
122 int (*suspend)(struct soc_camera_device *, pm_message_t state);
123 int (*resume)(struct soc_camera_device *);
e55222ef
GL
124 int (*init)(struct soc_camera_device *);
125 int (*release)(struct soc_camera_device *);
126 int (*start_capture)(struct soc_camera_device *);
127 int (*stop_capture)(struct soc_camera_device *);
ad5f2e85
GL
128 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
129 struct v4l2_rect *);
e55222ef 130 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
ad5f2e85
GL
131 unsigned long (*query_bus_param)(struct soc_camera_device *);
132 int (*set_bus_param)(struct soc_camera_device *, unsigned long);
e55222ef
GL
133 int (*get_chip_id)(struct soc_camera_device *,
134 struct v4l2_chip_ident *);
135#ifdef CONFIG_VIDEO_ADV_DEBUG
136 int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
137 int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
138#endif
e55222ef
GL
139 int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
140 int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
141 const struct v4l2_queryctrl *controls;
142 int num_controls;
e55222ef
GL
143};
144
145static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
146 struct soc_camera_ops *ops, int id)
147{
148 int i;
149
150 for (i = 0; i < ops->num_controls; i++)
151 if (ops->controls[i].id == id)
152 return &ops->controls[i];
153
154 return NULL;
155}
156
ad5f2e85
GL
157#define SOCAM_MASTER (1 << 0)
158#define SOCAM_SLAVE (1 << 1)
159#define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
160#define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
161#define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
162#define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
163#define SOCAM_DATAWIDTH_8 (1 << 6)
164#define SOCAM_DATAWIDTH_9 (1 << 7)
165#define SOCAM_DATAWIDTH_10 (1 << 8)
b15cf1fc
MD
166#define SOCAM_DATAWIDTH_16 (1 << 9)
167#define SOCAM_PCLK_SAMPLE_RISING (1 << 10)
168#define SOCAM_PCLK_SAMPLE_FALLING (1 << 11)
ad5f2e85
GL
169
170#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
b15cf1fc 171 SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16)
ad5f2e85
GL
172
173static inline unsigned long soc_camera_bus_param_compatible(
174 unsigned long camera_flags, unsigned long bus_flags)
175{
176 unsigned long common_flags, hsync, vsync, pclk;
177
178 common_flags = camera_flags & bus_flags;
179
180 hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
181 vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
182 pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
183
184 return (!hsync || !vsync || !pclk) ? 0 : common_flags;
185}
e55222ef
GL
186
187#endif