coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio_baseboard_dalboz.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <baseboard/variants.h>
4 #include <delay.h>
5 #include <gpio.h>
6 #include <soc/gpio.h>
7 #include <soc/smi.h>
8 #include <variant/gpio.h>
9 
10 static const struct soc_amd_gpio gpio_set_stage_ram[] = {
11  /* PWR_BTN_L */
12  PAD_NF(GPIO_0, PWR_BTN_L, PULL_NONE),
13  /* SYS_RESET_L */
14  PAD_NF(GPIO_1, SYS_RESET_L, PULL_NONE),
15  /* WIFI_PCIE_WAKE_ODL */
16  PAD_NF_SCI(GPIO_2, WAKE_L, PULL_NONE, EDGE_LOW),
17  /* H1_FCH_INT_ODL */
18  PAD_INT(GPIO_3, PULL_NONE, EDGE_LOW, STATUS_DELIVERY),
19  /* PEN_DETECT_ODL */
20  PAD_WAKE(GPIO_4, PULL_NONE, EDGE_HIGH, S3),
21  /* PEN_POWER_EN - Enabled*/
22  PAD_GPO(GPIO_5, HIGH),
23  /* EN_PWR_TOUCHPAD */
24  PAD_GPO(GPIO_6, HIGH),
25  /* I2S_SDIN */
26  PAD_NF(GPIO_7, ACP_I2S_SDIN, PULL_NONE),
27  /* I2S_LRCLK - Bit banged in depthcharge */
28  PAD_NF(GPIO_8, ACP_I2S_LRCLK, PULL_NONE),
29  /* TOUCHPAD_INT_ODL */
30  PAD_SCI(GPIO_9, PULL_NONE, LEVEL_LOW),
31  /* S0iX SLP - goes to EC */
32  PAD_GPO(GPIO_10, HIGH),
33  /* EC_IN_RW_OD */
35  /* USI_INT_ODL */
37  /* GPIO_13 - GPIO_15: Not available */
38  /* USB_OC0_L - USB C0/A0 */
39  PAD_NF(GPIO_16, USB_OC0_L, PULL_NONE),
40  /* USB_OC1_L - USB C1 */
41  PAD_NF(GPIO_17, USB_OC1_L, PULL_NONE),
42  /* WIFI_DISABLE */
43  PAD_GPO(GPIO_18, LOW),
44  /* I2C3_SCL - H1 */
45  PAD_NF(GPIO_19, I2C3_SCL, PULL_NONE),
46  /* I2C3_SDA - H1 */
47  PAD_NF(GPIO_20, I2C3_SDA, PULL_NONE),
48  /* EMMC_CMD */
49  PAD_NF(GPIO_21, EMMC_CMD, PULL_NONE),
50  /* EC_FCH_SCI_ODL */
51  PAD_SCI(GPIO_22, PULL_NONE, EDGE_LOW),
52  /* AC_PRES */
53  PAD_NF(GPIO_23, AC_PRES, PULL_UP),
54  /* EC_FCH_WAKE_L */
55  PAD_SCI(GPIO_24, PULL_NONE, EDGE_LOW),
56  /* GPIO_25: Not available */
57  /* PCIE_RST0_L - Fixed timings */
58  PAD_NF(GPIO_26, PCIE_RST_L, PULL_NONE),
59  /* GPIO_27: Configured in bootblock. */
60  /* GPIO_28: Not available */
61  /* GPIO_29: Handled in bootblock for wifi power/reset control. */
62  /* FCH_ESPI_EC_CS_L */
63  PAD_NF(GPIO_30, ESPI_CS_L, PULL_NONE),
64  /* EC_AP_INT_ODL (Sensor Framesync) */
66  /* EN_PWR_TOUCHSCREEN */
67  PAD_GPO(GPIO_32, LOW),
68  /* GPIO_33 - GPIO_39: Not available */
69  /* NVME_AUX_RESET_L */
70  PAD_GPO(GPIO_40, HIGH),
71  /* GPIO_41: Not available */
72  /* GPIO_42: Handled in bootblock for wifi power/reset control. */
73  /* GPIO_43 - GPIO_66: Not available */
74  /* DMIC_SEL */
75  /*
76  * Make sure Ext ROM Sharing is disabled before using this GPIO. Otherwise SPI flash
77  * access will be very slow.
78  */
79  PAD_GPO(GPIO_67, LOW), // Select Camera 1 Dmic
80  /* EMMC_RESET_L */
81  PAD_GPO(GPIO_68, HIGH),
82  /* RAM ID 3 */
84  /* EMMC_CLK */
85  PAD_NF(GPIO_70, EMMC_CLK, PULL_NONE),
86  /* GPIO_71 - GPIO_73: Not available */
87  /* EMMC_DATA4 */
88  PAD_NF(GPIO_74, EMMC_DATA4, PULL_NONE),
89  /* EMMC_DATA6 */
90  PAD_NF(GPIO_75, EMMC_DATA6, PULL_NONE),
91  /* EN_PWR_CAMERA */
92  PAD_GPO(GPIO_76, HIGH),
93  /* GPIO_77 - GPIO_83: Not available */
94  /* HP_INT_ODL */
96  /* APU_EDP_BL_DISABLE */
97  PAD_GPO(GPIO_85, LOW),
98  /* RAM ID 2 - Keep High */
99  PAD_GPO(GPIO_86, HIGH),
100  /* EMMC_DATA7 */
101  PAD_NF(GPIO_87, EMMC_DATA7, PULL_NONE),
102  /* EMMC_DATA5 */
103  PAD_NF(GPIO_88, EMMC_DATA5, PULL_NONE),
104  /* GPIO_89 - unused */
105  PAD_NC(GPIO_89),
106  /* RAM ID 1 */
108  /* EN_SPKR */
109  PAD_GPO(GPIO_91, LOW),
110  /* CLK_REQ0_L - WIFI */
111  PAD_NF(GPIO_92, CLK_REQ0_L, PULL_NONE),
112  /* GPIO_93 - GPIO_103: Not available */
113  /* EMMC_DATA0 */
114  PAD_NF(GPIO_104, EMMC_DATA0, PULL_NONE),
115  /* EMMC_DATA1 */
116  PAD_NF(GPIO_105, EMMC_DATA1, PULL_NONE),
117  /* EMMC_DATA2 */
118  PAD_NF(GPIO_106, EMMC_DATA2, PULL_NONE),
119  /* EMMC_DATA3 */
120  PAD_NF(GPIO_107, EMMC_DATA3, PULL_NONE),
121  /* ESPI_ALERT_L */
122  PAD_NF(GPIO_108, ESPI_ALERT_L, PULL_UP),
123  /* EMMC_DS */
124  PAD_NF(GPIO_109, EMMC_DS, PULL_NONE),
125  /* GPIO_110 - GPIO112: Not available */
126  /* I2C2_SCL - USI/Touchpad */
127  PAD_NF(GPIO_113, I2C2_SCL, PULL_NONE),
128  /* I2C2_SDA - USI/Touchpad */
129  PAD_NF(GPIO_114, I2C2_SDA, PULL_NONE),
130  /* CLK_REQ1_L - SD Card */
131  PAD_NF(GPIO_115, CLK_REQ1_L, PULL_NONE),
132  /* CLK_REQ2_L - NVMe */
133  PAD_NF(GPIO_116, CLK_REQ2_L, PULL_NONE),
134  /* GPIO_117 - GPIO_128: Not available */
135  /* KBRST_L */
136  PAD_NF(GPIO_129, KBRST_L, PULL_NONE),
137  /* GPIO_130 - GPIO_131: Not available */
138  /* RAM ID 0 */
140  /* GPIO_133 - GPIO_134: Not available */
141  /* DEV_BEEP_CODEC_IN (Dev beep Data out) */
143  /* UART0_RXD - DEBUG */
144  PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
145  /* BIOS_FLASH_WP_ODL */
147  /* UART0_TXD - DEBUG */
148  PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
149  /* DEV_BEEP_BCLK */
151  /* USI_RESET_L */
152  PAD_GPO(GPIO_140, LOW),
153  /* USB_HUB_RST_L */
154  PAD_GPO(GPIO_141, HIGH),
155  /* SD_AUX_RESET_L */
156  PAD_GPO(GPIO_142, HIGH),
157  /* BT_DISABLE */
158  PAD_GPO(GPIO_143, LOW),
159  /* USI_REPORT_EN */
160  PAD_GPO(GPIO_144, LOW),
161 };
162 
163 const __weak
165 {
167  return gpio_set_stage_ram;
168 }
169 
171 {
172  /*
173  * Configure WiFi GPIOs such that:
174  * - WIFI_AUX_RESET is configured first to assert PERST# to WiFi device.
175  * - Enable power to WiFi using EN_PWR_WIFI_L.
176  * - Wait for 50ms after power to WiFi is enabled.
177  * - Deassert WIFI_AUX_RESET.
178  */
179  static const struct soc_amd_gpio v3_wifi_table[] = {
180  /* WIFI_AUX_RESET */
181  PAD_GPO(GPIO_29, HIGH),
182  /* EN_PWR_WIFI_L */
183  PAD_GPO(GPIO_42, LOW),
184  };
185  gpio_configure_pads(v3_wifi_table, ARRAY_SIZE(v3_wifi_table));
186 
187  mdelay(50);
188  gpio_set(GPIO_29, 0);
189 }
190 
192 {
193  /*
194  * When GPIO_42 is configured as active high for enabling WiFi power, WIFI_AUX_RESET
195  * gets pulled high because of external PU to PP3300_WIFI. Thus, EN_PWR_WIFI needs to be
196  * set low before driving it high to trigger a WiFi power cycle to meet PCIe
197  * requirements. Thus, configure GPIOs such that:
198  * - WIFI_AUX_RESET is configured first to assert PERST# to WiFi device
199  * - Disable power to WiFi.
200  * - Wait 10ms for WiFi power to go low.
201  * - Enable power to WiFi using EN_PWR_WIFI.
202  * - Deassert WIFI_AUX_RESET.
203  */
204  static const struct soc_amd_gpio v3_wifi_table[] = {
205  /* WIFI_AUX_RESET */
206  PAD_GPO(GPIO_29, HIGH),
207  /* EN_PWR_WIFI */
208  PAD_GPO(GPIO_42, LOW),
209  };
210  gpio_configure_pads(v3_wifi_table, ARRAY_SIZE(v3_wifi_table));
211 
212  mdelay(10);
213  gpio_set(GPIO_42, 1);
214  mdelay(50);
215  gpio_set(GPIO_29, 0);
216 }
217 
219 {
222  else
224 }
225 
227 {
228  /*
229  * Configure WiFi GPIOs such that:
230  * - WIFI_AUX_RESET_L is configured first to assert PERST# to WiFi device.
231  * - Disable power to WiFi since GPIO_29 goes high on PWRGOOD but has a glitch on RESET#
232  * deassertion causing WiFi to enter a bad state.
233  * - Wait 10ms for WiFi power to go low.
234  * - Enable power to WiFi using EN_PWR_WIFI.
235  * - Wait for 50ms after power to WiFi is enabled.
236  * - Deassert WIFI_AUX_RESET_L.
237  */
238  static const struct soc_amd_gpio pre_v3_wifi_table[] = {
239  /* WIFI_AUX_RESET_L */
240  PAD_GPO(GPIO_42, LOW),
241  /* EN_PWR_WIFI */
242  PAD_GPO(GPIO_29, LOW),
243  };
244  gpio_configure_pads(pre_v3_wifi_table, ARRAY_SIZE(pre_v3_wifi_table));
245 
246  mdelay(10);
247  gpio_set(GPIO_29, 1);
248  mdelay(50);
249  gpio_set(GPIO_42, 1);
250 }
251 
253 {
254  static const struct soc_amd_gpio pcie_gpio_table[] = {
255  /* PCIE_RST1_L - Variable timings (May remove) */
256  PAD_NF(GPIO_27, PCIE_RST1_L, PULL_NONE),
257  /* NVME_AUX_RESET_L */
258  PAD_GPO(GPIO_40, HIGH),
259  /* CLK_REQ0_L - WIFI */
260  PAD_NF(GPIO_92, CLK_REQ0_L, PULL_NONE),
261  /* CLK_REQ1_L - SD Card */
262  PAD_NF(GPIO_115, CLK_REQ1_L, PULL_NONE),
263  /* CLK_REQ2_L - NVMe */
264  PAD_NF(GPIO_116, CLK_REQ2_L, PULL_NONE),
265  /* SD_AUX_RESET_L */
266  PAD_GPO(GPIO_142, HIGH),
267  };
268 
270 
271  /* Deassert PCIE_RST1_L */
272  gpio_set(GPIO_27, 1);
273 
276  else
278 }
279 
280 __weak void finalize_gpios(int slp_typ)
281 {
282 }
283 
284 const __weak struct soc_amd_gpio *variant_bootblock_gpio_table(size_t *size, int slp_typ)
285 {
286  *size = 0;
287  return NULL;
288 }
289 
290 static const struct soc_amd_gpio gpio_sleep_table[] = {
291  /* S0iX SLP */
292  PAD_GPO(GPIO_10, LOW),
293  /* PCIE_RST1_L */
294  PAD_GPO(GPIO_27, LOW),
295  /*
296  * On pre-v3 schematics, GPIO_29 is EN_PWR_WIFI. So, setting to high should be no-op.
297  * On v3+ schematics, GPIO_29 is WIFI_AUX_RESET. Setting to high ensures that PERST# is
298  * asserted to WiFi device until coreboot reconfigures GPIO_29 on resume path.
299  */
300  PAD_GPO(GPIO_29, HIGH),
301  /* NVME_AUX_RESET_L */
302  PAD_GPO(GPIO_40, LOW),
303  /* EN_PWR_CAMERA */
304  PAD_GPO(GPIO_76, LOW),
305 };
306 
307 const __weak struct soc_amd_gpio *variant_sleep_gpio_table(size_t *size, int slp_typ)
308 {
309  *size = ARRAY_SIZE(gpio_sleep_table);
310  return gpio_sleep_table;
311 }
312 
313 static const struct soc_amd_gpio espi_gpio_table[] = {
314  /* PCIE_RST0_L - Fixed timings */
315  PAD_NF(GPIO_26, PCIE_RST_L, PULL_NONE),
316  /* FCH_ESPI_EC_CS_L */
317  PAD_NF(GPIO_30, ESPI_CS_L, PULL_NONE),
318  /* ESPI_ALERT_L */
319  PAD_NF(GPIO_108, ESPI_ALERT_L, PULL_NONE),
320 };
321 
322 const __weak struct soc_amd_gpio *variant_espi_gpio_table(size_t *size)
323 {
324  *size = ARRAY_SIZE(espi_gpio_table);
325  return espi_gpio_table;
326 }
327 
328 static const struct soc_amd_gpio tpm_gpio_table[] = {
329  /* H1_FCH_INT_ODL */
330  PAD_INT(GPIO_3, PULL_NONE, EDGE_LOW, STATUS),
331  /* I2C3_SCL - H1 */
332  PAD_NF(GPIO_19, I2C3_SCL, PULL_NONE),
333  /* I2C3_SDA - H1 */
334  PAD_NF(GPIO_20, I2C3_SDA, PULL_NONE),
335  /* EC_IN_RW_OD */
337 };
338 
339 const __weak struct soc_amd_gpio *variant_tpm_gpio_table(size_t *size)
340 {
341  *size = ARRAY_SIZE(tpm_gpio_table);
342  return tpm_gpio_table;
343 }
344 
345 static const struct soc_amd_gpio early_gpio_table[] = {
346  /* UART0_RXD - DEBUG */
347  PAD_NF(GPIO_136, UART0_RXD, PULL_NONE),
348  /* UART0_TXD - DEBUG */
349  PAD_NF(GPIO_138, UART0_TXD, PULL_NONE),
350 };
351 
352 const struct soc_amd_gpio *variant_early_gpio_table(size_t *size)
353 {
354  *size = ARRAY_SIZE(early_gpio_table);
355  return early_gpio_table;
356 }
#define GPIO_10
Definition: gpio_ftns.h:12
#define GPIO_18
Definition: gpio_ftns.h:17
#define GPIO_17
Definition: gpio_ftns.h:16
#define GPIO_16
Definition: gpio_ftns.h:15
#define GPIO_11
Definition: gpio_ftns.h:13
#define GPIO_22
Definition: gpio_ftns.h:14
#define GPIO_32
Definition: gpio_ftns.h:15
#define GPIO_68
Definition: gpio_ftns.h:26
#define ARRAY_SIZE(a)
Definition: helpers.h:12
void mdelay(unsigned int msecs)
Definition: delay.c:2
static const struct soc_amd_gpio tpm_gpio_table[]
__weak void finalize_gpios(int slp_typ)
const __weak struct soc_amd_gpio * variant_bootblock_gpio_table(size_t *size, int slp_typ)
const __weak struct soc_amd_gpio * variant_base_gpio_table(size_t *size)
static const struct soc_amd_gpio early_gpio_table[]
const __weak struct soc_amd_gpio * variant_espi_gpio_table(size_t *size)
const struct soc_amd_gpio * variant_early_gpio_table(size_t *size)
static const struct soc_amd_gpio gpio_sleep_table[]
const __weak struct soc_amd_gpio * variant_sleep_gpio_table(size_t *size, int slp_typ)
static void wifi_power_reset_configure_active_low_power(void)
const __weak struct soc_amd_gpio * variant_tpm_gpio_table(size_t *size)
static void wifi_power_reset_configure_v3(void)
static void wifi_power_reset_configure_active_high_power(void)
static const struct soc_amd_gpio espi_gpio_table[]
__weak void variant_pcie_gpio_configure(void)
static const struct soc_amd_gpio gpio_set_stage_ram[]
static void wifi_power_reset_configure_pre_v3(void)
#define PULL_UP
Definition: buildOpts.c:70
#define PULL_NONE
Definition: buildOpts.c:72
void gpio_set(gpio_t gpio, int value)
Definition: gpio.c:174
static const struct soc_amd_gpio pcie_gpio_table[]
Definition: gpio.c:276
@ S3
Definition: smihandler.c:21
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
#define GPIO_91
Definition: gpio.h:67
#define GPIO_30
Definition: gpio.h:46
#define GPIO_76
Definition: gpio.h:59
#define GPIO_27
Definition: gpio.h:44
#define GPIO_0
Definition: gpio.h:21
#define GPIO_7
Definition: gpio.h:28
#define GPIO_90
Definition: gpio.h:66
#define GPIO_143
Definition: gpio.h:90
#define GPIO_89
Definition: gpio.h:65
#define GPIO_69
Definition: gpio.h:55
#define GPIO_12
Definition: gpio.h:33
#define GPIO_1
Definition: gpio.h:22
#define GPIO_5
Definition: gpio.h:26
#define GPIO_113
Definition: gpio.h:75
#define GPIO_104
Definition: gpio.h:69
#define GPIO_88
Definition: gpio.h:64
#define GPIO_84
Definition: gpio.h:60
#define GPIO_105
Definition: gpio.h:70
#define GPIO_8
Definition: gpio.h:29
#define GPIO_141
Definition: gpio.h:88
#define GPIO_67
Definition: gpio.h:53
#define GPIO_24
Definition: gpio.h:42
#define GPIO_132
Definition: gpio.h:86
#define GPIO_4
Definition: gpio.h:25
#define GPIO_107
Definition: gpio.h:72
#define GPIO_129
Definition: gpio.h:83
#define GPIO_140
Definition: gpio.h:87
#define GPIO_20
Definition: gpio.h:38
#define GPIO_92
Definition: gpio.h:68
#define GPIO_19
Definition: gpio.h:37
#define GPIO_70
Definition: gpio.h:56
#define GPIO_116
Definition: gpio.h:78
#define GPIO_115
Definition: gpio.h:77
#define GPIO_108
Definition: gpio.h:73
#define GPIO_109
Definition: gpio.h:74
#define GPIO_31
Definition: gpio.h:47
#define GPIO_9
Definition: gpio.h:30
#define GPIO_26
Definition: gpio.h:43
#define GPIO_29
Definition: gpio.h:45
#define GPIO_75
Definition: gpio.h:58
#define GPIO_86
Definition: gpio.h:62
#define GPIO_87
Definition: gpio.h:63
#define GPIO_3
Definition: gpio.h:24
#define GPIO_142
Definition: gpio.h:89
#define GPIO_144
Definition: gpio.h:91
#define GPIO_106
Definition: gpio.h:71
#define GPIO_85
Definition: gpio.h:61
#define GPIO_2
Definition: gpio.h:23
#define GPIO_21
Definition: gpio.h:39
#define GPIO_40
Definition: gpio.h:49
#define GPIO_42
Definition: gpio.h:50
#define GPIO_114
Definition: gpio.h:76
#define GPIO_23
Definition: gpio.h:41
#define GPIO_74
Definition: gpio.h:57
#define GPIO_6
Definition: gpio.h:27
void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size)
program a particular set of GPIO
Definition: gpio.c:307
#define PAD_WAKE(pin, pull, trigger, type)
Definition: gpio_defs.h:247
#define PAD_SCI(pin, pull, trigger)
Definition: gpio_defs.h:229
#define PAD_NC(pin)
Definition: gpio_defs.h:263
#define PAD_NF_SCI(pin, func, pull, trigger)
Definition: gpio_defs.h:241
#define PAD_GPO(pin, direction)
Definition: gpio_defs.h:220
#define PAD_NF(pin, func, pull)
Definition: gpio_defs.h:208
#define PAD_INT(pin, pull, trigger, action)
Definition: gpio_defs.h:224
#define PAD_GPI(pin, pull)
Definition: gpio_defs.h:216
#define GPIO_139
Definition: gpio.h:94
#define GPIO_136
Definition: gpio.h:91
#define GPIO_137
Definition: gpio.h:92
#define GPIO_138
Definition: gpio.h:93
#define GPIO_135
Definition: gpio.h:90
#define NULL
Definition: stddef.h:19
bool variant_uses_v3_schematics(void)
Definition: helpers.c:124
bool variant_has_active_low_wifi_power(void)
Definition: helpers.c:165