Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2000 AG Electronics Ltd. |
| 5 | * Copyright (C) 2003-2004 Linux Networx |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004 Tyan |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 7 | * Copyright (C) 2007 AMD |
| 8 | * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <arch/io.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pnp.h> |
| 27 | #include <console/console.h> |
| 28 | #include <string.h> |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 29 | #include <uart8250.h> |
| 30 | #include <pc80/keyboard.h> |
| 31 | #include <pc80/mc146818rtc.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 32 | #include <stdlib.h> |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 33 | #include "chip.h" |
| 34 | #include "w83627ehg.h" |
| 35 | |
| 36 | static void pnp_enter_ext_func_mode(device_t dev) |
| 37 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 38 | outb(0x87, dev->path.pnp.port); |
| 39 | outb(0x87, dev->path.pnp.port); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void pnp_exit_ext_func_mode(device_t dev) |
| 43 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 44 | outb(0xaa, dev->path.pnp.port); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 47 | static void pnp_write_index(u16 port, u8 reg, u8 value) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 48 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 49 | outb(reg, port); |
| 50 | outb(value, port + 1); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 53 | static u8 pnp_read_index(u16 port, u8 reg) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 54 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 55 | outb(reg, port); |
| 56 | return inb(port + 1); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 59 | static void enable_hwm_smbus(device_t dev) |
| 60 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 61 | u8 reg8; |
| 62 | |
| 63 | /* Configure pins 91/92 as SDA/SCL (I2C bus). */ |
| 64 | reg8 = pnp_read_config(dev, 0x2a); |
| 65 | reg8 |= (1 << 1); |
| 66 | pnp_write_config(dev, 0x2a, reg8); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static void init_acpi(device_t dev) |
| 70 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 71 | u8 value = 0x20; /* TODO: 0x20 value here never used? */ |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 72 | int power_on = 1; |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 73 | |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 74 | get_option(&power_on, "power_on_after_fail"); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 75 | pnp_enter_ext_func_mode(dev); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 76 | pnp_set_logical_device(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 77 | value = pnp_read_config(dev, 0xe4); |
| 78 | value &= ~(3 << 5); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 79 | if (power_on) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 80 | value |= (1 << 5); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 81 | pnp_write_config(dev, 0xe4, value); |
| 82 | pnp_exit_ext_func_mode(dev); |
| 83 | } |
| 84 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 85 | static void init_hwm(u16 base) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 86 | { |
| 87 | int i; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 88 | u8 reg, value; |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 89 | |
| 90 | /* reg mask data */ |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 91 | u8 hwm_reg_values[] = { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 92 | 0x40, 0xff, 0x81, /* Start HWM. */ |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 93 | 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */ |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 96 | for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 97 | reg = hwm_reg_values[i]; |
| 98 | value = pnp_read_index(base, reg); |
| 99 | value &= 0xff & (~(hwm_reg_values[i + 1])); |
| 100 | value |= 0xff & hwm_reg_values[i + 2]; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 101 | printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, " |
| 102 | "value = 0x%02x\n", base, reg, value); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 103 | pnp_write_index(base, reg, value); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static void w83627ehg_init(device_t dev) |
| 108 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 109 | struct superio_winbond_w83627ehg_config *conf = dev->chip_info; |
Uwe Hermann | 5330dd9 | 2010-11-11 13:14:55 +0000 | [diff] [blame] | 110 | struct resource *res0; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 111 | |
| 112 | if (!dev->enabled) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 113 | return; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 114 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 115 | switch(dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 116 | case W83627EHG_KBC: |
Stefan Reinauer | 740b587 | 2010-02-23 20:31:37 +0000 | [diff] [blame] | 117 | pc_keyboard_init(&conf->keyboard); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 118 | break; |
| 119 | case W83627EHG_HWM: |
| 120 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 121 | #define HWM_INDEX_PORT 5 |
| 122 | init_hwm(res0->base + HWM_INDEX_PORT); |
| 123 | break; |
| 124 | case W83627EHG_ACPI: |
| 125 | init_acpi(dev); |
| 126 | break; |
| 127 | } |
| 128 | } |
| 129 | |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 130 | static void w83627ehg_pnp_set_resources(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 131 | { |
| 132 | pnp_enter_ext_func_mode(dev); |
| 133 | pnp_set_resources(dev); |
| 134 | pnp_exit_ext_func_mode(dev); |
| 135 | } |
| 136 | |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 137 | static void w83627ehg_pnp_enable_resources(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 138 | { |
| 139 | pnp_enter_ext_func_mode(dev); |
| 140 | pnp_enable_resources(dev); |
| 141 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 142 | switch (dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 143 | case W83627EHG_HWM: |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 144 | printk(BIOS_DEBUG, "W83627EHG HWM SMBus enabled\n"); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 145 | enable_hwm_smbus(dev); |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | pnp_exit_ext_func_mode(dev); |
| 150 | } |
| 151 | |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 152 | static void w83627ehg_pnp_enable(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 153 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 154 | pnp_enter_ext_func_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 155 | pnp_alt_enable(dev); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 156 | pnp_exit_ext_func_mode(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static struct device_operations ops = { |
| 160 | .read_resources = pnp_read_resources, |
| 161 | .set_resources = w83627ehg_pnp_set_resources, |
| 162 | .enable_resources = w83627ehg_pnp_enable_resources, |
| 163 | .enable = w83627ehg_pnp_enable, |
| 164 | .init = w83627ehg_init, |
| 165 | }; |
| 166 | |
| 167 | static struct pnp_info pnp_dev_info[] = { |
Uwe Hermann | 3a4ed15 | 2010-12-05 22:36:14 +0000 | [diff] [blame] | 168 | { &ops, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 169 | { &ops, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 170 | { &ops, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 171 | { &ops, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 172 | { &ops, W83627EHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, }, |
| 173 | { &ops, W83627EHG_SFI, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 174 | { &ops, W83627EHG_WDTO_PLED, }, |
Uwe Hermann | 3a4ed15 | 2010-12-05 22:36:14 +0000 | [diff] [blame] | 175 | { &ops, W83627EHG_ACPI, PNP_IRQ0, }, |
| 176 | { &ops, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, {0x07fe, 0}, }, |
| 177 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 178 | { &ops, W83627EHG_GAME, PNP_IO0, {0x07ff, 0}, }, |
Alexandru Gagniuc | 4a038ca | 2011-02-08 02:36:39 +0000 | [diff] [blame] | 179 | { &ops, W83627EHG_MIDI, PNP_IO1 | PNP_IRQ0, {0, 0}, {0x07fe, 4}, }, |
Rudolf Marek | 8dcab78 | 2008-02-18 20:37:49 +0000 | [diff] [blame] | 180 | { &ops, W83627EHG_GPIO1, }, |
| 181 | { &ops, W83627EHG_GPIO2, }, |
| 182 | { &ops, W83627EHG_GPIO3, }, |
| 183 | { &ops, W83627EHG_GPIO4, }, |
| 184 | { &ops, W83627EHG_GPIO5, }, |
| 185 | { &ops, W83627EHG_GPIO6, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | static void enable_dev(struct device *dev) |
| 189 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 190 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | struct chip_operations superio_winbond_w83627ehg_ops = { |
| 194 | CHIP_NAME("Winbond W83627EHG Super I/O") |
| 195 | .enable_dev = enable_dev, |
| 196 | }; |