1 /* 2 * Copyright (c) 2020 Nuvoton Technology Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_ 8 #define ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_ 9 10 #include <zephyr/device.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** 17 * @brief Lock the mutex of npcx i2c controller. 18 * 19 * @param i2c_dev Pointer to the device structure for i2c controller instance. 20 */ 21 void npcx_i2c_ctrl_mutex_lock(const struct device *i2c_dev); 22 23 /** 24 * @brief Unlock the mutex of npcx i2c controller. 25 * 26 * @param i2c_dev Pointer to the device structure for i2c controller instance. 27 */ 28 void npcx_i2c_ctrl_mutex_unlock(const struct device *i2c_dev); 29 30 /** 31 * @brief Configure operation of a npcx i2c controller. 32 * 33 * @param i2c_dev Pointer to the device structure for i2c controller instance. 34 * @param dev_config Bit-packed 32-bit value to the device runtime configuration 35 * for the I2C controller. 36 * 37 * @retval 0 If successful. 38 * @retval -EIO General input / output error, failed to configure device. 39 * @retval -ERANGE Out of supported i2c frequency. 40 */ 41 int npcx_i2c_ctrl_configure(const struct device *i2c_dev, uint32_t dev_config); 42 43 /** 44 * @brief Get I2C controller speed. 45 * 46 * @param i2c_dev Pointer to the device structure for i2c controller instance. 47 * @param speed Pointer to store the I2C speed. 48 * 49 * @retval 0 If successful. 50 * @retval -ERANGE Stored I2C frequency out of supported range. 51 * @retval -EIO Controller is not configured. 52 */ 53 int npcx_i2c_ctrl_get_speed(const struct device *i2c_dev, uint32_t *speed); 54 55 /** 56 * @brief Perform data transfer to via npcx i2c controller. 57 * 58 * @param i2c_dev Pointer to the device structure for i2c controller instance. 59 * @param msgs Array of messages to transfer. 60 * @param num_msgs Number of messages to transfer. 61 * @param addr Address of the I2C target device. 62 * @param port Port index of selected i2c port. 63 * 64 * @retval 0 If successful. 65 * @retval -EIO General input / output error. 66 * @retval -ENXIO No slave address match. 67 * @retval -ETIMEDOUT Timeout occurred for a i2c transaction. 68 */ 69 int npcx_i2c_ctrl_transfer(const struct device *i2c_dev, struct i2c_msg *msgs, 70 uint8_t num_msgs, uint16_t addr, uint8_t port); 71 72 /** 73 * @brief Toggle the SCL to generate maxmium 9 clocks until the target release 74 * the SDA line and send a STOP condition. 75 * 76 * @param i2c_dev Pointer to the device structure for i2c controller instance. 77 * 78 * @retval 0 If successful. 79 * @retval -EBUSY fail to recover the bus. 80 */ 81 int npcx_i2c_ctrl_recover_bus(const struct device *dev); 82 83 /** 84 * @brief Registers the provided config as Target device of a npcx i2c controller. 85 * 86 * @param i2c_dev Pointer to the device structure for i2c controller instance. 87 * @param target_cfg Config struct used by the i2c target driver 88 * @param port Port index of selected i2c port. 89 * 90 * @retval 0 Is successful 91 * @retval -EBUSY If i2c transaction is proceeding. 92 */ 93 int npcx_i2c_ctrl_target_register(const struct device *i2c_dev, 94 struct i2c_target_config *target_cfg, uint8_t port); 95 96 /** 97 * @brief Unregisters the provided config as Target device of a npcx i2c controller. 98 * 99 * @param i2c_dev Pointer to the device structure for i2c controller instance. 100 * @param target_cfg Config struct used by the i2c target driver 101 * 102 * @retval 0 Is successful 103 * @retval -EBUSY If i2c transaction is proceeding. 104 * @retval -EINVAL If parameters are invalid 105 */ 106 int npcx_i2c_ctrl_target_unregister(const struct device *i2c_dev, 107 struct i2c_target_config *target_cfg); 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif /* ZEPHYR_DRIVERS_I2C_I2C_NPCX_CONTROLLER_H_ */ 114