blob: eb137be11caceffd0c356882f88368980d0867fa [file] [log] [blame]
Stephen Warren6be3c9f2013-01-29 16:37:40 +00001/*
2 * (C) Copyright 2012 Stephen Warren
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Stephen Warren6be3c9f2013-01-29 16:37:40 +00005 */
6
7#include <common.h>
8#include <lcd.h>
Simon Glasscf92e052015-09-02 17:24:58 -06009#include <memalign.h>
Stephen Warren13826482016-02-06 10:42:43 -070010#include <phys2bus.h>
Stephen Warren6be3c9f2013-01-29 16:37:40 +000011#include <asm/arch/mbox.h>
Simon Glass2e4170b2017-04-05 16:23:40 -060012#include <asm/arch/msg.h>
Stephen Warren6be3c9f2013-01-29 16:37:40 +000013#include <asm/global_data.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17/* Global variables that lcd.c expects to exist */
Stephen Warren6be3c9f2013-01-29 16:37:40 +000018vidinfo_t panel_info;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000019
Andre Heider44376ef2013-11-09 11:07:53 +010020static u32 bcm2835_pitch;
21
Stephen Warren6be3c9f2013-01-29 16:37:40 +000022struct msg_setup {
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;
Andre Heider44376ef2013-11-09 11:07:53 +010032 struct bcm2835_mbox_tag_pitch pitch;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000033 u32 end_tag;
34};
35
36void lcd_ctrl_init(void *lcdbase)
37{
Alexander Stein927753a2015-07-24 09:22:12 +020038 ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000039 int ret;
Simon Glass2e4170b2017-04-05 16:23:40 -060040 int w, h;
Alexander Graf99de2542016-03-24 10:31:11 +010041 u32 fb_start, fb_end;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000042
43 debug("bcm2835: Query resolution...\n");
Simon Glass2e4170b2017-04-05 16:23:40 -060044 ret = bcm2835_get_video_size(&w, &h);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000045 if (ret) {
Stephen Warren6be3c9f2013-01-29 16:37:40 +000046 /* FIXME: How to disable the LCD to prevent errors? hang()? */
47 return;
48 }
49
Stephen Warren6be3c9f2013-01-29 16:37:40 +000050 debug("bcm2835: Setting up display for %d x %d\n", w, h);
51
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);
Alexander Graf8b82dd92016-11-02 10:36:19 +010060 msg_setup->depth.body.req.bpp = 32;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000061 BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
Alexander Graf8b82dd92016-11-02 10:36:19 +010062 msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_RGB;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000063 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;
Andre Heider44376ef2013-11-09 11:07:53 +010075 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000076
77 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
78 if (ret) {
79 printf("bcm2835: Could not configure display\n");
80 /* FIXME: How to disable the LCD to prevent errors? hang()? */
81 return;
82 }
83
84 w = msg_setup->physical_w_h.body.resp.width;
85 h = msg_setup->physical_w_h.body.resp.height;
Andre Heider44376ef2013-11-09 11:07:53 +010086 bcm2835_pitch = msg_setup->pitch.body.resp.pitch;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000087
88 debug("bcm2835: Final resolution is %d x %d\n", w, h);
89
90 panel_info.vl_col = w;
91 panel_info.vl_row = h;
Alexander Graf8b82dd92016-11-02 10:36:19 +010092 panel_info.vl_bpix = LCD_COLOR32;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000093
Stephen Warren13826482016-02-06 10:42:43 -070094 gd->fb_base = bus_to_phys(
95 msg_setup->allocate_buffer.body.resp.fb_address);
Alexander Graf99de2542016-03-24 10:31:11 +010096
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,
102 DCACHE_WRITEBACK);
103 lcd_set_flush_dcache(1);
Stephen Warren6be3c9f2013-01-29 16:37:40 +0000104}
105
106void lcd_enable(void)
107{
108}
Andre Heider44376ef2013-11-09 11:07:53 +0100109
110int lcd_get_size(int *line_length)
111{
112 *line_length = bcm2835_pitch;
113 return *line_length * panel_info.vl_row;
114}