ddac22e4aa455ce4836b354fda35195dc646a7fb
[coreboot.git] / src / superio / winbond / w83627hf / devtree.asl
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 Christoph Grenz <christophg+cb@grenz-bonn.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; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /*
21  * include this file into a mainboard's DSDT _SB device tree and it will expose the
22  * W83627HF SuperIO and its functionality.
23  *
24  * Devices are marked as nonexistant if they got 0x00000000 as I/O base address
25  * (compatibility with legacy bios, which disables logical devices that way)
26  *
27  * It allows the change of IO ports, IRQs and DMA settings on most logical
28  * devices, disabling and reenabling logical devices and controlling power
29  * saving mode on logical devices or the whole chip.
30  *
31  * Notes:
32  * - ECP mode of parallel port not implemented, DMA settings of parallel port
33  *   will be reset on DSDT init
34  * - Hardware monitor is only shown as "Motherboard Resource", shows no real
35  *   functionality
36  *
37  * Controllable through preprocessor macros:
38  * NO_W83627HF_FDC:      don't expose the floppy disk controller
39  * NO_W83627HF_FDC_ENUM: don't try to enumerate the connected floppy drives
40  * NO_W83627HF_PPORT:    don't expose the parallel port
41  * NO_W83627HF_UARTA:    don't expose the first serial port
42  * NO_W83627HF_UARTB:    don't expose the second serial port (already hidden
43  *                       if UARTB is configured as IRDA port by firmware)
44  * NO_W83627HF_IRDA:     don't expose the IRDA port (already hidden if UARTB is
45  *                       configured as serial port by firmware)
46  * NO_W83627HF_CIR:      don't expose the Consumer Infrared functionality
47  * NO_W83627HF_KBC:      don't expose the keyboard controller
48  * NO_W83627HF_PS2M:     don't expose the PS/2 mouse functionality of the
49  *                       keyboard controller
50  * NO_W83627HF_GAME:     don't expose the game port
51  * NO_W83627HF_MIDI:     don't expose the MIDI port
52  * NO_W83627HF_HWMON:    don't expose the hardware monitor as
53  *                       PnP "Motherboard Ressource"
54  *
55  * Datasheet: "W83627HF/F WINBOND I/O" rev. 6.0
56  * http://www.itox.com/pages/support/wdt/W83627HF.pdf
57  */
58
59 Device(SIO) {
60         Name (_HID, EisaId("PNP0A05"))
61         Name (_STR, Unicode("Winbond W83627HF SuperIO"))
62         Name (_UID, "w83627hf")
63
64         /* Mutex for accesses to the configuration ports (prolog and epilog commands are used, so synchronization is useful) */
65         Mutex(CRMX, 1)
66
67         /* SuperIO configuration ports */
68         OperationRegion (CREG, SystemIO, 0x2E, 0x02)
69         Field (CREG, ByteAcc, NoLock, Preserve)
70         {
71                 ADDR,   8,
72                 DATA,   8
73         }
74         IndexField (ADDR, DATA, ByteAcc, NoLock, Preserve)
75         {
76                 Offset (0x02),
77                 RST,    1,     /* Soft reset */
78                 ,       7,
79                 Offset (0x07),
80                 LDN,    8,     /* Logical device selector */
81                 Offset (0x20),
82                 DID,    8,     /* Device ID */
83                 DREV,   8,     /* Device Revision */
84                 FDPW,   1,     /* FDC Power Down */
85                 ,       2,
86                 PRPW,   1,     /* PRT Power Down */
87                 UAPW,   1,     /* UART A Power Down */
88                 UBPW,   1,     /* UART B Power Down */
89                 HWPW,   1,     /* HWM Power Down */
90                 ,       1,
91                 IPD,    1,     /* Immediate Chip Power Down */
92                 ,       7,
93                 PNPS,   1,     /* PnP Address Select Register Default Value Mode */
94                 ,       1,
95                 KBCR,   1,     /* KBC enabled after system reset (read-only) */
96                 ,       3,
97                 CLKS,   1,     /* Clock select */
98                 AQ16,   1,     /* 16bit Address Qualification */
99                 FDCT,   1,     /* Tristate FDC (?) */
100                 ,       2,
101                 PRTT,   1,     /* Tristate parallel port (?) */
102                 URAT,   1,     /* Tristate UART A (?) */
103                 URBT,   1,     /* Tristate UART B (?) */
104                 ,       2,
105                 URAI,   1,     /* UART A Legacy IRQ Select Disable */
106                 URBI,   1,     /* UART B Legacy IRQ Select Disable */
107                 PRTI,   1,     /* Parallel Port Legacy IRQ/DRQ Select Disable */
108                 FDCI,   1,     /* FDC Legacy IRQ/DRQ Select Disable */
109                 ,       1,
110                 LCKC,   1,     /* Lock Configuration Registers */
111                 Offset (0x29),
112                 IO3S,   8,     /* GPIO3 pin selection register */
113                 ACTR,   1,     /* Logical device activation */
114                 ACT1,   1,     /* Logical part activation 1 (mostly unused) */
115                 ACT2,   1,     /* Logical part activation 2 (mostly unused) */
116                 ,       5,
117                 Offset (0x60),
118                 IO1H,   8,      /* First I/O port base - high byte */
119                 IO1L,   8,      /* First I/O port base - low byte */
120                 IO2H,   8,      /* Second I/O port base - high byte */
121                 IO2L,   8,      /* Second I/O port base - low byte */
122                 Offset (0x70),
123                 IRQ0,   8,      /* First IRQ */
124                 Offset (0x72),
125                 IRQ1,   8,      /* First IRQ */
126                 Offset (0x74),
127                 DMA0,   8,      /* DMA */
128                 Offset (0xE0),
129                 /* CRE0-CRE4: function logical device dependant, seems to be reserved for ACPI settings */
130                 CRE0,   8,
131                 CRE1,   8,
132                 CRE2,   8,
133                 CRE3,   8,
134                 CRE4,   8,
135                 Offset (0xF0),
136                 /* OPT1-OPTA aka CRF0-CRF9: function logical device dependant */
137                 OPT1,   8,
138                 OPT2,   8,
139                 OPT3,   8,
140                 OPT4,   8,
141                 OPT5,   8,
142                 OPT6,   8,
143                 OPT7,   8,
144                 OPT8,   8,
145                 OPT9,   8,
146                 OPTA,   8
147         }
148
149         Name (_CRS, ResourceTemplate () {
150                 IO (Decode16, 0x002E, 0x002E, 0x02, 0x01) /* Announce the used I/O ports to the OS */
151                 IO (Decode16, 0x004E, 0x004E, 0x01, 0x01) /* this port is used in some configurations, so announce it to be sure */
152         })
153
154         /* Enter configuration mode (and aquire mutex)
155            Method must be run before accesssing the configuration region.
156         */
157         Method (ENCM)
158         {
159                 Acquire (CRMX, 0xFFFF)
160                 Store (0x87, ADDR)
161                 Store (0x87, ADDR)
162         }
163
164         /* Exit configuration mode (and release mutex)
165            Method must be run after accessing the configuration region.
166         */
167         Method (EXCM)
168         {
169                 Release (CRMX)
170                 Store (0xAA, ADDR)
171         }
172
173         /* PM: indicate IPD (Immediate Power Down) bit state as D0/D2 */
174         Method (_PSC) {
175                 ENCM ()
176                 Store (IPD, Local0)
177                 EXCM ()
178                 If (Local0) { Return (2) }
179                 Else { Return (0) }
180         }
181
182         /* PM: Switch to D0 by setting IPD low  */
183         Method (_PS0) {
184                 ENCM ()
185                 Store (Zero, IPD)
186                 EXCM ()
187         }
188
189         /* PM: Switch to D2 by setting IPD high  */
190         Method (_PS2) {
191                 ENCM ()
192                 Store (One, IPD)
193                 EXCM ()
194         }
195
196         #ifndef NO_W83627HF_FDC
197         /* =================== Floppy Disk Controller ================ */
198         Device (FDC0) {
199                 Name (_HID, EisaId ("PNP0700"))
200                 Name (_STR, Unicode ("W83627HF Floppy Disk Controller"))
201                 Name (_UID, "w83627hf-fdc")
202
203                 #ifndef NO_W83627HF_FDC_ENUM
204                 /* Initialization method: Should be run once on boot
205                    If FDC is active, enumerate all connected devices */
206                 Method (_INI) {
207                         ENCM ()
208                         Store (0x00, LDN)
209                         Store (ACTR, Local0)
210                         Store (IO1H, Local1)
211                         Store (IO1L, Local2)
212                         EXCM ()
213                         ShiftLeft(Local1, 8, Local1)
214                         Or(Local1, Local2, Local1)
215                         If (Local0) {
216                                 /* Try probing drives and save result in _FDE */
217                                 PROB(Local1)
218                         }
219                 }
220                 #endif
221
222                 Method (_STA)
223                 {
224                         Store (0x00, Local0)
225                         ENCM ()
226                         Store (0x00, LDN)
227                         If (ACTR) {
228                                 Store (0x0F, Local0)
229                         }
230                         ElseIf (LOr (IO1H, IO1L))
231                         {
232                                 Store (0x0D, Local0)
233                         }
234                         EXCM ()
235                         Return (Local0)
236                 }
237
238                 Method (_PSC) {
239                         Store(^^_PSC (), Local0)
240                         If (Local0) { Return (Local0) }
241                         ENCM ()
242                         Store (FDPW, Local0)
243                         EXCM ()
244                         If (Local0) { Return (1) }
245                         Else { Return (0) }
246                 }
247                 Method (_PS0) {
248                         ENCM ()
249                         Store (Zero, FDPW)
250                         EXCM ()
251                 }
252                 Method (_PS1) {
253                         ENCM ()
254                         Store (One, FDPW)
255                         EXCM ()
256                 }
257
258                 Method (_DIS)
259                 {
260                         ENCM ()
261                         Store (0x00, LDN)
262                         Store (Zero, ACTR)
263                         EXCM ()
264                 }
265
266                 Method (_CRS)
267                 {
268                         Name (CRS, ResourceTemplate () {
269                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x06, IO0)
270                                 IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01)
271                                 IRQNoFlags () {6}
272                                 DMA (Compatibility, NotBusMaster, Transfer8) {2}
273                         })
274                         ENCM ()
275                         Store (0x00, LDN)
276                         Store(IO1H, Local0)
277                         Store(IO1L, Local1)
278                         EXCM ()
279                         ShiftLeft(Local1, 8, Local1)
280                         Or (Local1, Local0, Local0)
281
282                         CreateWordField (CRS, IO0._MIN, IMIN)
283                         Store (Local0, IMIN)
284                         CreateWordField (CRS, IO0._MAX, IMAX)
285                         Store (Local0, IMAX)
286
287                         Return (CRS)
288                 }
289
290                 Name (_PRS, ResourceTemplate ()
291                 {
292                         StartDependentFnNoPri ()
293                         {
294                                 IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06)
295                                 IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01)
296                                 IRQNoFlags () {6}
297                                 DMA (Compatibility, NotBusMaster, Transfer8) {2}
298                         }
299                         EndDependentFn ()
300                 })
301
302                 #ifndef NO_W83627HF_FDC_ENUM
303                 Name(_FDE, Buffer(){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
304                 #endif
305
306                 Method (PROB, 1) {
307                         #ifndef NO_W83627HF_FDC_ENUM
308                         /* Try probing drives and save result in _FDE
309                            Probing is done through selecting and activating a drive
310                            and reading 0x03F7 aka the "shared IDE and floppy register"
311                            as any value there besides zero seems to indicate a
312                            connected drive.
313                         */
314                         OperationRegion (FIO1, SystemIO, Arg0, 0x06)
315                         Field (FIO1, ByteAcc, NoLock, Preserve)
316                         {
317                                 Offset(0x02),
318                                 SELE,  2,
319                                 RSTL,  1,
320                                 IDMA,  1,
321                                 ACT1,  1,
322                                 ACT2,  1,
323                                 ACT3,  1,
324                                 ACT4,  1,
325                                 Offset(0x04),
326                                 BSY1,  1,
327                                 BSY2,  1,
328                                 BSY3,  1,
329                                 BSY4,  1,
330                                 BUSY,  1,
331                                 NDMA,  1,
332                                 IODI,  1,
333                                 RDY,   1,
334                                 DATA,  8,
335                         }
336                         OperationRegion (FIO2, SystemIO, 0x3F7, 0x01)
337
338                         CreateByteField (_FDE, 3, FD1)
339                         CreateByteField (_FDE, 7, FD2)
340                         CreateByteField (_FDE, 11, FD3)
341                         CreateByteField (_FDE, 15, FD4)
342
343                         Store(One, ACT1)
344                         Store(0, SELE)
345                         Sleep(0x64)
346                         If (FIO2) { Store (One, FD1) }
347
348                         Store(Zero, ACT1)
349                         Store(One, ACT2)
350                         Store(1, SELE)
351                         Sleep(0x64)
352                         If (FIO2) { Store (One, FD2) }
353
354                         Store(Zero, ACT2)
355                         Store(One, ACT3)
356                         Store(2, SELE)
357                         Sleep(0x64)
358                         If (FIO2) { Store (One, FD3) }
359
360                         Store(Zero, ACT3)
361                         Store(One, ACT4)
362                         Store(3, SELE)
363                         Sleep(0x64)
364                         If (FIO2) { Store (One, FD4) }
365                         Store(Zero, ACT4)
366                         Store(Zero, SELE)
367                         #endif
368                 }
369
370
371                 Method (_SRS, 1, Serialized)
372                 {
373                         Name (TMPL, ResourceTemplate () {
374                                 IO (Decode16, 0, 0, 1, 6, IO0)
375                                 IO (Decode16, 0, 0, 1, 1, IO1)
376                                 IRQNoFlags (IRQ0) {}
377                                 DMA (Compatibility, NotBusMaster, Transfer8, DMA0) {}
378                         })
379                         CreateWordField (Arg0, IO0._MIN, IOA0)
380                         CreateWordField (Arg0, IO1._MIN, IOA1)
381                         CreateByteField (Arg0, IRQ0._INT, IRQL)
382                         CreateByteField (Arg0, DMA0._DMA, DMCH)
383
384                         Divide(IOA0, 256, Local0, Local1)
385                         ShiftRight(Local1, 8, Local1)
386
387                         ENCM ()
388                         Store (0, LDN)
389                         Store (Local1, IO1H)
390                         Store (Local0, IO1L)
391                         Store (One, ACTR)
392                         EXCM ()
393
394                         /* Try probing drives and save result in _FDE */
395                         PROB(IOA0)
396                 }
397         }
398         #endif
399
400         #ifndef NO_W83627HF_PPORT
401         /* ======================== Parallel Port ======================== */
402         /* Currently no ECP support */
403         Device (PAR0) {
404                 Name (_HID, EisaId ("PNP0400"))
405                 Name (_DDN, "LPT1")
406                 Name (_UID, "w83627hf-pport")
407
408                 Method (MODE, 1) {
409                         And(Arg0, 0x07, Local0)
410                         ENCM ()
411                         Store (0x01, LDN)
412                         And(OPT1, 0x3, Local1)
413                         Or(Local1, Local0, OPT1)
414                         EXCM()
415                 }
416
417                 Method (_INI)
418                 {
419                         /* Deactivate DMA, even if set by BIOS. We don't announce it
420                            through _CRS and it's only useful in ECP mode which we
421                            don't support at the moment. */
422                         ENCM ()
423                         Store (0x01, LDN)
424                         Store (0x04, DMA0)
425                         EXCM ()
426                 }
427
428                 Method (_STA)
429                 {
430                         Store (0x00, Local0)
431                         ENCM ()
432                         Store (0x01, LDN)
433                         And(OPT1, 0x3, Local1)
434                         If (ACTR) {
435                                 If (LNotEqual(Local1, 2)) {
436                                         Store (0x0D, Local0)
437                                 } Else {
438                                         Store (0x0D, Local0)
439                                 }
440                         }
441                         ElseIf (LOr (IO1H, IO1L))
442                         {
443                                 Store (0x0D, Local0)
444                         }
445                         EXCM ()
446                         Return (Local0)
447                 }
448
449                 Method (_PSC) {
450                         Store(^^_PSC (), Local0)
451                         If (Local0) { Return (Local0) }
452                         ENCM ()
453                         Store (PRPW, Local0)
454                         EXCM ()
455                         If (Local0) { Return (1) }
456                         Else { Return (0) }
457                 }
458                 Method (_PS0) {
459                         ENCM ()
460                         Store (Zero, PRPW)
461                         EXCM ()
462                 }
463                 Method (_PS1) {
464                         ENCM ()
465                         Store (One, PRPW)
466                         EXCM ()
467                 }
468
469                 Method (_DIS) {
470                         ENCM ()
471                         Store (0x01, LDN)
472                         Store (Zero, ACTR)
473                         EXCM ()
474                 }
475
476                 Method (_CRS)
477                 {
478                         Name (CRS, ResourceTemplate ()
479                         {
480                                 IO (Decode16, 0x0000, 0x0000, 0x04, 0x08, IO0)
481                                 IRQNoFlags (IRQX) {}
482                         })
483                         CreateWordField (CRS, IO0._MIN, IOP0)
484                         CreateWordField (CRS, IO0._MAX, IOR0)
485                         CreateByteField (CRS, IO0._ALN, IOAL)
486                         CreateByteField (CRS, IO0._LEN, IOLE)
487                         CreateWordField (CRS, IRQX._INT, IRQW)
488
489                         ENCM ()
490                         Store (0x01, LDN)
491                         Store (IO1L, Local0)
492                         Store (IO1H, Local1)
493                         Store (OPT1, Local2)
494                         Store (IRQ0, Local5)
495                         EXCM ()
496                         ShiftLeft(Local1, 8, Local1)
497                         Or (Local1, Local0, Local1)
498
499                         And(Local2, 0x3, Local3)
500                         And(Local2, 0x4, Local4)
501                         If (Local4) {
502                                 Store(0x04, IOAL)
503                         }
504
505                         Store(Local1, IOP0)
506                         Store(Local1, IOR0)
507
508                         If (LEqual (Local0, 0xBC))
509                         {
510                                 Store (0x04, IOLE)
511                         }
512                         Else
513                         {
514                                 Store (0x08, IOLE)
515                         }
516
517                         Store (One, Local0)
518                         ShiftLeft (Local0, Local5, IRQW)
519
520                         Return (CRS)
521                 }
522
523                 Name (_PRS, ResourceTemplate ()
524                 {
525                         StartDependentFn (0,1)
526                         {
527                                 IO (Decode16, 0x0378, 0x0378, 0x04, 0x08)
528                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
529                         }
530                         StartDependentFn (0,1)
531                         {
532                                 IO (Decode16, 0x0278, 0x0278, 0x04, 0x08)
533                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
534                         }
535                         StartDependentFn (0,1)
536                         {
537                                 IO (Decode16, 0x03BC, 0x03BC, 0x04, 0x04)
538                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
539                         }
540                         StartDependentFn (0,0)
541                         {
542                                 IO (Decode16, 0x0378, 0x0378, 0x08, 0x08)
543                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
544                         }
545                         StartDependentFn (0,0)
546                         {
547                                 IO (Decode16, 0x0278, 0x0278, 0x08, 0x08)
548                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
549                         }
550                         StartDependentFn (2,0)
551                         {
552                                 IO (Decode16, 0x0100, 0x0FFC, 0x08, 0x08)
553                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
554                         }
555                         StartDependentFn (2,1)
556                         {
557                                 IO (Decode16, 0x0100, 0x0FFC, 0x04, 0x08)
558                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
559                         }
560                         EndDependentFn ()
561                 })
562
563                 Method (_SRS, 1, Serialized)
564                 {
565                         Name (TMPL, ResourceTemplate () {
566                                 IO (Decode16, 0, 0, 4, 4, IO0)
567                                 IRQNoFlags (IRQX) {}
568                         })
569                         CreateWordField (Arg0, IO0._MIN, IOA0)
570                         CreateWordField (Arg0, IO0._MIN, IOA1)
571                         CreateByteField (Arg0, IO0._ALN, IOAL)
572                         CreateByteField (Arg0, IO0._LEN, IOLE)
573                         CreateWordField (Arg0, IRQX._INT, IRQL)
574
575                         If (LEqual(IOAL, 4)) {
576                                 Store(0x0, Local2)
577                         } else  {
578                                 Store(0x1, Local2)
579                         }
580
581                         Divide(IOA0, 256, Local0, Local1)
582                         ShiftRight(Local1, 8, Local1)
583
584                         ENCM ()
585                         Store (0x01, LDN)
586                         Store (Local1, IO1H)
587                         Store (Local0, IO1L)
588                         /*Mode*/
589                         Store (OPT1, Local3)
590                         And (Local3, 0xF8, Local3)
591                         Or (Local2, Local3, OPT1)
592                         /*DMA off*/
593                         Store (0x04, DMA0)
594                         /*IRQ*/
595                         FindSetLeftBit (IRQL, Local3)
596                         Subtract (Local3, 0x01, Local3)
597                         Store (Local3, IRQ0)
598                         /*Activate*/
599                         Store (One, ACTR)
600                         EXCM ()
601                 }
602         }
603         #endif
604
605         #ifndef NO_W83627HF_UARTA
606         /* =========================== UART A ============================ */
607         Device (SER0) {
608                 Name (_HID, EisaId ("PNP0501"))
609                 Name (_UID, "w83627hf-uarta")
610                 Name (_DDN, "COM1")
611
612                 Method (_STA)
613                 {
614                         Store (0x00, Local0)
615                         ENCM ()
616                         Store (0x02, LDN)
617                         If (ACTR) {
618                                 Store (0x0F, Local0)
619                         }
620                         ElseIf (LOr (IO1H, IO1L))
621                         {
622                                 Store (0x0D, Local0)
623                         }
624                         EXCM ()
625                         Return (Local0)
626                 }
627
628                 Method (_PSC) {
629                         Store(^^_PSC (), Local0)
630                         If (Local0) { Return (Local0) }
631                         ENCM ()
632                         Store (UAPW, Local0)
633                         EXCM ()
634                         If (Local0) { Return (1) }
635                         Else { Return (0) }
636                 }
637                 Method (_PS0) {
638                         ENCM ()
639                         Store (Zero, UAPW)
640                         EXCM ()
641                 }
642                 Method (_PS1) {
643                         ENCM ()
644                         Store (One, UAPW)
645                         EXCM ()
646                 }
647
648                 Method (_DIS)
649                 {
650                         ENCM ()
651                         Store (0x02, LDN)
652                         Store (Zero, ACTR)
653                         EXCM ()
654                 }
655
656                 Method (_CRS)
657                 {
658                         Name (CRS, ResourceTemplate () {
659                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x08, IO0)
660                                 IRQNoFlags (IRQX) {6}
661                         })
662                         ENCM ()
663                         Store (0x02, LDN)
664                         Store(IO1H, Local1)
665                         Store(IO1L, Local0)
666                         Store(IRQ0, Local2)
667                         EXCM ()
668                         ShiftLeft(Local1, 8, Local1)
669                         Or (Local1, Local0, Local0)
670
671                         CreateWordField (CRS, IO0._MIN, IMIN)
672                         Store (Local0, IMIN)
673                         CreateWordField (CRS, IO0._MAX, IMAX)
674                         Store (Local0, IMAX)
675
676                         CreateWordField (CRS, IRQX._INT, IRQW)
677                         Store (One, Local3)
678                         ShiftLeft (Local3, Local2, IRQW)
679
680                         Return (CRS)
681                 }
682
683                 Name (_PRS, ResourceTemplate ()
684                 {
685                         StartDependentFn (0,0) {
686                                 IO (Decode16, 0x03F8, 0x03F8, 0x08, 0x08)
687                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
688                         }
689                         StartDependentFn (0,0) {
690                                 IO (Decode16, 0x02F8, 0x02F8, 0x08, 0x08)
691                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
692                         }
693                         StartDependentFn (1,0) {
694                                 IO (Decode16, 0x03E8, 0x03E8, 0x08, 0x08)
695                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
696                         }
697                         StartDependentFn (1,0) {
698                                 IO (Decode16, 0x02E8, 0x02E8, 0x08, 0x08)
699                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
700                         }
701                         StartDependentFn (2,0) {
702                                 IO (Decode16, 0x0100, 0x0FF8, 0x08, 0x08)
703                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
704                         }
705                         EndDependentFn()
706                 })
707
708                 Method (_SRS, 1, Serialized)
709                 {
710                         Name (TMPL, ResourceTemplate () {
711                                 IO (Decode16, 0, 0, 1, 6, IO0)
712                                 IRQNoFlags (IRQX) {}
713                         })
714                         CreateWordField (Arg0, IO0._MIN, IOA0)
715                         CreateByteField (Arg0, IRQX._INT, IRQL)
716
717                         Divide(IOA0, 256, Local0, Local1)
718                         ShiftRight(Local1, 8, Local1)
719
720                         FindSetLeftBit (IRQL, Local3)
721                         Subtract (Local3, 0x01, Local3)
722
723                         ENCM ()
724                         Store (2, LDN)
725                         Store (Local1, IO1H)
726                         Store (Local0, IO1L)
727                         Store (Local3, IRQ0)
728                         Store (One, ACTR)
729                         EXCM ()
730                 }
731         }
732         #endif
733
734         #ifndef NO_W83627HF_UARTB
735         /* =========================== UART B ============================ */
736         Device (SER1) {
737                 Name (_HID, EisaId ("PNP0501"))
738                 Name (_UID, "w83627hf-uartb")
739                 Name (_DDN, "COM2")
740
741                 Method (_STA)
742                 {
743                         Store (0x00, Local0)
744                         ENCM ()
745                         Store (0x03, LDN)
746                         If (LNot(And(OPT2, 0x30)))
747                         {
748                                 If (ACTR) {
749                                         Store (0x0F, Local0)
750                                 }
751                                 ElseIf (LOr (IO1H, IO1L))
752                                 {
753                                         Store (0x0D, Local0)
754                                 }
755                         }
756                         EXCM ()
757                         Return (Local0)
758                 }
759
760                 Method (_PSC) {
761                         Store(^^_PSC (), Local0)
762                         If (Local0) { Return (Local0) }
763                         ENCM ()
764                         Store (UBPW, Local0)
765                         EXCM ()
766                         If (Local0) { Return (1) }
767                         Else { Return (0) }
768                 }
769                 Method (_PS0) {
770                         ENCM ()
771                         Store (Zero, UBPW)
772                         EXCM ()
773                 }
774                 Method (_PS1) {
775                         ENCM ()
776                         Store (One, UBPW)
777                         EXCM ()
778                 }
779
780                 Method (_DIS)
781                 {
782                         ENCM ()
783                         Store (0x03, LDN)
784                         Store (Zero, ACTR)
785                         EXCM ()
786                 }
787
788                 Method (_CRS)
789                 {
790                         Name (CRS, ResourceTemplate () {
791                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x08, IO0)
792                                 IRQNoFlags (IRQX) {6}
793                         })
794                         ENCM ()
795                         Store (0x03, LDN)
796                         Store(IO1H, Local1)
797                         Store(IO1L, Local0)
798                         Store(IRQ0, Local2)
799                         EXCM ()
800                         ShiftLeft(Local1, 8, Local1)
801                         Or (Local1, Local0, Local0)
802
803                         CreateWordField (CRS, IO0._MIN, IMIN)
804                         Store (Local0, IMIN)
805                         CreateWordField (CRS, IO0._MAX, IMAX)
806                         Store (Local0, IMAX)
807
808                         CreateWordField (CRS, IRQX._INT, IRQW)
809                         Store (One, Local3)
810                         ShiftLeft (Local3, Local2, IRQW)
811
812                         Return (CRS)
813                 }
814
815                 Name (_PRS, ResourceTemplate ()
816                 {
817                         StartDependentFn (0,0) {
818                                 IO (Decode16, 0x02F8, 0x02F8, 0x08, 0x08)
819                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
820                         }
821                         StartDependentFn (0,0) {
822                                 IO (Decode16, 0x03F8, 0x03F8, 0x08, 0x08)
823                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
824                         }
825                         StartDependentFn (1,0) {
826                                 IO (Decode16, 0x03E8, 0x03E8, 0x08, 0x08)
827                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
828                         }
829                         StartDependentFn (1,0) {
830                                 IO (Decode16, 0x02E8, 0x02E8, 0x08, 0x08)
831                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
832                         }
833                         StartDependentFn (2,0) {
834                                 IO (Decode16, 0x0100, 0x0FF8, 0x08, 0x08)
835                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
836                         }
837                         EndDependentFn()
838                 })
839
840                 Method (_SRS, 1, Serialized)
841                 {
842                         Name (TMPL, ResourceTemplate () {
843                                 IO (Decode16, 0, 0, 1, 8, IO0)
844                                 IRQNoFlags (IRQX) {}
845                         })
846                         CreateWordField (Arg0, IO0._MIN, IOA0)
847                         CreateByteField (Arg0, IRQX._INT, IRQL)
848
849                         Divide(IOA0, 256, Local0, Local1)
850                         ShiftRight(Local1, 8, Local1)
851
852                         FindSetLeftBit (IRQL, Local3)
853                         Subtract (Local3, 0x01, Local3)
854
855                         ENCM ()
856                         Store (3, LDN)
857                         Store (Local1, IO1H)
858                         Store (Local0, IO1L)
859                         Store (Local3, IRQ0)
860                         Store (One, ACTR)
861                         EXCM ()
862                 }
863         }
864         #endif
865
866         #ifndef NO_W83627HF_IRDA
867         /* ======================== UART B (IRDA) ======================== */
868         Device (IRDA) {
869                 Name (_HID, EisaId ("PNP0510"))
870                 Name (_UID, "w83627hf-irda")
871                 Name (_STR, Unicode("IrDA Port"))
872
873                 Method (_STA)
874                 {
875                         Store (0x00, Local0)
876                         ENCM ()
877                         Store (0x03, LDN)
878                         If (And(OPT2, 0x30))
879                         {
880                                 If (ACTR) {
881                                         Store (0x0F, Local0)
882                                 }
883                                 ElseIf (LOr (IO1H, IO1L))
884                                 {
885                                         Store (0x0D, Local0)
886                                 }
887                         }
888                         EXCM ()
889                         Return (Local0)
890                 }
891
892                 Method (_PSC) {
893                         Store(^^_PSC (), Local0)
894                         If (Local0) { Return (Local0) }
895                         ENCM ()
896                         Store (UBPW, Local0)
897                         EXCM ()
898                         If (Local0) { Return (1) }
899                         Else { Return (0) }
900                 }
901                 Method (_PS0) {
902                         ENCM ()
903                         Store (Zero, UBPW)
904                         EXCM ()
905                 }
906                 Method (_PS1) {
907                         ENCM ()
908                         Store (One, UBPW)
909                         EXCM ()
910                 }
911
912                 Method (_DIS)
913                 {
914                         ENCM ()
915                         Store (0x03, LDN)
916                         Store (Zero, ACTR)
917                         EXCM ()
918                 }
919
920                 Method (_CRS)
921                 {
922                         Name (CRS, ResourceTemplate () {
923                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x08, IO0)
924                                 IRQNoFlags (IRQX) {6}
925                         })
926                         ENCM ()
927                         Store (0x03, LDN)
928                         Store(IO1H, Local1)
929                         Store(IO1L, Local0)
930                         Store(IRQ0, Local2)
931                         EXCM ()
932                         ShiftLeft(Local1, 8, Local1)
933                         Or (Local1, Local0, Local0)
934
935                         CreateWordField (CRS, IO0._MIN, IMIN)
936                         Store (Local0, IMIN)
937                         CreateWordField (CRS, IO0._MAX, IMAX)
938                         Store (Local0, IMAX)
939
940                         CreateWordField (CRS, IRQX._INT, IRQW)
941                         Store (One, Local3)
942                         ShiftLeft (Local3, Local2, IRQW)
943
944                         Return (CRS)
945                 }
946
947                 Name (_PRS, ResourceTemplate ()
948                 {
949                         StartDependentFn (0,0) {
950                                 IO (Decode16, 0x02F8, 0x02F8, 0x08, 0x08)
951                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
952                         }
953                         StartDependentFn (1,0) {
954                                 IO (Decode16, 0x03F8, 0x03F8, 0x08, 0x08)
955                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
956                         }
957                         StartDependentFn (0,0) {
958                                 IO (Decode16, 0x03E8, 0x03E8, 0x08, 0x08)
959                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
960                         }
961                         StartDependentFn (0,0) {
962                                 IO (Decode16, 0x02E8, 0x02E8, 0x08, 0x08)
963                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
964                         }
965                         StartDependentFn (2,0) {
966                                 IO (Decode16, 0x0100, 0x0FF8, 0x08, 0x08)
967                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
968                         }
969                         EndDependentFn()
970                 })
971
972                 Method (_SRS, 1, Serialized)
973                 {
974                         Name (TMPL, ResourceTemplate () {
975                                 IO (Decode16, 0, 0, 1, 8, IO0)
976                                 IRQNoFlags (IRQX) {}
977                         })
978                         CreateWordField (Arg0, IO0._MIN, IOA0)
979                         CreateByteField (Arg0, IRQX._INT, IRQL)
980
981                         Divide(IOA0, 256, Local0, Local1)
982                         ShiftRight(Local1, 8, Local1)
983
984                         FindSetLeftBit (IRQL, Local3)
985                         Subtract (Local3, 0x01, Local3)
986
987                         ENCM ()
988                         Store (3, LDN)
989                         Store (Local1, IO1H)
990                         Store (Local0, IO1L)
991                         Store (Local3, IRQ0)
992                         Store (One, ACTR)
993                         EXCM ()
994                 }
995         }
996         #endif
997
998         #ifndef NO_W83627HF_CIR
999         /* ========================= Consumer IR ========================= */
1000         Device (CIR0) {
1001                 Name (_HID, EisaId ("WEC1022")) /* Should be the correct one */
1002                 Name (_UID, "w83627hf-cir")
1003                 Name (_STR, Unicode("Winbond Consumer Infrared Transceiver"))
1004
1005                 Method (_STA)
1006                 {
1007                         Store (0x00, Local0)
1008                         ENCM ()
1009                         Store (0x06, LDN)
1010                         If (ACTR) {
1011                                 Store (0x0F, Local0)
1012                         }
1013                         ElseIf (LOr (IO1H, IO1L))
1014                         {
1015                                 Store (0x0D, Local0)
1016                         }
1017                         EXCM ()
1018                         Return (Local0)
1019                 }
1020
1021                 Method (_DIS)
1022                 {
1023                         ENCM ()
1024                         Store (0x06, LDN)
1025                         Store (Zero, ACTR)
1026                         EXCM ()
1027                 }
1028
1029                 Method (_CRS)
1030                 {
1031                         Name (CRS, ResourceTemplate () {
1032                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x08, IO0)
1033                                 IRQNoFlags (IRQX) {6}
1034                         })
1035                         ENCM ()
1036                         Store (0x03, LDN)
1037                         Store(IO1H, Local1)
1038                         Store(IO1L, Local0)
1039                         Store(IRQ0, Local2)
1040                         EXCM ()
1041                         ShiftLeft(Local1, 8, Local1)
1042                         Or (Local1, Local0, Local0)
1043
1044                         CreateWordField (CRS, IO0._MIN, IMIN)
1045                         Store (Local0, IMIN)
1046                         CreateWordField (CRS, IO0._MAX, IMAX)
1047                         Store (Local0, IMAX)
1048
1049                         CreateWordField (CRS, IRQX._INT, IRQW)
1050                         Store (One, Local3)
1051                         ShiftLeft (Local3, Local2, IRQW)
1052
1053                         Return (CRS)
1054                 }
1055
1056                 Name (_PRS, ResourceTemplate ()
1057                 {
1058                         StartDependentFn (0,0) {
1059                                 IO (Decode16, 0x0100, 0x0FF8, 0x08, 0x08)
1060                                 IRQNoFlags () {3,4,5,7,9,10,11,12}
1061                         }
1062                         EndDependentFn()
1063                 })
1064
1065                 Method (_SRS, 1, Serialized)
1066                 {
1067                         Name (TMPL, ResourceTemplate () {
1068                                 IO (Decode16, 0, 0, 1, 8, IO0)
1069                                 IRQNoFlags (IRQX) {}
1070                         })
1071                         CreateWordField (Arg0, IO0._MIN, IOA0)
1072                         CreateByteField (Arg0, IRQX._INT, IRQL)
1073
1074                         Divide(IOA0, 256, Local0, Local1)
1075                         ShiftRight(Local1, 8, Local1)
1076
1077                         FindSetLeftBit (IRQL, Local3)
1078                         Subtract (Local3, 0x01, Local3)
1079
1080                         ENCM ()
1081                         Store (6, LDN)
1082                         Store (Local1, IO1H)
1083                         Store (Local0, IO1L)
1084                         Store (Local3, IRQ0)
1085                         Store (One, ACTR)
1086                         EXCM ()
1087                 }
1088         }
1089         #endif
1090
1091         #ifndef NO_W83627HF_KBC
1092         /* ===================== Keyboard Controller ===================== */
1093         Device (KBD0) {
1094                 Name (_HID, EisaId ("PNP0303"))
1095                 Name (_CID, 0x0B03D041)
1096                 Name (_UID, "w83627hf-kbc")
1097
1098                 Method (_STA)
1099                 {
1100                         Store (0x00, Local0)
1101                         ENCM ()
1102                         Store (0x05, LDN)
1103                         If (ACTR) {
1104                                 Store (0x0F, Local0)
1105                         }
1106                         ElseIf (Lor(LOr (IO1H, IO1L), LOr (IO2H, IO2L)))
1107                         {
1108                                 Store (0x0D, Local0)
1109                         }
1110                         EXCM ()
1111                         Return (Local0)
1112                 }
1113
1114                 Method (_DIS)
1115                 {
1116                         ENCM ()
1117                         Store (0x05, LDN)
1118                         Store (Zero, ACTR)
1119                         EXCM ()
1120                         Notify(PS2M, 1)
1121                 }
1122
1123                 Method (_CRS)
1124                 {
1125                         Name (CRS, ResourceTemplate () {
1126                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x01, IO0)
1127                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x01, IO1)
1128                                 IRQNoFlags (IRQX) {}
1129                         })
1130                         ENCM ()
1131                         Store (0x05, LDN)
1132                         Store(IO1H, Local0)
1133                         Store(IO1L, Local1)
1134                         Store(IO2H, Local2)
1135                         Store(IO2L, Local3)
1136                         Store(IRQ0, Local4)
1137                         EXCM ()
1138                         ShiftLeft(Local0, 8, Local0)
1139                         Or (Local1, Local0, Local0)
1140
1141                         ShiftLeft(Local2, 8, Local2)
1142                         Or (Local1, Local0, Local0)
1143
1144                         CreateWordField (CRS, IO0._MIN, IMIN)
1145                         Store (Local0, IMIN)
1146                         CreateWordField (CRS, IO0._MAX, IMAX)
1147                         Store (Local0, IMAX)
1148
1149                         CreateWordField (CRS, IO1._MIN, I1MI)
1150                         Store (Local2, I1MI)
1151                         CreateWordField (CRS, IO1._MAX, I1MA)
1152                         Store (Local2, I1MA)
1153
1154                         CreateWordField (CRS, IRQX._INT, IRQW)
1155                         Store (One, Local5)
1156                         ShiftLeft (Local5, Local4, IRQW)
1157
1158                         Return (CRS)
1159                 }
1160
1161                 Name (_PRS, ResourceTemplate ()
1162                 {
1163                         StartDependentFn (0,0) {
1164                                 IO (Decode16, 0x0060, 0x0060, 0x01, 0x01)
1165                                 IO (Decode16, 0x0064, 0x0064, 0x01, 0x01)
1166                                 IRQNoFlags () {1}
1167                         }
1168                         EndDependentFn()
1169                 })
1170
1171                 Method (_SRS, 1, Serialized)
1172                 {
1173                         Name (TMPL, ResourceTemplate () {
1174                                 IO (Decode16, 0, 0, 1, 1, IO0)
1175                                 IO (Decode16, 0, 0, 1, 1, IO1)
1176                                 IRQNoFlags (IRQX) {}
1177                         })
1178                         CreateWordField (Arg0, IO0._MIN, IOA0)
1179                         CreateWordField (Arg0, IO1._MIN, IOA1)
1180                         CreateByteField (Arg0, IRQX._INT, IRQL)
1181
1182                         Divide(IOA0, 256, Local0, Local1)
1183                         ShiftRight(Local1, 8, Local1)
1184
1185                         Divide(IOA1, 256, Local2, Local3)
1186                         ShiftRight(Local1, 8, Local1)
1187
1188                         FindSetLeftBit (IRQL, Local4)
1189                         Subtract (Local4, 0x01, Local4)
1190
1191                         ENCM ()
1192                         Store (5, LDN)
1193                         Store (Local1, IO1H)
1194                         Store (Local0, IO1L)
1195                         Store (Local3, IO2H)
1196                         Store (Local2, IO2L)
1197                         Store (Local3, IRQ0)
1198                         Store (One, ACTR)
1199                         EXCM ()
1200                 }
1201         }
1202         #ifndef NO_W83627HF_PS2M
1203         Device (PS2M) {
1204                 Name (_HID, EisaId ("PNP0F13"))
1205                 Name (_UID, "w83627hf-ps2m")
1206
1207                 Method (_STA)
1208                 {
1209                         Store (0x00, Local0)
1210                         ENCM ()
1211                         Store (0x05, LDN)
1212                         If (LAnd(ACTR, IRQ1) ) {
1213                                 Store (0x0F, Local0)
1214                         }
1215                         ElseIf (Lor(LOr (IO1H, IO1L), LOr (IO2H, IO2L)))
1216                         {
1217                                 Store (0x0D, Local0)
1218                         }
1219                         EXCM ()
1220                         Return (Local0)
1221                 }
1222
1223                 Method (_DIS)
1224                 {
1225                         ENCM ()
1226                         Store (0x05, LDN)
1227                         Store (Zero, IRQ1)
1228                         EXCM ()
1229                 }
1230
1231                 Method (_CRS)
1232                 {
1233                         Name (CRS, ResourceTemplate () {
1234                                 IRQNoFlags (IRQX) {}
1235                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x01, IO0)
1236                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x01, IO1)
1237                         })
1238                         ENCM ()
1239                         Store (0x05, LDN)
1240                         Store(IO1H, Local0)
1241                         Store(IO1L, Local1)
1242                         Store(IO2H, Local2)
1243                         Store(IO2L, Local3)
1244                         Store(IRQ1, Local4)
1245                         EXCM ()
1246                         ShiftLeft(Local0, 8, Local0)
1247                         Or (Local1, Local0, Local0)
1248
1249                         ShiftLeft(Local2, 8, Local2)
1250                         Or (Local1, Local0, Local0)
1251
1252                         CreateWordField (CRS, IO0._MIN, IMIN)
1253                         Store (Local0, IMIN)
1254                         CreateWordField (CRS, IO0._MAX, IMAX)
1255                         Store (Local0, IMAX)
1256
1257                         CreateWordField (CRS, IO1._MIN, I1MI)
1258                         Store (Local2, I1MI)
1259                         CreateWordField (CRS, IO1._MAX, I1MA)
1260                         Store (Local2, I1MA)
1261
1262                         CreateWordField (CRS, IRQX._INT, IRQW)
1263                         Store (One, Local5)
1264                         ShiftLeft (Local5, Local4, IRQW)
1265
1266                         Return (CRS)
1267                 }
1268
1269                 Name (_PRS, ResourceTemplate ()
1270                 {
1271                         StartDependentFn (0,0) {
1272                                 IRQNoFlags () {12}
1273                         }
1274                         StartDependentFn (2,0) {
1275                                 IRQNoFlags () {1,3,4,5,6,7,9,10,11,12}
1276                         }
1277                         EndDependentFn()
1278                 })
1279
1280                 Method (_SRS, 1, Serialized)
1281                 {
1282                         Name (TMPL, ResourceTemplate () {
1283                                 IRQNoFlags (IRQX) {}
1284                         })
1285                         CreateByteField (Arg0, IRQX._INT, IRQL)
1286
1287                         FindSetLeftBit (IRQL, Local0)
1288                         Subtract (Local0, 0x01, Local0)
1289
1290                         ENCM ()
1291                         Store (5, LDN)
1292                         Store (Local0, IRQ1)
1293                         /* Only activates if KBD is active */
1294                         Store (One, ACTR)
1295                         EXCM ()
1296                 }
1297         }
1298         #endif
1299         #endif
1300
1301         #ifndef NO_W83627HF_GAME
1302         /* ========================== Game Port ========================== */
1303         Device (GAME) {
1304                 Name (_HID, EisaId ("PNPB02F"))
1305                 Name (_STR, Unicode ("Joystick/Game Port"))
1306                 Name (_UID, "w83627hf-game")
1307
1308                 Method (_STA) {
1309                         ENCM ()
1310                         Store(0, Local0)
1311                         Store (0x07, LDN)
1312                         If (LOr(IO1L, IO1H)) {
1313                                 If (LOr(ACTR, ACT1)) {
1314                                         Store (0x0F, Local0)
1315                                 }
1316                                 Else {
1317                                         Store (0x0D, Local0)
1318                                 }
1319                         }
1320                         EXCM ()
1321                         Return (Local0)
1322                 }
1323
1324                 Method (_CRS)
1325                 {
1326                         Name (CRS, ResourceTemplate () {
1327                                 IO (Decode16, 0x0000, 0x0000, 0x01, 0x01, IO0)
1328                                 IRQNoFlags (IRQX) {}
1329                         })
1330                         ENCM ()
1331                         Store (0x07, LDN)
1332                         Store(IO1H, Local0)
1333                         Store(IO1L, Local1)
1334                         Store(IRQ0, Local2)
1335                         EXCM ()
1336                         ShiftLeft(Local0, 8, Local0)
1337                         Or (Local1, Local0, Local0)
1338
1339                         CreateWordField (CRS, IO0._MIN, IMIN)
1340                         Store (Local0, IMIN)
1341                         CreateWordField (CRS, IO0._MAX, IMAX)
1342                         Store (Local0, IMAX)
1343
1344                         If (Local2) {
1345                                 CreateWordField (CRS, IRQX._INT, IRQW)
1346                                 Store (One, Local3)
1347                                 ShiftLeft (Local3, Local2, IRQW)
1348                         }
1349
1350                         Return (CRS)
1351                 }
1352
1353         }
1354         #endif
1355
1356         #ifndef NO_W83627HF_MIDI
1357         /* ========================== MIDI Port ========================== */
1358         Device (MIDI) {
1359                 Name (_HID, EisaId ("PNPB006"))
1360                 Name (_STR, Unicode ("MPU-401 Compatible MIDI Port"))
1361                 Name (_UID, "w83627hf-midi")
1362
1363                 Method (_STA) {
1364                         ENCM ()
1365                         Store(0, Local0)
1366                         Store (0x07, LDN)
1367                         If (LOr(IO2L, IO2H)) {
1368                                 If (LOr(ACTR, ACT2)) {
1369                                         Store (0x0F, Local0)
1370                                 }
1371                                 Else {
1372                                         Store (0x0D, Local0)
1373                                 }
1374                         }
1375                         EXCM ()
1376                         Return (Local0)
1377                 }
1378
1379                 Method (_CRS)
1380                 {
1381                         Name (CRS, ResourceTemplate () {
1382                                 IO (Decode16, 0x0000, 0x0000, 0x02, 0x02, IO0)
1383                                 IRQNoFlags (IRQX) {}
1384                         })
1385                         ENCM ()
1386                         Store (0x07, LDN)
1387                         Store(IO2H, Local0)
1388                         Store(IO2L, Local1)
1389                         Store(IRQ1, Local2)
1390                         EXCM ()
1391                         ShiftLeft(Local0, 8, Local0)
1392                         Or (Local1, Local0, Local0)
1393
1394                         CreateWordField (CRS, IO0._MIN, IMIN)
1395                         Store (Local0, IMIN)
1396                         CreateWordField (CRS, IO0._MAX, IMAX)
1397                         Store (Local0, IMAX)
1398
1399                         If (Local2) {
1400                                 CreateWordField (CRS, IRQX._INT, IRQW)
1401                                 Store (One, Local3)
1402                                 ShiftLeft (Local3, Local2, IRQW)
1403                         }
1404
1405                         Return (CRS)
1406                 }
1407
1408         }
1409         #endif
1410
1411         /* ==== Suspend LED control if it is connected to the SuperIO ==== */
1412         Method (SLED, 1) {
1413                 ENCM ()
1414                 Store (9, LDN)
1415                 Store(OPT4, Local0)
1416                 And(Local0, 63, Local0)
1417                 Or(Local0, ShiftLeft(And(Arg0, 0x03), 6), OPT4)
1418                 EXCM ()
1419         }
1420
1421         /* ===== Power LED control if it is connected to the SuperIO ===== */
1422         Method (PLED, 1) {
1423                 ENCM ()
1424                 Store (8, LDN)
1425                 Store(OPT4, Local0)
1426                 And(Local0, 63, Local0)
1427                 Or(Local0, ShiftLeft(And(Arg0, 0x03), 6), OPT4)
1428                 EXCM ()
1429         }
1430
1431         #ifndef NO_W83627HF_HWMON
1432         /* ====================== Hardware Monitor ======================= */
1433         Device (HMON) {
1434                 Name (_HID, EisaId ("PNP0C02")) // TODO: find better matching ID
1435                 Name (_STR, Unicode("W83627 Hardware Monitor"))
1436                 Name (_UID, "w83627hf-hwmon")
1437
1438                 Method (_STA)
1439                 {
1440                         Store (0x00, Local0)
1441                         ENCM ()
1442                         Store (0x0B, LDN)
1443                         If (ACTR) {
1444                                 Store (0x0F, Local0)
1445                         }
1446                         ElseIf (LOr (IO1H, IO1L))
1447                         {
1448                                 Store (0x0D, Local0)
1449                         }
1450                         EXCM ()
1451                         Return (Local0)
1452                 }
1453
1454                 Method (_PSC) {
1455                         Store(^^_PSC (), Local0)
1456                         If (Local0) { Return (Local0) }
1457                         ENCM ()
1458                         Store (HWPW, Local0)
1459                         EXCM ()
1460                         If (Local0) { Return (1) }
1461                         Else { Return (0) }
1462                 }
1463                 Method (_PS0) {
1464                         ENCM ()
1465                         Store (Zero, HWPW)
1466                         EXCM ()
1467                 }
1468                 Method (_PS1) {
1469                         ENCM ()
1470                         Store (One, HWPW)
1471                         EXCM ()
1472                 }
1473
1474                 Method (_CRS)
1475                 {
1476                         Name (CRS, ResourceTemplate () {
1477                                 IO (Decode16, 0x0000, 0x0000, 0x08, 0x02, IO0)
1478                                 IRQNoFlags (IRQX) {}
1479                         })
1480                         ENCM ()
1481                         Store (0x0B, LDN)
1482                         Store(IO1H, Local0)
1483                         Store(IO1L, Local1)
1484                         Store(IRQ1, Local2)
1485                         EXCM ()
1486                         ShiftLeft(Local0, 8, Local0)
1487                         Or (Local1, Local0, Local0)
1488
1489                         CreateWordField (CRS, IO0._MIN, IMIN)
1490                         Store (Local0, IMIN)
1491                         CreateWordField (CRS, IO0._MAX, IMAX)
1492                         Store (Local0, IMAX)
1493
1494                         If (Local2) {
1495                                 CreateWordField (CRS, IRQX._INT, IRQW)
1496                                 Store (One, Local3)
1497                                 ShiftLeft (Local3, Local2, IRQW)
1498                         }
1499                         Return (CRS)
1500                 }
1501         }
1502         #endif
1503
1504         /* Returns the wake source register.
1505            It is cleared after reading.
1506            Bit 0: Keyboard wake-up event
1507            Bit 1: Mouse wake-up event
1508            Bit 2: Power button event
1509            Bit 3: CIR wake-up event
1510            Bit 4: Power loss event
1511            Bit 5: VSB power loss status
1512         */
1513         Method (WAKS) {
1514                 ENCM ()
1515                 Store (0x0A, LDN)
1516                 Store (CRE3, Local0)
1517                 EXCM ()
1518                 Return (Local0)
1519         }
1520 }