Merge tag 'fuse-update-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/mszered...
[linux-2.6-microblaze.git] / drivers / gpu / drm / rcar-du / rcar_du_drv.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * rcar_du_drv.h  --  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_CLOCK  BIT(0)  /* Per-CRTC IRQ and clock */
30 #define RCAR_DU_FEATURE_VSP1_SOURCE     BIT(1)  /* Has inputs from VSP1 */
31 #define RCAR_DU_FEATURE_INTERLACED      BIT(2)  /* HW supports interlaced */
32 #define RCAR_DU_FEATURE_TVM_SYNC        BIT(3)  /* Has TV switch/sync modes */
33
34 #define RCAR_DU_QUIRK_ALIGN_128B        BIT(0)  /* Align pitches to 128 bytes */
35
36 /*
37  * struct rcar_du_output_routing - Output routing specification
38  * @possible_crtcs: bitmask of possible CRTCs for the output
39  * @port: device tree port number corresponding to this output route
40  *
41  * The DU has 5 possible outputs (DPAD0/1, LVDS0/1, TCON). Output routing data
42  * specify the valid SoC outputs, which CRTCs can drive the output, and the type
43  * of in-SoC encoder for the output.
44  */
45 struct rcar_du_output_routing {
46         unsigned int possible_crtcs;
47         unsigned int port;
48 };
49
50 /*
51  * struct rcar_du_device_info - DU model-specific information
52  * @gen: device generation (2 or 3)
53  * @features: device features (RCAR_DU_FEATURE_*)
54  * @quirks: device quirks (RCAR_DU_QUIRK_*)
55  * @channels_mask: bit mask of available DU channels
56  * @routes: array of CRTC to output routes, indexed by output (RCAR_DU_OUTPUT_*)
57  * @num_lvds: number of internal LVDS encoders
58  * @dpll_mask: bit mask of DU channels equipped with a DPLL
59  * @lvds_clk_mask: bitmask of channels that can use the LVDS clock as dot clock
60  */
61 struct rcar_du_device_info {
62         unsigned int gen;
63         unsigned int features;
64         unsigned int quirks;
65         unsigned int channels_mask;
66         struct rcar_du_output_routing routes[RCAR_DU_OUTPUT_MAX];
67         unsigned int num_lvds;
68         unsigned int dpll_mask;
69         unsigned int lvds_clk_mask;
70 };
71
72 #define RCAR_DU_MAX_CRTCS               4
73 #define RCAR_DU_MAX_GROUPS              DIV_ROUND_UP(RCAR_DU_MAX_CRTCS, 2)
74 #define RCAR_DU_MAX_VSPS                4
75 #define RCAR_DU_MAX_LVDS                2
76
77 struct rcar_du_device {
78         struct device *dev;
79         const struct rcar_du_device_info *info;
80
81         void __iomem *mmio;
82
83         struct drm_device ddev;
84
85         struct rcar_du_crtc crtcs[RCAR_DU_MAX_CRTCS];
86         unsigned int num_crtcs;
87
88         struct rcar_du_group groups[RCAR_DU_MAX_GROUPS];
89         struct platform_device *cmms[RCAR_DU_MAX_CRTCS];
90         struct rcar_du_vsp vsps[RCAR_DU_MAX_VSPS];
91         struct drm_bridge *lvds[RCAR_DU_MAX_LVDS];
92
93         struct {
94                 struct drm_property *colorkey;
95         } props;
96
97         unsigned int dpad0_source;
98         unsigned int dpad1_source;
99         unsigned int vspd1_sink;
100 };
101
102 static inline struct rcar_du_device *to_rcar_du_device(struct drm_device *dev)
103 {
104         return container_of(dev, struct rcar_du_device, ddev);
105 }
106
107 static inline bool rcar_du_has(struct rcar_du_device *rcdu,
108                                unsigned int feature)
109 {
110         return rcdu->info->features & feature;
111 }
112
113 static inline bool rcar_du_needs(struct rcar_du_device *rcdu,
114                                  unsigned int quirk)
115 {
116         return rcdu->info->quirks & quirk;
117 }
118
119 static inline u32 rcar_du_read(struct rcar_du_device *rcdu, u32 reg)
120 {
121         return ioread32(rcdu->mmio + reg);
122 }
123
124 static inline void rcar_du_write(struct rcar_du_device *rcdu, u32 reg, u32 data)
125 {
126         iowrite32(data, rcdu->mmio + reg);
127 }
128
129 #endif /* __RCAR_DU_DRV_H__ */