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> |
| 12 | #include <asm/global_data.h> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | /* Global variables that lcd.c expects to exist */ |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 17 | vidinfo_t panel_info; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 18 | |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 19 | static u32 bcm2835_pitch; |
| 20 | |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 21 | struct msg_query { |
| 22 | struct bcm2835_mbox_hdr hdr; |
| 23 | struct bcm2835_mbox_tag_physical_w_h physical_w_h; |
| 24 | u32 end_tag; |
| 25 | }; |
| 26 | |
| 27 | struct msg_setup { |
| 28 | struct bcm2835_mbox_hdr hdr; |
| 29 | struct bcm2835_mbox_tag_physical_w_h physical_w_h; |
| 30 | struct bcm2835_mbox_tag_virtual_w_h virtual_w_h; |
| 31 | struct bcm2835_mbox_tag_depth depth; |
| 32 | struct bcm2835_mbox_tag_pixel_order pixel_order; |
| 33 | struct bcm2835_mbox_tag_alpha_mode alpha_mode; |
| 34 | struct bcm2835_mbox_tag_virtual_offset virtual_offset; |
| 35 | struct bcm2835_mbox_tag_overscan overscan; |
| 36 | struct bcm2835_mbox_tag_allocate_buffer allocate_buffer; |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 37 | struct bcm2835_mbox_tag_pitch pitch; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 38 | u32 end_tag; |
| 39 | }; |
| 40 | |
| 41 | void lcd_ctrl_init(void *lcdbase) |
| 42 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 43 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_query, msg_query, 1); |
| 44 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_setup, msg_setup, 1); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 45 | int ret; |
| 46 | u32 w, h; |
| 47 | |
| 48 | debug("bcm2835: Query resolution...\n"); |
| 49 | |
| 50 | BCM2835_MBOX_INIT_HDR(msg_query); |
| 51 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h, |
| 52 | GET_PHYSICAL_W_H); |
| 53 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr); |
| 54 | if (ret) { |
| 55 | printf("bcm2835: Could not query display resolution\n"); |
| 56 | /* FIXME: How to disable the LCD to prevent errors? hang()? */ |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | w = msg_query->physical_w_h.body.resp.width; |
| 61 | h = msg_query->physical_w_h.body.resp.height; |
| 62 | |
| 63 | debug("bcm2835: Setting up display for %d x %d\n", w, h); |
| 64 | |
| 65 | BCM2835_MBOX_INIT_HDR(msg_setup); |
| 66 | BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H); |
| 67 | msg_setup->physical_w_h.body.req.width = w; |
| 68 | msg_setup->physical_w_h.body.req.height = h; |
| 69 | BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H); |
| 70 | msg_setup->virtual_w_h.body.req.width = w; |
| 71 | msg_setup->virtual_w_h.body.req.height = h; |
| 72 | BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH); |
| 73 | msg_setup->depth.body.req.bpp = 16; |
| 74 | BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER); |
| 75 | msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR; |
| 76 | BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE); |
| 77 | msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED; |
| 78 | BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET); |
| 79 | msg_setup->virtual_offset.body.req.x = 0; |
| 80 | msg_setup->virtual_offset.body.req.y = 0; |
| 81 | BCM2835_MBOX_INIT_TAG(&msg_setup->overscan, SET_OVERSCAN); |
| 82 | msg_setup->overscan.body.req.top = 0; |
| 83 | msg_setup->overscan.body.req.bottom = 0; |
| 84 | msg_setup->overscan.body.req.left = 0; |
| 85 | msg_setup->overscan.body.req.right = 0; |
| 86 | BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER); |
| 87 | msg_setup->allocate_buffer.body.req.alignment = 0x100; |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 88 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 89 | |
| 90 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr); |
| 91 | if (ret) { |
| 92 | printf("bcm2835: Could not configure display\n"); |
| 93 | /* FIXME: How to disable the LCD to prevent errors? hang()? */ |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | w = msg_setup->physical_w_h.body.resp.width; |
| 98 | h = msg_setup->physical_w_h.body.resp.height; |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 99 | bcm2835_pitch = msg_setup->pitch.body.resp.pitch; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 100 | |
| 101 | debug("bcm2835: Final resolution is %d x %d\n", w, h); |
| 102 | |
| 103 | panel_info.vl_col = w; |
| 104 | panel_info.vl_row = h; |
| 105 | panel_info.vl_bpix = LCD_COLOR16; |
| 106 | |
Stephen Warren | 888a90c | 2016-02-06 10:42:43 -0700 | [diff] [blame] | 107 | gd->fb_base = bus_to_phys( |
| 108 | msg_setup->allocate_buffer.body.resp.fb_address); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void lcd_enable(void) |
| 112 | { |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | int lcd_get_size(int *line_length) |
| 116 | { |
| 117 | *line_length = bcm2835_pitch; |
| 118 | return *line_length * panel_info.vl_row; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 119 | } |