1 /*
2  * Copyright (c) 2022 Google LLC
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_SUBSYS_MGMT_EC_HOST_CMD_BACKENDS_EC_HOST_CMD_BACKEND_SHI_H_
8 #define ZEPHYR_SUBSYS_MGMT_EC_HOST_CMD_BACKENDS_EC_HOST_CMD_BACKEND_SHI_H_
9 
10 #include <zephyr/device.h>
11 
12 /*
13  * Byte codes returned by EC over SPI interface.
14  *
15  * These can be used by the AP to debug the EC interface, and to determine
16  * when the EC is not in a state where it will ever get around to responding
17  * to the AP.
18  *
19  * Example of sequence of bytes read from EC for a current good transfer:
20  *   1. -                  - AP asserts chip select (CS#)
21  *   2. EC_SHI_OLD_READY   - AP sends first byte(s) of request
22  *   3. -                  - EC starts handling CS# interrupt
23  *   4. EC_SHI_RECEIVING   - AP sends remaining byte(s) of request
24  *   5. EC_SHI_PROCESSING  - EC starts processing request; AP is clocking in
25  *                           bytes looking for EC_SHI_FRAME_START
26  *   6. -                  - EC finishes processing and sets up response
27  *   7. EC_SHI_FRAME_START - AP reads frame byte
28  *   8. (response packet)  - AP reads response packet
29  *   9. EC_SHI_PAST_END    - Any additional bytes read by AP
30  *   10 -                  - AP deasserts chip select
31  *   11 -                  - EC processes CS# interrupt and sets up DMA for
32  *                           next request
33  *
34  * If the AP is waiting for EC_SHI_FRAME_START and sees any value other than
35  * the following byte values:
36  *   EC_SHI_OLD_READY
37  *   EC_SHI_RX_READY
38  *   EC_SHI_RECEIVING
39  *   EC_SHI_PROCESSING
40  *
41  * Then the EC found an error in the request, or was not ready for the request
42  * and lost data.  The AP should give up waiting for EC_SHI_FRAME_START,
43  * because the EC is unable to tell when the AP is done sending its request.
44  */
45 
46 /*
47  * Framing byte which precedes a response packet from the EC.  After sending a
48  * request, the AP will clock in bytes until it sees the framing byte, then
49  * clock in the response packet.
50  */
51 #define EC_SHI_FRAME_START 0xec
52 
53 /*
54  * Padding bytes which are clocked out after the end of a response packet.
55  */
56 #define EC_SHI_PAST_END 0xed
57 
58 /*
59  * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
60  * that the AP will send a valid packet header (starting with
61  * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
62  *
63  * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
64  *	 CS goes low. This macro has the Most Significant Bit set to zero,
65  *	 so SDO will not be driven high when CS goes low.
66  */
67 #define EC_SHI_RX_READY 0x78
68 
69 /*
70  * EC has started receiving the request from the AP, but hasn't started
71  * processing it yet.
72  */
73 #define EC_SHI_RECEIVING 0xf9
74 
75 /* EC has received the entire request from the AP and is processing it. */
76 #define EC_SHI_PROCESSING 0xfa
77 
78 /*
79  * EC received bad data from the AP, such as a packet header with an invalid
80  * length.  EC will ignore all data until chip select deasserts.
81  */
82 #define EC_SHI_RX_BAD_DATA 0xfb
83 
84 /*
85  * EC received data from the AP before it was ready.  That is, the AP asserted
86  * chip select and started clocking data before the EC was ready to receive it.
87  * EC will ignore all data until chip select deasserts.
88  */
89 #define EC_SHI_NOT_READY 0xfc
90 
91 /*
92  * EC was ready to receive a request from the AP.  EC has treated the byte sent
93  * by the AP as part of a request packet, or (for old-style ECs) is processing
94  * a fully received packet but is not ready to respond yet.
95  */
96 #define EC_SHI_OLD_READY 0xfd
97 
98 /* Supported version of host commands protocol. */
99 #define EC_HOST_REQUEST_VERSION 3
100 
101 #endif /* ZEPHYR_SUBSYS_MGMT_EC_HOST_CMD_BACKENDS_EC_HOST_CMD_BACKEND_SHI_H_ */
102