Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: add of_graph endpoint helper to find possible CRTCs

Add a helper to allow encoders to find their possible CRTCs from the
OF graph without having to re-implement this functionality. We add a
device_node to drm_crtc which corresponds with the port node in the
DT description of the CRTC device.

We can then scan the DRM device list for CRTCs to find their index,
matching the appropriate CRTC using the port device_node, thus building
up the possible CRTC mask.

Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

+88
+1
drivers/gpu/drm/Makefile
··· 20 20 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o 21 21 drm-$(CONFIG_PCI) += ati_pcigart.o 22 22 drm-$(CONFIG_DRM_PANEL) += drm_panel.o 23 + drm-$(CONFIG_OF) += drm_of.o 23 24 24 25 drm-usb-y := drm_usb.o 25 26
+67
drivers/gpu/drm/drm_of.c
··· 1 + #include <linux/export.h> 2 + #include <linux/list.h> 3 + #include <linux/of_graph.h> 4 + #include <drm/drmP.h> 5 + #include <drm/drm_crtc.h> 6 + #include <drm/drm_of.h> 7 + 8 + /** 9 + * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node 10 + * @dev: DRM device 11 + * @port: port OF node 12 + * 13 + * Given a port OF node, return the possible mask of the corresponding 14 + * CRTC within a device's list of CRTCs. Returns zero if not found. 15 + */ 16 + static uint32_t drm_crtc_port_mask(struct drm_device *dev, 17 + struct device_node *port) 18 + { 19 + unsigned int index = 0; 20 + struct drm_crtc *tmp; 21 + 22 + list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { 23 + if (tmp->port == port) 24 + return 1 << index; 25 + 26 + index++; 27 + } 28 + 29 + return 0; 30 + } 31 + 32 + /** 33 + * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port 34 + * @dev: DRM device 35 + * @port: encoder port to scan for endpoints 36 + * 37 + * Scan all endpoints attached to a port, locate their attached CRTCs, 38 + * and generate the DRM mask of CRTCs which may be attached to this 39 + * encoder. 40 + * 41 + * See Documentation/devicetree/bindings/graph.txt for the bindings. 42 + */ 43 + uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 44 + struct device_node *port) 45 + { 46 + struct device_node *remote_port, *ep = NULL; 47 + uint32_t possible_crtcs = 0; 48 + 49 + do { 50 + ep = of_graph_get_next_endpoint(port, ep); 51 + if (!ep) 52 + break; 53 + 54 + remote_port = of_graph_get_remote_port(ep); 55 + if (!remote_port) { 56 + of_node_put(ep); 57 + return 0; 58 + } 59 + 60 + possible_crtcs |= drm_crtc_port_mask(dev, remote_port); 61 + 62 + of_node_put(remote_port); 63 + } while (1); 64 + 65 + return possible_crtcs; 66 + } 67 + EXPORT_SYMBOL(drm_of_find_possible_crtcs);
+2
include/drm/drm_crtc.h
··· 41 41 struct drm_object_properties; 42 42 struct drm_file; 43 43 struct drm_clip_rect; 44 + struct device_node; 44 45 45 46 #define DRM_MODE_OBJECT_CRTC 0xcccccccc 46 47 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0 ··· 315 314 */ 316 315 struct drm_crtc { 317 316 struct drm_device *dev; 317 + struct device_node *port; 318 318 struct list_head head; 319 319 320 320 /**
+18
include/drm/drm_of.h
··· 1 + #ifndef __DRM_OF_H__ 2 + #define __DRM_OF_H__ 3 + 4 + struct drm_device; 5 + struct device_node; 6 + 7 + #ifdef CONFIG_OF 8 + extern uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 9 + struct device_node *port); 10 + #else 11 + static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 12 + struct device_node *port) 13 + { 14 + return 0; 15 + } 16 + #endif 17 + 18 + #endif /* __DRM_OF_H__ */