Angel Pons | 210a008 | 2020-04-02 23:48:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 21dde8b | 2018-10-15 02:00:39 +0000 | [diff] [blame] | 2 | |
| 3 | #ifndef EC_GOOGLE_WILCO_EC_H |
| 4 | #define EC_GOOGLE_WILCO_EC_H |
| 5 | |
| 6 | #include <stddef.h> |
| 7 | #include <stdint.h> |
| 8 | |
| 9 | /* Different supported message types */ |
| 10 | enum wilco_ec_msg_type { |
| 11 | WILCO_EC_MSG_RAW, /* Raw message, do not skip any data */ |
| 12 | WILCO_EC_MSG_DEFAULT, /* Skip 1 byte of response data */ |
| 13 | WILCO_EC_MSG_NO_RESPONSE, /* EC does not respond to command */ |
| 14 | }; |
| 15 | |
| 16 | /** |
| 17 | * wilco_ec_mailbox |
| 18 | * |
| 19 | * Send a command request to the EC mailbox and receive the response. |
| 20 | * |
| 21 | * @type: Mailbox message type, see enum above |
| 22 | * @command: Command to execute |
| 23 | * @request_data: Request data buffer |
| 24 | * @request_size: Number of bytes in request data buffer (max 32) |
| 25 | * @response_data: Response data buffer |
| 26 | * @response_size: Number of bytes in response data buffer (max 32) |
| 27 | * |
| 28 | * @return number of bytes received, negative error code on failure |
| 29 | */ |
| 30 | int wilco_ec_mailbox(enum wilco_ec_msg_type type, uint8_t command, |
| 31 | const void *request_data, size_t request_size, |
| 32 | void *response_data, size_t response_size); |
| 33 | |
Duncan Laurie | 5f6f1da | 2018-10-15 02:11:30 +0000 | [diff] [blame] | 34 | /** |
| 35 | * wilco_ec_send |
| 36 | * |
| 37 | * Send a basic EC command with a one byte parameter with no |
| 38 | * returned data; |
| 39 | * |
| 40 | * @command: Command to execute |
| 41 | * @param: Command parameter to send |
| 42 | * |
| 43 | * @return negative error code on failure |
| 44 | */ |
| 45 | static inline int wilco_ec_send(uint8_t command, uint8_t param) |
| 46 | { |
| 47 | return wilco_ec_mailbox(WILCO_EC_MSG_DEFAULT, command, |
| 48 | ¶m, sizeof(param), NULL, 0); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * wilco_ec_send_noargs |
| 53 | * |
| 54 | * Send a basic EC command with no parameters and no returned data. |
| 55 | * |
| 56 | * @command: Command to execute |
| 57 | * |
| 58 | * @return negative error code on failure |
| 59 | */ |
| 60 | static inline int wilco_ec_send_noargs(uint8_t command) |
| 61 | { |
| 62 | return wilco_ec_mailbox(WILCO_EC_MSG_DEFAULT, command, |
| 63 | NULL, 0, NULL, 0); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * wilco_ec_sendrecv |
| 68 | * |
| 69 | * Send a basic EC command with a one byte parameter, ignoring the |
| 70 | * first byte of returned data to match the common behavior. |
| 71 | * The maximum response size is 31 due to the ignored byte. |
| 72 | * |
| 73 | * @command: Command to execute |
| 74 | * @param: Command parameter to send |
| 75 | * @data: Response data buffer |
| 76 | * @size: Number of bytes in response data buffer (max 31) |
| 77 | * |
| 78 | * @return number of bytes received, negative error code on failure |
| 79 | */ |
| 80 | static inline int wilco_ec_sendrecv(uint8_t command, uint8_t param, |
| 81 | void *data, size_t size) |
| 82 | { |
| 83 | return wilco_ec_mailbox(WILCO_EC_MSG_DEFAULT, command, |
| 84 | ¶m, sizeof(param), data, size); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * wilco_ec_sendrecv_noargs |
| 89 | * |
| 90 | * Send a basic EC command with no parameters, ignoring the |
| 91 | * first byte of returned data to match the common behavior. |
| 92 | * The maximum response size is 31 due to the ignored byte. |
| 93 | * |
| 94 | * @command: Command to execute |
| 95 | * @data: Response data buffer |
| 96 | * @size: Number of bytes in response data buffer (max 31) |
| 97 | * |
| 98 | * @return number of bytes received, negative error code on failure |
| 99 | */ |
| 100 | static inline int wilco_ec_sendrecv_noargs(uint8_t command, |
| 101 | void *data, size_t size) |
| 102 | { |
| 103 | return wilco_ec_mailbox(WILCO_EC_MSG_DEFAULT, command, |
| 104 | NULL, 0, data, size); |
| 105 | } |
| 106 | |
Duncan Laurie | 21dde8b | 2018-10-15 02:00:39 +0000 | [diff] [blame] | 107 | #endif /* EC_GOOGLE_WILCO_EC_H */ |