Lines Matching +full:i2c +full:- +full:speed
4 * SPDX-License-Identifier: Apache-2.0
11 * @brief Nuvoton NPCX smb/i2c port driver
13 * This file contains the driver of SMBus/I2C buses (ports) which provides
14 * pin-muxing for each i2c io-pads. In order to support "SMBus Multi-Bus"
16 * between Zephyr i2c api functions and i2c controller driver which provides
17 * full support for SMBus/I2C transactions.
22 * SCL_N Port 0----| \ +--------------+
23 * SDA_N Port 0----| |----| SMB/I2C |
24 * | |----| Controller N |
25 * SCL_N Port 1----| | +--------------+
26 * SDA_N Port 1----| /
33 #include <zephyr/drivers/i2c.h>
35 #include <zephyr/dt-bindings/i2c/i2c.h>
42 #include "i2c-priv.h"
53 /* I2C api functions */
57 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_port_configure()
59 if (config->i2c_ctrl == NULL) { in i2c_npcx_port_configure()
60 LOG_ERR("Cannot find i2c controller on port%02x!", in i2c_npcx_port_configure()
61 config->port); in i2c_npcx_port_configure()
62 return -EIO; in i2c_npcx_port_configure()
66 return -ENOTSUP; in i2c_npcx_port_configure()
70 return -ENOTSUP; in i2c_npcx_port_configure()
73 /* Configure i2c controller */ in i2c_npcx_port_configure()
74 return npcx_i2c_ctrl_configure(config->i2c_ctrl, dev_config); in i2c_npcx_port_configure()
79 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_port_get_config()
80 uint32_t speed; in i2c_npcx_port_get_config() local
83 if (config->i2c_ctrl == NULL) { in i2c_npcx_port_get_config()
84 LOG_ERR("Cannot find i2c controller on port%02x!", config->port); in i2c_npcx_port_get_config()
85 return -EIO; in i2c_npcx_port_get_config()
88 ret = npcx_i2c_ctrl_get_speed(config->i2c_ctrl, &speed); in i2c_npcx_port_get_config()
90 *dev_config = (I2C_MODE_CONTROLLER | speed); in i2c_npcx_port_get_config()
99 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_port_transfer()
101 int idx_ctrl = (config->port & 0xF0) >> 4; in i2c_npcx_port_transfer()
102 int idx_port = (config->port & 0x0F); in i2c_npcx_port_transfer()
104 if (config->i2c_ctrl == NULL) { in i2c_npcx_port_transfer()
105 LOG_ERR("Cannot find i2c controller on port%02x!", in i2c_npcx_port_transfer()
106 config->port); in i2c_npcx_port_transfer()
107 return -EIO; in i2c_npcx_port_transfer()
110 /* Lock mutex of i2c/smb controller */ in i2c_npcx_port_transfer()
111 npcx_i2c_ctrl_mutex_lock(config->i2c_ctrl); in i2c_npcx_port_transfer()
113 /* Switch correct port for i2c controller first */ in i2c_npcx_port_transfer()
116 /* Start transaction with i2c controller */ in i2c_npcx_port_transfer()
117 ret = npcx_i2c_ctrl_transfer(config->i2c_ctrl, msgs, num_msgs, addr, in i2c_npcx_port_transfer()
118 config->port); in i2c_npcx_port_transfer()
120 /* Unlock mutex of i2c/smb controller */ in i2c_npcx_port_transfer()
121 npcx_i2c_ctrl_mutex_unlock(config->i2c_ctrl); in i2c_npcx_port_transfer()
127 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_port_recover_bus()
130 if (config->i2c_ctrl == NULL) { in i2c_npcx_port_recover_bus()
131 LOG_ERR("Cannot find i2c controller on port%02x!", config->port); in i2c_npcx_port_recover_bus()
132 return -EIO; in i2c_npcx_port_recover_bus()
135 /* Lock mutex of i2c/smb controller */ in i2c_npcx_port_recover_bus()
136 npcx_i2c_ctrl_mutex_lock(config->i2c_ctrl); in i2c_npcx_port_recover_bus()
138 ret = npcx_i2c_ctrl_recover_bus(config->i2c_ctrl); in i2c_npcx_port_recover_bus()
140 /* Unlock mutex of i2c/smb controller */ in i2c_npcx_port_recover_bus()
141 npcx_i2c_ctrl_mutex_unlock(config->i2c_ctrl); in i2c_npcx_port_recover_bus()
150 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_target_register()
153 return -EINVAL; in i2c_npcx_target_register()
156 if (config->i2c_ctrl == NULL) { in i2c_npcx_target_register()
157 LOG_ERR("Cannot find i2c controller on port%02x!", config->port); in i2c_npcx_target_register()
158 return -EIO; in i2c_npcx_target_register()
161 return npcx_i2c_ctrl_target_register(config->i2c_ctrl, target_cfg, config->port); in i2c_npcx_target_register()
167 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_target_unregister()
169 if (config->i2c_ctrl == NULL) { in i2c_npcx_target_unregister()
170 LOG_ERR("Cannot find i2c controller on port%02x!", config->port); in i2c_npcx_target_unregister()
171 return -EIO; in i2c_npcx_target_unregister()
174 return npcx_i2c_ctrl_target_unregister(config->i2c_ctrl, target_cfg); in i2c_npcx_target_unregister()
178 /* I2C driver registration */
181 const struct i2c_npcx_port_config *const config = dev->config; in i2c_npcx_port_init()
185 /* Configure pin-mux for I2C device */ in i2c_npcx_port_init()
186 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in i2c_npcx_port_init()
188 LOG_ERR("I2C pinctrl setup failed (%d)", ret); in i2c_npcx_port_init()
193 /* Setup initial i2c configuration */ in i2c_npcx_port_init()
194 i2c_config = (I2C_MODE_CONTROLLER | i2c_map_dt_bitrate(config->bitrate)); in i2c_npcx_port_init()
203 static DEVICE_API(i2c, i2c_port_npcx_driver_api) = {
217 /* I2C port init macro functions */