blob: 7867fe3895d00a763ff7b841554f46de1fd2ecd1 [file] [log] [blame]
Stephen Warren4ecd4982013-01-29 16:37:40 +00001/*
2 * (C) Copyright 2012 Stephen Warren
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Stephen Warren4ecd4982013-01-29 16:37:40 +00005 */
6
7#include <common.h>
8#include <lcd.h>
Simon Glass2dd337a2015-09-02 17:24:58 -06009#include <memalign.h>
Stephen Warren4ecd4982013-01-29 16:37:40 +000010#include <asm/arch/mbox.h>
11#include <asm/global_data.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15/* Global variables that lcd.c expects to exist */
Stephen Warren4ecd4982013-01-29 16:37:40 +000016vidinfo_t panel_info;
Stephen Warren4ecd4982013-01-29 16:37:40 +000017
Andre Heider191211c2013-11-09 11:07:53 +010018static u32 bcm2835_pitch;
19
Stephen Warren4ecd4982013-01-29 16:37:40 +000020struct msg_query {
21 struct bcm2835_mbox_hdr hdr;
22 struct bcm2835_mbox_tag_physical_w_h physical_w_h;
23 u32 end_tag;
24};
25
26struct msg_setup {
27 struct bcm2835_mbox_hdr hdr;
28 struct bcm2835_mbox_tag_physical_w_h physical_w_h;
29 struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
30 struct bcm2835_mbox_tag_depth depth;
31 struct bcm2835_mbox_tag_pixel_order pixel_order;
32 struct bcm2835_mbox_tag_alpha_mode alpha_mode;
33 struct bcm2835_mbox_tag_virtual_offset virtual_offset;
34 struct bcm2835_mbox_tag_overscan overscan;
35 struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
Andre Heider191211c2013-11-09 11:07:53 +010036 struct bcm2835_mbox_tag_pitch pitch;
Stephen Warren4ecd4982013-01-29 16:37:40 +000037 u32 end_tag;
38};
39
40void lcd_ctrl_init(void *lcdbase)
41{
Alexander Steinc56c9472015-07-24 09:22:12 +020042 ALLOC_CACHE_ALIGN_BUFFER(struct msg_query, msg_query, 1);
43 ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1);
Stephen Warren4ecd4982013-01-29 16:37:40 +000044 int ret;
45 u32 w, h;
46
47 debug("bcm2835: Query resolution...\n");
48
49 BCM2835_MBOX_INIT_HDR(msg_query);
50 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
51 GET_PHYSICAL_W_H);
52 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
53 if (ret) {
54 printf("bcm2835: Could not query display resolution\n");
55 /* FIXME: How to disable the LCD to prevent errors? hang()? */
56 return;
57 }
58
59 w = msg_query->physical_w_h.body.resp.width;
60 h = msg_query->physical_w_h.body.resp.height;
61
62 debug("bcm2835: Setting up display for %d x %d\n", w, h);
63
64 BCM2835_MBOX_INIT_HDR(msg_setup);
65 BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
66 msg_setup->physical_w_h.body.req.width = w;
67 msg_setup->physical_w_h.body.req.height = h;
68 BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
69 msg_setup->virtual_w_h.body.req.width = w;
70 msg_setup->virtual_w_h.body.req.height = h;
71 BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
72 msg_setup->depth.body.req.bpp = 16;
73 BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
74 msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR;
75 BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
76 msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
77 BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
78 msg_setup->virtual_offset.body.req.x = 0;
79 msg_setup->virtual_offset.body.req.y = 0;
80 BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN);
81 msg_setup->overscan.body.req.top = 0;
82 msg_setup->overscan.body.req.bottom = 0;
83 msg_setup->overscan.body.req.left = 0;
84 msg_setup->overscan.body.req.right = 0;
85 BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
86 msg_setup->allocate_buffer.body.req.alignment = 0x100;
Andre Heider191211c2013-11-09 11:07:53 +010087 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
Stephen Warren4ecd4982013-01-29 16:37:40 +000088
89 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
90 if (ret) {
91 printf("bcm2835: Could not configure display\n");
92 /* FIXME: How to disable the LCD to prevent errors? hang()? */
93 return;
94 }
95
96 w = msg_setup->physical_w_h.body.resp.width;
97 h = msg_setup->physical_w_h.body.resp.height;
Andre Heider191211c2013-11-09 11:07:53 +010098 bcm2835_pitch = msg_setup->pitch.body.resp.pitch;
Stephen Warren4ecd4982013-01-29 16:37:40 +000099
100 debug("bcm2835: Final resolution is %d x %d\n", w, h);
101
102 panel_info.vl_col = w;
103 panel_info.vl_row = h;
104 panel_info.vl_bpix = LCD_COLOR16;
105
106 gd->fb_base = msg_setup->allocate_buffer.body.resp.fb_address;
Stephen Warren4ecd4982013-01-29 16:37:40 +0000107}
108
109void lcd_enable(void)
110{
Andre Heider191211c2013-11-09 11:07:53 +0100111}
112
113int lcd_get_size(int *line_length)
114{
115 *line_length = bcm2835_pitch;
116 return *line_length * panel_info.vl_row;
Stephen Warren4ecd4982013-01-29 16:37:40 +0000117}