12#ifndef ZEPHYR_INCLUDE_ESPI_H_
13#define ZEPHYR_INCLUDE_ESPI_H_
161#define ESPI_PERIPHERAL_INDEX_0 0ul
162#define ESPI_PERIPHERAL_INDEX_1 1ul
163#define ESPI_PERIPHERAL_INDEX_2 2ul
165#define ESPI_TARGET_TO_CONTROLLER 0ul
166#define ESPI_CONTROLLER_TO_TARGET 1ul
168#define ESPI_VWIRE_SRC_ID0 0ul
169#define ESPI_VWIRE_SRC_ID1 1ul
170#define ESPI_VWIRE_SRC_ID2 2ul
171#define ESPI_VWIRE_SRC_ID3 3ul
172#define ESPI_VWIRE_SRC_ID_MAX 4ul
174#define ESPI_PERIPHERAL_NODATA 0ul
176#define E8042_START_OPCODE 0x50
177#define E8042_MAX_OPCODE 0x5F
179#define EACPI_START_OPCODE 0x60
180#define EACPI_MAX_OPCODE 0x6F
182#define ECUSTOM_START_OPCODE 0xF0
183#define ECUSTOM_MAX_OPCODE 0xFF
199#if defined(CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD)
200 ESPI_PERIPHERAL_EC_HOST_CMD,
279#define ESPI_VWIRE_SIGNAL_OCB_0 ESPI_VWIRE_SIGNAL_TARGET_GPIO_0
280#define ESPI_VWIRE_SIGNAL_OCB_1 ESPI_VWIRE_SIGNAL_TARGET_GPIO_1
281#define ESPI_VWIRE_SIGNAL_OCB_2 ESPI_VWIRE_SIGNAL_TARGET_GPIO_2
282#define ESPI_VWIRE_SIGNAL_OCB_3 ESPI_VWIRE_SIGNAL_TARGET_GPIO_3
308#if defined(CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION)
310 EACPI_GET_SHARED_MEMORY,
312#if defined(CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE)
314 ECUSTOM_HOST_SUBS_INTERRUPT_EN = ECUSTOM_START_OPCODE,
315 ECUSTOM_HOST_CMD_GET_PARAM_MEMORY,
316 ECUSTOM_HOST_CMD_GET_PARAM_MEMORY_SIZE,
317 ECUSTOM_HOST_CMD_SEND_RESULT,
322#define HOST_KBC_EVT_IBF BIT(0)
324#define HOST_KBC_EVT_OBE BIT(1)
414 struct espi_callback *cb,
427struct espi_callback {
450typedef int (*espi_api_config)(
const struct device *dev,
struct espi_cfg *cfg);
451typedef bool (*espi_api_get_channel_status)(
const struct device *dev,
454typedef int (*espi_api_read_request)(
const struct device *dev,
456typedef int (*espi_api_write_request)(
const struct device *dev,
458typedef int (*espi_api_lpc_read_request)(
const struct device *dev,
461typedef int (*espi_api_lpc_write_request)(
const struct device *dev,
465typedef int (*espi_api_send_vwire)(
const struct device *dev,
468typedef int (*espi_api_receive_vwire)(
const struct device *dev,
472typedef int (*espi_api_send_oob)(
const struct device *dev,
474typedef int (*espi_api_receive_oob)(
const struct device *dev,
477typedef int (*espi_api_flash_read)(
const struct device *dev,
479typedef int (*espi_api_flash_write)(
const struct device *dev,
481typedef int (*espi_api_flash_erase)(
const struct device *dev,
484typedef int (*espi_api_manage_callback)(
const struct device *dev,
485 struct espi_callback *callback,
488__subsystem
struct espi_driver_api {
489 espi_api_config config;
490 espi_api_get_channel_status get_channel_status;
491 espi_api_read_request read_request;
492 espi_api_write_request write_request;
493 espi_api_lpc_read_request read_lpc_request;
494 espi_api_lpc_write_request write_lpc_request;
495 espi_api_send_vwire send_vwire;
496 espi_api_receive_vwire receive_vwire;
497 espi_api_send_oob send_oob;
498 espi_api_receive_oob receive_oob;
502 espi_api_manage_callback manage_callback;
559static inline int z_impl_espi_config(
const struct device *dev,
562 const struct espi_driver_api *api =
563 (
const struct espi_driver_api *)dev->
api;
565 return api->config(dev, cfg);
583static inline bool z_impl_espi_get_channel_status(
const struct device *dev,
586 const struct espi_driver_api *api =
587 (
const struct espi_driver_api *)dev->
api;
589 return api->get_channel_status(dev, ch);
609static inline int z_impl_espi_read_request(
const struct device *dev,
612 const struct espi_driver_api *api =
613 (
const struct espi_driver_api *)dev->
api;
615 if (!api->read_request) {
619 return api->read_request(dev, req);
639static inline int z_impl_espi_write_request(
const struct device *dev,
642 const struct espi_driver_api *api =
643 (
const struct espi_driver_api *)dev->
api;
645 if (!api->write_request) {
649 return api->write_request(dev, req);
672static inline int z_impl_espi_read_lpc_request(
const struct device *dev,
676 const struct espi_driver_api *api =
677 (
const struct espi_driver_api *)dev->
api;
679 if (!api->read_lpc_request) {
683 return api->read_lpc_request(dev, op,
data);
705static inline int z_impl_espi_write_lpc_request(
const struct device *dev,
709 const struct espi_driver_api *api =
710 (
const struct espi_driver_api *)dev->
api;
712 if (!api->write_lpc_request) {
716 return api->write_lpc_request(dev, op,
data);
736static inline int z_impl_espi_send_vwire(
const struct device *dev,
740 const struct espi_driver_api *api =
741 (
const struct espi_driver_api *)dev->
api;
743 return api->send_vwire(dev,
signal, level);
762static inline int z_impl_espi_receive_vwire(
const struct device *dev,
766 const struct espi_driver_api *api =
767 (
const struct espi_driver_api *)dev->
api;
769 return api->receive_vwire(dev,
signal, level);
786static inline int z_impl_espi_send_oob(
const struct device *dev,
789 const struct espi_driver_api *api =
790 (
const struct espi_driver_api *)dev->
api;
792 if (!api->send_oob) {
796 return api->send_oob(dev, pckt);
813static inline int z_impl_espi_receive_oob(
const struct device *dev,
816 const struct espi_driver_api *api =
817 (
const struct espi_driver_api *)dev->
api;
819 if (!api->receive_oob) {
823 return api->receive_oob(dev, pckt);
842static inline int z_impl_espi_read_flash(
const struct device *dev,
845 const struct espi_driver_api *api =
846 (
const struct espi_driver_api *)dev->
api;
848 if (!api->flash_read) {
852 return api->flash_read(dev, pckt);
871static inline int z_impl_espi_write_flash(
const struct device *dev,
874 const struct espi_driver_api *api =
875 (
const struct espi_driver_api *)dev->
api;
877 if (!api->flash_write) {
881 return api->flash_write(dev, pckt);
900static inline int z_impl_espi_flash_erase(
const struct device *dev,
903 const struct espi_driver_api *api =
904 (
const struct espi_driver_api *)dev->
api;
906 if (!api->flash_erase) {
910 return api->flash_erase(dev, pckt);
986 __ASSERT(callback,
"Callback pointer should not be NULL");
987 __ASSERT(
handler,
"Callback handler pointer should not be NULL");
990 callback->evt_type = evt_type;
1006 struct espi_callback *callback)
1008 const struct espi_driver_api *api =
1009 (
const struct espi_driver_api *)dev->
api;
1011 if (!api->manage_callback) {
1015 return api->manage_callback(dev, callback,
true);
1035 struct espi_callback *callback)
1037 const struct espi_driver_api *api =
1038 (
const struct espi_driver_api *)dev->
api;
1040 if (!api->manage_callback) {
1044 return api->manage_callback(dev, callback,
false);
1054#include <zephyr/syscalls/espi.h>
int espi_read_flash(const struct device *dev, struct espi_flash_packet *pckt)
Sends a read request packet for shared flash.
espi_io_mode
eSPI I/O mode capabilities
Definition espi.h:36
int espi_read_request(const struct device *dev, struct espi_request_packet *req)
Sends memory, I/O or message read request over eSPI.
int espi_write_request(const struct device *dev, struct espi_request_packet *req)
Sends memory, I/O or message write request over eSPI.
int espi_send_oob(const struct device *dev, struct espi_oob_packet *pckt)
Sends SMBus transaction (out-of-band) packet over eSPI bus.
espi_virtual_peripheral
eSPI peripheral notification type.
Definition espi.h:193
void(* espi_callback_handler_t)(const struct device *dev, struct espi_callback *cb, struct espi_event espi_evt)
Define the application callback handler function signature.
Definition espi.h:413
espi_bus_event
eSPI bus event.
Definition espi.h:114
espi_cycle_type
eSPI cycle types supported over eSPI peripheral channel
Definition espi.h:207
int espi_receive_oob(const struct device *dev, struct espi_oob_packet *pckt)
Receives SMBus transaction (out-of-band) packet from eSPI bus.
int espi_config(const struct device *dev, struct espi_cfg *cfg)
Configure operation of a eSPI controller.
static int espi_remove_callback(const struct device *dev, struct espi_callback *callback)
Remove an application callback.
Definition espi.h:1034
bool espi_get_channel_status(const struct device *dev, enum espi_channel ch)
Query to see if it a channel is ready.
int espi_write_lpc_request(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data)
Writes data to a LPC peripheral which generates an eSPI transaction.
static void espi_init_callback(struct espi_callback *callback, espi_callback_handler_t handler, enum espi_bus_event evt_type)
Callback model.
Definition espi.h:982
int espi_receive_vwire(const struct device *dev, enum espi_vwire_signal signal, uint8_t *level)
Retrieves level status for a signal encapsulated in a virtual wire.
int espi_write_flash(const struct device *dev, struct espi_flash_packet *pckt)
Sends a write request packet for shared flash.
int espi_flash_erase(const struct device *dev, struct espi_flash_packet *pckt)
Sends a write request packet for shared flash.
espi_vwire_signal
eSPI system platform signals that can be send or receive through virtual wire channel
Definition espi.h:223
static int espi_add_callback(const struct device *dev, struct espi_callback *callback)
Add an application callback.
Definition espi.h:1005
espi_pc_event
eSPI peripheral channel events.
Definition espi.h:152
int espi_send_vwire(const struct device *dev, enum espi_vwire_signal signal, uint8_t level)
Sends system/platform signal as a virtual wire packet.
lpc_peripheral_opcode
Definition espi.h:285
int espi_read_lpc_request(const struct device *dev, enum lpc_peripheral_opcode op, uint32_t *data)
Reads SOC data from a LPC peripheral with information updated over eSPI.
espi_channel
eSPI channel.
Definition espi.h:102
@ ESPI_IO_MODE_QUAD_LINES
Definition espi.h:39
@ ESPI_IO_MODE_SINGLE_LINE
Definition espi.h:37
@ ESPI_IO_MODE_DUAL_LINES
Definition espi.h:38
@ ESPI_PERIPHERAL_UART
Definition espi.h:194
@ ESPI_PERIPHERAL_HOST_IO
Definition espi.h:196
@ ESPI_PERIPHERAL_HOST_IO_PVT
Definition espi.h:198
@ ESPI_PERIPHERAL_8042_KBC
Definition espi.h:195
@ ESPI_PERIPHERAL_DEBUG_PORT80
Definition espi.h:197
@ ESPI_BUS_EVENT_OOB_RECEIVED
Indicates the eSPI HW has received a Out-of-band package from eSPI host.
Definition espi.h:137
@ ESPI_BUS_EVENT_CHANNEL_READY
Indicates the eSPI HW has received channel enable notification from eSPI host, once the eSPI channel ...
Definition espi.h:128
@ ESPI_BUS_PERIPHERAL_NOTIFICATION
Indicates the eSPI HW has received a peripheral eSPI host event.
Definition espi.h:142
@ ESPI_BUS_TAF_NOTIFICATION
Definition espi.h:143
@ ESPI_BUS_EVENT_VWIRE_RECEIVED
Indicates the eSPI HW has received a virtual wire message from eSPI host.
Definition espi.h:133
@ ESPI_BUS_RESET
Indicates the eSPI bus was reset either via eSPI reset pin.
Definition espi.h:122
@ ESPI_CYCLE_OK_COMPLETION_NODATA
Definition espi.h:214
@ ESPI_CYCLE_NOK_COMPLETION_NODATA
Definition espi.h:216
@ ESPI_CYCLE_MEMORY_WRITE32
Definition espi.h:210
@ ESPI_CYCLE_MESSAGE_DATA
Definition espi.h:213
@ ESPI_CYCLE_MEMORY_WRITE64
Definition espi.h:211
@ ESPI_CYCLE_MEMORY_READ32
Definition espi.h:208
@ ESPI_CYCLE_MESSAGE_NODATA
Definition espi.h:212
@ ESPI_CYCLE_MEMORY_READ64
Definition espi.h:209
@ ESPI_CYCLE_OKCOMPLETION_DATA
Definition espi.h:215
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_11
Definition espi.h:272
@ ESPI_VWIRE_SIGNAL_PLTRST
Definition espi.h:229
@ ESPI_VWIRE_SIGNAL_SUS_STAT
Definition espi.h:230
@ ESPI_VWIRE_SIGNAL_RST_CPU_INIT
Definition espi.h:250
@ ESPI_VWIRE_SIGNAL_SMIOUT
Definition espi.h:232
@ ESPI_VWIRE_SIGNAL_TARGET_BOOT_STS
Definition espi.h:245
@ ESPI_VWIRE_SIGNAL_SMI
Definition espi.h:252
@ ESPI_VWIRE_SIGNAL_OOB_RST_WARN
Definition espi.h:228
@ ESPI_VWIRE_SIGNAL_SLP_WLAN
Definition espi.h:237
@ ESPI_VWIRE_SIGNAL_SLP_S4
Definition espi.h:226
@ ESPI_VWIRE_SIGNAL_ERR_NON_FATAL
Definition espi.h:246
@ ESPI_VWIRE_SIGNAL_DNX_ACK
Definition espi.h:255
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_2
Definition espi.h:263
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_10
Definition espi.h:271
@ ESPI_VWIRE_SIGNAL_WAKE
Definition espi.h:243
@ ESPI_VWIRE_SIGNAL_HOST_RST_ACK
Definition espi.h:249
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_8
Definition espi.h:269
@ ESPI_VWIRE_SIGNAL_OOB_RST_ACK
Definition espi.h:244
@ ESPI_VWIRE_SIGNAL_DNX_WARN
Definition espi.h:240
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_9
Definition espi.h:270
@ ESPI_VWIRE_SIGNAL_SUS_WARN
Definition espi.h:236
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_0
Definition espi.h:261
@ ESPI_VWIRE_SIGNAL_SLP_A
Definition espi.h:234
@ ESPI_VWIRE_SIGNAL_PME
Definition espi.h:242
@ ESPI_VWIRE_SIGNAL_ERR_FATAL
Definition espi.h:247
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_1
Definition espi.h:262
@ ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK
Definition espi.h:235
@ ESPI_VWIRE_SIGNAL_SLP_S3
Definition espi.h:225
@ ESPI_VWIRE_SIGNAL_HOST_C10
Definition espi.h:239
@ ESPI_VWIRE_SIGNAL_SLP_LAN
Definition espi.h:238
@ ESPI_VWIRE_SIGNAL_SUS_ACK
Definition espi.h:256
@ ESPI_VWIRE_SIGNAL_SLP_S5
Definition espi.h:227
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_3
Definition espi.h:264
@ ESPI_VWIRE_SIGNAL_NMIOUT
Definition espi.h:231
@ ESPI_VWIRE_SIGNAL_COUNT
Definition espi.h:275
@ ESPI_VWIRE_SIGNAL_TARGET_BOOT_DONE
Definition espi.h:248
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_4
Definition espi.h:265
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_7
Definition espi.h:268
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_6
Definition espi.h:267
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_5
Definition espi.h:266
@ ESPI_VWIRE_SIGNAL_HOST_RST_WARN
Definition espi.h:233
@ ESPI_VWIRE_SIGNAL_SCI
Definition espi.h:254
@ ESPI_PC_EVT_BUS_MASTER_ENABLE
Definition espi.h:154
@ ESPI_PC_EVT_BUS_CHANNEL_READY
Definition espi.h:153
@ EACPI_READ_STS
Definition espi.h:306
@ EACPI_WRITE_STS
Definition espi.h:307
@ EACPI_IBF_HAS_CHAR
Definition espi.h:302
@ EACPI_OBF_HAS_CHAR
Definition espi.h:301
@ E8042_CLEAR_FLAG
Definition espi.h:299
@ E8042_PAUSE_IRQ
Definition espi.h:294
@ EACPI_WRITE_CHAR
Definition espi.h:304
@ E8042_SET_FLAG
Definition espi.h:298
@ E8042_READ_KB_STS
Definition espi.h:297
@ E8042_WRITE_KB_CHAR
Definition espi.h:290
@ E8042_WRITE_MB_CHAR
Definition espi.h:291
@ E8042_IBF_HAS_CHAR
Definition espi.h:288
@ E8042_OBF_HAS_CHAR
Definition espi.h:287
@ E8042_RESUME_IRQ
Definition espi.h:293
@ E8042_CLEAR_OBF
Definition espi.h:295
@ ESPI_CHANNEL_OOB
Definition espi.h:105
@ ESPI_CHANNEL_PERIPHERAL
Definition espi.h:103
@ ESPI_CHANNEL_FLASH
Definition espi.h:106
@ ESPI_CHANNEL_VWIRE
Definition espi.h:104
int flash_erase(const struct device *dev, off_t offset, size_t size)
Erase part or all of a flash memory.
int flash_write(const struct device *dev, off_t offset, const void *data, size_t len)
Write buffer into flash memory.
int flash_read(const struct device *dev, off_t offset, void *data, size_t len)
Read data from flash.
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
eSPI bus configuration parameters
Definition espi.h:359
enum espi_io_mode io_caps
Supported I/O mode.
Definition espi.h:361
enum espi_channel channel_caps
Supported channels.
Definition espi.h:363
uint8_t max_freq
Maximum supported frequency in MHz.
Definition espi.h:365
eSPI event
Definition espi.h:347
uint32_t evt_data
Data associated to the event.
Definition espi.h:353
enum espi_bus_event evt_type
Event type.
Definition espi.h:349
uint32_t evt_details
Additional details for bus event type.
Definition espi.h:351
Bit field definition of evt_data in struct espi_event for ACPI.
Definition espi.h:338
uint32_t data
Definition espi.h:340
uint32_t type
Definition espi.h:339
uint32_t reserved
Definition espi.h:341
Bit field definition of evt_data in struct espi_event for KBC.
Definition espi.h:328
uint32_t reserved
Definition espi.h:332
uint32_t evt
Definition espi.h:331
uint32_t data
Definition espi.h:330
uint32_t type
Definition espi.h:329
eSPI flash transactions packet format
Definition espi.h:396
uint8_t * buf
Definition espi.h:397
uint32_t flash_addr
Definition espi.h:398
uint16_t len
Definition espi.h:399
eSPI out-of-band transaction packet format
Definition espi.h:388
uint8_t * buf
Definition espi.h:389
uint16_t len
Definition espi.h:390
eSPI peripheral request packet format
Definition espi.h:371
uint8_t tag
Definition espi.h:373
uint32_t address
Definition espi.h:375
uint8_t * data
Definition espi.h:376
enum espi_cycle_type cycle_type
Definition espi.h:372
uint16_t len
Definition espi.h:374
static fdata_t data[2]
Definition test_fifo_contexts.c:15
static struct k_poll_signal signal
Definition test_poll.c:707
static void handler(struct k_timer *timer)
Definition main.c:19