f6eee68440ce2a079603f9eaac890c66f9373b06
[coreboot.git] / src / mainboard / thomson / ip1000 / mainboard.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008-2010 Joseph Smith <joe@settoplinux.org>
5  * Copyright (C) 2010 Stefan Reinauer <stepan@openbios.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <console/console.h>
22 #include <device/device.h>
23 #include <boot/tables.h>
24 #include <delay.h>
25 #if CONFIG_PCI_OPTION_ROM_RUN_YABEL
26 #include <x86emu/x86emu.h>
27 #endif
28 #include <arch/coreboot_tables.h>
29 #include <arch/io.h>
30 #include "chip.h"
31
32 int add_mainboard_resources(struct lb_memory *mem)
33 {
34         return add_northbridge_resources(mem);
35 }
36
37 // setting the bit disables the led.
38 #define PARPORT_GPIO_LED_GREEN  (1 << 0)
39 #define PARPORT_GPIO_LED_ORANGE (1 << 1)
40 #define PARPORT_GPIO_LED_RED    (1 << 2)
41 #define PARPORT_GPIO_IR_PORT    (1 << 6)
42
43 static u8 get_parport_gpio(void)
44 {
45         return inb(0x378);
46 }
47
48 static void set_parport_gpio(u8 gpios)
49 {
50         outb(gpios, 0x378);
51 }
52
53 static void parport_gpios(void)
54 {
55         u8 pp_gpios = get_parport_gpio();
56
57         /* disable red led */
58         pp_gpios |= PARPORT_GPIO_LED_RED;
59         set_parport_gpio(pp_gpios);
60
61         pp_gpios = get_parport_gpio();
62
63         printk(BIOS_DEBUG, "IP1000 GPIOs:\n");
64         printk(BIOS_DEBUG, "  GPIO mask:  %02x\n", pp_gpios);
65         printk(BIOS_DEBUG, "  green led:  %s\n",
66                         (pp_gpios & PARPORT_GPIO_LED_GREEN) ? "off" : "on");
67         printk(BIOS_DEBUG, "  orange led: %s\n",
68                         (pp_gpios & PARPORT_GPIO_LED_ORANGE) ? "off" : "on");
69         printk(BIOS_DEBUG, "  red led:    %s\n",
70                         (pp_gpios & PARPORT_GPIO_LED_RED) ? "off" : "on");
71         printk(BIOS_DEBUG, "  IR port:    %s\n",
72                         (pp_gpios & PARPORT_GPIO_IR_PORT) ? "off" : "on");
73 }
74
75 static void flash_gpios(void)
76 {
77         u8 manufacturer_id = read8(0xffbc0000);
78         u8 device_id = read8(0xffbc0001);
79
80         if ((manufacturer_id == 0x20) &&
81                 ((device_id == 0x2c) || (device_id == 0x2d))) {
82                 printk(BIOS_DEBUG, "Detected ST M50FW0%c0 flash:\n",
83                                 (device_id==0x2c)?'4':'8');
84                 u8 fgpi = read8(0xffbc0100);
85                 printk(BIOS_DEBUG, "  FGPI0 [%c] FGPI1 [%c] FGPI2 [%c] FGPI3 [%c] FGPI4 [%c]\n",
86                         (fgpi & (1 << 0)) ? 'X' : ' ',
87                         (fgpi & (1 << 1)) ? 'X' : ' ',
88                         (fgpi & (1 << 2)) ? 'X' : ' ',
89                         (fgpi & (1 << 3)) ? 'X' : ' ',
90                         (fgpi & (1 << 4)) ? 'X' : ' ');
91         } else {
92                 printk(BIOS_DEBUG, "No ST M50FW040/M50FW080 flash, don't read FGPI.\n");
93         }
94 }
95
96
97 #if CONFIG_PCI_OPTION_ROM_RUN_YABEL
98 static int int15_handler(void)
99 {
100 #define BOOT_DISPLAY_DEFAULT    0
101 #define BOOT_DISPLAY_CRT        (1 << 0)
102 #define BOOT_DISPLAY_TV         (1 << 1)
103 #define BOOT_DISPLAY_EFP        (1 << 2)
104 #define BOOT_DISPLAY_LCD        (1 << 3)
105 #define BOOT_DISPLAY_CRT2       (1 << 4)
106 #define BOOT_DISPLAY_TV2        (1 << 5)
107 #define BOOT_DISPLAY_EFP2       (1 << 6)
108 #define BOOT_DISPLAY_LCD2       (1 << 7)
109
110         printk(BIOS_DEBUG, "%s: AX=%04x BX=%04x CX=%04x DX=%04x\n",
111                           __func__, M.x86.R_AX, M.x86.R_BX, M.x86.R_CX, M.x86.R_DX);
112
113         switch (M.x86.R_AX) {
114         case 0x5f35: /* Boot Display */
115                 M.x86.R_AX = 0x005f; // Success
116                 //M.x86.R_CL = BOOT_DISPLAY_TV2;
117                 M.x86.R_CL = BOOT_DISPLAY_DEFAULT;
118                 break;
119         case 0x5f36: /* Boot TV Format Hook */
120                 printk(BIOS_DEBUG, "Boot TV Format Hook. TODO\n");
121                 /* Interrupt was not handled */
122                 return 0;
123         case 0x5f31: /* Post Completion Hook */
124         case 0x5f33: /* Hook After Mode Set */
125         case 0x5f34: /* Set Panel Fitting Hook */
126         case 0x5f38: /* Hook Before Mode Set */
127         case 0x5f45: /* Hook Before VESA VBE/DDC */
128         case 0x5f46: /* Hook Before VESA VBE/PM */
129         case 0x5f47: /* Notif Display Switch Hook */
130         case 0x5f65: /* Local Memory Initialization Hook */
131                 /* Interrupt was not handled */
132                 return 0;
133         default:
134                 /* Interrupt was not handled */
135                 return 0;
136         }
137
138         /* Interrupt handled */
139         return 1;
140 }
141
142 static void int15_install(void)
143 {
144         typedef int (* yabel_handleIntFunc)(void);
145         extern yabel_handleIntFunc yabel_intFuncArray[256];
146         yabel_intFuncArray[0x15] = int15_handler;
147 }
148 #endif
149
150 static void mainboard_init(device_t dev)
151 {
152         parport_gpios();
153         flash_gpios();
154 }
155
156 static void mainboard_enable(device_t dev)
157 {
158         dev->ops->init = mainboard_init;
159 #if CONFIG_PCI_OPTION_ROM_RUN_YABEL
160         /* Install custom int15 handler for VGA OPROM */
161         int15_install();
162 #endif
163 }
164
165 struct chip_operations mainboard_ops = {
166         .enable_dev = mainboard_enable,
167         CHIP_NAME("THOMSON IP1000 Mainboard")
168 };