blob: 4d8cb0796bc60d637cd69a7381cb93e1318a723d [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>
Junghak Sungc1399902015-09-22 10:30:29 -030020#include <media/videobuf2-v4l2.h>
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030021#include <media/v4l2-async.h>
Hans Verkuilee02da62011-09-06 12:36:39 -030022#include <media/v4l2-ctrls.h>
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030023#include <media/v4l2-device.h>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030024
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030025struct file;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030026struct soc_camera_desc;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030027struct soc_camera_async_client;
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030028
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030029struct soc_camera_device {
Guennadi Liakhovetskid33b2902011-07-01 11:31:35 -030030 struct list_head list; /* list of all registered devices */
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030031 struct soc_camera_desc *sdesc;
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030032 struct device *pdev; /* Platform device */
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030033 struct device *parent; /* Camera host device */
34 struct device *control; /* E.g., the i2c client */
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -030035 s32 user_width;
36 s32 user_height;
Sergio Aguirre0e4c1802011-03-07 21:49:48 -030037 u32 bytesperline; /* for padding, zero if unused */
38 u32 sizeimage;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030039 enum v4l2_colorspace colorspace;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030040 unsigned char iface; /* Host number */
41 unsigned char devnum; /* Device number per host */
Guennadi Liakhovetskia9bef512008-12-18 11:34:20 -030042 struct soc_camera_sense *sense; /* See comment in struct definition */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030043 struct video_device *vdev;
Hans Verkuilee02da62011-09-06 12:36:39 -030044 struct v4l2_ctrl_handler ctrl_handler;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030045 const struct soc_camera_format_xlate *current_fmt;
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -030046 struct soc_camera_format_xlate *user_formats;
47 int num_user_formats;
Guennadi Liakhovetski025c18a2009-03-13 06:08:20 -030048 enum v4l2_field field; /* Preserve field over close() */
Guennadi Liakhovetski1c3bb742008-12-18 12:28:54 -030049 void *host_priv; /* Per-device host private data */
Guennadi Liakhovetskidd669e92012-12-24 09:31:33 -030050 /* soc_camera.c private count. Only accessed with .host_lock held */
Guennadi Liakhovetski9dc4e482008-04-22 14:45:32 -030051 int use_count;
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030052 struct file *streamer; /* stream owner */
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -030053 struct v4l2_clk *clk;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030054 /* Asynchronous subdevice management */
55 struct soc_camera_async_client *sasc;
56 /* video buffer queue */
Laurent Pinchart73a01592017-03-08 12:33:27 -030057 struct vb2_queue vb2_vidq;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030058};
59
Laurent Pinchart914f05c2012-03-21 08:03:28 -030060/* Host supports programmable stride */
61#define SOCAM_HOST_CAP_STRIDE (1 << 0)
62
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030063enum soc_camera_subdev_role {
64 SOCAM_SUBDEV_DATA_SOURCE = 1,
65 SOCAM_SUBDEV_DATA_SINK,
66 SOCAM_SUBDEV_DATA_PROCESSOR,
67};
68
69struct soc_camera_async_subdev {
70 struct v4l2_async_subdev asd;
71 enum soc_camera_subdev_role role;
72};
73
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030074struct soc_camera_host {
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030075 struct v4l2_device v4l2_dev;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030076 struct list_head list;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030077 struct mutex host_lock; /* Main synchronisation lock */
78 struct mutex clk_lock; /* Protect pipeline modifications */
Guennadi Liakhovetski2f9a0c82012-04-18 06:43:09 -030079 unsigned char nr; /* Host number */
Laurent Pinchart914f05c2012-03-21 08:03:28 -030080 u32 capabilities;
Guennadi Liakhovetskif7f6ce22013-04-04 08:21:12 -030081 struct soc_camera_device *icd; /* Currently attached client */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030082 void *priv;
Kay Sieversaf128a12008-10-30 00:51:46 -030083 const char *drv_name;
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030084 struct soc_camera_host_ops *ops;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030085 struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */
Guennadi Liakhovetskif687f322013-06-24 05:19:19 -030086 unsigned int *asd_sizes; /* 0-terminated array of asd group sizes */
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030087};
88
89struct soc_camera_host_ops {
90 struct module *owner;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030091 int (*add)(struct soc_camera_device *);
92 void (*remove)(struct soc_camera_device *);
Guennadi Liakhovetskieb569cf2013-04-04 08:51:36 -030093 int (*clock_start)(struct soc_camera_host *);
94 void (*clock_stop)(struct soc_camera_host *);
Guennadi Liakhovetskifa489842009-08-25 11:46:43 -030095 /*
96 * .get_formats() is called for each client device format, but
97 * .put_formats() is only called once. Further, if any of the calls to
98 * .get_formats() fail, .put_formats() will not be called at all, the
99 * failing .get_formats() must then clean up internally.
100 */
Hans Verkuil3805f202010-05-08 17:55:00 -0300101 int (*get_formats)(struct soc_camera_device *, unsigned int,
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300102 struct soc_camera_format_xlate *);
Guennadi Liakhovetskifa489842009-08-25 11:46:43 -0300103 void (*put_formats)(struct soc_camera_device *);
Guennadi Liakhovetski3bfb4102012-06-22 13:40:08 -0300104 int (*get_selection)(struct soc_camera_device *, struct v4l2_selection *);
105 int (*set_selection)(struct soc_camera_device *, struct v4l2_selection *);
Guennadi Liakhovetskiaee5c2f2011-03-28 13:28:28 -0300106 /*
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200107 * The difference to .set_selection() is, that .set_liveselection is not allowed
Guennadi Liakhovetskiaee5c2f2011-03-28 13:28:28 -0300108 * to change the output sizes
109 */
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200110 int (*set_liveselection)(struct soc_camera_device *, struct v4l2_selection *);
Guennadi Liakhovetski09e231b2009-03-13 06:08:20 -0300111 int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *);
Guennadi Liakhovetskid8fac212008-12-01 09:45:21 -0300112 int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *);
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -0300113 int (*init_videobuf2)(struct vb2_queue *,
114 struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300115 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
Guennadi Liakhovetski8843d112011-09-21 17:52:51 -0300116 int (*set_bus_param)(struct soc_camera_device *);
Guennadi Liakhovetskic9f6ef62010-02-09 18:00:30 +0100117 int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
118 int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
Guennadi Liakhovetskiad3537b2012-05-08 13:00:51 -0300119 int (*enum_framesizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300120 unsigned int (*poll)(struct file *, poll_table *);
121};
122
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300123#define SOCAM_SENSOR_INVERT_PCLK (1 << 0)
124#define SOCAM_SENSOR_INVERT_MCLK (1 << 1)
125#define SOCAM_SENSOR_INVERT_HSYNC (1 << 2)
126#define SOCAM_SENSOR_INVERT_VSYNC (1 << 3)
127#define SOCAM_SENSOR_INVERT_DATA (1 << 4)
128
Guennadi Liakhovetski0fd327b2009-05-07 13:25:32 -0300129struct i2c_board_info;
Alberto Panizzo96e442c2010-12-02 07:43:37 -0300130struct regulator_bulk_data;
Guennadi Liakhovetski0fd327b2009-05-07 13:25:32 -0300131
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300132struct soc_camera_subdev_desc {
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300133 /* Per camera SOCAM_SENSOR_* bus flags */
134 unsigned long flags;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300135
136 /* sensor driver private platform data */
137 void *drv_priv;
Guennadi Liakhovetski3fd7cef2009-12-11 11:15:06 -0300138
Guennadi Liakhovetski40f07532013-10-21 06:28:02 -0300139 /*
140 * Set unbalanced_power to true to deal with legacy drivers, failing to
141 * balance their calls to subdevice's .s_power() method. clock_state is
142 * then used internally by helper functions, it shouldn't be touched by
143 * drivers or the platform code.
144 */
145 bool unbalanced_power;
146 unsigned long clock_state;
147
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300148 /* Optional callbacks to power on or off and reset the sensor */
149 int (*power)(struct device *, int);
150 int (*reset)(struct device *);
151
152 /*
153 * some platforms may support different data widths than the sensors
154 * native ones due to different data line routing. Let the board code
155 * overwrite the width flags.
156 */
157 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
158 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
159 void (*free_bus)(struct soc_camera_subdev_desc *);
Guennadi Liakhovetskid3f884a2013-04-18 18:35:28 -0300160
161 /* Optional regulators that have to be managed on power on/off events */
162 struct v4l2_subdev_platform_data sd_pdata;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300163};
164
165struct soc_camera_host_desc {
166 /* Camera bus id, used to match a camera and a bus */
167 int bus_id;
168 int i2c_adapter_id;
169 struct i2c_board_info *board_info;
170 const char *module_name;
171
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -0300172 /*
Guennadi Liakhovetskid33b2902011-07-01 11:31:35 -0300173 * For non-I2C devices platform has to provide methods to add a device
174 * to the system and to remove it
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -0300175 */
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -0300176 int (*add_device)(struct soc_camera_device *);
177 void (*del_device)(struct soc_camera_device *);
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300178};
179
180/*
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -0300181 * Platform data for "soc-camera-pdrv"
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300182 * This MUST be kept binary-identical to struct soc_camera_link below, until
183 * it is completely replaced by this one, after which we can split it into its
184 * two components.
185 */
186struct soc_camera_desc {
187 struct soc_camera_subdev_desc subdev_desc;
188 struct soc_camera_host_desc host_desc;
189};
190
191/* Prepare to replace this struct: don't change its layout any more! */
192struct soc_camera_link {
193 /*
194 * Subdevice part - keep at top and compatible to
195 * struct soc_camera_subdev_desc
196 */
197
198 /* Per camera SOCAM_SENSOR_* bus flags */
199 unsigned long flags;
200
201 void *priv;
202
Guennadi Liakhovetski40f07532013-10-21 06:28:02 -0300203 /* Set by platforms to handle misbehaving drivers */
204 bool unbalanced_power;
205 /* Used by soc-camera helper functions */
206 unsigned long clock_state;
207
Stefan Herbrechtsmeier81034662008-08-14 12:04:11 -0300208 /* Optional callbacks to power on or off and reset the sensor */
209 int (*power)(struct device *, int);
210 int (*reset)(struct device *);
Sascha Hauer28f59332009-03-13 06:08:20 -0300211 /*
212 * some platforms may support different data widths than the sensors
213 * native ones due to different data line routing. Let the board code
214 * overwrite the width flags.
215 */
216 int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
217 unsigned long (*query_bus_param)(struct soc_camera_link *);
Guennadi Liakhovetski594bb462009-04-24 12:53:51 -0300218 void (*free_bus)(struct soc_camera_link *);
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300219
Guennadi Liakhovetskid3f884a2013-04-18 18:35:28 -0300220 /* Optional regulators that have to be managed on power on/off events */
221 struct regulator_bulk_data *regulators;
222 int num_regulators;
223
224 void *host_priv;
225
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300226 /*
227 * Host part - keep at bottom and compatible to
228 * struct soc_camera_host_desc
229 */
230
231 /* Camera bus id, used to match a camera and a bus */
232 int bus_id;
233 int i2c_adapter_id;
234 struct i2c_board_info *board_info;
235 const char *module_name;
236
237 /*
238 * For non-I2C devices platform has to provide methods to add a device
239 * to the system and to remove it
240 */
241 int (*add_device)(struct soc_camera_device *);
242 void (*del_device)(struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300243};
244
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300245static inline struct soc_camera_host *to_soc_camera_host(
246 const struct device *dev)
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300247{
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -0300248 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
249
250 return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300251}
252
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300253static inline struct soc_camera_desc *to_soc_camera_desc(
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300254 const struct soc_camera_device *icd)
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300255{
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300256 return icd->sdesc;
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300257}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300258
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300259static inline struct device *to_soc_camera_control(
260 const struct soc_camera_device *icd)
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300261{
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -0300262 return icd->control;
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300263}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300264
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300265static inline struct v4l2_subdev *soc_camera_to_subdev(
266 const struct soc_camera_device *icd)
Guennadi Liakhovetskic9c1f1c2009-08-25 11:46:59 -0300267{
268 struct device *control = to_soc_camera_control(icd);
269 return dev_get_drvdata(control);
270}
271
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300272int soc_camera_host_register(struct soc_camera_host *ici);
273void soc_camera_host_unregister(struct soc_camera_host *ici);
274
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300275const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300276 struct soc_camera_device *icd, unsigned int fourcc);
Guennadi Liakhovetski25c4d742008-12-01 09:44:59 -0300277
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300278/**
279 * struct soc_camera_format_xlate - match between host and sensor formats
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -0300280 * @code: code of a sensor provided format
281 * @host_fmt: host format after host translation from code
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300282 *
283 * Host and sensor translation structure. Used in table of host and sensor
284 * formats matchings in soc_camera_device. A host can override the generic list
285 * generation by implementing get_formats(), and use it for format checks and
286 * format setup.
287 */
288struct soc_camera_format_xlate {
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -0300289 u32 code;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -0300290 const struct soc_mbus_pixelfmt *host_fmt;
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300291};
292
Guennadi Liakhovetskia9bef512008-12-18 11:34:20 -0300293#define SOCAM_SENSE_PCLK_CHANGED (1 << 0)
294
295/**
296 * This struct can be attached to struct soc_camera_device by the host driver
297 * to request sense from the camera, for example, when calling .set_fmt(). The
298 * host then can check which flags are set and verify respective values if any.
299 * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has
300 * changed during this operation. After completion the host should detach sense.
301 *
302 * @flags ored SOCAM_SENSE_* flags
303 * @master_clock if the host wants to be informed about pixel-clock
304 * change, it better set master_clock.
305 * @pixel_clock_max maximum pixel clock frequency supported by the host,
306 * camera is not allowed to exceed this.
307 * @pixel_clock if the camera driver changed pixel clock during this
308 * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses
309 * master_clock to calculate the new pixel-clock and
310 * sets this field.
311 */
312struct soc_camera_sense {
313 unsigned long flags;
314 unsigned long master_clock;
315 unsigned long pixel_clock_max;
316 unsigned long pixel_clock;
317};
318
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -0300319#define SOCAM_DATAWIDTH(x) BIT((x) - 1)
320#define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4)
321#define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8)
322#define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9)
323#define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10)
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300324#define SOCAM_DATAWIDTH_12 SOCAM_DATAWIDTH(12)
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -0300325#define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15)
326#define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16)
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300327#define SOCAM_DATAWIDTH_18 SOCAM_DATAWIDTH(18)
328#define SOCAM_DATAWIDTH_24 SOCAM_DATAWIDTH(24)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300329
Guennadi Liakhovetski042d8792008-12-19 10:07:49 -0300330#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \
331 SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300332 SOCAM_DATAWIDTH_12 | SOCAM_DATAWIDTH_15 | \
333 SOCAM_DATAWIDTH_16 | SOCAM_DATAWIDTH_18 | \
334 SOCAM_DATAWIDTH_24)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300335
Márton Némethe26b3142010-02-24 17:13:29 -0300336static inline void soc_camera_limit_side(int *start, int *length,
337 unsigned int start_min,
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -0300338 unsigned int length_min, unsigned int length_max)
339{
340 if (*length < length_min)
341 *length = length_min;
342 else if (*length > length_max)
343 *length = length_max;
344
345 if (*start < start_min)
346 *start = start_min;
347 else if (*start > start_min + length_max - *length)
348 *start = start_min + length_max - *length;
349}
350
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300351unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
Guennadi Liakhovetski32c69fcc2011-07-26 11:38:01 -0300352 const struct v4l2_mbus_config *cfg);
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300353
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -0300354int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd);
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300355int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
356 struct v4l2_clk *clk);
357int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd,
358 struct v4l2_clk *clk);
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300359
360static inline int soc_camera_set_power(struct device *dev,
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300361 struct soc_camera_subdev_desc *ssdd, struct v4l2_clk *clk, bool on)
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300362{
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300363 return on ? soc_camera_power_on(dev, ssdd, clk)
364 : soc_camera_power_off(dev, ssdd, clk);
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300365}
366
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300367/* This is only temporary here - until v4l2-subdev begins to link to video_device */
368#include <linux/i2c.h>
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300369static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client)
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300370{
Guennadi Liakhovetski2f0babb72011-09-09 13:39:20 -0300371 struct v4l2_subdev *sd = i2c_get_clientdata(client);
Guennadi Liakhovetski4c0b0362011-12-05 16:01:13 -0300372 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300373 return icd ? icd->vdev : NULL;
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300374}
375
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300376static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct i2c_client *client)
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300377{
Guennadi Liakhovetski2f0babb72011-09-09 13:39:20 -0300378 return client->dev.platform_data;
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300379}
380
Hans Verkuil14381c22013-06-10 09:27:41 -0300381static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(struct video_device *vdev)
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300382{
Hans Verkuil14381c22013-06-10 09:27:41 -0300383 struct soc_camera_device *icd = video_get_drvdata(vdev);
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300384 return soc_camera_to_subdev(icd);
385}
386
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300387static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq)
Guennadi Liakhovetski8eb44762011-02-07 18:09:30 -0300388{
389 return container_of(vq, struct soc_camera_device, vb2_vidq);
390}
391
Guennadi Liakhovetski4c0b0362011-12-05 16:01:13 -0300392static inline u32 soc_camera_grp_id(const struct soc_camera_device *icd)
393{
394 return (icd->iface << 8) | (icd->devnum + 1);
395}
396
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -0300397void soc_camera_lock(struct vb2_queue *vq);
398void soc_camera_unlock(struct vb2_queue *vq);
399
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300400#endif