xref: /rk3399_rockchip-uboot/include/video.h (revision 1acafc73bfc7535c185f321012ac70821471b816)
1167c5898Swdenk /*
2*1acafc73SSimon Glass  * Video uclass and legacy implementation
3*1acafc73SSimon Glass  *
4*1acafc73SSimon Glass  * Copyright (c) 2015 Google, Inc
5*1acafc73SSimon Glass  *
6*1acafc73SSimon Glass  * MPC823 Video Controller
7*1acafc73SSimon Glass  * =======================
8*1acafc73SSimon Glass  * (C) 2000 by Paolo Scaffardi (arsenio@tin.it)
9*1acafc73SSimon Glass  * AIRVENT SAM s.p.a - RIMINI(ITALY)
10*1acafc73SSimon Glass  *
11167c5898Swdenk  */
12167c5898Swdenk 
13167c5898Swdenk #ifndef _VIDEO_H_
14167c5898Swdenk #define _VIDEO_H_
15167c5898Swdenk 
16*1acafc73SSimon Glass #ifdef CONFIG_DM_VIDEO
17*1acafc73SSimon Glass 
18*1acafc73SSimon Glass #include <stdio_dev.h>
19*1acafc73SSimon Glass 
20*1acafc73SSimon Glass struct video_uc_platdata {
21*1acafc73SSimon Glass 	uint align;
22*1acafc73SSimon Glass 	uint size;
23*1acafc73SSimon Glass 	ulong base;
24*1acafc73SSimon Glass };
25*1acafc73SSimon Glass 
26*1acafc73SSimon Glass /*
27*1acafc73SSimon Glass  * Bits per pixel selector. Each value n is such that the bits-per-pixel is
28*1acafc73SSimon Glass  * 2 ^ n
29*1acafc73SSimon Glass  */
30*1acafc73SSimon Glass enum video_log2_bpp {
31*1acafc73SSimon Glass 	VIDEO_BPP1	= 0,
32*1acafc73SSimon Glass 	VIDEO_BPP2,
33*1acafc73SSimon Glass 	VIDEO_BPP4,
34*1acafc73SSimon Glass 	VIDEO_BPP8,
35*1acafc73SSimon Glass 	VIDEO_BPP16,
36*1acafc73SSimon Glass 	VIDEO_BPP32,
37*1acafc73SSimon Glass };
38*1acafc73SSimon Glass 
39*1acafc73SSimon Glass /*
40*1acafc73SSimon Glass  * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
41*1acafc73SSimon Glass  * brackets to allow multiplication by fractional pixels.
42*1acafc73SSimon Glass  */
43*1acafc73SSimon Glass #define VNBYTES(bpix)	(1 << (bpix)) / 8
44*1acafc73SSimon Glass 
45*1acafc73SSimon Glass #define VNBITS(bpix)	(1 << (bpix))
46*1acafc73SSimon Glass 
47*1acafc73SSimon Glass /**
48*1acafc73SSimon Glass  * struct video_priv - Device information used by the video uclass
49*1acafc73SSimon Glass  *
50*1acafc73SSimon Glass  * @xsize:	Number of pixel columns (e.g. 1366)
51*1acafc73SSimon Glass  * @ysize:	Number of pixels rows (e.g.. 768)
52*1acafc73SSimon Glass  * @tor:	Display rotation (0=none, 1=90 degrees clockwise, etc.)
53*1acafc73SSimon Glass  * @bpix:	Encoded bits per pixel
54*1acafc73SSimon Glass  * @fb:		Frame buffer
55*1acafc73SSimon Glass  * @fb_size:	Frame buffer size
56*1acafc73SSimon Glass  * @line_length:	Length of each frame buffer line, in bytes
57*1acafc73SSimon Glass  * @colour_fg:	Foreground colour (pixel value)
58*1acafc73SSimon Glass  * @colour_bg:	Background colour (pixel value)
59*1acafc73SSimon Glass  * @flush_dcache:	true to enable flushing of the data cache after
60*1acafc73SSimon Glass  *		the LCD is updated
61*1acafc73SSimon Glass  * @cmap:	Colour map for 8-bit-per-pixel displays
62*1acafc73SSimon Glass  */
63*1acafc73SSimon Glass struct video_priv {
64*1acafc73SSimon Glass 	/* Things set up by the driver: */
65*1acafc73SSimon Glass 	ushort xsize;
66*1acafc73SSimon Glass 	ushort ysize;
67*1acafc73SSimon Glass 	ushort rot;
68*1acafc73SSimon Glass 	enum video_log2_bpp bpix;
69*1acafc73SSimon Glass 
70*1acafc73SSimon Glass 	/*
71*1acafc73SSimon Glass 	 * Things that are private to the uclass: don't use these in the
72*1acafc73SSimon Glass 	 * driver
73*1acafc73SSimon Glass 	 */
74*1acafc73SSimon Glass 	void *fb;
75*1acafc73SSimon Glass 	int fb_size;
76*1acafc73SSimon Glass 	int line_length;
77*1acafc73SSimon Glass 	int colour_fg;
78*1acafc73SSimon Glass 	int colour_bg;
79*1acafc73SSimon Glass 	bool flush_dcache;
80*1acafc73SSimon Glass 	ushort *cmap;
81*1acafc73SSimon Glass };
82*1acafc73SSimon Glass 
83*1acafc73SSimon Glass /* Placeholder - there are no video operations at present */
84*1acafc73SSimon Glass struct video_ops {
85*1acafc73SSimon Glass };
86*1acafc73SSimon Glass 
87*1acafc73SSimon Glass #define video_get_ops(dev)        ((struct video_ops *)(dev)->driver->ops)
88*1acafc73SSimon Glass 
89*1acafc73SSimon Glass /**
90*1acafc73SSimon Glass  * video_reserve() - Reserve frame-buffer memory for video devices
91*1acafc73SSimon Glass  *
92*1acafc73SSimon Glass  * Note: This function is for internal use.
93*1acafc73SSimon Glass  *
94*1acafc73SSimon Glass  * This uses the uclass platdata's @size and @align members to figure out
95*1acafc73SSimon Glass  * a size and position for each frame buffer as part of the pre-relocation
96*1acafc73SSimon Glass  * process of determining the post-relocation memory layout.
97*1acafc73SSimon Glass  *
98*1acafc73SSimon Glass  * gd->video_top is set to the initial value of *@addrp and gd->video_bottom
99*1acafc73SSimon Glass  * is set to the final value.
100*1acafc73SSimon Glass  *
101*1acafc73SSimon Glass  * @addrp:	On entry, the top of available memory. On exit, the new top,
102*1acafc73SSimon Glass  *		after allocating the required memory.
103*1acafc73SSimon Glass  * @return 0
104*1acafc73SSimon Glass  */
105*1acafc73SSimon Glass int video_reserve(ulong *addrp);
106*1acafc73SSimon Glass 
107*1acafc73SSimon Glass /**
108*1acafc73SSimon Glass  * video_sync() - Sync a device's frame buffer with its hardware
109*1acafc73SSimon Glass  *
110*1acafc73SSimon Glass  * Some frame buffers are cached or have a secondary frame buffer. This
111*1acafc73SSimon Glass  * function syncs these up so that the current contents of the U-Boot frame
112*1acafc73SSimon Glass  * buffer are displayed to the user.
113*1acafc73SSimon Glass  *
114*1acafc73SSimon Glass  * @dev:	Device to sync
115*1acafc73SSimon Glass  */
116*1acafc73SSimon Glass void video_sync(struct udevice *vid);
117*1acafc73SSimon Glass 
118*1acafc73SSimon Glass /**
119*1acafc73SSimon Glass  * video_sync_all() - Sync all devices' frame buffers with there hardware
120*1acafc73SSimon Glass  *
121*1acafc73SSimon Glass  * This calls video_sync() on all active video devices.
122*1acafc73SSimon Glass  */
123*1acafc73SSimon Glass void video_sync_all(void);
124*1acafc73SSimon Glass 
125*1acafc73SSimon Glass /**
126*1acafc73SSimon Glass  * video_bmp_display() - Display a BMP file
127*1acafc73SSimon Glass  *
128*1acafc73SSimon Glass  * @dev:	Device to display the bitmap on
129*1acafc73SSimon Glass  * @bmp_image:	Address of bitmap image to display
130*1acafc73SSimon Glass  * @x:		X position in pixels from the left
131*1acafc73SSimon Glass  * @y:		Y position in pixels from the top
132*1acafc73SSimon Glass  * @align:	true to adjust the coordinates to centre the image. If false
133*1acafc73SSimon Glass  *		the coordinates are used as is. If true:
134*1acafc73SSimon Glass  *
135*1acafc73SSimon Glass  *		- if a coordinate is 0x7fff then the image will be centred in
136*1acafc73SSimon Glass  *		  that direction
137*1acafc73SSimon Glass  *		- if a coordinate is -ve then it will be offset to the
138*1acafc73SSimon Glass  *		  left/top of the centre by that many pixels
139*1acafc73SSimon Glass  *		- if a coordinate is positive it will be used unchnaged.
140*1acafc73SSimon Glass  * @return 0 if OK, -ve on error
141*1acafc73SSimon Glass  */
142*1acafc73SSimon Glass int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
143*1acafc73SSimon Glass 		      bool align);
144*1acafc73SSimon Glass 
145*1acafc73SSimon Glass /**
146*1acafc73SSimon Glass  * video_get_xsize() - Get the width of the display in pixels
147*1acafc73SSimon Glass  *
148*1acafc73SSimon Glass  * @dev:	Device to check
149*1acafc73SSimon Glass  * @return device frame buffer width in pixels
150*1acafc73SSimon Glass  */
151*1acafc73SSimon Glass int video_get_xsize(struct udevice *dev);
152*1acafc73SSimon Glass 
153*1acafc73SSimon Glass /**
154*1acafc73SSimon Glass  * video_get_ysize() - Get the height of the display in pixels
155*1acafc73SSimon Glass  *
156*1acafc73SSimon Glass  * @dev:	Device to check
157*1acafc73SSimon Glass  * @return device frame buffer height in pixels
158*1acafc73SSimon Glass  */
159*1acafc73SSimon Glass int video_get_ysize(struct udevice *dev);
160*1acafc73SSimon Glass 
161*1acafc73SSimon Glass #endif /* CONFIG_DM_VIDEO */
162*1acafc73SSimon Glass 
163*1acafc73SSimon Glass #ifndef CONFIG_DM_VIDEO
164*1acafc73SSimon Glass 
165167c5898Swdenk /* Video functions */
166167c5898Swdenk 
167709ea543SSimon Glass struct stdio_dev;
168709ea543SSimon Glass 
169167c5898Swdenk int	video_init(void *videobase);
170709ea543SSimon Glass void	video_putc(struct stdio_dev *dev, const char c);
171709ea543SSimon Glass void	video_puts(struct stdio_dev *dev, const char *s);
172167c5898Swdenk 
173f674f7cfSStefan Reinauer /**
174f674f7cfSStefan Reinauer  * Display a BMP format bitmap on the screen
175f674f7cfSStefan Reinauer  *
176f674f7cfSStefan Reinauer  * @param bmp_image	Address of BMP image
177f674f7cfSStefan Reinauer  * @param x		X position to draw image
178f674f7cfSStefan Reinauer  * @param y		Y position to draw image
179f674f7cfSStefan Reinauer  */
180f674f7cfSStefan Reinauer int video_display_bitmap(ulong bmp_image, int x, int y);
181f674f7cfSStefan Reinauer 
182f674f7cfSStefan Reinauer /**
183f674f7cfSStefan Reinauer  * Get the width of the screen in pixels
184f674f7cfSStefan Reinauer  *
185f674f7cfSStefan Reinauer  * @return width of screen in pixels
186f674f7cfSStefan Reinauer  */
187f674f7cfSStefan Reinauer int video_get_pixel_width(void);
188f674f7cfSStefan Reinauer 
189f674f7cfSStefan Reinauer /**
190f674f7cfSStefan Reinauer  * Get the height of the screen in pixels
191f674f7cfSStefan Reinauer  *
192f674f7cfSStefan Reinauer  * @return height of screen in pixels
193f674f7cfSStefan Reinauer  */
194f674f7cfSStefan Reinauer int video_get_pixel_height(void);
195f674f7cfSStefan Reinauer 
196f674f7cfSStefan Reinauer /**
197f674f7cfSStefan Reinauer  * Get the number of text lines/rows on the screen
198f674f7cfSStefan Reinauer  *
199f674f7cfSStefan Reinauer  * @return number of rows
200f674f7cfSStefan Reinauer  */
201f674f7cfSStefan Reinauer int video_get_screen_rows(void);
202f674f7cfSStefan Reinauer 
203f674f7cfSStefan Reinauer /**
204f674f7cfSStefan Reinauer  * Get the number of text columns on the screen
205f674f7cfSStefan Reinauer  *
206f674f7cfSStefan Reinauer  * @return number of columns
207f674f7cfSStefan Reinauer  */
208f674f7cfSStefan Reinauer int video_get_screen_columns(void);
209f674f7cfSStefan Reinauer 
210f674f7cfSStefan Reinauer /**
211f674f7cfSStefan Reinauer  * Set the position of the text cursor
212f674f7cfSStefan Reinauer  *
213f674f7cfSStefan Reinauer  * @param col	Column to place cursor (0 = left side)
214f674f7cfSStefan Reinauer  * @param row	Row to place cursor (0 = top line)
215f674f7cfSStefan Reinauer  */
216f674f7cfSStefan Reinauer void video_position_cursor(unsigned col, unsigned row);
217f674f7cfSStefan Reinauer 
218f674f7cfSStefan Reinauer /* Clear the display */
219f674f7cfSStefan Reinauer void video_clear(void);
220f674f7cfSStefan Reinauer 
221b26354cfSHeiko Schocher #if defined(CONFIG_FORMIKE)
222b26354cfSHeiko Schocher int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs,
223b26354cfSHeiko Schocher 	unsigned int max_hz, unsigned int spi_mode);
224b26354cfSHeiko Schocher #endif
225fc1a79d9SHeiko Schocher #if defined(CONFIG_LG4573)
226fc1a79d9SHeiko Schocher int lg4573_spi_startup(unsigned int bus, unsigned int cs,
227fc1a79d9SHeiko Schocher 	unsigned int max_hz, unsigned int spi_mode);
228fc1a79d9SHeiko Schocher #endif
229*1acafc73SSimon Glass 
230*1acafc73SSimon Glass #endif /* CONFIG_DM_VIDEO */
231*1acafc73SSimon Glass 
232167c5898Swdenk #endif
233