Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * V4L2 fwnode binding parsing library
0004  *
0005  * Copyright (c) 2016 Intel Corporation.
0006  * Author: Sakari Ailus <sakari.ailus@linux.intel.com>
0007  *
0008  * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
0009  * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
0010  *
0011  * Copyright (C) 2012 Renesas Electronics Corp.
0012  * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
0013  */
0014 #ifndef _V4L2_FWNODE_H
0015 #define _V4L2_FWNODE_H
0016 
0017 #include <linux/errno.h>
0018 #include <linux/fwnode.h>
0019 #include <linux/list.h>
0020 #include <linux/types.h>
0021 
0022 #include <media/v4l2-mediabus.h>
0023 
0024 struct fwnode_handle;
0025 struct v4l2_async_notifier;
0026 struct v4l2_async_subdev;
0027 
0028 /**
0029  * struct v4l2_fwnode_endpoint - the endpoint data structure
0030  * @base: fwnode endpoint of the v4l2_fwnode
0031  * @bus_type: bus type
0032  * @bus: bus configuration data structure
0033  * @bus.parallel: embedded &struct v4l2_mbus_config_parallel.
0034  *        Used if the bus is parallel.
0035  * @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1.
0036  *         Used if the bus is MIPI Alliance's Camera Serial
0037  *         Interface version 1 (MIPI CSI1) or Standard
0038  *         Mobile Imaging Architecture's Compact Camera Port 2
0039  *         (SMIA CCP2).
0040  * @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2.
0041  *         Used if the bus is MIPI Alliance's Camera Serial
0042  *         Interface version 2 (MIPI CSI2).
0043  * @link_frequencies: array of supported link frequencies
0044  * @nr_of_link_frequencies: number of elements in link_frequenccies array
0045  */
0046 struct v4l2_fwnode_endpoint {
0047     struct fwnode_endpoint base;
0048     /*
0049      * Fields below this line will be zeroed by
0050      * v4l2_fwnode_endpoint_parse()
0051      */
0052     enum v4l2_mbus_type bus_type;
0053     struct {
0054         struct v4l2_mbus_config_parallel parallel;
0055         struct v4l2_mbus_config_mipi_csi1 mipi_csi1;
0056         struct v4l2_mbus_config_mipi_csi2 mipi_csi2;
0057     } bus;
0058     u64 *link_frequencies;
0059     unsigned int nr_of_link_frequencies;
0060 };
0061 
0062 /**
0063  * V4L2_FWNODE_PROPERTY_UNSET - identify a non initialized property
0064  *
0065  * All properties in &struct v4l2_fwnode_device_properties are initialized
0066  * to this value.
0067  */
0068 #define V4L2_FWNODE_PROPERTY_UNSET   (-1U)
0069 
0070 /**
0071  * enum v4l2_fwnode_orientation - possible device orientation
0072  * @V4L2_FWNODE_ORIENTATION_FRONT: device installed on the front side
0073  * @V4L2_FWNODE_ORIENTATION_BACK: device installed on the back side
0074  * @V4L2_FWNODE_ORIENTATION_EXTERNAL: device externally located
0075  */
0076 enum v4l2_fwnode_orientation {
0077     V4L2_FWNODE_ORIENTATION_FRONT,
0078     V4L2_FWNODE_ORIENTATION_BACK,
0079     V4L2_FWNODE_ORIENTATION_EXTERNAL
0080 };
0081 
0082 /**
0083  * struct v4l2_fwnode_device_properties - fwnode device properties
0084  * @orientation: device orientation. See &enum v4l2_fwnode_orientation
0085  * @rotation: device rotation
0086  */
0087 struct v4l2_fwnode_device_properties {
0088     enum v4l2_fwnode_orientation orientation;
0089     unsigned int rotation;
0090 };
0091 
0092 /**
0093  * struct v4l2_fwnode_link - a link between two endpoints
0094  * @local_node: pointer to device_node of this endpoint
0095  * @local_port: identifier of the port this endpoint belongs to
0096  * @local_id: identifier of the id this endpoint belongs to
0097  * @remote_node: pointer to device_node of the remote endpoint
0098  * @remote_port: identifier of the port the remote endpoint belongs to
0099  * @remote_id: identifier of the id the remote endpoint belongs to
0100  */
0101 struct v4l2_fwnode_link {
0102     struct fwnode_handle *local_node;
0103     unsigned int local_port;
0104     unsigned int local_id;
0105     struct fwnode_handle *remote_node;
0106     unsigned int remote_port;
0107     unsigned int remote_id;
0108 };
0109 
0110 /**
0111  * enum v4l2_connector_type - connector type
0112  * @V4L2_CONN_UNKNOWN:   unknown connector type, no V4L2 connector configuration
0113  * @V4L2_CONN_COMPOSITE: analog composite connector
0114  * @V4L2_CONN_SVIDEO:    analog svideo connector
0115  */
0116 enum v4l2_connector_type {
0117     V4L2_CONN_UNKNOWN,
0118     V4L2_CONN_COMPOSITE,
0119     V4L2_CONN_SVIDEO,
0120 };
0121 
0122 /**
0123  * struct v4l2_connector_link - connector link data structure
0124  * @head: structure to be used to add the link to the
0125  *        &struct v4l2_fwnode_connector
0126  * @fwnode_link: &struct v4l2_fwnode_link link between the connector and the
0127  *               device the connector belongs to.
0128  */
0129 struct v4l2_connector_link {
0130     struct list_head head;
0131     struct v4l2_fwnode_link fwnode_link;
0132 };
0133 
0134 /**
0135  * struct v4l2_fwnode_connector_analog - analog connector data structure
0136  * @sdtv_stds: sdtv standards this connector supports, set to V4L2_STD_ALL
0137  *             if no restrictions are specified.
0138  */
0139 struct v4l2_fwnode_connector_analog {
0140     v4l2_std_id sdtv_stds;
0141 };
0142 
0143 /**
0144  * struct v4l2_fwnode_connector - the connector data structure
0145  * @name: the connector device name
0146  * @label: optional connector label
0147  * @type: connector type
0148  * @links: list of all connector &struct v4l2_connector_link links
0149  * @nr_of_links: total number of links
0150  * @connector: connector configuration
0151  * @connector.analog: analog connector configuration
0152  *                    &struct v4l2_fwnode_connector_analog
0153  */
0154 struct v4l2_fwnode_connector {
0155     const char *name;
0156     const char *label;
0157     enum v4l2_connector_type type;
0158     struct list_head links;
0159     unsigned int nr_of_links;
0160 
0161     union {
0162         struct v4l2_fwnode_connector_analog analog;
0163         /* future connectors */
0164     } connector;
0165 };
0166 
0167 /**
0168  * enum v4l2_fwnode_bus_type - Video bus types defined by firmware properties
0169  * @V4L2_FWNODE_BUS_TYPE_GUESS: Default value if no bus-type fwnode property
0170  * @V4L2_FWNODE_BUS_TYPE_CSI2_CPHY: MIPI CSI-2 bus, C-PHY physical layer
0171  * @V4L2_FWNODE_BUS_TYPE_CSI1: MIPI CSI-1 bus
0172  * @V4L2_FWNODE_BUS_TYPE_CCP2: SMIA Compact Camera Port 2 bus
0173  * @V4L2_FWNODE_BUS_TYPE_CSI2_DPHY: MIPI CSI-2 bus, D-PHY physical layer
0174  * @V4L2_FWNODE_BUS_TYPE_PARALLEL: Camera Parallel Interface bus
0175  * @V4L2_FWNODE_BUS_TYPE_BT656: BT.656 video format bus-type
0176  * @V4L2_FWNODE_BUS_TYPE_DPI: Video Parallel Interface bus
0177  * @NR_OF_V4L2_FWNODE_BUS_TYPE: Number of bus-types
0178  */
0179 enum v4l2_fwnode_bus_type {
0180     V4L2_FWNODE_BUS_TYPE_GUESS = 0,
0181     V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
0182     V4L2_FWNODE_BUS_TYPE_CSI1,
0183     V4L2_FWNODE_BUS_TYPE_CCP2,
0184     V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
0185     V4L2_FWNODE_BUS_TYPE_PARALLEL,
0186     V4L2_FWNODE_BUS_TYPE_BT656,
0187     V4L2_FWNODE_BUS_TYPE_DPI,
0188     NR_OF_V4L2_FWNODE_BUS_TYPE
0189 };
0190 
0191 /**
0192  * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
0193  * @fwnode: pointer to the endpoint's fwnode handle
0194  * @vep: pointer to the V4L2 fwnode data structure
0195  *
0196  * This function parses the V4L2 fwnode endpoint specific parameters from the
0197  * firmware. There are two ways to use this function, either by letting it
0198  * obtain the type of the bus (by setting the @vep.bus_type field to
0199  * V4L2_MBUS_UNKNOWN) or specifying the bus type explicitly to one of the &enum
0200  * v4l2_mbus_type types.
0201  *
0202  * When @vep.bus_type is V4L2_MBUS_UNKNOWN, the function will use the "bus-type"
0203  * property to determine the type when it is available. The caller is
0204  * responsible for validating the contents of @vep.bus_type field after the call
0205  * returns.
0206  *
0207  * As a deprecated functionality to support older DT bindings without "bus-type"
0208  * property for devices that support multiple types, if the "bus-type" property
0209  * does not exist, the function will attempt to guess the type based on the
0210  * endpoint properties available. NEVER RELY ON GUESSING THE BUS TYPE IN NEW
0211  * DRIVERS OR BINDINGS.
0212  *
0213  * It is also possible to set @vep.bus_type corresponding to an actual bus. In
0214  * this case the function will only attempt to parse properties related to this
0215  * bus, and it will return an error if the value of the "bus-type" property
0216  * corresponds to a different bus.
0217  *
0218  * The caller is required to initialise all fields of @vep, either with
0219  * explicitly values, or by zeroing them.
0220  *
0221  * The function does not change the V4L2 fwnode endpoint state if it fails.
0222  *
0223  * NOTE: This function does not parse "link-frequencies" property as its size is
0224  * not known in advance. Please use v4l2_fwnode_endpoint_alloc_parse() if you
0225  * need properties of variable size.
0226  *
0227  * Return: %0 on success or a negative error code on failure:
0228  *     %-ENOMEM on memory allocation failure
0229  *     %-EINVAL on parsing failure
0230  *     %-ENXIO on mismatching bus types
0231  */
0232 int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
0233                    struct v4l2_fwnode_endpoint *vep);
0234 
0235 /**
0236  * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by
0237  * v4l2_fwnode_endpoint_alloc_parse()
0238  * @vep: the V4L2 fwnode the resources of which are to be released
0239  *
0240  * It is safe to call this function with NULL argument or on a V4L2 fwnode the
0241  * parsing of which failed.
0242  */
0243 void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
0244 
0245 /**
0246  * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
0247  * @fwnode: pointer to the endpoint's fwnode handle
0248  * @vep: pointer to the V4L2 fwnode data structure
0249  *
0250  * This function parses the V4L2 fwnode endpoint specific parameters from the
0251  * firmware. There are two ways to use this function, either by letting it
0252  * obtain the type of the bus (by setting the @vep.bus_type field to
0253  * V4L2_MBUS_UNKNOWN) or specifying the bus type explicitly to one of the &enum
0254  * v4l2_mbus_type types.
0255  *
0256  * When @vep.bus_type is V4L2_MBUS_UNKNOWN, the function will use the "bus-type"
0257  * property to determine the type when it is available. The caller is
0258  * responsible for validating the contents of @vep.bus_type field after the call
0259  * returns.
0260  *
0261  * As a deprecated functionality to support older DT bindings without "bus-type"
0262  * property for devices that support multiple types, if the "bus-type" property
0263  * does not exist, the function will attempt to guess the type based on the
0264  * endpoint properties available. NEVER RELY ON GUESSING THE BUS TYPE IN NEW
0265  * DRIVERS OR BINDINGS.
0266  *
0267  * It is also possible to set @vep.bus_type corresponding to an actual bus. In
0268  * this case the function will only attempt to parse properties related to this
0269  * bus, and it will return an error if the value of the "bus-type" property
0270  * corresponds to a different bus.
0271  *
0272  * The caller is required to initialise all fields of @vep, either with
0273  * explicitly values, or by zeroing them.
0274  *
0275  * The function does not change the V4L2 fwnode endpoint state if it fails.
0276  *
0277  * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
0278  * v4l2_fwnode_endpoint_parse():
0279  *
0280  * 1. It also parses variable size data.
0281  *
0282  * 2. The memory it has allocated to store the variable size data must be freed
0283  *    using v4l2_fwnode_endpoint_free() when no longer needed.
0284  *
0285  * Return: %0 on success or a negative error code on failure:
0286  *     %-ENOMEM on memory allocation failure
0287  *     %-EINVAL on parsing failure
0288  *     %-ENXIO on mismatching bus types
0289  */
0290 int v4l2_fwnode_endpoint_alloc_parse(struct fwnode_handle *fwnode,
0291                      struct v4l2_fwnode_endpoint *vep);
0292 
0293 /**
0294  * v4l2_fwnode_parse_link() - parse a link between two endpoints
0295  * @fwnode: pointer to the endpoint's fwnode at the local end of the link
0296  * @link: pointer to the V4L2 fwnode link data structure
0297  *
0298  * Fill the link structure with the local and remote nodes and port numbers.
0299  * The local_node and remote_node fields are set to point to the local and
0300  * remote port's parent nodes respectively (the port parent node being the
0301  * parent node of the port node if that node isn't a 'ports' node, or the
0302  * grand-parent node of the port node otherwise).
0303  *
0304  * A reference is taken to both the local and remote nodes, the caller must use
0305  * v4l2_fwnode_put_link() to drop the references when done with the
0306  * link.
0307  *
0308  * Return: 0 on success, or -ENOLINK if the remote endpoint fwnode can't be
0309  * found.
0310  */
0311 int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
0312                struct v4l2_fwnode_link *link);
0313 
0314 /**
0315  * v4l2_fwnode_put_link() - drop references to nodes in a link
0316  * @link: pointer to the V4L2 fwnode link data structure
0317  *
0318  * Drop references to the local and remote nodes in the link. This function
0319  * must be called on every link parsed with v4l2_fwnode_parse_link().
0320  */
0321 void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);
0322 
0323 /**
0324  * v4l2_fwnode_connector_free() - free the V4L2 connector acquired memory
0325  * @connector: the V4L2 connector resources of which are to be released
0326  *
0327  * Free all allocated memory and put all links acquired by
0328  * v4l2_fwnode_connector_parse() and v4l2_fwnode_connector_add_link().
0329  *
0330  * It is safe to call this function with NULL argument or on a V4L2 connector
0331  * the parsing of which failed.
0332  */
0333 void v4l2_fwnode_connector_free(struct v4l2_fwnode_connector *connector);
0334 
0335 /**
0336  * v4l2_fwnode_connector_parse() - initialize the 'struct v4l2_fwnode_connector'
0337  * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector
0338  *      is connected to or to the connector endpoint fwnode handle.
0339  * @connector: pointer to the V4L2 fwnode connector data structure
0340  *
0341  * Fill the &struct v4l2_fwnode_connector with the connector type, label and
0342  * all &enum v4l2_connector_type specific connector data. The label is optional
0343  * so it is set to %NULL if no one was found. The function initialize the links
0344  * to zero. Adding links to the connector is done by calling
0345  * v4l2_fwnode_connector_add_link().
0346  *
0347  * The memory allocated for the label must be freed when no longer needed.
0348  * Freeing the memory is done by v4l2_fwnode_connector_free().
0349  *
0350  * Return:
0351  * * %0 on success or a negative error code on failure:
0352  * * %-EINVAL if @fwnode is invalid
0353  * * %-ENOTCONN if connector type is unknown or connector device can't be found
0354  */
0355 int v4l2_fwnode_connector_parse(struct fwnode_handle *fwnode,
0356                 struct v4l2_fwnode_connector *connector);
0357 
0358 /**
0359  * v4l2_fwnode_connector_add_link - add a link between a connector node and
0360  *                  a v4l2-subdev node.
0361  * @fwnode: pointer to the subdev endpoint's fwnode handle where the connector
0362  *          is connected to
0363  * @connector: pointer to the V4L2 fwnode connector data structure
0364  *
0365  * Add a new &struct v4l2_connector_link link to the
0366  * &struct v4l2_fwnode_connector connector links list. The link local_node
0367  * points to the connector node, the remote_node to the host v4l2 (sub)dev.
0368  *
0369  * The taken references to remote_node and local_node must be dropped and the
0370  * allocated memory must be freed when no longer needed. Both is done by calling
0371  * v4l2_fwnode_connector_free().
0372  *
0373  * Return:
0374  * * %0 on success or a negative error code on failure:
0375  * * %-EINVAL if @fwnode or @connector is invalid or @connector type is unknown
0376  * * %-ENOMEM on link memory allocation failure
0377  * * %-ENOTCONN if remote connector device can't be found
0378  * * %-ENOLINK if link parsing between v4l2 (sub)dev and connector fails
0379  */
0380 int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
0381                    struct v4l2_fwnode_connector *connector);
0382 
0383 /**
0384  * v4l2_fwnode_device_parse() - parse fwnode device properties
0385  * @dev: pointer to &struct device
0386  * @props: pointer to &struct v4l2_fwnode_device_properties where to store the
0387  *     parsed properties values
0388  *
0389  * This function parses and validates the V4L2 fwnode device properties from the
0390  * firmware interface, and fills the @struct v4l2_fwnode_device_properties
0391  * provided by the caller.
0392  *
0393  * Return:
0394  *  % 0 on success
0395  *  %-EINVAL if a parsed property value is not valid
0396  */
0397 int v4l2_fwnode_device_parse(struct device *dev,
0398                  struct v4l2_fwnode_device_properties *props);
0399 
0400 /**
0401  * typedef parse_endpoint_func - Driver's callback function to be called on
0402  *  each V4L2 fwnode endpoint.
0403  *
0404  * @dev: pointer to &struct device
0405  * @vep: pointer to &struct v4l2_fwnode_endpoint
0406  * @asd: pointer to &struct v4l2_async_subdev
0407  *
0408  * Return:
0409  * * %0 on success
0410  * * %-ENOTCONN if the endpoint is to be skipped but this
0411  *   should not be considered as an error
0412  * * %-EINVAL if the endpoint configuration is invalid
0413  */
0414 typedef int (*parse_endpoint_func)(struct device *dev,
0415                   struct v4l2_fwnode_endpoint *vep,
0416                   struct v4l2_async_subdev *asd);
0417 
0418 /**
0419  * v4l2_async_nf_parse_fwnode_endpoints - Parse V4L2 fwnode endpoints in a
0420  *                      device node
0421  * @dev: the device the endpoints of which are to be parsed
0422  * @notifier: notifier for @dev
0423  * @asd_struct_size: size of the driver's async sub-device struct, including
0424  *           sizeof(struct v4l2_async_subdev). The &struct
0425  *           v4l2_async_subdev shall be the first member of
0426  *           the driver's async sub-device struct, i.e. both
0427  *           begin at the same memory address.
0428  * @parse_endpoint: Driver's callback function called on each V4L2 fwnode
0429  *          endpoint. Optional.
0430  *
0431  * DEPRECATED! This function is deprecated. Don't use it in new drivers.
0432  * Instead see an example in cio2_parse_firmware() function in
0433  * drivers/media/pci/intel/ipu3/ipu3-cio2.c .
0434  *
0435  * Parse the fwnode endpoints of the @dev device and populate the async sub-
0436  * devices list in the notifier. The @parse_endpoint callback function is
0437  * called for each endpoint with the corresponding async sub-device pointer to
0438  * let the caller initialize the driver-specific part of the async sub-device
0439  * structure.
0440  *
0441  * The notifier memory shall be zeroed before this function is called on the
0442  * notifier.
0443  *
0444  * This function may not be called on a registered notifier and may be called on
0445  * a notifier only once.
0446  *
0447  * The &struct v4l2_fwnode_endpoint passed to the callback function
0448  * @parse_endpoint is released once the function is finished. If there is a need
0449  * to retain that configuration, the user needs to allocate memory for it.
0450  *
0451  * Any notifier populated using this function must be released with a call to
0452  * v4l2_async_nf_cleanup() after it has been unregistered and the async
0453  * sub-devices are no longer in use, even if the function returned an error.
0454  *
0455  * Return: %0 on success, including when no async sub-devices are found
0456  *     %-ENOMEM if memory allocation failed
0457  *     %-EINVAL if graph or endpoint parsing failed
0458  *     Other error codes as returned by @parse_endpoint
0459  */
0460 int
0461 v4l2_async_nf_parse_fwnode_endpoints(struct device *dev,
0462                      struct v4l2_async_notifier *notifier,
0463                      size_t asd_struct_size,
0464                      parse_endpoint_func parse_endpoint);
0465 
0466 /* Helper macros to access the connector links. */
0467 
0468 /** v4l2_connector_last_link - Helper macro to get the first
0469  *                             &struct v4l2_fwnode_connector link
0470  * @v4l2c: &struct v4l2_fwnode_connector owning the connector links
0471  *
0472  * This marco returns the first added &struct v4l2_connector_link connector
0473  * link or @NULL if the connector has no links.
0474  */
0475 #define v4l2_connector_first_link(v4l2c)                       \
0476     list_first_entry_or_null(&(v4l2c)->links,                  \
0477                  struct v4l2_connector_link, head)
0478 
0479 /** v4l2_connector_last_link - Helper macro to get the last
0480  *                             &struct v4l2_fwnode_connector link
0481  * @v4l2c: &struct v4l2_fwnode_connector owning the connector links
0482  *
0483  * This marco returns the last &struct v4l2_connector_link added connector link.
0484  */
0485 #define v4l2_connector_last_link(v4l2c)                        \
0486     list_last_entry(&(v4l2c)->links, struct v4l2_connector_link, head)
0487 
0488 #endif /* _V4L2_FWNODE_H */