C and other Super I/O cosmetic fixes.
[coreboot.git] / src / superio / ite / it8716f / 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 AMD
6  * (Written by Yinghai Lu <yinghai.lu@amd.com> for AMD)
7  * Copyright (C) 2007 Ward Vandewege <ward@gnu.org>
8  *
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  */
23
24 #include <device/device.h>
25 #include <device/pnp.h>
26 #include <console/console.h>
27 #include <uart8250.h>
28 #include <pc80/keyboard.h>
29 #include <arch/io.h>
30 #include <stdlib.h>
31 #include "chip.h"
32 #include "it8716f.h"
33
34 static void pnp_enter_ext_func_mode(device_t dev)
35 {
36         u16 port = dev->path.pnp.port;
37
38         outb(0x87, port);
39         outb(0x01, port);
40         outb(0x55, port);
41         outb((port == 0x4e) ? 0xaa : 0x55, port);
42 }
43
44 static void pnp_exit_ext_func_mode(device_t dev)
45 {
46         pnp_write_config(dev, 0x02, 0x02);
47 }
48
49 #if !defined(CONFIG_SUPERIO_ITE_IT8716F_OVERRIDE_FANCTL) || !CONFIG_SUPERIO_ITE_IT8716F_OVERRIDE_FANCTL
50 static void pnp_write_index(u16 port_base, u8 reg, u8 value)
51 {
52         outb(reg, port_base);
53         outb(value, port_base + 1);
54 }
55
56 static u8 pnp_read_index(u16 port_base, u8 reg)
57 {
58         outb(reg, port_base);
59         return inb(port_base + 1);
60 }
61
62 static void init_ec(u16 base)
63 {
64         u8 value;
65
66         /* Read out current value of FAN_CTL (0x14). */
67         value = pnp_read_index(base, 0x14);
68         printk(BIOS_DEBUG, "FAN_CTL: reg = 0x%04x, read value = 0x%02x\n",
69                base + 0x14, value);
70
71         /* Set FAN_CTL (0x14) polarity to high, activate fans 1, 2 and 3. */
72         pnp_write_index(base, 0x14, value | 0x87);
73         printk(BIOS_DEBUG, "FAN_CTL: reg = 0x%04x, writing value = 0x%02x\n",
74                base + 0x14, value | 0x87);
75 }
76 #endif
77
78 static void it8716f_init(device_t dev)
79 {
80         struct superio_ite_it8716f_config *conf = dev->chip_info;
81         struct resource *res0;
82
83         if (!dev->enabled)
84                 return;
85
86         /* TODO: FDC, PP, KBCM, MIDI, GAME, IR. */
87         switch (dev->path.pnp.device) {
88         case IT8716F_SP1:
89                 res0 = find_resource(dev, PNP_IDX_IO0);
90                 init_uart8250(res0->base, &conf->com1);
91                 break;
92         case IT8716F_SP2:
93                 res0 = find_resource(dev, PNP_IDX_IO0);
94                 init_uart8250(res0->base, &conf->com2);
95                 break;
96         case IT8716F_EC:
97                 res0 = find_resource(dev, PNP_IDX_IO0);
98 #define EC_INDEX_PORT 5
99                 init_ec(res0->base + EC_INDEX_PORT);
100                 break;
101         case IT8716F_KBCK:
102                 pc_keyboard_init(&conf->keyboard);
103                 break;
104         }
105 }
106
107 static void it8716f_pnp_set_resources(device_t dev)
108 {
109         pnp_enter_ext_func_mode(dev);
110         pnp_set_resources(dev);
111         pnp_exit_ext_func_mode(dev);
112 }
113
114 static void it8716f_pnp_enable_resources(device_t dev)
115 {
116         pnp_enter_ext_func_mode(dev);
117         pnp_enable_resources(dev);
118         pnp_exit_ext_func_mode(dev);
119 }
120
121 static void it8716f_pnp_enable(device_t dev)
122 {
123         pnp_enter_ext_func_mode(dev);
124         pnp_set_logical_device(dev);
125         pnp_set_enable(dev, dev->enabled);
126         pnp_exit_ext_func_mode(dev);
127 }
128
129 static struct device_operations ops = {
130         .read_resources   = pnp_read_resources,
131         .set_resources    = it8716f_pnp_set_resources,
132         .enable_resources = it8716f_pnp_enable_resources,
133         .enable           = it8716f_pnp_enable,
134         .init             = it8716f_init,
135 };
136
137 static struct pnp_info pnp_dev_info[] = {
138         { &ops, IT8716F_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
139         { &ops, IT8716F_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
140         { &ops, IT8716F_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
141         { &ops, IT8716F_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
142         { &ops, IT8716F_EC, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x07f8, 0}, {0x07f8, 4}, },
143         { &ops, IT8716F_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x07ff, 0}, {0x07ff, 4}, },
144         { &ops, IT8716F_KBCM, PNP_IRQ0, },
145         { &ops, IT8716F_GPIO, PNP_IO1 | PNP_IO2, {0, 0}, {0x07f8, 0}, {0x07f8, 0}, },
146         { &ops, IT8716F_MIDI, PNP_IO0 | PNP_IRQ0, {0x07fe, 4}, },
147         { &ops, IT8716F_GAME, PNP_IO0, {0x07ff, 0}, },
148         { &ops, IT8716F_IR, },
149 };
150
151 static void enable_dev(struct device *dev)
152 {
153         pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
154 }
155
156 struct chip_operations superio_ite_it8716f_ops = {
157         CHIP_NAME("ITE IT8716F Super I/O")
158         .enable_dev = enable_dev,
159 };