blob: cc65a651608d66ed02423dec537e9a141ac100e2 [file] [log] [blame]
Yinghai Lubc7ceb12007-02-03 15:28:20 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Yinghai Lubc7ceb12007-02-03 15:28:20 +00003 *
4 * Copyright (C) 2000 AG Electronics Ltd.
5 * Copyright (C) 2003-2004 Linux Networx
Zheng Bao9db833b2009-12-28 09:59:44 +00006 * Copyright (C) 2004 Tyan
Yinghai Lubc7ceb12007-02-03 15:28:20 +00007 * 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 Hailfinger2ee67792008-10-01 12:52:52 +000033#include <stdlib.h>
Yinghai Lubc7ceb12007-02-03 15:28:20 +000034#include "chip.h"
35#include "w83627ehg.h"
36
37static void pnp_enter_ext_func_mode(device_t dev)
38{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000039 outb(0x87, dev->path.pnp.port);
40 outb(0x87, dev->path.pnp.port);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000041}
42
43static void pnp_exit_ext_func_mode(device_t dev)
44{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000045 outb(0xaa, dev->path.pnp.port);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000046}
47
Uwe Hermann340fa932010-11-10 14:53:36 +000048static void pnp_write_index(u16 port, u8 reg, u8 value)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000049{
Uwe Hermann340fa932010-11-10 14:53:36 +000050 outb(reg, port);
51 outb(value, port + 1);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000052}
53
Uwe Hermann340fa932010-11-10 14:53:36 +000054static u8 pnp_read_index(u16 port, u8 reg)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000055{
Uwe Hermann340fa932010-11-10 14:53:36 +000056 outb(reg, port);
57 return inb(port + 1);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000058}
59
Zheng Bao9db833b2009-12-28 09:59:44 +000060static void enable_hwm_smbus(device_t dev)
61{
Uwe Hermann340fa932010-11-10 14:53:36 +000062 u8 reg8;
63
64 /* Configure pins 91/92 as SDA/SCL (I2C bus). */
65 reg8 = pnp_read_config(dev, 0x2a);
66 reg8 |= (1 << 1);
67 pnp_write_config(dev, 0x2a, reg8);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000068}
69
70static void init_acpi(device_t dev)
71{
Uwe Hermann340fa932010-11-10 14:53:36 +000072 u8 value = 0x20; /* TODO: 0x20 value here never used? */
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000073 int power_on = 1;
Yinghai Lubc7ceb12007-02-03 15:28:20 +000074
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000075 get_option(&power_on, "power_on_after_fail");
Yinghai Lubc7ceb12007-02-03 15:28:20 +000076 pnp_enter_ext_func_mode(dev);
Uwe Hermann340fa932010-11-10 14:53:36 +000077 pnp_set_logical_device(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000078 value = pnp_read_config(dev, 0xe4);
79 value &= ~(3 << 5);
Uwe Hermann340fa932010-11-10 14:53:36 +000080 if (power_on)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000081 value |= (1 << 5);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000082 pnp_write_config(dev, 0xe4, value);
83 pnp_exit_ext_func_mode(dev);
84}
85
Uwe Hermann340fa932010-11-10 14:53:36 +000086static void init_hwm(u16 base)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000087{
88 int i;
Uwe Hermann340fa932010-11-10 14:53:36 +000089 u8 reg, value;
Yinghai Lubc7ceb12007-02-03 15:28:20 +000090
91 /* reg mask data */
Uwe Hermann340fa932010-11-10 14:53:36 +000092 u8 hwm_reg_values[] = {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000093 0x40, 0xff, 0x81, /* Start HWM. */
Uwe Hermann340fa932010-11-10 14:53:36 +000094 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */
Yinghai Lubc7ceb12007-02-03 15:28:20 +000095 };
96
Uwe Hermann340fa932010-11-10 14:53:36 +000097 for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000098 reg = hwm_reg_values[i];
99 value = pnp_read_index(base, reg);
100 value &= 0xff & (~(hwm_reg_values[i + 1]));
101 value |= 0xff & hwm_reg_values[i + 2];
Uwe Hermann340fa932010-11-10 14:53:36 +0000102 printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, "
103 "value = 0x%02x\n", base, reg, value);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000104 pnp_write_index(base, reg, value);
105 }
106}
107
108static void w83627ehg_init(device_t dev)
109{
Uwe Hermann340fa932010-11-10 14:53:36 +0000110 struct superio_winbond_w83627ehg_config *conf = dev->chip_info;
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000111 struct resource *res0, *res1;
Uwe Hermann340fa932010-11-10 14:53:36 +0000112
113 if (!dev->enabled)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000114 return;
Uwe Hermann340fa932010-11-10 14:53:36 +0000115
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000116 switch(dev->path.pnp.device) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000117 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);
Stefan Reinauer740b5872010-02-23 20:31:37 +0000128 pc_keyboard_init(&conf->keyboard);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000129 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 Watson7943fe62009-10-30 02:08:07 +0000141static void w83627ehg_pnp_set_resources(device_t dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000142{
143 pnp_enter_ext_func_mode(dev);
144 pnp_set_resources(dev);
145 pnp_exit_ext_func_mode(dev);
146}
147
Myles Watson7943fe62009-10-30 02:08:07 +0000148static void w83627ehg_pnp_enable_resources(device_t dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000149{
150 pnp_enter_ext_func_mode(dev);
151 pnp_enable_resources(dev);
152
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000153 switch (dev->path.pnp.device) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000154 case W83627EHG_HWM:
Uwe Hermann340fa932010-11-10 14:53:36 +0000155 printk(BIOS_DEBUG, "W83627EHG HWM SMBus enabled\n");
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000156 enable_hwm_smbus(dev);
157 break;
158 }
159
160 pnp_exit_ext_func_mode(dev);
161}
162
Myles Watson7943fe62009-10-30 02:08:07 +0000163static void w83627ehg_pnp_enable(device_t dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000164{
Uwe Hermann340fa932010-11-10 14:53:36 +0000165 if (dev->enabled)
166 return;
167
168 pnp_enter_ext_func_mode(dev);
169 pnp_set_logical_device(dev);
170 pnp_set_enable(dev, 0);
171 pnp_exit_ext_func_mode(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000172}
173
174static struct device_operations ops = {
175 .read_resources = pnp_read_resources,
176 .set_resources = w83627ehg_pnp_set_resources,
177 .enable_resources = w83627ehg_pnp_enable_resources,
178 .enable = w83627ehg_pnp_enable,
179 .init = w83627ehg_init,
180};
181
182static struct pnp_info pnp_dev_info[] = {
183 { &ops, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
184 { &ops, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
185 { &ops, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
186 { &ops, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000187 { &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 Lubc7ceb12007-02-03 15:28:20 +0000189 { &ops, W83627EHG_WDTO_PLED, },
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000190 { &ops, W83627EHG_ACPI, },
191 { &ops, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, },
Rudolf Marek8dcab782008-02-18 20:37:49 +0000192 { &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 Lubc7ceb12007-02-03 15:28:20 +0000200};
201
202static void enable_dev(struct device *dev)
203{
Uwe Hermann340fa932010-11-10 14:53:36 +0000204 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000205}
206
207struct chip_operations superio_winbond_w83627ehg_ops = {
208 CHIP_NAME("Winbond W83627EHG Super I/O")
209 .enable_dev = enable_dev,
210};