blob: d548de326722a657ae8a257fe35e214f6585f432 [file] [log] [blame]
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -03001/*
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>
Paulius Zaleckas092d3922008-07-11 20:50:31 -030016#include <media/videobuf-core.h>
Robert Jarzmik2e521062008-08-01 20:14:50 -030017#include <linux/pm.h>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030018
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 */
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -030038 unsigned char buswidth; /* See comment in .c */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030039 struct soc_camera_ops *ops;
40 struct video_device *vdev;
41 const struct soc_camera_data_format *current_fmt;
Guennadi Liakhovetski26f1b942008-03-24 12:18:36 -030042 const struct soc_camera_data_format *formats;
43 int num_formats;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030044 struct module *owner;
Guennadi Liakhovetski9dc4e482008-04-22 14:45:32 -030045 /* soc_camera.c private count. Only accessed with video_lock held */
46 int use_count;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030047};
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 */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030058 void *priv;
59 char *drv_name;
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030060 struct soc_camera_host_ops *ops;
61};
62
63struct soc_camera_host_ops {
64 struct module *owner;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030065 int (*add)(struct soc_camera_device *);
66 void (*remove)(struct soc_camera_device *);
Robert Jarzmik2e521062008-08-01 20:14:50 -030067 int (*suspend)(struct soc_camera_device *, pm_message_t state);
68 int (*resume)(struct soc_camera_device *);
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -030069 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 *);
Magnus Damma034d1b2008-07-11 20:59:34 -030072 void (*init_videobuf)(struct videobuf_queue *,
Paulius Zaleckas092d3922008-07-11 20:50:31 -030073 struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030074 int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
75 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -030076 int (*try_bus_param)(struct soc_camera_device *, __u32);
77 int (*set_bus_param)(struct soc_camera_device *, __u32);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030078 unsigned int (*poll)(struct file *, poll_table *);
79};
80
81struct soc_camera_link {
82 /* Camera bus id, used to match a camera and a bus */
83 int bus_id;
84 /* GPIO number to switch between 8 and 10 bit modes */
85 unsigned int gpio;
86};
87
88static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
89{
90 return container_of(dev, struct soc_camera_device, dev);
91}
92
93static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
94{
95 return container_of(dev, struct soc_camera_host, dev);
96}
97
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030098extern int soc_camera_host_register(struct soc_camera_host *ici);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030099extern void soc_camera_host_unregister(struct soc_camera_host *ici);
100extern int soc_camera_device_register(struct soc_camera_device *icd);
101extern void soc_camera_device_unregister(struct soc_camera_device *icd);
102
103extern int soc_camera_video_start(struct soc_camera_device *icd);
104extern void soc_camera_video_stop(struct soc_camera_device *icd);
105
106struct soc_camera_data_format {
107 char *name;
108 unsigned int depth;
109 __u32 fourcc;
110 enum v4l2_colorspace colorspace;
111};
112
113struct soc_camera_ops {
114 struct module *owner;
Guennadi Liakhovetski26f1b942008-03-24 12:18:36 -0300115 int (*probe)(struct soc_camera_device *);
116 void (*remove)(struct soc_camera_device *);
Robert Jarzmik2e521062008-08-01 20:14:50 -0300117 int (*suspend)(struct soc_camera_device *, pm_message_t state);
118 int (*resume)(struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300119 int (*init)(struct soc_camera_device *);
120 int (*release)(struct soc_camera_device *);
121 int (*start_capture)(struct soc_camera_device *);
122 int (*stop_capture)(struct soc_camera_device *);
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300123 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
124 struct v4l2_rect *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300125 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300126 unsigned long (*query_bus_param)(struct soc_camera_device *);
127 int (*set_bus_param)(struct soc_camera_device *, unsigned long);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300128 int (*get_chip_id)(struct soc_camera_device *,
129 struct v4l2_chip_ident *);
130#ifdef CONFIG_VIDEO_ADV_DEBUG
131 int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
132 int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
133#endif
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300134 int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
135 int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
136 const struct v4l2_queryctrl *controls;
137 int num_controls;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300138};
139
140static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
141 struct soc_camera_ops *ops, int id)
142{
143 int i;
144
145 for (i = 0; i < ops->num_controls; i++)
146 if (ops->controls[i].id == id)
147 return &ops->controls[i];
148
149 return NULL;
150}
151
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300152#define SOCAM_MASTER (1 << 0)
153#define SOCAM_SLAVE (1 << 1)
154#define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
155#define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
156#define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
157#define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
158#define SOCAM_DATAWIDTH_8 (1 << 6)
159#define SOCAM_DATAWIDTH_9 (1 << 7)
160#define SOCAM_DATAWIDTH_10 (1 << 8)
Magnus Dammb15cf1f2008-07-11 21:03:25 -0300161#define SOCAM_DATAWIDTH_16 (1 << 9)
162#define SOCAM_PCLK_SAMPLE_RISING (1 << 10)
163#define SOCAM_PCLK_SAMPLE_FALLING (1 << 11)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300164
165#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
Magnus Dammb15cf1f2008-07-11 21:03:25 -0300166 SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300167
168static inline unsigned long soc_camera_bus_param_compatible(
169 unsigned long camera_flags, unsigned long bus_flags)
170{
171 unsigned long common_flags, hsync, vsync, pclk;
172
173 common_flags = camera_flags & bus_flags;
174
175 hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
176 vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
177 pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
178
179 return (!hsync || !vsync || !pclk) ? 0 : common_flags;
180}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300181
182#endif