blob: ad2e96915d44a253c8d77dc2e5d98c22c758fc5c [file] [log] [blame]
Liviu Dudauad49f862016-03-07 10:00:53 +00001/*
2 *
3 * (C) COPYRIGHT 2013-2016 ARM Limited. All rights reserved.
4 *
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
8 * of such GNU licence.
9 *
10 * ARM Mali DP hardware manipulation routines.
11 */
12
13#ifndef __MALIDP_HW_H__
14#define __MALIDP_HW_H__
15
16#include <linux/bitops.h>
17#include "malidp_regs.h"
18
19struct videomode;
20struct clk;
21
22/* Mali DP IP blocks */
23enum {
24 MALIDP_DE_BLOCK = 0,
25 MALIDP_SE_BLOCK,
26 MALIDP_DC_BLOCK
27};
28
29/* Mali DP layer IDs */
30enum {
31 DE_VIDEO1 = BIT(0),
32 DE_GRAPHICS1 = BIT(1),
33 DE_GRAPHICS2 = BIT(2), /* used only in DP500 */
34 DE_VIDEO2 = BIT(3),
35 DE_SMART = BIT(4),
Brian Starkeya67bbbe2017-03-29 17:42:35 +010036 SE_MEMWRITE = BIT(5),
Liviu Dudauad49f862016-03-07 10:00:53 +000037};
38
Brian Starkey6211b482016-10-03 15:08:12 +010039struct malidp_format_id {
Liviu Dudauad49f862016-03-07 10:00:53 +000040 u32 format; /* DRM fourcc */
41 u8 layer; /* bitmask of layers supporting it */
42 u8 id; /* used internally */
43};
44
45#define MALIDP_INVALID_FORMAT_ID 0xff
46
47/*
48 * hide the differences between register maps
49 * by using a common structure to hold the
50 * base register offsets
51 */
52
53struct malidp_irq_map {
54 u32 irq_mask; /* mask of IRQs that can be enabled in the block */
55 u32 vsync_irq; /* IRQ bit used for signaling during VSYNC */
Alexandru Gheorghe613c5c72018-05-15 11:18:50 +010056 u32 err_mask; /* mask of bits that represent errors */
Liviu Dudauad49f862016-03-07 10:00:53 +000057};
58
59struct malidp_layer {
60 u16 id; /* layer ID */
61 u16 base; /* address offset for the register bank */
62 u16 ptr; /* address offset for the pointer register */
Mihail Atanassov6e810eb2017-11-07 15:30:46 +000063 u16 stride_offset; /* offset to the first stride register. */
64 s16 yuv2rgb_offset; /* offset to the YUV->RGB matrix entries */
Liviu Dudauad49f862016-03-07 10:00:53 +000065};
66
Mihail Atanassov28ce6752017-02-13 15:14:05 +000067enum malidp_scaling_coeff_set {
68 MALIDP_UPSCALING_COEFFS = 1,
69 MALIDP_DOWNSCALING_1_5_COEFFS = 2,
70 MALIDP_DOWNSCALING_2_COEFFS = 3,
71 MALIDP_DOWNSCALING_2_75_COEFFS = 4,
72 MALIDP_DOWNSCALING_4_COEFFS = 5,
73};
74
75struct malidp_se_config {
76 u8 scale_enable : 1;
Mihail Atanassov0274e6a2017-02-06 12:20:56 +000077 u8 enhancer_enable : 1;
Mihail Atanassov28ce6752017-02-13 15:14:05 +000078 u8 hcoeff : 3;
79 u8 vcoeff : 3;
80 u8 plane_src_id;
81 u16 input_w, input_h;
82 u16 output_w, output_h;
83 u32 h_init_phase, h_delta_phase;
84 u32 v_init_phase, v_delta_phase;
85};
86
Liviu Dudauad49f862016-03-07 10:00:53 +000087/* regmap features */
88#define MALIDP_REGMAP_HAS_CLEARIRQ (1 << 0)
89
90struct malidp_hw_regmap {
91 /* address offset of the DE register bank */
92 /* is always 0x0000 */
Mihail Atanassov02725d32017-02-01 14:48:50 +000093 /* address offset of the DE coefficients registers */
94 const u16 coeffs_base;
Liviu Dudauad49f862016-03-07 10:00:53 +000095 /* address offset of the SE registers bank */
96 const u16 se_base;
97 /* address offset of the DC registers bank */
98 const u16 dc_base;
99
100 /* address offset for the output depth register */
101 const u16 out_depth_base;
102
103 /* bitmap with register map features */
104 const u8 features;
105
106 /* list of supported layers */
107 const u8 n_layers;
108 const struct malidp_layer *layers;
109
110 const struct malidp_irq_map de_irq_map;
111 const struct malidp_irq_map se_irq_map;
112 const struct malidp_irq_map dc_irq_map;
113
Brian Starkey6211b482016-10-03 15:08:12 +0100114 /* list of supported pixel formats for each layer */
115 const struct malidp_format_id *pixel_formats;
116 const u8 n_pixel_formats;
Brian Starkeya2280622016-10-11 15:26:04 +0100117
118 /* pitch alignment requirement in bytes */
119 const u8 bus_align_bytes;
Liviu Dudauad49f862016-03-07 10:00:53 +0000120};
121
Mihail Atanassov83d642e2017-01-23 15:24:35 +0000122/* device features */
123/* Unlike DP550/650, DP500 has 3 stride registers in its video layer. */
124#define MALIDP_DEVICE_LV_HAS_3_STRIDES BIT(0)
125
Liviu Dudaua6993b22017-08-31 15:48:43 +0100126struct malidp_hw_device;
Liviu Dudauad49f862016-03-07 10:00:53 +0000127
Liviu Dudaua6993b22017-08-31 15:48:43 +0100128/*
129 * Static structure containing hardware specific data and pointers to
130 * functions that behave differently between various versions of the IP.
131 */
132struct malidp_hw {
133 const struct malidp_hw_regmap map;
Liviu Dudauad49f862016-03-07 10:00:53 +0000134
135 /*
136 * Validate the driver instance against the hardware bits
137 */
138 int (*query_hw)(struct malidp_hw_device *hwdev);
139
140 /*
141 * Set the hardware into config mode, ready to accept mode changes
142 */
143 void (*enter_config_mode)(struct malidp_hw_device *hwdev);
144
145 /*
146 * Tell hardware to exit configuration mode
147 */
148 void (*leave_config_mode)(struct malidp_hw_device *hwdev);
149
150 /*
151 * Query if hardware is in configuration mode
152 */
153 bool (*in_config_mode)(struct malidp_hw_device *hwdev);
154
155 /*
Liviu Dudau0735cfd2018-06-15 16:56:09 +0100156 * Set/clear configuration valid flag for hardware parameters that can
157 * be changed outside the configuration mode to the given value.
158 * Hardware will use the new settings when config valid is set,
159 * after the end of the current buffer scanout, and will ignore
160 * any new values for those parameters if config valid flag is cleared
Liviu Dudauad49f862016-03-07 10:00:53 +0000161 */
Liviu Dudau0735cfd2018-06-15 16:56:09 +0100162 void (*set_config_valid)(struct malidp_hw_device *hwdev, u8 value);
Liviu Dudauad49f862016-03-07 10:00:53 +0000163
164 /*
165 * Set a new mode in hardware. Requires the hardware to be in
166 * configuration mode before this function is called.
167 */
168 void (*modeset)(struct malidp_hw_device *hwdev, struct videomode *m);
169
170 /*
171 * Calculate the required rotation memory given the active area
172 * and the buffer format.
173 */
174 int (*rotmem_required)(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt);
175
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000176 int (*se_set_scaling_coeffs)(struct malidp_hw_device *hwdev,
177 struct malidp_se_config *se_config,
178 struct malidp_se_config *old_config);
179
Mihail Atanassovc2e7f822017-02-13 15:09:01 +0000180 long (*se_calc_mclk)(struct malidp_hw_device *hwdev,
181 struct malidp_se_config *se_config,
182 struct videomode *vm);
Liviu Dudau1cb3cbe2018-04-10 17:25:57 +0100183 /*
Liviu Dudau846c87a2017-03-29 17:42:34 +0100184 * Enable writing to memory the content of the next frame
185 * @param hwdev - malidp_hw_device structure containing the HW description
186 * @param addrs - array of addresses for each plane
187 * @param pitches - array of pitches for each plane
188 * @param num_planes - number of planes to be written
189 * @param w - width of the output frame
190 * @param h - height of the output frame
191 * @param fmt_id - internal format ID of output buffer
192 */
193 int (*enable_memwrite)(struct malidp_hw_device *hwdev, dma_addr_t *addrs,
194 s32 *pitches, int num_planes, u16 w, u16 h, u32 fmt_id);
195
196 /*
197 * Disable the writing to memory of the next frame's content.
198 */
199 void (*disable_memwrite)(struct malidp_hw_device *hwdev);
Mihail Atanassovc2e7f822017-02-13 15:09:01 +0000200
Liviu Dudauad49f862016-03-07 10:00:53 +0000201 u8 features;
Liviu Dudauad49f862016-03-07 10:00:53 +0000202};
203
204/* Supported variants of the hardware */
205enum {
206 MALIDP_500 = 0,
207 MALIDP_550,
208 MALIDP_650,
209 /* keep the next entry last */
210 MALIDP_MAX_DEVICES
211};
212
Liviu Dudaua6993b22017-08-31 15:48:43 +0100213extern const struct malidp_hw malidp_device[MALIDP_MAX_DEVICES];
214
215/*
216 * Structure used by the driver during runtime operation.
217 */
218struct malidp_hw_device {
219 struct malidp_hw *hw;
220 void __iomem *regs;
221
222 /* APB clock */
223 struct clk *pclk;
224 /* AXI clock */
225 struct clk *aclk;
226 /* main clock for display core */
227 struct clk *mclk;
228 /* pixel clock for display core */
229 struct clk *pxlclk;
230
231 u8 min_line_size;
232 u16 max_line_size;
Ayan Kumar Halderf8770062018-05-15 17:04:18 +0100233 u32 output_color_depth;
Liviu Dudaua6993b22017-08-31 15:48:43 +0100234
235 /* track the device PM state */
236 bool pm_suspended;
237
Liviu Dudau1cb3cbe2018-04-10 17:25:57 +0100238 /* track the SE memory writeback state */
239 u8 mw_state;
240
Liviu Dudaua6993b22017-08-31 15:48:43 +0100241 /* size of memory used for rotating layers, up to two banks available */
242 u32 rotation_memory[2];
243};
Liviu Dudauad49f862016-03-07 10:00:53 +0000244
245static inline u32 malidp_hw_read(struct malidp_hw_device *hwdev, u32 reg)
246{
Liviu Dudau85f64212017-03-22 10:44:57 +0000247 WARN_ON(hwdev->pm_suspended);
Liviu Dudauad49f862016-03-07 10:00:53 +0000248 return readl(hwdev->regs + reg);
249}
250
251static inline void malidp_hw_write(struct malidp_hw_device *hwdev,
252 u32 value, u32 reg)
253{
Liviu Dudau85f64212017-03-22 10:44:57 +0000254 WARN_ON(hwdev->pm_suspended);
Liviu Dudauad49f862016-03-07 10:00:53 +0000255 writel(value, hwdev->regs + reg);
256}
257
258static inline void malidp_hw_setbits(struct malidp_hw_device *hwdev,
259 u32 mask, u32 reg)
260{
261 u32 data = malidp_hw_read(hwdev, reg);
262
263 data |= mask;
264 malidp_hw_write(hwdev, data, reg);
265}
266
267static inline void malidp_hw_clearbits(struct malidp_hw_device *hwdev,
268 u32 mask, u32 reg)
269{
270 u32 data = malidp_hw_read(hwdev, reg);
271
272 data &= ~mask;
273 malidp_hw_write(hwdev, data, reg);
274}
275
276static inline u32 malidp_get_block_base(struct malidp_hw_device *hwdev,
277 u8 block)
278{
279 switch (block) {
280 case MALIDP_SE_BLOCK:
Liviu Dudaua6993b22017-08-31 15:48:43 +0100281 return hwdev->hw->map.se_base;
Liviu Dudauad49f862016-03-07 10:00:53 +0000282 case MALIDP_DC_BLOCK:
Liviu Dudaua6993b22017-08-31 15:48:43 +0100283 return hwdev->hw->map.dc_base;
Liviu Dudauad49f862016-03-07 10:00:53 +0000284 }
285
286 return 0;
287}
288
289static inline void malidp_hw_disable_irq(struct malidp_hw_device *hwdev,
290 u8 block, u32 irq)
291{
292 u32 base = malidp_get_block_base(hwdev, block);
293
294 malidp_hw_clearbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
295}
296
297static inline void malidp_hw_enable_irq(struct malidp_hw_device *hwdev,
298 u8 block, u32 irq)
299{
300 u32 base = malidp_get_block_base(hwdev, block);
301
302 malidp_hw_setbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
303}
304
305int malidp_de_irq_init(struct drm_device *drm, int irq);
Ayan Kumar Halderff8fc262018-05-15 17:04:16 +0100306void malidp_se_irq_hw_init(struct malidp_hw_device *hwdev);
307void malidp_de_irq_hw_init(struct malidp_hw_device *hwdev);
Ayan Kumar Halder62862cf2018-05-15 17:04:15 +0100308void malidp_de_irq_fini(struct malidp_hw_device *hwdev);
Liviu Dudauad49f862016-03-07 10:00:53 +0000309int malidp_se_irq_init(struct drm_device *drm, int irq);
Ayan Kumar Halder62862cf2018-05-15 17:04:15 +0100310void malidp_se_irq_fini(struct malidp_hw_device *hwdev);
Liviu Dudauad49f862016-03-07 10:00:53 +0000311
312u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
313 u8 layer_id, u32 format);
314
Liviu Dudaufcad73b2017-12-05 16:51:03 +0000315static inline u8 malidp_hw_get_pitch_align(struct malidp_hw_device *hwdev, bool rotated)
Brian Starkeya2280622016-10-11 15:26:04 +0100316{
Liviu Dudaufcad73b2017-12-05 16:51:03 +0000317 /*
318 * only hardware that cannot do 8 bytes bus alignments have further
319 * constraints on rotated planes
320 */
321 if (hwdev->hw->map.bus_align_bytes == 8)
322 return 8;
323 else
324 return hwdev->hw->map.bus_align_bytes << (rotated ? 2 : 0);
Brian Starkeya2280622016-10-11 15:26:04 +0100325}
326
Mihail Atanassov28ce6752017-02-13 15:14:05 +0000327/* U16.16 */
328#define FP_1_00000 0x00010000 /* 1.0 */
329#define FP_0_66667 0x0000AAAA /* 0.6667 = 1/1.5 */
330#define FP_0_50000 0x00008000 /* 0.5 = 1/2 */
331#define FP_0_36363 0x00005D17 /* 0.36363 = 1/2.75 */
332#define FP_0_25000 0x00004000 /* 0.25 = 1/4 */
333
334static inline enum malidp_scaling_coeff_set
335malidp_se_select_coeffs(u32 upscale_factor)
336{
337 return (upscale_factor >= FP_1_00000) ? MALIDP_UPSCALING_COEFFS :
338 (upscale_factor >= FP_0_66667) ? MALIDP_DOWNSCALING_1_5_COEFFS :
339 (upscale_factor >= FP_0_50000) ? MALIDP_DOWNSCALING_2_COEFFS :
340 (upscale_factor >= FP_0_36363) ? MALIDP_DOWNSCALING_2_75_COEFFS :
341 MALIDP_DOWNSCALING_4_COEFFS;
342}
343
344#undef FP_0_25000
345#undef FP_0_36363
346#undef FP_0_50000
347#undef FP_0_66667
348#undef FP_1_00000
Mihail Atanassov0274e6a2017-02-06 12:20:56 +0000349
350static inline void malidp_se_set_enh_coeffs(struct malidp_hw_device *hwdev)
351{
352 static const s32 enhancer_coeffs[] = {
353 -8, -8, -8, -8, 128, -8, -8, -8, -8
354 };
355 u32 val = MALIDP_SE_SET_ENH_LIMIT_LOW(MALIDP_SE_ENH_LOW_LEVEL) |
356 MALIDP_SE_SET_ENH_LIMIT_HIGH(MALIDP_SE_ENH_HIGH_LEVEL);
Liviu Dudaua6993b22017-08-31 15:48:43 +0100357 u32 image_enh = hwdev->hw->map.se_base +
358 ((hwdev->hw->map.features & MALIDP_REGMAP_HAS_CLEARIRQ) ?
Mihail Atanassov0274e6a2017-02-06 12:20:56 +0000359 0x10 : 0xC) + MALIDP_SE_IMAGE_ENH;
360 u32 enh_coeffs = image_enh + MALIDP_SE_ENH_COEFF0;
361 int i;
362
363 malidp_hw_write(hwdev, val, image_enh);
364 for (i = 0; i < ARRAY_SIZE(enhancer_coeffs); ++i)
365 malidp_hw_write(hwdev, enhancer_coeffs[i], enh_coeffs + i * 4);
366}
367
Liviu Dudauad49f862016-03-07 10:00:53 +0000368/*
369 * background color components are defined as 12bits values,
370 * they will be shifted right when stored on hardware that
371 * supports only 8bits per channel
372 */
373#define MALIDP_BGND_COLOR_R 0x000
374#define MALIDP_BGND_COLOR_G 0x000
375#define MALIDP_BGND_COLOR_B 0x000
376
Mihail Atanassov6954f242017-02-13 12:49:03 +0000377#define MALIDP_COLORADJ_NUM_COEFFS 12
Mihail Atanassov02725d32017-02-01 14:48:50 +0000378#define MALIDP_COEFFTAB_NUM_COEFFS 64
379
380#define MALIDP_GAMMA_LUT_SIZE 4096
381
Liviu Dudauad49f862016-03-07 10:00:53 +0000382#endif /* __MALIDP_HW_H__ */