2020-08-17 11:41:30 +08:00
|
|
|
/*
|
|
|
|
* 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_
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/device.h>
|
2020-08-17 11:41:30 +08:00
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2021-09-30 18:42:20 +08:00
|
|
|
/**
|
|
|
|
* @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);
|
2020-08-17 11:41:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
2022-08-18 13:59:38 +08:00
|
|
|
/**
|
2024-01-13 01:55:44 +08:00
|
|
|
* @brief Toggle the SCL to generate maximum 9 clocks until the target release
|
2022-08-18 13:59:38 +08:00
|
|
|
* the SDA line and send a STOP condition.
|
|
|
|
*
|
|
|
|
* @param i2c_dev Pointer to the device structure for i2c controller instance.
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval -EBUSY fail to recover the bus.
|
|
|
|
*/
|
|
|
|
int npcx_i2c_ctrl_recover_bus(const struct device *dev);
|
|
|
|
|
2023-04-19 14:28:53 +08:00
|
|
|
/**
|
|
|
|
* @brief Registers the provided config as Target device of a npcx i2c controller.
|
|
|
|
*
|
|
|
|
* @param i2c_dev Pointer to the device structure for i2c controller instance.
|
|
|
|
* @param target_cfg Config struct used by the i2c target driver
|
|
|
|
* @param port Port index of selected i2c port.
|
|
|
|
*
|
|
|
|
* @retval 0 Is successful
|
|
|
|
* @retval -EBUSY If i2c transaction is proceeding.
|
|
|
|
*/
|
|
|
|
int npcx_i2c_ctrl_target_register(const struct device *i2c_dev,
|
|
|
|
struct i2c_target_config *target_cfg, uint8_t port);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unregisters the provided config as Target device of a npcx i2c controller.
|
|
|
|
*
|
|
|
|
* @param i2c_dev Pointer to the device structure for i2c controller instance.
|
|
|
|
* @param target_cfg Config struct used by the i2c target driver
|
|
|
|
*
|
|
|
|
* @retval 0 Is successful
|
|
|
|
* @retval -EBUSY If i2c transaction is proceeding.
|
|
|
|
* @retval -EINVAL If parameters are invalid
|
|
|
|
*/
|
|
|
|
int npcx_i2c_ctrl_target_unregister(const struct device *i2c_dev,
|
|
|
|
struct i2c_target_config *target_cfg);
|
|
|
|
|
2020-08-17 11:41:30 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_ */
|