]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/video/bcm2835.c
Merge branch 'master' of git://git.denx.de/u-boot-i2c
[karo-tx-uboot.git] / drivers / video / bcm2835.c
1 /*
2  * (C) Copyright 2012 Stephen Warren
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <lcd.h>
9 #include <asm/arch/mbox.h>
10 #include <asm/global_data.h>
11
12 DECLARE_GLOBAL_DATA_PTR;
13
14 /* Global variables that lcd.c expects to exist */
15 vidinfo_t panel_info;
16
17 struct msg_query {
18         struct bcm2835_mbox_hdr hdr;
19         struct bcm2835_mbox_tag_physical_w_h physical_w_h;
20         u32 end_tag;
21 };
22
23 struct msg_setup {
24         struct bcm2835_mbox_hdr hdr;
25         struct bcm2835_mbox_tag_physical_w_h physical_w_h;
26         struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
27         struct bcm2835_mbox_tag_depth depth;
28         struct bcm2835_mbox_tag_pixel_order pixel_order;
29         struct bcm2835_mbox_tag_alpha_mode alpha_mode;
30         struct bcm2835_mbox_tag_virtual_offset virtual_offset;
31         struct bcm2835_mbox_tag_overscan overscan;
32         struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
33         u32 end_tag;
34 };
35
36 void lcd_ctrl_init(void *lcdbase)
37 {
38         ALLOC_ALIGN_BUFFER(struct msg_query, msg_query, 1, 16);
39         ALLOC_ALIGN_BUFFER(struct msg_setup, msg_setup, 1, 16);
40         int ret;
41         u32 w, h;
42
43         debug("bcm2835: Query resolution...\n");
44
45         BCM2835_MBOX_INIT_HDR(msg_query);
46         BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
47                                         GET_PHYSICAL_W_H);
48         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
49         if (ret) {
50                 printf("bcm2835: Could not query display resolution\n");
51                 /* FIXME: How to disable the LCD to prevent errors? hang()? */
52                 return;
53         }
54
55         w = msg_query->physical_w_h.body.resp.width;
56         h = msg_query->physical_w_h.body.resp.height;
57
58         debug("bcm2835: Setting up display for %d x %d\n", w, h);
59
60         BCM2835_MBOX_INIT_HDR(msg_setup);
61         BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
62         msg_setup->physical_w_h.body.req.width = w;
63         msg_setup->physical_w_h.body.req.height = h;
64         BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
65         msg_setup->virtual_w_h.body.req.width = w;
66         msg_setup->virtual_w_h.body.req.height = h;
67         BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
68         msg_setup->depth.body.req.bpp = 16;
69         BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
70         msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR;
71         BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
72         msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
73         BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
74         msg_setup->virtual_offset.body.req.x = 0;
75         msg_setup->virtual_offset.body.req.y = 0;
76         BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
77         msg_setup->overscan.body.req.top = 0;
78         msg_setup->overscan.body.req.bottom = 0;
79         msg_setup->overscan.body.req.left = 0;
80         msg_setup->overscan.body.req.right = 0;
81         BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
82         msg_setup->allocate_buffer.body.req.alignment = 0x100;
83
84         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
85         if (ret) {
86                 printf("bcm2835: Could not configure display\n");
87                 /* FIXME: How to disable the LCD to prevent errors? hang()? */
88                 return;
89         }
90
91         w = msg_setup->physical_w_h.body.resp.width;
92         h = msg_setup->physical_w_h.body.resp.height;
93
94         debug("bcm2835: Final resolution is %d x %d\n", w, h);
95
96         panel_info.vl_col = w;
97         panel_info.vl_row = h;
98         panel_info.vl_bpix = LCD_COLOR16;
99
100         gd->fb_base = msg_setup->allocate_buffer.body.resp.fb_address;
101 }
102
103 void lcd_enable(void)
104 {
105 }