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 static const struct reset_mapping rst_map[] = {
9  { .logical = PAD_CFG0_LOGICAL_RESET_RSMRST, .chipset = 0U << 30 },
10  { .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 },
11  { .logical = PAD_CFG0_LOGICAL_RESET_PLTRST, .chipset = 2U << 30 },
12 };
13 
14 static const struct reset_mapping rst_map_com0[] = {
15  { .logical = PAD_CFG0_LOGICAL_RESET_PWROK, .chipset = 0U << 30 },
16  { .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 },
17  { .logical = PAD_CFG0_LOGICAL_RESET_PLTRST, .chipset = 2U << 30 },
18  { .logical = PAD_CFG0_LOGICAL_RESET_RSMRST, .chipset = 3U << 30 },
19 };
20 
21 /*
22  * The GPIO driver for Icelake on Windows/Linux expects 32 GPIOs per pad
23  * group, regardless of whether or not there is a physical pad for each
24  * exposed GPIO number.
25  *
26  * This results in the OS having a sparse GPIO map, and devices that need
27  * to export an ACPI GPIO must use the OS expected number.
28  *
29  * Not all pins are usable as GPIO and those groups do not have a pad base.
30  *
31  * This layout matches the Linux kernel pinctrl map for CNL-LP at:
32  * linux/drivers/pinctrl/intel/pinctrl-icelake.c
33  */
34 static const struct pad_group icl_community0_groups[] = {
35  INTEL_GPP_BASE(GPP_G0, GPP_G0, GPP_G7, 0), /* GPP_G */
36  INTEL_GPP_BASE(GPP_G0, GPP_B0, GPP_B23, 32), /* GPP_B */
38  INTEL_GPP_BASE(GPP_G0, GPP_A0, GPP_A23, 64), /* GPP_A */
39 };
40 
41 static const struct pad_group icl_community1_groups[] = {
42  INTEL_GPP_BASE(GPP_H0, GPP_H0, GPP_H23, 96), /* GPP_H */
43  INTEL_GPP_BASE(GPP_H0, GPP_D0, GPIO_RSVD_2, 128), /* GPP_D */
44  INTEL_GPP_BASE(GPP_H0, GPP_F0, GPP_F19, 160), /* GPP_F */
45 };
46 
47 /* This community is not visible to the OS */
48 static const struct pad_group icl_community2_groups[] = {
49  INTEL_GPP(GPD0, GPD0, GPD11), /* GPD */
50 };
51 
52 static const struct pad_group icl_community4_groups[] = {
53  INTEL_GPP_BASE(GPP_C0, GPP_C0, GPP_C23, 224), /* GPP_C */
54  INTEL_GPP(GPP_C0, EDP_BKLTEN, MLK_RST_B), /* HVCMOS */
55  INTEL_GPP_BASE(GPP_C0, GPP_E0, GPP_E23, 256), /* GPP_E */
57 };
58 
59 static const struct pad_group icl_community5_groups[] = {
60  INTEL_GPP_BASE(GPP_R0, GPP_R0, GPP_R7, 288), /* GPP_R */
61  INTEL_GPP_BASE(GPP_C0, GPP_S0, GPP_S7, 320), /* GPP_S */
62 };
63 
64 static const struct pad_community icl_communities[TOTAL_GPIO_COMM] = {
65  /* GPP G, B, A */
66  [COMM_0] = {
67  .port = PID_GPIOCOM0,
68  .first_pad = GPP_G0,
69  .last_pad = GPP_A23,
70  .num_gpi_regs = NUM_GPIO_COM0_GPI_REGS,
71  .pad_cfg_base = PAD_CFG_BASE,
72  .host_own_reg_0 = HOSTSW_OWN_REG_0,
73  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
74  .gpi_int_en_reg_0 = GPI_INT_EN_0,
75  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
76  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
77  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
78  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
79  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
80  .name = "GPP_GBA",
81  .acpi_path = "\\_SB.PCI0.GPIO",
82  .reset_map = rst_map_com0,
83  .num_reset_vals = ARRAY_SIZE(rst_map_com0),
84  .groups = icl_community0_groups,
85  .num_groups = ARRAY_SIZE(icl_community0_groups),
86  },
87  /* GPP H, D, F */
88  [COMM_1] = {
89  .port = PID_GPIOCOM1,
90  .first_pad = GPP_H0,
91  .last_pad = GPP_F19,
92  .num_gpi_regs = NUM_GPIO_COM1_GPI_REGS,
93  .pad_cfg_base = PAD_CFG_BASE,
94  .host_own_reg_0 = HOSTSW_OWN_REG_0,
95  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
96  .gpi_int_en_reg_0 = GPI_INT_EN_0,
97  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
98  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
99  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
100  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
101  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
102  .name = "GPP_HDF",
103  .acpi_path = "\\_SB.PCI0.GPIO",
104  .reset_map = rst_map,
105  .num_reset_vals = ARRAY_SIZE(rst_map),
106  .groups = icl_community1_groups,
107  .num_groups = ARRAY_SIZE(icl_community1_groups),
108  },
109  /* GPD */
110  [COMM_2] = {
111  .port = PID_GPIOCOM2,
112  .first_pad = GPD0,
113  .last_pad = GPD11,
114  .num_gpi_regs = NUM_GPIO_COM2_GPI_REGS,
115  .pad_cfg_base = PAD_CFG_BASE,
116  .host_own_reg_0 = HOSTSW_OWN_REG_0,
117  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
118  .gpi_int_en_reg_0 = GPI_INT_EN_0,
119  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
120  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
121  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
122  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
123  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
124  .name = "GPD",
125  .acpi_path = "\\_SB.PCI0.GPIO",
126  .reset_map = rst_map,
127  .num_reset_vals = ARRAY_SIZE(rst_map),
128  .groups = icl_community2_groups,
129  .num_groups = ARRAY_SIZE(icl_community2_groups),
130  },
131  /* GPP C, E */
132  [COMM_3] = {
133  .port = PID_GPIOCOM4,
134  .first_pad = GPP_C0,
135  .last_pad = GPP_E23,
136  .num_gpi_regs = NUM_GPIO_COM4_GPI_REGS,
137  .pad_cfg_base = PAD_CFG_BASE,
138  .host_own_reg_0 = HOSTSW_OWN_REG_0,
139  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
140  .gpi_int_en_reg_0 = GPI_INT_EN_0,
141  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
142  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
143  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
144  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
145  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
146  .name = "GPP_CE",
147  .acpi_path = "\\_SB.PCI0.GPIO",
148  .reset_map = rst_map,
149  .num_reset_vals = ARRAY_SIZE(rst_map),
150  .groups = icl_community4_groups,
151  .num_groups = ARRAY_SIZE(icl_community4_groups),
152  },
153  /* GPP R, S */
154  [COMM_4] = {
155  .port = PID_GPIOCOM5,
156  .first_pad = GPP_R0,
157  .last_pad = GPP_S7,
158  .num_gpi_regs = NUM_GPIO_COM5_GPI_REGS,
159  .pad_cfg_base = PAD_CFG_BASE,
160  .host_own_reg_0 = HOSTSW_OWN_REG_0,
161  .gpi_int_sts_reg_0 = GPI_INT_STS_0,
162  .gpi_int_en_reg_0 = GPI_INT_EN_0,
163  .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
164  .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
165  .gpi_nmi_sts_reg_0 = GPI_NMI_STS_0,
166  .gpi_nmi_en_reg_0 = GPI_NMI_EN_0,
167  .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
168  .name = "GPP_RS",
169  .acpi_path = "\\_SB.PCI0.GPIO",
170  .reset_map = rst_map,
171  .num_reset_vals = ARRAY_SIZE(rst_map),
172  .groups = icl_community5_groups,
173  .num_groups = ARRAY_SIZE(icl_community5_groups),
174  }
175 };
176 
177 const struct pad_community *soc_gpio_get_community(size_t *num_communities)
178 {
179  *num_communities = ARRAY_SIZE(icl_communities);
180  return icl_communities;
181 }
182 
183 const struct pmc_to_gpio_route *soc_pmc_gpio_routes(size_t *num)
184 {
185  static const struct pmc_to_gpio_route routes[] = {
186  { PMC_GPP_G, GPP_G },
187  { PMC_GPP_B, GPP_B },
188  { PMC_GPP_A, GPP_A },
189  { PMC_GPP_H, GPP_H },
190  { PMC_GPP_D, GPP_D },
191  { PMC_GPP_F, GPP_F },
192  { PMC_GPD, GPD },
193  { PMC_GPP_C, GPP_C },
194  { PMC_GPP_E, GPP_E },
195  { PMC_GPP_R, GPP_R },
196  { PMC_GPP_S, GPP_S }
197 
198  };
199  *num = ARRAY_SIZE(routes);
200  return routes;
201 }
#define GPD11
#define GPIO_MAX_NUM_PER_GROUP
Definition: gpio_soc_defs.h:31
#define COMM_0
Definition: gpio_soc_defs.h:33
#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_S0
#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 TOTAL_GPIO_COMM
#define GPP_S7
#define COMM_1
Definition: gpio_soc_defs.h:34
#define GPP_A23
#define GPP_E23
#define GPP_A0
#define COMM_3
Definition: gpio_soc_defs.h:36
#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_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 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 GPP_C0
#define GPP_F19
#define COMM_2
Definition: gpio_soc_defs.h:35
#define GPP_H23
#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 EDP_BKLTEN
#define GPP_G7
Definition: gpio_soc_defs.h:95
#define GPP_G0
Definition: gpio_soc_defs.h:88
#define GPP_G
Definition: gpio_soc_defs.h:13
@ PID_GPIOCOM0
Definition: pcr.h:17
@ PID_GPIOCOM1
Definition: pcr.h:18
#define GPIO_RSVD_1
Definition: gpio_soc_defs.h:61
#define GPIO_RSVD_8
#define GPIO_RSVD_0
Definition: gpio_soc_defs.h:60
#define GPIO_RSVD_3
#define GPIO_RSVD_2
#define MLK_RST_B
#define PMC_GPP_H
Definition: pmc.h:124
#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_G
Definition: pmc.h:137
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 pad_group icl_community5_groups[]
Definition: gpio.c:59
static const struct pad_group icl_community4_groups[]
Definition: gpio.c:52
static const struct pad_group icl_community0_groups[]
Definition: gpio.c:34
static const struct pad_group icl_community2_groups[]
Definition: gpio.c:48
static const struct reset_mapping rst_map_com0[]
Definition: gpio.c:14
static const struct reset_mapping rst_map[]
Definition: gpio.c:8
static const struct pad_group icl_community1_groups[]
Definition: gpio.c:41
static const struct pad_community icl_communities[TOTAL_GPIO_COMM]
Definition: gpio.c:64
uint8_t port
Definition: gpio.h:135
Definition: gpio.h:94
uint32_t logical
Definition: gpio.h:89