12#ifndef ZEPHYR_INCLUDE_ESPI_H_
13#define ZEPHYR_INCLUDE_ESPI_H_
137#define ESPI_PERIPHERAL_INDEX_0 0ul
138#define ESPI_PERIPHERAL_INDEX_1 1ul
139#define ESPI_PERIPHERAL_INDEX_2 2ul
141#define ESPI_TARGET_TO_CONTROLLER 0ul
142#define ESPI_CONTROLLER_TO_TARGET 1ul
144#define ESPI_VWIRE_SRC_ID0 0ul
145#define ESPI_VWIRE_SRC_ID1 1ul
146#define ESPI_VWIRE_SRC_ID2 2ul
147#define ESPI_VWIRE_SRC_ID3 3ul
148#define ESPI_VWIRE_SRC_ID_MAX 4ul
150#define ESPI_PERIPHERAL_NODATA 0ul
152#define E8042_START_OPCODE 0x50
153#define E8042_MAX_OPCODE 0x5F
155#define EACPI_START_OPCODE 0x60
156#define EACPI_MAX_OPCODE 0x6F
158#define ECUSTOM_START_OPCODE 0xF0
159#define ECUSTOM_MAX_OPCODE 0xFF
175#if defined(CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD)
176 ESPI_PERIPHERAL_EC_HOST_CMD,
255#define ESPI_VWIRE_SIGNAL_OCB_0 ESPI_VWIRE_SIGNAL_TARGET_GPIO_0
256#define ESPI_VWIRE_SIGNAL_OCB_1 ESPI_VWIRE_SIGNAL_TARGET_GPIO_1
257#define ESPI_VWIRE_SIGNAL_OCB_2 ESPI_VWIRE_SIGNAL_TARGET_GPIO_2
258#define ESPI_VWIRE_SIGNAL_OCB_3 ESPI_VWIRE_SIGNAL_TARGET_GPIO_3
284#if defined(CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION)
286 EACPI_GET_SHARED_MEMORY,
288#if defined(CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE)
290 ECUSTOM_HOST_SUBS_INTERRUPT_EN = ECUSTOM_START_OPCODE,
291 ECUSTOM_HOST_CMD_GET_PARAM_MEMORY,
292 ECUSTOM_HOST_CMD_GET_PARAM_MEMORY_SIZE,
293 ECUSTOM_HOST_CMD_SEND_RESULT,
298#define HOST_KBC_EVT_IBF BIT(0)
300#define HOST_KBC_EVT_OBE BIT(1)
384 struct espi_callback *cb,
397struct espi_callback {
420typedef int (*espi_api_config)(
const struct device *dev,
struct espi_cfg *cfg);
421typedef bool (*espi_api_get_channel_status)(
const struct device *dev,
424typedef int (*espi_api_read_request)(
const struct device *dev,
426typedef int (*espi_api_write_request)(
const struct device *dev,
428typedef int (*espi_api_lpc_read_request)(
const struct device *dev,
431typedef int (*espi_api_lpc_write_request)(
const struct device *dev,
435typedef int (*espi_api_send_vwire)(
const struct device *dev,
438typedef int (*espi_api_receive_vwire)(
const struct device *dev,
442typedef int (*espi_api_send_oob)(
const struct device *dev,
444typedef int (*espi_api_receive_oob)(
const struct device *dev,
447typedef int (*espi_api_flash_read)(
const struct device *dev,
449typedef int (*espi_api_flash_write)(
const struct device *dev,
451typedef int (*espi_api_flash_erase)(
const struct device *dev,
454typedef int (*espi_api_manage_callback)(
const struct device *dev,
455 struct espi_callback *callback,
458__subsystem
struct espi_driver_api {
459 espi_api_config config;
460 espi_api_get_channel_status get_channel_status;
461 espi_api_read_request read_request;
462 espi_api_write_request write_request;
463 espi_api_lpc_read_request read_lpc_request;
464 espi_api_lpc_write_request write_lpc_request;
465 espi_api_send_vwire send_vwire;
466 espi_api_receive_vwire receive_vwire;
467 espi_api_send_oob send_oob;
468 espi_api_receive_oob receive_oob;
472 espi_api_manage_callback manage_callback;
529static inline int z_impl_espi_config(
const struct device *dev,
532 const struct espi_driver_api *api =
533 (
const struct espi_driver_api *)dev->
api;
535 return api->config(dev, cfg);
553static inline bool z_impl_espi_get_channel_status(
const struct device *dev,
556 const struct espi_driver_api *api =
557 (
const struct espi_driver_api *)dev->
api;
559 return api->get_channel_status(dev, ch);
579static inline int z_impl_espi_read_request(
const struct device *dev,
582 const struct espi_driver_api *api =
583 (
const struct espi_driver_api *)dev->
api;
585 if (!api->read_request) {
589 return api->read_request(dev, req);
609static inline int z_impl_espi_write_request(
const struct device *dev,
612 const struct espi_driver_api *api =
613 (
const struct espi_driver_api *)dev->
api;
615 if (!api->write_request) {
619 return api->write_request(dev, req);
642static inline int z_impl_espi_read_lpc_request(
const struct device *dev,
646 const struct espi_driver_api *api =
647 (
const struct espi_driver_api *)dev->
api;
649 if (!api->read_lpc_request) {
653 return api->read_lpc_request(dev, op, data);
675static inline int z_impl_espi_write_lpc_request(
const struct device *dev,
679 const struct espi_driver_api *api =
680 (
const struct espi_driver_api *)dev->
api;
682 if (!api->write_lpc_request) {
686 return api->write_lpc_request(dev, op, data);
706static inline int z_impl_espi_send_vwire(
const struct device *dev,
710 const struct espi_driver_api *api =
711 (
const struct espi_driver_api *)dev->
api;
713 return api->send_vwire(dev, signal, level);
732static inline int z_impl_espi_receive_vwire(
const struct device *dev,
736 const struct espi_driver_api *api =
737 (
const struct espi_driver_api *)dev->
api;
739 return api->receive_vwire(dev, signal, level);
756static inline int z_impl_espi_send_oob(
const struct device *dev,
759 const struct espi_driver_api *api =
760 (
const struct espi_driver_api *)dev->
api;
762 if (!api->send_oob) {
766 return api->send_oob(dev, pckt);
783static inline int z_impl_espi_receive_oob(
const struct device *dev,
786 const struct espi_driver_api *api =
787 (
const struct espi_driver_api *)dev->
api;
789 if (!api->receive_oob) {
793 return api->receive_oob(dev, pckt);
812static inline int z_impl_espi_read_flash(
const struct device *dev,
815 const struct espi_driver_api *api =
816 (
const struct espi_driver_api *)dev->
api;
818 if (!api->flash_read) {
822 return api->flash_read(dev, pckt);
841static inline int z_impl_espi_write_flash(
const struct device *dev,
844 const struct espi_driver_api *api =
845 (
const struct espi_driver_api *)dev->
api;
847 if (!api->flash_write) {
851 return api->flash_write(dev, pckt);
870static inline int z_impl_espi_flash_erase(
const struct device *dev,
873 const struct espi_driver_api *api =
874 (
const struct espi_driver_api *)dev->
api;
876 if (!api->flash_erase) {
880 return api->flash_erase(dev, pckt);
957 __ASSERT(callback,
"Callback pointer should not be NULL");
958 __ASSERT(handler,
"Callback handler pointer should not be NULL");
960 callback->handler = handler;
961 callback->evt_type = evt_type;
977 struct espi_callback *callback)
979 const struct espi_driver_api *api =
980 (
const struct espi_driver_api *)dev->
api;
982 if (!api->manage_callback) {
986 return api->manage_callback(dev, callback,
true);
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,
false);
1025#include <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:169
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:383
espi_bus_event
eSPI bus event.
Definition: espi.h:114
espi_cycle_type
eSPI cycle types supported over eSPI peripheral channel
Definition: espi.h:183
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:1005
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:953
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:199
static int espi_add_callback(const struct device *dev, struct espi_callback *callback)
Add an application callback.
Definition: espi.h:976
espi_pc_event
eSPI peripheral channel events.
Definition: espi.h:128
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:261
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:170
@ ESPI_PERIPHERAL_HOST_IO
Definition: espi.h:172
@ ESPI_PERIPHERAL_HOST_IO_PVT
Definition: espi.h:174
@ ESPI_PERIPHERAL_8042_KBC
Definition: espi.h:171
@ ESPI_PERIPHERAL_DEBUG_PORT80
Definition: espi.h:173
@ ESPI_BUS_EVENT_OOB_RECEIVED
Definition: espi.h:118
@ ESPI_BUS_SAF_NOTIFICATION
Definition: espi.h:120
@ ESPI_BUS_EVENT_CHANNEL_READY
Definition: espi.h:116
@ ESPI_BUS_PERIPHERAL_NOTIFICATION
Definition: espi.h:119
@ ESPI_BUS_EVENT_VWIRE_RECEIVED
Definition: espi.h:117
@ ESPI_BUS_RESET
Definition: espi.h:115
@ ESPI_CYCLE_OK_COMPLETION_NODATA
Definition: espi.h:190
@ ESPI_CYCLE_NOK_COMPLETION_NODATA
Definition: espi.h:192
@ ESPI_CYCLE_MEMORY_WRITE32
Definition: espi.h:186
@ ESPI_CYCLE_MESSAGE_DATA
Definition: espi.h:189
@ ESPI_CYCLE_MEMORY_WRITE64
Definition: espi.h:187
@ ESPI_CYCLE_MEMORY_READ32
Definition: espi.h:184
@ ESPI_CYCLE_MESSAGE_NODATA
Definition: espi.h:188
@ ESPI_CYCLE_MEMORY_READ64
Definition: espi.h:185
@ ESPI_CYCLE_OKCOMPLETION_DATA
Definition: espi.h:191
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_11
Definition: espi.h:248
@ ESPI_VWIRE_SIGNAL_PLTRST
Definition: espi.h:205
@ ESPI_VWIRE_SIGNAL_SUS_STAT
Definition: espi.h:206
@ ESPI_VWIRE_SIGNAL_RST_CPU_INIT
Definition: espi.h:226
@ ESPI_VWIRE_SIGNAL_SMIOUT
Definition: espi.h:208
@ ESPI_VWIRE_SIGNAL_TARGET_BOOT_STS
Definition: espi.h:221
@ ESPI_VWIRE_SIGNAL_SMI
Definition: espi.h:228
@ ESPI_VWIRE_SIGNAL_OOB_RST_WARN
Definition: espi.h:204
@ ESPI_VWIRE_SIGNAL_SLP_WLAN
Definition: espi.h:213
@ ESPI_VWIRE_SIGNAL_SLP_S4
Definition: espi.h:202
@ ESPI_VWIRE_SIGNAL_ERR_NON_FATAL
Definition: espi.h:222
@ ESPI_VWIRE_SIGNAL_DNX_ACK
Definition: espi.h:231
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_2
Definition: espi.h:239
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_10
Definition: espi.h:247
@ ESPI_VWIRE_SIGNAL_WAKE
Definition: espi.h:219
@ ESPI_VWIRE_SIGNAL_HOST_RST_ACK
Definition: espi.h:225
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_8
Definition: espi.h:245
@ ESPI_VWIRE_SIGNAL_OOB_RST_ACK
Definition: espi.h:220
@ ESPI_VWIRE_SIGNAL_DNX_WARN
Definition: espi.h:216
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_9
Definition: espi.h:246
@ ESPI_VWIRE_SIGNAL_SUS_WARN
Definition: espi.h:212
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_0
Definition: espi.h:237
@ ESPI_VWIRE_SIGNAL_SLP_A
Definition: espi.h:210
@ ESPI_VWIRE_SIGNAL_PME
Definition: espi.h:218
@ ESPI_VWIRE_SIGNAL_ERR_FATAL
Definition: espi.h:223
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_1
Definition: espi.h:238
@ ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK
Definition: espi.h:211
@ ESPI_VWIRE_SIGNAL_SLP_S3
Definition: espi.h:201
@ ESPI_VWIRE_SIGNAL_HOST_C10
Definition: espi.h:215
@ ESPI_VWIRE_SIGNAL_SLP_LAN
Definition: espi.h:214
@ ESPI_VWIRE_SIGNAL_SUS_ACK
Definition: espi.h:232
@ ESPI_VWIRE_SIGNAL_SLP_S5
Definition: espi.h:203
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_3
Definition: espi.h:240
@ ESPI_VWIRE_SIGNAL_NMIOUT
Definition: espi.h:207
@ ESPI_VWIRE_SIGNAL_COUNT
Definition: espi.h:251
@ ESPI_VWIRE_SIGNAL_TARGET_BOOT_DONE
Definition: espi.h:224
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_4
Definition: espi.h:241
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_7
Definition: espi.h:244
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_6
Definition: espi.h:243
@ ESPI_VWIRE_SIGNAL_TARGET_GPIO_5
Definition: espi.h:242
@ ESPI_VWIRE_SIGNAL_HOST_RST_WARN
Definition: espi.h:209
@ ESPI_VWIRE_SIGNAL_SCI
Definition: espi.h:230
@ ESPI_PC_EVT_BUS_MASTER_ENABLE
Definition: espi.h:130
@ ESPI_PC_EVT_BUS_CHANNEL_READY
Definition: espi.h:129
@ EACPI_READ_STS
Definition: espi.h:282
@ EACPI_WRITE_STS
Definition: espi.h:283
@ EACPI_IBF_HAS_CHAR
Definition: espi.h:278
@ EACPI_OBF_HAS_CHAR
Definition: espi.h:277
@ E8042_CLEAR_FLAG
Definition: espi.h:275
@ E8042_PAUSE_IRQ
Definition: espi.h:270
@ EACPI_WRITE_CHAR
Definition: espi.h:280
@ E8042_SET_FLAG
Definition: espi.h:274
@ E8042_READ_KB_STS
Definition: espi.h:273
@ E8042_WRITE_KB_CHAR
Definition: espi.h:266
@ E8042_WRITE_MB_CHAR
Definition: espi.h:267
@ E8042_IBF_HAS_CHAR
Definition: espi.h:264
@ E8042_OBF_HAS_CHAR
Definition: espi.h:263
@ E8042_RESUME_IRQ
Definition: espi.h:269
@ E8042_CLEAR_OBF
Definition: espi.h:271
@ 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:115
#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:399
void * data
Address of the device instance private data.
Definition: device.h:409
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405
eSPI bus configuration parameters
Definition: espi.h:335
enum espi_io_mode io_caps
Supported I/O mode.
Definition: espi.h:337
enum espi_channel channel_caps
Supported channels.
Definition: espi.h:339
uint8_t max_freq
Maximum supported frequency in MHz.
Definition: espi.h:341
eSPI event
Definition: espi.h:323
uint32_t evt_data
Data associated to the event.
Definition: espi.h:329
enum espi_bus_event evt_type
Event type.
Definition: espi.h:325
uint32_t evt_details
Additional details for bus event type.
Definition: espi.h:327
Bit field definition of evt_data in struct espi_event for ACPI.
Definition: espi.h:314
uint32_t data
Definition: espi.h:316
uint32_t type
Definition: espi.h:315
uint32_t reserved
Definition: espi.h:317
Bit field definition of evt_data in struct espi_event for KBC.
Definition: espi.h:304
uint32_t reserved
Definition: espi.h:308
uint32_t evt
Definition: espi.h:307
uint32_t data
Definition: espi.h:306
uint32_t type
Definition: espi.h:305
eSPI flash transactions packet format
Definition: espi.h:366
uint8_t * buf
Definition: espi.h:367
uint32_t flash_addr
Definition: espi.h:368
uint16_t len
Definition: espi.h:369
eSPI out-of-band transaction packet format
Definition: espi.h:358
uint8_t * buf
Definition: espi.h:359
uint16_t len
Definition: espi.h:360
eSPI peripheral request packet format
Definition: espi.h:347
uint8_t tag
Definition: espi.h:349
uint32_t address
Definition: espi.h:351
uint8_t * data
Definition: espi.h:352
enum espi_cycle_type cycle_type
Definition: espi.h:348
uint16_t len
Definition: espi.h:350