1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * V4L2 fwnode binding parsing library 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (c) 2016 Intel Corporation. 6*4882a593Smuzhiyun * Author: Sakari Ailus <sakari.ailus@linux.intel.com> 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd. 9*4882a593Smuzhiyun * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> 10*4882a593Smuzhiyun * 11*4882a593Smuzhiyun * Copyright (C) 2012 Renesas Electronics Corp. 12*4882a593Smuzhiyun * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de> 13*4882a593Smuzhiyun */ 14*4882a593Smuzhiyun #ifndef _V4L2_FWNODE_H 15*4882a593Smuzhiyun #define _V4L2_FWNODE_H 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun #include <linux/errno.h> 18*4882a593Smuzhiyun #include <linux/fwnode.h> 19*4882a593Smuzhiyun #include <linux/list.h> 20*4882a593Smuzhiyun #include <linux/types.h> 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun #include <media/v4l2-mediabus.h> 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun struct fwnode_handle; 25*4882a593Smuzhiyun struct v4l2_async_notifier; 26*4882a593Smuzhiyun struct v4l2_async_subdev; 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun #define V4L2_FWNODE_CSI2_MAX_DATA_LANES 4 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /** 31*4882a593Smuzhiyun * struct v4l2_fwnode_bus_mipi_csi2 - MIPI CSI-2 bus data structure 32*4882a593Smuzhiyun * @flags: media bus (V4L2_MBUS_*) flags 33*4882a593Smuzhiyun * @data_lanes: an array of physical data lane indexes 34*4882a593Smuzhiyun * @clock_lane: physical lane index of the clock lane 35*4882a593Smuzhiyun * @num_data_lanes: number of data lanes 36*4882a593Smuzhiyun * @lane_polarities: polarity of the lanes. The order is the same of 37*4882a593Smuzhiyun * the physical lanes. 38*4882a593Smuzhiyun */ 39*4882a593Smuzhiyun struct v4l2_fwnode_bus_mipi_csi2 { 40*4882a593Smuzhiyun unsigned int flags; 41*4882a593Smuzhiyun unsigned char data_lanes[V4L2_FWNODE_CSI2_MAX_DATA_LANES]; 42*4882a593Smuzhiyun unsigned char clock_lane; 43*4882a593Smuzhiyun unsigned char num_data_lanes; 44*4882a593Smuzhiyun bool lane_polarities[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES]; 45*4882a593Smuzhiyun }; 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun /** 48*4882a593Smuzhiyun * struct v4l2_fwnode_bus_parallel - parallel data bus data structure 49*4882a593Smuzhiyun * @flags: media bus (V4L2_MBUS_*) flags 50*4882a593Smuzhiyun * @bus_width: bus width in bits 51*4882a593Smuzhiyun * @data_shift: data shift in bits 52*4882a593Smuzhiyun */ 53*4882a593Smuzhiyun struct v4l2_fwnode_bus_parallel { 54*4882a593Smuzhiyun unsigned int flags; 55*4882a593Smuzhiyun unsigned char bus_width; 56*4882a593Smuzhiyun unsigned char data_shift; 57*4882a593Smuzhiyun }; 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun /** 60*4882a593Smuzhiyun * struct v4l2_fwnode_bus_mipi_csi1 - CSI-1/CCP2 data bus structure 61*4882a593Smuzhiyun * @clock_inv: polarity of clock/strobe signal 62*4882a593Smuzhiyun * false - not inverted, true - inverted 63*4882a593Smuzhiyun * @strobe: false - data/clock, true - data/strobe 64*4882a593Smuzhiyun * @lane_polarity: the polarities of the clock (index 0) and data lanes 65*4882a593Smuzhiyun * index (1) 66*4882a593Smuzhiyun * @data_lane: the number of the data lane 67*4882a593Smuzhiyun * @clock_lane: the number of the clock lane 68*4882a593Smuzhiyun */ 69*4882a593Smuzhiyun struct v4l2_fwnode_bus_mipi_csi1 { 70*4882a593Smuzhiyun unsigned char clock_inv:1; 71*4882a593Smuzhiyun unsigned char strobe:1; 72*4882a593Smuzhiyun bool lane_polarity[2]; 73*4882a593Smuzhiyun unsigned char data_lane; 74*4882a593Smuzhiyun unsigned char clock_lane; 75*4882a593Smuzhiyun }; 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun /** 78*4882a593Smuzhiyun * struct v4l2_fwnode_endpoint - the endpoint data structure 79*4882a593Smuzhiyun * @base: fwnode endpoint of the v4l2_fwnode 80*4882a593Smuzhiyun * @bus_type: bus type 81*4882a593Smuzhiyun * @bus: bus configuration data structure 82*4882a593Smuzhiyun * @bus.parallel: embedded &struct v4l2_fwnode_bus_parallel. 83*4882a593Smuzhiyun * Used if the bus is parallel. 84*4882a593Smuzhiyun * @bus.mipi_csi1: embedded &struct v4l2_fwnode_bus_mipi_csi1. 85*4882a593Smuzhiyun * Used if the bus is MIPI Alliance's Camera Serial 86*4882a593Smuzhiyun * Interface version 1 (MIPI CSI1) or Standard 87*4882a593Smuzhiyun * Mobile Imaging Architecture's Compact Camera Port 2 88*4882a593Smuzhiyun * (SMIA CCP2). 89*4882a593Smuzhiyun * @bus.mipi_csi2: embedded &struct v4l2_fwnode_bus_mipi_csi2. 90*4882a593Smuzhiyun * Used if the bus is MIPI Alliance's Camera Serial 91*4882a593Smuzhiyun * Interface version 2 (MIPI CSI2). 92*4882a593Smuzhiyun * @link_frequencies: array of supported link frequencies 93*4882a593Smuzhiyun * @nr_of_link_frequencies: number of elements in link_frequenccies array 94*4882a593Smuzhiyun */ 95*4882a593Smuzhiyun struct v4l2_fwnode_endpoint { 96*4882a593Smuzhiyun struct fwnode_endpoint base; 97*4882a593Smuzhiyun /* 98*4882a593Smuzhiyun * Fields below this line will be zeroed by 99*4882a593Smuzhiyun * v4l2_fwnode_endpoint_parse() 100*4882a593Smuzhiyun */ 101*4882a593Smuzhiyun enum v4l2_mbus_type bus_type; 102*4882a593Smuzhiyun struct { 103*4882a593Smuzhiyun struct v4l2_fwnode_bus_parallel parallel; 104*4882a593Smuzhiyun struct v4l2_fwnode_bus_mipi_csi1 mipi_csi1; 105*4882a593Smuzhiyun struct v4l2_fwnode_bus_mipi_csi2 mipi_csi2; 106*4882a593Smuzhiyun } bus; 107*4882a593Smuzhiyun u64 *link_frequencies; 108*4882a593Smuzhiyun unsigned int nr_of_link_frequencies; 109*4882a593Smuzhiyun }; 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun /** 112*4882a593Smuzhiyun * V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property 113*4882a593Smuzhiyun * 114*4882a593Smuzhiyun * All properties in &struct v4l2_fwnode_device_properties are initialized 115*4882a593Smuzhiyun * to this value. 116*4882a593Smuzhiyun */ 117*4882a593Smuzhiyun #define V4L2_FWNODE_PROPERTY_UNSET (-1U) 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun /** 120*4882a593Smuzhiyun * enum v4l2_fwnode_orientation - possible device orientation 121*4882a593Smuzhiyun * @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side 122*4882a593Smuzhiyun * @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side 123*4882a593Smuzhiyun * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located 124*4882a593Smuzhiyun */ 125*4882a593Smuzhiyun enum v4l2_fwnode_orientation { 126*4882a593Smuzhiyun V4L2_FWNODE_ORIENTATION_FRONT, 127*4882a593Smuzhiyun V4L2_FWNODE_ORIENTATION_BACK, 128*4882a593Smuzhiyun V4L2_FWNODE_ORIENTATION_EXTERNAL 129*4882a593Smuzhiyun }; 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun /** 132*4882a593Smuzhiyun * struct v4l2_fwnode_device_properties - fwnode device properties 133*4882a593Smuzhiyun * @orientation: device orientation. See &enum v4l2_fwnode_orientation 134*4882a593Smuzhiyun * @rotation: device rotation 135*4882a593Smuzhiyun */ 136*4882a593Smuzhiyun struct v4l2_fwnode_device_properties { 137*4882a593Smuzhiyun enum v4l2_fwnode_orientation orientation; 138*4882a593Smuzhiyun unsigned int rotation; 139*4882a593Smuzhiyun }; 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun /** 142*4882a593Smuzhiyun * struct v4l2_fwnode_link - a link between two endpoints 143*4882a593Smuzhiyun * @local_node: pointer to device_node of this endpoint 144*4882a593Smuzhiyun * @local_port: identifier of the port this endpoint belongs to 145*4882a593Smuzhiyun * @local_id: identifier of the id this endpoint belongs to 146*4882a593Smuzhiyun * @remote_node: pointer to device_node of the remote endpoint 147*4882a593Smuzhiyun * @remote_port: identifier of the port the remote endpoint belongs to 148*4882a593Smuzhiyun * @remote_id: identifier of the id the remote endpoint belongs to 149*4882a593Smuzhiyun */ 150*4882a593Smuzhiyun struct v4l2_fwnode_link { 151*4882a593Smuzhiyun struct fwnode_handle *local_node; 152*4882a593Smuzhiyun unsigned int local_port; 153*4882a593Smuzhiyun unsigned int local_id; 154*4882a593Smuzhiyun struct fwnode_handle *remote_node; 155*4882a593Smuzhiyun unsigned int remote_port; 156*4882a593Smuzhiyun unsigned int remote_id; 157*4882a593Smuzhiyun }; 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun /** 160*4882a593Smuzhiyun * enum v4l2_connector_type - connector type 161*4882a593Smuzhiyun * @V4L2_CONN_UNKNOWN: unknown connector type, no V4L2 connector configuration 162*4882a593Smuzhiyun * @V4L2_CONN_COMPOSITE: analog composite connector 163*4882a593Smuzhiyun * @V4L2_CONN_SVIDEO: analog svideo connector 164*4882a593Smuzhiyun */ 165*4882a593Smuzhiyun enum v4l2_connector_type { 166*4882a593Smuzhiyun V4L2_CONN_UNKNOWN, 167*4882a593Smuzhiyun V4L2_CONN_COMPOSITE, 168*4882a593Smuzhiyun V4L2_CONN_SVIDEO, 169*4882a593Smuzhiyun }; 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun /** 172*4882a593Smuzhiyun * struct v4l2_connector_link - connector link data structure 173*4882a593Smuzhiyun * @head: structure to be used to add the link to the 174*4882a593Smuzhiyun * &struct v4l2_fwnode_connector 175*4882a593Smuzhiyun * @fwnode_link: &struct v4l2_fwnode_link link between the connector and the 176*4882a593Smuzhiyun * device the connector belongs to. 177*4882a593Smuzhiyun */ 178*4882a593Smuzhiyun struct v4l2_connector_link { 179*4882a593Smuzhiyun struct list_head head; 180*4882a593Smuzhiyun struct v4l2_fwnode_link fwnode_link; 181*4882a593Smuzhiyun }; 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun /** 184*4882a593Smuzhiyun * struct v4l2_fwnode_connector_analog - analog connector data structure 185*4882a593Smuzhiyun * @sdtv_stds: sdtv standards this connector supports, set to V4L2_STD_ALL 186*4882a593Smuzhiyun * if no restrictions are specified. 187*4882a593Smuzhiyun */ 188*4882a593Smuzhiyun struct v4l2_fwnode_connector_analog { 189*4882a593Smuzhiyun v4l2_std_id sdtv_stds; 190*4882a593Smuzhiyun }; 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun /** 193*4882a593Smuzhiyun * struct v4l2_fwnode_connector - the connector data structure 194*4882a593Smuzhiyun * @name: the connector device name 195*4882a593Smuzhiyun * @label: optional connector label 196*4882a593Smuzhiyun * @type: connector type 197*4882a593Smuzhiyun * @links: list of all connector &struct v4l2_connector_link links 198*4882a593Smuzhiyun * @nr_of_links: total number of links 199*4882a593Smuzhiyun * @connector: connector configuration 200*4882a593Smuzhiyun * @connector.analog: analog connector configuration 201*4882a593Smuzhiyun * &struct v4l2_fwnode_connector_analog 202*4882a593Smuzhiyun */ 203*4882a593Smuzhiyun struct v4l2_fwnode_connector { 204*4882a593Smuzhiyun const char *name; 205*4882a593Smuzhiyun const char *label; 206*4882a593Smuzhiyun enum v4l2_connector_type type; 207*4882a593Smuzhiyun struct list_head links; 208*4882a593Smuzhiyun unsigned int nr_of_links; 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun union { 211*4882a593Smuzhiyun struct v4l2_fwnode_connector_analog analog; 212*4882a593Smuzhiyun /* future connectors */ 213*4882a593Smuzhiyun } connector; 214*4882a593Smuzhiyun }; 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun /** 217*4882a593Smuzhiyun * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties 218*4882a593Smuzhiyun * @fwnode: pointer to the endpoint's fwnode handle 219*4882a593Smuzhiyun * @vep: pointer to the V4L2 fwnode data structure 220*4882a593Smuzhiyun * 221*4882a593Smuzhiyun * This function parses the V4L2 fwnode endpoint specific parameters from the 222*4882a593Smuzhiyun * firmware. The caller is responsible for assigning @vep.bus_type to a valid 223*4882a593Smuzhiyun * media bus type. The caller may also set the default configuration for the 224*4882a593Smuzhiyun * endpoint --- a configuration that shall be in line with the DT binding 225*4882a593Smuzhiyun * documentation. Should a device support multiple bus types, the caller may 226*4882a593Smuzhiyun * call this function once the correct type is found --- with a default 227*4882a593Smuzhiyun * configuration valid for that type. 228*4882a593Smuzhiyun * 229*4882a593Smuzhiyun * It is also allowed to set @vep.bus_type to V4L2_MBUS_UNKNOWN. USING THIS 230*4882a593Smuzhiyun * FEATURE REQUIRES "bus-type" PROPERTY IN DT BINDINGS. For old drivers, 231*4882a593Smuzhiyun * guessing @vep.bus_type between CSI-2 D-PHY, parallel and BT.656 busses is 232*4882a593Smuzhiyun * supported. NEVER RELY ON GUESSING @vep.bus_type IN NEW DRIVERS! 233*4882a593Smuzhiyun * 234*4882a593Smuzhiyun * The caller is required to initialise all fields of @vep, either with 235*4882a593Smuzhiyun * explicitly values, or by zeroing them. 236*4882a593Smuzhiyun * 237*4882a593Smuzhiyun * The function does not change the V4L2 fwnode endpoint state if it fails. 238*4882a593Smuzhiyun * 239*4882a593Smuzhiyun * NOTE: This function does not parse properties the size of which is variable 240*4882a593Smuzhiyun * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in 241*4882a593Smuzhiyun * new drivers instead. 242*4882a593Smuzhiyun * 243*4882a593Smuzhiyun * Return: %0 on success or a negative error code on failure: 244*4882a593Smuzhiyun * %-ENOMEM on memory allocation failure 245*4882a593Smuzhiyun * %-EINVAL on parsing failure 246*4882a593Smuzhiyun * %-ENXIO on mismatching bus types 247*4882a593Smuzhiyun */ 248*4882a593Smuzhiyun int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode, 249*4882a593Smuzhiyun struct v4l2_fwnode_endpoint *vep); 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun /** 252*4882a593Smuzhiyun * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by 253*4882a593Smuzhiyun * v4l2_fwnode_endpoint_alloc_parse() 254*4882a593Smuzhiyun * @vep: the V4L2 fwnode the resources of which are to be released 255*4882a593Smuzhiyun * 256*4882a593Smuzhiyun * It is safe to call this function with NULL argument or on a V4L2 fwnode the 257*4882a593Smuzhiyun * parsing of which failed. 258*4882a593Smuzhiyun */ 259*4882a593Smuzhiyun void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep); 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun /** 262*4882a593Smuzhiyun * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties 263*4882a593Smuzhiyun * @fwnode: pointer to the endpoint's fwnode handle 264*4882a593Smuzhiyun * @vep: pointer to the V4L2 fwnode data structure 265*4882a593Smuzhiyun * 266*4882a593Smuzhiyun * This function parses the V4L2 fwnode endpoint specific parameters from the 267*4882a593Smuzhiyun * firmware. The caller is responsible for assigning @vep.bus_type to a valid 268*4882a593Smuzhiyun * media bus type. The caller may also set the default configuration for the 269*4882a593Smuzhiyun * endpoint --- a configuration that shall be in line with the DT binding 270*4882a593Smuzhiyun * documentation. Should a device support multiple bus types, the caller may 271*4882a593Smuzhiyun * call this function once the correct type is found --- with a default 272*4882a593Smuzhiyun * configuration valid for that type. 273*4882a593Smuzhiyun * 274*4882a593Smuzhiyun * It is also allowed to set @vep.bus_type to V4L2_MBUS_UNKNOWN. USING THIS 275*4882a593Smuzhiyun * FEATURE REQUIRES "bus-type" PROPERTY IN DT BINDINGS. For old drivers, 276*4882a593Smuzhiyun * guessing @vep.bus_type between CSI-2 D-PHY, parallel and BT.656 busses is 277*4882a593Smuzhiyun * supported. NEVER RELY ON GUESSING @vep.bus_type IN NEW DRIVERS! 278*4882a593Smuzhiyun * 279*4882a593Smuzhiyun * The caller is required to initialise all fields of @vep, either with 280*4882a593Smuzhiyun * explicitly values, or by zeroing them. 281*4882a593Smuzhiyun * 282*4882a593Smuzhiyun * The function does not change the V4L2 fwnode endpoint state if it fails. 283*4882a593Smuzhiyun * 284*4882a593Smuzhiyun * v4l2_fwnode_endpoint_alloc_parse() has two important differences to 285*4882a593Smuzhiyun * v4l2_fwnode_endpoint_parse(): 286*4882a593Smuzhiyun * 287*4882a593Smuzhiyun * 1. It also parses variable size data. 288*4882a593Smuzhiyun * 289*4882a593Smuzhiyun * 2. The memory it has allocated to store the variable size data must be freed 290*4882a593Smuzhiyun * using v4l2_fwnode_endpoint_free() when no longer needed. 291*4882a593Smuzhiyun * 292*4882a593Smuzhiyun * Return: %0 on success or a negative error code on failure: 293*4882a593Smuzhiyun * %-ENOMEM on memory allocation failure 294*4882a593Smuzhiyun * %-EINVAL on parsing failure 295*4882a593Smuzhiyun * %-ENXIO on mismatching bus types 296*4882a593Smuzhiyun */ 297*4882a593Smuzhiyun int v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode, 298*4882a593Smuzhiyun struct v4l2_fwnode_endpoint *vep); 299*4882a593Smuzhiyun 300*4882a593Smuzhiyun /** 301*4882a593Smuzhiyun * v4l2_fwnode_parse_link() - parse a link between two endpoints 302*4882a593Smuzhiyun * @fwnode: pointer to the endpoint's fwnode at the local end of the link 303*4882a593Smuzhiyun * @link: pointer to the V4L2 fwnode link data structure 304*4882a593Smuzhiyun * 305*4882a593Smuzhiyun * Fill the link structure with the local and remote nodes and port numbers. 306*4882a593Smuzhiyun * The local_node and remote_node fields are set to point to the local and 307*4882a593Smuzhiyun * remote port's parent nodes respectively (the port parent node being the 308*4882a593Smuzhiyun * parent node of the port node if that node isn't a 'ports' node, or the 309*4882a593Smuzhiyun * grand-parent node of the port node otherwise). 310*4882a593Smuzhiyun * 311*4882a593Smuzhiyun * A reference is taken to both the local and remote nodes, the caller must use 312*4882a593Smuzhiyun * v4l2_fwnode_put_link() to drop the references when done with the 313*4882a593Smuzhiyun * link. 314*4882a593Smuzhiyun * 315*4882a593Smuzhiyun * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be 316*4882a593Smuzhiyun * found. 317*4882a593Smuzhiyun */ 318*4882a593Smuzhiyun int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, 319*4882a593Smuzhiyun struct v4l2_fwnode_link *link); 320*4882a593Smuzhiyun 321*4882a593Smuzhiyun /** 322*4882a593Smuzhiyun * v4l2_fwnode_put_link() - drop references to nodes in a link 323*4882a593Smuzhiyun * @link: pointer to the V4L2 fwnode link data structure 324*4882a593Smuzhiyun * 325*4882a593Smuzhiyun * Drop references to the local and remote nodes in the link. This function 326*4882a593Smuzhiyun * must be called on every link parsed with v4l2_fwnode_parse_link(). 327*4882a593Smuzhiyun */ 328*4882a593Smuzhiyun void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link); 329*4882a593Smuzhiyun 330*4882a593Smuzhiyun /** 331*4882a593Smuzhiyun * v4l2_fwnode_connector_free() - free the V4L2 connector acquired memory 332*4882a593Smuzhiyun * @connector: the V4L2 connector resources of which are to be released 333*4882a593Smuzhiyun * 334*4882a593Smuzhiyun * Free all allocated memory and put all links acquired by 335*4882a593Smuzhiyun * v4l2_fwnode_connector_parse() and v4l2_fwnode_connector_add_link(). 336*4882a593Smuzhiyun * 337*4882a593Smuzhiyun * It is safe to call this function with NULL argument or on a V4L2 connector 338*4882a593Smuzhiyun * the parsing of which failed. 339*4882a593Smuzhiyun */ 340*4882a593Smuzhiyun void v4l2_fwnode_connector_free(struct v4l2_fwnode_connector *connector); 341*4882a593Smuzhiyun 342*4882a593Smuzhiyun /** 343*4882a593Smuzhiyun * v4l2_fwnode_connector_parse() - initialize the 'struct v4l2_fwnode_connector' 344*4882a593Smuzhiyun * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector 345*4882a593Smuzhiyun * is connected to or to the connector endpoint fwnode handle. 346*4882a593Smuzhiyun * @connector: pointer to the V4L2 fwnode connector data structure 347*4882a593Smuzhiyun * 348*4882a593Smuzhiyun * Fill the &struct v4l2_fwnode_connector with the connector type, label and 349*4882a593Smuzhiyun * all &enum v4l2_connector_type specific connector data. The label is optional 350*4882a593Smuzhiyun * so it is set to %NULL if no one was found. The function initialize the links 351*4882a593Smuzhiyun * to zero. Adding links to the connector is done by calling 352*4882a593Smuzhiyun * v4l2_fwnode_connector_add_link(). 353*4882a593Smuzhiyun * 354*4882a593Smuzhiyun * The memory allocated for the label must be freed when no longer needed. 355*4882a593Smuzhiyun * Freeing the memory is done by v4l2_fwnode_connector_free(). 356*4882a593Smuzhiyun * 357*4882a593Smuzhiyun * Return: 358*4882a593Smuzhiyun * * %0 on success or a negative error code on failure: 359*4882a593Smuzhiyun * * %-EINVAL if @fwnode is invalid 360*4882a593Smuzhiyun * * %-ENOTCONN if connector type is unknown or connector device can't be found 361*4882a593Smuzhiyun */ 362*4882a593Smuzhiyun int v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode, 363*4882a593Smuzhiyun struct v4l2_fwnode_connector *connector); 364*4882a593Smuzhiyun 365*4882a593Smuzhiyun /** 366*4882a593Smuzhiyun * v4l2_fwnode_connector_add_link - add a link between a connector node and 367*4882a593Smuzhiyun * a v4l2-subdev node. 368*4882a593Smuzhiyun * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector 369*4882a593Smuzhiyun * is connected to 370*4882a593Smuzhiyun * @connector: pointer to the V4L2 fwnode connector data structure 371*4882a593Smuzhiyun * 372*4882a593Smuzhiyun * Add a new &struct v4l2_connector_link link to the 373*4882a593Smuzhiyun * &struct v4l2_fwnode_connector connector links list. The link local_node 374*4882a593Smuzhiyun * points to the connector node, the remote_node to the host v4l2 (sub)dev. 375*4882a593Smuzhiyun * 376*4882a593Smuzhiyun * The taken references to remote_node and local_node must be dropped and the 377*4882a593Smuzhiyun * allocated memory must be freed when no longer needed. Both is done by calling 378*4882a593Smuzhiyun * v4l2_fwnode_connector_free(). 379*4882a593Smuzhiyun * 380*4882a593Smuzhiyun * Return: 381*4882a593Smuzhiyun * * %0 on success or a negative error code on failure: 382*4882a593Smuzhiyun * * %-EINVAL if @fwnode or @connector is invalid or @connector type is unknown 383*4882a593Smuzhiyun * * %-ENOMEM on link memory allocation failure 384*4882a593Smuzhiyun * * %-ENOTCONN if remote connector device can't be found 385*4882a593Smuzhiyun * * %-ENOLINK if link parsing between v4l2 (sub)dev and connector fails 386*4882a593Smuzhiyun */ 387*4882a593Smuzhiyun int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode, 388*4882a593Smuzhiyun struct v4l2_fwnode_connector *connector); 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun /** 391*4882a593Smuzhiyun * v4l2_fwnode_device_parse() - parse fwnode device properties 392*4882a593Smuzhiyun * @dev: pointer to &struct device 393*4882a593Smuzhiyun * @props: pointer to &struct v4l2_fwnode_device_properties where to store the 394*4882a593Smuzhiyun * parsed properties values 395*4882a593Smuzhiyun * 396*4882a593Smuzhiyun * This function parses and validates the V4L2 fwnode device properties from the 397*4882a593Smuzhiyun * firmware interface, and fills the @struct v4l2_fwnode_device_properties 398*4882a593Smuzhiyun * provided by the caller. 399*4882a593Smuzhiyun * 400*4882a593Smuzhiyun * Return: 401*4882a593Smuzhiyun * % 0 on success 402*4882a593Smuzhiyun * %-EINVAL if a parsed property value is not valid 403*4882a593Smuzhiyun */ 404*4882a593Smuzhiyun int v4l2_fwnode_device_parse(struct device *dev, 405*4882a593Smuzhiyun struct v4l2_fwnode_device_properties *props); 406*4882a593Smuzhiyun 407*4882a593Smuzhiyun /** 408*4882a593Smuzhiyun * typedef parse_endpoint_func - Driver's callback function to be called on 409*4882a593Smuzhiyun * each V4L2 fwnode endpoint. 410*4882a593Smuzhiyun * 411*4882a593Smuzhiyun * @dev: pointer to &struct device 412*4882a593Smuzhiyun * @vep: pointer to &struct v4l2_fwnode_endpoint 413*4882a593Smuzhiyun * @asd: pointer to &struct v4l2_async_subdev 414*4882a593Smuzhiyun * 415*4882a593Smuzhiyun * Return: 416*4882a593Smuzhiyun * * %0 on success 417*4882a593Smuzhiyun * * %-ENOTCONN if the endpoint is to be skipped but this 418*4882a593Smuzhiyun * should not be considered as an error 419*4882a593Smuzhiyun * * %-EINVAL if the endpoint configuration is invalid 420*4882a593Smuzhiyun */ 421*4882a593Smuzhiyun typedef int (*parse_endpoint_func)(struct device *dev, 422*4882a593Smuzhiyun struct v4l2_fwnode_endpoint *vep, 423*4882a593Smuzhiyun struct v4l2_async_subdev *asd); 424*4882a593Smuzhiyun 425*4882a593Smuzhiyun /** 426*4882a593Smuzhiyun * v4l2_async_notifier_parse_fwnode_endpoints - Parse V4L2 fwnode endpoints in a 427*4882a593Smuzhiyun * device node 428*4882a593Smuzhiyun * @dev: the device the endpoints of which are to be parsed 429*4882a593Smuzhiyun * @notifier: notifier for @dev 430*4882a593Smuzhiyun * @asd_struct_size: size of the driver's async sub-device struct, including 431*4882a593Smuzhiyun * sizeof(struct v4l2_async_subdev). The &struct 432*4882a593Smuzhiyun * v4l2_async_subdev shall be the first member of 433*4882a593Smuzhiyun * the driver's async sub-device struct, i.e. both 434*4882a593Smuzhiyun * begin at the same memory address. 435*4882a593Smuzhiyun * @parse_endpoint: Driver's callback function called on each V4L2 fwnode 436*4882a593Smuzhiyun * endpoint. Optional. 437*4882a593Smuzhiyun * 438*4882a593Smuzhiyun * Parse the fwnode endpoints of the @dev device and populate the async sub- 439*4882a593Smuzhiyun * devices list in the notifier. The @parse_endpoint callback function is 440*4882a593Smuzhiyun * called for each endpoint with the corresponding async sub-device pointer to 441*4882a593Smuzhiyun * let the caller initialize the driver-specific part of the async sub-device 442*4882a593Smuzhiyun * structure. 443*4882a593Smuzhiyun * 444*4882a593Smuzhiyun * The notifier memory shall be zeroed before this function is called on the 445*4882a593Smuzhiyun * notifier. 446*4882a593Smuzhiyun * 447*4882a593Smuzhiyun * This function may not be called on a registered notifier and may be called on 448*4882a593Smuzhiyun * a notifier only once. 449*4882a593Smuzhiyun * 450*4882a593Smuzhiyun * The &struct v4l2_fwnode_endpoint passed to the callback function 451*4882a593Smuzhiyun * @parse_endpoint is released once the function is finished. If there is a need 452*4882a593Smuzhiyun * to retain that configuration, the user needs to allocate memory for it. 453*4882a593Smuzhiyun * 454*4882a593Smuzhiyun * Any notifier populated using this function must be released with a call to 455*4882a593Smuzhiyun * v4l2_async_notifier_cleanup() after it has been unregistered and the async 456*4882a593Smuzhiyun * sub-devices are no longer in use, even if the function returned an error. 457*4882a593Smuzhiyun * 458*4882a593Smuzhiyun * Return: %0 on success, including when no async sub-devices are found 459*4882a593Smuzhiyun * %-ENOMEM if memory allocation failed 460*4882a593Smuzhiyun * %-EINVAL if graph or endpoint parsing failed 461*4882a593Smuzhiyun * Other error codes as returned by @parse_endpoint 462*4882a593Smuzhiyun */ 463*4882a593Smuzhiyun int 464*4882a593Smuzhiyun v4l2_async_notifier_parse_fwnode_endpoints(struct device *dev, 465*4882a593Smuzhiyun struct v4l2_async_notifier *notifier, 466*4882a593Smuzhiyun size_t asd_struct_size, 467*4882a593Smuzhiyun parse_endpoint_func parse_endpoint); 468*4882a593Smuzhiyun 469*4882a593Smuzhiyun /** 470*4882a593Smuzhiyun * v4l2_async_notifier_parse_fwnode_endpoints_by_port - Parse V4L2 fwnode 471*4882a593Smuzhiyun * endpoints of a port in a 472*4882a593Smuzhiyun * device node 473*4882a593Smuzhiyun * @dev: the device the endpoints of which are to be parsed 474*4882a593Smuzhiyun * @notifier: notifier for @dev 475*4882a593Smuzhiyun * @asd_struct_size: size of the driver's async sub-device struct, including 476*4882a593Smuzhiyun * sizeof(struct v4l2_async_subdev). The &struct 477*4882a593Smuzhiyun * v4l2_async_subdev shall be the first member of 478*4882a593Smuzhiyun * the driver's async sub-device struct, i.e. both 479*4882a593Smuzhiyun * begin at the same memory address. 480*4882a593Smuzhiyun * @port: port number where endpoints are to be parsed 481*4882a593Smuzhiyun * @parse_endpoint: Driver's callback function called on each V4L2 fwnode 482*4882a593Smuzhiyun * endpoint. Optional. 483*4882a593Smuzhiyun * 484*4882a593Smuzhiyun * This function is just like v4l2_async_notifier_parse_fwnode_endpoints() with 485*4882a593Smuzhiyun * the exception that it only parses endpoints in a given port. This is useful 486*4882a593Smuzhiyun * on devices that have both sinks and sources: the async sub-devices connected 487*4882a593Smuzhiyun * to sources have already been configured by another driver (on capture 488*4882a593Smuzhiyun * devices). In this case the driver must know which ports to parse. 489*4882a593Smuzhiyun * 490*4882a593Smuzhiyun * Parse the fwnode endpoints of the @dev device on a given @port and populate 491*4882a593Smuzhiyun * the async sub-devices list of the notifier. The @parse_endpoint callback 492*4882a593Smuzhiyun * function is called for each endpoint with the corresponding async sub-device 493*4882a593Smuzhiyun * pointer to let the caller initialize the driver-specific part of the async 494*4882a593Smuzhiyun * sub-device structure. 495*4882a593Smuzhiyun * 496*4882a593Smuzhiyun * The notifier memory shall be zeroed before this function is called on the 497*4882a593Smuzhiyun * notifier the first time. 498*4882a593Smuzhiyun * 499*4882a593Smuzhiyun * This function may not be called on a registered notifier and may be called on 500*4882a593Smuzhiyun * a notifier only once per port. 501*4882a593Smuzhiyun * 502*4882a593Smuzhiyun * The &struct v4l2_fwnode_endpoint passed to the callback function 503*4882a593Smuzhiyun * @parse_endpoint is released once the function is finished. If there is a need 504*4882a593Smuzhiyun * to retain that configuration, the user needs to allocate memory for it. 505*4882a593Smuzhiyun * 506*4882a593Smuzhiyun * Any notifier populated using this function must be released with a call to 507*4882a593Smuzhiyun * v4l2_async_notifier_cleanup() after it has been unregistered and the async 508*4882a593Smuzhiyun * sub-devices are no longer in use, even if the function returned an error. 509*4882a593Smuzhiyun * 510*4882a593Smuzhiyun * Return: %0 on success, including when no async sub-devices are found 511*4882a593Smuzhiyun * %-ENOMEM if memory allocation failed 512*4882a593Smuzhiyun * %-EINVAL if graph or endpoint parsing failed 513*4882a593Smuzhiyun * Other error codes as returned by @parse_endpoint 514*4882a593Smuzhiyun */ 515*4882a593Smuzhiyun int 516*4882a593Smuzhiyun v4l2_async_notifier_parse_fwnode_endpoints_by_port(struct device *dev, 517*4882a593Smuzhiyun struct v4l2_async_notifier *notifier, 518*4882a593Smuzhiyun size_t asd_struct_size, 519*4882a593Smuzhiyun unsigned int port, 520*4882a593Smuzhiyun parse_endpoint_func parse_endpoint); 521*4882a593Smuzhiyun 522*4882a593Smuzhiyun /** 523*4882a593Smuzhiyun * v4l2_fwnode_reference_parse_sensor_common - parse common references on 524*4882a593Smuzhiyun * sensors for async sub-devices 525*4882a593Smuzhiyun * @dev: the device node the properties of which are parsed for references 526*4882a593Smuzhiyun * @notifier: the async notifier where the async subdevs will be added 527*4882a593Smuzhiyun * 528*4882a593Smuzhiyun * Parse common sensor properties for remote devices related to the 529*4882a593Smuzhiyun * sensor and set up async sub-devices for them. 530*4882a593Smuzhiyun * 531*4882a593Smuzhiyun * Any notifier populated using this function must be released with a call to 532*4882a593Smuzhiyun * v4l2_async_notifier_release() after it has been unregistered and the async 533*4882a593Smuzhiyun * sub-devices are no longer in use, even in the case the function returned an 534*4882a593Smuzhiyun * error. 535*4882a593Smuzhiyun * 536*4882a593Smuzhiyun * Return: 0 on success 537*4882a593Smuzhiyun * -ENOMEM if memory allocation failed 538*4882a593Smuzhiyun * -EINVAL if property parsing failed 539*4882a593Smuzhiyun */ 540*4882a593Smuzhiyun int v4l2_async_notifier_parse_fwnode_sensor_common(struct device *dev, 541*4882a593Smuzhiyun struct v4l2_async_notifier *notifier); 542*4882a593Smuzhiyun 543*4882a593Smuzhiyun /* Helper macros to access the connector links. */ 544*4882a593Smuzhiyun 545*4882a593Smuzhiyun /** v4l2_connector_last_link - Helper macro to get the first 546*4882a593Smuzhiyun * &struct v4l2_fwnode_connector link 547*4882a593Smuzhiyun * @v4l2c: &struct v4l2_fwnode_connector owning the connector links 548*4882a593Smuzhiyun * 549*4882a593Smuzhiyun * This marco returns the first added &struct v4l2_connector_link connector 550*4882a593Smuzhiyun * link or @NULL if the connector has no links. 551*4882a593Smuzhiyun */ 552*4882a593Smuzhiyun #define v4l2_connector_first_link(v4l2c) \ 553*4882a593Smuzhiyun list_first_entry_or_null(&(v4l2c)->links, \ 554*4882a593Smuzhiyun struct v4l2_connector_link, head) 555*4882a593Smuzhiyun 556*4882a593Smuzhiyun /** v4l2_connector_last_link - Helper macro to get the last 557*4882a593Smuzhiyun * &struct v4l2_fwnode_connector link 558*4882a593Smuzhiyun * @v4l2c: &struct v4l2_fwnode_connector owning the connector links 559*4882a593Smuzhiyun * 560*4882a593Smuzhiyun * This marco returns the last &struct v4l2_connector_link added connector link. 561*4882a593Smuzhiyun */ 562*4882a593Smuzhiyun #define v4l2_connector_last_link(v4l2c) \ 563*4882a593Smuzhiyun list_last_entry(&(v4l2c)->links, struct v4l2_connector_link, head) 564*4882a593Smuzhiyun 565*4882a593Smuzhiyun #endif /* _V4L2_FWNODE_H */ 566