Merge tag 'powerpc-4.14-6' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[sfrench/cifs-2.6.git] / include / media / v4l2-fwnode.h
1 /*
2  * V4L2 fwnode binding parsing library
3  *
4  * Copyright (c) 2016 Intel Corporation.
5  * Author: Sakari Ailus <sakari.ailus@linux.intel.com>
6  *
7  * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
8  * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
9  *
10  * Copyright (C) 2012 Renesas Electronics Corp.
11  * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of version 2 of the GNU General Public License as
15  * published by the Free Software Foundation.
16  */
17 #ifndef _V4L2_FWNODE_H
18 #define _V4L2_FWNODE_H
19
20 #include <linux/errno.h>
21 #include <linux/fwnode.h>
22 #include <linux/list.h>
23 #include <linux/types.h>
24
25 #include <media/v4l2-mediabus.h>
26
27 struct fwnode_handle;
28
29 #define V4L2_FWNODE_CSI2_MAX_DATA_LANES 4
30
31 /**
32  * struct v4l2_fwnode_bus_mipi_csi2 - MIPI CSI-2 bus data structure
33  * @flags: media bus (V4L2_MBUS_*) flags
34  * @data_lanes: an array of physical data lane indexes
35  * @clock_lane: physical lane index of the clock lane
36  * @num_data_lanes: number of data lanes
37  * @lane_polarities: polarity of the lanes. The order is the same of
38  *                 the physical lanes.
39  */
40 struct v4l2_fwnode_bus_mipi_csi2 {
41         unsigned int flags;
42         unsigned char data_lanes[V4L2_FWNODE_CSI2_MAX_DATA_LANES];
43         unsigned char clock_lane;
44         unsigned short num_data_lanes;
45         bool lane_polarities[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
46 };
47
48 /**
49  * struct v4l2_fwnode_bus_parallel - parallel data bus data structure
50  * @flags: media bus (V4L2_MBUS_*) flags
51  * @bus_width: bus width in bits
52  * @data_shift: data shift in bits
53  */
54 struct v4l2_fwnode_bus_parallel {
55         unsigned int flags;
56         unsigned char bus_width;
57         unsigned char data_shift;
58 };
59
60 /**
61  * struct v4l2_fwnode_bus_mipi_csi1 - CSI-1/CCP2 data bus structure
62  * @clock_inv: polarity of clock/strobe signal
63  *             false - not inverted, true - inverted
64  * @strobe: false - data/clock, true - data/strobe
65  * @lane_polarity: the polarities of the clock (index 0) and data lanes
66  *                 index (1)
67  * @data_lane: the number of the data lane
68  * @clock_lane: the number of the clock lane
69  */
70 struct v4l2_fwnode_bus_mipi_csi1 {
71         bool clock_inv;
72         bool strobe;
73         bool lane_polarity[2];
74         unsigned char data_lane;
75         unsigned char clock_lane;
76 };
77
78 /**
79  * struct v4l2_fwnode_endpoint - the endpoint data structure
80  * @base: fwnode endpoint of the v4l2_fwnode
81  * @bus_type: bus type
82  * @bus: bus configuration data structure
83  * @link_frequencies: array of supported link frequencies
84  * @nr_of_link_frequencies: number of elements in link_frequenccies array
85  */
86 struct v4l2_fwnode_endpoint {
87         struct fwnode_endpoint base;
88         /*
89          * Fields below this line will be zeroed by
90          * v4l2_fwnode_parse_endpoint()
91          */
92         enum v4l2_mbus_type bus_type;
93         union {
94                 struct v4l2_fwnode_bus_parallel parallel;
95                 struct v4l2_fwnode_bus_mipi_csi1 mipi_csi1;
96                 struct v4l2_fwnode_bus_mipi_csi2 mipi_csi2;
97         } bus;
98         u64 *link_frequencies;
99         unsigned int nr_of_link_frequencies;
100 };
101
102 /**
103  * struct v4l2_fwnode_link - a link between two endpoints
104  * @local_node: pointer to device_node of this endpoint
105  * @local_port: identifier of the port this endpoint belongs to
106  * @remote_node: pointer to device_node of the remote endpoint
107  * @remote_port: identifier of the port the remote endpoint belongs to
108  */
109 struct v4l2_fwnode_link {
110         struct fwnode_handle *local_node;
111         unsigned int local_port;
112         struct fwnode_handle *remote_node;
113         unsigned int remote_port;
114 };
115
116 int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
117                                struct v4l2_fwnode_endpoint *vep);
118 struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
119         struct fwnode_handle *fwnode);
120 void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
121 int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
122                            struct v4l2_fwnode_link *link);
123 void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);
124
125 #endif /* _V4L2_FWNODE_H */