Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012 Stephen Warren |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <lcd.h> |
Simon Glass | cf92e05 | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 9 | #include <memalign.h> |
Stephen Warren | 1382648 | 2016-02-06 10:42:43 -0700 | [diff] [blame] | 10 | #include <phys2bus.h> |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 11 | #include <asm/arch/mbox.h> |
Simon Glass | 2e4170b | 2017-04-05 16:23:40 -0600 | [diff] [blame] | 12 | #include <asm/arch/msg.h> |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 13 | #include <asm/global_data.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | /* Global variables that lcd.c expects to exist */ |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 18 | vidinfo_t panel_info; |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 19 | |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 20 | static int bcm2835_pitch; |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 21 | |
| 22 | void lcd_ctrl_init(void *lcdbase) |
| 23 | { |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 24 | int ret; |
Simon Glass | 2e4170b | 2017-04-05 16:23:40 -0600 | [diff] [blame] | 25 | int w, h; |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 26 | ulong fb_base, fb_size, fb_start, fb_end; |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 27 | |
| 28 | debug("bcm2835: Query resolution...\n"); |
Simon Glass | 2e4170b | 2017-04-05 16:23:40 -0600 | [diff] [blame] | 29 | ret = bcm2835_get_video_size(&w, &h); |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 30 | if (ret) { |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 31 | /* FIXME: How to disable the LCD to prevent errors? hang()? */ |
| 32 | return; |
| 33 | } |
| 34 | |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 35 | debug("bcm2835: Setting up display for %d x %d\n", w, h); |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 36 | 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 Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 39 | |
| 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 Graf | 8b82dd9 | 2016-11-02 10:36:19 +0100 | [diff] [blame] | 44 | panel_info.vl_bpix = LCD_COLOR32; |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 45 | |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 46 | gd->fb_base = fb_base; |
Alexander Graf | 99de254 | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 47 | |
| 48 | /* Enable dcache for the frame buffer */ |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 49 | fb_start = fb_base & ~(MMU_SECTION_SIZE - 1); |
| 50 | fb_end = fb_base + fb_size; |
Alexander Graf | 99de254 | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 51 | fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT); |
| 52 | mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start, |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 53 | DCACHE_WRITEBACK); |
Alexander Graf | 99de254 | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 54 | lcd_set_flush_dcache(1); |
Stephen Warren | 6be3c9f | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void lcd_enable(void) |
| 58 | { |
| 59 | } |
Andre Heider | 44376ef | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 60 | |
| 61 | int lcd_get_size(int *line_length) |
| 62 | { |
| 63 | *line_length = bcm2835_pitch; |
Simon Glass | 7cac2fc | 2017-04-05 16:23:41 -0600 | [diff] [blame^] | 64 | |
Andre Heider | 44376ef | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 65 | return *line_length * panel_info.vl_row; |
| 66 | } |