Lines Matching +full:write +full:- +full:command
4 * SPDX-License-Identifier: Apache-2.0
18 #include "i2c-priv.h"
22 #define I2C_REG(config, reg) ((mem_addr_t) ((config)->base + reg))
32 /* Transmit on write, receive on read */
36 /* Command on write, status on read */
73 const struct i2c_sifive_cfg *config = dev->config; in i2c_sifive_busy()
82 const struct i2c_sifive_cfg *config = dev->config; in i2c_sifive_send_addr()
83 uint8_t command = 0U; in i2c_sifive_send_addr() local
89 /* Set transmit register to address with read/write flag */ in i2c_sifive_send_addr()
93 command = SF_CMD_WRITE | SF_CMD_START; in i2c_sifive_send_addr()
95 /* Write the command register to start the transfer */ in i2c_sifive_send_addr()
96 sys_write8(command, I2C_REG(config, REG_COMMAND)); in i2c_sifive_send_addr()
103 return -EIO; in i2c_sifive_send_addr()
113 const struct i2c_sifive_cfg *config = dev->config; in i2c_sifive_write_msg()
115 uint8_t command = 0U; in i2c_sifive_write_msg() local
119 LOG_ERR("I2C failed to write message\n"); in i2c_sifive_write_msg()
123 for (uint32_t i = 0; i < msg->len; i++) { in i2c_sifive_write_msg()
129 sys_write8((msg->buf)[i], I2C_REG(config, REG_TRANSMIT)); in i2c_sifive_write_msg()
131 /* Generate command byte */ in i2c_sifive_write_msg()
132 command = SF_CMD_WRITE; in i2c_sifive_write_msg()
135 if (i == (msg->len - 1)) { in i2c_sifive_write_msg()
137 if (msg->flags & I2C_MSG_STOP) { in i2c_sifive_write_msg()
138 command |= SF_CMD_STOP; in i2c_sifive_write_msg()
142 /* Write command reg */ in i2c_sifive_write_msg()
143 sys_write8(command, I2C_REG(config, REG_COMMAND)); in i2c_sifive_write_msg()
151 return -EIO; in i2c_sifive_write_msg()
162 const struct i2c_sifive_cfg *config = dev->config; in i2c_sifive_read_msg()
163 uint8_t command = 0U; in i2c_sifive_read_msg() local
170 for (int i = 0; i < msg->len; i++) { in i2c_sifive_read_msg()
171 /* Generate command byte */ in i2c_sifive_read_msg()
172 command = SF_CMD_READ; in i2c_sifive_read_msg()
175 if (i == (msg->len - 1)) { in i2c_sifive_read_msg()
177 command |= SF_CMD_ACK; in i2c_sifive_read_msg()
180 if (msg->flags & I2C_MSG_STOP) { in i2c_sifive_read_msg()
181 command |= SF_CMD_STOP; in i2c_sifive_read_msg()
185 /* Write command reg */ in i2c_sifive_read_msg()
186 sys_write8(command, I2C_REG(config, REG_COMMAND)); in i2c_sifive_read_msg()
193 (msg->buf)[i] = sys_read8(I2C_REG(config, REG_RECEIVE)); in i2c_sifive_read_msg()
210 return -EINVAL; in i2c_sifive_configure()
212 config = dev->config; in i2c_sifive_configure()
215 return -EINVAL; in i2c_sifive_configure()
234 return -ENOTSUP; in i2c_sifive_configure()
238 prescale = (config->f_sys / (i2c_speed * 5U)) - 1; in i2c_sifive_configure()
248 return -ENOTSUP; in i2c_sifive_configure()
252 * Driver does not support 10-bit addressing. This can be added in i2c_sifive_configure()
256 LOG_ERR("I2C driver does not support 10-bit addresses"); in i2c_sifive_configure()
257 return -ENOTSUP; in i2c_sifive_configure()
276 return -EINVAL; in i2c_sifive_transfer()
278 if (dev->config == NULL) { in i2c_sifive_transfer()
280 return -EINVAL; in i2c_sifive_transfer()
283 return -EINVAL; in i2c_sifive_transfer()
304 const struct i2c_sifive_cfg *config = dev->config; in i2c_sifive_init()
308 dev_config = (I2C_MODE_CONTROLLER | i2c_map_dt_bitrate(config->f_bus)); in i2c_sifive_init()