blob: 42ad46e3e1d09e20e92d1a36dd0ee95ecaa54ead [file] [log] [blame]
Zheng Bao9db833b2009-12-28 09:59:44 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2000 AG Electronics Ltd.
5 * Copyright (C) 2003-2004 Linux Networx
Uwe Hermann340fa932010-11-10 14:53:36 +00006 * Copyright (C) 2004 Tyan
Stefan Reinauer14e22772010-04-27 06:56:47 +00007 * Copyright (C) 2010 Win Enterprises (anishp@win-ent.com)
Zheng Bao9db833b2009-12-28 09:59:44 +00008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
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 */
Ronald G. Minnich142babf2004-03-12 16:54:31 +000023
24#include <arch/io.h>
25#include <device/device.h>
26#include <device/pnp.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000027#include <console/console.h>
28#include <string.h>
29#include <bitops.h>
30#include <uart8250.h>
31#include <pc80/keyboard.h>
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000032#include <pc80/mc146818rtc.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000033#include <stdlib.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000034#include "chip.h"
35#include "w83627hf.h"
36
Myles Watsoncee94382008-10-02 19:21:30 +000037static void pnp_enter_ext_func_mode(device_t dev)
Eric Biederman018d8dd2004-11-04 11:04:33 +000038{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000039 outb(0x87, dev->path.pnp.port);
40 outb(0x87, dev->path.pnp.port);
Yinghai Lu70093f72004-07-01 03:55:03 +000041}
Zheng Bao9db833b2009-12-28 09:59:44 +000042
Myles Watsoncee94382008-10-02 19:21:30 +000043static void pnp_exit_ext_func_mode(device_t dev)
Eric Biederman018d8dd2004-11-04 11:04:33 +000044{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000045 outb(0xaa, dev->path.pnp.port);
Yinghai Lu70093f72004-07-01 03:55:03 +000046}
47
Uwe Hermann340fa932010-11-10 14:53:36 +000048static void pnp_write_index(u16 port, u8 reg, u8 value)
Yinghai Lu70093f72004-07-01 03:55:03 +000049{
Uwe Hermann340fa932010-11-10 14:53:36 +000050 outb(reg, port);
51 outb(value, port + 1);
Yinghai Lu70093f72004-07-01 03:55:03 +000052}
53
Uwe Hermann340fa932010-11-10 14:53:36 +000054static u8 pnp_read_index(u16 port, u8 reg)
Yinghai Lu70093f72004-07-01 03:55:03 +000055{
Uwe Hermann340fa932010-11-10 14:53:36 +000056 outb(reg, port);
57 return inb(port + 1);
Myles Watsoncee94382008-10-02 19:21:30 +000058}
Yinghai Lu70093f72004-07-01 03:55:03 +000059
Stefan Reinauer50776fa2010-03-17 04:40:15 +000060#if CONFIG_EXPERT
Anish K. Patel3a54ac92010-02-24 16:36:56 +000061static void w83627hf_16_bit_addr_qual(device_t dev)
62{
Uwe Hermann340fa932010-11-10 14:53:36 +000063 u8 reg8;
64
65 /* Enable 16 bit address qualification. */
66 pnp_enter_ext_func_mode(dev);
67 reg8 = pnp_read_config(dev, 0x24);
68 reg8 |= (1 << 7);
69 pnp_write_config(dev, 0x24, reg8);
70 pnp_exit_ext_func_mode(dev);
Anish K. Patel3a54ac92010-02-24 16:36:56 +000071}
Stefan Reinauer50776fa2010-03-17 04:40:15 +000072#endif
Anish K. Patel3a54ac92010-02-24 16:36:56 +000073
Zheng Bao9db833b2009-12-28 09:59:44 +000074static void enable_hwm_smbus(device_t dev)
75{
Uwe Hermann340fa932010-11-10 14:53:36 +000076 u8 reg8;
77
78 /* Configure pins 91/92 as SDA/SCL (I2C bus). */
79 reg8 = pnp_read_config(dev, 0x2b);
80 reg8 &= 0x3f;
81 pnp_write_config(dev, 0x2b, reg8);
Yinghai Lu70093f72004-07-01 03:55:03 +000082}
83
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000084static void init_acpi(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +000085{
Uwe Hermann340fa932010-11-10 14:53:36 +000086 u8 value = 0x20; /* FIXME: The 0x20 value here is never used? */
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000087 int power_on = 1;
Yinghai Lu70093f72004-07-01 03:55:03 +000088
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000089 get_option(&power_on, "power_on_after_fail");
Uwe Hermann340fa932010-11-10 14:53:36 +000090
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000091 pnp_enter_ext_func_mode(dev);
Uwe Hermann340fa932010-11-10 14:53:36 +000092 pnp_set_logical_device(dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000093 value = pnp_read_config(dev, 0xE4);
Uwe Hermann340fa932010-11-10 14:53:36 +000094 value &= ~(3 << 5);
95 if (power_on)
96 value |= (1 << 5);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000097 pnp_write_config(dev, 0xE4, value);
Myles Watsoncee94382008-10-02 19:21:30 +000098 pnp_exit_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +000099}
Yinghai Lu70093f72004-07-01 03:55:03 +0000100
Uwe Hermann340fa932010-11-10 14:53:36 +0000101static void init_hwm(u16 base)
Yinghai Lu70093f72004-07-01 03:55:03 +0000102{
Uwe Hermann340fa932010-11-10 14:53:36 +0000103 u8 reg, value;
Yinghai Lu70093f72004-07-01 03:55:03 +0000104 int i;
105
Uwe Hermann340fa932010-11-10 14:53:36 +0000106 u8 hwm_reg_values[] = {
107 /* reg mask data */
108 0x40, 0xff, 0x81, /* Start HWM. */
109 0x48, 0xaa, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */
110 0x4a, 0x21, 0x21, /* Set T2 SMBus base to 0x92>>1 and T3 SMBus base to 0x94>>1. */
Myles Watsoncee94382008-10-02 19:21:30 +0000111 0x4e, 0x80, 0x00,
112 0x43, 0x00, 0xff,
113 0x44, 0x00, 0x3f,
114 0x4c, 0xbf, 0x18,
Uwe Hermann340fa932010-11-10 14:53:36 +0000115 0x4d, 0xff, 0x80, /* Turn off beep */
Yinghai Lu70093f72004-07-01 03:55:03 +0000116 };
117
Uwe Hermann340fa932010-11-10 14:53:36 +0000118 for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) {
Zheng Bao9db833b2009-12-28 09:59:44 +0000119 reg = hwm_reg_values[i];
Uwe Hermann340fa932010-11-10 14:53:36 +0000120 value = pnp_read_index(base, reg);
121 value &= 0xff & hwm_reg_values[i + 1];
122 value |= 0xff & hwm_reg_values[i + 2];
123 printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, "
124 "value = 0x%02x\n", base, reg, value);
Yinghai Lu12eb7bc2004-11-08 21:16:16 +0000125 pnp_write_index(base, reg, value);
Yinghai Lu70093f72004-07-01 03:55:03 +0000126 }
127}
128
Yinghai Lu70093f72004-07-01 03:55:03 +0000129static void w83627hf_init(device_t dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000130{
Uwe Hermann340fa932010-11-10 14:53:36 +0000131 struct superio_winbond_w83627hf_config *conf = dev->chip_info;
Uwe Hermann5330dd92010-11-11 13:14:55 +0000132 struct resource *res0;
Uwe Hermann340fa932010-11-10 14:53:36 +0000133
134 if (!dev->enabled)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000135 return;
Uwe Hermann340fa932010-11-10 14:53:36 +0000136
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000137 switch(dev->path.pnp.device) {
Myles Watsoncee94382008-10-02 19:21:30 +0000138 case W83627HF_SP1:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000139 res0 = find_resource(dev, PNP_IDX_IO0);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000140 init_uart8250(res0->base, &conf->com1);
141 break;
142 case W83627HF_SP2:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000143 res0 = find_resource(dev, PNP_IDX_IO0);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000144 init_uart8250(res0->base, &conf->com2);
145 break;
146 case W83627HF_KBC:
Stefan Reinauer740b5872010-02-23 20:31:37 +0000147 pc_keyboard_init(&conf->keyboard);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000148 break;
Myles Watsoncee94382008-10-02 19:21:30 +0000149 case W83627HF_HWM:
150 res0 = find_resource(dev, PNP_IDX_IO0);
Yinghai Lu12eb7bc2004-11-08 21:16:16 +0000151#define HWM_INDEX_PORT 5
Myles Watsoncee94382008-10-02 19:21:30 +0000152 init_hwm(res0->base + HWM_INDEX_PORT);
153 break;
154 case W83627HF_ACPI:
155 init_acpi(dev);
156 break;
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000157 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000158}
159
Myles Watson7943fe62009-10-30 02:08:07 +0000160static void w83627hf_pnp_set_resources(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +0000161{
Myles Watsoncee94382008-10-02 19:21:30 +0000162 pnp_enter_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000163 pnp_set_resources(dev);
Myles Watsoncee94382008-10-02 19:21:30 +0000164 pnp_exit_ext_func_mode(dev);
Myles Watsoncee94382008-10-02 19:21:30 +0000165}
166
Myles Watson7943fe62009-10-30 02:08:07 +0000167static void w83627hf_pnp_enable_resources(device_t dev)
Myles Watsoncee94382008-10-02 19:21:30 +0000168{
169 pnp_enter_ext_func_mode(dev);
170 pnp_enable_resources(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000171 switch(dev->path.pnp.device) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000172 case W83627HF_HWM:
Uwe Hermann340fa932010-11-10 14:53:36 +0000173 printk(BIOS_DEBUG, "W83627HF HWM SMBus enabled\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000174 enable_hwm_smbus(dev);
175 break;
176 }
Myles Watsoncee94382008-10-02 19:21:30 +0000177 pnp_exit_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000178}
179
Myles Watson7943fe62009-10-30 02:08:07 +0000180static void w83627hf_pnp_enable(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +0000181{
Uwe Hermann340fa932010-11-10 14:53:36 +0000182 if (dev->enabled)
183 return;
Yinghai Lu70093f72004-07-01 03:55:03 +0000184
Uwe Hermann340fa932010-11-10 14:53:36 +0000185 pnp_enter_ext_func_mode(dev);
186 pnp_set_logical_device(dev);
187 pnp_set_enable(dev, 0);
188 pnp_exit_ext_func_mode(dev);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000189}
190
191static struct device_operations ops = {
192 .read_resources = pnp_read_resources,
Yinghai Lu70093f72004-07-01 03:55:03 +0000193 .set_resources = w83627hf_pnp_set_resources,
194 .enable_resources = w83627hf_pnp_enable_resources,
195 .enable = w83627hf_pnp_enable,
196 .init = w83627hf_init,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000197};
198
199static struct pnp_info pnp_dev_info[] = {
Myles Watsoncee94382008-10-02 19:21:30 +0000200 { &ops, W83627HF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
201 { &ops, W83627HF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
202 { &ops, W83627HF_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
203 { &ops, W83627HF_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
Myles Watsoncee94382008-10-02 19:21:30 +0000204 { &ops, W83627HF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, },
205 { &ops, W83627HF_CIR, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
206 { &ops, W83627HF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, { 0x7ff, 0 }, {0x7fe, 0x4}, },
207 { &ops, W83627HF_GPIO2, },
208 { &ops, W83627HF_GPIO3, },
209 { &ops, W83627HF_ACPI, },
210 { &ops, W83627HF_HWM, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, },
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000211};
212
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000213static void enable_dev(struct device *dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000214{
Uwe Hermann340fa932010-11-10 14:53:36 +0000215 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000216}
217
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000218struct chip_operations superio_winbond_w83627hf_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +0000219 CHIP_NAME("Winbond W83627HF Super I/O")
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000220 .enable_dev = enable_dev,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000221};