TT-System-Firmware APIs 19.13.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
smbus_target.c File Reference
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#include <errno.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/atomic.h>
#include <tenstorrent/smbus_target.h>
#include <zephyr/logging/log.h>
Include dependency graph for smbus_target.c:

Data Structures

struct  smbus_target_data
struct  smbus_target_config

Macros

#define DT_DRV_COMPAT   zephyr_smbus_target
#define LOG_LEVEL   CONFIG_I2C_LOG_LEVEL
#define SMBUS_LOG_ERR_RATELIMIT(data, fmt, ...)
#define SMBUS_TARGET_INIT(inst)

Enumerations

enum  smbus_state {
  SMBUS_STATE_IDLE ,
  SMBUS_STATE_CMD ,
  SMBUS_STATE_RCV_DATA ,
  SMBUS_STATE_RCV_PEC ,
  SMBUS_STATE_SEND_DATA ,
  SMBUS_STATE_SEND_PEC ,
  SMBUS_STATE_WAIT_IDLE
}

Functions

 LOG_MODULE_REGISTER (i2c_target)
static const struct smbus_cmd_defget_cmd_def (struct smbus_target_data *smbus_data, uint8_t cmd)
static uint8_t pec_crc_8 (uint8_t crc, uint8_t data)
static int32_t smbus_target_register (const struct device *dev)
static int32_t smbus_target_unregister (const struct device *dev)
static int smbus_write_handler (struct i2c_target_config *config, uint8_t val)
static int32_t smbus_read_handler (struct i2c_target_config *config, uint8_t *val)
uint32_t smbus_target_get_error_count (const struct device *dev)
 Get total number of SMBUS target errors.
static void reset_state_machine (struct smbus_target_data *smbus_data)
static int32_t smbus_stop_handler (struct i2c_target_config *config)
static int32_t smbus_write_requested (struct i2c_target_config *config)
static DEVICE_API (i2c_target, api_funcs)
static int32_t smbus_target_init (const struct device *dev)
int32_t smbus_target_register_cmd (const struct device *dev, uint8_t cmd_id, const struct smbus_cmd_def *smbus_cmd)
 Register the given command to the SMBUS target implementation.
int32_t smbus_target_register_cmds (const struct device *dev, const struct smbus_cmd_registration *cmds, size_t num_cmds)
 Register a table of commands to the SMBUS target implementation.

Variables

const struct i2c_target_callbacks smbus_target_cb_impl

Macro Definition Documentation

◆ DT_DRV_COMPAT

#define DT_DRV_COMPAT   zephyr_smbus_target

◆ LOG_LEVEL

#define LOG_LEVEL   CONFIG_I2C_LOG_LEVEL

◆ SMBUS_LOG_ERR_RATELIMIT

#define SMBUS_LOG_ERR_RATELIMIT ( data,
fmt,
... )
Value:
do { \
atomic_inc(&(data)->error_count); \
LOG_ERR_RATELIMIT(fmt, ##__VA_ARGS__); \
} while (0)

◆ SMBUS_TARGET_INIT

#define SMBUS_TARGET_INIT ( inst)
Value:
static struct smbus_target_data smbus_target_##inst##_dev_data = {0}; \
static const struct smbus_target_config smbus_target_##inst##_cfg = { \
.bus = I2C_DT_SPEC_INST_GET(inst), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, &smbus_target_init, NULL, &smbus_target_##inst##_dev_data, \
&smbus_target_##inst##_cfg, POST_KERNEL, \
CONFIG_I2C_TARGET_INIT_PRIORITY, &api_funcs);
#define NULL
Definition avs.c:45
static int32_t smbus_target_init(const struct device *dev)
Definition smbus_target.c:385
#define I2C_DT_SPEC_INST_GET(inst)
Definition smbus_target.c:51
Definition smbus_target.c:37

Enumeration Type Documentation

◆ smbus_state

Enumerator
SMBUS_STATE_IDLE 
SMBUS_STATE_CMD 
SMBUS_STATE_RCV_DATA 
SMBUS_STATE_RCV_PEC 
SMBUS_STATE_SEND_DATA 
SMBUS_STATE_SEND_PEC 
SMBUS_STATE_WAIT_IDLE 

Function Documentation

◆ DEVICE_API()

DEVICE_API ( i2c_target ,
api_funcs  )
static

◆ get_cmd_def()

const struct smbus_cmd_def * get_cmd_def ( struct smbus_target_data * smbus_data,
uint8_t cmd )
static

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( i2c_target )

◆ pec_crc_8()

uint8_t pec_crc_8 ( uint8_t crc,
uint8_t data )
inlinestatic

◆ reset_state_machine()

void reset_state_machine ( struct smbus_target_data * smbus_data)
static

◆ smbus_read_handler()

int32_t smbus_read_handler ( struct i2c_target_config * config,
uint8_t * val )
static

◆ smbus_stop_handler()

int32_t smbus_stop_handler ( struct i2c_target_config * config)
static

◆ smbus_target_get_error_count()

uint32_t smbus_target_get_error_count ( const struct device * dev)

Get total number of SMBUS target errors.

Parameters
devThe SMBUS target device instance.
Returns
Number of errors that went through the SMBUS ratelimited error macro.

◆ smbus_target_init()

int32_t smbus_target_init ( const struct device * dev)
static

◆ smbus_target_register()

int32_t smbus_target_register ( const struct device * dev)
static

◆ smbus_target_register_cmd()

int32_t smbus_target_register_cmd ( const struct device * dev,
uint8_t cmd_id,
const struct smbus_cmd_def * smbus_cmd )

Register the given command to the SMBUS target implementation.

Parameters
devThe device to register the command for.
cmd_idThe command ID to register the handler for.
smbus_cmdPointer to the smbus command to register. The memory must have persistent storage for the duration of the time the target remains registered to the I2C.

◆ smbus_target_register_cmds()

int32_t smbus_target_register_cmds ( const struct device * dev,
const struct smbus_cmd_registration * cmds,
size_t num_cmds )

Register a table of commands to the SMBUS target implementation.

Parameters
devThe device to register commands for.
cmdsPointer to command registration table.
num_cmdsNumber of entries in cmds.
Returns
0 on success, otherwise a negative error code.

◆ smbus_target_unregister()

int32_t smbus_target_unregister ( const struct device * dev)
static

◆ smbus_write_handler()

int smbus_write_handler ( struct i2c_target_config * config,
uint8_t val )
static

◆ smbus_write_requested()

int32_t smbus_write_requested ( struct i2c_target_config * config)
static

Variable Documentation

◆ smbus_target_cb_impl

const struct i2c_target_callbacks smbus_target_cb_impl
Initial value:
= {
.write_requested = &smbus_write_requested,
.write_received = &smbus_write_handler,
.read_requested = &smbus_read_handler,
.read_processed = &smbus_read_handler,
}
static int smbus_write_handler(struct i2c_target_config *config, uint8_t val)
Definition smbus_target.c:81
static int32_t smbus_read_handler(struct i2c_target_config *config, uint8_t *val)
Definition smbus_target.c:216
static int32_t smbus_write_requested(struct i2c_target_config *config)
Definition smbus_target.c:366
static int32_t smbus_stop_handler(struct i2c_target_config *config)
Definition smbus_target.c:356