1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __DRM_OF_H__ 3 #define __DRM_OF_H__ 4 5 #include <linux/err.h> 6 #include <linux/of_graph.h> 7 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 8 #include <linux/of.h> 9 #include <drm/drm_bridge.h> 10 #endif 11 12 struct component_master_ops; 13 struct component_match; 14 struct device; 15 struct drm_device; 16 struct drm_encoder; 17 struct drm_panel; 18 struct drm_bridge; 19 struct device_node; 20 struct mipi_dsi_device_info; 21 struct mipi_dsi_host; 22 23 /** 24 * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection 25 * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated 26 * from the first port, odd pixels from the second port 27 * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated 28 * from the first port, even pixels from the second port 29 */ 30 enum drm_lvds_dual_link_pixels { 31 DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0, 32 DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1, 33 }; 34 35 #ifdef CONFIG_OF 36 uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 37 struct device_node *port); 38 uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 39 struct device_node *port); 40 void drm_of_component_match_add(struct device *master, 41 struct component_match **matchptr, 42 int (*compare)(struct device *, void *), 43 struct device_node *node); 44 int drm_of_component_probe(struct device *dev, 45 int (*compare_of)(struct device *, void *), 46 const struct component_master_ops *m_ops); 47 int drm_of_encoder_active_endpoint(struct device_node *node, 48 struct drm_encoder *encoder, 49 struct of_endpoint *endpoint); 50 int drm_of_find_panel_or_bridge(const struct device_node *np, 51 int port, int endpoint, 52 struct drm_panel **panel, 53 struct drm_bridge **bridge); 54 int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 55 const struct device_node *port2); 56 int drm_of_lvds_get_dual_link_pixel_order_sink(struct device_node *port1, 57 struct device_node *port2); 58 int drm_of_lvds_get_data_mapping(const struct device_node *port); 59 int drm_of_get_data_lanes_count(const struct device_node *endpoint, 60 const unsigned int min, const unsigned int max); 61 int drm_of_get_data_lanes_count_ep(const struct device_node *port, 62 int port_reg, int reg, 63 const unsigned int min, 64 const unsigned int max); 65 int drm_of_get_data_lanes_count_remote(const struct device_node *port, 66 int port_reg, int reg, 67 const unsigned int min, 68 const unsigned int max); 69 #else 70 static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 71 struct device_node *port) 72 { 73 return 0; 74 } 75 76 static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 77 struct device_node *port) 78 { 79 return 0; 80 } 81 82 static inline void 83 drm_of_component_match_add(struct device *master, 84 struct component_match **matchptr, 85 int (*compare)(struct device *, void *), 86 struct device_node *node) 87 { 88 } 89 90 static inline int 91 drm_of_component_probe(struct device *dev, 92 int (*compare_of)(struct device *, void *), 93 const struct component_master_ops *m_ops) 94 { 95 return -EINVAL; 96 } 97 98 static inline int drm_of_encoder_active_endpoint(struct device_node *node, 99 struct drm_encoder *encoder, 100 struct of_endpoint *endpoint) 101 { 102 return -EINVAL; 103 } 104 static inline int drm_of_find_panel_or_bridge(const struct device_node *np, 105 int port, int endpoint, 106 struct drm_panel **panel, 107 struct drm_bridge **bridge) 108 { 109 return -EINVAL; 110 } 111 112 static inline int 113 drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 114 const struct device_node *port2) 115 { 116 return -EINVAL; 117 } 118 119 static inline int 120 drm_of_lvds_get_dual_link_pixel_order_sink(struct device_node *port1, 121 struct device_node *port2) 122 { 123 return -EINVAL; 124 } 125 126 static inline int 127 drm_of_lvds_get_data_mapping(const struct device_node *port) 128 { 129 return -EINVAL; 130 } 131 132 static inline int 133 drm_of_get_data_lanes_count(const struct device_node *endpoint, 134 const unsigned int min, const unsigned int max) 135 { 136 return -EINVAL; 137 } 138 139 static inline int 140 drm_of_get_data_lanes_count_ep(const struct device_node *port, 141 int port_reg, int reg, 142 const unsigned int min, 143 const unsigned int max) 144 { 145 return -EINVAL; 146 } 147 148 static inline int 149 drm_of_get_data_lanes_count_remote(const struct device_node *port, 150 int port_reg, int reg, 151 const unsigned int min, 152 const unsigned int max) 153 { 154 return -EINVAL; 155 } 156 #endif 157 158 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_MIPI_DSI) 159 struct mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev); 160 #else 161 static inline struct 162 mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev) 163 { 164 return ERR_PTR(-EINVAL); 165 } 166 #endif /* CONFIG_OF && CONFIG_DRM_MIPI_DSI */ 167 168 /* 169 * drm_of_panel_bridge_remove - remove panel bridge 170 * @np: device tree node containing panel bridge output ports 171 * 172 * Remove the panel bridge of a given DT node's port and endpoint number 173 * 174 * Returns zero if successful, or one of the standard error codes if it fails. 175 */ 176 static inline int drm_of_panel_bridge_remove(const struct device_node *np, 177 int port, int endpoint) 178 { 179 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 180 struct drm_bridge *bridge; 181 struct device_node *remote; 182 183 remote = of_graph_get_remote_node(np, port, endpoint); 184 if (!remote) 185 return -ENODEV; 186 187 bridge = of_drm_find_and_get_bridge(remote); 188 drm_panel_bridge_remove(bridge); 189 190 drm_bridge_put(bridge); 191 of_node_put(remote); 192 193 return 0; 194 #else 195 return -EINVAL; 196 #endif 197 } 198 199 static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, 200 struct drm_encoder *encoder) 201 { 202 struct of_endpoint endpoint; 203 int ret = drm_of_encoder_active_endpoint(node, encoder, 204 &endpoint); 205 206 return ret ?: endpoint.id; 207 } 208 209 static inline int drm_of_encoder_active_port_id(struct device_node *node, 210 struct drm_encoder *encoder) 211 { 212 struct of_endpoint endpoint; 213 int ret = drm_of_encoder_active_endpoint(node, encoder, 214 &endpoint); 215 216 return ret ?: endpoint.port; 217 } 218 219 #endif /* __DRM_OF_H__ */ 220