Skip to content

Commit

Permalink
Add kudu6
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 authored and crawfxrd committed Jul 9, 2022
1 parent a36b9a7 commit 26f20f4
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/board/system76/kudu6/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only

#include <board/battery.h>
#include <board/board.h>
#include <ec/ec.h>

void board_init(void) {
// Make sure charger is in off state, also enables PSYS
battery_charger_disable();
}

void board_event(void) {
ec_read_post_codes();
}
57 changes: 57 additions & 0 deletions src/board/system76/kudu6/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-License-Identifier: GPL-3.0-only

EC=it5570e

# AMD CPU
CFLAGS+=-DHAVE_AMD_CPU=1

# Include keyboard
KEYBOARD=15in_102

# Set keyboard LED mechanism
KBLED=rgb_pwm

# Set CPU I2C bus
CFLAGS+=-DI2C_CPU=I2C_1

# 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 smart charger parameters
CHARGER=oz26786
CFLAGS+=\
-DCHARGER_CHARGE_CURRENT=1536 \
-DCHARGER_CHARGE_VOLTAGE=16800 \
-DCHARGER_INPUT_CURRENT=11800

# Custom fan curve
CFLAGS+=-DBOARD_HEATUP=5
CFLAGS+=-DBOARD_COOLDOWN=20
CFLAGS+=-DBOARD_FAN_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
"

# Enable DGPU support
CFLAGS+=-DHAVE_DGPU=1
CFLAGS+=-DBOARD_DGPU_HEATUP=5
CFLAGS+=-DBOARD_DGPU_COOLDOWN=20
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
FAN_POINT(60, 40), \
FAN_POINT(65, 60), \
FAN_POINT(70, 75), \
FAN_POINT(75, 90), \
FAN_POINT(80, 100) \
"

# Add system76 common code
include src/board/system76/common/common.mk
273 changes: 273 additions & 0 deletions src/board/system76/kudu6/gpio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
// SPDX-License-Identifier: GPL-3.0-only

#include <board/gpio.h>
#include <common/debug.h>

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(C, 7);
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2); // renamed to LPC_RST#
struct Gpio __code CCD_EN = GPIO(D, 1);
struct Gpio __code DD_ON = GPIO(E, 4);
struct Gpio __code DGPU_PWR_EN = GPIO(J, 2);
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 LAN_WAKEUP_N = GPIO(B, 2);
struct Gpio __code LED_ACIN = GPIO(H, 2);
struct Gpio __code LED_AIRPLANE_N = GPIO(H, 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 PCH_PWROK_EC = GPIO(I, 5); // renamed to SYS_PWROK
struct Gpio __code PM_PWROK = GPIO(C, 6);
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
struct Gpio __code PWR_SW_N = GPIO(B, 3);
struct Gpio __code SCI_N = GPIO(D, 3);
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 XLP_OUT = GPIO(B, 4);

void gpio_init() {
// Enable LPC reset on GPD2
GCR = 0x04;
// Enable SMBus channel 4
GCR15 = BIT(4);
// Set GPF2 and GPF3 to 3.3V
GCR20 = 0;

// Set GPIO data
// WLAN_PWR_EN
GPDRA = BIT(3);
// SWI#, XLP_OUT, PWR_SW#
GPDRB = BIT(5) | BIT(4) | BIT(3);
GPDRC = 0;
// PWR_BTN#, SMI#, SCI#
GPDRD = BIT(5) | BIT(4) | BIT(3);
GPDRE = 0;
// EC_BT_EN
GPDRF = BIT(3);
// H_PROCHOT#, WLAN_EN
GPDRG = BIT(6) | BIT(1);
// AIRPLAN_LED#
GPDRH = BIT(7);
GPDRI = 0;
GPDRJ = 0;

// Set GPIO control
// EC_PWM_LEDKB_P
GPCRA0 = GPIO_ALT;
// KBC_BEEP
GPCRA1 = GPIO_ALT;
// CPU_FANPWM
GPCRA2 = GPIO_ALT;
// WLAN_PWR_EN
GPCRA3 = GPIO_OUT | GPIO_UP;
// VGA_FAN_PWM
GPCRA4 = GPIO_ALT;
// 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;
// LAN_WAKE#
GPCRB2 = GPIO_IN | GPIO_UP;
// PWR_SW#
GPCRB3 = GPIO_IN;
// XLP_OUT
GPCRB4 = GPIO_OUT;
// SWI#
GPCRB5 = GPIO_OUT | GPIO_UP;
// EC_EN
GPCRB6 = GPIO_OUT | GPIO_UP;
// Doesn't exist
GPCRB7 = GPIO_IN;
// ALL_SYS_PWRGD
GPCRC0 = GPIO_IN;
// SMC_VGA_THERM
GPCRC1 = GPIO_ALT;
// SMD_VGA_THERM
GPCRC2 = GPIO_ALT;
// KB-SO16
GPCRC3 = GPIO_IN;
// NC
GPCRC4 = GPIO_IN | GPIO_UP;
// KB-SO17
GPCRC5 = GPIO_IN;
// PM_PWROK
GPCRC6 = GPIO_OUT;
// BKL_EN
GPCRC7 = GPIO_OUT | GPIO_UP;
// LED_PWR
GPCRD0 = GPIO_OUT | GPIO_UP;
// CCD_EN
GPCRD1 = GPIO_OUT | GPIO_UP;
// LPC_RST#
GPCRD2 = GPIO_ALT;
// SCI#
GPCRD3 = GPIO_IN;
// SMI#
GPCRD4 = GPIO_IN;
// PWR_BTN#
GPCRD5 = GPIO_OUT | GPIO_UP;
// CPU_FANSEN
GPCRD6 = GPIO_ALT;
// VGA_FANSEN
GPCRD7 = GPIO_ALT;
// SMC_BAT
GPCRE0 = GPIO_ALT;
// AC_PRESENT
GPCRE1 = GPIO_OUT | GPIO_UP;
// RGBKB-DET#
GPCRE2 = GPIO_IN | GPIO_UP;
// 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;
// 80CLK
GPCRF0 = GPIO_IN;
// USB_CHARGE_EN
GPCRF1 = GPIO_OUT | GPIO_UP;
// 3IN1
GPCRF2 = GPIO_IN | GPIO_UP;
// EC_BT_EN
GPCRF3 = GPIO_OUT;
// TP_CLK
GPCRF4 = GPIO_ALT;
// TP_DATA
GPCRF5 = GPIO_ALT;
// APU_THRM_ALERT#
GPCRF6 = GPIO_IN;
// THRMTRIP#
GPCRF7 = GPIO_IN | GPIO_UP;
// dGPU_GPIO8_OVERT
GPCRG0 = GPIO_IN | GPIO_UP;
// WLAN_EN
GPCRG1 = GPIO_OUT | GPIO_UP;
// AUTO_LOAD_PWR
GPCRG2 = GPIO_IN;
// ALSPI_CE#
GPCRG3 = GPIO_ALT;
// ALSPI_MSI
GPCRG4 = GPIO_ALT;
// ALSPI_MSO
GPCRG5 = GPIO_ALT;
// H_PROCHOT#
GPCRG6 = GPIO_OUT | GPIO_UP;
// ALSPI_SCLK
GPCRG7 = GPIO_ALT;
// PM_CLKRUN#
GPCRH0 = GPIO_IN;
// SUSC#_APU
GPCRH1 = GPIO_IN;
// LED_ACIN
GPCRH2 = GPIO_OUT | GPIO_UP;
// WLAN_EC_RST#
GPCRH3 = GPIO_OUT;
// d_GPIO9_ALERT_FAN
GPCRH4 = GPIO_IN;
// LED_BAT_CHG
GPCRH5 = GPIO_OUT;
// SUSB#_APU
GPCRH6 = GPIO_IN;
// AIRPLAN_LED#
GPCRH7 = GPIO_OUT | GPIO_UP;
// BAT_DET
GPCRI0 = GPIO_ALT;
// BAT_VOLT
GPCRI1 = GPIO_ALT;
// LAN_RTD3_EN#
GPCRI2 = GPIO_OUT;
// THERM_VOLT_1
GPCRI3 = GPIO_ALT;
// TOTAL_CUR
GPCRI4 = GPIO_ALT;
// SYS_PWROK
GPCRI5 = GPIO_IN;
// LAN_PWR_EN
GPCRI6 = GPIO_OUT;
// MODEL_ID
GPCRI7 = GPIO_IN;
// LED_BAT_FULL
GPCRJ0 = GPIO_OUT | GPIO_UP;
// KBC_MUTE#
GPCRJ1 = GPIO_IN;
// DGPU_PWR_EN
GPCRJ2 = GPIO_IN;
// GC6_FB_EN_PCH
GPCRJ3 = GPIO_IN;
// VA_EC_EN
GPCRJ4 = GPIO_OUT;
// VBATT_BOOST#
GPCRJ5 = GPIO_OUT;
// EC_GPIO
GPCRJ6 = GPIO_OUT;
// LAN_EC_RST#
GPCRJ7 = GPIO_OUT;
// LPC_AD0
GPCRM0 = GPIO_ALT;
// LPC_AD1
GPCRM1 = GPIO_ALT;
// LPC_AD2
GPCRM2 = GPIO_ALT;
// LPC_AD3
GPCRM3 = GPIO_ALT;
// PCLK_KBC
GPCRM4 = GPIO_ALT;
// LPC_FRAME#
GPCRM5 = GPIO_ALT;
// SERIRQ
GPCRM6 = GPIO_ALT;
}

#if GPIO_DEBUG
void gpio_debug_bank(
char * bank,
uint8_t data,
uint8_t mirror,
uint8_t pot,
volatile uint8_t * control
) {
for(char i = 0; i < 8; i++) {
DEBUG(
"%s%d:\n\tdata %d\n\tmirror %d\n\tpot %d\n\tcontrol %02X\n",
bank,
i,
(data >> i) & 1,
(mirror >> i) & 1,
(pot >> i) & 1,
*(control + i)
);
}
}

void gpio_debug(void) {
#define bank(BANK) gpio_debug_bank(#BANK, GPDR ## BANK, GPDMR ## BANK, GPOT ## BANK, &GPCR ## BANK ## 0)
bank(A);
bank(B);
bank(C);
bank(D);
bank(E);
bank(F);
bank(G);
bank(H);
bank(I);
bank(J);
#undef bank
}
#endif
42 changes: 42 additions & 0 deletions src/board/system76/kudu6/include/board/gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: GPL-3.0-only

#ifndef _BOARD_GPIO_H
#define _BOARD_GPIO_H

#include <ec/gpio.h>

void gpio_init(void);
void gpio_debug(void);

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;
extern struct Gpio __code BUF_PLT_RST_N;
extern struct Gpio __code CCD_EN;
extern struct Gpio __code DD_ON;
extern struct Gpio __code DGPU_PWR_EN;
extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code GC6_FB_EN;
extern struct Gpio __code LAN_WAKEUP_N;
extern struct Gpio __code LED_ACIN;
extern struct Gpio __code LED_AIRPLANE_N;
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 PCH_PWROK_EC;
extern struct Gpio __code PM_PWROK;
extern struct Gpio __code PWR_BTN_N;
extern struct Gpio __code PWR_SW_N;
extern struct Gpio __code SCI_N;
#define HAVE_SLP_SUS_N 0
extern struct Gpio __code SUSB_N_PCH;
extern struct Gpio __code SUSC_N_PCH;
#define HAVE_SUSWARN_N 0
extern struct Gpio __code SWI_N;
extern struct Gpio __code VA_EC_EN;
extern struct Gpio __code XLP_OUT;

#endif // _BOARD_GPIO_H

0 comments on commit 26f20f4

Please sign in to comment.