]>
Commit | Line | Data |
---|---|---|
6be3c9fc SW |
1 | /* |
2 | * (C) Copyright 2012 Stephen Warren | |
3 | * | |
1a459660 | 4 | * SPDX-License-Identifier: GPL-2.0+ |
6be3c9fc SW |
5 | */ |
6 | ||
7 | #include <common.h> | |
8 | #include <lcd.h> | |
cf92e05c | 9 | #include <memalign.h> |
1382648b | 10 | #include <phys2bus.h> |
6be3c9fc SW |
11 | #include <asm/arch/mbox.h> |
12 | #include <asm/global_data.h> | |
13 | ||
14 | DECLARE_GLOBAL_DATA_PTR; | |
15 | ||
16 | /* Global variables that lcd.c expects to exist */ | |
6be3c9fc | 17 | vidinfo_t panel_info; |
6be3c9fc | 18 | |
44376eff AH |
19 | static u32 bcm2835_pitch; |
20 | ||
6be3c9fc SW |
21 | struct msg_query { |
22 | struct bcm2835_mbox_hdr hdr; | |
23 | struct bcm2835_mbox_tag_physical_w_h physical_w_h; | |
24 | u32 end_tag; | |
25 | }; | |
26 | ||
27 | struct msg_setup { | |
28 | struct bcm2835_mbox_hdr hdr; | |
29 | struct bcm2835_mbox_tag_physical_w_h physical_w_h; | |
30 | struct bcm2835_mbox_tag_virtual_w_h virtual_w_h; | |
31 | struct bcm2835_mbox_tag_depth depth; | |
32 | struct bcm2835_mbox_tag_pixel_order pixel_order; | |
33 | struct bcm2835_mbox_tag_alpha_mode alpha_mode; | |
34 | struct bcm2835_mbox_tag_virtual_offset virtual_offset; | |
35 | struct bcm2835_mbox_tag_overscan overscan; | |
36 | struct bcm2835_mbox_tag_allocate_buffer allocate_buffer; | |
44376eff | 37 | struct bcm2835_mbox_tag_pitch pitch; |
6be3c9fc SW |
38 | u32 end_tag; |
39 | }; | |
40 | ||
41 | void lcd_ctrl_init(void *lcdbase) | |
42 | { | |
927753ae AS |
43 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_query, msg_query, 1); |
44 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1); | |
6be3c9fc SW |
45 | int ret; |
46 | u32 w, h; | |
99de254e | 47 | u32 fb_start, fb_end; |
6be3c9fc SW |
48 | |
49 | debug("bcm2835: Query resolution...\n"); | |
50 | ||
51 | BCM2835_MBOX_INIT_HDR(msg_query); | |
52 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h, | |
53 | GET_PHYSICAL_W_H); | |
54 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr); | |
55 | if (ret) { | |
56 | printf("bcm2835: Could not query display resolution\n"); | |
57 | /* FIXME: How to disable the LCD to prevent errors? hang()? */ | |
58 | return; | |
59 | } | |
60 | ||
61 | w = msg_query->physical_w_h.body.resp.width; | |
62 | h = msg_query->physical_w_h.body.resp.height; | |
63 | ||
64 | debug("bcm2835: Setting up display for %d x %d\n", w, h); | |
65 | ||
66 | BCM2835_MBOX_INIT_HDR(msg_setup); | |
67 | BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H); | |
68 | msg_setup->physical_w_h.body.req.width = w; | |
69 | msg_setup->physical_w_h.body.req.height = h; | |
70 | BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H); | |
71 | msg_setup->virtual_w_h.body.req.width = w; | |
72 | msg_setup->virtual_w_h.body.req.height = h; | |
73 | BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH); | |
8b82dd9a | 74 | msg_setup->depth.body.req.bpp = 32; |
6be3c9fc | 75 | BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER); |
8b82dd9a | 76 | msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_RGB; |
6be3c9fc SW |
77 | BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE); |
78 | msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED; | |
79 | BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET); | |
80 | msg_setup->virtual_offset.body.req.x = 0; | |
81 | msg_setup->virtual_offset.body.req.y = 0; | |
82 | BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN); | |
83 | msg_setup->overscan.body.req.top = 0; | |
84 | msg_setup->overscan.body.req.bottom = 0; | |
85 | msg_setup->overscan.body.req.left = 0; | |
86 | msg_setup->overscan.body.req.right = 0; | |
87 | BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER); | |
88 | msg_setup->allocate_buffer.body.req.alignment = 0x100; | |
44376eff | 89 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH); |
6be3c9fc SW |
90 | |
91 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr); | |
92 | if (ret) { | |
93 | printf("bcm2835: Could not configure display\n"); | |
94 | /* FIXME: How to disable the LCD to prevent errors? hang()? */ | |
95 | return; | |
96 | } | |
97 | ||
98 | w = msg_setup->physical_w_h.body.resp.width; | |
99 | h = msg_setup->physical_w_h.body.resp.height; | |
44376eff | 100 | bcm2835_pitch = msg_setup->pitch.body.resp.pitch; |
6be3c9fc SW |
101 | |
102 | debug("bcm2835: Final resolution is %d x %d\n", w, h); | |
103 | ||
104 | panel_info.vl_col = w; | |
105 | panel_info.vl_row = h; | |
8b82dd9a | 106 | panel_info.vl_bpix = LCD_COLOR32; |
6be3c9fc | 107 | |
1382648b SW |
108 | gd->fb_base = bus_to_phys( |
109 | msg_setup->allocate_buffer.body.resp.fb_address); | |
99de254e AG |
110 | |
111 | /* Enable dcache for the frame buffer */ | |
112 | fb_start = gd->fb_base & ~(MMU_SECTION_SIZE - 1); | |
113 | fb_end = gd->fb_base + msg_setup->allocate_buffer.body.resp.fb_size; | |
114 | fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT); | |
115 | mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start, | |
116 | DCACHE_WRITEBACK); | |
117 | lcd_set_flush_dcache(1); | |
6be3c9fc SW |
118 | } |
119 | ||
120 | void lcd_enable(void) | |
121 | { | |
122 | } | |
44376eff AH |
123 | |
124 | int lcd_get_size(int *line_length) | |
125 | { | |
126 | *line_length = bcm2835_pitch; | |
127 | return *line_length * panel_info.vl_row; | |
128 | } |