Skip to content

Commit 53a2adf

Browse files
barnas-michalChromeos LUCI
authored andcommitted
zephyr: add documentation about host commands
This commit adds information about available Kconfigs and device tree definitions used to enable and configure host interface support. BRANCH=main BUG=b:208438167 TEST=generate preview Change-Id: I049dbd5efd5edc32492b191b8f1cc7911ad2b2bd Signed-off-by: Michał Barnaś <mb@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3401640 Reviewed-by: Keith Short <keithshort@chromium.org>
1 parent 0d5c246 commit 53a2adf

4 files changed

Lines changed: 314 additions & 1 deletion

File tree

docs/ap-ec-comm.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ the following sections.
2525
providing a CLI. They call one of the transport-specific `ec_command`
2626
implementations in the `util/comm-*.c` files to send and receive from the EC.
2727

28+
#### Stress test
29+
30+
The `ectool stress` command sends a large amount of host commands continuously
31+
to the EC. This verifies that the EC can respond to all commands received
32+
without timeouts or communication errors.
33+
34+
It will log the time elapsed for every iteration of sending 10000 host commands
35+
with the time that it took to send them.
36+
37+
Example output of stress test is:
38+
`Update: attempt 10000 round 1 | took 205 seconds`
39+
40+
Killing the process will result in displaying the total runtime and failures
41+
that happened during it.
42+
2843
### EC kernel driver
2944

3045
In most cases, `ectool` communicates via the [`cros-ec` Kernel driver], rather

docs/zephyr/zephyr_ap_ec_comm.md

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
# Application Processor to EC communication
2+
3+
[TOC]
4+
5+
## Overview
6+
7+
Host commands allow communication between AP and EC.
8+
9+
This communication is used to inform the ChromeOS running on AP about events
10+
like opening or closing lid, connecting or disconnecting charger,
11+
thermal status, keyboard events.
12+
13+
## Kconfig options
14+
15+
Kconfig Option | Default | Documentation
16+
:--------------------------------------- | :---------: | :------------
17+
`CONFIG_PLATFORM_EC_HOSTCMD` | y if AP | [EC host commands]
18+
19+
### Transport layer
20+
21+
The `CONFIG_PLATFORM_EC_HOST_INTERFACE_TYPE` choice selects the interface type
22+
used to transport the AP/EC messages.
23+
24+
Kconfig to select interface | Default | Documentation
25+
:--------------------------------------- | :---------: | :------------
26+
`CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI` | y if AP_X86 | [eSPI interface]
27+
`CONFIG_PLATFORM_EC_HOST_INTERFACE_HECI` | n | [HECI interface]
28+
`CONFIG_PLATFORM_EC_HOST_INTERFACE_LPC` | n | [LPC interface]
29+
`CONFIG_PLATFORM_EC_HOST_INTERFACE_SHI` | y if AP_ARM | [SHI interface]
30+
31+
#### SHI
32+
33+
[SHI] is acronym for SPI Host Interface. It's default interface for computers
34+
with ARM AP.
35+
It doesn't have any special Kconfigs.
36+
37+
#### eSPI - Virtual wires
38+
39+
[eSPI] is acronym for Enhanced Serial Peripheral Interface.
40+
It allows to define signals as virtual ones instead of using normal GPIOs.
41+
42+
See the [Kconfig.espi] file for all sub-options related to the eSPI interface.
43+
44+
#### HECI
45+
46+
HECI is acronym for Host Embedded Controller Interface.
47+
It doesn't have any special Kconfigs.
48+
49+
#### LPC
50+
51+
[LPC] is acronym for Low Pin Count bus.
52+
It doesn't have any special Kconfigs.
53+
54+
### Generic configuration
55+
56+
The following options are generic and defines features available through
57+
host interface.
58+
59+
Kconfig sub-options | Default | Documentation
60+
:------------------------------------------- | :---------: | :------------
61+
`CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE` | y | [Host command console]
62+
`CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE_BUF_SIZE`| 4096 | [Host command console buffer size]
63+
`CONFIG_PLATFORM_EC_HOST_COMMAND_STATUS` | y if PLATFORM_EC_HOST_INTERFACE_SHI | [Host command - status]
64+
65+
### MKBP - Matrix Keyboard Protocol
66+
67+
MKBP was originally used to send keyboard events to AP OS.
68+
Later, more functionalities were added and more types of events can be sent
69+
using this protocol. It can transfer information about keystrokes, sensors,
70+
switches, fingerprints and more.
71+
72+
Kconfig sub-options | Default | Documentation
73+
:------------------------------------------- | :---------: | :------------
74+
`CONFIG_PLATFORM_EC_MKBP_INPUT_DEVICES` | n | [MKBP input devices]
75+
`CONFIG_PLATFORM_EC_MKBP_EVENT` | n | [MKBP event]
76+
77+
The following options must be enabled to use respective masks specified in
78+
device tree. See [Device Tree nodes](#device-tree-nodes) paragraph for details.
79+
80+
Kconfig sub-options | Default | Documentation
81+
:---------------------------------------------- | :---------: | :------------
82+
`CONFIG_PLATFORM_EC_MKBP_EVENT_WAKEUP_MASK` | n | [MKBP event wake-up mask]
83+
`CONFIG_PLATFORM_EC_MKBP_HOST_EVENT_WAKEUP_MASK`| n | [MKBP host event wake-up mask]
84+
85+
The following options select the delivery method of MKBP messages.
86+
87+
Kconfig sub-options | Default | Documentation
88+
:----------------------------------------------- | :---------: | :------------
89+
`CONFIG_PLATFORM_EC_MKBP_USE_GPIO` | y | [MKBP gpio]
90+
`CONFIG_PLATFORM_EC_MKBP_USE_HOST_EVENT` | n | [MKBP host event]
91+
`CONFIG_PLATFORM_EC_MKBP_USE_GPIO_AND_HOST_EVENT`| n | [MKBP gpio and host event]
92+
`CONFIG_PLATFORM_EC_MKBP_USE_CUSTOM` | n | [MKBP custom]
93+
94+
### Debug
95+
96+
The `CONFIG_PLATFORM_EC_HOSTCMD_DEBUG_MODE` choice selects the verbosity
97+
level of messages on the EC console.
98+
99+
Kconfig debug verbosity | Default | Documentation
100+
:---------------------- | :-----: | :------------
101+
`CONFIG_HCDEBUG_OFF` | n | [Debug off]
102+
`CONFIG_HCDEBUG_NORMAL` | y | [Debug normal]
103+
`CONFIG_HCDEBUG_EVERY` | n | [Debug every]
104+
`CONFIG_HCDEBUG_PARAMS` | n | [Debug params]
105+
106+
## Device Tree nodes
107+
108+
### eSPI
109+
110+
Zephyr has built-in support for eSPI and EC takes advantage of this.
111+
Boards supported by Zephyr should have definitions of eSPI interfaces in their
112+
device trees.
113+
To select the eSPI interface to be used for sending the host commands it must
114+
be set as chosen node with name `cros-ec,espi`.
115+
The referenced node has to be enabled, which means that its `status` must
116+
be set as `okay`.
117+
118+
```
119+
/ {
120+
chosen {
121+
cros-ec,espi = &espi0;
122+
}
123+
}
124+
125+
&espi0 {
126+
status = "okay";
127+
};
128+
```
129+
130+
### SHI
131+
132+
The SoC specific Kconfig for SHI driver is automatically enabled based on
133+
selected host interface and SoC family. Each SoC driver has specific
134+
compatibility string which is used to get node with configuration from the
135+
device tree.
136+
For example, the nuvoton npcx chip uses compatibility string
137+
`nuvoton,npcx-cros-shi`.
138+
139+
The node's required properties are defined in yaml files: [SHI bindings]
140+
141+
```
142+
/ {
143+
shi: shi@4000f000 {
144+
compatible = "nuvoton,npcx-cros-shi";
145+
reg = <0x4000f000 0x120>;
146+
interrupts = <18 1>;
147+
clocks = <&pcc NPCX_CLOCK_BUS_APB3 NPCX_PWDWN_CTL5 1>;
148+
pinctrl-0 = <&altc_shi_sl>;
149+
shi-cs-wui =<&wui_io53>;
150+
label = "SHI";
151+
};
152+
}
153+
```
154+
155+
### MKBP Wake-up Masks
156+
157+
The EC can wake up the AP from sleep modes based on multiple event types.
158+
A wake-up mask specifies which specific event types are able to wake the AP.
159+
160+
For x86 based Chromebooks, the wake-up mask is controlled by the AP firmware
161+
directly using host commands `EC_CMD_HOST_EVENT_SET_SMI_MASK`,
162+
`EC_CMD_HOST_EVENT_SET_SCI_MASK` and `EC_CMD_HOST_EVENT_SET_WAKE_MASK`.
163+
164+
For ARM based Chromebooks, the wake-up mask is defined as device tree nodes,
165+
one for MKBP events and one for generic host events.
166+
They have respective Kconfig options, which must be enabled to take the masks
167+
into account.
168+
169+
Both masks have to be compatible with binding file: [MKBP event mask yaml]
170+
171+
Possible enums to use in these nodes are specified in file: [MKBP event mask enums]
172+
173+
```
174+
/ {
175+
ec-mkbp-host-event-wakeup-mask {
176+
compatible = "ec-wake-mask-event";
177+
wakeup-mask = <(HOST_EVENT_LID_OPEN |
178+
HOST_EVENT_POWER_BUTTON |
179+
HOST_EVENT_AC_CONNECTED |
180+
HOST_EVENT_AC_DISCONNECTED |
181+
HOST_EVENT_HANG_DETECT |
182+
HOST_EVENT_RTC |
183+
HOST_EVENT_MODE_CHANGE |
184+
HOST_EVENT_DEVICE)>;
185+
};
186+
187+
ec-mkbp-event-wakeup-mask {
188+
compatible = "ec-wake-mask-event";
189+
wakeup-mask = <(MKBP_EVENT_KEY_MATRIX |
190+
MKBP_EVENT_HOST_EVENT |
191+
MKBP_EVENT_SENSOR_FIFO)>;
192+
};
193+
}
194+
```
195+
196+
## Board Specific Code
197+
198+
No board specific code is required.
199+
200+
## Threads
201+
202+
The host_command_task() thread processes all requests from the AP, regardless
203+
of the host interface type enabled.
204+
205+
Enabling the `CONFIG_PLATFORM_EC_HOSTCMD` automatically selects
206+
`CONFIG_HAS_TASK_HOSTCMD` which is responsible for creating the thread.
207+
208+
## Testing and Debugging
209+
210+
Testing and debugging the host commands on DUT are described in
211+
[CrOS EC documentation]. It is recommended to run the stress test to check
212+
if communication is working properly with a huge amount of data sent.
213+
Running the stress test is described in the previously mentioned documentation,
214+
in the chapter [stress test].
215+
216+
### From EC console
217+
218+
If debug level is higher than `CONFIG_HCDEBUG_OFF`, then HC messages can
219+
be seen on EC console.
220+
221+
If there's no output lines starting from HC, that may be due to hostcmd channel
222+
being masked.
223+
To check what channels are masked, execute `chan` command in EC console.
224+
```
225+
uart:~$ chan
226+
# Mask E Channel
227+
...
228+
7 00000080 * hostcmd
229+
```
230+
The asterisk next to channel name means that it is enabled. Otherwise, execute
231+
command `chan 128` to enable hostcmd channel while disabling others.
232+
233+
If the hostcmd channel is disabled by default, it may be enabled by removing
234+
its name from `ec-console` node.
235+
236+
```
237+
ec-console {
238+
compatible = "ec-console";
239+
240+
disabled = "hostcmd";
241+
};
242+
```
243+
244+
Removing the `hostcmd` and leaving the empty quotes will result in hostcmd
245+
messages visible on EC console since boot-up.
246+
247+
## Examples
248+
249+
[Lazor MKBP wake-up](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/projects/trogdor/lazor/gpio.dts?q=ec-mkbp-host-event-wakeup-mask)
250+
251+
[Lazor MKBP Kconfig](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/projects/trogdor/lazor/prj.conf?q=CONFIG_PLATFORM_EC_MKBP_EVENT_WAKEUP_MASK)
252+
253+
[NPCX eSPI selection](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/include/cros/nuvoton/npcx.dtsi?q=cros-ec,espi)
254+
255+
[NPCX SHI definition](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/include/cros/nuvoton/npcx.dtsi?q=shi)
256+
257+
<!--
258+
Links to the documentation
259+
-->
260+
[SHI]:../ec_terms.md#shi
261+
[eSPI]:../ec_terms.md#espi
262+
[LPC]:../ec_terms.md#lpc
263+
[EC host commands]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22menuconfig%20PLATFORM_EC_HOSTCMD%22
264+
[eSPI interface]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.host_interface?q=%22config%20PLATFORM_EC_HOST_INTERFACE_ESPI%22
265+
[HECI interface]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.host_interface?q=%22config%20PLATFORM_EC_HOST_INTERFACE_HECI%22
266+
[LPC interface]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.host_interface?q=%22config%20PLATFORM_EC_HOST_INTERFACE_LPC%22
267+
[SHI interface]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.host_interface?q=%22config%20PLATFORM_EC_HOST_INTERFACE_SHI%22
268+
269+
[Kconfig.espi]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.espi
270+
271+
[Host command console]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.console?q=%22menuconfig%20PLATFORM_EC_HOSTCMD_CONSOLE%22
272+
[Host command console buffer size]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.console?q=%22config%20PLATFORM_EC_HOSTCMD_CONSOLE_BUF_SIZE%22
273+
[Host command - status]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20PLATFORM_EC_HOST_COMMAND_STATUS%22
274+
275+
[MKBP input devices]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20PLATFORM_EC_MKBP_INPUT_DEVICES%22
276+
[MKBP event]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20PLATFORM_EC_MKBP_EVENT%22
277+
278+
[MKBP event wake-up mask]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20PLATFORM_EC_MKBP_EVENT_WAKEUP_MASK%22
279+
[MKBP host event wake-up mask]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20PLATFORM_EC_MKBP_HOST_EVENT_WAKEUP_MASK%22
280+
281+
[MKBP gpio]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.mkbp_event?q=%22config%20PLATFORM_EC_MKBP_USE_GPIO%22
282+
[MKBP host event]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.mkbp_event?q=%22config%20PLATFORM_EC_MKBP_USE_HOST_EVENT%22
283+
[MKBP gpio and host event]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.mkbp_event?q=%22config%20PLATFORM_EC_MKBP_USE_GPIO_AND_HOST_EVENT%22
284+
[MKBP custom]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig.mkbp_event?q=%22config%20PLATFORM_EC_MKBP_USE_CUSTOM%22
285+
286+
[Debug off]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20HCDEBUG_OFF%22
287+
[Debug normal]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20HCDEBUG_NORMAL%22
288+
[Debug every]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20HCDEBUG_EVERY%22
289+
[Debug params]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/Kconfig?q=%22config%20HCDEBUG_PARAMS%22
290+
291+
[SHI bindings]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/dts/bindings/cros_shi/
292+
[MKBP event mask yaml]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/dts/bindings/cros_mkbp_event/ec-mkbp-event.yaml
293+
[MKBP event mask enums]:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/ec/zephyr/include/dt-bindings/wake_mask_event_defines.h
294+
295+
[CrOS EC documentation]:../ap-ec-comm.md#ectool
296+
[stress test]:../ap-ec-comm.md#stress-test

docs/zephyr/zephyr_new_board_checklist.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ feature.
5252
EC Feature | Needed for Power On
5353
:-------------------------------------------------------------------------- | :-----------------:
5454
[Configure EC Chipset (TODO)](./zephyr_template.md) | yes
55-
[Configure AP to EC Communication (TOD0)](./zephyr_template.md) | yes
55+
[Configure AP to EC Communication](./zephyr_ap_ec_comm.md) | yes
5656
[Configure AP Power Sequencing (TODO)](./zephyr_template.md) | yes
5757
[Configure USB-C (TODO)](./zephyr_template.md) | yes
5858
[Configure Charger (TODO)](./zephyr_template.md) | yes

docs/zephyr/zephyr_poc_device_bringup.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ As long as you get this compiling that should be enough to move to the
3838
next step. Further testing of the host command layer will require
3939
power sequencing up and going.
4040

41+
For further explanation, check [AP-EC communication](zephyr_ap_ec_comm.md) document.
42+
4143
## Enabling some simple GPIO-based buttons and switches
4244

4345
Next, you can:

0 commit comments

Comments
 (0)