blob: 4c99999eb4a71c880b9ef9770f98c079abb3dd98 [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
Zheng Bao9db833b2009-12-28 09:59:44 +00007 *
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 */
Richard Smith924f92f2006-07-29 17:40:36 +000022
Richard Smith924f92f2006-07-29 17:40:36 +000023#include <arch/io.h>
24#include <device/device.h>
25#include <device/pnp.h>
26#include <console/console.h>
27#include <string.h>
28#include <bitops.h>
29#include <uart8250.h>
30#include <pc80/keyboard.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000031#include <stdlib.h>
Richard Smith924f92f2006-07-29 17:40:36 +000032#include "chip.h"
33#include "w83977tf.h"
34
Zheng Bao9db833b2009-12-28 09:59:44 +000035static void w83977tf_enter_ext_func_mode(device_t dev)
Richard Smith924f92f2006-07-29 17:40:36 +000036{
Zheng Bao9db833b2009-12-28 09:59:44 +000037 outb(0x87, dev->path.pnp.port);
38 outb(0x87, dev->path.pnp.port);
Richard Smith924f92f2006-07-29 17:40:36 +000039}
Uwe Hermann340fa932010-11-10 14:53:36 +000040
Zheng Bao9db833b2009-12-28 09:59:44 +000041static void w83977tf_exit_ext_func_mode(device_t dev)
Richard Smith924f92f2006-07-29 17:40:36 +000042{
Zheng Bao9db833b2009-12-28 09:59:44 +000043 outb(0xaa, dev->path.pnp.port);
Richard Smith924f92f2006-07-29 17:40:36 +000044}
45
46static void w83977tf_init(device_t dev)
47{
Uwe Hermann340fa932010-11-10 14:53:36 +000048 struct superio_winbond_w83977tf_config *conf = dev->chip_info;
Uwe Hermann5330dd92010-11-11 13:14:55 +000049 struct resource *res0;
Uwe Hermann340fa932010-11-10 14:53:36 +000050
51 if (!dev->enabled)
Richard Smith924f92f2006-07-29 17:40:36 +000052 return;
Uwe Hermann340fa932010-11-10 14:53:36 +000053
Stefan Reinauer2b34db82009-02-28 20:10:20 +000054 switch(dev->path.pnp.device) {
Zheng Bao9db833b2009-12-28 09:59:44 +000055 case W83977TF_SP1:
Richard Smith924f92f2006-07-29 17:40:36 +000056 res0 = find_resource(dev, PNP_IDX_IO0);
57 init_uart8250(res0->base, &conf->com1);
58 break;
59 case W83977TF_SP2:
60 res0 = find_resource(dev, PNP_IDX_IO0);
61 init_uart8250(res0->base, &conf->com2);
62 break;
63 case W83977TF_KBC:
Stefan Reinauer740b5872010-02-23 20:31:37 +000064 pc_keyboard_init(&conf->keyboard);
Richard Smith924f92f2006-07-29 17:40:36 +000065 break;
66 }
67}
68
69static void w83977tf_set_resources(device_t dev)
70{
71 w83977tf_enter_ext_func_mode(dev);
72 pnp_set_resources(dev);
73 w83977tf_exit_ext_func_mode(dev);
74}
75
76static void w83977tf_enable_resources(device_t dev)
77{
78 w83977tf_enter_ext_func_mode(dev);
79 pnp_enable_resources(dev);
80 w83977tf_exit_ext_func_mode(dev);
81}
82
83static void w83977tf_enable(device_t dev)
84{
Zheng Bao9db833b2009-12-28 09:59:44 +000085 w83977tf_enter_ext_func_mode(dev);
Richard Smith924f92f2006-07-29 17:40:36 +000086 pnp_enable(dev);
Zheng Bao9db833b2009-12-28 09:59:44 +000087 w83977tf_exit_ext_func_mode(dev);
Richard Smith924f92f2006-07-29 17:40:36 +000088}
89
Richard Smith924f92f2006-07-29 17:40:36 +000090static struct device_operations ops = {
91 .read_resources = pnp_read_resources,
92 .set_resources = w83977tf_set_resources,
93 .enable_resources = w83977tf_enable_resources,
94 .enable = w83977tf_enable,
95 .init = w83977tf_init,
96};
97
98static struct pnp_info pnp_dev_info[] = {
Uwe Hermanna69d9782010-11-15 19:35:14 +000099 { &ops, W83977TF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
100 { &ops, W83977TF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
101 { &ops, W83977TF_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
102 { &ops, W83977TF_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
103 { &ops, W83977TF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, },
104 { &ops, W83977TF_CIR, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
105 { &ops, W83977TF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x07ff, 0}, {0x07fe, 4}, },
106 { &ops, W83977TF_ACPI, PNP_IRQ0, },
Richard Smith924f92f2006-07-29 17:40:36 +0000107};
108
109static void enable_dev(device_t dev)
110{
Uwe Hermann340fa932010-11-10 14:53:36 +0000111 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Richard Smith924f92f2006-07-29 17:40:36 +0000112}
113
114struct chip_operations superio_winbond_w83977tf_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +0000115 CHIP_NAME("Winbond W83977TF Super I/O")
Richard Smith924f92f2006-07-29 17:40:36 +0000116 .enable_dev = enable_dev,
117};