blob: b3238de3b142e4900078c6d5d4b9f24a07af2354 [file] [log] [blame]
Uwe Hermann3fa13632007-07-12 13:13:56 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermann3fa13632007-07-12 13:13:56 +00003 *
4 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
5 *
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.
10 *
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.
Uwe Hermann3fa13632007-07-12 13:13:56 +000015 */
16
17/*
18 * Generic driver for pretty much all known Standard Microsystems Corporation
19 * (SMSC) Super I/O chips.
20 *
21 * Datasheets are available from: http://www.smsc.com/main/datasheet.html
22 *
23 * Most of the SMSC Super I/O chips seem to be similar enough (for our
24 * purposes) so that we can handle them with a unified driver.
25 *
26 * So far only the ASUS A8000 has been tested on real hardware!
27 *
28 * The floppy disk controller, the parallel port, the serial ports, and the
29 * keyboard controller should work with all the chips. For the more advanced
30 * stuff (e.g. HWM, ACPI, SMBus) more work is probably required.
31 */
32
33#include <arch/io.h>
34#include <device/device.h>
35#include <device/pnp.h>
Nico Huber1c811282013-06-15 20:33:44 +020036#include <superio/conf_mode.h>
Uwe Hermann3fa13632007-07-12 13:13:56 +000037#include <console/console.h>
Uwe Hermann3fa13632007-07-12 13:13:56 +000038#include <pc80/keyboard.h>
Uwe Hermann55e6eba2007-10-27 20:05:21 +000039#include <stdlib.h>
Uwe Hermann3fa13632007-07-12 13:13:56 +000040
41/* The following Super I/O chips are currently supported by this driver: */
Thomas Jourdan1a692d82009-07-01 17:01:17 +000042#define LPC47M172 0x14
Uwe Hermann3fa13632007-07-12 13:13:56 +000043#define FDC37B80X 0x42 /* Same ID: FDC37M70X (a.k.a. FDC37M707) */
44#define FDC37B78X 0x44
45#define FDC37B72X 0x4c
46#define FDC37M81X 0x4d
47#define FDC37M60X 0x47
48#define LPC47B27X 0x51 /* a.k.a. LPC47B272 */
Michael Goldb70a45a2009-07-05 19:29:39 +000049#define LPC47U33X 0x54
Uwe Hermann3fa13632007-07-12 13:13:56 +000050#define LPC47M10X 0x59 /* Same ID: LPC47M112, LPC47M13X */
51#define LPC47M15X 0x60 /* Same ID: LPC47M192 */
52#define LPC47S45X 0x62
53#define LPC47B397 0x6f
54#define A8000 0x77 /* ASUS A8000, a rebranded DME1737(?) */
55#define DME1737 0x78
Christopher Kilgour7bc63fd2008-04-19 13:32:19 +000056#define SCH3112 0x7c
Mark Norman0d21cd32011-06-14 22:20:37 +093057#define SCH3114 0x7d
Uwe Hermann3fa13632007-07-12 13:13:56 +000058#define SCH5307 0x81 /* Rebranded LPC47B397(?) */
Arnaud Maye5b1d51b2009-08-28 20:42:21 +000059#define SCH5027D 0x89
Zheng Bao01dd9e12009-12-01 03:22:16 +000060#define SCH4304 0x90 /* SCH4304, SCH4307 */
Uwe Hermann3fa13632007-07-12 13:13:56 +000061
62/* Register defines */
63#define DEVICE_ID_REG 0x20 /* Device ID register */
64#define DEVICE_REV_REG 0x21 /* Device revision register */
Thomas Jourdan1a692d82009-07-01 17:01:17 +000065#define DEVICE_TEST7_REG 0x29 /* Device test 7 register */
Uwe Hermann3fa13632007-07-12 13:13:56 +000066
67/* Static variables for the Super I/O device ID and revision. */
68static int first_time = 1;
Uwe Hermanna69d9782010-11-15 19:35:14 +000069static u8 superio_id = 0;
70static u8 superio_rev = 0;
Uwe Hermann3fa13632007-07-12 13:13:56 +000071
Uwe Hermann3fa13632007-07-12 13:13:56 +000072/**
73 * A list of all possible logical devices which may be supported by at least
74 * one of the Super I/O chips. These values are used as index into the
75 * logical_device_table[i].devs array(s).
76 *
77 * If you change this enum, you must also adapt the logical_device_table[]
78 * array and MAX_LOGICAL_DEVICES!
79 */
80enum {
81 LD_FDC, /* Floppy disk controller */
82 LD_PP, /* Parallel port */
83 LD_SP1, /* Serial port 1 (COM1) */
84 LD_SP2, /* Serial port 2 (COM2) */
85 LD_RTC, /* Real-time clock */
86 LD_KBC, /* Keyboard controller */
87 LD_AUX, /* Auxiliary I/O */
88 LD_XBUS, /* X-Bus */
89 LD_HWM, /* Hardware monitor */
90 LD_GAME, /* Game port */
91 LD_PME, /* Power management events */
92 LD_MPU401, /* MPU-401 MIDI UART */
93 LD_RT, /* Runtime registers / security key registers */
94 LD_ACPI, /* ACPI */
95 LD_SMB, /* SMBus */
96};
97
98/* Note: This value must match the number of items in the enum above! */
99#define MAX_LOGICAL_DEVICES 15
100
101/**
102 * A table describing the logical devices which are present on the
103 * supported Super I/O chips.
104 *
105 * The first entry (superio_id) is the device ID of the Super I/O chip
106 * as stored in the (read-only) DEVICE_ID_REG register.
107 *
108 * The second entry (devs) is the list of logical device IDs which are
109 * present on that particular Super I/O chip. A value of -1 means the
110 * device is not present on that chip.
111 *
112 * Note: Do _not_ list chips with different name but same device ID twice!
113 * The result would be that the init code would be executed twice!
114 */
Uwe Hermanna0181ea2007-10-31 22:26:51 +0000115static const struct logical_devices {
Uwe Hermanna69d9782010-11-15 19:35:14 +0000116 u8 superio_id;
Uwe Hermann3fa13632007-07-12 13:13:56 +0000117 int devs[MAX_LOGICAL_DEVICES];
118} logical_device_table[] = {
Zheng Bao9db833b2009-12-28 09:59:44 +0000119 /* Chip FDC PP SP1 SP2 RTC KBC AUX XBUS HWM GAME PME MPU RT ACPI SMB */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000120 {LPC47M172,{0, 3, 4, 2, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000121 {FDC37B80X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
122 {FDC37B78X,{0, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
123 {FDC37B72X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
124 {FDC37M81X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
125 {FDC37M60X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
126 {LPC47B27X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, -1, 11, 10, -1, -1}},
127 {LPC47M10X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
128 {LPC47M15X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
129 {LPC47S45X,{0, 3, 4, 5, 6, 7, -1, 8, -1, -1, -1, -1, 10, -1, 11}},
130 {LPC47B397,{0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
Michael Goldb70a45a2009-07-05 19:29:39 +0000131 {LPC47U33X,{0, 3, 4, -1, -1, 7, -1, -1, -1, 9, 0, 5, 10, 0, 11}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000132 {A8000, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
133 {DME1737, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Christopher Kilgour7bc63fd2008-04-19 13:32:19 +0000134 {SCH3112, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Mark Norman0d21cd32011-06-14 22:20:37 +0930135 {SCH3114, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000136 {SCH5307, {0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
Arnaud Maye5b1d51b2009-08-28 20:42:21 +0000137 {SCH5027D, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, 11}},
Zheng Bao60855272009-11-30 23:53:06 +0000138 {SCH4304, {0, 3, 4, 5, -1, 7, -1, 11, -1, -1, -1, -1, 10, -1, -1}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000139};
140
141/**
Uwe Hermann3fa13632007-07-12 13:13:56 +0000142 * Initialize those logical devices which need a special init.
143 *
144 * @param dev The device to use.
145 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100146static void smsc_init(struct device *dev)
Uwe Hermann3fa13632007-07-12 13:13:56 +0000147{
Uwe Hermann3fa13632007-07-12 13:13:56 +0000148 int i, ld;
149
150 /* Do not initialize disabled devices. */
151 if (!dev->enabled)
152 return;
153
154 /* Find the correct Super I/O. */
155 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
156 if (logical_device_table[i].superio_id == superio_id)
157 break;
158
159 /* If no Super I/O was found, return. */
160 if (i == ARRAY_SIZE(logical_device_table))
161 return;
162
163 /* A Super I/O was found, so initialize the respective device. */
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000164 ld = dev->path.pnp.device;
Stefan Reinauer13508b92011-04-19 21:33:40 +0000165 if (ld == logical_device_table[i].devs[LD_KBC]) {
Edward O'Callaghandef00be2014-04-30 05:01:52 +1000166 pc_keyboard_init();
Uwe Hermann3fa13632007-07-12 13:13:56 +0000167 }
168}
169
170/** Standard device operations. */
171static struct device_operations ops = {
Nico Huber9cb09412013-06-15 15:30:19 +0200172 .read_resources = pnp_read_resources,
Nico Huber0b2ee932013-06-15 19:58:35 +0200173 .set_resources = pnp_set_resources,
174 .enable_resources = pnp_enable_resources,
175 .enable = pnp_alt_enable,
Nico Huber9cb09412013-06-15 15:30:19 +0200176 .init = smsc_init,
Nico Huber1c811282013-06-15 20:33:44 +0200177 .ops_pnp_mode = &pnp_conf_mode_55_aa,
Uwe Hermann3fa13632007-07-12 13:13:56 +0000178};
179
180/**
181 * TODO.
182 *
183 * This table should contain all possible entries for any of the supported
184 * Super I/O chips, even if some of them don't have the respective logical
185 * devices. That will be handled correctly by our code.
186 *
187 * The LD_FOO entries are device markers which tell you the type of the logical
188 * device (e.g. whether it's a floppy disk controller or a serial port etc.).
189 *
190 * Before using pnp_dev_info[] in pnp_enable_devices() these markers have
191 * to be replaced with the real logical device IDs of the respective
192 * Super I/O chip. This is done in enable_dev().
193 *
194 * TODO: FDC, PP, SP1, SP2, and KBC should work, the rest probably not (yet).
195 */
196static struct pnp_info pnp_dev_info[] = {
Uwe Hermanna69d9782010-11-15 19:35:14 +0000197 { &ops, LD_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
198 { &ops, LD_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, },
199 { &ops, LD_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
200 { &ops, LD_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, },
Uwe Hermann3fa13632007-07-12 13:13:56 +0000201 { &ops, LD_RTC, },
Uwe Hermanna69d9782010-11-15 19:35:14 +0000202 { &ops, LD_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, },
Uwe Hermann3fa13632007-07-12 13:13:56 +0000203 { &ops, LD_AUX, },
204 { &ops, LD_XBUS, },
Uwe Hermanna69d9782010-11-15 19:35:14 +0000205 { &ops, LD_HWM, PNP_IO0, {0x07f0, 0}, },
Uwe Hermann3fa13632007-07-12 13:13:56 +0000206 { &ops, LD_GAME, },
207 { &ops, LD_PME, },
208 { &ops, LD_MPU401, },
Uwe Hermanna69d9782010-11-15 19:35:14 +0000209 { &ops, LD_RT, PNP_IO0, {0x0780, 0}, },
Uwe Hermann3fa13632007-07-12 13:13:56 +0000210 { &ops, LD_ACPI, },
211 { &ops, LD_SMB, },
212};
213
214/**
215 * Enable the logical devices of the Super I/O chip.
216 *
217 * TODO: Think about how to handle the case when a mainboard has multiple
218 * Super I/O chips soldered on.
219 * TODO: Can this code be simplified a bit?
220 *
221 * @param dev The device to use.
222 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100223static void enable_dev(struct device *dev)
Uwe Hermann3fa13632007-07-12 13:13:56 +0000224{
225 int i, j, fn;
226 int tmp[MAX_LOGICAL_DEVICES];
Uwe Hermanna69d9782010-11-15 19:35:14 +0000227 u8 test7;
Uwe Hermann3fa13632007-07-12 13:13:56 +0000228
229 if (first_time) {
Kyösti Mälkki33eaf3a2014-06-06 21:46:47 +0300230
231 pnp_enter_conf_mode_55(dev);
232
Uwe Hermann3fa13632007-07-12 13:13:56 +0000233 /* Read the device ID and revision of the Super I/O chip. */
Uwe Hermann3fa13632007-07-12 13:13:56 +0000234 superio_id = pnp_read_config(dev, DEVICE_ID_REG);
235 superio_rev = pnp_read_config(dev, DEVICE_REV_REG);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000236
237 /* TODO: Error handling? */
238
Uwe Hermanna69d9782010-11-15 19:35:14 +0000239 printk(BIOS_INFO, "Found SMSC Super I/O (ID=0x%02x, "
240 "rev=0x%02x)\n", superio_id, superio_rev);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000241 first_time = 0;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000242
Uwe Hermanna69d9782010-11-15 19:35:14 +0000243 if (superio_id == LPC47M172) {
244 /*
245 * Do not use the default logical device number but
246 * instead the standard SMSC registers set.
247 */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000248
Uwe Hermanna69d9782010-11-15 19:35:14 +0000249 /*
250 * TEST7 configuration register (0x29)
251 * Bit 0: LD_NUM (0 = new, 1 = std SMSC)
252 */
253 test7 = pnp_read_config(dev, DEVICE_TEST7_REG);
254 test7 |= (1 << 0);
255 pnp_write_config(dev, DEVICE_TEST7_REG, test7);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000256 }
Kyösti Mälkki33eaf3a2014-06-06 21:46:47 +0300257
258 pnp_exit_conf_mode_aa(dev);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000259 }
260
261 /* Find the correct Super I/O. */
262 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
263 if (logical_device_table[i].superio_id == superio_id)
264 break;
265
266 /* If no Super I/O was found, return. */
267 if (i == ARRAY_SIZE(logical_device_table))
268 return;
269
270 /* Temporarily save the LD_FOO values. */
271 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
272 tmp[j] = pnp_dev_info[j].function;
273
Uwe Hermanna69d9782010-11-15 19:35:14 +0000274 /*
275 * Replace the LD_FOO markers in pnp_dev_info[] with
Uwe Hermann3fa13632007-07-12 13:13:56 +0000276 * the real logical device IDs of this Super I/O chip.
277 */
278 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++) {
279 fn = pnp_dev_info[j].function;
280 pnp_dev_info[j].function = logical_device_table[i].devs[fn];
281 }
282
283 /* Enable the specified devices (if present on the chip). */
284 pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info),
Stefan Reinauerbd112982010-03-17 03:14:54 +0000285 &pnp_dev_info[0]);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000286
287 /* Restore LD_FOO values. */
288 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
289 pnp_dev_info[j].function = tmp[j];
290}
291
292struct chip_operations superio_smsc_smscsuperio_ops = {
293 CHIP_NAME("Various SMSC Super I/Os")
294 .enable_dev = enable_dev
295};