Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 1 | /* |
| 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. |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <arch/io.h> |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 20 | #include <cpu/x86/msr.h> |
| 21 | #include <cpu/amd/mtrr.h> |
| 22 | #include <device/pci_def.h> |
Stefan Reinauer | 523ebd9 | 2010-04-14 18:59:42 +0000 | [diff] [blame] | 23 | #include <southbridge/amd/sb600/sb600.h> |
| 24 | #include <superio/ite/it8712f/it8712f.h> |
Libra Li | 031029d | 2009-11-09 11:53:41 +0000 | [diff] [blame] | 25 | #include "tn_post_code.h" |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 26 | #include "vgabios.h" |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 27 | |
| 28 | #define ADT7461_ADDRESS 0x4C |
| 29 | #define ARA_ADDRESS 0x0C /* Alert Response Address */ |
| 30 | #define SMBUS_IO_BASE 0x1000 |
| 31 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 32 | |
| 33 | /* Video BIOS Function Extensions Specification |
| 34 | */ |
| 35 | //Callback Sub-Function 00h - Get LCD Panel ID |
| 36 | #define LCD_PANEL_ID_NO 0x00 /* No LCD */ |
| 37 | #define LCD_PANEL_ID_01 0x01 /* 1024x768, 24 bits, 1 channel */ |
| 38 | #define LCD_PANEL_ID_02 0x02 /* 1280x1024, 24 bits, 2 channels */ |
| 39 | #define LCD_PANEL_ID_03 0x03 /* 1440x900, 24 bits, 2 channels */ |
| 40 | #define LCD_PANEL_ID_04 0x04 /* 1680x1050, 24 bits, 2 channels */ |
| 41 | #define LCD_PANEL_ID_05 0x05 /* 1920x1200, 24 bits, 2 channels */ |
| 42 | #define LCD_PANEL_ID_06 0x06 /* 1920x1080, 24 bits, 2 channels */ |
| 43 | //Callback Sub-Function 05h – Select Boot-up TV Standard |
| 44 | #define TV_MODE_00 0x00 /* NTSC */ |
| 45 | #define TV_MODE_01 0x01 /* PAL */ |
| 46 | #define TV_MODE_02 0x02 /* PALM */ |
| 47 | #define TV_MODE_03 0x03 /* PAL60 */ |
| 48 | #define TV_MODE_04 0x04 /* NTSCJ */ |
| 49 | #define TV_MODE_05 0x05 /* PALCN */ |
| 50 | #define TV_MODE_06 0x06 /* PALN */ |
| 51 | #define TV_MODE_09 0x09 /* SCART-RGB */ |
| 52 | #define TV_MODE_NO 0xff /* No TV Support */ |
| 53 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 54 | /* The base address is 0x2e or 0x4e, depending on config bytes. */ |
| 55 | #define SIO_BASE 0x2e |
| 56 | #define SIO_INDEX SIO_BASE |
| 57 | #define SIO_DATA SIO_BASE+1 |
| 58 | |
| 59 | /* Global configuration registers. */ |
| 60 | #define IT8712F_CONFIG_REG_CC 0x02 /* Configure Control (write-only). */ |
| 61 | #define IT8712F_CONFIG_REG_LDN 0x07 /* Logical Device Number. */ |
| 62 | #define IT8712F_CONFIG_REG_CONFIGSEL 0x22 /* Configuration Select. */ |
| 63 | #define IT8712F_CONFIG_REG_CLOCKSEL 0x23 /* Clock Selection. */ |
| 64 | #define IT8712F_CONFIG_REG_SWSUSP 0x24 /* Software Suspend, Flash I/F. */ |
| 65 | #define IT8712F_CONFIG_REG_MFC 0x2a /* Multi-function control */ |
| 66 | #define IT8712F_CONFIG_REG_WATCHDOG 0x72 /* Watchdog control. */ |
| 67 | |
| 68 | #define IT8712F_CONFIGURATION_PORT 0x2e /* Write-only. */ |
| 69 | #define IT8712F_SIMPLE_IO_BASE 0x200 /* Simple I/O base address */ |
| 70 | |
Stefan Reinauer | 523ebd9 | 2010-04-14 18:59:42 +0000 | [diff] [blame] | 71 | int do_smbus_read_byte(u32 smbus_io_base, u32 device, u32 address); |
| 72 | int do_smbus_write_byte(u32 smbus_io_base, u32 device, u32 address, u8 val); |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 73 | #define ADT7461_read_byte(address) \ |
| 74 | do_smbus_read_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address) |
| 75 | #define ARA_read_byte(address) \ |
| 76 | do_smbus_read_byte(SMBUS_IO_BASE, ARA_ADDRESS, address) |
| 77 | #define ADT7461_write_byte(address, val) \ |
| 78 | do_smbus_write_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address, val) |
| 79 | |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 80 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 81 | /* The content of IT8712F_CONFIG_REG_LDN (index 0x07) must be set to the |
| 82 | LDN the register belongs to, before you can access the register. */ |
| 83 | static void it8712f_sio_write(uint8_t ldn, uint8_t index, uint8_t value) |
| 84 | { |
| 85 | outb(IT8712F_CONFIG_REG_LDN, SIO_BASE); |
| 86 | outb(ldn, SIO_DATA); |
| 87 | outb(index, SIO_BASE); |
| 88 | outb(value, SIO_DATA); |
| 89 | } |
| 90 | |
| 91 | static void it8712f_enter_conf(void) |
| 92 | { |
| 93 | /* Enter the configuration state (MB PnP mode). */ |
| 94 | |
| 95 | /* Perform MB PnP setup to put the SIO chip at 0x2e. */ |
| 96 | /* Base address 0x2e: 0x87 0x01 0x55 0x55. */ |
| 97 | /* Base address 0x4e: 0x87 0x01 0x55 0xaa. */ |
| 98 | outb(0x87, IT8712F_CONFIGURATION_PORT); |
| 99 | outb(0x01, IT8712F_CONFIGURATION_PORT); |
| 100 | outb(0x55, IT8712F_CONFIGURATION_PORT); |
| 101 | outb(0x55, IT8712F_CONFIGURATION_PORT); |
| 102 | } |
| 103 | |
| 104 | static void it8712f_exit_conf(void) |
| 105 | { |
| 106 | /* Exit the configuration state (MB PnP mode). */ |
| 107 | it8712f_sio_write(0x00, IT8712F_CONFIG_REG_CC, 0x02); |
| 108 | } |
| 109 | |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 110 | /* set thermal config |
| 111 | */ |
Libra Li | 031029d | 2009-11-09 11:53:41 +0000 | [diff] [blame] | 112 | static void set_thermal_config(void) |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 113 | { |
| 114 | u8 byte; |
| 115 | u16 word; |
| 116 | device_t sm_dev; |
| 117 | |
| 118 | /* set ADT 7461 */ |
| 119 | ADT7461_write_byte(0x0B, 0x50); /* Local Temperature Hight limit */ |
| 120 | ADT7461_write_byte(0x0C, 0x00); /* Local Temperature Low limit */ |
| 121 | ADT7461_write_byte(0x0D, 0x50); /* External Temperature Hight limit High Byte */ |
| 122 | ADT7461_write_byte(0x0E, 0x00); /* External Temperature Low limit High Byte */ |
| 123 | |
| 124 | ADT7461_write_byte(0x19, 0x55); /* External THERM limit */ |
| 125 | ADT7461_write_byte(0x20, 0x55); /* Local THERM limit */ |
| 126 | |
| 127 | byte = ADT7461_read_byte(0x02); /* read status register to clear it */ |
| 128 | ARA_read_byte(0x05); /* A hardware alert can only be cleared by the master sending an ARA as a read command */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 129 | printk(BIOS_INFO, "Init adt7461 end , status 0x02 %02x\n", byte); |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 130 | |
| 131 | /* sb600 settings for thermal config */ |
| 132 | /* set SB600 GPIO 64 to GPIO with pull-up */ |
| 133 | byte = pm2_ioread(0x42); |
| 134 | byte &= 0x3f; |
| 135 | pm2_iowrite(0x42, byte); |
| 136 | |
| 137 | /* set GPIO 64 to input */ |
| 138 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 139 | word = pci_read_config16(sm_dev, 0x56); |
| 140 | word |= 1 << 7; |
| 141 | pci_write_config16(sm_dev, 0x56, word); |
| 142 | |
| 143 | /* set GPIO 64 internal pull-up */ |
| 144 | byte = pm2_ioread(0xf0); |
| 145 | byte &= 0xee; |
| 146 | pm2_iowrite(0xf0, byte); |
| 147 | |
| 148 | /* set Talert to be active low */ |
| 149 | byte = pm_ioread(0x67); |
| 150 | byte &= ~(1 << 5); |
| 151 | pm_iowrite(0x67, byte); |
| 152 | |
| 153 | /* set Talert to generate ACPI event */ |
| 154 | byte = pm_ioread(0x3c); |
| 155 | byte &= 0xf3; |
| 156 | pm_iowrite(0x3c, byte); |
| 157 | |
| 158 | /* THERMTRIP pin */ |
| 159 | /* byte = pm_ioread(0x68); |
| 160 | * byte |= 1 << 3; |
| 161 | * pm_iowrite(0x68, byte); |
| 162 | * |
| 163 | * byte = pm_ioread(0x55); |
| 164 | * byte |= 1 << 0; |
| 165 | * pm_iowrite(0x55, byte); |
| 166 | * |
| 167 | * byte = pm_ioread(0x67); |
| 168 | * byte &= ~( 1 << 6); |
| 169 | * pm_iowrite(0x67, byte); |
| 170 | */ |
| 171 | } |
| 172 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 173 | /* Mainboard specific GPIO setup. */ |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 174 | static void mb_gpio_init(u16 *iobase) |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 175 | { |
| 176 | /* Init Super I/O GPIOs. */ |
| 177 | it8712f_enter_conf(); |
| 178 | outb(IT8712F_CONFIG_REG_LDN, SIO_INDEX); |
| 179 | outb(IT8712F_GPIO, SIO_DATA); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 180 | outb(0x62, SIO_INDEX); |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 181 | outb((*iobase >> 8), SIO_DATA); |
| 182 | outb(0x63, SIO_INDEX); |
| 183 | outb((*iobase & 0xff), SIO_DATA); |
| 184 | it8712f_exit_conf(); |
| 185 | } |
| 186 | |
Stefan Reinauer | bdc1816 | 2012-11-27 12:44:18 -0800 | [diff] [blame] | 187 | #if CONFIG_VGA_ROM_RUN |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 188 | /* The LCD's panel id seletion. */ |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 189 | static void lcd_panel_id(rs690_vbios_regs *vbios_regs, u8 num_id) |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 190 | { |
| 191 | switch (num_id) { |
| 192 | case 0x1: |
| 193 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_01; |
| 194 | break; |
| 195 | case 0x2: |
| 196 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_02; |
| 197 | break; |
| 198 | case 0x3: |
| 199 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_03; |
| 200 | break; |
| 201 | case 0x4: |
| 202 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_04; |
| 203 | break; |
| 204 | case 0x5: |
| 205 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_05; |
| 206 | break; |
| 207 | case 0x6: |
| 208 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_06; |
| 209 | break; |
| 210 | default: |
| 211 | vbios_regs->int15_regs.fun00_panel_id = LCD_PANEL_ID_NO; |
| 212 | break; |
| 213 | } |
| 214 | } |
Stefan Reinauer | bdc1816 | 2012-11-27 12:44:18 -0800 | [diff] [blame] | 215 | #endif |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 216 | |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 217 | /************************************************* |
| 218 | * enable the dedicated function in tim5690 board. |
| 219 | * This function called early than rs690_enable. |
| 220 | *************************************************/ |
Paul Menzel | 528640d | 2013-02-23 21:31:23 +0100 | [diff] [blame] | 221 | static void mainboard_enable(device_t dev) |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 222 | { |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 223 | u16 gpio_base = IT8712F_SIMPLE_IO_BASE; |
Stefan Reinauer | bdc1816 | 2012-11-27 12:44:18 -0800 | [diff] [blame] | 224 | #if CONFIG_VGA_ROM_RUN |
| 225 | rs690_vbios_regs vbios_regs; |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 226 | u8 port2; |
Stefan Reinauer | bdc1816 | 2012-11-27 12:44:18 -0800 | [diff] [blame] | 227 | #endif |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 228 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 229 | printk(BIOS_INFO, "Mainboard tim5690 Enable. dev=0x%p\n", dev); |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 230 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 231 | mb_gpio_init(&gpio_base); |
| 232 | |
Stefan Reinauer | bdc1816 | 2012-11-27 12:44:18 -0800 | [diff] [blame] | 233 | #if CONFIG_VGA_ROM_RUN |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 234 | /* The LCD's panel id seletion by switch. */ |
| 235 | port2 = inb(gpio_base+1); |
| 236 | lcd_panel_id(&vbios_regs, ((~port2) & 0xf)); |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 237 | |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 238 | /* No support TV */ |
| 239 | vbios_regs.int15_regs.fun05_tv_standard = TV_MODE_NO; |
| 240 | vgabios_init(&vbios_regs); |
Stefan Reinauer | bdc1816 | 2012-11-27 12:44:18 -0800 | [diff] [blame] | 241 | #endif |
Libra Li | c143693 | 2009-12-23 19:16:47 +0000 | [diff] [blame] | 242 | |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 243 | set_thermal_config(); |
| 244 | } |
| 245 | |
Kyösti Mälkki | cc3b188 | 2012-08-02 09:44:14 +0300 | [diff] [blame] | 246 | void mainboard_post(u8 value) |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 247 | { |
Kyösti Mälkki | cc3b188 | 2012-08-02 09:44:14 +0300 | [diff] [blame] | 248 | switch (value) { |
| 249 | case POST_ENTER_ELF_BOOT: |
| 250 | technexion_post_code(LED_MESSAGE_FINISH); |
| 251 | break; |
| 252 | } |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | struct chip_operations mainboard_ops = { |
Paul Menzel | 528640d | 2013-02-23 21:31:23 +0100 | [diff] [blame] | 256 | .enable_dev = mainboard_enable, |
Libra Li | 7d3649a | 2009-10-13 16:56:58 +0000 | [diff] [blame] | 257 | }; |