Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
|
SMBus Interface . More...
Data Structures | |
struct | smbus_callback |
SMBus callback structure. More... | |
struct | smbus_dt_spec |
Complete SMBus DT information. More... | |
Macros | |
#define | SMBUS_BLOCK_BYTES_MAX 32 |
Maximum number of bytes in SMBus Block protocol. | |
#define | SMBUS_DT_SPEC_GET(node_id) |
Structure initializer for smbus_dt_spec from devicetree. | |
#define | SMBUS_DT_SPEC_INST_GET(inst) |
Structure initializer for smbus_dt_spec from devicetree instance. | |
#define | SMBUS_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, data_ptr, cfg_ptr, level, prio, api_ptr, ...) |
Like DEVICE_DT_DEFINE() with SMBus specifics. | |
#define | SMBUS_DEVICE_DT_INST_DEFINE(inst, ...) |
Like SMBUS_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT compatible. | |
Typedefs | |
typedef void(* | smbus_callback_handler_t) (const struct device *dev, struct smbus_callback *cb, uint8_t addr) |
Define SMBus callback handler function signature. | |
Functions | |
static void | smbus_xfer_stats (const struct device *dev, uint8_t sent, uint8_t recv) |
Updates the SMBus stats. | |
int | smbus_configure (const struct device *dev, uint32_t dev_config) |
Configure operation of a SMBus host controller. | |
int | smbus_get_config (const struct device *dev, uint32_t *dev_config) |
Get configuration of a SMBus host controller. | |
static int | smbus_smbalert_set_cb (const struct device *dev, struct smbus_callback *cb) |
Add SMBUSALERT callback for a SMBus host controller. | |
int | smbus_smbalert_remove_cb (const struct device *dev, struct smbus_callback *cb) |
Remove SMBUSALERT callback from a SMBus host controller. | |
static int | smbus_host_notify_set_cb (const struct device *dev, struct smbus_callback *cb) |
Add Host Notify callback for a SMBus host controller. | |
int | smbus_host_notify_remove_cb (const struct device *dev, struct smbus_callback *cb) |
Remove Host Notify callback from a SMBus host controller. | |
int | smbus_quick (const struct device *dev, uint16_t addr, enum smbus_direction direction) |
Perform SMBus Quick operation. | |
int | smbus_byte_write (const struct device *dev, uint16_t addr, uint8_t byte) |
Perform SMBus Byte Write operation. | |
int | smbus_byte_read (const struct device *dev, uint16_t addr, uint8_t *byte) |
Perform SMBus Byte Read operation. | |
int | smbus_byte_data_write (const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t byte) |
Perform SMBus Byte Data Write operation. | |
int | smbus_byte_data_read (const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *byte) |
Perform SMBus Byte Data Read operation. | |
int | smbus_word_data_write (const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t word) |
Perform SMBus Word Data Write operation. | |
int | smbus_word_data_read (const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t *word) |
Perform SMBus Word Data Read operation. | |
int | smbus_pcall (const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t send_word, uint16_t *recv_word) |
Perform SMBus Process Call operation. | |
int | smbus_block_write (const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t count, uint8_t *buf) |
Perform SMBus Block Write operation. | |
int | smbus_block_read (const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *count, uint8_t *buf) |
Perform 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 SMBus Block Process Call operation. | |
SMBus read / write direction | |
enum | smbus_direction { SMBUS_MSG_WRITE = 0 , SMBUS_MSG_READ = 1 } |
SMBus read / write direction. More... | |
SMBus Protocol commands | |
SMBus Specification defines the following SMBus protocols operations | |
#define | SMBUS_CMD_QUICK 0b000 |
SMBus Quick protocol is a very simple command with no data sent or received. | |
#define | SMBUS_CMD_BYTE 0b001 |
SMBus Byte protocol can send or receive one byte of data. | |
#define | SMBUS_CMD_BYTE_DATA 0b010 |
SMBus Byte Data protocol sends the first byte (command) followed by read or write one byte. | |
#define | SMBUS_CMD_WORD_DATA 0b011 |
SMBus Word Data protocol sends the first byte (command) followed by read or write two bytes. | |
#define | SMBUS_CMD_PROC_CALL 0b100 |
SMBus Process Call protocol is Write Word followed by Read Word. | |
#define | SMBUS_CMD_BLOCK 0b101 |
SMBus Block protocol reads or writes a block of data up to 32 bytes. | |
#define | SMBUS_CMD_BLOCK_PROC 0b111 |
SMBus Block Write - Block Read Process Call protocol is Block Write followed by Block Read. | |
SMBus device functionality | |
The following parameters describe the functionality of the SMBus device | |
#define | SMBUS_MODE_CONTROLLER BIT(0) |
Peripheral to act as Controller. | |
#define | SMBUS_MODE_PEC BIT(1) |
Support Packet Error Code (PEC) checking. | |
#define | SMBUS_MODE_HOST_NOTIFY BIT(2) |
Support Host Notify functionality. | |
#define | SMBUS_MODE_SMBALERT BIT(3) |
Support SMBALERT signal functionality. | |
SMBus special reserved addresses | |
The following addresses are reserved by SMBus specification | |
#define | SMBUS_ADDRESS_ARA 0x0c |
Alert Response Address (ARA) | |
SMBus Interface .
#define SMBUS_ADDRESS_ARA 0x0c |
#include <zephyr/drivers/smbus.h>
Alert Response Address (ARA)
A broadcast address used by the system host as part of the Alert Response Protocol.
#define SMBUS_BLOCK_BYTES_MAX 32 |
#include <zephyr/drivers/smbus.h>
Maximum number of bytes in SMBus Block protocol.
#define SMBUS_CMD_BLOCK 0b101 |
#include <zephyr/drivers/smbus.h>
SMBus Block protocol reads or writes a block of data up to 32 bytes.
The Count byte specifies the amount of data.
#define SMBUS_CMD_BLOCK_PROC 0b111 |
#include <zephyr/drivers/smbus.h>
SMBus Block Write - Block Read Process Call protocol is Block Write followed by Block Read.
#define SMBUS_CMD_BYTE 0b001 |
#include <zephyr/drivers/smbus.h>
SMBus Byte protocol can send or receive one byte of data.
#define SMBUS_CMD_BYTE_DATA 0b010 |
#include <zephyr/drivers/smbus.h>
SMBus Byte Data protocol sends the first byte (command) followed by read or write one byte.
#define SMBUS_CMD_PROC_CALL 0b100 |
#include <zephyr/drivers/smbus.h>
SMBus Process Call protocol is Write Word followed by Read Word.
It is named so because the command sends data and waits for the peripheral to return a reply.
#define SMBUS_CMD_QUICK 0b000 |
#include <zephyr/drivers/smbus.h>
SMBus Quick protocol is a very simple command with no data sent or received.
Peripheral may denote only R/W bit, which can still be used for the peripheral management, for example to switch peripheral On/Off. Quick protocol can also be used for peripheral devices scanning.
#define SMBUS_CMD_WORD_DATA 0b011 |
#include <zephyr/drivers/smbus.h>
SMBus Word Data protocol sends the first byte (command) followed by read or write two bytes.
#define SMBUS_DEVICE_DT_DEFINE | ( | node_id, | |
init_fn, | |||
pm_device, | |||
data_ptr, | |||
cfg_ptr, | |||
level, | |||
prio, | |||
api_ptr, | |||
... ) |
#include <zephyr/drivers/smbus.h>
Like DEVICE_DT_DEFINE() with SMBus specifics.
Defines a device which implements the SMBus API. May generate a custom device_state container struct and init_fn wrapper when needed depending on SMBus CONFIG_SMBUS_STATS
.
node_id | The devicetree node identifier. |
init_fn | Name of the init function of the driver. |
pm_device | PM device resources reference (NULL if device does not use PM). |
data_ptr | Pointer to the device's private data. |
cfg_ptr | The address to the structure containing the configuration information for this instance of the driver. |
level | The initialization level. See SYS_INIT() for details. |
prio | Priority within the selected initialization level. See SYS_INIT() for details. |
api_ptr | Provides an initial pointer to the API function struct used by the driver. Can be NULL. |
#define SMBUS_DEVICE_DT_INST_DEFINE | ( | inst, | |
... ) |
#include <zephyr/drivers/smbus.h>
Like SMBUS_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT compatible.
inst | instance number. This is replaced by DT_DRV_COMPAT(inst) in the call to SMBUS_DEVICE_DT_DEFINE(). |
... | other parameters as expected by SMBUS_DEVICE_DT_DEFINE(). |
#define SMBUS_DT_SPEC_GET | ( | node_id | ) |
#include <zephyr/drivers/smbus.h>
Structure initializer for smbus_dt_spec from devicetree.
This helper macro expands to a static initializer for a struct smbus_dt_spec
by reading the relevant bus and address data from the devicetree.
node_id | Devicetree node identifier for the SMBus device whose struct smbus_dt_spec to create an initializer for |
#define SMBUS_DT_SPEC_INST_GET | ( | inst | ) |
#include <zephyr/drivers/smbus.h>
Structure initializer for smbus_dt_spec from devicetree instance.
This is equivalent to SMBUS_DT_SPEC_GET(DT_DRV_INST(inst))
.
inst | Devicetree instance number |
#define SMBUS_MODE_CONTROLLER BIT(0) |
#include <zephyr/drivers/smbus.h>
Peripheral to act as Controller.
#define SMBUS_MODE_HOST_NOTIFY BIT(2) |
#include <zephyr/drivers/smbus.h>
Support Host Notify functionality.
#define SMBUS_MODE_PEC BIT(1) |
#include <zephyr/drivers/smbus.h>
Support Packet Error Code (PEC) checking.
#define SMBUS_MODE_SMBALERT BIT(3) |
#include <zephyr/drivers/smbus.h>
Support SMBALERT signal functionality.
typedef void(* smbus_callback_handler_t) (const struct device *dev, struct smbus_callback *cb, uint8_t addr) |
#include <zephyr/drivers/smbus.h>
Define SMBus callback handler function signature.
dev | Pointer to the device structure for the SMBus driver instance. |
cb | Structure smbus_callback owning this handler. |
addr | Address of the SMBus peripheral device. |
enum smbus_direction |
#include <zephyr/drivers/smbus.h>
SMBus read / write direction.
Enumerator | |
---|---|
SMBUS_MSG_WRITE | Write a message to SMBus peripheral. |
SMBUS_MSG_READ | Read a message from SMBus peripheral. |
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 ) |
#include <zephyr/drivers/smbus.h>
Perform SMBus Block Process Call operation.
This routine provides a generic interface to perform SMBus Block Process Call operation. This operation is basically Block Write followed by Block Read.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
snd_count | Size of the data block buffer to send. |
snd_buf | Data block buffer send to the peripheral device. |
rcv_count | Size of the data peripheral sent. |
rcv_buf | Data block buffer received from the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_block_pcall() is not implemented by the driver. |
int smbus_block_read | ( | const struct device * | dev, |
uint16_t | addr, | ||
uint8_t | cmd, | ||
uint8_t * | count, | ||
uint8_t * | buf ) |
#include <zephyr/drivers/smbus.h>
Perform SMBus Block Read operation.
This routine provides a generic interface to perform SMBus Block Read operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
count | Size of the data peripheral sent. Maximum 32 bytes. |
buf | Data block buffer received from the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_block_read() is not implemented by the driver. |
int smbus_block_write | ( | const struct device * | dev, |
uint16_t | addr, | ||
uint8_t | cmd, | ||
uint8_t | count, | ||
uint8_t * | buf ) |
#include <zephyr/drivers/smbus.h>
Perform SMBus Block Write operation.
This routine provides a generic interface to perform SMBus Block Write operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
count | Size of the data block buffer. Maximum 32 bytes. |
buf | Data block buffer to be sent to the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_block_write() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Perform SMBus Byte Data Read operation.
This routine provides a generic interface to perform SMBus Byte Data Read operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
byte | Byte received from the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_byte_data_read() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Perform SMBus Byte Data Write operation.
This routine provides a generic interface to perform SMBus Byte Data Write operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
byte | Byte to be sent to the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_byte_data_write() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Perform SMBus Byte Read operation.
This routine provides a generic interface to perform SMBus Byte Read operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
byte | Byte received from the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_byte_read() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Perform SMBus Byte Write operation.
This routine provides a generic interface to perform SMBus Byte Write operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
byte | Byte to be sent to the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_byte_write() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Configure operation of a SMBus host controller.
dev | Pointer to the device structure for the SMBus driver instance. |
dev_config | Bit-packed 32-bit value to the device runtime configuration for the SMBus controller. |
0 | If successful. |
-EIO | General input / output error. |
#include <zephyr/drivers/smbus.h>
Get configuration of a SMBus host controller.
This routine provides a way to get current configuration. It is allowed to call the function before smbus_configure, because some SMBus ports can be configured during init process. However, if the SMBus port is not configured, smbus_get_config returns an error.
smbus_get_config can return cached config or probe hardware, but it has to be up to date with current configuration.
dev | Pointer to the device structure for the SMBus driver instance. |
dev_config | Pointer to return bit-packed 32-bit value of the SMBus controller configuration. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_get_config() is not implemented by the driver. |
int smbus_host_notify_remove_cb | ( | const struct device * | dev, |
struct smbus_callback * | cb ) |
#include <zephyr/drivers/smbus.h>
Remove Host Notify callback from a SMBus host controller.
dev | Pointer to the device structure for the SMBus driver instance. |
cb | Pointer to a callback structure. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_host_notify_remove_cb() is not implemented by the driver. |
|
inlinestatic |
#include <zephyr/drivers/smbus.h>
Add Host Notify callback for a SMBus host controller.
dev | Pointer to the device structure for the SMBus driver instance. |
cb | Pointer to a callback structure. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_host_notify_set_cb() is not implemented by the driver. |
int smbus_pcall | ( | const struct device * | dev, |
uint16_t | addr, | ||
uint8_t | cmd, | ||
uint16_t | send_word, | ||
uint16_t * | recv_word ) |
#include <zephyr/drivers/smbus.h>
Perform SMBus Process Call operation.
This routine provides a generic interface to perform SMBus Process Call operation, which means Write 2 bytes following by Read 2 bytes.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
send_word | Word (16-bit) to be sent to the peripheral device. |
recv_word | Word (16-bit) received from the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_pcall() is not implemented by the driver. |
int smbus_quick | ( | const struct device * | dev, |
uint16_t | addr, | ||
enum smbus_direction | direction ) |
#include <zephyr/drivers/smbus.h>
Perform SMBus Quick operation.
This routine provides a generic interface to perform SMBus Quick operation.
dev | Pointer to the device structure for the SMBus driver instance. driver configured in controller mode. |
addr | Address of the SMBus peripheral device. |
direction | Direction Read or Write. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_quick() is not implemented by the driver. |
int smbus_smbalert_remove_cb | ( | const struct device * | dev, |
struct smbus_callback * | cb ) |
#include <zephyr/drivers/smbus.h>
Remove SMBUSALERT callback from a SMBus host controller.
dev | Pointer to the device structure for the SMBus driver instance. |
cb | Pointer to a callback structure. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_smbalert_remove_cb() is not implemented by the driver. |
|
inlinestatic |
#include <zephyr/drivers/smbus.h>
Add SMBUSALERT callback for a SMBus host controller.
dev | Pointer to the device structure for the SMBus driver instance. |
cb | Pointer to a callback structure. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_smbalert_set_cb() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Perform SMBus Word Data Read operation.
This routine provides a generic interface to perform SMBus Word Data Read operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
word | Word (16-bit) received from the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_word_data_read() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Perform SMBus Word Data Write operation.
This routine provides a generic interface to perform SMBus Word Data Write operation.
dev | Pointer to the device structure for the SMBus driver instance. |
addr | Address of the SMBus peripheral device. |
cmd | Command byte which is sent to peripheral device first. |
word | Word (16-bit) to be sent to the peripheral device. |
0 | If successful. |
-EIO | General input / output error. |
-ENOSYS | If function smbus_word_data_write() is not implemented by the driver. |
#include <zephyr/drivers/smbus.h>
Updates the SMBus stats.
dev | Pointer to the device structure for the SMBus driver instance to update stats for. |
sent | Number of bytes sent |
recv | Number of bytes received |