Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[platform/kernel/u-boot.git] / drivers / video / bcm2835.c
1 /*
2  * (C) Copyright 2012 Stephen Warren
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  */
17
18 #include <common.h>
19 #include <lcd.h>
20 #include <asm/arch/mbox.h>
21 #include <asm/global_data.h>
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 /* Global variables that lcd.c expects to exist */
26 int lcd_line_length;
27 int lcd_color_fg;
28 int lcd_color_bg;
29 void *lcd_base;
30 void *lcd_console_address;
31 short console_col;
32 short console_row;
33 vidinfo_t panel_info;
34 char lcd_cursor_enabled;
35 ushort lcd_cursor_width;
36 ushort lcd_cursor_height;
37
38 struct msg_query {
39         struct bcm2835_mbox_hdr hdr;
40         struct bcm2835_mbox_tag_physical_w_h physical_w_h;
41         u32 end_tag;
42 };
43
44 struct msg_setup {
45         struct bcm2835_mbox_hdr hdr;
46         struct bcm2835_mbox_tag_physical_w_h physical_w_h;
47         struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
48         struct bcm2835_mbox_tag_depth depth;
49         struct bcm2835_mbox_tag_pixel_order pixel_order;
50         struct bcm2835_mbox_tag_alpha_mode alpha_mode;
51         struct bcm2835_mbox_tag_virtual_offset virtual_offset;
52         struct bcm2835_mbox_tag_overscan overscan;
53         struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
54         u32 end_tag;
55 };
56
57 void lcd_ctrl_init(void *lcdbase)
58 {
59         ALLOC_ALIGN_BUFFER(struct msg_query, msg_query, 1, 16);
60         ALLOC_ALIGN_BUFFER(struct msg_setup, msg_setup, 1, 16);
61         int ret;
62         u32 w, h;
63
64         debug("bcm2835: Query resolution...\n");
65
66         BCM2835_MBOX_INIT_HDR(msg_query);
67         BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
68                                         GET_PHYSICAL_W_H);
69         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
70         if (ret) {
71                 printf("bcm2835: Could not query display resolution\n");
72                 /* FIXME: How to disable the LCD to prevent errors? hang()? */
73                 return;
74         }
75
76         w = msg_query->physical_w_h.body.resp.width;
77         h = msg_query->physical_w_h.body.resp.height;
78
79         debug("bcm2835: Setting up display for %d x %d\n", w, h);
80
81         BCM2835_MBOX_INIT_HDR(msg_setup);
82         BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
83         msg_setup->physical_w_h.body.req.width = w;
84         msg_setup->physical_w_h.body.req.height = h;
85         BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
86         msg_setup->virtual_w_h.body.req.width = w;
87         msg_setup->virtual_w_h.body.req.height = h;
88         BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
89         msg_setup->depth.body.req.bpp = 16;
90         BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
91         msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR;
92         BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
93         msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
94         BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
95         msg_setup->virtual_offset.body.req.x = 0;
96         msg_setup->virtual_offset.body.req.y = 0;
97         BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
98         msg_setup->overscan.body.req.top = 0;
99         msg_setup->overscan.body.req.bottom = 0;
100         msg_setup->overscan.body.req.left = 0;
101         msg_setup->overscan.body.req.right = 0;
102         BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
103         msg_setup->allocate_buffer.body.req.alignment = 0x100;
104
105         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
106         if (ret) {
107                 printf("bcm2835: Could not configure display\n");
108                 /* FIXME: How to disable the LCD to prevent errors? hang()? */
109                 return;
110         }
111
112         w = msg_setup->physical_w_h.body.resp.width;
113         h = msg_setup->physical_w_h.body.resp.height;
114
115         debug("bcm2835: Final resolution is %d x %d\n", w, h);
116
117         panel_info.vl_col = w;
118         panel_info.vl_row = h;
119         panel_info.vl_bpix = LCD_COLOR16;
120
121         gd->fb_base = msg_setup->allocate_buffer.body.resp.fb_address;
122         lcd_base = (void *)gd->fb_base;
123 }
124
125 void lcd_enable(void)
126 {
127 }