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 |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 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> |
| 29 | #include <bitops.h> |
| 30 | #include <uart8250.h> |
| 31 | #include <pc80/keyboard.h> |
| 32 | #include <pc80/mc146818rtc.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 33 | #include <stdlib.h> |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 34 | #include "chip.h" |
| 35 | #include "w83627ehg.h" |
| 36 | |
| 37 | static void pnp_enter_ext_func_mode(device_t dev) |
| 38 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 39 | outb(0x87, dev->path.pnp.port); |
| 40 | outb(0x87, dev->path.pnp.port); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static void pnp_exit_ext_func_mode(device_t dev) |
| 44 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 45 | outb(0xaa, dev->path.pnp.port); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static void pnp_write_index(unsigned long port_base, uint8_t reg, uint8_t value) |
| 49 | { |
| 50 | outb(reg, port_base); |
| 51 | outb(value, port_base + 1); |
| 52 | } |
| 53 | |
| 54 | static uint8_t pnp_read_index(unsigned long port_base, uint8_t reg) |
| 55 | { |
| 56 | outb(reg, port_base); |
| 57 | return inb(port_base + 1); |
| 58 | } |
| 59 | |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame^] | 60 | static void enable_hwm_smbus(device_t dev) |
| 61 | { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 62 | /* Set the pin 91,92 as I2C bus. */ |
| 63 | uint8_t reg, value; |
| 64 | reg = 0x2a; |
| 65 | value = pnp_read_config(dev, reg); |
| 66 | value |= (1 << 1); |
| 67 | pnp_write_config(dev, reg, value); |
| 68 | } |
| 69 | |
| 70 | static void init_acpi(device_t dev) |
| 71 | { |
| 72 | uint8_t value = 0x20; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 73 | int power_on = 1; |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 74 | |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 75 | get_option(&power_on, "power_on_after_fail"); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 76 | pnp_enter_ext_func_mode(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 77 | pnp_write_index(dev->path.pnp.port, 7, 0x0a); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 78 | value = pnp_read_config(dev, 0xe4); |
| 79 | value &= ~(3 << 5); |
| 80 | if (power_on) { |
| 81 | value |= (1 << 5); |
| 82 | } |
| 83 | pnp_write_config(dev, 0xe4, value); |
| 84 | pnp_exit_ext_func_mode(dev); |
| 85 | } |
| 86 | |
| 87 | static void init_hwm(unsigned long base) |
| 88 | { |
| 89 | int i; |
| 90 | uint8_t reg, value; |
| 91 | |
| 92 | /* reg mask data */ |
| 93 | unsigned hwm_reg_values[] = { |
| 94 | 0x40, 0xff, 0x81, /* Start HWM. */ |
| 95 | 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x54 >> 1. */ |
| 96 | }; |
| 97 | |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 98 | for(i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 99 | reg = hwm_reg_values[i]; |
| 100 | value = pnp_read_index(base, reg); |
| 101 | value &= 0xff & (~(hwm_reg_values[i + 1])); |
| 102 | value |= 0xff & hwm_reg_values[i + 2]; |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame^] | 103 | /* printk_debug("base = 0x%04x, reg = 0x%02x, value = 0x%02x\r\n", base, reg,value); */ |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 104 | pnp_write_index(base, reg, value); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | static void w83627ehg_init(device_t dev) |
| 109 | { |
| 110 | struct superio_winbond_w83627ehg_config *conf; |
| 111 | struct resource *res0, *res1; |
| 112 | if (!dev->enabled) { |
| 113 | return; |
| 114 | } |
| 115 | conf = dev->chip_info; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 116 | switch(dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 117 | case W83627EHG_SP1: |
| 118 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 119 | init_uart8250(res0->base, &conf->com1); |
| 120 | break; |
| 121 | case W83627EHG_SP2: |
| 122 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 123 | init_uart8250(res0->base, &conf->com2); |
| 124 | break; |
| 125 | case W83627EHG_KBC: |
| 126 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 127 | res1 = find_resource(dev, PNP_IDX_IO1); |
| 128 | init_pc_keyboard(res0->base, res1->base, &conf->keyboard); |
| 129 | break; |
| 130 | case W83627EHG_HWM: |
| 131 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 132 | #define HWM_INDEX_PORT 5 |
| 133 | init_hwm(res0->base + HWM_INDEX_PORT); |
| 134 | break; |
| 135 | case W83627EHG_ACPI: |
| 136 | init_acpi(dev); |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 141 | static void w83627ehg_pnp_set_resources(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 142 | { |
| 143 | pnp_enter_ext_func_mode(dev); |
| 144 | pnp_set_resources(dev); |
| 145 | pnp_exit_ext_func_mode(dev); |
| 146 | } |
| 147 | |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 148 | static void w83627ehg_pnp_enable_resources(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 149 | { |
| 150 | pnp_enter_ext_func_mode(dev); |
| 151 | pnp_enable_resources(dev); |
| 152 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 153 | switch (dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 154 | case W83627EHG_HWM: |
| 155 | printk_debug("w83627ehg hwm smbus enabled\n"); |
| 156 | enable_hwm_smbus(dev); |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | pnp_exit_ext_func_mode(dev); |
| 161 | } |
| 162 | |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 163 | static void w83627ehg_pnp_enable(device_t dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 164 | { |
| 165 | if (!dev->enabled) { |
| 166 | pnp_enter_ext_func_mode(dev); |
| 167 | pnp_set_logical_device(dev); |
| 168 | pnp_set_enable(dev, 0); |
| 169 | pnp_exit_ext_func_mode(dev); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | static struct device_operations ops = { |
| 174 | .read_resources = pnp_read_resources, |
| 175 | .set_resources = w83627ehg_pnp_set_resources, |
| 176 | .enable_resources = w83627ehg_pnp_enable_resources, |
| 177 | .enable = w83627ehg_pnp_enable, |
| 178 | .init = w83627ehg_init, |
| 179 | }; |
| 180 | |
| 181 | static struct pnp_info pnp_dev_info[] = { |
| 182 | { &ops, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, }, |
| 183 | { &ops, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, }, |
| 184 | { &ops, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
| 185 | { &ops, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame^] | 186 | /* No 4 { 0,}, */ |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 187 | { &ops, W83627EHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, }, |
| 188 | { &ops, W83627EHG_SFI, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 189 | { &ops, W83627EHG_WDTO_PLED, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 190 | { &ops, W83627EHG_ACPI, }, |
| 191 | { &ops, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, }, |
Rudolf Marek | 8dcab78 | 2008-02-18 20:37:49 +0000 | [diff] [blame] | 192 | { &ops, W83627EHG_GAME, PNP_IO0, { 0x7ff, 0 }, }, |
| 193 | { &ops, W83627EHG_MIDI, PNP_IO1 | PNP_IRQ0, { 0x7ff, 0 } , {0x7fe, 0x4}, }, |
| 194 | { &ops, W83627EHG_GPIO1, }, |
| 195 | { &ops, W83627EHG_GPIO2, }, |
| 196 | { &ops, W83627EHG_GPIO3, }, |
| 197 | { &ops, W83627EHG_GPIO4, }, |
| 198 | { &ops, W83627EHG_GPIO5, }, |
| 199 | { &ops, W83627EHG_GPIO6, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | static void enable_dev(struct device *dev) |
| 203 | { |
| 204 | pnp_enable_devices(dev, &ops, |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 205 | ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | struct chip_operations superio_winbond_w83627ehg_ops = { |
| 209 | CHIP_NAME("Winbond W83627EHG Super I/O") |
| 210 | .enable_dev = enable_dev, |
| 211 | }; |