TT-System-Firmware APIs 19.13.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
smbus_target.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tenstorrent AI ULC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef SMBUS_TARGET
8#define SMBUS_TARGET
9
10#include <stddef.h>
11#include <stdint.h>
12
25
32typedef int32_t (*smbus_rcv_handler)(const uint8_t *data, uint8_t size);
33
40typedef int32_t (*smbus_send_handler)(uint8_t *data, uint8_t *size);
41
48
56
60#define SMBUS_CMD_ENTRY(_cmd, _pec, _trans_type, _rcv, _send) \
61 { \
62 .cmd = (_cmd), \
63 .def = {.pec = (_pec), \
64 .trans_type = (_trans_type), \
65 .rcv_handler = (_rcv), \
66 .send_handler = (_send)}, \
67 }
68
72#define SMBUS_CMD_HANDLER_FIELDS_WRITE(_func) .rcv_handler = (_func), .send_handler = NULL
73
77#define SMBUS_CMD_HANDLER_FIELDS_READ(_func) .rcv_handler = NULL, .send_handler = (_func)
78
84#define SMBUS_CMD_GEN_ENTRY(_cmd, _pec, _dir, _kind, _func) \
85 { \
86 .cmd = (_cmd), \
87 .def = {.pec = (_pec), \
88 .trans_type = SMBUS_TRANS_##_dir##_##_kind, \
89 SMBUS_CMD_HANDLER_FIELDS_##_dir(_func)}, \
90 }
91
95#define SMBUS_CMD_BLOCK_RD_ENTRY(_cmd, _pec, _send) \
96 SMBUS_CMD_GEN_ENTRY(_cmd, _pec, READ, BLOCK, _send)
97
101#define SMBUS_CMD_BLOCK_WR_ENTRY(_cmd, _pec, _rcv) \
102 SMBUS_CMD_GEN_ENTRY(_cmd, _pec, WRITE, BLOCK, _rcv)
103
107#define SMBUS_CMD_READ_BYTE_ENTRY(_cmd, _pec, _send) \
108 SMBUS_CMD_GEN_ENTRY(_cmd, _pec, READ, BYTE, _send)
109
113#define SMBUS_CMD_WRITE_BYTE_ENTRY(_cmd, _pec, _rcv) \
114 SMBUS_CMD_GEN_ENTRY(_cmd, _pec, WRITE, BYTE, _rcv)
115
119#define SMBUS_CMD_READ_WORD_ENTRY(_cmd, _pec, _send) \
120 SMBUS_CMD_GEN_ENTRY(_cmd, _pec, READ, WORD, _send)
121
125#define SMBUS_CMD_WRITE_WORD_ENTRY(_cmd, _pec, _rcv) \
126 SMBUS_CMD_GEN_ENTRY(_cmd, _pec, WRITE, WORD, _rcv)
127
131#define SMBUS_CMD_BLOCK_WR_BLOCK_RD_ENTRY(_cmd, _pec, _rcv, _send) \
132 SMBUS_CMD_ENTRY(_cmd, _pec, SMBUS_TRANS_READ_WRITE_BLOCK, _rcv, _send)
133
142int32_t smbus_target_register_cmd(const struct device *dev, uint8_t cmd_id,
143 const struct smbus_cmd_def *smbus_cmd);
144
153 const struct smbus_cmd_registration *cmds, size_t num_cmds);
154
161#endif
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.
Definition smbus_target.c:402
smbus_trans_type
A list of supported SMBUS transaction types.
Definition smbus_target.h:16
@ SMBUS_TRANS_READ_BYTE
Definition smbus_target.h:18
@ SMBUS_TRANS_READ_WRITE_BLOCK
Definition smbus_target.h:23
@ SMBUS_TRANS_WRITE_BYTE
Definition smbus_target.h:17
@ SMBUS_TRANS_WRITE_BLOCK
Definition smbus_target.h:21
@ SMBUS_TRANS_WRITE_WORD
Definition smbus_target.h:19
@ SMBUS_TRANS_READ_BLOCK
Definition smbus_target.h:22
@ SMBUS_TRANS_READ_WORD
Definition smbus_target.h:20
uint32_t smbus_target_get_error_count(const struct device *dev)
Get total number of SMBUS target errors.
Definition smbus_target.c:333
int32_t(* smbus_rcv_handler)(const uint8_t *data, uint8_t size)
Definition of a SMBUS receive handler.
Definition smbus_target.h:32
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.
Definition smbus_target.c:416
int32_t(* smbus_send_handler)(uint8_t *data, uint8_t *size)
Definition of a SMBUS send handler.
Definition smbus_target.h:40
__UINT32_TYPE__ uint32_t
__INT32_TYPE__ int32_t
__UINT8_TYPE__ uint8_t
Definition smbus_target.h:42
uint8_t pec
Definition smbus_target.h:46
smbus_rcv_handler rcv_handler
Definition smbus_target.h:44
smbus_send_handler send_handler
Definition smbus_target.h:45
enum smbus_trans_type trans_type
Definition smbus_target.h:43
Command registration entry for table-driven SMBus setup.
Definition smbus_target.h:52
struct smbus_cmd_def def
Definition smbus_target.h:54
uint8_t cmd
Definition smbus_target.h:53