2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Generic driver for pretty much all known Standard Microsystems Corporation
23 * (SMSC) Super I/O chips.
25 * Datasheets are available from: http://www.smsc.com/main/datasheet.html
27 * Most of the SMSC Super I/O chips seem to be similar enough (for our
28 * purposes) so that we can handle them with a unified driver.
30 * So far only the ASUS A8000 has been tested on real hardware!
32 * The floppy disk controller, the parallel port, the serial ports, and the
33 * keyboard controller should work with all the chips. For the more advanced
34 * stuff (e.g. HWM, ACPI, SMBus) more work is probably required.
38 #include <device/device.h>
39 #include <device/pnp.h>
40 #include <console/console.h>
42 #include <pc80/keyboard.h>
46 /* The following Super I/O chips are currently supported by this driver: */
47 #define FDC37B80X 0x42 /* Same ID: FDC37M70X (a.k.a. FDC37M707) */
48 #define FDC37B78X 0x44
49 #define FDC37B72X 0x4c
50 #define FDC37M81X 0x4d
51 #define FDC37M60X 0x47
52 #define LPC47B27X 0x51 /* a.k.a. LPC47B272 */
53 #define LPC47M10X 0x59 /* Same ID: LPC47M112, LPC47M13X */
54 #define LPC47M15X 0x60 /* Same ID: LPC47M192 */
55 #define LPC47S45X 0x62
56 #define LPC47B397 0x6f
57 #define A8000 0x77 /* ASUS A8000, a rebranded DME1737(?) */
59 #define SCH5307 0x81 /* Rebranded LPC47B397(?) */
61 /* Register defines */
62 #define DEVICE_ID_REG 0x20 /* Device ID register */
63 #define DEVICE_REV_REG 0x21 /* Device revision register */
65 /* Static variables for the Super I/O device ID and revision. */
66 static int first_time = 1;
67 static uint8_t superio_id = 0;
68 static uint8_t superio_rev = 0;
71 * A list of all possible logical devices which may be supported by at least
72 * one of the Super I/O chips. These values are used as index into the
73 * logical_device_table[i].devs array(s).
75 * If you change this enum, you must also adapt the logical_device_table[]
76 * array and MAX_LOGICAL_DEVICES!
79 LD_FDC, /* Floppy disk controller */
80 LD_PP, /* Parallel port */
81 LD_SP1, /* Serial port 1 (COM1) */
82 LD_SP2, /* Serial port 2 (COM2) */
83 LD_RTC, /* Real-time clock */
84 LD_KBC, /* Keyboard controller */
85 LD_AUX, /* Auxiliary I/O */
87 LD_HWM, /* Hardware monitor */
88 LD_GAME, /* Game port */
89 LD_PME, /* Power management events */
90 LD_MPU401, /* MPU-401 MIDI UART */
91 LD_RT, /* Runtime registers / security key registers */
96 /* Note: This value must match the number of items in the enum above! */
97 #define MAX_LOGICAL_DEVICES 15
100 * A table describing the logical devices which are present on the
101 * supported Super I/O chips.
103 * The first entry (superio_id) is the device ID of the Super I/O chip
104 * as stored in the (read-only) DEVICE_ID_REG register.
106 * The second entry (devs) is the list of logical device IDs which are
107 * present on that particular Super I/O chip. A value of -1 means the
108 * device is not present on that chip.
110 * Note: Do _not_ list chips with different name but same device ID twice!
111 * The result would be that the init code would be executed twice!
113 static const struct logical_devices {
115 int devs[MAX_LOGICAL_DEVICES];
116 } logical_device_table[] = {
117 // Chip FDC PP SP1 SP2 RTC KBC AUX XBUS HWM GAME PME MPU RT ACPI SMB
118 {FDC37B80X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
119 {FDC37B78X,{0, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
120 {FDC37B72X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
121 {FDC37M81X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
122 {FDC37M60X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
123 {LPC47B27X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, -1, 11, 10, -1, -1}},
124 {LPC47M10X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
125 {LPC47M15X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
126 {LPC47S45X,{0, 3, 4, 5, 6, 7, -1, 8, -1, -1, -1, -1, 10, -1, 11}},
127 {LPC47B397,{0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
128 {A8000, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
129 {DME1737, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
130 {SCH5307, {0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
134 * Enter the configuration state by writing 0x55 to the config port.
136 * The Super I/O configuration registers can only be modified when the chip
137 * is in the configuration state. Thus, to program the registers you have
138 * to a) enter config mode, b) program the registers, c) exit config mode.
140 * @param dev The device to use.
142 static inline void smsc_pnp_enter_conf_state(device_t dev)
144 outb(0x55, dev->path.u.pnp.port);
148 * Exit the configuration state by writing 0xaa to the config port.
150 * This puts the chip into the 'run' state again.
152 * @param dev The device to use.
154 static inline void smsc_pnp_exit_conf_state(device_t dev)
156 outb(0xaa, dev->path.u.pnp.port);
159 /** Wrapper for pnp_set_resources(). */
160 static void smsc_pnp_set_resources(device_t dev)
162 smsc_pnp_enter_conf_state(dev);
163 pnp_set_resources(dev);
164 smsc_pnp_exit_conf_state(dev);
167 /** Wrapper for pnp_enable_resources(). */
168 static void smsc_pnp_enable_resources(device_t dev)
170 smsc_pnp_enter_conf_state(dev);
171 pnp_enable_resources(dev);
172 smsc_pnp_exit_conf_state(dev);
176 * If so configured, enable the specified device, otherwise
177 * explicitly disable it.
179 * @param dev The device to use.
181 static void smsc_pnp_enable(device_t dev)
183 smsc_pnp_enter_conf_state(dev);
184 pnp_set_logical_device(dev);
185 (dev->enabled) ? pnp_set_enable(dev, 1) : pnp_set_enable(dev, 0);
186 smsc_pnp_exit_conf_state(dev);
190 * Initialize those logical devices which need a special init.
192 * @param dev The device to use.
194 static void smsc_init(device_t dev)
196 struct superio_smsc_smscsuperio_config *conf = dev->chip_info;
197 struct resource *res0, *res1;
200 /* Do not initialize disabled devices. */
204 /* Find the correct Super I/O. */
205 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
206 if (logical_device_table[i].superio_id == superio_id)
209 /* If no Super I/O was found, return. */
210 if (i == ARRAY_SIZE(logical_device_table))
213 /* A Super I/O was found, so initialize the respective device. */
214 ld = dev->path.u.pnp.device;
215 if (ld == logical_device_table[i].devs[LD_SP1]) {
216 res0 = find_resource(dev, PNP_IDX_IO0);
217 init_uart8250(res0->base, &conf->com1);
218 } else if (ld == logical_device_table[i].devs[LD_SP2]) {
219 res0 = find_resource(dev, PNP_IDX_IO0);
220 init_uart8250(res0->base, &conf->com2);
221 } else if (ld == logical_device_table[i].devs[LD_KBC]) {
222 res0 = find_resource(dev, PNP_IDX_IO0);
223 res1 = find_resource(dev, PNP_IDX_IO1);
224 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
228 /** Standard device operations. */
229 static struct device_operations ops = {
230 .read_resources = pnp_read_resources,
231 .set_resources = smsc_pnp_set_resources,
232 .enable_resources = smsc_pnp_enable_resources,
233 .enable = smsc_pnp_enable,
240 * This table should contain all possible entries for any of the supported
241 * Super I/O chips, even if some of them don't have the respective logical
242 * devices. That will be handled correctly by our code.
244 * The LD_FOO entries are device markers which tell you the type of the logical
245 * device (e.g. whether it's a floppy disk controller or a serial port etc.).
247 * Before using pnp_dev_info[] in pnp_enable_devices() these markers have
248 * to be replaced with the real logical device IDs of the respective
249 * Super I/O chip. This is done in enable_dev().
251 * TODO: FDC, PP, SP1, SP2, and KBC should work, the rest probably not (yet).
253 static struct pnp_info pnp_dev_info[] = {
254 { &ops, LD_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0 }, },
255 { &ops, LD_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0 }, },
256 { &ops, LD_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
257 { &ops, LD_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
259 { &ops, LD_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 },
263 { &ops, LD_HWM, PNP_IO0, { 0x7f0, 0 }, },
266 { &ops, LD_MPU401, },
267 { &ops, LD_RT, PNP_IO0, { 0x780, 0 }, },
273 * Enable the logical devices of the Super I/O chip.
275 * TODO: Think about how to handle the case when a mainboard has multiple
276 * Super I/O chips soldered on.
277 * TODO: Can this code be simplified a bit?
279 * @param dev The device to use.
281 static void enable_dev(device_t dev)
284 int tmp[MAX_LOGICAL_DEVICES];
287 /* Read the device ID and revision of the Super I/O chip. */
288 smsc_pnp_enter_conf_state(dev);
289 superio_id = pnp_read_config(dev, DEVICE_ID_REG);
290 superio_rev = pnp_read_config(dev, DEVICE_REV_REG);
291 smsc_pnp_exit_conf_state(dev);
293 /* TODO: Error handling? */
295 printk_info("Found SMSC Super I/O (ID=0x%02x, rev=0x%02x)\n",
296 superio_id, superio_rev);
300 /* Find the correct Super I/O. */
301 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
302 if (logical_device_table[i].superio_id == superio_id)
305 /* If no Super I/O was found, return. */
306 if (i == ARRAY_SIZE(logical_device_table))
309 /* Temporarily save the LD_FOO values. */
310 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
311 tmp[j] = pnp_dev_info[j].function;
313 /* Replace the LD_FOO markers in pnp_dev_info[] with
314 * the real logical device IDs of this Super I/O chip.
316 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++) {
317 fn = pnp_dev_info[j].function;
318 pnp_dev_info[j].function = logical_device_table[i].devs[fn];
321 /* Enable the specified devices (if present on the chip). */
322 pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info),
325 /* Restore LD_FOO values. */
326 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
327 pnp_dev_info[j].function = tmp[j];
330 struct chip_operations superio_smsc_smscsuperio_ops = {
331 CHIP_NAME("Various SMSC Super I/Os")
332 .enable_dev = enable_dev