18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * V4L2 fwnode binding parsing library 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2016 Intel Corporation. 68c2ecf20Sopenharmony_ci * Author: Sakari Ailus <sakari.ailus@linux.intel.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd. 98c2ecf20Sopenharmony_ci * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Copyright (C) 2012 Renesas Electronics Corp. 128c2ecf20Sopenharmony_ci * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de> 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci#ifndef _V4L2_FWNODE_H 158c2ecf20Sopenharmony_ci#define _V4L2_FWNODE_H 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/errno.h> 188c2ecf20Sopenharmony_ci#include <linux/fwnode.h> 198c2ecf20Sopenharmony_ci#include <linux/list.h> 208c2ecf20Sopenharmony_ci#include <linux/types.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include <media/v4l2-mediabus.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistruct fwnode_handle; 258c2ecf20Sopenharmony_cistruct v4l2_async_notifier; 268c2ecf20Sopenharmony_cistruct v4l2_async_subdev; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define V4L2_FWNODE_CSI2_MAX_DATA_LANES 4 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/** 318c2ecf20Sopenharmony_ci * struct v4l2_fwnode_bus_mipi_csi2 - MIPI CSI-2 bus data structure 328c2ecf20Sopenharmony_ci * @flags: media bus (V4L2_MBUS_*) flags 338c2ecf20Sopenharmony_ci * @data_lanes: an array of physical data lane indexes 348c2ecf20Sopenharmony_ci * @clock_lane: physical lane index of the clock lane 358c2ecf20Sopenharmony_ci * @num_data_lanes: number of data lanes 368c2ecf20Sopenharmony_ci * @lane_polarities: polarity of the lanes. The order is the same of 378c2ecf20Sopenharmony_ci * the physical lanes. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_cistruct v4l2_fwnode_bus_mipi_csi2 { 408c2ecf20Sopenharmony_ci unsigned int flags; 418c2ecf20Sopenharmony_ci unsigned char data_lanes[V4L2_FWNODE_CSI2_MAX_DATA_LANES]; 428c2ecf20Sopenharmony_ci unsigned char clock_lane; 438c2ecf20Sopenharmony_ci unsigned char num_data_lanes; 448c2ecf20Sopenharmony_ci bool lane_polarities[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES]; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/** 488c2ecf20Sopenharmony_ci * struct v4l2_fwnode_bus_parallel - parallel data bus data structure 498c2ecf20Sopenharmony_ci * @flags: media bus (V4L2_MBUS_*) flags 508c2ecf20Sopenharmony_ci * @bus_width: bus width in bits 518c2ecf20Sopenharmony_ci * @data_shift: data shift in bits 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_cistruct v4l2_fwnode_bus_parallel { 548c2ecf20Sopenharmony_ci unsigned int flags; 558c2ecf20Sopenharmony_ci unsigned char bus_width; 568c2ecf20Sopenharmony_ci unsigned char data_shift; 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/** 608c2ecf20Sopenharmony_ci * struct v4l2_fwnode_bus_mipi_csi1 - CSI-1/CCP2 data bus structure 618c2ecf20Sopenharmony_ci * @clock_inv: polarity of clock/strobe signal 628c2ecf20Sopenharmony_ci * false - not inverted, true - inverted 638c2ecf20Sopenharmony_ci * @strobe: false - data/clock, true - data/strobe 648c2ecf20Sopenharmony_ci * @lane_polarity: the polarities of the clock (index 0) and data lanes 658c2ecf20Sopenharmony_ci * index (1) 668c2ecf20Sopenharmony_ci * @data_lane: the number of the data lane 678c2ecf20Sopenharmony_ci * @clock_lane: the number of the clock lane 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_cistruct v4l2_fwnode_bus_mipi_csi1 { 708c2ecf20Sopenharmony_ci unsigned char clock_inv:1; 718c2ecf20Sopenharmony_ci unsigned char strobe:1; 728c2ecf20Sopenharmony_ci bool lane_polarity[2]; 738c2ecf20Sopenharmony_ci unsigned char data_lane; 748c2ecf20Sopenharmony_ci unsigned char clock_lane; 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/** 788c2ecf20Sopenharmony_ci * struct v4l2_fwnode_endpoint - the endpoint data structure 798c2ecf20Sopenharmony_ci * @base: fwnode endpoint of the v4l2_fwnode 808c2ecf20Sopenharmony_ci * @bus_type: bus type 818c2ecf20Sopenharmony_ci * @bus: bus configuration data structure 828c2ecf20Sopenharmony_ci * @bus.parallel: embedded &struct v4l2_fwnode_bus_parallel. 838c2ecf20Sopenharmony_ci * Used if the bus is parallel. 848c2ecf20Sopenharmony_ci * @bus.mipi_csi1: embedded &struct v4l2_fwnode_bus_mipi_csi1. 858c2ecf20Sopenharmony_ci * Used if the bus is MIPI Alliance's Camera Serial 868c2ecf20Sopenharmony_ci * Interface version 1 (MIPI CSI1) or Standard 878c2ecf20Sopenharmony_ci * Mobile Imaging Architecture's Compact Camera Port 2 888c2ecf20Sopenharmony_ci * (SMIA CCP2). 898c2ecf20Sopenharmony_ci * @bus.mipi_csi2: embedded &struct v4l2_fwnode_bus_mipi_csi2. 908c2ecf20Sopenharmony_ci * Used if the bus is MIPI Alliance's Camera Serial 918c2ecf20Sopenharmony_ci * Interface version 2 (MIPI CSI2). 928c2ecf20Sopenharmony_ci * @link_frequencies: array of supported link frequencies 938c2ecf20Sopenharmony_ci * @nr_of_link_frequencies: number of elements in link_frequenccies array 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_cistruct v4l2_fwnode_endpoint { 968c2ecf20Sopenharmony_ci struct fwnode_endpoint base; 978c2ecf20Sopenharmony_ci /* 988c2ecf20Sopenharmony_ci * Fields below this line will be zeroed by 998c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_parse() 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci enum v4l2_mbus_type bus_type; 1028c2ecf20Sopenharmony_ci struct { 1038c2ecf20Sopenharmony_ci struct v4l2_fwnode_bus_parallel parallel; 1048c2ecf20Sopenharmony_ci struct v4l2_fwnode_bus_mipi_csi1 mipi_csi1; 1058c2ecf20Sopenharmony_ci struct v4l2_fwnode_bus_mipi_csi2 mipi_csi2; 1068c2ecf20Sopenharmony_ci } bus; 1078c2ecf20Sopenharmony_ci u64 *link_frequencies; 1088c2ecf20Sopenharmony_ci unsigned int nr_of_link_frequencies; 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/** 1128c2ecf20Sopenharmony_ci * V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property 1138c2ecf20Sopenharmony_ci * 1148c2ecf20Sopenharmony_ci * All properties in &struct v4l2_fwnode_device_properties are initialized 1158c2ecf20Sopenharmony_ci * to this value. 1168c2ecf20Sopenharmony_ci */ 1178c2ecf20Sopenharmony_ci#define V4L2_FWNODE_PROPERTY_UNSET (-1U) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/** 1208c2ecf20Sopenharmony_ci * enum v4l2_fwnode_orientation - possible device orientation 1218c2ecf20Sopenharmony_ci * @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side 1228c2ecf20Sopenharmony_ci * @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side 1238c2ecf20Sopenharmony_ci * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_cienum v4l2_fwnode_orientation { 1268c2ecf20Sopenharmony_ci V4L2_FWNODE_ORIENTATION_FRONT, 1278c2ecf20Sopenharmony_ci V4L2_FWNODE_ORIENTATION_BACK, 1288c2ecf20Sopenharmony_ci V4L2_FWNODE_ORIENTATION_EXTERNAL 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/** 1328c2ecf20Sopenharmony_ci * struct v4l2_fwnode_device_properties - fwnode device properties 1338c2ecf20Sopenharmony_ci * @orientation: device orientation. See &enum v4l2_fwnode_orientation 1348c2ecf20Sopenharmony_ci * @rotation: device rotation 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_cistruct v4l2_fwnode_device_properties { 1378c2ecf20Sopenharmony_ci enum v4l2_fwnode_orientation orientation; 1388c2ecf20Sopenharmony_ci unsigned int rotation; 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci/** 1428c2ecf20Sopenharmony_ci * struct v4l2_fwnode_link - a link between two endpoints 1438c2ecf20Sopenharmony_ci * @local_node: pointer to device_node of this endpoint 1448c2ecf20Sopenharmony_ci * @local_port: identifier of the port this endpoint belongs to 1458c2ecf20Sopenharmony_ci * @local_id: identifier of the id this endpoint belongs to 1468c2ecf20Sopenharmony_ci * @remote_node: pointer to device_node of the remote endpoint 1478c2ecf20Sopenharmony_ci * @remote_port: identifier of the port the remote endpoint belongs to 1488c2ecf20Sopenharmony_ci * @remote_id: identifier of the id the remote endpoint belongs to 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_cistruct v4l2_fwnode_link { 1518c2ecf20Sopenharmony_ci struct fwnode_handle *local_node; 1528c2ecf20Sopenharmony_ci unsigned int local_port; 1538c2ecf20Sopenharmony_ci unsigned int local_id; 1548c2ecf20Sopenharmony_ci struct fwnode_handle *remote_node; 1558c2ecf20Sopenharmony_ci unsigned int remote_port; 1568c2ecf20Sopenharmony_ci unsigned int remote_id; 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/** 1608c2ecf20Sopenharmony_ci * enum v4l2_connector_type - connector type 1618c2ecf20Sopenharmony_ci * @V4L2_CONN_UNKNOWN: unknown connector type, no V4L2 connector configuration 1628c2ecf20Sopenharmony_ci * @V4L2_CONN_COMPOSITE: analog composite connector 1638c2ecf20Sopenharmony_ci * @V4L2_CONN_SVIDEO: analog svideo connector 1648c2ecf20Sopenharmony_ci */ 1658c2ecf20Sopenharmony_cienum v4l2_connector_type { 1668c2ecf20Sopenharmony_ci V4L2_CONN_UNKNOWN, 1678c2ecf20Sopenharmony_ci V4L2_CONN_COMPOSITE, 1688c2ecf20Sopenharmony_ci V4L2_CONN_SVIDEO, 1698c2ecf20Sopenharmony_ci}; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci/** 1728c2ecf20Sopenharmony_ci * struct v4l2_connector_link - connector link data structure 1738c2ecf20Sopenharmony_ci * @head: structure to be used to add the link to the 1748c2ecf20Sopenharmony_ci * &struct v4l2_fwnode_connector 1758c2ecf20Sopenharmony_ci * @fwnode_link: &struct v4l2_fwnode_link link between the connector and the 1768c2ecf20Sopenharmony_ci * device the connector belongs to. 1778c2ecf20Sopenharmony_ci */ 1788c2ecf20Sopenharmony_cistruct v4l2_connector_link { 1798c2ecf20Sopenharmony_ci struct list_head head; 1808c2ecf20Sopenharmony_ci struct v4l2_fwnode_link fwnode_link; 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/** 1848c2ecf20Sopenharmony_ci * struct v4l2_fwnode_connector_analog - analog connector data structure 1858c2ecf20Sopenharmony_ci * @sdtv_stds: sdtv standards this connector supports, set to V4L2_STD_ALL 1868c2ecf20Sopenharmony_ci * if no restrictions are specified. 1878c2ecf20Sopenharmony_ci */ 1888c2ecf20Sopenharmony_cistruct v4l2_fwnode_connector_analog { 1898c2ecf20Sopenharmony_ci v4l2_std_id sdtv_stds; 1908c2ecf20Sopenharmony_ci}; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/** 1938c2ecf20Sopenharmony_ci * struct v4l2_fwnode_connector - the connector data structure 1948c2ecf20Sopenharmony_ci * @name: the connector device name 1958c2ecf20Sopenharmony_ci * @label: optional connector label 1968c2ecf20Sopenharmony_ci * @type: connector type 1978c2ecf20Sopenharmony_ci * @links: list of all connector &struct v4l2_connector_link links 1988c2ecf20Sopenharmony_ci * @nr_of_links: total number of links 1998c2ecf20Sopenharmony_ci * @connector: connector configuration 2008c2ecf20Sopenharmony_ci * @connector.analog: analog connector configuration 2018c2ecf20Sopenharmony_ci * &struct v4l2_fwnode_connector_analog 2028c2ecf20Sopenharmony_ci */ 2038c2ecf20Sopenharmony_cistruct v4l2_fwnode_connector { 2048c2ecf20Sopenharmony_ci const char *name; 2058c2ecf20Sopenharmony_ci const char *label; 2068c2ecf20Sopenharmony_ci enum v4l2_connector_type type; 2078c2ecf20Sopenharmony_ci struct list_head links; 2088c2ecf20Sopenharmony_ci unsigned int nr_of_links; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci union { 2118c2ecf20Sopenharmony_ci struct v4l2_fwnode_connector_analog analog; 2128c2ecf20Sopenharmony_ci /* future connectors */ 2138c2ecf20Sopenharmony_ci } connector; 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/** 2178c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties 2188c2ecf20Sopenharmony_ci * @fwnode: pointer to the endpoint's fwnode handle 2198c2ecf20Sopenharmony_ci * @vep: pointer to the V4L2 fwnode data structure 2208c2ecf20Sopenharmony_ci * 2218c2ecf20Sopenharmony_ci * This function parses the V4L2 fwnode endpoint specific parameters from the 2228c2ecf20Sopenharmony_ci * firmware. The caller is responsible for assigning @vep.bus_type to a valid 2238c2ecf20Sopenharmony_ci * media bus type. The caller may also set the default configuration for the 2248c2ecf20Sopenharmony_ci * endpoint --- a configuration that shall be in line with the DT binding 2258c2ecf20Sopenharmony_ci * documentation. Should a device support multiple bus types, the caller may 2268c2ecf20Sopenharmony_ci * call this function once the correct type is found --- with a default 2278c2ecf20Sopenharmony_ci * configuration valid for that type. 2288c2ecf20Sopenharmony_ci * 2298c2ecf20Sopenharmony_ci * It is also allowed to set @vep.bus_type to V4L2_MBUS_UNKNOWN. USING THIS 2308c2ecf20Sopenharmony_ci * FEATURE REQUIRES "bus-type" PROPERTY IN DT BINDINGS. For old drivers, 2318c2ecf20Sopenharmony_ci * guessing @vep.bus_type between CSI-2 D-PHY, parallel and BT.656 busses is 2328c2ecf20Sopenharmony_ci * supported. NEVER RELY ON GUESSING @vep.bus_type IN NEW DRIVERS! 2338c2ecf20Sopenharmony_ci * 2348c2ecf20Sopenharmony_ci * The caller is required to initialise all fields of @vep, either with 2358c2ecf20Sopenharmony_ci * explicitly values, or by zeroing them. 2368c2ecf20Sopenharmony_ci * 2378c2ecf20Sopenharmony_ci * The function does not change the V4L2 fwnode endpoint state if it fails. 2388c2ecf20Sopenharmony_ci * 2398c2ecf20Sopenharmony_ci * NOTE: This function does not parse properties the size of which is variable 2408c2ecf20Sopenharmony_ci * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() in 2418c2ecf20Sopenharmony_ci * new drivers instead. 2428c2ecf20Sopenharmony_ci * 2438c2ecf20Sopenharmony_ci * Return: %0 on success or a negative error code on failure: 2448c2ecf20Sopenharmony_ci * %-ENOMEM on memory allocation failure 2458c2ecf20Sopenharmony_ci * %-EINVAL on parsing failure 2468c2ecf20Sopenharmony_ci * %-ENXIO on mismatching bus types 2478c2ecf20Sopenharmony_ci */ 2488c2ecf20Sopenharmony_ciint v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode, 2498c2ecf20Sopenharmony_ci struct v4l2_fwnode_endpoint *vep); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci/** 2528c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by 2538c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_alloc_parse() 2548c2ecf20Sopenharmony_ci * @vep: the V4L2 fwnode the resources of which are to be released 2558c2ecf20Sopenharmony_ci * 2568c2ecf20Sopenharmony_ci * It is safe to call this function with NULL argument or on a V4L2 fwnode the 2578c2ecf20Sopenharmony_ci * parsing of which failed. 2588c2ecf20Sopenharmony_ci */ 2598c2ecf20Sopenharmony_civoid v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci/** 2628c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties 2638c2ecf20Sopenharmony_ci * @fwnode: pointer to the endpoint's fwnode handle 2648c2ecf20Sopenharmony_ci * @vep: pointer to the V4L2 fwnode data structure 2658c2ecf20Sopenharmony_ci * 2668c2ecf20Sopenharmony_ci * This function parses the V4L2 fwnode endpoint specific parameters from the 2678c2ecf20Sopenharmony_ci * firmware. The caller is responsible for assigning @vep.bus_type to a valid 2688c2ecf20Sopenharmony_ci * media bus type. The caller may also set the default configuration for the 2698c2ecf20Sopenharmony_ci * endpoint --- a configuration that shall be in line with the DT binding 2708c2ecf20Sopenharmony_ci * documentation. Should a device support multiple bus types, the caller may 2718c2ecf20Sopenharmony_ci * call this function once the correct type is found --- with a default 2728c2ecf20Sopenharmony_ci * configuration valid for that type. 2738c2ecf20Sopenharmony_ci * 2748c2ecf20Sopenharmony_ci * It is also allowed to set @vep.bus_type to V4L2_MBUS_UNKNOWN. USING THIS 2758c2ecf20Sopenharmony_ci * FEATURE REQUIRES "bus-type" PROPERTY IN DT BINDINGS. For old drivers, 2768c2ecf20Sopenharmony_ci * guessing @vep.bus_type between CSI-2 D-PHY, parallel and BT.656 busses is 2778c2ecf20Sopenharmony_ci * supported. NEVER RELY ON GUESSING @vep.bus_type IN NEW DRIVERS! 2788c2ecf20Sopenharmony_ci * 2798c2ecf20Sopenharmony_ci * The caller is required to initialise all fields of @vep, either with 2808c2ecf20Sopenharmony_ci * explicitly values, or by zeroing them. 2818c2ecf20Sopenharmony_ci * 2828c2ecf20Sopenharmony_ci * The function does not change the V4L2 fwnode endpoint state if it fails. 2838c2ecf20Sopenharmony_ci * 2848c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_alloc_parse() has two important differences to 2858c2ecf20Sopenharmony_ci * v4l2_fwnode_endpoint_parse(): 2868c2ecf20Sopenharmony_ci * 2878c2ecf20Sopenharmony_ci * 1. It also parses variable size data. 2888c2ecf20Sopenharmony_ci * 2898c2ecf20Sopenharmony_ci * 2. The memory it has allocated to store the variable size data must be freed 2908c2ecf20Sopenharmony_ci * using v4l2_fwnode_endpoint_free() when no longer needed. 2918c2ecf20Sopenharmony_ci * 2928c2ecf20Sopenharmony_ci * Return: %0 on success or a negative error code on failure: 2938c2ecf20Sopenharmony_ci * %-ENOMEM on memory allocation failure 2948c2ecf20Sopenharmony_ci * %-EINVAL on parsing failure 2958c2ecf20Sopenharmony_ci * %-ENXIO on mismatching bus types 2968c2ecf20Sopenharmony_ci */ 2978c2ecf20Sopenharmony_ciint v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode, 2988c2ecf20Sopenharmony_ci struct v4l2_fwnode_endpoint *vep); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/** 3018c2ecf20Sopenharmony_ci * v4l2_fwnode_parse_link() - parse a link between two endpoints 3028c2ecf20Sopenharmony_ci * @fwnode: pointer to the endpoint's fwnode at the local end of the link 3038c2ecf20Sopenharmony_ci * @link: pointer to the V4L2 fwnode link data structure 3048c2ecf20Sopenharmony_ci * 3058c2ecf20Sopenharmony_ci * Fill the link structure with the local and remote nodes and port numbers. 3068c2ecf20Sopenharmony_ci * The local_node and remote_node fields are set to point to the local and 3078c2ecf20Sopenharmony_ci * remote port's parent nodes respectively (the port parent node being the 3088c2ecf20Sopenharmony_ci * parent node of the port node if that node isn't a 'ports' node, or the 3098c2ecf20Sopenharmony_ci * grand-parent node of the port node otherwise). 3108c2ecf20Sopenharmony_ci * 3118c2ecf20Sopenharmony_ci * A reference is taken to both the local and remote nodes, the caller must use 3128c2ecf20Sopenharmony_ci * v4l2_fwnode_put_link() to drop the references when done with the 3138c2ecf20Sopenharmony_ci * link. 3148c2ecf20Sopenharmony_ci * 3158c2ecf20Sopenharmony_ci * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be 3168c2ecf20Sopenharmony_ci * found. 3178c2ecf20Sopenharmony_ci */ 3188c2ecf20Sopenharmony_ciint v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, 3198c2ecf20Sopenharmony_ci struct v4l2_fwnode_link *link); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/** 3228c2ecf20Sopenharmony_ci * v4l2_fwnode_put_link() - drop references to nodes in a link 3238c2ecf20Sopenharmony_ci * @link: pointer to the V4L2 fwnode link data structure 3248c2ecf20Sopenharmony_ci * 3258c2ecf20Sopenharmony_ci * Drop references to the local and remote nodes in the link. This function 3268c2ecf20Sopenharmony_ci * must be called on every link parsed with v4l2_fwnode_parse_link(). 3278c2ecf20Sopenharmony_ci */ 3288c2ecf20Sopenharmony_civoid v4l2_fwnode_put_link(struct v4l2_fwnode_link *link); 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci/** 3318c2ecf20Sopenharmony_ci * v4l2_fwnode_connector_free() - free the V4L2 connector acquired memory 3328c2ecf20Sopenharmony_ci * @connector: the V4L2 connector resources of which are to be released 3338c2ecf20Sopenharmony_ci * 3348c2ecf20Sopenharmony_ci * Free all allocated memory and put all links acquired by 3358c2ecf20Sopenharmony_ci * v4l2_fwnode_connector_parse() and v4l2_fwnode_connector_add_link(). 3368c2ecf20Sopenharmony_ci * 3378c2ecf20Sopenharmony_ci * It is safe to call this function with NULL argument or on a V4L2 connector 3388c2ecf20Sopenharmony_ci * the parsing of which failed. 3398c2ecf20Sopenharmony_ci */ 3408c2ecf20Sopenharmony_civoid v4l2_fwnode_connector_free(struct v4l2_fwnode_connector *connector); 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci/** 3438c2ecf20Sopenharmony_ci * v4l2_fwnode_connector_parse() - initialize the 'struct v4l2_fwnode_connector' 3448c2ecf20Sopenharmony_ci * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector 3458c2ecf20Sopenharmony_ci * is connected to or to the connector endpoint fwnode handle. 3468c2ecf20Sopenharmony_ci * @connector: pointer to the V4L2 fwnode connector data structure 3478c2ecf20Sopenharmony_ci * 3488c2ecf20Sopenharmony_ci * Fill the &struct v4l2_fwnode_connector with the connector type, label and 3498c2ecf20Sopenharmony_ci * all &enum v4l2_connector_type specific connector data. The label is optional 3508c2ecf20Sopenharmony_ci * so it is set to %NULL if no one was found. The function initialize the links 3518c2ecf20Sopenharmony_ci * to zero. Adding links to the connector is done by calling 3528c2ecf20Sopenharmony_ci * v4l2_fwnode_connector_add_link(). 3538c2ecf20Sopenharmony_ci * 3548c2ecf20Sopenharmony_ci * The memory allocated for the label must be freed when no longer needed. 3558c2ecf20Sopenharmony_ci * Freeing the memory is done by v4l2_fwnode_connector_free(). 3568c2ecf20Sopenharmony_ci * 3578c2ecf20Sopenharmony_ci * Return: 3588c2ecf20Sopenharmony_ci * * %0 on success or a negative error code on failure: 3598c2ecf20Sopenharmony_ci * * %-EINVAL if @fwnode is invalid 3608c2ecf20Sopenharmony_ci * * %-ENOTCONN if connector type is unknown or connector device can't be found 3618c2ecf20Sopenharmony_ci */ 3628c2ecf20Sopenharmony_ciint v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode, 3638c2ecf20Sopenharmony_ci struct v4l2_fwnode_connector *connector); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci/** 3668c2ecf20Sopenharmony_ci * v4l2_fwnode_connector_add_link - add a link between a connector node and 3678c2ecf20Sopenharmony_ci * a v4l2-subdev node. 3688c2ecf20Sopenharmony_ci * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector 3698c2ecf20Sopenharmony_ci * is connected to 3708c2ecf20Sopenharmony_ci * @connector: pointer to the V4L2 fwnode connector data structure 3718c2ecf20Sopenharmony_ci * 3728c2ecf20Sopenharmony_ci * Add a new &struct v4l2_connector_link link to the 3738c2ecf20Sopenharmony_ci * &struct v4l2_fwnode_connector connector links list. The link local_node 3748c2ecf20Sopenharmony_ci * points to the connector node, the remote_node to the host v4l2 (sub)dev. 3758c2ecf20Sopenharmony_ci * 3768c2ecf20Sopenharmony_ci * The taken references to remote_node and local_node must be dropped and the 3778c2ecf20Sopenharmony_ci * allocated memory must be freed when no longer needed. Both is done by calling 3788c2ecf20Sopenharmony_ci * v4l2_fwnode_connector_free(). 3798c2ecf20Sopenharmony_ci * 3808c2ecf20Sopenharmony_ci * Return: 3818c2ecf20Sopenharmony_ci * * %0 on success or a negative error code on failure: 3828c2ecf20Sopenharmony_ci * * %-EINVAL if @fwnode or @connector is invalid or @connector type is unknown 3838c2ecf20Sopenharmony_ci * * %-ENOMEM on link memory allocation failure 3848c2ecf20Sopenharmony_ci * * %-ENOTCONN if remote connector device can't be found 3858c2ecf20Sopenharmony_ci * * %-ENOLINK if link parsing between v4l2 (sub)dev and connector fails 3868c2ecf20Sopenharmony_ci */ 3878c2ecf20Sopenharmony_ciint v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode, 3888c2ecf20Sopenharmony_ci struct v4l2_fwnode_connector *connector); 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci/** 3918c2ecf20Sopenharmony_ci * v4l2_fwnode_device_parse() - parse fwnode device properties 3928c2ecf20Sopenharmony_ci * @dev: pointer to &struct device 3938c2ecf20Sopenharmony_ci * @props: pointer to &struct v4l2_fwnode_device_properties where to store the 3948c2ecf20Sopenharmony_ci * parsed properties values 3958c2ecf20Sopenharmony_ci * 3968c2ecf20Sopenharmony_ci * This function parses and validates the V4L2 fwnode device properties from the 3978c2ecf20Sopenharmony_ci * firmware interface, and fills the @struct v4l2_fwnode_device_properties 3988c2ecf20Sopenharmony_ci * provided by the caller. 3998c2ecf20Sopenharmony_ci * 4008c2ecf20Sopenharmony_ci * Return: 4018c2ecf20Sopenharmony_ci * % 0 on success 4028c2ecf20Sopenharmony_ci * %-EINVAL if a parsed property value is not valid 4038c2ecf20Sopenharmony_ci */ 4048c2ecf20Sopenharmony_ciint v4l2_fwnode_device_parse(struct device *dev, 4058c2ecf20Sopenharmony_ci struct v4l2_fwnode_device_properties *props); 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/** 4088c2ecf20Sopenharmony_ci * typedef parse_endpoint_func - Driver's callback function to be called on 4098c2ecf20Sopenharmony_ci * each V4L2 fwnode endpoint. 4108c2ecf20Sopenharmony_ci * 4118c2ecf20Sopenharmony_ci * @dev: pointer to &struct device 4128c2ecf20Sopenharmony_ci * @vep: pointer to &struct v4l2_fwnode_endpoint 4138c2ecf20Sopenharmony_ci * @asd: pointer to &struct v4l2_async_subdev 4148c2ecf20Sopenharmony_ci * 4158c2ecf20Sopenharmony_ci * Return: 4168c2ecf20Sopenharmony_ci * * %0 on success 4178c2ecf20Sopenharmony_ci * * %-ENOTCONN if the endpoint is to be skipped but this 4188c2ecf20Sopenharmony_ci * should not be considered as an error 4198c2ecf20Sopenharmony_ci * * %-EINVAL if the endpoint configuration is invalid 4208c2ecf20Sopenharmony_ci */ 4218c2ecf20Sopenharmony_citypedef int (*parse_endpoint_func)(struct device *dev, 4228c2ecf20Sopenharmony_ci struct v4l2_fwnode_endpoint *vep, 4238c2ecf20Sopenharmony_ci struct v4l2_async_subdev *asd); 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci/** 4268c2ecf20Sopenharmony_ci * v4l2_async_notifier_parse_fwnode_endpoints - Parse V4L2 fwnode endpoints in a 4278c2ecf20Sopenharmony_ci * device node 4288c2ecf20Sopenharmony_ci * @dev: the device the endpoints of which are to be parsed 4298c2ecf20Sopenharmony_ci * @notifier: notifier for @dev 4308c2ecf20Sopenharmony_ci * @asd_struct_size: size of the driver's async sub-device struct, including 4318c2ecf20Sopenharmony_ci * sizeof(struct v4l2_async_subdev). The &struct 4328c2ecf20Sopenharmony_ci * v4l2_async_subdev shall be the first member of 4338c2ecf20Sopenharmony_ci * the driver's async sub-device struct, i.e. both 4348c2ecf20Sopenharmony_ci * begin at the same memory address. 4358c2ecf20Sopenharmony_ci * @parse_endpoint: Driver's callback function called on each V4L2 fwnode 4368c2ecf20Sopenharmony_ci * endpoint. Optional. 4378c2ecf20Sopenharmony_ci * 4388c2ecf20Sopenharmony_ci * Parse the fwnode endpoints of the @dev device and populate the async sub- 4398c2ecf20Sopenharmony_ci * devices list in the notifier. The @parse_endpoint callback function is 4408c2ecf20Sopenharmony_ci * called for each endpoint with the corresponding async sub-device pointer to 4418c2ecf20Sopenharmony_ci * let the caller initialize the driver-specific part of the async sub-device 4428c2ecf20Sopenharmony_ci * structure. 4438c2ecf20Sopenharmony_ci * 4448c2ecf20Sopenharmony_ci * The notifier memory shall be zeroed before this function is called on the 4458c2ecf20Sopenharmony_ci * notifier. 4468c2ecf20Sopenharmony_ci * 4478c2ecf20Sopenharmony_ci * This function may not be called on a registered notifier and may be called on 4488c2ecf20Sopenharmony_ci * a notifier only once. 4498c2ecf20Sopenharmony_ci * 4508c2ecf20Sopenharmony_ci * The &struct v4l2_fwnode_endpoint passed to the callback function 4518c2ecf20Sopenharmony_ci * @parse_endpoint is released once the function is finished. If there is a need 4528c2ecf20Sopenharmony_ci * to retain that configuration, the user needs to allocate memory for it. 4538c2ecf20Sopenharmony_ci * 4548c2ecf20Sopenharmony_ci * Any notifier populated using this function must be released with a call to 4558c2ecf20Sopenharmony_ci * v4l2_async_notifier_cleanup() after it has been unregistered and the async 4568c2ecf20Sopenharmony_ci * sub-devices are no longer in use, even if the function returned an error. 4578c2ecf20Sopenharmony_ci * 4588c2ecf20Sopenharmony_ci * Return: %0 on success, including when no async sub-devices are found 4598c2ecf20Sopenharmony_ci * %-ENOMEM if memory allocation failed 4608c2ecf20Sopenharmony_ci * %-EINVAL if graph or endpoint parsing failed 4618c2ecf20Sopenharmony_ci * Other error codes as returned by @parse_endpoint 4628c2ecf20Sopenharmony_ci */ 4638c2ecf20Sopenharmony_ciint 4648c2ecf20Sopenharmony_civ4l2_async_notifier_parse_fwnode_endpoints(struct device *dev, 4658c2ecf20Sopenharmony_ci struct v4l2_async_notifier *notifier, 4668c2ecf20Sopenharmony_ci size_t asd_struct_size, 4678c2ecf20Sopenharmony_ci parse_endpoint_func parse_endpoint); 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci/** 4708c2ecf20Sopenharmony_ci * v4l2_async_notifier_parse_fwnode_endpoints_by_port - Parse V4L2 fwnode 4718c2ecf20Sopenharmony_ci * endpoints of a port in a 4728c2ecf20Sopenharmony_ci * device node 4738c2ecf20Sopenharmony_ci * @dev: the device the endpoints of which are to be parsed 4748c2ecf20Sopenharmony_ci * @notifier: notifier for @dev 4758c2ecf20Sopenharmony_ci * @asd_struct_size: size of the driver's async sub-device struct, including 4768c2ecf20Sopenharmony_ci * sizeof(struct v4l2_async_subdev). The &struct 4778c2ecf20Sopenharmony_ci * v4l2_async_subdev shall be the first member of 4788c2ecf20Sopenharmony_ci * the driver's async sub-device struct, i.e. both 4798c2ecf20Sopenharmony_ci * begin at the same memory address. 4808c2ecf20Sopenharmony_ci * @port: port number where endpoints are to be parsed 4818c2ecf20Sopenharmony_ci * @parse_endpoint: Driver's callback function called on each V4L2 fwnode 4828c2ecf20Sopenharmony_ci * endpoint. Optional. 4838c2ecf20Sopenharmony_ci * 4848c2ecf20Sopenharmony_ci * This function is just like v4l2_async_notifier_parse_fwnode_endpoints() with 4858c2ecf20Sopenharmony_ci * the exception that it only parses endpoints in a given port. This is useful 4868c2ecf20Sopenharmony_ci * on devices that have both sinks and sources: the async sub-devices connected 4878c2ecf20Sopenharmony_ci * to sources have already been configured by another driver (on capture 4888c2ecf20Sopenharmony_ci * devices). In this case the driver must know which ports to parse. 4898c2ecf20Sopenharmony_ci * 4908c2ecf20Sopenharmony_ci * Parse the fwnode endpoints of the @dev device on a given @port and populate 4918c2ecf20Sopenharmony_ci * the async sub-devices list of the notifier. The @parse_endpoint callback 4928c2ecf20Sopenharmony_ci * function is called for each endpoint with the corresponding async sub-device 4938c2ecf20Sopenharmony_ci * pointer to let the caller initialize the driver-specific part of the async 4948c2ecf20Sopenharmony_ci * sub-device structure. 4958c2ecf20Sopenharmony_ci * 4968c2ecf20Sopenharmony_ci * The notifier memory shall be zeroed before this function is called on the 4978c2ecf20Sopenharmony_ci * notifier the first time. 4988c2ecf20Sopenharmony_ci * 4998c2ecf20Sopenharmony_ci * This function may not be called on a registered notifier and may be called on 5008c2ecf20Sopenharmony_ci * a notifier only once per port. 5018c2ecf20Sopenharmony_ci * 5028c2ecf20Sopenharmony_ci * The &struct v4l2_fwnode_endpoint passed to the callback function 5038c2ecf20Sopenharmony_ci * @parse_endpoint is released once the function is finished. If there is a need 5048c2ecf20Sopenharmony_ci * to retain that configuration, the user needs to allocate memory for it. 5058c2ecf20Sopenharmony_ci * 5068c2ecf20Sopenharmony_ci * Any notifier populated using this function must be released with a call to 5078c2ecf20Sopenharmony_ci * v4l2_async_notifier_cleanup() after it has been unregistered and the async 5088c2ecf20Sopenharmony_ci * sub-devices are no longer in use, even if the function returned an error. 5098c2ecf20Sopenharmony_ci * 5108c2ecf20Sopenharmony_ci * Return: %0 on success, including when no async sub-devices are found 5118c2ecf20Sopenharmony_ci * %-ENOMEM if memory allocation failed 5128c2ecf20Sopenharmony_ci * %-EINVAL if graph or endpoint parsing failed 5138c2ecf20Sopenharmony_ci * Other error codes as returned by @parse_endpoint 5148c2ecf20Sopenharmony_ci */ 5158c2ecf20Sopenharmony_ciint 5168c2ecf20Sopenharmony_civ4l2_async_notifier_parse_fwnode_endpoints_by_port(struct device *dev, 5178c2ecf20Sopenharmony_ci struct v4l2_async_notifier *notifier, 5188c2ecf20Sopenharmony_ci size_t asd_struct_size, 5198c2ecf20Sopenharmony_ci unsigned int port, 5208c2ecf20Sopenharmony_ci parse_endpoint_func parse_endpoint); 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci/** 5238c2ecf20Sopenharmony_ci * v4l2_fwnode_reference_parse_sensor_common - parse common references on 5248c2ecf20Sopenharmony_ci * sensors for async sub-devices 5258c2ecf20Sopenharmony_ci * @dev: the device node the properties of which are parsed for references 5268c2ecf20Sopenharmony_ci * @notifier: the async notifier where the async subdevs will be added 5278c2ecf20Sopenharmony_ci * 5288c2ecf20Sopenharmony_ci * Parse common sensor properties for remote devices related to the 5298c2ecf20Sopenharmony_ci * sensor and set up async sub-devices for them. 5308c2ecf20Sopenharmony_ci * 5318c2ecf20Sopenharmony_ci * Any notifier populated using this function must be released with a call to 5328c2ecf20Sopenharmony_ci * v4l2_async_notifier_release() after it has been unregistered and the async 5338c2ecf20Sopenharmony_ci * sub-devices are no longer in use, even in the case the function returned an 5348c2ecf20Sopenharmony_ci * error. 5358c2ecf20Sopenharmony_ci * 5368c2ecf20Sopenharmony_ci * Return: 0 on success 5378c2ecf20Sopenharmony_ci * -ENOMEM if memory allocation failed 5388c2ecf20Sopenharmony_ci * -EINVAL if property parsing failed 5398c2ecf20Sopenharmony_ci */ 5408c2ecf20Sopenharmony_ciint v4l2_async_notifier_parse_fwnode_sensor_common(struct device *dev, 5418c2ecf20Sopenharmony_ci struct v4l2_async_notifier *notifier); 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci/* Helper macros to access the connector links. */ 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci/** v4l2_connector_last_link - Helper macro to get the first 5468c2ecf20Sopenharmony_ci * &struct v4l2_fwnode_connector link 5478c2ecf20Sopenharmony_ci * @v4l2c: &struct v4l2_fwnode_connector owning the connector links 5488c2ecf20Sopenharmony_ci * 5498c2ecf20Sopenharmony_ci * This marco returns the first added &struct v4l2_connector_link connector 5508c2ecf20Sopenharmony_ci * link or @NULL if the connector has no links. 5518c2ecf20Sopenharmony_ci */ 5528c2ecf20Sopenharmony_ci#define v4l2_connector_first_link(v4l2c) \ 5538c2ecf20Sopenharmony_ci list_first_entry_or_null(&(v4l2c)->links, \ 5548c2ecf20Sopenharmony_ci struct v4l2_connector_link, head) 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci/** v4l2_connector_last_link - Helper macro to get the last 5578c2ecf20Sopenharmony_ci * &struct v4l2_fwnode_connector link 5588c2ecf20Sopenharmony_ci * @v4l2c: &struct v4l2_fwnode_connector owning the connector links 5598c2ecf20Sopenharmony_ci * 5608c2ecf20Sopenharmony_ci * This marco returns the last &struct v4l2_connector_link added connector link. 5618c2ecf20Sopenharmony_ci */ 5628c2ecf20Sopenharmony_ci#define v4l2_connector_last_link(v4l2c) \ 5638c2ecf20Sopenharmony_ci list_last_entry(&(v4l2c)->links, struct v4l2_connector_link, head) 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci#endif /* _V4L2_FWNODE_H */ 566