1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 3 * V4L2 fwnode binding parsing library 4 * 5 * Copyright (c) 2016 Intel Corporation. 6 * Author: Sakari Ailus <sakari.ailus@linux.in 7 * 8 * Copyright (C) 2012 - 2013 Samsung Electroni 9 * Author: Sylwester Nawrocki <s.nawrocki@sams 10 * 11 * Copyright (C) 2012 Renesas Electronics Corp 12 * Author: Guennadi Liakhovetski <g.liakhovets 13 */ 14 #ifndef _V4L2_FWNODE_H 15 #define _V4L2_FWNODE_H 16 17 #include <linux/errno.h> 18 #include <linux/fwnode.h> 19 #include <linux/list.h> 20 #include <linux/types.h> 21 22 #include <media/v4l2-mediabus.h> 23 24 /** 25 * struct v4l2_fwnode_endpoint - the endpoint 26 * @base: fwnode endpoint of the v4l2_fwnode 27 * @bus_type: bus type 28 * @bus: bus configuration data structure 29 * @bus.parallel: embedded &struct v4l2_mbus_c 30 * Used if the bus is parallel. 31 * @bus.mipi_csi1: embedded &struct v4l2_mbus_ 32 * Used if the bus is MIPI All 33 * Interface version 1 (MIPI C 34 * Mobile Imaging Architecture 35 * (SMIA CCP2). 36 * @bus.mipi_csi2: embedded &struct v4l2_mbus_ 37 * Used if the bus is MIPI All 38 * Interface version 2 (MIPI C 39 * @link_frequencies: array of supported link 40 * @nr_of_link_frequencies: number of elements 41 */ 42 struct v4l2_fwnode_endpoint { 43 struct fwnode_endpoint base; 44 enum v4l2_mbus_type bus_type; 45 struct { 46 struct v4l2_mbus_config_parall 47 struct v4l2_mbus_config_mipi_c 48 struct v4l2_mbus_config_mipi_c 49 } bus; 50 u64 *link_frequencies; 51 unsigned int nr_of_link_frequencies; 52 }; 53 54 /** 55 * V4L2_FWNODE_PROPERTY_UNSET - identify a non 56 * 57 * All properties in &struct v4l2_fwnode_devic 58 * to this value. 59 */ 60 #define V4L2_FWNODE_PROPERTY_UNSET (-1U) 61 62 /** 63 * enum v4l2_fwnode_orientation - possible dev 64 * @V4L2_FWNODE_ORIENTATION_FRONT: device inst 65 * @V4L2_FWNODE_ORIENTATION_BACK: device insta 66 * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device e 67 */ 68 enum v4l2_fwnode_orientation { 69 V4L2_FWNODE_ORIENTATION_FRONT, 70 V4L2_FWNODE_ORIENTATION_BACK, 71 V4L2_FWNODE_ORIENTATION_EXTERNAL 72 }; 73 74 /** 75 * struct v4l2_fwnode_device_properties - fwno 76 * @orientation: device orientation. See &enum 77 * @rotation: device rotation 78 */ 79 struct v4l2_fwnode_device_properties { 80 enum v4l2_fwnode_orientation orientati 81 unsigned int rotation; 82 }; 83 84 /** 85 * struct v4l2_fwnode_link - a link between tw 86 * @local_node: pointer to device_node of this 87 * @local_port: identifier of the port this en 88 * @local_id: identifier of the id this endpoi 89 * @remote_node: pointer to device_node of the 90 * @remote_port: identifier of the port the re 91 * @remote_id: identifier of the id the remote 92 */ 93 struct v4l2_fwnode_link { 94 struct fwnode_handle *local_node; 95 unsigned int local_port; 96 unsigned int local_id; 97 struct fwnode_handle *remote_node; 98 unsigned int remote_port; 99 unsigned int remote_id; 100 }; 101 102 /** 103 * enum v4l2_connector_type - connector type 104 * @V4L2_CONN_UNKNOWN: unknown connector typ 105 * @V4L2_CONN_COMPOSITE: analog composite conn 106 * @V4L2_CONN_SVIDEO: analog svideo connect 107 */ 108 enum v4l2_connector_type { 109 V4L2_CONN_UNKNOWN, 110 V4L2_CONN_COMPOSITE, 111 V4L2_CONN_SVIDEO, 112 }; 113 114 /** 115 * struct v4l2_connector_link - connector link 116 * @head: structure to be used to add the link 117 * &struct v4l2_fwnode_connector 118 * @fwnode_link: &struct v4l2_fwnode_link link 119 * device the connector belongs 120 */ 121 struct v4l2_connector_link { 122 struct list_head head; 123 struct v4l2_fwnode_link fwnode_link; 124 }; 125 126 /** 127 * struct v4l2_fwnode_connector_analog - analo 128 * @sdtv_stds: sdtv standards this connector s 129 * if no restrictions are specifie 130 */ 131 struct v4l2_fwnode_connector_analog { 132 v4l2_std_id sdtv_stds; 133 }; 134 135 /** 136 * struct v4l2_fwnode_connector - the connecto 137 * @name: the connector device name 138 * @label: optional connector label 139 * @type: connector type 140 * @links: list of all connector &struct v4l2_ 141 * @nr_of_links: total number of links 142 * @connector: connector configuration 143 * @connector.analog: analog connector configu 144 * &struct v4l2_fwnode_conn 145 */ 146 struct v4l2_fwnode_connector { 147 const char *name; 148 const char *label; 149 enum v4l2_connector_type type; 150 struct list_head links; 151 unsigned int nr_of_links; 152 153 union { 154 struct v4l2_fwnode_connector_a 155 /* future connectors */ 156 } connector; 157 }; 158 159 /** 160 * enum v4l2_fwnode_bus_type - Video bus types 161 * @V4L2_FWNODE_BUS_TYPE_GUESS: Default value 162 * @V4L2_FWNODE_BUS_TYPE_CSI2_CPHY: MIPI CSI-2 163 * @V4L2_FWNODE_BUS_TYPE_CSI1: MIPI CSI-1 bus 164 * @V4L2_FWNODE_BUS_TYPE_CCP2: SMIA Compact Ca 165 * @V4L2_FWNODE_BUS_TYPE_CSI2_DPHY: MIPI CSI-2 166 * @V4L2_FWNODE_BUS_TYPE_PARALLEL: Camera Para 167 * @V4L2_FWNODE_BUS_TYPE_BT656: BT.656 video f 168 * @V4L2_FWNODE_BUS_TYPE_DPI: Video Parallel I 169 * @NR_OF_V4L2_FWNODE_BUS_TYPE: Number of bus- 170 */ 171 enum v4l2_fwnode_bus_type { 172 V4L2_FWNODE_BUS_TYPE_GUESS = 0, 173 V4L2_FWNODE_BUS_TYPE_CSI2_CPHY, 174 V4L2_FWNODE_BUS_TYPE_CSI1, 175 V4L2_FWNODE_BUS_TYPE_CCP2, 176 V4L2_FWNODE_BUS_TYPE_CSI2_DPHY, 177 V4L2_FWNODE_BUS_TYPE_PARALLEL, 178 V4L2_FWNODE_BUS_TYPE_BT656, 179 V4L2_FWNODE_BUS_TYPE_DPI, 180 NR_OF_V4L2_FWNODE_BUS_TYPE 181 }; 182 183 /** 184 * v4l2_fwnode_endpoint_parse() - parse all fw 185 * @fwnode: pointer to the endpoint's fwnode h 186 * @vep: pointer to the V4L2 fwnode data struc 187 * 188 * This function parses the V4L2 fwnode endpoi 189 * firmware. There are two ways to use this fu 190 * obtain the type of the bus (by setting the 191 * V4L2_MBUS_UNKNOWN) or specifying the bus ty 192 * v4l2_mbus_type types. 193 * 194 * When @vep.bus_type is V4L2_MBUS_UNKNOWN, th 195 * property to determine the type when it is a 196 * responsible for validating the contents of 197 * returns. 198 * 199 * As a deprecated functionality to support ol 200 * property for devices that support multiple 201 * does not exist, the function will attempt t 202 * endpoint properties available. NEVER RELY O 203 * DRIVERS OR BINDINGS. 204 * 205 * It is also possible to set @vep.bus_type co 206 * this case the function will only attempt to 207 * bus, and it will return an error if the val 208 * corresponds to a different bus. 209 * 210 * The caller is required to initialise all fi 211 * explicitly values, or by zeroing them. 212 * 213 * The function does not change the V4L2 fwnod 214 * 215 * NOTE: This function does not parse "link-fr 216 * not known in advance. Please use v4l2_fwnod 217 * need properties of variable size. 218 * 219 * Return: %0 on success or a negative error c 220 * %-ENOMEM on memory allocation failu 221 * %-EINVAL on parsing failure 222 * %-ENXIO on mismatching bus types 223 */ 224 int v4l2_fwnode_endpoint_parse(struct fwnode_h 225 struct v4l2_fwn 226 227 /** 228 * v4l2_fwnode_endpoint_free() - free the V4L2 229 * v4l2_fwnode_endpoint_alloc_parse() 230 * @vep: the V4L2 fwnode the resources of whic 231 * 232 * It is safe to call this function with NULL 233 * parsing of which failed. 234 */ 235 void v4l2_fwnode_endpoint_free(struct v4l2_fwn 236 237 /** 238 * v4l2_fwnode_endpoint_alloc_parse() - parse 239 * @fwnode: pointer to the endpoint's fwnode h 240 * @vep: pointer to the V4L2 fwnode data struc 241 * 242 * This function parses the V4L2 fwnode endpoi 243 * firmware. There are two ways to use this fu 244 * obtain the type of the bus (by setting the 245 * V4L2_MBUS_UNKNOWN) or specifying the bus ty 246 * v4l2_mbus_type types. 247 * 248 * When @vep.bus_type is V4L2_MBUS_UNKNOWN, th 249 * property to determine the type when it is a 250 * responsible for validating the contents of 251 * returns. 252 * 253 * As a deprecated functionality to support ol 254 * property for devices that support multiple 255 * does not exist, the function will attempt t 256 * endpoint properties available. NEVER RELY O 257 * DRIVERS OR BINDINGS. 258 * 259 * It is also possible to set @vep.bus_type co 260 * this case the function will only attempt to 261 * bus, and it will return an error if the val 262 * corresponds to a different bus. 263 * 264 * The caller is required to initialise all fi 265 * explicitly values, or by zeroing them. 266 * 267 * The function does not change the V4L2 fwnod 268 * 269 * v4l2_fwnode_endpoint_alloc_parse() has two 270 * v4l2_fwnode_endpoint_parse(): 271 * 272 * 1. It also parses variable size data. 273 * 274 * 2. The memory it has allocated to store the 275 * using v4l2_fwnode_endpoint_free() when n 276 * 277 * Return: %0 on success or a negative error c 278 * %-ENOMEM on memory allocation failu 279 * %-EINVAL on parsing failure 280 * %-ENXIO on mismatching bus types 281 */ 282 int v4l2_fwnode_endpoint_alloc_parse(struct fw 283 struct v4 284 285 /** 286 * v4l2_fwnode_parse_link() - parse a link bet 287 * @fwnode: pointer to the endpoint's fwnode a 288 * @link: pointer to the V4L2 fwnode link data 289 * 290 * Fill the link structure with the local and 291 * The local_node and remote_node fields are s 292 * remote port's parent nodes respectively (th 293 * parent node of the port node if that node i 294 * grand-parent node of the port node otherwis 295 * 296 * A reference is taken to both the local and 297 * v4l2_fwnode_put_link() to drop the referenc 298 * link. 299 * 300 * Return: 0 on success, or -ENOLINK if the re 301 * found. 302 */ 303 int v4l2_fwnode_parse_link(struct fwnode_handl 304 struct v4l2_fwnode_ 305 306 /** 307 * v4l2_fwnode_put_link() - drop references to 308 * @link: pointer to the V4L2 fwnode link data 309 * 310 * Drop references to the local and remote nod 311 * must be called on every link parsed with v4 312 */ 313 void v4l2_fwnode_put_link(struct v4l2_fwnode_l 314 315 /** 316 * v4l2_fwnode_connector_free() - free the V4L 317 * @connector: the V4L2 connector resources of 318 * 319 * Free all allocated memory and put all links 320 * v4l2_fwnode_connector_parse() and v4l2_fwno 321 * 322 * It is safe to call this function with NULL 323 * the parsing of which failed. 324 */ 325 void v4l2_fwnode_connector_free(struct v4l2_fw 326 327 /** 328 * v4l2_fwnode_connector_parse() - initialize 329 * @fwnode: pointer to the subdev endpoint's f 330 * is connected to or to the connecto 331 * @connector: pointer to the V4L2 fwnode conn 332 * 333 * Fill the &struct v4l2_fwnode_connector with 334 * all &enum v4l2_connector_type specific conn 335 * so it is set to %NULL if no one was found. 336 * to zero. Adding links to the connector is d 337 * v4l2_fwnode_connector_add_link(). 338 * 339 * The memory allocated for the label must be 340 * Freeing the memory is done by v4l2_fwnode_c 341 * 342 * Return: 343 * * %0 on success or a negative error code on 344 * * %-EINVAL if @fwnode is invalid 345 * * %-ENOTCONN if connector type is unknown o 346 */ 347 int v4l2_fwnode_connector_parse(struct fwnode_ 348 struct v4l2_fw 349 350 /** 351 * v4l2_fwnode_connector_add_link - add a link 352 * a v4l2-sub 353 * @fwnode: pointer to the subdev endpoint's f 354 * is connected to 355 * @connector: pointer to the V4L2 fwnode conn 356 * 357 * Add a new &struct v4l2_connector_link link 358 * &struct v4l2_fwnode_connector connector lin 359 * points to the connector node, the remote_no 360 * 361 * The taken references to remote_node and loc 362 * allocated memory must be freed when no long 363 * v4l2_fwnode_connector_free(). 364 * 365 * Return: 366 * * %0 on success or a negative error code on 367 * * %-EINVAL if @fwnode or @connector is inva 368 * * %-ENOMEM on link memory allocation failur 369 * * %-ENOTCONN if remote connector device can 370 * * %-ENOLINK if link parsing between v4l2 (s 371 */ 372 int v4l2_fwnode_connector_add_link(struct fwno 373 struct v4l2 374 375 /** 376 * v4l2_fwnode_device_parse() - parse fwnode d 377 * @dev: pointer to &struct device 378 * @props: pointer to &struct v4l2_fwnode_devi 379 * parsed properties values 380 * 381 * This function parses and validates the V4L2 382 * firmware interface, and fills the @struct v 383 * provided by the caller. 384 * 385 * Return: 386 * % 0 on success 387 * %-EINVAL if a parsed property value is 388 */ 389 int v4l2_fwnode_device_parse(struct device *de 390 struct v4l2_fwnod 391 392 /* Helper macros to access the connector links 393 394 /** v4l2_connector_last_link - Helper macro to 395 * &struct v4l2_fw 396 * @v4l2c: &struct v4l2_fwnode_connector ownin 397 * 398 * This marco returns the first added &struct 399 * link or @NULL if the connector has no links 400 */ 401 #define v4l2_connector_first_link(v4l2c) 402 list_first_entry_or_null(&(v4l2c)->lin 403 struct v4l2_c 404 405 /** v4l2_connector_last_link - Helper macro to 406 * &struct v4l2_fw 407 * @v4l2c: &struct v4l2_fwnode_connector ownin 408 * 409 * This marco returns the last &struct v4l2_co 410 */ 411 #define v4l2_connector_last_link(v4l2c) 412 list_last_entry(&(v4l2c)->links, struc 413 414 #endif /* _V4L2_FWNODE_H */ 415
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.