2 * V4L2 fwnode binding parsing library
4 * Copyright (c) 2016 Intel Corporation.
5 * Author: Sakari Ailus <sakari.ailus@linux.intel.com>
7 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
8 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
10 * Copyright (C) 2012 Renesas Electronics Corp.
11 * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 #ifndef _V4L2_FWNODE_H
18 #define _V4L2_FWNODE_H
20 #include <linux/errno.h>
21 #include <linux/fwnode.h>
22 #include <linux/list.h>
23 #include <linux/types.h>
25 #include <media/v4l2-mediabus.h>
28 struct v4l2_async_notifier
;
29 struct v4l2_async_subdev
;
31 #define V4L2_FWNODE_CSI2_MAX_DATA_LANES 4
34 * struct v4l2_fwnode_bus_mipi_csi2 - MIPI CSI-2 bus data structure
35 * @flags: media bus (V4L2_MBUS_*) flags
36 * @data_lanes: an array of physical data lane indexes
37 * @clock_lane: physical lane index of the clock lane
38 * @num_data_lanes: number of data lanes
39 * @lane_polarities: polarity of the lanes. The order is the same of
42 struct v4l2_fwnode_bus_mipi_csi2
{
44 unsigned char data_lanes
[V4L2_FWNODE_CSI2_MAX_DATA_LANES
];
45 unsigned char clock_lane
;
46 unsigned short num_data_lanes
;
47 bool lane_polarities
[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES
];
51 * struct v4l2_fwnode_bus_parallel - parallel data bus data structure
52 * @flags: media bus (V4L2_MBUS_*) flags
53 * @bus_width: bus width in bits
54 * @data_shift: data shift in bits
56 struct v4l2_fwnode_bus_parallel
{
58 unsigned char bus_width
;
59 unsigned char data_shift
;
63 * struct v4l2_fwnode_bus_mipi_csi1 - CSI-1/CCP2 data bus structure
64 * @clock_inv: polarity of clock/strobe signal
65 * false - not inverted, true - inverted
66 * @strobe: false - data/clock, true - data/strobe
67 * @lane_polarity: the polarities of the clock (index 0) and data lanes
69 * @data_lane: the number of the data lane
70 * @clock_lane: the number of the clock lane
72 struct v4l2_fwnode_bus_mipi_csi1
{
75 bool lane_polarity
[2];
76 unsigned char data_lane
;
77 unsigned char clock_lane
;
81 * struct v4l2_fwnode_endpoint - the endpoint data structure
82 * @base: fwnode endpoint of the v4l2_fwnode
84 * @bus: union with bus configuration data structure
85 * @bus.parallel: embedded &struct v4l2_fwnode_bus_parallel.
86 * Used if the bus is parallel.
87 * @bus.mipi_csi1: embedded &struct v4l2_fwnode_bus_mipi_csi1.
88 * Used if the bus is MIPI Alliance's Camera Serial
89 * Interface version 1 (MIPI CSI1) or Standard
90 * Mobile Imaging Architecture's Compact Camera Port 2
92 * @bus.mipi_csi2: embedded &struct v4l2_fwnode_bus_mipi_csi2.
93 * Used if the bus is MIPI Alliance's Camera Serial
94 * Interface version 2 (MIPI CSI2).
95 * @link_frequencies: array of supported link frequencies
96 * @nr_of_link_frequencies: number of elements in link_frequenccies array
98 struct v4l2_fwnode_endpoint
{
99 struct fwnode_endpoint base
;
101 * Fields below this line will be zeroed by
102 * v4l2_fwnode_parse_endpoint()
104 enum v4l2_mbus_type bus_type
;
106 struct v4l2_fwnode_bus_parallel parallel
;
107 struct v4l2_fwnode_bus_mipi_csi1 mipi_csi1
;
108 struct v4l2_fwnode_bus_mipi_csi2 mipi_csi2
;
110 u64
*link_frequencies
;
111 unsigned int nr_of_link_frequencies
;
115 * struct v4l2_fwnode_link - a link between two endpoints
116 * @local_node: pointer to device_node of this endpoint
117 * @local_port: identifier of the port this endpoint belongs to
118 * @remote_node: pointer to device_node of the remote endpoint
119 * @remote_port: identifier of the port the remote endpoint belongs to
121 struct v4l2_fwnode_link
{
122 struct fwnode_handle
*local_node
;
123 unsigned int local_port
;
124 struct fwnode_handle
*remote_node
;
125 unsigned int remote_port
;
129 * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
130 * @fwnode: pointer to the endpoint's fwnode handle
131 * @vep: pointer to the V4L2 fwnode data structure
133 * All properties are optional. If none are found, we don't set any flags. This
134 * means the port has a static configuration and no properties have to be
135 * specified explicitly. If any properties that identify the bus as parallel
136 * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
137 * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
138 * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
139 * reference to @fwnode.
141 * NOTE: This function does not parse properties the size of which is variable
142 * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in
143 * new drivers instead.
145 * Return: 0 on success or a negative error code on failure.
147 int v4l2_fwnode_endpoint_parse(struct fwnode_handle
*fwnode
,
148 struct v4l2_fwnode_endpoint
*vep
);
151 * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by
152 * v4l2_fwnode_endpoint_alloc_parse()
153 * @vep: the V4L2 fwnode the resources of which are to be released
155 * It is safe to call this function with NULL argument or on a V4L2 fwnode the
156 * parsing of which failed.
158 void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint
*vep
);
161 * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
162 * @fwnode: pointer to the endpoint's fwnode handle
164 * All properties are optional. If none are found, we don't set any flags. This
165 * means the port has a static configuration and no properties have to be
166 * specified explicitly. If any properties that identify the bus as parallel
167 * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
168 * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
169 * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
170 * reference to @fwnode.
172 * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
173 * v4l2_fwnode_endpoint_parse():
175 * 1. It also parses variable size data.
177 * 2. The memory it has allocated to store the variable size data must be freed
178 * using v4l2_fwnode_endpoint_free() when no longer needed.
180 * Return: Pointer to v4l2_fwnode_endpoint if successful, on an error pointer
183 struct v4l2_fwnode_endpoint
*v4l2_fwnode_endpoint_alloc_parse(
184 struct fwnode_handle
*fwnode
);
187 * v4l2_fwnode_parse_link() - parse a link between two endpoints
188 * @fwnode: pointer to the endpoint's fwnode at the local end of the link
189 * @link: pointer to the V4L2 fwnode link data structure
191 * Fill the link structure with the local and remote nodes and port numbers.
192 * The local_node and remote_node fields are set to point to the local and
193 * remote port's parent nodes respectively (the port parent node being the
194 * parent node of the port node if that node isn't a 'ports' node, or the
195 * grand-parent node of the port node otherwise).
197 * A reference is taken to both the local and remote nodes, the caller must use
198 * v4l2_fwnode_put_link() to drop the references when done with the
201 * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be
204 int v4l2_fwnode_parse_link(struct fwnode_handle
*fwnode
,
205 struct v4l2_fwnode_link
*link
);
208 * v4l2_fwnode_put_link() - drop references to nodes in a link
209 * @link: pointer to the V4L2 fwnode link data structure
211 * Drop references to the local and remote nodes in the link. This function
212 * must be called on every link parsed with v4l2_fwnode_parse_link().
214 void v4l2_fwnode_put_link(struct v4l2_fwnode_link
*link
);
218 * typedef parse_endpoint_func - Driver's callback function to be called on
219 * each V4L2 fwnode endpoint.
221 * @dev: pointer to &struct device
222 * @vep: pointer to &struct v4l2_fwnode_endpoint
223 * @asd: pointer to &struct v4l2_async_subdev
227 * * %-ENOTCONN if the endpoint is to be skipped but this
228 * should not be considered as an error
229 * * %-EINVAL if the endpoint configuration is invalid
231 typedef int (*parse_endpoint_func
)(struct device
*dev
,
232 struct v4l2_fwnode_endpoint
*vep
,
233 struct v4l2_async_subdev
*asd
);
237 * v4l2_async_notifier_parse_fwnode_endpoints - Parse V4L2 fwnode endpoints in a
239 * @dev: the device the endpoints of which are to be parsed
240 * @notifier: notifier for @dev
241 * @asd_struct_size: size of the driver's async sub-device struct, including
242 * sizeof(struct v4l2_async_subdev). The &struct
243 * v4l2_async_subdev shall be the first member of
244 * the driver's async sub-device struct, i.e. both
245 * begin at the same memory address.
246 * @parse_endpoint: Driver's callback function called on each V4L2 fwnode
247 * endpoint. Optional.
249 * Parse the fwnode endpoints of the @dev device and populate the async sub-
250 * devices array of the notifier. The @parse_endpoint callback function is
251 * called for each endpoint with the corresponding async sub-device pointer to
252 * let the caller initialize the driver-specific part of the async sub-device
255 * The notifier memory shall be zeroed before this function is called on the
258 * This function may not be called on a registered notifier and may be called on
259 * a notifier only once.
261 * Do not change the notifier's subdevs array, take references to the subdevs
262 * array itself or change the notifier's num_subdevs field. This is because this
263 * function allocates and reallocates the subdevs array based on parsing
266 * The &struct v4l2_fwnode_endpoint passed to the callback function
267 * @parse_endpoint is released once the function is finished. If there is a need
268 * to retain that configuration, the user needs to allocate memory for it.
270 * Any notifier populated using this function must be released with a call to
271 * v4l2_async_notifier_cleanup() after it has been unregistered and the async
272 * sub-devices are no longer in use, even if the function returned an error.
274 * Return: %0 on success, including when no async sub-devices are found
275 * %-ENOMEM if memory allocation failed
276 * %-EINVAL if graph or endpoint parsing failed
277 * Other error codes as returned by @parse_endpoint
279 int v4l2_async_notifier_parse_fwnode_endpoints(
280 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
281 size_t asd_struct_size
,
282 parse_endpoint_func parse_endpoint
);
285 * v4l2_async_notifier_parse_fwnode_endpoints_by_port - Parse V4L2 fwnode
286 * endpoints of a port in a
288 * @dev: the device the endpoints of which are to be parsed
289 * @notifier: notifier for @dev
290 * @asd_struct_size: size of the driver's async sub-device struct, including
291 * sizeof(struct v4l2_async_subdev). The &struct
292 * v4l2_async_subdev shall be the first member of
293 * the driver's async sub-device struct, i.e. both
294 * begin at the same memory address.
295 * @port: port number where endpoints are to be parsed
296 * @parse_endpoint: Driver's callback function called on each V4L2 fwnode
297 * endpoint. Optional.
299 * This function is just like v4l2_async_notifier_parse_fwnode_endpoints() with
300 * the exception that it only parses endpoints in a given port. This is useful
301 * on devices that have both sinks and sources: the async sub-devices connected
302 * to sources have already been configured by another driver (on capture
303 * devices). In this case the driver must know which ports to parse.
305 * Parse the fwnode endpoints of the @dev device on a given @port and populate
306 * the async sub-devices array of the notifier. The @parse_endpoint callback
307 * function is called for each endpoint with the corresponding async sub-device
308 * pointer to let the caller initialize the driver-specific part of the async
309 * sub-device structure.
311 * The notifier memory shall be zeroed before this function is called on the
312 * notifier the first time.
314 * This function may not be called on a registered notifier and may be called on
315 * a notifier only once per port.
317 * Do not change the notifier's subdevs array, take references to the subdevs
318 * array itself or change the notifier's num_subdevs field. This is because this
319 * function allocates and reallocates the subdevs array based on parsing
322 * The &struct v4l2_fwnode_endpoint passed to the callback function
323 * @parse_endpoint is released once the function is finished. If there is a need
324 * to retain that configuration, the user needs to allocate memory for it.
326 * Any notifier populated using this function must be released with a call to
327 * v4l2_async_notifier_cleanup() after it has been unregistered and the async
328 * sub-devices are no longer in use, even if the function returned an error.
330 * Return: %0 on success, including when no async sub-devices are found
331 * %-ENOMEM if memory allocation failed
332 * %-EINVAL if graph or endpoint parsing failed
333 * Other error codes as returned by @parse_endpoint
335 int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
336 struct device
*dev
, struct v4l2_async_notifier
*notifier
,
337 size_t asd_struct_size
, unsigned int port
,
338 parse_endpoint_func parse_endpoint
);
341 * v4l2_fwnode_reference_parse_sensor_common - parse common references on
342 * sensors for async sub-devices
343 * @dev: the device node the properties of which are parsed for references
344 * @notifier: the async notifier where the async subdevs will be added
346 * Parse common sensor properties for remote devices related to the
347 * sensor and set up async sub-devices for them.
349 * Any notifier populated using this function must be released with a call to
350 * v4l2_async_notifier_release() after it has been unregistered and the async
351 * sub-devices are no longer in use, even in the case the function returned an
354 * Return: 0 on success
355 * -ENOMEM if memory allocation failed
356 * -EINVAL if property parsing failed
358 int v4l2_async_notifier_parse_fwnode_sensor_common(
359 struct device
*dev
, struct v4l2_async_notifier
*notifier
);
361 #endif /* _V4L2_FWNODE_H */