C and other Super I/O cosmetic fixes.
[coreboot.git] / src / superio / ite / it8712f / superio.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
5  * Copyright (C) 2007 Philipp Degler <pdegler@rumms.uni-mannheim.de>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <device/device.h>
23 #include <device/pnp.h>
24 #include <uart8250.h>
25 #include <pc80/keyboard.h>
26 #include <arch/io.h>
27 #include <stdlib.h>
28 #include "chip.h"
29 #include "it8712f.h"
30
31 static void pnp_enter_ext_func_mode(device_t dev)
32 {
33         u16 port = dev->path.pnp.port;
34
35         outb(0x87, port);
36         outb(0x01, port);
37         outb(0x55, port);
38         outb((port == 0x4e) ? 0xaa : 0x55, port);
39 }
40
41 static void pnp_exit_ext_func_mode(device_t dev)
42 {
43         pnp_write_config(dev, 0x02, 0x02);
44 }
45
46 static void it8712f_init(device_t dev)
47 {
48         struct superio_ite_it8712f_config *conf = dev->chip_info;
49         struct resource *res0;
50
51         if (!dev->enabled)
52                 return;
53
54         switch (dev->path.pnp.device) {
55         case IT8712F_FDC: /* TODO. */
56                 break;
57         case IT8712F_SP1:
58                 res0 = find_resource(dev, PNP_IDX_IO0);
59                 init_uart8250(res0->base, &conf->com1);
60                 break;
61         case IT8712F_SP2:
62                 res0 = find_resource(dev, PNP_IDX_IO0);
63                 init_uart8250(res0->base, &conf->com2);
64                 break;
65         case IT8712F_PP: /* TODO. */
66                 break;
67         case IT8712F_EC: /* TODO. */
68                 break;
69         case IT8712F_KBCK:
70                 set_kbc_ps2_mode();
71                 pc_keyboard_init(&conf->keyboard);
72                 break;
73         case IT8712F_KBCM: /* TODO. */
74                 break;
75         case IT8712F_MIDI: /* TODO. */
76                 break;
77         case IT8712F_GAME: /* TODO. */
78                 break;
79         case IT8712F_IR: /* TODO. */
80                 break;
81         }
82 }
83
84 static void it8712f_pnp_set_resources(device_t dev)
85 {
86         pnp_enter_ext_func_mode(dev);
87         pnp_set_resources(dev);
88         pnp_exit_ext_func_mode(dev);
89 }
90
91 static void it8712f_pnp_enable_resources(device_t dev)
92 {
93         pnp_enter_ext_func_mode(dev);
94         pnp_enable_resources(dev);
95         pnp_exit_ext_func_mode(dev);
96 }
97
98 static void it8712f_pnp_enable(device_t dev)
99 {
100         pnp_enter_ext_func_mode(dev);
101         pnp_set_logical_device(dev);
102         pnp_set_enable(dev, dev->enabled);
103         pnp_exit_ext_func_mode(dev);
104 }
105
106 static struct device_operations ops = {
107         .read_resources         = pnp_read_resources,
108         .set_resources          = it8712f_pnp_set_resources,
109         .enable_resources       = it8712f_pnp_enable_resources,
110         .enable                 = it8712f_pnp_enable,
111         .init                   = it8712f_init,
112 };
113
114 static struct pnp_info pnp_dev_info[] = {
115         { &ops, IT8712F_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x0ff8, 0}, },
116         { &ops, IT8712F_SP1, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
117         { &ops, IT8712F_SP2, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
118         { &ops, IT8712F_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x0ffc, 0}, },
119         { &ops, IT8712F_EC, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x0ff8, 0}, {0x0ff8, 4}, },
120         { &ops, IT8712F_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x0fff, 0}, {0x0fff, 4}, },
121         { &ops, IT8712F_KBCM, PNP_IRQ0, },
122         { &ops, IT8712F_GPIO, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IRQ0, {0x0fff, 0}, {0x0ff8, 0}, {0x0ff8, 0}, },
123         { &ops, IT8712F_MIDI, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
124         { &ops, IT8712F_GAME, PNP_IO0, {0x0fff, 0}, },
125         { &ops, IT8712F_IR, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
126 };
127
128 static void enable_dev(struct device *dev)
129 {
130         pnp_enable_devices(dev, &pnp_ops,
131                 ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
132 }
133
134 struct chip_operations superio_ite_it8712f_ops = {
135         CHIP_NAME("ITE IT8712F Super I/O")
136         .enable_dev = enable_dev,
137 };