Compare commits
81 Commits
181d4c5d59
...
e41716575c
Author | SHA1 | Date | |
---|---|---|---|
|
e41716575c | ||
|
3d8204c3f4 | ||
|
2c6977bc6b | ||
|
ae63a9e3fb | ||
|
88ad52491a | ||
|
85cd3aa9ce | ||
|
710b4795fb | ||
|
2925376b6b | ||
|
51d35cb272 | ||
|
716efd4eb5 | ||
|
984428b6a8 | ||
|
0f7642defb | ||
|
9e7f1952fa | ||
|
face381354 | ||
|
a7bd81432e | ||
|
ffd0b7cbde | ||
|
e75a2f1e10 | ||
|
f8697a7ec4 | ||
|
ceba69d7fa | ||
|
e01536005a | ||
|
8f88c0c7aa | ||
|
80cfa91b9f | ||
|
2a44e03a40 | ||
|
70c8678a5f | ||
|
54d795480c | ||
|
426dc99f10 | ||
|
1e02be1cbe | ||
|
d3894392d5 | ||
|
6c3b34ee6e | ||
|
3d09a0b546 | ||
|
5b0766a209 | ||
|
d88a175e23 | ||
|
2c5c708569 | ||
|
a67b0c98b8 | ||
|
f79f4d1157 | ||
|
1e4667f1d3 | ||
|
fc3bad29a2 | ||
|
8382c81b9d | ||
|
09c5a3b5f0 | ||
|
b4768ed2dd | ||
|
88c77aa1d3 | ||
|
522284e5d5 | ||
|
e7ad77898b | ||
|
b744529960 | ||
|
748ec13132 | ||
|
38d4666a90 | ||
|
637036ec02 | ||
|
6a40a54932 | ||
|
91b8c48773 | ||
|
90af96faf5 | ||
|
17aae5af71 | ||
|
6aced2fd57 | ||
|
16e4f93f2c | ||
|
9fb08ffa46 | ||
|
d60a8e4c8e | ||
|
8c52c313e1 | ||
|
8af7fd5bad | ||
|
2174b4593a | ||
|
fff6208f98 | ||
|
ecac574671 | ||
|
acf67d4413 | ||
|
183778c32f | ||
|
82b9e19746 | ||
|
449bafd130 | ||
|
ef4eeae2df | ||
|
4b86176659 | ||
|
766fb738a0 | ||
|
0ccb8079ae | ||
|
0e1a748b16 | ||
|
11b1e724b5 | ||
|
47b070418a | ||
|
cbad8e09be | ||
|
713e1d9681 | ||
|
01be30f107 | ||
|
946415f3a7 | ||
|
a3fb9e1c77 | ||
|
166e03972b | ||
|
4fa389e1bd | ||
|
782f18a3f6 | ||
|
c461e20df3 | ||
|
bb1ce2273b |
141
.clang-format
141
.clang-format
@@ -1,141 +0,0 @@
|
||||
# https://releases.llvm.org/14.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||
# LLVM 14 used to support Ubuntu 22.04 LTS.
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveMacros: false
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: DontAlign
|
||||
AlignTrailingComments: false
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakAfterJavaFieldAnnotations: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakInheritanceList: AfterColon
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros:
|
||||
- 'foreach'
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(_test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseLabels: false
|
||||
IndentExternBlock: NoIndent
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: Wrapped
|
||||
JavaScriptQuotes: Double
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakAssignment: 1000
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatementsExceptForEachMacros
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- 'STRINGIZE'
|
||||
...
|
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -6,11 +6,11 @@ on:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
outputs:
|
||||
boards: ${{ steps.board-matrix.outputs.boards }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: ./scripts/deps.sh
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
run: ./scripts/lint/01-spdx-tags.sh
|
||||
|
||||
- name: Check formatting
|
||||
run: ./scripts/lint/02-clang-format.sh
|
||||
run: ./scripts/lint/02-uncrustify.sh
|
||||
|
||||
- name: Check shell scripts
|
||||
run: ./scripts/lint/03-shellcheck.sh
|
||||
@@ -35,9 +35,9 @@ jobs:
|
||||
- features:
|
||||
- features: --no-default-features --features="redox_hwio"
|
||||
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: ./scripts/deps.sh
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
run: cargo build ${{ matrix.features }} --release --manifest-path tool/Cargo.toml
|
||||
|
||||
ec:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
needs: lint
|
||||
strategy:
|
||||
matrix:
|
||||
@@ -54,10 +54,14 @@ jobs:
|
||||
# TODO: Conditionally build based on files changed?
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: ./scripts/deps.sh
|
||||
|
||||
- name: Build firmware
|
||||
run: make BOARD=${{ matrix.boards }} VERBOSE=1
|
||||
|
||||
- name: Show memory layout
|
||||
run: cat build/ec.mem
|
||||
continue-on-error: true
|
||||
|
156
.uncrustify.cfg
Normal file
156
.uncrustify.cfg
Normal file
@@ -0,0 +1,156 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
# SPDX-FileCopyrightText: NONE
|
||||
|
||||
# Uncrustify-0.78.1_f
|
||||
# https://github.com/uncrustify/uncrustify/blob/uncrustify-0.78.1/documentation/htdocs/config.txt
|
||||
|
||||
newlines = lf
|
||||
input_tab_size = 4
|
||||
output_tab_size = 4
|
||||
disable_processing_cmt = "uncrustify:off"
|
||||
enable_processing_cmt = "uncrustify:on"
|
||||
utf8_bom = remove
|
||||
sp_arith_additive = force
|
||||
sp_assign = force
|
||||
sp_enum_brace = force
|
||||
sp_enum_after_assign = force
|
||||
sp_pp_concat = ignore
|
||||
sp_bool = force
|
||||
sp_compare = force
|
||||
sp_inside_paren = remove
|
||||
sp_paren_paren = remove
|
||||
sp_cparen_oparen = remove
|
||||
sp_paren_brace = force
|
||||
sp_before_ptr_star = force
|
||||
sp_between_ptr_star = remove
|
||||
sp_between_ptr_ref = remove
|
||||
sp_after_ptr_star = remove
|
||||
sp_after_type = ignore # XXX: Fixes using macros in assignments
|
||||
sp_before_sparen = force
|
||||
sp_inside_sparen = remove
|
||||
sp_inside_for = remove
|
||||
sp_sparen_paren = remove
|
||||
sp_sparen_brace = force
|
||||
sp_do_brace_open = force
|
||||
sp_brace_close_while = force
|
||||
sp_before_semi_for = remove
|
||||
sp_before_semi_for_empty = remove
|
||||
sp_between_semi_for_empty = remove
|
||||
sp_after_semi_for_empty = remove
|
||||
sp_before_square = remove
|
||||
sp_before_squares = remove
|
||||
sp_inside_square = remove
|
||||
sp_after_comma = add
|
||||
sp_after_cast = remove
|
||||
sp_inside_paren_cast = remove
|
||||
sp_sizeof_paren = remove
|
||||
sp_inside_braces = add
|
||||
sp_inside_braces_empty = remove
|
||||
sp_func_proto_paren = remove
|
||||
sp_func_def_paren = remove
|
||||
sp_inside_fparens = remove
|
||||
sp_inside_fparen = remove
|
||||
sp_inside_tparen = remove
|
||||
sp_after_tparen_close = remove
|
||||
sp_fparen_brace = force
|
||||
sp_func_call_paren = remove
|
||||
sp_return_paren = force
|
||||
sp_attribute_paren = remove
|
||||
sp_defined_paren = remove
|
||||
sp_else_brace = force
|
||||
sp_brace_else = force
|
||||
sp_brace_typedef = force
|
||||
sp_before_nl_cont = force
|
||||
sp_cond_colon = force
|
||||
sp_cond_question = force
|
||||
sp_endif_cmt = force
|
||||
sp_before_tr_cmt = add
|
||||
sp_num_before_tr_cmt = 1
|
||||
indent_columns = 4
|
||||
indent_with_tabs = 0
|
||||
indent_macro_brace = false
|
||||
indent_ignore_label = true
|
||||
indent_paren_close = 2
|
||||
indent_align_assign = false
|
||||
indent_align_paren = false
|
||||
indent_compound_literal_return = false
|
||||
nl_collapse_empty_body = true
|
||||
nl_collapse_empty_body_functions = true
|
||||
nl_start_of_file = remove
|
||||
nl_end_of_file = force
|
||||
nl_end_of_file_min = 1
|
||||
nl_assign_brace = remove
|
||||
nl_fcall_brace = remove
|
||||
nl_enum_brace = remove
|
||||
nl_struct_brace = remove
|
||||
nl_union_brace = remove
|
||||
nl_if_brace = remove
|
||||
nl_brace_else = remove
|
||||
nl_else_brace = remove
|
||||
nl_else_if = remove
|
||||
nl_for_brace = remove
|
||||
nl_while_brace = remove
|
||||
nl_do_brace = remove
|
||||
nl_brace_while = remove
|
||||
nl_switch_brace = remove
|
||||
nl_after_case = true
|
||||
nl_enum_own_lines = force
|
||||
nl_func_type_name = remove
|
||||
nl_func_proto_type_name = remove
|
||||
nl_func_paren = remove
|
||||
nl_func_def_paren = remove
|
||||
nl_func_call_paren = remove
|
||||
nl_fdef_brace = remove
|
||||
nl_return_expr = remove
|
||||
nl_after_semicolon = true
|
||||
nl_brace_struct_var = remove
|
||||
nl_ds_struct_enum_close_brace = true
|
||||
nl_split_if_one_liner = true
|
||||
nl_split_for_one_liner = true
|
||||
nl_split_while_one_liner = true
|
||||
nl_max = 2
|
||||
eat_blanks_after_open_brace = true
|
||||
eat_blanks_before_close_brace = true
|
||||
code_width = 100
|
||||
ls_for_split_full = true
|
||||
ls_func_split_full = true
|
||||
align_on_tabstop = true
|
||||
align_var_def_star_style = 1
|
||||
align_var_def_amp_style = 1
|
||||
align_typedef_star_style = 1
|
||||
align_typedef_amp_style = 1
|
||||
align_func_proto_star_style = 1
|
||||
align_func_proto_amp_style = 1
|
||||
align_pp_define_together = true
|
||||
cmt_width = 100
|
||||
cmt_convert_tab_to_spaces = true
|
||||
cmt_trailing_single_line_c_to_cpp = true
|
||||
mod_paren_on_return = remove
|
||||
mod_remove_extra_semicolon = true
|
||||
mod_remove_duplicate_include = true
|
||||
mod_sort_incl_import_prioritize_filename = true
|
||||
mod_move_case_break = true
|
||||
mod_move_case_return = true
|
||||
mod_remove_empty_return = true
|
||||
mod_enum_last_comma = add
|
||||
pp_multiline_define_body_indent = 4
|
||||
pp_indent_case = false
|
||||
pp_indent_func_def = false
|
||||
pp_indent_extern = false
|
||||
|
||||
#set QUALIFIER __at # XXX: Allow it to be treated as a function call
|
||||
set QUALIFIER __code
|
||||
set QUALIFIER __critical
|
||||
set QUALIFIER __data
|
||||
set QUALIFIER __idata
|
||||
set QUALIFIER __pdata
|
||||
set QUALIFIER __reentrant
|
||||
set QUALIFIER __xdata
|
||||
|
||||
set TYPE __bit
|
||||
set TYPE __sbit
|
||||
set TYPE __sfr
|
||||
set TYPE __sfr16
|
||||
set TYPE __sfr32
|
||||
|
||||
set FUNC_CALL __asm__
|
14
Makefile
14
Makefile
@@ -10,21 +10,19 @@ ifneq ($(VERBOSE),1)
|
||||
MAKEFLAGS += -s
|
||||
endif
|
||||
|
||||
# Set build directory
|
||||
BUILD = build
|
||||
|
||||
# Parameter for current board
|
||||
ifeq ($(BOARD),)
|
||||
all:
|
||||
@echo -e "\x1B[31mBOARD must be specified\x1B[0m"
|
||||
@exit 1
|
||||
$(error BOARD must be specified)
|
||||
else
|
||||
# Calculate version
|
||||
DATE=$(shell git show --format="%cs" --no-patch --no-show-signature)
|
||||
REV=$(shell git describe --abbrev=7 --always --dirty)
|
||||
VERSION?=$(DATE)_$(REV)
|
||||
|
||||
# Set build directory
|
||||
obj = build
|
||||
BUILD = $(obj)/$(BOARD)/$(VERSION)
|
||||
|
||||
# Default target - build the board's EC firmware
|
||||
all: $(BUILD)/ec.rom
|
||||
$(info Built $(VERSION) for $(BOARD))
|
||||
@@ -72,11 +70,11 @@ docs:
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(obj)
|
||||
rm -rf $(BUILD)
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
./scripts/clang-format.sh apply
|
||||
uncrustify -c .uncrustify.cfg -q --no-backup $(shell git ls-files '*.c' '*.h')
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
|
@@ -1,11 +1,27 @@
|
||||
# Flashing firmware
|
||||
|
||||
## UEFI application
|
||||
|
||||
The `flash.sh` script from the top-level firmware-open project will use
|
||||
firmware-update, the UEFI application which is used for normal system updates.
|
||||
|
||||
This will flash both the SBIOS and the EC after building the firmware. To
|
||||
flash just the EC, delete the built `firmware.rom` before running `flash.sh`.
|
||||
|
||||
## Internal programmer
|
||||
|
||||
Use this method for flashing a system already running System76 EC.
|
||||
|
||||
This will trigger a watchdog reset causing the system to **immediately power
|
||||
off**. OS data may be lost or corrupted as a result. Save and close all
|
||||
This method will only work if the running firmware is not locked. Firmware is
|
||||
write locked if it was built with `CONFIG_SECURITY=y`. The firmware can be
|
||||
unlocked using ectool for a single boot:
|
||||
|
||||
```
|
||||
./scripts/ectool.sh security unlock
|
||||
```
|
||||
|
||||
This method will trigger a watchdog reset causing the system to **immediately
|
||||
power off**. OS data may be lost or corrupted as a result. Save and close all
|
||||
applications before flashing.
|
||||
|
||||
```
|
||||
|
@@ -104,10 +104,6 @@ make
|
||||
|
||||
See [flashing firmware](./flashing.md) for details.
|
||||
|
||||
```sh
|
||||
make flash_internal
|
||||
```
|
||||
|
||||
Do not use the keyboard or touchpad while it is flashing.
|
||||
|
||||
The system will power off as part of the flash process. Turn it back on after
|
||||
|
2
ecspy
2
ecspy
Submodule ecspy updated: 3ff52b2348...f0bf26d577
@@ -1,3 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2023-01-21"
|
||||
components = ["rust-src"]
|
||||
channel = "nightly-2024-05-11"
|
||||
components = ["clippy", "rustfmt"]
|
||||
profile = "minimal"
|
||||
|
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
readarray -t FILES < <(git ls-files '*.c' '*.h')
|
||||
|
||||
FMT_OPTS=(
|
||||
"-style=file"
|
||||
"--fallback-style=none"
|
||||
"--Werror"
|
||||
)
|
||||
|
||||
if [[ "$1" = "apply" ]]; then
|
||||
clang-format "${FMT_OPTS[@]}" -i "${FILES[@]}"
|
||||
else
|
||||
clang-format "${FMT_OPTS[@]}" --dry-run "${FILES[@]}"
|
||||
fi
|
@@ -19,7 +19,6 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then
|
||||
--yes \
|
||||
avr-libc \
|
||||
avrdude \
|
||||
clang-format \
|
||||
curl \
|
||||
gcc \
|
||||
gcc-avr \
|
||||
@@ -30,6 +29,7 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then
|
||||
pkgconf \
|
||||
sdcc \
|
||||
shellcheck \
|
||||
uncrustify \
|
||||
xxd
|
||||
elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
|
||||
sudo dnf install \
|
||||
@@ -37,13 +37,13 @@ elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
|
||||
avr-gcc \
|
||||
avr-libc \
|
||||
avrdude \
|
||||
clang-tools-extra \
|
||||
curl \
|
||||
gcc \
|
||||
make \
|
||||
sdcc \
|
||||
ShellCheck \
|
||||
systemd-devel \
|
||||
uncrustify \
|
||||
vim-common
|
||||
elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
|
||||
sudo pacman -S \
|
||||
@@ -51,7 +51,6 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
|
||||
avr-gcc \
|
||||
avr-libc \
|
||||
avrdude \
|
||||
clang \
|
||||
curl \
|
||||
gcc \
|
||||
make \
|
||||
@@ -59,6 +58,7 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
|
||||
sdcc \
|
||||
shellcheck \
|
||||
systemd-libs \
|
||||
uncrustify \
|
||||
vim
|
||||
else
|
||||
msg "Please add support for your distribution to:"
|
||||
@@ -73,10 +73,7 @@ msg "Installing git hooks"
|
||||
make git-config
|
||||
|
||||
RUSTUP_NEW_INSTALL=0
|
||||
if which rustup &> /dev/null; then
|
||||
msg "Updating rustup"
|
||||
rustup self update
|
||||
else
|
||||
if ! command -v rustup >/dev/null 2>&1; then
|
||||
RUSTUP_NEW_INSTALL=1
|
||||
msg "Installing Rust"
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
||||
|
@@ -2,5 +2,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
set -e
|
||||
cargo build --release --manifest-path tool/Cargo.toml
|
||||
cargo build --release --quiet --manifest-path tool/Cargo.toml
|
||||
sudo tool/target/release/system76_ectool "$@"
|
||||
|
@@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Check if any C files or headers need to be formatted.
|
||||
|
||||
LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
||||
. "$LINT_DIR/util.sh"
|
||||
|
||||
echo -n "Checking C style..."
|
||||
|
||||
if ! command -v clang-format > /dev/null; then
|
||||
skipped "clang-format not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
readarray -t FILES < <(git ls-files '*.c' '*.h')
|
||||
|
||||
FMT_OPTS=(
|
||||
"-style=file"
|
||||
"--fallback-style=none"
|
||||
"--dry-run"
|
||||
"--Werror"
|
||||
)
|
||||
|
||||
# NOTE: It is too slow to run clang-format on every file individually to report
|
||||
# which ones fail. Leave it up to the user to apply formatting via `make fmt`.
|
||||
|
||||
_output=$(clang-format "${FMT_OPTS[@]}" "${FILES[@]}" 2>&1)
|
||||
if [[ $_output != "" ]]; then
|
||||
failed
|
||||
exit 1
|
||||
fi
|
||||
|
||||
passed
|
36
scripts/lint/02-uncrustify.sh
Executable file
36
scripts/lint/02-uncrustify.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Check if any C files or headers need to be formatted.
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
||||
. "$LINT_DIR/util.sh"
|
||||
|
||||
echo -n "Checking C style..."
|
||||
|
||||
if ! command -v uncrustify > /dev/null; then
|
||||
skipped "uncrustify not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
needs_formatting=()
|
||||
|
||||
for file in $(git ls-files '*.c' '*.h'); do
|
||||
if ! uncrustify -c .uncrustify.cfg -q --check "$file" >/dev/null 2>&1; then
|
||||
needs_formatting+=("$file")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${#needs_formatting[@]}" != "0" ]]; then
|
||||
failed
|
||||
|
||||
for file in "${needs_formatting[@]}"; do
|
||||
echo "- $file"
|
||||
done
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
passed
|
@@ -5,7 +5,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint16_t systick_t;
|
||||
|
||||
void time_init(void);
|
||||
uint32_t time_get(void);
|
||||
systick_t time_get(void);
|
||||
|
||||
#endif // _ARCH_TIME_H
|
||||
|
@@ -3,23 +3,34 @@
|
||||
// Uses timer 0 to keep track of global time
|
||||
|
||||
#include <8051.h>
|
||||
|
||||
#include <arch/time.h>
|
||||
|
||||
static volatile uint32_t time_overflows = 0;
|
||||
#define OSC_DIVISOR 12
|
||||
#define TICK_INTERVAL_MS 1
|
||||
// Value to reload into the timer when the overflow interrupt is triggered.
|
||||
#define TIMER_RELOAD (0xFFFF - (TICK_INTERVAL_MS * (CONFIG_CLOCK_FREQ_KHZ / OSC_DIVISOR)))
|
||||
|
||||
static volatile systick_t time_overflows = 0;
|
||||
|
||||
void timer_0(void) __interrupt(1) {
|
||||
// Hardware automatically clears the the interrupt
|
||||
|
||||
// Stop timer
|
||||
TR0 = 0;
|
||||
|
||||
time_overflows++;
|
||||
|
||||
// Start timer
|
||||
TH0 = 0xFD;
|
||||
TL0 = 0x01;
|
||||
// Reload the values
|
||||
TH0 = TIMER_RELOAD >> 8;
|
||||
TL0 = TIMER_RELOAD & 0xFF;
|
||||
|
||||
// Restart the timer
|
||||
TR0 = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up Timer 0 as the system tick.
|
||||
*/
|
||||
void time_init(void) __critical {
|
||||
// Stop the timer
|
||||
TR0 = 0;
|
||||
@@ -27,17 +38,20 @@ void time_init(void) __critical {
|
||||
|
||||
time_overflows = 0;
|
||||
|
||||
// Enable timer interrupts
|
||||
// Enable the interrupt
|
||||
ET0 = 1;
|
||||
|
||||
// Start timer in mode 1
|
||||
// (65536 - 64769) / (9.2 MHz / 12) = ~1 ms interval
|
||||
// Set the timer to mode 1 (16-bit timer)
|
||||
TMOD = (TMOD & 0xF0) | 0x01;
|
||||
TH0 = 0xFD;
|
||||
TL0 = 0x01;
|
||||
|
||||
// Set the initial values
|
||||
TH0 = TIMER_RELOAD >> 8;
|
||||
TL0 = TIMER_RELOAD & 0xFF;
|
||||
|
||||
// Start the timer
|
||||
TR0 = 1;
|
||||
}
|
||||
|
||||
uint32_t time_get(void) __critical {
|
||||
systick_t time_get(void) __critical {
|
||||
return time_overflows;
|
||||
}
|
||||
|
@@ -31,25 +31,25 @@ sim: $(BUILD)/ec.rom
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(BUILD)/ec.rom: $(BUILD)/ec.ihx
|
||||
@echo " OBJCOPY $(subst $(obj)/,,$@)"
|
||||
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
objcopy -I ihex -O binary --gap-fill=0xFF --pad-to=$(CONFIG_EC_FLASH_SIZE) $< $@
|
||||
|
||||
# Link object files into Intel Hex file
|
||||
$(BUILD)/ec.ihx: $(OBJ)
|
||||
@echo " LINK $(subst $(obj)/,,$@)"
|
||||
@echo " LINK $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
||||
# Compile ASM files into object files
|
||||
$(ASM_OBJ): $(BUILD)/%.rel: src/%.asm
|
||||
@echo " AS $(subst $(obj)/,,$@)"
|
||||
@echo " AS $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(AS) $(ASFLAGS) $@ $<
|
||||
|
||||
# Compile C files into object files
|
||||
$(C_OBJ): $(BUILD)/%.rel: src/%.c $(INCLUDE)
|
||||
@echo " CC $(subst $(obj)/,,$@)"
|
||||
@echo " CC $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <arch/gpio.h>
|
||||
|
||||
bool gpio_get_dir(struct Gpio *gpio) {
|
||||
bool gpio_get_dir(const struct Gpio *const gpio) {
|
||||
if (*gpio->ddr & gpio->value) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -10,7 +10,7 @@ bool gpio_get_dir(struct Gpio *gpio) {
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_set_dir(struct Gpio *gpio, bool value) {
|
||||
void gpio_set_dir(struct Gpio *const gpio, bool value) {
|
||||
if (value) {
|
||||
*gpio->ddr |= gpio->value;
|
||||
} else {
|
||||
@@ -18,7 +18,7 @@ void gpio_set_dir(struct Gpio *gpio, bool value) {
|
||||
}
|
||||
}
|
||||
|
||||
bool gpio_get(struct Gpio *gpio) {
|
||||
bool gpio_get(const struct Gpio *const gpio) {
|
||||
if (*gpio->pin & gpio->value) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -26,7 +26,7 @@ bool gpio_get(struct Gpio *gpio) {
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_set(struct Gpio *gpio, bool value) {
|
||||
void gpio_set(struct Gpio *const gpio, bool value) {
|
||||
if (value) {
|
||||
*gpio->port |= gpio->value;
|
||||
} else {
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
#define TIMEOUT (F_CPU / 1000)
|
||||
|
||||
int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) {
|
||||
int16_t i2c_start(struct I2C *const i2c, uint8_t addr, bool read) {
|
||||
uint32_t count;
|
||||
|
||||
// reset TWI control register
|
||||
@@ -47,12 +47,12 @@ int16_t i2c_start(struct I2C *i2c, uint8_t addr, bool read) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_stop(struct I2C *i2c) {
|
||||
void i2c_stop(struct I2C *const i2c) {
|
||||
// transmit STOP condition
|
||||
TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO);
|
||||
}
|
||||
|
||||
int16_t i2c_write(struct I2C *i2c, uint8_t *data, uint16_t length) {
|
||||
int16_t i2c_write(struct I2C *const i2c, const uint8_t *const data, uint16_t length) {
|
||||
uint16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
// load data into data register
|
||||
@@ -74,7 +74,7 @@ int16_t i2c_write(struct I2C *i2c, uint8_t *data, uint16_t length) {
|
||||
return i;
|
||||
}
|
||||
|
||||
int16_t i2c_read(struct I2C *i2c, uint8_t *data, uint16_t length) {
|
||||
int16_t i2c_read(struct I2C *const i2c, uint8_t *const data, uint16_t length) {
|
||||
uint16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if ((i + 1) < length) {
|
||||
|
@@ -11,9 +11,11 @@
|
||||
#include <arch/i2c_slave.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// uncrustify:off
|
||||
static void (*volatile i2c_slave_new_cb)() = NULL;
|
||||
static void (*volatile i2c_slave_recv_cb)(uint8_t) = NULL;
|
||||
static uint8_t (*volatile i2c_slave_send_cb)() = NULL;
|
||||
// uncrustify:on
|
||||
|
||||
void i2c_slave_init(
|
||||
uint8_t address,
|
||||
@@ -40,7 +42,7 @@ void i2c_slave_init(
|
||||
sei();
|
||||
}
|
||||
|
||||
void i2c_slave_stop() {
|
||||
void i2c_slave_stop(void) {
|
||||
// clear interrupts
|
||||
cli();
|
||||
|
||||
|
@@ -16,18 +16,16 @@ struct Gpio {
|
||||
uint8_t value;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
#define GPIO(BLOCK, NUMBER) { \
|
||||
.pin = &PIN ## BLOCK, \
|
||||
.ddr = &DDR ## BLOCK, \
|
||||
.port = &PORT ## BLOCK, \
|
||||
.value = BIT(NUMBER), \
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
bool gpio_get(struct Gpio *gpio);
|
||||
void gpio_set(struct Gpio *gpio, bool value);
|
||||
bool gpio_get_dir(struct Gpio *gpio);
|
||||
void gpio_set_dir(struct Gpio *gpio, bool value);
|
||||
bool gpio_get(const struct Gpio *const gpio);
|
||||
void gpio_set(struct Gpio *const gpio, bool value);
|
||||
bool gpio_get_dir(const struct Gpio *const gpio);
|
||||
void gpio_set_dir(struct Gpio *const gpio, bool value);
|
||||
|
||||
#endif // _ARCH_GPIO_H
|
||||
|
@@ -9,6 +9,6 @@ void i2c_slave_init(
|
||||
void (*recv_cb)(uint8_t),
|
||||
uint8_t (*send_cb)()
|
||||
);
|
||||
void i2c_slave_stop();
|
||||
void i2c_slave_stop(void);
|
||||
|
||||
#endif // _ARCH_I2C_SLAVE_H
|
||||
|
@@ -19,16 +19,16 @@ struct Uart {
|
||||
uint8_t c_init;
|
||||
};
|
||||
|
||||
void uart_init(struct Uart *uart, uint32_t baud);
|
||||
void uart_init(struct Uart *const uart, uint32_t baud);
|
||||
|
||||
int16_t uart_count();
|
||||
int16_t uart_count(void);
|
||||
struct Uart *uart_new(int16_t num);
|
||||
|
||||
uint8_t uart_can_read(struct Uart *uart);
|
||||
uint8_t uart_can_write(struct Uart *uart);
|
||||
uint8_t uart_can_read(struct Uart *const uart);
|
||||
uint8_t uart_can_write(struct Uart *const uart);
|
||||
|
||||
uint8_t uart_read(struct Uart *uart);
|
||||
void uart_write(struct Uart *uart, uint8_t data);
|
||||
uint8_t uart_read(struct Uart *const uart);
|
||||
void uart_write(struct Uart *const uart, uint8_t data);
|
||||
|
||||
extern struct Uart *uart_stdio;
|
||||
void uart_stdio_init(int16_t num, uint32_t baud);
|
||||
|
@@ -5,7 +5,10 @@ CFLAGS += -MMD -Os -fstack-usage -Wall -Werror \
|
||||
-Wl,--gc-sections -Wl,-u,vfprintf -lprintf_flt
|
||||
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
|
||||
ifneq ($(findstring 12.,$(shell avr-gcc --version 2>/dev/null)),)
|
||||
_gcc_version = $(shell avr-gcc --version 2>/dev/null)
|
||||
ifneq ($(findstring 12.,$(_gcc_version)),)
|
||||
CFLAGS += --param=min-pagesize=0
|
||||
else ifneq ($(findstring 13.,$(_gcc_version)),)
|
||||
CFLAGS += --param=min-pagesize=0
|
||||
endif
|
||||
|
||||
@@ -19,25 +22,25 @@ sim: $(BUILD)/ec.elf
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(BUILD)/ec.rom: $(BUILD)/ec.ihx
|
||||
@echo " OBJCOPY $(subst $(obj)/,,$@)"
|
||||
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(OBJCOPY) -I ihex -O binary --gap-fill 0xFF $< $@
|
||||
|
||||
# Convert from ELF file to Intel Hex file
|
||||
$(BUILD)/ec.ihx: $(BUILD)/ec.elf
|
||||
@echo " OBJCOPY $(subst $(obj)/,,$@)"
|
||||
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(OBJCOPY) -j .text -j .data -O ihex $< $@
|
||||
|
||||
# Link object files into ELF file
|
||||
$(BUILD)/ec.elf: $(OBJ)
|
||||
@echo " LINK $(subst $(obj)/,,$@)"
|
||||
@echo " LINK $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(CC) -o $@ $^
|
||||
|
||||
# Compile C files into object files
|
||||
$(BUILD)/%.o: src/%.c $(INCLUDE)
|
||||
@echo " CC $(subst $(obj)/,,$@)"
|
||||
@echo " CC $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include <arch/uart.h>
|
||||
#include <board/cpu.h>
|
||||
|
||||
// clang-format off
|
||||
#define UART(N) \
|
||||
{ \
|
||||
&UCSR ## N ## A, \
|
||||
@@ -23,26 +22,25 @@
|
||||
}
|
||||
|
||||
#if defined(__AVR_ATmega328P__)
|
||||
static struct Uart UARTS[] = {
|
||||
UART(0)
|
||||
};
|
||||
static struct Uart UARTS[] = {
|
||||
UART(0)
|
||||
};
|
||||
#elif defined(__AVR_ATmega32U4__)
|
||||
static struct Uart UARTS[] = {
|
||||
UART(1)
|
||||
};
|
||||
static struct Uart UARTS[] = {
|
||||
UART(1)
|
||||
};
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
static struct Uart UARTS[] = {
|
||||
UART(0),
|
||||
UART(1),
|
||||
UART(2),
|
||||
UART(3)
|
||||
};
|
||||
static struct Uart UARTS[] = {
|
||||
UART(0),
|
||||
UART(1),
|
||||
UART(2),
|
||||
UART(3)
|
||||
};
|
||||
#else
|
||||
#error "Could not find UART definitions"
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
int16_t uart_count() {
|
||||
int16_t uart_count(void) {
|
||||
return sizeof(UARTS) / sizeof(struct Uart);
|
||||
}
|
||||
|
||||
@@ -54,7 +52,7 @@ struct Uart *uart_new(int16_t num) {
|
||||
}
|
||||
}
|
||||
|
||||
void uart_init(struct Uart *uart, uint32_t baud) {
|
||||
void uart_init(struct Uart *const uart, uint32_t baud) {
|
||||
uint32_t baud_prescale = (F_CPU / (baud * 16UL)) - 1;
|
||||
*(uart->baud_h) = (uint8_t)(baud_prescale >> 8);
|
||||
*(uart->baud_l) = (uint8_t)(baud_prescale);
|
||||
@@ -63,20 +61,20 @@ void uart_init(struct Uart *uart, uint32_t baud) {
|
||||
*(uart->c) = uart->c_init;
|
||||
}
|
||||
|
||||
uint8_t uart_can_read(struct Uart *uart) {
|
||||
uint8_t uart_can_read(struct Uart *const uart) {
|
||||
return (*(uart->a)) & uart->a_read;
|
||||
}
|
||||
|
||||
uint8_t uart_read(struct Uart *uart) {
|
||||
uint8_t uart_read(struct Uart *const uart) {
|
||||
while (!uart_can_read(uart)) {}
|
||||
return *(uart->data);
|
||||
}
|
||||
|
||||
uint8_t uart_can_write(struct Uart *uart) {
|
||||
uint8_t uart_can_write(struct Uart *const uart) {
|
||||
return (*(uart->a)) & uart->a_write;
|
||||
}
|
||||
|
||||
void uart_write(struct Uart *uart, uint8_t data) {
|
||||
void uart_write(struct Uart *const uart, uint8_t data) {
|
||||
while (!uart_can_write(uart)) {}
|
||||
*(uart->data) = data;
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <common/i2c.h>
|
||||
|
||||
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data) {
|
||||
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data) {
|
||||
return i2c_get(NULL, address, command, (uint8_t *)data, 2);
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@
|
||||
#include <arch/gpio.h>
|
||||
#include <arch/uart.h>
|
||||
|
||||
// clang-format off
|
||||
// Mapping of 24-pin ribbon cable to parallel pins. See schematic
|
||||
#define PINS \
|
||||
/* Data (KSO0 - KSO7) - bi-directional */ \
|
||||
@@ -114,10 +113,8 @@ static struct Parallel PORT = {
|
||||
.state = PARALLEL_STATE_UNKNOWN,
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
// Set port to all high-impedance inputs
|
||||
void parallel_hiz(struct Parallel *port) {
|
||||
void parallel_hiz(struct Parallel *const port) {
|
||||
#define PIN(N, P) \
|
||||
gpio_set_dir(port->N, false); \
|
||||
gpio_set(port->N, false);
|
||||
@@ -126,7 +123,7 @@ void parallel_hiz(struct Parallel *port) {
|
||||
}
|
||||
|
||||
// Place all data lines in high or low impendance state
|
||||
void parallel_data_dir(struct Parallel *port, bool dir) {
|
||||
void parallel_data_dir(struct Parallel *const port, bool dir) {
|
||||
#define DATA_BIT(B) gpio_set_dir(port->d##B, dir);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
@@ -134,17 +131,19 @@ void parallel_data_dir(struct Parallel *port, bool dir) {
|
||||
#define parallel_data_forward(P) parallel_data_dir(P, true)
|
||||
#define parallel_data_reverse(P) parallel_data_dir(P, false)
|
||||
|
||||
void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
|
||||
void parallel_data_set_high(struct Parallel *const port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, true);
|
||||
if (!(byte & (1 << B))) { \
|
||||
gpio_set(port->d##B, true); \
|
||||
}
|
||||
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
|
||||
// Set port to initial state required before being able to perform cycles
|
||||
void parallel_reset(struct Parallel *port, bool host) {
|
||||
void parallel_reset(struct Parallel *const port, bool host) {
|
||||
parallel_hiz(port);
|
||||
|
||||
// nRESET: output on host, input on peripherals
|
||||
@@ -183,7 +182,7 @@ void parallel_reset(struct Parallel *port, bool host) {
|
||||
}
|
||||
}
|
||||
|
||||
void parallel_state(struct Parallel *port, enum ParallelState state) {
|
||||
void parallel_state(struct Parallel *const port, enum ParallelState state) {
|
||||
if (port->state != state) {
|
||||
switch (state) {
|
||||
case PARALLEL_STATE_UNKNOWN:
|
||||
@@ -202,30 +201,34 @@ void parallel_state(struct Parallel *port, enum ParallelState state) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t parallel_read_data(struct Parallel *port) {
|
||||
uint8_t parallel_read_data(struct Parallel *const port) {
|
||||
uint8_t byte = 0;
|
||||
#define DATA_BIT(B) \
|
||||
if (gpio_get(port->d##B)) \
|
||||
byte |= (1 << B);
|
||||
if (gpio_get(port->d##B)) { \
|
||||
byte |= (1 << B); \
|
||||
}
|
||||
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
return byte;
|
||||
}
|
||||
|
||||
void parallel_write_data(struct Parallel *port, uint8_t byte) {
|
||||
void parallel_write_data(struct Parallel *const port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, false);
|
||||
if (!(byte & (1 << B))) { \
|
||||
gpio_set(port->d##B, false); \
|
||||
}
|
||||
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
|
||||
//TODO: timeout
|
||||
int16_t parallel_transaction(
|
||||
struct Parallel *port,
|
||||
uint8_t *data,
|
||||
struct Parallel *const port,
|
||||
uint8_t *const data,
|
||||
int16_t length,
|
||||
bool read,
|
||||
bool addr
|
||||
@@ -299,7 +302,12 @@ int16_t parallel_transaction(
|
||||
|
||||
// host write -> peripheral read
|
||||
// host read -> peripheral write
|
||||
bool parallel_peripheral_cycle(struct Parallel *port, uint8_t *data, bool *read, bool *addr) {
|
||||
bool parallel_peripheral_cycle(
|
||||
struct Parallel *const port,
|
||||
uint8_t *const data,
|
||||
bool *const read,
|
||||
bool *const addr
|
||||
) {
|
||||
if (!gpio_get(port->reset_n)) {
|
||||
// XXX: Give host some time to get ready
|
||||
_delay_ms(1);
|
||||
@@ -351,7 +359,12 @@ static uint8_t ZERO = 0x00;
|
||||
static uint8_t SPI_ENABLE = 0xFE;
|
||||
static uint8_t SPI_DATA = 0xFD;
|
||||
|
||||
int16_t parallel_ecms_read(struct Parallel *port, uint16_t addr, uint8_t *data, int16_t length) {
|
||||
int16_t parallel_ecms_read(
|
||||
struct Parallel *const port,
|
||||
uint16_t addr,
|
||||
uint8_t *const data,
|
||||
int16_t length
|
||||
) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_ECMSADDR1, 1);
|
||||
@@ -378,7 +391,7 @@ int16_t parallel_ecms_read(struct Parallel *port, uint16_t addr, uint8_t *data,
|
||||
}
|
||||
|
||||
// Disable chip
|
||||
int16_t parallel_spi_reset(struct Parallel *port) {
|
||||
int16_t parallel_spi_reset(struct Parallel *const port) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
@@ -397,7 +410,12 @@ int16_t parallel_spi_reset(struct Parallel *port) {
|
||||
}
|
||||
|
||||
// Enable chip and read or write data
|
||||
int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t length, bool read) {
|
||||
int16_t parallel_spi_transaction(
|
||||
struct Parallel *const port,
|
||||
uint8_t *const data,
|
||||
int16_t length,
|
||||
bool read
|
||||
) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
@@ -420,8 +438,8 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t l
|
||||
|
||||
// "Hardware" accelerated SPI programming, requires ECINDARs to be set
|
||||
int16_t parallel_spi_program(
|
||||
struct Parallel *port,
|
||||
uint8_t *data,
|
||||
struct Parallel *const port,
|
||||
const uint8_t *const data,
|
||||
int16_t length,
|
||||
bool initialized
|
||||
) {
|
||||
@@ -483,7 +501,7 @@ int16_t parallel_spi_program(
|
||||
return i;
|
||||
}
|
||||
|
||||
int16_t serial_transaction(uint8_t *data, int16_t length, bool read) {
|
||||
int16_t serial_transaction(uint8_t *const data, int16_t length, bool read) {
|
||||
int16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (read) {
|
||||
|
@@ -11,8 +11,6 @@
|
||||
#include <arch/gpio.h>
|
||||
#include <arch/uart.h>
|
||||
|
||||
// clang-format off
|
||||
|
||||
// Mapping of 24-pin ribbon cable to parallel pins. See schematic
|
||||
#define PINS \
|
||||
/* Data (KSO0 - KSO7) - bi-directional */ \
|
||||
@@ -67,8 +65,6 @@ static struct Gpio GPIOS[13] = {
|
||||
GPIO(C, 0),
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
// Parallel struct definition
|
||||
// See http://efplus.com/techref/io/parallel/1284/eppmode.htm
|
||||
struct Parallel {
|
||||
@@ -85,16 +81,17 @@ static struct Parallel PORT = {
|
||||
};
|
||||
|
||||
// Set port to all high-impedance inputs
|
||||
void parallel_hiz(struct Parallel *port) {
|
||||
void parallel_hiz(struct Parallel *const port) {
|
||||
#define PIN(N, P) \
|
||||
gpio_set_dir(port->N, false); \
|
||||
gpio_set(port->N, false);
|
||||
|
||||
PINS
|
||||
#undef PIN
|
||||
}
|
||||
|
||||
// Place all data lines in high or low impendance state
|
||||
void parallel_data_dir(struct Parallel *port, bool dir) {
|
||||
void parallel_data_dir(struct Parallel *const port, bool dir) {
|
||||
#define DATA_BIT(B) gpio_set_dir(port->d##B, dir);
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
@@ -102,17 +99,19 @@ void parallel_data_dir(struct Parallel *port, bool dir) {
|
||||
#define parallel_data_forward(P) parallel_data_dir(P, true)
|
||||
#define parallel_data_reverse(P) parallel_data_dir(P, false)
|
||||
|
||||
void parallel_data_set_high(struct Parallel *port, uint8_t byte) {
|
||||
void parallel_data_set_high(struct Parallel *const port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, true);
|
||||
if (!(byte & (1 << B))) { \
|
||||
gpio_set(port->d##B, true); \
|
||||
}
|
||||
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
|
||||
// Set port to initial state required before being able to perform cycles
|
||||
void parallel_reset(struct Parallel *port, bool host) {
|
||||
void parallel_reset(struct Parallel *const port, bool host) {
|
||||
parallel_hiz(port);
|
||||
|
||||
// nRESET: output on host, input on peripherals
|
||||
@@ -151,29 +150,33 @@ void parallel_reset(struct Parallel *port, bool host) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t parallel_read_data(struct Parallel *port) {
|
||||
uint8_t parallel_read_data(struct Parallel *const port) {
|
||||
uint8_t byte = 0;
|
||||
#define DATA_BIT(B) \
|
||||
if (gpio_get(port->d##B)) \
|
||||
byte |= (1 << B);
|
||||
if (gpio_get(port->d##B)) { \
|
||||
byte |= (1 << B); \
|
||||
}
|
||||
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
return byte;
|
||||
}
|
||||
|
||||
void parallel_write_data(struct Parallel *port, uint8_t byte) {
|
||||
void parallel_write_data(struct Parallel *const port, uint8_t byte) {
|
||||
// By convention all lines are high, so only set the ones needed
|
||||
#define DATA_BIT(B) \
|
||||
if (!(byte & (1 << B))) \
|
||||
gpio_set(port->d##B, false);
|
||||
if (!(byte & (1 << B))) { \
|
||||
gpio_set(port->d##B, false); \
|
||||
}
|
||||
|
||||
DATA_BITS
|
||||
#undef DATA_BIT
|
||||
}
|
||||
|
||||
//TODO: timeout
|
||||
int16_t parallel_transaction(
|
||||
struct Parallel *port,
|
||||
uint8_t *data,
|
||||
struct Parallel *const port,
|
||||
uint8_t *const data,
|
||||
int16_t length,
|
||||
bool read,
|
||||
bool addr
|
||||
@@ -248,7 +251,12 @@ int16_t parallel_transaction(
|
||||
|
||||
// host write -> peripheral read
|
||||
// host read -> peripheral write
|
||||
bool parallel_peripheral_cycle(struct Parallel *port, uint8_t *data, bool *read, bool *addr) {
|
||||
bool parallel_peripheral_cycle(
|
||||
struct Parallel *const port,
|
||||
uint8_t *const data,
|
||||
bool *const read,
|
||||
bool *const addr
|
||||
) {
|
||||
if (!gpio_get(port->reset_n)) {
|
||||
// XXX: Give host some time to get ready
|
||||
_delay_ms(1);
|
||||
@@ -293,7 +301,7 @@ static uint8_t SPI_ENABLE = 0xFE;
|
||||
static uint8_t SPI_DATA = 0xFD;
|
||||
|
||||
// Disable chip
|
||||
int16_t parallel_spi_reset(struct Parallel *port) {
|
||||
int16_t parallel_spi_reset(struct Parallel *const port) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
@@ -312,7 +320,12 @@ int16_t parallel_spi_reset(struct Parallel *port) {
|
||||
}
|
||||
|
||||
// Enable chip and read or write data
|
||||
int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t length, bool read) {
|
||||
int16_t parallel_spi_transaction(
|
||||
struct Parallel *const port,
|
||||
uint8_t *const data,
|
||||
int16_t length,
|
||||
bool read
|
||||
) {
|
||||
int16_t res;
|
||||
|
||||
res = parallel_set_address(port, &ADDRESS_INDAR1, 1);
|
||||
@@ -335,8 +348,8 @@ int16_t parallel_spi_transaction(struct Parallel *port, uint8_t *data, int16_t l
|
||||
|
||||
// "Hardware" accelerated SPI programming, requires ECINDARs to be set
|
||||
int16_t parallel_spi_program(
|
||||
struct Parallel *port,
|
||||
uint8_t *data,
|
||||
struct Parallel *const port,
|
||||
const uint8_t *const data,
|
||||
int16_t length,
|
||||
bool initialized
|
||||
) {
|
||||
@@ -398,7 +411,7 @@ int16_t parallel_spi_program(
|
||||
return i;
|
||||
}
|
||||
|
||||
int16_t serial_transaction(uint8_t *data, int16_t length, bool read) {
|
||||
int16_t serial_transaction(uint8_t *const data, int16_t length, bool read) {
|
||||
int16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (read) {
|
||||
|
@@ -5,16 +5,18 @@ board-y += gpio.c
|
||||
|
||||
EC=ite
|
||||
CONFIG_EC_ITE_IT8587E=y
|
||||
CONFIG_EC_FLASH_SIZE_128K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
|
||||
# Include keyboard
|
||||
KEYBOARD=15in_102
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED=rgb_pwm
|
||||
|
||||
# Set discrete GPU I2C bus
|
||||
CFLAGS+=-DI2C_DGPU=I2C_1
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS+=-DI2C_SMBUS=I2C_0
|
||||
|
||||
@@ -34,23 +36,27 @@ CFLAGS+=\
|
||||
-DPOWER_LIMIT_AC=180 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Custom fan curve
|
||||
CFLAGS+=-DBOARD_FAN_POINTS="\
|
||||
# Enable dGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Enable DGPU support
|
||||
CFLAGS+=-DHAVE_DGPU=1
|
||||
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 6);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 7);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@@ -42,9 +42,9 @@ struct Gpio __code USB_PWR_EN_N = GPIO(F, 7);
|
||||
struct Gpio __code VA_EC_EN = GPIO(J, 0); // renamed to SLP_SUS_EC#
|
||||
struct Gpio __code WLAN_EN = GPIO(J, 2);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(B, 0);
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init() {
|
||||
void gpio_init(void) {
|
||||
// Enable LPC reset on GPD2
|
||||
GCR = 0x04;
|
||||
|
||||
@@ -192,8 +192,6 @@ void gpio_init() {
|
||||
GPCRH5 = GPIO_OUT | GPIO_UP;
|
||||
// SUSB#_PCH
|
||||
GPCRH6 = GPIO_IN;
|
||||
// TODO
|
||||
GPCRH7 = GPIO_IN;
|
||||
// BAT_DET
|
||||
GPCRI0 = GPIO_ALT;
|
||||
// BAT_VOLT
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
// clang-format off
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code ALL_SYS_PWRGD;
|
||||
@@ -53,6 +52,5 @@ extern struct Gpio __code VA_EC_EN;
|
||||
extern struct Gpio __code WLAN_EN;
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
#define HAVE_XLP_OUT 0
|
||||
// clang-format on
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
||||
|
@@ -5,16 +5,18 @@ board-y += gpio.c
|
||||
|
||||
EC=ite
|
||||
CONFIG_EC_ITE_IT5570E=y
|
||||
CONFIG_EC_FLASH_SIZE_128K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
|
||||
# Include keyboard
|
||||
KEYBOARD=15in_102
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED=rgb_pwm
|
||||
|
||||
# Set discrete GPU I2C bus
|
||||
CFLAGS+=-DI2C_DGPU=I2C_1
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS+=-DI2C_SMBUS=I2C_4
|
||||
|
||||
@@ -34,23 +36,27 @@ CFLAGS+=\
|
||||
-DPOWER_LIMIT_AC=180 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Custom fan curve
|
||||
CFLAGS+=-DBOARD_FAN_POINTS="\
|
||||
# Enable dGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Enable DGPU support
|
||||
CFLAGS+=-DHAVE_DGPU=1
|
||||
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@@ -40,9 +40,9 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(J, 7);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init() {
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
@@ -105,8 +105,6 @@ void gpio_init() {
|
||||
GPCRB5 = GPIO_OUT | GPIO_UP;
|
||||
// SUSBC_EN
|
||||
GPCRB6 = GPIO_OUT | GPIO_UP;
|
||||
//
|
||||
GPCRB7 = GPIO_IN;
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
// SMC_VGA_THERM
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
// clang-format off
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code ALL_SYS_PWRGD;
|
||||
@@ -50,6 +49,5 @@ extern struct Gpio __code VA_EC_EN;
|
||||
extern struct Gpio __code WLAN_EN;
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
extern struct Gpio __code XLP_OUT;
|
||||
// clang-format on
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
||||
|
@@ -5,8 +5,10 @@ board-y += gpio.c
|
||||
|
||||
EC=ite
|
||||
CONFIG_EC_ITE_IT5570E=y
|
||||
CONFIG_EC_FLASH_SIZE_128K = y
|
||||
|
||||
# Enable eSPI
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
CONFIG_BUS_ESPI=y
|
||||
|
||||
# Enable firmware security
|
||||
@@ -16,11 +18,9 @@ CONFIG_SECURITY=y
|
||||
KEYBOARD=15in_102
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED=rgb_pwm
|
||||
|
||||
# Set discrete GPU I2C bus
|
||||
CFLAGS+=-DI2C_DGPU=I2C_1
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS+=-DI2C_SMBUS=I2C_4
|
||||
|
||||
@@ -43,27 +43,31 @@ CFLAGS+=\
|
||||
-DPOWER_LIMIT_AC=280 \
|
||||
-DPOWER_LIMIT_DC=55
|
||||
|
||||
# Custom fan curve
|
||||
CFLAGS+=-DBOARD_HEATUP=5
|
||||
CFLAGS+=-DBOARD_COOLDOWN=20
|
||||
CFLAGS+=-DBOARD_FAN_POINTS="\
|
||||
# Enable dGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Enable DGPU support
|
||||
CFLAGS+=-DHAVE_DGPU=1
|
||||
CFLAGS+=-DBOARD_DGPU_HEATUP=5
|
||||
CFLAGS+=-DBOARD_DGPU_COOLDOWN=20
|
||||
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@@ -32,9 +32,9 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(D, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init() {
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
@@ -118,8 +118,6 @@ void gpio_init() {
|
||||
GPCRB5 = GPIO_OUT;
|
||||
// SUSBC_EC#
|
||||
GPCRB6 = GPIO_OUT | GPIO_UP;
|
||||
// Not connected
|
||||
GPCRB7 = GPIO_IN;
|
||||
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
|
27
src/board/system76/addw4/board.c
Normal file
27
src/board/system76/addw4/board.c
Normal file
@@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/battery.h>
|
||||
#include <board/board.h>
|
||||
#include <board/espi.h>
|
||||
#include <board/gctrl.h>
|
||||
#include <board/gpio.h>
|
||||
#include <common/debug.h>
|
||||
#include <ec/ec.h>
|
||||
|
||||
void board_init(void) {
|
||||
espi_init();
|
||||
|
||||
// Make sure charger is in off state, also enables PSYS
|
||||
battery_charger_disable();
|
||||
|
||||
// Allow backlight to be turned on
|
||||
gpio_set(&BKL_EN, true);
|
||||
// Enable camera
|
||||
gpio_set(&CCD_EN, true);
|
||||
}
|
||||
|
||||
void board_event(void) {
|
||||
espi_event();
|
||||
|
||||
ec_read_post_codes();
|
||||
}
|
74
src/board/system76/addw4/board.mk
Normal file
74
src/board/system76/addw4/board.mk
Normal file
@@ -0,0 +1,74 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
board-y += board.c
|
||||
board-y += gpio.c
|
||||
|
||||
EC = ite
|
||||
CONFIG_EC_ITE_IT5570E = y
|
||||
CONFIG_EC_FLASH_SIZE_256K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
CONFIG_BUS_ESPI = y
|
||||
CONFIG_PECI_OVER_ESPI = y
|
||||
|
||||
# Enable firmware security
|
||||
CONFIG_SECURITY = y
|
||||
|
||||
# Set keyboard configs
|
||||
KEYBOARD = 18H9LHA04
|
||||
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED = rgb_pwm
|
||||
|
||||
# Set touchpad PS2 bus
|
||||
CFLAGS += -DPS2_TOUCHPAD=PS2_3
|
||||
|
||||
# Set smart charger parameters
|
||||
CHARGER = oz26786
|
||||
CFLAGS += -DI2C_SMBUS=I2C_4
|
||||
CFLAGS += \
|
||||
-DCHARGER_ADAPTER_RSENSE=5 \
|
||||
-DCHARGER_BATTERY_RSENSE=10 \
|
||||
-DCHARGER_CHARGE_CURRENT=3072 \
|
||||
-DCHARGER_CHARGE_VOLTAGE=17400 \
|
||||
-DCHARGER_INPUT_CURRENT=11500
|
||||
|
||||
# Set CPU power limits in watts
|
||||
CFLAGS += \
|
||||
-DPOWER_LIMIT_AC=230 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Enable DGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 28), \
|
||||
FAN_POINT(65, 28), \
|
||||
FAN_POINT(70, 40), \
|
||||
FAN_POINT(75, 60), \
|
||||
FAN_POINT(80, 75), \
|
||||
FAN_POINT(85, 90), \
|
||||
FAN_POINT(90, 100), \
|
||||
"
|
||||
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 28), \
|
||||
FAN_POINT(65, 28), \
|
||||
FAN_POINT(70, 40), \
|
||||
FAN_POINT(75, 60), \
|
||||
FAN_POINT(80, 75), \
|
||||
FAN_POINT(85, 90), \
|
||||
FAN_POINT(90, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
include src/board/system76/common/common.mk
|
259
src/board/system76/addw4/gpio.c
Normal file
259
src/board/system76/addw4/gpio.c
Normal file
@@ -0,0 +1,259 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
struct Gpio __code BKL_EN = GPIO(C, 7);
|
||||
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2); // renamed to ESPI_RESET_N
|
||||
struct Gpio __code CCD_EN = GPIO(D, 1);
|
||||
struct Gpio __code DD_ON = GPIO(E, 4);
|
||||
struct Gpio __code DGPU_PWR_EN = GPIO(H, 6);
|
||||
struct Gpio __code EC_EN = GPIO(B, 6); // renamed to SUSBC_EN#
|
||||
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
|
||||
struct Gpio __code GC6_FB_EN = GPIO(B, 5);
|
||||
struct Gpio __code LAN_WAKEUP_N = GPIO(B, 2);
|
||||
struct Gpio __code LED_ACIN = GPIO(H, 2);
|
||||
struct Gpio __code LED_BAT_CHG = GPIO(H, 5);
|
||||
struct Gpio __code LED_BAT_FULL = GPIO(J, 0);
|
||||
struct Gpio __code LED_PWR = GPIO(D, 0);
|
||||
struct Gpio __code LID_SW_N = GPIO(B, 1);
|
||||
struct Gpio __code ME_WE = GPIO(I, 2);
|
||||
struct Gpio __code PCH_DPWROK_EC = GPIO(F, 3);
|
||||
struct Gpio __code PM_PWROK = GPIO(C, 6);
|
||||
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
|
||||
struct Gpio __code PWR_SW_N = GPIO(B, 3);
|
||||
struct Gpio __code RGBKB_DET_N = GPIO(E, 2);
|
||||
struct Gpio __code SLP_SUS_N = GPIO(H, 7);
|
||||
struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
//struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(H, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
GCR8 = BIT(4);
|
||||
|
||||
// Enable LPC reset on GPD2
|
||||
GCR = 0x04;
|
||||
// Disable UARTs
|
||||
GCR6 = 0;
|
||||
// Enable SMBus channel 4
|
||||
GCR15 = BIT(4);
|
||||
// Set GPD2 to 1.8V
|
||||
GCR19 = BIT(0);
|
||||
// Set GPF2 and GPF3 to 3.3V
|
||||
GCR20 = 0;
|
||||
|
||||
// Set GPM6 power domain to VCC
|
||||
GCR23 = BIT(0);
|
||||
|
||||
// Set GPIO data
|
||||
// DDS_EC_PWM
|
||||
GPDRA = BIT(3);
|
||||
// XLP_OUT, PWR_SW#
|
||||
GPDRB = BIT(4) | BIT(3);
|
||||
GPDRC = 0;
|
||||
// VGA_HEATSINK_SW
|
||||
GPDRD = BIT(3);
|
||||
// USB_PWR_EN#
|
||||
GPDRE = BIT(3);
|
||||
GPDRF = 0;
|
||||
// H_PROCHOT_EC, BL_PWM_EN_EC
|
||||
GPDRG = BIT(6) | BIT(0);
|
||||
GPDRH = 0;
|
||||
GPDRI = 0;
|
||||
// PLVDD_RST_EC, KBC_MUTE#
|
||||
GPDRJ = BIT(7) | BIT(1);
|
||||
|
||||
// Set GPIO control
|
||||
|
||||
// EC_PWM_LEDKB_P
|
||||
GPCRA0 = GPIO_ALT;
|
||||
// KBC_BEEP
|
||||
GPCRA1 = GPIO_ALT;
|
||||
// CPU_FAN_PWM
|
||||
GPCRA2 = GPIO_ALT;
|
||||
// DDS_EC_PWM
|
||||
GPCRA3 = GPIO_IN;
|
||||
// VGA_FAN_PWM
|
||||
GPCRA4 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_R
|
||||
GPCRA5 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_G
|
||||
GPCRA6 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_B
|
||||
GPCRA7 = GPIO_ALT;
|
||||
|
||||
// AC_IN#
|
||||
GPCRB0 = GPIO_IN | GPIO_UP;
|
||||
// LID_SW#
|
||||
GPCRB1 = GPIO_IN | GPIO_UP;
|
||||
// EC_LAN_WAKEUP#
|
||||
GPCRB2 = GPIO_IN;
|
||||
// PWR_SW#
|
||||
GPCRB3 = GPIO_IN;
|
||||
// XLP_OUT
|
||||
GPCRB4 = GPIO_OUT;
|
||||
// GC6_FB_EN_PCH
|
||||
GPCRB5 = GPIO_IN;
|
||||
// SUSBC_EC#
|
||||
GPCRB6 = GPIO_OUT | GPIO_UP;
|
||||
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
// SMC_VGA_THERM
|
||||
GPCRC1 = GPIO_ALT | GPIO_UP;
|
||||
// SMD_VGA_THERM
|
||||
GPCRC2 = GPIO_ALT | GPIO_UP;
|
||||
// KB-SO16
|
||||
GPCRC3 = GPIO_ALT | GPIO_UP;
|
||||
// CNVI_DET#
|
||||
GPCRC4 = GPIO_IN | GPIO_UP;
|
||||
// KB-SO17
|
||||
GPCRC5 = GPIO_ALT | GPIO_UP;
|
||||
// PM_PWROK
|
||||
GPCRC6 = GPIO_OUT;
|
||||
// BKL_EN
|
||||
GPCRC7 = GPIO_OUT | GPIO_UP;
|
||||
|
||||
// LED_PWR
|
||||
GPCRD0 = GPIO_OUT | GPIO_UP;
|
||||
// CCD_EN
|
||||
GPCRD1 = GPIO_OUT;
|
||||
// ESPI_RESET#
|
||||
GPCRD2 = GPIO_ALT;
|
||||
// VGA_HEATSINK_SW
|
||||
GPCRD3 = GPIO_OUT;
|
||||
// 7411_SINK_CTRL
|
||||
GPCRD4 = GPIO_IN;
|
||||
// PWR_BTN#
|
||||
GPCRD5 = GPIO_OUT | GPIO_UP;
|
||||
// CPU_FANSEN
|
||||
GPCRD6 = GPIO_ALT;
|
||||
// VGA_HEATSINK_FANSEN
|
||||
GPCRD7 = GPIO_ALT;
|
||||
|
||||
// SMC_BAT
|
||||
GPCRE0 = GPIO_ALT | GPIO_UP;
|
||||
// AC_PRESENT
|
||||
GPCRE1 = GPIO_OUT | GPIO_UP;
|
||||
// RGBKB-DET#
|
||||
GPCRE2 = GPIO_IN | GPIO_UP;
|
||||
// USB_PWR_EN# (XXX: Active high, despite pin name)
|
||||
GPCRE3 = GPIO_OUT;
|
||||
// DD_ON
|
||||
GPCRE4 = GPIO_OUT | GPIO_DOWN;
|
||||
// EC_RSMRST#
|
||||
GPCRE5 = GPIO_OUT;
|
||||
// JACK_IN#_EC
|
||||
GPCRE6 = GPIO_IN;
|
||||
// SMD_BAT
|
||||
GPCRE7 = GPIO_ALT | GPIO_UP;
|
||||
|
||||
// 80CLK
|
||||
GPCRF0 = GPIO_IN;
|
||||
// USB_CHARGE_EN
|
||||
GPCRF1 = GPIO_OUT | GPIO_UP;
|
||||
// 3IN1
|
||||
GPCRF2 = GPIO_IN | GPIO_UP;
|
||||
// PCH_DPWROK_EC
|
||||
GPCRF3 = GPIO_OUT;
|
||||
// TP_CLK
|
||||
GPCRF4 = GPIO_ALT | GPIO_UP;
|
||||
// TP_DATA
|
||||
GPCRF5 = GPIO_ALT | GPIO_UP;
|
||||
// EC_SMD_EN#
|
||||
GPCRF6 = GPIO_IN;
|
||||
// MUX_CTRL_BIOS
|
||||
GPCRF7 = GPIO_OUT;
|
||||
|
||||
// BL_PWM_EN_EC
|
||||
GPCRG0 = GPIO_OUT;
|
||||
// EC_WLAN_EN (NC)
|
||||
GPCRG1 = GPIO_IN;
|
||||
// AUTO_LOAD_PWR
|
||||
GPCRG2 = GPIO_IN;
|
||||
// ALSPI_CE#
|
||||
GPCRG3 = GPIO_ALT;
|
||||
// ALSPI_MSI
|
||||
GPCRG4 = GPIO_ALT;
|
||||
// ALSPI_MSO
|
||||
GPCRG5 = GPIO_ALT;
|
||||
// H_PROCHOT_EC
|
||||
GPCRG6 = GPIO_OUT | GPIO_UP;
|
||||
// ALSPI_SCLK
|
||||
GPCRG7 = GPIO_ALT;
|
||||
|
||||
// PM_SLP_S0_CS_N
|
||||
GPCRH0 = GPIO_IN;
|
||||
// EC_TEST_R_2
|
||||
GPCRH1 = GPIO_IN;
|
||||
// LED_ACIN
|
||||
GPCRH2 = GPIO_OUT | GPIO_UP;
|
||||
// WLAN_PWR_EN
|
||||
GPCRH3 = GPIO_OUT;
|
||||
// OVERT#_EC
|
||||
GPCRH4 = GPIO_IN | GPIO_UP;
|
||||
// LED_BAT_CHG
|
||||
GPCRH5 = GPIO_OUT | GPIO_UP;
|
||||
// DGPU_PWR_EN
|
||||
GPCRH6 = GPIO_IN;
|
||||
// SLP_SUS#
|
||||
GPCRH7 = GPIO_IN;
|
||||
|
||||
// BAT_DET
|
||||
GPCRI0 = GPIO_ALT;
|
||||
// BAT_VOLT
|
||||
GPCRI1 = GPIO_ALT;
|
||||
// ME_WE
|
||||
GPCRI2 = GPIO_OUT;
|
||||
// THERM_VOLT_CPU
|
||||
GPCRI3 = GPIO_ALT;
|
||||
// TOTAL_CUR
|
||||
GPCRI4 = GPIO_ALT;
|
||||
// THERM_VOLT_GPU
|
||||
GPCRI5 = GPIO_ALT;
|
||||
// THERM_VOLT_HEATSINK
|
||||
GPCRI6 = GPIO_ALT;
|
||||
// MODEL_ID
|
||||
GPCRI7 = GPIO_IN;
|
||||
|
||||
// LED_BAT_FULL
|
||||
GPCRJ0 = GPIO_OUT | GPIO_UP;
|
||||
// KBC_MUTE# / USB charger detection
|
||||
GPCRJ1 = GPIO_IN;
|
||||
// PCH_FAN
|
||||
GPCRJ2 = GPIO_ALT;
|
||||
// HEATSINK_FANSEN_R
|
||||
GPCRJ3 = GPIO_IN;
|
||||
// VA_EC_EN
|
||||
GPCRJ4 = GPIO_OUT;
|
||||
// VBATT_BOOST#
|
||||
GPCRJ5 = GPIO_IN;
|
||||
// EC_GPIO
|
||||
GPCRJ6 = GPIO_IN;
|
||||
// PLVDD_RST_EC
|
||||
GPCRJ7 = GPIO_OUT;
|
||||
|
||||
// ESPI_IO0_EC
|
||||
GPCRM0 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO1_EC
|
||||
GPCRM1 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO2_EC
|
||||
GPCRM2 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO3_EC
|
||||
GPCRM3 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_CLK_EC
|
||||
GPCRM4 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_CS_EC#
|
||||
GPCRM5 = GPIO_ALT;
|
||||
// ESPI_ALRT0#
|
||||
GPCRM6 = GPIO_IN | GPIO_UP | GPIO_DOWN;
|
||||
}
|
43
src/board/system76/addw4/include/board/gpio.h
Normal file
43
src/board/system76/addw4/include/board/gpio.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#ifndef _BOARD_GPIO_H
|
||||
#define _BOARD_GPIO_H
|
||||
|
||||
#include <ec/gpio.h>
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code ALL_SYS_PWRGD;
|
||||
extern struct Gpio __code BKL_EN;
|
||||
#define HAVE_BT_EN 0
|
||||
extern struct Gpio __code BUF_PLT_RST_N;
|
||||
extern struct Gpio __code CCD_EN;
|
||||
extern struct Gpio __code DD_ON;
|
||||
extern struct Gpio __code DGPU_PWR_EN;
|
||||
extern struct Gpio __code EC_EN;
|
||||
extern struct Gpio __code EC_RSMRST_N;
|
||||
extern struct Gpio __code GC6_FB_EN;
|
||||
extern struct Gpio __code LAN_WAKEUP_N;
|
||||
extern struct Gpio __code LED_ACIN;
|
||||
#define HAVE_LED_AIRPLANE_N 0
|
||||
extern struct Gpio __code LED_BAT_CHG;
|
||||
extern struct Gpio __code LED_BAT_FULL;
|
||||
extern struct Gpio __code LED_PWR;
|
||||
extern struct Gpio __code LID_SW_N;
|
||||
extern struct Gpio __code ME_WE;
|
||||
extern struct Gpio __code PCH_DPWROK_EC;
|
||||
#define HAVE_PCH_PWROK_EC 0
|
||||
extern struct Gpio __code PM_PWROK;
|
||||
extern struct Gpio __code PWR_BTN_N;
|
||||
extern struct Gpio __code PWR_SW_N;
|
||||
extern struct Gpio __code RGBKB_DET_N;
|
||||
extern struct Gpio __code SLP_SUS_N;
|
||||
#define HAVE_SUS_PWR_ACK 0
|
||||
extern struct Gpio __code VA_EC_EN;
|
||||
#define HAVE_WLAN_EN 0
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
extern struct Gpio __code XLP_OUT;
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
@@ -5,16 +5,18 @@ board-y += gpio.c
|
||||
|
||||
EC=ite
|
||||
CONFIG_EC_ITE_IT5570E=y
|
||||
CONFIG_EC_FLASH_SIZE_128K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
|
||||
# Include keyboard
|
||||
KEYBOARD=15in_102_nkey
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED=bonw14
|
||||
|
||||
# Set discrete GPU I2C bus
|
||||
CFLAGS+=-DI2C_DGPU=I2C_1
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS+=-DI2C_SMBUS=I2C_4
|
||||
|
||||
@@ -34,23 +36,27 @@ CFLAGS+=\
|
||||
-DPOWER_LIMIT_AC=180 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Custom fan curve
|
||||
CFLAGS+=-DBOARD_FAN_POINTS="\
|
||||
# Enable dGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Enable DGPU support
|
||||
CFLAGS+=-DHAVE_DGPU=1
|
||||
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code AC_V1_EC = GPIO(J, 7);
|
||||
@@ -39,9 +39,9 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4); // renamed to SLP_SUS#
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4); // renamed to EN_3V
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init() {
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
@@ -97,8 +97,6 @@ void gpio_init() {
|
||||
GPCRB5 = GPIO_OUT | GPIO_UP;
|
||||
// EC_EN
|
||||
GPCRB6 = GPIO_OUT | GPIO_UP;
|
||||
// NO PIN
|
||||
GPCRB7 = GPIO_IN;
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
// KBC_SMBus_CLK1
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
// clang-format off
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code AC_V1_EC;
|
||||
@@ -48,6 +47,5 @@ extern struct Gpio __code VA_EC_EN;
|
||||
extern struct Gpio __code WLAN_EN;
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
extern struct Gpio __code XLP_OUT;
|
||||
// clang-format on
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
||||
|
81
src/board/system76/bonw15-b/board.mk
Normal file
81
src/board/system76/bonw15-b/board.mk
Normal file
@@ -0,0 +1,81 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
board-y += ../bonw15/board.c
|
||||
board-y += ../bonw15/gpio.c
|
||||
|
||||
# FIXME: Handle this better
|
||||
CFLAGS += -I$(BOARD_DIR)/../bonw15/include
|
||||
|
||||
EC = ite
|
||||
CONFIG_EC_ITE_IT5570E = y
|
||||
CONFIG_EC_FLASH_SIZE_256K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
CONFIG_BUS_ESPI = y
|
||||
|
||||
# Enable firmware security
|
||||
CONFIG_SECURITY = y
|
||||
|
||||
# Include keyboard
|
||||
KEYBOARD = 15in_102
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED = bonw14
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS += -DI2C_SMBUS=I2C_4
|
||||
|
||||
# Set touchpad PS2 bus
|
||||
CFLAGS += -DPS2_TOUCHPAD=PS2_3
|
||||
|
||||
# Set smart charger parameters
|
||||
# XXX: PRS1 and PRS2 are in parallel for adapter Rsense?
|
||||
CHARGER = oz26786
|
||||
CFLAGS += \
|
||||
-DCHARGER_ADAPTER_RSENSE=5 \
|
||||
-DCHARGER_BATTERY_RSENSE=5 \
|
||||
-DCHARGER_CHARGE_CURRENT=3072 \
|
||||
-DCHARGER_CHARGE_VOLTAGE=17400 \
|
||||
-DCHARGER_INPUT_CURRENT=16920
|
||||
|
||||
# Set USB-PD parameters
|
||||
CONFIG_HAVE_USBPD = y
|
||||
CONFIG_USBPD_TPS65987 = y
|
||||
CFLAGS += -DI2C_USBPD=I2C_1
|
||||
|
||||
# Set CPU power limits in watts
|
||||
CFLAGS += \
|
||||
-DPOWER_LIMIT_AC=330 \
|
||||
-DPOWER_LIMIT_DC=55
|
||||
|
||||
# Enable dGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
include src/board/system76/common/common.mk
|
@@ -5,9 +5,11 @@ board-y += gpio.c
|
||||
|
||||
EC=ite
|
||||
CONFIG_EC_ITE_IT5570E=y
|
||||
CONFIG_EC_FLASH_SIZE_128K = y
|
||||
|
||||
# Enable eSPI
|
||||
CONFIG_BUS_ESPI=y
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
CONFIG_BUS_ESPI = y
|
||||
|
||||
# Enable firmware security
|
||||
CONFIG_SECURITY=y
|
||||
@@ -16,19 +18,15 @@ CONFIG_SECURITY=y
|
||||
KEYBOARD=15in_102
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED=bonw14
|
||||
|
||||
# Set discrete GPU I2C bus
|
||||
CFLAGS+=-DI2C_DGPU=I2C_1
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS+=-DI2C_SMBUS=I2C_4
|
||||
|
||||
# Set touchpad PS2 bus
|
||||
CFLAGS+=-DPS2_TOUCHPAD=PS2_3
|
||||
|
||||
# Set USB-PD I2C bus
|
||||
CFLAGS+=-DI2C_USBPD=I2C_1
|
||||
|
||||
# Set smart charger parameters
|
||||
# XXX: PRS1 and PRS2 are in parallel for adapter Rsense?
|
||||
@@ -41,34 +39,40 @@ CFLAGS+=\
|
||||
-DCHARGER_INPUT_CURRENT=16920
|
||||
|
||||
# Set USB-PD parameters
|
||||
USBPD=tps65987
|
||||
CONFIG_HAVE_USBPD = y
|
||||
CONFIG_USBPD_TPS65987 = y
|
||||
CFLAGS += -DI2C_USBPD=I2C_1
|
||||
|
||||
# Set CPU power limits in watts
|
||||
CFLAGS+=\
|
||||
-DPOWER_LIMIT_AC=330 \
|
||||
-DPOWER_LIMIT_DC=55
|
||||
|
||||
# Custom fan curve
|
||||
CFLAGS+=-DBOARD_HEATUP=5
|
||||
CFLAGS+=-DBOARD_COOLDOWN=20
|
||||
CFLAGS+=-DBOARD_FAN_POINTS="\
|
||||
# Enable dGPU support
|
||||
CONFIG_HAVE_DGPU = y
|
||||
CFLAGS += -DI2C_DGPU=I2C_1
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN1_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Enable DGPU support
|
||||
CFLAGS+=-DHAVE_DGPU=1
|
||||
CFLAGS+=-DBOARD_DGPU_HEATUP=5
|
||||
CFLAGS+=-DBOARD_DGPU_COOLDOWN=20
|
||||
CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\
|
||||
CFLAGS += -DFAN2_PWM=DCR4
|
||||
CFLAGS += -DBOARD_FAN2_HEATUP=5
|
||||
CFLAGS += -DBOARD_FAN2_COOLDOWN=20
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(60, 40), \
|
||||
FAN_POINT(65, 60), \
|
||||
FAN_POINT(70, 75), \
|
||||
FAN_POINT(75, 90), \
|
||||
FAN_POINT(80, 100) \
|
||||
FAN_POINT(80, 100), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 1);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@@ -34,9 +34,9 @@ struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(G, 1);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(B, 5);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init() {
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
@@ -121,8 +121,6 @@ void gpio_init() {
|
||||
GPCRB5 = GPIO_OUT;
|
||||
// SUSBC_EC#
|
||||
GPCRB6 = GPIO_OUT | GPIO_UP;
|
||||
// Not connected
|
||||
GPCRB7 = GPIO_IN;
|
||||
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
// clang-format off
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code ALL_SYS_PWRGD;
|
||||
@@ -43,6 +42,5 @@ extern struct Gpio __code VA_EC_EN;
|
||||
extern struct Gpio __code WLAN_EN;
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
extern struct Gpio __code XLP_OUT;
|
||||
// clang-format on
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
||||
|
@@ -3,13 +3,17 @@
|
||||
#include <board/acpi.h>
|
||||
#include <board/battery.h>
|
||||
#include <board/dgpu.h>
|
||||
#include <board/fan.h>
|
||||
#include <board/gpio.h>
|
||||
#include <board/kbled.h>
|
||||
#include <board/lid.h>
|
||||
#include <board/peci.h>
|
||||
#include <common/macro.h>
|
||||
#include <board/pwm.h>
|
||||
#include <common/debug.h>
|
||||
#include <ec/pwm.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
#include <board/peci.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LED_AIRPLANE_N
|
||||
#define HAVE_LED_AIRPLANE_N 1
|
||||
@@ -25,6 +29,7 @@ static uint8_t fbuf[4] = { 0, 0, 0, 0 };
|
||||
|
||||
void fcommand(void) {
|
||||
switch (fcmd) {
|
||||
#if CONFIG_HAVE_KBLED
|
||||
// Keyboard backlight
|
||||
case 0xCA:
|
||||
switch (fdat) {
|
||||
@@ -42,22 +47,22 @@ void fcommand(void) {
|
||||
break;
|
||||
// Set color
|
||||
case 3:
|
||||
// clang-format off
|
||||
kbled_set_color(
|
||||
((uint32_t)fbuf[0]) |
|
||||
((uint32_t)fbuf[1] << 16) |
|
||||
((uint32_t)fbuf[2] << 8)
|
||||
);
|
||||
// clang-format on
|
||||
break;
|
||||
// Get color
|
||||
case 4:
|
||||
// uncrustify:off
|
||||
{
|
||||
uint32_t color = kbled_get_color();
|
||||
fbuf[0] = color & 0xFF;
|
||||
fbuf[1] = (color >> 16) & 0xFF;
|
||||
fbuf[2] = (color >> 8) & 0xFF;
|
||||
}
|
||||
// uncrustify:on
|
||||
break;
|
||||
// DUPLICATE: Set brightness
|
||||
case 6:
|
||||
@@ -65,6 +70,7 @@ void fcommand(void) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif // CONFIG_HAVE_KBLED
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +87,7 @@ void acpi_reset(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
uint8_t acpi_read(uint8_t addr) {
|
||||
uint8_t data = 0;
|
||||
|
||||
@@ -110,7 +116,9 @@ uint8_t acpi_read(uint8_t addr) {
|
||||
}
|
||||
break;
|
||||
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
ACPI_8(0x07, peci_temp);
|
||||
#endif
|
||||
|
||||
// Handle AC adapter and battery present
|
||||
case 0x10:
|
||||
@@ -159,15 +167,15 @@ uint8_t acpi_read(uint8_t addr) {
|
||||
|
||||
ACPI_8(0xCC, sci_extra);
|
||||
|
||||
ACPI_8(0xCE, DCR2);
|
||||
ACPI_8(0xD0, F1TLRR);
|
||||
ACPI_8(0xD1, F1TMRR);
|
||||
#if HAVE_DGPU
|
||||
ACPI_8(0xCE, fan1_pwm_actual);
|
||||
ACPI_16(0xD0, fan1_rpm);
|
||||
#if CONFIG_HAVE_DGPU
|
||||
ACPI_8(0xCD, dgpu_temp);
|
||||
ACPI_8(0xCF, DCR4);
|
||||
ACPI_8(0xD2, F2TLRR);
|
||||
ACPI_8(0xD3, F2TMRR);
|
||||
#endif // HAVE_DGPU
|
||||
#endif // CONFIG_HAVE_DGPU
|
||||
#ifdef FAN2_PWM
|
||||
ACPI_8(0xCF, fan2_pwm_actual);
|
||||
ACPI_16(0xD2, fan2_rpm);
|
||||
#endif // FAN2_PWM
|
||||
|
||||
#if HAVE_LED_AIRPLANE_N
|
||||
// Airplane mode LED
|
||||
@@ -179,20 +187,20 @@ uint8_t acpi_read(uint8_t addr) {
|
||||
#endif // HAVE_LED_AIRPLANE_N
|
||||
|
||||
// Set size of flash (from old firmware)
|
||||
ACPI_8 (0xE5, 0x80);
|
||||
ACPI_8(0xE5, 0x80);
|
||||
|
||||
ACPI_8 (0xF8, fcmd);
|
||||
ACPI_8 (0xF9, fdat);
|
||||
ACPI_8 (0xFA, fbuf[0]);
|
||||
ACPI_8 (0xFB, fbuf[1]);
|
||||
ACPI_8 (0xFC, fbuf[2]);
|
||||
ACPI_8 (0xFD, fbuf[3]);
|
||||
ACPI_8(0xF8, fcmd);
|
||||
ACPI_8(0xF9, fdat);
|
||||
ACPI_8(0xFA, fbuf[0]);
|
||||
ACPI_8(0xFB, fbuf[1]);
|
||||
ACPI_8(0xFC, fbuf[2]);
|
||||
ACPI_8(0xFD, fbuf[3]);
|
||||
}
|
||||
|
||||
TRACE("acpi_read %02X = %02X\n", addr, data);
|
||||
return data;
|
||||
}
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void acpi_write(uint8_t addr, uint8_t data) {
|
||||
TRACE("acpi_write %02X = %02X\n", addr, data);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include <common/macro.h>
|
||||
#include <common/debug.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
|
||||
// Registers
|
||||
#define REG_CHARGE_CURRENT 0x14
|
||||
@@ -86,7 +86,7 @@
|
||||
#error Invalid adapter:battery RSENSE ratio
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
// XXX: Assumption: ac_last is initialized high.
|
||||
static bool charger_enabled = false;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include <common/debug.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
|
||||
// Registers
|
||||
#define REG_CHARGE_CURRENT 0x14
|
||||
@@ -71,7 +71,8 @@
|
||||
#else
|
||||
#error Invalid CHARGER_PSYS_GAIN value
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
// uncrustify:on
|
||||
|
||||
// Sense resistor values in milliohms.
|
||||
enum sense_resistor {
|
||||
|
@@ -3,22 +3,19 @@
|
||||
board-common-y += acpi.c
|
||||
board-common-y += battery.c
|
||||
board-common-y += config.c
|
||||
board-common-y += dgpu.c
|
||||
board-common-$(CONFIG_HAVE_DGPU) += dgpu.c
|
||||
board-common-y += ecpm.c
|
||||
board-common-$(CONFIG_BUS_ESPI) += espi.c
|
||||
board-common-y += fan.c
|
||||
board-common-y += gctrl.c
|
||||
board-common-y += kbc.c
|
||||
board-common-y += kbled.c
|
||||
board-common-y += kbscan.c
|
||||
board-common-y += keymap.c
|
||||
board-common-y += lid.c
|
||||
board-common-y += main.c
|
||||
board-common-y += parallel.c
|
||||
board-common-y += peci.c
|
||||
board-common-y += pmc.c
|
||||
board-common-y += pnp.c
|
||||
board-common-y += power.c
|
||||
board-common-y += ps2.c
|
||||
board-common-y += pwm.c
|
||||
board-common-y += scratch.c
|
||||
@@ -43,6 +40,17 @@ CFLAGS+=-DLEVEL=4
|
||||
# Uncomment to enable I2C debug on 0x76
|
||||
#CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||
|
||||
ifeq ($(CONFIG_PLATFORM_INTEL),y)
|
||||
board-common-y += peci.c
|
||||
board-common-y += power/intel.c
|
||||
CFLAGS += -DCONFIG_PLATFORM_INTEL=1
|
||||
else ifeq ($(CONFIG_PLATFORM_AMD),y)
|
||||
board-common-y += power/amd.c
|
||||
CFLAGS += -DCONFIG_PLATFORM_AMD=1
|
||||
else
|
||||
$(error PLATFORM not specified)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SECURITY),y)
|
||||
CFLAGS+=-DCONFIG_SECURITY=1
|
||||
endif
|
||||
@@ -59,6 +67,10 @@ CFLAGS += -DCONFIG_PECI_OVER_ESPI=1
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_HAVE_DGPU),y)
|
||||
CFLAGS += -DCONFIG_HAVE_DGPU=1
|
||||
endif
|
||||
|
||||
# Include system76 common source
|
||||
SYSTEM76_COMMON_DIR=src/board/system76/common
|
||||
INCLUDE += $(SYSTEM76_COMMON_DIR)/common.mk
|
||||
@@ -77,8 +89,10 @@ CHARGER?=bq24780s
|
||||
board-common-y += charger/$(CHARGER).c
|
||||
|
||||
# Add USB-PD
|
||||
USBPD?=none
|
||||
board-common-y += usbpd/$(USBPD).c
|
||||
ifeq ($(CONFIG_HAVE_USBPD),y)
|
||||
CFLAGS += -DCONFIG_HAVE_USBPD=1
|
||||
board-common-$(CONFIG_USBPD_TPS65987) += usbpd/tps65987.c
|
||||
endif
|
||||
|
||||
# Add keyboard
|
||||
ifndef KEYBOARD
|
||||
@@ -88,8 +102,11 @@ KEYBOARD_DIR=src/keyboard/system76/$(KEYBOARD)
|
||||
include $(KEYBOARD_DIR)/keyboard.mk
|
||||
|
||||
# Add kbled
|
||||
KBLED?=none
|
||||
ifeq ($(CONFIG_HAVE_KBLED),y)
|
||||
CFLAGS += -DCONFIG_HAVE_KBLED=1
|
||||
board-common-y += kbled/common.c
|
||||
board-common-y += kbled/$(KBLED).c
|
||||
endif
|
||||
|
||||
# Add scratch ROM
|
||||
include $(SYSTEM76_COMMON_DIR)/scratch/scratch.mk
|
||||
|
@@ -1,107 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/dgpu.h>
|
||||
#include <board/fan.h>
|
||||
|
||||
#if HAVE_DGPU
|
||||
|
||||
#include <board/gpio.h>
|
||||
#include <board/peci.h>
|
||||
#include <board/power.h>
|
||||
#include <common/debug.h>
|
||||
#include <common/macro.h>
|
||||
#include <ec/i2c.h>
|
||||
#include <ec/pwm.h>
|
||||
|
||||
// Fan speed is the lowest requested over HEATUP seconds
|
||||
#ifndef BOARD_DGPU_HEATUP
|
||||
#define BOARD_DGPU_HEATUP 4
|
||||
#endif
|
||||
|
||||
static uint8_t FAN_HEATUP[BOARD_DGPU_HEATUP] = { 0 };
|
||||
|
||||
// Fan speed is the highest HEATUP speed over COOLDOWN seconds
|
||||
#ifndef BOARD_DGPU_COOLDOWN
|
||||
#define BOARD_DGPU_COOLDOWN 10
|
||||
#endif
|
||||
|
||||
static uint8_t FAN_COOLDOWN[BOARD_DGPU_COOLDOWN] = { 0 };
|
||||
|
||||
int16_t dgpu_temp = 0;
|
||||
|
||||
#define DGPU_TEMP(X) ((int16_t)(X))
|
||||
|
||||
#define FAN_POINT(T, D) \
|
||||
{ .temp = DGPU_TEMP(T), .duty = PWM_DUTY(D) }
|
||||
|
||||
// Fan curve with temperature in degrees C, duty cycle in percent
|
||||
static struct FanPoint __code FAN_POINTS[] = {
|
||||
#ifdef BOARD_DGPU_FAN_POINTS
|
||||
BOARD_DGPU_FAN_POINTS
|
||||
#else
|
||||
FAN_POINT(70, 40),
|
||||
FAN_POINT(75, 50),
|
||||
FAN_POINT(80, 60),
|
||||
FAN_POINT(85, 65),
|
||||
FAN_POINT(90, 65)
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct Fan __code FAN = {
|
||||
.points = FAN_POINTS,
|
||||
.points_size = ARRAY_SIZE(FAN_POINTS),
|
||||
.heatup = FAN_HEATUP,
|
||||
.heatup_size = ARRAY_SIZE(FAN_HEATUP),
|
||||
.cooldown = FAN_COOLDOWN,
|
||||
.cooldown_size = ARRAY_SIZE(FAN_COOLDOWN),
|
||||
.interpolate = SMOOTH_FANS != 0,
|
||||
};
|
||||
|
||||
void dgpu_init(void) {
|
||||
// Set up for i2c usage
|
||||
i2c_reset(&I2C_DGPU, true);
|
||||
}
|
||||
|
||||
uint8_t dgpu_get_fan_duty(void) {
|
||||
uint8_t duty;
|
||||
if (power_state == POWER_STATE_S0 && gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
|
||||
// Use I2CS if in S0 state
|
||||
bool dgpu_get_temp(int16_t *const data) {
|
||||
if (gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
|
||||
int8_t rlts;
|
||||
int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1);
|
||||
if (res == 1) {
|
||||
dgpu_temp = (int16_t)rlts;
|
||||
duty = fan_duty(&FAN, dgpu_temp);
|
||||
*data = (int16_t)rlts;
|
||||
return true;
|
||||
} else {
|
||||
DEBUG("DGPU temp error: %d\n", res);
|
||||
// Default to 50% if there is an error
|
||||
dgpu_temp = 0;
|
||||
duty = PWM_DUTY(50);
|
||||
*data = 0;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Turn fan off if not in S0 state or GPU power not on
|
||||
dgpu_temp = 0;
|
||||
duty = PWM_DUTY(0);
|
||||
}
|
||||
|
||||
if (peci_on && fan_max) {
|
||||
// Override duty if fans are manually set to maximum
|
||||
duty = PWM_DUTY(100);
|
||||
} else {
|
||||
// Apply heatup and cooldown filters to duty
|
||||
duty = fan_heatup(&FAN, duty);
|
||||
duty = fan_cooldown(&FAN, duty);
|
||||
*data = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void dgpu_read_temp(void) {
|
||||
if (power_state == POWER_STATE_S0) {
|
||||
if (dgpu_get_temp(&dgpu_temp)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TRACE("DGPU temp=%d\n", dgpu_temp);
|
||||
return duty;
|
||||
dgpu_temp = 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void dgpu_init(void) {}
|
||||
|
||||
uint8_t dgpu_get_fan_duty(void) {
|
||||
return PWM_DUTY(0);
|
||||
}
|
||||
|
||||
#endif // HAVE_DGPU
|
||||
|
@@ -16,7 +16,7 @@
|
||||
#define DEBUG_SET(REG, MASK, BITS) \
|
||||
{ \
|
||||
DEBUG("%s: %X", #REG, REG); \
|
||||
REG = ((REG) & ~(MASK)) | (BITS); \
|
||||
REG = (REG & ~(MASK)) | (BITS); \
|
||||
DEBUG(" set to %X\n", REG); \
|
||||
}
|
||||
|
||||
@@ -176,6 +176,15 @@ void espi_event(void) {
|
||||
VW_SET_DEBUG(VW_SUS_ACK_N, wire);
|
||||
}
|
||||
}
|
||||
if (value & BIT(4)) {
|
||||
DEBUG("VWIDX42 %X\n", VWIDX42);
|
||||
}
|
||||
if (value & BIT(5)) {
|
||||
DEBUG("VWIDX43 %X\n", VWIDX43);
|
||||
}
|
||||
if (value & BIT(6)) {
|
||||
DEBUG("VWIDX44 %X\n", VWIDX44);
|
||||
}
|
||||
if (value & BIT(7)) {
|
||||
DEBUG("VWIDX47 %X\n", VWIDX47);
|
||||
}
|
||||
|
@@ -1,31 +1,121 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/fan.h>
|
||||
#include <board/dgpu.h>
|
||||
#include <board/power.h>
|
||||
#include <common/debug.h>
|
||||
#include <common/macro.h>
|
||||
#include <ec/pwm.h>
|
||||
|
||||
#if SMOOTH_FANS != 0
|
||||
#define MAX_JUMP_UP ((MAX_FAN_SPEED - MIN_FAN_SPEED) / (uint8_t)SMOOTH_FANS_UP)
|
||||
#define MAX_JUMP_DOWN ((MAX_FAN_SPEED - MIN_FAN_SPEED) / (uint8_t)SMOOTH_FANS_DOWN)
|
||||
#else
|
||||
#define MAX_JUMP_UP (MAX_FAN_SPEED - MIN_FAN_SPEED)
|
||||
#define MAX_JUMP_DOWN (MAX_FAN_SPEED - MIN_FAN_SPEED)
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
#include <board/peci.h>
|
||||
#endif
|
||||
|
||||
#define MIN_SPEED_TO_SMOOTH PWM_DUTY(SMOOTH_FANS_MIN)
|
||||
|
||||
bool fan_max = false;
|
||||
uint8_t last_duty_dgpu = 0;
|
||||
uint8_t last_duty_peci = 0;
|
||||
|
||||
uint8_t fan1_pwm_actual = 0;
|
||||
uint8_t fan1_pwm_target = 0;
|
||||
uint16_t fan1_rpm = 0;
|
||||
|
||||
uint8_t fan2_pwm_actual = 0;
|
||||
uint8_t fan2_pwm_target = 0;
|
||||
uint16_t fan2_rpm = 0;
|
||||
|
||||
#define TACH_FREQ (CONFIG_CLOCK_FREQ_KHZ * 1000UL)
|
||||
|
||||
// Fan Speed (RPM) = 60 / (1/fs sec * {FnTMRR, FnRLRR} * P)
|
||||
// - n: 1 or 2
|
||||
// - P: the numbers of square pulses per revolution
|
||||
// - fs: sample rate (FreqEC / 128)
|
||||
// - {FnTMRR, FnTLRR} = 0000h: Fan Speed is zero
|
||||
#define TACH_TO_RPM(x) (60UL * TACH_FREQ / 128UL / 2UL / (x))
|
||||
|
||||
#define FAN_POINT(T, D) { .temp = (int16_t)(T), .duty = PWM_DUTY(D) }
|
||||
|
||||
#ifndef FAN1_PWM_MIN
|
||||
#define FAN1_PWM_MIN 0
|
||||
#endif
|
||||
|
||||
// Fan speed is the lowest requested over HEATUP seconds
|
||||
#ifndef BOARD_FAN1_HEATUP
|
||||
#define BOARD_FAN1_HEATUP 4
|
||||
#endif
|
||||
|
||||
static uint8_t FAN1_HEATUP[BOARD_FAN1_HEATUP] = { 0 };
|
||||
|
||||
// Fan speed is the highest HEATUP speed over COOLDOWN seconds
|
||||
#ifndef BOARD_FAN1_COOLDOWN
|
||||
#define BOARD_FAN1_COOLDOWN 10
|
||||
#endif
|
||||
|
||||
static uint8_t FAN1_COOLDOWN[BOARD_FAN1_COOLDOWN] = { 0 };
|
||||
|
||||
// Fan curve with temperature in degrees C, duty cycle in percent
|
||||
static const struct FanPoint __code FAN1_POINTS[] = {
|
||||
#ifndef BOARD_FAN1_POINTS
|
||||
#error Board must declare fan points
|
||||
#else
|
||||
BOARD_FAN1_POINTS
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct Fan __code FAN1 = {
|
||||
.points = FAN1_POINTS,
|
||||
.points_size = ARRAY_SIZE(FAN1_POINTS),
|
||||
.heatup = FAN1_HEATUP,
|
||||
.heatup_size = ARRAY_SIZE(FAN1_HEATUP),
|
||||
.cooldown = FAN1_COOLDOWN,
|
||||
.cooldown_size = ARRAY_SIZE(FAN1_COOLDOWN),
|
||||
.pwm_min = PWM_DUTY(FAN1_PWM_MIN),
|
||||
};
|
||||
|
||||
#ifdef FAN2_PWM
|
||||
|
||||
#ifndef FAN2_PWM_MIN
|
||||
#define FAN2_PWM_MIN 0
|
||||
#endif
|
||||
|
||||
// Fan speed is the lowest requested over HEATUP seconds
|
||||
#ifndef BOARD_FAN2_HEATUP
|
||||
#define BOARD_FAN2_HEATUP 4
|
||||
#endif
|
||||
|
||||
static uint8_t FAN2_HEATUP[BOARD_FAN2_HEATUP] = { 0 };
|
||||
|
||||
// Fan speed is the highest HEATUP speed over COOLDOWN seconds
|
||||
#ifndef BOARD_FAN2_COOLDOWN
|
||||
#define BOARD_FAN2_COOLDOWN 10
|
||||
#endif
|
||||
|
||||
static uint8_t FAN2_COOLDOWN[BOARD_FAN2_COOLDOWN] = { 0 };
|
||||
|
||||
// Fan curve with temperature in degrees C, duty cycle in percent
|
||||
static const struct FanPoint __code FAN2_POINTS[] = {
|
||||
#ifndef BOARD_FAN2_POINTS
|
||||
#error Board must declare fan points
|
||||
#else
|
||||
BOARD_FAN2_POINTS
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct Fan __code FAN2 = {
|
||||
.points = FAN2_POINTS,
|
||||
.points_size = ARRAY_SIZE(FAN2_POINTS),
|
||||
.heatup = FAN2_HEATUP,
|
||||
.heatup_size = ARRAY_SIZE(FAN2_HEATUP),
|
||||
.cooldown = FAN2_COOLDOWN,
|
||||
.cooldown_size = ARRAY_SIZE(FAN2_COOLDOWN),
|
||||
.pwm_min = PWM_DUTY(FAN2_PWM_MIN),
|
||||
};
|
||||
|
||||
#endif // FAN2_PWM
|
||||
|
||||
void fan_reset(void) {
|
||||
// Do not manually set fans to maximum speed
|
||||
fan_max = false;
|
||||
}
|
||||
|
||||
// Get duty cycle based on temperature, adapted from
|
||||
// https://github.com/pop-os/system76-power/blob/master/src/fan.rs
|
||||
uint8_t fan_duty(const struct Fan *fan, int16_t temp) __reentrant {
|
||||
static uint8_t fan_duty(const struct Fan *const fan, int16_t temp) {
|
||||
for (uint8_t i = 0; i < fan->points_size; i++) {
|
||||
const struct FanPoint *cur = &fan->points[i];
|
||||
|
||||
@@ -35,57 +125,19 @@ uint8_t fan_duty(const struct Fan *fan, int16_t temp) __reentrant {
|
||||
} else if (temp < cur->temp) {
|
||||
// If lower than first temp, return 0%
|
||||
if (i == 0) {
|
||||
return MIN_FAN_SPEED;
|
||||
return 0;
|
||||
} else {
|
||||
const struct FanPoint *prev = &fan->points[i - 1];
|
||||
|
||||
if (fan->interpolate) {
|
||||
// If in between current temp and previous temp, interpolate
|
||||
if (temp > prev->temp) {
|
||||
int16_t dtemp = (cur->temp - prev->temp);
|
||||
int16_t dduty = ((int16_t)cur->duty) - ((int16_t)prev->duty);
|
||||
// clang-format off
|
||||
return (uint8_t)(
|
||||
((int16_t)prev->duty) +
|
||||
((temp - prev->temp) * dduty) / dtemp
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
} else {
|
||||
return prev->duty;
|
||||
}
|
||||
return prev->duty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no point is found, return 100%
|
||||
return MAX_FAN_SPEED;
|
||||
return CTR0;
|
||||
}
|
||||
|
||||
void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant {
|
||||
#if SYNC_FANS != 0
|
||||
peci_fan_duty = peci_fan_duty > dgpu_fan_duty ? peci_fan_duty : dgpu_fan_duty;
|
||||
dgpu_fan_duty = peci_fan_duty > dgpu_fan_duty ? peci_fan_duty : dgpu_fan_duty;
|
||||
#endif
|
||||
|
||||
// set PECI fan duty
|
||||
if (peci_fan_duty != DCR2) {
|
||||
TRACE("PECI fan_duty_raw=%d\n", peci_fan_duty);
|
||||
last_duty_peci = peci_fan_duty = fan_smooth(last_duty_peci, peci_fan_duty);
|
||||
DCR2 = fan_max ? MAX_FAN_SPEED : peci_fan_duty;
|
||||
TRACE("PECI fan_duty_smoothed=%d\n", peci_fan_duty);
|
||||
}
|
||||
|
||||
// set dGPU fan duty
|
||||
if (dgpu_fan_duty != DCR4) {
|
||||
TRACE("DGPU fan_duty_raw=%d\n", dgpu_fan_duty);
|
||||
last_duty_dgpu = dgpu_fan_duty = fan_smooth(last_duty_dgpu, dgpu_fan_duty);
|
||||
DCR4 = fan_max ? MAX_FAN_SPEED : dgpu_fan_duty;
|
||||
TRACE("DGPU fan_duty_smoothed=%d\n", dgpu_fan_duty);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant {
|
||||
static uint8_t fan_heatup(const struct Fan *const fan, uint8_t duty) {
|
||||
uint8_t lowest = duty;
|
||||
|
||||
uint8_t i;
|
||||
@@ -101,7 +153,7 @@ uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant {
|
||||
return lowest;
|
||||
}
|
||||
|
||||
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant {
|
||||
static uint8_t fan_cooldown(const struct Fan *const fan, uint8_t duty) {
|
||||
uint8_t highest = duty;
|
||||
|
||||
uint8_t i;
|
||||
@@ -117,38 +169,109 @@ uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant {
|
||||
return highest;
|
||||
}
|
||||
|
||||
uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant {
|
||||
uint8_t next_duty = duty;
|
||||
static uint8_t fan_get_duty(const struct Fan *const fan, int16_t temp) {
|
||||
uint8_t duty;
|
||||
|
||||
// ramping down
|
||||
if (duty < last_duty) {
|
||||
// out of bounds (lower) safeguard
|
||||
// clang-format off
|
||||
uint8_t smoothed = last_duty < MIN_FAN_SPEED + MAX_JUMP_DOWN
|
||||
? MIN_FAN_SPEED
|
||||
: last_duty - MAX_JUMP_DOWN;
|
||||
// clang-format on
|
||||
duty = fan_duty(fan, temp);
|
||||
duty = fan_heatup(fan, duty);
|
||||
duty = fan_cooldown(fan, duty);
|
||||
|
||||
// use smoothed value if above min and if smoothed is closer than raw
|
||||
if (last_duty > MIN_SPEED_TO_SMOOTH && smoothed > duty) {
|
||||
next_duty = smoothed;
|
||||
}
|
||||
}
|
||||
|
||||
// ramping up
|
||||
if (duty > last_duty) {
|
||||
// out of bounds (higher) safeguard
|
||||
// clang-format off
|
||||
uint8_t smoothed = last_duty > MAX_FAN_SPEED - MAX_JUMP_UP
|
||||
? MAX_FAN_SPEED
|
||||
: last_duty + MAX_JUMP_UP;
|
||||
// clang-format on
|
||||
|
||||
// use smoothed value if above min and if smoothed is closer than raw
|
||||
if (duty > MIN_SPEED_TO_SMOOTH && smoothed < duty) {
|
||||
next_duty = smoothed;
|
||||
}
|
||||
}
|
||||
|
||||
return next_duty;
|
||||
return duty;
|
||||
}
|
||||
|
||||
static uint16_t fan_get_tach0_rpm(void) {
|
||||
uint16_t rpm = (F1TMRR << 8) | F1TLRR;
|
||||
|
||||
if (rpm)
|
||||
rpm = TACH_TO_RPM(rpm);
|
||||
|
||||
return rpm;
|
||||
}
|
||||
|
||||
static uint16_t fan_get_tach1_rpm(void) {
|
||||
uint16_t rpm = (F2TMRR << 8) | F2TLRR;
|
||||
|
||||
if (rpm)
|
||||
rpm = TACH_TO_RPM(rpm);
|
||||
|
||||
return rpm;
|
||||
}
|
||||
|
||||
void fan_event(void) {
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
#if CONFIG_HAVE_DGPU
|
||||
int16_t sys_temp = MAX(peci_temp, dgpu_temp);
|
||||
#else
|
||||
int16_t sys_temp = peci_temp;
|
||||
#endif
|
||||
#elif CONFIG_PLATFORM_AMD
|
||||
// TODO: AMD SB-TSI temp
|
||||
int16_t sys_temp = 50;
|
||||
#endif
|
||||
|
||||
// Fan update interval is 100ms (main.c). The event changes PWM duty
|
||||
// by 1 every interval to give a smoothing effect.
|
||||
|
||||
// Enabling fan max toggle and exiting S0 will cause duty to immediately
|
||||
// change instead of stepping to provide the desired effects.
|
||||
|
||||
// Set FAN1 duty
|
||||
fan1_pwm_target = fan_get_duty(&FAN1, sys_temp);
|
||||
if (fan_max) {
|
||||
fan1_pwm_target = CTR0;
|
||||
fan1_pwm_actual = CTR0;
|
||||
} else if (power_state != POWER_STATE_S0) {
|
||||
fan1_pwm_target = 0;
|
||||
fan1_pwm_actual = 0;
|
||||
} else {
|
||||
if (fan1_pwm_actual < fan1_pwm_target) {
|
||||
if (fan1_pwm_actual < CTR0) {
|
||||
fan1_pwm_actual++;
|
||||
if (fan1_pwm_actual < FAN1.pwm_min) {
|
||||
fan1_pwm_actual = FAN1.pwm_min;
|
||||
}
|
||||
}
|
||||
} else if (fan1_pwm_actual > fan1_pwm_target) {
|
||||
if (fan1_pwm_actual > 0) {
|
||||
fan1_pwm_actual--;
|
||||
if (fan1_pwm_actual < FAN1.pwm_min) {
|
||||
fan1_pwm_actual = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TRACE("FAN1 duty=%d\n", fan1_pwm_actual);
|
||||
FAN1_PWM = fan1_pwm_actual;
|
||||
fan1_rpm = fan_get_tach0_rpm();
|
||||
|
||||
#ifdef FAN2_PWM
|
||||
// set FAN2 duty
|
||||
fan2_pwm_target = fan_get_duty(&FAN2, sys_temp);
|
||||
if (fan_max) {
|
||||
fan2_pwm_target = CTR0;
|
||||
fan2_pwm_actual = CTR0;
|
||||
} else if (power_state != POWER_STATE_S0) {
|
||||
fan2_pwm_target = 0;
|
||||
fan2_pwm_actual = 0;
|
||||
} else {
|
||||
if (fan2_pwm_actual < fan2_pwm_target) {
|
||||
if (fan2_pwm_actual < CTR0) {
|
||||
fan2_pwm_actual++;
|
||||
if (fan2_pwm_actual < FAN2.pwm_min) {
|
||||
fan2_pwm_actual = FAN2.pwm_min;
|
||||
}
|
||||
}
|
||||
} else if (fan2_pwm_actual > fan2_pwm_target) {
|
||||
if (fan2_pwm_actual > 0) {
|
||||
fan2_pwm_actual--;
|
||||
if (fan2_pwm_actual < FAN2.pwm_min) {
|
||||
fan2_pwm_actual = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TRACE("FAN2 duty=%d\n", fan2_pwm_actual);
|
||||
FAN2_PWM = fan2_pwm_actual;
|
||||
fan2_rpm = fan_get_tach1_rpm();
|
||||
#endif
|
||||
}
|
||||
|
@@ -33,25 +33,25 @@ FLASH_CC=\
|
||||
|
||||
# Convert from binary file to C header
|
||||
$(BUILD)/include/flash.h: $(FLASH_BUILD)/flash.rom
|
||||
@echo " XXD $(subst $(obj)/,,$@)"
|
||||
@echo " XXD $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
xxd -include < $< > $@
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(FLASH_BUILD)/flash.rom: $(FLASH_BUILD)/flash.ihx
|
||||
@echo " OBJCOPY $(subst $(obj)/,,$@)"
|
||||
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
objcopy -I ihex -O binary $< $@
|
||||
|
||||
# Link object files into Intel Hex file
|
||||
$(FLASH_BUILD)/flash.ihx: $(FLASH_OBJ)
|
||||
@echo " LINK $(subst $(obj)/,,$@)"
|
||||
@echo " LINK $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(FLASH_CC) -o $@ $^
|
||||
|
||||
# Compile C files into object files
|
||||
$(FLASH_OBJ): $(FLASH_BUILD)/%.rel: src/%.c $(FLASH_INCLUDE)
|
||||
@echo " CC $(subst $(obj)/,,$@)"
|
||||
@echo " CC $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(FLASH_CC) $(FLASH_CFLAGS) -o $@ -c $<
|
||||
|
||||
|
@@ -15,7 +15,6 @@ volatile uint8_t __xdata __at(0x103D) ECINDAR2;
|
||||
volatile uint8_t __xdata __at(0x103E) ECINDAR3;
|
||||
volatile uint8_t __xdata __at(0x103F) ECINDDR;
|
||||
|
||||
// clang-format off
|
||||
#define SPI_DEVICE (0x70)
|
||||
#define SPI_FOLLOW_MODE (0x0F)
|
||||
#define SPI_CHIP_SELECT (0xFD)
|
||||
@@ -30,7 +29,6 @@ volatile uint8_t __xdata __at(0x103F) ECINDDR;
|
||||
#define SPI_ERASE_SECTOR_COMMAND (0xD7)
|
||||
|
||||
#define SPI_STATUS_WIP (0x01)
|
||||
// clang-format on
|
||||
|
||||
void flash_enter_follow_mode(void);
|
||||
void flash_exit_follow_mode(void);
|
||||
@@ -48,9 +46,8 @@ void flash_write_enable(void);
|
||||
* NOTE: __critical to ensure interrupts are disabled. This does mean that interrupt
|
||||
* such as the timer will be block until flash acccess is complete
|
||||
*/
|
||||
// clang-format off
|
||||
void flash_entry(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) __reentrant __critical {
|
||||
// clang-format on
|
||||
void flash_entry(uint32_t addr, uint8_t *data, uint32_t length,
|
||||
uint8_t command) __reentrant __critical {
|
||||
// Only allow access from 64KB to 128KB.
|
||||
if ((addr < 0x10000) || (length > 0x10000) || ((addr + length) > 0x20000))
|
||||
return;
|
||||
@@ -73,7 +70,8 @@ void flash_entry(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command)
|
||||
flash_enter_follow_mode();
|
||||
|
||||
while (length) {
|
||||
// Note, this is the slow way to do it, but it's simple and all bytes are written properly.
|
||||
// Note, this is the slow way to do it, but it's simple and all
|
||||
// bytes are written properly.
|
||||
flash_write_enable();
|
||||
|
||||
// Select the device
|
||||
|
@@ -15,7 +15,7 @@ uint8_t __code __at(FLASH_OFFSET) flash_rom[] = {
|
||||
#include <flash.h>
|
||||
};
|
||||
|
||||
static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t command) {
|
||||
static void flash_api(uint32_t addr, uint8_t *const data, uint32_t length, uint8_t command) {
|
||||
// Use DMA mapping to copy flash ROM to scratch ROM
|
||||
SCARH = 0x80;
|
||||
SCARL = (uint8_t)(FLASH_OFFSET);
|
||||
@@ -29,7 +29,7 @@ static void flash_api(uint32_t addr, uint8_t *data, uint32_t length, uint8_t com
|
||||
SCARH = 0x07;
|
||||
}
|
||||
|
||||
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length) {
|
||||
void flash_read(uint32_t addr, __xdata uint8_t *const data, uint32_t length) {
|
||||
flash_api(addr, data, length, FLASH_COMMAND_READ);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ uint8_t flash_read_u8(uint32_t addr) {
|
||||
return data;
|
||||
}
|
||||
|
||||
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length) {
|
||||
void flash_write(uint32_t addr, __xdata uint8_t *const data, uint32_t length) {
|
||||
flash_api(addr, data, length, FLASH_COMMAND_WRITE);
|
||||
}
|
||||
|
||||
|
@@ -3,17 +3,28 @@
|
||||
#ifndef _BOARD_DGPU_H
|
||||
#define _BOARD_DGPU_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef HAVE_DGPU
|
||||
#define HAVE_DGPU 0
|
||||
#endif
|
||||
#if CONFIG_HAVE_DGPU
|
||||
|
||||
#if HAVE_DGPU
|
||||
extern int16_t dgpu_temp;
|
||||
#endif // HAVE_DGPU
|
||||
|
||||
void dgpu_init(void);
|
||||
uint8_t dgpu_get_fan_duty(void);
|
||||
bool dgpu_get_temp(int16_t *const data);
|
||||
void dgpu_read_temp(void);
|
||||
|
||||
#else
|
||||
|
||||
static inline void dgpu_init(void) {}
|
||||
|
||||
static inline bool dgpu_get_temp(int16_t *const data) {
|
||||
*data = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void dgpu_read_temp(void) {}
|
||||
|
||||
#endif // CONFIG_HAVE_DGPU
|
||||
|
||||
#endif // _BOARD_DGPU_H
|
||||
|
@@ -7,29 +7,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define PWM_DUTY(X) ((uint8_t)(((((uint16_t)(X)) * 255) + 99) / 100))
|
||||
#define MAX_FAN_SPEED PWM_DUTY(100)
|
||||
#define MIN_FAN_SPEED PWM_DUTY(0)
|
||||
|
||||
#ifndef SMOOTH_FANS
|
||||
#define SMOOTH_FANS 1 // default to fan smoothing
|
||||
#endif
|
||||
|
||||
#ifndef SYNC_FANS
|
||||
#define SYNC_FANS 1 // default to syncing fan speeds
|
||||
#endif
|
||||
|
||||
#if SMOOTH_FANS != 0
|
||||
#ifndef SMOOTH_FANS_UP
|
||||
#define SMOOTH_FANS_UP 45 // default to ~11 seconds for full ramp-up
|
||||
#endif
|
||||
#ifndef SMOOTH_FANS_DOWN
|
||||
#define SMOOTH_FANS_DOWN 100 // default to ~25 seconds for full ramp-down
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SMOOTH_FANS_MIN
|
||||
#define SMOOTH_FANS_MIN 0 // default to smoothing all fan speed changes
|
||||
#endif
|
||||
|
||||
struct FanPoint {
|
||||
int16_t temp;
|
||||
@@ -43,17 +20,19 @@ struct Fan {
|
||||
uint8_t heatup_size;
|
||||
uint8_t *cooldown;
|
||||
uint8_t cooldown_size;
|
||||
bool interpolate;
|
||||
uint8_t pwm_min;
|
||||
};
|
||||
|
||||
extern bool fan_max;
|
||||
|
||||
void fan_reset(void);
|
||||
extern uint8_t fan1_pwm_actual;
|
||||
extern uint8_t fan1_pwm_target;
|
||||
extern uint16_t fan1_rpm;
|
||||
extern uint8_t fan2_pwm_actual;
|
||||
extern uint8_t fan2_pwm_target;
|
||||
extern uint16_t fan2_rpm;
|
||||
|
||||
uint8_t fan_duty(const struct Fan *fan, int16_t temp) __reentrant;
|
||||
void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant;
|
||||
uint8_t fan_heatup(const struct Fan *fan, uint8_t duty) __reentrant;
|
||||
uint8_t fan_cooldown(const struct Fan *fan, uint8_t duty) __reentrant;
|
||||
uint8_t fan_smooth(uint8_t last_duty, uint8_t duty) __reentrant;
|
||||
void fan_reset(void);
|
||||
void fan_event(void);
|
||||
|
||||
#endif // _BOARD_FAN_H
|
||||
|
@@ -12,11 +12,9 @@
|
||||
/** \cond INTERNAL
|
||||
* Internal defines
|
||||
*/
|
||||
// clang-format off
|
||||
#define FLASH_COMMAND_READ (0x0)
|
||||
#define FLASH_COMMAND_WRITE (0x1)
|
||||
#define FLASH_COMMAND_ERASE_1K (0x2)
|
||||
// clang-format on
|
||||
/** \endcond */
|
||||
|
||||
/**
|
||||
@@ -26,7 +24,7 @@
|
||||
* \param[out] data The memory area to copy to.
|
||||
* \param[in] length The number of bytes to copy.
|
||||
*/
|
||||
void flash_read(uint32_t addr, __xdata uint8_t *data, uint32_t length);
|
||||
void flash_read(uint32_t addr, __xdata uint8_t *const data, uint32_t length);
|
||||
|
||||
/**
|
||||
* Read a single byte from flash.
|
||||
@@ -62,7 +60,7 @@ uint32_t flash_read_u32(uint32_t addr);
|
||||
* \param[in] data The memory area to copy from.
|
||||
* \param[in] length The number of bytes to copy.
|
||||
*/
|
||||
void flash_write(uint32_t addr, __xdata uint8_t *data, uint32_t length);
|
||||
void flash_write(uint32_t addr, __xdata uint8_t *const data, uint32_t length);
|
||||
|
||||
/**
|
||||
* Write a single byte to flash.
|
||||
|
@@ -12,6 +12,6 @@ extern uint8_t kbc_leds;
|
||||
void kbc_init(void);
|
||||
void kbc_reset(void);
|
||||
bool kbc_scancode(uint16_t key, bool pressed);
|
||||
void kbc_event(struct Kbc *kbc);
|
||||
void kbc_event(struct Kbc *const kbc);
|
||||
|
||||
#endif // _BOARD_KBC_H
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if CONFIG_HAVE_KBLED
|
||||
|
||||
enum KbledKind {
|
||||
KBLED_NONE = 0,
|
||||
KBLED_WHITE = 1,
|
||||
@@ -12,7 +14,7 @@ enum KbledKind {
|
||||
};
|
||||
extern enum KbledKind kbled_kind;
|
||||
|
||||
// Must be specified by board
|
||||
// Must be specified per mechanism
|
||||
void kbled_init(void);
|
||||
void kbled_reset(void);
|
||||
uint8_t kbled_get(void);
|
||||
@@ -28,4 +30,37 @@ void kbled_hotkey_up(void);
|
||||
void kbled_hotkey_toggle(void);
|
||||
void kbled_hotkey_step(void);
|
||||
|
||||
#else // CONFIG_HAVE_KBLED
|
||||
|
||||
static inline void kbled_init(void) {}
|
||||
static inline void kbled_reset(void) {}
|
||||
|
||||
static inline uint8_t kbled_get(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline uint8_t kbled_max(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void kbled_set(uint8_t level) {
|
||||
(void)level;
|
||||
}
|
||||
|
||||
static inline uint32_t kbled_get_color(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void kbled_set_color(uint32_t color) {
|
||||
(void)color;
|
||||
}
|
||||
|
||||
static inline void kbled_hotkey_color(void) {}
|
||||
static inline void kbled_hotkey_down(void) {}
|
||||
static inline void kbled_hotkey_up(void) {}
|
||||
static inline void kbled_hotkey_toggle(void) {}
|
||||
static inline void kbled_hotkey_step(void) {}
|
||||
|
||||
#endif // CONFIG_HAVE_KBLED
|
||||
|
||||
#endif // _BOARD_KBLED_H
|
||||
|
@@ -8,6 +8,6 @@
|
||||
|
||||
extern bool parallel_debug;
|
||||
bool parallel_init(void);
|
||||
int16_t parallel_write(uint8_t *data, uint16_t length);
|
||||
int16_t parallel_write(const uint8_t *const data, uint16_t length);
|
||||
|
||||
#endif // _BOARD_PARALLEL_H
|
||||
|
@@ -3,16 +3,24 @@
|
||||
#ifndef _BOARD_PECI_H
|
||||
#define _BOARD_PECI_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <ec/peci.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool peci_on;
|
||||
extern int16_t peci_temp;
|
||||
|
||||
enum PeciCmd {
|
||||
PECI_CMD_PING = 0x00,
|
||||
PECI_CMD_GET_TEMP = 0x01,
|
||||
PECI_CMD_RD_PKG_CONFIG = 0xA1,
|
||||
PECI_CMD_WR_PKG_CONFIG = 0xA5,
|
||||
PECI_CMD_RD_IAMSR = 0xB1,
|
||||
PECI_CMD_GET_DIB = 0xF7,
|
||||
};
|
||||
|
||||
void peci_init(void);
|
||||
bool peci_available(void);
|
||||
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data);
|
||||
uint8_t peci_get_fan_duty(void);
|
||||
void peci_read_temp(void);
|
||||
|
||||
#endif // _BOARD_PECI_H
|
||||
|
@@ -6,8 +6,8 @@
|
||||
#include <ec/pmc.h>
|
||||
|
||||
void pmc_init(void);
|
||||
bool pmc_sci(struct Pmc *pmc, uint8_t sci);
|
||||
bool pmc_sci(struct Pmc *const pmc, uint8_t sci);
|
||||
void pmc_swi(void);
|
||||
void pmc_event(struct Pmc *pmc);
|
||||
void pmc_event(struct Pmc *const pmc);
|
||||
|
||||
#endif // _BOARD_PMC_H
|
||||
|
@@ -17,7 +17,6 @@ void power_init(void);
|
||||
void power_on(void);
|
||||
void power_off(void);
|
||||
void power_cpu_reset(void);
|
||||
|
||||
void power_event(void);
|
||||
|
||||
#endif // _BOARD_POWER_H
|
||||
|
@@ -3,8 +3,6 @@
|
||||
#ifndef _BOARD_PWM_H
|
||||
#define _BOARD_PWM_H
|
||||
|
||||
#include <ec/pwm.h>
|
||||
|
||||
void pwm_init(void);
|
||||
|
||||
#endif // _BOARD_PWM_H
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include <ec/smbus.h>
|
||||
|
||||
void smbus_init(void);
|
||||
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data);
|
||||
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data);
|
||||
int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data);
|
||||
|
||||
#endif // _BOARD_SMBUS_H
|
||||
|
@@ -3,9 +3,20 @@
|
||||
#ifndef _BOARD_USBPD_H
|
||||
#define _BOARD_USBPD_H
|
||||
|
||||
#if CONFIG_HAVE_USBPD
|
||||
|
||||
void usbpd_init(void);
|
||||
void usbpd_event(void);
|
||||
void usbpd_disable_charging(void);
|
||||
void usbpd_enable_charging(void);
|
||||
|
||||
#else
|
||||
|
||||
static inline void usbpd_init(void) {}
|
||||
static inline void usbpd_event(void) {}
|
||||
static inline void usbpd_disable_charging(void) {}
|
||||
static inline void usbpd_enable_charging(void) {}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _BOARD_USBPD_H
|
||||
|
@@ -41,7 +41,6 @@ static bool kbc_translate = true;
|
||||
// LED state
|
||||
uint8_t kbc_leds = 0;
|
||||
|
||||
// clang-format off
|
||||
// Values from linux/drivers/input/keyboard/atkbd.c
|
||||
static const uint16_t kbc_typematic_period[32] = {
|
||||
33, // 30.0 cps = ~33.33ms
|
||||
@@ -77,13 +76,12 @@ static const uint16_t kbc_typematic_period[32] = {
|
||||
470, // 2.1 cps = ~478.19ms
|
||||
500, // 2.0 cps = 500ms
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
static uint8_t kbc_buffer[16] = { 0 };
|
||||
static uint8_t kbc_buffer_head = 0;
|
||||
static uint8_t kbc_buffer_tail = 0;
|
||||
|
||||
static bool kbc_buffer_pop(uint8_t *scancode) {
|
||||
static bool kbc_buffer_pop(uint8_t *const scancode) {
|
||||
if (kbc_buffer_head == kbc_buffer_tail) {
|
||||
return false;
|
||||
}
|
||||
@@ -92,7 +90,7 @@ static bool kbc_buffer_pop(uint8_t *scancode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool kbc_buffer_push(uint8_t *scancodes, uint8_t len) {
|
||||
static bool kbc_buffer_push(const uint8_t *const scancodes, uint8_t len) {
|
||||
//TODO: make this test more efficient
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
if ((kbc_buffer_tail + i + 1U) % ARRAY_SIZE(kbc_buffer) == kbc_buffer_head) {
|
||||
@@ -122,7 +120,7 @@ bool kbc_scancode(uint16_t key, bool pressed) {
|
||||
case KF_E0:
|
||||
scancodes[scancodes_len++] = 0xE0;
|
||||
key &= 0xFF;
|
||||
// Fall through
|
||||
// Fall through
|
||||
case 0x00:
|
||||
if (!pressed) {
|
||||
if (kbc_translate) {
|
||||
@@ -165,13 +163,13 @@ static uint8_t state_data = 0;
|
||||
static enum KbcState state_next = KBC_STATE_NORMAL;
|
||||
|
||||
// Clear output buffer
|
||||
static void kbc_clear_output(struct Kbc *kbc) {
|
||||
static void kbc_clear_output(struct Kbc *const kbc) {
|
||||
*(kbc->control) |= BIT(5);
|
||||
*(kbc->control) |= BIT(6);
|
||||
*(kbc->control) &= ~BIT(5);
|
||||
}
|
||||
|
||||
static void kbc_on_input_command(struct Kbc *kbc, uint8_t data) {
|
||||
static void kbc_on_input_command(struct Kbc *const kbc, uint8_t data) {
|
||||
TRACE("kbc cmd: %02X\n", data);
|
||||
// Controller commands always reset the state
|
||||
state = KBC_STATE_NORMAL;
|
||||
@@ -254,13 +252,13 @@ static void kbc_on_input_command(struct Kbc *kbc, uint8_t data) {
|
||||
}
|
||||
}
|
||||
|
||||
static void kbc_on_input_data(struct Kbc *kbc, uint8_t data) {
|
||||
static void kbc_on_input_data(struct Kbc *const kbc, uint8_t data) {
|
||||
TRACE("kbc data: %02X\n", data);
|
||||
switch (state) {
|
||||
case KBC_STATE_TOUCHPAD:
|
||||
// Interrupt touchpad command
|
||||
state = KBC_STATE_NORMAL;
|
||||
// Fall through
|
||||
// Fall through
|
||||
case KBC_STATE_NORMAL:
|
||||
TRACE(" keyboard command\n");
|
||||
// Keyboard commands clear output buffer
|
||||
@@ -400,22 +398,20 @@ static void kbc_on_input_data(struct Kbc *kbc, uint8_t data) {
|
||||
TRACE(" write second port input\n");
|
||||
state = KBC_STATE_NORMAL;
|
||||
// Begin write
|
||||
*(PS2_TOUCHPAD.control) = 0x0D;
|
||||
// Enable Transaction Done interrupt
|
||||
*(PS2_TOUCHPAD.interrupt) |= BIT(2);
|
||||
*(PS2_TOUCHPAD.control) = 0x1D;
|
||||
// Write the data
|
||||
*(PS2_TOUCHPAD.data) = data;
|
||||
// Pull data line low
|
||||
*(PS2_TOUCHPAD.control) = 0x0C;
|
||||
*(PS2_TOUCHPAD.control) = 0x1C;
|
||||
// Pull clock line high
|
||||
*(PS2_TOUCHPAD.control) = 0x0E;
|
||||
*(PS2_TOUCHPAD.control) = 0x1E;
|
||||
// Set wait timeout of 100 cycles
|
||||
kbc_second_wait = 100;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void kbc_on_output_empty(struct Kbc *kbc) {
|
||||
static void kbc_on_output_empty(struct Kbc *const kbc) {
|
||||
switch (state) {
|
||||
case KBC_STATE_KEYBOARD:
|
||||
TRACE("kbc keyboard: %02X\n", state_data);
|
||||
@@ -426,7 +422,7 @@ static void kbc_on_output_empty(struct Kbc *kbc) {
|
||||
break;
|
||||
case KBC_STATE_TOUCHPAD:
|
||||
state_data = *(PS2_TOUCHPAD.data);
|
||||
// Fall through
|
||||
// Fall through
|
||||
case KBC_STATE_MOUSE:
|
||||
TRACE("kbc mouse: %02X\n", state_data);
|
||||
if (kbc_mouse(kbc, state_data, KBC_TIMEOUT)) {
|
||||
@@ -454,7 +450,7 @@ static void kbc_on_output_empty(struct Kbc *kbc) {
|
||||
}
|
||||
}
|
||||
|
||||
void kbc_event(struct Kbc *kbc) {
|
||||
void kbc_event(struct Kbc *const kbc) {
|
||||
uint8_t sts;
|
||||
|
||||
// Read from scancode buffer when possible
|
||||
@@ -468,6 +464,7 @@ void kbc_event(struct Kbc *kbc) {
|
||||
// Wait for touchpad write transaction to finish
|
||||
kbc_second_wait -= 1;
|
||||
uint8_t sts = *(PS2_TOUCHPAD.status);
|
||||
*(PS2_TOUCHPAD.status) = sts;
|
||||
// If transaction is done, stop waiting
|
||||
if (sts & PSSTS_DONE) {
|
||||
kbc_second_wait = 0;
|
||||
@@ -488,9 +485,7 @@ void kbc_event(struct Kbc *kbc) {
|
||||
|
||||
if (kbc_second_wait == 0) {
|
||||
// Attempt to read from touchpad
|
||||
*(PS2_TOUCHPAD.control) = 0x07;
|
||||
// Enable Transaction Done interrupt
|
||||
*(PS2_TOUCHPAD.interrupt) |= BIT(2);
|
||||
*(PS2_TOUCHPAD.control) = 0x17;
|
||||
if (state == KBC_STATE_NORMAL) {
|
||||
uint8_t sts = *(PS2_TOUCHPAD.status);
|
||||
*(PS2_TOUCHPAD.status) = sts;
|
||||
|
@@ -31,26 +31,26 @@ void kbled_reset(void) {
|
||||
|
||||
// Keep the following functions for compatibility - they are set via USB HID
|
||||
uint8_t kbled_get(void) {
|
||||
/* Always off */
|
||||
// Always off
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t kbled_max(void) {
|
||||
/* Always off */
|
||||
// Always off
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set(uint8_t level) {
|
||||
/* Fix unused variable */
|
||||
// Fix unused variable
|
||||
level = level;
|
||||
}
|
||||
|
||||
uint32_t kbled_get_color(void) {
|
||||
/* Always black */
|
||||
// Always black
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) {
|
||||
/* Fix unused variable */
|
||||
// Fix unused variable
|
||||
color = color;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
|
||||
enum KbledKind kbled_kind = KBLED_NONE;
|
||||
|
||||
// clang-format off
|
||||
static uint8_t LEVEL_I = 1;
|
||||
#ifdef KBLED_DAC
|
||||
// XXX: DAC uses separate levels due to brightness being different.
|
||||
@@ -38,7 +37,6 @@ static const uint32_t __code COLORS[] = {
|
||||
0x00FFFF,
|
||||
0xFFFF00
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
void kbled_hotkey_color(void) {
|
||||
if (COLOR_I < (ARRAY_SIZE(COLORS) - 1)) {
|
@@ -1,32 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/kbled.h>
|
||||
|
||||
void kbled_init(void) {}
|
||||
|
||||
void kbled_reset(void) {}
|
||||
|
||||
uint8_t kbled_get(void) {
|
||||
/* Always off */
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t kbled_max(void) {
|
||||
/* Always off */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set(uint8_t level) {
|
||||
/* Fix unused variable */
|
||||
level = level;
|
||||
}
|
||||
|
||||
uint32_t kbled_get_color(void) {
|
||||
/* Always black */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) {
|
||||
/* Fix unused variable */
|
||||
color = color;
|
||||
}
|
@@ -35,11 +35,11 @@ void kbled_set(uint8_t level) {
|
||||
}
|
||||
|
||||
uint32_t kbled_get_color(void) {
|
||||
/* Always white */
|
||||
// Always white
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
void kbled_set_color(uint32_t color) {
|
||||
/* Fix unused variable */
|
||||
// Fix unused variable
|
||||
color = color;
|
||||
}
|
||||
|
@@ -23,9 +23,6 @@
|
||||
// Debounce time in milliseconds
|
||||
#define DEBOUNCE_DELAY 10
|
||||
|
||||
// Deselect all columns for reading
|
||||
#define KBSCAN_MATRIX_NONE 0xFF
|
||||
|
||||
bool kbscan_fn_held = false;
|
||||
bool kbscan_esc_held = false;
|
||||
|
||||
@@ -45,6 +42,38 @@ static inline bool matrix_position_is_fn(uint8_t row, uint8_t col) {
|
||||
return (row == MATRIX_FN_OUTPUT) && (col == MATRIX_FN_INPUT);
|
||||
}
|
||||
|
||||
// Assert the specified column for reading the row.
|
||||
static void kbscan_set_column(uint8_t col) {
|
||||
// Assert the specific bit corresponding to the column.
|
||||
// XXX: IT8587E will hang if the column is determined with:
|
||||
// uint32_t colbit = ~BIT(col);
|
||||
if (col < 8) {
|
||||
KSOL = ~BIT(col);
|
||||
KSOH1 = 0xFF;
|
||||
KSOH2 = 0xFF;
|
||||
} else if (col < 16) {
|
||||
KSOL = 0xFF;
|
||||
KSOH1 = ~BIT(col - 8);
|
||||
KSOH2 = 0xFF;
|
||||
} else {
|
||||
KSOL = 0xFF;
|
||||
KSOH1 = 0xFF;
|
||||
KSOH2 = ~BIT(col - 16);
|
||||
}
|
||||
|
||||
// Wait for matrix to stabilize
|
||||
delay_ticks(20);
|
||||
}
|
||||
|
||||
// Disable reading from all columns.
|
||||
static void kbscan_disable_reading(void) {
|
||||
KSOL = 0xFF;
|
||||
KSOH1 = 0xFF;
|
||||
KSOH2 = 0xFF;
|
||||
|
||||
// No need to wait for matrix to stabilize as a read won't happen.
|
||||
}
|
||||
|
||||
// Initialize the Keyboard Matrix Scan Controller in KBS (Normal) mode for
|
||||
// reading keyboard input.
|
||||
void kbscan_init(void) {
|
||||
@@ -53,10 +82,8 @@ void kbscan_init(void) {
|
||||
KSOCTRL = BIT(2) | BIT(0);
|
||||
KSOHGCTRL = 0;
|
||||
KSOLGCTRL = 0;
|
||||
// XXX: Still set outputs low?
|
||||
KSOL = 0;
|
||||
KSOH1 = 0;
|
||||
KSOH2 = 0;
|
||||
|
||||
kbscan_disable_reading();
|
||||
|
||||
// KSI[7:0]: Enable pull-up, set to KBS mode
|
||||
KSICTRLR = BIT(2);
|
||||
@@ -65,36 +92,12 @@ void kbscan_init(void) {
|
||||
|
||||
// Read the state of the row for the selected column.
|
||||
static inline uint8_t kbscan_get_row(void) {
|
||||
// Report all keys as released when lid is closed
|
||||
if (!lid_state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Invert KSI for positive logic of pressed keys.
|
||||
return ~KSI;
|
||||
}
|
||||
|
||||
// Assert the specified column for reading the row.
|
||||
static void kbscan_set_column(uint8_t col) {
|
||||
if (col == KBSCAN_MATRIX_NONE) {
|
||||
// Disable reading from all columns
|
||||
KSOL = 0xFF;
|
||||
KSOH1 = 0xFF;
|
||||
KSOH2 = 0x3;
|
||||
} else {
|
||||
// Assert the specific bit corresponding to the column
|
||||
uint32_t colbit = ~BIT(col);
|
||||
KSOL = colbit & 0xFF;
|
||||
KSOH1 = (colbit >> 8) & 0xFF;
|
||||
KSOH2 = (colbit >> 16) & 0x03;
|
||||
}
|
||||
|
||||
// Wait for matrix to stabilize
|
||||
delay_ticks(20);
|
||||
}
|
||||
|
||||
#if KM_NKEY
|
||||
static bool kbscan_row_has_ghost(uint8_t *matrix, uint8_t col) {
|
||||
static bool kbscan_row_has_ghost(uint8_t *const matrix, uint8_t col) {
|
||||
(void)matrix;
|
||||
(void)col;
|
||||
return false;
|
||||
@@ -104,7 +107,7 @@ static inline bool popcount_more_than_one(uint8_t rowdata) {
|
||||
return rowdata & (rowdata - 1);
|
||||
}
|
||||
|
||||
static bool kbscan_row_has_ghost(uint8_t *matrix, uint8_t col) {
|
||||
static bool kbscan_row_has_ghost(const uint8_t *const matrix, uint8_t col) {
|
||||
uint8_t rowdata = matrix[col];
|
||||
|
||||
// No ghosts exist when less than 2 keys in the row are active.
|
||||
@@ -139,6 +142,7 @@ static void hardware_hotkey(uint16_t key) {
|
||||
case K_FAN_TOGGLE:
|
||||
fan_max = !fan_max;
|
||||
break;
|
||||
#if CONFIG_HAVE_KBLED
|
||||
case K_KBD_BKL:
|
||||
kbled_hotkey_step();
|
||||
break;
|
||||
@@ -158,12 +162,13 @@ static void hardware_hotkey(uint16_t key) {
|
||||
if (acpi_ecos != EC_OS_FULL)
|
||||
kbled_hotkey_toggle();
|
||||
break;
|
||||
#endif // CONFIG_HAVE_KBLED
|
||||
}
|
||||
}
|
||||
|
||||
bool kbscan_press(uint16_t key, bool pressed, uint8_t *layer) {
|
||||
bool kbscan_press(uint16_t key, bool pressed, uint8_t *const layer) {
|
||||
// Wake from sleep on keypress
|
||||
if (pressed && lid_state && (power_state == POWER_STATE_S3)) {
|
||||
if (pressed && (power_state == POWER_STATE_S3)) {
|
||||
pmc_swi();
|
||||
}
|
||||
|
||||
@@ -287,19 +292,18 @@ void kbscan_event(void) {
|
||||
static uint8_t kbscan_layer = 0;
|
||||
uint8_t layer = kbscan_layer;
|
||||
static uint8_t kbscan_last_layer[KM_OUT][KM_IN] = { { 0 } };
|
||||
static bool kbscan_ghost[KM_OUT] = { false };
|
||||
uint8_t matrix_curr[KM_OUT];
|
||||
|
||||
static bool debounce = false;
|
||||
static uint32_t debounce_time = 0;
|
||||
static systick_t debounce_time = 0;
|
||||
|
||||
static bool repeat = false;
|
||||
static uint16_t repeat_key = 0;
|
||||
static uint32_t repeat_key_time = 0;
|
||||
static systick_t repeat_key_time = 0;
|
||||
|
||||
// If debounce complete
|
||||
if (debounce) {
|
||||
uint32_t time = time_get();
|
||||
systick_t time = time_get();
|
||||
if ((time - debounce_time) >= DEBOUNCE_DELAY) {
|
||||
// Debounce time elapsed: Read new state
|
||||
debounce = false;
|
||||
@@ -311,11 +315,15 @@ void kbscan_event(void) {
|
||||
|
||||
// Read the current state of the hardware matrix
|
||||
for (uint8_t i = 0; i < KM_OUT; i++) {
|
||||
kbscan_set_column(i);
|
||||
matrix_curr[i] = kbscan_get_row();
|
||||
if (!lid_state) {
|
||||
// Report all keys as released when lid is closed
|
||||
matrix_curr[i] = 0;
|
||||
} else {
|
||||
kbscan_set_column(i);
|
||||
matrix_curr[i] = kbscan_get_row();
|
||||
}
|
||||
}
|
||||
// Disable reading any keys
|
||||
kbscan_set_column(KBSCAN_MATRIX_NONE);
|
||||
kbscan_disable_reading();
|
||||
|
||||
for (uint8_t i = 0; i < KM_OUT; i++) {
|
||||
uint8_t new = matrix_curr[i];
|
||||
@@ -333,10 +341,8 @@ void kbscan_event(void) {
|
||||
|
||||
// A key was pressed or released
|
||||
for (uint8_t j = 0; j < KM_IN; j++) {
|
||||
// clang-format off
|
||||
bool new_b = new & BIT(j);
|
||||
bool last_b = last & BIT(j);
|
||||
// clang-format on
|
||||
if (new_b != last_b) {
|
||||
bool reset = false;
|
||||
|
||||
@@ -387,10 +393,10 @@ void kbscan_event(void) {
|
||||
}
|
||||
|
||||
kbscan_matrix[i] = new;
|
||||
} else if (new &&repeat_key != 0 && key_should_repeat(repeat_key)) {
|
||||
} else if (new && repeat_key != 0 && key_should_repeat(repeat_key)) {
|
||||
// A key is being pressed
|
||||
uint32_t time = time_get();
|
||||
static uint32_t repeat_start = 0;
|
||||
systick_t time = time_get();
|
||||
static systick_t repeat_start = 0;
|
||||
|
||||
if (!repeat) {
|
||||
if (time < repeat_key_time) {
|
||||
|
@@ -69,7 +69,7 @@ bool keymap_save_config(void) {
|
||||
return flash_read_u16(CONFIG_ADDR) == CONFIG_SIGNATURE;
|
||||
}
|
||||
|
||||
bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) {
|
||||
bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *const value) {
|
||||
if (layer < KM_LAY && output < KM_OUT && input < KM_IN) {
|
||||
if (keymap_fnlock && keymap_is_f_key(output, input))
|
||||
layer ^= 1;
|
||||
|
@@ -18,7 +18,6 @@
|
||||
#include <board/kbscan.h>
|
||||
#include <board/keymap.h>
|
||||
#include <board/lid.h>
|
||||
#include <board/peci.h>
|
||||
#include <board/pmc.h>
|
||||
#include <board/power.h>
|
||||
#include <board/ps2.h>
|
||||
@@ -31,6 +30,10 @@
|
||||
#include <common/version.h>
|
||||
#include <ec/ec.h>
|
||||
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
#include <board/peci.h>
|
||||
#endif
|
||||
|
||||
#ifdef PARALLEL_DEBUG
|
||||
#include <board/parallel.h>
|
||||
#endif // PARALLEL_DEBUG
|
||||
@@ -44,10 +47,10 @@ void serial(void) __interrupt(4) {}
|
||||
void timer_2(void) __interrupt(5) {}
|
||||
|
||||
uint8_t main_cycle = 0;
|
||||
const uint16_t battery_interval = 1000;
|
||||
// update fan speed more frequently for smoother fans
|
||||
// NOTE: event loop is longer than 100ms and maybe even longer than 250
|
||||
const uint16_t fan_interval = SMOOTH_FANS != 0 ? 250 : 1000;
|
||||
|
||||
#define INTERVAL_100MS 100U
|
||||
#define INTERVAL_250MS 250U
|
||||
#define INTERVAL_1SEC 1000U
|
||||
|
||||
void init(void) {
|
||||
// Must happen first
|
||||
@@ -57,7 +60,7 @@ void init(void) {
|
||||
gpio_init();
|
||||
|
||||
// Can happen in any order
|
||||
#if HAVE_DGPU
|
||||
#if CONFIG_HAVE_DGPU
|
||||
dgpu_init();
|
||||
#endif
|
||||
ecpm_init();
|
||||
@@ -73,7 +76,9 @@ void init(void) {
|
||||
kbscan_init();
|
||||
}
|
||||
keymap_init();
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
peci_init();
|
||||
#endif
|
||||
pmc_init();
|
||||
pwm_init();
|
||||
smbus_init();
|
||||
@@ -98,11 +103,14 @@ void main(void) {
|
||||
|
||||
INFO("System76 EC board '%s', version '%s'\n", board(), version());
|
||||
|
||||
uint32_t last_time_battery = 0;
|
||||
uint32_t last_time_fan = 0;
|
||||
systick_t last_time_100ms = 0;
|
||||
systick_t last_time_250ms = 0;
|
||||
systick_t last_time_1sec = 0;
|
||||
|
||||
for (main_cycle = 0;; main_cycle++) {
|
||||
switch (main_cycle % 3U) {
|
||||
// NOTE: Do note use modulo to avoid expensive call to SDCC library
|
||||
// call. (Modulo is optimized for powers of 2, however.)
|
||||
switch (main_cycle & 3U) {
|
||||
case 0:
|
||||
// Handle USB-C events immediately before power states
|
||||
usbpd_event();
|
||||
@@ -126,20 +134,26 @@ void main(void) {
|
||||
}
|
||||
|
||||
if (main_cycle == 0) {
|
||||
uint32_t time = time_get();
|
||||
// Only run the following once per interval
|
||||
if ((time - last_time_fan) >= fan_interval) {
|
||||
last_time_fan = time;
|
||||
systick_t time = time_get();
|
||||
|
||||
// Update fan speeds
|
||||
fan_duty_set(peci_get_fan_duty(), dgpu_get_fan_duty());
|
||||
if ((time - last_time_100ms) >= INTERVAL_100MS) {
|
||||
last_time_100ms = time;
|
||||
|
||||
fan_event();
|
||||
}
|
||||
|
||||
// Only run the following once per interval
|
||||
if ((time - last_time_battery) >= battery_interval) {
|
||||
last_time_battery = time;
|
||||
if ((time - last_time_250ms) >= INTERVAL_250MS) {
|
||||
last_time_250ms = time;
|
||||
|
||||
#if CONFIG_PLATFORM_INTEL
|
||||
peci_read_temp();
|
||||
#endif
|
||||
dgpu_read_temp();
|
||||
}
|
||||
|
||||
if ((time - last_time_1sec) >= INTERVAL_1SEC) {
|
||||
last_time_1sec = time;
|
||||
|
||||
// Updates battery status
|
||||
battery_event();
|
||||
}
|
||||
}
|
||||
|
@@ -19,14 +19,12 @@
|
||||
* nWAIT = KSOH[1]
|
||||
*/
|
||||
|
||||
// clang-format off
|
||||
#define CTL_WRITE BIT(0)
|
||||
#define CTL_DATA BIT(1)
|
||||
#define CTL_RESET BIT(2)
|
||||
#define CTL_ADDR BIT(3)
|
||||
|
||||
#define STS_WAIT BIT(1)
|
||||
// clang-format on
|
||||
|
||||
// Maximum peripheral response time in ms
|
||||
#define PARALLEL_TIMEOUT 10
|
||||
@@ -34,7 +32,7 @@
|
||||
bool parallel_debug = false;
|
||||
|
||||
static bool parallel_wait_peripheral(uint8_t mask, uint8_t value) {
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
|
||||
while ((time_get() - start) < PARALLEL_TIMEOUT) {
|
||||
if ((KSOHGDMRR & mask) == value) {
|
||||
@@ -84,7 +82,7 @@ bool parallel_init(void) {
|
||||
return parallel_wait_peripheral(STS_WAIT, 0);
|
||||
}
|
||||
|
||||
int16_t parallel_write(uint8_t *data, uint16_t length) {
|
||||
int16_t parallel_write(const uint8_t *const data, uint16_t length) {
|
||||
// Assert nWRITE
|
||||
KSIGDAT &= ~CTL_WRITE;
|
||||
|
||||
|
@@ -1,5 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
// PECI information can be found here:
|
||||
// https://www.intel.com/content/dam/www/public/us/en/documents/design-guides/core-i7-lga-2011-guide.pdf
|
||||
|
||||
#include <arch/time.h>
|
||||
#include <board/espi.h>
|
||||
#include <board/fan.h>
|
||||
@@ -11,54 +14,14 @@
|
||||
#include <ec/gpio.h>
|
||||
#include <ec/pwm.h>
|
||||
|
||||
// Fan speed is the lowest requested over HEATUP seconds
|
||||
#ifndef BOARD_HEATUP
|
||||
#define BOARD_HEATUP 4
|
||||
#endif
|
||||
|
||||
static uint8_t FAN_HEATUP[BOARD_HEATUP] = { 0 };
|
||||
|
||||
// Fan speed is the highest HEATUP speed over COOLDOWN seconds
|
||||
#ifndef BOARD_COOLDOWN
|
||||
#define BOARD_COOLDOWN 10
|
||||
#endif
|
||||
|
||||
static uint8_t FAN_COOLDOWN[BOARD_COOLDOWN] = { 0 };
|
||||
|
||||
// Tjunction = 100C for i7-8565U (and probably the same for all WHL-U)
|
||||
#define T_JUNCTION 100
|
||||
|
||||
bool peci_on = false;
|
||||
int16_t peci_temp = 0;
|
||||
|
||||
#define PECI_TEMP(X) ((int16_t)(X))
|
||||
// Tjunction = 100C for i7-8565U (and probably the same for all WHL-U)
|
||||
#define T_JUNCTION ((int16_t)100)
|
||||
|
||||
// clang-format off
|
||||
#define FAN_POINT(T, D) { .temp = PECI_TEMP(T), .duty = PWM_DUTY(D) }
|
||||
// clang-format on
|
||||
|
||||
// Fan curve with temperature in degrees C, duty cycle in percent
|
||||
static struct FanPoint __code FAN_POINTS[] = {
|
||||
#ifdef BOARD_FAN_POINTS
|
||||
BOARD_FAN_POINTS
|
||||
#else
|
||||
FAN_POINT(70, 40),
|
||||
FAN_POINT(75, 50),
|
||||
FAN_POINT(80, 60),
|
||||
FAN_POINT(85, 65),
|
||||
FAN_POINT(90, 65)
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct Fan __code FAN = {
|
||||
.points = FAN_POINTS,
|
||||
.points_size = ARRAY_SIZE(FAN_POINTS),
|
||||
.heatup = FAN_HEATUP,
|
||||
.heatup_size = ARRAY_SIZE(FAN_HEATUP),
|
||||
.cooldown = FAN_COOLDOWN,
|
||||
.cooldown_size = ARRAY_SIZE(FAN_COOLDOWN),
|
||||
.interpolate = SMOOTH_FANS != 0,
|
||||
};
|
||||
// Maximum OOB channel response time in ms
|
||||
#define PECI_ESPI_TIMEOUT 10
|
||||
|
||||
// Returns true if peci is available
|
||||
bool peci_available(void) {
|
||||
@@ -81,7 +44,7 @@ bool peci_available(void) {
|
||||
|
||||
// If VW_HOST_C10 virtual wire is VWS_HIGH, PECI will wake the CPU
|
||||
//TODO: wake CPU every 8 seconds following Intel recommendation?
|
||||
return (vw_get(&VW_HOST_C10) != VWS_HIGH);
|
||||
return vw_get(&VW_HOST_C10) != VWS_HIGH;
|
||||
#else
|
||||
// PECI is available if PLTRST# is high
|
||||
return gpio_get(&BUF_PLT_RST_N);
|
||||
@@ -90,13 +53,10 @@ bool peci_available(void) {
|
||||
|
||||
#if CONFIG_PECI_OVER_ESPI
|
||||
|
||||
// Maximum OOB channel response time in ms
|
||||
#define PECI_ESPI_TIMEOUT 10
|
||||
|
||||
void peci_init(void) {}
|
||||
|
||||
// Returns true on success, false on error
|
||||
bool peci_get_temp(int16_t *data) {
|
||||
bool peci_get_temp(int16_t *const data) {
|
||||
//TODO: Wait for completion?
|
||||
// Clear upstream status
|
||||
ESUCTRL0 = ESUCTRL0;
|
||||
@@ -124,8 +84,8 @@ bool peci_get_temp(int16_t *data) {
|
||||
UDB[5] = 1;
|
||||
// PECI read length
|
||||
UDB[6] = 2;
|
||||
// PECI command (0x01 = GetTemp)
|
||||
UDB[7] = 0x01;
|
||||
// PECI command
|
||||
UDB[7] = PECI_CMD_GET_TEMP;
|
||||
|
||||
// Set upstream enable
|
||||
ESUCTRL0 |= ESUCTRL0_ENABLE;
|
||||
@@ -133,7 +93,7 @@ bool peci_get_temp(int16_t *data) {
|
||||
ESUCTRL0 |= ESUCTRL0_GO;
|
||||
|
||||
// Wait until upstream done
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
while (!(ESUCTRL0 & ESUCTRL0_DONE)) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("peci_get_temp: upstream timeout\n");
|
||||
@@ -161,9 +121,12 @@ bool peci_get_temp(int16_t *data) {
|
||||
// Received enough data for temperature
|
||||
uint8_t low = PUTOOBDB[5];
|
||||
uint8_t high = PUTOOBDB[6];
|
||||
*data = (((int16_t)high << 8) | (int16_t)low);
|
||||
int16_t offset = (((int16_t)high << 8) | (int16_t)low);
|
||||
*data = T_JUNCTION + (offset >> 6);
|
||||
|
||||
// Clear PUT_OOB status
|
||||
ESOCTRL0 = ESOCTRL0_STATUS;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// Did not receive enough data
|
||||
@@ -204,8 +167,8 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
UDB[5] = 10;
|
||||
// PECI read length
|
||||
UDB[6] = 1;
|
||||
// PECI command (0xA5 = WrPkgConfig)
|
||||
UDB[7] = 0xA5;
|
||||
// PECI command
|
||||
UDB[7] = PECI_CMD_WR_PKG_CONFIG;
|
||||
|
||||
// Write host ID
|
||||
UDB[8] = 0;
|
||||
@@ -226,7 +189,7 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
ESUCTRL0 |= ESUCTRL0_GO;
|
||||
|
||||
// Wait until upstream done
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
while (!(ESUCTRL0 & ESUCTRL0_DONE)) {
|
||||
DEBUG("peci_wr_pkg_config: wait upstream\n");
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
@@ -289,9 +252,16 @@ void peci_init(void) {
|
||||
}
|
||||
|
||||
// Returns true on success, false on error
|
||||
bool peci_get_temp(int16_t *data) {
|
||||
bool peci_get_temp(int16_t *const data) {
|
||||
// Wait for any in-progress transaction to complete
|
||||
while (HOSTAR & BIT(0)) {}
|
||||
systick_t start = time_get();
|
||||
while (HOSTAR & BIT(0)) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("%s: host timeout\n", __func__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear status
|
||||
HOSTAR = HOSTAR;
|
||||
|
||||
@@ -304,12 +274,18 @@ bool peci_get_temp(int16_t *data) {
|
||||
// Set read length
|
||||
HORDLR = 2;
|
||||
// Set command
|
||||
HOCMDR = 1;
|
||||
HOCMDR = PECI_CMD_GET_TEMP;
|
||||
// Start transaction
|
||||
HOCTLR |= 1;
|
||||
|
||||
// Wait for command completion
|
||||
while (!(HOSTAR & BIT(1))) {}
|
||||
start = time_get();
|
||||
while (!(HOSTAR & BIT(1))) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("%s: command timeout\n", __func__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t status = HOSTAR;
|
||||
if (status & 0xEC) {
|
||||
@@ -317,23 +293,31 @@ bool peci_get_temp(int16_t *data) {
|
||||
// Clear status
|
||||
HOSTAR = HOSTAR;
|
||||
return false;
|
||||
} else {
|
||||
// Read two byte temperature data if finished successfully
|
||||
uint8_t low = HORDDR;
|
||||
uint8_t high = HORDDR;
|
||||
*data = (((int16_t)high << 8) | (int16_t)low);
|
||||
|
||||
// Clear status
|
||||
HOSTAR = HOSTAR;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Read two byte temperature data if finished successfully
|
||||
uint8_t low = HORDDR;
|
||||
uint8_t high = HORDDR;
|
||||
int16_t offset = (((int16_t)high << 8) | (int16_t)low);
|
||||
*data = T_JUNCTION + (offset >> 6);
|
||||
|
||||
// Clear status
|
||||
HOSTAR = HOSTAR;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns positive completion code on success, negative completion code or
|
||||
// negative (0x1000 | status register) on PECI hardware error
|
||||
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
// Wait for any in-progress transaction to complete
|
||||
while (HOSTAR & BIT(0)) {}
|
||||
systick_t start = time_get();
|
||||
while (HOSTAR & BIT(0)) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("%s: host timeout\n", __func__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear status
|
||||
HOSTAR = HOSTAR;
|
||||
|
||||
@@ -346,7 +330,7 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
// Set read length
|
||||
HORDLR = 1;
|
||||
// Set command
|
||||
HOCMDR = 0xA5;
|
||||
HOCMDR = PECI_CMD_WR_PKG_CONFIG;
|
||||
|
||||
// Write host ID
|
||||
HOWRDR = 0;
|
||||
@@ -365,7 +349,13 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
HOCTLR |= 1;
|
||||
|
||||
// Wait for command completion
|
||||
while (!(HOSTAR & BIT(1))) {}
|
||||
start = time_get();
|
||||
while (!(HOSTAR & BIT(1))) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("%s: command timeout\n", __func__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t status = HOSTAR;
|
||||
if (status & 0xEC) {
|
||||
@@ -391,37 +381,13 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
|
||||
#endif // CONFIG_PECI_OVER_ESPI
|
||||
|
||||
// PECI information can be found here: https://www.intel.com/content/dam/www/public/us/en/documents/design-guides/core-i7-lga-2011-guide.pdf
|
||||
uint8_t peci_get_fan_duty(void) {
|
||||
uint8_t duty;
|
||||
|
||||
void peci_read_temp(void) {
|
||||
peci_on = peci_available();
|
||||
if (peci_on) {
|
||||
int16_t peci_offset = 0;
|
||||
if (peci_get_temp(&peci_offset)) {
|
||||
// Use result if finished successfully
|
||||
peci_temp = PECI_TEMP(T_JUNCTION) + (peci_offset >> 6);
|
||||
duty = fan_duty(&FAN, peci_temp);
|
||||
} else {
|
||||
// Default to 50% if there is an error
|
||||
peci_temp = 0;
|
||||
duty = PWM_DUTY(50);
|
||||
if (peci_get_temp(&peci_temp)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Turn fan off if not in S0 state
|
||||
peci_temp = 0;
|
||||
duty = PWM_DUTY(0);
|
||||
}
|
||||
|
||||
if (peci_on && fan_max) {
|
||||
// Override duty if fans are manually set to maximum
|
||||
duty = PWM_DUTY(100);
|
||||
} else {
|
||||
// Apply heatup and cooldown filters to duty
|
||||
duty = fan_heatup(&FAN, duty);
|
||||
duty = fan_cooldown(&FAN, duty);
|
||||
}
|
||||
|
||||
TRACE("PECI temp=%d\n", peci_temp);
|
||||
return duty;
|
||||
peci_temp = 0;
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ static void pmc_sci_interrupt(void) {
|
||||
#endif // CONFIG_BUS_ESPI
|
||||
}
|
||||
|
||||
bool pmc_sci(struct Pmc *pmc, uint8_t sci) {
|
||||
bool pmc_sci(struct Pmc *const pmc, uint8_t sci) {
|
||||
// Set SCI pending bit
|
||||
pmc_set_status(pmc, pmc_status(pmc) | BIT(5));
|
||||
|
||||
@@ -101,7 +101,7 @@ void pmc_swi(void) {
|
||||
static enum PmcState state = PMC_STATE_DEFAULT;
|
||||
static uint8_t state_data = 0;
|
||||
|
||||
static void pmc_on_input_command(struct Pmc *pmc, uint8_t data) {
|
||||
static void pmc_on_input_command(struct Pmc *const pmc, uint8_t data) {
|
||||
TRACE("pmc cmd: %02X\n", data);
|
||||
state = PMC_STATE_DEFAULT;
|
||||
switch (data) {
|
||||
@@ -169,7 +169,7 @@ static void pmc_on_input_data(uint8_t data) {
|
||||
}
|
||||
}
|
||||
|
||||
static void pmc_on_output_empty(struct Pmc *pmc) {
|
||||
static void pmc_on_output_empty(struct Pmc *const pmc) {
|
||||
switch (state) {
|
||||
case PMC_STATE_WRITE:
|
||||
TRACE("pmc write: %02X\n", state_data);
|
||||
@@ -181,7 +181,7 @@ static void pmc_on_output_empty(struct Pmc *pmc) {
|
||||
}
|
||||
}
|
||||
|
||||
void pmc_event(struct Pmc *pmc) {
|
||||
void pmc_event(struct Pmc *const pmc) {
|
||||
uint8_t sts;
|
||||
|
||||
// Read command/data if available
|
||||
|
@@ -13,22 +13,29 @@ volatile uint8_t __xdata __at(0x1204) IBMAE;
|
||||
volatile uint8_t __xdata __at(0x1205) IBCTL;
|
||||
|
||||
uint8_t ec2i_read(uint8_t port) {
|
||||
uint8_t ihd;
|
||||
|
||||
while (IBCTL & (BIT(2) | BIT(1))) {}
|
||||
IBCTL = 1;
|
||||
IBMAE = 1;
|
||||
IHIOA = port;
|
||||
IBCTL |= BIT(1);
|
||||
IBMAE = BIT(0);
|
||||
IBCTL = BIT(1);
|
||||
IBCTL |= BIT(0);
|
||||
while (IBCTL & BIT(1)) {}
|
||||
return IHD;
|
||||
ihd = IHD;
|
||||
IBMAE = 0;
|
||||
IBCTL = 0;
|
||||
return ihd;
|
||||
}
|
||||
|
||||
void ec2i_write(uint8_t port, uint8_t data) {
|
||||
while (IBCTL & (BIT(2) | BIT(1))) {}
|
||||
IBCTL = 1;
|
||||
IBMAE = 1;
|
||||
IHIOA = port;
|
||||
IHD = data;
|
||||
IBMAE = BIT(0);
|
||||
IBCTL = BIT(0);
|
||||
while (IBCTL & BIT(2)) {}
|
||||
IBMAE = 0;
|
||||
IBCTL = 0;
|
||||
}
|
||||
|
||||
uint8_t pnp_read(uint8_t reg) {
|
||||
@@ -41,7 +48,7 @@ void pnp_write(uint8_t reg, uint8_t data) {
|
||||
ec2i_write(0x2F, data);
|
||||
}
|
||||
|
||||
void pnp_enable() {
|
||||
void pnp_enable(void) {
|
||||
DEBUG("Enable PNP devices\n");
|
||||
|
||||
// Enable PMC1
|
||||
|
12
src/board/system76/common/power/amd.c
Normal file
12
src/board/system76/common/power/amd.c
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/power.h>
|
||||
|
||||
enum PowerState power_state = POWER_STATE_OFF;
|
||||
|
||||
void update_power_state(void) {}
|
||||
void power_init(void) {}
|
||||
void power_on(void) {}
|
||||
void power_off(void) {}
|
||||
void power_cpu_reset(void) {}
|
||||
void power_event(void) {}
|
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/power.h>
|
||||
|
||||
#include <arch/delay.h>
|
||||
#include <arch/time.h>
|
||||
#include <board/acpi.h>
|
||||
@@ -12,7 +14,6 @@
|
||||
#include <board/kbled.h>
|
||||
#include <board/lid.h>
|
||||
#include <board/peci.h>
|
||||
#include <board/power.h>
|
||||
#include <board/pmc.h>
|
||||
#include <board/pnp.h>
|
||||
#include <board/wireless.h>
|
||||
@@ -491,7 +492,6 @@ void power_event(void) {
|
||||
}
|
||||
pg_last = pg_new;
|
||||
|
||||
// clang-format off
|
||||
static bool rst_last = false;
|
||||
bool rst_new = gpio_get(&BUF_PLT_RST_N);
|
||||
#if LEVEL >= LEVEL_DEBUG
|
||||
@@ -508,7 +508,6 @@ void power_event(void) {
|
||||
#endif // CONFIG_BUS_ESPI
|
||||
}
|
||||
rst_last = rst_new;
|
||||
// clang-format on
|
||||
|
||||
#if HAVE_SLP_SUS_N
|
||||
#if LEVEL >= LEVEL_DEBUG
|
||||
@@ -574,8 +573,8 @@ void power_event(void) {
|
||||
wake_last = wake_new;
|
||||
#endif // HAVE_LAN_WAKEUP_N
|
||||
|
||||
static uint32_t last_time = 0;
|
||||
uint32_t time = time_get();
|
||||
static systick_t last_time = 0;
|
||||
systick_t time = time_get();
|
||||
if (power_state == POWER_STATE_S0) {
|
||||
#if CONFIG_BUS_ESPI
|
||||
// HOST_C10 virtual wire is high when CPU is in C10 sleep state
|
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/pwm.h>
|
||||
#include <ec/pwm.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
void pwm_init(void) {
|
||||
@@ -23,8 +24,11 @@ void pwm_init(void) {
|
||||
// Set cycle time to 255 + 1
|
||||
CTR0 = 255;
|
||||
|
||||
// Turn off CPU fan (temperature control in peci_get_fan_duty)
|
||||
DCR2 = 0;
|
||||
// Turn off fans
|
||||
FAN1_PWM = 0;
|
||||
#ifdef FAN2_PWM
|
||||
FAN2_PWM = 0;
|
||||
#endif
|
||||
|
||||
#if CONFIG_EC_ITE_IT5570E || CONFIG_EC_ITE_IT5571E
|
||||
// Reload counters when they reach 0 instead of immediately
|
||||
|
@@ -1,14 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <8051.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <board/dgpu.h>
|
||||
#include <board/fan.h>
|
||||
#include <board/smfi.h>
|
||||
#include <common/macro.h>
|
||||
#include <ec/pwm.h>
|
||||
#include <ec/scratch.h>
|
||||
|
||||
#include <8051.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Include scratch ROM
|
||||
uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = {
|
||||
#include <scratch.h>
|
||||
@@ -17,9 +18,9 @@ uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = {
|
||||
// Enter or exit scratch ROM
|
||||
void scratch_trampoline(void) {
|
||||
// Set fans to 100%
|
||||
DCR2 = 0xFF;
|
||||
#if HAVE_DGPU
|
||||
DCR4 = 0xFF;
|
||||
FAN1_PWM = CTR0;
|
||||
#ifdef FAN2_PWM
|
||||
FAN2_PWM = CTR0;
|
||||
#endif
|
||||
|
||||
//TODO: Clear keyboard presses
|
||||
|
@@ -32,25 +32,25 @@ SCRATCH_CC=\
|
||||
|
||||
# Convert from binary file to C header
|
||||
$(BUILD)/include/scratch.h: $(SCRATCH_BUILD)/scratch.rom
|
||||
@echo " XXD $(subst $(obj)/,,$@)"
|
||||
@echo " XXD $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
xxd -include < $< > $@
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(SCRATCH_BUILD)/scratch.rom: $(SCRATCH_BUILD)/scratch.ihx
|
||||
@echo " OBJCOPY $(subst $(obj)/,,$@)"
|
||||
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
objcopy -I ihex -O binary $< $@
|
||||
|
||||
# Link object files into Intel Hex file
|
||||
$(SCRATCH_BUILD)/scratch.ihx: $(SCRATCH_OBJ)
|
||||
@echo " LINK $(subst $(obj)/,,$@)"
|
||||
@echo " LINK $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(SCRATCH_CC) -o $@ $^
|
||||
|
||||
# Compile C files into object files
|
||||
$(SCRATCH_OBJ): $(SCRATCH_BUILD)/%.rel: src/%.c $(SCRATCH_INCLUDE)
|
||||
@echo " CC $(subst $(obj)/,,$@)"
|
||||
@echo " CC $(subst $(BUILD)/,,$@)"
|
||||
mkdir -p $(@D)
|
||||
$(SCRATCH_CC) $(SCRATCH_CFLAGS) -o $@ -c $<
|
||||
|
||||
|
@@ -11,7 +11,7 @@ enum SecurityState security_get(void) {
|
||||
|
||||
bool security_set(enum SecurityState state) {
|
||||
switch (state) {
|
||||
// Allow perpare states to be set
|
||||
// Allow prepare states to be set
|
||||
case SECURITY_STATE_PREPARE_LOCK:
|
||||
case SECURITY_STATE_PREPARE_UNLOCK:
|
||||
security_state = state;
|
||||
|
@@ -22,10 +22,10 @@ void smbus_init(void) {
|
||||
i2c_reset(&I2C_SMBUS, true);
|
||||
}
|
||||
|
||||
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *data) {
|
||||
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2);
|
||||
int16_t smbus_read(uint8_t address, uint8_t command, uint16_t *const data) {
|
||||
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *const)data, 2);
|
||||
}
|
||||
|
||||
int16_t smbus_write(uint8_t address, uint8_t command, uint16_t data) {
|
||||
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2);
|
||||
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *const)&data, 2);
|
||||
}
|
||||
|
@@ -13,27 +13,29 @@
|
||||
// the command is complete and the result is available. The client should only
|
||||
// read the SMFI_CMD_RES value when SMFI_CMD_CMD is set to CMD_NONE.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <board/smfi.h>
|
||||
|
||||
#if !defined(__SCRATCH__)
|
||||
#include <board/scratch.h>
|
||||
#include <board/fan.h>
|
||||
#include <board/kbled.h>
|
||||
#include <board/kbscan.h>
|
||||
#include <board/scratch.h>
|
||||
|
||||
#if CONFIG_SECURITY
|
||||
#include <board/security.h>
|
||||
#endif // CONFIG_SECURITY
|
||||
|
||||
#endif // !defined(__SCRATCH__)
|
||||
#include <board/smfi.h>
|
||||
|
||||
#include <common/command.h>
|
||||
#include <common/macro.h>
|
||||
#include <common/version.h>
|
||||
#include <ec/etwd.h>
|
||||
#include <ec/pwm.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// Shared memory host semaphore
|
||||
volatile uint8_t __xdata __at(0x1022) SMHSR;
|
||||
// Host RAM window control
|
||||
@@ -123,15 +125,14 @@ static enum Result cmd_print(void) {
|
||||
|
||||
static enum Result cmd_fan_get(void) {
|
||||
switch (smfi_cmd[SMFI_CMD_DATA]) {
|
||||
case 0:
|
||||
// Get duty of fan 0
|
||||
smfi_cmd[SMFI_CMD_DATA + 1] = DCR2;
|
||||
return RES_OK;
|
||||
case 1:
|
||||
// Get duty of fan 1
|
||||
//TODO: only allow on platforms like addw2
|
||||
smfi_cmd[SMFI_CMD_DATA + 1] = DCR4;
|
||||
smfi_cmd[SMFI_CMD_DATA + 1] = fan1_pwm_actual;
|
||||
return RES_OK;
|
||||
#ifdef FAN2_PWM
|
||||
case 2:
|
||||
smfi_cmd[SMFI_CMD_DATA + 1] = fan2_pwm_actual;
|
||||
return RES_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Failed if fan not found
|
||||
@@ -140,15 +141,16 @@ static enum Result cmd_fan_get(void) {
|
||||
|
||||
static enum Result cmd_fan_set(void) {
|
||||
switch (smfi_cmd[SMFI_CMD_DATA]) {
|
||||
case 0:
|
||||
// Set duty cycle of fan 0
|
||||
DCR2 = smfi_cmd[SMFI_CMD_DATA + 1];
|
||||
return RES_OK;
|
||||
case 1:
|
||||
// Set duty cycle of fan 1
|
||||
//TODO: only allow on platforms like addw2
|
||||
DCR4 = smfi_cmd[SMFI_CMD_DATA + 1];
|
||||
// Set duty cycle of FAN1
|
||||
fan1_pwm_target = smfi_cmd[SMFI_CMD_DATA + 1];
|
||||
return RES_OK;
|
||||
#ifdef FAN2_PWM
|
||||
case 2:
|
||||
// Set duty cycle of FAN2
|
||||
fan2_pwm_target = smfi_cmd[SMFI_CMD_DATA + 1];
|
||||
return RES_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Failed if fan not found
|
||||
@@ -241,9 +243,7 @@ static enum Result cmd_matrix_get(void) {
|
||||
smfi_cmd[SMFI_CMD_DATA] = KM_OUT;
|
||||
smfi_cmd[SMFI_CMD_DATA + 1] = KM_IN;
|
||||
for (uint8_t row = 0; row < KM_OUT; row++) {
|
||||
if ((SMFI_CMD_DATA + 2 + row) < ARRAY_SIZE(smfi_cmd)) {
|
||||
smfi_cmd[SMFI_CMD_DATA + 2 + row] = kbscan_matrix[row];
|
||||
}
|
||||
smfi_cmd[SMFI_CMD_DATA + 2 + row] = kbscan_matrix[row];
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/usbpd.h>
|
||||
|
||||
void usbpd_init(void) {}
|
||||
|
||||
void usbpd_event(void) {}
|
||||
|
||||
void usbpd_disable_charging(void) {}
|
||||
|
||||
void usbpd_enable_charging(void) {}
|
@@ -69,7 +69,7 @@ static int16_t usbpd_current_limit(void) {
|
||||
}
|
||||
|
||||
static void usbpd_dump(void) {
|
||||
/* Dump all registers for debugging */
|
||||
// Dump all registers for debugging
|
||||
for (uint8_t reg = 0x00; reg < 0x40; reg += 1) {
|
||||
uint8_t value[65] = { 0 };
|
||||
int16_t res = i2c_get(&I2C_USBPD, USBPD_ADDRESS, reg, value, sizeof(value));
|
||||
|
23
src/board/system76/darp10-b/board.c
Normal file
23
src/board/system76/darp10-b/board.c
Normal file
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/board.h>
|
||||
#include <board/battery.h>
|
||||
#include <board/gpio.h>
|
||||
#include <board/espi.h>
|
||||
#include <ec/ec.h>
|
||||
|
||||
void board_init(void) {
|
||||
espi_init();
|
||||
battery_charger_disable();
|
||||
|
||||
// Allow backlight to be turned on
|
||||
gpio_set(&BKL_EN, true);
|
||||
// Enable camera
|
||||
gpio_set(&CCD_EN, true);
|
||||
}
|
||||
|
||||
void board_event(void) {
|
||||
espi_event();
|
||||
|
||||
ec_read_post_codes();
|
||||
}
|
73
src/board/system76/darp10-b/board.mk
Normal file
73
src/board/system76/darp10-b/board.mk
Normal file
@@ -0,0 +1,73 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
board-y += board.c
|
||||
board-y += gpio.c
|
||||
|
||||
EC = ite
|
||||
CONFIG_EC_ITE_IT5570E = y
|
||||
CONFIG_EC_FLASH_SIZE_256K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
CONFIG_BUS_ESPI = y
|
||||
|
||||
# Enable firmware security
|
||||
CONFIG_SECURITY = y
|
||||
|
||||
# Keyboard configuration
|
||||
KEYBOARD = 14in_83
|
||||
KEYMAP = darp10-b
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED = white_dac
|
||||
CFLAGS += -DKBLED_DAC=2
|
||||
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS += -DI2C_SMBUS=I2C_4
|
||||
|
||||
# Set touchpad PS2 bus
|
||||
CFLAGS += -DPS2_TOUCHPAD=PS2_3
|
||||
|
||||
# Set smart charger parameters
|
||||
CHARGER = oz26786
|
||||
CFLAGS += \
|
||||
-DCHARGER_ADAPTER_RSENSE=5 \
|
||||
-DCHARGER_BATTERY_RSENSE=10 \
|
||||
-DCHARGER_CHARGE_CURRENT=1536 \
|
||||
-DCHARGER_CHARGE_VOLTAGE=17600 \
|
||||
-DCHARGER_INPUT_CURRENT=4740
|
||||
|
||||
# Set CPU power limits in watts
|
||||
CFLAGS += \
|
||||
-DPOWER_LIMIT_AC=65 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DFAN1_PWM_MIN=27
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(48, 27), \
|
||||
FAN_POINT(52, 27), \
|
||||
FAN_POINT(56, 33), \
|
||||
FAN_POINT(60, 37), \
|
||||
FAN_POINT(75, 53), \
|
||||
FAN_POINT(83, 65), \
|
||||
FAN_POINT(87, 75), \
|
||||
FAN_POINT(89, 77), \
|
||||
"
|
||||
|
||||
CFLAGS += -DFAN2_PWM=DCR3
|
||||
CFLAGS += -DFAN2_PWM_MIN=27
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(48, 27), \
|
||||
FAN_POINT(52, 27), \
|
||||
FAN_POINT(56, 33), \
|
||||
FAN_POINT(60, 37), \
|
||||
FAN_POINT(75, 53), \
|
||||
FAN_POINT(83, 65), \
|
||||
FAN_POINT(87, 75), \
|
||||
FAN_POINT(89, 77), \
|
||||
"
|
||||
|
||||
# Add common code
|
||||
include src/board/system76/common/common.mk
|
262
src/board/system76/darp10-b/gpio.c
Normal file
262
src/board/system76/darp10-b/gpio.c
Normal file
@@ -0,0 +1,262 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(F, 7);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
struct Gpio __code BKL_EN = GPIO(C, 7);
|
||||
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2); // renamed to ESPI_RESET#
|
||||
struct Gpio __code CCD_EN = GPIO(D, 1);
|
||||
struct Gpio __code DD_ON = GPIO(E, 4);
|
||||
struct Gpio __code EC_EN = GPIO(B, 6); // renamed to SUSBC_EC
|
||||
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
|
||||
struct Gpio __code LAN_WAKEUP_N = GPIO(B, 2);
|
||||
struct Gpio __code LED_ACIN = GPIO(H, 2);
|
||||
struct Gpio __code LED_BAT_CHG = GPIO(H, 5);
|
||||
struct Gpio __code LED_BAT_FULL = GPIO(J, 0);
|
||||
struct Gpio __code LED_PWR = GPIO(D, 0);
|
||||
struct Gpio __code LID_SW_N = GPIO(B, 1);
|
||||
struct Gpio __code ME_WE = GPIO(E, 6);
|
||||
struct Gpio __code PCH_PWROK_EC = GPIO(F, 3);
|
||||
struct Gpio __code PD_EN = GPIO(D, 4); // renamed to PD_POWER_EN
|
||||
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
|
||||
struct Gpio __code PWR_SW_N = GPIO(B, 3);
|
||||
struct Gpio __code RGBKB_DET_N = GPIO(I, 2);
|
||||
struct Gpio __code SLP_S0_N = GPIO(B, 5);
|
||||
struct Gpio __code SUSB_N_PCH = GPIO(H, 0);
|
||||
struct Gpio __code SUSC_N_PCH = GPIO(H, 1);
|
||||
struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(E, 1);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
GCR8 = BIT(4);
|
||||
|
||||
// Enable LPC reset on GPD2
|
||||
GCR = 0b10 << 1;
|
||||
// Disable UARTs
|
||||
GCR6 = 0;
|
||||
// Enable SMBus channel 4
|
||||
GCR15 = BIT(4);
|
||||
// Set GPB5 and GPD2 to 1.8V
|
||||
GCR19 = BIT(7) | BIT(0);
|
||||
// Set GPD3 to 1.8V, GPF2 and GPF3 to 3.3V
|
||||
GCR20 = BIT(7);
|
||||
// Set GPF7, GPH0, and GPH1 to 1.8V
|
||||
GCR21 = BIT(5) | BIT(2) | BIT(1);
|
||||
// Not documented
|
||||
GCR22 = BIT(7);
|
||||
// Set GPM6 power domain to VCC
|
||||
GCR23 = BIT(0);
|
||||
|
||||
// Set GPIO data
|
||||
GPDRA = 0;
|
||||
// XLP_OUT, PWR_SW#
|
||||
GPDRB = BIT(4) | BIT(3);
|
||||
GPDRC = 0;
|
||||
// PWR_BTN#
|
||||
GPDRD = BIT(5);
|
||||
// USB_PWR_EN
|
||||
GPDRE = BIT(3);
|
||||
// H_PECI
|
||||
GPDRF = BIT(6);
|
||||
// H_PROCHOT_EC
|
||||
GPDRG = BIT(6);
|
||||
GPDRH = 0;
|
||||
GPDRI = 0;
|
||||
// KBC_MUTE#
|
||||
GPDRJ = BIT(1);
|
||||
GPDRM = 0;
|
||||
|
||||
// Set GPIO control
|
||||
|
||||
// EC_PWM_LEDKB_P
|
||||
GPCRA0 = GPIO_ALT;
|
||||
// KBC_BEEP (NC)
|
||||
GPCRA1 = GPIO_IN;
|
||||
// CPU_FAN1
|
||||
GPCRA2 = GPIO_ALT;
|
||||
// CPU_FAN2
|
||||
GPCRA3 = GPIO_ALT;
|
||||
// NC
|
||||
GPCRA4 = GPIO_IN;
|
||||
// EC_PWM_LEDKB_R
|
||||
GPCRA5 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_G
|
||||
GPCRA6 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_B
|
||||
GPCRA7 = GPIO_ALT;
|
||||
|
||||
// AC_IN#
|
||||
GPCRB0 = GPIO_IN | GPIO_UP;
|
||||
// LID_SW#
|
||||
GPCRB1 = GPIO_IN | GPIO_UP;
|
||||
// EC_LAN_WAKEUP#
|
||||
GPCRB2 = GPIO_IN | GPIO_UP;
|
||||
// PWR_SW#
|
||||
GPCRB3 = GPIO_IN;
|
||||
// XLP_OUT
|
||||
GPCRB4 = GPIO_OUT;
|
||||
// SLP_S0#
|
||||
GPCRB5 = GPIO_IN;
|
||||
// SUSBC_EC
|
||||
GPCRB6 = GPIO_OUT;
|
||||
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
// SMC_VGA_THERM
|
||||
GPCRC1 = GPIO_ALT | GPIO_UP;
|
||||
// SMD_VGA_THERM
|
||||
GPCRC2 = GPIO_ALT | GPIO_UP;
|
||||
// KB-SO16
|
||||
GPCRC3 = GPIO_ALT | GPIO_UP;
|
||||
// CNVI_DET#
|
||||
GPCRC4 = GPIO_IN | GPIO_UP;
|
||||
// KB-SO17
|
||||
GPCRC5 = GPIO_ALT | GPIO_UP;
|
||||
// JACK_IN#_EC
|
||||
GPCRC6 = GPIO_IN;
|
||||
// BKL_EN
|
||||
GPCRC7 = GPIO_OUT;
|
||||
|
||||
// LED_PWR
|
||||
GPCRD0 = GPIO_OUT;
|
||||
// CCD_EN
|
||||
GPCRD1 = GPIO_OUT;
|
||||
// ESPI_RESET_N
|
||||
GPCRD2 = GPIO_ALT;
|
||||
// SLP_A#
|
||||
GPCRD3 = GPIO_IN;
|
||||
// PD_POWER_EN
|
||||
GPCRD4 = GPIO_OUT;
|
||||
// PWR_BTN#
|
||||
GPCRD5 = GPIO_OUT;
|
||||
// CPU_FANSEN1
|
||||
GPCRD6 = GPIO_ALT;
|
||||
// CPU_FANSEN2
|
||||
GPCRD7 = GPIO_ALT;
|
||||
|
||||
// SMC_BAT
|
||||
GPCRE0 = GPIO_ALT | GPIO_UP;
|
||||
// WLAN_PWR_EN
|
||||
GPCRE1 = GPIO_OUT;
|
||||
// TBT_I2C_IRQ2Z
|
||||
GPCRE2 = GPIO_IN;
|
||||
// USB_PWR_EN
|
||||
GPCRE3 = GPIO_OUT;
|
||||
// DD_ON
|
||||
GPCRE4 = GPIO_OUT;
|
||||
// EC_RSMRST#
|
||||
GPCRE5 = GPIO_OUT;
|
||||
// ME_WE
|
||||
GPCRE6 = GPIO_OUT;
|
||||
// SMD_BAT
|
||||
GPCRE7 = GPIO_ALT | GPIO_UP;
|
||||
|
||||
// 80CLK
|
||||
GPCRF0 = GPIO_IN;
|
||||
// USB_CHARGE_EN
|
||||
GPCRF1 = GPIO_OUT;
|
||||
// 3IN1
|
||||
GPCRF2 = GPIO_IN;
|
||||
// PCH_PWROK_EC
|
||||
GPCRF3 = GPIO_OUT;
|
||||
// TP_CLK
|
||||
GPCRF4 = GPIO_ALT | GPIO_UP;
|
||||
// TP_DATA
|
||||
GPCRF5 = GPIO_ALT | GPIO_UP;
|
||||
// H_PECI
|
||||
GPCRF6 = GPIO_ALT;
|
||||
// AC_PRESENT
|
||||
GPCRF7 = GPIO_OUT;
|
||||
|
||||
// NC
|
||||
GPCRG0 = GPIO_IN;
|
||||
// NC
|
||||
GPCRG1 = GPIO_IN;
|
||||
// 100k pull-up to VDD3
|
||||
GPCRG2 = GPIO_IN;
|
||||
// HSPI_CE#
|
||||
GPCRG3 = GPIO_ALT;
|
||||
// HSPI_MSI
|
||||
GPCRG4 = GPIO_ALT;
|
||||
// HSPI_MSO
|
||||
GPCRG5 = GPIO_ALT;
|
||||
// H_PROCHOT_EC
|
||||
GPCRG6 = GPIO_OUT;
|
||||
// HSPI_SCLK
|
||||
GPCRG7 = GPIO_ALT;
|
||||
|
||||
// SUSB#_PCH
|
||||
GPCRH0 = GPIO_IN;
|
||||
// SUSC#_PCH
|
||||
GPCRH1 = GPIO_IN;
|
||||
// LED_ACIN
|
||||
GPCRH2 = GPIO_OUT;
|
||||
// NC
|
||||
GPCRH3 = GPIO_IN;
|
||||
// NC
|
||||
GPCRH4 = GPIO_IN;
|
||||
// LED_BAT_CHG
|
||||
GPCRH5 = GPIO_OUT;
|
||||
// NC
|
||||
GPCRH6 = GPIO_IN;
|
||||
// NC
|
||||
GPCRH7 = GPIO_IN;
|
||||
|
||||
// BAT_DET
|
||||
GPCRI0 = GPIO_ALT;
|
||||
// BAT_VOLT
|
||||
GPCRI1 = GPIO_ALT;
|
||||
// RGBKB_DET#
|
||||
GPCRI2 = GPIO_IN | GPIO_UP;
|
||||
// THERM_VOLT
|
||||
GPCRI3 = GPIO_ALT;
|
||||
// TOTAL_CUR
|
||||
GPCRI4 = GPIO_ALT;
|
||||
// EC_CCD_WP#
|
||||
GPCRI5 = GPIO_OUT;
|
||||
// THERM_VOLT2
|
||||
GPCRI6 = GPIO_ALT;
|
||||
// MODEL_ID
|
||||
GPCRI7 = GPIO_IN;
|
||||
|
||||
// LED_BAT_FULL
|
||||
GPCRJ0 = GPIO_OUT;
|
||||
// KBC_MUTE#
|
||||
GPCRJ1 = GPIO_OUT;
|
||||
// KBLIGHT_ADJ
|
||||
GPCRJ2 = GPIO_ALT;
|
||||
// SINK_CTRL_EC_1
|
||||
GPCRJ3 = GPIO_IN;
|
||||
// VA_EC_EN
|
||||
GPCRJ4 = GPIO_OUT;
|
||||
// SINK_CTRL_EC_2
|
||||
GPCRJ5 = GPIO_IN;
|
||||
// EC_GPIO
|
||||
GPCRJ6 = GPIO_OUT;
|
||||
// KB-DET
|
||||
GPCRJ7 = GPIO_IN;
|
||||
|
||||
// ESPI_IO0_EC
|
||||
GPCRM0 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO1_EC
|
||||
GPCRM1 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO2_EC
|
||||
GPCRM2 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO3_EC
|
||||
GPCRM3 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_CLK_EC
|
||||
GPCRM4 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_CS_EC#
|
||||
GPCRM5 = GPIO_ALT;
|
||||
// ESPI_ALRT0#
|
||||
GPCRM6 = GPIO_IN | GPIO_UP | GPIO_DOWN;
|
||||
}
|
47
src/board/system76/darp10-b/include/board/gpio.h
Normal file
47
src/board/system76/darp10-b/include/board/gpio.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#ifndef _BOARD_GPIO_H
|
||||
#define _BOARD_GPIO_H
|
||||
|
||||
#include <ec/gpio.h>
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code ALL_SYS_PWRGD;
|
||||
extern struct Gpio __code BKL_EN;
|
||||
#define HAVE_BT_EN 0
|
||||
extern struct Gpio __code BUF_PLT_RST_N;
|
||||
extern struct Gpio __code CCD_EN;
|
||||
extern struct Gpio __code DD_ON;
|
||||
extern struct Gpio __code EC_EN;
|
||||
extern struct Gpio __code EC_RSMRST_N;
|
||||
extern struct Gpio __code LAN_WAKEUP_N;
|
||||
extern struct Gpio __code LED_ACIN;
|
||||
#define HAVE_LED_AIRPLANE_N 0
|
||||
extern struct Gpio __code LED_BAT_CHG;
|
||||
extern struct Gpio __code LED_BAT_FULL;
|
||||
extern struct Gpio __code LED_PWR;
|
||||
extern struct Gpio __code LID_SW_N;
|
||||
extern struct Gpio __code ME_WE;
|
||||
#define HAVE_PCH_DPWROK_EC 0
|
||||
extern struct Gpio __code PCH_PWROK_EC;
|
||||
#define HAVE_PD_EN 1
|
||||
extern struct Gpio __code PD_EN;
|
||||
#define HAVE_PM_PWROK 0
|
||||
extern struct Gpio __code PWR_BTN_N;
|
||||
extern struct Gpio __code PWR_SW_N;
|
||||
extern struct Gpio __code RGBKB_DET_N;
|
||||
extern struct Gpio __code SLP_S0_N;
|
||||
#define HAVE_SLP_SUS_N 0
|
||||
#define HAVE_SUS_PWR_ACK 0
|
||||
extern struct Gpio __code SUSB_N_PCH;
|
||||
extern struct Gpio __code SUSC_N_PCH;
|
||||
#define HAVE_SUSWARN_N 0
|
||||
extern struct Gpio __code VA_EC_EN;
|
||||
#define HAVE_WLAN_EN 0
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
extern struct Gpio __code XLP_OUT;
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
23
src/board/system76/darp10/board.c
Normal file
23
src/board/system76/darp10/board.c
Normal file
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/board.h>
|
||||
#include <board/battery.h>
|
||||
#include <board/gpio.h>
|
||||
#include <board/espi.h>
|
||||
#include <ec/ec.h>
|
||||
|
||||
void board_init(void) {
|
||||
espi_init();
|
||||
battery_charger_disable();
|
||||
|
||||
// Allow backlight to be turned on
|
||||
gpio_set(&BKL_EN, true);
|
||||
// Enable camera
|
||||
gpio_set(&CCD_EN, true);
|
||||
}
|
||||
|
||||
void board_event(void) {
|
||||
espi_event();
|
||||
|
||||
ec_read_post_codes();
|
||||
}
|
71
src/board/system76/darp10/board.mk
Normal file
71
src/board/system76/darp10/board.mk
Normal file
@@ -0,0 +1,71 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
board-y += board.c
|
||||
board-y += gpio.c
|
||||
|
||||
EC = ite
|
||||
CONFIG_EC_ITE_IT5570E = y
|
||||
CONFIG_EC_FLASH_SIZE_256K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
CONFIG_BUS_ESPI = y
|
||||
|
||||
# Enable firmware security
|
||||
CONFIG_SECURITY = y
|
||||
|
||||
# Keyboard configuration
|
||||
KEYBOARD = 18H9LHA05
|
||||
KEYMAP = darp10
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED = rgb_pwm
|
||||
|
||||
# Set battery I2C bus
|
||||
CFLAGS += -DI2C_SMBUS=I2C_4
|
||||
|
||||
# Set touchpad PS2 bus
|
||||
CFLAGS += -DPS2_TOUCHPAD=PS2_3
|
||||
|
||||
# Set smart charger parameters
|
||||
CHARGER = oz26786
|
||||
CFLAGS += \
|
||||
-DCHARGER_ADAPTER_RSENSE=5 \
|
||||
-DCHARGER_BATTERY_RSENSE=10 \
|
||||
-DCHARGER_CHARGE_CURRENT=1536 \
|
||||
-DCHARGER_CHARGE_VOLTAGE=17600 \
|
||||
-DCHARGER_INPUT_CURRENT=4740
|
||||
|
||||
# Set CPU power limits in watts
|
||||
CFLAGS += \
|
||||
-DPOWER_LIMIT_AC=65 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DFAN1_PWM_MIN=27
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(48, 27), \
|
||||
FAN_POINT(52, 27), \
|
||||
FAN_POINT(56, 33), \
|
||||
FAN_POINT(60, 37), \
|
||||
FAN_POINT(75, 53), \
|
||||
FAN_POINT(83, 65), \
|
||||
FAN_POINT(87, 75), \
|
||||
FAN_POINT(89, 77), \
|
||||
"
|
||||
|
||||
CFLAGS += -DFAN2_PWM=DCR3
|
||||
CFLAGS += -DFAN2_PWM_MIN=27
|
||||
CFLAGS += -DBOARD_FAN2_POINTS="\
|
||||
FAN_POINT(48, 27), \
|
||||
FAN_POINT(52, 27), \
|
||||
FAN_POINT(56, 33), \
|
||||
FAN_POINT(60, 37), \
|
||||
FAN_POINT(75, 53), \
|
||||
FAN_POINT(83, 65), \
|
||||
FAN_POINT(87, 75), \
|
||||
FAN_POINT(89, 77), \
|
||||
"
|
||||
|
||||
# Add common code
|
||||
include src/board/system76/common/common.mk
|
262
src/board/system76/darp10/gpio.c
Normal file
262
src/board/system76/darp10/gpio.c
Normal file
@@ -0,0 +1,262 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 0);
|
||||
struct Gpio __code AC_PRESENT = GPIO(F, 7);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
struct Gpio __code BKL_EN = GPIO(C, 7);
|
||||
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2); // renamed to ESPI_RESET#
|
||||
struct Gpio __code CCD_EN = GPIO(D, 1);
|
||||
struct Gpio __code DD_ON = GPIO(E, 4);
|
||||
struct Gpio __code EC_EN = GPIO(B, 6); // renamed to SUSBC_EC
|
||||
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
|
||||
struct Gpio __code LAN_WAKEUP_N = GPIO(B, 2);
|
||||
struct Gpio __code LED_ACIN = GPIO(H, 2);
|
||||
struct Gpio __code LED_BAT_CHG = GPIO(H, 5);
|
||||
struct Gpio __code LED_BAT_FULL = GPIO(J, 0);
|
||||
struct Gpio __code LED_PWR = GPIO(D, 0);
|
||||
struct Gpio __code LID_SW_N = GPIO(B, 1);
|
||||
struct Gpio __code ME_WE = GPIO(E, 6);
|
||||
struct Gpio __code PCH_PWROK_EC = GPIO(F, 3);
|
||||
struct Gpio __code PD_EN = GPIO(D, 4); // renamed to PD_POWER_EN
|
||||
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
|
||||
struct Gpio __code PWR_SW_N = GPIO(B, 3);
|
||||
struct Gpio __code RGBKB_DET_N = GPIO(I, 2);
|
||||
struct Gpio __code SLP_S0_N = GPIO(B, 5);
|
||||
struct Gpio __code SUSB_N_PCH = GPIO(H, 0);
|
||||
struct Gpio __code SUSC_N_PCH = GPIO(H, 1);
|
||||
struct Gpio __code VA_EC_EN = GPIO(J, 4);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(E, 1);
|
||||
struct Gpio __code XLP_OUT = GPIO(B, 4);
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init(void) {
|
||||
// PWRSW WDT 2 Enable 2
|
||||
GCR9 = BIT(5);
|
||||
// PWRSW WDT 2 Enable 1
|
||||
GCR8 = BIT(4);
|
||||
|
||||
// Enable LPC reset on GPD2
|
||||
GCR = 0b10 << 1;
|
||||
// Disable UARTs
|
||||
GCR6 = 0;
|
||||
// Enable SMBus channel 4
|
||||
GCR15 = BIT(4);
|
||||
// Set GPB5 and GPD2 to 1.8V
|
||||
GCR19 = BIT(7) | BIT(0);
|
||||
// Set GPD3 to 1.8V, GPF2 and GPF3 to 3.3V
|
||||
GCR20 = BIT(7);
|
||||
// Set GPF7, GPH0, and GPH1 to 1.8V
|
||||
GCR21 = BIT(5) | BIT(2) | BIT(1);
|
||||
// Not documented
|
||||
GCR22 = BIT(7);
|
||||
// Set GPM6 power domain to VCC
|
||||
GCR23 = BIT(0);
|
||||
|
||||
// Set GPIO data
|
||||
GPDRA = 0;
|
||||
// XLP_OUT, PWR_SW#
|
||||
GPDRB = BIT(4) | BIT(3);
|
||||
GPDRC = 0;
|
||||
// PWR_BTN#
|
||||
GPDRD = BIT(5);
|
||||
// USB_PWR_EN
|
||||
GPDRE = BIT(3);
|
||||
// H_PECI
|
||||
GPDRF = BIT(6);
|
||||
// H_PROCHOT_EC
|
||||
GPDRG = BIT(6);
|
||||
GPDRH = 0;
|
||||
GPDRI = 0;
|
||||
// KBC_MUTE#
|
||||
GPDRJ = BIT(1);
|
||||
GPDRM = 0;
|
||||
|
||||
// Set GPIO control
|
||||
|
||||
// EC_PWM_LEDKB_P
|
||||
GPCRA0 = GPIO_ALT;
|
||||
// KBC_BEEP (NC)
|
||||
GPCRA1 = GPIO_IN;
|
||||
// CPU_FAN1
|
||||
GPCRA2 = GPIO_ALT;
|
||||
// CPU_FAN2
|
||||
GPCRA3 = GPIO_ALT;
|
||||
// NC
|
||||
GPCRA4 = GPIO_IN;
|
||||
// EC_PWM_LEDKB_R
|
||||
GPCRA5 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_G
|
||||
GPCRA6 = GPIO_ALT;
|
||||
// EC_PWM_LEDKB_B
|
||||
GPCRA7 = GPIO_ALT;
|
||||
|
||||
// AC_IN#
|
||||
GPCRB0 = GPIO_IN | GPIO_UP;
|
||||
// LID_SW#
|
||||
GPCRB1 = GPIO_IN | GPIO_UP;
|
||||
// EC_LAN_WAKEUP#
|
||||
GPCRB2 = GPIO_IN | GPIO_UP;
|
||||
// PWR_SW#
|
||||
GPCRB3 = GPIO_IN;
|
||||
// XLP_OUT
|
||||
GPCRB4 = GPIO_OUT;
|
||||
// SLP_S0#
|
||||
GPCRB5 = GPIO_IN;
|
||||
// SUSBC_EC
|
||||
GPCRB6 = GPIO_OUT;
|
||||
|
||||
// ALL_SYS_PWRGD
|
||||
GPCRC0 = GPIO_IN;
|
||||
// SMC_VGA_THERM
|
||||
GPCRC1 = GPIO_ALT | GPIO_UP;
|
||||
// SMD_VGA_THERM
|
||||
GPCRC2 = GPIO_ALT | GPIO_UP;
|
||||
// KB-SO16
|
||||
GPCRC3 = GPIO_ALT | GPIO_UP;
|
||||
// CNVI_DET#
|
||||
GPCRC4 = GPIO_IN | GPIO_UP;
|
||||
// KB-SO17
|
||||
GPCRC5 = GPIO_ALT | GPIO_UP;
|
||||
// JACK_IN#_EC
|
||||
GPCRC6 = GPIO_IN;
|
||||
// BKL_EN
|
||||
GPCRC7 = GPIO_OUT;
|
||||
|
||||
// LED_PWR
|
||||
GPCRD0 = GPIO_OUT;
|
||||
// CCD_EN
|
||||
GPCRD1 = GPIO_OUT;
|
||||
// ESPI_RESET_N
|
||||
GPCRD2 = GPIO_ALT;
|
||||
// SLP_A#
|
||||
GPCRD3 = GPIO_IN;
|
||||
// PD_POWER_EN
|
||||
GPCRD4 = GPIO_OUT;
|
||||
// PWR_BTN#
|
||||
GPCRD5 = GPIO_OUT;
|
||||
// CPU_FANSEN1
|
||||
GPCRD6 = GPIO_ALT;
|
||||
// CPU_FANSEN2
|
||||
GPCRD7 = GPIO_ALT;
|
||||
|
||||
// SMC_BAT
|
||||
GPCRE0 = GPIO_ALT | GPIO_UP;
|
||||
// WLAN_PWR_EN
|
||||
GPCRE1 = GPIO_OUT;
|
||||
// TBT_I2C_IRQ2Z
|
||||
GPCRE2 = GPIO_IN;
|
||||
// USB_PWR_EN
|
||||
GPCRE3 = GPIO_OUT;
|
||||
// DD_ON
|
||||
GPCRE4 = GPIO_OUT;
|
||||
// EC_RSMRST#
|
||||
GPCRE5 = GPIO_OUT;
|
||||
// ME_WE
|
||||
GPCRE6 = GPIO_OUT;
|
||||
// SMD_BAT
|
||||
GPCRE7 = GPIO_ALT | GPIO_UP;
|
||||
|
||||
// 80CLK
|
||||
GPCRF0 = GPIO_IN;
|
||||
// USB_CHARGE_EN
|
||||
GPCRF1 = GPIO_OUT;
|
||||
// 3IN1
|
||||
GPCRF2 = GPIO_IN;
|
||||
// PCH_PWROK_EC
|
||||
GPCRF3 = GPIO_OUT;
|
||||
// TP_CLK
|
||||
GPCRF4 = GPIO_ALT | GPIO_UP;
|
||||
// TP_DATA
|
||||
GPCRF5 = GPIO_ALT | GPIO_UP;
|
||||
// H_PECI
|
||||
GPCRF6 = GPIO_ALT;
|
||||
// AC_PRESENT
|
||||
GPCRF7 = GPIO_OUT;
|
||||
|
||||
// NC
|
||||
GPCRG0 = GPIO_IN;
|
||||
// NC
|
||||
GPCRG1 = GPIO_IN;
|
||||
// 100k pull-up to VDD3
|
||||
GPCRG2 = GPIO_IN;
|
||||
// HSPI_CE#
|
||||
GPCRG3 = GPIO_ALT;
|
||||
// HSPI_MSI
|
||||
GPCRG4 = GPIO_ALT;
|
||||
// HSPI_MSO
|
||||
GPCRG5 = GPIO_ALT;
|
||||
// H_PROCHOT_EC
|
||||
GPCRG6 = GPIO_OUT;
|
||||
// HSPI_SCLK
|
||||
GPCRG7 = GPIO_ALT;
|
||||
|
||||
// SUSB#_PCH
|
||||
GPCRH0 = GPIO_IN;
|
||||
// SUSC#_PCH
|
||||
GPCRH1 = GPIO_IN;
|
||||
// LED_ACIN
|
||||
GPCRH2 = GPIO_OUT;
|
||||
// NC
|
||||
GPCRH3 = GPIO_IN;
|
||||
// NC
|
||||
GPCRH4 = GPIO_IN;
|
||||
// LED_BAT_CHG
|
||||
GPCRH5 = GPIO_OUT;
|
||||
// NC
|
||||
GPCRH6 = GPIO_IN;
|
||||
// NC
|
||||
GPCRH7 = GPIO_IN;
|
||||
|
||||
// BAT_DET
|
||||
GPCRI0 = GPIO_ALT;
|
||||
// BAT_VOLT
|
||||
GPCRI1 = GPIO_ALT;
|
||||
// RGBKB_DET#
|
||||
GPCRI2 = GPIO_IN | GPIO_UP;
|
||||
// THERM_VOLT
|
||||
GPCRI3 = GPIO_ALT;
|
||||
// TOTAL_CUR
|
||||
GPCRI4 = GPIO_ALT;
|
||||
// EC_CCD_WP#
|
||||
GPCRI5 = GPIO_OUT;
|
||||
// THERM_VOLT2
|
||||
GPCRI6 = GPIO_ALT;
|
||||
// MODEL_ID
|
||||
GPCRI7 = GPIO_IN;
|
||||
|
||||
// LED_BAT_FULL
|
||||
GPCRJ0 = GPIO_OUT;
|
||||
// KBC_MUTE#
|
||||
GPCRJ1 = GPIO_OUT;
|
||||
// KBLIGHT_ADJ
|
||||
GPCRJ2 = GPIO_ALT;
|
||||
// SINK_CTRL_EC_1
|
||||
GPCRJ3 = GPIO_IN;
|
||||
// VA_EC_EN
|
||||
GPCRJ4 = GPIO_OUT;
|
||||
// SINK_CTRL_EC_2
|
||||
GPCRJ5 = GPIO_IN;
|
||||
// EC_GPIO
|
||||
GPCRJ6 = GPIO_OUT;
|
||||
// KB-DET
|
||||
GPCRJ7 = GPIO_IN;
|
||||
|
||||
// ESPI_IO0_EC
|
||||
GPCRM0 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO1_EC
|
||||
GPCRM1 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO2_EC
|
||||
GPCRM2 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_IO3_EC
|
||||
GPCRM3 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_CLK_EC
|
||||
GPCRM4 = GPIO_ALT | GPIO_UP | GPIO_DOWN;
|
||||
// ESPI_CS_EC#
|
||||
GPCRM5 = GPIO_ALT;
|
||||
// ESPI_ALRT0#
|
||||
GPCRM6 = GPIO_IN | GPIO_UP | GPIO_DOWN;
|
||||
}
|
47
src/board/system76/darp10/include/board/gpio.h
Normal file
47
src/board/system76/darp10/include/board/gpio.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#ifndef _BOARD_GPIO_H
|
||||
#define _BOARD_GPIO_H
|
||||
|
||||
#include <ec/gpio.h>
|
||||
|
||||
void gpio_init(void);
|
||||
|
||||
extern struct Gpio __code ACIN_N;
|
||||
extern struct Gpio __code AC_PRESENT;
|
||||
extern struct Gpio __code ALL_SYS_PWRGD;
|
||||
extern struct Gpio __code BKL_EN;
|
||||
#define HAVE_BT_EN 0
|
||||
extern struct Gpio __code BUF_PLT_RST_N;
|
||||
extern struct Gpio __code CCD_EN;
|
||||
extern struct Gpio __code DD_ON;
|
||||
extern struct Gpio __code EC_EN;
|
||||
extern struct Gpio __code EC_RSMRST_N;
|
||||
extern struct Gpio __code LAN_WAKEUP_N;
|
||||
extern struct Gpio __code LED_ACIN;
|
||||
#define HAVE_LED_AIRPLANE_N 0
|
||||
extern struct Gpio __code LED_BAT_CHG;
|
||||
extern struct Gpio __code LED_BAT_FULL;
|
||||
extern struct Gpio __code LED_PWR;
|
||||
extern struct Gpio __code LID_SW_N;
|
||||
extern struct Gpio __code ME_WE;
|
||||
#define HAVE_PCH_DPWROK_EC 0
|
||||
extern struct Gpio __code PCH_PWROK_EC;
|
||||
#define HAVE_PD_EN 1
|
||||
extern struct Gpio __code PD_EN;
|
||||
#define HAVE_PM_PWROK 0
|
||||
extern struct Gpio __code PWR_BTN_N;
|
||||
extern struct Gpio __code PWR_SW_N;
|
||||
extern struct Gpio __code RGBKB_DET_N;
|
||||
extern struct Gpio __code SLP_S0_N;
|
||||
#define HAVE_SLP_SUS_N 0
|
||||
#define HAVE_SUS_PWR_ACK 0
|
||||
extern struct Gpio __code SUSB_N_PCH;
|
||||
extern struct Gpio __code SUSC_N_PCH;
|
||||
#define HAVE_SUSWARN_N 0
|
||||
extern struct Gpio __code VA_EC_EN;
|
||||
#define HAVE_WLAN_EN 0
|
||||
extern struct Gpio __code WLAN_PWR_EN;
|
||||
extern struct Gpio __code XLP_OUT;
|
||||
|
||||
#endif // _BOARD_GPIO_H
|
@@ -5,11 +5,16 @@ board-y += gpio.c
|
||||
|
||||
EC=ite
|
||||
CONFIG_EC_ITE_IT8587E=y
|
||||
CONFIG_EC_FLASH_SIZE_128K = y
|
||||
|
||||
# Intel-based host
|
||||
CONFIG_PLATFORM_INTEL = y
|
||||
|
||||
# Include keyboard
|
||||
KEYBOARD=15in_102
|
||||
|
||||
# Set keyboard LED mechanism
|
||||
CONFIG_HAVE_KBLED = y
|
||||
KBLED=darp5
|
||||
CFLAGS+=-DI2C_KBLED=I2C_1
|
||||
|
||||
@@ -32,5 +37,15 @@ CFLAGS+=\
|
||||
-DPOWER_LIMIT_AC=65 \
|
||||
-DPOWER_LIMIT_DC=45
|
||||
|
||||
# Fan configs
|
||||
CFLAGS += -DFAN1_PWM=DCR2
|
||||
CFLAGS += -DBOARD_FAN1_POINTS="\
|
||||
FAN_POINT(70, 40), \
|
||||
FAN_POINT(75, 50), \
|
||||
FAN_POINT(80, 60), \
|
||||
FAN_POINT(85, 65), \
|
||||
FAN_POINT(90, 65), \
|
||||
"
|
||||
|
||||
# Add system76 common code
|
||||
include src/board/system76/common/common.mk
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <board/gpio.h>
|
||||
#include <common/macro.h>
|
||||
|
||||
// clang-format off
|
||||
// uncrustify:off
|
||||
struct Gpio __code ACIN_N = GPIO(B, 6);
|
||||
struct Gpio __code AC_PRESENT = GPIO(E, 7);
|
||||
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
|
||||
@@ -43,9 +43,9 @@ struct Gpio __code VA_EC_EN = GPIO(E, 3);
|
||||
struct Gpio __code VR_ON = GPIO(H, 4);
|
||||
struct Gpio __code WLAN_EN = GPIO(H, 5);
|
||||
struct Gpio __code WLAN_PWR_EN = GPIO(J, 4);
|
||||
// clang-format on
|
||||
// uncrustify:on
|
||||
|
||||
void gpio_init() {
|
||||
void gpio_init(void) {
|
||||
// Enable LPC reset on GPD2
|
||||
GCR = 0x04;
|
||||
|
||||
@@ -192,8 +192,6 @@ void gpio_init() {
|
||||
GPCRH5 = GPIO_OUT;
|
||||
// SUSB#_PCH
|
||||
GPCRH6 = GPIO_IN;
|
||||
// Unknown
|
||||
GPCRH7 = GPIO_IN;
|
||||
// BAT_DET
|
||||
GPCRI0 = GPIO_ALT;
|
||||
// BAT_VOLT
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user