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 | |
Guennadi Liakhovetski | d839fe1 | 2011-07-28 18:42:57 -0300 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Guennadi Liakhovetski | 52d268a | 2010-07-26 11:37:13 -0300 | [diff] [blame] | 16 | #include <linux/device.h> |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 17 | #include <linux/mutex.h> |
| 18 | #include <linux/pm.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 19 | #include <linux/videodev2.h> |
Paulius Zaleckas | 092d3921 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 20 | #include <media/videobuf-core.h> |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 21 | #include <media/videobuf2-core.h> |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 22 | #include <media/v4l2-ctrls.h> |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 23 | #include <media/v4l2-device.h> |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 24 | |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 25 | struct file; |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 26 | struct soc_camera_desc; |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 27 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 28 | struct soc_camera_device { |
Guennadi Liakhovetski | d33b290 | 2011-07-01 11:31:35 -0300 | [diff] [blame] | 29 | struct list_head list; /* list of all registered devices */ |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 30 | struct soc_camera_desc *sdesc; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 31 | struct device *pdev; /* Platform device */ |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 32 | struct device *parent; /* Camera host device */ |
| 33 | struct device *control; /* E.g., the i2c client */ |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 34 | s32 user_width; |
| 35 | s32 user_height; |
Sergio Aguirre | 0e4c180 | 2011-03-07 21:49:48 -0300 | [diff] [blame] | 36 | u32 bytesperline; /* for padding, zero if unused */ |
| 37 | u32 sizeimage; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 38 | enum v4l2_colorspace colorspace; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 39 | unsigned char iface; /* Host number */ |
| 40 | unsigned char devnum; /* Device number per host */ |
Guennadi Liakhovetski | a9bef51 | 2008-12-18 11:34:20 -0300 | [diff] [blame] | 41 | struct soc_camera_sense *sense; /* See comment in struct definition */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 42 | struct video_device *vdev; |
Hans Verkuil | ee02da6 | 2011-09-06 12:36:39 -0300 | [diff] [blame] | 43 | struct v4l2_ctrl_handler ctrl_handler; |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 44 | const struct soc_camera_format_xlate *current_fmt; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 45 | struct soc_camera_format_xlate *user_formats; |
| 46 | int num_user_formats; |
Guennadi Liakhovetski | 025c18a | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 47 | enum v4l2_field field; /* Preserve field over close() */ |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 48 | void *host_priv; /* Per-device host private data */ |
Guennadi Liakhovetski | dd669e9 | 2012-12-24 09:31:33 -0300 | [diff] [blame] | 49 | /* soc_camera.c private count. Only accessed with .host_lock held */ |
Guennadi Liakhovetski | 9dc4e48 | 2008-04-22 14:45:32 -0300 | [diff] [blame] | 50 | int use_count; |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 51 | struct file *streamer; /* stream owner */ |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame^] | 52 | struct v4l2_clk *clk; |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 53 | union { |
| 54 | struct videobuf_queue vb_vidq; |
| 55 | struct vb2_queue vb2_vidq; |
| 56 | }; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 57 | }; |
| 58 | |
Laurent Pinchart | 914f05c | 2012-03-21 08:03:28 -0300 | [diff] [blame] | 59 | /* Host supports programmable stride */ |
| 60 | #define SOCAM_HOST_CAP_STRIDE (1 << 0) |
| 61 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 62 | struct soc_camera_host { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 63 | struct v4l2_device v4l2_dev; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 64 | struct list_head list; |
Guennadi Liakhovetski | 7d051b3 | 2012-12-20 13:02:51 -0300 | [diff] [blame] | 65 | struct mutex host_lock; /* Protect pipeline modifications */ |
Guennadi Liakhovetski | 2f9a0c8 | 2012-04-18 06:43:09 -0300 | [diff] [blame] | 66 | unsigned char nr; /* Host number */ |
Laurent Pinchart | 914f05c | 2012-03-21 08:03:28 -0300 | [diff] [blame] | 67 | u32 capabilities; |
Guennadi Liakhovetski | f7f6ce2 | 2013-04-04 08:21:12 -0300 | [diff] [blame] | 68 | struct soc_camera_device *icd; /* Currently attached client */ |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 69 | void *priv; |
Kay Sievers | af128a1 | 2008-10-30 00:51:46 -0300 | [diff] [blame] | 70 | const char *drv_name; |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 71 | struct soc_camera_host_ops *ops; |
| 72 | }; |
| 73 | |
| 74 | struct soc_camera_host_ops { |
| 75 | struct module *owner; |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 76 | int (*add)(struct soc_camera_device *); |
| 77 | void (*remove)(struct soc_camera_device *); |
Guennadi Liakhovetski | eb569cf | 2013-04-04 08:51:36 -0300 | [diff] [blame] | 78 | int (*clock_start)(struct soc_camera_host *); |
| 79 | void (*clock_stop)(struct soc_camera_host *); |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 80 | /* |
| 81 | * .get_formats() is called for each client device format, but |
| 82 | * .put_formats() is only called once. Further, if any of the calls to |
| 83 | * .get_formats() fail, .put_formats() will not be called at all, the |
| 84 | * failing .get_formats() must then clean up internally. |
| 85 | */ |
Hans Verkuil | 3805f20 | 2010-05-08 17:55:00 -0300 | [diff] [blame] | 86 | int (*get_formats)(struct soc_camera_device *, unsigned int, |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 87 | struct soc_camera_format_xlate *); |
Guennadi Liakhovetski | fa48984 | 2009-08-25 11:46:43 -0300 | [diff] [blame] | 88 | void (*put_formats)(struct soc_camera_device *); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 89 | int (*cropcap)(struct soc_camera_device *, struct v4l2_cropcap *); |
| 90 | int (*get_crop)(struct soc_camera_device *, struct v4l2_crop *); |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 91 | int (*set_crop)(struct soc_camera_device *, const struct v4l2_crop *); |
Guennadi Liakhovetski | 3bfb410 | 2012-06-22 13:40:08 -0300 | [diff] [blame] | 92 | int (*get_selection)(struct soc_camera_device *, struct v4l2_selection *); |
| 93 | int (*set_selection)(struct soc_camera_device *, struct v4l2_selection *); |
Guennadi Liakhovetski | aee5c2f | 2011-03-28 13:28:28 -0300 | [diff] [blame] | 94 | /* |
| 95 | * The difference to .set_crop() is, that .set_livecrop is not allowed |
| 96 | * to change the output sizes |
| 97 | */ |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 98 | int (*set_livecrop)(struct soc_camera_device *, const struct v4l2_crop *); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 99 | int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); |
Guennadi Liakhovetski | d8fac21 | 2008-12-01 09:45:21 -0300 | [diff] [blame] | 100 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); |
Magnus Damm | a034d1b | 2008-07-11 20:59:34 -0300 | [diff] [blame] | 101 | void (*init_videobuf)(struct videobuf_queue *, |
Paulius Zaleckas | 092d3921 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 102 | struct soc_camera_device *); |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 103 | int (*init_videobuf2)(struct vb2_queue *, |
| 104 | struct soc_camera_device *); |
Guennadi Liakhovetski | 57bee29 | 2010-08-17 14:29:51 -0300 | [diff] [blame] | 105 | int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 106 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
Guennadi Liakhovetski | 8843d11 | 2011-09-21 17:52:51 -0300 | [diff] [blame] | 107 | int (*set_bus_param)(struct soc_camera_device *); |
Guennadi Liakhovetski | c9f6ef6 | 2010-02-09 18:00:30 +0100 | [diff] [blame] | 108 | int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *); |
| 109 | int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *); |
Guennadi Liakhovetski | ad3537b | 2012-05-08 13:00:51 -0300 | [diff] [blame] | 110 | int (*enum_framesizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 111 | unsigned int (*poll)(struct file *, poll_table *); |
| 112 | }; |
| 113 | |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 114 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) |
| 115 | #define SOCAM_SENSOR_INVERT_MCLK (1 << 1) |
| 116 | #define SOCAM_SENSOR_INVERT_HSYNC (1 << 2) |
| 117 | #define SOCAM_SENSOR_INVERT_VSYNC (1 << 3) |
| 118 | #define SOCAM_SENSOR_INVERT_DATA (1 << 4) |
| 119 | |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 120 | struct i2c_board_info; |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 121 | struct regulator_bulk_data; |
Guennadi Liakhovetski | 0fd327b | 2009-05-07 13:25:32 -0300 | [diff] [blame] | 122 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 123 | struct soc_camera_subdev_desc { |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 124 | /* Per camera SOCAM_SENSOR_* bus flags */ |
| 125 | unsigned long flags; |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 126 | |
| 127 | /* sensor driver private platform data */ |
| 128 | void *drv_priv; |
Guennadi Liakhovetski | 3fd7cef | 2009-12-11 11:15:06 -0300 | [diff] [blame] | 129 | |
Alberto Panizzo | 96e442c | 2010-12-02 07:43:37 -0300 | [diff] [blame] | 130 | /* Optional regulators that have to be managed on power on/off events */ |
| 131 | struct regulator_bulk_data *regulators; |
| 132 | int num_regulators; |
| 133 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 134 | /* Optional callbacks to power on or off and reset the sensor */ |
| 135 | int (*power)(struct device *, int); |
| 136 | int (*reset)(struct device *); |
| 137 | |
| 138 | /* |
| 139 | * some platforms may support different data widths than the sensors |
| 140 | * native ones due to different data line routing. Let the board code |
| 141 | * overwrite the width flags. |
| 142 | */ |
| 143 | int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags); |
| 144 | unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *); |
| 145 | void (*free_bus)(struct soc_camera_subdev_desc *); |
| 146 | }; |
| 147 | |
| 148 | struct soc_camera_host_desc { |
| 149 | /* Camera bus id, used to match a camera and a bus */ |
| 150 | int bus_id; |
| 151 | int i2c_adapter_id; |
| 152 | struct i2c_board_info *board_info; |
| 153 | const char *module_name; |
| 154 | |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 155 | /* |
Guennadi Liakhovetski | d33b290 | 2011-07-01 11:31:35 -0300 | [diff] [blame] | 156 | * For non-I2C devices platform has to provide methods to add a device |
| 157 | * to the system and to remove it |
Guennadi Liakhovetski | c41deba | 2009-08-25 11:06:21 -0300 | [diff] [blame] | 158 | */ |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 159 | int (*add_device)(struct soc_camera_device *); |
| 160 | void (*del_device)(struct soc_camera_device *); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /* |
| 164 | * This MUST be kept binary-identical to struct soc_camera_link below, until |
| 165 | * it is completely replaced by this one, after which we can split it into its |
| 166 | * two components. |
| 167 | */ |
| 168 | struct soc_camera_desc { |
| 169 | struct soc_camera_subdev_desc subdev_desc; |
| 170 | struct soc_camera_host_desc host_desc; |
| 171 | }; |
| 172 | |
| 173 | /* Prepare to replace this struct: don't change its layout any more! */ |
| 174 | struct soc_camera_link { |
| 175 | /* |
| 176 | * Subdevice part - keep at top and compatible to |
| 177 | * struct soc_camera_subdev_desc |
| 178 | */ |
| 179 | |
| 180 | /* Per camera SOCAM_SENSOR_* bus flags */ |
| 181 | unsigned long flags; |
| 182 | |
| 183 | void *priv; |
| 184 | |
| 185 | /* Optional regulators that have to be managed on power on/off events */ |
| 186 | struct regulator_bulk_data *regulators; |
| 187 | int num_regulators; |
| 188 | |
Stefan Herbrechtsmeier | 8103466 | 2008-08-14 12:04:11 -0300 | [diff] [blame] | 189 | /* Optional callbacks to power on or off and reset the sensor */ |
| 190 | int (*power)(struct device *, int); |
| 191 | int (*reset)(struct device *); |
Sascha Hauer | 28f5933 | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 192 | /* |
| 193 | * some platforms may support different data widths than the sensors |
| 194 | * native ones due to different data line routing. Let the board code |
| 195 | * overwrite the width flags. |
| 196 | */ |
| 197 | int (*set_bus_param)(struct soc_camera_link *, unsigned long flags); |
| 198 | unsigned long (*query_bus_param)(struct soc_camera_link *); |
Guennadi Liakhovetski | 594bb46 | 2009-04-24 12:53:51 -0300 | [diff] [blame] | 199 | void (*free_bus)(struct soc_camera_link *); |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * Host part - keep at bottom and compatible to |
| 203 | * struct soc_camera_host_desc |
| 204 | */ |
| 205 | |
| 206 | /* Camera bus id, used to match a camera and a bus */ |
| 207 | int bus_id; |
| 208 | int i2c_adapter_id; |
| 209 | struct i2c_board_info *board_info; |
| 210 | const char *module_name; |
| 211 | |
| 212 | /* |
| 213 | * For non-I2C devices platform has to provide methods to add a device |
| 214 | * to the system and to remove it |
| 215 | */ |
| 216 | int (*add_device)(struct soc_camera_device *); |
| 217 | void (*del_device)(struct soc_camera_device *); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 218 | }; |
| 219 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 220 | static inline struct soc_camera_host *to_soc_camera_host( |
| 221 | const struct device *dev) |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 222 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 223 | struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); |
| 224 | |
| 225 | return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev); |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 226 | } |
| 227 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 228 | static inline struct soc_camera_desc *to_soc_camera_desc( |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 229 | const struct soc_camera_device *icd) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 230 | { |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 231 | return icd->sdesc; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 232 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 233 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 234 | static inline struct device *to_soc_camera_control( |
| 235 | const struct soc_camera_device *icd) |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 236 | { |
Guennadi Liakhovetski | 7dfff95 | 2011-07-15 20:03:38 -0300 | [diff] [blame] | 237 | return icd->control; |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 238 | } |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 239 | |
Guennadi Liakhovetski | 96c7539 | 2009-08-25 11:53:23 -0300 | [diff] [blame] | 240 | static inline struct v4l2_subdev *soc_camera_to_subdev( |
| 241 | const struct soc_camera_device *icd) |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 242 | { |
| 243 | struct device *control = to_soc_camera_control(icd); |
| 244 | return dev_get_drvdata(control); |
| 245 | } |
| 246 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 247 | int soc_camera_host_register(struct soc_camera_host *ici); |
| 248 | void soc_camera_host_unregister(struct soc_camera_host *ici); |
| 249 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 250 | const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 251 | struct soc_camera_device *icd, unsigned int fourcc); |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 252 | |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 253 | /** |
| 254 | * struct soc_camera_format_xlate - match between host and sensor formats |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 255 | * @code: code of a sensor provided format |
| 256 | * @host_fmt: host format after host translation from code |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 257 | * |
| 258 | * Host and sensor translation structure. Used in table of host and sensor |
| 259 | * formats matchings in soc_camera_device. A host can override the generic list |
| 260 | * generation by implementing get_formats(), and use it for format checks and |
| 261 | * format setup. |
| 262 | */ |
| 263 | struct soc_camera_format_xlate { |
Guennadi Liakhovetski | 760697b | 2009-12-11 11:46:49 -0300 | [diff] [blame] | 264 | enum v4l2_mbus_pixelcode code; |
| 265 | const struct soc_mbus_pixelfmt *host_fmt; |
Guennadi Liakhovetski | c2786ad | 2008-12-01 09:45:27 -0300 | [diff] [blame] | 266 | }; |
| 267 | |
Guennadi Liakhovetski | a9bef51 | 2008-12-18 11:34:20 -0300 | [diff] [blame] | 268 | #define SOCAM_SENSE_PCLK_CHANGED (1 << 0) |
| 269 | |
| 270 | /** |
| 271 | * This struct can be attached to struct soc_camera_device by the host driver |
| 272 | * to request sense from the camera, for example, when calling .set_fmt(). The |
| 273 | * host then can check which flags are set and verify respective values if any. |
| 274 | * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has |
| 275 | * changed during this operation. After completion the host should detach sense. |
| 276 | * |
| 277 | * @flags ored SOCAM_SENSE_* flags |
| 278 | * @master_clock if the host wants to be informed about pixel-clock |
| 279 | * change, it better set master_clock. |
| 280 | * @pixel_clock_max maximum pixel clock frequency supported by the host, |
| 281 | * camera is not allowed to exceed this. |
| 282 | * @pixel_clock if the camera driver changed pixel clock during this |
| 283 | * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses |
| 284 | * master_clock to calculate the new pixel-clock and |
| 285 | * sets this field. |
| 286 | */ |
| 287 | struct soc_camera_sense { |
| 288 | unsigned long flags; |
| 289 | unsigned long master_clock; |
| 290 | unsigned long pixel_clock_max; |
| 291 | unsigned long pixel_clock; |
| 292 | }; |
| 293 | |
Guennadi Liakhovetski | d839fe1 | 2011-07-28 18:42:57 -0300 | [diff] [blame] | 294 | #define SOCAM_DATAWIDTH(x) BIT((x) - 1) |
| 295 | #define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4) |
| 296 | #define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8) |
| 297 | #define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9) |
| 298 | #define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10) |
Phil Edworthy | 7b88fc0 | 2013-03-18 08:47:59 -0300 | [diff] [blame] | 299 | #define SOCAM_DATAWIDTH_12 SOCAM_DATAWIDTH(12) |
Guennadi Liakhovetski | d839fe1 | 2011-07-28 18:42:57 -0300 | [diff] [blame] | 300 | #define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15) |
| 301 | #define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16) |
Phil Edworthy | 7b88fc0 | 2013-03-18 08:47:59 -0300 | [diff] [blame] | 302 | #define SOCAM_DATAWIDTH_18 SOCAM_DATAWIDTH(18) |
| 303 | #define SOCAM_DATAWIDTH_24 SOCAM_DATAWIDTH(24) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 304 | |
Guennadi Liakhovetski | 042d879 | 2008-12-19 10:07:49 -0300 | [diff] [blame] | 305 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \ |
| 306 | SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \ |
Phil Edworthy | 7b88fc0 | 2013-03-18 08:47:59 -0300 | [diff] [blame] | 307 | SOCAM_DATAWIDTH_12 | SOCAM_DATAWIDTH_15 | \ |
| 308 | SOCAM_DATAWIDTH_16 | SOCAM_DATAWIDTH_18 | \ |
| 309 | SOCAM_DATAWIDTH_24) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 310 | |
Márton Németh | e26b314 | 2010-02-24 17:13:29 -0300 | [diff] [blame] | 311 | static inline void soc_camera_limit_side(int *start, int *length, |
| 312 | unsigned int start_min, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 313 | unsigned int length_min, unsigned int length_max) |
| 314 | { |
| 315 | if (*length < length_min) |
| 316 | *length = length_min; |
| 317 | else if (*length > length_max) |
| 318 | *length = length_max; |
| 319 | |
| 320 | if (*start < start_min) |
| 321 | *start = start_min; |
| 322 | else if (*start > start_min + length_max - *length) |
| 323 | *start = start_min + length_max - *length; |
| 324 | } |
| 325 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 326 | unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd, |
Guennadi Liakhovetski | 32c69fcc | 2011-07-26 11:38:01 -0300 | [diff] [blame] | 327 | const struct v4l2_mbus_config *cfg); |
Guennadi Liakhovetski | bd73b36 | 2008-12-23 05:54:45 -0300 | [diff] [blame] | 328 | |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame^] | 329 | int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd, |
| 330 | struct v4l2_clk *clk); |
| 331 | int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd, |
| 332 | struct v4l2_clk *clk); |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 333 | |
| 334 | static inline int soc_camera_set_power(struct device *dev, |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame^] | 335 | struct soc_camera_subdev_desc *ssdd, struct v4l2_clk *clk, bool on) |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 336 | { |
Guennadi Liakhovetski | 9aea470 | 2012-12-21 13:01:55 -0300 | [diff] [blame^] | 337 | return on ? soc_camera_power_on(dev, ssdd, clk) |
| 338 | : soc_camera_power_off(dev, ssdd, clk); |
Laurent Pinchart | 4ec10ba | 2012-07-20 10:19:50 -0300 | [diff] [blame] | 339 | } |
| 340 | |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 341 | /* This is only temporary here - until v4l2-subdev begins to link to video_device */ |
| 342 | #include <linux/i2c.h> |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 343 | static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client) |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 344 | { |
Guennadi Liakhovetski | 2f0babb7 | 2011-09-09 13:39:20 -0300 | [diff] [blame] | 345 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Guennadi Liakhovetski | 4c0b036 | 2011-12-05 16:01:13 -0300 | [diff] [blame] | 346 | struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd); |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 347 | return icd ? icd->vdev : NULL; |
Mauro Carvalho Chehab | 4f9fb5e | 2010-05-18 00:46:09 -0300 | [diff] [blame] | 348 | } |
| 349 | |
Guennadi Liakhovetski | 25a3481 | 2012-12-21 08:11:48 -0300 | [diff] [blame] | 350 | static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct i2c_client *client) |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 351 | { |
Guennadi Liakhovetski | 2f0babb7 | 2011-09-09 13:39:20 -0300 | [diff] [blame] | 352 | return client->dev.platform_data; |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 353 | } |
| 354 | |
Hans Verkuil | 14381c2 | 2013-06-10 09:27:41 -0300 | [diff] [blame] | 355 | static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(struct video_device *vdev) |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 356 | { |
Hans Verkuil | 14381c2 | 2013-06-10 09:27:41 -0300 | [diff] [blame] | 357 | struct soc_camera_device *icd = video_get_drvdata(vdev); |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 358 | return soc_camera_to_subdev(icd); |
| 359 | } |
| 360 | |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 361 | static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq) |
Guennadi Liakhovetski | 8eb4476 | 2011-02-07 18:09:30 -0300 | [diff] [blame] | 362 | { |
| 363 | return container_of(vq, struct soc_camera_device, vb2_vidq); |
| 364 | } |
| 365 | |
Guennadi Liakhovetski | 14178aa | 2011-09-21 15:16:30 -0300 | [diff] [blame] | 366 | static inline struct soc_camera_device *soc_camera_from_vbq(const struct videobuf_queue *vq) |
Guennadi Liakhovetski | 8eb4476 | 2011-02-07 18:09:30 -0300 | [diff] [blame] | 367 | { |
| 368 | return container_of(vq, struct soc_camera_device, vb_vidq); |
| 369 | } |
| 370 | |
Guennadi Liakhovetski | 4c0b036 | 2011-12-05 16:01:13 -0300 | [diff] [blame] | 371 | static inline u32 soc_camera_grp_id(const struct soc_camera_device *icd) |
| 372 | { |
| 373 | return (icd->iface << 8) | (icd->devnum + 1); |
| 374 | } |
| 375 | |
Guennadi Liakhovetski | 592c2ab | 2011-01-29 12:44:51 -0300 | [diff] [blame] | 376 | void soc_camera_lock(struct vb2_queue *vq); |
| 377 | void soc_camera_unlock(struct vb2_queue *vq); |
| 378 | |
Guennadi Liakhovetski | e55222e | 2008-04-22 14:42:03 -0300 | [diff] [blame] | 379 | #endif |