Angel Pons | f5627e8 | 2020-04-05 15:46:52 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 2 | #include <soc/gpio_defs.h> |
Subrata Banik | 8ff80b2 | 2020-09-23 19:17:12 +0530 | [diff] [blame] | 3 | #include <soc/intel/common/block/acpi/acpi/gpio_op.asl> |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 4 | #include <soc/irq.h> |
| 5 | #include <soc/pcr_ids.h> |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 6 | #include <intelblocks/gpio.h> |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 7 | |
| 8 | Device (GPIO) |
| 9 | { |
| 10 | Name (_HID, "INT34BB") |
| 11 | Name (_UID, 0) |
| 12 | Name (_DDN, "GPIO Controller") |
| 13 | |
| 14 | Name (RBUF, ResourceTemplate() |
| 15 | { |
| 16 | Memory32Fixed (ReadWrite, 0, 0, COM0) |
| 17 | Memory32Fixed (ReadWrite, 0, 0, COM1) |
| 18 | Memory32Fixed (ReadWrite, 0, 0, COM4) |
| 19 | Interrupt (ResourceConsumer, Level, ActiveLow, Shared,,, GIRQ) |
| 20 | { GPIO_IRQ14 } |
| 21 | }) |
| 22 | |
Duncan Laurie | f63c3f6 | 2018-12-08 11:58:32 -0800 | [diff] [blame] | 23 | /* |
| 24 | * GPIO communities 0, 1, and 4 are exported for the OS. |
| 25 | * This is based on the Linux kernel provided community map at |
| 26 | * drivers/pinctrl/intel/pinctrl-cannonlake.c:cnllp_communities[] |
| 27 | */ |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 28 | Method (_CRS, 0, NotSerialized) |
| 29 | { |
| 30 | /* GPIO Community 0 */ |
| 31 | CreateDWordField (^RBUF, ^COM0._BAS, BAS0) |
Bora Guvendik | 630b644 | 2017-10-11 17:54:58 -0700 | [diff] [blame] | 32 | CreateDWordField (^RBUF, ^COM0._LEN, LEN0) |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 33 | BAS0 = ^^PCRB (PID_GPIOCOM0) |
| 34 | LEN0 = GPIO_BASE_SIZE |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 35 | |
| 36 | /* GPIO Community 1 */ |
| 37 | CreateDWordField (^RBUF, ^COM1._BAS, BAS1) |
Bora Guvendik | 630b644 | 2017-10-11 17:54:58 -0700 | [diff] [blame] | 38 | CreateDWordField (^RBUF, ^COM1._LEN, LEN1) |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 39 | BAS1 = ^^PCRB (PID_GPIOCOM1) |
| 40 | LEN1 = GPIO_BASE_SIZE |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 41 | |
| 42 | /* GPIO Community 4 */ |
| 43 | CreateDWordField (^RBUF, ^COM4._BAS, BAS4) |
Lijian Zhao | e1b8221 | 2018-02-08 16:58:47 -0800 | [diff] [blame] | 44 | CreateDWordField (^RBUF, ^COM4._LEN, LEN4) |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 45 | BAS4 = ^^PCRB (PID_GPIOCOM4) |
| 46 | LEN4 = GPIO_BASE_SIZE |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 47 | |
| 48 | Return (RBUF) |
| 49 | } |
| 50 | |
| 51 | Method (_STA, 0, NotSerialized) |
| 52 | { |
| 53 | Return (0xF) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Get GPIO DW0 Address |
| 59 | * Arg0 - GPIO Number |
| 60 | */ |
| 61 | Method (GADD, 1, NotSerialized) |
| 62 | { |
| 63 | /* GPIO Community 0 */ |
Felix Singer | b1557e8 | 2022-01-02 03:51:21 +0100 | [diff] [blame] | 64 | If (Arg0 >= GPP_A0 && Arg0 <= SPI0_CLK_LOOPBK) |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 65 | { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 66 | Local0 = PID_GPIOCOM0 |
Felix Singer | a6fe3f8 | 2021-12-29 23:29:18 +0100 | [diff] [blame] | 67 | Local1 = Arg0 - GPP_A0 |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 68 | } |
| 69 | /* GPIO Community 1 */ |
Felix Singer | b1557e8 | 2022-01-02 03:51:21 +0100 | [diff] [blame] | 70 | If (Arg0 >= GPP_D0 && Arg0 <= vSD3_CD_B) |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 71 | { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 72 | Local0 = PID_GPIOCOM1 |
Felix Singer | a6fe3f8 | 2021-12-29 23:29:18 +0100 | [diff] [blame] | 73 | Local1 = Arg0 - GPP_D0 |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 74 | } |
Lijian Zhao | e1b8221 | 2018-02-08 16:58:47 -0800 | [diff] [blame] | 75 | /* GPIO Community 2 */ |
Felix Singer | b1557e8 | 2022-01-02 03:51:21 +0100 | [diff] [blame] | 76 | If (Arg0 >= GPD0 && Arg0 <= DRAM_RESET_B) |
Lijian Zhao | e1b8221 | 2018-02-08 16:58:47 -0800 | [diff] [blame] | 77 | { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 78 | Local0 = PID_GPIOCOM2 |
Felix Singer | a6fe3f8 | 2021-12-29 23:29:18 +0100 | [diff] [blame] | 79 | Local1 = Arg0 - GPD0 |
Lijian Zhao | e1b8221 | 2018-02-08 16:58:47 -0800 | [diff] [blame] | 80 | } |
| 81 | /* GPIO Community 3 */ |
Felix Singer | b1557e8 | 2022-01-02 03:51:21 +0100 | [diff] [blame] | 82 | If (Arg0 >= HDA_BCLK && Arg0 <= TRIGGER_OUT) |
Lijian Zhao | e1b8221 | 2018-02-08 16:58:47 -0800 | [diff] [blame] | 83 | { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 84 | Local0 = PID_GPIOCOM3 |
Felix Singer | a6fe3f8 | 2021-12-29 23:29:18 +0100 | [diff] [blame] | 85 | Local1 = Arg0 - HDA_BCLK |
Lijian Zhao | e1b8221 | 2018-02-08 16:58:47 -0800 | [diff] [blame] | 86 | } |
Michael Niewöhner | 1c2b1b9 | 2020-09-09 21:34:05 +0200 | [diff] [blame] | 87 | /* GPIO Community 4*/ |
Felix Singer | b1557e8 | 2022-01-02 03:51:21 +0100 | [diff] [blame] | 88 | If (Arg0 >= GPP_C0 && Arg0 <= CL_RST_B) |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 89 | { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 90 | Local0 = PID_GPIOCOM4 |
Felix Singer | a6fe3f8 | 2021-12-29 23:29:18 +0100 | [diff] [blame] | 91 | Local1 = Arg0 - GPP_C0 |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 92 | } |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 93 | Local2 = PCRB (Local0) |
Felix Singer | 3a8f087 | 2021-12-30 01:27:07 +0100 | [diff] [blame] | 94 | Local2 += PAD_CFG_BASE |
Felix Singer | 3d3d498 | 2021-12-31 11:52:19 +0100 | [diff] [blame] | 95 | Return (Local2 + Local1 * 16) |
Bora Guvendik | 5d11cc9 | 2017-09-25 14:33:17 -0700 | [diff] [blame] | 96 | } |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Return PCR Port ID of GPIO Communities |
| 100 | * |
| 101 | * Arg0: GPIO Community (0-4) |
| 102 | */ |
| 103 | Method (GPID, 1, Serialized) |
| 104 | { |
| 105 | Switch (ToInteger (Arg0)) |
| 106 | { |
| 107 | Case (0) { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 108 | Local0 = PID_GPIOCOM0 |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 109 | } |
| 110 | Case (1) { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 111 | Local0 = PID_GPIOCOM1 |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 112 | } |
| 113 | Case (2) { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 114 | Local0 = PID_GPIOCOM2 |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 115 | } |
| 116 | Case (3) { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 117 | Local0 = PID_GPIOCOM3 |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 118 | } |
| 119 | Case (4) { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 120 | Local0 = PID_GPIOCOM4 |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 121 | } |
| 122 | Default { |
| 123 | Return (0) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | Return (Local0) |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Configure GPIO Power Management bits |
| 132 | * |
| 133 | * Arg0: GPIO community (0-4) |
| 134 | * Arg1: PM bits in MISCCFG |
| 135 | */ |
| 136 | Method (CGPM, 2, Serialized) |
| 137 | { |
Felix Singer | 3dc4d84 | 2022-12-12 07:36:41 +0100 | [diff] [blame] | 138 | Local0 = GPID (Arg0) |
Felix Singer | 0767747 | 2022-01-02 02:55:22 +0100 | [diff] [blame] | 139 | If (Local0 != 0) { |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 140 | /* Mask off current PM bits */ |
Felix Singer | c87c1ab | 2022-12-25 16:25:06 +0100 | [diff] [blame^] | 141 | PCRA (Local0, GPIO_MISCCFG, ~MISCCFG_GPIO_PM_CONFIG_BITS) |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 142 | /* Mask in requested bits */ |
Felix Singer | d252776 | 2022-12-16 07:54:16 +0100 | [diff] [blame] | 143 | PCRO (Local0, GPIO_MISCCFG, Arg1 & MISCCFG_GPIO_PM_CONFIG_BITS) |
Tim Wawrzynczak | a172425 | 2019-07-10 09:12:05 -0600 | [diff] [blame] | 144 | } |
| 145 | } |
Eric Lai | 086f0fa | 2019-12-13 12:31:46 +0800 | [diff] [blame] | 146 | |
| 147 | /* GPIO Power Management bits */ |
Subrata Banik | 2883f7a | 2020-01-13 10:56:58 +0530 | [diff] [blame] | 148 | Name(GPMB, Package(TOTAL_GPIO_COMM) {0, 0, 0, 0, 0}) |
Eric Lai | 086f0fa | 2019-12-13 12:31:46 +0800 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * Save GPIO Power Management bits |
| 152 | */ |
| 153 | Method (SGPM, 0, Serialized) |
| 154 | { |
| 155 | For (Local0 = 0, Local0 < TOTAL_GPIO_COMM, Local0++) |
| 156 | { |
| 157 | Local1 = GPID (Local0) |
| 158 | GPMB[Local0] = PCRR (Local1, GPIO_MISCCFG) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Restore GPIO Power Management bits |
| 164 | */ |
| 165 | Method (RGPM, 0, Serialized) |
| 166 | { |
| 167 | For (Local0 = 0, Local0 < TOTAL_GPIO_COMM, Local0++) |
| 168 | { |
| 169 | CGPM (Local0, DerefOf(GPMB[Local0])) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Save current setting of GPIO Power Management bits and |
| 175 | * enable all Power Management bits for all communities |
| 176 | */ |
| 177 | Method (EGPM, 0, Serialized) |
| 178 | { |
| 179 | /* Save current setting and will restore it when resuming */ |
| 180 | SGPM () |
| 181 | /* Enable PM bits */ |
| 182 | For (Local0 = 0, Local0 < TOTAL_GPIO_COMM, Local0++) |
| 183 | { |
Subrata Banik | 2ccc0a4 | 2021-03-25 20:01:47 +0530 | [diff] [blame] | 184 | CGPM (Local0, MISCCFG_GPIO_PM_CONFIG_BITS) |
Eric Lai | 086f0fa | 2019-12-13 12:31:46 +0800 | [diff] [blame] | 185 | } |
| 186 | } |