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 */
38 struct malidp_format_id {
39 u32 format; /* DRM fourcc */
40 u8 layer; /* bitmask of layers supporting it */
41 u8 id; /* used internally */
44 #define MALIDP_INVALID_FORMAT_ID 0xff
47 * hide the differences between register maps
48 * by using a common structure to hold the
49 * base register offsets
52 struct malidp_irq_map {
53 u32 irq_mask; /* mask of IRQs that can be enabled in the block */
54 u32 vsync_irq; /* IRQ bit used for signaling during VSYNC */
58 u16 id; /* layer ID */
59 u16 base; /* address offset for the register bank */
60 u16 ptr; /* address offset for the pointer register */
61 u16 stride_offset; /* offset to the first stride register. */
62 s16 yuv2rgb_offset; /* offset to the YUV->RGB matrix entries */
65 enum malidp_scaling_coeff_set {
66 MALIDP_UPSCALING_COEFFS = 1,
67 MALIDP_DOWNSCALING_1_5_COEFFS = 2,
68 MALIDP_DOWNSCALING_2_COEFFS = 3,
69 MALIDP_DOWNSCALING_2_75_COEFFS = 4,
70 MALIDP_DOWNSCALING_4_COEFFS = 5,
73 struct malidp_se_config {
75 u8 enhancer_enable : 1;
80 u16 output_w, output_h;
81 u32 h_init_phase, h_delta_phase;
82 u32 v_init_phase, v_delta_phase;
86 #define MALIDP_REGMAP_HAS_CLEARIRQ (1 << 0)
88 struct malidp_hw_regmap {
89 /* address offset of the DE register bank */
90 /* is always 0x0000 */
91 /* address offset of the DE coefficients registers */
92 const u16 coeffs_base;
93 /* address offset of the SE registers bank */
95 /* address offset of the DC registers bank */
98 /* address offset for the output depth register */
99 const u16 out_depth_base;
101 /* bitmap with register map features */
104 /* list of supported layers */
106 const struct malidp_layer *layers;
108 const struct malidp_irq_map de_irq_map;
109 const struct malidp_irq_map se_irq_map;
110 const struct malidp_irq_map dc_irq_map;
112 /* list of supported pixel formats for each layer */
113 const struct malidp_format_id *pixel_formats;
114 const u8 n_pixel_formats;
116 /* pitch alignment requirement in bytes */
117 const u8 bus_align_bytes;
120 /* device features */
121 /* Unlike DP550/650, DP500 has 3 stride registers in its video layer. */
122 #define MALIDP_DEVICE_LV_HAS_3_STRIDES BIT(0)
124 struct malidp_hw_device;
127 * Static structure containing hardware specific data and pointers to
128 * functions that behave differently between various versions of the IP.
131 const struct malidp_hw_regmap map;
134 * Validate the driver instance against the hardware bits
136 int (*query_hw)(struct malidp_hw_device *hwdev);
139 * Set the hardware into config mode, ready to accept mode changes
141 void (*enter_config_mode)(struct malidp_hw_device *hwdev);
144 * Tell hardware to exit configuration mode
146 void (*leave_config_mode)(struct malidp_hw_device *hwdev);
149 * Query if hardware is in configuration mode
151 bool (*in_config_mode)(struct malidp_hw_device *hwdev);
154 * Set configuration valid flag for hardware parameters that can
155 * be changed outside the configuration mode. Hardware will use
156 * the new settings when config valid is set after the end of the
157 * current buffer scanout
159 void (*set_config_valid)(struct malidp_hw_device *hwdev);
162 * Set a new mode in hardware. Requires the hardware to be in
163 * configuration mode before this function is called.
165 void (*modeset)(struct malidp_hw_device *hwdev, struct videomode *m);
168 * Calculate the required rotation memory given the active area
169 * and the buffer format.
171 int (*rotmem_required)(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt);
173 int (*se_set_scaling_coeffs)(struct malidp_hw_device *hwdev,
174 struct malidp_se_config *se_config,
175 struct malidp_se_config *old_config);
177 long (*se_calc_mclk)(struct malidp_hw_device *hwdev,
178 struct malidp_se_config *se_config,
179 struct videomode *vm);
184 /* Supported variants of the hardware */
189 /* keep the next entry last */
193 extern const struct malidp_hw malidp_device[MALIDP_MAX_DEVICES];
196 * Structure used by the driver during runtime operation.
198 struct malidp_hw_device {
199 struct malidp_hw *hw;
206 /* main clock for display core */
208 /* pixel clock for display core */
214 /* track the device PM state */
217 /* size of memory used for rotating layers, up to two banks available */
218 u32 rotation_memory[2];
221 static inline u32 malidp_hw_read(struct malidp_hw_device *hwdev, u32 reg)
223 WARN_ON(hwdev->pm_suspended);
224 return readl(hwdev->regs + reg);
227 static inline void malidp_hw_write(struct malidp_hw_device *hwdev,
230 WARN_ON(hwdev->pm_suspended);
231 writel(value, hwdev->regs + reg);
234 static inline void malidp_hw_setbits(struct malidp_hw_device *hwdev,
237 u32 data = malidp_hw_read(hwdev, reg);
240 malidp_hw_write(hwdev, data, reg);
243 static inline void malidp_hw_clearbits(struct malidp_hw_device *hwdev,
246 u32 data = malidp_hw_read(hwdev, reg);
249 malidp_hw_write(hwdev, data, reg);
252 static inline u32 malidp_get_block_base(struct malidp_hw_device *hwdev,
256 case MALIDP_SE_BLOCK:
257 return hwdev->hw->map.se_base;
258 case MALIDP_DC_BLOCK:
259 return hwdev->hw->map.dc_base;
265 static inline void malidp_hw_disable_irq(struct malidp_hw_device *hwdev,
268 u32 base = malidp_get_block_base(hwdev, block);
270 malidp_hw_clearbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
273 static inline void malidp_hw_enable_irq(struct malidp_hw_device *hwdev,
276 u32 base = malidp_get_block_base(hwdev, block);
278 malidp_hw_setbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
281 int malidp_de_irq_init(struct drm_device *drm, int irq);
282 void malidp_de_irq_fini(struct drm_device *drm);
283 int malidp_se_irq_init(struct drm_device *drm, int irq);
284 void malidp_se_irq_fini(struct drm_device *drm);
286 u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
287 u8 layer_id, u32 format);
289 static inline u8 malidp_hw_get_pitch_align(struct malidp_hw_device *hwdev, bool rotated)
292 * only hardware that cannot do 8 bytes bus alignments have further
293 * constraints on rotated planes
295 if (hwdev->hw->map.bus_align_bytes == 8)
298 return hwdev->hw->map.bus_align_bytes << (rotated ? 2 : 0);
302 #define FP_1_00000 0x00010000 /* 1.0 */
303 #define FP_0_66667 0x0000AAAA /* 0.6667 = 1/1.5 */
304 #define FP_0_50000 0x00008000 /* 0.5 = 1/2 */
305 #define FP_0_36363 0x00005D17 /* 0.36363 = 1/2.75 */
306 #define FP_0_25000 0x00004000 /* 0.25 = 1/4 */
308 static inline enum malidp_scaling_coeff_set
309 malidp_se_select_coeffs(u32 upscale_factor)
311 return (upscale_factor >= FP_1_00000) ? MALIDP_UPSCALING_COEFFS :
312 (upscale_factor >= FP_0_66667) ? MALIDP_DOWNSCALING_1_5_COEFFS :
313 (upscale_factor >= FP_0_50000) ? MALIDP_DOWNSCALING_2_COEFFS :
314 (upscale_factor >= FP_0_36363) ? MALIDP_DOWNSCALING_2_75_COEFFS :
315 MALIDP_DOWNSCALING_4_COEFFS;
324 static inline void malidp_se_set_enh_coeffs(struct malidp_hw_device *hwdev)
326 static const s32 enhancer_coeffs[] = {
327 -8, -8, -8, -8, 128, -8, -8, -8, -8
329 u32 val = MALIDP_SE_SET_ENH_LIMIT_LOW(MALIDP_SE_ENH_LOW_LEVEL) |
330 MALIDP_SE_SET_ENH_LIMIT_HIGH(MALIDP_SE_ENH_HIGH_LEVEL);
331 u32 image_enh = hwdev->hw->map.se_base +
332 ((hwdev->hw->map.features & MALIDP_REGMAP_HAS_CLEARIRQ) ?
333 0x10 : 0xC) + MALIDP_SE_IMAGE_ENH;
334 u32 enh_coeffs = image_enh + MALIDP_SE_ENH_COEFF0;
337 malidp_hw_write(hwdev, val, image_enh);
338 for (i = 0; i < ARRAY_SIZE(enhancer_coeffs); ++i)
339 malidp_hw_write(hwdev, enhancer_coeffs[i], enh_coeffs + i * 4);
343 * background color components are defined as 12bits values,
344 * they will be shifted right when stored on hardware that
345 * supports only 8bits per channel
347 #define MALIDP_BGND_COLOR_R 0x000
348 #define MALIDP_BGND_COLOR_G 0x000
349 #define MALIDP_BGND_COLOR_B 0x000
351 #define MALIDP_COLORADJ_NUM_COEFFS 12
352 #define MALIDP_COEFFTAB_NUM_COEFFS 64
354 #define MALIDP_GAMMA_LUT_SIZE 4096
356 #endif /* __MALIDP_HW_H__ */