13#ifndef ZEPHYR_INCLUDE_DRIVERS_SMBUS_H_
14#define ZEPHYR_INCLUDE_DRIVERS_SMBUS_H_
56#define SMBUS_CMD_QUICK 0b000
79#define SMBUS_CMD_BYTE 0b001
105#define SMBUS_CMD_BYTE_DATA 0b010
133#define SMBUS_CMD_WORD_DATA 0b011
152#define SMBUS_CMD_PROC_CALL 0b100
183#define SMBUS_CMD_BLOCK 0b101
203#define SMBUS_CMD_BLOCK_PROC 0b111
207#define SMBUS_BLOCK_BYTES_MAX 32
217#define SMBUS_MODE_CONTROLLER BIT(0)
220#define SMBUS_MODE_PEC BIT(1)
223#define SMBUS_MODE_HOST_NOTIFY BIT(2)
226#define SMBUS_MODE_SMBALERT BIT(3)
243#define SMBUS_ADDRESS_ARA 0x0c
263#define SMBUS_MSG_RW_MASK BIT(0)
319#define SMBUS_DT_SPEC_GET(node_id) \
321 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
322 .addr = DT_REG_ADDR(node_id) \
333#define SMBUS_DT_SPEC_INST_GET(inst) SMBUS_DT_SPEC_GET(DT_DRV_INST(inst))
482#if defined(CONFIG_SMBUS_STATS) || defined(__DOXYGEN__)
500struct smbus_device_state {
502 struct stats_smbus stats;
508#define Z_SMBUS_DEVICE_STATE_DEFINE(node_id, dev_name) \
509 static struct smbus_device_state Z_DEVICE_STATE_NAME(dev_name) \
510 __attribute__((__section__(".z_devstate")));
518#define Z_SMBUS_INIT_FN(dev_name, init_fn) \
520 UTIL_CAT(dev_name, _init)(const struct device *dev) \
522 struct smbus_device_state *state = \
523 CONTAINER_OF(dev->state, \
524 struct smbus_device_state, \
526 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 4, \
527 STATS_NAME_INIT_PARMS(smbus)); \
528 stats_register(dev->name, &(state->stats.s_hdr)); \
529 return init_fn(dev); \
545 struct smbus_device_state *
state =
581#define SMBUS_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
582 data_ptr, cfg_ptr, level, prio, \
584 Z_SMBUS_DEVICE_STATE_DEFINE(node_id, \
585 Z_DEVICE_DT_DEV_NAME(node_id)); \
586 Z_SMBUS_INIT_FN(Z_DEVICE_DT_DEV_NAME(node_id), init_fn) \
587 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
588 DEVICE_DT_NAME(node_id), \
589 &UTIL_CAT(Z_DEVICE_DT_DEV_NAME(node_id), _init),\
590 NULL, Z_DEVICE_DT_FLAGS(node_id), pm_device, \
591 data_ptr, cfg_ptr, level, prio, \
593 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_NAME \
594 (node_id)).devstate), \
607#define SMBUS_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
608 data_ptr, cfg_ptr, level, prio, \
610 DEVICE_DT_DEFINE(node_id, &init_fn, pm_device, \
611 data_ptr, cfg_ptr, level, prio, \
612 api_ptr, __VA_ARGS__)
625#define SMBUS_DEVICE_DT_INST_DEFINE(inst, ...) \
626 SMBUS_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
640static inline int z_impl_smbus_configure(
const struct device *dev,
668static inline int z_impl_smbus_get_config(
const struct device *dev,
791static inline int z_impl_smbus_quick(
const struct device *dev,
uint16_t addr,
825static inline int z_impl_smbus_byte_write(
const struct device *dev,
855static inline int z_impl_smbus_byte_read(
const struct device *dev,
886static inline int z_impl_smbus_byte_data_write(
const struct device *dev,
918static inline int z_impl_smbus_byte_data_read(
const struct device *dev,
950static inline int z_impl_smbus_word_data_write(
const struct device *dev,
982static inline int z_impl_smbus_word_data_read(
const struct device *dev,
1016static inline int z_impl_smbus_pcall(
const struct device *dev,
1049static inline int z_impl_smbus_block_write(
const struct device *dev,
1086static inline int z_impl_smbus_block_read(
const struct device *dev,
1124static inline int z_impl_smbus_block_pcall(
const struct device *dev,
1136 rcv_count, rcv_buf);
1147#include <zephyr/syscalls/smbus.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1461
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
static void smbus_xfer_stats(const struct device *dev, uint8_t sent, uint8_t recv)
Updates the SMBus stats.
Definition smbus.h:542
int smbus_byte_data_read(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *byte)
Perform an SMBus Byte Data Read operation.
int(* smbus_api_byte_write_t)(const struct device *dev, uint16_t addr, uint8_t byte)
Perform an SMBus Byte Write operation.
Definition smbus.h:362
int smbus_pcall(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t send_word, uint16_t *recv_word)
Perform an SMBus Process Call operation.
int(* smbus_api_word_data_write_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t word)
Perform an SMBus Word Data Write operation.
Definition smbus.h:388
int(* smbus_api_byte_data_read_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *byte)
Perform an SMBus Byte Data Read operation.
Definition smbus.h:381
static int smbus_host_notify_set_cb(const struct device *dev, struct smbus_callback *cb)
Add Host Notify callback for an SMBus host controller.
Definition smbus.h:737
int smbus_configure(const struct device *dev, uint32_t dev_config)
Configure operation of an SMBus host controller.
int smbus_block_write(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t count, uint8_t *buf)
Perform an SMBus Block Write operation.
#define SMBUS_BLOCK_BYTES_MAX
Maximum number of bytes in SMBus Block protocol.
Definition smbus.h:207
int(* smbus_api_configure_t)(const struct device *dev, uint32_t dev_config)
@def_driverbackendgroup{SMBus,smbus_interface}
Definition smbus.h:344
int smbus_block_read(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *count, uint8_t *buf)
Perform an SMBus Block Read operation.
int smbus_block_pcall(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t snd_count, uint8_t *snd_buf, uint8_t *rcv_count, uint8_t *rcv_buf)
Perform an SMBus Block Process Call operation.
void(* smbus_callback_handler_t)(const struct device *dev, struct smbus_callback *cb, uint8_t addr)
Define SMBus callback handler function signature.
Definition smbus.h:275
int smbus_word_data_read(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t *word)
Perform an SMBus Word Data Read operation.
int(* smbus_api_byte_data_write_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t byte)
Perform an SMBus Byte Data Write operation.
Definition smbus.h:374
int smbus_byte_write(const struct device *dev, uint16_t addr, uint8_t byte)
Perform an SMBus Byte Write operation.
int(* smbus_api_host_notify_cb_t)(const struct device *dev, struct smbus_callback *cb)
Add or remove a Host Notify callback.
Definition smbus.h:437
int(* smbus_api_block_pcall_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t send_count, uint8_t *send_buf, uint8_t *recv_count, uint8_t *recv_buf)
Perform an SMBus Block Process Call operation.
Definition smbus.h:423
static int smbus_host_notify_remove_cb(const struct device *dev, struct smbus_callback *cb)
Remove Host Notify callback from an SMBus host controller.
Definition smbus.h:760
int(* smbus_api_quick_t)(const struct device *dev, uint16_t addr, enum smbus_direction)
Perform an SMBus Quick operation.
Definition smbus.h:356
int(* smbus_api_word_data_read_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t *word)
Perform an SMBus Word Data Read operation.
Definition smbus.h:395
int(* smbus_api_smbalert_cb_t)(const struct device *dev, struct smbus_callback *cb)
Add or remove an SMBALERT callback.
Definition smbus.h:431
int smbus_get_config(const struct device *dev, uint32_t *dev_config)
Get configuration of an SMBus host controller.
static int smbus_smbalert_remove_cb(const struct device *dev, struct smbus_callback *cb)
Remove SMBALERT callback from an SMBus host controller.
Definition smbus.h:714
int(* smbus_api_pcall_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t send_word, uint16_t *recv_word)
Perform an SMBus Process Call operation.
Definition smbus.h:402
int smbus_quick(const struct device *dev, uint16_t addr, enum smbus_direction direction)
Perform an SMBus Quick operation.
int(* smbus_api_get_config_t)(const struct device *dev, uint32_t *dev_config)
Get configuration of an SMBus host controller.
Definition smbus.h:350
smbus_direction
SMBus read / write direction.
Definition smbus.h:253
int(* smbus_api_block_write_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t count, uint8_t *buf)
Perform an SMBus Block Write operation.
Definition smbus.h:409
int(* smbus_api_block_read_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *count, uint8_t *buf)
Perform an SMBus Block Read operation.
Definition smbus.h:416
int smbus_byte_read(const struct device *dev, uint16_t addr, uint8_t *byte)
Perform an SMBus Byte Read operation.
int smbus_byte_data_write(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t byte)
Perform an SMBus Byte Data Write operation.
int smbus_word_data_write(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t word)
Perform an SMBus Word Data Write operation.
static int smbus_smbalert_set_cb(const struct device *dev, struct smbus_callback *cb)
Add SMBALERT callback for an SMBus host controller.
Definition smbus.h:691
int(* smbus_api_byte_read_t)(const struct device *dev, uint16_t addr, uint8_t *byte)
Perform an SMBus Byte Read operation.
Definition smbus.h:368
@ SMBUS_MSG_WRITE
Write a message to SMBus peripheral.
Definition smbus.h:255
@ SMBUS_MSG_READ
Read a message from SMBus peripheral.
Definition smbus.h:257
#define STATS_SECT_END
Ends a stats group struct definition.
Definition stats.h:169
#define STATS_NAME(sectname__, entry__)
Add an entry name to a statistics entry name map.
Definition stats.h:519
#define STATS_SECT_ENTRY32(var__)
Declares a 32-bit stat entry inside a group struct.
Definition stats.h:204
#define STATS_NAME_START(sectname__)
Begin a statistics entry name map.
Definition stats.h:510
#define STATS_NAME_END(sectname__)
End a statistics entry name map.
Definition stats.h:527
#define STATS_INC(group__, var__)
Increments a statistic entry.
Definition stats.h:255
#define STATS_INCN(group__, var__, n__)
Increases a statistic entry by the specified amount.
Definition stats.h:243
#define STATS_SECT_START(group__)
Begins a stats group struct definition.
Definition stats.h:181
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:281
#define EINVAL
Invalid argument.
Definition errno.h:61
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define NULL
Definition iar_missing_defs.h:20
state
Definition parser_state.h:29
ssize_t recv(int sock, void *buf, size_t max_len, int flags)
Header file for the single-linked list API.
__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 dynamic structure (in RAM) per driver instance.
Definition device.h:470
Runtime device structure (in ROM) per driver instance.
Definition device.h:525
struct device_state * state
Address of the common device state.
Definition device.h:533
SMBus callback structure.
Definition smbus.h:288
smbus_callback_handler_t handler
Actual callback function being called when relevant.
Definition smbus.h:293
uint8_t addr
Peripheral device address.
Definition smbus.h:296
sys_snode_t node
This should be used in driver for a callback list management.
Definition smbus.h:290
@driver_ops{SMBus}
Definition smbus.h:443
smbus_api_byte_data_write_t smbus_byte_data_write
@driver_ops_optional Perform an SMBus Byte Data Write operation.
Definition smbus.h:455
smbus_api_get_config_t get_config
@driver_ops_optional Get configuration of an SMBus host controller.
Definition smbus.h:447
smbus_api_word_data_read_t smbus_word_data_read
@driver_ops_optional Perform an SMBus Word Data Read operation.
Definition smbus.h:461
smbus_api_pcall_t smbus_pcall
@driver_ops_optional Perform an SMBus Process Call operation.
Definition smbus.h:463
smbus_api_block_read_t smbus_block_read
@driver_ops_optional Perform an SMBus Block Read operation.
Definition smbus.h:467
smbus_api_host_notify_cb_t smbus_host_notify_remove_cb
@driver_ops_optional Remove Host Notify callback from an SMBus host controller.
Definition smbus.h:477
smbus_api_host_notify_cb_t smbus_host_notify_set_cb
@driver_ops_optional Add Host Notify callback for an SMBus host controller.
Definition smbus.h:475
smbus_api_word_data_write_t smbus_word_data_write
@driver_ops_optional Perform an SMBus Word Data Write operation.
Definition smbus.h:459
smbus_api_block_write_t smbus_block_write
@driver_ops_optional Perform an SMBus Block Write operation.
Definition smbus.h:465
smbus_api_smbalert_cb_t smbus_smbalert_set_cb
@driver_ops_optional Add SMBALERT callback for an SMBus host controller.
Definition smbus.h:471
smbus_api_byte_data_read_t smbus_byte_data_read
@driver_ops_optional Perform an SMBus Byte Data Read operation.
Definition smbus.h:457
smbus_api_smbalert_cb_t smbus_smbalert_remove_cb
@driver_ops_optional Remove SMBALERT callback from an SMBus host controller.
Definition smbus.h:473
smbus_api_byte_write_t smbus_byte_write
@driver_ops_optional Perform an SMBus Byte Write operation.
Definition smbus.h:451
smbus_api_byte_read_t smbus_byte_read
@driver_ops_optional Perform an SMBus Byte Read operation.
Definition smbus.h:453
smbus_api_quick_t smbus_quick
@driver_ops_optional Perform an SMBus Quick operation.
Definition smbus.h:449
smbus_api_block_pcall_t smbus_block_pcall
@driver_ops_optional Perform an SMBus Block Process Call operation.
Definition smbus.h:469
smbus_api_configure_t configure
@driver_ops_mandatory Configure operation of an SMBus host controller.
Definition smbus.h:445
Complete SMBus DT information.
Definition smbus.h:302
uint16_t addr
Address of the SMBus peripheral device.
Definition smbus.h:306
const struct device * bus
SMBus bus.
Definition smbus.h:304