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> |
| 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 */ |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 37 | unsigned char buswidth; /* See comment in .c */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 38 | struct soc_camera_ops *ops; |
| 39 | struct video_device *vdev; |
| 40 | const struct soc_camera_data_format *current_fmt; |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 41 | const struct soc_camera_data_format *formats; |
| 42 | int num_formats; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 43 | struct module *owner; |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 44 | /* soc_camera.c private count. Only accessed with video_lock held */ |
| 45 | int use_count; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | struct soc_camera_file { |
| 49 | struct soc_camera_device *icd; |
| 50 | struct videobuf_queue vb_vidq; |
Guennadi Liakhovetski | 1a0063a | 2008-04-04 13:46:34 -0300 | [diff] [blame] | 51 | spinlock_t *lock; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct soc_camera_host { |
| 55 | struct list_head list; |
| 56 | struct device dev; |
| 57 | unsigned char nr; /* Host number */ |
| 58 | size_t msize; |
| 59 | struct videobuf_queue_ops *vbq_ops; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 60 | void *priv; |
| 61 | char *drv_name; |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 62 | struct soc_camera_host_ops *ops; |
| 63 | }; |
| 64 | |
| 65 | struct soc_camera_host_ops { |
| 66 | struct module *owner; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 67 | int (*add)(struct soc_camera_device *); |
| 68 | void (*remove)(struct soc_camera_device *); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 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 *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 72 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); |
| 73 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 74 | int (*try_bus_param)(struct soc_camera_device *, __u32); |
| 75 | int (*set_bus_param)(struct soc_camera_device *, __u32); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 76 | unsigned int (*poll)(struct file *, poll_table *); |
Guennadi Liakhovetski | 1a0063a | 2008-04-04 13:46:34 -0300 | [diff] [blame] | 77 | spinlock_t* (*spinlock_alloc)(struct soc_camera_file *); |
| 78 | void (*spinlock_free)(spinlock_t *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | struct 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 | |
| 88 | static 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 | |
| 93 | static 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 Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 98 | extern int soc_camera_host_register(struct soc_camera_host *ici); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 99 | extern void soc_camera_host_unregister(struct soc_camera_host *ici); |
| 100 | extern int soc_camera_device_register(struct soc_camera_device *icd); |
| 101 | extern void soc_camera_device_unregister(struct soc_camera_device *icd); |
| 102 | |
| 103 | extern int soc_camera_video_start(struct soc_camera_device *icd); |
| 104 | extern void soc_camera_video_stop(struct soc_camera_device *icd); |
| 105 | |
| 106 | struct soc_camera_data_format { |
| 107 | char *name; |
| 108 | unsigned int depth; |
| 109 | __u32 fourcc; |
| 110 | enum v4l2_colorspace colorspace; |
| 111 | }; |
| 112 | |
| 113 | struct soc_camera_ops { |
| 114 | struct module *owner; |
Guennadi Liakhovetski | 26f1b94 | 2008-03-24 12:18:36 -0300 | [diff] [blame] | 115 | int (*probe)(struct soc_camera_device *); |
| 116 | void (*remove)(struct soc_camera_device *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 117 | int (*init)(struct soc_camera_device *); |
| 118 | int (*release)(struct soc_camera_device *); |
| 119 | int (*start_capture)(struct soc_camera_device *); |
| 120 | int (*stop_capture)(struct soc_camera_device *); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 121 | int (*set_fmt_cap)(struct soc_camera_device *, __u32, |
| 122 | struct v4l2_rect *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 123 | int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 124 | unsigned long (*query_bus_param)(struct soc_camera_device *); |
| 125 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 126 | int (*get_chip_id)(struct soc_camera_device *, |
| 127 | struct v4l2_chip_ident *); |
| 128 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 129 | int (*get_register)(struct soc_camera_device *, struct v4l2_register *); |
| 130 | int (*set_register)(struct soc_camera_device *, struct v4l2_register *); |
| 131 | #endif |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 132 | int (*get_control)(struct soc_camera_device *, struct v4l2_control *); |
| 133 | int (*set_control)(struct soc_camera_device *, struct v4l2_control *); |
| 134 | const struct v4l2_queryctrl *controls; |
| 135 | int num_controls; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( |
| 139 | struct soc_camera_ops *ops, int id) |
| 140 | { |
| 141 | int i; |
| 142 | |
| 143 | for (i = 0; i < ops->num_controls; i++) |
| 144 | if (ops->controls[i].id == id) |
| 145 | return &ops->controls[i]; |
| 146 | |
| 147 | return NULL; |
| 148 | } |
| 149 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 150 | #define SOCAM_MASTER (1 << 0) |
| 151 | #define SOCAM_SLAVE (1 << 1) |
| 152 | #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2) |
| 153 | #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3) |
| 154 | #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4) |
| 155 | #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5) |
| 156 | #define SOCAM_DATAWIDTH_8 (1 << 6) |
| 157 | #define SOCAM_DATAWIDTH_9 (1 << 7) |
| 158 | #define SOCAM_DATAWIDTH_10 (1 << 8) |
| 159 | #define SOCAM_PCLK_SAMPLE_RISING (1 << 9) |
| 160 | #define SOCAM_PCLK_SAMPLE_FALLING (1 << 10) |
| 161 | |
| 162 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \ |
| 163 | SOCAM_DATAWIDTH_10) |
| 164 | |
| 165 | static inline unsigned long soc_camera_bus_param_compatible( |
| 166 | unsigned long camera_flags, unsigned long bus_flags) |
| 167 | { |
| 168 | unsigned long common_flags, hsync, vsync, pclk; |
| 169 | |
| 170 | common_flags = camera_flags & bus_flags; |
| 171 | |
| 172 | hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW); |
| 173 | vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW); |
| 174 | pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING); |
| 175 | |
| 176 | return (!hsync || !vsync || !pclk) ? 0 : common_flags; |
| 177 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 178 | |
| 179 | #endif |