1 /*
2 * Copyright (c) 2015 MediaTek Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14 #ifndef MTK_DRM_DDP_COMP_H
15 #define MTK_DRM_DDP_COMP_H
16
17 #include <linux/io.h>
18
19 struct device;
20 struct device_node;
21 struct drm_crtc;
22 struct drm_device;
23 struct mtk_plane_state;
24 struct drm_crtc_state;
25
26 enum mtk_ddp_comp_type {
27 MTK_DISP_OVL,
28 MTK_DISP_RDMA,
29 MTK_DISP_WDMA,
30 MTK_DISP_COLOR,
31 MTK_DISP_AAL,
32 MTK_DISP_GAMMA,
33 MTK_DISP_UFOE,
34 MTK_DSI,
35 MTK_DPI,
36 MTK_DISP_PWM,
37 MTK_DISP_MUTEX,
38 MTK_DISP_OD,
39 MTK_DISP_BLS,
40 MTK_DDP_COMP_TYPE_MAX,
41 };
42
43 enum mtk_ddp_comp_id {
44 DDP_COMPONENT_AAL0,
45 DDP_COMPONENT_AAL1,
46 DDP_COMPONENT_BLS,
47 DDP_COMPONENT_COLOR0,
48 DDP_COMPONENT_COLOR1,
49 DDP_COMPONENT_DPI0,
50 DDP_COMPONENT_DPI1,
51 DDP_COMPONENT_DSI0,
52 DDP_COMPONENT_DSI1,
53 DDP_COMPONENT_DSI2,
54 DDP_COMPONENT_DSI3,
55 DDP_COMPONENT_GAMMA,
56 DDP_COMPONENT_OD0,
57 DDP_COMPONENT_OD1,
58 DDP_COMPONENT_OVL0,
59 DDP_COMPONENT_OVL1,
60 DDP_COMPONENT_PWM0,
61 DDP_COMPONENT_PWM1,
62 DDP_COMPONENT_PWM2,
63 DDP_COMPONENT_RDMA0,
64 DDP_COMPONENT_RDMA1,
65 DDP_COMPONENT_RDMA2,
66 DDP_COMPONENT_UFOE,
67 DDP_COMPONENT_WDMA0,
68 DDP_COMPONENT_WDMA1,
69 DDP_COMPONENT_ID_MAX,
70 };
71
72 struct mtk_ddp_comp;
73
74 struct mtk_ddp_comp_funcs {
75 void (*config)(struct mtk_ddp_comp *comp, unsigned int w,
76 unsigned int h, unsigned int vrefresh, unsigned int bpc);
77 void (*start)(struct mtk_ddp_comp *comp);
78 void (*stop)(struct mtk_ddp_comp *comp);
79 void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
80 void (*disable_vblank)(struct mtk_ddp_comp *comp);
81 unsigned int (*layer_nr)(struct mtk_ddp_comp *comp);
82 void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx);
83 void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx);
84 void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
85 struct mtk_plane_state *state);
86 void (*gamma_set)(struct mtk_ddp_comp *comp,
87 struct drm_crtc_state *state);
88 };
89
90 struct mtk_ddp_comp {
91 struct clk *clk;
92 void __iomem *regs;
93 int irq;
94 struct device *larb_dev;
95 enum mtk_ddp_comp_id id;
96 const struct mtk_ddp_comp_funcs *funcs;
97 };
98
mtk_ddp_comp_config(struct mtk_ddp_comp * comp,unsigned int w,unsigned int h,unsigned int vrefresh,unsigned int bpc)99 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
100 unsigned int w, unsigned int h,
101 unsigned int vrefresh, unsigned int bpc)
102 {
103 if (comp->funcs && comp->funcs->config)
104 comp->funcs->config(comp, w, h, vrefresh, bpc);
105 }
106
mtk_ddp_comp_start(struct mtk_ddp_comp * comp)107 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
108 {
109 if (comp->funcs && comp->funcs->start)
110 comp->funcs->start(comp);
111 }
112
mtk_ddp_comp_stop(struct mtk_ddp_comp * comp)113 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
114 {
115 if (comp->funcs && comp->funcs->stop)
116 comp->funcs->stop(comp);
117 }
118
mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp * comp,struct drm_crtc * crtc)119 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
120 struct drm_crtc *crtc)
121 {
122 if (comp->funcs && comp->funcs->enable_vblank)
123 comp->funcs->enable_vblank(comp, crtc);
124 }
125
mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp * comp)126 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
127 {
128 if (comp->funcs && comp->funcs->disable_vblank)
129 comp->funcs->disable_vblank(comp);
130 }
131
mtk_ddp_comp_layer_nr(struct mtk_ddp_comp * comp)132 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
133 {
134 if (comp->funcs && comp->funcs->layer_nr)
135 return comp->funcs->layer_nr(comp);
136
137 return 0;
138 }
139
mtk_ddp_comp_layer_on(struct mtk_ddp_comp * comp,unsigned int idx)140 static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp,
141 unsigned int idx)
142 {
143 if (comp->funcs && comp->funcs->layer_on)
144 comp->funcs->layer_on(comp, idx);
145 }
146
mtk_ddp_comp_layer_off(struct mtk_ddp_comp * comp,unsigned int idx)147 static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp,
148 unsigned int idx)
149 {
150 if (comp->funcs && comp->funcs->layer_off)
151 comp->funcs->layer_off(comp, idx);
152 }
153
mtk_ddp_comp_layer_config(struct mtk_ddp_comp * comp,unsigned int idx,struct mtk_plane_state * state)154 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
155 unsigned int idx,
156 struct mtk_plane_state *state)
157 {
158 if (comp->funcs && comp->funcs->layer_config)
159 comp->funcs->layer_config(comp, idx, state);
160 }
161
mtk_ddp_gamma_set(struct mtk_ddp_comp * comp,struct drm_crtc_state * state)162 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
163 struct drm_crtc_state *state)
164 {
165 if (comp->funcs && comp->funcs->gamma_set)
166 comp->funcs->gamma_set(comp, state);
167 }
168
169 int mtk_ddp_comp_get_id(struct device_node *node,
170 enum mtk_ddp_comp_type comp_type);
171 int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
172 struct mtk_ddp_comp *comp, enum mtk_ddp_comp_id comp_id,
173 const struct mtk_ddp_comp_funcs *funcs);
174 int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp);
175 void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp);
176 void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
177 unsigned int CFG);
178
179 #endif /* MTK_DRM_DDP_COMP_H */
180