.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
---|
3 | 4 | * Copyright (C) 2017 Broadcom |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or |
---|
6 | | - * modify it under the terms of the GNU General Public License as |
---|
7 | | - * published by the Free Software Foundation; either version 2 of |
---|
8 | | - * the License, or (at your option) any later version. |
---|
9 | 5 | */ |
---|
10 | 6 | |
---|
11 | | -#include <drm/drmP.h> |
---|
12 | | -#include <drm/drm_panel.h> |
---|
13 | 7 | #include <drm/drm_atomic_helper.h> |
---|
| 8 | +#include <drm/drm_bridge.h> |
---|
14 | 9 | #include <drm/drm_connector.h> |
---|
15 | | -#include <drm/drm_crtc_helper.h> |
---|
16 | 10 | #include <drm/drm_encoder.h> |
---|
17 | 11 | #include <drm/drm_modeset_helper_vtables.h> |
---|
18 | 12 | #include <drm/drm_panel.h> |
---|
| 13 | +#include <drm/drm_print.h> |
---|
| 14 | +#include <drm/drm_probe_helper.h> |
---|
19 | 15 | |
---|
20 | 16 | struct panel_bridge { |
---|
21 | 17 | struct drm_bridge bridge; |
---|
.. | .. |
---|
41 | 37 | struct panel_bridge *panel_bridge = |
---|
42 | 38 | drm_connector_to_panel_bridge(connector); |
---|
43 | 39 | |
---|
44 | | - return drm_panel_get_modes(panel_bridge->panel); |
---|
| 40 | + return drm_panel_get_modes(panel_bridge->panel, connector); |
---|
45 | 41 | } |
---|
46 | 42 | |
---|
47 | 43 | static const struct drm_connector_helper_funcs |
---|
.. | .. |
---|
57 | 53 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
---|
58 | 54 | }; |
---|
59 | 55 | |
---|
60 | | -static int panel_bridge_attach(struct drm_bridge *bridge) |
---|
| 56 | +static int panel_bridge_attach(struct drm_bridge *bridge, |
---|
| 57 | + enum drm_bridge_attach_flags flags) |
---|
61 | 58 | { |
---|
62 | 59 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
---|
63 | 60 | struct drm_connector *connector = &panel_bridge->connector; |
---|
64 | 61 | int ret; |
---|
| 62 | + |
---|
| 63 | + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) |
---|
| 64 | + return 0; |
---|
65 | 65 | |
---|
66 | 66 | if (!bridge->encoder) { |
---|
67 | 67 | DRM_ERROR("Missing encoder\n"); |
---|
.. | .. |
---|
82 | 82 | drm_connector_attach_encoder(&panel_bridge->connector, |
---|
83 | 83 | bridge->encoder); |
---|
84 | 84 | |
---|
85 | | - ret = drm_panel_attach(panel_bridge->panel, &panel_bridge->connector); |
---|
86 | | - if (ret < 0) |
---|
87 | | - return ret; |
---|
88 | | - |
---|
89 | 85 | return 0; |
---|
90 | 86 | } |
---|
91 | 87 | |
---|
92 | 88 | static void panel_bridge_detach(struct drm_bridge *bridge) |
---|
93 | 89 | { |
---|
94 | 90 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
---|
| 91 | + struct drm_connector *connector = &panel_bridge->connector; |
---|
95 | 92 | |
---|
96 | | - drm_panel_detach(panel_bridge->panel); |
---|
| 93 | + /* |
---|
| 94 | + * Cleanup the connector if we know it was initialized. |
---|
| 95 | + * |
---|
| 96 | + * FIXME: This wouldn't be needed if the panel_bridge structure was |
---|
| 97 | + * allocated with drmm_kzalloc(). This might be tricky since the |
---|
| 98 | + * drm_device pointer can only be retrieved when the bridge is attached. |
---|
| 99 | + */ |
---|
| 100 | + if (connector->dev) |
---|
| 101 | + drm_connector_cleanup(connector); |
---|
97 | 102 | } |
---|
98 | 103 | |
---|
99 | 104 | static void panel_bridge_pre_enable(struct drm_bridge *bridge) |
---|
.. | .. |
---|
124 | 129 | drm_panel_unprepare(panel_bridge->panel); |
---|
125 | 130 | } |
---|
126 | 131 | |
---|
| 132 | +static int panel_bridge_get_modes(struct drm_bridge *bridge, |
---|
| 133 | + struct drm_connector *connector) |
---|
| 134 | +{ |
---|
| 135 | + struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
---|
| 136 | + |
---|
| 137 | + return drm_panel_get_modes(panel_bridge->panel, connector); |
---|
| 138 | +} |
---|
| 139 | + |
---|
127 | 140 | static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { |
---|
128 | 141 | .attach = panel_bridge_attach, |
---|
129 | 142 | .detach = panel_bridge_detach, |
---|
.. | .. |
---|
131 | 144 | .enable = panel_bridge_enable, |
---|
132 | 145 | .disable = panel_bridge_disable, |
---|
133 | 146 | .post_disable = panel_bridge_post_disable, |
---|
| 147 | + .get_modes = panel_bridge_get_modes, |
---|
| 148 | + .atomic_reset = drm_atomic_helper_bridge_reset, |
---|
| 149 | + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, |
---|
| 150 | + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, |
---|
| 151 | + .atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt, |
---|
134 | 152 | }; |
---|
135 | 153 | |
---|
136 | 154 | /** |
---|
137 | | - * drm_panel_bridge_add - Creates a drm_bridge and drm_connector that |
---|
138 | | - * just calls the appropriate functions from drm_panel. |
---|
| 155 | + * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that |
---|
| 156 | + * just calls the appropriate functions from &drm_panel. |
---|
139 | 157 | * |
---|
140 | 158 | * @panel: The drm_panel being wrapped. Must be non-NULL. |
---|
141 | | - * @connector_type: The DRM_MODE_CONNECTOR_* for the connector to be |
---|
142 | | - * created. |
---|
143 | 159 | * |
---|
144 | 160 | * For drivers converting from directly using drm_panel: The expected |
---|
145 | 161 | * usage pattern is that during either encoder module probe or DSI |
---|
.. | .. |
---|
149 | 165 | * passed to drm_bridge_attach(). The drm_panel_prepare() and related |
---|
150 | 166 | * functions can be dropped from the encoder driver (they're now |
---|
151 | 167 | * called by the KMS helpers before calling into the encoder), along |
---|
152 | | - * with connector creation. When done with the bridge, |
---|
153 | | - * drm_bridge_detach() should be called as normal, then |
---|
| 168 | + * with connector creation. When done with the bridge (after |
---|
| 169 | + * drm_mode_config_cleanup() if the bridge has already been attached), then |
---|
154 | 170 | * drm_panel_bridge_remove() to free it. |
---|
| 171 | + * |
---|
| 172 | + * The connector type is set to @panel->connector_type, which must be set to a |
---|
| 173 | + * known type. Calling this function with a panel whose connector type is |
---|
| 174 | + * DRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL). |
---|
| 175 | + * |
---|
| 176 | + * See devm_drm_panel_bridge_add() for an automatically managed version of this |
---|
| 177 | + * function. |
---|
155 | 178 | */ |
---|
156 | | -struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel, |
---|
157 | | - u32 connector_type) |
---|
| 179 | +struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel) |
---|
| 180 | +{ |
---|
| 181 | + if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) |
---|
| 182 | + return ERR_PTR(-EINVAL); |
---|
| 183 | + |
---|
| 184 | + return drm_panel_bridge_add_typed(panel, panel->connector_type); |
---|
| 185 | +} |
---|
| 186 | +EXPORT_SYMBOL(drm_panel_bridge_add); |
---|
| 187 | + |
---|
| 188 | +/** |
---|
| 189 | + * drm_panel_bridge_add_typed - Creates a &drm_bridge and &drm_connector with |
---|
| 190 | + * an explicit connector type. |
---|
| 191 | + * @panel: The drm_panel being wrapped. Must be non-NULL. |
---|
| 192 | + * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) |
---|
| 193 | + * |
---|
| 194 | + * This is just like drm_panel_bridge_add(), but forces the connector type to |
---|
| 195 | + * @connector_type instead of infering it from the panel. |
---|
| 196 | + * |
---|
| 197 | + * This function is deprecated and should not be used in new drivers. Use |
---|
| 198 | + * drm_panel_bridge_add() instead, and fix panel drivers as necessary if they |
---|
| 199 | + * don't report a connector type. |
---|
| 200 | + */ |
---|
| 201 | +struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, |
---|
| 202 | + u32 connector_type) |
---|
158 | 203 | { |
---|
159 | 204 | struct panel_bridge *panel_bridge; |
---|
160 | 205 | |
---|
.. | .. |
---|
173 | 218 | #ifdef CONFIG_OF |
---|
174 | 219 | panel_bridge->bridge.of_node = panel->dev->of_node; |
---|
175 | 220 | #endif |
---|
| 221 | + panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES; |
---|
| 222 | + panel_bridge->bridge.type = connector_type; |
---|
176 | 223 | |
---|
177 | 224 | drm_bridge_add(&panel_bridge->bridge); |
---|
178 | 225 | |
---|
179 | 226 | return &panel_bridge->bridge; |
---|
180 | 227 | } |
---|
181 | | -EXPORT_SYMBOL(drm_panel_bridge_add); |
---|
| 228 | +EXPORT_SYMBOL(drm_panel_bridge_add_typed); |
---|
182 | 229 | |
---|
183 | 230 | /** |
---|
184 | 231 | * drm_panel_bridge_remove - Unregisters and frees a drm_bridge |
---|
.. | .. |
---|
210 | 257 | drm_panel_bridge_remove(*bridge); |
---|
211 | 258 | } |
---|
212 | 259 | |
---|
| 260 | +/** |
---|
| 261 | + * devm_drm_panel_bridge_add - Creates a managed &drm_bridge and &drm_connector |
---|
| 262 | + * that just calls the appropriate functions from &drm_panel. |
---|
| 263 | + * @dev: device to tie the bridge lifetime to |
---|
| 264 | + * @panel: The drm_panel being wrapped. Must be non-NULL. |
---|
| 265 | + * |
---|
| 266 | + * This is the managed version of drm_panel_bridge_add() which automatically |
---|
| 267 | + * calls drm_panel_bridge_remove() when @dev is unbound. |
---|
| 268 | + */ |
---|
213 | 269 | struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, |
---|
214 | | - struct drm_panel *panel, |
---|
215 | | - u32 connector_type) |
---|
| 270 | + struct drm_panel *panel) |
---|
| 271 | +{ |
---|
| 272 | + if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) |
---|
| 273 | + return ERR_PTR(-EINVAL); |
---|
| 274 | + |
---|
| 275 | + return devm_drm_panel_bridge_add_typed(dev, panel, |
---|
| 276 | + panel->connector_type); |
---|
| 277 | +} |
---|
| 278 | +EXPORT_SYMBOL(devm_drm_panel_bridge_add); |
---|
| 279 | + |
---|
| 280 | +/** |
---|
| 281 | + * devm_drm_panel_bridge_add_typed - Creates a managed &drm_bridge and |
---|
| 282 | + * &drm_connector with an explicit connector type. |
---|
| 283 | + * @dev: device to tie the bridge lifetime to |
---|
| 284 | + * @panel: The drm_panel being wrapped. Must be non-NULL. |
---|
| 285 | + * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) |
---|
| 286 | + * |
---|
| 287 | + * This is just like devm_drm_panel_bridge_add(), but forces the connector type |
---|
| 288 | + * to @connector_type instead of infering it from the panel. |
---|
| 289 | + * |
---|
| 290 | + * This function is deprecated and should not be used in new drivers. Use |
---|
| 291 | + * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if |
---|
| 292 | + * they don't report a connector type. |
---|
| 293 | + */ |
---|
| 294 | +struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, |
---|
| 295 | + struct drm_panel *panel, |
---|
| 296 | + u32 connector_type) |
---|
216 | 297 | { |
---|
217 | 298 | struct drm_bridge **ptr, *bridge; |
---|
218 | 299 | |
---|
.. | .. |
---|
221 | 302 | if (!ptr) |
---|
222 | 303 | return ERR_PTR(-ENOMEM); |
---|
223 | 304 | |
---|
224 | | - bridge = drm_panel_bridge_add(panel, connector_type); |
---|
| 305 | + bridge = drm_panel_bridge_add_typed(panel, connector_type); |
---|
225 | 306 | if (!IS_ERR(bridge)) { |
---|
226 | 307 | *ptr = bridge; |
---|
227 | 308 | devres_add(dev, ptr); |
---|
.. | .. |
---|
231 | 312 | |
---|
232 | 313 | return bridge; |
---|
233 | 314 | } |
---|
234 | | -EXPORT_SYMBOL(devm_drm_panel_bridge_add); |
---|
| 315 | +EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed); |
---|
| 316 | + |
---|
| 317 | +/** |
---|
| 318 | + * drm_panel_bridge_connector - return the connector for the panel bridge |
---|
| 319 | + * @bridge: The drm_bridge. |
---|
| 320 | + * |
---|
| 321 | + * drm_panel_bridge creates the connector. |
---|
| 322 | + * This function gives external access to the connector. |
---|
| 323 | + * |
---|
| 324 | + * Returns: Pointer to drm_connector |
---|
| 325 | + */ |
---|
| 326 | +struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge) |
---|
| 327 | +{ |
---|
| 328 | + struct panel_bridge *panel_bridge; |
---|
| 329 | + |
---|
| 330 | + panel_bridge = drm_bridge_to_panel_bridge(bridge); |
---|
| 331 | + |
---|
| 332 | + return &panel_bridge->connector; |
---|
| 333 | +} |
---|
| 334 | +EXPORT_SYMBOL(drm_panel_bridge_connector); |
---|