2a58ef774f772feb326654923ad0428bd03aed7b
[coreboot.git] / src / superio / winbond / w83627dhg / superio.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <arch/io.h>
21 #include <device/device.h>
22 #include <device/pnp.h>
23 #include <uart8250.h>
24 #include <pc80/keyboard.h>
25 #include <stdlib.h>
26 #include "chip.h"
27 #include "w83627dhg.h"
28
29 static void pnp_enter_ext_func_mode(device_t dev)
30 {
31         outb(0x87, dev->path.pnp.port);
32         outb(0x87, dev->path.pnp.port);
33 }
34
35 static void pnp_exit_ext_func_mode(device_t dev)
36 {
37         outb(0xaa, dev->path.pnp.port);
38 }
39
40 static void w83627dhg_init(device_t dev)
41 {
42         struct superio_winbond_w83627dhg_config *conf;
43         struct resource *res0, *res1;
44
45         if (!dev->enabled)
46                 return;
47
48         conf = dev->chip_info;
49
50         switch(dev->path.pnp.device) {
51         case W83627DHG_SP1:
52                 res0 = find_resource(dev, PNP_IDX_IO0);
53                 init_uart8250(res0->base, &conf->com1);
54                 break;
55         case W83627DHG_SP2:
56                 res0 = find_resource(dev, PNP_IDX_IO0);
57                 init_uart8250(res0->base, &conf->com2);
58                 break;
59         case W83627DHG_KBC:
60                 res0 = find_resource(dev, PNP_IDX_IO0);
61                 res1 = find_resource(dev, PNP_IDX_IO1);
62                 pc_keyboard_init(&conf->keyboard);
63                 break;
64         }
65 }
66
67 static void w83627dhg_pnp_set_resources(device_t dev)
68 {
69         pnp_enter_ext_func_mode(dev);
70         pnp_set_resources(dev);
71         pnp_exit_ext_func_mode(dev);
72 }
73
74 static void w83627dhg_pnp_enable_resources(device_t dev)
75 {
76         pnp_enter_ext_func_mode(dev);
77         pnp_enable_resources(dev);
78         pnp_exit_ext_func_mode(dev);
79 }
80
81 static void w83627dhg_pnp_enable(device_t dev)
82 {
83         if (!dev->enabled)
84                 return;
85
86         pnp_enter_ext_func_mode(dev);
87         pnp_set_logical_device(dev);
88         pnp_set_enable(dev, 0);
89         pnp_exit_ext_func_mode(dev);
90 }
91
92 static struct device_operations ops = {
93         .read_resources   = pnp_read_resources,
94         .set_resources    = w83627dhg_pnp_set_resources,
95         .enable_resources = w83627dhg_pnp_enable_resources,
96         .enable           = w83627dhg_pnp_enable,
97         .init             = w83627dhg_init,
98 };
99
100 static struct pnp_info pnp_dev_info[] = {
101         { &ops, W83627DHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x0ff8, 0}, },
102         { &ops, W83627DHG_PP,  PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x0ff8, 0}, },
103         { &ops, W83627DHG_SP1, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, },
104         { &ops, W83627DHG_SP2, PNP_IO0 | PNP_IRQ0, { 0xff8, 0 }, },
105         { &ops, W83627DHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0xfff, 0 }, { 0xfff, 0x4}, },
106         /* the next line makes coreboot hang in pnp_enable_devices() */
107         /* { &ops, W83627DHG_SPI, PNP_IO1, { 0xff8, 0 }, }, */
108         { &ops, W83627DHG_GPIO6, },
109         { &ops, W83627DHG_WDTO_PLED, },
110         { &ops, W83627DHG_GPIO2345, },
111         { &ops, W83627DHG_ACPI, },
112         { &ops, W83627DHG_HWM, PNP_IO0 | PNP_IRQ0, { 0xffe, 0 }, },
113         { &ops, W83627DHG_PECI_SST, },
114 };
115
116 static void enable_dev(struct device *dev)
117 {
118         pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
119 }
120
121 struct chip_operations superio_winbond_w83627dhg_ops = {
122         CHIP_NAME("Winbond W83627DHG Super I/O")
123         .enable_dev = enable_dev,
124 };