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 2197ac0e47SRussell King static void drm_release_of(struct device *dev, void *data) 2297ac0e47SRussell King { 2397ac0e47SRussell King of_node_put(data); 2497ac0e47SRussell King } 2597ac0e47SRussell King 267e435aadSRussell King /** 278b5f7a62SJernej Skrabec * drm_of_crtc_port_mask - find the mask of a registered CRTC by port OF node 287e435aadSRussell King * @dev: DRM device 297e435aadSRussell King * @port: port OF node 307e435aadSRussell King * 317e435aadSRussell King * Given a port OF node, return the possible mask of the corresponding 327e435aadSRussell King * CRTC within a device's list of CRTCs. Returns zero if not found. 337e435aadSRussell King */ 348b5f7a62SJernej Skrabec uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 357e435aadSRussell King struct device_node *port) 367e435aadSRussell King { 377e435aadSRussell King unsigned int index = 0; 387e435aadSRussell King struct drm_crtc *tmp; 397e435aadSRussell King 406295d607SDaniel Vetter drm_for_each_crtc(tmp, dev) { 417e435aadSRussell King if (tmp->port == port) 427e435aadSRussell King return 1 << index; 437e435aadSRussell King 447e435aadSRussell King index++; 457e435aadSRussell King } 467e435aadSRussell King 477e435aadSRussell King return 0; 487e435aadSRussell King } 498b5f7a62SJernej Skrabec EXPORT_SYMBOL(drm_of_crtc_port_mask); 507e435aadSRussell King 517e435aadSRussell King /** 527e435aadSRussell King * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port 537e435aadSRussell King * @dev: DRM device 547e435aadSRussell King * @port: encoder port to scan for endpoints 557e435aadSRussell King * 567e435aadSRussell King * Scan all endpoints attached to a port, locate their attached CRTCs, 577e435aadSRussell King * and generate the DRM mask of CRTCs which may be attached to this 587e435aadSRussell King * encoder. 597e435aadSRussell King * 607e435aadSRussell King * See Documentation/devicetree/bindings/graph.txt for the bindings. 617e435aadSRussell King */ 627e435aadSRussell King uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 637e435aadSRussell King struct device_node *port) 647e435aadSRussell King { 657416f4e3SPhilipp Zabel struct device_node *remote_port, *ep; 667e435aadSRussell King uint32_t possible_crtcs = 0; 677e435aadSRussell King 687416f4e3SPhilipp Zabel for_each_endpoint_of_node(port, ep) { 697e435aadSRussell King remote_port = of_graph_get_remote_port(ep); 707e435aadSRussell King if (!remote_port) { 717e435aadSRussell King of_node_put(ep); 727e435aadSRussell King return 0; 737e435aadSRussell King } 747e435aadSRussell King 758b5f7a62SJernej Skrabec possible_crtcs |= drm_of_crtc_port_mask(dev, remote_port); 767e435aadSRussell King 777e435aadSRussell King of_node_put(remote_port); 787416f4e3SPhilipp Zabel } 797e435aadSRussell King 807e435aadSRussell King return possible_crtcs; 817e435aadSRussell King } 827e435aadSRussell King EXPORT_SYMBOL(drm_of_find_possible_crtcs); 83df785aa8SLiviu Dudau 84df785aa8SLiviu Dudau /** 8597ac0e47SRussell King * drm_of_component_match_add - Add a component helper OF node match rule 8697ac0e47SRussell King * @master: master device 8797ac0e47SRussell King * @matchptr: component match pointer 8897ac0e47SRussell King * @compare: compare function used for matching component 8997ac0e47SRussell King * @node: of_node 9097ac0e47SRussell King */ 9197ac0e47SRussell King void drm_of_component_match_add(struct device *master, 9297ac0e47SRussell King struct component_match **matchptr, 9397ac0e47SRussell King int (*compare)(struct device *, void *), 9497ac0e47SRussell King struct device_node *node) 9597ac0e47SRussell King { 9697ac0e47SRussell King of_node_get(node); 9797ac0e47SRussell King component_match_add_release(master, matchptr, drm_release_of, 9897ac0e47SRussell King compare, node); 9997ac0e47SRussell King } 10097ac0e47SRussell King EXPORT_SYMBOL_GPL(drm_of_component_match_add); 10197ac0e47SRussell King 10297ac0e47SRussell King /** 103df785aa8SLiviu Dudau * drm_of_component_probe - Generic probe function for a component based master 104df785aa8SLiviu Dudau * @dev: master device containing the OF node 105df785aa8SLiviu Dudau * @compare_of: compare function used for matching components 1067f9e7ec9SDaniel Vetter * @m_ops: component master ops to be used 107df785aa8SLiviu Dudau * 108df785aa8SLiviu Dudau * Parse the platform device OF node and bind all the components associated 109df785aa8SLiviu Dudau * with the master. Interface ports are added before the encoders in order to 110df785aa8SLiviu Dudau * satisfy their .bind requirements 111df785aa8SLiviu Dudau * See Documentation/devicetree/bindings/graph.txt for the bindings. 112df785aa8SLiviu Dudau * 113df785aa8SLiviu Dudau * Returns zero if successful, or one of the standard error codes if it fails. 114df785aa8SLiviu Dudau */ 115df785aa8SLiviu Dudau int drm_of_component_probe(struct device *dev, 116df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 117df785aa8SLiviu Dudau const struct component_master_ops *m_ops) 118df785aa8SLiviu Dudau { 119df785aa8SLiviu Dudau struct device_node *ep, *port, *remote; 120df785aa8SLiviu Dudau struct component_match *match = NULL; 121df785aa8SLiviu Dudau int i; 122df785aa8SLiviu Dudau 123df785aa8SLiviu Dudau if (!dev->of_node) 124df785aa8SLiviu Dudau return -EINVAL; 125df785aa8SLiviu Dudau 126df785aa8SLiviu Dudau /* 127df785aa8SLiviu Dudau * Bind the crtc's ports first, so that drm_of_find_possible_crtcs() 128df785aa8SLiviu Dudau * called from encoder's .bind callbacks works as expected 129df785aa8SLiviu Dudau */ 130df785aa8SLiviu Dudau for (i = 0; ; i++) { 131df785aa8SLiviu Dudau port = of_parse_phandle(dev->of_node, "ports", i); 132df785aa8SLiviu Dudau if (!port) 133df785aa8SLiviu Dudau break; 134df785aa8SLiviu Dudau 1352efa8392SBaruch Siach if (of_device_is_available(port->parent)) 1362efa8392SBaruch Siach drm_of_component_match_add(dev, &match, compare_of, 1372efa8392SBaruch Siach port); 138df785aa8SLiviu Dudau 139df785aa8SLiviu Dudau of_node_put(port); 140df785aa8SLiviu Dudau } 141df785aa8SLiviu Dudau 142df785aa8SLiviu Dudau if (i == 0) { 143df785aa8SLiviu Dudau dev_err(dev, "missing 'ports' property\n"); 144df785aa8SLiviu Dudau return -ENODEV; 145df785aa8SLiviu Dudau } 146df785aa8SLiviu Dudau 147df785aa8SLiviu Dudau if (!match) { 148df785aa8SLiviu Dudau dev_err(dev, "no available port\n"); 149df785aa8SLiviu Dudau return -ENODEV; 150df785aa8SLiviu Dudau } 151df785aa8SLiviu Dudau 152df785aa8SLiviu Dudau /* 153df785aa8SLiviu Dudau * For bound crtcs, bind the encoders attached to their remote endpoint 154df785aa8SLiviu Dudau */ 155df785aa8SLiviu Dudau for (i = 0; ; i++) { 156df785aa8SLiviu Dudau port = of_parse_phandle(dev->of_node, "ports", i); 157df785aa8SLiviu Dudau if (!port) 158df785aa8SLiviu Dudau break; 159df785aa8SLiviu Dudau 160df785aa8SLiviu Dudau if (!of_device_is_available(port->parent)) { 161df785aa8SLiviu Dudau of_node_put(port); 162df785aa8SLiviu Dudau continue; 163df785aa8SLiviu Dudau } 164df785aa8SLiviu Dudau 165df785aa8SLiviu Dudau for_each_child_of_node(port, ep) { 166df785aa8SLiviu Dudau remote = of_graph_get_remote_port_parent(ep); 167df785aa8SLiviu Dudau if (!remote || !of_device_is_available(remote)) { 168df785aa8SLiviu Dudau of_node_put(remote); 169df785aa8SLiviu Dudau continue; 170df785aa8SLiviu Dudau } else if (!of_device_is_available(remote->parent)) { 1714bf99144SRob Herring dev_warn(dev, "parent device of %pOF is not available\n", 1724bf99144SRob Herring remote); 173df785aa8SLiviu Dudau of_node_put(remote); 174df785aa8SLiviu Dudau continue; 175df785aa8SLiviu Dudau } 176df785aa8SLiviu Dudau 17797ac0e47SRussell King drm_of_component_match_add(dev, &match, compare_of, 17897ac0e47SRussell King remote); 179df785aa8SLiviu Dudau of_node_put(remote); 180df785aa8SLiviu Dudau } 181df785aa8SLiviu Dudau of_node_put(port); 182df785aa8SLiviu Dudau } 183df785aa8SLiviu Dudau 184df785aa8SLiviu Dudau return component_master_add_with_match(dev, m_ops, match); 185df785aa8SLiviu Dudau } 186df785aa8SLiviu Dudau EXPORT_SYMBOL(drm_of_component_probe); 1874cacf91fSPhilipp Zabel 1884cacf91fSPhilipp Zabel /* 1894cacf91fSPhilipp Zabel * drm_of_encoder_active_endpoint - return the active encoder endpoint 1904cacf91fSPhilipp Zabel * @node: device tree node containing encoder input ports 1914cacf91fSPhilipp Zabel * @encoder: drm_encoder 1924cacf91fSPhilipp Zabel * 1934cacf91fSPhilipp Zabel * Given an encoder device node and a drm_encoder with a connected crtc, 1944cacf91fSPhilipp Zabel * parse the encoder endpoint connecting to the crtc port. 1954cacf91fSPhilipp Zabel */ 1964cacf91fSPhilipp Zabel int drm_of_encoder_active_endpoint(struct device_node *node, 1974cacf91fSPhilipp Zabel struct drm_encoder *encoder, 1984cacf91fSPhilipp Zabel struct of_endpoint *endpoint) 1994cacf91fSPhilipp Zabel { 2004cacf91fSPhilipp Zabel struct device_node *ep; 2014cacf91fSPhilipp Zabel struct drm_crtc *crtc = encoder->crtc; 2024cacf91fSPhilipp Zabel struct device_node *port; 2034cacf91fSPhilipp Zabel int ret; 2044cacf91fSPhilipp Zabel 2054cacf91fSPhilipp Zabel if (!node || !crtc) 2064cacf91fSPhilipp Zabel return -EINVAL; 2074cacf91fSPhilipp Zabel 2084cacf91fSPhilipp Zabel for_each_endpoint_of_node(node, ep) { 2094cacf91fSPhilipp Zabel port = of_graph_get_remote_port(ep); 2104cacf91fSPhilipp Zabel of_node_put(port); 2114cacf91fSPhilipp Zabel if (port == crtc->port) { 2124cacf91fSPhilipp Zabel ret = of_graph_parse_endpoint(ep, endpoint); 2134cacf91fSPhilipp Zabel of_node_put(ep); 2144cacf91fSPhilipp Zabel return ret; 2154cacf91fSPhilipp Zabel } 2164cacf91fSPhilipp Zabel } 2174cacf91fSPhilipp Zabel 2184cacf91fSPhilipp Zabel return -EINVAL; 2194cacf91fSPhilipp Zabel } 2204cacf91fSPhilipp Zabel EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint); 2211f2db303SRob Herring 2223fbdfe99SDaniel Vetter /** 2231f2db303SRob Herring * drm_of_find_panel_or_bridge - return connected panel or bridge device 2241f2db303SRob Herring * @np: device tree node containing encoder output ports 2253fbdfe99SDaniel Vetter * @port: port in the device tree node 2263fbdfe99SDaniel Vetter * @endpoint: endpoint in the device tree node 2271f2db303SRob Herring * @panel: pointer to hold returned drm_panel 2281f2db303SRob Herring * @bridge: pointer to hold returned drm_bridge 2291f2db303SRob Herring * 2301f2db303SRob Herring * Given a DT node's port and endpoint number, find the connected node and 2311f2db303SRob Herring * return either the associated struct drm_panel or drm_bridge device. Either 2321f2db303SRob Herring * @panel or @bridge must not be NULL. 2331f2db303SRob Herring * 23487ea9580SMaxime Ripard * This function is deprecated and should not be used in new drivers. Use 23587ea9580SMaxime Ripard * devm_drm_of_get_bridge() instead. 23687ea9580SMaxime Ripard * 2371f2db303SRob Herring * Returns zero if successful, or one of the standard error codes if it fails. 2381f2db303SRob Herring */ 2391f2db303SRob Herring int drm_of_find_panel_or_bridge(const struct device_node *np, 2401f2db303SRob Herring int port, int endpoint, 2411f2db303SRob Herring struct drm_panel **panel, 2421f2db303SRob Herring struct drm_bridge **bridge) 2431f2db303SRob Herring { 2441f2db303SRob Herring int ret = -EPROBE_DEFER; 2451f2db303SRob Herring struct device_node *remote; 2461f2db303SRob Herring 2471f2db303SRob Herring if (!panel && !bridge) 2481f2db303SRob Herring return -EINVAL; 249320e421eSDan Carpenter if (panel) 250320e421eSDan Carpenter *panel = NULL; 2511f2db303SRob Herring 252ea5bc3b1SDmitry Osipenko /* 253ea5bc3b1SDmitry Osipenko * of_graph_get_remote_node() produces a noisy error message if port 254ea5bc3b1SDmitry Osipenko * node isn't found and the absence of the port is a legit case here, 255ea5bc3b1SDmitry Osipenko * so at first we silently check whether graph presents in the 256ea5bc3b1SDmitry Osipenko * device-tree node. 257ea5bc3b1SDmitry Osipenko */ 258ea5bc3b1SDmitry Osipenko if (!of_graph_is_present(np)) 259ea5bc3b1SDmitry Osipenko return -ENODEV; 260ea5bc3b1SDmitry Osipenko 2611f2db303SRob Herring remote = of_graph_get_remote_node(np, port, endpoint); 2621f2db303SRob Herring if (!remote) 2631f2db303SRob Herring return -ENODEV; 2641f2db303SRob Herring 2651f2db303SRob Herring if (panel) { 2661f2db303SRob Herring *panel = of_drm_find_panel(remote); 2675fa8e4a2SBoris Brezillon if (!IS_ERR(*panel)) 2681f2db303SRob Herring ret = 0; 2695fa8e4a2SBoris Brezillon else 2705fa8e4a2SBoris Brezillon *panel = NULL; 2711f2db303SRob Herring } 2721f2db303SRob Herring 2731f2db303SRob Herring /* No panel found yet, check for a bridge next. */ 2741f2db303SRob Herring if (bridge) { 2751f2db303SRob Herring if (ret) { 2761f2db303SRob Herring *bridge = of_drm_find_bridge(remote); 2771f2db303SRob Herring if (*bridge) 2781f2db303SRob Herring ret = 0; 2791f2db303SRob Herring } else { 2801f2db303SRob Herring *bridge = NULL; 2811f2db303SRob Herring } 2821f2db303SRob Herring 2831f2db303SRob Herring } 2841f2db303SRob Herring 2851f2db303SRob Herring of_node_put(remote); 2861f2db303SRob Herring return ret; 2871f2db303SRob Herring } 2881f2db303SRob Herring EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge); 28965290075SFabrizio Castro 29065290075SFabrizio Castro enum drm_of_lvds_pixels { 29165290075SFabrizio Castro DRM_OF_LVDS_EVEN = BIT(0), 29265290075SFabrizio Castro DRM_OF_LVDS_ODD = BIT(1), 29365290075SFabrizio Castro }; 29465290075SFabrizio Castro 29565290075SFabrizio Castro static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node) 29665290075SFabrizio Castro { 29765290075SFabrizio Castro bool even_pixels = 29865290075SFabrizio Castro of_property_read_bool(port_node, "dual-lvds-even-pixels"); 29965290075SFabrizio Castro bool odd_pixels = 30065290075SFabrizio Castro of_property_read_bool(port_node, "dual-lvds-odd-pixels"); 30165290075SFabrizio Castro 30265290075SFabrizio Castro return (even_pixels ? DRM_OF_LVDS_EVEN : 0) | 30365290075SFabrizio Castro (odd_pixels ? DRM_OF_LVDS_ODD : 0); 30465290075SFabrizio Castro } 30565290075SFabrizio Castro 30665290075SFabrizio Castro static int drm_of_lvds_get_remote_pixels_type( 30765290075SFabrizio Castro const struct device_node *port_node) 30865290075SFabrizio Castro { 30965290075SFabrizio Castro struct device_node *endpoint = NULL; 31065290075SFabrizio Castro int pixels_type = -EPIPE; 31165290075SFabrizio Castro 31265290075SFabrizio Castro for_each_child_of_node(port_node, endpoint) { 31365290075SFabrizio Castro struct device_node *remote_port; 31465290075SFabrizio Castro int current_pt; 31565290075SFabrizio Castro 31665290075SFabrizio Castro if (!of_node_name_eq(endpoint, "endpoint")) 31765290075SFabrizio Castro continue; 31865290075SFabrizio Castro 31965290075SFabrizio Castro remote_port = of_graph_get_remote_port(endpoint); 32065290075SFabrizio Castro if (!remote_port) { 321b557a5f8SJulia Lawall of_node_put(endpoint); 32265290075SFabrizio Castro return -EPIPE; 32365290075SFabrizio Castro } 32465290075SFabrizio Castro 32565290075SFabrizio Castro current_pt = drm_of_lvds_get_port_pixels_type(remote_port); 32665290075SFabrizio Castro of_node_put(remote_port); 32765290075SFabrizio Castro if (pixels_type < 0) 32865290075SFabrizio Castro pixels_type = current_pt; 32965290075SFabrizio Castro 33065290075SFabrizio Castro /* 33165290075SFabrizio Castro * Sanity check, ensure that all remote endpoints have the same 33265290075SFabrizio Castro * pixel type. We may lift this restriction later if we need to 33365290075SFabrizio Castro * support multiple sinks with different dual-link 33465290075SFabrizio Castro * configurations by passing the endpoints explicitly to 33565290075SFabrizio Castro * drm_of_lvds_get_dual_link_pixel_order(). 33665290075SFabrizio Castro */ 3376f9223a5SSteven Price if (!current_pt || pixels_type != current_pt) { 3386f9223a5SSteven Price of_node_put(endpoint); 33965290075SFabrizio Castro return -EINVAL; 34065290075SFabrizio Castro } 3416f9223a5SSteven Price } 34265290075SFabrizio Castro 34365290075SFabrizio Castro return pixels_type; 34465290075SFabrizio Castro } 34565290075SFabrizio Castro 34665290075SFabrizio Castro /** 34765290075SFabrizio Castro * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order 34865290075SFabrizio Castro * @port1: First DT port node of the Dual-link LVDS source 34965290075SFabrizio Castro * @port2: Second DT port node of the Dual-link LVDS source 35065290075SFabrizio Castro * 35165290075SFabrizio Castro * An LVDS dual-link connection is made of two links, with even pixels 35265290075SFabrizio Castro * transitting on one link, and odd pixels on the other link. This function 35365290075SFabrizio Castro * returns, for two ports of an LVDS dual-link source, which port shall transmit 35465290075SFabrizio Castro * the even and odd pixels, based on the requirements of the connected sink. 35565290075SFabrizio Castro * 35665290075SFabrizio Castro * The pixel order is determined from the dual-lvds-even-pixels and 35765290075SFabrizio Castro * dual-lvds-odd-pixels properties in the sink's DT port nodes. If those 35865290075SFabrizio Castro * properties are not present, or if their usage is not valid, this function 35965290075SFabrizio Castro * returns -EINVAL. 36065290075SFabrizio Castro * 36165290075SFabrizio Castro * If either port is not connected, this function returns -EPIPE. 36265290075SFabrizio Castro * 36365290075SFabrizio Castro * @port1 and @port2 are typically DT sibling nodes, but may have different 36465290075SFabrizio Castro * parents when, for instance, two separate LVDS encoders carry the even and odd 36565290075SFabrizio Castro * pixels. 36665290075SFabrizio Castro * 36765290075SFabrizio Castro * Return: 36865290075SFabrizio Castro * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2 36965290075SFabrizio Castro * carries odd pixels 37065290075SFabrizio Castro * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2 37165290075SFabrizio Castro * carries even pixels 37265290075SFabrizio Castro * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or 37365290075SFabrizio Castro * the sink configuration is invalid 37465290075SFabrizio Castro * * -EPIPE - when @port1 or @port2 are not connected 37565290075SFabrizio Castro */ 37665290075SFabrizio Castro int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 37765290075SFabrizio Castro const struct device_node *port2) 37865290075SFabrizio Castro { 37965290075SFabrizio Castro int remote_p1_pt, remote_p2_pt; 38065290075SFabrizio Castro 38165290075SFabrizio Castro if (!port1 || !port2) 38265290075SFabrizio Castro return -EINVAL; 38365290075SFabrizio Castro 38465290075SFabrizio Castro remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1); 38565290075SFabrizio Castro if (remote_p1_pt < 0) 38665290075SFabrizio Castro return remote_p1_pt; 38765290075SFabrizio Castro 38865290075SFabrizio Castro remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2); 38965290075SFabrizio Castro if (remote_p2_pt < 0) 39065290075SFabrizio Castro return remote_p2_pt; 39165290075SFabrizio Castro 39265290075SFabrizio Castro /* 39365290075SFabrizio Castro * A valid dual-lVDS bus is found when one remote port is marked with 39465290075SFabrizio Castro * "dual-lvds-even-pixels", and the other remote port is marked with 39565290075SFabrizio Castro * "dual-lvds-odd-pixels", bail out if the markers are not right. 39665290075SFabrizio Castro */ 39765290075SFabrizio Castro if (remote_p1_pt + remote_p2_pt != DRM_OF_LVDS_EVEN + DRM_OF_LVDS_ODD) 39865290075SFabrizio Castro return -EINVAL; 39965290075SFabrizio Castro 40065290075SFabrizio Castro return remote_p1_pt == DRM_OF_LVDS_EVEN ? 40165290075SFabrizio Castro DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS : 40265290075SFabrizio Castro DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS; 40365290075SFabrizio Castro } 40465290075SFabrizio Castro EXPORT_SYMBOL_GPL(drm_of_lvds_get_dual_link_pixel_order); 405*7c4dd0a2SMarek Vasut 406*7c4dd0a2SMarek Vasut /** 407*7c4dd0a2SMarek Vasut * drm_of_lvds_get_data_mapping - Get LVDS data mapping 408*7c4dd0a2SMarek Vasut * @port: DT port node of the LVDS source or sink 409*7c4dd0a2SMarek Vasut * 410*7c4dd0a2SMarek Vasut * Convert DT "data-mapping" property string value into media bus format value. 411*7c4dd0a2SMarek Vasut * 412*7c4dd0a2SMarek Vasut * Return: 413*7c4dd0a2SMarek Vasut * * MEDIA_BUS_FMT_RGB666_1X7X3_SPWG - data-mapping is "jeida-18" 414*7c4dd0a2SMarek Vasut * * MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA - data-mapping is "jeida-24" 415*7c4dd0a2SMarek Vasut * * MEDIA_BUS_FMT_RGB888_1X7X4_SPWG - data-mapping is "vesa-24" 416*7c4dd0a2SMarek Vasut * * -EINVAL - the "data-mapping" property is unsupported 417*7c4dd0a2SMarek Vasut * * -ENODEV - the "data-mapping" property is missing 418*7c4dd0a2SMarek Vasut */ 419*7c4dd0a2SMarek Vasut int drm_of_lvds_get_data_mapping(const struct device_node *port) 420*7c4dd0a2SMarek Vasut { 421*7c4dd0a2SMarek Vasut const char *mapping; 422*7c4dd0a2SMarek Vasut int ret; 423*7c4dd0a2SMarek Vasut 424*7c4dd0a2SMarek Vasut ret = of_property_read_string(port, "data-mapping", &mapping); 425*7c4dd0a2SMarek Vasut if (ret < 0) 426*7c4dd0a2SMarek Vasut return -ENODEV; 427*7c4dd0a2SMarek Vasut 428*7c4dd0a2SMarek Vasut if (!strcmp(mapping, "jeida-18")) 429*7c4dd0a2SMarek Vasut return MEDIA_BUS_FMT_RGB666_1X7X3_SPWG; 430*7c4dd0a2SMarek Vasut if (!strcmp(mapping, "jeida-24")) 431*7c4dd0a2SMarek Vasut return MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA; 432*7c4dd0a2SMarek Vasut if (!strcmp(mapping, "vesa-24")) 433*7c4dd0a2SMarek Vasut return MEDIA_BUS_FMT_RGB888_1X7X4_SPWG; 434*7c4dd0a2SMarek Vasut 435*7c4dd0a2SMarek Vasut return -EINVAL; 436*7c4dd0a2SMarek Vasut } 437*7c4dd0a2SMarek Vasut EXPORT_SYMBOL_GPL(drm_of_lvds_get_data_mapping); 438