xref: /openbmc/linux/drivers/gpu/drm/arm/malidp_hw.h (revision a228062c)
1ad49f860SLiviu Dudau /*
2ad49f860SLiviu Dudau  *
3ad49f860SLiviu Dudau  * (C) COPYRIGHT 2013-2016 ARM Limited. All rights reserved.
4ad49f860SLiviu Dudau  *
5ad49f860SLiviu Dudau  * This program is free software and is provided to you under the terms of the
6ad49f860SLiviu Dudau  * GNU General Public License version 2 as published by the Free Software
7ad49f860SLiviu Dudau  * Foundation, and any use by you of this program is subject to the terms
8ad49f860SLiviu Dudau  * of such GNU licence.
9ad49f860SLiviu Dudau  *
10ad49f860SLiviu Dudau  * ARM Mali DP hardware manipulation routines.
11ad49f860SLiviu Dudau  */
12ad49f860SLiviu Dudau 
13ad49f860SLiviu Dudau #ifndef __MALIDP_HW_H__
14ad49f860SLiviu Dudau #define __MALIDP_HW_H__
15ad49f860SLiviu Dudau 
16ad49f860SLiviu Dudau #include <linux/bitops.h>
17ad49f860SLiviu Dudau #include "malidp_regs.h"
18ad49f860SLiviu Dudau 
19ad49f860SLiviu Dudau struct videomode;
20ad49f860SLiviu Dudau struct clk;
21ad49f860SLiviu Dudau 
22ad49f860SLiviu Dudau /* Mali DP IP blocks */
23ad49f860SLiviu Dudau enum {
24ad49f860SLiviu Dudau 	MALIDP_DE_BLOCK = 0,
25ad49f860SLiviu Dudau 	MALIDP_SE_BLOCK,
26ad49f860SLiviu Dudau 	MALIDP_DC_BLOCK
27ad49f860SLiviu Dudau };
28ad49f860SLiviu Dudau 
29ad49f860SLiviu Dudau /* Mali DP layer IDs */
30ad49f860SLiviu Dudau enum {
31ad49f860SLiviu Dudau 	DE_VIDEO1 = BIT(0),
32ad49f860SLiviu Dudau 	DE_GRAPHICS1 = BIT(1),
33ad49f860SLiviu Dudau 	DE_GRAPHICS2 = BIT(2), /* used only in DP500 */
34ad49f860SLiviu Dudau 	DE_VIDEO2 = BIT(3),
35ad49f860SLiviu Dudau 	DE_SMART = BIT(4),
36ad49f860SLiviu Dudau };
37ad49f860SLiviu Dudau 
38ad49f860SLiviu Dudau struct malidp_input_format {
39ad49f860SLiviu Dudau 	u32 format;		/* DRM fourcc */
40ad49f860SLiviu Dudau 	u8 layer;		/* bitmask of layers supporting it */
41ad49f860SLiviu Dudau 	u8 id;			/* used internally */
42ad49f860SLiviu Dudau };
43ad49f860SLiviu Dudau 
44ad49f860SLiviu Dudau #define MALIDP_INVALID_FORMAT_ID	0xff
45ad49f860SLiviu Dudau 
46ad49f860SLiviu Dudau /*
47ad49f860SLiviu Dudau  * hide the differences between register maps
48ad49f860SLiviu Dudau  * by using a common structure to hold the
49ad49f860SLiviu Dudau  * base register offsets
50ad49f860SLiviu Dudau  */
51ad49f860SLiviu Dudau 
52ad49f860SLiviu Dudau struct malidp_irq_map {
53ad49f860SLiviu Dudau 	u32 irq_mask;		/* mask of IRQs that can be enabled in the block */
54ad49f860SLiviu Dudau 	u32 vsync_irq;		/* IRQ bit used for signaling during VSYNC */
55ad49f860SLiviu Dudau };
56ad49f860SLiviu Dudau 
57ad49f860SLiviu Dudau struct malidp_layer {
58ad49f860SLiviu Dudau 	u16 id;			/* layer ID */
59ad49f860SLiviu Dudau 	u16 base;		/* address offset for the register bank */
60ad49f860SLiviu Dudau 	u16 ptr;		/* address offset for the pointer register */
61ad49f860SLiviu Dudau };
62ad49f860SLiviu Dudau 
63ad49f860SLiviu Dudau /* regmap features */
64ad49f860SLiviu Dudau #define MALIDP_REGMAP_HAS_CLEARIRQ	(1 << 0)
65ad49f860SLiviu Dudau 
66ad49f860SLiviu Dudau struct malidp_hw_regmap {
67ad49f860SLiviu Dudau 	/* address offset of the DE register bank */
68ad49f860SLiviu Dudau 	/* is always 0x0000 */
69ad49f860SLiviu Dudau 	/* address offset of the SE registers bank */
70ad49f860SLiviu Dudau 	const u16 se_base;
71ad49f860SLiviu Dudau 	/* address offset of the DC registers bank */
72ad49f860SLiviu Dudau 	const u16 dc_base;
73ad49f860SLiviu Dudau 
74ad49f860SLiviu Dudau 	/* address offset for the output depth register */
75ad49f860SLiviu Dudau 	const u16 out_depth_base;
76ad49f860SLiviu Dudau 
77ad49f860SLiviu Dudau 	/* bitmap with register map features */
78ad49f860SLiviu Dudau 	const u8 features;
79ad49f860SLiviu Dudau 
80ad49f860SLiviu Dudau 	/* list of supported layers */
81ad49f860SLiviu Dudau 	const u8 n_layers;
82ad49f860SLiviu Dudau 	const struct malidp_layer *layers;
83ad49f860SLiviu Dudau 
84ad49f860SLiviu Dudau 	const struct malidp_irq_map de_irq_map;
85ad49f860SLiviu Dudau 	const struct malidp_irq_map se_irq_map;
86ad49f860SLiviu Dudau 	const struct malidp_irq_map dc_irq_map;
87ad49f860SLiviu Dudau 
88ad49f860SLiviu Dudau 	/* list of supported input formats for each layer */
89ad49f860SLiviu Dudau 	const struct malidp_input_format *input_formats;
90ad49f860SLiviu Dudau 	const u8 n_input_formats;
91a228062cSBrian Starkey 
92a228062cSBrian Starkey 	/* pitch alignment requirement in bytes */
93a228062cSBrian Starkey 	const u8 bus_align_bytes;
94ad49f860SLiviu Dudau };
95ad49f860SLiviu Dudau 
96ad49f860SLiviu Dudau struct malidp_hw_device {
97ad49f860SLiviu Dudau 	const struct malidp_hw_regmap map;
98ad49f860SLiviu Dudau 	void __iomem *regs;
99ad49f860SLiviu Dudau 
100ad49f860SLiviu Dudau 	/* APB clock */
101ad49f860SLiviu Dudau 	struct clk *pclk;
102ad49f860SLiviu Dudau 	/* AXI clock */
103ad49f860SLiviu Dudau 	struct clk *aclk;
104ad49f860SLiviu Dudau 	/* main clock for display core */
105ad49f860SLiviu Dudau 	struct clk *mclk;
106ad49f860SLiviu Dudau 	/* pixel clock for display core */
107ad49f860SLiviu Dudau 	struct clk *pxlclk;
108ad49f860SLiviu Dudau 
109ad49f860SLiviu Dudau 	/*
110ad49f860SLiviu Dudau 	 * Validate the driver instance against the hardware bits
111ad49f860SLiviu Dudau 	 */
112ad49f860SLiviu Dudau 	int (*query_hw)(struct malidp_hw_device *hwdev);
113ad49f860SLiviu Dudau 
114ad49f860SLiviu Dudau 	/*
115ad49f860SLiviu Dudau 	 * Set the hardware into config mode, ready to accept mode changes
116ad49f860SLiviu Dudau 	 */
117ad49f860SLiviu Dudau 	void (*enter_config_mode)(struct malidp_hw_device *hwdev);
118ad49f860SLiviu Dudau 
119ad49f860SLiviu Dudau 	/*
120ad49f860SLiviu Dudau 	 * Tell hardware to exit configuration mode
121ad49f860SLiviu Dudau 	 */
122ad49f860SLiviu Dudau 	void (*leave_config_mode)(struct malidp_hw_device *hwdev);
123ad49f860SLiviu Dudau 
124ad49f860SLiviu Dudau 	/*
125ad49f860SLiviu Dudau 	 * Query if hardware is in configuration mode
126ad49f860SLiviu Dudau 	 */
127ad49f860SLiviu Dudau 	bool (*in_config_mode)(struct malidp_hw_device *hwdev);
128ad49f860SLiviu Dudau 
129ad49f860SLiviu Dudau 	/*
130ad49f860SLiviu Dudau 	 * Set configuration valid flag for hardware parameters that can
131ad49f860SLiviu Dudau 	 * be changed outside the configuration mode. Hardware will use
132ad49f860SLiviu Dudau 	 * the new settings when config valid is set after the end of the
133ad49f860SLiviu Dudau 	 * current buffer scanout
134ad49f860SLiviu Dudau 	 */
135ad49f860SLiviu Dudau 	void (*set_config_valid)(struct malidp_hw_device *hwdev);
136ad49f860SLiviu Dudau 
137ad49f860SLiviu Dudau 	/*
138ad49f860SLiviu Dudau 	 * Set a new mode in hardware. Requires the hardware to be in
139ad49f860SLiviu Dudau 	 * configuration mode before this function is called.
140ad49f860SLiviu Dudau 	 */
141ad49f860SLiviu Dudau 	void (*modeset)(struct malidp_hw_device *hwdev, struct videomode *m);
142ad49f860SLiviu Dudau 
143ad49f860SLiviu Dudau 	/*
144ad49f860SLiviu Dudau 	 * Calculate the required rotation memory given the active area
145ad49f860SLiviu Dudau 	 * and the buffer format.
146ad49f860SLiviu Dudau 	 */
147ad49f860SLiviu Dudau 	int (*rotmem_required)(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt);
148ad49f860SLiviu Dudau 
149ad49f860SLiviu Dudau 	u8 features;
150ad49f860SLiviu Dudau 
151ad49f860SLiviu Dudau 	u8 min_line_size;
152ad49f860SLiviu Dudau 	u16 max_line_size;
153ad49f860SLiviu Dudau 
154ad49f860SLiviu Dudau 	/* size of memory used for rotating layers, up to two banks available */
155ad49f860SLiviu Dudau 	u32 rotation_memory[2];
156ad49f860SLiviu Dudau };
157ad49f860SLiviu Dudau 
158ad49f860SLiviu Dudau /* Supported variants of the hardware */
159ad49f860SLiviu Dudau enum {
160ad49f860SLiviu Dudau 	MALIDP_500 = 0,
161ad49f860SLiviu Dudau 	MALIDP_550,
162ad49f860SLiviu Dudau 	MALIDP_650,
163ad49f860SLiviu Dudau 	/* keep the next entry last */
164ad49f860SLiviu Dudau 	MALIDP_MAX_DEVICES
165ad49f860SLiviu Dudau };
166ad49f860SLiviu Dudau 
167ad49f860SLiviu Dudau extern const struct malidp_hw_device malidp_device[MALIDP_MAX_DEVICES];
168ad49f860SLiviu Dudau 
169ad49f860SLiviu Dudau static inline u32 malidp_hw_read(struct malidp_hw_device *hwdev, u32 reg)
170ad49f860SLiviu Dudau {
171ad49f860SLiviu Dudau 	return readl(hwdev->regs + reg);
172ad49f860SLiviu Dudau }
173ad49f860SLiviu Dudau 
174ad49f860SLiviu Dudau static inline void malidp_hw_write(struct malidp_hw_device *hwdev,
175ad49f860SLiviu Dudau 				   u32 value, u32 reg)
176ad49f860SLiviu Dudau {
177ad49f860SLiviu Dudau 	writel(value, hwdev->regs + reg);
178ad49f860SLiviu Dudau }
179ad49f860SLiviu Dudau 
180ad49f860SLiviu Dudau static inline void malidp_hw_setbits(struct malidp_hw_device *hwdev,
181ad49f860SLiviu Dudau 				     u32 mask, u32 reg)
182ad49f860SLiviu Dudau {
183ad49f860SLiviu Dudau 	u32 data = malidp_hw_read(hwdev, reg);
184ad49f860SLiviu Dudau 
185ad49f860SLiviu Dudau 	data |= mask;
186ad49f860SLiviu Dudau 	malidp_hw_write(hwdev, data, reg);
187ad49f860SLiviu Dudau }
188ad49f860SLiviu Dudau 
189ad49f860SLiviu Dudau static inline void malidp_hw_clearbits(struct malidp_hw_device *hwdev,
190ad49f860SLiviu Dudau 				       u32 mask, u32 reg)
191ad49f860SLiviu Dudau {
192ad49f860SLiviu Dudau 	u32 data = malidp_hw_read(hwdev, reg);
193ad49f860SLiviu Dudau 
194ad49f860SLiviu Dudau 	data &= ~mask;
195ad49f860SLiviu Dudau 	malidp_hw_write(hwdev, data, reg);
196ad49f860SLiviu Dudau }
197ad49f860SLiviu Dudau 
198ad49f860SLiviu Dudau static inline u32 malidp_get_block_base(struct malidp_hw_device *hwdev,
199ad49f860SLiviu Dudau 					u8 block)
200ad49f860SLiviu Dudau {
201ad49f860SLiviu Dudau 	switch (block) {
202ad49f860SLiviu Dudau 	case MALIDP_SE_BLOCK:
203ad49f860SLiviu Dudau 		return hwdev->map.se_base;
204ad49f860SLiviu Dudau 	case MALIDP_DC_BLOCK:
205ad49f860SLiviu Dudau 		return hwdev->map.dc_base;
206ad49f860SLiviu Dudau 	}
207ad49f860SLiviu Dudau 
208ad49f860SLiviu Dudau 	return 0;
209ad49f860SLiviu Dudau }
210ad49f860SLiviu Dudau 
211ad49f860SLiviu Dudau static inline void malidp_hw_disable_irq(struct malidp_hw_device *hwdev,
212ad49f860SLiviu Dudau 					 u8 block, u32 irq)
213ad49f860SLiviu Dudau {
214ad49f860SLiviu Dudau 	u32 base = malidp_get_block_base(hwdev, block);
215ad49f860SLiviu Dudau 
216ad49f860SLiviu Dudau 	malidp_hw_clearbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
217ad49f860SLiviu Dudau }
218ad49f860SLiviu Dudau 
219ad49f860SLiviu Dudau static inline void malidp_hw_enable_irq(struct malidp_hw_device *hwdev,
220ad49f860SLiviu Dudau 					u8 block, u32 irq)
221ad49f860SLiviu Dudau {
222ad49f860SLiviu Dudau 	u32 base = malidp_get_block_base(hwdev, block);
223ad49f860SLiviu Dudau 
224ad49f860SLiviu Dudau 	malidp_hw_setbits(hwdev, irq, base + MALIDP_REG_MASKIRQ);
225ad49f860SLiviu Dudau }
226ad49f860SLiviu Dudau 
227ad49f860SLiviu Dudau int malidp_de_irq_init(struct drm_device *drm, int irq);
228ad49f860SLiviu Dudau void malidp_de_irq_fini(struct drm_device *drm);
229ad49f860SLiviu Dudau int malidp_se_irq_init(struct drm_device *drm, int irq);
230ad49f860SLiviu Dudau void malidp_se_irq_fini(struct drm_device *drm);
231ad49f860SLiviu Dudau 
232ad49f860SLiviu Dudau u8 malidp_hw_get_format_id(const struct malidp_hw_regmap *map,
233ad49f860SLiviu Dudau 			   u8 layer_id, u32 format);
234ad49f860SLiviu Dudau 
235a228062cSBrian Starkey static inline bool malidp_hw_pitch_valid(struct malidp_hw_device *hwdev,
236a228062cSBrian Starkey 					 unsigned int pitch)
237a228062cSBrian Starkey {
238a228062cSBrian Starkey 	return !(pitch & (hwdev->map.bus_align_bytes - 1));
239a228062cSBrian Starkey }
240a228062cSBrian Starkey 
241ad49f860SLiviu Dudau /*
242ad49f860SLiviu Dudau  * background color components are defined as 12bits values,
243ad49f860SLiviu Dudau  * they will be shifted right when stored on hardware that
244ad49f860SLiviu Dudau  * supports only 8bits per channel
245ad49f860SLiviu Dudau  */
246ad49f860SLiviu Dudau #define MALIDP_BGND_COLOR_R		0x000
247ad49f860SLiviu Dudau #define MALIDP_BGND_COLOR_G		0x000
248ad49f860SLiviu Dudau #define MALIDP_BGND_COLOR_B		0x000
249ad49f860SLiviu Dudau 
250ad49f860SLiviu Dudau #endif  /* __MALIDP_HW_H__ */
251