V4L/DVB (7276): soc-camera: deactivate cameras when not used
[safe/jmp/linux-2.6] / include / media / soc_camera.h
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
18 struct 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 */
37         unsigned char cached_datawidth; /* See comment in .c */
38         struct soc_camera_ops *ops;
39         struct video_device *vdev;
40         const struct soc_camera_data_format *current_fmt;
41         int (*probe)(struct soc_camera_device *icd);
42         void (*remove)(struct soc_camera_device *icd);
43         struct module *owner;
44         /* soc_camera.c private count. Only accessed with video_lock held */
45         int use_count;
46 };
47
48 struct soc_camera_file {
49         struct soc_camera_device *icd;
50         struct videobuf_queue vb_vidq;
51 };
52
53 struct 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 *);
64         int (*set_capture_format)(struct soc_camera_device *, __u32,
65                                   struct v4l2_rect *);
66         int (*try_fmt_cap)(struct soc_camera_host *, struct v4l2_format *);
67         int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
68         int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
69         unsigned int (*poll)(struct file *, poll_table *);
70 };
71
72 struct soc_camera_link {
73         /* Camera bus id, used to match a camera and a bus */
74         int bus_id;
75         /* GPIO number to switch between 8 and 10 bit modes */
76         unsigned int gpio;
77 };
78
79 static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
80 {
81         return container_of(dev, struct soc_camera_device, dev);
82 }
83
84 static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
85 {
86         return container_of(dev, struct soc_camera_host, dev);
87 }
88
89 extern int soc_camera_host_register(struct soc_camera_host *ici,
90                                      struct module *owner);
91 extern void soc_camera_host_unregister(struct soc_camera_host *ici);
92 extern int soc_camera_device_register(struct soc_camera_device *icd);
93 extern void soc_camera_device_unregister(struct soc_camera_device *icd);
94
95 extern int soc_camera_video_start(struct soc_camera_device *icd);
96 extern void soc_camera_video_stop(struct soc_camera_device *icd);
97
98 struct soc_camera_data_format {
99         char *name;
100         unsigned int depth;
101         __u32 fourcc;
102         enum v4l2_colorspace colorspace;
103 };
104
105 struct soc_camera_ops {
106         struct module *owner;
107         int (*init)(struct soc_camera_device *);
108         int (*release)(struct soc_camera_device *);
109         int (*start_capture)(struct soc_camera_device *);
110         int (*stop_capture)(struct soc_camera_device *);
111         int (*set_capture_format)(struct soc_camera_device *, __u32,
112                                   struct v4l2_rect *, unsigned int);
113         int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
114         int (*get_chip_id)(struct soc_camera_device *,
115                            struct v4l2_chip_ident *);
116 #ifdef CONFIG_VIDEO_ADV_DEBUG
117         int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
118         int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
119 #endif
120         const struct soc_camera_data_format *formats;
121         int num_formats;
122         int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
123         int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
124         const struct v4l2_queryctrl *controls;
125         int num_controls;
126         unsigned int(*get_datawidth)(struct soc_camera_device *icd);
127 };
128
129 static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
130         struct soc_camera_ops *ops, int id)
131 {
132         int i;
133
134         for (i = 0; i < ops->num_controls; i++)
135                 if (ops->controls[i].id == id)
136                         return &ops->controls[i];
137
138         return NULL;
139 }
140
141 #define IS_MASTER               (1<<0)
142 #define IS_HSYNC_ACTIVE_HIGH    (1<<1)
143 #define IS_VSYNC_ACTIVE_HIGH    (1<<2)
144 #define IS_DATAWIDTH_8          (1<<3)
145 #define IS_DATAWIDTH_9          (1<<4)
146 #define IS_DATAWIDTH_10         (1<<5)
147 #define IS_PCLK_SAMPLE_RISING   (1<<6)
148
149 #endif