blob: cd15f7f32ae9b5bfdbf3531fb70c44353e4c5dfd [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
Simon Glass7cac2fc2017-04-05 16:23:41 -060020static int bcm2835_pitch;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000021
22void lcd_ctrl_init(void *lcdbase)
23{
Stephen Warren6be3c9f2013-01-29 16:37:40 +000024 int ret;
Simon Glass2e4170b2017-04-05 16:23:40 -060025 int w, h;
Simon Glass7cac2fc2017-04-05 16:23:41 -060026 ulong fb_base, fb_size, fb_start, fb_end;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000027
28 debug("bcm2835: Query resolution...\n");
Simon Glass2e4170b2017-04-05 16:23:40 -060029 ret = bcm2835_get_video_size(&w, &h);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000030 if (ret) {
Stephen Warren6be3c9f2013-01-29 16:37:40 +000031 /* FIXME: How to disable the LCD to prevent errors? hang()? */
32 return;
33 }
34
Stephen Warren6be3c9f2013-01-29 16:37:40 +000035 debug("bcm2835: Setting up display for %d x %d\n", w, h);
Simon Glass7cac2fc2017-04-05 16:23:41 -060036 ret = bcm2835_set_video_params(&w, &h, 32, BCM2835_MBOX_PIXEL_ORDER_RGB,
37 BCM2835_MBOX_ALPHA_MODE_IGNORED,
38 &fb_base, &fb_size, &bcm2835_pitch);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000039
40 debug("bcm2835: Final resolution is %d x %d\n", w, h);
41
42 panel_info.vl_col = w;
43 panel_info.vl_row = h;
Alexander Graf8b82dd92016-11-02 10:36:19 +010044 panel_info.vl_bpix = LCD_COLOR32;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000045
Simon Glass7cac2fc2017-04-05 16:23:41 -060046 gd->fb_base = fb_base;
Alexander Graf99de2542016-03-24 10:31:11 +010047
48 /* Enable dcache for the frame buffer */
Simon Glass7cac2fc2017-04-05 16:23:41 -060049 fb_start = fb_base & ~(MMU_SECTION_SIZE - 1);
50 fb_end = fb_base + fb_size;
Alexander Graf99de2542016-03-24 10:31:11 +010051 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
52 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
Simon Glass7cac2fc2017-04-05 16:23:41 -060053 DCACHE_WRITEBACK);
Alexander Graf99de2542016-03-24 10:31:11 +010054 lcd_set_flush_dcache(1);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000055}
56
57void lcd_enable(void)
58{
59}
Andre Heider44376ef2013-11-09 11:07:53 +010060
61int lcd_get_size(int *line_length)
62{
63 *line_length = bcm2835_pitch;
Simon Glass7cac2fc2017-04-05 16:23:41 -060064
Andre Heider44376ef2013-11-09 11:07:53 +010065 return *line_length * panel_info.vl_row;
66}