forked from system76/ec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michał Kopeć <[email protected]>
- Loading branch information
Showing
4 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#include <board/board.h> | ||
#include <board/battery.h> | ||
#include <board/gpio.h> | ||
#include <board/espi.h> | ||
#include <common/debug.h> | ||
#include <ec/adc.h> | ||
#include <ec/ec.h> | ||
|
||
void board_init(void) { | ||
espi_init(); | ||
battery_charger_disable(); | ||
|
||
// Allow backlight to be turned on | ||
gpio_set(&BKL_EN, true); | ||
// Enable camera | ||
gpio_set(&CCD_EN, true); | ||
|
||
adc_init(); | ||
} | ||
|
||
uint8_t board_id(void) { | ||
static bool cached = false; | ||
static uint8_t board_id = 0; | ||
|
||
if (cached) | ||
return board_id; | ||
|
||
// TODO | ||
|
||
int16_t id = adc_read_channel(7); | ||
if (id < 0) { | ||
ERROR("Board ID error %ld, defaulting to V560TU\n", id); | ||
board_id = 0; | ||
goto exit; | ||
} | ||
|
||
INFO("Board ID: V540TU\n"); | ||
board_id = 1; | ||
|
||
exit: | ||
cached = true; | ||
return board_id; | ||
} | ||
|
||
void board_event(void) { | ||
espi_event(); | ||
|
||
board_id(); | ||
|
||
ec_read_post_codes(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# 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 | ||
|
||
# Use S0ix | ||
CFLAGS+=-DUSE_S0IX=1 | ||
|
||
# Include keyboard | ||
KEYBOARD = 15in_102 | ||
|
||
# Set keyboard LED mechanism | ||
KBLED = rgb_pwm | ||
|
||
# Set discrete GPU I2C bus | ||
CFLAGS+=-DI2C_DGPU=I2C_1 | ||
|
||
# Set battery I2C bus | ||
CFLAGS += -DI2C_SMBUS=I2C_4 | ||
|
||
# Set touchpad PS2 bus | ||
CFLAGS += -DPS2_TOUCHPAD=PS2_3 | ||
|
||
# Set USB-PD I2C bus | ||
CFLAGS+=-DI2C_USBPD=I2C_1 | ||
|
||
# Set smart charger parameters | ||
CHARGER = oz26786 | ||
CFLAGS += \ | ||
-DCHARGER_ADAPTER_RSENSE=5 \ | ||
-DCHARGER_BATTERY_RSENSE=10 \ | ||
-DCHARGER_CHARGE_CURRENT=1536 \ | ||
-DCHARGER_CHARGE_VOLTAGE=17600 \ | ||
-DCHARGER_INPUT_CURRENT=4740 | ||
|
||
# Set CPU power limits in watts | ||
# AC: power rating of the included AC adapter | ||
# DC: battery discharge rate (assume 1C rating??) | ||
CFLAGS += \ | ||
-DPOWER_LIMIT_AC=90 \ | ||
-DPOWER_LIMIT_DC=73 | ||
|
||
# DGPU support | ||
CFLAGS+=-DHAVE_DGPU=1 | ||
|
||
# Set USB-PD parameters | ||
USBPD=tps65987 | ||
|
||
# Add common code | ||
include src/board/system76/common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,266 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
#include <board/gpio.h> | ||
#include <common/macro.h> | ||
|
||
// clang-format off | ||
struct Gpio __code ACIN_N = GPIO(B, 0); | ||
struct Gpio __code AC_PRESENT = GPIO(F, 7); | ||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0); | ||
struct Gpio __code BKL_EN = GPIO(C, 7); | ||
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2); | ||
struct Gpio __code CCD_EN = GPIO(D, 1); | ||
struct Gpio __code DD_ON = GPIO(E, 4); | ||
struct Gpio __code DGPU_PWR_EN = GPIO(H, 4); | ||
struct Gpio __code EC_EN = GPIO(B, 6); | ||
struct Gpio __code EC_RSMRST_N = GPIO(E, 5); | ||
struct Gpio __code GC6_FB_EN = GPIO(J, 3); | ||
struct Gpio __code H_PROCHOT_EC = GPIO(G, 6); | ||
struct Gpio __code JACK_IN_N = GPIO(C, 6); | ||
struct Gpio __code LAN_WAKEUP_N = GPIO(B, 2); | ||
struct Gpio __code LED_ACIN = GPIO(H, 2); | ||
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 PCH_PWROK_EC = GPIO(F, 3); | ||
struct Gpio __code PD_EN = GPIO(D, 4); | ||
struct Gpio __code PWR_BTN_N = GPIO(D, 5); | ||
struct Gpio __code PWR_SW_N = GPIO(B, 3); | ||
struct Gpio __code RGBKB_DET_N = GPIO(I, 2); | ||
struct Gpio __code SINK_CTRL = GPIO(H, 7); | ||
struct Gpio __code SUSB_N_PCH = GPIO(H, 0); | ||
struct Gpio __code SUSC_N_PCH = GPIO(H, 1); | ||
struct Gpio __code VA_EC_EN = GPIO(J, 4); | ||
struct Gpio __code WLAN_PWR_EN = GPIO(E, 1); | ||
struct Gpio __code XLP_OUT = GPIO(B, 4); | ||
// clang-format on | ||
|
||
void gpio_init(void) { | ||
// Set global configuration | ||
// Enable LPC reset on GPD2 | ||
GCR = 0b10 << 1; | ||
// Disable UARTs | ||
GCR6 = 0; | ||
// PWRSW WDT 2 Enable 1 | ||
GCR8 = BIT(4); | ||
// PWRSW WDT 2 Enable 2 | ||
GCR9 = BIT(5); | ||
// Enable SMBus channel 4 | ||
GCR15 = BIT(4); | ||
// Set GPB5 and GPD2 to 1.8V | ||
GCR19 = BIT(7) | BIT(0); | ||
// Set GPD3 to 1.8V, GPF2 and GPF3 to 3.3V | ||
GCR20 = BIT(7); | ||
// Set GPF6, GPF7, GPH0, and GPH1 to 1.8V | ||
GCR21 = BIT(6), BIT(5) | BIT(2) | BIT(1); | ||
// Set VCC power domain to 1.8V | ||
GCR22 = BIT(7); | ||
// Set GPM6 power domain to VCC | ||
GCR23 = BIT(0); | ||
|
||
// Set GPIO data | ||
GPDRA = 0; | ||
// XLP_OUT, PWR_SW# | ||
GPDRB = BIT(4) | BIT(3); | ||
GPDRC = 0; | ||
// PWR_BTN# | ||
GPDRD = BIT(5); | ||
// USB_PWR_EN | ||
GPDRE = BIT(3); | ||
// H_PECI | ||
GPDRF = BIT(6); | ||
// H_PROCHOT_EC | ||
GPDRG = BIT(6); | ||
// BL_PWM_EN_EC, PLVDD_RST_EC | ||
GPDRH = BIT(6) | BIT(3); | ||
GPDRI = 0; | ||
// KBC_MUTE# | ||
GPDRJ = BIT(1); | ||
GPDRM = 0; | ||
|
||
// Set GPIO control | ||
|
||
// EC_PWM_LEDKB_P | ||
GPCRA0 = GPIO_ALT; | ||
// KBC_BEEP | ||
GPCRA1 = GPIO_IN; | ||
// CPU_FAN | ||
GPCRA2 = GPIO_ALT; | ||
// VGA_FAN | ||
GPCRA3 = GPIO_ALT; | ||
// DDS_EC_PWM | ||
GPCRA4 = GPIO_IN; | ||
// 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; | ||
// EC_LAN_WAKEUP# | ||
GPCRB2 = GPIO_IN | GPIO_UP; | ||
// PWR_SW# | ||
GPCRB3 = GPIO_IN; | ||
// XLP_OUT | ||
GPCRB4 = GPIO_OUT; | ||
// SLP_S0# | ||
GPCRB5 = GPIO_IN; | ||
// SUSBC_EC | ||
GPCRB6 = GPIO_OUT; | ||
|
||
// 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; | ||
// JACK_IN#_EC | ||
GPCRC6 = GPIO_IN; | ||
// BKL_EN | ||
GPCRC7 = GPIO_OUT | GPIO_UP; | ||
|
||
// LED_PWR | ||
GPCRD0 = GPIO_OUT; | ||
// CCD_EN | ||
GPCRD1 = GPIO_OUT | GPIO_UP; | ||
// ESPI_RESET_N | ||
GPCRD2 = GPIO_ALT; | ||
// SLP_A# | ||
GPCRD3 = GPIO_IN; | ||
// PD_POWER_EN | ||
GPCRD4 = GPIO_OUT; | ||
// PWR_BTN# | ||
GPCRD5 = GPIO_OUT; | ||
// CPU_FANSEN | ||
GPCRD6 = GPIO_ALT | GPIO_DOWN; | ||
// VGA_FANSEN | ||
GPCRD7 = GPIO_ALT | GPIO_DOWN; | ||
|
||
// SMC_BAT | ||
GPCRE0 = GPIO_ALT | GPIO_UP; | ||
// WLAN_PWR_EN | ||
GPCRE1 = GPIO_OUT; | ||
// TBT_I2C_IRQ2Z | ||
GPCRE2 = GPIO_IN; | ||
// USB_PWR_EN | ||
GPCRE3 = GPIO_OUT | GPIO_UP; | ||
// DD_ON | ||
GPCRE4 = GPIO_OUT; | ||
// EC_RSMRST# | ||
GPCRE5 = GPIO_OUT; | ||
// ME_WE | ||
GPCRE6 = GPIO_IN; | ||
// SMD_BAT | ||
GPCRE7 = GPIO_ALT | GPIO_UP; | ||
|
||
// 80CLK | ||
GPCRF0 = GPIO_OUT | GPIO_UP; | ||
// USB_CHARGE_EN | ||
GPCRF1 = GPIO_OUT; | ||
// 3IN1 | ||
GPCRF2 = GPIO_OUT | GPIO_UP; | ||
// PCH_PWROK_EC | ||
GPCRF3 = GPIO_OUT | GPIO_UP; | ||
// TP_CLK | ||
GPCRF4 = GPIO_ALT | GPIO_UP; | ||
// TP_DATA | ||
GPCRF5 = GPIO_ALT | GPIO_UP; | ||
// H_PECI | ||
GPCRF6 = GPIO_ALT; | ||
// AC_PRESENT | ||
GPCRF7 = GPIO_OUT | GPIO_UP; | ||
|
||
// dGPU_GPIO8_OVERT | ||
GPCRG0 = GPIO_IN | GPIO_UP; | ||
// MUX_CTRL_BIOS | ||
GPCRG1 = GPIO_OUT; | ||
// 100k pull-up to VDD3 | ||
GPCRG2 = GPIO_IN; | ||
// HSPI_CE# | ||
GPCRG3 = GPIO_ALT; | ||
// HSPI_MSI | ||
GPCRG4 = GPIO_ALT; | ||
// HSPI_MSO | ||
GPCRG5 = GPIO_ALT; | ||
// H_PROCHOT_EC | ||
GPCRG6 = GPIO_OUT; | ||
// HSPI_SCLK | ||
GPCRG7 = GPIO_ALT; | ||
|
||
// SUSB#_PCH | ||
GPCRH0 = GPIO_IN; | ||
// SUSC#_PCH | ||
GPCRH1 = GPIO_IN; | ||
// LED_ACIN | ||
GPCRH2 = GPIO_OUT | GPIO_UP; | ||
// PLVDD_RST_EC | ||
GPCRH3 = GPIO_OUT; | ||
// DGPU_PWR_EN | ||
GPCRH4 = GPIO_IN; | ||
// LED_BAT_CHG | ||
GPCRH5 = GPIO_OUT; | ||
// BL_PWM_EN_EC | ||
GPCRH6 = GPIO_OUT; | ||
// SINK_CTRL_EC | ||
GPCRH7 = GPIO_IN; | ||
|
||
// BAT_DET | ||
GPCRI0 = GPIO_ALT; | ||
// BAT_VOLT | ||
GPCRI1 = GPIO_ALT; | ||
// RGBKB_DET# | ||
GPCRI2 = GPIO_IN | GPIO_UP; | ||
// THERM_VOLT | ||
GPCRI3 = GPIO_ALT; | ||
// TOTAL_CUR | ||
GPCRI4 = GPIO_ALT; | ||
// THERM_VOLT3 | ||
GPCRI5 = GPIO_ALT; | ||
// THERM_VOLT2 | ||
GPCRI6 = GPIO_ALT; | ||
// MODEL_ID | ||
GPCRI7 = GPIO_ALT; | ||
|
||
// LED_BAT_FULL | ||
GPCRJ0 = GPIO_OUT; | ||
// KBC_MUTE# | ||
GPCRJ1 = GPIO_OUT; | ||
// KBLIGHT_ADJ | ||
GPCRJ2 = GPIO_ALT; | ||
// GC6_FB_EN_PCH | ||
GPCRJ3 = GPIO_IN; | ||
// VA_EC_EN | ||
GPCRJ4 = GPIO_OUT; | ||
// VBATT_BOOST# | ||
GPCRJ5 = GPIO_OUT; | ||
// EC_GPIO | ||
GPCRJ6 = GPIO_OUT | GPIO_UP; | ||
// KB-DET | ||
GPCRJ7 = GPIO_IN | GPIO_UP; | ||
|
||
// 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; | ||
} |
Oops, something went wrong.