1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/ 4 * Author: Archit Taneja <archit@ti.com> 5 */ 6 7 #include <linux/kernel.h> 8 #include <linux/module.h> 9 #include <linux/platform_device.h> 10 #include <linux/slab.h> 11 #include <linux/of.h> 12 #include <linux/of_graph.h> 13 14 #include <drm/drm_bridge.h> 15 #include <drm/drm_panel.h> 16 17 #include "dss.h" 18 #include "omapdss.h" 19 20 int omapdss_device_init_output(struct omap_dss_device *out, 21 struct drm_bridge *local_bridge) 22 { 23 struct device_node *remote_node; 24 int ret; 25 26 remote_node = of_graph_get_remote_node(out->dev->of_node, 27 out->of_port, 0); 28 if (!remote_node) { 29 dev_dbg(out->dev, "failed to find video sink\n"); 30 return 0; 31 } 32 33 out->panel = of_drm_find_panel(remote_node); 34 if (IS_ERR(out->panel)) 35 out->panel = NULL; 36 37 if (!out->panel) 38 out->bridge = of_drm_find_and_get_bridge(remote_node); 39 40 of_node_put(remote_node); 41 42 if (out->panel) { 43 struct drm_bridge *bridge; 44 45 bridge = drm_panel_bridge_add(out->panel); 46 if (IS_ERR(bridge)) { 47 dev_err(out->dev, 48 "unable to create panel bridge (%ld)\n", 49 PTR_ERR(bridge)); 50 ret = PTR_ERR(bridge); 51 goto error; 52 } 53 54 out->bridge = drm_bridge_get(bridge); 55 } 56 57 if (local_bridge) { 58 if (!out->bridge) { 59 ret = -EPROBE_DEFER; 60 goto error; 61 } 62 63 out->next_bridge = out->bridge; 64 out->bridge = drm_bridge_get(local_bridge); 65 } 66 67 if (!out->bridge) { 68 ret = -EPROBE_DEFER; 69 goto error; 70 } 71 72 return 0; 73 74 error: 75 omapdss_device_cleanup_output(out); 76 return ret; 77 } 78 79 void omapdss_device_cleanup_output(struct omap_dss_device *out) 80 { 81 if (out->bridge && out->panel) 82 drm_panel_bridge_remove(out->next_bridge ? 83 out->next_bridge : out->bridge); 84 85 drm_bridge_put(out->next_bridge); 86 drm_bridge_put(out->bridge); 87 } 88 89 void dss_mgr_set_timings(struct omap_dss_device *dssdev, 90 const struct videomode *vm) 91 { 92 omap_crtc_dss_set_timings(dssdev->dss->mgr_ops_priv, 93 dssdev->dispc_channel, vm); 94 } 95 96 void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev, 97 const struct dss_lcd_mgr_config *config) 98 { 99 omap_crtc_dss_set_lcd_config(dssdev->dss->mgr_ops_priv, 100 dssdev->dispc_channel, config); 101 } 102 103 int dss_mgr_enable(struct omap_dss_device *dssdev) 104 { 105 return omap_crtc_dss_enable(dssdev->dss->mgr_ops_priv, 106 dssdev->dispc_channel); 107 } 108 109 void dss_mgr_disable(struct omap_dss_device *dssdev) 110 { 111 omap_crtc_dss_disable(dssdev->dss->mgr_ops_priv, 112 dssdev->dispc_channel); 113 } 114 115 void dss_mgr_start_update(struct omap_dss_device *dssdev) 116 { 117 omap_crtc_dss_start_update(dssdev->dss->mgr_ops_priv, 118 dssdev->dispc_channel); 119 } 120 121 int dss_mgr_register_framedone_handler(struct omap_dss_device *dssdev, 122 void (*handler)(void *), void *data) 123 { 124 struct dss_device *dss = dssdev->dss; 125 126 return omap_crtc_dss_register_framedone(dss->mgr_ops_priv, 127 dssdev->dispc_channel, 128 handler, data); 129 } 130 131 void dss_mgr_unregister_framedone_handler(struct omap_dss_device *dssdev, 132 void (*handler)(void *), void *data) 133 { 134 struct dss_device *dss = dssdev->dss; 135 136 omap_crtc_dss_unregister_framedone(dss->mgr_ops_priv, 137 dssdev->dispc_channel, 138 handler, data); 139 } 140