coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <intelblocks/gpio.h>
4 #include <intelblocks/pcr.h>
5 #include <soc/pcr_ids.h>
6 #include <soc/pmc.h>
7 
8 #define DEFAULT_VW_BASE 0x10
9 
10 /*
11  * This file is created based on Intel Tiger Lake Processor PCH Datasheet
12  * Document number: 575857
13  * Chapter number: 27
14  */
15 
16 static const struct reset_mapping rst_map[] = {
17  { .logical = PAD_CFG0_LOGICAL_RESET_RSMRST, .chipset = 0U << 30 },
18  { .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 },
19  { .logical = PAD_CFG0_LOGICAL_RESET_PLTRST, .chipset = 2U << 30 },
20 };
21 static const struct reset_mapping rst_map_com2[] = {
22  { .logical = PAD_CFG0_LOGICAL_RESET_PWROK, .chipset = 0U << 30 },
23  { .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 },
24  { .logical = PAD_CFG0_LOGICAL_RESET_PLTRST, .chipset = 2U << 30 },
25  { .logical = PAD_CFG0_LOGICAL_RESET_RSMRST, .chipset = 3U << 30 },
26 };
27 
28 /*
29  * The GPIO pinctrl driver for Tiger Lake on Linux expects 32 GPIOs per pad
30  * group, regardless of whether or not there is a physical pad for each
31  * exposed GPIO number.
32  *
33  * This results in the OS having a sparse GPIO map, and devices that need
34  * to export an ACPI GPIO must use the OS expected number.
35  *
36  * Not all pins are usable as GPIO and those groups do not have a pad base.
37  *
38  * This layout matches the Linux kernel pinctrl map for TGL at:
39  * linux/drivers/pinctrl/intel/pinctrl-tigerlake.c
40  */
41 static const struct pad_group tgl_community0_groups[] = {
42  INTEL_GPP_BASE(GPP_B0, GPP_B0, GPP_B25, 0), /* GPP_B */
43  INTEL_GPP_BASE(GPP_B0, GPP_T0, GPP_T15, 32), /* GPP_T */
44  INTEL_GPP_BASE(GPP_B0, GPP_A0, GPP_A24, 64), /* GPP_A */
45 };
46 
47 static const struct vw_entries tgl_community0_vw[] = {
48  {GPP_A0, GPP_A23},
49  {GPP_B0, GPP_B23},
50 };
51 
52 static const struct pad_group tgl_community1_groups[] = {
53  INTEL_GPP_BASE(GPP_S0, GPP_S0, GPP_S7, 96), /* GPP_S */
54  INTEL_GPP_BASE(GPP_S0, GPP_H0, GPP_H23, 128), /* GPP_H */
57  INTEL_GPP_BASE(GPP_S0, CNV_BTEN, vI2S2_RXD, 224), /* GPP_VGPIO */
58 };
59 
60 static const struct vw_entries tgl_community1_vw[] = {
61  {GPP_D0, GPP_D19},
62  {GPP_H0, GPP_H23},
63 };
64 
65 /* This community is not visible to the OS */
66 static const struct pad_group tgl_community2_groups[] = {
67  INTEL_GPP(GPD0, GPD0, GPD_DRAM_RESETB), /* GPD */
68 };
69 
70 static const struct pad_group tgl_community4_groups[] = {
71  INTEL_GPP_BASE(GPP_C0, GPP_C0, GPP_C23, 256), /* GPP_C */
72  INTEL_GPP_BASE(GPP_C0, GPP_F0, GPP_F_CLK_LOOPBK, 288), /* GPP_F */
73  INTEL_GPP(GPP_C0, GPP_L_BKLTEN, GPP_MLK_RSTB), /* GPP_HVCMOS */
74  INTEL_GPP_BASE(GPP_C0, GPP_E0, GPP_E_CLK_LOOPBK, 320), /* GPP_E */
75  INTEL_GPP(GPP_C0, GPP_JTAG_TDO, GPP_DBG_PMODE), /* GPP_JTAG */
76 };
77 
78 static const struct vw_entries tgl_community4_vw[] = {
79  {GPP_F0, GPP_F23},
80  {GPP_C0, GPP_C23},
81  {GPP_E0, GPP_E23},
82 };
83 
84 static const struct pad_group tgl_community5_groups[] = {
85  INTEL_GPP_BASE(GPP_R0, GPP_R0, GPP_R7, 352), /* GPP_R */
87 };
88 
89 static const struct pad_community tgl_communities[] = {
90  [COMM_0] = { /* GPP B, T, A */
91  .port = PID_GPIOCOM0,
92  .cpu_port = PID_CPU_GPIOCOM0,
93  .first_pad = GPP_B0,
94  .last_pad = GPP_A24,
95  .num_gpi_regs = NUM_GPIO_COM0_GPI_REGS,
96  .pad_cfg_base = PAD_CFG_BASE,
97  .host_own_reg_0 = HOSTSW_OWN_REG_0,
98  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
99  .gpi_int_en_reg_0 = GPI_INT_EN_0,
100  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
101  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
102  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
103  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
104  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
105  .name = "GPP_BTA",
106  .acpi_path = "\\_SB.PCI0.GPIO",
107  .reset_map = rst_map,
108  .num_reset_vals = ARRAY_SIZE(rst_map),
109  .groups = tgl_community0_groups,
110  .num_groups = ARRAY_SIZE(tgl_community0_groups),
111  .vw_base = DEFAULT_VW_BASE,
112  .vw_entries = tgl_community0_vw,
113  .num_vw_entries = ARRAY_SIZE(tgl_community0_vw),
114  },
115  [COMM_1] = { /* GPP S, D, H, U, VGPIO */
116  .port = PID_GPIOCOM1,
117  .cpu_port = PID_CPU_GPIOCOM1,
118  .first_pad = GPP_S0,
119  .last_pad = vI2S2_RXD,
120  .num_gpi_regs = NUM_GPIO_COM1_GPI_REGS,
121  .pad_cfg_base = PAD_CFG_BASE,
122  .host_own_reg_0 = HOSTSW_OWN_REG_0,
123  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
124  .gpi_int_en_reg_0 = GPI_INT_EN_0,
125  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
126  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
127  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
128  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
129  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
130  .name = "GPP_SDHU",
131  .acpi_path = "\\_SB.PCI0.GPIO",
132  .reset_map = rst_map,
133  .num_reset_vals = ARRAY_SIZE(rst_map),
134  .groups = tgl_community1_groups,
135  .num_groups = ARRAY_SIZE(tgl_community1_groups),
136  .vw_base = DEFAULT_VW_BASE,
137  .vw_entries = tgl_community1_vw,
138  .num_vw_entries = ARRAY_SIZE(tgl_community1_vw),
139  },
140  [COMM_2] = { /* GPD */
141  .port = PID_GPIOCOM2,
142  .first_pad = GPD0,
143  .last_pad = GPD_DRAM_RESETB,
144  .num_gpi_regs = NUM_GPIO_COM2_GPI_REGS,
145  .pad_cfg_base = PAD_CFG_BASE,
146  .host_own_reg_0 = HOSTSW_OWN_REG_0,
147  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
148  .gpi_int_en_reg_0 = GPI_INT_EN_0,
149  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
150  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
151  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
152  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
153  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
154  .name = "GPD",
155  .acpi_path = "\\_SB.PCI0.GPIO",
156  .reset_map = rst_map_com2,
157  .num_reset_vals = ARRAY_SIZE(rst_map_com2),
158  .groups = tgl_community2_groups,
159  .num_groups = ARRAY_SIZE(tgl_community2_groups),
160  },
161  [COMM_4] = { /* GPP F, C, HVCOS, E, JTAG */
162  .port = PID_GPIOCOM4,
163  .cpu_port = PID_CPU_GPIOCOM4,
164  .first_pad = GPP_C0,
165  .last_pad = GPP_DBG_PMODE,
166  .num_gpi_regs = NUM_GPIO_COM4_GPI_REGS,
167  .pad_cfg_base = PAD_CFG_BASE,
168  .host_own_reg_0 = HOSTSW_OWN_REG_0,
169  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
170  .gpi_int_en_reg_0 = GPI_INT_EN_0,
171  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
172  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
173  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
174  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
175  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
176  .name = "GPP_FCE",
177  .acpi_path = "\\_SB.PCI0.GPIO",
178  .reset_map = rst_map,
179  .num_reset_vals = ARRAY_SIZE(rst_map),
180  .groups = tgl_community4_groups,
181  .num_groups = ARRAY_SIZE(tgl_community4_groups),
182  .vw_base = DEFAULT_VW_BASE,
183  .vw_entries = tgl_community4_vw,
184  .num_vw_entries = ARRAY_SIZE(tgl_community4_vw),
185  },
186  [COMM_5] = { /* GPP R, SPI */
187  .port = PID_GPIOCOM5,
188  .cpu_port = PID_CPU_GPIOCOM5,
189  .first_pad = GPP_R0,
190  .last_pad = GPP_CLK_LOOPBK,
191  .num_gpi_regs = NUM_GPIO_COM5_GPI_REGS,
192  .pad_cfg_base = PAD_CFG_BASE,
193  .host_own_reg_0 = HOSTSW_OWN_REG_0,
194  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
195  .gpi_int_en_reg_0 = GPI_INT_EN_0,
196  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
197  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
198  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
199  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
200  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
201  .name = "GPP_CPU_VBPIO",
202  .acpi_path = "\\_SB.PCI0.GPIO",
203  .reset_map = rst_map,
204  .num_reset_vals = ARRAY_SIZE(rst_map),
205  .groups = tgl_community5_groups,
206  .num_groups = ARRAY_SIZE(tgl_community5_groups),
207  }
208 };
209 
210 const struct pad_community *soc_gpio_get_community(size_t *num_communities)
211 {
212  *num_communities = ARRAY_SIZE(tgl_communities);
213  return tgl_communities;
214 }
215 
216 const struct pmc_to_gpio_route *soc_pmc_gpio_routes(size_t *num)
217 {
218  static const struct pmc_to_gpio_route routes[] = {
219  { PMC_GPP_B, GPP_B },
220  { PMC_GPP_T, GPP_T },
221  { PMC_GPP_A, GPP_A },
222  { PMC_GPP_R, GPP_R },
223  { PMC_GPD, GPD },
224  { PMC_GPP_S, GPP_S },
225  { PMC_GPP_H, GPP_H },
226  { PMC_GPP_D, GPP_D },
227  { PMC_GPP_U, GPP_U },
228  { PMC_GPP_F, GPP_F },
229  { PMC_GPP_C, GPP_C },
230  { PMC_GPP_E, GPP_E },
231  };
232  *num = ARRAY_SIZE(routes);
233  return routes;
234 }
#define GPIO_MAX_NUM_PER_GROUP
Definition: gpio_soc_defs.h:31
#define COMM_0
Definition: gpio_soc_defs.h:33
#define GPP_E_CLK_LOOPBK
#define GPP_F_CLK_LOOPBK
#define GPP_D
Definition: gpio_soc_defs.h:26
#define GPP_A
Definition: gpio_soc_defs.h:16
#define GPP_E0
#define GPP_R7
#define GPP_T
Definition: gpio_soc_defs.h:15
#define GPD_DRAM_RESETB
#define GPP_S0
#define GPP_F23
#define GPP_F0
#define GPP_R
Definition: gpio_soc_defs.h:17
#define GPP_B
Definition: gpio_soc_defs.h:14
#define GPD0
#define GPP_R0
#define GPP_C23
#define GPP_S7
#define COMM_1
Definition: gpio_soc_defs.h:34
#define GPP_T0
Definition: gpio_soc_defs.h:91
#define GPP_A23
#define GPP_E23
#define GPP_GSPI2_CLK_LOOPBK
#define GPP_A0
#define GPP_T15
#define GPP_B25
Definition: gpio_soc_defs.h:78
#define GPP_L_BKLTEN
#define GPP_H0
#define GPP_S
Definition: gpio_soc_defs.h:19
#define GPP_C
Definition: gpio_soc_defs.h:28
#define GPP_D0
#define GPP_MLK_RSTB
#define GPP_B0
Definition: gpio_soc_defs.h:53
#define GPP_F
Definition: gpio_soc_defs.h:27
#define GPP_B23
Definition: gpio_soc_defs.h:76
#define GPP_E
Definition: gpio_soc_defs.h:29
#define GPP_D19
#define GPD
Definition: gpio_soc_defs.h:18
#define GPP_H
Definition: gpio_soc_defs.h:24
#define COMM_4
Definition: gpio_soc_defs.h:37
#define COMM_5
Definition: gpio_soc_defs.h:38
#define GPP_C0
#define COMM_2
Definition: gpio_soc_defs.h:35
#define GPP_H23
#define PID_CPU_GPIOCOM0
Definition: pcr_ids.h:40
#define PID_CPU_GPIOCOM4
Definition: pcr_ids.h:43
#define PID_CPU_GPIOCOM5
Definition: pcr_ids.h:44
#define PID_CPU_GPIOCOM1
Definition: pcr_ids.h:41
#define PID_GPIOCOM4
Definition: pcr_ids.h:19
#define PID_GPIOCOM5
Definition: pcr_ids.h:20
#define PID_GPIOCOM2
Definition: pcr_ids.h:17
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define CNV_BTEN
@ PID_GPIOCOM0
Definition: pcr.h:17
@ PID_GPIOCOM1
Definition: pcr.h:18
#define GPP_U0
#define GPP_U
Definition: gpio_soc_defs.h:19
#define PMC_GPP_H
Definition: pmc.h:124
#define PMC_GPP_T
Definition: pmc.h:114
#define PMC_GPP_B
Definition: pmc.h:113
#define PMC_GPD
Definition: pmc.h:117
#define PMC_GPP_F
Definition: pmc.h:127
#define PMC_GPP_D
Definition: pmc.h:125
#define PMC_GPP_E
Definition: pmc.h:129
#define PMC_GPP_S
Definition: pmc.h:118
#define PMC_GPP_R
Definition: pmc.h:116
#define PMC_GPP_A
Definition: pmc.h:115
#define PMC_GPP_C
Definition: pmc.h:128
#define PMC_GPP_U
Definition: pmc.h:114
const struct pmc_to_gpio_route * soc_pmc_gpio_routes(size_t *num)
Definition: gpio.c:247
const struct pad_community * soc_gpio_get_community(size_t *num_communities)
Definition: gpio.c:241
#define NUM_GPIO_COM5_GPI_REGS
Definition: gpio_defs.h:21
#define NUM_GPIO_COM1_GPI_REGS
Definition: gpio_defs.h:17
#define GPI_INT_EN_0
Definition: gpio_defs.h:346
#define GPI_INT_STS_0
Definition: gpio_defs.h:345
#define NUM_GPIO_COM2_GPI_REGS
Definition: gpio_defs.h:18
#define NUM_GPIO_COM4_GPI_REGS
Definition: gpio_defs.h:20
#define HOSTSW_OWN_REG_0
Definition: gpio_defs.h:344
#define NUM_GPIO_COM0_GPI_REGS
Definition: gpio_defs.h:16
#define GPI_SMI_STS_0
Definition: gpio_defs.h:347
#define PAD_CFG_BASE
Definition: gpio_defs.h:349
#define GPI_SMI_EN_0
Definition: gpio_defs.h:348
#define GPI_NMI_EN_0
Definition: gpio_defs.h:240
#define GPI_NMI_STS_0
Definition: gpio_defs.h:239
#define INTEL_GPP_BASE(first_of_community, start_of_group, end_of_group, group_pad_base)
Definition: gpio.h:34
#define INTEL_GPP(first_of_community, start_of_group, end_of_group)
Definition: gpio.h:49
#define PAD_CFG0_LOGICAL_RESET_PWROK
Definition: gpio_defs.h:44
#define PAD_CFG0_LOGICAL_RESET_RSMRST
Definition: gpio_defs.h:47
#define PAD_CFG0_LOGICAL_RESET_PLTRST
Definition: gpio_defs.h:46
#define PAD_CFG0_LOGICAL_RESET_DEEP
Definition: gpio_defs.h:45
static const struct reset_mapping rst_map_com2[]
Definition: gpio.c:21
static const struct vw_entries tgl_community1_vw[]
Definition: gpio.c:60
static const struct vw_entries tgl_community4_vw[]
Definition: gpio.c:78
static const struct pad_group tgl_community4_groups[]
Definition: gpio.c:70
static const struct pad_group tgl_community0_groups[]
Definition: gpio.c:41
static const struct pad_group tgl_community2_groups[]
Definition: gpio.c:66
static const struct reset_mapping rst_map[]
Definition: gpio.c:16
static const struct pad_group tgl_community5_groups[]
Definition: gpio.c:84
static const struct pad_community tgl_communities[]
Definition: gpio.c:89
static const struct vw_entries tgl_community0_vw[]
Definition: gpio.c:47
static const struct pad_group tgl_community1_groups[]
Definition: gpio.c:52
#define DEFAULT_VW_BASE
Definition: gpio.c:8
uint8_t port
Definition: gpio.h:135
Definition: gpio.h:94
uint32_t logical
Definition: gpio.h:89
#define GPP_CLK_LOOPBK
#define GPP_SPI_IO_2
#define GPP_A24
#define vI2S2_RXD
#define GPP_GSPI6_CLK_LOOPBK
#define GPP_JTAG_TDO
#define GPP_DBG_PMODE