/* SPDX-License-Identifier: GPL-2.0-only */1/*2* V4L2 fwnode binding parsing library3*4* Copyright (c) 2016 Intel Corporation.5* Author: Sakari Ailus <[email protected]>6*7* Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.8* Author: Sylwester Nawrocki <[email protected]>9*10* Copyright (C) 2012 Renesas Electronics Corp.11* Author: Guennadi Liakhovetski <[email protected]>12*/13#ifndef _V4L2_FWNODE_H14#define _V4L2_FWNODE_H1516#include <linux/errno.h>17#include <linux/fwnode.h>18#include <linux/list.h>19#include <linux/types.h>2021#include <media/v4l2-mediabus.h>2223/**24* struct v4l2_fwnode_endpoint - the endpoint data structure25* @base: fwnode endpoint of the v4l2_fwnode26* @bus_type: bus type27* @bus: bus configuration data structure28* @bus.parallel: embedded &struct v4l2_mbus_config_parallel.29* Used if the bus is parallel.30* @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1.31* Used if the bus is MIPI Alliance's Camera Serial32* Interface version 1 (MIPI CSI1) or Standard33* Mobile Imaging Architecture's Compact Camera Port 234* (SMIA CCP2).35* @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2.36* Used if the bus is MIPI Alliance's Camera Serial37* Interface version 2 (MIPI CSI2).38* @link_frequencies: array of supported link frequencies39* @nr_of_link_frequencies: number of elements in link_frequenccies array40*/41struct v4l2_fwnode_endpoint {42struct fwnode_endpoint base;43enum v4l2_mbus_type bus_type;44struct {45struct v4l2_mbus_config_parallel parallel;46struct v4l2_mbus_config_mipi_csi1 mipi_csi1;47struct v4l2_mbus_config_mipi_csi2 mipi_csi2;48} bus;49u64 *link_frequencies;50unsigned int nr_of_link_frequencies;51};5253/**54* V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property55*56* All properties in &struct v4l2_fwnode_device_properties are initialized57* to this value.58*/59#define V4L2_FWNODE_PROPERTY_UNSET (-1U)6061/**62* enum v4l2_fwnode_orientation - possible device orientation63* @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side64* @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side65* @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located66*/67enum v4l2_fwnode_orientation {68V4L2_FWNODE_ORIENTATION_FRONT,69V4L2_FWNODE_ORIENTATION_BACK,70V4L2_FWNODE_ORIENTATION_EXTERNAL71};7273/**74* struct v4l2_fwnode_device_properties - fwnode device properties75* @orientation: device orientation. See &enum v4l2_fwnode_orientation76* @rotation: device rotation77*/78struct v4l2_fwnode_device_properties {79enum v4l2_fwnode_orientation orientation;80unsigned int rotation;81};8283/**84* struct v4l2_fwnode_link - a link between two endpoints85* @local_node: pointer to device_node of this endpoint86* @local_port: identifier of the port this endpoint belongs to87* @local_id: identifier of the id this endpoint belongs to88* @remote_node: pointer to device_node of the remote endpoint89* @remote_port: identifier of the port the remote endpoint belongs to90* @remote_id: identifier of the id the remote endpoint belongs to91*/92struct v4l2_fwnode_link {93struct fwnode_handle *local_node;94unsigned int local_port;95unsigned int local_id;96struct fwnode_handle *remote_node;97unsigned int remote_port;98unsigned int remote_id;99};100101/**102* enum v4l2_connector_type - connector type103* @V4L2_CONN_UNKNOWN: unknown connector type, no V4L2 connector configuration104* @V4L2_CONN_COMPOSITE: analog composite connector105* @V4L2_CONN_SVIDEO: analog svideo connector106*/107enum v4l2_connector_type {108V4L2_CONN_UNKNOWN,109V4L2_CONN_COMPOSITE,110V4L2_CONN_SVIDEO,111};112113/**114* struct v4l2_connector_link - connector link data structure115* @head: structure to be used to add the link to the116* &struct v4l2_fwnode_connector117* @fwnode_link: &struct v4l2_fwnode_link link between the connector and the118* device the connector belongs to.119*/120struct v4l2_connector_link {121struct list_head head;122struct v4l2_fwnode_link fwnode_link;123};124125/**126* struct v4l2_fwnode_connector_analog - analog connector data structure127* @sdtv_stds: sdtv standards this connector supports, set to V4L2_STD_ALL128* if no restrictions are specified.129*/130struct v4l2_fwnode_connector_analog {131v4l2_std_id sdtv_stds;132};133134/**135* struct v4l2_fwnode_connector - the connector data structure136* @name: the connector device name137* @label: optional connector label138* @type: connector type139* @links: list of all connector &struct v4l2_connector_link links140* @nr_of_links: total number of links141* @connector: connector configuration142* @connector.analog: analog connector configuration143* &struct v4l2_fwnode_connector_analog144*/145struct v4l2_fwnode_connector {146const char *name;147const char *label;148enum v4l2_connector_type type;149struct list_head links;150unsigned int nr_of_links;151152union {153struct v4l2_fwnode_connector_analog analog;154/* future connectors */155} connector;156};157158/**159* enum v4l2_fwnode_bus_type - Video bus types defined by firmware properties160* @V4L2_FWNODE_BUS_TYPE_GUESS: Default value if no bus-type fwnode property161* @V4L2_FWNODE_BUS_TYPE_CSI2_CPHY: MIPI CSI-2 bus, C-PHY physical layer162* @V4L2_FWNODE_BUS_TYPE_CSI1: MIPI CSI-1 bus163* @V4L2_FWNODE_BUS_TYPE_CCP2: SMIA Compact Camera Port 2 bus164* @V4L2_FWNODE_BUS_TYPE_CSI2_DPHY: MIPI CSI-2 bus, D-PHY physical layer165* @V4L2_FWNODE_BUS_TYPE_PARALLEL: Camera Parallel Interface bus166* @V4L2_FWNODE_BUS_TYPE_BT656: BT.656 video format bus-type167* @V4L2_FWNODE_BUS_TYPE_DPI: Video Parallel Interface bus168* @NR_OF_V4L2_FWNODE_BUS_TYPE: Number of bus-types169*/170enum v4l2_fwnode_bus_type {171V4L2_FWNODE_BUS_TYPE_GUESS = 0,172V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,173V4L2_FWNODE_BUS_TYPE_CSI1,174V4L2_FWNODE_BUS_TYPE_CCP2,175V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,176V4L2_FWNODE_BUS_TYPE_PARALLEL,177V4L2_FWNODE_BUS_TYPE_BT656,178V4L2_FWNODE_BUS_TYPE_DPI,179NR_OF_V4L2_FWNODE_BUS_TYPE180};181182/**183* v4l2_fwnode_endpoint_parse() - parse all fwnode node properties184* @fwnode: pointer to the endpoint's fwnode handle185* @vep: pointer to the V4L2 fwnode data structure186*187* This function parses the V4L2 fwnode endpoint specific parameters from the188* firmware. There are two ways to use this function, either by letting it189* obtain the type of the bus (by setting the @vep.bus_type field to190* V4L2_MBUS_UNKNOWN) or specifying the bus type explicitly to one of the &enum191* v4l2_mbus_type types.192*193* When @vep.bus_type is V4L2_MBUS_UNKNOWN, the function will use the "bus-type"194* property to determine the type when it is available. The caller is195* responsible for validating the contents of @vep.bus_type field after the call196* returns.197*198* As a deprecated functionality to support older DT bindings without "bus-type"199* property for devices that support multiple types, if the "bus-type" property200* does not exist, the function will attempt to guess the type based on the201* endpoint properties available. NEVER RELY ON GUESSING THE BUS TYPE IN NEW202* DRIVERS OR BINDINGS.203*204* It is also possible to set @vep.bus_type corresponding to an actual bus. In205* this case the function will only attempt to parse properties related to this206* bus, and it will return an error if the value of the "bus-type" property207* corresponds to a different bus.208*209* The caller is required to initialise all fields of @vep, either with210* explicitly values, or by zeroing them.211*212* The function does not change the V4L2 fwnode endpoint state if it fails.213*214* NOTE: This function does not parse "link-frequencies" property as its size is215* not known in advance. Please use v4l2_fwnode_endpoint_alloc_parse() if you216* need properties of variable size.217*218* Return: %0 on success or a negative error code on failure:219* %-ENOMEM on memory allocation failure220* %-EINVAL on parsing failure221* %-ENXIO on mismatching bus types222*/223int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,224struct v4l2_fwnode_endpoint *vep);225226/**227* v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by228* v4l2_fwnode_endpoint_alloc_parse()229* @vep: the V4L2 fwnode the resources of which are to be released230*231* It is safe to call this function with NULL argument or on a V4L2 fwnode the232* parsing of which failed.233*/234void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);235236/**237* v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties238* @fwnode: pointer to the endpoint's fwnode handle239* @vep: pointer to the V4L2 fwnode data structure240*241* This function parses the V4L2 fwnode endpoint specific parameters from the242* firmware. There are two ways to use this function, either by letting it243* obtain the type of the bus (by setting the @vep.bus_type field to244* V4L2_MBUS_UNKNOWN) or specifying the bus type explicitly to one of the &enum245* v4l2_mbus_type types.246*247* When @vep.bus_type is V4L2_MBUS_UNKNOWN, the function will use the "bus-type"248* property to determine the type when it is available. The caller is249* responsible for validating the contents of @vep.bus_type field after the call250* returns.251*252* As a deprecated functionality to support older DT bindings without "bus-type"253* property for devices that support multiple types, if the "bus-type" property254* does not exist, the function will attempt to guess the type based on the255* endpoint properties available. NEVER RELY ON GUESSING THE BUS TYPE IN NEW256* DRIVERS OR BINDINGS.257*258* It is also possible to set @vep.bus_type corresponding to an actual bus. In259* this case the function will only attempt to parse properties related to this260* bus, and it will return an error if the value of the "bus-type" property261* corresponds to a different bus.262*263* The caller is required to initialise all fields of @vep, either with264* explicitly values, or by zeroing them.265*266* The function does not change the V4L2 fwnode endpoint state if it fails.267*268* v4l2_fwnode_endpoint_alloc_parse() has two important differences to269* v4l2_fwnode_endpoint_parse():270*271* 1. It also parses variable size data.272*273* 2. The memory it has allocated to store the variable size data must be freed274* using v4l2_fwnode_endpoint_free() when no longer needed.275*276* Return: %0 on success or a negative error code on failure:277* %-ENOMEM on memory allocation failure278* %-EINVAL on parsing failure279* %-ENXIO on mismatching bus types280*/281int v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode,282struct v4l2_fwnode_endpoint *vep);283284/**285* v4l2_fwnode_parse_link() - parse a link between two endpoints286* @fwnode: pointer to the endpoint's fwnode at the local end of the link287* @link: pointer to the V4L2 fwnode link data structure288*289* Fill the link structure with the local and remote nodes and port numbers.290* The local_node and remote_node fields are set to point to the local and291* remote port's parent nodes respectively (the port parent node being the292* parent node of the port node if that node isn't a 'ports' node, or the293* grand-parent node of the port node otherwise).294*295* A reference is taken to both the local and remote nodes, the caller must use296* v4l2_fwnode_put_link() to drop the references when done with the297* link.298*299* Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be300* found.301*/302int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,303struct v4l2_fwnode_link *link);304305/**306* v4l2_fwnode_put_link() - drop references to nodes in a link307* @link: pointer to the V4L2 fwnode link data structure308*309* Drop references to the local and remote nodes in the link. This function310* must be called on every link parsed with v4l2_fwnode_parse_link().311*/312void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);313314/**315* v4l2_fwnode_connector_free() - free the V4L2 connector acquired memory316* @connector: the V4L2 connector resources of which are to be released317*318* Free all allocated memory and put all links acquired by319* v4l2_fwnode_connector_parse() and v4l2_fwnode_connector_add_link().320*321* It is safe to call this function with NULL argument or on a V4L2 connector322* the parsing of which failed.323*/324void v4l2_fwnode_connector_free(struct v4l2_fwnode_connector *connector);325326/**327* v4l2_fwnode_connector_parse() - initialize the 'struct v4l2_fwnode_connector'328* @fwnode: pointer to the subdev endpoint's fwnode handle where the connector329* is connected to or to the connector endpoint fwnode handle.330* @connector: pointer to the V4L2 fwnode connector data structure331*332* Fill the &struct v4l2_fwnode_connector with the connector type, label and333* all &enum v4l2_connector_type specific connector data. The label is optional334* so it is set to %NULL if no one was found. The function initialize the links335* to zero. Adding links to the connector is done by calling336* v4l2_fwnode_connector_add_link().337*338* The memory allocated for the label must be freed when no longer needed.339* Freeing the memory is done by v4l2_fwnode_connector_free().340*341* Return:342* * %0 on success or a negative error code on failure:343* * %-EINVAL if @fwnode is invalid344* * %-ENOTCONN if connector type is unknown or connector device can't be found345*/346int v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode,347struct v4l2_fwnode_connector *connector);348349/**350* v4l2_fwnode_connector_add_link - add a link between a connector node and351* a v4l2-subdev node.352* @fwnode: pointer to the subdev endpoint's fwnode handle where the connector353* is connected to354* @connector: pointer to the V4L2 fwnode connector data structure355*356* Add a new &struct v4l2_connector_link link to the357* &struct v4l2_fwnode_connector connector links list. The link local_node358* points to the connector node, the remote_node to the host v4l2 (sub)dev.359*360* The taken references to remote_node and local_node must be dropped and the361* allocated memory must be freed when no longer needed. Both is done by calling362* v4l2_fwnode_connector_free().363*364* Return:365* * %0 on success or a negative error code on failure:366* * %-EINVAL if @fwnode or @connector is invalid or @connector type is unknown367* * %-ENOMEM on link memory allocation failure368* * %-ENOTCONN if remote connector device can't be found369* * %-ENOLINK if link parsing between v4l2 (sub)dev and connector fails370*/371int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,372struct v4l2_fwnode_connector *connector);373374/**375* v4l2_fwnode_device_parse() - parse fwnode device properties376* @dev: pointer to &struct device377* @props: pointer to &struct v4l2_fwnode_device_properties where to store the378* parsed properties values379*380* This function parses and validates the V4L2 fwnode device properties from the381* firmware interface, and fills the @struct v4l2_fwnode_device_properties382* provided by the caller.383*384* Return:385* % 0 on success386* %-EINVAL if a parsed property value is not valid387*/388int v4l2_fwnode_device_parse(struct device *dev,389struct v4l2_fwnode_device_properties *props);390391/* Helper macros to access the connector links. */392393/** v4l2_connector_last_link - Helper macro to get the first394* &struct v4l2_fwnode_connector link395* @v4l2c: &struct v4l2_fwnode_connector owning the connector links396*397* This marco returns the first added &struct v4l2_connector_link connector398* link or @NULL if the connector has no links.399*/400#define v4l2_connector_first_link(v4l2c) \401list_first_entry_or_null(&(v4l2c)->links, \402struct v4l2_connector_link, head)403404/** v4l2_connector_last_link - Helper macro to get the last405* &struct v4l2_fwnode_connector link406* @v4l2c: &struct v4l2_fwnode_connector owning the connector links407*408* This marco returns the last &struct v4l2_connector_link added connector link.409*/410#define v4l2_connector_last_link(v4l2c) \411list_last_entry(&(v4l2c)->links, struct v4l2_connector_link, head)412413#endif /* _V4L2_FWNODE_H */414415416