1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Freescale i.MX drm driver 4 * 5 * bridge driver for legacy DT bindings, utilizing display-timings node 6 */ 7 8 #include <drm/drm_bridge.h> 9 #include <drm/drm_modes.h> 10 #include <drm/drm_probe_helper.h> 11 #include <drm/bridge/imx.h> 12 13 #include <video/of_display_timing.h> 14 #include <video/of_videomode.h> 15 16 struct imx_legacy_bridge { 17 struct drm_bridge base; 18 19 struct drm_display_mode mode; 20 u32 bus_flags; 21 }; 22 23 #define to_imx_legacy_bridge(bridge) container_of(bridge, struct imx_legacy_bridge, base) 24 25 static int imx_legacy_bridge_attach(struct drm_bridge *bridge, 26 enum drm_bridge_attach_flags flags) 27 { 28 if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) 29 return -EINVAL; 30 31 return 0; 32 } 33 34 static int imx_legacy_bridge_get_modes(struct drm_bridge *bridge, 35 struct drm_connector *connector) 36 { 37 struct imx_legacy_bridge *imx_bridge = to_imx_legacy_bridge(bridge); 38 int ret; 39 40 ret = drm_connector_helper_get_modes_fixed(connector, &imx_bridge->mode); 41 if (ret) 42 return ret; 43 44 connector->display_info.bus_flags = imx_bridge->bus_flags; 45 46 return 0; 47 } 48 49 struct drm_bridge_funcs imx_legacy_bridge_funcs = { 50 .attach = imx_legacy_bridge_attach, 51 .get_modes = imx_legacy_bridge_get_modes, 52 }; 53 54 struct drm_bridge *devm_imx_drm_legacy_bridge(struct device *dev, 55 struct device_node *np, 56 int type) 57 { 58 struct imx_legacy_bridge *imx_bridge; 59 int ret; 60 61 imx_bridge = devm_kzalloc(dev, sizeof(*imx_bridge), GFP_KERNEL); 62 if (!imx_bridge) 63 return ERR_PTR(-ENOMEM); 64 65 ret = of_get_drm_display_mode(np, 66 &imx_bridge->mode, 67 &imx_bridge->bus_flags, 68 OF_USE_NATIVE_MODE); 69 if (ret) 70 return ERR_PTR(ret); 71 72 imx_bridge->mode.type |= DRM_MODE_TYPE_DRIVER; 73 74 imx_bridge->base.funcs = &imx_legacy_bridge_funcs; 75 imx_bridge->base.of_node = np; 76 imx_bridge->base.ops = DRM_BRIDGE_OP_MODES; 77 imx_bridge->base.type = type; 78 79 ret = devm_drm_bridge_add(dev, &imx_bridge->base); 80 if (ret) 81 return ERR_PTR(ret); 82 83 return &imx_bridge->base; 84 } 85 EXPORT_SYMBOL_GPL(devm_imx_drm_legacy_bridge); 86 87 MODULE_LICENSE("GPL"); 88 MODULE_DESCRIPTION("Freescale i.MX DRM bridge driver for legacy DT bindings"); 89