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"); |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 75 | pnp_enter_conf_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); |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 82 | pnp_exit_conf_mode(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 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_enable_resources(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 131 | { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 132 | pnp_enable_resources(dev); |
| 133 | |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 134 | pnp_enter_conf_mode(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 135 | switch (dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 136 | case W83627EHG_HWM: |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 137 | printk(BIOS_DEBUG, "W83627EHG HWM SMBus enabled\n"); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 138 | enable_hwm_smbus(dev); |
| 139 | break; |
| 140 | } |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 141 | pnp_exit_conf_mode(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 144 | static const struct pnp_mode_ops pnp_conf_mode_ops = { |
| 145 | .enter_conf_mode = pnp_enter_ext_func_mode, |
| 146 | .exit_conf_mode = pnp_exit_ext_func_mode, |
| 147 | }; |
| 148 | |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 149 | static struct device_operations ops = { |
| 150 | .read_resources = pnp_read_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 151 | .set_resources = pnp_set_resources, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 152 | .enable_resources = w83627ehg_pnp_enable_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 153 | .enable = pnp_alt_enable, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 154 | .init = w83627ehg_init, |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 155 | .ops_pnp_mode = &pnp_conf_mode_ops, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | static struct pnp_info pnp_dev_info[] = { |
Uwe Hermann | 3a4ed15 | 2010-12-05 22:36:14 +0000 | [diff] [blame] | 159 | { &ops, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 160 | { &ops, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 161 | { &ops, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 162 | { &ops, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 163 | { &ops, W83627EHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, }, |
| 164 | { &ops, W83627EHG_SFI, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 165 | { &ops, W83627EHG_WDTO_PLED, }, |
Uwe Hermann | 3a4ed15 | 2010-12-05 22:36:14 +0000 | [diff] [blame] | 166 | { &ops, W83627EHG_ACPI, PNP_IRQ0, }, |
| 167 | { &ops, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, {0x07fe, 0}, }, |
| 168 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 169 | { &ops, W83627EHG_GAME, PNP_IO0, {0x07ff, 0}, }, |
Alexandru Gagniuc | 4a038ca | 2011-02-08 02:36:39 +0000 | [diff] [blame] | 170 | { &ops, W83627EHG_MIDI, PNP_IO1 | PNP_IRQ0, {0, 0}, {0x07fe, 4}, }, |
Rudolf Marek | 8dcab78 | 2008-02-18 20:37:49 +0000 | [diff] [blame] | 171 | { &ops, W83627EHG_GPIO1, }, |
| 172 | { &ops, W83627EHG_GPIO2, }, |
| 173 | { &ops, W83627EHG_GPIO3, }, |
| 174 | { &ops, W83627EHG_GPIO4, }, |
| 175 | { &ops, W83627EHG_GPIO5, }, |
| 176 | { &ops, W83627EHG_GPIO6, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | static void enable_dev(struct device *dev) |
| 180 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 181 | 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] | 182 | } |
| 183 | |
| 184 | struct chip_operations superio_winbond_w83627ehg_ops = { |
| 185 | CHIP_NAME("Winbond W83627EHG Super I/O") |
| 186 | .enable_dev = enable_dev, |
| 187 | }; |