Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012 Stephen Warren |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <lcd.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 9 | #include <memalign.h> |
Stephen Warren | 888a90c | 2016-02-06 10:42:43 -0700 | [diff] [blame] | 10 | #include <phys2bus.h> |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 11 | #include <asm/arch/mbox.h> |
Simon Glass | 31efc38 | 2017-04-05 16:23:40 -0600 | [diff] [blame^] | 12 | #include <asm/arch/msg.h> |
Stephen Warren | 4ecd498 | 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 | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 18 | vidinfo_t panel_info; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 19 | |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 20 | static u32 bcm2835_pitch; |
| 21 | |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 22 | struct 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 Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 32 | struct bcm2835_mbox_tag_pitch pitch; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 33 | u32 end_tag; |
| 34 | }; |
| 35 | |
| 36 | void lcd_ctrl_init(void *lcdbase) |
| 37 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 38 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 39 | int ret; |
Simon Glass | 31efc38 | 2017-04-05 16:23:40 -0600 | [diff] [blame^] | 40 | int w, h; |
Alexander Graf | 2e1075c | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 41 | u32 fb_start, fb_end; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 42 | |
| 43 | debug("bcm2835: Query resolution...\n"); |
Simon Glass | 31efc38 | 2017-04-05 16:23:40 -0600 | [diff] [blame^] | 44 | ret = bcm2835_get_video_size(&w, &h); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 45 | if (ret) { |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 46 | /* FIXME: How to disable the LCD to prevent errors? hang()? */ |
| 47 | return; |
| 48 | } |
| 49 | |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 50 | 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 Graf | 13b6697 | 2016-11-02 10:36:19 +0100 | [diff] [blame] | 60 | msg_setup->depth.body.req.bpp = 32; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 61 | BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER); |
Alexander Graf | 13b6697 | 2016-11-02 10:36:19 +0100 | [diff] [blame] | 62 | msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_RGB; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 63 | 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 Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 75 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 76 | |
| 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 Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 86 | bcm2835_pitch = msg_setup->pitch.body.resp.pitch; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 87 | |
| 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 Graf | 13b6697 | 2016-11-02 10:36:19 +0100 | [diff] [blame] | 92 | panel_info.vl_bpix = LCD_COLOR32; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 93 | |
Stephen Warren | 888a90c | 2016-02-06 10:42:43 -0700 | [diff] [blame] | 94 | gd->fb_base = bus_to_phys( |
| 95 | msg_setup->allocate_buffer.body.resp.fb_address); |
Alexander Graf | 2e1075c | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 96 | |
| 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 Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void lcd_enable(void) |
| 107 | { |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | int lcd_get_size(int *line_length) |
| 111 | { |
| 112 | *line_length = bcm2835_pitch; |
| 113 | return *line_length * panel_info.vl_row; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 114 | } |