3 * (C) COPYRIGHT 2013-2016 ARM Limited. All rights reserved.
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
10 * ARM Mali DP hardware manipulation routines.
13 #ifndef __MALIDP_HW_H__
14 #define __MALIDP_HW_H__
16 #include <linux/bitops.h>
17 #include "malidp_regs.h"
22 /* Mali DP IP blocks */
29 /* Mali DP layer IDs */
32 DE_GRAPHICS1
= BIT(1),
33 DE_GRAPHICS2
= BIT(2), /* used only in DP500 */
39 enum rotation_features
{
40 ROTATE_NONE
, /* does not support rotation at all */
41 ROTATE_ANY
, /* supports rotation on any buffers */
42 ROTATE_COMPRESSED
, /* supports rotation only on compressed buffers */
45 struct malidp_format_id
{
46 u32 format
; /* DRM fourcc */
47 u8 layer
; /* bitmask of layers supporting it */
48 u8 id
; /* used internally */
51 #define MALIDP_INVALID_FORMAT_ID 0xff
54 * hide the differences between register maps
55 * by using a common structure to hold the
56 * base register offsets
59 struct malidp_irq_map
{
60 u32 irq_mask
; /* mask of IRQs that can be enabled in the block */
61 u32 vsync_irq
; /* IRQ bit used for signaling during VSYNC */
62 u32 err_mask
; /* mask of bits that represent errors */
66 u16 id
; /* layer ID */
67 u16 base
; /* address offset for the register bank */
68 u16 ptr
; /* address offset for the pointer register */
69 u16 stride_offset
; /* offset to the first stride register. */
70 s16 yuv2rgb_offset
; /* offset to the YUV->RGB matrix entries */
71 u16 mmu_ctrl_offset
; /* offset to the MMU control register */
72 enum rotation_features rot
; /* type of rotation supported */
75 enum malidp_scaling_coeff_set
{
76 MALIDP_UPSCALING_COEFFS
= 1,
77 MALIDP_DOWNSCALING_1_5_COEFFS
= 2,
78 MALIDP_DOWNSCALING_2_COEFFS
= 3,
79 MALIDP_DOWNSCALING_2_75_COEFFS
= 4,
80 MALIDP_DOWNSCALING_4_COEFFS
= 5,
83 struct malidp_se_config
{
85 u8 enhancer_enable
: 1;
90 u16 output_w
, output_h
;
91 u32 h_init_phase
, h_delta_phase
;
92 u32 v_init_phase
, v_delta_phase
;
96 #define MALIDP_REGMAP_HAS_CLEARIRQ (1 << 0)
98 struct malidp_hw_regmap
{
99 /* address offset of the DE register bank */
100 /* is always 0x0000 */
101 /* address offset of the DE coefficients registers */
102 const u16 coeffs_base
;
103 /* address offset of the SE registers bank */
105 /* address offset of the DC registers bank */
108 /* address offset for the output depth register */
109 const u16 out_depth_base
;
111 /* bitmap with register map features */
114 /* list of supported layers */
116 const struct malidp_layer
*layers
;
118 const struct malidp_irq_map de_irq_map
;
119 const struct malidp_irq_map se_irq_map
;
120 const struct malidp_irq_map dc_irq_map
;
122 /* list of supported pixel formats for each layer */
123 const struct malidp_format_id
*pixel_formats
;
124 const u8 n_pixel_formats
;
126 /* pitch alignment requirement in bytes */
127 const u8 bus_align_bytes
;
130 /* device features */
131 /* Unlike DP550/650, DP500 has 3 stride registers in its video layer. */
132 #define MALIDP_DEVICE_LV_HAS_3_STRIDES BIT(0)
134 struct malidp_hw_device
;
137 * Static structure containing hardware specific data and pointers to
138 * functions that behave differently between various versions of the IP.
141 const struct malidp_hw_regmap map
;
144 * Validate the driver instance against the hardware bits
146 int (*query_hw
)(struct malidp_hw_device
*hwdev
);
149 * Set the hardware into config mode, ready to accept mode changes
151 void (*enter_config_mode
)(struct malidp_hw_device
*hwdev
);
154 * Tell hardware to exit configuration mode
156 void (*leave_config_mode
)(struct malidp_hw_device
*hwdev
);
159 * Query if hardware is in configuration mode
161 bool (*in_config_mode
)(struct malidp_hw_device
*hwdev
);
164 * Set/clear configuration valid flag for hardware parameters that can
165 * be changed outside the configuration mode to the given value.
166 * Hardware will use the new settings when config valid is set,
167 * after the end of the current buffer scanout, and will ignore
168 * any new values for those parameters if config valid flag is cleared
170 void (*set_config_valid
)(struct malidp_hw_device
*hwdev
, u8 value
);
173 * Set a new mode in hardware. Requires the hardware to be in
174 * configuration mode before this function is called.
176 void (*modeset
)(struct malidp_hw_device
*hwdev
, struct videomode
*m
);
179 * Calculate the required rotation memory given the active area
180 * and the buffer format.
182 int (*rotmem_required
)(struct malidp_hw_device
*hwdev
, u16 w
, u16 h
, u32 fmt
);
184 int (*se_set_scaling_coeffs
)(struct malidp_hw_device
*hwdev
,
185 struct malidp_se_config
*se_config
,
186 struct malidp_se_config
*old_config
);
188 long (*se_calc_mclk
)(struct malidp_hw_device
*hwdev
,
189 struct malidp_se_config
*se_config
,
190 struct videomode
*vm
);
192 * Enable writing to memory the content of the next frame
193 * @param hwdev - malidp_hw_device structure containing the HW description
194 * @param addrs - array of addresses for each plane
195 * @param pitches - array of pitches for each plane
196 * @param num_planes - number of planes to be written
197 * @param w - width of the output frame
198 * @param h - height of the output frame
199 * @param fmt_id - internal format ID of output buffer
201 int (*enable_memwrite
)(struct malidp_hw_device
*hwdev
, dma_addr_t
*addrs
,
202 s32
*pitches
, int num_planes
, u16 w
, u16 h
, u32 fmt_id
,
203 const s16
*rgb2yuv_coeffs
);
206 * Disable the writing to memory of the next frame's content.
208 void (*disable_memwrite
)(struct malidp_hw_device
*hwdev
);
213 /* Supported variants of the hardware */
218 /* keep the next entry last */
222 extern const struct malidp_hw malidp_device
[MALIDP_MAX_DEVICES
];
225 * Structure used by the driver during runtime operation.
227 struct malidp_hw_device
{
228 struct malidp_hw
*hw
;
235 /* main clock for display core */
237 /* pixel clock for display core */
242 u32 output_color_depth
;
244 /* track the device PM state */
247 /* track the SE memory writeback state */
250 /* size of memory used for rotating layers, up to two banks available */
251 u32 rotation_memory
[2];
254 static inline u32
malidp_hw_read(struct malidp_hw_device
*hwdev
, u32 reg
)
256 WARN_ON(hwdev
->pm_suspended
);
257 return readl(hwdev
->regs
+ reg
);
260 static inline void malidp_hw_write(struct malidp_hw_device
*hwdev
,
263 WARN_ON(hwdev
->pm_suspended
);
264 writel(value
, hwdev
->regs
+ reg
);
267 static inline void malidp_hw_setbits(struct malidp_hw_device
*hwdev
,
270 u32 data
= malidp_hw_read(hwdev
, reg
);
273 malidp_hw_write(hwdev
, data
, reg
);
276 static inline void malidp_hw_clearbits(struct malidp_hw_device
*hwdev
,
279 u32 data
= malidp_hw_read(hwdev
, reg
);
282 malidp_hw_write(hwdev
, data
, reg
);
285 static inline u32
malidp_get_block_base(struct malidp_hw_device
*hwdev
,
289 case MALIDP_SE_BLOCK
:
290 return hwdev
->hw
->map
.se_base
;
291 case MALIDP_DC_BLOCK
:
292 return hwdev
->hw
->map
.dc_base
;
298 static inline void malidp_hw_disable_irq(struct malidp_hw_device
*hwdev
,
301 u32 base
= malidp_get_block_base(hwdev
, block
);
303 malidp_hw_clearbits(hwdev
, irq
, base
+ MALIDP_REG_MASKIRQ
);
306 static inline void malidp_hw_enable_irq(struct malidp_hw_device
*hwdev
,
309 u32 base
= malidp_get_block_base(hwdev
, block
);
311 malidp_hw_setbits(hwdev
, irq
, base
+ MALIDP_REG_MASKIRQ
);
314 int malidp_de_irq_init(struct drm_device
*drm
, int irq
);
315 void malidp_se_irq_hw_init(struct malidp_hw_device
*hwdev
);
316 void malidp_de_irq_hw_init(struct malidp_hw_device
*hwdev
);
317 void malidp_de_irq_fini(struct malidp_hw_device
*hwdev
);
318 int malidp_se_irq_init(struct drm_device
*drm
, int irq
);
319 void malidp_se_irq_fini(struct malidp_hw_device
*hwdev
);
321 u8
malidp_hw_get_format_id(const struct malidp_hw_regmap
*map
,
322 u8 layer_id
, u32 format
);
324 static inline u8
malidp_hw_get_pitch_align(struct malidp_hw_device
*hwdev
, bool rotated
)
327 * only hardware that cannot do 8 bytes bus alignments have further
328 * constraints on rotated planes
330 if (hwdev
->hw
->map
.bus_align_bytes
== 8)
333 return hwdev
->hw
->map
.bus_align_bytes
<< (rotated
? 2 : 0);
337 #define FP_1_00000 0x00010000 /* 1.0 */
338 #define FP_0_66667 0x0000AAAA /* 0.6667 = 1/1.5 */
339 #define FP_0_50000 0x00008000 /* 0.5 = 1/2 */
340 #define FP_0_36363 0x00005D17 /* 0.36363 = 1/2.75 */
341 #define FP_0_25000 0x00004000 /* 0.25 = 1/4 */
343 static inline enum malidp_scaling_coeff_set
344 malidp_se_select_coeffs(u32 upscale_factor
)
346 return (upscale_factor
>= FP_1_00000
) ? MALIDP_UPSCALING_COEFFS
:
347 (upscale_factor
>= FP_0_66667
) ? MALIDP_DOWNSCALING_1_5_COEFFS
:
348 (upscale_factor
>= FP_0_50000
) ? MALIDP_DOWNSCALING_2_COEFFS
:
349 (upscale_factor
>= FP_0_36363
) ? MALIDP_DOWNSCALING_2_75_COEFFS
:
350 MALIDP_DOWNSCALING_4_COEFFS
;
359 static inline void malidp_se_set_enh_coeffs(struct malidp_hw_device
*hwdev
)
361 static const s32 enhancer_coeffs
[] = {
362 -8, -8, -8, -8, 128, -8, -8, -8, -8
364 u32 val
= MALIDP_SE_SET_ENH_LIMIT_LOW(MALIDP_SE_ENH_LOW_LEVEL
) |
365 MALIDP_SE_SET_ENH_LIMIT_HIGH(MALIDP_SE_ENH_HIGH_LEVEL
);
366 u32 image_enh
= hwdev
->hw
->map
.se_base
+
367 ((hwdev
->hw
->map
.features
& MALIDP_REGMAP_HAS_CLEARIRQ
) ?
368 0x10 : 0xC) + MALIDP_SE_IMAGE_ENH
;
369 u32 enh_coeffs
= image_enh
+ MALIDP_SE_ENH_COEFF0
;
372 malidp_hw_write(hwdev
, val
, image_enh
);
373 for (i
= 0; i
< ARRAY_SIZE(enhancer_coeffs
); ++i
)
374 malidp_hw_write(hwdev
, enhancer_coeffs
[i
], enh_coeffs
+ i
* 4);
378 * background color components are defined as 12bits values,
379 * they will be shifted right when stored on hardware that
380 * supports only 8bits per channel
382 #define MALIDP_BGND_COLOR_R 0x000
383 #define MALIDP_BGND_COLOR_G 0x000
384 #define MALIDP_BGND_COLOR_B 0x000
386 #define MALIDP_COLORADJ_NUM_COEFFS 12
387 #define MALIDP_COEFFTAB_NUM_COEFFS 64
389 #define MALIDP_GAMMA_LUT_SIZE 4096
391 #define AFBC_MOD_VALID_BITS (AFBC_FORMAT_MOD_BLOCK_SIZE_MASK | \
392 AFBC_FORMAT_MOD_YTR | AFBC_FORMAT_MOD_SPLIT | \
393 AFBC_FORMAT_MOD_SPARSE | AFBC_FORMAT_MOD_CBR | \
394 AFBC_FORMAT_MOD_TILED | AFBC_FORMAT_MOD_SC)
396 #endif /* __MALIDP_HW_H__ */