zephyr/drivers/i2c/i2c_npcx_controller.h

77 lines
2.3 KiB
C

/*
* Copyright (c) 2020 Nuvoton Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_
#define ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Lock the mutex of npcx i2c controller.
*
* @param i2c_dev Pointer to the device structure for i2c controller instance.
*/
void npcx_i2c_ctrl_mutex_lock(const struct device *i2c_dev);
/**
* @brief Unlock the mutex of npcx i2c controller.
*
* @param i2c_dev Pointer to the device structure for i2c controller instance.
*/
void npcx_i2c_ctrl_mutex_unlock(const struct device *i2c_dev);
/**
* @brief Configure operation of a npcx i2c controller.
*
* @param i2c_dev Pointer to the device structure for i2c controller instance.
* @param dev_config Bit-packed 32-bit value to the device runtime configuration
* for the I2C controller.
*
* @retval 0 If successful.
* @retval -EIO General input / output error, failed to configure device.
* @retval -ERANGE Out of supported i2c frequency.
*/
int npcx_i2c_ctrl_configure(const struct device *i2c_dev, uint32_t dev_config);
/**
* @brief Get I2C controller speed.
*
* @param i2c_dev Pointer to the device structure for i2c controller instance.
* @param speed Pointer to store the I2C speed.
*
* @retval 0 If successful.
* @retval -ERANGE Stored I2C frequency out of supported range.
* @retval -EIO Controller is not configured.
*/
int npcx_i2c_ctrl_get_speed(const struct device *i2c_dev, uint32_t *speed);
/**
* @brief Perform data transfer to via npcx i2c controller.
*
* @param i2c_dev Pointer to the device structure for i2c controller instance.
* @param msgs Array of messages to transfer.
* @param num_msgs Number of messages to transfer.
* @param addr Address of the I2C target device.
* @param port Port index of selected i2c port.
*
* @retval 0 If successful.
* @retval -EIO General input / output error.
* @retval -ENXIO No slave address match.
* @retval -ETIMEDOUT Timeout occurred for a i2c transaction.
*/
int npcx_i2c_ctrl_transfer(const struct device *i2c_dev, struct i2c_msg *msgs,
uint8_t num_msgs, uint16_t addr, uint8_t port);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_ */