blob: 5a22182df80efdfedd6228d8aea6c4a2b022b076 [file] [log] [blame]
Libra Li7d3649a2009-10-13 16:56:58 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <arch/io.h>
Stefan Reinauer23836e22010-04-15 12:39:29 +000024#include <boot/tables.h>
Libra Li7d3649a2009-10-13 16:56:58 +000025#include <cpu/x86/msr.h>
26#include <cpu/amd/mtrr.h>
27#include <device/pci_def.h>
Stefan Reinauer523ebd92010-04-14 18:59:42 +000028#include <southbridge/amd/sb600/sb600.h>
29#include <superio/ite/it8712f/it8712f.h>
Libra Li7d3649a2009-10-13 16:56:58 +000030#include "chip.h"
Libra Li031029d2009-11-09 11:53:41 +000031#include "tn_post_code.h"
Libra Lic1436932009-12-23 19:16:47 +000032#include "vgabios.h"
Libra Li7d3649a2009-10-13 16:56:58 +000033
34#define ADT7461_ADDRESS 0x4C
35#define ARA_ADDRESS 0x0C /* Alert Response Address */
36#define SMBUS_IO_BASE 0x1000
37
Libra Lic1436932009-12-23 19:16:47 +000038
39/* Video BIOS Function Extensions Specification
40 */
41//Callback Sub-Function 00h - Get LCD Panel ID
42#define LCD_PANEL_ID_NO 0x00 /* No LCD */
43#define LCD_PANEL_ID_01 0x01 /* 1024x768, 24 bits, 1 channel */
44#define LCD_PANEL_ID_02 0x02 /* 1280x1024, 24 bits, 2 channels */
45#define LCD_PANEL_ID_03 0x03 /* 1440x900, 24 bits, 2 channels */
46#define LCD_PANEL_ID_04 0x04 /* 1680x1050, 24 bits, 2 channels */
47#define LCD_PANEL_ID_05 0x05 /* 1920x1200, 24 bits, 2 channels */
48#define LCD_PANEL_ID_06 0x06 /* 1920x1080, 24 bits, 2 channels */
49//Callback Sub-Function 05h – Select Boot-up TV Standard
50#define TV_MODE_00 0x00 /* NTSC */
51#define TV_MODE_01 0x01 /* PAL */
52#define TV_MODE_02 0x02 /* PALM */
53#define TV_MODE_03 0x03 /* PAL60 */
54#define TV_MODE_04 0x04 /* NTSCJ */
55#define TV_MODE_05 0x05 /* PALCN */
56#define TV_MODE_06 0x06 /* PALN */
57#define TV_MODE_09 0x09 /* SCART-RGB */
58#define TV_MODE_NO 0xff /* No TV Support */
59
Libra Lic1436932009-12-23 19:16:47 +000060/* The base address is 0x2e or 0x4e, depending on config bytes. */
61#define SIO_BASE 0x2e
62#define SIO_INDEX SIO_BASE
63#define SIO_DATA SIO_BASE+1
64
65/* Global configuration registers. */
66#define IT8712F_CONFIG_REG_CC 0x02 /* Configure Control (write-only). */
67#define IT8712F_CONFIG_REG_LDN 0x07 /* Logical Device Number. */
68#define IT8712F_CONFIG_REG_CONFIGSEL 0x22 /* Configuration Select. */
69#define IT8712F_CONFIG_REG_CLOCKSEL 0x23 /* Clock Selection. */
70#define IT8712F_CONFIG_REG_SWSUSP 0x24 /* Software Suspend, Flash I/F. */
71#define IT8712F_CONFIG_REG_MFC 0x2a /* Multi-function control */
72#define IT8712F_CONFIG_REG_WATCHDOG 0x72 /* Watchdog control. */
73
74#define IT8712F_CONFIGURATION_PORT 0x2e /* Write-only. */
75#define IT8712F_SIMPLE_IO_BASE 0x200 /* Simple I/O base address */
76
Stefan Reinauer523ebd92010-04-14 18:59:42 +000077int do_smbus_read_byte(u32 smbus_io_base, u32 device, u32 address);
78int do_smbus_write_byte(u32 smbus_io_base, u32 device, u32 address, u8 val);
Libra Li7d3649a2009-10-13 16:56:58 +000079#define ADT7461_read_byte(address) \
80 do_smbus_read_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address)
81#define ARA_read_byte(address) \
82 do_smbus_read_byte(SMBUS_IO_BASE, ARA_ADDRESS, address)
83#define ADT7461_write_byte(address, val) \
84 do_smbus_write_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address, val)
85
Libra Li7d3649a2009-10-13 16:56:58 +000086
Libra Lic1436932009-12-23 19:16:47 +000087/* The content of IT8712F_CONFIG_REG_LDN (index 0x07) must be set to the
88 LDN the register belongs to, before you can access the register. */
89static void it8712f_sio_write(uint8_t ldn, uint8_t index, uint8_t value)
90{
91 outb(IT8712F_CONFIG_REG_LDN, SIO_BASE);
92 outb(ldn, SIO_DATA);
93 outb(index, SIO_BASE);
94 outb(value, SIO_DATA);
95}
96
97static void it8712f_enter_conf(void)
98{
99 /* Enter the configuration state (MB PnP mode). */
100
101 /* Perform MB PnP setup to put the SIO chip at 0x2e. */
102 /* Base address 0x2e: 0x87 0x01 0x55 0x55. */
103 /* Base address 0x4e: 0x87 0x01 0x55 0xaa. */
104 outb(0x87, IT8712F_CONFIGURATION_PORT);
105 outb(0x01, IT8712F_CONFIGURATION_PORT);
106 outb(0x55, IT8712F_CONFIGURATION_PORT);
107 outb(0x55, IT8712F_CONFIGURATION_PORT);
108}
109
110static void it8712f_exit_conf(void)
111{
112 /* Exit the configuration state (MB PnP mode). */
113 it8712f_sio_write(0x00, IT8712F_CONFIG_REG_CC, 0x02);
114}
115
Libra Li7d3649a2009-10-13 16:56:58 +0000116/* set thermal config
117 */
Libra Li031029d2009-11-09 11:53:41 +0000118static void set_thermal_config(void)
Libra Li7d3649a2009-10-13 16:56:58 +0000119{
120 u8 byte;
121 u16 word;
122 device_t sm_dev;
123
124 /* set ADT 7461 */
125 ADT7461_write_byte(0x0B, 0x50); /* Local Temperature Hight limit */
126 ADT7461_write_byte(0x0C, 0x00); /* Local Temperature Low limit */
127 ADT7461_write_byte(0x0D, 0x50); /* External Temperature Hight limit High Byte */
128 ADT7461_write_byte(0x0E, 0x00); /* External Temperature Low limit High Byte */
129
130 ADT7461_write_byte(0x19, 0x55); /* External THERM limit */
131 ADT7461_write_byte(0x20, 0x55); /* Local THERM limit */
132
133 byte = ADT7461_read_byte(0x02); /* read status register to clear it */
134 ARA_read_byte(0x05); /* A hardware alert can only be cleared by the master sending an ARA as a read command */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000135 printk(BIOS_INFO, "Init adt7461 end , status 0x02 %02x\n", byte);
Libra Li7d3649a2009-10-13 16:56:58 +0000136
137 /* sb600 settings for thermal config */
138 /* set SB600 GPIO 64 to GPIO with pull-up */
139 byte = pm2_ioread(0x42);
140 byte &= 0x3f;
141 pm2_iowrite(0x42, byte);
142
143 /* set GPIO 64 to input */
144 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
145 word = pci_read_config16(sm_dev, 0x56);
146 word |= 1 << 7;
147 pci_write_config16(sm_dev, 0x56, word);
148
149 /* set GPIO 64 internal pull-up */
150 byte = pm2_ioread(0xf0);
151 byte &= 0xee;
152 pm2_iowrite(0xf0, byte);
153
154 /* set Talert to be active low */
155 byte = pm_ioread(0x67);
156 byte &= ~(1 << 5);
157 pm_iowrite(0x67, byte);
158
159 /* set Talert to generate ACPI event */
160 byte = pm_ioread(0x3c);
161 byte &= 0xf3;
162 pm_iowrite(0x3c, byte);
163
164 /* THERMTRIP pin */
165 /* byte = pm_ioread(0x68);
166 * byte |= 1 << 3;
167 * pm_iowrite(0x68, byte);
168 *
169 * byte = pm_ioread(0x55);
170 * byte |= 1 << 0;
171 * pm_iowrite(0x55, byte);
172 *
173 * byte = pm_ioread(0x67);
174 * byte &= ~( 1 << 6);
175 * pm_iowrite(0x67, byte);
176 */
177}
178
Libra Lic1436932009-12-23 19:16:47 +0000179/* Mainboard specific GPIO setup. */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000180static void mb_gpio_init(u16 *iobase)
Libra Lic1436932009-12-23 19:16:47 +0000181{
182 /* Init Super I/O GPIOs. */
183 it8712f_enter_conf();
184 outb(IT8712F_CONFIG_REG_LDN, SIO_INDEX);
185 outb(IT8712F_GPIO, SIO_DATA);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000186 outb(0x62, SIO_INDEX);
Libra Lic1436932009-12-23 19:16:47 +0000187 outb((*iobase >> 8), SIO_DATA);
188 outb(0x63, SIO_INDEX);
189 outb((*iobase & 0xff), SIO_DATA);
190 it8712f_exit_conf();
191}
192
193/* The LCD's panel id seletion. */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000194static void lcd_panel_id(rs690_vbios_regs *vbios_regs, u8 num_id)
Libra Lic1436932009-12-23 19:16:47 +0000195{
196 switch (num_id) {
197 case 0x1:
198 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_01;
199 break;
200 case 0x2:
201 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_02;
202 break;
203 case 0x3:
204 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_03;
205 break;
206 case 0x4:
207 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_04;
208 break;
209 case 0x5:
210 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_05;
211 break;
212 case 0x6:
213 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_06;
214 break;
215 default:
216 vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_NO;
217 break;
218 }
219}
220
Libra Li7d3649a2009-10-13 16:56:58 +0000221/*************************************************
222* enable the dedicated function in tim5690 board.
223* This function called early than rs690_enable.
224*************************************************/
Stefan Reinauer523ebd92010-04-14 18:59:42 +0000225static void tim5690_enable(device_t dev)
Libra Li7d3649a2009-10-13 16:56:58 +0000226{
Libra Lic1436932009-12-23 19:16:47 +0000227 rs690_vbios_regs vbios_regs;
228 u16 gpio_base = IT8712F_SIMPLE_IO_BASE;
229 u8 port2;
230
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000231 printk(BIOS_INFO, "Mainboard tim5690 Enable. dev=0x%p\n", dev);
Libra Li7d3649a2009-10-13 16:56:58 +0000232
Libra Lic1436932009-12-23 19:16:47 +0000233 mb_gpio_init(&gpio_base);
234
235 /* The LCD's panel id seletion by switch. */
236 port2 = inb(gpio_base+1);
237 lcd_panel_id(&vbios_regs, ((~port2) & 0xf));
Stefan Reinauer23836e22010-04-15 12:39:29 +0000238
Libra Lic1436932009-12-23 19:16:47 +0000239 /* No support TV */
240 vbios_regs.int15_regs.fun05_tv_standard = TV_MODE_NO;
241 vgabios_init(&vbios_regs);
242
Kyösti Mälkkiba589e32012-07-11 08:03:13 +0300243 setup_uma_memory();
Libra Li7d3649a2009-10-13 16:56:58 +0000244
Libra Li7d3649a2009-10-13 16:56:58 +0000245 set_thermal_config();
246}
247
248int add_mainboard_resources(struct lb_memory *mem)
249{
Libra Li031029d2009-11-09 11:53:41 +0000250 technexion_post_code(LED_MESSAGE_FINISH);
Stefan Reinauer523ebd92010-04-14 18:59:42 +0000251 return 0;
Libra Li7d3649a2009-10-13 16:56:58 +0000252}
253
254struct chip_operations mainboard_ops = {
255 CHIP_NAME("TechNexion TIM-5690 Mainboard")
256 .enable_dev = tim5690_enable,
257};