Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 1 | /* |
| 2 | * V4L2 fwnode binding parsing library |
| 3 | * |
| 4 | * Copyright (c) 2016 Intel Corporation. |
| 5 | * Author: Sakari Ailus <sakari.ailus@linux.intel.com> |
| 6 | * |
| 7 | * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd. |
| 8 | * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> |
| 9 | * |
| 10 | * Copyright (C) 2012 Renesas Electronics Corp. |
| 11 | * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
| 12 | * |
| 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. |
| 16 | */ |
| 17 | #ifndef _V4L2_FWNODE_H |
| 18 | #define _V4L2_FWNODE_H |
| 19 | |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/fwnode.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/types.h> |
| 24 | |
| 25 | #include <media/v4l2-mediabus.h> |
| 26 | |
| 27 | struct fwnode_handle; |
Sakari Ailus | 9ca4653 | 2017-08-17 11:28:21 -0400 | [diff] [blame] | 28 | struct v4l2_async_notifier; |
| 29 | struct v4l2_async_subdev; |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 30 | |
Sakari Ailus | ad3cdf3 | 2017-08-14 06:43:07 -0400 | [diff] [blame] | 31 | #define V4L2_FWNODE_CSI2_MAX_DATA_LANES 4 |
Mauro Carvalho Chehab | 4ee2362 | 2017-06-26 14:07:54 -0400 | [diff] [blame] | 32 | |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 33 | /** |
| 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 |
| 40 | * the physical lanes. |
| 41 | */ |
| 42 | struct v4l2_fwnode_bus_mipi_csi2 { |
| 43 | unsigned int flags; |
Sakari Ailus | ad3cdf3 | 2017-08-14 06:43:07 -0400 | [diff] [blame] | 44 | unsigned char data_lanes[V4L2_FWNODE_CSI2_MAX_DATA_LANES]; |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 45 | unsigned char clock_lane; |
| 46 | unsigned short num_data_lanes; |
Sakari Ailus | ad3cdf3 | 2017-08-14 06:43:07 -0400 | [diff] [blame] | 47 | bool lane_polarities[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES]; |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /** |
| 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 |
| 55 | */ |
| 56 | struct v4l2_fwnode_bus_parallel { |
| 57 | unsigned int flags; |
| 58 | unsigned char bus_width; |
| 59 | unsigned char data_shift; |
| 60 | }; |
| 61 | |
| 62 | /** |
Sakari Ailus | 97bbdf0 | 2015-02-25 14:39:11 -0500 | [diff] [blame] | 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 |
Mauro Carvalho Chehab | 8382a11 | 2017-07-21 08:03:24 -0400 | [diff] [blame] | 68 | * index (1) |
Sakari Ailus | 97bbdf0 | 2015-02-25 14:39:11 -0500 | [diff] [blame] | 69 | * @data_lane: the number of the data lane |
| 70 | * @clock_lane: the number of the clock lane |
| 71 | */ |
| 72 | struct v4l2_fwnode_bus_mipi_csi1 { |
| 73 | bool clock_inv; |
| 74 | bool strobe; |
| 75 | bool lane_polarity[2]; |
| 76 | unsigned char data_lane; |
| 77 | unsigned char clock_lane; |
| 78 | }; |
| 79 | |
| 80 | /** |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 81 | * struct v4l2_fwnode_endpoint - the endpoint data structure |
| 82 | * @base: fwnode endpoint of the v4l2_fwnode |
| 83 | * @bus_type: bus type |
| 84 | * @bus: bus configuration data structure |
| 85 | * @link_frequencies: array of supported link frequencies |
| 86 | * @nr_of_link_frequencies: number of elements in link_frequenccies array |
| 87 | */ |
| 88 | struct v4l2_fwnode_endpoint { |
| 89 | struct fwnode_endpoint base; |
| 90 | /* |
| 91 | * Fields below this line will be zeroed by |
| 92 | * v4l2_fwnode_parse_endpoint() |
| 93 | */ |
| 94 | enum v4l2_mbus_type bus_type; |
| 95 | union { |
| 96 | struct v4l2_fwnode_bus_parallel parallel; |
Sakari Ailus | 97bbdf0 | 2015-02-25 14:39:11 -0500 | [diff] [blame] | 97 | struct v4l2_fwnode_bus_mipi_csi1 mipi_csi1; |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 98 | struct v4l2_fwnode_bus_mipi_csi2 mipi_csi2; |
| 99 | } bus; |
| 100 | u64 *link_frequencies; |
| 101 | unsigned int nr_of_link_frequencies; |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * struct v4l2_fwnode_link - a link between two endpoints |
| 106 | * @local_node: pointer to device_node of this endpoint |
| 107 | * @local_port: identifier of the port this endpoint belongs to |
| 108 | * @remote_node: pointer to device_node of the remote endpoint |
| 109 | * @remote_port: identifier of the port the remote endpoint belongs to |
| 110 | */ |
| 111 | struct v4l2_fwnode_link { |
| 112 | struct fwnode_handle *local_node; |
| 113 | unsigned int local_port; |
| 114 | struct fwnode_handle *remote_node; |
| 115 | unsigned int remote_port; |
| 116 | }; |
| 117 | |
Sakari Ailus | baf249e | 2017-08-29 06:13:19 -0400 | [diff] [blame] | 118 | /** |
| 119 | * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties |
| 120 | * @fwnode: pointer to the endpoint's fwnode handle |
| 121 | * @vep: pointer to the V4L2 fwnode data structure |
| 122 | * |
| 123 | * All properties are optional. If none are found, we don't set any flags. This |
| 124 | * means the port has a static configuration and no properties have to be |
| 125 | * specified explicitly. If any properties that identify the bus as parallel |
| 126 | * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if |
| 127 | * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we |
| 128 | * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a |
| 129 | * reference to @fwnode. |
| 130 | * |
| 131 | * NOTE: This function does not parse properties the size of which is variable |
| 132 | * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in |
| 133 | * new drivers instead. |
| 134 | * |
| 135 | * Return: 0 on success or a negative error code on failure. |
| 136 | */ |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 137 | int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode, |
| 138 | struct v4l2_fwnode_endpoint *vep); |
Sakari Ailus | baf249e | 2017-08-29 06:13:19 -0400 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by |
| 142 | * v4l2_fwnode_endpoint_alloc_parse() |
| 143 | * @vep: the V4L2 fwnode the resources of which are to be released |
| 144 | * |
| 145 | * It is safe to call this function with NULL argument or on a V4L2 fwnode the |
| 146 | * parsing of which failed. |
| 147 | */ |
| 148 | void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep); |
| 149 | |
| 150 | /** |
| 151 | * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties |
| 152 | * @fwnode: pointer to the endpoint's fwnode handle |
| 153 | * |
| 154 | * All properties are optional. If none are found, we don't set any flags. This |
| 155 | * means the port has a static configuration and no properties have to be |
| 156 | * specified explicitly. If any properties that identify the bus as parallel |
| 157 | * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if |
| 158 | * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we |
| 159 | * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a |
| 160 | * reference to @fwnode. |
| 161 | * |
| 162 | * v4l2_fwnode_endpoint_alloc_parse() has two important differences to |
| 163 | * v4l2_fwnode_endpoint_parse(): |
| 164 | * |
| 165 | * 1. It also parses variable size data. |
| 166 | * |
| 167 | * 2. The memory it has allocated to store the variable size data must be freed |
| 168 | * using v4l2_fwnode_endpoint_free() when no longer needed. |
| 169 | * |
| 170 | * Return: Pointer to v4l2_fwnode_endpoint if successful, on an error pointer |
| 171 | * on error. |
| 172 | */ |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 173 | struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse( |
| 174 | struct fwnode_handle *fwnode); |
Sakari Ailus | baf249e | 2017-08-29 06:13:19 -0400 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * v4l2_fwnode_parse_link() - parse a link between two endpoints |
| 178 | * @fwnode: pointer to the endpoint's fwnode at the local end of the link |
| 179 | * @link: pointer to the V4L2 fwnode link data structure |
| 180 | * |
| 181 | * Fill the link structure with the local and remote nodes and port numbers. |
| 182 | * The local_node and remote_node fields are set to point to the local and |
| 183 | * remote port's parent nodes respectively (the port parent node being the |
| 184 | * parent node of the port node if that node isn't a 'ports' node, or the |
| 185 | * grand-parent node of the port node otherwise). |
| 186 | * |
| 187 | * A reference is taken to both the local and remote nodes, the caller must use |
| 188 | * v4l2_fwnode_put_link() to drop the references when done with the |
| 189 | * link. |
| 190 | * |
| 191 | * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be |
| 192 | * found. |
| 193 | */ |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 194 | int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, |
| 195 | struct v4l2_fwnode_link *link); |
Sakari Ailus | baf249e | 2017-08-29 06:13:19 -0400 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * v4l2_fwnode_put_link() - drop references to nodes in a link |
| 199 | * @link: pointer to the V4L2 fwnode link data structure |
| 200 | * |
| 201 | * Drop references to the local and remote nodes in the link. This function |
| 202 | * must be called on every link parsed with v4l2_fwnode_parse_link(). |
| 203 | */ |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 204 | void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link); |
| 205 | |
Sakari Ailus | 9ca4653 | 2017-08-17 11:28:21 -0400 | [diff] [blame] | 206 | /** |
| 207 | * v4l2_async_notifier_parse_fwnode_endpoints - Parse V4L2 fwnode endpoints in a |
| 208 | * device node |
| 209 | * @dev: the device the endpoints of which are to be parsed |
| 210 | * @notifier: notifier for @dev |
| 211 | * @asd_struct_size: size of the driver's async sub-device struct, including |
| 212 | * sizeof(struct v4l2_async_subdev). The &struct |
| 213 | * v4l2_async_subdev shall be the first member of |
| 214 | * the driver's async sub-device struct, i.e. both |
| 215 | * begin at the same memory address. |
| 216 | * @parse_endpoint: Driver's callback function called on each V4L2 fwnode |
| 217 | * endpoint. Optional. |
| 218 | * Return: %0 on success |
| 219 | * %-ENOTCONN if the endpoint is to be skipped but this |
| 220 | * should not be considered as an error |
| 221 | * %-EINVAL if the endpoint configuration is invalid |
| 222 | * |
| 223 | * Parse the fwnode endpoints of the @dev device and populate the async sub- |
| 224 | * devices array of the notifier. The @parse_endpoint callback function is |
| 225 | * called for each endpoint with the corresponding async sub-device pointer to |
| 226 | * let the caller initialize the driver-specific part of the async sub-device |
| 227 | * structure. |
| 228 | * |
| 229 | * The notifier memory shall be zeroed before this function is called on the |
| 230 | * notifier. |
| 231 | * |
| 232 | * This function may not be called on a registered notifier and may be called on |
| 233 | * a notifier only once. |
| 234 | * |
| 235 | * Do not change the notifier's subdevs array, take references to the subdevs |
| 236 | * array itself or change the notifier's num_subdevs field. This is because this |
| 237 | * function allocates and reallocates the subdevs array based on parsing |
| 238 | * endpoints. |
| 239 | * |
| 240 | * The &struct v4l2_fwnode_endpoint passed to the callback function |
| 241 | * @parse_endpoint is released once the function is finished. If there is a need |
| 242 | * to retain that configuration, the user needs to allocate memory for it. |
| 243 | * |
| 244 | * Any notifier populated using this function must be released with a call to |
| 245 | * v4l2_async_notifier_cleanup() after it has been unregistered and the async |
| 246 | * sub-devices are no longer in use, even if the function returned an error. |
| 247 | * |
| 248 | * Return: %0 on success, including when no async sub-devices are found |
| 249 | * %-ENOMEM if memory allocation failed |
| 250 | * %-EINVAL if graph or endpoint parsing failed |
| 251 | * Other error codes as returned by @parse_endpoint |
| 252 | */ |
| 253 | int v4l2_async_notifier_parse_fwnode_endpoints( |
| 254 | struct device *dev, struct v4l2_async_notifier *notifier, |
| 255 | size_t asd_struct_size, |
| 256 | int (*parse_endpoint)(struct device *dev, |
| 257 | struct v4l2_fwnode_endpoint *vep, |
| 258 | struct v4l2_async_subdev *asd)); |
| 259 | |
| 260 | /** |
| 261 | * v4l2_async_notifier_parse_fwnode_endpoints_by_port - Parse V4L2 fwnode |
| 262 | * endpoints of a port in a |
| 263 | * device node |
| 264 | * @dev: the device the endpoints of which are to be parsed |
| 265 | * @notifier: notifier for @dev |
| 266 | * @asd_struct_size: size of the driver's async sub-device struct, including |
| 267 | * sizeof(struct v4l2_async_subdev). The &struct |
| 268 | * v4l2_async_subdev shall be the first member of |
| 269 | * the driver's async sub-device struct, i.e. both |
| 270 | * begin at the same memory address. |
| 271 | * @port: port number where endpoints are to be parsed |
| 272 | * @parse_endpoint: Driver's callback function called on each V4L2 fwnode |
| 273 | * endpoint. Optional. |
| 274 | * Return: %0 on success |
| 275 | * %-ENOTCONN if the endpoint is to be skipped but this |
| 276 | * should not be considered as an error |
| 277 | * %-EINVAL if the endpoint configuration is invalid |
| 278 | * |
| 279 | * This function is just like v4l2_async_notifier_parse_fwnode_endpoints() with |
| 280 | * the exception that it only parses endpoints in a given port. This is useful |
| 281 | * on devices that have both sinks and sources: the async sub-devices connected |
| 282 | * to sources have already been configured by another driver (on capture |
| 283 | * devices). In this case the driver must know which ports to parse. |
| 284 | * |
| 285 | * Parse the fwnode endpoints of the @dev device on a given @port and populate |
| 286 | * the async sub-devices array of the notifier. The @parse_endpoint callback |
| 287 | * function is called for each endpoint with the corresponding async sub-device |
| 288 | * pointer to let the caller initialize the driver-specific part of the async |
| 289 | * sub-device structure. |
| 290 | * |
| 291 | * The notifier memory shall be zeroed before this function is called on the |
| 292 | * notifier the first time. |
| 293 | * |
| 294 | * This function may not be called on a registered notifier and may be called on |
| 295 | * a notifier only once per port. |
| 296 | * |
| 297 | * Do not change the notifier's subdevs array, take references to the subdevs |
| 298 | * array itself or change the notifier's num_subdevs field. This is because this |
| 299 | * function allocates and reallocates the subdevs array based on parsing |
| 300 | * endpoints. |
| 301 | * |
| 302 | * The &struct v4l2_fwnode_endpoint passed to the callback function |
| 303 | * @parse_endpoint is released once the function is finished. If there is a need |
| 304 | * to retain that configuration, the user needs to allocate memory for it. |
| 305 | * |
| 306 | * Any notifier populated using this function must be released with a call to |
| 307 | * v4l2_async_notifier_cleanup() after it has been unregistered and the async |
| 308 | * sub-devices are no longer in use, even if the function returned an error. |
| 309 | * |
| 310 | * Return: %0 on success, including when no async sub-devices are found |
| 311 | * %-ENOMEM if memory allocation failed |
| 312 | * %-EINVAL if graph or endpoint parsing failed |
| 313 | * Other error codes as returned by @parse_endpoint |
| 314 | */ |
| 315 | int v4l2_async_notifier_parse_fwnode_endpoints_by_port( |
| 316 | struct device *dev, struct v4l2_async_notifier *notifier, |
| 317 | size_t asd_struct_size, unsigned int port, |
| 318 | int (*parse_endpoint)(struct device *dev, |
| 319 | struct v4l2_fwnode_endpoint *vep, |
| 320 | struct v4l2_async_subdev *asd)); |
| 321 | |
Sakari Ailus | 7a9ec80 | 2017-09-06 08:35:42 -0400 | [diff] [blame^] | 322 | /** |
| 323 | * v4l2_fwnode_reference_parse_sensor_common - parse common references on |
| 324 | * sensors for async sub-devices |
| 325 | * @dev: the device node the properties of which are parsed for references |
| 326 | * @notifier: the async notifier where the async subdevs will be added |
| 327 | * |
| 328 | * Parse common sensor properties for remote devices related to the |
| 329 | * sensor and set up async sub-devices for them. |
| 330 | * |
| 331 | * Any notifier populated using this function must be released with a call to |
| 332 | * v4l2_async_notifier_release() after it has been unregistered and the async |
| 333 | * sub-devices are no longer in use, even in the case the function returned an |
| 334 | * error. |
| 335 | * |
| 336 | * Return: 0 on success |
| 337 | * -ENOMEM if memory allocation failed |
| 338 | * -EINVAL if property parsing failed |
| 339 | */ |
| 340 | int v4l2_async_notifier_parse_fwnode_sensor_common( |
| 341 | struct device *dev, struct v4l2_async_notifier *notifier); |
| 342 | |
Sakari Ailus | ca50c19 | 2016-08-12 08:05:51 -0300 | [diff] [blame] | 343 | #endif /* _V4L2_FWNODE_H */ |