media: ipu-bridge: Only keep PLD around while parsing
[platform/kernel/linux-starfive.git] / drivers / media / pci / intel / ipu-bridge.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Author: Dan Scally <djrscally@gmail.com> */
3 #ifndef __IPU_BRIDGE_H
4 #define __IPU_BRIDGE_H
5
6 #include <linux/property.h>
7 #include <linux/types.h>
8
9 struct i2c_client;
10
11 #define IPU_HID                         "INT343E"
12 #define IPU_MAX_LANES                           4
13 #define IPU_MAX_PORTS                           4
14 #define MAX_NUM_LINK_FREQS                      3
15
16 /* Values are educated guesses as we don't have a spec */
17 #define IPU_SENSOR_ROTATION_NORMAL              0
18 #define IPU_SENSOR_ROTATION_INVERTED            1
19
20 #define IPU_SENSOR_CONFIG(_HID, _NR, ...)       \
21         (const struct ipu_sensor_config) {      \
22                 .hid = _HID,                    \
23                 .nr_link_freqs = _NR,           \
24                 .link_freqs = { __VA_ARGS__ }   \
25         }
26
27 #define NODE_SENSOR(_HID, _PROPS)               \
28         (const struct software_node) {          \
29                 .name = _HID,                   \
30                 .properties = _PROPS,           \
31         }
32
33 #define NODE_PORT(_PORT, _SENSOR_NODE)          \
34         (const struct software_node) {          \
35                 .name = _PORT,                  \
36                 .parent = _SENSOR_NODE,         \
37         }
38
39 #define NODE_ENDPOINT(_EP, _PORT, _PROPS)       \
40         (const struct software_node) {          \
41                 .name = _EP,                    \
42                 .parent = _PORT,                \
43                 .properties = _PROPS,           \
44         }
45
46 #define NODE_VCM(_TYPE)                         \
47         (const struct software_node) {          \
48                 .name = _TYPE,                  \
49         }
50
51 enum ipu_sensor_swnodes {
52         SWNODE_SENSOR_HID,
53         SWNODE_SENSOR_PORT,
54         SWNODE_SENSOR_ENDPOINT,
55         SWNODE_IPU_PORT,
56         SWNODE_IPU_ENDPOINT,
57         /* Must be last because it is optional / maybe empty */
58         SWNODE_VCM,
59         SWNODE_COUNT
60 };
61
62 /* Data representation as it is in ACPI SSDB buffer */
63 struct ipu_sensor_ssdb {
64         u8 version;
65         u8 sku;
66         u8 guid_csi2[16];
67         u8 devfunction;
68         u8 bus;
69         u32 dphylinkenfuses;
70         u32 clockdiv;
71         u8 link;
72         u8 lanes;
73         u32 csiparams[10];
74         u32 maxlanespeed;
75         u8 sensorcalibfileidx;
76         u8 sensorcalibfileidxInMBZ[3];
77         u8 romtype;
78         u8 vcmtype;
79         u8 platforminfo;
80         u8 platformsubinfo;
81         u8 flash;
82         u8 privacyled;
83         u8 degree;
84         u8 mipilinkdefined;
85         u32 mclkspeed;
86         u8 controllogicid;
87         u8 reserved1[3];
88         u8 mclkport;
89         u8 reserved2[13];
90 } __packed;
91
92 struct ipu_property_names {
93         char clock_frequency[16];
94         char rotation[9];
95         char orientation[12];
96         char bus_type[9];
97         char data_lanes[11];
98         char remote_endpoint[16];
99         char link_frequencies[17];
100 };
101
102 struct ipu_node_names {
103         char port[7];
104         char endpoint[11];
105         char remote_port[7];
106         char vcm[16];
107 };
108
109 struct ipu_sensor_config {
110         const char *hid;
111         const u8 nr_link_freqs;
112         const u64 link_freqs[MAX_NUM_LINK_FREQS];
113 };
114
115 struct ipu_sensor {
116         /* append ssdb.link(u8) in "-%u" format as suffix of HID */
117         char name[ACPI_ID_LEN + 4];
118         struct acpi_device *adev;
119         struct i2c_client *vcm_i2c_client;
120
121         /* SWNODE_COUNT + 1 for terminating NULL */
122         const struct software_node *group[SWNODE_COUNT + 1];
123         struct software_node swnodes[SWNODE_COUNT];
124         struct ipu_node_names node_names;
125
126         struct ipu_sensor_ssdb ssdb;
127
128         struct ipu_property_names prop_names;
129         struct property_entry ep_properties[5];
130         struct property_entry dev_properties[5];
131         struct property_entry ipu_properties[3];
132         struct software_node_ref_args local_ref[1];
133         struct software_node_ref_args remote_ref[1];
134         struct software_node_ref_args vcm_ref[1];
135 };
136
137 struct ipu_bridge {
138         struct device *dev;
139         char ipu_node_name[ACPI_ID_LEN];
140         struct software_node ipu_hid_node;
141         u32 data_lanes[4];
142         unsigned int n_sensors;
143         struct ipu_sensor sensors[IPU_MAX_PORTS];
144 };
145
146 #if IS_ENABLED(CONFIG_IPU_BRIDGE)
147 int ipu_bridge_init(struct device *dev);
148 #else
149 static inline int ipu_bridge_init(struct device *dev) { return 0; }
150 #endif
151
152 #endif