1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * R-Car Display Unit DRM driver
4  *
5  * Copyright (C) 2013-2015 Renesas Electronics Corporation
6  *
7  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8  */
9 
10 #ifndef __RCAR_DU_DRV_H__
11 #define __RCAR_DU_DRV_H__
12 
13 #include <linux/kernel.h>
14 #include <linux/wait.h>
15 
16 #include <drm/drm_device.h>
17 
18 #include "rcar_cmm.h"
19 #include "rcar_du_crtc.h"
20 #include "rcar_du_group.h"
21 #include "rcar_du_vsp.h"
22 
23 struct clk;
24 struct device;
25 struct drm_bridge;
26 struct drm_property;
27 struct rcar_du_device;
28 
29 #define RCAR_DU_FEATURE_CRTC_IRQ	BIT(0)	/* Per-CRTC IRQ */
30 #define RCAR_DU_FEATURE_CRTC_CLOCK	BIT(1)	/* Per-CRTC clock */
31 #define RCAR_DU_FEATURE_VSP1_SOURCE	BIT(2)	/* Has inputs from VSP1 */
32 #define RCAR_DU_FEATURE_INTERLACED	BIT(3)	/* HW supports interlaced */
33 #define RCAR_DU_FEATURE_TVM_SYNC	BIT(4)	/* Has TV switch/sync modes */
34 #define RCAR_DU_FEATURE_NO_BLENDING	BIT(5)	/* PnMR.SPIM does not have ALP nor EOR bits */
35 
36 #define RCAR_DU_QUIRK_ALIGN_128B	BIT(0)	/* Align pitches to 128 bytes */
37 
38 enum rcar_du_output {
39 	RCAR_DU_OUTPUT_DPAD0,
40 	RCAR_DU_OUTPUT_DPAD1,
41 	RCAR_DU_OUTPUT_DSI0,
42 	RCAR_DU_OUTPUT_DSI1,
43 	RCAR_DU_OUTPUT_HDMI0,
44 	RCAR_DU_OUTPUT_HDMI1,
45 	RCAR_DU_OUTPUT_LVDS0,
46 	RCAR_DU_OUTPUT_LVDS1,
47 	RCAR_DU_OUTPUT_TCON,
48 	RCAR_DU_OUTPUT_MAX,
49 };
50 
51 /*
52  * struct rcar_du_output_routing - Output routing specification
53  * @possible_crtcs: bitmask of possible CRTCs for the output
54  * @port: device tree port number corresponding to this output route
55  *
56  * The DU has 5 possible outputs (DPAD0/1, LVDS0/1, TCON). Output routing data
57  * specify the valid SoC outputs, which CRTCs can drive the output, and the type
58  * of in-SoC encoder for the output.
59  */
60 struct rcar_du_output_routing {
61 	unsigned int possible_crtcs;
62 	unsigned int port;
63 };
64 
65 /*
66  * struct rcar_du_device_info - DU model-specific information
67  * @gen: device generation (2 or 3)
68  * @features: device features (RCAR_DU_FEATURE_*)
69  * @quirks: device quirks (RCAR_DU_QUIRK_*)
70  * @channels_mask: bit mask of available DU channels
71  * @routes: array of CRTC to output routes, indexed by output (RCAR_DU_OUTPUT_*)
72  * @num_lvds: number of internal LVDS encoders
73  * @num_rpf: number of RPFs in VSP
74  * @dpll_mask: bit mask of DU channels equipped with a DPLL
75  * @dsi_clk_mask: bitmask of channels that can use the DSI clock as dot clock
76  * @lvds_clk_mask: bitmask of channels that can use the LVDS clock as dot clock
77  */
78 struct rcar_du_device_info {
79 	unsigned int gen;
80 	unsigned int features;
81 	unsigned int quirks;
82 	unsigned int channels_mask;
83 	struct rcar_du_output_routing routes[RCAR_DU_OUTPUT_MAX];
84 	unsigned int num_lvds;
85 	unsigned int num_rpf;
86 	unsigned int dpll_mask;
87 	unsigned int dsi_clk_mask;
88 	unsigned int lvds_clk_mask;
89 };
90 
91 #define RCAR_DU_MAX_CRTCS		4
92 #define RCAR_DU_MAX_GROUPS		DIV_ROUND_UP(RCAR_DU_MAX_CRTCS, 2)
93 #define RCAR_DU_MAX_VSPS		4
94 #define RCAR_DU_MAX_LVDS		2
95 #define RCAR_DU_MAX_DSI			2
96 
97 struct rcar_du_device {
98 	struct device *dev;
99 	const struct rcar_du_device_info *info;
100 
101 	void __iomem *mmio;
102 
103 	struct drm_device ddev;
104 
105 	struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
106 	unsigned int num_crtcs;
107 
108 	struct rcar_du_group groups[RCAR_DU_MAX_GROUPS];
109 	struct platform_device *cmms[RCAR_DU_MAX_CRTCS];
110 	struct rcar_du_vsp vsps[RCAR_DU_MAX_VSPS];
111 	struct drm_bridge *lvds[RCAR_DU_MAX_LVDS];
112 	struct drm_bridge *dsi[RCAR_DU_MAX_DSI];
113 
114 	struct {
115 		struct drm_property *colorkey;
116 	} props;
117 
118 	unsigned int dpad0_source;
119 	unsigned int dpad1_source;
120 	unsigned int vspd1_sink;
121 };
122 
123 static inline struct rcar_du_device *to_rcar_du_device(struct drm_device *dev)
124 {
125 	return container_of(dev, struct rcar_du_device, ddev);
126 }
127 
128 static inline bool rcar_du_has(struct rcar_du_device *rcdu,
129 			       unsigned int feature)
130 {
131 	return rcdu->info->features & feature;
132 }
133 
134 static inline bool rcar_du_needs(struct rcar_du_device *rcdu,
135 				 unsigned int quirk)
136 {
137 	return rcdu->info->quirks & quirk;
138 }
139 
140 static inline u32 rcar_du_read(struct rcar_du_device *rcdu, u32 reg)
141 {
142 	return ioread32(rcdu->mmio + reg);
143 }
144 
145 static inline void rcar_du_write(struct rcar_du_device *rcdu, u32 reg, u32 data)
146 {
147 	iowrite32(data, rcdu->mmio + reg);
148 }
149 
150 const char *rcar_du_output_name(enum rcar_du_output output);
151 
152 #endif /* __RCAR_DU_DRV_H__ */
153