Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __DRM_OF_H__
0003 #define __DRM_OF_H__
0004 
0005 #include <linux/of_graph.h>
0006 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
0007 #include <drm/drm_bridge.h>
0008 #endif
0009 
0010 struct component_master_ops;
0011 struct component_match;
0012 struct device;
0013 struct drm_device;
0014 struct drm_encoder;
0015 struct drm_panel;
0016 struct drm_bridge;
0017 struct device_node;
0018 
0019 /**
0020  * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection
0021  * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated
0022  *    from the first port, odd pixels from the second port
0023  * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated
0024  *    from the first port, even pixels from the second port
0025  */
0026 enum drm_lvds_dual_link_pixels {
0027     DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0,
0028     DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1,
0029 };
0030 
0031 #ifdef CONFIG_OF
0032 uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
0033                 struct device_node *port);
0034 uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
0035                     struct device_node *port);
0036 void drm_of_component_match_add(struct device *master,
0037                 struct component_match **matchptr,
0038                 int (*compare)(struct device *, void *),
0039                 struct device_node *node);
0040 int drm_of_component_probe(struct device *dev,
0041                int (*compare_of)(struct device *, void *),
0042                const struct component_master_ops *m_ops);
0043 int drm_of_encoder_active_endpoint(struct device_node *node,
0044                    struct drm_encoder *encoder,
0045                    struct of_endpoint *endpoint);
0046 int drm_of_find_panel_or_bridge(const struct device_node *np,
0047                 int port, int endpoint,
0048                 struct drm_panel **panel,
0049                 struct drm_bridge **bridge);
0050 int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
0051                       const struct device_node *port2);
0052 int drm_of_lvds_get_data_mapping(const struct device_node *port);
0053 int drm_of_get_data_lanes_count(const struct device_node *endpoint,
0054                 const unsigned int min, const unsigned int max);
0055 int drm_of_get_data_lanes_count_ep(const struct device_node *port,
0056                    int port_reg, int reg,
0057                    const unsigned int min,
0058                    const unsigned int max);
0059 #else
0060 static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
0061                       struct device_node *port)
0062 {
0063     return 0;
0064 }
0065 
0066 static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
0067                           struct device_node *port)
0068 {
0069     return 0;
0070 }
0071 
0072 static inline void
0073 drm_of_component_match_add(struct device *master,
0074                struct component_match **matchptr,
0075                int (*compare)(struct device *, void *),
0076                struct device_node *node)
0077 {
0078 }
0079 
0080 static inline int
0081 drm_of_component_probe(struct device *dev,
0082                int (*compare_of)(struct device *, void *),
0083                const struct component_master_ops *m_ops)
0084 {
0085     return -EINVAL;
0086 }
0087 
0088 static inline int drm_of_encoder_active_endpoint(struct device_node *node,
0089                          struct drm_encoder *encoder,
0090                          struct of_endpoint *endpoint)
0091 {
0092     return -EINVAL;
0093 }
0094 static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
0095                           int port, int endpoint,
0096                           struct drm_panel **panel,
0097                           struct drm_bridge **bridge)
0098 {
0099     return -EINVAL;
0100 }
0101 
0102 static inline int
0103 drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
0104                       const struct device_node *port2)
0105 {
0106     return -EINVAL;
0107 }
0108 
0109 static inline int
0110 drm_of_lvds_get_data_mapping(const struct device_node *port)
0111 {
0112     return -EINVAL;
0113 }
0114 
0115 static inline int
0116 drm_of_get_data_lanes_count(const struct device_node *endpoint,
0117                 const unsigned int min, const unsigned int max)
0118 {
0119     return -EINVAL;
0120 }
0121 
0122 static inline int
0123 drm_of_get_data_lanes_count_ep(const struct device_node *port,
0124                    int port_reg, int reg,
0125                    const unsigned int min,
0126                    const unsigned int max)
0127 {
0128     return -EINVAL;
0129 }
0130 #endif
0131 
0132 /*
0133  * drm_of_panel_bridge_remove - remove panel bridge
0134  * @np: device tree node containing panel bridge output ports
0135  *
0136  * Remove the panel bridge of a given DT node's port and endpoint number
0137  *
0138  * Returns zero if successful, or one of the standard error codes if it fails.
0139  */
0140 static inline int drm_of_panel_bridge_remove(const struct device_node *np,
0141                          int port, int endpoint)
0142 {
0143 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
0144     struct drm_bridge *bridge;
0145     struct device_node *remote;
0146 
0147     remote = of_graph_get_remote_node(np, port, endpoint);
0148     if (!remote)
0149         return -ENODEV;
0150 
0151     bridge = of_drm_find_bridge(remote);
0152     drm_panel_bridge_remove(bridge);
0153 
0154     return 0;
0155 #else
0156     return -EINVAL;
0157 #endif
0158 }
0159 
0160 static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
0161                             struct drm_encoder *encoder)
0162 {
0163     struct of_endpoint endpoint;
0164     int ret = drm_of_encoder_active_endpoint(node, encoder,
0165                          &endpoint);
0166 
0167     return ret ?: endpoint.id;
0168 }
0169 
0170 static inline int drm_of_encoder_active_port_id(struct device_node *node,
0171                         struct drm_encoder *encoder)
0172 {
0173     struct of_endpoint endpoint;
0174     int ret = drm_of_encoder_active_endpoint(node, encoder,
0175                          &endpoint);
0176 
0177     return ret ?: endpoint.port;
0178 }
0179 
0180 #endif /* __DRM_OF_H__ */