^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/component.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/of_graph.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <drm/drm_bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <drm/drm_crtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <drm/drm_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <drm/drm_encoder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <drm/drm_of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <drm/drm_panel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * DOC: overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * A set of helper functions to aid DRM drivers in parsing standard DT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * properties.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static void drm_release_of(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) of_node_put(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * drm_of_crtc_port_mask - find the mask of a registered CRTC by port OF node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @dev: DRM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @port: port OF node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Given a port OF node, return the possible mask of the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * CRTC within a device's list of CRTCs. Returns zero if not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct device_node *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned int index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct drm_crtc *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) drm_for_each_crtc(tmp, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (tmp->port == port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 1 << index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) EXPORT_SYMBOL(drm_of_crtc_port_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @dev: DRM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @port: encoder port to scan for endpoints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Scan all endpoints attached to a port, locate their attached CRTCs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * and generate the DRM mask of CRTCs which may be attached to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * encoder.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * See Documentation/devicetree/bindings/graph.txt for the bindings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct device_node *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct device_node *remote_port, *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) uint32_t possible_crtcs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) for_each_endpoint_of_node(port, ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) remote_port = of_graph_get_remote_port(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!remote_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) of_node_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) possible_crtcs |= drm_of_crtc_port_mask(dev, remote_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) of_node_put(remote_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return possible_crtcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) EXPORT_SYMBOL(drm_of_find_possible_crtcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * drm_of_component_match_add - Add a component helper OF node match rule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @master: master device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @matchptr: component match pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @compare: compare function used for matching component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @node: of_node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void drm_of_component_match_add(struct device *master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct component_match **matchptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int (*compare)(struct device *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) of_node_get(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) component_match_add_release(master, matchptr, drm_release_of,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) compare, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) EXPORT_SYMBOL_GPL(drm_of_component_match_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * drm_of_component_probe - Generic probe function for a component based master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @dev: master device containing the OF node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @compare_of: compare function used for matching components
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @m_ops: component master ops to be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Parse the platform device OF node and bind all the components associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * with the master. Interface ports are added before the encoders in order to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * satisfy their .bind requirements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * See Documentation/devicetree/bindings/graph.txt for the bindings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Returns zero if successful, or one of the standard error codes if it fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int drm_of_component_probe(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int (*compare_of)(struct device *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) const struct component_master_ops *m_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct device_node *ep, *port, *remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct component_match *match = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!dev->of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * Bind the crtc's ports first, so that drm_of_find_possible_crtcs()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * called from encoder's .bind callbacks works as expected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) for (i = 0; ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) port = of_parse_phandle(dev->of_node, "ports", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (of_device_is_available(port->parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) drm_of_component_match_add(dev, &match, compare_of,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) of_node_put(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (i == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) dev_err(dev, "missing 'ports' property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dev_err(dev, "no available port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * For bound crtcs, bind the encoders attached to their remote endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) for (i = 0; ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) port = of_parse_phandle(dev->of_node, "ports", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (!of_device_is_available(port->parent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) of_node_put(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) for_each_child_of_node(port, ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) remote = of_graph_get_remote_port_parent(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (!remote || !of_device_is_available(remote)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) of_node_put(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) } else if (!of_device_is_available(remote->parent)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_warn(dev, "parent device of %pOF is not available\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) of_node_put(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) drm_of_component_match_add(dev, &match, compare_of,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) of_node_put(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) of_node_put(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return component_master_add_with_match(dev, m_ops, match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL(drm_of_component_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * drm_of_encoder_active_endpoint - return the active encoder endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @node: device tree node containing encoder input ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @encoder: drm_encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Given an encoder device node and a drm_encoder with a connected crtc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * parse the encoder endpoint connecting to the crtc port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int drm_of_encoder_active_endpoint(struct device_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct drm_encoder *encoder,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct of_endpoint *endpoint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct device_node *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct drm_crtc *crtc = encoder->crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct device_node *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!node || !crtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) for_each_endpoint_of_node(node, ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) port = of_graph_get_remote_port(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) of_node_put(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (port == crtc->port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ret = of_graph_parse_endpoint(ep, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) of_node_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) EXPORT_SYMBOL_GPL(drm_of_encoder_active_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * drm_of_find_panel_or_bridge - return connected panel or bridge device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * @np: device tree node containing encoder output ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @port: port in the device tree node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @endpoint: endpoint in the device tree node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * @panel: pointer to hold returned drm_panel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * @bridge: pointer to hold returned drm_bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * Given a DT node's port and endpoint number, find the connected node and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * return either the associated struct drm_panel or drm_bridge device. Either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * @panel or @bridge must not be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Returns zero if successful, or one of the standard error codes if it fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int drm_of_find_panel_or_bridge(const struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int port, int endpoint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct drm_panel **panel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct drm_bridge **bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int ret = -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct device_node *remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!panel && !bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *panel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * of_graph_get_remote_node() produces a noisy error message if port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * node isn't found and the absence of the port is a legit case here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * so at first we silently check whether graph presents in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * device-tree node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!of_graph_is_present(np))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) remote = of_graph_get_remote_node(np, port, endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (panel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) *panel = of_drm_find_panel(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!IS_ERR(*panel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) *panel = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* No panel found yet, check for a bridge next. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) *bridge = of_drm_find_bridge(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (*bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *bridge = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) of_node_put(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) enum drm_of_lvds_pixels {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) DRM_OF_LVDS_EVEN = BIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) DRM_OF_LVDS_ODD = BIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static int drm_of_lvds_get_port_pixels_type(struct device_node *port_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) bool even_pixels =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) of_property_read_bool(port_node, "dual-lvds-even-pixels");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) bool odd_pixels =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) of_property_read_bool(port_node, "dual-lvds-odd-pixels");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return (even_pixels ? DRM_OF_LVDS_EVEN : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) (odd_pixels ? DRM_OF_LVDS_ODD : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int drm_of_lvds_get_remote_pixels_type(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) const struct device_node *port_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct device_node *endpoint = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int pixels_type = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) for_each_child_of_node(port_node, endpoint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct device_node *remote_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int current_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (!of_node_name_eq(endpoint, "endpoint"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) remote_port = of_graph_get_remote_port(endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (!remote_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) of_node_put(endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) current_pt = drm_of_lvds_get_port_pixels_type(remote_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) of_node_put(remote_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (pixels_type < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) pixels_type = current_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * Sanity check, ensure that all remote endpoints have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * pixel type. We may lift this restriction later if we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * support multiple sinks with different dual-link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * configurations by passing the endpoints explicitly to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * drm_of_lvds_get_dual_link_pixel_order().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (!current_pt || pixels_type != current_pt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) of_node_put(endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return pixels_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * drm_of_lvds_get_dual_link_pixel_order - Get LVDS dual-link pixel order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * @port1: First DT port node of the Dual-link LVDS source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * @port2: Second DT port node of the Dual-link LVDS source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * An LVDS dual-link connection is made of two links, with even pixels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * transitting on one link, and odd pixels on the other link. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * returns, for two ports of an LVDS dual-link source, which port shall transmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * the even and odd pixels, based on the requirements of the connected sink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * The pixel order is determined from the dual-lvds-even-pixels and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * dual-lvds-odd-pixels properties in the sink's DT port nodes. If those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * properties are not present, or if their usage is not valid, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * returns -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * If either port is not connected, this function returns -EPIPE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * @port1 and @port2 are typically DT sibling nodes, but may have different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * parents when, for instance, two separate LVDS encoders carry the even and odd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * pixels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * * DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS - @port1 carries even pixels and @port2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * carries odd pixels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * * DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS - @port1 carries odd pixels and @port2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * carries even pixels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * * -EINVAL - @port1 and @port2 are not connected to a dual-link LVDS sink, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * the sink configuration is invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * * -EPIPE - when @port1 or @port2 are not connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) const struct device_node *port2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int remote_p1_pt, remote_p2_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!port1 || !port2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) remote_p1_pt = drm_of_lvds_get_remote_pixels_type(port1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (remote_p1_pt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return remote_p1_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) remote_p2_pt = drm_of_lvds_get_remote_pixels_type(port2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (remote_p2_pt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return remote_p2_pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * A valid dual-lVDS bus is found when one remote port is marked with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * "dual-lvds-even-pixels", and the other remote port is marked with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * "dual-lvds-odd-pixels", bail out if the markers are not right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (remote_p1_pt + remote_p2_pt != DRM_OF_LVDS_EVEN + DRM_OF_LVDS_ODD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return remote_p1_pt == DRM_OF_LVDS_EVEN ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) EXPORT_SYMBOL_GPL(drm_of_lvds_get_dual_link_pixel_order);