blob: 331c343a5b5a9b7b348420306bee475ad4a94a17 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -03002/*
3 * camera image capture (abstract) bus driver header
4 *
5 * Copyright (C) 2006, Sascha Hauer, Pengutronix
6 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -03007 */
8
9#ifndef SOC_CAMERA_H
10#define SOC_CAMERA_H
11
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -030012#include <linux/bitops.h>
Guennadi Liakhovetski52d268a2010-07-26 11:37:13 -030013#include <linux/device.h>
Guennadi Liakhovetski1c3bb742008-12-18 12:28:54 -030014#include <linux/mutex.h>
15#include <linux/pm.h>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030016#include <linux/videodev2.h>
Junghak Sungc1399902015-09-22 10:30:29 -030017#include <media/videobuf2-v4l2.h>
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030018#include <media/v4l2-async.h>
Hans Verkuilee02da62011-09-06 12:36:39 -030019#include <media/v4l2-ctrls.h>
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030020#include <media/v4l2-device.h>
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030021
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030022struct file;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030023struct soc_camera_desc;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030024struct soc_camera_async_client;
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030025
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030026struct soc_camera_device {
Guennadi Liakhovetskid33b2902011-07-01 11:31:35 -030027 struct list_head list; /* list of all registered devices */
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -030028 struct soc_camera_desc *sdesc;
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030029 struct device *pdev; /* Platform device */
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -030030 struct device *parent; /* Camera host device */
31 struct device *control; /* E.g., the i2c client */
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -030032 s32 user_width;
33 s32 user_height;
Sergio Aguirre0e4c1802011-03-07 21:49:48 -030034 u32 bytesperline; /* for padding, zero if unused */
35 u32 sizeimage;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030036 enum v4l2_colorspace colorspace;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030037 unsigned char iface; /* Host number */
38 unsigned char devnum; /* Device number per host */
Guennadi Liakhovetskia9bef512008-12-18 11:34:20 -030039 struct soc_camera_sense *sense; /* See comment in struct definition */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030040 struct video_device *vdev;
Hans Verkuilee02da62011-09-06 12:36:39 -030041 struct v4l2_ctrl_handler ctrl_handler;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -030042 const struct soc_camera_format_xlate *current_fmt;
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -030043 struct soc_camera_format_xlate *user_formats;
44 int num_user_formats;
Guennadi Liakhovetski025c18a2009-03-13 06:08:20 -030045 enum v4l2_field field; /* Preserve field over close() */
Guennadi Liakhovetski1c3bb742008-12-18 12:28:54 -030046 void *host_priv; /* Per-device host private data */
Guennadi Liakhovetskidd669e92012-12-24 09:31:33 -030047 /* soc_camera.c private count. Only accessed with .host_lock held */
Guennadi Liakhovetski9dc4e482008-04-22 14:45:32 -030048 int use_count;
Guennadi Liakhovetski57bee292010-08-17 14:29:51 -030049 struct file *streamer; /* stream owner */
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -030050 struct v4l2_clk *clk;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030051 /* Asynchronous subdevice management */
52 struct soc_camera_async_client *sasc;
53 /* video buffer queue */
Laurent Pinchart73a01592017-03-08 12:33:27 -030054 struct vb2_queue vb2_vidq;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030055};
56
Laurent Pinchart914f05c2012-03-21 08:03:28 -030057/* Host supports programmable stride */
58#define SOCAM_HOST_CAP_STRIDE (1 << 0)
59
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030060enum soc_camera_subdev_role {
61 SOCAM_SUBDEV_DATA_SOURCE = 1,
62 SOCAM_SUBDEV_DATA_SINK,
63 SOCAM_SUBDEV_DATA_PROCESSOR,
64};
65
66struct soc_camera_async_subdev {
67 struct v4l2_async_subdev asd;
68 enum soc_camera_subdev_role role;
69};
70
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030071struct soc_camera_host {
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -030072 struct v4l2_device v4l2_dev;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030073 struct list_head list;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030074 struct mutex host_lock; /* Main synchronisation lock */
75 struct mutex clk_lock; /* Protect pipeline modifications */
Guennadi Liakhovetski2f9a0c82012-04-18 06:43:09 -030076 unsigned char nr; /* Host number */
Laurent Pinchart914f05c2012-03-21 08:03:28 -030077 u32 capabilities;
Guennadi Liakhovetskif7f6ce22013-04-04 08:21:12 -030078 struct soc_camera_device *icd; /* Currently attached client */
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030079 void *priv;
Kay Sieversaf128a12008-10-30 00:51:46 -030080 const char *drv_name;
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030081 struct soc_camera_host_ops *ops;
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -030082 struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */
Guennadi Liakhovetskif687f322013-06-24 05:19:19 -030083 unsigned int *asd_sizes; /* 0-terminated array of asd group sizes */
Guennadi Liakhovetskib8d99042008-04-04 13:41:25 -030084};
85
86struct soc_camera_host_ops {
87 struct module *owner;
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -030088 int (*add)(struct soc_camera_device *);
89 void (*remove)(struct soc_camera_device *);
Guennadi Liakhovetskieb569cf2013-04-04 08:51:36 -030090 int (*clock_start)(struct soc_camera_host *);
91 void (*clock_stop)(struct soc_camera_host *);
Guennadi Liakhovetskifa489842009-08-25 11:46:43 -030092 /*
93 * .get_formats() is called for each client device format, but
94 * .put_formats() is only called once. Further, if any of the calls to
95 * .get_formats() fail, .put_formats() will not be called at all, the
96 * failing .get_formats() must then clean up internally.
97 */
Hans Verkuil3805f202010-05-08 17:55:00 -030098 int (*get_formats)(struct soc_camera_device *, unsigned int,
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -030099 struct soc_camera_format_xlate *);
Guennadi Liakhovetskifa489842009-08-25 11:46:43 -0300100 void (*put_formats)(struct soc_camera_device *);
Guennadi Liakhovetski3bfb4102012-06-22 13:40:08 -0300101 int (*get_selection)(struct soc_camera_device *, struct v4l2_selection *);
102 int (*set_selection)(struct soc_camera_device *, struct v4l2_selection *);
Guennadi Liakhovetskiaee5c2f2011-03-28 13:28:28 -0300103 /*
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200104 * The difference to .set_selection() is, that .set_liveselection is not allowed
Guennadi Liakhovetskiaee5c2f2011-03-28 13:28:28 -0300105 * to change the output sizes
106 */
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200107 int (*set_liveselection)(struct soc_camera_device *, struct v4l2_selection *);
Guennadi Liakhovetski09e231b2009-03-13 06:08:20 -0300108 int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *);
Guennadi Liakhovetskid8fac212008-12-01 09:45:21 -0300109 int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *);
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -0300110 int (*init_videobuf2)(struct vb2_queue *,
111 struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300112 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
Guennadi Liakhovetski8843d112011-09-21 17:52:51 -0300113 int (*set_bus_param)(struct soc_camera_device *);
Guennadi Liakhovetskic9f6ef62010-02-09 18:00:30 +0100114 int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
115 int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
Guennadi Liakhovetskiad3537b2012-05-08 13:00:51 -0300116 int (*enum_framesizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *);
Al Viroa3f86832017-07-02 22:22:01 -0400117 __poll_t (*poll)(struct file *, poll_table *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300118};
119
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300120#define SOCAM_SENSOR_INVERT_PCLK (1 << 0)
121#define SOCAM_SENSOR_INVERT_MCLK (1 << 1)
122#define SOCAM_SENSOR_INVERT_HSYNC (1 << 2)
123#define SOCAM_SENSOR_INVERT_VSYNC (1 << 3)
124#define SOCAM_SENSOR_INVERT_DATA (1 << 4)
125
Guennadi Liakhovetski0fd327b2009-05-07 13:25:32 -0300126struct i2c_board_info;
Alberto Panizzo96e442c2010-12-02 07:43:37 -0300127struct regulator_bulk_data;
Guennadi Liakhovetski0fd327b2009-05-07 13:25:32 -0300128
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300129struct soc_camera_subdev_desc {
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300130 /* Per camera SOCAM_SENSOR_* bus flags */
131 unsigned long flags;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300132
133 /* sensor driver private platform data */
134 void *drv_priv;
Guennadi Liakhovetski3fd7cef2009-12-11 11:15:06 -0300135
Guennadi Liakhovetski40f07532013-10-21 06:28:02 -0300136 /*
137 * Set unbalanced_power to true to deal with legacy drivers, failing to
138 * balance their calls to subdevice's .s_power() method. clock_state is
139 * then used internally by helper functions, it shouldn't be touched by
140 * drivers or the platform code.
141 */
142 bool unbalanced_power;
143 unsigned long clock_state;
144
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300145 /* Optional callbacks to power on or off and reset the sensor */
146 int (*power)(struct device *, int);
147 int (*reset)(struct device *);
148
149 /*
150 * some platforms may support different data widths than the sensors
151 * native ones due to different data line routing. Let the board code
152 * overwrite the width flags.
153 */
154 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
155 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
156 void (*free_bus)(struct soc_camera_subdev_desc *);
Guennadi Liakhovetskid3f884a2013-04-18 18:35:28 -0300157
158 /* Optional regulators that have to be managed on power on/off events */
159 struct v4l2_subdev_platform_data sd_pdata;
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300160};
161
162struct soc_camera_host_desc {
163 /* Camera bus id, used to match a camera and a bus */
164 int bus_id;
165 int i2c_adapter_id;
166 struct i2c_board_info *board_info;
167 const char *module_name;
168
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -0300169 /*
Guennadi Liakhovetskid33b2902011-07-01 11:31:35 -0300170 * For non-I2C devices platform has to provide methods to add a device
171 * to the system and to remove it
Guennadi Liakhovetskic41deba2009-08-25 11:06:21 -0300172 */
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -0300173 int (*add_device)(struct soc_camera_device *);
174 void (*del_device)(struct soc_camera_device *);
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300175};
176
177/*
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -0300178 * Platform data for "soc-camera-pdrv"
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300179 * This MUST be kept binary-identical to struct soc_camera_link below, until
180 * it is completely replaced by this one, after which we can split it into its
181 * two components.
182 */
183struct soc_camera_desc {
184 struct soc_camera_subdev_desc subdev_desc;
185 struct soc_camera_host_desc host_desc;
186};
187
188/* Prepare to replace this struct: don't change its layout any more! */
189struct soc_camera_link {
190 /*
191 * Subdevice part - keep at top and compatible to
192 * struct soc_camera_subdev_desc
193 */
194
195 /* Per camera SOCAM_SENSOR_* bus flags */
196 unsigned long flags;
197
198 void *priv;
199
Guennadi Liakhovetski40f07532013-10-21 06:28:02 -0300200 /* Set by platforms to handle misbehaving drivers */
201 bool unbalanced_power;
202 /* Used by soc-camera helper functions */
203 unsigned long clock_state;
204
Stefan Herbrechtsmeier81034662008-08-14 12:04:11 -0300205 /* Optional callbacks to power on or off and reset the sensor */
206 int (*power)(struct device *, int);
207 int (*reset)(struct device *);
Sascha Hauer28f59332009-03-13 06:08:20 -0300208 /*
209 * some platforms may support different data widths than the sensors
210 * native ones due to different data line routing. Let the board code
211 * overwrite the width flags.
212 */
213 int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
214 unsigned long (*query_bus_param)(struct soc_camera_link *);
Guennadi Liakhovetski594bb462009-04-24 12:53:51 -0300215 void (*free_bus)(struct soc_camera_link *);
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300216
Guennadi Liakhovetskid3f884a2013-04-18 18:35:28 -0300217 /* Optional regulators that have to be managed on power on/off events */
218 struct regulator_bulk_data *regulators;
219 int num_regulators;
220
221 void *host_priv;
222
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300223 /*
224 * Host part - keep at bottom and compatible to
225 * struct soc_camera_host_desc
226 */
227
228 /* Camera bus id, used to match a camera and a bus */
229 int bus_id;
230 int i2c_adapter_id;
231 struct i2c_board_info *board_info;
232 const char *module_name;
233
234 /*
235 * For non-I2C devices platform has to provide methods to add a device
236 * to the system and to remove it
237 */
238 int (*add_device)(struct soc_camera_device *);
239 void (*del_device)(struct soc_camera_device *);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300240};
241
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300242static inline struct soc_camera_host *to_soc_camera_host(
243 const struct device *dev)
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300244{
Guennadi Liakhovetski979ea1d2009-08-25 11:43:33 -0300245 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
246
247 return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev);
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300248}
249
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300250static inline struct soc_camera_desc *to_soc_camera_desc(
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300251 const struct soc_camera_device *icd)
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300252{
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300253 return icd->sdesc;
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300254}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300255
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300256static inline struct device *to_soc_camera_control(
257 const struct soc_camera_device *icd)
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300258{
Guennadi Liakhovetski7dfff952011-07-15 20:03:38 -0300259 return icd->control;
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300260}
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300261
Guennadi Liakhovetski96c75392009-08-25 11:53:23 -0300262static inline struct v4l2_subdev *soc_camera_to_subdev(
263 const struct soc_camera_device *icd)
Guennadi Liakhovetskic9c1f1c2009-08-25 11:46:59 -0300264{
265 struct device *control = to_soc_camera_control(icd);
266 return dev_get_drvdata(control);
267}
268
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300269int soc_camera_host_register(struct soc_camera_host *ici);
270void soc_camera_host_unregister(struct soc_camera_host *ici);
271
Guennadi Liakhovetski40e2e092009-08-25 11:28:22 -0300272const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300273 struct soc_camera_device *icd, unsigned int fourcc);
Guennadi Liakhovetski25c4d742008-12-01 09:44:59 -0300274
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300275/**
276 * struct soc_camera_format_xlate - match between host and sensor formats
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -0300277 * @code: code of a sensor provided format
278 * @host_fmt: host format after host translation from code
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300279 *
280 * Host and sensor translation structure. Used in table of host and sensor
281 * formats matchings in soc_camera_device. A host can override the generic list
282 * generation by implementing get_formats(), and use it for format checks and
283 * format setup.
284 */
285struct soc_camera_format_xlate {
Boris BREZILLON27ffaeb2014-11-10 14:28:31 -0300286 u32 code;
Guennadi Liakhovetski760697b2009-12-11 11:46:49 -0300287 const struct soc_mbus_pixelfmt *host_fmt;
Guennadi Liakhovetskic2786ad2008-12-01 09:45:27 -0300288};
289
Guennadi Liakhovetskia9bef512008-12-18 11:34:20 -0300290#define SOCAM_SENSE_PCLK_CHANGED (1 << 0)
291
292/**
293 * This struct can be attached to struct soc_camera_device by the host driver
294 * to request sense from the camera, for example, when calling .set_fmt(). The
295 * host then can check which flags are set and verify respective values if any.
296 * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has
297 * changed during this operation. After completion the host should detach sense.
298 *
299 * @flags ored SOCAM_SENSE_* flags
300 * @master_clock if the host wants to be informed about pixel-clock
301 * change, it better set master_clock.
302 * @pixel_clock_max maximum pixel clock frequency supported by the host,
303 * camera is not allowed to exceed this.
304 * @pixel_clock if the camera driver changed pixel clock during this
305 * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses
306 * master_clock to calculate the new pixel-clock and
307 * sets this field.
308 */
309struct soc_camera_sense {
310 unsigned long flags;
311 unsigned long master_clock;
312 unsigned long pixel_clock_max;
313 unsigned long pixel_clock;
314};
315
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -0300316#define SOCAM_DATAWIDTH(x) BIT((x) - 1)
317#define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4)
318#define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8)
319#define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9)
320#define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10)
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300321#define SOCAM_DATAWIDTH_12 SOCAM_DATAWIDTH(12)
Guennadi Liakhovetskid839fe12011-07-28 18:42:57 -0300322#define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15)
323#define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16)
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300324#define SOCAM_DATAWIDTH_18 SOCAM_DATAWIDTH(18)
325#define SOCAM_DATAWIDTH_24 SOCAM_DATAWIDTH(24)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300326
Guennadi Liakhovetski042d8792008-12-19 10:07:49 -0300327#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \
328 SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \
Phil Edworthy7b88fc02013-03-18 08:47:59 -0300329 SOCAM_DATAWIDTH_12 | SOCAM_DATAWIDTH_15 | \
330 SOCAM_DATAWIDTH_16 | SOCAM_DATAWIDTH_18 | \
331 SOCAM_DATAWIDTH_24)
Guennadi Liakhovetskiad5f2e82008-03-07 21:57:18 -0300332
Márton Némethe26b3142010-02-24 17:13:29 -0300333static inline void soc_camera_limit_side(int *start, int *length,
334 unsigned int start_min,
Guennadi Liakhovetski6a6c8782009-08-25 11:50:46 -0300335 unsigned int length_min, unsigned int length_max)
336{
337 if (*length < length_min)
338 *length = length_min;
339 else if (*length > length_max)
340 *length = length_max;
341
342 if (*start < start_min)
343 *start = start_min;
344 else if (*start > start_min + length_max - *length)
345 *start = start_min + length_max - *length;
346}
347
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300348unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
Guennadi Liakhovetski32c69fcc2011-07-26 11:38:01 -0300349 const struct v4l2_mbus_config *cfg);
Guennadi Liakhovetskibd73b362008-12-23 05:54:45 -0300350
Guennadi Liakhovetskie09da112012-12-26 12:44:11 -0300351int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd);
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300352int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
353 struct v4l2_clk *clk);
354int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd,
355 struct v4l2_clk *clk);
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300356
357static inline int soc_camera_set_power(struct device *dev,
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300358 struct soc_camera_subdev_desc *ssdd, struct v4l2_clk *clk, bool on)
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300359{
Guennadi Liakhovetski9aea4702012-12-21 13:01:55 -0300360 return on ? soc_camera_power_on(dev, ssdd, clk)
361 : soc_camera_power_off(dev, ssdd, clk);
Laurent Pinchart4ec10ba2012-07-20 10:19:50 -0300362}
363
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300364/* This is only temporary here - until v4l2-subdev begins to link to video_device */
365#include <linux/i2c.h>
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300366static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client)
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300367{
Guennadi Liakhovetski2f0babb72011-09-09 13:39:20 -0300368 struct v4l2_subdev *sd = i2c_get_clientdata(client);
Guennadi Liakhovetski4c0b0362011-12-05 16:01:13 -0300369 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300370 return icd ? icd->vdev : NULL;
Mauro Carvalho Chehab4f9fb5e2010-05-18 00:46:09 -0300371}
372
Guennadi Liakhovetski25a34812012-12-21 08:11:48 -0300373static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct i2c_client *client)
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300374{
Guennadi Liakhovetski2f0babb72011-09-09 13:39:20 -0300375 return client->dev.platform_data;
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300376}
377
Hans Verkuil14381c22013-06-10 09:27:41 -0300378static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(struct video_device *vdev)
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300379{
Hans Verkuil14381c22013-06-10 09:27:41 -0300380 struct soc_camera_device *icd = video_get_drvdata(vdev);
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300381 return soc_camera_to_subdev(icd);
382}
383
Guennadi Liakhovetski14178aa2011-09-21 15:16:30 -0300384static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq)
Guennadi Liakhovetski8eb44762011-02-07 18:09:30 -0300385{
386 return container_of(vq, struct soc_camera_device, vb2_vidq);
387}
388
Guennadi Liakhovetski4c0b0362011-12-05 16:01:13 -0300389static inline u32 soc_camera_grp_id(const struct soc_camera_device *icd)
390{
391 return (icd->iface << 8) | (icd->devnum + 1);
392}
393
Guennadi Liakhovetski592c2ab2011-01-29 12:44:51 -0300394void soc_camera_lock(struct vb2_queue *vq);
395void soc_camera_unlock(struct vb2_queue *vq);
396
Guennadi Liakhovetskie55222e2008-04-22 14:42:03 -0300397#endif