C and other Super I/O cosmetic fixes.
[coreboot.git] / src / superio / smsc / lpc47m10x / 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  * Copyright (C) 2006 Ron Minnich, LANL
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  */
24
25 #include <arch/io.h>
26 #include <device/device.h>
27 #include <device/pnp.h>
28 #include <console/console.h>
29 #include <device/smbus.h>
30 #include <string.h>
31 #include <bitops.h>
32 #include <uart8250.h>
33 #include <pc80/keyboard.h>
34 #include <stdlib.h>
35 #include "chip.h"
36 #include "lpc47m10x.h"
37
38 /* Forward declarations */
39 static void enable_dev(device_t dev);
40 static void lpc47m10x_pnp_set_resources(device_t dev);
41 static void lpc47m10x_pnp_enable_resources(device_t dev);
42 static void lpc47m10x_pnp_enable(device_t dev);
43 static void lpc47m10x_init(device_t dev);
44
45 static void pnp_enter_conf_state(device_t dev);
46 static void pnp_exit_conf_state(device_t dev);
47 // static void dump_pnp_device(device_t dev);
48
49 struct chip_operations superio_smsc_lpc47m10x_ops = {
50         CHIP_NAME("SMSC LPC47M10x Super I/O")
51         .enable_dev = enable_dev
52 };
53
54 static struct device_operations ops = {
55         .read_resources   = pnp_read_resources,
56         .set_resources    = lpc47m10x_pnp_set_resources,
57         .enable_resources = lpc47m10x_pnp_enable_resources,
58         .enable           = lpc47m10x_pnp_enable,
59         .init             = lpc47m10x_init,
60 };
61
62 static struct pnp_info pnp_dev_info[] = {
63         { &ops, LPC47M10X2_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
64         { &ops, LPC47M10X2_PP,  PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
65         { &ops, LPC47M10X2_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
66         { &ops, LPC47M10X2_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
67         { &ops, LPC47M10X2_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, },
68 };
69
70 /**
71  * Create device structures and allocate resources to devices specified in the
72  * pnp_dev_info array (above).
73  *
74  * @param dev Pointer to structure describing a Super I/O device.
75  */
76 static void enable_dev(device_t dev)
77 {
78         pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info),
79                            pnp_dev_info);
80 }
81
82 /**
83  * Configure the specified Super I/O device with the resources (I/O space,
84  * etc.) that have been allocated for it.
85  *
86  * @param dev Pointer to structure describing a Super I/O device.
87  */
88 static void lpc47m10x_pnp_set_resources(device_t dev)
89 {
90         pnp_enter_conf_state(dev);
91         pnp_set_resources(dev);
92         pnp_exit_conf_state(dev);
93 }
94
95 static void lpc47m10x_pnp_enable_resources(device_t dev)
96 {
97         pnp_enter_conf_state(dev);
98         pnp_enable_resources(dev);
99         pnp_exit_conf_state(dev);
100 }
101
102 static void lpc47m10x_pnp_enable(device_t dev)
103 {
104         pnp_enter_conf_state(dev);
105         pnp_set_logical_device(dev);
106         pnp_set_enable(dev, (dev->enabled) ? 1 : 0);
107         pnp_exit_conf_state(dev);
108 }
109
110 /**
111  * Initialize the specified Super I/O device.
112  *
113  * Devices other than COM ports and the keyboard controller are ignored.
114  * For COM ports, we configure the baud rate.
115  *
116  * @param dev Pointer to structure describing a Super I/O device.
117  */
118 static void lpc47m10x_init(device_t dev)
119 {
120         struct superio_smsc_lpc47m10x_config *conf = dev->chip_info;
121         struct resource *res0;
122
123         if (!dev->enabled)
124                 return;
125
126         switch(dev->path.pnp.device) {
127         case LPC47M10X2_SP1:
128                 res0 = find_resource(dev, PNP_IDX_IO0);
129                 init_uart8250(res0->base, &conf->com1);
130                 break;
131         case LPC47M10X2_SP2:
132                 res0 = find_resource(dev, PNP_IDX_IO0);
133                 init_uart8250(res0->base, &conf->com2);
134                 break;
135         case LPC47M10X2_KBC:
136                 pc_keyboard_init(&conf->keyboard);
137                 break;
138         }
139 }
140
141 static void pnp_enter_conf_state(device_t dev)
142 {
143         outb(0x55, dev->path.pnp.port);
144 }
145
146 static void pnp_exit_conf_state(device_t dev)
147 {
148         outb(0xaa, dev->path.pnp.port);
149 }
150
151 #if 0
152 /**
153  * Print the values of all of the LPC47M10X2's configuration registers.
154  *
155  * NOTE: The LPC47M10X2 must be in config mode when this function is called.
156  *
157  * @param dev Pointer to structure describing a Super I/O device.
158  */
159 static void dump_pnp_device(device_t dev)
160 {
161         int i;
162         print_debug("\n");
163
164         for (i = 0; i <= LPC47M10X2_MAX_CONFIG_REGISTER; i++) {
165                 u8 register_value;
166
167                 if ((i & 0x0f) == 0) {
168                         print_debug_hex8(i);
169                         print_debug_char(':');
170                 }
171
172                 /*
173                  * Skip over 'register' that would cause exit from
174                  * configuration mode.
175                  */
176                 if (i == 0xaa)
177                         register_value = 0xaa;
178                 else
179                         register_value = pnp_read_config(dev, i);
180
181                 print_debug_char(' ');
182                 print_debug_hex8(register_value);
183                 if ((i & 0x0f) == 0x0f)
184                         print_debug("\n");
185         }
186
187         print_debug("\n");
188 }
189 #endif