GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / gpu / drm / rcar-du / rcar_du_drv.h
1 /*
2  * rcar_du_drv.h  --  R-Car Display Unit DRM driver
3  *
4  * Copyright (C) 2013-2015 Renesas Electronics Corporation
5  *
6  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13
14 #ifndef __RCAR_DU_DRV_H__
15 #define __RCAR_DU_DRV_H__
16
17 #include <linux/kernel.h>
18 #include <linux/wait.h>
19
20 #include "rcar_du_crtc.h"
21 #include "rcar_du_group.h"
22 #include "rcar_du_vsp.h"
23
24 struct clk;
25 struct device;
26 struct drm_device;
27 struct drm_fbdev_cma;
28 struct rcar_du_device;
29 struct rcar_du_lvdsenc;
30
31 #define RCAR_DU_FEATURE_CRTC_IRQ_CLOCK  (1 << 0)        /* Per-CRTC IRQ and clock */
32 #define RCAR_DU_FEATURE_EXT_CTRL_REGS   (1 << 1)        /* Has extended control registers */
33 #define RCAR_DU_FEATURE_VSP1_SOURCE     (1 << 2)        /* Has inputs from VSP1 */
34
35 #define RCAR_DU_QUIRK_ALIGN_128B        (1 << 0)        /* Align pitches to 128 bytes */
36 #define RCAR_DU_QUIRK_LVDS_LANES        (1 << 1)        /* LVDS lanes 1 and 3 inverted */
37
38 /*
39  * struct rcar_du_output_routing - Output routing specification
40  * @possible_crtcs: bitmask of possible CRTCs for the output
41  * @port: device tree port number corresponding to this output route
42  *
43  * The DU has 5 possible outputs (DPAD0/1, LVDS0/1, TCON). Output routing data
44  * specify the valid SoC outputs, which CRTCs can drive the output, and the type
45  * of in-SoC encoder for the output.
46  */
47 struct rcar_du_output_routing {
48         unsigned int possible_crtcs;
49         unsigned int port;
50 };
51
52 /*
53  * struct rcar_du_device_info - DU model-specific information
54  * @gen: device generation (2 or 3)
55  * @features: device features (RCAR_DU_FEATURE_*)
56  * @quirks: device quirks (RCAR_DU_QUIRK_*)
57  * @num_crtcs: total number of CRTCs
58  * @routes: array of CRTC to output routes, indexed by output (RCAR_DU_OUTPUT_*)
59  * @num_lvds: number of internal LVDS encoders
60  */
61 struct rcar_du_device_info {
62         unsigned int gen;
63         unsigned int features;
64         unsigned int quirks;
65         unsigned int num_crtcs;
66         struct rcar_du_output_routing routes[RCAR_DU_OUTPUT_MAX];
67         unsigned int num_lvds;
68         unsigned int dpll_ch;
69 };
70
71 #define RCAR_DU_MAX_CRTCS               4
72 #define RCAR_DU_MAX_GROUPS              DIV_ROUND_UP(RCAR_DU_MAX_CRTCS, 2)
73 #define RCAR_DU_MAX_LVDS                2
74 #define RCAR_DU_MAX_VSPS                4
75
76 struct rcar_du_device {
77         struct device *dev;
78         const struct rcar_du_device_info *info;
79
80         void __iomem *mmio;
81
82         struct drm_device *ddev;
83         struct drm_fbdev_cma *fbdev;
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 rcar_du_vsp vsps[RCAR_DU_MAX_VSPS];
90
91         struct {
92                 struct drm_property *alpha;
93                 struct drm_property *colorkey;
94         } props;
95
96         unsigned int dpad0_source;
97         unsigned int vspd1_sink;
98
99         struct rcar_du_lvdsenc *lvds[RCAR_DU_MAX_LVDS];
100 };
101
102 static inline bool rcar_du_has(struct rcar_du_device *rcdu,
103                                unsigned int feature)
104 {
105         return rcdu->info->features & feature;
106 }
107
108 static inline bool rcar_du_needs(struct rcar_du_device *rcdu,
109                                  unsigned int quirk)
110 {
111         return rcdu->info->quirks & quirk;
112 }
113
114 static inline u32 rcar_du_read(struct rcar_du_device *rcdu, u32 reg)
115 {
116         return ioread32(rcdu->mmio + reg);
117 }
118
119 static inline void rcar_du_write(struct rcar_du_device *rcdu, u32 reg, u32 data)
120 {
121         iowrite32(data, rcdu->mmio + reg);
122 }
123
124 #endif /* __RCAR_DU_DRV_H__ */