├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── .mailmap ├── .uncrustify.cfg ├── LICENSE ├── Makefile ├── POWER.txt ├── README.md ├── containers ├── Makefile └── ec │ └── Containerfile ├── docs ├── SUMMARY.md ├── adding-a-new-board.md ├── book.toml ├── controllers.md ├── debugging.md ├── dev-env.md ├── flashing.md ├── index.md ├── keyboard-layout-customization.md ├── mega2560.md └── security.md ├── rust-toolchain.toml ├── scripts ├── coccinelle │ ├── bit-macro.cocci │ └── macros.h ├── deps.sh ├── ectool.sh ├── hooks │ └── pre-commit.sh ├── lint │ ├── 01-spdx-tags.sh │ ├── 02-uncrustify.sh │ ├── 03-shellcheck.sh │ ├── lint.sh │ └── util.sh ├── power.sh └── spatch.sh ├── src ├── arch │ ├── 8051 │ │ ├── arch.c │ │ ├── arch.mk │ │ ├── delay.c │ │ ├── include │ │ │ └── arch │ │ │ │ ├── arch.h │ │ │ │ ├── delay.h │ │ │ │ └── time.h │ │ ├── time.c │ │ └── toolchain.mk │ └── avr │ │ ├── arch.mk │ │ ├── gpio.c │ │ ├── i2c.c │ │ ├── i2c_slave.c │ │ ├── include │ │ └── arch │ │ │ ├── gpio.h │ │ │ ├── i2c_slave.h │ │ │ └── uart.h │ │ ├── toolchain.mk │ │ └── uart.c ├── board │ ├── arduino │ │ ├── mega2560 │ │ │ ├── README.md │ │ │ ├── battery.c │ │ │ ├── board.mk │ │ │ ├── i2c.c │ │ │ ├── include │ │ │ │ └── board │ │ │ │ │ ├── battery.h │ │ │ │ │ ├── cpu.h │ │ │ │ │ └── i2c.h │ │ │ ├── main.c │ │ │ └── parallel.c │ │ ├── micro │ │ │ ├── README.md │ │ │ ├── board.mk │ │ │ ├── include │ │ │ │ └── board │ │ │ │ │ └── cpu.h │ │ │ └── main.c │ │ └── uno │ │ │ ├── README.md │ │ │ ├── battery.c │ │ │ ├── board.mk │ │ │ ├── i2c.c │ │ │ ├── include │ │ │ └── board │ │ │ │ ├── battery.h │ │ │ │ ├── cpu.h │ │ │ │ └── i2c.h │ │ │ ├── main.c │ │ │ └── parallel.c │ └── system76 │ │ ├── addw1 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── addw2 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── addw3 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── addw4 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── bonw14 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── bonw15-b │ │ └── board.mk │ │ ├── bonw15 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── common │ │ ├── acpi.c │ │ ├── battery.c │ │ ├── charger │ │ │ ├── bq24780s.c │ │ │ └── oz26786.c │ │ ├── common.mk │ │ ├── config.c │ │ ├── dgpu.c │ │ ├── ecpm.c │ │ ├── espi.c │ │ ├── fan.c │ │ ├── flash │ │ │ ├── flash.mk │ │ │ ├── include │ │ │ │ └── flash │ │ │ │ │ └── entry.h │ │ │ ├── main.c │ │ │ └── wrapper.c │ │ ├── gctrl.c │ │ ├── include │ │ │ └── board │ │ │ │ ├── acpi.h │ │ │ │ ├── battery.h │ │ │ │ ├── board.h │ │ │ │ ├── config.h │ │ │ │ ├── cpu.h │ │ │ │ ├── dgpu.h │ │ │ │ ├── ecpm.h │ │ │ │ ├── espi.h │ │ │ │ ├── fan.h │ │ │ │ ├── flash.h │ │ │ │ ├── gctrl.h │ │ │ │ ├── kbc.h │ │ │ │ ├── kbled.h │ │ │ │ ├── kbscan.h │ │ │ │ ├── lid.h │ │ │ │ ├── parallel.h │ │ │ │ ├── peci.h │ │ │ │ ├── pmc.h │ │ │ │ ├── pnp.h │ │ │ │ ├── power.h │ │ │ │ ├── ps2.h │ │ │ │ ├── pwm.h │ │ │ │ ├── scratch.h │ │ │ │ ├── security.h │ │ │ │ ├── smbus.h │ │ │ │ ├── smfi.h │ │ │ │ ├── usbpd.h │ │ │ │ └── wireless.h │ │ ├── kbc.c │ │ ├── kbled │ │ │ ├── bonw14.c │ │ │ ├── common.c │ │ │ ├── darp5.c │ │ │ ├── oryp5.c │ │ │ ├── rgb_pwm.c │ │ │ └── white_dac.c │ │ ├── kbscan.c │ │ ├── keymap.c │ │ ├── lid.c │ │ ├── main.c │ │ ├── parallel.c │ │ ├── peci.c │ │ ├── pmc.c │ │ ├── pnp.c │ │ ├── power │ │ │ ├── amd.c │ │ │ └── intel.c │ │ ├── ps2.c │ │ ├── pwm.c │ │ ├── scratch.c │ │ ├── scratch │ │ │ ├── main.c │ │ │ ├── scratch.mk │ │ │ └── stdio.c │ │ ├── security.c │ │ ├── smbus.c │ │ ├── smfi.c │ │ ├── stdio.c │ │ ├── usbpd │ │ │ └── tps65987.c │ │ └── wireless.c │ │ ├── darp10-b │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp10 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp11-b │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp11 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp5 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp6 │ │ └── board.mk │ │ ├── darp7 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp8 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── darp9 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── galp3-c │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── galp4 │ │ └── board.mk │ │ ├── galp5 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── galp6 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── galp7 │ │ └── board.mk │ │ ├── gaze15 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── gaze16-3050 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── gaze16-3060-b │ │ └── board.mk │ │ ├── gaze16-3060 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── gaze17-3050 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── gaze17-3060-b │ │ └── board.mk │ │ ├── gaze17-3060 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── gaze18 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── lemp10 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── lemp11 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── lemp12 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── lemp13-b │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── lemp13 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── lemp9 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp10 │ │ └── board.mk │ │ ├── oryp11 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp12 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp5 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp6 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp7 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp8 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ ├── oryp9 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ │ └── board │ │ │ └── gpio.h │ │ └── serw13 │ │ ├── board.c │ │ ├── board.mk │ │ ├── gpio.c │ │ └── include │ │ └── board │ │ └── gpio.h ├── common │ ├── common.mk │ ├── i2c.c │ ├── include │ │ └── common │ │ │ ├── command.h │ │ │ ├── debug.h │ │ │ ├── i2c.h │ │ │ ├── keymap.h │ │ │ ├── macro.h │ │ │ └── version.h │ ├── keymap.c │ └── version.c ├── ec │ ├── atmega │ │ └── ec.mk │ └── ite │ │ ├── ec.c │ │ ├── ec.mk │ │ ├── espi.c │ │ ├── gpio.c │ │ ├── i2c.c │ │ ├── include │ │ └── ec │ │ │ ├── bram.h │ │ │ ├── dac.h │ │ │ ├── ec.h │ │ │ ├── ecpm.h │ │ │ ├── espi.h │ │ │ ├── etwd.h │ │ │ ├── gctrl.h │ │ │ ├── gpio.h │ │ │ ├── i2c.h │ │ │ ├── intc.h │ │ │ ├── kbc.h │ │ │ ├── kbscan.h │ │ │ ├── peci.h │ │ │ ├── pmc.h │ │ │ ├── ps2.h │ │ │ ├── pwm.h │ │ │ ├── scratch.h │ │ │ ├── smbus.h │ │ │ └── wuc.h │ │ ├── intc.c │ │ ├── kbc.c │ │ ├── pmc.c │ │ ├── ps2.c │ │ ├── signature.c │ │ └── wuc.c └── keyboard │ └── system76 │ ├── 14in_81 │ ├── include │ │ └── board │ │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ │ ├── default.c │ │ └── jeremy.c │ ├── 14in_83 │ ├── include │ │ └── board │ │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ │ ├── clevo_l141cu_us_iso.c │ │ ├── darp10-b.c │ │ ├── default.c │ │ ├── fabian.c │ │ ├── ins-prtsc.c │ │ ├── jeremy.c │ │ ├── levi.c │ │ └── valentin_french_iso.c │ ├── 14in_86 │ ├── include │ │ └── board │ │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ │ ├── carl.c │ │ ├── default.c │ │ └── jeremy.c │ ├── 15in_102 │ ├── include │ │ └── board │ │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ │ ├── default.c │ │ └── jeremy.c │ ├── 15in_102_nkey │ ├── include │ │ └── board │ │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ │ ├── default.c │ │ └── jeremy.c │ ├── 18H9LHA04 │ ├── include │ │ └── board │ │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ │ ├── default.c │ │ └── jeremy.c │ └── 18H9LHA05 │ ├── include │ └── board │ │ └── keymap.h │ ├── keyboard.mk │ └── keymap │ ├── darp10.c │ └── default.c └── tool ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE └── src ├── access ├── hid.rs ├── lpc │ ├── direct.rs │ ├── linux.rs │ ├── mod.rs │ └── sim.rs └── mod.rs ├── ec.rs ├── error.rs ├── firmware.rs ├── legacy.rs ├── lib.rs ├── main.rs ├── pmc.rs ├── spi.rs ├── super_io.rs └── timeout.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: https://editorconfig.org/ 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | 16 | [{Makefile,*.mk}] 17 | indent_style = tab 18 | 19 | [*.yml] 20 | indent_size = 2 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /config.mk 3 | /power.csv 4 | backup.rom 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ecsim"] 2 | path = ecsim 3 | url = https://github.com/system76/ecsim.git 4 | branch = master 5 | [submodule "ecflash"] 6 | path = ecflash 7 | url = https://github.com/system76/ecflash.git 8 | branch = master 9 | [submodule "ecspy"] 10 | path = ecspy 11 | url = https://github.com/system76/ecspy.git 12 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Andrew Rodland 2 | Carl Richell 3 | Evan Lojewski 4 | Jeremy Soller 5 | Levi Portenier 6 | Tim Crawford 7 | -------------------------------------------------------------------------------- /POWER.txt: -------------------------------------------------------------------------------- 1 | G3 state 2 | VCCRTC from VCC_RTC enabled by CMOS battery 3 | RTCRST# from VCC_RTC 4 | 5 | Power plugged in 6 | VCCDSW_3P3 from VDD3 enabled by AC power 7 | Assert VA_EC_EN 8 | VCCPRIM_3P3 from 3.3VA enabled by VA_EC_EN 9 | VCCPRIM_1P8 from 1.8VA enabled by VA_EC_EN 10 | VCCPRIM_1P05 from 1.05VA enabled by VA_EC_EN 11 | Assert DD_ON 12 | VDD5 enabled by DD_ON 13 | 3.3V enabled by DD_ON 14 | Assert SUS_ACK# by SUS_PWR_ACK 15 | Assert DSW_PWROK by PCH_DPWROK_EC 16 | Assert RSMRST# 17 | S5 state 18 | 19 | Assert ACPRESENT# 20 | Assert PWRBTN# 21 | Assert EC_EN - WHEN? 22 | Assert VR_ON 23 | Assert PCH_PWROK via PM_PWROK 24 | Assert PCH_PWROK_EC 25 | S0 state 26 | -------------------------------------------------------------------------------- /containers/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | # Disable built-in rules and variables 4 | MAKEFLAGS += --no-builtin-rules --no-builtin-variables 5 | .SUFFIXES: 6 | 7 | # Default to silent builds 8 | ifneq ($(VERBOSE),1) 9 | MAKEFLAGS += --silent 10 | .SILENT: 11 | endif 12 | 13 | PODMAN := $(shell command -v podman) 14 | 15 | CONTAINER_TAG := latest 16 | 17 | .PHONY: ec 18 | ec: 19 | $(PODMAN) build \ 20 | --tag system76/$@:$(CONTAINER_TAG) \ 21 | --file Containerfile \ 22 | $@ 23 | -------------------------------------------------------------------------------- /docs/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | - [Index](./index.md) 4 | - [Development environment](./dev-env.md) 5 | - [Adding a new board](./adding-a-new-board.md) 6 | - [Supported controllers](./controllers.md) 7 | - [Debugging](./debugging.md) 8 | - [Flashing](./flashing.md) 9 | - [Custom keyboard layouts](./keyboard-layout-customization.md) 10 | - [Mega2560](./mega2560.md) 11 | -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | [book] 4 | title = "System76 EC" 5 | description = "System76 EC documentation" 6 | language = "en" 7 | src = "." 8 | 9 | [build] 10 | build-dir = "../build/docs" 11 | create-missing = false 12 | 13 | [output.html] 14 | default-theme = "rust" 15 | preferred-dark-theme = "coal" 16 | no-section-label = true 17 | git-repository-url = "https://github.com/system76/ec" 18 | 19 | [output.html.print] 20 | enable = false 21 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # System76 EC documentation 2 | 3 | ## TODO 4 | 5 | - Define what functions are required in each board, ec, and arch 6 | -------------------------------------------------------------------------------- /docs/security.md: -------------------------------------------------------------------------------- 1 | # Firmware security 2 | 3 | The firmware security feature can be configured by setting `CONFIG_SECURITY=1` 4 | in the `src/board/system76/[board]/board.mk` file. This feature prevents 5 | programming the EC firmware at runtime, unless the EC is unlocked with the 6 | `system76-ectool security unlock` command. After this, on the next reboot, the 7 | EC will respond to the SPI and reset commands. On boards where the `ME_WE` GPIO 8 | exists, it will be set high when the EC security state is unlocked. 9 | 10 | Other firmware components can use this state to perform their own locking and 11 | unlocking primitives. For example, in `coreboot`, flash regions may be locked 12 | when the EC security state is locked. In `EDK2`, a physical presence dialog may 13 | be shown when the EC security state is unlocked. 14 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.85.0" 3 | components = ["clippy", "rustfmt"] 4 | profile = "minimal" 5 | -------------------------------------------------------------------------------- /scripts/coccinelle/bit-macro.cocci: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | // Replace shifts with BIT macro 3 | 4 | @@ expression val; @@ 5 | -(1 << val) 6 | +BIT(val) 7 | 8 | @@ expression val; @@ 9 | -(1U << val) 10 | +BIT(val) 11 | 12 | @@ expression val; @@ 13 | -1 << val 14 | +BIT(val) 15 | -------------------------------------------------------------------------------- /scripts/coccinelle/macros.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | // SDCC extenstions that need to be defined away for spatch 3 | 4 | #define __at(x) 5 | #define __code 6 | #define __critical 7 | #define __data 8 | #define __reentrant 9 | #define ___ 10 | -------------------------------------------------------------------------------- /scripts/ectool.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | set -e 5 | cargo build --release --quiet --manifest-path tool/Cargo.toml 6 | sudo tool/target/release/system76_ectool "$@" 7 | -------------------------------------------------------------------------------- /scripts/hooks/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | make lint 2>/dev/null || { 5 | echo -e "\nissues found, not committing" 6 | exit 1 7 | } 8 | -------------------------------------------------------------------------------- /scripts/lint/01-spdx-tags.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | # Check that all files have a SPDX license identifier 5 | # TODO: Validate license tags against a whitelist 6 | 7 | LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) 8 | . "$LINT_DIR/util.sh" 9 | 10 | echo -n "Checking for SPDX tags..." 11 | 12 | EXCLUDES=( 13 | # Ignore license files 14 | ':!:LICENSE' 15 | ':!:**/LICENSE' 16 | # Ignore cargo files 17 | ':!:**/Cargo.lock' 18 | ':!:**/Cargo.toml' 19 | ':!:rust-toolchain.toml' 20 | # Ignore text files 21 | ':!:*.md' 22 | ':!:*.txt' 23 | # Ignore dotfiles 24 | ':!:\.*' 25 | ':!:**/\.*' 26 | ) 27 | 28 | needs_tag=() 29 | 30 | for file in $(git ls-files "${EXCLUDES[@]}"); do 31 | # Only check regular files 32 | if [[ ! -f "$file" ]]; then 33 | continue 34 | fi 35 | 36 | # SPDX must appear at head of file 37 | if ! head "$file" | grep -q 'SPDX-License-Identifier:'; then 38 | needs_tag+=("$file") 39 | fi 40 | done 41 | 42 | if [[ "${#needs_tag[@]}" != "0" ]]; then 43 | failed 44 | 45 | for file in "${needs_tag[@]}"; do 46 | echo "- $file" 47 | done 48 | 49 | exit 1 50 | fi 51 | 52 | passed 53 | -------------------------------------------------------------------------------- /scripts/lint/02-uncrustify.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | # Check if any C files or headers need to be formatted. 5 | 6 | # shellcheck disable=SC1091 7 | 8 | LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) 9 | . "$LINT_DIR/util.sh" 10 | 11 | echo -n "Checking C style..." 12 | 13 | if ! command -v uncrustify > /dev/null; then 14 | skipped "uncrustify not found" 15 | exit 0 16 | fi 17 | 18 | needs_formatting=() 19 | 20 | for file in $(git ls-files '*.c' '*.h'); do 21 | if ! uncrustify -c .uncrustify.cfg -q --check "$file" >/dev/null 2>&1; then 22 | needs_formatting+=("$file") 23 | fi 24 | done 25 | 26 | if [[ "${#needs_formatting[@]}" != "0" ]]; then 27 | failed 28 | 29 | for file in "${needs_formatting[@]}"; do 30 | echo "- $file" 31 | done 32 | 33 | exit 1 34 | fi 35 | 36 | passed 37 | -------------------------------------------------------------------------------- /scripts/lint/03-shellcheck.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | # Check if any shell scripts have issues. 5 | 6 | LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) 7 | . "$LINT_DIR/util.sh" 8 | 9 | echo -n "Checking shell scripts..." 10 | 11 | if ! command -v shellcheck > /dev/null; then 12 | skipped "shellcheck not found" 13 | exit 0 14 | fi 15 | 16 | readarray -t FILES < <(git ls-files '*.sh') 17 | needs_formatting=() 18 | 19 | for file in "${FILES[@]}"; do 20 | # SC1091: Ignore external scripts 21 | if ! shellcheck -f quiet --exclude=SC1091 "$file"; then 22 | needs_formatting+=("$file") 23 | fi 24 | done 25 | 26 | if [[ "${#needs_formatting[@]}" != "0" ]]; then 27 | failed 28 | 29 | for file in "${needs_formatting[@]}"; do 30 | echo "- $file" 31 | done 32 | 33 | exit 1 34 | fi 35 | 36 | passed 37 | -------------------------------------------------------------------------------- /scripts/lint/lint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | # Run all lints. 5 | 6 | LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) 7 | LINTS=$(find "$LINT_DIR" -type f -name "[0-9][0-9]-*" | sort) 8 | FAILED=0 9 | 10 | for lint in $LINTS; do 11 | $lint || FAILED=1 12 | done 13 | 14 | [[ "$FAILED" = "0" ]] || exit 1 15 | -------------------------------------------------------------------------------- /scripts/lint/util.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | passed() { 5 | echo -e "\x1B[32mPASSED\x1B[0m" 6 | } 7 | 8 | skipped() { 9 | local reason=$1 10 | echo -e "\x1B[33mSKIPPED\x1B[0m ($reason)" 11 | } 12 | 13 | failed() { 14 | echo -e "\x1B[31mFAILED\x1B[0m" 15 | } 16 | -------------------------------------------------------------------------------- /scripts/spatch.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-License-Identifier: GPL-3.0-only 3 | 4 | spatch \ 5 | --sp-file ./scripts/coccinelle/bit-macro.cocci \ 6 | --macro-file ./scripts/coccinelle/macros.h \ 7 | --no-includes \ 8 | --include-headers \ 9 | --preprocess \ 10 | --in-place \ 11 | --dir src/ 12 | -------------------------------------------------------------------------------- /src/arch/8051/arch.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include <8051.h> 4 | 5 | #include 6 | #include 7 | 8 | void arch_init(void) { 9 | // Disable interrupts 10 | EA = 0; 11 | 12 | time_init(); 13 | 14 | // Enable interrupts 15 | EA = 1; 16 | } 17 | -------------------------------------------------------------------------------- /src/arch/8051/arch.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | arch-y += arch.c 4 | arch-y += delay.c 5 | arch-y += time.c 6 | -------------------------------------------------------------------------------- /src/arch/8051/delay.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // Uses timer 1 to implement delays 4 | 5 | #include <8051.h> 6 | 7 | #include 8 | 9 | void delay_ticks(uint16_t ticks) { 10 | uint16_t value = -ticks; 11 | 12 | // Stop the timer 13 | TR1 = 0; 14 | TF1 = 0; 15 | 16 | // Start timer in mode 1 17 | TMOD = (TMOD & 0x0F) | 0x10; 18 | TH1 = (uint8_t)(value >> 8); 19 | TL1 = (uint8_t)value; 20 | TR1 = 1; 21 | 22 | // Wait until complete 23 | while (TF1 == 0) {} 24 | } 25 | 26 | // This loops through delays of one ms in order to avoid overflow 27 | void delay_ms(uint8_t ms) { 28 | for (uint8_t i = ms; i != 0; i--) { 29 | delay_us(1000); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/arch/8051/include/arch/arch.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _ARCH_ARCH_H 4 | #define _ARCH_ARCH_H 5 | 6 | void arch_init(void); 7 | 8 | #endif // _ARCH_ARCH_H 9 | -------------------------------------------------------------------------------- /src/arch/8051/include/arch/delay.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _ARCH_DELAY_H 4 | #define _ARCH_DELAY_H 5 | 6 | #include 7 | 8 | void delay_ticks(uint16_t ticks); 9 | 10 | // 1 us * 9.2 MHz / 12 is 69/90 11 | // Warning: this will round to the nearest tick 12 | #define delay_us(X) delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89UL) / 90UL)); 13 | 14 | // 1 ns * 9.2 MHz / 12 is 69/90000 15 | // Warning: this will round to the nearest tick 16 | #define delay_ns(X) delay_ticks((uint16_t)((((uint32_t)(X)) * 69UL + 89999UL) / 90000UL)); 17 | 18 | void delay_ms(uint8_t ms); 19 | 20 | #endif // _ARCH_DELAY_H 21 | -------------------------------------------------------------------------------- /src/arch/8051/include/arch/time.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _ARCH_TIME_H 4 | #define _ARCH_TIME_H 5 | 6 | #include 7 | 8 | typedef uint16_t systick_t; 9 | 10 | void time_init(void); 11 | systick_t time_get(void); 12 | 13 | #endif // _ARCH_TIME_H 14 | -------------------------------------------------------------------------------- /src/arch/8051/time.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // Uses timer 0 to keep track of global time 4 | 5 | #include <8051.h> 6 | #include 7 | 8 | #define OSC_DIVISOR 12 9 | #define TICK_INTERVAL_MS 1 10 | // Value to reload into the timer when the overflow interrupt is triggered. 11 | #define TIMER_RELOAD (0xFFFF - (TICK_INTERVAL_MS * (CONFIG_CLOCK_FREQ_KHZ / OSC_DIVISOR))) 12 | 13 | static volatile systick_t time_overflows = 0; 14 | 15 | void timer_0(void) __interrupt(1) { 16 | // Hardware automatically clears the the interrupt 17 | 18 | // Stop timer 19 | TR0 = 0; 20 | 21 | time_overflows++; 22 | 23 | // Reload the values 24 | TH0 = TIMER_RELOAD >> 8; 25 | TL0 = TIMER_RELOAD & 0xFF; 26 | 27 | // Restart the timer 28 | TR0 = 1; 29 | } 30 | 31 | /** 32 | * Set up Timer 0 as the system tick. 33 | */ 34 | void time_init(void) __critical { 35 | // Stop the timer 36 | TR0 = 0; 37 | TF0 = 0; 38 | 39 | time_overflows = 0; 40 | 41 | // Enable the interrupt 42 | ET0 = 1; 43 | 44 | // Set the timer to mode 1 (16-bit timer) 45 | TMOD = (TMOD & 0xF0) | 0x01; 46 | 47 | // Set the initial values 48 | TH0 = TIMER_RELOAD >> 8; 49 | TL0 = TIMER_RELOAD & 0xFF; 50 | 51 | // Start the timer 52 | TR0 = 1; 53 | } 54 | 55 | systick_t time_get(void) __critical { 56 | return time_overflows; 57 | } 58 | -------------------------------------------------------------------------------- /src/arch/avr/arch.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | arch-y += gpio.c 4 | arch-y += i2c.c 5 | arch-y += i2c_slave.c 6 | arch-y += uart.c 7 | -------------------------------------------------------------------------------- /src/arch/avr/gpio.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | bool gpio_get_dir(const struct Gpio *const gpio) { 6 | if (*gpio->ddr & gpio->value) { 7 | return true; 8 | } else { 9 | return false; 10 | } 11 | } 12 | 13 | void gpio_set_dir(struct Gpio *const gpio, bool value) { 14 | if (value) { 15 | *gpio->ddr |= gpio->value; 16 | } else { 17 | *gpio->ddr &= ~gpio->value; 18 | } 19 | } 20 | 21 | bool gpio_get(const struct Gpio *const gpio) { 22 | if (*gpio->pin & gpio->value) { 23 | return true; 24 | } else { 25 | return false; 26 | } 27 | } 28 | 29 | void gpio_set(struct Gpio *const gpio, bool value) { 30 | if (value) { 31 | *gpio->port |= gpio->value; 32 | } else { 33 | *gpio->port &= ~gpio->value; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/arch/avr/include/arch/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _ARCH_GPIO_H 4 | #define _ARCH_GPIO_H 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | struct Gpio { 13 | volatile uint8_t *pin; 14 | volatile uint8_t *ddr; 15 | volatile uint8_t *port; 16 | uint8_t value; 17 | }; 18 | 19 | #define GPIO(BLOCK, NUMBER) { \ 20 | .pin = &PIN ## BLOCK, \ 21 | .ddr = &DDR ## BLOCK, \ 22 | .port = &PORT ## BLOCK, \ 23 | .value = BIT(NUMBER), \ 24 | } 25 | 26 | bool gpio_get(const struct Gpio *const gpio); 27 | void gpio_set(struct Gpio *const gpio, bool value); 28 | bool gpio_get_dir(const struct Gpio *const gpio); 29 | void gpio_set_dir(struct Gpio *const gpio, bool value); 30 | 31 | #endif // _ARCH_GPIO_H 32 | -------------------------------------------------------------------------------- /src/arch/avr/include/arch/i2c_slave.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _ARCH_I2C_SLAVE_H 4 | #define _ARCH_I2C_SLAVE_H 5 | 6 | void i2c_slave_init( 7 | uint8_t address, 8 | void (*new_cb)(), 9 | void (*recv_cb)(uint8_t), 10 | uint8_t (*send_cb)() 11 | ); 12 | void i2c_slave_stop(void); 13 | 14 | #endif // _ARCH_I2C_SLAVE_H 15 | -------------------------------------------------------------------------------- /src/arch/avr/include/arch/uart.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _ARCH_UART_H 4 | #define _ARCH_UART_H 5 | 6 | #include 7 | 8 | struct Uart { 9 | volatile uint8_t *a; 10 | volatile uint8_t *b; 11 | volatile uint8_t *c; 12 | volatile uint8_t *data; 13 | volatile uint8_t *baud_l; 14 | volatile uint8_t *baud_h; 15 | uint8_t a_read; 16 | uint8_t a_write; 17 | uint8_t a_init; 18 | uint8_t b_init; 19 | uint8_t c_init; 20 | }; 21 | 22 | void uart_init(struct Uart *const uart, uint32_t baud); 23 | 24 | int16_t uart_count(void); 25 | struct Uart *uart_new(int16_t num); 26 | 27 | uint8_t uart_can_read(struct Uart *const uart); 28 | uint8_t uart_can_write(struct Uart *const uart); 29 | 30 | uint8_t uart_read(struct Uart *const uart); 31 | void uart_write(struct Uart *const uart, uint8_t data); 32 | 33 | extern struct Uart *uart_stdio; 34 | void uart_stdio_init(int16_t num, uint32_t baud); 35 | 36 | #endif // _ARCH_UART_H 37 | -------------------------------------------------------------------------------- /src/arch/avr/toolchain.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | CC = avr-gcc -mmcu=$(EC_VARIANT) 4 | CFLAGS += -MMD -Os -fstack-usage -Wall -Werror \ 5 | -Wl,--gc-sections -Wl,-u,vfprintf -lprintf_flt 6 | 7 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 8 | _gcc_version = $(shell avr-gcc --version 2>/dev/null) 9 | ifneq ($(findstring 12.,$(_gcc_version)),) 10 | CFLAGS += --param=min-pagesize=0 11 | else ifneq ($(findstring 13.,$(_gcc_version)),) 12 | CFLAGS += --param=min-pagesize=0 13 | endif 14 | 15 | OBJCOPY = avr-objcopy 16 | 17 | OBJ=$(sort $(patsubst src/%.c,$(BUILD)/%.o,$(SRC))) 18 | 19 | # Run EC rom in simulator 20 | sim: $(BUILD)/ec.elf 21 | simavr $< --mcu $(EC_VARIANT) 22 | 23 | # Convert from Intel Hex file to binary file 24 | $(BUILD)/ec.rom: $(BUILD)/ec.ihx 25 | @echo " OBJCOPY $(subst $(BUILD)/,,$@)" 26 | mkdir -p $(@D) 27 | $(OBJCOPY) -I ihex -O binary --gap-fill 0xFF $< $@ 28 | 29 | # Convert from ELF file to Intel Hex file 30 | $(BUILD)/ec.ihx: $(BUILD)/ec.elf 31 | @echo " OBJCOPY $(subst $(BUILD)/,,$@)" 32 | mkdir -p $(@D) 33 | $(OBJCOPY) -j .text -j .data -O ihex $< $@ 34 | 35 | # Link object files into ELF file 36 | $(BUILD)/ec.elf: $(OBJ) 37 | @echo " LINK $(subst $(BUILD)/,,$@)" 38 | mkdir -p $(@D) 39 | $(CC) -o $@ $^ 40 | 41 | # Compile C files into object files 42 | $(BUILD)/%.o: src/%.c $(INCLUDE) 43 | @echo " CC $(subst $(BUILD)/,,$@)" 44 | mkdir -p $(@D) 45 | $(CC) $(CFLAGS) -o $@ -c $< 46 | 47 | # Add dependency rules 48 | DEP = $(OBJ:%.o=%.d) 49 | -include $(DEP) 50 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Mega 2560 2 | 3 | ![Arduino Mega 2560 Pinout](https://arduino.pinout.guide/arduino_mega_pinout.png) 4 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/battery.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | 7 | int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data) { 8 | return i2c_get(NULL, address, command, (uint8_t *)data, 2); 9 | } 10 | 11 | int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) { 12 | return i2c_set(NULL, address, command, (uint8_t *)&data, 2); 13 | } 14 | 15 | void battery_debug(void) { 16 | uint16_t data = 0; 17 | int16_t res = 0; 18 | 19 | #define command(N, A, V) \ 20 | { \ 21 | printf(#N ": "); \ 22 | res = smbus_read(A, V, &data); \ 23 | if (res < 0) { \ 24 | printf("ERROR %04X\n", -res); \ 25 | } else { \ 26 | printf("%04X\n", data); \ 27 | } \ 28 | } 29 | 30 | printf("Battery:\n"); 31 | command(Temperature, 0x0B, 0x08); 32 | command(Voltage, 0x0B, 0x09); 33 | command(Current, 0x0B, 0x0A); 34 | command(Charge, 0x0B, 0x0D); 35 | 36 | printf("Charger:\n"); 37 | command(ChargeOption0, 0x09, 0x12); 38 | command(ChargeOption1, 0x09, 0x3B); 39 | command(ChargeOption2, 0x09, 0x38); 40 | command(ChargeOption3, 0x09, 0x37); 41 | command(ChargeCurrent, 0x09, 0x14); 42 | command(ChargeVoltage, 0x09, 0x15); 43 | command(DishargeCurrent, 0x09, 0x39); 44 | command(InputCurrent, 0x09, 0x3F); 45 | command(ProchotOption0, 0x09, 0x3C); 46 | command(ProchotOption1, 0x09, 0x3D); 47 | command(ProchotStatus, 0x09, 0x3A); 48 | 49 | #undef command 50 | } 51 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += battery.c 4 | board-y += i2c.c 5 | board-y += main.c 6 | board-y += parallel.c 7 | 8 | EC=atmega 9 | EC_VARIANT=atmega2560 10 | 11 | PORT=$(wildcard /dev/ttyACM*) 12 | CONSOLE_BAUD=1000000 13 | CFLAGS+=-D__CONSOLE_BAUD__=$(CONSOLE_BAUD) 14 | 15 | console: 16 | sudo tio -b $(CONSOLE_BAUD) $(PORT) 17 | 18 | flash: $(BUILD)/ec.ihx 19 | sudo avrdude -v -v -p $(EC_VARIANT) -c wiring -P $(PORT) -b 115200 -D -U flash:w:$<:i 20 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/i2c.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | void i2c_init(uint32_t baud) { 9 | TWAR = 0; 10 | TWBR = (uint8_t)(((F_CPU / baud) - 16) / 2); 11 | TWCR = 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/include/board/battery.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_BATTERY_H 4 | #define _BOARD_BATTERY_H 5 | 6 | void battery_debug(void); 7 | 8 | #endif // _BOARD_BATTERY_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/include/board/cpu.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_CPU_H 4 | #define _BOARD_CPU_H 5 | 6 | #define F_CPU 16000000ULL 7 | 8 | #endif // _BOARD_CPU_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/include/board/i2c.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_I2C_H 4 | #define _BOARD_I2C_H 5 | 6 | void i2c_init(uint32_t baud); 7 | 8 | #endif // _BOARD_I2C_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/mega2560/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | void init(void) { 9 | uart_stdio_init(0, __CONSOLE_BAUD__); 10 | } 11 | 12 | struct Gpio LED = GPIO(B, 7); 13 | 14 | //TODO: .h file 15 | int parallel_main(void); 16 | 17 | int main(void) { 18 | init(); 19 | 20 | gpio_set_dir(&LED, true); 21 | gpio_set(&LED, false); 22 | 23 | parallel_main(); 24 | 25 | // If parallel_main exits with an error, wait for reset 26 | for (;;) {} 27 | } 28 | -------------------------------------------------------------------------------- /src/board/arduino/micro/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Micro 2 | 3 | ![Arduino Micro Pinout](https://arduino.pinout.guide/arduino_micro_pinout_and_ISP_pins.png) 4 | -------------------------------------------------------------------------------- /src/board/arduino/micro/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += main.c 4 | 5 | EC=atmega 6 | EC_VARIANT=atmega32u4 7 | 8 | PORT=$(wildcard /dev/ttyACM*) 9 | CONSOLE_BAUD=1000000 10 | CFLAGS+=-D__CONSOLE_BAUD__=$(CONSOLE_BAUD) 11 | 12 | console: 13 | sudo tio -b $(CONSOLE_BAUD) $(PORT) 14 | 15 | flash: $(BUILD)/ec.ihx 16 | sudo avrdude -v -v -p $(EC_VARIANT) -c avr109 -P $(PORT) -b 115200 -D -U flash:w:$<:i 17 | -------------------------------------------------------------------------------- /src/board/arduino/micro/include/board/cpu.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_CPU_H 4 | #define _BOARD_CPU_H 5 | 6 | #define F_CPU 16000000ULL 7 | 8 | #endif // _BOARD_CPU_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/micro/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | void init(void) { 9 | uart_stdio_init(0, __CONSOLE_BAUD__); 10 | } 11 | 12 | struct Gpio LED = GPIO(C, 7); 13 | 14 | int main(void) { 15 | init(); 16 | 17 | gpio_set_dir(&LED, true); 18 | gpio_set(&LED, false); 19 | printf("Hello from System76 EC for the Arduino Micro!\n"); 20 | for (;;) { 21 | int c = getchar(); 22 | if (c == '\r') { 23 | putchar('\n'); 24 | } else if (c > 0) { 25 | putchar(c); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/board/arduino/uno/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Uno 2 | 3 | ![Arduino Uno Pinout](https://arduino.pinout.guide/arduino_uno_and_atmega328_pinout.png) 4 | -------------------------------------------------------------------------------- /src/board/arduino/uno/battery.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | 7 | int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data) { 8 | return i2c_get(NULL, address, command, (uint8_t *)data, 2); 9 | } 10 | 11 | int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) { 12 | return i2c_set(NULL, address, command, (uint8_t *)&data, 2); 13 | } 14 | 15 | void battery_debug(void) { 16 | uint16_t data = 0; 17 | int16_t res = 0; 18 | 19 | #define command(N, A, V) \ 20 | { \ 21 | printf(#N ": "); \ 22 | res = smbus_read(A, V, &data); \ 23 | if (res < 0) { \ 24 | printf("ERROR %04X\n", -res); \ 25 | } else { \ 26 | printf("%04X\n", data); \ 27 | } \ 28 | } 29 | 30 | printf("Battery:\n"); 31 | command(Temperature, 0x0B, 0x08); 32 | command(Voltage, 0x0B, 0x09); 33 | command(Current, 0x0B, 0x0A); 34 | command(Charge, 0x0B, 0x0D); 35 | 36 | printf("Charger:\n"); 37 | command(ChargeOption0, 0x09, 0x12); 38 | command(ChargeOption1, 0x09, 0x3B); 39 | command(ChargeOption2, 0x09, 0x38); 40 | command(ChargeOption3, 0x09, 0x37); 41 | command(ChargeCurrent, 0x09, 0x14); 42 | command(ChargeVoltage, 0x09, 0x15); 43 | command(DishargeCurrent, 0x09, 0x39); 44 | command(InputCurrent, 0x09, 0x3F); 45 | command(ProchotOption0, 0x09, 0x3C); 46 | command(ProchotOption1, 0x09, 0x3D); 47 | command(ProchotStatus, 0x09, 0x3A); 48 | 49 | #undef command 50 | } 51 | -------------------------------------------------------------------------------- /src/board/arduino/uno/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += battery.c 4 | board-y += i2c.c 5 | board-y += main.c 6 | board-y += parallel.c 7 | 8 | EC=atmega 9 | EC_VARIANT=atmega328p 10 | 11 | PORT=$(wildcard /dev/ttyACM*) 12 | CONSOLE_BAUD=1000000 13 | CFLAGS+=-D__CONSOLE_BAUD__=$(CONSOLE_BAUD) 14 | 15 | console: 16 | sudo tio -b $(CONSOLE_BAUD) $(PORT) 17 | 18 | flash: $(BUILD)/ec.ihx 19 | sudo avrdude -v -v -p $(EC_VARIANT) -c arduino -P $(PORT) -b 115200 -D -U flash:w:$<:i 20 | -------------------------------------------------------------------------------- /src/board/arduino/uno/i2c.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | void i2c_init(uint32_t baud) { 9 | TWAR = 0; 10 | TWBR = (uint8_t)(((F_CPU / baud) - 16) / 2); 11 | TWCR = 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/board/arduino/uno/include/board/battery.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_BATTERY_H 4 | #define _BOARD_BATTERY_H 5 | 6 | void battery_debug(void); 7 | 8 | #endif // _BOARD_BATTERY_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/uno/include/board/cpu.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_CPU_H 4 | #define _BOARD_CPU_H 5 | 6 | #define F_CPU 16000000ULL 7 | 8 | #endif // _BOARD_CPU_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/uno/include/board/i2c.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_I2C_H 4 | #define _BOARD_I2C_H 5 | 6 | void i2c_init(uint32_t baud); 7 | 8 | #endif // _BOARD_I2C_H 9 | -------------------------------------------------------------------------------- /src/board/arduino/uno/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | void init(void) { 9 | uart_stdio_init(0, __CONSOLE_BAUD__); 10 | } 11 | 12 | struct Gpio LED = GPIO(B, 5); 13 | 14 | //TODO: .h file 15 | int parallel_main(void); 16 | 17 | int main(void) { 18 | init(); 19 | 20 | gpio_set_dir(&LED, true); 21 | gpio_set(&LED, false); 22 | 23 | parallel_main(); 24 | 25 | // If parallel_main exits with an error, wait for reset 26 | for (;;) {} 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/addw1/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void board_init(void) { 9 | // Allow CPU to boot 10 | gpio_set(&SB_KBCRST_N, true); 11 | // Allow backlight to be turned on 12 | gpio_set(&BKL_EN, true); 13 | // Enable camera 14 | gpio_set(&CCD_EN, true); 15 | // Enable right USB port 16 | gpio_set(&USB_PWR_EN_N, false); 17 | // Assert SMI#, SCI#, and SWI# 18 | gpio_set(&SCI_N, true); 19 | gpio_set(&SMI_N, true); 20 | gpio_set(&SWI_N, true); 21 | } 22 | 23 | void board_event(void) { 24 | // Set keyboard LEDs 25 | static uint8_t last_kbc_leds = 0; 26 | if (kbc_leds != last_kbc_leds) { 27 | gpio_set(&LED_SCROLL_N, (kbc_leds & 1) == 0); 28 | gpio_set(&LED_NUM_N, (kbc_leds & 2) == 0); 29 | gpio_set(&LED_CAP_N, (kbc_leds & 4) == 0); 30 | last_kbc_leds = kbc_leds; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/board/system76/addw1/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT8587E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=rgb_pwm 19 | 20 | # Set battery I2C bus 21 | CFLAGS+=-DI2C_SMBUS=I2C_0 22 | 23 | # Set touchpad PS2 bus 24 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 25 | 26 | # Set smart charger parameters 27 | CFLAGS+=\ 28 | -DCHARGER_ADAPTER_RSENSE=5 \ 29 | -DCHARGER_BATTERY_RSENSE=10 \ 30 | -DCHARGER_CHARGE_CURRENT=3072 \ 31 | -DCHARGER_CHARGE_VOLTAGE=12600 \ 32 | -DCHARGER_INPUT_CURRENT=11800 33 | 34 | # Set CPU power limits in watts 35 | CFLAGS+=\ 36 | -DPOWER_LIMIT_AC=180 \ 37 | -DPOWER_LIMIT_DC=45 38 | 39 | # Enable dGPU support 40 | CONFIG_HAVE_DGPU = y 41 | CFLAGS += -DI2C_DGPU=I2C_1 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DBOARD_FAN1_POINTS="\ 46 | FAN_POINT(60, 40), \ 47 | FAN_POINT(65, 60), \ 48 | FAN_POINT(70, 75), \ 49 | FAN_POINT(75, 90), \ 50 | FAN_POINT(80, 100), \ 51 | " 52 | 53 | CFLAGS += -DFAN2_PWM=DCR4 54 | CFLAGS += -DBOARD_FAN2_POINTS="\ 55 | FAN_POINT(60, 40), \ 56 | FAN_POINT(65, 60), \ 57 | FAN_POINT(70, 75), \ 58 | FAN_POINT(75, 90), \ 59 | FAN_POINT(80, 100), \ 60 | " 61 | 62 | # Add system76 common code 63 | include src/board/system76/common/common.mk 64 | -------------------------------------------------------------------------------- /src/board/system76/addw2/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void board_init(void) { 11 | // Allow backlight to be turned on 12 | gpio_set(&BKL_EN, true); 13 | // Enable camera 14 | gpio_set(&CCD_EN, true); 15 | // Assert SMI#, SCI#, and SWI# 16 | gpio_set(&SCI_N, true); 17 | gpio_set(&SMI_N, true); 18 | gpio_set(&SWI_N, true); 19 | } 20 | 21 | void board_event(void) { 22 | ec_read_post_codes(); 23 | 24 | // Set keyboard LEDs 25 | static uint8_t last_kbc_leds = 0; 26 | if (kbc_leds != last_kbc_leds) { 27 | gpio_set(&LED_SCROLL_N, (kbc_leds & 1) == 0); 28 | gpio_set(&LED_NUM_N, (kbc_leds & 2) == 0); 29 | gpio_set(&LED_CAP_N, (kbc_leds & 4) == 0); 30 | last_kbc_leds = kbc_leds; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/board/system76/addw2/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=rgb_pwm 19 | 20 | # Set battery I2C bus 21 | CFLAGS+=-DI2C_SMBUS=I2C_4 22 | 23 | # Set touchpad PS2 bus 24 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 25 | 26 | # Set smart charger parameters 27 | CFLAGS+=\ 28 | -DCHARGER_ADAPTER_RSENSE=5 \ 29 | -DCHARGER_BATTERY_RSENSE=10 \ 30 | -DCHARGER_CHARGE_CURRENT=3072 \ 31 | -DCHARGER_CHARGE_VOLTAGE=12600 \ 32 | -DCHARGER_INPUT_CURRENT=11800 33 | 34 | # Set CPU power limits in watts 35 | CFLAGS+=\ 36 | -DPOWER_LIMIT_AC=180 \ 37 | -DPOWER_LIMIT_DC=45 38 | 39 | # Enable dGPU support 40 | CONFIG_HAVE_DGPU = y 41 | CFLAGS += -DI2C_DGPU=I2C_1 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DBOARD_FAN1_POINTS="\ 46 | FAN_POINT(60, 40), \ 47 | FAN_POINT(65, 60), \ 48 | FAN_POINT(70, 75), \ 49 | FAN_POINT(75, 90), \ 50 | FAN_POINT(80, 100), \ 51 | " 52 | 53 | CFLAGS += -DFAN2_PWM=DCR4 54 | CFLAGS += -DBOARD_FAN2_POINTS="\ 55 | FAN_POINT(60, 40), \ 56 | FAN_POINT(65, 60), \ 57 | FAN_POINT(70, 75), \ 58 | FAN_POINT(75, 90), \ 59 | FAN_POINT(80, 100), \ 60 | " 61 | 62 | # Add system76 common code 63 | include src/board/system76/common/common.mk 64 | -------------------------------------------------------------------------------- /src/board/system76/addw3/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/addw3/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI=y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY=y 16 | 17 | # Include keyboard 18 | KEYBOARD=15in_102 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=rgb_pwm 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_4 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | # TODO: actually bq24800 32 | # FIXME: Verify parts and values. 33 | CHARGER=bq24780s 34 | CFLAGS+=\ 35 | -DCHARGER_ADAPTER_RSENSE=5 \ 36 | -DCHARGER_BATTERY_RSENSE=10 \ 37 | -DCHARGER_CHARGE_CURRENT=1536 \ 38 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 39 | -DCHARGER_INPUT_CURRENT=14000 40 | 41 | # Set CPU power limits in watts 42 | CFLAGS+=\ 43 | -DPOWER_LIMIT_AC=280 \ 44 | -DPOWER_LIMIT_DC=55 45 | 46 | # Enable dGPU support 47 | CONFIG_HAVE_DGPU = y 48 | CFLAGS += -DI2C_DGPU=I2C_1 49 | 50 | # Fan configs 51 | CFLAGS += -DFAN1_PWM=DCR2 52 | CFLAGS += -DBOARD_FAN1_POINTS="\ 53 | FAN_POINT(60, 40), \ 54 | FAN_POINT(65, 60), \ 55 | FAN_POINT(70, 75), \ 56 | FAN_POINT(75, 90), \ 57 | FAN_POINT(80, 100), \ 58 | " 59 | 60 | CFLAGS += -DFAN2_PWM=DCR4 61 | CFLAGS += -DBOARD_FAN2_POINTS="\ 62 | FAN_POINT(60, 40), \ 63 | FAN_POINT(65, 60), \ 64 | FAN_POINT(70, 75), \ 65 | FAN_POINT(75, 90), \ 66 | FAN_POINT(80, 100), \ 67 | " 68 | 69 | # Add system76 common code 70 | include src/board/system76/common/common.mk 71 | -------------------------------------------------------------------------------- /src/board/system76/addw3/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code DGPU_PWR_EN; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | extern struct Gpio __code GC6_FB_EN; 22 | extern struct Gpio __code LAN_WAKEUP_N; 23 | extern struct Gpio __code LED_ACIN; 24 | #define HAVE_LED_AIRPLANE_N 0 25 | extern struct Gpio __code LED_BAT_CHG; 26 | extern struct Gpio __code LED_BAT_FULL; 27 | extern struct Gpio __code LED_PWR; 28 | extern struct Gpio __code LID_SW_N; 29 | extern struct Gpio __code ME_WE; 30 | extern struct Gpio __code PCH_DPWROK_EC; 31 | #define HAVE_PCH_PWROK_EC 0 32 | extern struct Gpio __code PM_PWROK; 33 | extern struct Gpio __code PWR_BTN_N; 34 | extern struct Gpio __code PWR_SW_N; 35 | extern struct Gpio __code RGBKB_DET_N; 36 | extern struct Gpio __code SLP_SUS_N; 37 | #define HAVE_SUS_PWR_ACK 0 38 | extern struct Gpio __code VA_EC_EN; 39 | extern struct Gpio __code WLAN_EN; 40 | extern struct Gpio __code WLAN_PWR_EN; 41 | extern struct Gpio __code XLP_OUT; 42 | 43 | #endif // _BOARD_GPIO_H 44 | -------------------------------------------------------------------------------- /src/board/system76/addw4/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/addw4/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC = ite 7 | CONFIG_EC_ITE_IT5570E = y 8 | CONFIG_EC_FLASH_SIZE_256K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | CONFIG_PECI_OVER_ESPI = y 14 | 15 | # Enable firmware security 16 | CONFIG_SECURITY = y 17 | 18 | # Set keyboard configs 19 | KEYBOARD = 18H9LHA04 20 | 21 | CONFIG_HAVE_KBLED = y 22 | KBLED = rgb_pwm 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS += -DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CHARGER = oz26786 29 | CFLAGS += -DI2C_SMBUS=I2C_4 30 | CFLAGS += \ 31 | -DCHARGER_ADAPTER_RSENSE=5 \ 32 | -DCHARGER_BATTERY_RSENSE=10 \ 33 | -DCHARGER_CHARGE_CURRENT=3072 \ 34 | -DCHARGER_CHARGE_VOLTAGE=17400 \ 35 | -DCHARGER_INPUT_CURRENT=11500 36 | 37 | # Set CPU power limits in watts 38 | CFLAGS += \ 39 | -DPOWER_LIMIT_AC=230 \ 40 | -DPOWER_LIMIT_DC=45 41 | 42 | # Enable DGPU support 43 | CONFIG_HAVE_DGPU = y 44 | CFLAGS += -DI2C_DGPU=I2C_1 45 | 46 | # Fan configs 47 | CFLAGS += -DFAN1_PWM=DCR2 48 | CFLAGS += -DBOARD_FAN1_POINTS="\ 49 | FAN_POINT(60, 28), \ 50 | FAN_POINT(65, 28), \ 51 | FAN_POINT(70, 40), \ 52 | FAN_POINT(75, 60), \ 53 | FAN_POINT(80, 75), \ 54 | FAN_POINT(85, 90), \ 55 | FAN_POINT(90, 100), \ 56 | " 57 | 58 | CFLAGS += -DFAN2_PWM=DCR4 59 | CFLAGS += -DBOARD_FAN2_POINTS="\ 60 | FAN_POINT(60, 28), \ 61 | FAN_POINT(65, 28), \ 62 | FAN_POINT(70, 40), \ 63 | FAN_POINT(75, 60), \ 64 | FAN_POINT(80, 75), \ 65 | FAN_POINT(85, 90), \ 66 | FAN_POINT(90, 100), \ 67 | " 68 | 69 | # Add system76 common code 70 | include src/board/system76/common/common.mk 71 | -------------------------------------------------------------------------------- /src/board/system76/addw4/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code DGPU_PWR_EN; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | extern struct Gpio __code GC6_FB_EN; 22 | extern struct Gpio __code LAN_WAKEUP_N; 23 | extern struct Gpio __code LED_ACIN; 24 | #define HAVE_LED_AIRPLANE_N 0 25 | extern struct Gpio __code LED_BAT_CHG; 26 | extern struct Gpio __code LED_BAT_FULL; 27 | extern struct Gpio __code LED_PWR; 28 | extern struct Gpio __code LID_SW_N; 29 | extern struct Gpio __code ME_WE; 30 | extern struct Gpio __code PCH_DPWROK_EC; 31 | #define HAVE_PCH_PWROK_EC 0 32 | extern struct Gpio __code PM_PWROK; 33 | extern struct Gpio __code PWR_BTN_N; 34 | extern struct Gpio __code PWR_SW_N; 35 | extern struct Gpio __code RGBKB_DET_N; 36 | extern struct Gpio __code SLP_SUS_N; 37 | #define HAVE_SUS_PWR_ACK 0 38 | extern struct Gpio __code VA_EC_EN; 39 | #define HAVE_WLAN_EN 0 40 | extern struct Gpio __code WLAN_PWR_EN; 41 | extern struct Gpio __code XLP_OUT; 42 | 43 | #endif // _BOARD_GPIO_H 44 | -------------------------------------------------------------------------------- /src/board/system76/bonw14/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | // Allow CPU to boot 11 | gpio_set(&SB_KBCRST_N, true); 12 | // Allow backlight to be turned on 13 | gpio_set(&BKL_EN, true); 14 | // Enable camera 15 | gpio_set(&CCD_EN, true); 16 | // Enable USB port power? 17 | gpio_set(&USB_PWR_EN_N, false); 18 | // Assert SMI#, SCI#, and SWI# 19 | gpio_set(&SCI_N, true); 20 | gpio_set(&SMI_N, true); 21 | gpio_set(&SWI_N, true); 22 | } 23 | 24 | void board_event(void) { 25 | ec_read_post_codes(); 26 | } 27 | -------------------------------------------------------------------------------- /src/board/system76/bonw14/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102_nkey 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=bonw14 19 | 20 | # Set battery I2C bus 21 | CFLAGS+=-DI2C_SMBUS=I2C_4 22 | 23 | # Set touchpad PS2 bus 24 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 25 | 26 | # Set smart charger parameters 27 | CFLAGS+=\ 28 | -DCHARGER_ADAPTER_RSENSE=5 \ 29 | -DCHARGER_BATTERY_RSENSE=10 \ 30 | -DCHARGER_CHARGE_CURRENT=3072 \ 31 | -DCHARGER_CHARGE_VOLTAGE=16800 \ 32 | -DCHARGER_INPUT_CURRENT=14000 33 | 34 | # Set CPU power limits in watts 35 | CFLAGS+=\ 36 | -DPOWER_LIMIT_AC=180 \ 37 | -DPOWER_LIMIT_DC=45 38 | 39 | # Enable dGPU support 40 | CONFIG_HAVE_DGPU = y 41 | CFLAGS += -DI2C_DGPU=I2C_1 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DBOARD_FAN1_POINTS="\ 46 | FAN_POINT(60, 40), \ 47 | FAN_POINT(65, 60), \ 48 | FAN_POINT(70, 75), \ 49 | FAN_POINT(75, 90), \ 50 | FAN_POINT(80, 100), \ 51 | " 52 | 53 | CFLAGS += -DFAN2_PWM=DCR4 54 | CFLAGS += -DBOARD_FAN2_POINTS="\ 55 | FAN_POINT(60, 40), \ 56 | FAN_POINT(65, 60), \ 57 | FAN_POINT(70, 75), \ 58 | FAN_POINT(75, 90), \ 59 | FAN_POINT(80, 100), \ 60 | " 61 | 62 | # Add system76 common code 63 | include src/board/system76/common/common.mk 64 | -------------------------------------------------------------------------------- /src/board/system76/bonw15/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | } 20 | 21 | void board_event(void) { 22 | espi_event(); 23 | 24 | ec_read_post_codes(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/bonw15/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code JACK_IN_N; 24 | extern struct Gpio __code LAN_WAKEUP_N; 25 | extern struct Gpio __code LED_ACIN; 26 | #define HAVE_LED_AIRPLANE_N 0 27 | extern struct Gpio __code LED_BAT_CHG; 28 | extern struct Gpio __code LED_BAT_FULL; 29 | extern struct Gpio __code LED_PWR; 30 | extern struct Gpio __code LID_SW_N; 31 | extern struct Gpio __code ME_WE; 32 | extern struct Gpio __code PCH_DPWROK_EC; 33 | extern struct Gpio __code PCH_PWROK_EC; 34 | #define HAVE_PM_PWROK 0 35 | extern struct Gpio __code PWR_BTN_N; 36 | extern struct Gpio __code PWR_SW_N; 37 | extern struct Gpio __code RGBKB_DET_N; 38 | extern struct Gpio __code SINK_CTRL; 39 | extern struct Gpio __code SLP_SUS_N; 40 | #define HAVE_SUS_PWR_ACK 0 41 | extern struct Gpio __code VA_EC_EN; 42 | extern struct Gpio __code WLAN_EN; 43 | extern struct Gpio __code WLAN_PWR_EN; 44 | extern struct Gpio __code XLP_OUT; 45 | 46 | #endif // _BOARD_GPIO_H 47 | -------------------------------------------------------------------------------- /src/board/system76/common/config.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /** 11 | * Test if the EC should reset its configuration. 12 | */ 13 | bool config_should_reset(void) { 14 | return kbscan_fn_held && kbscan_esc_held; 15 | } 16 | 17 | /** 18 | * Reset the EC configuration data. 19 | */ 20 | void config_reset(void) { 21 | INFO("Reset configuration\n"); 22 | battery_reset(); 23 | keymap_erase_config(); 24 | keymap_load_default(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/common/dgpu.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int16_t dgpu_temp = 0; 11 | 12 | // Update interval is 250ms, so average over 1s period 13 | static int16_t dgpu_temps[4] = { 0 }; 14 | 15 | void dgpu_init(void) { 16 | // Set up for i2c usage 17 | i2c_reset(&I2C_DGPU, true); 18 | } 19 | 20 | bool dgpu_get_temp(int16_t *const data) { 21 | if (gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) { 22 | int8_t rlts; 23 | int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1); 24 | if (res == 1) { 25 | *data = (int16_t)rlts; 26 | return true; 27 | } else { 28 | DEBUG("DGPU temp error: %d\n", res); 29 | *data = 0; 30 | return false; 31 | } 32 | } 33 | 34 | *data = 0; 35 | return true; 36 | } 37 | 38 | void dgpu_read_temp(void) { 39 | dgpu_temps[0] = dgpu_temps[1]; 40 | dgpu_temps[1] = dgpu_temps[2]; 41 | dgpu_temps[2] = dgpu_temps[3]; 42 | 43 | if (power_state == POWER_STATE_S0) { 44 | if (!dgpu_get_temp(&dgpu_temps[3])) { 45 | dgpu_temps[3] = 0; 46 | } 47 | } else { 48 | dgpu_temps[3] = 0; 49 | } 50 | 51 | dgpu_temp = (dgpu_temps[0] + dgpu_temps[1] + dgpu_temps[2] + dgpu_temps[3]) / 52 | ARRAY_SIZE(dgpu_temps); 53 | } 54 | -------------------------------------------------------------------------------- /src/board/system76/common/ecpm.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | void ecpm_init(void) { 7 | // Clock gate EGPC, CIR, and SWUC 8 | CGCTRL2 |= BIT(6) | BIT(5) | BIT(4); 9 | // Clock gate UART, SSPI, and DBGR 10 | CGCTRL3 |= BIT(2) | BIT(1) | BIT(0); 11 | // Clock gate CEC 12 | CGCTRL4 |= BIT(0); 13 | } 14 | -------------------------------------------------------------------------------- /src/board/system76/common/flash/include/flash/entry.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | #ifndef _FLASH_ENTRY_H 4 | #define _FLASH_ENTRY_H 5 | 6 | void flash_entry(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) __reentrant; 7 | 8 | #endif // _FLASH_ENTRY_H 9 | -------------------------------------------------------------------------------- /src/board/system76/common/gctrl.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | void gctrl_init(void) { 6 | // Set I2EC as R/W 7 | SPCTRL1 |= 0x03; 8 | // Set PNPCFG base address 9 | BADRSEL = 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/acpi.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_ACPI_H 4 | #define _BOARD_ACPI_H 5 | 6 | #include 7 | 8 | enum EcOs { 9 | // No ACPI or driver support 10 | EC_OS_NONE = 0, 11 | // ACPI, but no driver support 12 | EC_OS_ACPI = 1, 13 | // ACPI with driver, full support 14 | EC_OS_FULL = 2, 15 | }; 16 | extern enum EcOs acpi_ecos; 17 | 18 | void acpi_reset(void); 19 | uint8_t acpi_read(uint8_t addr); 20 | void acpi_write(uint8_t addr, uint8_t data); 21 | 22 | #endif // _BOARD_ACPI_H 23 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/battery.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_BATTERY_H 4 | #define _BOARD_BATTERY_H 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #ifndef BATTERY_ADDRESS 12 | #define BATTERY_ADDRESS 0x0B 13 | #endif 14 | 15 | #ifndef CHARGER_ADDRESS 16 | #define CHARGER_ADDRESS 0x09 17 | #endif 18 | 19 | #define BATTERY_FULLY_DISCHARGED BIT(4) 20 | #define BATTERY_FULLY_CHARGED BIT(5) 21 | #define BATTERY_DISCHARGING BIT(6) 22 | #define BATTERY_INITIALIZED BIT(7) 23 | 24 | struct battery_info { 25 | uint16_t temp; 26 | uint16_t voltage; 27 | uint16_t current; 28 | uint16_t charge; 29 | uint16_t remaining_capacity; 30 | uint16_t full_capacity; 31 | uint16_t status; 32 | uint16_t cycle_count; 33 | uint16_t design_capacity; 34 | uint16_t design_voltage; 35 | }; 36 | extern struct battery_info battery_info; 37 | 38 | extern uint16_t battery_charger_input_current; 39 | 40 | uint8_t battery_get_start_threshold(void); 41 | bool battery_set_start_threshold(uint8_t value); 42 | 43 | uint8_t battery_get_end_threshold(void); 44 | bool battery_set_end_threshold(uint8_t value); 45 | 46 | bool battery_load_thresholds(void); 47 | bool battery_save_thresholds(void); 48 | 49 | int16_t battery_charger_configure(void); 50 | void battery_event(void); 51 | void battery_reset(void); 52 | 53 | // Defined by charger/*.c 54 | int16_t battery_charger_disable(void); 55 | int16_t battery_charger_enable(void); 56 | void battery_charger_event(void); 57 | void battery_debug(void); 58 | 59 | #endif // _BOARD_BATTERY_H 60 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/board.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_BOARD_H 4 | #define _BOARD_BOARD_H 5 | 6 | #include 7 | 8 | void board_init(void); 9 | void board_event(void); 10 | 11 | #endif // _BOARD_BOARD_H 12 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/config.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_CONFIG_H 4 | #define _BOARD_CONFIG_H 5 | 6 | #include 7 | 8 | bool config_should_reset(void); 9 | void config_reset(void); 10 | 11 | #endif // _BOARD_CONFIG_H 12 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/cpu.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_CPU_H 4 | #define _BOARD_CPU_H 5 | 6 | #define F_CPU 9200000ULL 7 | 8 | #endif // _BOARD_CPU_H 9 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/dgpu.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_DGPU_H 4 | #define _BOARD_DGPU_H 5 | 6 | #include 7 | #include 8 | 9 | #if CONFIG_HAVE_DGPU 10 | 11 | extern int16_t dgpu_temp; 12 | 13 | void dgpu_init(void); 14 | bool dgpu_get_temp(int16_t *const data); 15 | void dgpu_read_temp(void); 16 | 17 | #else 18 | 19 | static inline void dgpu_init(void) {} 20 | 21 | static inline bool dgpu_get_temp(int16_t *const data) { 22 | *data = 0; 23 | return true; 24 | } 25 | 26 | static inline void dgpu_read_temp(void) {} 27 | 28 | #endif // CONFIG_HAVE_DGPU 29 | 30 | #endif // _BOARD_DGPU_H 31 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/ecpm.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_ECPM_H 4 | #define _BOARD_ECPM_H 5 | 6 | #include 7 | 8 | void ecpm_init(void); 9 | 10 | #endif // _BOARD_ECPM_H 11 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/espi.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_ESPI_H 4 | #define _BOARD_ESPI_H 5 | 6 | #include 7 | 8 | #include 9 | 10 | extern bool espi_host_reset; 11 | 12 | void espi_init(void); 13 | void espi_reset(void); 14 | void espi_event(void); 15 | 16 | #endif // _BOARD_ESPI_H 17 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/fan.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_FAN_H 4 | #define _BOARD_FAN_H 5 | 6 | #include 7 | #include 8 | 9 | #define PWM_DUTY(X) ((uint8_t)(((((uint16_t)(X)) * 255) + 99) / 100)) 10 | 11 | struct FanPoint { 12 | int16_t temp; 13 | uint8_t duty; 14 | }; 15 | 16 | struct Fan { 17 | const struct FanPoint *points; 18 | uint8_t points_size; 19 | uint8_t *cooldown; 20 | uint8_t cooldown_size; 21 | uint8_t pwm_min; 22 | }; 23 | 24 | enum FanMode { 25 | // EC control 26 | FAN_MODE_AUTO = 0, 27 | // Host control via target PWM 28 | FAN_MODE_PWM = 1, 29 | // Host control via target RPM 30 | FAN_MODE_RPM = 2, 31 | }; 32 | 33 | extern bool fan_max; 34 | 35 | extern uint8_t fan1_pwm_actual; 36 | extern uint8_t fan1_pwm_target; 37 | extern uint16_t fan1_rpm; 38 | extern uint8_t fan2_pwm_actual; 39 | extern uint8_t fan2_pwm_target; 40 | extern uint16_t fan2_rpm; 41 | 42 | void fan_reset(void); 43 | void fan_update_duty(void); 44 | void fan_update_target(void); 45 | 46 | enum FanMode fan_get_mode(void); 47 | void fan_set_mode(enum FanMode); 48 | 49 | #endif // _BOARD_FAN_H 50 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/gctrl.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GCTRL_H 4 | #define _BOARD_GCTRL_H 5 | 6 | #include 7 | 8 | void gctrl_init(void); 9 | 10 | #endif // _BOARD_GCTRL_H 11 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/kbc.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_KBC_H 4 | #define _BOARD_KBC_H 5 | 6 | #include 7 | 8 | #include 9 | 10 | extern uint8_t kbc_leds; 11 | 12 | void kbc_init(void); 13 | void kbc_reset(void); 14 | bool kbc_scancode(uint16_t key, bool pressed); 15 | void kbc_event(struct Kbc *const kbc); 16 | 17 | #endif // _BOARD_KBC_H 18 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/kbled.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_KBLED_H 4 | #define _BOARD_KBLED_H 5 | 6 | #include 7 | 8 | #if CONFIG_HAVE_KBLED 9 | 10 | enum KbledKind { 11 | KBLED_NONE = 0, 12 | KBLED_WHITE = 1, 13 | KBLED_RGB = 2, 14 | }; 15 | extern enum KbledKind kbled_kind; 16 | 17 | // Must be specified per mechanism 18 | void kbled_init(void); 19 | void kbled_reset(void); 20 | uint8_t kbled_get(void); 21 | uint8_t kbled_max(void); 22 | void kbled_set(uint8_t level); 23 | uint32_t kbled_get_color(void); 24 | void kbled_set_color(uint32_t color); 25 | 26 | // Provided by common code 27 | void kbled_hotkey_color(void); 28 | void kbled_hotkey_down(void); 29 | void kbled_hotkey_up(void); 30 | void kbled_hotkey_toggle(void); 31 | void kbled_hotkey_step(void); 32 | 33 | #else // CONFIG_HAVE_KBLED 34 | 35 | static inline void kbled_init(void) {} 36 | static inline void kbled_reset(void) {} 37 | 38 | static inline uint8_t kbled_get(void) { 39 | return 0; 40 | } 41 | 42 | static inline uint8_t kbled_max(void) { 43 | return 0; 44 | } 45 | 46 | static inline void kbled_set(uint8_t level) { 47 | (void)level; 48 | } 49 | 50 | static inline uint32_t kbled_get_color(void) { 51 | return 0; 52 | } 53 | 54 | static inline void kbled_set_color(uint32_t color) { 55 | (void)color; 56 | } 57 | 58 | static inline void kbled_hotkey_color(void) {} 59 | static inline void kbled_hotkey_down(void) {} 60 | static inline void kbled_hotkey_up(void) {} 61 | static inline void kbled_hotkey_toggle(void) {} 62 | static inline void kbled_hotkey_step(void) {} 63 | 64 | #endif // CONFIG_HAVE_KBLED 65 | 66 | #endif // _BOARD_KBLED_H 67 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/kbscan.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_KBSCAN_H 4 | #define _BOARD_KBSCAN_H 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | // EC config reset key combo: Fn+Esc 12 | extern bool kbscan_fn_held; 13 | extern bool kbscan_esc_held; 14 | 15 | extern bool kbscan_enabled; 16 | 17 | // ms between repeating key 18 | extern uint16_t kbscan_repeat_period; 19 | // ms between pressing key and repeating 20 | extern uint16_t kbscan_repeat_delay; 21 | 22 | // Debounced kbscan matrix 23 | extern uint8_t kbscan_matrix[KM_OUT]; 24 | 25 | void kbscan_init(void); 26 | void kbscan_event(void); 27 | 28 | #endif // _BOARD_KBSCAN_H 29 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/lid.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_LID_H 4 | #define _BOARD_LID_H 5 | 6 | #include 7 | 8 | extern bool lid_state; 9 | extern bool lid_wake; 10 | 11 | void lid_event(void); 12 | 13 | #endif // _BOARD_LID_H 14 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/parallel.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_PARALLEL_H 4 | #define _BOARD_PARALLEL_H 5 | 6 | #include 7 | #include 8 | 9 | extern bool parallel_debug; 10 | bool parallel_init(void); 11 | int16_t parallel_write(const uint8_t *const data, uint16_t length); 12 | 13 | #endif // _BOARD_PARALLEL_H 14 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/peci.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_PECI_H 4 | #define _BOARD_PECI_H 5 | 6 | #include 7 | #include 8 | 9 | extern bool peci_on; 10 | extern int16_t peci_temp; 11 | 12 | enum PeciCmd { 13 | PECI_CMD_PING = 0x00, 14 | PECI_CMD_GET_TEMP = 0x01, 15 | PECI_CMD_RD_PKG_CONFIG = 0xA1, 16 | PECI_CMD_WR_PKG_CONFIG = 0xA5, 17 | PECI_CMD_RD_IAMSR = 0xB1, 18 | PECI_CMD_GET_DIB = 0xF7, 19 | }; 20 | 21 | void peci_init(void); 22 | bool peci_available(void); 23 | int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data); 24 | void peci_read_temp(void); 25 | 26 | #endif // _BOARD_PECI_H 27 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/pmc.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_PMC_H 4 | #define _BOARD_PMC_H 5 | 6 | #include 7 | 8 | void pmc_init(void); 9 | bool pmc_sci(struct Pmc *const pmc, uint8_t sci); 10 | void pmc_swi(void); 11 | void pmc_event(struct Pmc *const pmc); 12 | 13 | #endif // _BOARD_PMC_H 14 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/pnp.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_PNP_H 4 | #define _BOARD_PNP_H 5 | 6 | #include 7 | 8 | uint8_t pnp_read(uint8_t reg); 9 | void pnp_write(uint8_t reg, uint8_t data); 10 | void pnp_enable(void); 11 | 12 | #endif // _BOARD_PNP_H 13 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/power.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_POWER_H 4 | #define _BOARD_POWER_H 5 | 6 | enum PowerState { 7 | POWER_STATE_OFF, 8 | POWER_STATE_S5, 9 | POWER_STATE_S3, 10 | POWER_STATE_S0, 11 | }; 12 | 13 | extern enum PowerState power_state; 14 | void update_power_state(void); 15 | 16 | void power_init(void); 17 | void power_on(void); 18 | void power_off(void); 19 | void power_cpu_reset(void); 20 | void power_event(void); 21 | 22 | #endif // _BOARD_POWER_H 23 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/ps2.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_PS2_H 4 | #define _BOARD_PS2_H 5 | 6 | #include 7 | 8 | void ps2_init(void); 9 | 10 | #endif // _BOARD_PS2_H 11 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/pwm.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_PWM_H 4 | #define _BOARD_PWM_H 5 | 6 | void pwm_init(void); 7 | 8 | #endif // _BOARD_PWM_H 9 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/scratch.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_SCRATCH_H 4 | #define _BOARD_SCRATCH_H 5 | 6 | void scratch_trampoline(void); 7 | 8 | #endif // _BOARD_SCRATCH_H 9 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/security.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_SECURITY_H 4 | #define _BOARD_SECURITY_H 5 | 6 | #include 7 | #include 8 | 9 | enum SecurityState security_get(void); 10 | bool security_set(enum SecurityState state); 11 | bool security_power(void); 12 | 13 | #endif // _BOARD_SECURITY_H 14 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/smbus.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_SMBUS_H 4 | #define _BOARD_SMBUS_H 5 | 6 | #include 7 | 8 | void smbus_init(void); 9 | int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data); 10 | int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data); 11 | 12 | #endif // _BOARD_SMBUS_H 13 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/smfi.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_SMFI_H 4 | #define _BOARD_SMFI_H 5 | 6 | #include 7 | 8 | void smfi_init(void); 9 | void smfi_watchdog(void); 10 | void smfi_event(void); 11 | void smfi_debug(uint8_t byte); 12 | 13 | #endif // _BOARD_SMFI_H 14 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/usbpd.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_USBPD_H 4 | #define _BOARD_USBPD_H 5 | 6 | #if CONFIG_HAVE_USBPD 7 | 8 | void usbpd_init(void); 9 | void usbpd_event(void); 10 | void usbpd_disable_charging(void); 11 | void usbpd_enable_charging(void); 12 | 13 | #else 14 | 15 | static inline void usbpd_init(void) {} 16 | static inline void usbpd_event(void) {} 17 | static inline void usbpd_disable_charging(void) {} 18 | static inline void usbpd_enable_charging(void) {} 19 | 20 | #endif 21 | 22 | #endif // _BOARD_USBPD_H 23 | -------------------------------------------------------------------------------- /src/board/system76/common/include/board/wireless.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_WIRELESS_H 4 | #define _BOARD_WIRELESS_H 5 | 6 | #include 7 | 8 | void wireless_power(bool); 9 | 10 | #endif // _BOARD_WIRELESS_H 11 | -------------------------------------------------------------------------------- /src/board/system76/common/kbled/bonw14.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void kbled_init(void) { 10 | kbled_kind = KBLED_RGB; 11 | 12 | i2c_reset(&I2C_DGPU, true); 13 | 14 | // Force SMBUS B design to 100kHZ 15 | SCLKTSB = 0b10; 16 | } 17 | 18 | void kbled_reset(void) { 19 | uint8_t value = 0xE4; 20 | int16_t res = i2c_set(&I2C_DGPU, 0x2D, 0xA0, &value, 1); 21 | DEBUG("kbled_reset 0x2D: %d\n", res); 22 | 23 | //value = 0xC4; 24 | //res = i2c_set(&I2C_DGPU, 0x66, 0xA0, &value, 1); 25 | //DEBUG("kbled_reset 0x66: %d\n", res); 26 | 27 | // Set brightness and color 28 | kbled_set_color(0xFFFFFF); 29 | kbled_set(0x00); 30 | } 31 | 32 | // Keep the following functions for compatibility - they are set via USB HID 33 | uint8_t kbled_get(void) { 34 | // Always off 35 | return 0; 36 | } 37 | 38 | uint8_t kbled_max(void) { 39 | // Always off 40 | return 0; 41 | } 42 | 43 | void kbled_set(uint8_t level) { 44 | // Fix unused variable 45 | level = level; 46 | } 47 | 48 | uint32_t kbled_get_color(void) { 49 | // Always black 50 | return 0; 51 | } 52 | 53 | void kbled_set_color(uint32_t color) { 54 | // Fix unused variable 55 | color = color; 56 | } 57 | -------------------------------------------------------------------------------- /src/board/system76/common/kbled/rgb_pwm.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void kbled_init(void) { 8 | if (!gpio_get(&RGBKB_DET_N)) { 9 | kbled_kind = KBLED_RGB; 10 | } else { 11 | kbled_kind = KBLED_WHITE; 12 | } 13 | 14 | //TODO: enable PWMs 15 | kbled_reset(); 16 | } 17 | 18 | void kbled_reset(void) { 19 | // Set brightness and color 20 | kbled_set_color(0xFFFFFF); 21 | kbled_set(0x00); 22 | } 23 | 24 | uint8_t kbled_get(void) { 25 | // Get PWM for power 26 | return DCR0; 27 | } 28 | 29 | uint8_t kbled_max(void) { 30 | return 255; 31 | } 32 | 33 | void kbled_set(uint8_t level) { 34 | // Set PWM for power 35 | DCR0 = level; 36 | } 37 | 38 | uint32_t kbled_get_color(void) { 39 | if (kbled_kind == KBLED_WHITE) 40 | return 0xFFFFFF; 41 | 42 | // Get PWM of blue component 43 | uint32_t color = (uint32_t)DCR7; 44 | 45 | // Get PWM of green component 46 | color |= ((uint32_t)DCR6) << 8; 47 | 48 | // Get PWM of red component 49 | color |= ((uint32_t)DCR5) << 16; 50 | 51 | return color; 52 | } 53 | 54 | void kbled_set_color(uint32_t color) { 55 | if (kbled_kind == KBLED_WHITE) 56 | color = 0xFFFFFF; 57 | 58 | // Set PWM for blue component 59 | DCR7 = (uint8_t)(color); 60 | 61 | // Set PWM for green component 62 | DCR6 = (uint8_t)(color >> 8); 63 | 64 | // Set PWM for red component 65 | DCR5 = (uint8_t)(color >> 16); 66 | } 67 | -------------------------------------------------------------------------------- /src/board/system76/common/kbled/white_dac.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #if !defined(KBLED_DAC) 8 | #error "KBLED_DAC must be defined" 9 | #endif 10 | 11 | #define KBLED_DACDAT xconcat(DACDAT, KBLED_DAC) 12 | 13 | void kbled_init(void) { 14 | kbled_kind = KBLED_WHITE; 15 | 16 | // Enable DAC used for KBLIGHT_ADJ 17 | DACPDREG &= ~BIT(KBLED_DAC); 18 | kbled_reset(); 19 | } 20 | 21 | void kbled_reset(void) { 22 | kbled_set(0); 23 | } 24 | 25 | uint8_t kbled_get(void) { 26 | return KBLED_DACDAT; 27 | } 28 | 29 | uint8_t kbled_max(void) { 30 | return 0xFF; 31 | } 32 | 33 | void kbled_set(uint8_t level) { 34 | KBLED_DACDAT = level; 35 | } 36 | 37 | uint32_t kbled_get_color(void) { 38 | // Always white 39 | return 0xFFFFFF; 40 | } 41 | 42 | void kbled_set_color(uint32_t color) { 43 | // Fix unused variable 44 | color = color; 45 | } 46 | -------------------------------------------------------------------------------- /src/board/system76/common/lid.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // Default closed to prevent spurious power on 11 | bool lid_state = false; 12 | bool lid_wake = false; 13 | 14 | void lid_event(void) { 15 | static bool send_sci = true; 16 | 17 | // Check if the lid switch has changed 18 | bool new = gpio_get(&LID_SW_N); 19 | if (new != lid_state) { 20 | DEBUG("Lid "); 21 | if (new) { 22 | DEBUG("open\n"); 23 | 24 | if (lid_wake) { 25 | pmc_swi(); 26 | lid_wake = false; 27 | } 28 | } else { 29 | DEBUG("closed\n"); 30 | } 31 | 32 | // Send SCI if ACPI OS is loaded 33 | send_sci = true; 34 | } 35 | lid_state = new; 36 | 37 | if (send_sci) { 38 | // Send SCI 0x1B for lid event if ACPI OS is loaded 39 | if (acpi_ecos != EC_OS_NONE) { 40 | if (pmc_sci(&PMC_1, 0x1B)) { 41 | send_sci = false; 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/board/system76/common/power/amd.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | enum PowerState power_state = POWER_STATE_OFF; 6 | 7 | void update_power_state(void) {} 8 | void power_init(void) {} 9 | void power_on(void) {} 10 | void power_off(void) {} 11 | void power_cpu_reset(void) {} 12 | void power_event(void) {} 13 | -------------------------------------------------------------------------------- /src/board/system76/common/ps2.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | void ps2_init(void) { 6 | ps2_reset(&PS2_1); 7 | ps2_reset(&PS2_2); 8 | ps2_reset(&PS2_3); 9 | } 10 | -------------------------------------------------------------------------------- /src/board/system76/common/pwm.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void pwm_init(void) { 8 | // Set T0CHSEL to TACH0A and T1CHSEL to TACH1A 9 | TSWCTLR = 0; 10 | 11 | // Disable PWM 12 | ZTIER = 0; 13 | 14 | // Set prescalar clock frequency to EC clock 15 | PCFSR = 0b01; 16 | 17 | // Use C0CPRS and CTR0 for all channels 18 | PCSSGL = 0; 19 | PCSSGH = 0; 20 | 21 | // Set clock prescaler to 0 + 1 22 | C0CPRS = 0; 23 | 24 | // Set cycle time to 255 + 1 25 | CTR0 = 255; 26 | 27 | // Turn off fans 28 | FAN1_PWM = 0; 29 | #ifdef FAN2_PWM 30 | FAN2_PWM = 0; 31 | #endif 32 | 33 | #if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E 34 | // Reload counters when they reach 0 instead of immediately 35 | PWMLCCR = 0xFF; 36 | #endif 37 | 38 | // Enable PWM 39 | ZTIER = BIT(1); 40 | } 41 | -------------------------------------------------------------------------------- /src/board/system76/common/scratch.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include <8051.h> 11 | #include 12 | 13 | // Include scratch ROM 14 | uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = { 15 | #include 16 | }; 17 | 18 | // Enter or exit scratch ROM 19 | void scratch_trampoline(void) { 20 | // Set fans to 100% 21 | FAN1_PWM = CTR0; 22 | #ifdef FAN2_PWM 23 | FAN2_PWM = CTR0; 24 | #endif 25 | 26 | //TODO: Clear keyboard presses 27 | 28 | // Start watchdog timer 29 | smfi_watchdog(); 30 | 31 | // Disable interrupts 32 | EA = 0; 33 | 34 | // Use DMA mapping to copy flash data 35 | SCARH = 0x80; 36 | SCARL = (uint8_t)(SCRATCH_OFFSET); 37 | SCARM = (uint8_t)(SCRATCH_OFFSET >> 8); 38 | SCARH = 0; 39 | 40 | // Jump to scratch reset function 41 | __asm__("ljmp " xstr(SCRATCH_OFFSET)); 42 | } 43 | -------------------------------------------------------------------------------- /src/board/system76/common/scratch/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | // Main program while running in scratch ROM 6 | void main(void) { 7 | for (;;) { 8 | smfi_event(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/board/system76/common/scratch/stdio.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | 7 | int putchar(int c) { 8 | uint8_t byte = (uint8_t)c; 9 | smfi_debug(byte); 10 | return (int)byte; 11 | } 12 | -------------------------------------------------------------------------------- /src/board/system76/common/security.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | static enum SecurityState security_state = SECURITY_STATE_LOCK; 7 | 8 | enum SecurityState security_get(void) { 9 | return security_state; 10 | } 11 | 12 | bool security_set(enum SecurityState state) { 13 | switch (state) { 14 | // Allow prepare states to be set 15 | case SECURITY_STATE_PREPARE_LOCK: 16 | case SECURITY_STATE_PREPARE_UNLOCK: 17 | security_state = state; 18 | return true; 19 | // Any other states will be ignored 20 | default: 21 | return false; 22 | } 23 | } 24 | 25 | bool security_power(void) { 26 | switch (security_state) { 27 | // Apply lock state and power on 28 | case SECURITY_STATE_PREPARE_LOCK: 29 | gpio_set(&ME_WE, false); 30 | security_state = SECURITY_STATE_LOCK; 31 | return true; 32 | // Apply unlock state and power on 33 | case SECURITY_STATE_PREPARE_UNLOCK: 34 | gpio_set(&ME_WE, true); 35 | security_state = SECURITY_STATE_UNLOCK; 36 | return true; 37 | // Any other states will be ignored 38 | default: 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/board/system76/common/smbus.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | void smbus_init(void) { 7 | // 9.2 MHz * 4.7 us = 43.24 8 | SMB4P7USL = 43; 9 | // 9.2 MHz * 4.0 us = 36.8 10 | SMB4P0USL = 37; 11 | // 9.2 MHz * 300 ns = 2.76 12 | SMB300NS = 3; 13 | // 9.2 MHz * 250 ns = 2.3 14 | SMB250NS = 2; 15 | // 1.024 KHz * 25 ms = 25.6 16 | SMB25MS = 26; 17 | // 9.2 MHz * 45.3 us = 416.76 (0x01A1) 18 | SMB45P3USL = 0xA1; 19 | SMB45P3USH = 0x01; 20 | 21 | // Set up for i2c usage 22 | i2c_reset(&I2C_SMBUS, true); 23 | } 24 | 25 | int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data) { 26 | return i2c_get(&I2C_SMBUS, address, command, (uint8_t *const)data, 2); 27 | } 28 | 29 | int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) { 30 | return i2c_set(&I2C_SMBUS, address, command, (uint8_t *const)&data, 2); 31 | } 32 | -------------------------------------------------------------------------------- /src/board/system76/common/stdio.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #include 6 | 7 | #ifdef SERIAL_DEBUGGER 8 | #include 9 | #endif 10 | 11 | #ifdef I2C_DEBUGGER 12 | #include 13 | #endif 14 | 15 | #ifdef PARALLEL_DEBUG 16 | #include 17 | #endif // PARALLEL_DEBUG 18 | 19 | int putchar(int c) { 20 | uint8_t byte = (uint8_t)c; 21 | 22 | smfi_debug(byte); 23 | 24 | #ifdef SERIAL_DEBUGGER 25 | SBUF = byte; 26 | #endif 27 | 28 | #ifdef I2C_DEBUGGER 29 | i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); 30 | #endif 31 | 32 | #ifdef PARALLEL_DEBUG 33 | if (parallel_debug) { 34 | parallel_write(&byte, 1); 35 | } 36 | #endif // PARALLEL_DEBUG 37 | 38 | return (int)byte; 39 | } 40 | -------------------------------------------------------------------------------- /src/board/system76/common/wireless.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | #ifndef HAVE_BT_EN 7 | #define HAVE_BT_EN 1 8 | #endif 9 | #ifndef HAVE_WLAN_EN 10 | #define HAVE_WLAN_EN 1 11 | #endif 12 | #ifndef HAVE_WLAN_PWR_EN 13 | #define HAVE_WLAN_PWR_EN 1 14 | #endif 15 | 16 | /** 17 | * Set the WLAN card power state. 18 | */ 19 | void wireless_power(bool enable) { 20 | MAYBE_UNUSED(enable); 21 | 22 | #if HAVE_BT_EN 23 | gpio_set(&BT_EN, enable); 24 | #endif 25 | #if HAVE_WLAN_EN 26 | gpio_set(&WLAN_EN, enable); 27 | #endif 28 | #if HAVE_WLAN_PWR_EN 29 | gpio_set(&WLAN_PWR_EN, enable); 30 | #endif 31 | } 32 | -------------------------------------------------------------------------------- /src/board/system76/darp10-b/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | battery_charger_disable(); 12 | 13 | // Allow backlight to be turned on 14 | gpio_set(&BKL_EN, true); 15 | // Enable camera 16 | gpio_set(&CCD_EN, true); 17 | } 18 | 19 | void board_event(void) { 20 | espi_event(); 21 | 22 | ec_read_post_codes(); 23 | } 24 | -------------------------------------------------------------------------------- /src/board/system76/darp10-b/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code EC_EN; 19 | extern struct Gpio __code EC_RSMRST_N; 20 | extern struct Gpio __code LAN_WAKEUP_N; 21 | extern struct Gpio __code LED_ACIN; 22 | #define HAVE_LED_AIRPLANE_N 0 23 | extern struct Gpio __code LED_BAT_CHG; 24 | extern struct Gpio __code LED_BAT_FULL; 25 | extern struct Gpio __code LED_PWR; 26 | extern struct Gpio __code LID_SW_N; 27 | extern struct Gpio __code ME_WE; 28 | #define HAVE_PCH_DPWROK_EC 0 29 | extern struct Gpio __code PCH_PWROK_EC; 30 | #define HAVE_PD_EN 1 31 | extern struct Gpio __code PD_EN; 32 | #define HAVE_PM_PWROK 0 33 | extern struct Gpio __code PWR_BTN_N; 34 | extern struct Gpio __code PWR_SW_N; 35 | extern struct Gpio __code RGBKB_DET_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | #define HAVE_SLP_SUS_N 0 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | #define HAVE_SUSWARN_N 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/darp10/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | battery_charger_disable(); 12 | 13 | // Allow backlight to be turned on 14 | gpio_set(&BKL_EN, true); 15 | // Enable camera 16 | gpio_set(&CCD_EN, true); 17 | } 18 | 19 | void board_event(void) { 20 | espi_event(); 21 | 22 | ec_read_post_codes(); 23 | } 24 | -------------------------------------------------------------------------------- /src/board/system76/darp10/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC = ite 7 | CONFIG_EC_ITE_IT5570E = y 8 | CONFIG_EC_FLASH_SIZE_256K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY = y 16 | 17 | # Keyboard configuration 18 | KEYBOARD = 18H9LHA05 19 | KEYMAP = darp10 20 | CONFIG_HAVE_KBLED = y 21 | KBLED = rgb_pwm 22 | 23 | # Set battery I2C bus 24 | CFLAGS += -DI2C_SMBUS=I2C_4 25 | 26 | # Set touchpad PS2 bus 27 | CFLAGS += -DPS2_TOUCHPAD=PS2_3 28 | 29 | # Set smart charger parameters 30 | CHARGER = oz26786 31 | CFLAGS += \ 32 | -DCHARGER_ADAPTER_RSENSE=5 \ 33 | -DCHARGER_BATTERY_RSENSE=10 \ 34 | -DCHARGER_CHARGE_CURRENT=1536 \ 35 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 36 | -DCHARGER_INPUT_CURRENT=4740 37 | 38 | # Set CPU power limits in watts 39 | CFLAGS += \ 40 | -DPOWER_LIMIT_AC=65 \ 41 | -DPOWER_LIMIT_DC=45 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DFAN1_PWM_MIN=27 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(48, 27), \ 48 | FAN_POINT(52, 27), \ 49 | FAN_POINT(56, 33), \ 50 | FAN_POINT(60, 37), \ 51 | FAN_POINT(75, 53), \ 52 | FAN_POINT(83, 65), \ 53 | FAN_POINT(87, 75), \ 54 | FAN_POINT(89, 77), \ 55 | " 56 | 57 | CFLAGS += -DFAN2_PWM=DCR3 58 | CFLAGS += -DFAN2_PWM_MIN=27 59 | CFLAGS += -DBOARD_FAN2_POINTS="\ 60 | FAN_POINT(48, 27), \ 61 | FAN_POINT(52, 27), \ 62 | FAN_POINT(56, 33), \ 63 | FAN_POINT(60, 37), \ 64 | FAN_POINT(75, 53), \ 65 | FAN_POINT(83, 65), \ 66 | FAN_POINT(87, 75), \ 67 | FAN_POINT(89, 77), \ 68 | " 69 | 70 | # Add common code 71 | include src/board/system76/common/common.mk 72 | -------------------------------------------------------------------------------- /src/board/system76/darp10/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code EC_EN; 19 | extern struct Gpio __code EC_RSMRST_N; 20 | extern struct Gpio __code LAN_WAKEUP_N; 21 | extern struct Gpio __code LED_ACIN; 22 | #define HAVE_LED_AIRPLANE_N 0 23 | extern struct Gpio __code LED_BAT_CHG; 24 | extern struct Gpio __code LED_BAT_FULL; 25 | extern struct Gpio __code LED_PWR; 26 | extern struct Gpio __code LID_SW_N; 27 | extern struct Gpio __code ME_WE; 28 | #define HAVE_PCH_DPWROK_EC 0 29 | extern struct Gpio __code PCH_PWROK_EC; 30 | #define HAVE_PD_EN 1 31 | extern struct Gpio __code PD_EN; 32 | #define HAVE_PM_PWROK 0 33 | extern struct Gpio __code PWR_BTN_N; 34 | extern struct Gpio __code PWR_SW_N; 35 | extern struct Gpio __code RGBKB_DET_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | #define HAVE_SLP_SUS_N 0 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | #define HAVE_SUSWARN_N 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/darp11-b/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | battery_charger_disable(); 12 | 13 | // Allow backlight to be turned on 14 | gpio_set(&BKL_EN, true); 15 | // Enable camera 16 | gpio_set(&CCD_EN, true); 17 | } 18 | 19 | void board_event(void) { 20 | espi_event(); 21 | 22 | ec_read_post_codes(); 23 | } 24 | -------------------------------------------------------------------------------- /src/board/system76/darp11-b/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code EC_EN; 19 | extern struct Gpio __code EC_RSMRST_N; 20 | extern struct Gpio __code LAN_WAKEUP_N; 21 | extern struct Gpio __code LED_ACIN; 22 | #define HAVE_LED_AIRPLANE_N 0 23 | extern struct Gpio __code LED_BAT_CHG; 24 | extern struct Gpio __code LED_BAT_FULL; 25 | extern struct Gpio __code LED_PWR; 26 | extern struct Gpio __code LID_SW_N; 27 | extern struct Gpio __code ME_WE; 28 | #define HAVE_PCH_DPWROK_EC 0 29 | extern struct Gpio __code PCH_PWROK_EC; 30 | #define HAVE_PD_EN 1 31 | extern struct Gpio __code PD_EN; 32 | #define HAVE_PM_PWROK 0 33 | extern struct Gpio __code PWR_BTN_N; 34 | extern struct Gpio __code PWR_SW_N; 35 | extern struct Gpio __code RGBKB_DET_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | #define HAVE_SLP_SUS_N 0 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | #define HAVE_SUSWARN_N 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/darp11/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | battery_charger_disable(); 12 | 13 | // Allow backlight to be turned on 14 | gpio_set(&BKL_EN, true); 15 | // Enable camera 16 | gpio_set(&CCD_EN, true); 17 | } 18 | 19 | void board_event(void) { 20 | espi_event(); 21 | 22 | ec_read_post_codes(); 23 | } 24 | -------------------------------------------------------------------------------- /src/board/system76/darp11/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC = ite 7 | CONFIG_EC_ITE_IT5570E = y 8 | CONFIG_EC_FLASH_SIZE_256K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY = y 16 | 17 | # Keyboard configuration 18 | KEYBOARD = 18H9LHA05 19 | KEYMAP = darp10 20 | CONFIG_HAVE_KBLED = y 21 | KBLED = rgb_pwm 22 | 23 | # Set battery I2C bus 24 | CFLAGS += -DI2C_SMBUS=I2C_4 25 | 26 | # Set touchpad PS2 bus 27 | CFLAGS += -DPS2_TOUCHPAD=PS2_3 28 | 29 | # Set smart charger parameters 30 | CHARGER = oz26786 31 | CFLAGS += \ 32 | -DCHARGER_ADAPTER_RSENSE=5 \ 33 | -DCHARGER_BATTERY_RSENSE=10 \ 34 | -DCHARGER_CHARGE_CURRENT=1536 \ 35 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 36 | -DCHARGER_INPUT_CURRENT=4740 37 | 38 | # Set CPU power limits in watts 39 | CFLAGS += \ 40 | -DPOWER_LIMIT_AC=65 \ 41 | -DPOWER_LIMIT_DC=45 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DFAN1_PWM_MIN=27 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(48, 27), \ 48 | FAN_POINT(52, 27), \ 49 | FAN_POINT(56, 33), \ 50 | FAN_POINT(60, 37), \ 51 | FAN_POINT(75, 53), \ 52 | FAN_POINT(83, 65), \ 53 | FAN_POINT(87, 75), \ 54 | FAN_POINT(89, 77), \ 55 | " 56 | 57 | CFLAGS += -DFAN2_PWM=DCR3 58 | CFLAGS += -DFAN2_PWM_MIN=27 59 | CFLAGS += -DBOARD_FAN2_POINTS="\ 60 | FAN_POINT(48, 27), \ 61 | FAN_POINT(52, 27), \ 62 | FAN_POINT(56, 33), \ 63 | FAN_POINT(60, 37), \ 64 | FAN_POINT(75, 53), \ 65 | FAN_POINT(83, 65), \ 66 | FAN_POINT(87, 75), \ 67 | FAN_POINT(89, 77), \ 68 | " 69 | 70 | # Add common code 71 | include src/board/system76/common/common.mk 72 | -------------------------------------------------------------------------------- /src/board/system76/darp11/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code EC_EN; 19 | extern struct Gpio __code EC_RSMRST_N; 20 | extern struct Gpio __code LAN_WAKEUP_N; 21 | extern struct Gpio __code LED_ACIN; 22 | #define HAVE_LED_AIRPLANE_N 0 23 | extern struct Gpio __code LED_BAT_CHG; 24 | extern struct Gpio __code LED_BAT_FULL; 25 | extern struct Gpio __code LED_PWR; 26 | extern struct Gpio __code LID_SW_N; 27 | extern struct Gpio __code ME_WE; 28 | #define HAVE_PCH_DPWROK_EC 0 29 | extern struct Gpio __code PCH_PWROK_EC; 30 | #define HAVE_PD_EN 1 31 | extern struct Gpio __code PD_EN; 32 | #define HAVE_PM_PWROK 0 33 | extern struct Gpio __code PWR_BTN_N; 34 | extern struct Gpio __code PWR_SW_N; 35 | extern struct Gpio __code RGBKB_DET_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | #define HAVE_SLP_SUS_N 0 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | #define HAVE_SUSWARN_N 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/darp5/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | void board_init(void) { 7 | // Allow CPU to boot 8 | gpio_set(&SB_KBCRST_N, true); 9 | // Allow backlight to be turned on 10 | gpio_set(&BKL_EN, true); 11 | // Enable camera 12 | gpio_set(&CCD_EN, true); 13 | // Enable right USB port 14 | gpio_set(&USB_PWR_EN_N, false); 15 | // Assert SMI#, SCI#, and SWI# 16 | gpio_set(&SCI_N, true); 17 | gpio_set(&SMI_N, true); 18 | gpio_set(&SWI_N, true); 19 | } 20 | 21 | void board_event(void) {} 22 | -------------------------------------------------------------------------------- /src/board/system76/darp5/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT8587E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=darp5 19 | CFLAGS+=-DI2C_KBLED=I2C_1 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_0 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CFLAGS+=\ 29 | -DCHARGER_ADAPTER_RSENSE=10 \ 30 | -DCHARGER_BATTERY_RSENSE=10 \ 31 | -DCHARGER_CHARGE_CURRENT=3072 \ 32 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 33 | -DCHARGER_INPUT_CURRENT=3420 34 | 35 | # Set CPU power limits in watts 36 | CFLAGS+=\ 37 | -DPOWER_LIMIT_AC=65 \ 38 | -DPOWER_LIMIT_DC=45 39 | 40 | # Fan configs 41 | CFLAGS += -DFAN1_PWM=DCR2 42 | CFLAGS += -DBOARD_FAN1_POINTS="\ 43 | FAN_POINT(70, 40), \ 44 | FAN_POINT(75, 50), \ 45 | FAN_POINT(80, 60), \ 46 | FAN_POINT(85, 65), \ 47 | FAN_POINT(90, 65), \ 48 | " 49 | 50 | # Add system76 common code 51 | include src/board/system76/common/common.mk 52 | -------------------------------------------------------------------------------- /src/board/system76/darp6/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += ../darp5/board.c 4 | board-y += ../darp5/gpio.c 5 | 6 | # FIXME: Handle this better 7 | CFLAGS += -I$(BOARD_DIR)/../darp5/include 8 | 9 | EC=ite 10 | CONFIG_EC_ITE_IT8587E=y 11 | CONFIG_EC_FLASH_SIZE_128K = y 12 | 13 | # Intel-based host 14 | CONFIG_PLATFORM_INTEL = y 15 | 16 | # Include keyboard 17 | KEYBOARD=15in_102 18 | 19 | # Set keyboard LED mechanism 20 | CONFIG_HAVE_KBLED = y 21 | KBLED=darp5 22 | CFLAGS+=-DI2C_KBLED=I2C_1 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_0 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | CFLAGS+=\ 32 | -DCHARGER_ADAPTER_RSENSE=10 \ 33 | -DCHARGER_BATTERY_RSENSE=10 \ 34 | -DCHARGER_CHARGE_CURRENT=3072 \ 35 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 36 | -DCHARGER_INPUT_CURRENT=3420 37 | 38 | # Set CPU power limits in watts 39 | CFLAGS+=\ 40 | -DPOWER_LIMIT_AC=65 \ 41 | -DPOWER_LIMIT_DC=45 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DBOARD_FAN1_POINTS="\ 46 | FAN_POINT(70, 40), \ 47 | FAN_POINT(75, 50), \ 48 | FAN_POINT(80, 60), \ 49 | FAN_POINT(85, 65), \ 50 | FAN_POINT(90, 65), \ 51 | " 52 | 53 | # Add system76 common code 54 | include src/board/system76/common/common.mk 55 | -------------------------------------------------------------------------------- /src/board/system76/darp7/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void board_init(void) { 11 | espi_init(); 12 | 13 | // Allow CPU to boot 14 | gpio_set(&SB_KBCRST_N, true); 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | // Enable right USB port 20 | gpio_set(&USB_PWR_EN_N, false); 21 | // Assert SMI# and SWI# 22 | gpio_set(&SMI_N, true); 23 | gpio_set(&SWI_N, true); 24 | } 25 | 26 | void board_event(void) { 27 | espi_event(); 28 | 29 | ec_read_post_codes(); 30 | } 31 | -------------------------------------------------------------------------------- /src/board/system76/darp7/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=15in_102 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=rgb_pwm 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CFLAGS+=\ 29 | -DCHARGER_ADAPTER_RSENSE=5 \ 30 | -DCHARGER_BATTERY_RSENSE=5 \ 31 | -DCHARGER_CHARGE_CURRENT=3072 \ 32 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 33 | -DCHARGER_INPUT_CURRENT=3420 34 | 35 | # Set CPU power limits in watts 36 | CFLAGS+=\ 37 | -DPOWER_LIMIT_AC=65 \ 38 | -DPOWER_LIMIT_DC=45 39 | 40 | # Fan configs 41 | CFLAGS += -DFAN1_PWM=DCR2 42 | CFLAGS += -DBOARD_FAN1_POINTS="\ 43 | FAN_POINT(70, 40), \ 44 | FAN_POINT(75, 50), \ 45 | FAN_POINT(80, 60), \ 46 | FAN_POINT(85, 65), \ 47 | FAN_POINT(90, 65), \ 48 | " 49 | 50 | # Add system76 common code 51 | include src/board/system76/common/common.mk 52 | -------------------------------------------------------------------------------- /src/board/system76/darp8/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow CPU to boot 16 | gpio_set(&SB_KBCRST_N, true); 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | // Assert SMI# and SWI# 22 | gpio_set(&SMI_N, true); 23 | gpio_set(&SWI_N, true); 24 | } 25 | 26 | void board_event(void) { 27 | espi_event(); 28 | 29 | ec_read_post_codes(); 30 | } 31 | -------------------------------------------------------------------------------- /src/board/system76/darp8/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=15in_102 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=rgb_pwm 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CHARGER=oz26786 29 | CFLAGS+=\ 30 | -DCHARGER_ADAPTER_RSENSE=10 \ 31 | -DCHARGER_BATTERY_RSENSE=10 \ 32 | -DCHARGER_CHARGE_CURRENT=3072 \ 33 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 34 | -DCHARGER_INPUT_CURRENT=4740 35 | 36 | # Set CPU power limits in watts 37 | CFLAGS+=\ 38 | -DPOWER_LIMIT_AC=65 \ 39 | -DPOWER_LIMIT_DC=45 40 | 41 | # Fan configs 42 | CFLAGS += -DFAN1_PWM=DCR2 43 | CFLAGS += -DBOARD_FAN1_POINTS="\ 44 | FAN_POINT(70, 40), \ 45 | FAN_POINT(75, 50), \ 46 | FAN_POINT(80, 60), \ 47 | FAN_POINT(85, 65), \ 48 | FAN_POINT(90, 65), \ 49 | " 50 | 51 | # Add system76 common code 52 | include src/board/system76/common/common.mk 53 | -------------------------------------------------------------------------------- /src/board/system76/darp8/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | extern struct Gpio __code LAN_WAKEUP_N; 22 | extern struct Gpio __code LED_ACIN; 23 | #define HAVE_LED_AIRPLANE_N 0 24 | extern struct Gpio __code LED_BAT_CHG; 25 | extern struct Gpio __code LED_BAT_FULL; 26 | extern struct Gpio __code LED_PWR; 27 | extern struct Gpio __code LID_SW_N; 28 | extern struct Gpio __code ME_WE; 29 | extern struct Gpio __code PCH_DPWROK_EC; 30 | extern struct Gpio __code PCH_PWROK_EC; 31 | #define HAVE_PM_PWROK 0 32 | extern struct Gpio __code PWR_BTN_N; 33 | extern struct Gpio __code PWR_SW_N; 34 | extern struct Gpio __code RGBKB_DET_N; 35 | extern struct Gpio __code SB_KBCRST_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | extern struct Gpio __code SLP_SUS_N; 38 | #define HAVE_SUSWARN_N 0 39 | #define HAVE_SUS_PWR_ACK 0 40 | extern struct Gpio __code SMI_N; 41 | extern struct Gpio __code SUSB_N_PCH; 42 | extern struct Gpio __code SUSC_N_PCH; 43 | extern struct Gpio __code SWI_N; 44 | extern struct Gpio __code VA_EC_EN; 45 | extern struct Gpio __code WLAN_EN; 46 | extern struct Gpio __code WLAN_PWR_EN; 47 | extern struct Gpio __code XLP_OUT; 48 | 49 | #endif // _BOARD_GPIO_H 50 | -------------------------------------------------------------------------------- /src/board/system76/darp9/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow CPU to boot 16 | gpio_set(&SB_KBCRST_N, true); 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | // Assert SWI# 22 | gpio_set(&SWI_N, true); 23 | } 24 | 25 | void board_event(void) { 26 | espi_event(); 27 | 28 | ec_read_post_codes(); 29 | } 30 | -------------------------------------------------------------------------------- /src/board/system76/darp9/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY=y 16 | 17 | # Include keyboard 18 | KEYBOARD=18H9LHA05 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=rgb_pwm 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_4 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | CFLAGS+=\ 32 | -DCHARGER_ADAPTER_RSENSE=5 \ 33 | -DCHARGER_BATTERY_RSENSE=5 \ 34 | -DCHARGER_CHARGE_CURRENT=3072 \ 35 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 36 | -DCHARGER_INPUT_CURRENT=4740 37 | 38 | # Set CPU power limits in watts 39 | CFLAGS+=\ 40 | -DPOWER_LIMIT_AC=65 \ 41 | -DPOWER_LIMIT_DC=45 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DBOARD_FAN1_POINTS="\ 46 | FAN_POINT(70, 40), \ 47 | FAN_POINT(75, 50), \ 48 | FAN_POINT(80, 60), \ 49 | FAN_POINT(85, 65), \ 50 | FAN_POINT(90, 65), \ 51 | " 52 | 53 | # Add system76 common code 54 | include src/board/system76/common/common.mk 55 | -------------------------------------------------------------------------------- /src/board/system76/galp3-c/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | void board_init(void) { 7 | // Allow CPU to boot 8 | gpio_set(&SB_KBCRST_N, true); 9 | // Allow backlight to be turned on 10 | gpio_set(&BKL_EN, true); 11 | // Enable camera 12 | gpio_set(&CCD_EN, true); 13 | // Enable right USB port 14 | gpio_set(&USB_PWR_EN_N, false); 15 | // Assert SMI#, SCI#, and SWI# 16 | gpio_set(&SCI_N, true); 17 | gpio_set(&SMI_N, true); 18 | gpio_set(&SWI_N, true); 19 | } 20 | 21 | void board_event(void) {} 22 | -------------------------------------------------------------------------------- /src/board/system76/galp3-c/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT8587E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=14in_86 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=white_dac 19 | CFLAGS+=-DKBLED_DAC=5 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_0 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | # FIXME: Verify parts and values. 29 | CFLAGS+=\ 30 | -DCHARGER_ADAPTER_RSENSE=10 \ 31 | -DCHARGER_BATTERY_RSENSE=10 \ 32 | -DCHARGER_CHARGE_CURRENT=1536 \ 33 | -DCHARGER_CHARGE_VOLTAGE=13056 \ 34 | -DCHARGER_INPUT_CURRENT=2100 35 | 36 | # Set CPU power limits in watts 37 | CFLAGS+=\ 38 | -DPOWER_LIMIT_AC=40 \ 39 | -DPOWER_LIMIT_DC=28 40 | 41 | # Fan configs 42 | CFLAGS += -DFAN1_PWM=DCR2 43 | CFLAGS += -DBOARD_FAN1_POINTS="\ 44 | FAN_POINT(70, 40), \ 45 | FAN_POINT(75, 50), \ 46 | FAN_POINT(80, 60), \ 47 | FAN_POINT(85, 65), \ 48 | FAN_POINT(90, 65), \ 49 | " 50 | 51 | # Add system76 common code 52 | include src/board/system76/common/common.mk 53 | -------------------------------------------------------------------------------- /src/board/system76/galp4/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += ../galp3-c/board.c 4 | board-y += ../galp3-c/gpio.c 5 | 6 | # FIXME: Handle this better 7 | CFLAGS += -I$(BOARD_DIR)/../galp3-c/include 8 | 9 | EC=ite 10 | CONFIG_EC_ITE_IT8587E=y 11 | CONFIG_EC_FLASH_SIZE_128K = y 12 | 13 | # Intel-based host 14 | CONFIG_PLATFORM_INTEL = y 15 | 16 | # Include keyboard 17 | KEYBOARD=14in_86 18 | 19 | # Set keyboard LED mechanism 20 | CONFIG_HAVE_KBLED = y 21 | KBLED=white_dac 22 | CFLAGS+=-DKBLED_DAC=5 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_0 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | # FIXME: Verify parts and values. 32 | CFLAGS+=\ 33 | -DCHARGER_ADAPTER_RSENSE=10 \ 34 | -DCHARGER_BATTERY_RSENSE=10 \ 35 | -DCHARGER_CHARGE_CURRENT=1536 \ 36 | -DCHARGER_CHARGE_VOLTAGE=13056 \ 37 | -DCHARGER_INPUT_CURRENT=2100 38 | 39 | # Set CPU power limits in watts 40 | CFLAGS+=\ 41 | -DPOWER_LIMIT_AC=40 \ 42 | -DPOWER_LIMIT_DC=28 43 | 44 | # Fan configs 45 | CFLAGS += -DFAN1_PWM=DCR2 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(70, 40), \ 48 | FAN_POINT(75, 50), \ 49 | FAN_POINT(80, 60), \ 50 | FAN_POINT(85, 65), \ 51 | FAN_POINT(90, 65), \ 52 | " 53 | 54 | # Add system76 common code 55 | include src/board/system76/common/common.mk 56 | -------------------------------------------------------------------------------- /src/board/system76/galp5/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow CPU to boot 18 | gpio_set(&SB_KBCRST_N, true); 19 | // Allow backlight to be turned on 20 | gpio_set(&BKL_EN, true); 21 | // Enable camera 22 | gpio_set(&CCD_EN, true); 23 | // Enable right USB port 24 | gpio_set(&USB_PWR_EN_N, false); 25 | // Assert SMI# and SWI# 26 | gpio_set(&SMI_N, true); 27 | gpio_set(&SWI_N, true); 28 | } 29 | 30 | void board_event(void) { 31 | espi_event(); 32 | 33 | ec_read_post_codes(); 34 | } 35 | -------------------------------------------------------------------------------- /src/board/system76/galp5/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=14in_83 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=white_dac 20 | CFLAGS+=-DKBLED_DAC=2 21 | 22 | # Set battery I2C bus 23 | CFLAGS+=-DI2C_SMBUS=I2C_4 24 | 25 | # Set touchpad PS2 bus 26 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 27 | 28 | # Set smart charger parameters 29 | # FIXME: Verify parts and values. 30 | CHARGER=oz26786 31 | CFLAGS+=\ 32 | -DCHARGER_ADAPTER_RSENSE=10 \ 33 | -DCHARGER_BATTERY_RSENSE=10 \ 34 | -DCHARGER_CHARGE_CURRENT=1536 \ 35 | -DCHARGER_CHARGE_VOLTAGE=17400 \ 36 | -DCHARGER_INPUT_CURRENT=3420 37 | 38 | # Set CPU power limits in watts 39 | CFLAGS+=\ 40 | -DPOWER_LIMIT_AC=65 \ 41 | -DPOWER_LIMIT_DC=45 42 | 43 | # Enable dGPU support 44 | CONFIG_HAVE_DGPU = y 45 | CFLAGS += -DI2C_DGPU=I2C_1 46 | 47 | # Fan configs 48 | CFLAGS += -DFAN1_PWM=DCR2 49 | CFLAGS += -DBOARD_FAN1_POINTS="\ 50 | FAN_POINT(70, 25), \ 51 | FAN_POINT(80, 25), \ 52 | FAN_POINT(80, 40), \ 53 | FAN_POINT(88, 40), \ 54 | FAN_POINT(88, 100), \ 55 | " 56 | 57 | CFLAGS += -DFAN2_PWM=DCR4 58 | CFLAGS += -DBOARD_FAN2_POINTS="\ 59 | FAN_POINT(70, 25), \ 60 | FAN_POINT(75, 40), \ 61 | FAN_POINT(80, 75), \ 62 | FAN_POINT(85, 90), \ 63 | FAN_POINT(90, 100), \ 64 | " 65 | 66 | # Add system76 common code 67 | include src/board/system76/common/common.mk 68 | -------------------------------------------------------------------------------- /src/board/system76/galp6/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Allow backlight to be turned on 13 | gpio_set(&BKL_EN, true); 14 | // Enable camera 15 | gpio_set(&CCD_EN, true); 16 | // Assert SMI# and SWI# 17 | gpio_set(&SMI_N, true); 18 | gpio_set(&SWI_N, true); 19 | 20 | // Make sure charger is in off state, also enables PSYS 21 | battery_charger_disable(); 22 | } 23 | 24 | void board_event(void) { 25 | espi_event(); 26 | 27 | ec_read_post_codes(); 28 | } 29 | -------------------------------------------------------------------------------- /src/board/system76/galp6/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY=y 16 | 17 | # Include keyboard 18 | KEYBOARD=14in_83 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=white_dac 23 | CFLAGS+=-DKBLED_DAC=2 24 | 25 | # Set battery I2C bus 26 | CFLAGS+=-DI2C_SMBUS=I2C_4 27 | 28 | # Set touchpad PS2 bus 29 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 30 | 31 | # Set smart charger parameters 32 | # TODO: actually bq24800 33 | # FIXME: Verify parts and values. 34 | CFLAGS+=\ 35 | -DCHARGER_ADAPTER_RSENSE=5 \ 36 | -DCHARGER_BATTERY_RSENSE=10 \ 37 | -DCHARGER_CHARGE_CURRENT=1536 \ 38 | -DCHARGER_CHARGE_VOLTAGE=17400 \ 39 | -DCHARGER_INPUT_CURRENT=4740 40 | 41 | # Set CPU power limits in watts 42 | CFLAGS+=\ 43 | -DPOWER_LIMIT_AC=65 \ 44 | -DPOWER_LIMIT_DC=45 45 | 46 | # Fan configs 47 | CFLAGS += -DFAN1_PWM=DCR2 48 | CFLAGS += -DBOARD_FAN1_POINTS="\ 49 | FAN_POINT(70, 40), \ 50 | FAN_POINT(75, 50), \ 51 | FAN_POINT(80, 60), \ 52 | FAN_POINT(85, 65), \ 53 | FAN_POINT(90, 65), \ 54 | " 55 | 56 | # Add system76 common code 57 | include src/board/system76/common/common.mk 58 | -------------------------------------------------------------------------------- /src/board/system76/galp7/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += ../galp6/board.c 4 | board-y += ../galp6/gpio.c 5 | 6 | # FIXME: Handle this better 7 | CFLAGS += -I$(BOARD_DIR)/../galp6/include 8 | 9 | EC=ite 10 | CONFIG_EC_ITE_IT5570E=y 11 | CONFIG_EC_FLASH_SIZE_128K = y 12 | 13 | # Intel-based host 14 | CONFIG_PLATFORM_INTEL = y 15 | CONFIG_BUS_ESPI = y 16 | 17 | # Enable firmware security 18 | CONFIG_SECURITY=y 19 | 20 | # Include keyboard 21 | KEYBOARD=14in_83 22 | 23 | # Set keyboard LED mechanism 24 | CONFIG_HAVE_KBLED = y 25 | KBLED=white_dac 26 | CFLAGS+=-DKBLED_DAC=2 27 | 28 | # Set battery I2C bus 29 | CFLAGS+=-DI2C_SMBUS=I2C_4 30 | 31 | # Set touchpad PS2 bus 32 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 33 | 34 | # Set smart charger parameters 35 | # TODO: actually bq24800 36 | # FIXME: Verify parts and values. 37 | CFLAGS+=\ 38 | -DCHARGER_ADAPTER_RSENSE=5 \ 39 | -DCHARGER_BATTERY_RSENSE=10 \ 40 | -DCHARGER_CHARGE_CURRENT=1536 \ 41 | -DCHARGER_CHARGE_VOLTAGE=17400 \ 42 | -DCHARGER_INPUT_CURRENT=4740 43 | 44 | # Set CPU power limits in watts 45 | CFLAGS+=\ 46 | -DPOWER_LIMIT_AC=65 \ 47 | -DPOWER_LIMIT_DC=45 48 | 49 | # Fan configs 50 | CFLAGS += -DFAN1_PWM=DCR2 51 | CFLAGS += -DBOARD_FAN1_POINTS="\ 52 | FAN_POINT(70, 40), \ 53 | FAN_POINT(75, 50), \ 54 | FAN_POINT(80, 60), \ 55 | FAN_POINT(85, 65), \ 56 | FAN_POINT(90, 65), \ 57 | " 58 | 59 | # Add system76 common code 60 | include src/board/system76/common/common.mk 61 | -------------------------------------------------------------------------------- /src/board/system76/gaze15/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | // Allow backlight to be turned on 11 | gpio_set(&BKL_EN, true); 12 | // Enable camera 13 | gpio_set(&CCD_EN, true); 14 | // Assert SMI#, SCI#, and SWI# 15 | gpio_set(&SCI_N, true); 16 | gpio_set(&SMI_N, true); 17 | gpio_set(&SWI_N, true); 18 | } 19 | 20 | void board_event(void) { 21 | ec_read_post_codes(); 22 | } 23 | -------------------------------------------------------------------------------- /src/board/system76/gaze15/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=rgb_pwm 19 | 20 | # Set battery I2C bus 21 | CFLAGS+=-DI2C_SMBUS=I2C_4 22 | 23 | # Set touchpad PS2 bus 24 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 25 | 26 | # Set smart charger parameters 27 | CFLAGS+=\ 28 | -DCHARGER_ADAPTER_RSENSE=5 \ 29 | -DCHARGER_BATTERY_RSENSE=5 \ 30 | -DCHARGER_CHARGE_CURRENT=3072 \ 31 | -DCHARGER_CHARGE_VOLTAGE=16800 \ 32 | -DCHARGER_INPUT_CURRENT=9230 33 | 34 | # Set CPU power limits in watts 35 | CFLAGS+=\ 36 | -DPOWER_LIMIT_AC=180 \ 37 | -DPOWER_LIMIT_DC=45 38 | 39 | # Enable dGPU support 40 | CONFIG_HAVE_DGPU = y 41 | CFLAGS += -DI2C_DGPU=I2C_1 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DBOARD_FAN1_POINTS="\ 46 | FAN_POINT(60, 40), \ 47 | FAN_POINT(65, 60), \ 48 | FAN_POINT(70, 75), \ 49 | FAN_POINT(75, 90), \ 50 | FAN_POINT(80, 100), \ 51 | " 52 | 53 | CFLAGS += -DFAN2_PWM=DCR4 54 | CFLAGS += -DBOARD_FAN2_POINTS="\ 55 | FAN_POINT(60, 40), \ 56 | FAN_POINT(65, 60), \ 57 | FAN_POINT(70, 75), \ 58 | FAN_POINT(75, 90), \ 59 | FAN_POINT(80, 100), \ 60 | " 61 | 62 | # Add system76 common code 63 | include src/board/system76/common/common.mk 64 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3050/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3050/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=15in_102 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=rgb_pwm 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | # FIXME: Verify parts and values. 29 | CHARGER=oz26786 30 | CFLAGS+=\ 31 | -DCHARGER_ADAPTER_RSENSE=5 \ 32 | -DCHARGER_BATTERY_RSENSE=10 \ 33 | -DCHARGER_CHARGE_CURRENT=1536 \ 34 | -DCHARGER_CHARGE_VOLTAGE=16800 \ 35 | -DCHARGER_INPUT_CURRENT=7700 36 | 37 | # Set CPU power limits in watts 38 | CFLAGS+=\ 39 | -DPOWER_LIMIT_AC=180 \ 40 | -DPOWER_LIMIT_DC=45 41 | 42 | # Enable dGPU support 43 | CONFIG_HAVE_DGPU = y 44 | CFLAGS += -DI2C_DGPU=I2C_1 45 | 46 | # Fan configs 47 | CFLAGS += -DFAN1_PWM=DCR2 48 | CFLAGS += -DBOARD_FAN1_POINTS="\ 49 | FAN_POINT(60, 40), \ 50 | FAN_POINT(65, 60), \ 51 | FAN_POINT(70, 75), \ 52 | FAN_POINT(75, 90), \ 53 | FAN_POINT(80, 100), \ 54 | " 55 | 56 | CFLAGS += -DFAN2_PWM=DCR4 57 | CFLAGS += -DBOARD_FAN2_POINTS="\ 58 | FAN_POINT(60, 40), \ 59 | FAN_POINT(65, 60), \ 60 | FAN_POINT(70, 75), \ 61 | FAN_POINT(75, 90), \ 62 | FAN_POINT(80, 100), \ 63 | " 64 | 65 | # Add system76 common code 66 | include src/board/system76/common/common.mk 67 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3050/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | extern struct Gpio __code LED_AIRPLANE_N; 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SLP_SUS_N; 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | extern struct Gpio __code VA_EC_EN; 42 | extern struct Gpio __code WLAN_EN; 43 | extern struct Gpio __code WLAN_PWR_EN; 44 | extern struct Gpio __code XLP_OUT; 45 | 46 | #endif // _BOARD_GPIO_H 47 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3060-b/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += ../gaze16-3060/board.c 4 | board-y += ../gaze16-3060/gpio.c 5 | 6 | # FIXME: Handle this better 7 | CFLAGS += -I$(BOARD_DIR)/../gaze16-3060/include 8 | 9 | EC=ite 10 | CONFIG_EC_ITE_IT5570E=y 11 | CONFIG_EC_FLASH_SIZE_128K = y 12 | 13 | # Intel-based host 14 | CONFIG_PLATFORM_INTEL = y 15 | CONFIG_BUS_ESPI = y 16 | 17 | # Include keyboard 18 | KEYBOARD=15in_102 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=rgb_pwm 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_4 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | # FIXME: Verify parts and values. 32 | CHARGER=oz26786 33 | CFLAGS+=\ 34 | -DCHARGER_ADAPTER_RSENSE=5 \ 35 | -DCHARGER_BATTERY_RSENSE=10 \ 36 | -DCHARGER_CHARGE_CURRENT=1536 \ 37 | -DCHARGER_CHARGE_VOLTAGE=16800 \ 38 | -DCHARGER_INPUT_CURRENT=9230 39 | 40 | # Set CPU power limits in watts 41 | CFLAGS+=\ 42 | -DPOWER_LIMIT_AC=180 \ 43 | -DPOWER_LIMIT_DC=45 44 | 45 | # Enable dGPU support 46 | CONFIG_HAVE_DGPU = y 47 | CFLAGS += -DI2C_DGPU=I2C_1 48 | 49 | # Fan configs 50 | CFLAGS += -DFAN1_PWM=DCR2 51 | CFLAGS += -DBOARD_FAN1_POINTS="\ 52 | FAN_POINT(60, 40), \ 53 | FAN_POINT(65, 60), \ 54 | FAN_POINT(70, 75), \ 55 | FAN_POINT(75, 90), \ 56 | FAN_POINT(80, 100), \ 57 | " 58 | 59 | CFLAGS += -DFAN2_PWM=DCR4 60 | CFLAGS+=-DBOARD_FAN2_POINTS="\ 61 | FAN_POINT(60, 40), \ 62 | FAN_POINT(65, 60), \ 63 | FAN_POINT(70, 75), \ 64 | FAN_POINT(75, 90), \ 65 | FAN_POINT(80, 100), \ 66 | " 67 | 68 | # Add system76 common code 69 | include src/board/system76/common/common.mk 70 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3060/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3060/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=15in_102 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=rgb_pwm 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | # FIXME: Verify parts and values. 29 | CHARGER=oz26786 30 | CFLAGS+=\ 31 | -DCHARGER_ADAPTER_RSENSE=5 \ 32 | -DCHARGER_BATTERY_RSENSE=10 \ 33 | -DCHARGER_CHARGE_CURRENT=1536 \ 34 | -DCHARGER_CHARGE_VOLTAGE=16800 \ 35 | -DCHARGER_INPUT_CURRENT=9230 36 | 37 | # Set CPU power limits in watts 38 | CFLAGS+=\ 39 | -DPOWER_LIMIT_AC=180 \ 40 | -DPOWER_LIMIT_DC=45 41 | 42 | # Enable dGPU support 43 | CONFIG_HAVE_DGPU = y 44 | CFLAGS += -DI2C_DGPU=I2C_1 45 | 46 | # Fan configs 47 | CFLAGS += -DFAN1_PWM=DCR2 48 | CFLAGS += -DBOARD_FAN1_POINTS="\ 49 | FAN_POINT(60, 40), \ 50 | FAN_POINT(65, 60), \ 51 | FAN_POINT(70, 75), \ 52 | FAN_POINT(75, 90), \ 53 | FAN_POINT(80, 100), \ 54 | " 55 | 56 | CFLAGS += -DFAN2_PWM=DCR4 57 | CFLAGS += -DBOARD_FAN2_POINTS="\ 58 | FAN_POINT(60, 40), \ 59 | FAN_POINT(65, 60), \ 60 | FAN_POINT(70, 75), \ 61 | FAN_POINT(75, 90), \ 62 | FAN_POINT(80, 100), \ 63 | " 64 | 65 | # Add system76 common code 66 | include src/board/system76/common/common.mk 67 | -------------------------------------------------------------------------------- /src/board/system76/gaze16-3060/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | extern struct Gpio __code LED_AIRPLANE_N; 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | extern struct Gpio __code PM_PWROK; 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SLP_SUS_N; 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | extern struct Gpio __code VA_EC_EN; 42 | extern struct Gpio __code WLAN_EN; 43 | extern struct Gpio __code WLAN_PWR_EN; 44 | extern struct Gpio __code XLP_OUT; 45 | 46 | #endif // _BOARD_GPIO_H 47 | -------------------------------------------------------------------------------- /src/board/system76/gaze17-3050/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/gaze17-3050/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SLP_S0_N; 38 | extern struct Gpio __code SLP_SUS_N; 39 | #define HAVE_SUS_PWR_ACK 0 40 | extern struct Gpio __code SUSB_N_PCH; 41 | extern struct Gpio __code SUSC_N_PCH; 42 | extern struct Gpio __code VA_EC_EN; 43 | extern struct Gpio __code WLAN_EN; 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/gaze17-3060-b/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += ../gaze17-3060/board.c 4 | board-y += ../gaze17-3060/gpio.c 5 | 6 | # FIXME: Handle this better 7 | CFLAGS += -I$(BOARD_DIR)/../gaze17-3060/include 8 | 9 | EC=ite 10 | CONFIG_EC_ITE_IT5570E=y 11 | CONFIG_EC_FLASH_SIZE_128K = y 12 | 13 | # Intel-based host 14 | CONFIG_PLATFORM_INTEL = y 15 | CONFIG_BUS_ESPI = y 16 | 17 | # Include keyboard 18 | KEYBOARD=15in_102 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=rgb_pwm 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_4 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | # TODO: actually bq24800 32 | # FIXME: Verify parts and values. 33 | CHARGER=bq24780s 34 | CFLAGS+=\ 35 | -DCHARGER_ADAPTER_RSENSE=5 \ 36 | -DCHARGER_BATTERY_RSENSE=10 \ 37 | -DCHARGER_CHARGE_CURRENT=1536 \ 38 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 39 | -DCHARGER_INPUT_CURRENT=7500 40 | 41 | # Set CPU power limits in watts 42 | CFLAGS+=\ 43 | -DPOWER_LIMIT_AC=180 \ 44 | -DPOWER_LIMIT_DC=45 45 | 46 | # Enable dGPU support 47 | CONFIG_HAVE_DGPU = y 48 | CFLAGS += -DI2C_DGPU=I2C_1 49 | 50 | # Fan configs 51 | CFLAGS += -DFAN1_PWM=DCR2 52 | CFLAGS += -DBOARD_FAN1_POINTS="\ 53 | FAN_POINT(60, 40), \ 54 | FAN_POINT(65, 60), \ 55 | FAN_POINT(70, 75), \ 56 | FAN_POINT(75, 90), \ 57 | FAN_POINT(80, 100), \ 58 | " 59 | 60 | CFLAGS += -DFAN2_PWM=DCR4 61 | CFLAGS += -DBOARD_FAN2_POINTS="\ 62 | FAN_POINT(60, 40), \ 63 | FAN_POINT(65, 60), \ 64 | FAN_POINT(70, 75), \ 65 | FAN_POINT(75, 90), \ 66 | FAN_POINT(80, 100), \ 67 | " 68 | 69 | # Add system76 common code 70 | include src/board/system76/common/common.mk 71 | -------------------------------------------------------------------------------- /src/board/system76/gaze17-3060/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void board_init(void) { 12 | espi_init(); 13 | 14 | // Make sure charger is in off state, also enables PSYS 15 | battery_charger_disable(); 16 | 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/gaze17-3060/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=15in_102 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=rgb_pwm 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | # TODO: actually bq24800 29 | # FIXME: Verify parts and values. 30 | CHARGER=bq24780s 31 | CFLAGS+=\ 32 | -DCHARGER_ADAPTER_RSENSE=5 \ 33 | -DCHARGER_BATTERY_RSENSE=10 \ 34 | -DCHARGER_CHARGE_CURRENT=1536 \ 35 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 36 | -DCHARGER_INPUT_CURRENT=7500 37 | 38 | # Set CPU power limits in watts 39 | CFLAGS+=\ 40 | -DPOWER_LIMIT_AC=180 \ 41 | -DPOWER_LIMIT_DC=45 42 | 43 | # Enable dGPU support 44 | CONFIG_HAVE_DGPU = y 45 | CFLAGS += -DI2C_DGPU=I2C_1 46 | 47 | # Fan configs 48 | CFLAGS += -DFAN1_PWM=DCR2 49 | CFLAGS += -DBOARD_FAN1_POINTS="\ 50 | FAN_POINT(60, 40), \ 51 | FAN_POINT(65, 60), \ 52 | FAN_POINT(70, 75), \ 53 | FAN_POINT(75, 90), \ 54 | FAN_POINT(80, 100), \ 55 | " 56 | 57 | CFLAGS += -DFAN2_PWM=DCR4 58 | CFLAGS += -DBOARD_FAN2_POINTS="\ 59 | FAN_POINT(60, 40), \ 60 | FAN_POINT(65, 60), \ 61 | FAN_POINT(70, 75), \ 62 | FAN_POINT(75, 90), \ 63 | FAN_POINT(80, 100), \ 64 | " 65 | 66 | # Add system76 common code 67 | include src/board/system76/common/common.mk 68 | -------------------------------------------------------------------------------- /src/board/system76/gaze17-3060/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SLP_S0_N; 38 | extern struct Gpio __code SLP_SUS_N; 39 | #define HAVE_SUS_PWR_ACK 0 40 | extern struct Gpio __code SUSB_N_PCH; 41 | extern struct Gpio __code SUSC_N_PCH; 42 | extern struct Gpio __code VA_EC_EN; 43 | extern struct Gpio __code WLAN_EN; 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/gaze18/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | } 20 | 21 | void board_event(void) { 22 | espi_event(); 23 | 24 | ec_read_post_codes(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/gaze18/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY=y 16 | 17 | # Include keyboard 18 | KEYBOARD=15in_102 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=rgb_pwm 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_4 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | # TODO: actually bq24800 32 | CHARGER=bq24780s 33 | CFLAGS+=\ 34 | -DCHARGER_ADAPTER_RSENSE=10 \ 35 | -DCHARGER_BATTERY_RSENSE=10 \ 36 | -DCHARGER_CHARGE_CURRENT=3072 \ 37 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 38 | -DCHARGER_INPUT_CURRENT=7500 39 | 40 | # Set CPU power limits in watts 41 | CFLAGS+=\ 42 | -DPOWER_LIMIT_AC=150 \ 43 | -DPOWER_LIMIT_DC=45 44 | 45 | # Enable dGPU support 46 | CONFIG_HAVE_DGPU = y 47 | CFLAGS += -DI2C_DGPU=I2C_1 48 | 49 | # Fan configs 50 | CFLAGS += -DFAN1_PWM=DCR2 51 | CFLAGS += -DBOARD_FAN1_POINTS="\ 52 | FAN_POINT(60, 40), \ 53 | FAN_POINT(65, 60), \ 54 | FAN_POINT(70, 75), \ 55 | FAN_POINT(75, 90), \ 56 | FAN_POINT(80, 100), \ 57 | " 58 | 59 | CFLAGS += -DFAN2_PWM=DCR4 60 | CFLAGS += -DBOARD_FAN2_POINTS="\ 61 | FAN_POINT(60, 40), \ 62 | FAN_POINT(65, 60), \ 63 | FAN_POINT(70, 75), \ 64 | FAN_POINT(75, 90), \ 65 | FAN_POINT(80, 100), \ 66 | " 67 | 68 | # Add system76 common code 69 | include src/board/system76/common/common.mk 70 | -------------------------------------------------------------------------------- /src/board/system76/gaze18/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SLP_SUS_N; 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code VA_EC_EN; 40 | extern struct Gpio __code WLAN_EN; 41 | extern struct Gpio __code WLAN_PWR_EN; 42 | extern struct Gpio __code XLP_OUT; 43 | 44 | #endif // _BOARD_GPIO_H 45 | -------------------------------------------------------------------------------- /src/board/system76/lemp10/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void board_init(void) { 11 | espi_init(); 12 | 13 | // Allow CPU to boot 14 | gpio_set(&SB_KBCRST_N, true); 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | // Enable right USB port 20 | gpio_set(&USB_PWR_EN_N, false); 21 | // Assert SMI#, SCI#, and SWI# 22 | gpio_set(&SCI_N, true); 23 | gpio_set(&SMI_N, true); 24 | gpio_set(&SWI_N, true); 25 | } 26 | 27 | void board_event(void) { 28 | espi_event(); 29 | 30 | ec_read_post_codes(); 31 | } 32 | -------------------------------------------------------------------------------- /src/board/system76/lemp10/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=14in_83 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=white_dac 20 | CFLAGS+=-DKBLED_DAC=2 21 | 22 | # Set battery I2C bus 23 | CFLAGS+=-DI2C_SMBUS=I2C_4 24 | 25 | # Set touchpad PS2 bus 26 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 27 | 28 | # Set smart charger parameters 29 | CFLAGS+=\ 30 | -DCHARGER_ADAPTER_RSENSE=5 \ 31 | -DCHARGER_BATTERY_RSENSE=5 \ 32 | -DCHARGER_CHARGE_CURRENT=3072 \ 33 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 34 | -DCHARGER_INPUT_CURRENT=3420 35 | 36 | # Set CPU power limits in watts 37 | CFLAGS+=\ 38 | -DPOWER_LIMIT_AC=65 \ 39 | -DPOWER_LIMIT_DC=45 40 | 41 | # Fan configs 42 | CFLAGS += -DFAN1_PWM=DCR2 43 | CFLAGS += -DBOARD_FAN1_POINTS="\ 44 | FAN_POINT(70, 40), \ 45 | FAN_POINT(75, 50), \ 46 | FAN_POINT(80, 60), \ 47 | FAN_POINT(85, 65), \ 48 | FAN_POINT(90, 65), \ 49 | " 50 | 51 | # Add system76 common code 52 | include src/board/system76/common/common.mk 53 | -------------------------------------------------------------------------------- /src/board/system76/lemp11/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow CPU to boot 16 | gpio_set(&SB_KBCRST_N, true); 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | // Assert SMI#, SCI#, and SWI# 22 | gpio_set(&SCI_N, true); 23 | gpio_set(&SMI_N, true); 24 | gpio_set(&SWI_N, true); 25 | } 26 | 27 | void board_event(void) { 28 | espi_event(); 29 | 30 | ec_read_post_codes(); 31 | } 32 | -------------------------------------------------------------------------------- /src/board/system76/lemp11/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=14in_83 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=white_dac 20 | CFLAGS+=-DKBLED_DAC=2 21 | 22 | # Set battery I2C bus 23 | CFLAGS+=-DI2C_SMBUS=I2C_4 24 | 25 | # Set touchpad PS2 bus 26 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 27 | 28 | # Set smart charger parameters 29 | CHARGER=oz26786 30 | CFLAGS+=\ 31 | -DCHARGER_ADAPTER_RSENSE=5 \ 32 | -DCHARGER_BATTERY_RSENSE=5 \ 33 | -DCHARGER_CHARGE_CURRENT=3072 \ 34 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 35 | -DCHARGER_INPUT_CURRENT=3420 36 | 37 | # Set CPU power limits in watts 38 | CFLAGS+=\ 39 | -DPOWER_LIMIT_AC=65 \ 40 | -DPOWER_LIMIT_DC=45 41 | 42 | # Fan configs 43 | CFLAGS += -DFAN1_PWM=DCR2 44 | CFLAGS += -DBOARD_FAN1_POINTS="\ 45 | FAN_POINT(70, 40), \ 46 | FAN_POINT(75, 50), \ 47 | FAN_POINT(80, 60), \ 48 | FAN_POINT(85, 65), \ 49 | FAN_POINT(90, 65), \ 50 | " 51 | 52 | # Add system76 common code 53 | include src/board/system76/common/common.mk 54 | -------------------------------------------------------------------------------- /src/board/system76/lemp11/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | extern struct Gpio __code BT_EN; 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | #define HAVE_LAN_WAKEUP_N 0 22 | extern struct Gpio __code LED_ACIN; 23 | #define HAVE_LED_AIRPLANE_N 0 24 | #define HAVE_LED_BAT_CHG 0 25 | #define HAVE_LED_BAT_FULL 0 26 | extern struct Gpio __code LED_PWR; 27 | extern struct Gpio __code LID_SW_N; 28 | extern struct Gpio __code ME_WE; 29 | extern struct Gpio __code PCH_DPWROK_EC; 30 | extern struct Gpio __code PCH_PWROK_EC; 31 | extern struct Gpio __code PM_PWROK; 32 | extern struct Gpio __code PWR_BTN_N; 33 | extern struct Gpio __code PWR_SW_N; 34 | extern struct Gpio __code SB_KBCRST_N; 35 | extern struct Gpio __code SCI_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | extern struct Gpio __code SLP_SUS_N; 38 | extern struct Gpio __code SMI_N; 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | #define HAVE_SUSWARN_N 0 42 | #define HAVE_SUS_PWR_ACK 0 43 | extern struct Gpio __code SWI_N; 44 | extern struct Gpio __code VA_EC_EN; 45 | extern struct Gpio __code WLAN_EN; 46 | extern struct Gpio __code WLAN_PWR_EN; 47 | extern struct Gpio __code XLP_OUT; 48 | 49 | #endif // _BOARD_GPIO_H 50 | -------------------------------------------------------------------------------- /src/board/system76/lemp12/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow CPU to boot 16 | gpio_set(&SB_KBCRST_N, true); 17 | // Allow backlight to be turned on 18 | gpio_set(&BKL_EN, true); 19 | // Enable camera 20 | gpio_set(&CCD_EN, true); 21 | // Assert SMI#, SCI#, and SWI# 22 | gpio_set(&SCI_N, true); 23 | gpio_set(&SMI_N, true); 24 | gpio_set(&SWI_N, true); 25 | } 26 | 27 | void board_event(void) { 28 | espi_event(); 29 | 30 | ec_read_post_codes(); 31 | 32 | // Hack to drain LDO_3V3 capacitors 33 | if (!gpio_get(&XLP_OUT)) { 34 | // These are pulled up by LDO_3V3, pull them low 35 | // SMB_CLK_EC 36 | GPCRC1 = GPIO_OUT; 37 | // SMB_DATA_EC 38 | GPCRC2 = GPIO_OUT; 39 | // SMB_CLK_EC, SMB_DATA_EC 40 | GPDRC &= ~(BIT(1) | BIT(2)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/board/system76/lemp12/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY=y 16 | 17 | # Include keyboard 18 | KEYBOARD=14in_83 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=white_dac 23 | CFLAGS+=-DKBLED_DAC=2 24 | 25 | # Set battery I2C bus 26 | CFLAGS+=-DI2C_SMBUS=I2C_4 27 | 28 | # Set touchpad PS2 bus 29 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 30 | 31 | # Set smart charger parameters 32 | #TODO: why is psys gain 0.5uA/W 33 | CHARGER=oz26786 34 | CFLAGS+=\ 35 | -DCHARGER_ADAPTER_RSENSE=5 \ 36 | -DCHARGER_BATTERY_RSENSE=5 \ 37 | -DCHARGER_CHARGE_CURRENT=3072 \ 38 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 39 | -DCHARGER_INPUT_CURRENT=3420 \ 40 | -DCHARGER_PSYS_GAIN=500 41 | 42 | # Set CPU power limits in watts 43 | CFLAGS+=\ 44 | -DPOWER_LIMIT_AC=65 \ 45 | -DPOWER_LIMIT_DC=45 46 | 47 | # Fan configs 48 | CFLAGS += -DFAN1_PWM=DCR2 49 | CFLAGS += -DBOARD_FAN1_POINTS="\ 50 | FAN_POINT(70, 40), \ 51 | FAN_POINT(75, 50), \ 52 | FAN_POINT(80, 60), \ 53 | FAN_POINT(85, 65), \ 54 | FAN_POINT(90, 65), \ 55 | " 56 | 57 | # Add system76 common code 58 | include src/board/system76/common/common.mk 59 | -------------------------------------------------------------------------------- /src/board/system76/lemp13-b/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | } 20 | 21 | void board_event(void) { 22 | espi_event(); 23 | 24 | ec_read_post_codes(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/lemp13-b/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_256K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | CONFIG_PECI_OVER_ESPI = y 14 | 15 | # Enable firmware security 16 | CONFIG_SECURITY=y 17 | 18 | # Include keyboard 19 | KEYBOARD=14in_83 20 | KEYMAP=darp10-b 21 | 22 | # Set keyboard LED mechanism 23 | CONFIG_HAVE_KBLED = y 24 | KBLED=white_dac 25 | CFLAGS+=-DKBLED_DAC=2 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | CHARGER=oz26786 32 | CFLAGS+=-DI2C_SMBUS=I2C_4 33 | CFLAGS+=\ 34 | -DCHARGER_ADAPTER_RSENSE=5 \ 35 | -DCHARGER_BATTERY_RSENSE=10 \ 36 | -DCHARGER_CHARGE_CURRENT=1536 \ 37 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 38 | -DCHARGER_INPUT_CURRENT=3420 39 | 40 | # Set CPU power limits in watts 41 | CFLAGS+=\ 42 | -DPOWER_LIMIT_AC=65 \ 43 | -DPOWER_LIMIT_DC=45 44 | 45 | # Fan configs 46 | CFLAGS += -DFAN1_PWM=DCR2 47 | CFLAGS += -DBOARD_FAN1_POINTS="\ 48 | FAN_POINT(70, 40), \ 49 | FAN_POINT(75, 50), \ 50 | FAN_POINT(80, 60), \ 51 | FAN_POINT(85, 65), \ 52 | FAN_POINT(90, 65), \ 53 | " 54 | 55 | # Add system76 common code 56 | include src/board/system76/common/common.mk 57 | -------------------------------------------------------------------------------- /src/board/system76/lemp13-b/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | #define HAVE_LAN_WAKEUP_N 0 22 | extern struct Gpio __code LED_ACIN; 23 | #define HAVE_LED_AIRPLANE_N 0 24 | #define HAVE_LED_BAT_CHG 0 25 | #define HAVE_LED_BAT_FULL 0 26 | extern struct Gpio __code LED_PWR; 27 | extern struct Gpio __code LID_SW_N; 28 | extern struct Gpio __code ME_WE; 29 | #define HAVE_PCH_DPWROK_EC 0 30 | extern struct Gpio __code PCH_PWROK_EC; 31 | #define HAVE_PD_EN 1 32 | extern struct Gpio __code PD_EN; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | #define HAVE_SLP_SUS_N 0 38 | extern struct Gpio __code SUSB_N_PCH; 39 | extern struct Gpio __code SUSC_N_PCH; 40 | #define HAVE_SUSWARN_N 0 41 | #define HAVE_SUS_PWR_ACK 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/lemp13/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | } 20 | 21 | void board_event(void) { 22 | espi_event(); 23 | 24 | ec_read_post_codes(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/lemp13/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_256K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | CONFIG_PECI_OVER_ESPI = y 14 | 15 | # Enable firmware security 16 | CONFIG_SECURITY=y 17 | 18 | # Include keyboard 19 | KEYBOARD=14in_81 20 | 21 | # Set keyboard LED mechanism 22 | CONFIG_HAVE_KBLED = y 23 | KBLED=white_dac 24 | CFLAGS+=-DKBLED_DAC=2 25 | 26 | # Set touchpad PS2 bus 27 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 28 | 29 | # Set smart charger parameters 30 | CHARGER=oz26786 31 | CFLAGS+=-DI2C_SMBUS=I2C_4 32 | CFLAGS+=\ 33 | -DCHARGER_ADAPTER_RSENSE=5 \ 34 | -DCHARGER_BATTERY_RSENSE=10 \ 35 | -DCHARGER_CHARGE_CURRENT=1536 \ 36 | -DCHARGER_CHARGE_VOLTAGE=17600 \ 37 | -DCHARGER_INPUT_CURRENT=3420 38 | 39 | # Set CPU power limits in watts 40 | CFLAGS+=\ 41 | -DPOWER_LIMIT_AC=65 \ 42 | -DPOWER_LIMIT_DC=45 43 | 44 | # Fan configs 45 | CFLAGS += -DFAN1_PWM=DCR2 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(70, 40), \ 48 | FAN_POINT(75, 50), \ 49 | FAN_POINT(80, 60), \ 50 | FAN_POINT(85, 65), \ 51 | FAN_POINT(90, 65), \ 52 | " 53 | 54 | # Add system76 common code 55 | include src/board/system76/common/common.mk 56 | -------------------------------------------------------------------------------- /src/board/system76/lemp13/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | #define HAVE_LAN_WAKEUP_N 0 22 | extern struct Gpio __code LED_ACIN; 23 | #define HAVE_LED_AIRPLANE_N 0 24 | #define HAVE_LED_BAT_CHG 0 25 | #define HAVE_LED_BAT_FULL 0 26 | extern struct Gpio __code LED_PWR; 27 | extern struct Gpio __code LID_SW_N; 28 | extern struct Gpio __code ME_WE; 29 | #define HAVE_PCH_DPWROK_EC 0 30 | extern struct Gpio __code PCH_PWROK_EC; 31 | #define HAVE_PD_EN 1 32 | extern struct Gpio __code PD_EN; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code SLP_S0_N; 37 | #define HAVE_SLP_SUS_N 0 38 | extern struct Gpio __code SUSB_N_PCH; 39 | extern struct Gpio __code SUSC_N_PCH; 40 | #define HAVE_SUSWARN_N 0 41 | #define HAVE_SUS_PWR_ACK 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/lemp9/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | void board_init(void) { 7 | // Allow CPU to boot 8 | gpio_set(&SB_KBCRST_N, true); 9 | // Allow backlight to be turned on 10 | gpio_set(&BKL_EN, true); 11 | // Enable camera 12 | gpio_set(&CCD_EN, true); 13 | // Enable right USB port 14 | gpio_set(&USB_PWR_EN_N, false); 15 | // Assert SMI#, SCI#, and SWI# 16 | gpio_set(&SCI_N, true); 17 | gpio_set(&SMI_N, true); 18 | gpio_set(&SWI_N, true); 19 | } 20 | 21 | void board_on_ac(bool ac) { 22 | // Fix unused variable 23 | ac = ac; 24 | } 25 | 26 | void board_event(void) {} 27 | -------------------------------------------------------------------------------- /src/board/system76/lemp9/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=14in_83 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=white_dac 19 | CFLAGS+=-DKBLED_DAC=2 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CFLAGS+=\ 29 | -DCHARGER_ADAPTER_RSENSE=5 \ 30 | -DCHARGER_BATTERY_RSENSE=5 \ 31 | -DCHARGER_CHARGE_CURRENT=3072 \ 32 | -DCHARGER_CHARGE_VOLTAGE=8800 \ 33 | -DCHARGER_INPUT_CURRENT=3420 34 | 35 | # Set CPU power limits in watts 36 | CFLAGS+=\ 37 | -DPOWER_LIMIT_AC=65 \ 38 | -DPOWER_LIMIT_DC=45 39 | 40 | # Fan configs 41 | CFLAGS += -DFAN1_PWM=DCR2 42 | CFLAGS += -DBOARD_FAN1_POINTS="\ 43 | FAN_POINT(70, 40), \ 44 | FAN_POINT(75, 50), \ 45 | FAN_POINT(80, 60), \ 46 | FAN_POINT(85, 65), \ 47 | FAN_POINT(90, 65), \ 48 | " 49 | 50 | # Add system76 common code 51 | include src/board/system76/common/common.mk 52 | -------------------------------------------------------------------------------- /src/board/system76/oryp11/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | } 20 | 21 | void board_event(void) { 22 | espi_event(); 23 | 24 | ec_read_post_codes(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/oryp11/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code DGPU_PWR_EN; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | extern struct Gpio __code GC6_FB_EN; 22 | extern struct Gpio __code JACK_IN_N; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PD_EN 1 34 | extern struct Gpio __code PD_EN; 35 | #define HAVE_PM_PWROK 0 36 | extern struct Gpio __code PWR_BTN_N; 37 | extern struct Gpio __code PWR_SW_N; 38 | extern struct Gpio __code RGBKB_DET_N; 39 | extern struct Gpio __code SINK_CTRL; 40 | extern struct Gpio __code SLP_SUS_N; 41 | #define HAVE_SUS_PWR_ACK 0 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/oryp12/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | } 20 | 21 | void board_event(void) { 22 | espi_event(); 23 | 24 | ec_read_post_codes(); 25 | } 26 | -------------------------------------------------------------------------------- /src/board/system76/oryp12/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code DGPU_PWR_EN; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | extern struct Gpio __code GC6_FB_EN; 22 | extern struct Gpio __code JACK_IN_N; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | #define HAVE_PCH_PWROK_EC 0 33 | extern struct Gpio __code PM_PWROK; 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SINK_CTRL; 38 | extern struct Gpio __code SLP_SUS_N; 39 | #define HAVE_SUS_PWR_ACK 0 40 | extern struct Gpio __code SUSB_N_PCH; 41 | extern struct Gpio __code SUSC_N_PCH; 42 | extern struct Gpio __code VA_EC_EN; 43 | #define HAVE_WLAN_EN 0 44 | extern struct Gpio __code WLAN_PWR_EN; 45 | extern struct Gpio __code XLP_OUT; 46 | 47 | #endif // _BOARD_GPIO_H 48 | -------------------------------------------------------------------------------- /src/board/system76/oryp5/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void board_init(void) { 8 | // Allow CPU to boot 9 | gpio_set(&SB_KBCRST_N, true); 10 | // Allow backlight to be turned on 11 | gpio_set(&BKL_EN, true); 12 | // Enable camera 13 | gpio_set(&CCD_EN, true); 14 | // Enable USB power 15 | gpio_set(&USB_PWR_EN_N, false); 16 | // Assert SMI#, SCI#, and SWI# 17 | gpio_set(&SCI_N, true); 18 | gpio_set(&SMI_N, true); 19 | gpio_set(&SWI_N, true); 20 | } 21 | 22 | void board_event(void) {} 23 | -------------------------------------------------------------------------------- /src/board/system76/oryp5/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT8587E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=oryp5 19 | CFLAGS+=-DI2C_KBLED=I2C_1 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_0 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CFLAGS+=\ 29 | -DCHARGER_ADAPTER_RSENSE=10 \ 30 | -DCHARGER_BATTERY_RSENSE=10 \ 31 | -DCHARGER_CHARGE_CURRENT=2048 \ 32 | -DCHARGER_CHARGE_VOLTAGE=17120 \ 33 | -DCHARGER_INPUT_CURRENT=9230 34 | 35 | # Set CPU power limits in watts 36 | CFLAGS+=\ 37 | -DPOWER_LIMIT_AC=180 \ 38 | -DPOWER_LIMIT_DC=45 39 | 40 | # Enable dGPU support 41 | CONFIG_HAVE_DGPU = y 42 | CFLAGS += -DI2C_DGPU=I2C_1 43 | 44 | # Fan configs 45 | CFLAGS += -DFAN1_PWM=DCR2 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(60, 40), \ 48 | FAN_POINT(65, 60), \ 49 | FAN_POINT(70, 75), \ 50 | FAN_POINT(75, 90), \ 51 | FAN_POINT(80, 100), \ 52 | " 53 | 54 | CFLAGS += -DFAN2_PWM=DCR4 55 | CFLAGS += -DBOARD_FAN2_POINTS="\ 56 | FAN_POINT(60, 40), \ 57 | FAN_POINT(65, 60), \ 58 | FAN_POINT(70, 75), \ 59 | FAN_POINT(75, 90), \ 60 | FAN_POINT(80, 100), \ 61 | " 62 | 63 | # Add system76 common code 64 | include src/board/system76/common/common.mk 65 | -------------------------------------------------------------------------------- /src/board/system76/oryp6/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | // Allow CPU to boot 11 | gpio_set(&SB_KBCRST_N, true); 12 | // Allow backlight to be turned on 13 | gpio_set(&BKL_EN, true); 14 | // Enable camera 15 | gpio_set(&CCD_EN, true); 16 | // Enable USB port power? 17 | gpio_set(&USB_PWR_EN_N, false); 18 | // Assert SMI#, SCI#, and SWI# 19 | gpio_set(&SCI_N, true); 20 | gpio_set(&SMI_N, true); 21 | gpio_set(&SWI_N, true); 22 | } 23 | 24 | void board_event(void) { 25 | ec_read_post_codes(); 26 | } 27 | -------------------------------------------------------------------------------- /src/board/system76/oryp6/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=rgb_pwm 19 | 20 | # Set battery I2C bus 21 | CFLAGS+=-DI2C_SMBUS=I2C_4 22 | 23 | # Set touchpad PS2 bus 24 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 25 | 26 | # Set smart charger parameters 27 | CFLAGS+=\ 28 | -DCHARGER_ADAPTER_RSENSE=10 \ 29 | -DCHARGER_BATTERY_RSENSE=10 \ 30 | -DCHARGER_CHARGE_CURRENT=2048 \ 31 | -DCHARGER_CHARGE_VOLTAGE=13050 \ 32 | -DCHARGER_INPUT_CURRENT=9230 33 | 34 | # Set CPU power limits in watts 35 | CFLAGS+=\ 36 | -DPOWER_LIMIT_AC=180 \ 37 | -DPOWER_LIMIT_DC=45 38 | 39 | # Enable dGPU support 40 | CONFIG_HAVE_DGPU = y 41 | CFLAGS += -DI2C_DGPU=I2C_1 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DFAN1_PWM_MIN=25 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(55, 25), \ 48 | FAN_POINT(65, 30), \ 49 | FAN_POINT(70, 40), \ 50 | FAN_POINT(75, 60), \ 51 | FAN_POINT(80, 75), \ 52 | FAN_POINT(85, 90), \ 53 | FAN_POINT(90, 100), \ 54 | " 55 | 56 | CFLAGS += -DFAN2_PWM=DCR4 57 | CFLAGS += -DFAN2_PWM_MIN=25 58 | CFLAGS += -DBOARD_FAN2_POINTS="\ 59 | FAN_POINT(55, 25), \ 60 | FAN_POINT(65, 30), \ 61 | FAN_POINT(70, 40), \ 62 | FAN_POINT(75, 60), \ 63 | FAN_POINT(80, 75), \ 64 | FAN_POINT(85, 90), \ 65 | FAN_POINT(90, 100), \ 66 | " 67 | 68 | # Add system76 common code 69 | include src/board/system76/common/common.mk 70 | -------------------------------------------------------------------------------- /src/board/system76/oryp7/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | // Allow CPU to boot 11 | gpio_set(&SB_KBCRST_N, true); 12 | // Allow backlight to be turned on 13 | gpio_set(&BKL_EN, true); 14 | // Enable camera 15 | gpio_set(&CCD_EN, true); 16 | // Enable USB port power? 17 | gpio_set(&USB_PWR_EN_N, false); 18 | // Assert SMI#, SCI#, and SWI# 19 | gpio_set(&SCI_N, true); 20 | gpio_set(&SMI_N, true); 21 | gpio_set(&SWI_N, true); 22 | } 23 | 24 | void board_event(void) { 25 | ec_read_post_codes(); 26 | } 27 | -------------------------------------------------------------------------------- /src/board/system76/oryp7/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | 13 | # Include keyboard 14 | KEYBOARD=15in_102 15 | 16 | # Set keyboard LED mechanism 17 | CONFIG_HAVE_KBLED = y 18 | KBLED=rgb_pwm 19 | 20 | # Set battery I2C bus 21 | CFLAGS+=-DI2C_SMBUS=I2C_4 22 | 23 | # Set touchpad PS2 bus 24 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 25 | 26 | # Set smart charger parameters 27 | CFLAGS+=\ 28 | -DCHARGER_ADAPTER_RSENSE=10 \ 29 | -DCHARGER_BATTERY_RSENSE=10 \ 30 | -DCHARGER_CHARGE_CURRENT=2048 \ 31 | -DCHARGER_CHARGE_VOLTAGE=13050 \ 32 | -DCHARGER_INPUT_CURRENT=9230 33 | 34 | # Set CPU power limits in watts 35 | CFLAGS+=\ 36 | -DPOWER_LIMIT_AC=180 \ 37 | -DPOWER_LIMIT_DC=45 38 | 39 | # Enable dGPU support 40 | CONFIG_HAVE_DGPU = y 41 | CFLAGS += -DI2C_DGPU=I2C_1 42 | 43 | # Fan configs 44 | CFLAGS += -DFAN1_PWM=DCR2 45 | CFLAGS += -DFAN1_PWM_MIN=25 46 | CFLAGS += -DBOARD_FAN1_POINTS="\ 47 | FAN_POINT(55, 25), \ 48 | FAN_POINT(65, 30), \ 49 | FAN_POINT(70, 40), \ 50 | FAN_POINT(75, 60), \ 51 | FAN_POINT(80, 75), \ 52 | FAN_POINT(85, 90), \ 53 | FAN_POINT(90, 100), \ 54 | " 55 | 56 | CFLAGS += -DFAN2_PWM=DCR4 57 | CFLAGS += -DFAN2_PWM_MIN=25 58 | CFLAGS += -DBOARD_FAN2_POINTS="\ 59 | FAN_POINT(55, 25), \ 60 | FAN_POINT(65, 30), \ 61 | FAN_POINT(70, 40), \ 62 | FAN_POINT(75, 60), \ 63 | FAN_POINT(80, 75), \ 64 | FAN_POINT(85, 90), \ 65 | FAN_POINT(90, 100), \ 66 | " 67 | 68 | # Add system76 common code 69 | include src/board/system76/common/common.mk 70 | -------------------------------------------------------------------------------- /src/board/system76/oryp8/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void board_init(void) { 11 | espi_init(); 12 | 13 | // Allow backlight to be turned on 14 | gpio_set(&BKL_EN, true); 15 | // Enable camera 16 | gpio_set(&CCD_EN, true); 17 | } 18 | 19 | void board_event(void) { 20 | espi_event(); 21 | 22 | ec_read_post_codes(); 23 | } 24 | -------------------------------------------------------------------------------- /src/board/system76/oryp8/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Include keyboard 15 | KEYBOARD=15in_102 16 | 17 | # Set keyboard LED mechanism 18 | CONFIG_HAVE_KBLED = y 19 | KBLED=rgb_pwm 20 | 21 | # Set battery I2C bus 22 | CFLAGS+=-DI2C_SMBUS=I2C_4 23 | 24 | # Set touchpad PS2 bus 25 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 26 | 27 | # Set smart charger parameters 28 | CFLAGS+=\ 29 | -DCHARGER_ADAPTER_RSENSE=10 \ 30 | -DCHARGER_BATTERY_RSENSE=10 \ 31 | -DCHARGER_CHARGE_CURRENT=2048 \ 32 | -DCHARGER_CHARGE_VOLTAGE=13050 \ 33 | -DCHARGER_INPUT_CURRENT=9230 34 | 35 | # Set CPU power limits in watts 36 | CFLAGS+=\ 37 | -DPOWER_LIMIT_AC=180 \ 38 | -DPOWER_LIMIT_DC=45 39 | 40 | # Enable dGPU support 41 | CONFIG_HAVE_DGPU = y 42 | CFLAGS += -DI2C_DGPU=I2C_1 43 | 44 | # Fan configs 45 | CFLAGS += -DFAN1_PWM=DCR2 46 | CFLAGS += -DFAN1_PWM_MIN=25 47 | CFLAGS += -DBOARD_FAN1_POINTS="\ 48 | FAN_POINT(55, 25), \ 49 | FAN_POINT(65, 30), \ 50 | FAN_POINT(70, 40), \ 51 | FAN_POINT(75, 60), \ 52 | FAN_POINT(80, 75), \ 53 | FAN_POINT(85, 90), \ 54 | FAN_POINT(90, 100), \ 55 | " 56 | 57 | CFLAGS += -DFAN2_PWM=DCR4 58 | CFLAGS += -DFAN2_PWM_MIN=25 59 | CFLAGS += -DBOARD_FAN2_POINTS="\ 60 | FAN_POINT(55, 25), \ 61 | FAN_POINT(65, 30), \ 62 | FAN_POINT(70, 40), \ 63 | FAN_POINT(75, 60), \ 64 | FAN_POINT(80, 75), \ 65 | FAN_POINT(85, 90), \ 66 | FAN_POINT(90, 100), \ 67 | " 68 | 69 | # Add system76 common code 70 | include src/board/system76/common/common.mk 71 | -------------------------------------------------------------------------------- /src/board/system76/oryp8/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code CPU_C10_GATE_N; 18 | extern struct Gpio __code DD_ON; 19 | extern struct Gpio __code DGPU_PWR_EN; 20 | extern struct Gpio __code EC_EN; 21 | extern struct Gpio __code EC_RSMRST_N; 22 | extern struct Gpio __code GC6_FB_EN; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SLP_SUS_N; 38 | #define HAVE_SUS_PWR_ACK 0 39 | extern struct Gpio __code SUSB_N_PCH; 40 | extern struct Gpio __code SUSC_N_PCH; 41 | extern struct Gpio __code VA_EC_EN; 42 | extern struct Gpio __code WLAN_EN; 43 | extern struct Gpio __code WLAN_PWR_EN; 44 | extern struct Gpio __code XLP_OUT; 45 | 46 | #endif // _BOARD_GPIO_H 47 | -------------------------------------------------------------------------------- /src/board/system76/oryp9/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | // Enable USB port power 20 | gpio_set(&USB_PWR_EN_N, false); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/oryp9/board.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | board-y += board.c 4 | board-y += gpio.c 5 | 6 | EC=ite 7 | CONFIG_EC_ITE_IT5570E=y 8 | CONFIG_EC_FLASH_SIZE_128K = y 9 | 10 | # Intel-based host 11 | CONFIG_PLATFORM_INTEL = y 12 | CONFIG_BUS_ESPI = y 13 | 14 | # Enable firmware security 15 | CONFIG_SECURITY=y 16 | 17 | # Include keyboard 18 | KEYBOARD=15in_102 19 | 20 | # Set keyboard LED mechanism 21 | CONFIG_HAVE_KBLED = y 22 | KBLED=rgb_pwm 23 | 24 | # Set battery I2C bus 25 | CFLAGS+=-DI2C_SMBUS=I2C_4 26 | 27 | # Set touchpad PS2 bus 28 | CFLAGS+=-DPS2_TOUCHPAD=PS2_3 29 | 30 | # Set smart charger parameters 31 | # TODO: actually bq24800 32 | # FIXME: Verify parts and values. 33 | CFLAGS+=\ 34 | -DCHARGER_ADAPTER_RSENSE=5 \ 35 | -DCHARGER_BATTERY_RSENSE=10 \ 36 | -DCHARGER_CHARGE_CURRENT=2048 \ 37 | -DCHARGER_CHARGE_VOLTAGE=13050 \ 38 | -DCHARGER_INPUT_CURRENT=11500 39 | 40 | # Set CPU power limits in watts 41 | CFLAGS+=\ 42 | -DPOWER_LIMIT_AC=180 \ 43 | -DPOWER_LIMIT_DC=45 44 | 45 | # Enable dGPU support 46 | CONFIG_HAVE_DGPU = y 47 | CFLAGS += -DI2C_DGPU=I2C_1 48 | 49 | # Fan configs 50 | CFLAGS += -DFAN1_PWM=DCR2 51 | CFLAGS += -DBOARD_FAN1_POINTS="\ 52 | FAN_POINT(50, 40), \ 53 | FAN_POINT(55, 40), \ 54 | FAN_POINT(60, 55), \ 55 | FAN_POINT(69, 55), \ 56 | FAN_POINT(74, 68), \ 57 | FAN_POINT(79, 68), \ 58 | FAN_POINT(80, 72), \ 59 | FAN_POINT(87, 100), \ 60 | " 61 | 62 | CFLAGS += -DFAN2_PWM=DCR4 63 | CFLAGS += -DBOARD_FAN2_POINTS="\ 64 | FAN_POINT(50, 40), \ 65 | FAN_POINT(56, 40), \ 66 | FAN_POINT(72, 100), \ 67 | " 68 | 69 | # Add system76 common code 70 | include src/board/system76/common/common.mk 71 | -------------------------------------------------------------------------------- /src/board/system76/serw13/board.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void board_init(void) { 10 | espi_init(); 11 | 12 | // Make sure charger is in off state, also enables PSYS 13 | battery_charger_disable(); 14 | 15 | // Allow backlight to be turned on 16 | gpio_set(&BKL_EN, true); 17 | // Enable camera 18 | gpio_set(&CCD_EN, true); 19 | // Enable USB port power 20 | gpio_set(&USB_PWR_EN_N, false); 21 | } 22 | 23 | void board_event(void) { 24 | espi_event(); 25 | 26 | ec_read_post_codes(); 27 | } 28 | -------------------------------------------------------------------------------- /src/board/system76/serw13/include/board/gpio.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _BOARD_GPIO_H 4 | #define _BOARD_GPIO_H 5 | 6 | #include 7 | 8 | void gpio_init(void); 9 | 10 | extern struct Gpio __code ACIN_N; 11 | extern struct Gpio __code AC_PRESENT; 12 | extern struct Gpio __code ALL_SYS_PWRGD; 13 | extern struct Gpio __code BKL_EN; 14 | #define HAVE_BT_EN 0 15 | extern struct Gpio __code BUF_PLT_RST_N; 16 | extern struct Gpio __code CCD_EN; 17 | extern struct Gpio __code DD_ON; 18 | extern struct Gpio __code DGPU_PWR_EN; 19 | extern struct Gpio __code EC_EN; 20 | extern struct Gpio __code EC_RSMRST_N; 21 | extern struct Gpio __code GC6_FB_EN; 22 | extern struct Gpio __code JACK_IN_N; 23 | extern struct Gpio __code LAN_WAKEUP_N; 24 | extern struct Gpio __code LED_ACIN; 25 | #define HAVE_LED_AIRPLANE_N 0 26 | extern struct Gpio __code LED_BAT_CHG; 27 | extern struct Gpio __code LED_BAT_FULL; 28 | extern struct Gpio __code LED_PWR; 29 | extern struct Gpio __code LID_SW_N; 30 | extern struct Gpio __code ME_WE; 31 | extern struct Gpio __code PCH_DPWROK_EC; 32 | extern struct Gpio __code PCH_PWROK_EC; 33 | #define HAVE_PM_PWROK 0 34 | extern struct Gpio __code PWR_BTN_N; 35 | extern struct Gpio __code PWR_SW_N; 36 | extern struct Gpio __code RGBKB_DET_N; 37 | extern struct Gpio __code SINK_CTRL; 38 | extern struct Gpio __code SLP_SUS_N; 39 | #define HAVE_SUSWARN_N 0 40 | #define HAVE_SUS_PWR_ACK 0 41 | extern struct Gpio __code SWI_N; 42 | extern struct Gpio __code USB_PWR_EN_N; 43 | extern struct Gpio __code VA_EC_EN; 44 | #define HAVE_WLAN_EN 0 45 | #define HAVE_WLAN_PWR_EN 0 46 | extern struct Gpio __code XLP_OUT; 47 | 48 | #endif // _BOARD_GPIO_H 49 | -------------------------------------------------------------------------------- /src/common/common.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | common-y += i2c.c 4 | common-y += keymap.c 5 | common-y += version.c 6 | -------------------------------------------------------------------------------- /src/common/include/common/debug.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _COMMON_DEBUG_H 4 | #define _COMMON_DEBUG_H 5 | 6 | #include 7 | 8 | #define LEVEL_TRACE 5 9 | #define LEVEL_DEBUG 4 10 | #define LEVEL_INFO 3 11 | #define LEVEL_WARN 2 12 | #define LEVEL_ERROR 1 13 | #define LEVEL_NONE 0 14 | 15 | // This is the user-configurable log level 16 | #ifndef LEVEL 17 | #define LEVEL LEVEL_INFO 18 | #endif 19 | 20 | #if LEVEL >= LEVEL_TRACE 21 | #define TRACE(...) printf(__VA_ARGS__) 22 | #else 23 | #define TRACE(...) 24 | #endif 25 | 26 | #if LEVEL >= LEVEL_DEBUG 27 | #define DEBUG(...) printf(__VA_ARGS__) 28 | #else 29 | #define DEBUG(...) 30 | #endif 31 | 32 | #if LEVEL >= LEVEL_INFO 33 | #define INFO(...) printf(__VA_ARGS__) 34 | #else 35 | #define INFO(...) 36 | #endif 37 | 38 | #if LEVEL >= LEVEL_WARN 39 | #define WARN(...) printf(__VA_ARGS__) 40 | #else 41 | #define WARN(...) 42 | #endif 43 | 44 | #if LEVEL >= LEVEL_ERROR 45 | #define ERROR(...) printf(__VA_ARGS__) 46 | #else 47 | #define ERROR(...) 48 | #endif 49 | 50 | #endif // _COMMON_DEBUG_H 51 | -------------------------------------------------------------------------------- /src/common/include/common/macro.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _COMMON_MACRO_H 4 | #define _COMMON_MACRO_H 5 | 6 | #define xconcat(a, b) concat(a, b) 7 | #define concat(a, b) a##b 8 | 9 | #define xstr(s) str(s) 10 | #define str(s) #s 11 | 12 | #define MAYBE_UNUSED(x) ((void)(x)) 13 | 14 | #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0])) 15 | 16 | #define BIT(X) (1UL << (X)) 17 | 18 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 19 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 20 | #define CLAMP(val, min, max) (MIN(MAX(val, min), max)) 21 | 22 | #endif // _COMMON_MACRO_H 23 | -------------------------------------------------------------------------------- /src/common/include/common/version.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _COMMON_VERSION_H 4 | #define _COMMON_VERSION_H 5 | 6 | const char *board(void); 7 | const char *version(void); 8 | 9 | #endif // _COMMON_VERSION_H 10 | -------------------------------------------------------------------------------- /src/common/version.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | // Prevent failures to compile on AVR 6 | #ifndef __SDCC 7 | #define __code 8 | #endif 9 | 10 | static const char __code BOARD[] = 11 | "76EC_BOARD=" 12 | xstr(__BOARD__); 13 | 14 | static const char __code VERSION[] = 15 | "76EC_VERSION=" 16 | xstr(__FIRMWARE_VERSION__); 17 | 18 | const char *board(void) { 19 | return &BOARD[11]; 20 | } 21 | 22 | const char *version(void) { 23 | return &VERSION[13]; 24 | } 25 | -------------------------------------------------------------------------------- /src/ec/atmega/ec.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | ARCH=avr 4 | -------------------------------------------------------------------------------- /src/ec/ite/ec.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void ec_init(void) { 9 | #if CONFIG_EC_ITE_IT8587E 10 | RSTS = (0b10U << 6) | BIT(2); 11 | #else 12 | RSTS = (0b01U << 6) | BIT(2); 13 | 14 | // Enable POST codes 15 | SPCTRL1 |= BIT(7) | BIT(6) | BIT(3); 16 | #endif 17 | } 18 | 19 | void ec_read_post_codes(void) { 20 | #if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E 21 | while (P80H81HS & 1) { 22 | uint8_t p80h = P80HD; 23 | uint8_t p81h = P81HD; 24 | P80H81HS |= 1; 25 | 26 | DEBUG("POST %02X%02X\n", p81h, p80h); 27 | } 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /src/ec/ite/ec.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | ec-y += ec.c 4 | ec-$(CONFIG_BUS_ESPI) += espi.c 5 | ec-y += gpio.c 6 | ec-y += i2c.c 7 | ec-y += intc.c 8 | ec-y += kbc.c 9 | ec-y += pmc.c 10 | ec-y += ps2.c 11 | ec-y += signature.c 12 | ec-y += wuc.c 13 | 14 | # Chip clock frequency: 9.2 MHz 15 | CFLAGS += -DCONFIG_CLOCK_FREQ_KHZ=9200 16 | 17 | ifeq ($(CONFIG_EC_ITE_IT8587E), y) 18 | CFLAGS+=-DCONFIG_EC_ITE_IT8587E=1 19 | # SRAM is 4096 bytes, but SRAM at address 2048 is used for scratch ROM 20 | SRAM_SIZE=2048 21 | else ifeq ($(CONFIG_EC_ITE_IT5570E), y) 22 | CFLAGS+=-DCONFIG_EC_ITE_IT5570E=1 23 | # SRAM is 6144 bytes, only 4096 bytes are mapped at address 0. Region at 24 | # 0x0E00-0x1000 is used for AP communication. So this is brought down to 2048, 25 | # which matches IT8587E limits 26 | SRAM_SIZE=2048 27 | else ifeq ($(CONFIG_EC_ITE_IT5571E), y) 28 | # The IT5571E is effectively the same as the IT5570E. 29 | CFLAGS+=-DCONFIG_EC_ITE_IT5571E=1 30 | SRAM_SIZE=2048 31 | else 32 | $(error Unsupported EC) 33 | endif 34 | 35 | ARCH=8051 36 | 37 | # 64 KB is the max without banking 38 | CODE_SIZE=65536 39 | 40 | # Chip flash size 41 | ifeq ($(CONFIG_EC_FLASH_SIZE_128K),y) 42 | CONFIG_EC_FLASH_SIZE = 131072 43 | else ifeq ($(CONFIG_EC_FLASH_SIZE_256K),y) 44 | CONFIG_EC_FLASH_SIZE = 262144 45 | else 46 | $(error flash size not specified) 47 | endif 48 | 49 | CFLAGS += -DCONFIG_EC_FLASH_SIZE=$(CONFIG_EC_FLASH_SIZE) 50 | -------------------------------------------------------------------------------- /src/ec/ite/gpio.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | bool gpio_get(const struct Gpio *const gpio) { 7 | if (*(gpio->data) & gpio->value) { 8 | return true; 9 | } else { 10 | return false; 11 | } 12 | } 13 | 14 | void gpio_set(struct Gpio *const gpio, bool value) { 15 | if (value) { 16 | *(gpio->data) |= gpio->value; 17 | } else { 18 | *(gpio->data) &= ~(gpio->value); 19 | } 20 | } 21 | 22 | #ifdef GPIO_DEBUG 23 | static void gpio_debug_bank( 24 | char *const bank, 25 | uint8_t data, 26 | uint8_t mirror, 27 | uint8_t pot, 28 | volatile uint8_t *const control 29 | ) { 30 | for (char i = 0; i < 8; i++) { 31 | DEBUG( 32 | "%s%d: data %d mirror %d pot %d control %02X\n", 33 | bank, 34 | i, 35 | (data >> i) & 1, 36 | (mirror >> i) & 1, 37 | (pot >> i) & 1, 38 | *(control + i) 39 | ); 40 | } 41 | } 42 | 43 | void gpio_debug(void) { 44 | #define bank(BANK) gpio_debug_bank(#BANK, GPDR##BANK, GPDMR##BANK, GPOT##BANK, &GPCR##BANK##0) 45 | bank(A); 46 | bank(B); 47 | bank(C); 48 | bank(D); 49 | bank(E); 50 | bank(F); 51 | bank(G); 52 | bank(H); 53 | bank(I); 54 | bank(J); 55 | #define GPOTM 0 56 | bank(M); 57 | #undef GPOTM 58 | #undef bank 59 | } 60 | #endif // GPIO_DEBUG 61 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/bram.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_BRAM_H 4 | #define _EC_BRAM_H 5 | 6 | #include 7 | 8 | volatile uint8_t __xdata __at(0x2200) BRAM[192]; 9 | 10 | #endif // _EC_BRAM_H 11 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/dac.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_DAC_H 4 | #define _EC_DAC_H 5 | 6 | #include 7 | 8 | volatile uint8_t __xdata __at(0x1A01) DACPDREG; 9 | volatile uint8_t __xdata __at(0x1A04) DACDAT2; 10 | volatile uint8_t __xdata __at(0x1A05) DACDAT3; 11 | volatile uint8_t __xdata __at(0x1A06) DACDAT4; 12 | volatile uint8_t __xdata __at(0x1A07) DACDAT5; 13 | 14 | #endif // _EC_DAC_H 15 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/ec.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_EC_H 4 | #define _EC_EC_H 5 | 6 | void ec_init(void); 7 | void ec_read_post_codes(void); 8 | 9 | #endif // _EC_EC_H 10 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/ecpm.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_ECPM_H 4 | #define _EC_ECPM_H 5 | 6 | #include 7 | 8 | volatile uint8_t __xdata __at(0x1E01) CGCTRL1; 9 | volatile uint8_t __xdata __at(0x1E02) CGCTRL2; 10 | volatile uint8_t __xdata __at(0x1E03) PLLCTRL; 11 | volatile uint8_t __xdata __at(0x1E04) AUTOCG; 12 | volatile uint8_t __xdata __at(0x1E05) CGCTRL3; 13 | volatile uint8_t __xdata __at(0x1E06) PLLFREQ; 14 | volatile uint8_t __xdata __at(0x1E08) PLLCSS; 15 | volatile uint8_t __xdata __at(0x1E09) CGCTRL4; 16 | 17 | #endif // _EC_ECPM_H 18 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/etwd.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_ECWD_H 4 | #define _EC_ECWD_H 5 | 6 | #include 7 | 8 | volatile uint8_t __xdata __at(0x1F01) ETWCFG; 9 | volatile uint8_t __xdata __at(0x1F02) ET1PSR; 10 | volatile uint8_t __xdata __at(0x1F04) ET1CNTLLR; 11 | volatile uint8_t __xdata __at(0x1F06) EWDCNTLLR; 12 | volatile uint8_t __xdata __at(0x1F07) EWDKEYR; 13 | volatile uint8_t __xdata __at(0x1F09) EWDCNTLHR; 14 | 15 | #endif // _EC_ECWD_H 16 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/gctrl.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_GCTRL_H 4 | #define _EC_GCTRL_H 5 | 6 | #include 7 | 8 | volatile uint8_t __xdata __at(0x2006) RSTS; 9 | volatile uint8_t __xdata __at(0x200A) BADRSEL; 10 | volatile uint8_t __xdata __at(0x200D) SPCTRL1; 11 | #if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E 12 | volatile uint8_t __xdata __at(0x2030) P80H81HS; 13 | volatile uint8_t __xdata __at(0x2031) P80HD; 14 | volatile uint8_t __xdata __at(0x2032) P81HD; 15 | #endif 16 | 17 | #endif // _EC_GCTRL_H 18 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/i2c.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_I2C_H 4 | #define _EC_I2C_H 5 | 6 | #include 7 | 8 | extern struct I2C __code I2C_0; 9 | extern struct I2C __code I2C_1; 10 | #if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E 11 | extern struct I2C __code I2C_4; 12 | #endif 13 | 14 | void i2c_reset(struct I2C *const i2c, bool kill); 15 | 16 | #endif // _EC_I2C_H 17 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/kbc.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_KBC_H 4 | #define _EC_KBC_H 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | struct Kbc { 12 | // Control register 13 | volatile uint8_t *control; 14 | // Interrupt control register 15 | volatile uint8_t *irq; 16 | // Status register 17 | volatile uint8_t *status; 18 | // Keyboard out register 19 | volatile uint8_t *keyboard_out; 20 | // Mouse out register 21 | volatile uint8_t *mouse_out; 22 | // Data in register 23 | volatile uint8_t *data_in; 24 | }; 25 | 26 | extern struct Kbc __code KBC; 27 | 28 | #define KBC_STS_OBF BIT(0) 29 | #define KBC_STS_IBF BIT(1) 30 | #define KBC_STS_CMD BIT(3) 31 | 32 | uint8_t kbc_status(const struct Kbc *const kbc); 33 | uint8_t kbc_read(const struct Kbc *const kbc); 34 | bool kbc_keyboard(struct Kbc *const kbc, uint8_t data, uint16_t timeout); 35 | bool kbc_mouse(struct Kbc *const kbc, uint8_t data, uint16_t timeout); 36 | 37 | volatile uint8_t __xdata __at(0x1300) KBHICR; 38 | volatile uint8_t __xdata __at(0x1302) KBIRQR; 39 | volatile uint8_t __xdata __at(0x1304) KBHISR; 40 | volatile uint8_t __xdata __at(0x1306) KBHIKDOR; 41 | volatile uint8_t __xdata __at(0x1308) KBHIMDOR; 42 | volatile uint8_t __xdata __at(0x130A) KBHIDIR; 43 | 44 | #endif // _EC_KBC_H 45 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/peci.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_PECI_H 4 | #define _EC_PECI_H 5 | 6 | #include 7 | 8 | static volatile uint8_t __xdata __at(0x3000) HOSTAR; 9 | static volatile uint8_t __xdata __at(0x3001) HOCTLR; 10 | static volatile uint8_t __xdata __at(0x3002) HOCMDR; 11 | static volatile uint8_t __xdata __at(0x3003) HOTRADDR; 12 | static volatile uint8_t __xdata __at(0x3004) HOWRLR; 13 | static volatile uint8_t __xdata __at(0x3005) HORDLR; 14 | static volatile uint8_t __xdata __at(0x3006) HOWRDR; 15 | static volatile uint8_t __xdata __at(0x3007) HORDDR; 16 | static volatile uint8_t __xdata __at(0x3008) HOCTL2R; 17 | static volatile uint8_t __xdata __at(0x3009) RWFCSV; 18 | static volatile uint8_t __xdata __at(0x300E) PADCTLR; 19 | 20 | #endif // _EC_PECI_H 21 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/ps2.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_PS2_H 4 | #define _EC_PS2_H 5 | 6 | #include 7 | 8 | #define PSSTS_TIMEOUT_ERR BIT(6) 9 | #define PSSTS_FRAME_ERR BIT(5) 10 | #define PSSTS_PARITY_ERR BIT(4) 11 | #define PSSTS_ALL_ERR (PSSTS_TIMEOUT_ERR | PSSTS_FRAME_ERR | PSSTS_PARITY_ERR) 12 | #define PSSTS_DONE BIT(3) 13 | 14 | struct Ps2 { 15 | volatile uint8_t *control; 16 | volatile uint8_t *interrupt; 17 | volatile uint8_t *status; 18 | volatile uint8_t *data; 19 | }; 20 | 21 | extern struct Ps2 __code PS2_1; 22 | extern struct Ps2 __code PS2_2; 23 | extern struct Ps2 __code PS2_3; 24 | 25 | void ps2_reset(struct Ps2 *const ps2); 26 | 27 | volatile uint8_t __xdata __at(0x1700) PSCTL1; 28 | volatile uint8_t __xdata __at(0x1701) PSCTL2; 29 | volatile uint8_t __xdata __at(0x1702) PSCTL3; 30 | 31 | volatile uint8_t __xdata __at(0x1704) PSINT1; 32 | volatile uint8_t __xdata __at(0x1705) PSINT2; 33 | volatile uint8_t __xdata __at(0x1706) PSINT3; 34 | 35 | volatile uint8_t __xdata __at(0x1708) PSSTS1; 36 | volatile uint8_t __xdata __at(0x1709) PSSTS2; 37 | volatile uint8_t __xdata __at(0x170A) PSSTS3; 38 | 39 | volatile uint8_t __xdata __at(0x170C) PSDAT1; 40 | volatile uint8_t __xdata __at(0x170D) PSDAT2; 41 | volatile uint8_t __xdata __at(0x170E) PSDAT3; 42 | 43 | #endif // _EC_PS2_H 44 | -------------------------------------------------------------------------------- /src/ec/ite/include/ec/scratch.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #ifndef _EC_SCRATCH_H 4 | #define _EC_SCRATCH_H 5 | 6 | #include 7 | 8 | // SCAR0 is stored in processor cache, not in xram 9 | volatile uint8_t __xdata __at(0x1040) SCAR0L; 10 | volatile uint8_t __xdata __at(0x1041) SCAR0M; 11 | volatile uint8_t __xdata __at(0x1042) SCAR0H; 12 | #if CONFIG_EC_ITE_IT8587E 13 | // SCAR1 is in xram at 0x800-0xC00 14 | volatile uint8_t __xdata __at(0x1043) SCAR1L; 15 | volatile uint8_t __xdata __at(0x1044) SCAR1M; 16 | volatile uint8_t __xdata __at(0x1045) SCAR1H; 17 | #endif 18 | 19 | #if CONFIG_EC_ITE_IT8587E 20 | #define SCARL SCAR1L 21 | #define SCARM SCAR1M 22 | #define SCARH SCAR1H 23 | #else 24 | #define SCARL SCAR0L 25 | #define SCARM SCAR0M 26 | #define SCARH SCAR0H 27 | #endif 28 | 29 | #endif // _EC_SCRATCH_H 30 | -------------------------------------------------------------------------------- /src/ec/ite/kbc.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | #include 5 | 6 | struct Kbc __code KBC = { 7 | .control = &KBHICR, 8 | .irq = &KBIRQR, 9 | .status = &KBHISR, 10 | .keyboard_out = &KBHIKDOR, 11 | .mouse_out = &KBHIMDOR, 12 | .data_in = &KBHIDIR, 13 | }; 14 | 15 | uint8_t kbc_status(const struct Kbc *const kbc) { 16 | return *(kbc->status); 17 | } 18 | 19 | uint8_t kbc_read(const struct Kbc *const kbc) { 20 | return *(kbc->data_in); 21 | } 22 | 23 | static bool kbc_wait(const struct Kbc *const kbc, uint16_t timeout) { 24 | while (*(kbc->status) & KBC_STS_OBF) { 25 | if (timeout == 0) 26 | return false; 27 | timeout -= 1; 28 | delay_us(1); 29 | } 30 | return true; 31 | } 32 | 33 | bool kbc_keyboard(struct Kbc *const kbc, uint8_t data, uint16_t timeout) { 34 | if (!kbc_wait(kbc, timeout)) 35 | return false; 36 | *(kbc->status) &= ~0x20; 37 | *(kbc->keyboard_out) = data; 38 | return true; 39 | } 40 | 41 | bool kbc_mouse(struct Kbc *const kbc, uint8_t data, uint16_t timeout) { 42 | if (!kbc_wait(kbc, timeout)) 43 | return false; 44 | *(kbc->status) |= 0x20; 45 | *(kbc->mouse_out) = data; 46 | return true; 47 | } 48 | -------------------------------------------------------------------------------- /src/ec/ite/pmc.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #define PMC(NUM) { \ 6 | .status = &PM ## NUM ## STS, \ 7 | .data_out = &PM ## NUM ## DO, \ 8 | .data_in = &PM ## NUM ## DI, \ 9 | .control = &PM ## NUM ## CTL, \ 10 | .interrupt_control = &PM ## NUM ## IC, \ 11 | .interrupt_enable = &PM ## NUM ## IE, \ 12 | } 13 | 14 | struct Pmc __code PMC_1 = PMC(1); 15 | struct Pmc __code PMC_2 = PMC(2); 16 | struct Pmc __code PMC_3 = PMC(3); 17 | struct Pmc __code PMC_4 = PMC(4); 18 | struct Pmc __code PMC_5 = PMC(5); 19 | 20 | uint8_t pmc_status(struct Pmc *const pmc) { 21 | return *(pmc->status); 22 | } 23 | 24 | void pmc_set_status(struct Pmc *const pmc, uint8_t status) { 25 | *(pmc->status) = status; 26 | } 27 | 28 | uint8_t pmc_read(struct Pmc *const pmc) { 29 | return *(pmc->data_in); 30 | } 31 | 32 | void pmc_write(struct Pmc *const pmc, uint8_t data) { 33 | *(pmc->data_out) = data; 34 | } 35 | -------------------------------------------------------------------------------- /src/ec/ite/ps2.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #define PS2(NUM) { \ 6 | .control = &PSCTL ## NUM, \ 7 | .interrupt = &PSINT ## NUM, \ 8 | .status = &PSSTS ## NUM, \ 9 | .data = &PSDAT ## NUM, \ 10 | } 11 | 12 | struct Ps2 __code PS2_1 = PS2(1); 13 | struct Ps2 __code PS2_2 = PS2(2); 14 | struct Ps2 __code PS2_3 = PS2(3); 15 | 16 | void ps2_reset(struct Ps2 *const ps2) { 17 | // Reset interface to defaults 18 | *(ps2->control) = 1; 19 | // Clear status 20 | *(ps2->status) = *(ps2->status); 21 | } 22 | -------------------------------------------------------------------------------- /src/ec/ite/signature.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | #include 4 | 5 | #if CONFIG_BUS_ESPI 6 | // eSPI signature (byte 7 = 0xA4) 7 | static __code const uint8_t __at(0x40) SIGNATURE[16] = { 8 | 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA4, 0x95, 9 | 0x85, 0x12, 0x5A, 0x5A, 0xAA, 0x00, 0x55, 0x55, 10 | }; 11 | #else // CONFIG_BUS_ESPI 12 | // LPC signature (byte 7 = 0xA5) 13 | static __code const uint8_t __at(0x40) SIGNATURE[16] = { 14 | 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0x94, 15 | 0x85, 0x12, 0x5A, 0x5A, 0xAA, 0x00, 0x55, 0x55, 16 | }; 17 | #endif // CONFIG_BUS_ESPI 18 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_81/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_81/keymap/default.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // Default layout 4 | 5 | #include 6 | 7 | // uncrustify:off 8 | uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN] = { 9 | LAYOUT( 10 | K_ESC, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, K_PRINT_SCREEN, K_INSERT, K_PAUSE, K_DEL, 11 | K_TICK, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 12 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 13 | K_CAPS, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 14 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, K_UP, 15 | K_LEFT_CTRL, KT_FN, K_LEFT_SUPER, K_LEFT_ALT, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_LEFT, K_RIGHT, K_DOWN 16 | ), 17 | LAYOUT( 18 | K_ESC, K_TOUCHPAD, K_MIC_MUTE, K_MUTE, K_KBD_BKL, K_VOLUME_DOWN, K_VOLUME_UP, K_DISPLAY_MODE, K_BRIGHTNESS_DOWN, K_BRIGHTNESS_UP, K_CAMERA_TOGGLE, K_AIRPLANE_MODE, K_SUSPEND, K_PRINT_SCREEN, K_INSERT, K_PAUSE, K_DEL, 19 | K_PLAY_PAUSE, K_FAN_TOGGLE, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 20 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 21 | K_CAPS, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 22 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, K_PGUP, 23 | K_LEFT_CTRL, KT_FN, K_LEFT_SUPER, K_LEFT_ALT, K_SPACE, K_RIGHT_ALT, K_APP, K_HOME, K_END, K_PGDN 24 | ) 25 | }; 26 | // uncrustify:on 27 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_81/keymap/jeremy.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // Jeremy's layout 4 | 5 | #include 6 | 7 | // uncrustify:off 8 | uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN] = { 9 | LAYOUT( 10 | K_ESC, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, K_PRINT_SCREEN, K_INSERT, K_PAUSE, K_DEL, 11 | K_TICK, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 12 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 13 | KT_FN, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 14 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, K_UP, 15 | K_LEFT_CTRL, KT_FN, K_LEFT_ALT, K_LEFT_SUPER, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_LEFT, K_RIGHT, K_DOWN 16 | ), 17 | LAYOUT( 18 | K_ESC, K_TOUCHPAD, K_MIC_MUTE, K_MUTE, K_KBD_BKL, K_VOLUME_DOWN, K_VOLUME_UP, K_DISPLAY_MODE, K_BRIGHTNESS_DOWN, K_BRIGHTNESS_UP, K_CAMERA_TOGGLE, K_AIRPLANE_MODE, K_SUSPEND, K_PRINT_SCREEN, K_INSERT, K_PAUSE, K_DEL, 19 | K_PLAY_PAUSE, K_FAN_TOGGLE, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_DEL, 20 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_PGUP, K_HOME, K_PGDN, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 21 | KT_FN, K_A, K_S, K_D, K_F, K_G, K_LEFT, K_DOWN, K_UP, K_RIGHT, K_BKSP, K_DEL, K_ENTER, 22 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_END, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, K_PGUP, 23 | K_LEFT_CTRL, KT_FN, K_LEFT_ALT, K_LEFT_SUPER, K_ESC, K_RIGHT_ALT, K_APP, K_HOME, K_END, K_PGDN 24 | ) 25 | }; 26 | // uncrustify:on 27 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_83/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_83/keymap/default.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // Default layout 4 | 5 | #include 6 | 7 | // uncrustify:off 8 | uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN] = { 9 | LAYOUT( 10 | K_ESC, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, 11 | K_TICK, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 12 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 13 | K_CAPS, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 14 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, 15 | K_LEFT_CTRL, KT_FN, K_LEFT_SUPER, K_LEFT_ALT, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_PGUP, K_UP, K_PGDN, 16 | K_LEFT, K_DOWN, K_RIGHT 17 | ), 18 | LAYOUT( 19 | K_ESC, K_TOUCHPAD, K_DISPLAY_TOGGLE, K_MUTE, K_KBD_BKL, K_VOLUME_DOWN, K_VOLUME_UP, K_DISPLAY_MODE, K_BRIGHTNESS_DOWN, K_BRIGHTNESS_UP, K_CAMERA_TOGGLE, K_AIRPLANE_MODE, K_SUSPEND, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, 20 | K_PLAY_PAUSE, K_FAN_TOGGLE, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 21 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 22 | K_CAPS, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 23 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, 24 | K_LEFT_CTRL, KT_FN, K_LEFT_SUPER, K_LEFT_ALT, K_SPACE, K_RIGHT_ALT, K_APP, K_PGUP, K_UP, K_PGDN, 25 | K_LEFT, K_DOWN, K_RIGHT 26 | ) 27 | }; 28 | // uncrustify:on 29 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_83/keymap/ins-prtsc.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // PrtSc == Insert 4 | // Fn + PrtSc == Print Screen 5 | 6 | #include 7 | 8 | // uncrustify:off 9 | uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN] = { 10 | LAYOUT( 11 | K_ESC, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, K_HOME, K_END, K_INSERT, K_DEL, 12 | K_TICK, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 13 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 14 | K_CAPS, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 15 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, 16 | K_LEFT_CTRL, KT_FN, K_LEFT_SUPER, K_LEFT_ALT, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_PGUP, K_UP, K_PGDN, 17 | K_LEFT, K_DOWN, K_RIGHT 18 | ), 19 | LAYOUT( 20 | K_ESC, K_TOUCHPAD, K_DISPLAY_TOGGLE, K_MUTE, K_KBD_BKL, K_VOLUME_DOWN, K_VOLUME_UP, K_DISPLAY_MODE, K_BRIGHTNESS_DOWN, K_BRIGHTNESS_UP, K_CAMERA_TOGGLE, K_AIRPLANE_MODE, K_SUSPEND, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, 21 | K_PLAY_PAUSE, K_FAN_TOGGLE, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 22 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 23 | K_CAPS, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 24 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, 25 | K_LEFT_CTRL, KT_FN, K_LEFT_SUPER, K_LEFT_ALT, K_SPACE, K_RIGHT_ALT, K_APP, K_PGUP, K_UP, K_PGDN, 26 | K_LEFT, K_DOWN, K_RIGHT 27 | ) 28 | }; 29 | // uncrustify:on 30 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_83/keymap/jeremy.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | 3 | // Jeremy's layout 4 | 5 | #include 6 | 7 | // uncrustify:off 8 | uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN] = { 9 | LAYOUT( 10 | K_ESC, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, 11 | K_TICK, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, 12 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_U, K_I, K_O, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 13 | KT_FN, K_A, K_S, K_D, K_F, K_G, K_H, K_J, K_K, K_L, K_SEMICOLON, K_QUOTE, K_ENTER, 14 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_N, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, 15 | K_LEFT_CTRL, KT_FN, K_LEFT_ALT, K_LEFT_SUPER, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_PGUP, K_UP, K_PGDN, 16 | K_LEFT, K_DOWN, K_RIGHT 17 | ), 18 | LAYOUT( 19 | K_ESC, K_TOUCHPAD, K_DISPLAY_TOGGLE, K_MUTE, K_KBD_BKL, K_VOLUME_DOWN, K_VOLUME_UP, K_DISPLAY_MODE, K_BRIGHTNESS_DOWN, K_BRIGHTNESS_UP, K_CAMERA_TOGGLE, K_AIRPLANE_MODE, K_SUSPEND, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, 20 | K_PLAY_PAUSE, K_FAN_TOGGLE, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_DEL, 21 | K_TAB, K_Q, K_W, K_E, K_R, K_T, K_Y, K_PGUP, K_HOME, K_PGDN, K_P, K_BRACE_OPEN, K_BRACE_CLOSE, K_BACKSLASH, 22 | KT_FN, K_A, K_S, K_D, K_F, K_G, K_LEFT, K_DOWN, K_UP, K_RIGHT, K_BKSP, K_DEL, K_ENTER, 23 | K_LEFT_SHIFT, K_Z, K_X, K_C, K_V, K_B, K_END, K_M, K_COMMA, K_PERIOD, K_SLASH, K_RIGHT_SHIFT, 24 | K_LEFT_CTRL, KT_FN, K_LEFT_ALT, K_LEFT_SUPER, K_ESC, K_RIGHT_ALT, K_APP, K_PGUP, K_UP, K_PGDN, 25 | K_LEFT, K_DOWN, K_RIGHT 26 | ) 27 | }; 28 | // uncrustify:on 29 | -------------------------------------------------------------------------------- /src/keyboard/system76/14in_86/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /src/keyboard/system76/15in_102/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /src/keyboard/system76/15in_102_nkey/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /src/keyboard/system76/18H9LHA04/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /src/keyboard/system76/18H9LHA05/keyboard.mk: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-3.0-only 2 | 3 | KEYMAP?=default 4 | keyboard-y += keymap/$(KEYMAP).c 5 | 6 | INCLUDE += $(KEYBOARD_DIR)/keyboard.mk 7 | CFLAGS+=-I$(KEYBOARD_DIR)/include 8 | -------------------------------------------------------------------------------- /tool/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /tool/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "system76_ectool" 3 | version = "0.3.8" 4 | edition = "2024" 5 | description = "System76 EC tool" 6 | license = "MIT" 7 | authors = ["Jeremy Soller "] 8 | repository = "https://github.com/system76/ec" 9 | documentation = "https://docs.rs/system76_ectool" 10 | 11 | [lib] 12 | name = "ectool" 13 | 14 | [[bin]] 15 | name = "system76_ectool" 16 | required-features = ["std", "hidapi", "clap"] 17 | 18 | [dependencies] 19 | clap = { version = "4.5", features = ["derive"], optional = true } 20 | libc = { version = "0.2", optional = true } 21 | hidapi = { version = "2.6.3", default-features = false, features = ["linux-shared-hidraw"], optional = true } 22 | redox_hwio = { version = "0.1.6", default-features = false, optional = true } 23 | downcast-rs = { version = "2.0.1", default-features = false } 24 | 25 | [features] 26 | default = ["std", "hidapi", "clap"] 27 | std = ["libc", "downcast-rs/std"] 28 | 29 | [package.metadata.docs.rs] 30 | all-features = true 31 | -------------------------------------------------------------------------------- /tool/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 System76 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tool/src/access/lpc/mod.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | const SMFI_CMD_BASE: u16 = 0xE00; 4 | const SMFI_CMD_SIZE: usize = 0x100; 5 | 6 | const SMFI_DBG_BASE: u16 = 0xF00; 7 | #[cfg(all(feature = "std", target_os = "linux"))] 8 | const SMFI_DBG_SIZE: usize = 0x100; 9 | 10 | const SMFI_CMD_CMD: u8 = 0x00; 11 | const SMFI_CMD_RES: u8 = 0x01; 12 | const SMFI_CMD_DATA: u8 = 0x02; 13 | 14 | #[cfg(feature = "redox_hwio")] 15 | pub use self::direct::AccessLpcDirect; 16 | #[cfg(feature = "redox_hwio")] 17 | mod direct; 18 | 19 | #[cfg(all(feature = "std", target_os = "linux"))] 20 | pub use self::linux::AccessLpcLinux; 21 | #[cfg(all(feature = "std", target_os = "linux"))] 22 | mod linux; 23 | 24 | #[cfg(feature = "std")] 25 | mod sim; 26 | #[cfg(feature = "std")] 27 | pub use self::sim::AccessLpcSim; 28 | -------------------------------------------------------------------------------- /tool/src/access/mod.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | use crate::Error; 4 | use downcast_rs::Downcast; 5 | 6 | #[cfg(not(feature = "std"))] 7 | use alloc::boxed::Box; 8 | 9 | #[cfg(feature = "hidapi")] 10 | pub use self::hid::AccessHid; 11 | #[cfg(feature = "hidapi")] 12 | mod hid; 13 | 14 | #[cfg(any(feature = "redox_hwio", all(feature = "std", target_os = "linux")))] 15 | pub use self::lpc::*; 16 | #[cfg(any(feature = "redox_hwio", all(feature = "std", target_os = "linux")))] 17 | mod lpc; 18 | 19 | /// Access method for running an EC command 20 | pub trait Access: Downcast + Send + 'static { 21 | /// Sends a command using the access method. Only internal use is recommended 22 | unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result; 23 | 24 | /// The maximum size that can be provided for the data argument 25 | fn data_size(&self) -> usize; 26 | 27 | /// Read from the debug space 28 | //TODO: better public interface 29 | unsafe fn read_debug(&mut self, _addr: u8) -> Result { 30 | Err(Error::NotSupported) 31 | } 32 | } 33 | 34 | impl Access for Box { 35 | unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result { 36 | unsafe { (**self).command(cmd, data) } 37 | } 38 | 39 | fn data_size(&self) -> usize { 40 | (**self).data_size() 41 | } 42 | 43 | unsafe fn read_debug(&mut self, addr: u8) -> Result { 44 | unsafe { (**self).read_debug(addr) } 45 | } 46 | } 47 | 48 | downcast_rs::impl_downcast!(Access); 49 | -------------------------------------------------------------------------------- /tool/src/error.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | /// Errors returned by operations 4 | #[derive(Debug)] 5 | pub enum Error { 6 | /// Data length is too large 7 | DataLength(usize), 8 | /// Operation not supported 9 | NotSupported, 10 | /// A parameter was invalid 11 | Parameter, 12 | /// EC protocol returned an error result 13 | Protocol(u8), 14 | /// EC protocol signature did not match 15 | Signature((u8, u8)), 16 | /// Super I/O ID did not match 17 | SuperIoId(u16), 18 | /// Blocking operation timed out 19 | Timeout, 20 | /// Unexpected data from EC 21 | Verify, 22 | /// EC protocol version is unsupported 23 | Version(u8), 24 | /// Indicates that a blocking operation would block 25 | WouldBlock, 26 | /// Encountered a std::io::Error 27 | #[cfg(feature = "std")] 28 | Io(std::io::Error), 29 | /// Encountered a hidapi::Error 30 | #[cfg(feature = "hidapi")] 31 | Hid(hidapi::HidError), 32 | /// Writing to flash is disabled 33 | WriteLocked, 34 | } 35 | 36 | #[cfg(feature = "std")] 37 | impl From for Error { 38 | fn from(error: std::io::Error) -> Self { 39 | Self::Io(error) 40 | } 41 | } 42 | 43 | #[cfg(feature = "hidapi")] 44 | impl From for Error { 45 | fn from(error: hidapi::HidError) -> Self { 46 | Self::Hid(error) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tool/src/firmware.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | /// Parses firmware information from a firmware ROM 4 | pub struct Firmware<'a> { 5 | pub board: &'a [u8], 6 | pub version: &'a [u8], 7 | pub data: &'a [u8], 8 | } 9 | 10 | fn firmware_str<'a>(data: &'a [u8], key: &[u8]) -> Option<&'a [u8]> { 11 | let mut data_i = 0; 12 | 13 | //First, locate the key 14 | let mut key_i = 0; 15 | while data_i < data.len() && key_i < key.len() { 16 | if data[data_i] == key[key_i] { 17 | key_i += 1; 18 | } else { 19 | key_i = 0; 20 | } 21 | data_i += 1; 22 | } 23 | 24 | // Return None if key not found 25 | if key_i < key.len() { 26 | return None; 27 | } 28 | 29 | // Locate end of data 30 | let start = data_i; 31 | while data_i < data.len() { 32 | if data[data_i] == 0 { 33 | break; 34 | } 35 | data_i += 1; 36 | } 37 | 38 | Some(&data[start..data_i]) 39 | } 40 | 41 | impl<'a> Firmware<'a> { 42 | /// Parses firmware board and version, and then returns firmware object 43 | pub fn new(data: &'a [u8]) -> Option { 44 | let board = firmware_str(data, b"76EC_BOARD=")?; 45 | let version = firmware_str(data, b"76EC_VERSION=")?; 46 | Some(Self { 47 | data, 48 | board, 49 | version, 50 | }) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tool/src/super_io.rs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | use hwio::{Io, Pio}; 4 | 5 | /// Super I/O interface provided by LPC ECs 6 | pub struct SuperIo { 7 | addr: Pio, 8 | data: Pio, 9 | } 10 | 11 | impl SuperIo { 12 | /// Create a new SuperIo using direct hardware access. `base` identifies the address port. The 13 | /// data port will be `base + 1`. Unsafe due to no mutual exclusion 14 | pub unsafe fn new(base: u16) -> Self { 15 | Self { 16 | addr: Pio::new(base), 17 | data: Pio::new(base + 1), 18 | } 19 | } 20 | 21 | /// Read a Super I/O register 22 | pub unsafe fn read(&mut self, addr: u8) -> u8 { 23 | self.addr.write(addr); 24 | self.data.read() 25 | } 26 | 27 | /// Write a Super I/O register 28 | pub unsafe fn write(&mut self, addr: u8, data: u8) { 29 | self.addr.write(addr); 30 | self.data.write(data); 31 | } 32 | } 33 | --------------------------------------------------------------------------------