blob: ebf4289218e6b9a864f2d79ab97c7ecc8e1270a5 [file] [log] [blame]
Lee Leahyb0005132015-05-12 18:19:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
Lee Leahy1d14b3e2015-05-12 18:23:27 -07005 * Copyright (C) 2015 Intel Corporation.
Lee Leahyb0005132015-05-12 18:19:47 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahyb0005132015-05-12 18:19:47 -070015 */
Hannah Williams1760cd32017-04-06 20:54:11 -070016#include <soc/gpio.h>
17
18#define GPIOTXSTATE_MASK 0x1
19#define GPIORXSTATE_MASK 0x1
Lee Leahyb0005132015-05-12 18:19:47 -070020
21Device (GPIO)
22{
Archana Patniee966282015-07-04 00:56:32 +053023 Name (_HID, "INT344B")
Lee Leahyb0005132015-05-12 18:19:47 -070024 Name (_UID, 1)
Duncan Lauriec97106f2015-08-27 17:15:00 -070025 Name (_DDN, "GPIO Controller")
Lee Leahyb0005132015-05-12 18:19:47 -070026
27 Name (RBUF, ResourceTemplate()
28 {
Duncan Lauriec97106f2015-08-27 17:15:00 -070029 Memory32Fixed (ReadWrite, 0, 0, COM0)
30 Memory32Fixed (ReadWrite, 0, 0, COM1)
31 Memory32Fixed (ReadWrite, 0, 0, COM3)
32 Interrupt (ResourceConsumer, Level, ActiveLow, Shared,,, GIRQ)
33 { 0 }
Lee Leahyb0005132015-05-12 18:19:47 -070034 })
35
Duncan Lauriec97106f2015-08-27 17:15:00 -070036 Method (_CRS, 0, NotSerialized)
Lee Leahyb0005132015-05-12 18:19:47 -070037 {
Duncan Lauriec97106f2015-08-27 17:15:00 -070038 /* GPIO Community 0 */
39 CreateDWordField (^RBUF, ^COM0._BAS, BAS0)
40 CreateDWordField (^RBUF, ^COM0._LEN, LEN0)
41 Store (^^PCRB (PID_GPIOCOM0), BAS0)
42 Store (GPIO_BASE_SIZE, LEN0)
Lee Leahyb0005132015-05-12 18:19:47 -070043
Duncan Lauriec97106f2015-08-27 17:15:00 -070044 /* GPIO Community 1 */
45 CreateDWordField (^RBUF, ^COM1._BAS, BAS1)
46 CreateDWordField (^RBUF, ^COM1._LEN, LEN1)
47 Store (^^PCRB (PID_GPIOCOM1), BAS1)
48 Store (GPIO_BASE_SIZE, LEN1)
49
50 /* GPIO Community 3 */
51 CreateDWordField (^RBUF, ^COM3._BAS, BAS3)
52 CreateDWordField (^RBUF, ^COM3._LEN, LEN3)
53 Store (^^PCRB (PID_GPIOCOM3), BAS3)
54 Store (GPIO_BASE_SIZE, LEN3)
55
56 CreateDWordField (^RBUF, ^GIRQ._INT, IRQN)
Hannah Williams1760cd32017-04-06 20:54:11 -070057 And (^^PCRR (PID_GPIOCOM0, GPIO_MISCCFG),
Duncan Lauriec97106f2015-08-27 17:15:00 -070058 GPIO_DRIVER_IRQ_ROUTE_MASK, Local0)
Archana Patniee966282015-07-04 00:56:32 +053059
60 If (LEqual (Local0, GPIO_DRIVER_IRQ_ROUTE_IRQ14)) {
61 Store (GPIO_IRQ14, IRQN)
62 } Else {
63 Store (GPIO_IRQ15, IRQN)
64 }
Lee Leahyb0005132015-05-12 18:19:47 -070065
66 Return (RBUF)
67 }
68
69 Method (_STA, 0, NotSerialized)
70 {
71 Return (0xF)
72 }
Lee Leahyb0005132015-05-12 18:19:47 -070073}
Subrata Banikfbc46092015-12-07 19:49:01 +053074
75/*
76 * Get GPIO DW0 Address
77 * Arg0 - GPIO Number
78 */
79Method (GADD, 1, NotSerialized)
80{
Li Cheng Sooi6a740532017-01-04 09:48:39 +080081#if IS_ENABLED(CONFIG_SKYLAKE_SOC_PCH_H)
82 /* GPIO Community 0 */
83 If (LAnd (LGreaterEqual (Arg0, GPP_A0), LLessEqual (Arg0, GPP_B23)))
84 {
85 Store (PID_GPIOCOM0, Local0)
86 Subtract (Arg0, GPP_A0, Local1)
87 }
88 /* GPIO Community 1 */
89 If (LAnd (LGreaterEqual (Arg0, GPP_C0), LLessEqual (Arg0, GPP_H23)))
90 {
91 Store (PID_GPIOCOM1, Local0)
92 Subtract (Arg0, GPP_C0, Local1)
93 }
94 /* GPIO Community 03 */
95 If (LAnd (LGreaterEqual (Arg0, GPP_I0), LLessEqual (Arg0, GPP_I10)))
96 {
97 Store (PID_GPIOCOM3, Local0)
98 Subtract (Arg0, GPP_I0, Local1)
99 }
100#else
Subrata Banikfbc46092015-12-07 19:49:01 +0530101 /* GPIO Community 0 */
102 If (LAnd (LGreaterEqual (Arg0, GPP_A0), LLessEqual (Arg0, GPP_B23)))
103 {
104 Store (PID_GPIOCOM0, Local0)
105 Subtract (Arg0, GPP_A0, Local1)
106 }
107 /* GPIO Community 1 */
108 If (LAnd (LGreaterEqual (Arg0, GPP_C0), LLessEqual (Arg0, GPP_E23)))
109 {
110 Store (PID_GPIOCOM1, Local0)
111 Subtract (Arg0, GPP_C0, Local1)
112 }
113 /* GPIO Community 03*/
114 If (LAnd (LGreaterEqual (Arg0, GPP_F0), LLessEqual (Arg0, GPP_G7)))
115 {
116 Store (PID_GPIOCOM3, Local0)
117 Subtract (Arg0, GPP_F0, Local1)
118 }
Li Cheng Sooi6a740532017-01-04 09:48:39 +0800119#endif /* CONFIG_SKYLAKE_SOC_PCH_H */
Subrata Banikfbc46092015-12-07 19:49:01 +0530120 Store (PCRB (Local0), Local2)
Hannah Williams1760cd32017-04-06 20:54:11 -0700121 Add (Local2, PAD_CFG_BASE, Local2)
Subrata Banikfbc46092015-12-07 19:49:01 +0530122 Return (Add (Local2, Multiply (Local1, 8)))
123}
124
125/*
Furquan Shaikha6f0b272017-05-23 11:53:47 -0700126 * Get GPIO Rx Value
Subrata Banikfbc46092015-12-07 19:49:01 +0530127 * Arg0 - GPIO Number
128 */
Duncan Laurie73b753a2016-02-08 16:08:15 -0800129Method (GRXS, 1, Serialized)
Subrata Banikfbc46092015-12-07 19:49:01 +0530130{
131 OperationRegion (PREG, SystemMemory, GADD (Arg0), 4)
132 Field (PREG, AnyAcc, NoLock, Preserve)
133 {
134 VAL0, 32
135 }
Hannah Williams1760cd32017-04-06 20:54:11 -0700136 And (GPIORXSTATE_MASK, ShiftRight (VAL0, PAD_CFG0_RX_STATE_BIT), Local0)
Subrata Banikfbc46092015-12-07 19:49:01 +0530137
138 Return (Local0)
139}
Furquan Shaikha6f0b272017-05-23 11:53:47 -0700140
141/*
142 * Get GPIO Tx Value
143 * Arg0 - GPIO Number
144 */
145Method (GTXS, 1, Serialized)
146{
147 OperationRegion (PREG, SystemMemory, GADD (Arg0), 4)
148 Field (PREG, AnyAcc, NoLock, Preserve)
149 {
150 VAL0, 32
151 }
Hannah Williams1760cd32017-04-06 20:54:11 -0700152 And (GPIOTXSTATE_MASK, ShiftRight (VAL0, PAD_CFG0_TX_STATE_BIT), Local0)
Furquan Shaikha6f0b272017-05-23 11:53:47 -0700153
154 Return (Local0)
155}
156
157/*
158 * Set GPIO Tx Value
159 * Arg0 - GPIO Number
160 */
161Method (STXS, 1, Serialized)
162{
163 OperationRegion (PREG, SystemMemory, GADD (Arg0), 4)
164 Field (PREG, AnyAcc, NoLock, Preserve)
165 {
166 VAL0, 32
167 }
168 Or (GPIOTXSTATE_MASK, VAL0, VAL0)
169}
170
171/*
172 * Clear GPIO Tx Value
173 * Arg0 - GPIO Number
174 */
175Method (CTXS, 1, Serialized)
176{
177 OperationRegion (PREG, SystemMemory, GADD (Arg0), 4)
178 Field (PREG, AnyAcc, NoLock, Preserve)
179 {
180 VAL0, 32
181 }
182 And (Not (GPIOTXSTATE_MASK), VAL0, VAL0)
183}