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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include <arch/io.h>
#include <console/console.h>
#include <device/device.h>
#include <device/pnp.h>
#include <option.h>
#include <pc80/keyboard.h>
#include <superio/conf_mode.h>
#include <acpi/acpi.h>
#include <acpi/acpigen.h>
#include <superio/common/ssdt.h>
#include <stdlib.h>
#include "npcd378.h"
uint8_t npcd378_hwm_read(const uint16_t iobase, const uint16_t reg)
{
outb((reg >> 8) & 0xf, iobase + 0xff);
uint8_t reg8 = inb(iobase + (reg & 0xff));
if (reg8 == 0xff)
reg8 = inb(iobase + (reg & 0xff));
outb(0, iobase + 0xff);
return reg8;
}
void npcd378_hwm_write(const uint16_t iobase, const uint16_t reg, const uint8_t val)
{
outb((reg >> 8) & 0xf, iobase + 0xff);
outb(val, iobase + (reg & 0xff));
outb(0, iobase + 0xff);
}
void npcd378_hwm_write_start(const uint16_t iobase)
{
u8 reg8 = npcd378_hwm_read(iobase, NPCD837_HWM_WRITE_LOCK_CTRL);
reg8 &= ~NPCD837_HWM_WRITE_LOCK_BIT;
npcd378_hwm_write(iobase, NPCD837_HWM_WRITE_LOCK_CTRL, reg8);
}
void npcd378_hwm_write_finished(const uint16_t iobase)
{
u8 reg8 = npcd378_hwm_read(iobase, NPCD837_HWM_WRITE_LOCK_CTRL);
reg8 |= NPCD837_HWM_WRITE_LOCK_BIT;
npcd378_hwm_write(iobase, NPCD837_HWM_WRITE_LOCK_CTRL, reg8);
}
static void npcd378_init(struct device *dev)
{
struct resource *res;
if (!dev->enabled)
return;
switch (dev->path.pnp.device) {
/* TODO: Might potentially need code for FDC etc. */
case NPCD378_KBC:
pc_keyboard_init(PROBE_AUX_DEVICE);
break;
case NPCD378_HWM:
res = find_resource(dev, PNP_IDX_IO0);
if (!res || !res->base) {
printk(BIOS_ERR, "NPCD378: LDN%u IOBASE not set.\n", NPCD378_HWM);
break;
}
npcd378_hwm_write_start(res->base);
int fan_lvl = get_int_option("psu_fan_lvl", -1);
if (fan_lvl < 0 || fan_lvl > 7)
fan_lvl = 3;
uint8_t pwm = NPCD378_HWM_PSU_FAN_MIN +
(NPCD378_HWM_PSU_FAN_MAX - NPCD378_HWM_PSU_FAN_MIN) *
fan_lvl / 7;
/* Set PSU fan PWM lvl */
npcd378_hwm_write(res->base, NPCD378_HWM_PSU_FAN_PWM_CTRL, pwm);
printk(BIOS_INFO, "NPCD378: PSU fan PWM 0x%02x\n", pwm);
npcd378_hwm_write_finished(res->base);
break;
}
}
#if CONFIG(HAVE_ACPI_TABLES)
/* Provide ACPI HIDs for generic Super I/O SSDT */
static const char *npcd378_acpi_hid(const struct device *dev)
{
/* Sanity checks */
if (dev->path.type != DEVICE_PATH_PNP)
return NULL;
if (dev->path.pnp.port == 0)
return NULL;
if ((dev->path.pnp.device & 0xff) > NPCD378_GPIOA)
return NULL;
switch (dev->path.pnp.device & 0xff) {
case NPCD378_FDC:
return ACPI_HID_FDC;
case NPCD378_PP:
return ACPI_HID_LPT;
case NPCD378_SP1: /* fallthrough */
case NPCD378_SP2:
return ACPI_HID_COM;
case NPCD378_AUX:
return ACPI_HID_MOUSE;
case NPCD378_KBC:
return ACPI_HID_KEYBOARD;
default:
return ACPI_HID_PNP;
}
}
static void npcd378_ssdt_aux(const struct device *dev)
{
/* Scope */
acpigen_write_scope(acpi_device_path(dev));
acpigen_write_method("_PSW", 1);
acpigen_write_store();
acpigen_emit_byte(ARG0_OP);
acpigen_emit_namestring("^^MSFG");
acpigen_pop_len(); /* Pop Method */
acpigen_write_PRW(8, 3);
acpigen_pop_len(); /* Pop Scope */
}
static void npcd378_ssdt_kbc(const struct device *dev)
{
/* Scope */
acpigen_write_scope(acpi_device_path(dev));
acpigen_write_method("_PSW", 1);
acpigen_write_store();
acpigen_emit_byte(ARG0_OP);
acpigen_emit_namestring("^^KBFG");
acpigen_pop_len(); /* Pop Method */
acpigen_write_PRW(8, 3);
acpigen_pop_len(); /* Pop Scope */
}
static void npcd378_ssdt_pwr(const struct device *dev)
{
const char *name = acpi_device_path(dev);
const char *scope = acpi_device_scope(dev);
char *tmp_name;
/* Scope */
acpigen_write_scope(name);
acpigen_emit_ext_op(OPREGION_OP);
acpigen_emit_namestring("SWCR");
acpigen_emit_byte(SYSTEMIO);
acpigen_emit_namestring("IO0B");
acpigen_emit_namestring("IO0S");
struct fieldlist l1[] = {
FIELDLIST_OFFSET(0),
FIELDLIST_NAMESTR("LEDC", 8),
FIELDLIST_NAMESTR("SWCC", 8),
};
acpigen_write_field("SWCR", l1, ARRAY_SIZE(l1), FIELD_BYTEACC |
FIELD_NOLOCK | FIELD_PRESERVE);
acpigen_emit_ext_op(OPREGION_OP);
acpigen_emit_namestring("RNTR");
acpigen_emit_byte(SYSTEMIO);
acpigen_emit_namestring("IO1B");
acpigen_emit_namestring("IO1S");
struct fieldlist l2[] = {
FIELDLIST_OFFSET(0),
FIELDLIST_NAMESTR("GPES", 8),
FIELDLIST_NAMESTR("GPEE", 8),
FIELDLIST_OFFSET(8),
FIELDLIST_NAMESTR("GPS0", 8),
FIELDLIST_NAMESTR("GPS1", 8),
FIELDLIST_NAMESTR("GPS2", 8),
FIELDLIST_NAMESTR("GPS3", 8),
FIELDLIST_NAMESTR("GPE0", 8),
FIELDLIST_NAMESTR("GPE1", 8),
FIELDLIST_NAMESTR("GPE2", 8),
FIELDLIST_NAMESTR("GPE3", 8),
};
acpigen_write_field("RNTR", l2, ARRAY_SIZE(l2), FIELD_BYTEACC |
FIELD_NOLOCK | FIELD_PRESERVE);
/* Method (SIOW, 1, NotSerialized) */
acpigen_write_method("SIOW", 1);
acpigen_write_store();
acpigen_emit_namestring("^GPS2");
acpigen_emit_namestring("^^PMFG");
acpigen_write_store();
acpigen_emit_byte(ZERO_OP);
acpigen_emit_namestring("^GPEE");
acpigen_write_store();
acpigen_emit_byte(ZERO_OP);
acpigen_emit_namestring("^GPE0");
acpigen_write_store();
acpigen_emit_byte(ZERO_OP);
acpigen_emit_namestring("^GPE1");
acpigen_emit_byte(AND_OP);
acpigen_emit_namestring("^LEDC");
acpigen_write_integer(0xE0);
acpigen_emit_byte(LOCAL0_OP);
acpigen_emit_byte(OR_OP);
acpigen_emit_byte(LOCAL0_OP);
acpigen_write_integer(0x1E);
acpigen_emit_namestring("^LEDC");
acpigen_emit_byte(AND_OP);
acpigen_emit_namestring("^SWCC");
acpigen_write_integer(0xBF);
acpigen_emit_namestring("^SWCC");
acpigen_pop_len(); /* SIOW method */
/* Method (SIOS, 1, NotSerialized) */
acpigen_write_method("SIOS", 1);
acpigen_write_if();
acpigen_emit_byte(LNOT_OP);
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_byte(ARG0_OP);
acpigen_write_integer(5);
acpigen_write_if();
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_namestring("^^KBFG");
acpigen_emit_byte(ONE_OP);
acpigen_emit_byte(OR_OP);
acpigen_emit_namestring("^GPE2");
acpigen_write_integer(0xE8);
acpigen_emit_namestring("^GPE2");
acpigen_write_else();
acpigen_emit_byte(AND_OP);
acpigen_emit_namestring("^GPE2");
acpigen_write_integer(0x17);
acpigen_emit_namestring("^GPE2");
acpigen_pop_len(); /* Pop Else */
acpigen_write_if();
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_namestring("^^MSFG");
acpigen_emit_byte(ONE_OP);
acpigen_emit_byte(OR_OP);
acpigen_emit_namestring("^GPE2");
acpigen_write_integer(0x10);
acpigen_emit_namestring("^GPE2");
acpigen_write_else();
acpigen_emit_byte(AND_OP);
acpigen_emit_namestring("^GPE2");
acpigen_write_integer(0xEF);
acpigen_emit_namestring("^GPE2");
acpigen_pop_len(); /* Pop Else */
/* Enable wake on GPE */
acpigen_write_store();
acpigen_emit_byte(ONE_OP);
acpigen_emit_namestring("^GPEE");
acpigen_write_if();
acpigen_emit_byte(LEQUAL_OP);
acpigen_emit_byte(ARG0_OP);
acpigen_write_integer(3);
acpigen_emit_byte(AND_OP);
acpigen_emit_namestring("^LEDC");
acpigen_write_integer(0xE0);
acpigen_emit_byte(LOCAL0_OP);
acpigen_emit_byte(OR_OP);
acpigen_emit_byte(LOCAL0_OP);
acpigen_write_integer(0x1C);
acpigen_emit_namestring("^LEDC");
acpigen_emit_byte(AND_OP);
acpigen_emit_namestring("^SWCC");
acpigen_write_integer(0xBF);
acpigen_emit_byte(LOCAL0_OP);
acpigen_emit_byte(OR_OP);
acpigen_emit_byte(LOCAL0_OP);
acpigen_write_integer(0x40);
acpigen_emit_namestring("^SWCC");
acpigen_pop_len(); /* Pop If */
acpigen_pop_len(); /* Pop If */
acpigen_write_store();
acpigen_write_integer(0x10);
acpigen_emit_namestring("^GPE0");
acpigen_write_store();
acpigen_write_integer(0x20);
acpigen_emit_namestring("^GPE1");
acpigen_pop_len(); /* Pop SIOS method */
acpigen_pop_len(); /* Pop Scope */
/* Inject into parent: */
if (!scope) {
printk(BIOS_ERR, "%s: Missing ACPI path/scope\n", dev_path(dev));
return;
}
acpigen_write_scope(scope);
acpigen_write_name_integer("MSFG", 1);
acpigen_write_name_integer("KBFG", 1);
acpigen_write_name_integer("PMFG", 0);
/* DSDT must call SIOW on _WAK */
/* Method (SIOW, 1, NotSerialized) */
acpigen_write_method("SIOW", 1);
acpigen_emit_byte(RETURN_OP);
tmp_name = strconcat(name, ".SIOW");
acpigen_emit_namestring(tmp_name);
free(tmp_name);
acpigen_emit_byte(ARG0_OP);
acpigen_pop_len();
/* DSDT must call SIOS on _PTS */
/* Method (SIOS, 1, NotSerialized) */
acpigen_write_method("SIOS", 1);
acpigen_emit_byte(RETURN_OP);
tmp_name = strconcat(name, ".SIOS");
acpigen_emit_namestring(tmp_name);
free(tmp_name);
acpigen_emit_byte(ARG0_OP);
acpigen_pop_len(); /* Pop Method */
acpigen_pop_len(); /* Scope */
acpigen_write_scope("\\_GPE");
/* Method (SIOH, 0, NotSerialized) */
acpigen_write_method("_L08", 0);
acpigen_emit_byte(AND_OP);
tmp_name = strconcat(scope, ".PMFG");
acpigen_emit_namestring(tmp_name);
free(tmp_name);
acpigen_write_integer(0xE8);
acpigen_emit_byte(LOCAL0_OP);
acpigen_write_if();
acpigen_emit_byte(LGREATER_OP);
acpigen_emit_byte(LOCAL0_OP);
acpigen_emit_byte(ZERO_OP);
acpigen_emit_byte(NOTIFY_OP);
tmp_name = strconcat(scope, ".L060");
acpigen_emit_namestring(tmp_name);
free(tmp_name);
acpigen_write_integer(2);
acpigen_pop_len(); /* Pop If */
acpigen_emit_byte(AND_OP);
tmp_name = strconcat(scope, ".PMFG");
acpigen_emit_namestring(tmp_name);
free(tmp_name);
acpigen_write_integer(0x10);
acpigen_emit_byte(LOCAL0_OP);
acpigen_write_if();
acpigen_emit_byte(LGREATER_OP);
acpigen_emit_byte(LOCAL0_OP);
acpigen_emit_byte(ZERO_OP);
acpigen_emit_byte(NOTIFY_OP);
tmp_name = strconcat(scope, ".L050");
acpigen_emit_namestring(tmp_name);
free(tmp_name);
acpigen_write_integer(2);
acpigen_pop_len(); /* Pop If */
acpigen_pop_len(); /* Pop Method */
acpigen_pop_len(); /* Scope */
}
static void npcd378_fill_ssdt_generator(const struct device *dev)
{
if (!dev)
return;
superio_common_fill_ssdt_generator(dev);
switch (dev->path.pnp.device) {
case NPCD378_PWR:
npcd378_ssdt_pwr(dev);
break;
case NPCD378_AUX:
npcd378_ssdt_aux(dev);
break;
case NPCD378_KBC:
npcd378_ssdt_kbc(dev);
break;
}
}
#endif
static struct device_operations ops = {
.read_resources = pnp_read_resources,
.set_resources = pnp_set_resources,
.enable_resources = pnp_enable_resources,
.enable = pnp_alt_enable,
.init = npcd378_init,
.ops_pnp_mode = &pnp_conf_mode_8787_aa,
#if CONFIG(HAVE_ACPI_TABLES)
.acpi_fill_ssdt = npcd378_fill_ssdt_generator,
.acpi_name = superio_common_ldn_acpi_name,
.acpi_hid = npcd378_acpi_hid,
#endif
};
static struct pnp_info pnp_dev_info[] = {
{ NULL, NPCD378_FDC, PNP_IO0|PNP_IRQ0|PNP_DRQ0, 0x0ff8, },
{ NULL, NPCD378_PP, PNP_IO0|PNP_IRQ0|PNP_DRQ0, 0x0ff8, },
{ NULL, NPCD378_SP1, PNP_IO0|PNP_IRQ0, 0x0ff8, },
{ NULL, NPC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able_dev(struct device *dev)
{
pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
}
struct chip_operations superio_nuvoton_npcd378_ops = {
CHIP_NAME("NUVOTON NPCD378 Super I/O")
.enable_dev = enable_dev,
};
|