2 * (C) Copyright 2012 Stephen Warren
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/mbox.h>
12 #include <asm/arch/msg.h>
13 #include <asm/global_data.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 /* Global variables that lcd.c expects to exist */
20 static u32 bcm2835_pitch;
23 struct bcm2835_mbox_hdr hdr;
24 struct bcm2835_mbox_tag_physical_w_h physical_w_h;
25 struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
26 struct bcm2835_mbox_tag_depth depth;
27 struct bcm2835_mbox_tag_pixel_order pixel_order;
28 struct bcm2835_mbox_tag_alpha_mode alpha_mode;
29 struct bcm2835_mbox_tag_virtual_offset virtual_offset;
30 struct bcm2835_mbox_tag_overscan overscan;
31 struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
32 struct bcm2835_mbox_tag_pitch pitch;
36 void lcd_ctrl_init(void *lcdbase)
38 ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1);
43 debug("bcm2835: Query resolution...\n");
44 ret = bcm2835_get_video_size(&w, &h);
46 /* FIXME: How to disable the LCD to prevent errors? hang()? */
50 debug("bcm2835: Setting up display for %d x %d\n", w, h);
52 BCM2835_MBOX_INIT_HDR(msg_setup);
53 BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
54 msg_setup->physical_w_h.body.req.width = w;
55 msg_setup->physical_w_h.body.req.height = h;
56 BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
57 msg_setup->virtual_w_h.body.req.width = w;
58 msg_setup->virtual_w_h.body.req.height = h;
59 BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
60 msg_setup->depth.body.req.bpp = 32;
61 BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
62 msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_RGB;
63 BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
64 msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
65 BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
66 msg_setup->virtual_offset.body.req.x = 0;
67 msg_setup->virtual_offset.body.req.y = 0;
68 BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
69 msg_setup->overscan.body.req.top = 0;
70 msg_setup->overscan.body.req.bottom = 0;
71 msg_setup->overscan.body.req.left = 0;
72 msg_setup->overscan.body.req.right = 0;
73 BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
74 msg_setup->allocate_buffer.body.req.alignment = 0x100;
75 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
77 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
79 printf("bcm2835: Could not configure display\n");
80 /* FIXME: How to disable the LCD to prevent errors? hang()? */
84 w = msg_setup->physical_w_h.body.resp.width;
85 h = msg_setup->physical_w_h.body.resp.height;
86 bcm2835_pitch = msg_setup->pitch.body.resp.pitch;
88 debug("bcm2835: Final resolution is %d x %d\n", w, h);
90 panel_info.vl_col = w;
91 panel_info.vl_row = h;
92 panel_info.vl_bpix = LCD_COLOR32;
94 gd->fb_base = bus_to_phys(
95 msg_setup->allocate_buffer.body.resp.fb_address);
97 /* Enable dcache for the frame buffer */
98 fb_start = gd->fb_base & ~(MMU_SECTION_SIZE - 1);
99 fb_end = gd->fb_base + msg_setup->allocate_buffer.body.resp.fb_size;
100 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
101 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
103 lcd_set_flush_dcache(1);
106 void lcd_enable(void)
110 int lcd_get_size(int *line_length)
112 *line_length = bcm2835_pitch;
113 return *line_length * panel_info.vl_row;