Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * R-Car Display Unit DRM driver
0004  *
0005  * Copyright (C) 2013-2015 Renesas Electronics Corporation
0006  *
0007  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
0008  */
0009 
0010 #ifndef __RCAR_DU_DRV_H__
0011 #define __RCAR_DU_DRV_H__
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/wait.h>
0015 
0016 #include <drm/drm_device.h>
0017 
0018 #include "rcar_cmm.h"
0019 #include "rcar_du_crtc.h"
0020 #include "rcar_du_group.h"
0021 #include "rcar_du_vsp.h"
0022 
0023 struct clk;
0024 struct device;
0025 struct drm_bridge;
0026 struct drm_property;
0027 struct rcar_du_device;
0028 
0029 #define RCAR_DU_FEATURE_CRTC_IRQ    BIT(0)  /* Per-CRTC IRQ */
0030 #define RCAR_DU_FEATURE_CRTC_CLOCK  BIT(1)  /* Per-CRTC clock */
0031 #define RCAR_DU_FEATURE_VSP1_SOURCE BIT(2)  /* Has inputs from VSP1 */
0032 #define RCAR_DU_FEATURE_INTERLACED  BIT(3)  /* HW supports interlaced */
0033 #define RCAR_DU_FEATURE_TVM_SYNC    BIT(4)  /* Has TV switch/sync modes */
0034 
0035 #define RCAR_DU_QUIRK_ALIGN_128B    BIT(0)  /* Align pitches to 128 bytes */
0036 
0037 enum rcar_du_output {
0038     RCAR_DU_OUTPUT_DPAD0,
0039     RCAR_DU_OUTPUT_DPAD1,
0040     RCAR_DU_OUTPUT_DSI0,
0041     RCAR_DU_OUTPUT_DSI1,
0042     RCAR_DU_OUTPUT_HDMI0,
0043     RCAR_DU_OUTPUT_HDMI1,
0044     RCAR_DU_OUTPUT_LVDS0,
0045     RCAR_DU_OUTPUT_LVDS1,
0046     RCAR_DU_OUTPUT_TCON,
0047     RCAR_DU_OUTPUT_MAX,
0048 };
0049 
0050 /*
0051  * struct rcar_du_output_routing - Output routing specification
0052  * @possible_crtcs: bitmask of possible CRTCs for the output
0053  * @port: device tree port number corresponding to this output route
0054  *
0055  * The DU has 5 possible outputs (DPAD0/1, LVDS0/1, TCON). Output routing data
0056  * specify the valid SoC outputs, which CRTCs can drive the output, and the type
0057  * of in-SoC encoder for the output.
0058  */
0059 struct rcar_du_output_routing {
0060     unsigned int possible_crtcs;
0061     unsigned int port;
0062 };
0063 
0064 /*
0065  * struct rcar_du_device_info - DU model-specific information
0066  * @gen: device generation (2 or 3)
0067  * @features: device features (RCAR_DU_FEATURE_*)
0068  * @quirks: device quirks (RCAR_DU_QUIRK_*)
0069  * @channels_mask: bit mask of available DU channels
0070  * @routes: array of CRTC to output routes, indexed by output (RCAR_DU_OUTPUT_*)
0071  * @num_lvds: number of internal LVDS encoders
0072  * @num_rpf: number of RPFs in VSP
0073  * @dpll_mask: bit mask of DU channels equipped with a DPLL
0074  * @dsi_clk_mask: bitmask of channels that can use the DSI clock as dot clock
0075  * @lvds_clk_mask: bitmask of channels that can use the LVDS clock as dot clock
0076  */
0077 struct rcar_du_device_info {
0078     unsigned int gen;
0079     unsigned int features;
0080     unsigned int quirks;
0081     unsigned int channels_mask;
0082     struct rcar_du_output_routing routes[RCAR_DU_OUTPUT_MAX];
0083     unsigned int num_lvds;
0084     unsigned int num_rpf;
0085     unsigned int dpll_mask;
0086     unsigned int dsi_clk_mask;
0087     unsigned int lvds_clk_mask;
0088 };
0089 
0090 #define RCAR_DU_MAX_CRTCS       4
0091 #define RCAR_DU_MAX_GROUPS      DIV_ROUND_UP(RCAR_DU_MAX_CRTCS, 2)
0092 #define RCAR_DU_MAX_VSPS        4
0093 #define RCAR_DU_MAX_LVDS        2
0094 
0095 struct rcar_du_device {
0096     struct device *dev;
0097     const struct rcar_du_device_info *info;
0098 
0099     void __iomem *mmio;
0100 
0101     struct drm_device ddev;
0102 
0103     struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
0104     unsigned int num_crtcs;
0105 
0106     struct rcar_du_group groups[RCAR_DU_MAX_GROUPS];
0107     struct platform_device *cmms[RCAR_DU_MAX_CRTCS];
0108     struct rcar_du_vsp vsps[RCAR_DU_MAX_VSPS];
0109     struct drm_bridge *lvds[RCAR_DU_MAX_LVDS];
0110 
0111     struct {
0112         struct drm_property *colorkey;
0113     } props;
0114 
0115     unsigned int dpad0_source;
0116     unsigned int dpad1_source;
0117     unsigned int vspd1_sink;
0118 };
0119 
0120 static inline struct rcar_du_device *to_rcar_du_device(struct drm_device *dev)
0121 {
0122     return container_of(dev, struct rcar_du_device, ddev);
0123 }
0124 
0125 static inline bool rcar_du_has(struct rcar_du_device *rcdu,
0126                    unsigned int feature)
0127 {
0128     return rcdu->info->features & feature;
0129 }
0130 
0131 static inline bool rcar_du_needs(struct rcar_du_device *rcdu,
0132                  unsigned int quirk)
0133 {
0134     return rcdu->info->quirks & quirk;
0135 }
0136 
0137 static inline u32 rcar_du_read(struct rcar_du_device *rcdu, u32 reg)
0138 {
0139     return ioread32(rcdu->mmio + reg);
0140 }
0141 
0142 static inline void rcar_du_write(struct rcar_du_device *rcdu, u32 reg, u32 data)
0143 {
0144     iowrite32(data, rcdu->mmio + reg);
0145 }
0146 
0147 const char *rcar_du_output_name(enum rcar_du_output output);
0148 
0149 #endif /* __RCAR_DU_DRV_H__ */