C and other Super I/O cosmetic fixes.
[coreboot.git] / src / superio / smsc / lpc47b272 / superio.c
1 /*
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
7  * Copyright (C) 2005 Digital Design Corporation
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 /* RAM driver for SMSC LPC47B272 Super I/O chip. */
25
26 #include <arch/io.h>
27 #include <device/device.h>
28 #include <device/pnp.h>
29 #include <console/console.h>
30 #include <device/smbus.h>
31 #include <string.h>
32 #include <bitops.h>
33 #include <uart8250.h>
34 #include <pc80/keyboard.h>
35 #include <stdlib.h>
36 #include "chip.h"
37 #include "lpc47b272.h"
38
39 /* Forward declarations */
40 static void enable_dev(device_t dev);
41 static void lpc47b272_pnp_set_resources(device_t dev);
42 static void lpc47b272_pnp_enable_resources(device_t dev);
43 static void lpc47b272_pnp_enable(device_t dev);
44 static void lpc47b272_init(device_t dev);
45
46 static void pnp_enter_conf_state(device_t dev);
47 static void pnp_exit_conf_state(device_t dev);
48 // static void dump_pnp_device(device_t dev);
49
50 struct chip_operations superio_smsc_lpc47b272_ops = {
51         CHIP_NAME("SMSC LPC47B272 Super I/O")
52         .enable_dev = enable_dev
53 };
54
55 static struct device_operations ops = {
56         .read_resources   = pnp_read_resources,
57         .set_resources    = lpc47b272_pnp_set_resources,
58         .enable_resources = lpc47b272_pnp_enable_resources,
59         .enable           = lpc47b272_pnp_enable,
60         .init             = lpc47b272_init,
61 };
62
63 static struct pnp_info pnp_dev_info[] = {
64         { &ops, LPC47B272_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
65         { &ops, LPC47B272_PP,  PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
66         { &ops, LPC47B272_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
67         { &ops, LPC47B272_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
68         { &ops, LPC47B272_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, },
69         { &ops, LPC47B272_RT,  PNP_IO0, {0x0780, 0}, },
70 };
71
72 /**
73  * Create device structures and allocate resources to devices specified in the
74  * pnp_dev_info array (above).
75  *
76  * @param dev Pointer to structure describing a Super I/O device.
77  */
78 static void enable_dev(device_t dev)
79 {
80         pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info),
81                            pnp_dev_info);
82 }
83
84 /**
85  * Configure the specified Super I/O device with the resources (I/O space,
86  * etc.) that have been allocated for it.
87  *
88  * @param dev Pointer to structure describing a Super I/O device.
89  */
90 static void lpc47b272_pnp_set_resources(device_t dev)
91 {
92         pnp_enter_conf_state(dev);
93         pnp_set_resources(dev);
94         pnp_exit_conf_state(dev);
95 }
96
97 static void lpc47b272_pnp_enable_resources(device_t dev)
98 {
99         pnp_enter_conf_state(dev);
100         pnp_enable_resources(dev);
101         pnp_exit_conf_state(dev);
102 }
103
104 static void lpc47b272_pnp_enable(device_t dev)
105 {
106         pnp_enter_conf_state(dev);
107         pnp_set_logical_device(dev);
108         pnp_set_enable(dev, (dev->enabled) ? 1 : 0);
109         pnp_exit_conf_state(dev);
110 }
111
112 /**
113  * Initialize the specified Super I/O device.
114  *
115  * Devices other than COM ports and the keyboard controller are ignored.
116  * For COM ports, we configure the baud rate.
117  *
118  * @param dev Pointer to structure describing a Super I/O device.
119  */
120 static void lpc47b272_init(device_t dev)
121 {
122         struct superio_smsc_lpc47b272_config *conf = dev->chip_info;
123         struct resource *res0;
124
125         if (!dev->enabled)
126                 return;
127
128         switch(dev->path.pnp.device) {
129         case LPC47B272_SP1:
130                 res0 = find_resource(dev, PNP_IDX_IO0);
131                 init_uart8250(res0->base, &conf->com1);
132                 break;
133         case LPC47B272_SP2:
134                 res0 = find_resource(dev, PNP_IDX_IO0);
135                 init_uart8250(res0->base, &conf->com2);
136                 break;
137         case LPC47B272_KBC:
138                 pc_keyboard_init(&conf->keyboard);
139                 break;
140         }
141 }
142
143 static void pnp_enter_conf_state(device_t dev)
144 {
145         outb(0x55, dev->path.pnp.port);
146 }
147
148 static void pnp_exit_conf_state(device_t dev)
149 {
150         outb(0xaa, dev->path.pnp.port);
151 }
152
153 #if 0
154 /**
155  * Print the values of all of the LPC47B272's configuration registers.
156  *
157  * NOTE: The LPC47B272 must be in config mode when this function is called.
158  *
159  * @param dev Pointer to structure describing a Super I/O device.
160  */
161 static void dump_pnp_device(device_t dev)
162 {
163         int i;
164         print_debug("\n");
165
166         for (i = 0; i <= LPC47B272_MAX_CONFIG_REGISTER; i++) {
167                 u8 register_value;
168
169                 if ((i & 0x0f) == 0) {
170                         print_debug_hex8(i);
171                         print_debug_char(':');
172                 }
173
174                 /*
175                  * Skip over 'register' that would cause exit from
176                  * configuration mode.
177                  */
178                 if (i == 0xaa)
179                         register_value = 0xaa;
180                 else
181                         register_value = pnp_read_config(dev, i);
182
183                 print_debug_char(' ');
184                 print_debug_hex8(register_value);
185                 if ((i & 0x0f) == 0x0f)
186                         print_debug("\n");
187         }
188
189         print_debug("\n");
190 }
191 #endif