Stefan Reinauer | 23218f7 | 2012-11-30 06:32:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * coreboot Framebuffer driver. |
| 3 | * |
| 4 | * Copyright (C) 2011 The Chromium OS authors |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <asm/arch/tables.h> |
| 27 | #include <asm/arch/sysinfo.h> |
| 28 | #include <video_fb.h> |
| 29 | #include "videomodes.h" |
| 30 | |
| 31 | /* |
| 32 | * The Graphic Device |
| 33 | */ |
| 34 | GraphicDevice ctfb; |
| 35 | |
| 36 | static int parse_coreboot_table_fb(GraphicDevice *gdev) |
| 37 | { |
| 38 | struct cb_framebuffer *fb = lib_sysinfo.framebuffer; |
| 39 | |
| 40 | /* If there is no framebuffer structure, bail out and keep |
| 41 | * running on the serial console. |
| 42 | */ |
| 43 | if (!fb) |
| 44 | return 0; |
| 45 | |
| 46 | gdev->winSizeX = fb->x_resolution; |
| 47 | gdev->winSizeY = fb->y_resolution; |
| 48 | |
| 49 | gdev->plnSizeX = fb->x_resolution; |
| 50 | gdev->plnSizeY = fb->y_resolution; |
| 51 | |
| 52 | gdev->gdfBytesPP = fb->bits_per_pixel / 8; |
| 53 | |
| 54 | switch (fb->bits_per_pixel) { |
| 55 | case 24: |
| 56 | gdev->gdfIndex = GDF_32BIT_X888RGB; |
| 57 | break; |
| 58 | case 16: |
| 59 | gdev->gdfIndex = GDF_16BIT_565RGB; |
| 60 | break; |
| 61 | default: |
| 62 | gdev->gdfIndex = GDF__8BIT_INDEX; |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | gdev->isaBase = CONFIG_SYS_ISA_IO_BASE_ADDRESS; |
| 67 | gdev->pciBase = (unsigned int)fb->physical_address; |
| 68 | |
| 69 | gdev->frameAdrs = (unsigned int)fb->physical_address; |
| 70 | gdev->memSize = fb->bytes_per_line * fb->y_resolution; |
| 71 | |
| 72 | gdev->vprBase = (unsigned int)fb->physical_address; |
| 73 | gdev->cprBase = (unsigned int)fb->physical_address; |
| 74 | |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | void *video_hw_init(void) |
| 79 | { |
| 80 | GraphicDevice *gdev = &ctfb; |
| 81 | int bits_per_pixel; |
| 82 | |
| 83 | printf("Video: "); |
| 84 | |
| 85 | if (!parse_coreboot_table_fb(gdev)) { |
| 86 | printf("No video mode configured in coreboot!\n"); |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | bits_per_pixel = gdev->gdfBytesPP * 8; |
| 91 | |
| 92 | /* fill in Graphic device struct */ |
| 93 | sprintf(gdev->modeIdent, "%dx%dx%d", gdev->winSizeX, gdev->winSizeY, |
| 94 | bits_per_pixel); |
| 95 | printf("%s\n", gdev->modeIdent); |
| 96 | |
| 97 | memset((void *)gdev->pciBase, 0, |
| 98 | gdev->winSizeX * gdev->winSizeY * gdev->gdfBytesPP); |
| 99 | |
| 100 | return (void *)gdev; |
| 101 | } |