blob: d9aa4777e59395eaa62ad99aceb0a94efe719bfd [file] [log] [blame]
Felix Held3f3eca92020-01-23 17:12:32 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann3fa13632007-07-12 13:13:56 +00002
3/*
4 * Generic driver for pretty much all known Standard Microsystems Corporation
5 * (SMSC) Super I/O chips.
6 *
7 * Datasheets are available from: http://www.smsc.com/main/datasheet.html
8 *
9 * Most of the SMSC Super I/O chips seem to be similar enough (for our
10 * purposes) so that we can handle them with a unified driver.
11 *
12 * So far only the ASUS A8000 has been tested on real hardware!
13 *
14 * The floppy disk controller, the parallel port, the serial ports, and the
15 * keyboard controller should work with all the chips. For the more advanced
16 * stuff (e.g. HWM, ACPI, SMBus) more work is probably required.
17 */
18
Uwe Hermann3fa13632007-07-12 13:13:56 +000019#include <device/device.h>
20#include <device/pnp.h>
Nico Huber1c811282013-06-15 20:33:44 +020021#include <superio/conf_mode.h>
Uwe Hermann3fa13632007-07-12 13:13:56 +000022#include <console/console.h>
Uwe Hermann3fa13632007-07-12 13:13:56 +000023#include <pc80/keyboard.h>
Uwe Hermann3fa13632007-07-12 13:13:56 +000024
25/* The following Super I/O chips are currently supported by this driver: */
Thomas Jourdan1a692d82009-07-01 17:01:17 +000026#define LPC47M172 0x14
Uwe Hermann3fa13632007-07-12 13:13:56 +000027#define FDC37B80X 0x42 /* Same ID: FDC37M70X (a.k.a. FDC37M707) */
28#define FDC37B78X 0x44
29#define FDC37B72X 0x4c
30#define FDC37M81X 0x4d
31#define FDC37M60X 0x47
32#define LPC47B27X 0x51 /* a.k.a. LPC47B272 */
Michael Goldb70a45a2009-07-05 19:29:39 +000033#define LPC47U33X 0x54
Uwe Hermann3fa13632007-07-12 13:13:56 +000034#define LPC47M10X 0x59 /* Same ID: LPC47M112, LPC47M13X */
35#define LPC47M15X 0x60 /* Same ID: LPC47M192 */
36#define LPC47S45X 0x62
37#define LPC47B397 0x6f
38#define A8000 0x77 /* ASUS A8000, a rebranded DME1737(?) */
39#define DME1737 0x78
Angel Pons0feaa852018-10-08 21:41:24 +020040#define SCH5504 0x79
Christopher Kilgour7bc63fd2008-04-19 13:32:19 +000041#define SCH3112 0x7c
Mark Norman0d21cd32011-06-14 22:20:37 +093042#define SCH3114 0x7d
Uwe Hermann3fa13632007-07-12 13:13:56 +000043#define SCH5307 0x81 /* Rebranded LPC47B397(?) */
Arnaud Maye5b1d51b2009-08-28 20:42:21 +000044#define SCH5027D 0x89
Zheng Bao01dd9e12009-12-01 03:22:16 +000045#define SCH4304 0x90 /* SCH4304, SCH4307 */
Arthur Heymansf1a35032018-12-15 18:25:03 +010046#define SCH5147 0xc1
Uwe Hermann3fa13632007-07-12 13:13:56 +000047
48/* Register defines */
49#define DEVICE_ID_REG 0x20 /* Device ID register */
50#define DEVICE_REV_REG 0x21 /* Device revision register */
Thomas Jourdan1a692d82009-07-01 17:01:17 +000051#define DEVICE_TEST7_REG 0x29 /* Device test 7 register */
Uwe Hermann3fa13632007-07-12 13:13:56 +000052
53/* Static variables for the Super I/O device ID and revision. */
54static int first_time = 1;
Uwe Hermanna69d9782010-11-15 19:35:14 +000055static u8 superio_id = 0;
56static u8 superio_rev = 0;
Uwe Hermann3fa13632007-07-12 13:13:56 +000057
Uwe Hermann3fa13632007-07-12 13:13:56 +000058/**
59 * A list of all possible logical devices which may be supported by at least
60 * one of the Super I/O chips. These values are used as index into the
61 * logical_device_table[i].devs array(s).
62 *
63 * If you change this enum, you must also adapt the logical_device_table[]
64 * array and MAX_LOGICAL_DEVICES!
65 */
66enum {
67 LD_FDC, /* Floppy disk controller */
68 LD_PP, /* Parallel port */
69 LD_SP1, /* Serial port 1 (COM1) */
70 LD_SP2, /* Serial port 2 (COM2) */
71 LD_RTC, /* Real-time clock */
72 LD_KBC, /* Keyboard controller */
73 LD_AUX, /* Auxiliary I/O */
74 LD_XBUS, /* X-Bus */
75 LD_HWM, /* Hardware monitor */
76 LD_GAME, /* Game port */
77 LD_PME, /* Power management events */
78 LD_MPU401, /* MPU-401 MIDI UART */
79 LD_RT, /* Runtime registers / security key registers */
80 LD_ACPI, /* ACPI */
81 LD_SMB, /* SMBus */
82};
83
84/* Note: This value must match the number of items in the enum above! */
85#define MAX_LOGICAL_DEVICES 15
86
87/**
88 * A table describing the logical devices which are present on the
89 * supported Super I/O chips.
90 *
91 * The first entry (superio_id) is the device ID of the Super I/O chip
92 * as stored in the (read-only) DEVICE_ID_REG register.
93 *
94 * The second entry (devs) is the list of logical device IDs which are
95 * present on that particular Super I/O chip. A value of -1 means the
96 * device is not present on that chip.
97 *
98 * Note: Do _not_ list chips with different name but same device ID twice!
99 * The result would be that the init code would be executed twice!
100 */
Uwe Hermanna0181ea2007-10-31 22:26:51 +0000101static const struct logical_devices {
Uwe Hermanna69d9782010-11-15 19:35:14 +0000102 u8 superio_id;
Uwe Hermann3fa13632007-07-12 13:13:56 +0000103 int devs[MAX_LOGICAL_DEVICES];
104} logical_device_table[] = {
Zheng Bao9db833b2009-12-28 09:59:44 +0000105 /* Chip FDC PP SP1 SP2 RTC KBC AUX XBUS HWM GAME PME MPU RT ACPI SMB */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000106 {LPC47M172,{0, 3, 4, 2, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000107 {FDC37B80X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
108 {FDC37B78X,{0, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
109 {FDC37B72X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
110 {FDC37M81X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
111 {FDC37M60X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
112 {LPC47B27X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, -1, 11, 10, -1, -1}},
113 {LPC47M10X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
114 {LPC47M15X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
115 {LPC47S45X,{0, 3, 4, 5, 6, 7, -1, 8, -1, -1, -1, -1, 10, -1, 11}},
116 {LPC47B397,{0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
Michael Goldb70a45a2009-07-05 19:29:39 +0000117 {LPC47U33X,{0, 3, 4, -1, -1, 7, -1, -1, -1, 9, 0, 5, 10, 0, 11}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000118 {A8000, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
119 {DME1737, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Angel Pons0feaa852018-10-08 21:41:24 +0200120 {SCH5504, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Christopher Kilgour7bc63fd2008-04-19 13:32:19 +0000121 {SCH3112, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Mark Norman0d21cd32011-06-14 22:20:37 +0930122 {SCH3114, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000123 {SCH5307, {0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
Arnaud Maye5b1d51b2009-08-28 20:42:21 +0000124 {SCH5027D, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, 11}},
Zheng Bao60855272009-11-30 23:53:06 +0000125 {SCH4304, {0, 3, 4, 5, -1, 7, -1, 11, -1, -1, -1, -1, 10, -1, -1}},
Arthur Heymansf1a35032018-12-15 18:25:03 +0100126 {SCH5147, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
Uwe Hermann3fa13632007-07-12 13:13:56 +0000127};
128
129/**
Uwe Hermann3fa13632007-07-12 13:13:56 +0000130 * Initialize those logical devices which need a special init.
131 *
132 * @param dev The device to use.
133 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100134static void smsc_init(struct device *dev)
Uwe Hermann3fa13632007-07-12 13:13:56 +0000135{
Uwe Hermann3fa13632007-07-12 13:13:56 +0000136 int i, ld;
137
138 /* Do not initialize disabled devices. */
139 if (!dev->enabled)
140 return;
141
142 /* Find the correct Super I/O. */
143 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
144 if (logical_device_table[i].superio_id == superio_id)
145 break;
146
147 /* If no Super I/O was found, return. */
148 if (i == ARRAY_SIZE(logical_device_table))
149 return;
150
151 /* A Super I/O was found, so initialize the respective device. */
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000152 ld = dev->path.pnp.device;
Stefan Reinauer13508b92011-04-19 21:33:40 +0000153 if (ld == logical_device_table[i].devs[LD_KBC]) {
Timothy Pearson448e3862015-11-24 14:12:01 -0600154 pc_keyboard_init(NO_AUX_DEVICE);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000155 }
156}
157
158/** Standard device operations. */
159static struct device_operations ops = {
Nico Huber9cb09412013-06-15 15:30:19 +0200160 .read_resources = pnp_read_resources,
Nico Huber0b2ee932013-06-15 19:58:35 +0200161 .set_resources = pnp_set_resources,
162 .enable_resources = pnp_enable_resources,
163 .enable = pnp_alt_enable,
Nico Huber9cb09412013-06-15 15:30:19 +0200164 .init = smsc_init,
Nico Huber1c811282013-06-15 20:33:44 +0200165 .ops_pnp_mode = &pnp_conf_mode_55_aa,
Uwe Hermann3fa13632007-07-12 13:13:56 +0000166};
167
168/**
169 * TODO.
170 *
171 * This table should contain all possible entries for any of the supported
172 * Super I/O chips, even if some of them don't have the respective logical
173 * devices. That will be handled correctly by our code.
174 *
175 * The LD_FOO entries are device markers which tell you the type of the logical
176 * device (e.g. whether it's a floppy disk controller or a serial port etc.).
177 *
178 * Before using pnp_dev_info[] in pnp_enable_devices() these markers have
179 * to be replaced with the real logical device IDs of the respective
180 * Super I/O chip. This is done in enable_dev().
181 *
182 * TODO: FDC, PP, SP1, SP2, and KBC should work, the rest probably not (yet).
183 */
184static struct pnp_info pnp_dev_info[] = {
Felix Heldb0d868e2018-07-06 23:39:00 +0200185 { NULL, LD_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
186 { NULL, LD_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
187 { NULL, LD_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
188 { NULL, LD_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, },
189 { NULL, LD_RTC, },
190 { NULL, LD_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1,
191 0x07ff, 0x07ff, },
192 { NULL, LD_AUX, },
193 { NULL, LD_XBUS, },
194 { NULL, LD_HWM, PNP_IO0, 0x07f0, },
195 { NULL, LD_GAME, },
196 { NULL, LD_PME, },
197 { NULL, LD_MPU401, },
198 { NULL, LD_RT, PNP_IO0, 0x0780, },
199 { NULL, LD_ACPI, },
200 { NULL, LD_SMB, },
Uwe Hermann3fa13632007-07-12 13:13:56 +0000201};
202
203/**
204 * Enable the logical devices of the Super I/O chip.
205 *
206 * TODO: Think about how to handle the case when a mainboard has multiple
207 * Super I/O chips soldered on.
208 * TODO: Can this code be simplified a bit?
209 *
210 * @param dev The device to use.
211 */
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100212static void enable_dev(struct device *dev)
Uwe Hermann3fa13632007-07-12 13:13:56 +0000213{
214 int i, j, fn;
215 int tmp[MAX_LOGICAL_DEVICES];
Uwe Hermanna69d9782010-11-15 19:35:14 +0000216 u8 test7;
Uwe Hermann3fa13632007-07-12 13:13:56 +0000217
218 if (first_time) {
Kyösti Mälkki33eaf3a2014-06-06 21:46:47 +0300219 pnp_enter_conf_mode_55(dev);
220
Uwe Hermann3fa13632007-07-12 13:13:56 +0000221 /* Read the device ID and revision of the Super I/O chip. */
Uwe Hermann3fa13632007-07-12 13:13:56 +0000222 superio_id = pnp_read_config(dev, DEVICE_ID_REG);
223 superio_rev = pnp_read_config(dev, DEVICE_REV_REG);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000224
225 /* TODO: Error handling? */
226
Elyes HAOUAScf139502016-09-16 20:32:00 +0200227 printk(BIOS_INFO, "Found SMSC Super I/O (ID = 0x%02x, "
228 "rev = 0x%02x)\n", superio_id, superio_rev);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000229 first_time = 0;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000230
Uwe Hermanna69d9782010-11-15 19:35:14 +0000231 if (superio_id == LPC47M172) {
232 /*
233 * Do not use the default logical device number but
234 * instead the standard SMSC registers set.
235 */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000236
Uwe Hermanna69d9782010-11-15 19:35:14 +0000237 /*
238 * TEST7 configuration register (0x29)
239 * Bit 0: LD_NUM (0 = new, 1 = std SMSC)
240 */
241 test7 = pnp_read_config(dev, DEVICE_TEST7_REG);
242 test7 |= (1 << 0);
243 pnp_write_config(dev, DEVICE_TEST7_REG, test7);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000244 }
Kyösti Mälkki33eaf3a2014-06-06 21:46:47 +0300245
246 pnp_exit_conf_mode_aa(dev);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000247 }
248
249 /* Find the correct Super I/O. */
250 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
251 if (logical_device_table[i].superio_id == superio_id)
252 break;
253
254 /* If no Super I/O was found, return. */
255 if (i == ARRAY_SIZE(logical_device_table))
256 return;
257
258 /* Temporarily save the LD_FOO values. */
259 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
260 tmp[j] = pnp_dev_info[j].function;
261
Uwe Hermanna69d9782010-11-15 19:35:14 +0000262 /*
263 * Replace the LD_FOO markers in pnp_dev_info[] with
Uwe Hermann3fa13632007-07-12 13:13:56 +0000264 * the real logical device IDs of this Super I/O chip.
265 */
266 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++) {
267 fn = pnp_dev_info[j].function;
Felix Held7b7bc592019-12-15 13:53:48 +0100268 if (logical_device_table[i].devs[fn] != -1)
269 pnp_dev_info[j].function = logical_device_table[i].devs[fn];
270 else
271 pnp_dev_info[j].function = PNP_SKIP_FUNCTION;
Uwe Hermann3fa13632007-07-12 13:13:56 +0000272 }
273
274 /* Enable the specified devices (if present on the chip). */
Felix Heldb0d868e2018-07-06 23:39:00 +0200275 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Uwe Hermann3fa13632007-07-12 13:13:56 +0000276
277 /* Restore LD_FOO values. */
278 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
279 pnp_dev_info[j].function = tmp[j];
280}
281
282struct chip_operations superio_smsc_smscsuperio_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900283 .name = "Various SMSC Super I/Os",
Uwe Hermann3fa13632007-07-12 13:13:56 +0000284 .enable_dev = enable_dev
285};