blob: 1ad79194bef8ef8929da68c35f379afff43d1197 [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
6 * Copyright (C) 2004 Tyan By LYH change from PC87360
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
Ronald G. Minnich142babf2004-03-12 16:54:31 +000022
23#include <arch/io.h>
24#include <device/device.h>
25#include <device/pnp.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000026#include <console/console.h>
27#include <string.h>
28#include <bitops.h>
29#include <uart8250.h>
30#include <pc80/keyboard.h>
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000031#include <pc80/mc146818rtc.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000032#include <stdlib.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000033#include "chip.h"
34#include "w83627hf.h"
35
Myles Watsoncee94382008-10-02 19:21:30 +000036static void pnp_enter_ext_func_mode(device_t dev)
Eric Biederman018d8dd2004-11-04 11:04:33 +000037{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000038 outb(0x87, dev->path.pnp.port);
39 outb(0x87, dev->path.pnp.port);
Yinghai Lu70093f72004-07-01 03:55:03 +000040}
Zheng Bao9db833b2009-12-28 09:59:44 +000041
Myles Watsoncee94382008-10-02 19:21:30 +000042static void pnp_exit_ext_func_mode(device_t dev)
Eric Biederman018d8dd2004-11-04 11:04:33 +000043{
Stefan Reinauer2b34db82009-02-28 20:10:20 +000044 outb(0xaa, dev->path.pnp.port);
Yinghai Lu70093f72004-07-01 03:55:03 +000045}
46
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000047static void pnp_write_index(unsigned long port_base, uint8_t reg, uint8_t value)
Yinghai Lu70093f72004-07-01 03:55:03 +000048{
Myles Watsoncee94382008-10-02 19:21:30 +000049 outb(reg, port_base);
50 outb(value, port_base + 1);
Yinghai Lu70093f72004-07-01 03:55:03 +000051}
52
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000053static uint8_t pnp_read_index(unsigned long port_base, uint8_t reg)
Yinghai Lu70093f72004-07-01 03:55:03 +000054{
Myles Watsoncee94382008-10-02 19:21:30 +000055 outb(reg, port_base);
56 return inb(port_base + 1);
57}
Yinghai Lu70093f72004-07-01 03:55:03 +000058
Zheng Bao9db833b2009-12-28 09:59:44 +000059static void enable_hwm_smbus(device_t dev)
60{
Yinghai Lu12eb7bc2004-11-08 21:16:16 +000061 /* set the pin 91,92 as I2C bus */
Yinghai Lu70093f72004-07-01 03:55:03 +000062 uint8_t reg, value;
63 reg = 0x2b;
64 value = pnp_read_config(dev, reg);
65 value &= 0x3f;
66 pnp_write_config(dev, reg, value);
67}
68
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000069static void init_acpi(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +000070{
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000071 uint8_t value = 0x20;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000072 int power_on = 1;
Yinghai Lu70093f72004-07-01 03:55:03 +000073
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000074 get_option(&power_on, "power_on_after_fail");
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000075 pnp_enter_ext_func_mode(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000076 pnp_write_index(dev->path.pnp.port,7,0x0a);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000077 value = pnp_read_config(dev, 0xE4);
78 value &= ~(3<<5);
79 if(power_on) {
80 value |= (1<<5);
81 }
82 pnp_write_config(dev, 0xE4, value);
Myles Watsoncee94382008-10-02 19:21:30 +000083 pnp_exit_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +000084}
Yinghai Lu70093f72004-07-01 03:55:03 +000085
86static void init_hwm(unsigned long base)
87{
88 uint8_t reg, value;
89 int i;
90
91 unsigned hwm_reg_values[] = {
Zheng Bao9db833b2009-12-28 09:59:44 +000092 /* reg mask data */
Myles Watsoncee94382008-10-02 19:21:30 +000093 0x40, 0xff, 0x81, /* start HWM */
94 0x48, 0xaa, 0x2a, /* set SMBus base to 0x54>>1 */
95 0x4a, 0x21, 0x21, /* set T2 SMBus base to 0x92>>1 and T3 SMBus base to 0x94>>1 */
96 0x4e, 0x80, 0x00,
97 0x43, 0x00, 0xff,
98 0x44, 0x00, 0x3f,
99 0x4c, 0xbf, 0x18,
100 0x4d, 0xff, 0x80 /* turn off beep */
101
Yinghai Lu70093f72004-07-01 03:55:03 +0000102 };
103
Zheng Bao9db833b2009-12-28 09:59:44 +0000104 for(i = 0; i< ARRAY_SIZE(hwm_reg_values); i+=3 ) {
105 reg = hwm_reg_values[i];
106 value = pnp_read_index(base, reg);
Yinghai Lu70093f72004-07-01 03:55:03 +0000107 value &= 0xff & hwm_reg_values[i+1];
108 value |= 0xff & hwm_reg_values[i+2];
109#if 0
Yinghai Lu12eb7bc2004-11-08 21:16:16 +0000110 printk_debug("base = 0x%04x, reg = 0x%02x, value = 0x%02x\r\n", base, reg,value);
Yinghai Lu70093f72004-07-01 03:55:03 +0000111#endif
Yinghai Lu12eb7bc2004-11-08 21:16:16 +0000112 pnp_write_index(base, reg, value);
Yinghai Lu70093f72004-07-01 03:55:03 +0000113 }
114}
115
Yinghai Lu70093f72004-07-01 03:55:03 +0000116static void w83627hf_init(device_t dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000117{
118 struct superio_winbond_w83627hf_config *conf;
119 struct resource *res0, *res1;
Li-Ta Lo69c5a902004-04-29 20:08:54 +0000120 if (!dev->enabled) {
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000121 return;
122 }
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000123 conf = dev->chip_info;
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000124 switch(dev->path.pnp.device) {
Myles Watsoncee94382008-10-02 19:21:30 +0000125 case W83627HF_SP1:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000126 res0 = find_resource(dev, PNP_IDX_IO0);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000127 init_uart8250(res0->base, &conf->com1);
128 break;
129 case W83627HF_SP2:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000130 res0 = find_resource(dev, PNP_IDX_IO0);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000131 init_uart8250(res0->base, &conf->com2);
132 break;
133 case W83627HF_KBC:
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000134 res0 = find_resource(dev, PNP_IDX_IO0);
135 res1 = find_resource(dev, PNP_IDX_IO1);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000136 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
137 break;
Myles Watsoncee94382008-10-02 19:21:30 +0000138 case W83627HF_HWM:
139 res0 = find_resource(dev, PNP_IDX_IO0);
Yinghai Lu12eb7bc2004-11-08 21:16:16 +0000140#define HWM_INDEX_PORT 5
Myles Watsoncee94382008-10-02 19:21:30 +0000141 init_hwm(res0->base + HWM_INDEX_PORT);
142 break;
143 case W83627HF_ACPI:
144 init_acpi(dev);
145 break;
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000146 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000147}
148
Myles Watson7943fe62009-10-30 02:08:07 +0000149static void w83627hf_pnp_set_resources(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +0000150{
Myles Watsoncee94382008-10-02 19:21:30 +0000151 pnp_enter_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000152 pnp_set_resources(dev);
Myles Watsoncee94382008-10-02 19:21:30 +0000153 pnp_exit_ext_func_mode(dev);
Myles Watsoncee94382008-10-02 19:21:30 +0000154}
155
Myles Watson7943fe62009-10-30 02:08:07 +0000156static void w83627hf_pnp_enable_resources(device_t dev)
Myles Watsoncee94382008-10-02 19:21:30 +0000157{
158 pnp_enter_ext_func_mode(dev);
159 pnp_enable_resources(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000160 switch(dev->path.pnp.device) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000161 case W83627HF_HWM:
Stefan Reinauere74f91a2005-01-13 18:58:41 +0000162 printk_debug("w83627hf hwm smbus enabled\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000163 enable_hwm_smbus(dev);
164 break;
165 }
Myles Watsoncee94382008-10-02 19:21:30 +0000166 pnp_exit_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000167}
168
Myles Watson7943fe62009-10-30 02:08:07 +0000169static void w83627hf_pnp_enable(device_t dev)
Yinghai Lu70093f72004-07-01 03:55:03 +0000170{
Myles Watsoncee94382008-10-02 19:21:30 +0000171 if (!dev->enabled) {
172 pnp_enter_ext_func_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000173
Myles Watsoncee94382008-10-02 19:21:30 +0000174 pnp_set_logical_device(dev);
175 pnp_set_enable(dev, 0);
Yinghai Lu70093f72004-07-01 03:55:03 +0000176
Myles Watsoncee94382008-10-02 19:21:30 +0000177 pnp_exit_ext_func_mode(dev);
178 }
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000179}
180
181static struct device_operations ops = {
182 .read_resources = pnp_read_resources,
Yinghai Lu70093f72004-07-01 03:55:03 +0000183 .set_resources = w83627hf_pnp_set_resources,
184 .enable_resources = w83627hf_pnp_enable_resources,
185 .enable = w83627hf_pnp_enable,
186 .init = w83627hf_init,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000187};
188
189static struct pnp_info pnp_dev_info[] = {
Myles Watsoncee94382008-10-02 19:21:30 +0000190 { &ops, W83627HF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
191 { &ops, W83627HF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
192 { &ops, W83627HF_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
193 { &ops, W83627HF_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
Zheng Bao9db833b2009-12-28 09:59:44 +0000194 /* No 4 { 0,}, */
Myles Watsoncee94382008-10-02 19:21:30 +0000195 { &ops, W83627HF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, },
196 { &ops, W83627HF_CIR, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
197 { &ops, W83627HF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, { 0x7ff, 0 }, {0x7fe, 0x4}, },
198 { &ops, W83627HF_GPIO2, },
199 { &ops, W83627HF_GPIO3, },
200 { &ops, W83627HF_ACPI, },
201 { &ops, W83627HF_HWM, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, },
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000202};
203
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000204static void enable_dev(struct device *dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000205{
Eric Biederman69afe282004-11-11 06:53:24 +0000206 pnp_enable_devices(dev, &ops,
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +0000207 ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000208}
209
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000210struct chip_operations superio_winbond_w83627hf_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +0000211 CHIP_NAME("Winbond W83627HF Super I/O")
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000212 .enable_dev = enable_dev,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000213};