1515#include "drv_fb.h"
1616#include "mmu.h"
1717
18- #define LCD_WIDTH (640 )
18+ #define LCD_WIDTH (800 )
1919#define LCD_HEIGHT (480)
2020#define LCD_DEPTH (32)
21+ #define LCD_BPP (32)
2122
2223#define TAG_ALLOCATE_BUFFER 0x00040001
2324#define TAG_SET_PHYS_WIDTH_HEIGHT 0x00048003
2829#define TAG_SET_VIRT_OFFSET 0x00048009
2930#define TAG_END 0x00000000
3031
32+
33+ enum {
34+ MBOX_TAG_FB_GET_GPIOVIRT = 0x00040010 ,
35+ MBOX_TAG_FB_ALLOCATE_BUFFER = 0x00040001 ,
36+ MBOX_TAG_FB_RELEASE_BUFFER = 0x00048001 ,
37+ MBOX_TAG_FB_BLANK_SCREEN = 0x00040002 ,
38+ MBOX_TAG_FB_GET_PHYS_WH = 0x00040003 ,
39+ MBOX_TAG_FB_TEST_PHYS_WH = 0x00044003 ,
40+ MBOX_TAG_FB_SET_PHYS_WH = 0x00048003 ,
41+ MBOX_TAG_FB_GET_VIRT_WH = 0x00040004 ,
42+ MBOX_TAG_FB_TEST_VIRT_WH = 0x00044004 ,
43+ MBOX_TAG_FB_SET_VIRT_WH = 0x00048004 ,
44+ MBOX_TAG_FB_GET_DEPTH = 0x00040005 ,
45+ MBOX_TAG_FB_TEST_DEPTH = 0x00044005 ,
46+ MBOX_TAG_FB_SET_DEPTH = 0x00048005 ,
47+ MBOX_TAG_FB_GET_PIXEL_ORDER = 0x00040006 ,
48+ MBOX_TAG_FB_TEST_PIXEL_ORDER = 0x00044006 ,
49+ MBOX_TAG_FB_SET_PIXEL_ORDER = 0x00048006 ,
50+ MBOX_TAG_FB_GET_ALPHA_MODE = 0x00040007 ,
51+ MBOX_TAG_FB_TEST_ALPHA_MODE = 0x00044007 ,
52+ MBOX_TAG_FB_SET_ALPHA_MODE = 0x00048007 ,
53+ MBOX_TAG_FB_GET_PITCH = 0x00040008 ,
54+ MBOX_TAG_FB_GET_VIRT_OFFSET = 0x00040009 ,
55+ MBOX_TAG_FB_TEST_VIRT_OFFSET = 0x00044009 ,
56+ MBOX_TAG_FB_SET_VIRT_OFFSET = 0x00048009 ,
57+ MBOX_TAG_FB_GET_OVERSCAN = 0x0004000a ,
58+ MBOX_TAG_FB_TEST_OVERSCAN = 0x0004400a ,
59+ MBOX_TAG_FB_SET_OVERSCAN = 0x0004800a ,
60+ MBOX_TAG_FB_GET_PALETTE = 0x0004000b ,
61+ MBOX_TAG_FB_TEST_PALETTE = 0x0004400b ,
62+ MBOX_TAG_FB_SET_PALETTE = 0x0004800b ,
63+ };
64+
3165#define LCD_DEVICE (dev ) (struct rt_hdmi_fb_device*)(dev)
3266
3367static struct rt_hdmi_fb_device _hdmi ;
@@ -75,7 +109,7 @@ rt_err_t hdmi_fb_control(rt_device_t dev, int cmd, void *args)
75109 info -> bits_per_pixel = LCD_DEPTH ;
76110 info -> width = lcd -> width ;
77111 info -> height = lcd -> height ;
78- info -> framebuffer = lcd -> fb ;//(rt_uint8_t *)lcd->fb;
112+ info -> framebuffer = lcd -> fb ;
79113 }
80114 break ;
81115 }
@@ -119,38 +153,122 @@ rt_err_t rt_hdmi_fb_device_init(struct rt_hdmi_fb_device *hdmi_fb, const char *n
119153 return RT_EOK ;
120154}
121155
122- int hdmi_fb_init (void )
156+ rt_uint32_t bcm283x_mbox_fb_get_gpiovirt (void )
157+ {
158+ mbox [0 ] = 8 * 4 ; // length of the message
159+ mbox [1 ] = MBOX_REQUEST ; // this is a request message
160+
161+ mbox [2 ] = MBOX_TAG_FB_GET_GPIOVIRT ;
162+ mbox [3 ] = 4 ; // buffer size
163+ mbox [4 ] = 0 ; // len
164+
165+ mbox [5 ] = 0 ; // id
166+ mbox [6 ] = 0 ;
167+
168+ mbox [7 ] = MBOX_TAG_LAST ;
169+ mbox_call (8 , MMU_DISABLE );
170+ return (mbox [5 ] & 0x3fffffff );
171+ }
172+
173+ rt_uint32_t bcm283x_mbox_fb_get_pitch (void )
174+ {
175+ mbox [0 ] = 8 * 4 ; // length of the message
176+ mbox [1 ] = MBOX_REQUEST ; // this is a request message
177+
178+ mbox [2 ] = MBOX_TAG_FB_GET_PITCH ;
179+ mbox [3 ] = 4 ; // buffer size
180+ mbox [4 ] = 0 ; // len
181+
182+ mbox [5 ] = 0 ; // id
183+ mbox [6 ] = 0 ;
184+
185+ mbox [7 ] = MBOX_TAG_LAST ;
186+ mbox_call (8 , MMU_DISABLE );
187+ return mbox [5 ];
188+ }
189+
190+ void bcm283x_mbox_fb_set_porder (int rgb )
191+ {
192+ mbox [0 ] = 8 * 4 ; // length of the message
193+ mbox [1 ] = MBOX_REQUEST ; // this is a request message
194+
195+ mbox [2 ] = MBOX_TAG_FB_SET_PIXEL_ORDER ;
196+ mbox [3 ] = 4 ; // buffer size
197+ mbox [4 ] = 4 ; // len
198+
199+ mbox [5 ] = rgb ; // id
200+ mbox [6 ] = 0 ;
201+
202+ mbox [7 ] = MBOX_TAG_LAST ;
203+ mbox_call (8 , MMU_DISABLE );
204+ }
205+
206+ void bcm283x_mbox_fb_setoffset (int xoffset , int yoffset )
207+ {
208+ mbox [0 ] = 8 * 4 ; // length of the message
209+ mbox [1 ] = MBOX_REQUEST ; // this is a request message
210+
211+ mbox [2 ] = MBOX_TAG_FB_SET_VIRT_OFFSET ;
212+ mbox [3 ] = 8 ; // buffer size
213+ mbox [4 ] = 8 ; // len
214+
215+ mbox [5 ] = xoffset ; // id
216+ mbox [6 ] = yoffset ;
217+
218+ mbox [7 ] = MBOX_TAG_LAST ;
219+ mbox_call (8 , MMU_DISABLE );
220+ }
221+
222+
223+ void bcm283x_mbox_fb_setalpha (int alpha )
224+ {
225+
226+ mbox [0 ] = 8 * 4 ; // length of the message
227+ mbox [1 ] = MBOX_REQUEST ; // this is a request message
228+
229+ mbox [2 ] = MBOX_TAG_FB_SET_ALPHA_MODE ;
230+ mbox [3 ] = 4 ; // buffer size
231+ mbox [4 ] = 4 ; // len
232+
233+ mbox [5 ] = alpha ; // id
234+ mbox [6 ] = 0 ;
235+
236+ mbox [7 ] = MBOX_TAG_LAST ;
237+ mbox_call (8 , MMU_DISABLE );
238+ }
239+
240+ void * bcm283x_mbox_fb_alloc (int width , int height , int bpp , int nrender )
123241{
124242 mbox [0 ] = 4 * 35 ;
125243 mbox [1 ] = MBOX_REQUEST ;
126244
127245 mbox [2 ] = TAG_ALLOCATE_BUFFER ;//get framebuffer, gets alignment on request
128- mbox [3 ] = 8 ;
129- mbox [4 ] = 0 ;
130- mbox [5 ] = 4096 ; //FrameBufferInfo.pointer
131- mbox [6 ] = 0 ; //FrameBufferInfo.size
246+ mbox [3 ] = 8 ; //size
247+ mbox [4 ] = 4 ; //len
248+ mbox [5 ] = 4096 ; //The design of MBOX driver forces us to give the virtual address 0x3C100000
249+ mbox [6 ] = 0 ; //FrameBufferInfo.size
132250
133251 mbox [7 ] = TAG_SET_PHYS_WIDTH_HEIGHT ;
134252 mbox [8 ] = 8 ;
135- mbox [9 ] = 0 ;
136- mbox [10 ] = LCD_WIDTH ;
137- mbox [11 ] = LCD_HEIGHT ;
253+ mbox [9 ] = 8 ;
254+ mbox [10 ] = width ;
255+ mbox [11 ] = height ;
138256
139257 mbox [12 ] = TAG_SET_VIRT_WIDTH_HEIGHT ;
140258 mbox [13 ] = 8 ;
141- mbox [14 ] = 0 ;
142- mbox [15 ] = LCD_WIDTH ;
143- mbox [16 ] = LCD_HEIGHT ;
259+ mbox [14 ] = 8 ;
260+ mbox [15 ] = width ;
261+ mbox [16 ] = height * nrender ;
144262
145263 mbox [17 ] = TAG_SET_DEPTH ;
146264 mbox [18 ] = 4 ;
147- mbox [19 ] = 0 ;
148- mbox [20 ] = 16 ; //FrameBufferInfo.depth RGB 565
265+ mbox [19 ] = 4 ;
266+ mbox [20 ] = bpp ;
149267
150268 mbox [21 ] = TAG_SET_PIXEL_ORDER ;
151269 mbox [22 ] = 4 ;
152270 mbox [23 ] = 0 ;
153- mbox [24 ] = 1 ; //RGB, not BGR preferably
271+ mbox [24 ] = 0 ; //RGB, not BGR preferably
154272
155273 mbox [25 ] = TAG_GET_PITCH ;
156274 mbox [26 ] = 4 ;
@@ -167,17 +285,25 @@ int hdmi_fb_init(void)
167285
168286 mbox_call (MBOX_CH_PROP , MMU_DISABLE );
169287
170- _hdmi .fb = (rt_uint8_t * )(uintptr_t )(mbox [5 ] & 0x3FFFFFFF );
288+ return (void * )((rt_uint64_t )(mbox [5 ] & 0x3fffffff ));
289+ }
171290
291+ int hdmi_fb_init (void )
292+ {
293+ _hdmi .fb = (rt_uint8_t * )bcm283x_mbox_fb_alloc (LCD_WIDTH , LCD_HEIGHT , LCD_BPP , 1 );
294+ bcm283x_mbox_fb_setoffset (0 , 0 );
295+ bcm283x_mbox_fb_set_porder (0 );
172296 _hdmi .width = LCD_WIDTH ;
173297 _hdmi .height = LCD_HEIGHT ;
174298 _hdmi .depth = LCD_DEPTH ;
175299 _hdmi .pitch = 0 ;
176300 _hdmi .pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB888 ;
177301
178- armv8_map ((unsigned long )_hdmi .fb , (unsigned long )_hdmi .fb , 0x200000 , MEM_ATTR_MEMORY );
302+ armv8_map ((unsigned long )_hdmi .fb , (unsigned long )_hdmi .fb , 0x200000 , MEM_ATTR_IO );
303+
304+ rt_hw_dcache_invalidate_range ((unsigned long )_hdmi .fb ,LCD_WIDTH * LCD_HEIGHT * 3 );
179305
180- rt_kprintf ("_hdmi.fb is %p\n" , _hdmi .fb );
306+ // rt_kprintf("_hdmi.fb is %p\n", _hdmi.fb);
181307 rt_hdmi_fb_device_init (& _hdmi , "lcd" );
182308
183309 return 0 ;
0 commit comments