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