Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corporation. |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 6 | * |
| 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 Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 15 | */ |
Hannah Williams | 1760cd3 | 2017-04-06 20:54:11 -0700 | [diff] [blame] | 16 | #include <soc/gpio.h> |
| 17 | |
| 18 | #define GPIOTXSTATE_MASK 0x1 |
| 19 | #define GPIORXSTATE_MASK 0x1 |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 20 | |
| 21 | Device (GPIO) |
| 22 | { |
Archana Patni | ee96628 | 2015-07-04 00:56:32 +0530 | [diff] [blame] | 23 | Name (_HID, "INT344B") |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 24 | Name (_UID, 1) |
Duncan Laurie | c97106f | 2015-08-27 17:15:00 -0700 | [diff] [blame] | 25 | Name (_DDN, "GPIO Controller") |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 26 | |
| 27 | Name (RBUF, ResourceTemplate() |
| 28 | { |
Duncan Laurie | c97106f | 2015-08-27 17:15:00 -0700 | [diff] [blame] | 29 | 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 Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 34 | }) |
| 35 | |
Duncan Laurie | c97106f | 2015-08-27 17:15:00 -0700 | [diff] [blame] | 36 | Method (_CRS, 0, NotSerialized) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 37 | { |
Duncan Laurie | c97106f | 2015-08-27 17:15:00 -0700 | [diff] [blame] | 38 | /* 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 Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 43 | |
Duncan Laurie | c97106f | 2015-08-27 17:15:00 -0700 | [diff] [blame] | 44 | /* 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 Williams | 1760cd3 | 2017-04-06 20:54:11 -0700 | [diff] [blame] | 57 | And (^^PCRR (PID_GPIOCOM0, GPIO_MISCCFG), |
Duncan Laurie | c97106f | 2015-08-27 17:15:00 -0700 | [diff] [blame] | 58 | GPIO_DRIVER_IRQ_ROUTE_MASK, Local0) |
Archana Patni | ee96628 | 2015-07-04 00:56:32 +0530 | [diff] [blame] | 59 | |
| 60 | If (LEqual (Local0, GPIO_DRIVER_IRQ_ROUTE_IRQ14)) { |
| 61 | Store (GPIO_IRQ14, IRQN) |
| 62 | } Else { |
| 63 | Store (GPIO_IRQ15, IRQN) |
| 64 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 65 | |
| 66 | Return (RBUF) |
| 67 | } |
| 68 | |
| 69 | Method (_STA, 0, NotSerialized) |
| 70 | { |
| 71 | Return (0xF) |
| 72 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 73 | } |
Subrata Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Get GPIO DW0 Address |
| 77 | * Arg0 - GPIO Number |
| 78 | */ |
| 79 | Method (GADD, 1, NotSerialized) |
| 80 | { |
Li Cheng Sooi | 6a74053 | 2017-01-04 09:48:39 +0800 | [diff] [blame] | 81 | #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 Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 101 | /* 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 Sooi | 6a74053 | 2017-01-04 09:48:39 +0800 | [diff] [blame] | 119 | #endif /* CONFIG_SKYLAKE_SOC_PCH_H */ |
Subrata Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 120 | Store (PCRB (Local0), Local2) |
Hannah Williams | 1760cd3 | 2017-04-06 20:54:11 -0700 | [diff] [blame] | 121 | Add (Local2, PAD_CFG_BASE, Local2) |
Subrata Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 122 | Return (Add (Local2, Multiply (Local1, 8))) |
| 123 | } |
| 124 | |
| 125 | /* |
Furquan Shaikh | a6f0b27 | 2017-05-23 11:53:47 -0700 | [diff] [blame] | 126 | * Get GPIO Rx Value |
Subrata Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 127 | * Arg0 - GPIO Number |
| 128 | */ |
Duncan Laurie | 73b753a | 2016-02-08 16:08:15 -0800 | [diff] [blame] | 129 | Method (GRXS, 1, Serialized) |
Subrata Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 130 | { |
| 131 | OperationRegion (PREG, SystemMemory, GADD (Arg0), 4) |
| 132 | Field (PREG, AnyAcc, NoLock, Preserve) |
| 133 | { |
| 134 | VAL0, 32 |
| 135 | } |
Hannah Williams | 1760cd3 | 2017-04-06 20:54:11 -0700 | [diff] [blame] | 136 | And (GPIORXSTATE_MASK, ShiftRight (VAL0, PAD_CFG0_RX_STATE_BIT), Local0) |
Subrata Banik | fbc4609 | 2015-12-07 19:49:01 +0530 | [diff] [blame] | 137 | |
| 138 | Return (Local0) |
| 139 | } |
Furquan Shaikh | a6f0b27 | 2017-05-23 11:53:47 -0700 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * Get GPIO Tx Value |
| 143 | * Arg0 - GPIO Number |
| 144 | */ |
| 145 | Method (GTXS, 1, Serialized) |
| 146 | { |
| 147 | OperationRegion (PREG, SystemMemory, GADD (Arg0), 4) |
| 148 | Field (PREG, AnyAcc, NoLock, Preserve) |
| 149 | { |
| 150 | VAL0, 32 |
| 151 | } |
Hannah Williams | 1760cd3 | 2017-04-06 20:54:11 -0700 | [diff] [blame] | 152 | And (GPIOTXSTATE_MASK, ShiftRight (VAL0, PAD_CFG0_TX_STATE_BIT), Local0) |
Furquan Shaikh | a6f0b27 | 2017-05-23 11:53:47 -0700 | [diff] [blame] | 153 | |
| 154 | Return (Local0) |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Set GPIO Tx Value |
| 159 | * Arg0 - GPIO Number |
| 160 | */ |
| 161 | Method (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 | */ |
| 175 | Method (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 | } |