blob: a94c4c0030208611bca110744ab11145a37e69ed [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
Paul Menzela46a7122013-02-23 18:37:27 +010021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Yinghai Lubc7ceb12007-02-03 15:28:20 +000022 */
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 Lubc7ceb12007-02-03 15:28:20 +000029#include <uart8250.h>
30#include <pc80/keyboard.h>
31#include <pc80/mc146818rtc.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000032#include <stdlib.h>
Yinghai Lubc7ceb12007-02-03 15:28:20 +000033#include "chip.h"
34#include "w83627ehg.h"
35
36static void pnp_enter_ext_func_mode(device_t dev)
37{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000038 outb(0x87, dev->path.pnp.port);
39 outb(0x87, dev->path.pnp.port);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000040}
41
42static void pnp_exit_ext_func_mode(device_t dev)
43{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000044 outb(0xaa, dev->path.pnp.port);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000045}
46
Uwe Hermann340fa932010-11-10 14:53:36 +000047static void pnp_write_index(u16 port, u8 reg, u8 value)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000048{
Uwe Hermann340fa932010-11-10 14:53:36 +000049 outb(reg, port);
50 outb(value, port + 1);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000051}
52
Uwe Hermann340fa932010-11-10 14:53:36 +000053static u8 pnp_read_index(u16 port, u8 reg)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000054{
Uwe Hermann340fa932010-11-10 14:53:36 +000055 outb(reg, port);
56 return inb(port + 1);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000057}
58
Zheng Bao9db833b2009-12-28 09:59:44 +000059static void enable_hwm_smbus(device_t dev)
60{
Uwe Hermann340fa932010-11-10 14:53:36 +000061 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 Lubc7ceb12007-02-03 15:28:20 +000067}
68
69static void init_acpi(device_t dev)
70{
Uwe Hermann340fa932010-11-10 14:53:36 +000071 u8 value = 0x20; /* TODO: 0x20 value here never used? */
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000072 int power_on = 1;
Yinghai Lubc7ceb12007-02-03 15:28:20 +000073
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000074 get_option(&power_on, "power_on_after_fail");
Nico Huber13dc9762013-06-15 19:33:15 +020075 pnp_enter_conf_mode(dev);
Uwe Hermann340fa932010-11-10 14:53:36 +000076 pnp_set_logical_device(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000077 value = pnp_read_config(dev, 0xe4);
78 value &= ~(3 << 5);
Uwe Hermann340fa932010-11-10 14:53:36 +000079 if (power_on)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000080 value |= (1 << 5);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000081 pnp_write_config(dev, 0xe4, value);
Nico Huber13dc9762013-06-15 19:33:15 +020082 pnp_exit_conf_mode(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000083}
84
Uwe Hermann340fa932010-11-10 14:53:36 +000085static void init_hwm(u16 base)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000086{
87 int i;
Uwe Hermann340fa932010-11-10 14:53:36 +000088 u8 reg, value;
Yinghai Lubc7ceb12007-02-03 15:28:20 +000089
90 /* reg mask data */
Uwe Hermann340fa932010-11-10 14:53:36 +000091 u8 hwm_reg_values[] = {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000092 0x40, 0xff, 0x81, /* Start HWM. */
Uwe Hermann340fa932010-11-10 14:53:36 +000093 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */
Yinghai Lubc7ceb12007-02-03 15:28:20 +000094 };
95
Uwe Hermann340fa932010-11-10 14:53:36 +000096 for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000097 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 Hermann340fa932010-11-10 14:53:36 +0000101 printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, "
102 "value = 0x%02x\n", base, reg, value);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000103 pnp_write_index(base, reg, value);
104 }
105}
106
107static void w83627ehg_init(device_t dev)
108{
Uwe Hermann340fa932010-11-10 14:53:36 +0000109 struct superio_winbond_w83627ehg_config *conf = dev->chip_info;
Uwe Hermann5330dd92010-11-11 13:14:55 +0000110 struct resource *res0;
Uwe Hermann340fa932010-11-10 14:53:36 +0000111
112 if (!dev->enabled)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000113 return;
Uwe Hermann340fa932010-11-10 14:53:36 +0000114
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000115 switch(dev->path.pnp.device) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000116 case W83627EHG_KBC:
Stefan Reinauer740b5872010-02-23 20:31:37 +0000117 pc_keyboard_init(&conf->keyboard);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000118 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 Watson7943fe62009-10-30 02:08:07 +0000130static void w83627ehg_pnp_set_resources(device_t dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000131{
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000132 pnp_set_resources(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000133}
134
Myles Watson7943fe62009-10-30 02:08:07 +0000135static void w83627ehg_pnp_enable_resources(device_t dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000136{
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000137 pnp_enable_resources(dev);
138
Nico Huber13dc9762013-06-15 19:33:15 +0200139 pnp_enter_conf_mode(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000140 switch (dev->path.pnp.device) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000141 case W83627EHG_HWM:
Uwe Hermann340fa932010-11-10 14:53:36 +0000142 printk(BIOS_DEBUG, "W83627EHG HWM SMBus enabled\n");
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000143 enable_hwm_smbus(dev);
144 break;
145 }
Nico Huber13dc9762013-06-15 19:33:15 +0200146 pnp_exit_conf_mode(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000147}
148
Myles Watson7943fe62009-10-30 02:08:07 +0000149static void w83627ehg_pnp_enable(device_t dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000150{
Nico Huberf898f7b2013-06-10 22:57:12 +0200151 pnp_alt_enable(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000152}
153
Nico Huber13dc9762013-06-15 19:33:15 +0200154static const struct pnp_mode_ops pnp_conf_mode_ops = {
155 .enter_conf_mode = pnp_enter_ext_func_mode,
156 .exit_conf_mode = pnp_exit_ext_func_mode,
157};
158
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000159static 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,
Nico Huber13dc9762013-06-15 19:33:15 +0200165 .ops_pnp_mode = &pnp_conf_mode_ops,
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000166};
167
168static struct pnp_info pnp_dev_info[] = {
Uwe Hermann3a4ed152010-12-05 22:36:14 +0000169 { &ops, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
170 { &ops, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
171 { &ops, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
172 { &ops, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
173 { &ops, W83627EHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, },
174 { &ops, W83627EHG_SFI, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000175 { &ops, W83627EHG_WDTO_PLED, },
Uwe Hermann3a4ed152010-12-05 22:36:14 +0000176 { &ops, W83627EHG_ACPI, PNP_IRQ0, },
177 { &ops, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, {0x07fe, 0}, },
178
Uwe Hermanna69d9782010-11-15 19:35:14 +0000179 { &ops, W83627EHG_GAME, PNP_IO0, {0x07ff, 0}, },
Alexandru Gagniuc4a038ca2011-02-08 02:36:39 +0000180 { &ops, W83627EHG_MIDI, PNP_IO1 | PNP_IRQ0, {0, 0}, {0x07fe, 4}, },
Rudolf Marek8dcab782008-02-18 20:37:49 +0000181 { &ops, W83627EHG_GPIO1, },
182 { &ops, W83627EHG_GPIO2, },
183 { &ops, W83627EHG_GPIO3, },
184 { &ops, W83627EHG_GPIO4, },
185 { &ops, W83627EHG_GPIO5, },
186 { &ops, W83627EHG_GPIO6, },
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000187};
188
189static void enable_dev(struct device *dev)
190{
Uwe Hermann340fa932010-11-10 14:53:36 +0000191 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000192}
193
194struct chip_operations superio_winbond_w83627ehg_ops = {
195 CHIP_NAME("Winbond W83627EHG Super I/O")
196 .enable_dev = enable_dev,
197};