1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#include <arch/io.h>
38#include <device/device.h>
39#include <device/pnp.h>
40#include <console/console.h>
41#include <uart8250.h>
42#include <pc80/keyboard.h>
43#include <stdlib.h>
44#include "chip.h"
45
46
47#define LPC47M172 0x14
48#define FDC37B80X 0x42
49#define FDC37B78X 0x44
50#define FDC37B72X 0x4c
51#define FDC37M81X 0x4d
52#define FDC37M60X 0x47
53#define LPC47B27X 0x51
54#define LPC47U33X 0x54
55#define LPC47M10X 0x59
56#define LPC47M15X 0x60
57#define LPC47S45X 0x62
58#define LPC47B397 0x6f
59#define A8000 0x77
60#define DME1737 0x78
61#define SCH3112 0x7c
62#define SCH5307 0x81
63#define SCH5027D 0x89
64
65
66#define DEVICE_ID_REG 0x20
67#define DEVICE_REV_REG 0x21
68#define DEVICE_TEST7_REG 0x29
69
70
71static int first_time = 1;
72static uint8_t superio_id = 0;
73static uint8_t superio_rev = 0;
74
75
76
77
78
79
80
81
82
83enum {
84 LD_FDC,
85 LD_PP,
86 LD_SP1,
87 LD_SP2,
88 LD_RTC,
89 LD_KBC,
90 LD_AUX,
91 LD_XBUS,
92 LD_HWM,
93 LD_GAME,
94 LD_PME,
95 LD_MPU401,
96 LD_RT,
97 LD_ACPI,
98 LD_SMB,
99};
100
101
102#define MAX_LOGICAL_DEVICES 15
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118static const struct logical_devices {
119 uint8_t superio_id;
120 int devs[MAX_LOGICAL_DEVICES];
121} logical_device_table[] = {
122
123 {LPC47M172,{0, 3, 4, 2, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
124 {FDC37B80X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
125 {FDC37B78X,{0, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
126 {FDC37B72X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, 10, -1}},
127 {FDC37M81X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
128 {FDC37M60X,{0, 3, 4, 5, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1}},
129 {LPC47B27X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, -1, 11, 10, -1, -1}},
130 {LPC47M10X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
131 {LPC47M15X,{0, 3, 4, 5, -1, 7, -1, -1, -1, 9, 10, 11, -1, -1, -1}},
132 {LPC47S45X,{0, 3, 4, 5, 6, 7, -1, 8, -1, -1, -1, -1, 10, -1, 11}},
133 {LPC47B397,{0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
134 {LPC47U33X,{0, 3, 4, -1, -1, 7, -1, -1, -1, 9, 0, 5, 10, 0, 11}},
135 {A8000, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
136 {DME1737, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
137 {SCH3112, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, -1}},
138 {SCH5307, {0, 3, 4, 5, -1, 7, -1, -1, 8, -1, -1, -1, 10, -1, -1}},
139 {SCH5027D, {0, 3, 4, 5, -1, 7, -1, -1, -1, -1, -1, -1, 10, -1, 11}},
140};
141
142
143
144
145
146
147
148
149
150
151static inline void smsc_pnp_enter_conf_state(device_t dev)
152{
153 outb(0x55, dev->path.pnp.port);
154}
155
156
157
158
159
160
161
162
163static inline void smsc_pnp_exit_conf_state(device_t dev)
164{
165 outb(0xaa, dev->path.pnp.port);
166}
167
168
169static void smsc_pnp_set_resources(device_t dev)
170{
171 smsc_pnp_enter_conf_state(dev);
172 pnp_set_resources(dev);
173 smsc_pnp_exit_conf_state(dev);
174}
175
176
177static void smsc_pnp_enable_resources(device_t dev)
178{
179 smsc_pnp_enter_conf_state(dev);
180 pnp_enable_resources(dev);
181 smsc_pnp_exit_conf_state(dev);
182}
183
184
185
186
187
188
189
190static void smsc_pnp_enable(device_t dev)
191{
192 smsc_pnp_enter_conf_state(dev);
193 pnp_set_logical_device(dev);
194 (dev->enabled) ? pnp_set_enable(dev, 1) : pnp_set_enable(dev, 0);
195 smsc_pnp_exit_conf_state(dev);
196}
197
198
199
200
201
202
203static void smsc_init(device_t dev)
204{
205 struct superio_smsc_smscsuperio_config *conf = dev->chip_info;
206 struct resource *res0, *res1;
207 int i, ld;
208
209
210 if (!dev->enabled)
211 return;
212
213
214 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
215 if (logical_device_table[i].superio_id == superio_id)
216 break;
217
218
219 if (i == ARRAY_SIZE(logical_device_table))
220 return;
221
222
223 ld = dev->path.pnp.device;
224 if (ld == logical_device_table[i].devs[LD_SP1]) {
225 res0 = find_resource(dev, PNP_IDX_IO0);
226 init_uart8250(res0->base, &conf->com1);
227 } else if (ld == logical_device_table[i].devs[LD_SP2]) {
228 res0 = find_resource(dev, PNP_IDX_IO0);
229 init_uart8250(res0->base, &conf->com2);
230 } else if (ld == logical_device_table[i].devs[LD_KBC]) {
231 res0 = find_resource(dev, PNP_IDX_IO0);
232 res1 = find_resource(dev, PNP_IDX_IO1);
233 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
234 }
235}
236
237
238static struct device_operations ops = {
239 .read_resources = pnp_read_resources,
240 .set_resources = smsc_pnp_set_resources,
241 .enable_resources = smsc_pnp_enable_resources,
242 .enable = smsc_pnp_enable,
243 .init = smsc_init,
244};
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262static struct pnp_info pnp_dev_info[] = {
263 { &ops, LD_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0 }, },
264 { &ops, LD_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0 }, },
265 { &ops, LD_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
266 { &ops, LD_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
267 { &ops, LD_RTC, },
268 { &ops, LD_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 },
269 { 0x7ff, 4 },},
270 { &ops, LD_AUX, },
271 { &ops, LD_XBUS, },
272 { &ops, LD_HWM, PNP_IO0, { 0x7f0, 0 }, },
273 { &ops, LD_GAME, },
274 { &ops, LD_PME, },
275 { &ops, LD_MPU401, },
276 { &ops, LD_RT, PNP_IO0, { 0x780, 0 }, },
277 { &ops, LD_ACPI, },
278 { &ops, LD_SMB, },
279};
280
281
282
283
284
285
286
287
288
289
290static void enable_dev(device_t dev)
291{
292 int i, j, fn;
293 int tmp[MAX_LOGICAL_DEVICES];
294 uint8_t test7;
295
296 if (first_time) {
297
298 smsc_pnp_enter_conf_state(dev);
299 superio_id = pnp_read_config(dev, DEVICE_ID_REG);
300 superio_rev = pnp_read_config(dev, DEVICE_REV_REG);
301 smsc_pnp_exit_conf_state(dev);
302
303
304
305 printk_info("Found SMSC Super I/O (ID=0x%02x, rev=0x%02x)\n",
306 superio_id, superio_rev);
307 first_time = 0;
308
309 if(superio_id == LPC47M172) {
310
311
312
313
314
315
316
317 test7 = pnp_read_config(dev, DEVICE_TEST7_REG);
318 test7 |= 1;
319 pnp_write_config(dev, DEVICE_TEST7_REG, test7);
320 }
321 }
322
323
324 for (i = 0; i < ARRAY_SIZE(logical_device_table); i++)
325 if (logical_device_table[i].superio_id == superio_id)
326 break;
327
328
329 if (i == ARRAY_SIZE(logical_device_table))
330 return;
331
332
333 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
334 tmp[j] = pnp_dev_info[j].function;
335
336
337
338
339 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++) {
340 fn = pnp_dev_info[j].function;
341 pnp_dev_info[j].function = logical_device_table[i].devs[fn];
342 }
343
344
345 pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info),
346 &pnp_dev_info);
347
348
349 for (j = 0; j < ARRAY_SIZE(pnp_dev_info); j++)
350 pnp_dev_info[j].function = tmp[j];
351}
352
353struct chip_operations superio_smsc_smscsuperio_ops = {
354 CHIP_NAME("Various SMSC Super I/Os")
355 .enable_dev = enable_dev
356};
357