Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 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> |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 16 | #include <media/videobuf-core.h> |
Robert Jarzmik | 2e52106 | 2008-08-01 20:14:50 -0300 | [diff] [blame] | 17 | #include <linux/pm.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 18 | |
| 19 | struct 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 Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 38 | unsigned char buswidth; /* See comment in .c */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 39 | struct soc_camera_ops *ops; |
| 40 | struct video_device *vdev; |
| 41 | const struct soc_camera_data_format *current_fmt; |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 42 | const struct soc_camera_data_format *formats; |
| 43 | int num_formats; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame^] | 44 | struct soc_camera_format_xlate *user_formats; |
| 45 | int num_user_formats; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 46 | struct module *owner; |
Guennadi Liakhovetski | d2e3dce | 2008-12-01 09:45:24 -0300 | [diff] [blame] | 47 | void *host_priv; /* per-device host private data */ |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 48 | /* soc_camera.c private count. Only accessed with video_lock held */ |
| 49 | int use_count; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct soc_camera_file { |
| 53 | struct soc_camera_device *icd; |
| 54 | struct videobuf_queue vb_vidq; |
| 55 | }; |
| 56 | |
| 57 | struct soc_camera_host { |
| 58 | struct list_head list; |
| 59 | struct device dev; |
| 60 | unsigned char nr; /* Host number */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 61 | void *priv; |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 62 | const char *drv_name; |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 63 | struct soc_camera_host_ops *ops; |
| 64 | }; |
| 65 | |
| 66 | struct soc_camera_host_ops { |
| 67 | struct module *owner; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 68 | int (*add)(struct soc_camera_device *); |
| 69 | void (*remove)(struct soc_camera_device *); |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame^] | 70 | int (*suspend)(struct soc_camera_device *, pm_message_t); |
Robert Jarzmik | 2e52106 | 2008-08-01 20:14:50 -0300 | [diff] [blame] | 71 | int (*resume)(struct soc_camera_device *); |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame^] | 72 | int (*get_formats)(struct soc_camera_device *, int, |
| 73 | struct soc_camera_format_xlate *); |
Guennadi Liakhovetski | d8fac21 | 2008-12-01 09:45:21 -0300 | [diff] [blame] | 74 | int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); |
| 75 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); |
Magnus Damm | a034d1b | 2008-07-11 20:59:34 -0300 | [diff] [blame] | 76 | void (*init_videobuf)(struct videobuf_queue *, |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 77 | struct soc_camera_device *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 78 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); |
| 79 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 80 | int (*set_bus_param)(struct soc_camera_device *, __u32); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 81 | unsigned int (*poll)(struct file *, poll_table *); |
| 82 | }; |
| 83 | |
| 84 | struct soc_camera_link { |
| 85 | /* Camera bus id, used to match a camera and a bus */ |
| 86 | int bus_id; |
| 87 | /* GPIO number to switch between 8 and 10 bit modes */ |
| 88 | unsigned int gpio; |
Stefan Herbrechtsmeier | 8103466 | 2008-08-14 12:04:11 -0300 | [diff] [blame] | 89 | /* Optional callbacks to power on or off and reset the sensor */ |
| 90 | int (*power)(struct device *, int); |
| 91 | int (*reset)(struct device *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev) |
| 95 | { |
| 96 | return container_of(dev, struct soc_camera_device, dev); |
| 97 | } |
| 98 | |
| 99 | static inline struct soc_camera_host *to_soc_camera_host(struct device *dev) |
| 100 | { |
| 101 | return container_of(dev, struct soc_camera_host, dev); |
| 102 | } |
| 103 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 104 | extern int soc_camera_host_register(struct soc_camera_host *ici); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 105 | extern void soc_camera_host_unregister(struct soc_camera_host *ici); |
| 106 | extern int soc_camera_device_register(struct soc_camera_device *icd); |
| 107 | extern void soc_camera_device_unregister(struct soc_camera_device *icd); |
| 108 | |
| 109 | extern int soc_camera_video_start(struct soc_camera_device *icd); |
| 110 | extern void soc_camera_video_stop(struct soc_camera_device *icd); |
| 111 | |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 112 | extern const struct soc_camera_data_format *soc_camera_format_by_fourcc( |
| 113 | struct soc_camera_device *icd, unsigned int fourcc); |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame^] | 114 | extern const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
| 115 | struct soc_camera_device *icd, unsigned int fourcc); |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 116 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 117 | struct soc_camera_data_format { |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 118 | const char *name; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 119 | unsigned int depth; |
| 120 | __u32 fourcc; |
| 121 | enum v4l2_colorspace colorspace; |
| 122 | }; |
| 123 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame^] | 124 | /** |
| 125 | * struct soc_camera_format_xlate - match between host and sensor formats |
| 126 | * @cam_fmt: sensor format provided by the sensor |
| 127 | * @host_fmt: host format after host translation from cam_fmt |
| 128 | * @buswidth: bus width for this format |
| 129 | * |
| 130 | * Host and sensor translation structure. Used in table of host and sensor |
| 131 | * formats matchings in soc_camera_device. A host can override the generic list |
| 132 | * generation by implementing get_formats(), and use it for format checks and |
| 133 | * format setup. |
| 134 | */ |
| 135 | struct soc_camera_format_xlate { |
| 136 | const struct soc_camera_data_format *cam_fmt; |
| 137 | const struct soc_camera_data_format *host_fmt; |
| 138 | unsigned char buswidth; |
| 139 | }; |
| 140 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 141 | struct soc_camera_ops { |
| 142 | struct module *owner; |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 143 | int (*probe)(struct soc_camera_device *); |
| 144 | void (*remove)(struct soc_camera_device *); |
Robert Jarzmik | 2e52106 | 2008-08-01 20:14:50 -0300 | [diff] [blame] | 145 | int (*suspend)(struct soc_camera_device *, pm_message_t state); |
| 146 | int (*resume)(struct soc_camera_device *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 147 | int (*init)(struct soc_camera_device *); |
| 148 | int (*release)(struct soc_camera_device *); |
| 149 | int (*start_capture)(struct soc_camera_device *); |
| 150 | int (*stop_capture)(struct soc_camera_device *); |
Guennadi Liakhovetski | d8fac21 | 2008-12-01 09:45:21 -0300 | [diff] [blame] | 151 | int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); |
| 152 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 153 | unsigned long (*query_bus_param)(struct soc_camera_device *); |
| 154 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 155 | int (*get_chip_id)(struct soc_camera_device *, |
| 156 | struct v4l2_chip_ident *); |
| 157 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 158 | int (*get_register)(struct soc_camera_device *, struct v4l2_register *); |
| 159 | int (*set_register)(struct soc_camera_device *, struct v4l2_register *); |
| 160 | #endif |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 161 | int (*get_control)(struct soc_camera_device *, struct v4l2_control *); |
| 162 | int (*set_control)(struct soc_camera_device *, struct v4l2_control *); |
| 163 | const struct v4l2_queryctrl *controls; |
| 164 | int num_controls; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( |
| 168 | struct soc_camera_ops *ops, int id) |
| 169 | { |
| 170 | int i; |
| 171 | |
| 172 | for (i = 0; i < ops->num_controls; i++) |
| 173 | if (ops->controls[i].id == id) |
| 174 | return &ops->controls[i]; |
| 175 | |
| 176 | return NULL; |
| 177 | } |
| 178 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 179 | #define SOCAM_MASTER (1 << 0) |
| 180 | #define SOCAM_SLAVE (1 << 1) |
| 181 | #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2) |
| 182 | #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3) |
| 183 | #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4) |
| 184 | #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5) |
| 185 | #define SOCAM_DATAWIDTH_8 (1 << 6) |
| 186 | #define SOCAM_DATAWIDTH_9 (1 << 7) |
| 187 | #define SOCAM_DATAWIDTH_10 (1 << 8) |
Magnus Damm | b15cf1f | 2008-07-11 21:03:25 -0300 | [diff] [blame] | 188 | #define SOCAM_DATAWIDTH_16 (1 << 9) |
| 189 | #define SOCAM_PCLK_SAMPLE_RISING (1 << 10) |
| 190 | #define SOCAM_PCLK_SAMPLE_FALLING (1 << 11) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 191 | |
| 192 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \ |
Magnus Damm | b15cf1f | 2008-07-11 21:03:25 -0300 | [diff] [blame] | 193 | SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 194 | |
| 195 | static inline unsigned long soc_camera_bus_param_compatible( |
| 196 | unsigned long camera_flags, unsigned long bus_flags) |
| 197 | { |
| 198 | unsigned long common_flags, hsync, vsync, pclk; |
| 199 | |
| 200 | common_flags = camera_flags & bus_flags; |
| 201 | |
| 202 | hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW); |
| 203 | vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW); |
| 204 | pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING); |
| 205 | |
| 206 | return (!hsync || !vsync || !pclk) ? 0 : common_flags; |
| 207 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 208 | |
| 209 | #endif |