1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2016 Intel Corporation
4 */
5
6/* Include in each PCIe Root Port device */
7
8/* lowest D-state supported by
9 * PCIe root port during S0 state
10 */
11Name (_S0W, 4)
12
13Name (PDST, 0) /* present Detect status */
14
15/* Dynamic Opregion needed to access registers
16 * when the controller is in D3 cold
17 */
18OperationRegion (PX01, PCI_Config, 0x00, 0xFF)
19Field (PX01, AnyAcc, NoLock, Preserve)
20{
21	Offset(0x5A),
22	, 6,
23	PDS, 1,		/* 6, Presence detect Change */
24	Offset(0xE2),	/* RPPGEN - Root Port Power Gating Enable */
25	, 2,
26	L23E, 1,	/* 2, L23_Rdy Entry Request (L23ER) */
27	L23R, 1,	/* 3, L23_Rdy to Detect Transition (L23R2DT) */
28	Offset(0xF4),	/* BLKPLLEN */
29	, 10,
30	BPLL, 1,
31}
32
33OperationRegion (PX02, PCI_Config, 0x338, 0x4)
34Field (PX02, AnyAcc, NoLock, Preserve)
35{
36	, 26,
37	BDQA, 1		/* BLKDQDA */
38}
39
40PowerResource (PXP, 0, 0)
41{
42	/* Define the PowerResource for PCIe slot */
43	Method (_STA, 0, Serialized)
44	{
45		Store (PDS, PDST)
46		If (LEqual (PDS, 1)) {
47			Return (0xf)
48		} Else {
49			Return (0)
50		}
51	}
52
53	Method (_ON, 0, Serialized)
54	{
55		If (LAnd (LEqual (PDST, 1), LNotEqual (\PRT0, 0))) {
56			/* Enter this condition if device
57			 * is connected
58			 */
59
60			/* De-assert PERST */
61			\_SB.PCI0.PRDA (\PRT0)
62
63			Store (0, BDQA) /* Set BLKDQDA to 0 */
64			Store (0, BPLL) /* Set BLKPLLEN to 0 */
65
66			/* Set L23_Rdy to Detect Transition
67			 * (L23R2DT)
68			 */
69			Store (1, L23R)
70			Sleep (16)
71			Store (0, Local0)
72
73			/* Delay for transition Detect
74			 * and link to train
75			 */
76			While (L23R) {
77				If (Lgreater (Local0, 4)) {
78					Break
79				}
80				Sleep (16)
81				Increment (Local0)
82			}
83		} /* End PDS condition check */
84	}
85
86	Method (_OFF, 0, Serialized)
87	{
88		/* Set L23_Rdy Entry Request (L23ER) */
89		If (LAnd (LEqual (PDST, 1), LNotEqual (\PRT0, 0))) {
90			/* enter this condition if device
91			 * is connected
92			 */
93			Store (1, L23E)
94			Sleep (16)
95			Store (0, Local0)
96			While (L23E) {
97				If (Lgreater (Local0, 4)) {
98					Break
99				}
100				Sleep (16)
101				Increment (Local0)
102			}
103			Store (1, BDQA) /* Set BLKDQDA to 1 */
104			Store (1, BPLL) /* Set BLKPLLEN to 1 */
105
106			/* Assert PERST */
107			\_SB.PCI0.PRAS (\PRT0)
108		} /* End PDS condition check */
109	} /* End of Method_OFF */
110} /* End PXP */
111
112Name(_PR0, Package() { PXP })
113Name(_PR3, Package() { PXP })
114