diff --git a/src/board/system76/darp9/board.c b/src/board/system76/darp9/board.c new file mode 100644 index 0000000..c132500 --- /dev/null +++ b/src/board/system76/darp9/board.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#include +#include +#include +#include +#include + +void board_init(void) { + espi_init(); + + // Make sure charger is in off state, also enables PSYS + battery_charger_disable(); + + // Allow CPU to boot + gpio_set(&SB_KBCRST_N, true); + // Allow backlight to be turned on + gpio_set(&BKL_EN, true); + // Enable camera + gpio_set(&CCD_EN, true); + // Assert SWI# + gpio_set(&SWI_N, true); +} + +void board_event(void) { + espi_event(); + + ec_read_post_codes(); +} diff --git a/src/board/system76/darp9/board.mk b/src/board/system76/darp9/board.mk new file mode 100644 index 0000000..f3ce210 --- /dev/null +++ b/src/board/system76/darp9/board.mk @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-3.0-only + +board-y += board.c +board-y += gpio.c + +EC=ite +CONFIG_EC_ITE_IT5570E=y + +# Enable eSPI +CONFIG_BUS_ESPI=y + +# Enable firmware security +CONFIG_SECURITY=y + +# Include keyboard +KEYBOARD=15in_102 + +# Set keyboard LED mechanism +KBLED=rgb_pwm + +# Set battery I2C bus +CFLAGS+=-DI2C_SMBUS=I2C_4 + +# Set touchpad PS2 bus +CFLAGS+=-DPS2_TOUCHPAD=PS2_3 + +# Set smart charger parameters +CFLAGS+=\ + -DCHARGER_ADAPTER_RSENSE=5 \ + -DCHARGER_BATTERY_RSENSE=5 \ + -DCHARGER_CHARGE_CURRENT=3072 \ + -DCHARGER_CHARGE_VOLTAGE=8800 \ + -DCHARGER_INPUT_CURRENT=4740 + +# Set CPU power limits in watts +CFLAGS+=\ + -DPOWER_LIMIT_AC=65 \ + -DPOWER_LIMIT_DC=45 + +# Add system76 common code +include src/board/system76/common/common.mk diff --git a/src/board/system76/darp9/gpio.c b/src/board/system76/darp9/gpio.c new file mode 100644 index 0000000..bc0e0bb --- /dev/null +++ b/src/board/system76/darp9/gpio.c @@ -0,0 +1,267 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#include +#include + +// clang-format off +struct Gpio __code ACIN_N = GPIO(B, 0); +struct Gpio __code AC_PRESENT = GPIO(E, 1); +struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0); +struct Gpio __code BKL_EN = GPIO(H, 2); +struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2); // renamed to EC_ERST# +struct Gpio __code CCD_EN = GPIO(D, 1); +struct Gpio __code CPU_C10_GATE_N = GPIO(D, 3); +struct Gpio __code DD_ON = GPIO(E, 4); +struct Gpio __code EC_EN = GPIO(B, 6); // renamed to SUSBC_EC# +struct Gpio __code EC_RSMRST_N = GPIO(E, 5); +struct Gpio __code LAN_WAKEUP_N = GPIO(H, 4); +struct Gpio __code LED_ACIN = GPIO(C, 7); +struct Gpio __code LED_BAT_CHG = GPIO(H, 5); +struct Gpio __code LED_BAT_FULL = GPIO(J, 0); +struct Gpio __code LED_PWR = GPIO(D, 0); +struct Gpio __code LID_SW_N = GPIO(B, 1); +struct Gpio __code ME_WE = GPIO(D, 4); +struct Gpio __code PCH_DPWROK_EC = GPIO(B, 2); +struct Gpio __code PCH_PWROK_EC = GPIO(A, 4); +struct Gpio __code PD_EN = GPIO(H, 7); // renamed to PD_POWER_EN +struct Gpio __code PWR_BTN_N = GPIO(D, 5); +struct Gpio __code PWR_SW_N = GPIO(B, 3); +struct Gpio __code SB_KBCRST_N = GPIO(E, 6); +struct Gpio __code SLP_S0_N = GPIO(J, 3); +struct Gpio __code SLP_SUS_N = GPIO(J, 7); +struct Gpio __code SUSB_N_PCH = GPIO(H, 6); +struct Gpio __code SUSC_N_PCH = GPIO(H, 1); +struct Gpio __code SWI_N = GPIO(B, 5); +struct Gpio __code VA_EC_EN = GPIO(J, 4); +struct Gpio __code WLAN_EN = GPIO(F, 3); +struct Gpio __code WLAN_PWR_EN = GPIO(G, 1); +struct Gpio __code XLP_OUT = GPIO(B, 4); +// clang-format on + +void gpio_init(void) { + // PWRSW WDT 2 Enable 2 + GCR9 = BIT(5); + // PWRSW WDT 2 Enable 1 + GCR8 = BIT(4); + + // Enable LPC reset on GPD2 + GCR = 0b10 << 1; + // Disable UARTs + GCR6 = 0; + // Enable SMBus channel 4 + GCR15 = BIT(4); + // Set GPD2 to 1.8V + GCR19 = BIT(0); + // Set GPF2 and GPF3 to 3.3V + GCR20 = 0; + + // Not documented + //GCR22 = BIT(7); + // Set GPM6 power domain to VCC + //GCR23 = BIT(0); + + // Set GPIO data + GPDRA = 0; + // XLP_OUT, PWR_SW#, PCH_DPWROK_EC + GPDRB = BIT(4) | BIT(3) | BIT(2); + GPDRC = 0; + // PWR_BTN# + GPDRD = BIT(5); + // USB_PWR_EN + GPDRE = BIT(3); + // H_PECI + GPDRF = BIT(6); + // H_PROCHOT_EC# + GPDRG = BIT(6); + GPDRH = 0; + GPDRI = 0; + // KBC_MUTE# + GPDRJ = BIT(1); + GPDRM = 0; + + // Set GPIO control + // EC_PWM_LEDKB_P + GPCRA0 = GPIO_ALT; + // KBC_BEEP + GPCRA1 = GPIO_ALT; + // CPU_FAN + GPCRA2 = GPIO_ALT; + // NC (JACK_IN#_EC) + GPCRA3 = GPIO_IN; + // PCH_PWROK_EC + GPCRA4 = GPIO_OUT | GPIO_UP; + // EC_PWM_LEDKB_R + GPCRA5 = GPIO_ALT; + // EC_PWM_LEDKB_G + GPCRA6 = GPIO_ALT; + // EC_PWM_LEDKB_B + GPCRA7 = GPIO_ALT; + + // AC_IN# + GPCRB0 = GPIO_IN | GPIO_UP; + // LID_SW# + GPCRB1 = GPIO_IN | GPIO_UP; + // PCH_DPWROK_EC + GPCRB2 = GPIO_OUT | GPIO_UP; + // PWR_SW# + GPCRB3 = GPIO_IN; + // XLP_OUT + GPCRB4 = GPIO_OUT; + // SWI# + GPCRB5 = GPIO_OUT | GPIO_UP; + // SUSBC_EC# + GPCRB6 = GPIO_OUT | GPIO_UP; + // Missing + GPCRB7 = GPIO_IN | GPIO_DOWN; + + // ALL_SYS_PWRGD + GPCRC0 = GPIO_IN; + // SMC_VGA_THERM + GPCRC1 = GPIO_ALT | GPIO_UP; + // SMD_VGA_THERM + GPCRC2 = GPIO_ALT | GPIO_UP; + // KB-SO16 + GPCRC3 = GPIO_ALT | GPIO_UP; + // CNVI_DET# + GPCRC4 = GPIO_IN | GPIO_UP; + // KB-SO17 + GPCRC5 = GPIO_ALT | GPIO_UP; + // Not connected + GPCRC6 = GPIO_IN | GPIO_DOWN; + // LED_ACIN + GPCRC7 = GPIO_OUT | GPIO_UP; + + // LED_PWR + GPCRD0 = GPIO_OUT | GPIO_UP; + // CCD_EN + GPCRD1 = GPIO_OUT | GPIO_UP; + // EC_ERST# + GPCRD2 = GPIO_ALT; + // CPU_C10_GATE# + GPCRD3 = GPIO_IN | GPIO_DOWN; + // ME_WE + GPCRD4 = GPIO_OUT; + // PWR_BTN# + GPCRD5 = GPIO_OUT | GPIO_UP; + // CPU_FANSEN + GPCRD6 = GPIO_ALT; + // SINK_CTRL_EC + GPCRD7 = GPIO_IN; + + // SMC_BAT + GPCRE0 = GPIO_ALT | GPIO_UP; + // AC_PRESENT + GPCRE1 = GPIO_OUT | GPIO_UP; + // ACE_I2C_IRQ2Z + GPCRE2 = GPIO_IN; + // USB_PWR_EN + GPCRE3 = GPIO_OUT; + // DD_ON + GPCRE4 = GPIO_OUT | GPIO_DOWN; + // EC_RSMRST# + GPCRE5 = GPIO_OUT; + // SB_KBCRST# + GPCRE6 = GPIO_IN; + // SMD_BAT + GPCRE7 = GPIO_ALT | GPIO_UP; + + // 80CLK + GPCRF0 = GPIO_IN; + // USB_CHARGE_EN + GPCRF1 = GPIO_OUT | GPIO_UP; + // 3IN1 + GPCRF2 = GPIO_IN | GPIO_UP; + // WLAN_EN + GPCRF3 = GPIO_OUT | GPIO_UP; + // TP_CLK + GPCRF4 = GPIO_ALT; + // TP_DATA + GPCRF5 = GPIO_ALT; + // H_PECI + GPCRF6 = GPIO_ALT; + // CC_EN + GPCRF7 = GPIO_OUT | GPIO_UP; + + // VCCIN_AUX_PG + GPCRG0 = GPIO_IN; + // WLAN_PWR_EN + GPCRG1 = GPIO_OUT | GPIO_UP; + // AUTO_LOAD_PWR + GPCRG2 = GPIO_IN; + // HSPI_CE# + GPCRG3 = GPIO_ALT; + // HSPI_MSI + GPCRG4 = GPIO_ALT; + // HSPI_MSO + GPCRG5 = GPIO_ALT; + // H_PROCHOT_EC# + GPCRG6 = GPIO_OUT | GPIO_UP; + // HSPI_SCLK + GPCRG7 = GPIO_ALT; + + // EC_GPIO + GPCRH0 = GPIO_OUT | GPIO_UP; + // SUSC#_PCH + GPCRH1 = GPIO_IN; + // BKL_EN + GPCRH2 = GPIO_OUT | GPIO_UP; + // PCIE_WAKE# + GPCRH3 = GPIO_IN; + // EC_LAN_WAKEUP# + GPCRH4 = GPIO_IN | GPIO_UP; + // LED_BAT_CHG + GPCRH5 = GPIO_OUT; + // SUSB#_PCH + GPCRH6 = GPIO_IN; + // PD_POWER_EN + GPCRH7 = GPIO_OUT; + + // BAT_DET + GPCRI0 = GPIO_ALT; + // BAT_VOLT + GPCRI1 = GPIO_ALT; + // RGBKB-DET# + GPCRI2 = GPIO_IN | GPIO_UP; + // THERM_VOLT_CPU + GPCRI3 = GPIO_ALT; + // TOTAL_CUR + GPCRI4 = GPIO_ALT; + // NC (USB_CC1) + GPCRI5 = GPIO_IN | GPIO_UP; + // NC (USB_CC2) + GPCRI6 = GPIO_IN | GPIO_UP; + // MODEL_ID + GPCRI7 = GPIO_IN; + + // LED_BAT_FULL + GPCRJ0 = GPIO_OUT | GPIO_UP; + // KBC_MUTE# + GPCRJ1 = GPIO_OUT; + // NC (EC_SDCARD_WAKEUP#) + GPCRJ2 = GPIO_IN | GPIO_DOWN; + // SLP_S0# + GPCRJ3 = GPIO_IN; + // VA_EC_EN + GPCRJ4 = GPIO_OUT; + // VBATT_BOOST# + GPCRJ5 = GPIO_OUT; + // SLP_WLAN# + GPCRJ6 = GPIO_IN; + // SLP_SUS# + GPCRJ7 = GPIO_IN; + + // ESPI_IO0_EC + GPCRM0 = GPIO_ALT | GPIO_UP | GPIO_DOWN; + // ESPI_IO1_EC + GPCRM1 = GPIO_ALT | GPIO_UP | GPIO_DOWN; + // ESPI_IO2_EC + GPCRM2 = GPIO_ALT | GPIO_UP | GPIO_DOWN; + // ESPI_IO3_EC + GPCRM3 = GPIO_ALT | GPIO_UP | GPIO_DOWN; + // ESPI_CLK_EC + GPCRM4 = GPIO_ALT | GPIO_UP | GPIO_DOWN; + // ESPI_CS_EC# + GPCRM5 = GPIO_ALT; + // ESPI_ALRT0# + GPCRM6 = GPIO_IN | GPIO_UP | GPIO_DOWN; +} diff --git a/src/board/system76/darp9/include/board/gpio.h b/src/board/system76/darp9/include/board/gpio.h new file mode 100644 index 0000000..70bc8f2 --- /dev/null +++ b/src/board/system76/darp9/include/board/gpio.h @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#ifndef _BOARD_GPIO_H +#define _BOARD_GPIO_H + +#include + +void gpio_init(void); + +// clang-format off +extern struct Gpio __code ACIN_N; +extern struct Gpio __code AC_PRESENT; +extern struct Gpio __code ALL_SYS_PWRGD; +extern struct Gpio __code BKL_EN; +#define HAVE_BT_EN 0 +extern struct Gpio __code BUF_PLT_RST_N; +extern struct Gpio __code CCD_EN; +extern struct Gpio __code CPU_C10_GATE_N; +extern struct Gpio __code DD_ON; +extern struct Gpio __code EC_EN; +extern struct Gpio __code EC_RSMRST_N; +extern struct Gpio __code LAN_WAKEUP_N; +extern struct Gpio __code LED_ACIN; +#define HAVE_LED_AIRPLANE_N 0 +extern struct Gpio __code LED_BAT_CHG; +extern struct Gpio __code LED_BAT_FULL; +extern struct Gpio __code LED_PWR; +extern struct Gpio __code LID_SW_N; +extern struct Gpio __code ME_WE; +extern struct Gpio __code PCH_DPWROK_EC; +extern struct Gpio __code PCH_PWROK_EC; +#define HAVE_PD_EN 1 +extern struct Gpio __code PD_EN; +#define HAVE_PM_PWROK 0 +extern struct Gpio __code PWR_BTN_N; +extern struct Gpio __code PWR_SW_N; +extern struct Gpio __code SB_KBCRST_N; +extern struct Gpio __code SLP_S0_N; +extern struct Gpio __code SLP_SUS_N; +#define HAVE_SUSWARN_N 0 +#define HAVE_SUS_PWR_ACK 0 +extern struct Gpio __code SUSB_N_PCH; +extern struct Gpio __code SUSC_N_PCH; +extern struct Gpio __code SWI_N; +extern struct Gpio __code VA_EC_EN; +extern struct Gpio __code WLAN_EN; +extern struct Gpio __code WLAN_PWR_EN; +extern struct Gpio __code XLP_OUT; +// clang-format on + +#endif // _BOARD_GPIO_H