1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2df785aa8SLiviu Dudau #include <linux/component.h> 37e435aadSRussell King #include <linux/export.h> 47e435aadSRussell King #include <linux/list.h> 57e435aadSRussell King #include <linux/of_graph.h> 60500c04eSSam Ravnborg 71f2db303SRob Herring #include <drm/drm_bridge.h> 87e435aadSRussell King #include <drm/drm_crtc.h> 90500c04eSSam Ravnborg #include <drm/drm_device.h> 109338203cSLaurent Pinchart #include <drm/drm_encoder.h> 117e435aadSRussell King #include <drm/drm_of.h> 120500c04eSSam Ravnborg #include <drm/drm_panel.h> 137e435aadSRussell King 147f9e7ec9SDaniel Vetter /** 157f9e7ec9SDaniel Vetter * DOC: overview 167f9e7ec9SDaniel Vetter * 177f9e7ec9SDaniel Vetter * A set of helper functions to aid DRM drivers in parsing standard DT 187f9e7ec9SDaniel Vetter * properties. 197f9e7ec9SDaniel Vetter */ 207f9e7ec9SDaniel Vetter 217e435aadSRussell King /** 228b5f7a62SJernej Skrabec * drm_of_crtc_port_mask - find the mask of a registered CRTC by port OF node 237e435aadSRussell King * @dev: DRM device 247e435aadSRussell King * @port: port OF node 257e435aadSRussell King * 267e435aadSRussell King * Given a port OF node, return the possible mask of the corresponding 277e435aadSRussell King * CRTC within a device's list of CRTCs. Returns zero if not found. 287e435aadSRussell King */ 298b5f7a62SJernej Skrabec uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 307e435aadSRussell King struct device_node *port) 317e435aadSRussell King { 327e435aadSRussell King unsigned int index = 0; 337e435aadSRussell King struct drm_crtc *tmp; 347e435aadSRussell King 356295d607SDaniel Vetter drm_for_each_crtc(tmp, dev) { 367e435aadSRussell King if (tmp->port == port) 377e435aadSRussell King return 1 << index; 387e435aadSRussell King 397e435aadSRussell King index++; 407e435aadSRussell King } 417e435aadSRussell King 427e435aadSRussell King return 0; 437e435aadSRussell King } 448b5f7a62SJernej Skrabec EXPORT_SYMBOL(drm_of_crtc_port_mask); 457e435aadSRussell King 467e435aadSRussell King /** 477e435aadSRussell King * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port 487e435aadSRussell King * @dev: DRM device 497e435aadSRussell King * @port: encoder port to scan for endpoints 507e435aadSRussell King * 517e435aadSRussell King * Scan all endpoints attached to a port, locate their attached CRTCs, 527e435aadSRussell King * and generate the DRM mask of CRTCs which may be attached to this 537e435aadSRussell King * encoder. 547e435aadSRussell King * 557e435aadSRussell King * See Documentation/devicetree/bindings/graph.txt for the bindings. 567e435aadSRussell King */ 577e435aadSRussell King uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 587e435aadSRussell King struct device_node *port) 597e435aadSRussell King { 607416f4e3SPhilipp Zabel struct device_node *remote_port, *ep; 617e435aadSRussell King uint32_t possible_crtcs = 0; 627e435aadSRussell King 637416f4e3SPhilipp Zabel for_each_endpoint_of_node(port, ep) { 647e435aadSRussell King remote_port = of_graph_get_remote_port(ep); 657e435aadSRussell King if (!remote_port) { 667e435aadSRussell King of_node_put(ep); 677e435aadSRussell King return 0; 687e435aadSRussell King } 697e435aadSRussell King 708b5f7a62SJernej Skrabec possible_crtcs |= drm_of_crtc_port_mask(dev, remote_port); 717e435aadSRussell King 727e435aadSRussell King of_node_put(remote_port); 737416f4e3SPhilipp Zabel } 747e435aadSRussell King 757e435aadSRussell King return possible_crtcs; 767e435aadSRussell King } 777e435aadSRussell King EXPORT_SYMBOL(drm_of_find_possible_crtcs); 78df785aa8SLiviu Dudau 79df785aa8SLiviu Dudau /** 8097ac0e47SRussell King * drm_of_component_match_add - Add a component helper OF node match rule 8197ac0e47SRussell King * @master: master device 8297ac0e47SRussell King * @matchptr: component match pointer 8397ac0e47SRussell King * @compare: compare function used for matching component 8497ac0e47SRussell King * @node: of_node 8597ac0e47SRussell King */ 8697ac0e47SRussell King void drm_of_component_match_add(struct device *master, 8797ac0e47SRussell King struct component_match **matchptr, 8897ac0e47SRussell King int (*compare)(struct device *, void *), 8997ac0e47SRussell King struct device_node *node) 9097ac0e47SRussell King { 9197ac0e47SRussell King of_node_get(node); 92*ab011ab6SYong Wu component_match_add_release(master, matchptr, component_release_of, 9397ac0e47SRussell King compare, node); 9497ac0e47SRussell King } 9597ac0e47SRussell King EXPORT_SYMBOL_GPL(drm_of_component_match_add); 9697ac0e47SRussell King 9797ac0e47SRussell King /** 98df785aa8SLiviu Dudau * drm_of_component_probe - Generic probe function for a component based master 99df785aa8SLiviu Dudau * @dev: master device containing the OF node 100df785aa8SLiviu Dudau * @compare_of: compare function used for matching components 1017f9e7ec9SDaniel Vetter * @m_ops: component master ops to be used 102df785aa8SLiviu Dudau * 103df785aa8SLiviu Dudau * Parse the platform device OF node and bind all the components associated 104df785aa8SLiviu Dudau * with the master. Interface ports are added before the encoders in order to 105df785aa8SLiviu Dudau * satisfy their .bind requirements 106df785aa8SLiviu Dudau * See Documentation/devicetree/bindings/graph.txt for the bindings. 107df785aa8SLiviu Dudau * 108df785aa8SLiviu Dudau * Returns zero if successful, or one of the standard error codes if it fails. 109df785aa8SLiviu Dudau */ 110df785aa8SLiviu Dudau int drm_of_component_probe(struct device *dev, 111df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 112df785aa8SLiviu Dudau const struct component_master_ops *m_ops) 113df785aa8SLiviu Dudau { 114df785aa8SLiviu Dudau struct device_node *ep, *port, *remote; 115df785aa8SLiviu Dudau struct component_match *match = NULL; 116df785aa8SLiviu Dudau int i; 117df785aa8SLiviu Dudau 118df785aa8SLiviu Dudau if (!dev->of_node) 119df785aa8SLiviu Dudau return -EINVAL; 120df785aa8SLiviu Dudau 121df785aa8SLiviu Dudau /* 122df785aa8SLiviu Dudau * Bind the crtc's ports first, so that drm_of_find_possible_crtcs() 123df785aa8SLiviu Dudau * called from encoder's .bind callbacks works as expected 124df785aa8SLiviu Dudau */ 125df785aa8SLiviu Dudau for (i = 0; ; i++) { 126df785aa8SLiviu Dudau port = of_parse_phandle(dev->of_node, "ports", i); 127df785aa8SLiviu Dudau if (!port) 128df785aa8SLiviu Dudau break; 129df785aa8SLiviu Dudau 1302efa8392SBaruch Siach if (of_device_is_available(port->parent)) 1312efa8392SBaruch Siach drm_of_component_match_add(dev, &match, compare_of, 1322efa8392SBaruch Siach port); 133df785aa8SLiviu Dudau 134df785aa8SLiviu Dudau of_node_put(port); 135df785aa8SLiviu Dudau } 136df785aa8SLiviu Dudau 137df785aa8SLiviu Dudau if (i == 0) { 138df785aa8SLiviu Dudau dev_err(dev, "missing 'ports' property\n"); 139df785aa8SLiviu Dudau return -ENODEV; 140df785aa8SLiviu Dudau } 141df785aa8SLiviu Dudau 142df785aa8SLiviu Dudau if (!match) { 143df785aa8SLiviu Dudau dev_err(dev, "no available port\n"); 144df785aa8SLiviu Dudau return -ENODEV; 145df785aa8SLiviu Dudau } 146df785aa8SLiviu Dudau 147df785aa8SLiviu Dudau /* 148df785aa8SLiviu Dudau * For bound crtcs, bind the encoders attached to their remote endpoint 149df785aa8SLiviu Dudau */ 150df785aa8SLiviu Dudau for (i = 0; ; i++) { 151df785aa8SLiviu Dudau port = of_parse_phandle(dev->of_node, "ports", i); 152df785aa8SLiviu Dudau if (!port) 153df785aa8SLiviu Dudau break; 154df785aa8SLiviu Dudau 155df785aa8SLiviu Dudau if (!of_device_is_available(port->parent)) { 156df785aa8SLiviu Dudau of_node_put(port); 157df785aa8SLiviu Dudau continue; 158df785aa8SLiviu Dudau } 159df785aa8SLiviu Dudau 160df785aa8SLiviu Dudau for_each_child_of_node(port, ep) { 161df785aa8SLiviu Dudau remote = of_graph_get_remote_port_parent(ep); 162df785aa8SLiviu Dudau if (!remote || !of_device_is_available(remote)) { 163df785aa8SLiviu Dudau of_node_put(remote); 164df785aa8SLiviu Dudau continue; 165df785aa8SLiviu Dudau } else if (!of_device_is_available(remote->parent)) { 1664bf99144SRob Herring dev_warn(dev, "parent device of %pOF is not available\n", 1674bf99144SRob Herring remote); 168df785aa8SLiviu Dudau of_node_put(remote); 169df785aa8SLiviu Dudau continue; 170df785aa8SLiviu Dudau } 171df785aa8SLiviu Dudau 17297ac0e47SRussell King drm_of_component_match_add(dev, &match, compare_of, 17397ac0e47SRussell King remote); 174df785aa8SLiviu Dudau of_node_put(remote); 175df785aa8SLiviu Dudau } 176df785aa8SLiviu Dudau of_node_put(port); 177df785aa8SLiviu Dudau } 178df785aa8SLiviu Dudau 179df785aa8SLiviu Dudau return component_master_add_with_match(dev, m_ops, match); 180df785aa8SLiviu Dudau } 181df785aa8SLiviu Dudau EXPORT_SYMBOL(drm_of_component_probe); 1824cacf91fSPhilipp Zabel 1834cacf91fSPhilipp Zabel /* 1844cacf91fSPhilipp Zabel * drm_of_encoder_active_endpoint - return the active encoder endpoint 1854cacf91fSPhilipp Zabel * @node: device tree node containing encoder input ports 1864cacf91fSPhilipp Zabel * @encoder: drm_encoder 1874cacf91fSPhilipp Zabel * 1884cacf91fSPhilipp Zabel * Given an encoder device node and a drm_encoder with a connected crtc, 1894cacf91fSPhilipp Zabel * parse the encoder endpoint connecting to the crtc port. 1904cacf91fSPhilipp Zabel */ 1914cacf91fSPhilipp Zabel int drm_of_encoder_active_endpoint(struct device_node *node, 1924cacf91fSPhilipp Zabel struct drm_encoder *encoder, 1934cacf91fSPhilipp Zabel struct of_endpoint *endpoint) 1944cacf91fSPhilipp Zabel { 1954cacf91fSPhilipp Zabel struct device_node *ep; 1964cacf91fSPhilipp Zabel struct drm_crtc *crtc = encoder->crtc; 1974cacf91fSPhilipp Zabel struct device_node *port; 1984cacf91fSPhilipp Zabel int ret; 1994cacf91fSPhilipp Zabel 2004cacf91fSPhilipp Zabel if (!node || !crtc) 2014cacf91fSPhilipp Zabel return -EINVAL; 2024cacf91fSPhilipp Zabel 2034cacf91fSPhilipp Zabel for_each_endpoint_of_node(node, ep) { 2044cacf91fSPhilipp Zabel port = of_graph_get_remote_port(ep); 2054cacf91fSPhilipp Zabel of_node_put(port); 2064cacf91fSPhilipp Zabel if (port == crtc->port) { 2074cacf91fSPhilipp Zabel ret = of_graph_parse_endpoint(ep, endpoint); 2084cacf91fSPhilipp Zabel of_node_put(ep); 2094cacf91fSPhilipp Zabel return ret; 2104cacf91fSPhilipp Zabel } 2114cacf91fSPhilipp Zabel } 2124cacf91fSPhilipp Zabel 2134cacf91fSPhilipp Zabel return -EINVAL; 2144cacf91fSPhilipp Zabel } 2154cacf91fSPhilipp Zabel EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint); 2161f2db303SRob Herring 2173fbdfe99SDaniel Vetter /** 2181f2db303SRob Herring * drm_of_find_panel_or_bridge - return connected panel or bridge device 2191f2db303SRob Herring * @np: device tree node containing encoder output ports 2203fbdfe99SDaniel Vetter * @port: port in the device tree node 2213fbdfe99SDaniel Vetter * @endpoint: endpoint in the device tree node 2221f2db303SRob Herring * @panel: pointer to hold returned drm_panel 2231f2db303SRob Herring * @bridge: pointer to hold returned drm_bridge 2241f2db303SRob Herring * 2251f2db303SRob Herring * Given a DT node's port and endpoint number, find the connected node and 2261f2db303SRob Herring * return either the associated struct drm_panel or drm_bridge device. Either 2271f2db303SRob Herring * @panel or @bridge must not be NULL. 2281f2db303SRob Herring * 22987ea9580SMaxime Ripard * This function is deprecated and should not be used in new drivers. Use 23087ea9580SMaxime Ripard * devm_drm_of_get_bridge() instead. 23187ea9580SMaxime Ripard * 2321f2db303SRob Herring * Returns zero if successful, or one of the standard error codes if it fails. 2331f2db303SRob Herring */ 2341f2db303SRob Herring int drm_of_find_panel_or_bridge(const struct device_node *np, 2351f2db303SRob Herring int port, int endpoint, 2361f2db303SRob Herring struct drm_panel **panel, 2371f2db303SRob Herring struct drm_bridge **bridge) 2381f2db303SRob Herring { 2391f2db303SRob Herring int ret = -EPROBE_DEFER; 2401f2db303SRob Herring struct device_node *remote; 2411f2db303SRob Herring 2421f2db303SRob Herring if (!panel && !bridge) 2431f2db303SRob Herring return -EINVAL; 244320e421eSDan Carpenter if (panel) 245320e421eSDan Carpenter *panel = NULL; 2461f2db303SRob Herring 247ea5bc3b1SDmitry Osipenko /* 248ea5bc3b1SDmitry Osipenko * of_graph_get_remote_node() produces a noisy error message if port 249ea5bc3b1SDmitry Osipenko * node isn't found and the absence of the port is a legit case here, 250ea5bc3b1SDmitry Osipenko * so at first we silently check whether graph presents in the 251ea5bc3b1SDmitry Osipenko * device-tree node. 252ea5bc3b1SDmitry Osipenko */ 253ea5bc3b1SDmitry Osipenko if (!of_graph_is_present(np)) 254ea5bc3b1SDmitry Osipenko return -ENODEV; 255ea5bc3b1SDmitry Osipenko 2561f2db303SRob Herring remote = of_graph_get_remote_node(np, port, endpoint); 2571f2db303SRob Herring if (!remote) 2581f2db303SRob Herring return -ENODEV; 2591f2db303SRob Herring 2601f2db303SRob Herring if (panel) { 2611f2db303SRob Herring *panel = of_drm_find_panel(remote); 2625fa8e4a2SBoris Brezillon if (!IS_ERR(*panel)) 2631f2db303SRob Herring ret = 0; 2645fa8e4a2SBoris Brezillon else 2655fa8e4a2SBoris Brezillon *panel = NULL; 2661f2db303SRob Herring } 2671f2db303SRob Herring 2681f2db303SRob Herring /* No panel found yet, check for a bridge next. */ 2691f2db303SRob Herring if (bridge) { 2701f2db303SRob Herring if (ret) { 2711f2db303SRob Herring *bridge = of_drm_find_bridge(remote); 2721f2db303SRob Herring if (*bridge) 2731f2db303SRob Herring ret = 0; 2741f2db303SRob Herring } else { 2751f2db303SRob Herring *bridge = NULL; 2761f2db303SRob Herring } 2771f2db303SRob Herring 2781f2db303SRob Herring } 2791f2db303SRob Herring 2801f2db303SRob Herring of_node_put(remote); 2811f2db303SRob Herring return ret; 2821f2db303SRob Herring } 2831f2db303SRob Herring EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge); 28465290075SFabrizio Castro 28565290075SFabrizio Castro enum drm_of_lvds_pixels { 28665290075SFabrizio Castro DRM_OF_LVDS_EVEN = BIT(0), 28765290075SFabrizio Castro DRM_OF_LVDS_ODD = BIT(1), 28865290075SFabrizio Castro }; 28965290075SFabrizio Castro 29065290075SFabrizio Castro static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node) 29165290075SFabrizio Castro { 29265290075SFabrizio Castro bool even_pixels = 29365290075SFabrizio Castro of_property_read_bool(port_node, "dual-lvds-even-pixels"); 29465290075SFabrizio Castro bool odd_pixels = 29565290075SFabrizio Castro of_property_read_bool(port_node, "dual-lvds-odd-pixels"); 29665290075SFabrizio Castro 29765290075SFabrizio Castro return (even_pixels ? DRM_OF_LVDS_EVEN : 0) | 29865290075SFabrizio Castro (odd_pixels ? DRM_OF_LVDS_ODD : 0); 29965290075SFabrizio Castro } 30065290075SFabrizio Castro 30165290075SFabrizio Castro static int drm_of_lvds_get_remote_pixels_type( 30265290075SFabrizio Castro const struct device_node *port_node) 30365290075SFabrizio Castro { 30465290075SFabrizio Castro struct device_node *endpoint = NULL; 30565290075SFabrizio Castro int pixels_type = -EPIPE; 30665290075SFabrizio Castro 30765290075SFabrizio Castro for_each_child_of_node(port_node, endpoint) { 30865290075SFabrizio Castro struct device_node *remote_port; 30965290075SFabrizio Castro int current_pt; 31065290075SFabrizio Castro 31165290075SFabrizio Castro if (!of_node_name_eq(endpoint, "endpoint")) 31265290075SFabrizio Castro continue; 31365290075SFabrizio Castro 31465290075SFabrizio Castro remote_port = of_graph_get_remote_port(endpoint); 31565290075SFabrizio Castro if (!remote_port) { 316b557a5f8SJulia Lawall of_node_put(endpoint); 31765290075SFabrizio Castro return -EPIPE; 31865290075SFabrizio Castro } 31965290075SFabrizio Castro 32065290075SFabrizio Castro current_pt = drm_of_lvds_get_port_pixels_type(remote_port); 32165290075SFabrizio Castro of_node_put(remote_port); 32265290075SFabrizio Castro if (pixels_type < 0) 32365290075SFabrizio Castro pixels_type = current_pt; 32465290075SFabrizio Castro 32565290075SFabrizio Castro /* 32665290075SFabrizio Castro * Sanity check, ensure that all remote endpoints have the same 32765290075SFabrizio Castro * pixel type. We may lift this restriction later if we need to 32865290075SFabrizio Castro * support multiple sinks with different dual-link 32965290075SFabrizio Castro * configurations by passing the endpoints explicitly to 33065290075SFabrizio Castro * drm_of_lvds_get_dual_link_pixel_order(). 33165290075SFabrizio Castro */ 3326f9223a5SSteven Price if (!current_pt || pixels_type != current_pt) { 3336f9223a5SSteven Price of_node_put(endpoint); 33465290075SFabrizio Castro return -EINVAL; 33565290075SFabrizio Castro } 3366f9223a5SSteven Price } 33765290075SFabrizio Castro 33865290075SFabrizio Castro return pixels_type; 33965290075SFabrizio Castro } 34065290075SFabrizio Castro 34165290075SFabrizio Castro /** 34265290075SFabrizio Castro * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order 34365290075SFabrizio Castro * @port1: First DT port node of the Dual-link LVDS source 34465290075SFabrizio Castro * @port2: Second DT port node of the Dual-link LVDS source 34565290075SFabrizio Castro * 34665290075SFabrizio Castro * An LVDS dual-link connection is made of two links, with even pixels 34765290075SFabrizio Castro * transitting on one link, and odd pixels on the other link. This function 34865290075SFabrizio Castro * returns, for two ports of an LVDS dual-link source, which port shall transmit 34965290075SFabrizio Castro * the even and odd pixels, based on the requirements of the connected sink. 35065290075SFabrizio Castro * 35165290075SFabrizio Castro * The pixel order is determined from the dual-lvds-even-pixels and 35265290075SFabrizio Castro * dual-lvds-odd-pixels properties in the sink's DT port nodes. If those 35365290075SFabrizio Castro * properties are not present, or if their usage is not valid, this function 35465290075SFabrizio Castro * returns -EINVAL. 35565290075SFabrizio Castro * 35665290075SFabrizio Castro * If either port is not connected, this function returns -EPIPE. 35765290075SFabrizio Castro * 35865290075SFabrizio Castro * @port1 and @port2 are typically DT sibling nodes, but may have different 35965290075SFabrizio Castro * parents when, for instance, two separate LVDS encoders carry the even and odd 36065290075SFabrizio Castro * pixels. 36165290075SFabrizio Castro * 36265290075SFabrizio Castro * Return: 36365290075SFabrizio Castro * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2 36465290075SFabrizio Castro * carries odd pixels 36565290075SFabrizio Castro * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2 36665290075SFabrizio Castro * carries even pixels 36765290075SFabrizio Castro * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or 36865290075SFabrizio Castro * the sink configuration is invalid 36965290075SFabrizio Castro * * -EPIPE - when @port1 or @port2 are not connected 37065290075SFabrizio Castro */ 37165290075SFabrizio Castro int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 37265290075SFabrizio Castro const struct device_node *port2) 37365290075SFabrizio Castro { 37465290075SFabrizio Castro int remote_p1_pt, remote_p2_pt; 37565290075SFabrizio Castro 37665290075SFabrizio Castro if (!port1 || !port2) 37765290075SFabrizio Castro return -EINVAL; 37865290075SFabrizio Castro 37965290075SFabrizio Castro remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1); 38065290075SFabrizio Castro if (remote_p1_pt < 0) 38165290075SFabrizio Castro return remote_p1_pt; 38265290075SFabrizio Castro 38365290075SFabrizio Castro remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2); 38465290075SFabrizio Castro if (remote_p2_pt < 0) 38565290075SFabrizio Castro return remote_p2_pt; 38665290075SFabrizio Castro 38765290075SFabrizio Castro /* 38865290075SFabrizio Castro * A valid dual-lVDS bus is found when one remote port is marked with 38965290075SFabrizio Castro * "dual-lvds-even-pixels", and the other remote port is marked with 39065290075SFabrizio Castro * "dual-lvds-odd-pixels", bail out if the markers are not right. 39165290075SFabrizio Castro */ 39265290075SFabrizio Castro if (remote_p1_pt + remote_p2_pt != DRM_OF_LVDS_EVEN + DRM_OF_LVDS_ODD) 39365290075SFabrizio Castro return -EINVAL; 39465290075SFabrizio Castro 39565290075SFabrizio Castro return remote_p1_pt == DRM_OF_LVDS_EVEN ? 39665290075SFabrizio Castro DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS : 39765290075SFabrizio Castro DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS; 39865290075SFabrizio Castro } 39965290075SFabrizio Castro EXPORT_SYMBOL_GPL(drm_of_lvds_get_dual_link_pixel_order); 4007c4dd0a2SMarek Vasut 4017c4dd0a2SMarek Vasut /** 4027c4dd0a2SMarek Vasut * drm_of_lvds_get_data_mapping - Get LVDS data mapping 4037c4dd0a2SMarek Vasut * @port: DT port node of the LVDS source or sink 4047c4dd0a2SMarek Vasut * 4057c4dd0a2SMarek Vasut * Convert DT "data-mapping" property string value into media bus format value. 4067c4dd0a2SMarek Vasut * 4077c4dd0a2SMarek Vasut * Return: 4087c4dd0a2SMarek Vasut * * MEDIA_BUS_FMT_RGB666_1X7X3_SPWG - data-mapping is "jeida-18" 4097c4dd0a2SMarek Vasut * * MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA - data-mapping is "jeida-24" 4107c4dd0a2SMarek Vasut * * MEDIA_BUS_FMT_RGB888_1X7X4_SPWG - data-mapping is "vesa-24" 4117c4dd0a2SMarek Vasut * * -EINVAL - the "data-mapping" property is unsupported 4127c4dd0a2SMarek Vasut * * -ENODEV - the "data-mapping" property is missing 4137c4dd0a2SMarek Vasut */ 4147c4dd0a2SMarek Vasut int drm_of_lvds_get_data_mapping(const struct device_node *port) 4157c4dd0a2SMarek Vasut { 4167c4dd0a2SMarek Vasut const char *mapping; 4177c4dd0a2SMarek Vasut int ret; 4187c4dd0a2SMarek Vasut 4197c4dd0a2SMarek Vasut ret = of_property_read_string(port, "data-mapping", &mapping); 4207c4dd0a2SMarek Vasut if (ret < 0) 4217c4dd0a2SMarek Vasut return -ENODEV; 4227c4dd0a2SMarek Vasut 4237c4dd0a2SMarek Vasut if (!strcmp(mapping, "jeida-18")) 4247c4dd0a2SMarek Vasut return MEDIA_BUS_FMT_RGB666_1X7X3_SPWG; 4257c4dd0a2SMarek Vasut if (!strcmp(mapping, "jeida-24")) 4267c4dd0a2SMarek Vasut return MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA; 4277c4dd0a2SMarek Vasut if (!strcmp(mapping, "vesa-24")) 4287c4dd0a2SMarek Vasut return MEDIA_BUS_FMT_RGB888_1X7X4_SPWG; 4297c4dd0a2SMarek Vasut 4307c4dd0a2SMarek Vasut return -EINVAL; 4317c4dd0a2SMarek Vasut } 4327c4dd0a2SMarek Vasut EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping); 433