drm: add of_graph endpoint helper to find possible CRTCs
Subsystems (2)
PATCH 1/1 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.
---
RFA = request for acks
- Updated commentry in the drm_of_find_possible_crtcs() comment block to point at the description of the of_graph bindings.
- Not updated for drm kerneldoc as I'm unable to build the documentation.
drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_of.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 2 ++ include/drm/drm_of.h | 18 +++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 drivers/gpu/drm/drm_of.c create mode 100644 include/drm/drm_of.h
drivers/gpu/drm/Makefile +1 -0
@@ -20,6 +20,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm-$(CONFIG_PCI) += ati_pcigart.o drm-$(CONFIG_DRM_PANEL) += drm_panel.o +drm-$(CONFIG_OF) += drm_of.o drm-usb-y := drm_usb.o
drivers/gpu/drm/drm_of.c new file +67 -0
67 lines not on this page · raw message
include/drm/drm_crtc.h +2 -0
@@ -41,6 +41,7 @@ struct drm_framebuffer;struct drm_object_properties ;struct drm_file ;struct drm_clip_rect ; +struct device_node ;#define DRM_MODE_OBJECT_CRTC 0xcccccccc#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
@@ -314,6 +315,7 @@ struct drm_crtc_funcs {*/ struct drm_crtc {struct drm_device *dev; +struct device_node *port;struct list_head head;/**
include/drm/drm_of.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef __DRM_OF_H__ +#define __DRM_OF_H__ + +struct drm_device ; +struct device_node ; + +#ifdef CONFIG_OF +extern uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port); +#else +static inline uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port) +{ +return 0 ; +} +#endif + +#endif /* __DRM_OF_H__ */
Signature · 1 line
1.8.3.1
Quoted 9 lines · Russell King
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_nodetodrm_crtcwhich 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.
Quoted 8 lines
Signed-off-by Russell King <[email protected]>---
RFA = request for acks
- Updated commentry in the
drm_of_find_possible_crtcs()comment block to point at the description of theof_graphbindings.
- Not updated for drm kerneldoc as I'm unable to build the documentation.
hmm, I wonder if kbuild robot builds docs?
Anyways, no worries.. I can add the entries in drm.tmpl once this lands.. if I forget, someone remind me ;-)
Quoted 141 lines
drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_of.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 2 ++ include/drm/drm_of.h | 18 +++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 drivers/gpu/drm/drm_of.c create mode 100644 include/drm/drm_of.hdrivers/gpu/drm/Makefile +1
-0@@ -20,6 +20,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm-$(CONFIG_PCI) += ati_pcigart.o drm-$(CONFIG_DRM_PANEL) += drm_panel.o +drm-$(CONFIG_OF) += drm_of.o drm-usb-y := drm_usb.odrivers/gpu/drm/drm_of.c new file +67
-0@@ -0,0 +1,67 @@ +#include <linux/export.h> +#include <linux/list.h> +#include <linux/of_graph.h> +#include <drm/drmP.h> +#include <drm/drm_crtc.h> +#include <drm/drm_of.h> + +/** +* drm_crtc_port_mask - find the mask of a registered CRTC by port OF node +* @dev: DRM device +* @port: port OF node +* +* Given a port OF node, return the possible mask of the corresponding +* CRTC within a device's list of CRTCs. Returns zero if not found. +*/ +static uint32_t drm_crtc_port_mask (struct drm_device *dev, +struct device_node *port) +{ +unsigned int index =0 ; +struct drm_crtc *tmp; + +list_for_each_entry (tmp, &dev->mode_config.crtc_list, head) { +if (tmp->port == port) +return 1 << index; + + index++; + } + +return 0 ; +} + +/** +* drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port +* @dev: DRM device +* @port: encoder port to scan for endpoints +* +* Scan all endpoints attached to a port, locate their attached CRTCs, +* and generate the DRM mask of CRTCs which may be attached to this +* encoder. +* +* See Documentation/devicetree/bindings/graph.txt for the bindings. +*/ +uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port) +{ +struct device_node *remote_port, *ep =NULL ; +uint32_t possible_crtcs =0 ; + +do { + ep =of_graph_get_next_endpoint (port, ep); +if (!ep) +break ; + + remote_port =of_graph_get_remote_port (ep); +if (!remote_port) { +of_node_put (ep); +return 0 ; + } + + possible_crtcs |=drm_crtc_port_mask (dev, remote_port); + +of_node_put (remote_port); + }while (1 ); + +return possible_crtcs; +} +EXPORT_SYMBOL (drm_of_find_possible_crtcs);include/drm/drm_crtc.h +2
-0@@ -41,6 +41,7 @@ struct drm_framebuffer;struct drm_object_properties ;struct drm_file ;struct drm_clip_rect ; +struct device_node ;#define DRM_MODE_OBJECT_CRTC 0xcccccccc#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0@@ -314,6 +315,7 @@ struct drm_crtc_funcs {*/ struct drm_crtc {struct drm_device *dev; +struct device_node *port;struct list_head head;/** include/drm/drm_of.h new file +18
-1@@ -0,0 +1,18 @@ +#ifndef __DRM_OF_H__ +#define __DRM_OF_H__ + +struct drm_device ; +struct device_node ; + +#ifdef CONFIG_OF +extern uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port); +#else +static inline uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port) +{ +return 0 ; +} +#endif + +#endif /* __DRM_OF_H__ */ --1.8.3.1
Hi Russell,
Quoted 96 lines · Russell King
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_nodetodrm_crtcwhich 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.Signed-off-by Russell King <[email protected]>---
RFA = request for acks
- Updated commentry in the
drm_of_find_possible_crtcs()comment block to point at the description of theof_graphbindings.
- Not updated for drm kerneldoc as I'm unable to build the documentation.drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_of.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 2 ++ include/drm/drm_of.h | 18 +++++++++++++ 4 files changed, 88 insertions(+)create mode 100644
drivers/gpu/drm/drm_of.c
create mode 100644include/drm/drm_of.hdrivers/gpu/drm/Makefile +1
-0@@ -20,6 +20,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm-$(CONFIG_PCI) += ati_pcigart.o drm-$(CONFIG_DRM_PANEL) += drm_panel.o +drm-$(CONFIG_OF) += drm_of.o drm-usb-y := drm_usb.odrivers/gpu/drm/drm_of.c new file +52
-0@@ -0,0 +1,67 @@ +#include <linux/export.h> +#include <linux/list.h> +#include <linux/of_graph.h> +#include <drm/drmP.h> +#include <drm/drm_crtc.h> +#include <drm/drm_of.h> + +/** +* drm_crtc_port_mask - find the mask of a registered CRTC by port OF node +* @dev: DRM device +* @port: port OF node +* +* Given a port OF node, return the possible mask of the corresponding +* CRTC within a device's list of CRTCs. Returns zero if not found. +*/ +static uint32_t drm_crtc_port_mask (struct drm_device *dev, +struct device_node *port) +{ +unsigned int index =0 ; +struct drm_crtc *tmp; + +list_for_each_entry (tmp, &dev->mode_config.crtc_list, head) { +if (tmp->port == port) +return 1 << index; + + index++; + } + +return 0 ; +} + +/** +* drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port +* @dev: DRM device +* @port: encoder port to scan for endpoints +* +* Scan all endpoints attached to a port, locate their attached CRTCs, +* and generate the DRM mask of CRTCs which may be attached to this +* encoder. +* +* See Documentation/devicetree/bindings/graph.txt for the bindings. +*/ +uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port) +{ +struct device_node *remote_port, *ep =NULL ; +uint32_t possible_crtcs =0 ; + + do { + ep = of_graph_get_next_endpoint(port, ep); + if (!ep) + break;
drivers/gpu/drm/drm_of.c line 62
Quoted 10 lines
drivers/gpu/drm/drm_of.c new file +10
-0+ + remote_port =of_graph_get_remote_port (ep); +if (!remote_port) { +of_node_put (ep); +return 0 ; + } + + possible_crtcs |=drm_crtc_port_mask (dev, remote_port); + +of_node_put (remote_port);
In my humble opinion, this requires of_node_put(ep), because of_graph_get_next_endpoint() doesn't decrement it.
+ of_node_put(ep);
Thank you.
Best regards YJ
Quoted 50 lines
drivers/gpu/drm/drm_of.c new file +5
-0+ }while (1 ); + +return possible_crtcs; +} +EXPORT_SYMBOL (drm_of_find_possible_crtcs);include/drm/drm_crtc.h +2
-0@@ -41,6 +41,7 @@ struct drm_framebuffer;struct drm_object_properties ;struct drm_file ;struct drm_clip_rect ; +struct device_node ;#define DRM_MODE_OBJECT_CRTC 0xcccccccc#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0@@ -314,6 +315,7 @@ struct drm_crtc_funcs {*/ struct drm_crtc {struct drm_device *dev; +struct device_node *port;struct list_head head;/** include/drm/drm_of.h new file +18
-0@@ -0,0 +1,18 @@ +#ifndef __DRM_OF_H__ +#define __DRM_OF_H__ + +struct drm_device ; +struct device_node ; + +#ifdef CONFIG_OF +extern uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port); +#else +static inline uint32_t drm_of_find_possible_crtcs (struct drm_device *dev, +struct device_node *port) +{ +return 0 ; +} +#endif + +#endif /* __DRM_OF_H__ */