summaryrefslogtreecommitdiff
path: root/src/superio/smsc/sch5545/acpi/resource_helpers.asl
blob: 818f47053435aa080cc288f6dd3d539f9ca56b48 (plain)
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
/* SPDX-License-Identifier: GPL-2.0-only */

/* Helper package for determining IO, DMA, IRQ location according to LDN */
Name (DCAT, Package (0x10) {
	0x07,	/* UARTA */
	0x08,	/* UARTB */
	0x11,	/* LPT */
	0x0B,	/* Floppy */
	0xFF,
	0xFF,
	0xFF,
	0xFF,
	0xFF,
	0xFF,
	One,	/* KBC */
	0xFF,
	0xFF,
	0xFF,
	One,	/* KBC */
	0xFF
})

Method (CGLD, 1, NotSerialized)
{
	Return (DerefOf (DCAT [Arg0]))
}

/* Return Parallel port mode*/
Method (LPTM, 1, NotSerialized)
{
	ENTER_CONFIG_MODE (CGLD (Arg0))
	Local0 = (OPT0 & 0x02)
	EXIT_CONFIG_MODE ()
	Return (Local0)
}

/* Device Status */
Method (DSTA, 1, NotSerialized)
{
	ENTER_CONFIG_MODE (CGLD (Arg0))
	Local0 = PNP_DEVICE_ACTIVE
	If (Local0 == 0xFF)
	{
		Return (Zero)
	}

	Local0 &= One
	If (Arg0 < 0x10)
	{
		IOST |= (Local0 << Arg0)
	}

	If (Local0)
	{
		Return (DEVICE_PRESENT_ACTIVE)
	}
	ElseIf ((One << Arg0) & IOST)
	{
		Return (DEVICE_PRESENT_INACTIVE)
	}
	Else
	{
		Return (Zero)
	}

	EXIT_CONFIG_MODE ()
}

Method (DCNT, 2, NotSerialized)
{
	ENTER_CONFIG_MODE (CGLD (Arg0))
	PNP_DEVICE_ACTIVE = Arg1
	EXIT_CONFIG_MODE ()
}

/* Resource templates for SIO LDNs */
Name (CRS1, ResourceTemplate ()
{
	IO (Decode16,
		0x0000,
		0x0000,
		0x01,
		0x00,
		_Y16)
	IRQ (Edge, ActiveHigh, Exclusive, _Y14) {}
	DMA (Compatibility, NotBusMaster, Transfer8, _Y15) {}
})

CreateWordField (CRS1, \_SB.PCI0.LPCB.SIO1._Y14._INT, IRQM)
CreateByteField (CRS1, \_SB.PCI0.LPCB.SIO1._Y15._DMA, DMAM)
CreateWordField (CRS1, \_SB.PCI0.LPCB.SIO1._Y16._MIN, IO11)
CreateWordField (CRS1, \_SB.PCI0.LPCB.SIO1._Y16._MAX, IO12)
CreateByteField (CRS1, \_SB.PCI0.LPCB.SIO1._Y16._LEN, LEN1)

Name (CRS2, ResourceTemplate ()
{
	IO (Decode16,
		0x0000,
		0x0000,
		0x01,
		0x00,
		_Y19)
	IO (Decode16,
		0x0000,
		0x0000,
		0x01,
		0x00,
		_Y1A)
	IRQ (Edge, ActiveHigh, Exclusive, _Y17) {}
	DMA (Compatibility, NotBusMaster, Transfer8, _Y18) {}
})

CreateWordField (CRS2, \_SB.PCI0.LPCB.SIO1._Y17._INT, IRQE)
CreateByteField (CRS2, \_SB.PCI0.LPCB.SIO1._Y18._DMA, DMAE)
CreateWordField (CRS2, \_SB.PCI0.LPCB.SIO1._Y19._MIN, IO21)
CreateWordField (CRS2, \_SB.PCI0.LPCB.SIO1._Y19._MAX, IO22)
CreateByteField (CRS2, \_SB.PCI0.LPCB.SIO1._Y19._LEN, LEN2)
CreateWordField (CRS2, \_SB.PCI0.LPCB.SIO1._Y1A._MIN, IO31)
CreateWordField (CRS2, \_SB.PCI0.LPCB.SIO1._Y1A._MAX, IO32)
CreateByteField (CRS2, \_SB.PCI0.LPCB.SIO1._Y1A._LEN, LEN3)

/* Read IO resource */
Method (GIOB, 1, NotSerialized)
{
	If (CGLD (Arg0) == 0x07)	/* UARTA */
	{
		SWITCH_LDN (SUPERIO_LPC_LDN)
		Local0 = (CR6B << 0x08)
		Local0 |= CR6A
		Return (Local0)
	}

	If (CGLD (Arg0) == 0x08)	/* UARTB */
	{
		SWITCH_LDN (SUPERIO_LPC_LDN)
		Local0 = (CR6F << 0x08)
		Local0 |= CR6E
		Return (Local0)
	}

	If (CGLD (Arg0) == 0x11)	/* LPT */
	{
		SWITCH_LDN (SUPERIO_LPC_LDN)
		Local0 = (CR83 << 0x08)
		Local0 |= CR82
		Return (Local0)
	}

	If (CGLD (Arg0) == 0x0B)	/* Floppy */
	{
		SWITCH_LDN (SUPERIO_LPC_LDN)
		Local0 = (CR7F << 0x08)
		Local0 |= CR7E
		Return (Local0)
	}

	Return (Zero)
}

/* Read IRQ resource */
Method (GIRQ, 1, NotSerialized)
{
	SWITCH_LDN (SUPERIO_LPC_LDN)
	Local0 = 0x0F	/* 15 IRQ regs, 1 for each IRQ number */
	While (Local0)
	{
		Local1 = (0x40 + Local0) /* IRQ regs begin at offset 0x40 */
		PNP_ADDR_REG = Local1
		Local1 = PNP_DATA_REG
		If (CGLD (Arg0) == Local1)
		{
			Local1 = One
			Local0 = (Local1 << Local0)
			Return (Local0)
		}

		Local0--
	}

	Return (0xFF)
}

/* Read DMA resource */
Method (GDMA, 1, NotSerialized)
{
	SWITCH_LDN (SUPERIO_LPC_LDN)
	Local0 = 0x03	/* Only DMA Channels 0-3 */
	While (Local0)
	{
		Local1 = (Local0 << One)
		Local1 += 0x51	/* DMA regs begin at offset 0x50 */
		PNP_ADDR_REG = Local1
		Local1 = PNP_DATA_REG
		If ((0x80 | CGLD (Arg0)) == Local1)
		{
			Local1 = One
			Local0 = (Local1 << Local0)
			Return (Local0)
		}

		Local0--
	}

	Return (0xFF)
}

/* Set IO resource */
Method (STIO, 2, NotSerialized)
{
	SWITCH_LDN (SUPERIO_LPC_LDN)
	Local0 = (Arg1 & 0xFF)
	PNP_ADDR_REG = Arg0
	PNP_DATA_REG = Local0
	Local0 = (Arg1 >> 0x08)
	Local1 = (Arg0 + One)
	PNP_ADDR_REG = Local1
	PNP_DATA_REG = Local0
}

/* Set IRQ resource */
Method (SIRQ, 2, NotSerialized)
{
	SWITCH_LDN (SUPERIO_LPC_LDN)
	FindSetRightBit (Arg1, Local0)
	Local0 -= One
	Local1 = 0x0F
	While (Local1)
	{
		Local2 = (0x40 + Local1)
		PNP_ADDR_REG = Local2
		Local3 = PNP_DATA_REG
		If (CGLD (Arg0) == Local3)
		{
			If (Local0 != Local1)
			{
				PNP_ADDR_REG = Local2
				PNP_DATA_REG = 0xFF
				Break
			}
			Else
			{
				Return (Zero)
			}
		}

		Local1--
	}

	Local0 += 0x40
	PNP_ADDR_REG = Local0
	PNP_DATA_REG = CGLD (Arg0)
	Return (0xFF)
}

/* Set DMA resource */
Method (SDMA, 2, NotSerialized)
{
	SWITCH_LDN (SUPERIO_LPC_LDN)
	FindSetRightBit (Arg1, Local0)
	Local0 -= One
	Local1 = 0x03
	While (Local1)
	{
		Local2 = (Local1 << One)
		Local3 = (0x51 + Local2)
		PNP_ADDR_REG = Local3
		Local4 = PNP_DATA_REG
		If ((0x80 | CGLD (Arg0)) == Local4)
		{
			If (Local0 != Local1)
			{
				PNP_ADDR_REG = Local3
				PNP_DATA_REG = Zero
				Break
			}
			Else
			{
				Return (Zero)
			}
		}

		Local1--
	}

	Local0 <<= One
	Local0 += 0x51
	PNP_ADDR_REG = Local0
	PNP_DATA_REG = (0x80 | CGLD (Arg0))
	Return (Zero)
}

/* Device Current Resource Settings */
Method (DCRS, 2, NotSerialized)
{
	If (CGLD (Arg0) == 0x07)	/* UARTA resources */
	{
		ENTER_CONFIG_MODE (SUPERIO_LPC_LDN)
		IO11 = GIOB (Arg0)
		IO12 = IO11
		LEN1 = 0x08
		IRQM = GIRQ (Arg0)
		If ((GDMA (Arg0) > 0x03) || (Arg1 == Zero))
		{
			DMAM = Zero
		}
		Else
		{
			DMAM = GDMA (Arg0)
		}

		EXIT_CONFIG_MODE ()
		Return (CRS1)
	}

	If (CGLD (Arg0) == 0x08)	/* UARTB resources */
	{
		ENTER_CONFIG_MODE (SUPERIO_LPC_LDN)
		IO11 = GIOB (Arg0)
		IO12 = IO11
		LEN1 = 0x08
		IRQM = GIRQ (Arg0)
		If ((GDMA (Arg0) > 0x03) || (Arg1 == Zero))
		{
			DMAM = Zero
		}
		Else
		{
			DMAM = GDMA (Arg0)
		}

		EXIT_CONFIG_MODE ()
		Return (CRS1)
	}

	If (CGLD (Arg0) == 0x11)	/* LPT resources */
	{
		If (LPTM (Arg0))
		{
			ENTER_CONFIG_MODE (SUPERIO_LPC_LDN)
			IO21 = GIOB (Arg0)
			IO22 = IO21
			IO31 = (IO21 + 0x0400)
			IO32 = IO31
			If ((IO21 & 0xFF) == 0xBC)
			{
				LEN2 = 0x04
				LEN3 = 0x04
			}
			Else
			{
				LEN2 = 0x08
				LEN3 = 0x04
			}

			IRQE = GIRQ (Arg0)
			If ((GDMA (Arg0) > 0x03) || (Arg1 == Zero))
			{
				DMAM = Zero
			}
			Else
			{
				DMAE = GDMA (Arg0)
			}

			EXIT_CONFIG_MODE ()
			Return (CRS2) /* \_SB_.PCI0.LPCB.SIO1.CRS2 */
		}
		Else
		{
			ENTER_CONFIG_MODE (SUPERIO_LPC_LDN)
			IO11 = GIOB (Arg0)
			IO12 = IO11 /* \_SB_.PCI0.LPCB.SIO1.IO11 */
			If ((IO11 & 0xFF) == 0xBC)
			{
				LEN1 = 0x04
			}
			Else
			{
				LEN1 = 0x08
			}

			IRQM = GIRQ (Arg0)
			EXIT_CONFIG_MODE ()
			Return (CRS1) /* \_SB_.PCI0.LPCB.SIO1.CRS1 */
		}
	}

	If (CGLD (Arg0) == 0x0B)	/* Floppy resources */
	{
		ENTER_CONFIG_MODE (SUPERIO_LPC_LDN)
		IO21 = GIOB (Arg0)
		IO22 = IO21 /* \_SB_.PCI0.LPCB.SIO1.IO21 */
		LEN2 = 0x06
		IO31 = (IO21 + 0x07)
		IO32 = IO31 /* \_SB_.PCI0.LPCB.SIO1.IO31 */
		LEN3 = One
		IRQE = GIRQ (Arg0)
		If ((GDMA (Arg0) > 0x03) || (Arg1 == Zero))
		{
			DMAM = Zero
		}
		Else
		{
			DMAE = GDMA (Arg0)
		}

		EXIT_CONFIG_MODE ()
		Return (CRS2) /* \_SB_.PCI0.LPCB.SIO1.CRS2 */
	}

	Return (CRS1) /* \_SB_.PCI0.LPCB.SIO1.CRS1 */
}