blob: 865246b001279ec611b5c7c8b3d23b194217d6f1 [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
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -030015#include <linux/bitops.h>
Guennadi Liakhovetski52d268a2010-07-26 11:37:13 -030016#include <linux/device.h>
Guennadi Liakhovetski1c3bb742008-12-18 12:28:54 -030017#include <linux/mutex.h>
18#include <linux/pm.h>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030019#include <linux/videodev2.h>
Paulius Zaleckas092d3922008-07-11 20:50:31 -030020#include <media/videobuf-core.h>
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -030021#include <media/videobuf2-core.h>
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030022#include <media/v4l2-async.h>
Hans Verkuilee02da62011-09-06 12:36:39 -030023#include <media/v4l2-ctrls.h>
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030024#include <media/v4l2-device.h>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030025
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030026struct file;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030027struct soc_camera_desc;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030028struct soc_camera_async_client;
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030029
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030030struct soc_camera_device {
Guennadi Liakhovetskid33b2902011-07-01 11:31:35 -030031 struct list_head list; /* list of all registered devices */
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030032 struct soc_camera_desc *sdesc;
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030033 struct device *pdev; /* Platform device */
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030034 struct device *parent; /* Camera host device */
35 struct device *control; /* E.g., the i2c client */
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -030036 s32 user_width;
37 s32 user_height;
Sergio Aguirre0e4c1802011-03-07 21:49:48 -030038 u32 bytesperline; /* for padding, zero if unused */
39 u32 sizeimage;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030040 enum v4l2_colorspace colorspace;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030041 unsigned char iface; /* Host number */
42 unsigned char devnum; /* Device number per host */
Guennadi Liakhovetskia9bef512008-12-18 11:34:20 -030043 struct soc_camera_sense *sense; /* See comment in struct definition */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030044 struct video_device *vdev;
Hans Verkuilee02da62011-09-06 12:36:39 -030045 struct v4l2_ctrl_handler ctrl_handler;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030046 const struct soc_camera_format_xlate *current_fmt;
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -030047 struct soc_camera_format_xlate *user_formats;
48 int num_user_formats;
Guennadi Liakhovetski025c18a2009-03-13 06:08:20 -030049 enum v4l2_field field; /* Preserve field over close() */
Guennadi Liakhovetski1c3bb742008-12-18 12:28:54 -030050 void *host_priv; /* Per-device host private data */
Guennadi Liakhovetskidd669e92012-12-24 09:31:33 -030051 /* soc_camera.c private count. Only accessed with .host_lock held */
Guennadi Liakhovetski9dc4e482008-04-22 14:45:32 -030052 int use_count;
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030053 struct file *streamer; /* stream owner */
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -030054 struct v4l2_clk *clk;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030055 /* Asynchronous subdevice management */
56 struct soc_camera_async_client *sasc;
57 /* video buffer queue */
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -030058 union {
59 struct videobuf_queue vb_vidq;
60 struct vb2_queue vb2_vidq;
61 };
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030062};
63
Laurent Pinchart914f05c2012-03-21 08:03:28 -030064/* Host supports programmable stride */
65#define SOCAM_HOST_CAP_STRIDE (1 << 0)
66
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030067enum soc_camera_subdev_role {
68 SOCAM_SUBDEV_DATA_SOURCE = 1,
69 SOCAM_SUBDEV_DATA_SINK,
70 SOCAM_SUBDEV_DATA_PROCESSOR,
71};
72
73struct soc_camera_async_subdev {
74 struct v4l2_async_subdev asd;
75 enum soc_camera_subdev_role role;
76};
77
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030078struct soc_camera_host {
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030079 struct v4l2_device v4l2_dev;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030080 struct list_head list;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030081 struct mutex host_lock; /* Main synchronisation lock */
82 struct mutex clk_lock; /* Protect pipeline modifications */
Guennadi Liakhovetski2f9a0c82012-04-18 06:43:09 -030083 unsigned char nr; /* Host number */
Laurent Pinchart914f05c2012-03-21 08:03:28 -030084 u32 capabilities;
Guennadi Liakhovetskif7f6ce22013-04-04 08:21:12 -030085 struct soc_camera_device *icd; /* Currently attached client */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030086 void *priv;
Kay Sieversaf128a12008-10-30 00:51:46 -030087 const char *drv_name;
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030088 struct soc_camera_host_ops *ops;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030089 struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */
Guennadi Liakhovetskif687f322013-06-24 05:19:19 -030090 unsigned int *asd_sizes; /* 0-terminated array of asd group sizes */
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030091};
92
93struct soc_camera_host_ops {
94 struct module *owner;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030095 int (*add)(struct soc_camera_device *);
96 void (*remove)(struct soc_camera_device *);
Guennadi Liakhovetskieb569cf92013-04-04 08:51:36 -030097 int (*clock_start)(struct soc_camera_host *);
98 void (*clock_stop)(struct soc_camera_host *);
Guennadi Liakhovetskifa489842009-08-25 11:46:43 -030099 /*
100 * .get_formats() is called for each client device format, but
101 * .put_formats() is only called once. Further, if any of the calls to
102 * .get_formats() fail, .put_formats() will not be called at all, the
103 * failing .get_formats() must then clean up internally.
104 */
Hans Verkuil3805f202010-05-08 17:55:00 -0300105 int (*get_formats)(struct soc_camera_device *, unsigned int,
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300106 struct soc_camera_format_xlate *);
Guennadi Liakhovetskifa489842009-08-25 11:46:43 -0300107 void (*put_formats)(struct soc_camera_device *);
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -0300108 int (*cropcap)(struct soc_camera_device *, struct v4l2_cropcap *);
109 int (*get_crop)(struct soc_camera_device *, struct v4l2_crop *);
Hans Verkuil4f996592012-09-05 05:10:48 -0300110 int (*set_crop)(struct soc_camera_device *, const struct v4l2_crop *);
Guennadi Liakhovetski3bfb4102012-06-22 13:40:08 -0300111 int (*get_selection)(struct soc_camera_device *, struct v4l2_selection *);
112 int (*set_selection)(struct soc_camera_device *, struct v4l2_selection *);
Guennadi Liakhovetskiaee5c2f2011-03-28 13:28:28 -0300113 /*
114 * The difference to .set_crop() is, that .set_livecrop is not allowed
115 * to change the output sizes
116 */
Hans Verkuil4f996592012-09-05 05:10:48 -0300117 int (*set_livecrop)(struct soc_camera_device *, const struct v4l2_crop *);
Guennadi Liakhovetski09e231b2009-03-13 06:08:20 -0300118 int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *);
Guennadi Liakhovetskid8fac212008-12-01 09:45:21 -0300119 int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *);
Magnus Damma034d1b2008-07-11 20:59:34 -0300120 void (*init_videobuf)(struct videobuf_queue *,
Paulius Zaleckas092d3922008-07-11 20:50:31 -0300121 struct soc_camera_device *);
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -0300122 int (*init_videobuf2)(struct vb2_queue *,
123 struct soc_camera_device *);
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -0300124 int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300125 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
Guennadi Liakhovetski8843d112011-09-21 17:52:51 -0300126 int (*set_bus_param)(struct soc_camera_device *);
Guennadi Liakhovetskic9f6ef62010-02-09 18:00:30 +0100127 int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
128 int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
Guennadi Liakhovetskiad3537b2012-05-08 13:00:51 -0300129 int (*enum_framesizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300130 unsigned int (*poll)(struct file *, poll_table *);
131};
132
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300133#define SOCAM_SENSOR_INVERT_PCLK (1 << 0)
134#define SOCAM_SENSOR_INVERT_MCLK (1 << 1)
135#define SOCAM_SENSOR_INVERT_HSYNC (1 << 2)
136#define SOCAM_SENSOR_INVERT_VSYNC (1 << 3)
137#define SOCAM_SENSOR_INVERT_DATA (1 << 4)
138
Guennadi Liakhovetski0fd327b2009-05-07 13:25:32 -0300139struct i2c_board_info;
Alberto Panizzo96e442c2010-12-02 07:43:37 -0300140struct regulator_bulk_data;
Guennadi Liakhovetski0fd327b2009-05-07 13:25:32 -0300141
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300142struct soc_camera_subdev_desc {
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300143 /* Per camera SOCAM_SENSOR_* bus flags */
144 unsigned long flags;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300145
146 /* sensor driver private platform data */
147 void *drv_priv;
Guennadi Liakhovetski3fd7cef2009-12-11 11:15:06 -0300148
Guennadi Liakhovetski40f07532013-10-21 06:28:02 -0300149 /*
150 * Set unbalanced_power to true to deal with legacy drivers, failing to
151 * balance their calls to subdevice's .s_power() method. clock_state is
152 * then used internally by helper functions, it shouldn't be touched by
153 * drivers or the platform code.
154 */
155 bool unbalanced_power;
156 unsigned long clock_state;
157
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300158 /* Optional callbacks to power on or off and reset the sensor */
159 int (*power)(struct device *, int);
160 int (*reset)(struct device *);
161
162 /*
163 * some platforms may support different data widths than the sensors
164 * native ones due to different data line routing. Let the board code
165 * overwrite the width flags.
166 */
167 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
168 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
169 void (*free_bus)(struct soc_camera_subdev_desc *);
Guennadi Liakhovetskid3f884a2013-04-18 18:35:28 -0300170
171 /* Optional regulators that have to be managed on power on/off events */
172 struct v4l2_subdev_platform_data sd_pdata;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300173};
174
175struct soc_camera_host_desc {
176 /* Camera bus id, used to match a camera and a bus */
177 int bus_id;
178 int i2c_adapter_id;
179 struct i2c_board_info *board_info;
180 const char *module_name;
181
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -0300182 /*
Guennadi Liakhovetskid33b2902011-07-01 11:31:35 -0300183 * For non-I2C devices platform has to provide methods to add a device
184 * to the system and to remove it
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -0300185 */
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -0300186 int (*add_device)(struct soc_camera_device *);
187 void (*del_device)(struct soc_camera_device *);
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300188};
189
190/*
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -0300191 * Platform data for "soc-camera-pdrv"
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300192 * This MUST be kept binary-identical to struct soc_camera_link below, until
193 * it is completely replaced by this one, after which we can split it into its
194 * two components.
195 */
196struct soc_camera_desc {
197 struct soc_camera_subdev_desc subdev_desc;
198 struct soc_camera_host_desc host_desc;
199};
200
201/* Prepare to replace this struct: don't change its layout any more! */
202struct soc_camera_link {
203 /*
204 * Subdevice part - keep at top and compatible to
205 * struct soc_camera_subdev_desc
206 */
207
208 /* Per camera SOCAM_SENSOR_* bus flags */
209 unsigned long flags;
210
211 void *priv;
212
Guennadi Liakhovetski40f07532013-10-21 06:28:02 -0300213 /* Set by platforms to handle misbehaving drivers */
214 bool unbalanced_power;
215 /* Used by soc-camera helper functions */
216 unsigned long clock_state;
217
Stefan Herbrechtsmeier81034662008-08-14 12:04:11 -0300218 /* Optional callbacks to power on or off and reset the sensor */
219 int (*power)(struct device *, int);
220 int (*reset)(struct device *);
Sascha Hauer28f59332009-03-13 06:08:20 -0300221 /*
222 * some platforms may support different data widths than the sensors
223 * native ones due to different data line routing. Let the board code
224 * overwrite the width flags.
225 */
226 int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
227 unsigned long (*query_bus_param)(struct soc_camera_link *);
Guennadi Liakhovetski594bb462009-04-24 12:53:51 -0300228 void (*free_bus)(struct soc_camera_link *);
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300229
Guennadi Liakhovetskid3f884a2013-04-18 18:35:28 -0300230 /* Optional regulators that have to be managed on power on/off events */
231 struct regulator_bulk_data *regulators;
232 int num_regulators;
233
234 void *host_priv;
235
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300236 /*
237 * Host part - keep at bottom and compatible to
238 * struct soc_camera_host_desc
239 */
240
241 /* Camera bus id, used to match a camera and a bus */
242 int bus_id;
243 int i2c_adapter_id;
244 struct i2c_board_info *board_info;
245 const char *module_name;
246
247 /*
248 * For non-I2C devices platform has to provide methods to add a device
249 * to the system and to remove it
250 */
251 int (*add_device)(struct soc_camera_device *);
252 void (*del_device)(struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300253};
254
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300255static inline struct soc_camera_host *to_soc_camera_host(
256 const struct device *dev)
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300257{
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -0300258 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
259
260 return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300261}
262
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300263static inline struct soc_camera_desc *to_soc_camera_desc(
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300264 const struct soc_camera_device *icd)
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300265{
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300266 return icd->sdesc;
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300267}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300268
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300269static inline struct device *to_soc_camera_control(
270 const struct soc_camera_device *icd)
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300271{
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -0300272 return icd->control;
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300273}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300274
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300275static inline struct v4l2_subdev *soc_camera_to_subdev(
276 const struct soc_camera_device *icd)
Guennadi Liakhovetskic9c1f1c2009-08-25 11:46:59 -0300277{
278 struct device *control = to_soc_camera_control(icd);
279 return dev_get_drvdata(control);
280}
281
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300282int soc_camera_host_register(struct soc_camera_host *ici);
283void soc_camera_host_unregister(struct soc_camera_host *ici);
284
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300285const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300286 struct soc_camera_device *icd, unsigned int fourcc);
Guennadi Liakhovetski25c4d742008-12-01 09:44:59 -0300287
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300288/**
289 * struct soc_camera_format_xlate - match between host and sensor formats
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -0300290 * @code: code of a sensor provided format
291 * @host_fmt: host format after host translation from code
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300292 *
293 * Host and sensor translation structure. Used in table of host and sensor
294 * formats matchings in soc_camera_device. A host can override the generic list
295 * generation by implementing get_formats(), and use it for format checks and
296 * format setup.
297 */
298struct soc_camera_format_xlate {
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -0300299 enum v4l2_mbus_pixelcode code;
300 const struct soc_mbus_pixelfmt *host_fmt;
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300301};
302
Guennadi Liakhovetskia9bef512008-12-18 11:34:20 -0300303#define SOCAM_SENSE_PCLK_CHANGED (1 << 0)
304
305/**
306 * This struct can be attached to struct soc_camera_device by the host driver
307 * to request sense from the camera, for example, when calling .set_fmt(). The
308 * host then can check which flags are set and verify respective values if any.
309 * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has
310 * changed during this operation. After completion the host should detach sense.
311 *
312 * @flags ored SOCAM_SENSE_* flags
313 * @master_clock if the host wants to be informed about pixel-clock
314 * change, it better set master_clock.
315 * @pixel_clock_max maximum pixel clock frequency supported by the host,
316 * camera is not allowed to exceed this.
317 * @pixel_clock if the camera driver changed pixel clock during this
318 * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses
319 * master_clock to calculate the new pixel-clock and
320 * sets this field.
321 */
322struct soc_camera_sense {
323 unsigned long flags;
324 unsigned long master_clock;
325 unsigned long pixel_clock_max;
326 unsigned long pixel_clock;
327};
328
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -0300329#define SOCAM_DATAWIDTH(x) BIT((x) - 1)
330#define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4)
331#define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8)
332#define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9)
333#define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10)
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300334#define SOCAM_DATAWIDTH_12 SOCAM_DATAWIDTH(12)
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -0300335#define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15)
336#define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16)
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300337#define SOCAM_DATAWIDTH_18 SOCAM_DATAWIDTH(18)
338#define SOCAM_DATAWIDTH_24 SOCAM_DATAWIDTH(24)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300339
Guennadi Liakhovetski042d8792008-12-19 10:07:49 -0300340#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \
341 SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300342 SOCAM_DATAWIDTH_12 | SOCAM_DATAWIDTH_15 | \
343 SOCAM_DATAWIDTH_16 | SOCAM_DATAWIDTH_18 | \
344 SOCAM_DATAWIDTH_24)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300345
Márton Némethe26b3142010-02-24 17:13:29 -0300346static inline void soc_camera_limit_side(int *start, int *length,
347 unsigned int start_min,
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -0300348 unsigned int length_min, unsigned int length_max)
349{
350 if (*length < length_min)
351 *length = length_min;
352 else if (*length > length_max)
353 *length = length_max;
354
355 if (*start < start_min)
356 *start = start_min;
357 else if (*start > start_min + length_max - *length)
358 *start = start_min + length_max - *length;
359}
360
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300361unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
Guennadi Liakhovetski32c69fcc2011-07-26 11:38:01 -0300362 const struct v4l2_mbus_config *cfg);
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300363
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -0300364int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd);
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300365int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
366 struct v4l2_clk *clk);
367int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd,
368 struct v4l2_clk *clk);
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300369
370static inline int soc_camera_set_power(struct device *dev,
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300371 struct soc_camera_subdev_desc *ssdd, struct v4l2_clk *clk, bool on)
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300372{
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300373 return on ? soc_camera_power_on(dev, ssdd, clk)
374 : soc_camera_power_off(dev, ssdd, clk);
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300375}
376
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300377/* This is only temporary here - until v4l2-subdev begins to link to video_device */
378#include <linux/i2c.h>
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300379static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client)
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300380{
Guennadi Liakhovetski2f0babb2011-09-09 13:39:20 -0300381 struct v4l2_subdev *sd = i2c_get_clientdata(client);
Guennadi Liakhovetski4c0b0362011-12-05 16:01:13 -0300382 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300383 return icd ? icd->vdev : NULL;
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300384}
385
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300386static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct i2c_client *client)
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300387{
Guennadi Liakhovetski2f0babb2011-09-09 13:39:20 -0300388 return client->dev.platform_data;
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300389}
390
Hans Verkuil14381c22013-06-10 09:27:41 -0300391static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(struct video_device *vdev)
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300392{
Hans Verkuil14381c22013-06-10 09:27:41 -0300393 struct soc_camera_device *icd = video_get_drvdata(vdev);
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300394 return soc_camera_to_subdev(icd);
395}
396
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300397static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq)
Guennadi Liakhovetski8eb44762011-02-07 18:09:30 -0300398{
399 return container_of(vq, struct soc_camera_device, vb2_vidq);
400}
401
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300402static inline struct soc_camera_device *soc_camera_from_vbq(const struct videobuf_queue *vq)
Guennadi Liakhovetski8eb44762011-02-07 18:09:30 -0300403{
404 return container_of(vq, struct soc_camera_device, vb_vidq);
405}
406
Guennadi Liakhovetski4c0b0362011-12-05 16:01:13 -0300407static inline u32 soc_camera_grp_id(const struct soc_camera_device *icd)
408{
409 return (icd->iface << 8) | (icd->devnum + 1);
410}
411
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -0300412void soc_camera_lock(struct vb2_queue *vq);
413void soc_camera_unlock(struct vb2_queue *vq);
414
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300415#endif