This source file includes following definitions.
- drm_bridge_to_panel_bridge
- drm_connector_to_panel_bridge
- panel_bridge_connector_get_modes
- panel_bridge_attach
- panel_bridge_detach
- panel_bridge_pre_enable
- panel_bridge_enable
- panel_bridge_disable
- panel_bridge_post_disable
- drm_panel_bridge_add
- drm_panel_bridge_remove
- devm_drm_panel_bridge_release
- devm_drm_panel_bridge_add
1
2
3
4
5
6
7 #include <drm/drm_atomic_helper.h>
8 #include <drm/drm_connector.h>
9 #include <drm/drm_encoder.h>
10 #include <drm/drm_modeset_helper_vtables.h>
11 #include <drm/drm_panel.h>
12 #include <drm/drm_print.h>
13 #include <drm/drm_probe_helper.h>
14
15 struct panel_bridge {
16 struct drm_bridge bridge;
17 struct drm_connector connector;
18 struct drm_panel *panel;
19 u32 connector_type;
20 };
21
22 static inline struct panel_bridge *
23 drm_bridge_to_panel_bridge(struct drm_bridge *bridge)
24 {
25 return container_of(bridge, struct panel_bridge, bridge);
26 }
27
28 static inline struct panel_bridge *
29 drm_connector_to_panel_bridge(struct drm_connector *connector)
30 {
31 return container_of(connector, struct panel_bridge, connector);
32 }
33
34 static int panel_bridge_connector_get_modes(struct drm_connector *connector)
35 {
36 struct panel_bridge *panel_bridge =
37 drm_connector_to_panel_bridge(connector);
38
39 return drm_panel_get_modes(panel_bridge->panel);
40 }
41
42 static const struct drm_connector_helper_funcs
43 panel_bridge_connector_helper_funcs = {
44 .get_modes = panel_bridge_connector_get_modes,
45 };
46
47 static const struct drm_connector_funcs panel_bridge_connector_funcs = {
48 .reset = drm_atomic_helper_connector_reset,
49 .fill_modes = drm_helper_probe_single_connector_modes,
50 .destroy = drm_connector_cleanup,
51 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
52 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
53 };
54
55 static int panel_bridge_attach(struct drm_bridge *bridge)
56 {
57 struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
58 struct drm_connector *connector = &panel_bridge->connector;
59 int ret;
60
61 if (!bridge->encoder) {
62 DRM_ERROR("Missing encoder\n");
63 return -ENODEV;
64 }
65
66 drm_connector_helper_add(connector,
67 &panel_bridge_connector_helper_funcs);
68
69 ret = drm_connector_init(bridge->dev, connector,
70 &panel_bridge_connector_funcs,
71 panel_bridge->connector_type);
72 if (ret) {
73 DRM_ERROR("Failed to initialize connector\n");
74 return ret;
75 }
76
77 drm_connector_attach_encoder(&panel_bridge->connector,
78 bridge->encoder);
79
80 ret = drm_panel_attach(panel_bridge->panel, &panel_bridge->connector);
81 if (ret < 0)
82 return ret;
83
84 return 0;
85 }
86
87 static void panel_bridge_detach(struct drm_bridge *bridge)
88 {
89 struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
90
91 drm_panel_detach(panel_bridge->panel);
92 }
93
94 static void panel_bridge_pre_enable(struct drm_bridge *bridge)
95 {
96 struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
97
98 drm_panel_prepare(panel_bridge->panel);
99 }
100
101 static void panel_bridge_enable(struct drm_bridge *bridge)
102 {
103 struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
104
105 drm_panel_enable(panel_bridge->panel);
106 }
107
108 static void panel_bridge_disable(struct drm_bridge *bridge)
109 {
110 struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
111
112 drm_panel_disable(panel_bridge->panel);
113 }
114
115 static void panel_bridge_post_disable(struct drm_bridge *bridge)
116 {
117 struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
118
119 drm_panel_unprepare(panel_bridge->panel);
120 }
121
122 static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
123 .attach = panel_bridge_attach,
124 .detach = panel_bridge_detach,
125 .pre_enable = panel_bridge_pre_enable,
126 .enable = panel_bridge_enable,
127 .disable = panel_bridge_disable,
128 .post_disable = panel_bridge_post_disable,
129 };
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel,
155 u32 connector_type)
156 {
157 struct panel_bridge *panel_bridge;
158
159 if (!panel)
160 return ERR_PTR(-EINVAL);
161
162 panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge),
163 GFP_KERNEL);
164 if (!panel_bridge)
165 return ERR_PTR(-ENOMEM);
166
167 panel_bridge->connector_type = connector_type;
168 panel_bridge->panel = panel;
169
170 panel_bridge->bridge.funcs = &panel_bridge_bridge_funcs;
171 #ifdef CONFIG_OF
172 panel_bridge->bridge.of_node = panel->dev->of_node;
173 #endif
174
175 drm_bridge_add(&panel_bridge->bridge);
176
177 return &panel_bridge->bridge;
178 }
179 EXPORT_SYMBOL(drm_panel_bridge_add);
180
181
182
183
184
185
186
187 void drm_panel_bridge_remove(struct drm_bridge *bridge)
188 {
189 struct panel_bridge *panel_bridge;
190
191 if (!bridge)
192 return;
193
194 if (bridge->funcs != &panel_bridge_bridge_funcs)
195 return;
196
197 panel_bridge = drm_bridge_to_panel_bridge(bridge);
198
199 drm_bridge_remove(bridge);
200 devm_kfree(panel_bridge->panel->dev, bridge);
201 }
202 EXPORT_SYMBOL(drm_panel_bridge_remove);
203
204 static void devm_drm_panel_bridge_release(struct device *dev, void *res)
205 {
206 struct drm_bridge **bridge = res;
207
208 drm_panel_bridge_remove(*bridge);
209 }
210
211
212
213
214
215
216
217
218
219
220
221
222 struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
223 struct drm_panel *panel,
224 u32 connector_type)
225 {
226 struct drm_bridge **ptr, *bridge;
227
228 ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr),
229 GFP_KERNEL);
230 if (!ptr)
231 return ERR_PTR(-ENOMEM);
232
233 bridge = drm_panel_bridge_add(panel, connector_type);
234 if (!IS_ERR(bridge)) {
235 *ptr = bridge;
236 devres_add(dev, ptr);
237 } else {
238 devres_free(ptr);
239 }
240
241 return bridge;
242 }
243 EXPORT_SYMBOL(devm_drm_panel_bridge_add);