Lines Matching +full:enable +full:- +full:high +full:- +full:speed +full:- +full:mode

5  * SPDX-License-Identifier: Apache-2.0
13 * Only I2C Master Mode with 7 bit addressing is currently supported.
32 #include "i2c-priv.h"
34 /** I2C bus speed [Hz] in Standard Mode */
36 /** I2C bus speed [Hz] in Fast Mode */
38 /** I2C bus speed [Hz] in High Speed Mode */
72 static int i2c_clk_set(Twihs *const twihs, uint32_t speed) in i2c_clk_set() argument
82 cl_div = ((SOC_ATMEL_SAM_MCK_FREQ_HZ / (speed * 2U)) - 3) in i2c_clk_set()
94 return -EIO; in i2c_clk_set()
98 twihs->TWIHS_CWGR = TWIHS_CWGR_CLDIV(cl_div) | TWIHS_CWGR_CHDIV(cl_div) in i2c_clk_set()
106 const struct i2c_sam_twihs_dev_cfg *const dev_cfg = dev->config; in i2c_sam_twihs_configure()
107 Twihs *const twihs = dev_cfg->regs; in i2c_sam_twihs_configure()
112 LOG_ERR("Master Mode is not enabled"); in i2c_sam_twihs_configure()
113 return -EIO; in i2c_sam_twihs_configure()
117 LOG_ERR("I2C 10-bit addressing is currently not supported"); in i2c_sam_twihs_configure()
119 return -EIO; in i2c_sam_twihs_configure()
131 LOG_ERR("Unsupported I2C speed value"); in i2c_sam_twihs_configure()
132 return -EIO; in i2c_sam_twihs_configure()
141 /* Disable Slave Mode */ in i2c_sam_twihs_configure()
142 twihs->TWIHS_CR = TWIHS_CR_SVDIS; in i2c_sam_twihs_configure()
144 /* Enable Master Mode */ in i2c_sam_twihs_configure()
145 twihs->TWIHS_CR = TWIHS_CR_MSEN; in i2c_sam_twihs_configure()
154 twihs->TWIHS_MMR = TWIHS_MMR_DADR(daddr); in write_msg_start()
157 twihs->TWIHS_THR = msg->buf[msg->idx++]; in write_msg_start()
159 /* Enable Transmit Ready and Transmission Completed interrupts */ in write_msg_start()
160 twihs->TWIHS_IER = TWIHS_IER_TXRDY | TWIHS_IER_TXCOMP | TWIHS_IER_NACK; in write_msg_start()
169 twihs->TWIHS_MMR = TWIHS_MMR_MREAD | TWIHS_MMR_DADR(daddr); in read_msg_start()
171 /* Enable Receive Ready and Transmission Completed interrupts */ in read_msg_start()
172 twihs->TWIHS_IER = TWIHS_IER_RXRDY | TWIHS_IER_TXCOMP | TWIHS_IER_NACK; in read_msg_start()
175 twihs_cr_stop = (msg->len == 1U) ? TWIHS_CR_STOP : 0; in read_msg_start()
177 twihs->TWIHS_CR = TWIHS_CR_START | twihs_cr_stop; in read_msg_start()
184 const struct i2c_sam_twihs_dev_cfg *const dev_cfg = dev->config; in i2c_sam_twihs_transfer()
185 struct i2c_sam_twihs_dev_data *const dev_data = dev->data; in i2c_sam_twihs_transfer()
186 Twihs *const twihs = dev_cfg->regs; in i2c_sam_twihs_transfer()
194 (void)twihs->TWIHS_SR; in i2c_sam_twihs_transfer()
197 twihs->TWIHS_IADR = 0; in i2c_sam_twihs_transfer()
200 dev_data->msg.buf = msgs[i].buf; in i2c_sam_twihs_transfer()
201 dev_data->msg.len = msgs[i].len; in i2c_sam_twihs_transfer()
202 dev_data->msg.idx = 0U; in i2c_sam_twihs_transfer()
203 dev_data->msg.twihs_sr = 0U; in i2c_sam_twihs_transfer()
204 dev_data->msg.flags = msgs[i].flags; in i2c_sam_twihs_transfer()
206 read_msg_start(twihs, &dev_data->msg, addr); in i2c_sam_twihs_transfer()
208 write_msg_start(twihs, &dev_data->msg, addr); in i2c_sam_twihs_transfer()
211 k_sem_take(&dev_data->sem, K_FOREVER); in i2c_sam_twihs_transfer()
213 if (dev_data->msg.twihs_sr > 0) { in i2c_sam_twihs_transfer()
215 return -EIO; in i2c_sam_twihs_transfer()
224 const struct i2c_sam_twihs_dev_cfg *const dev_cfg = dev->config; in i2c_sam_twihs_isr()
225 struct i2c_sam_twihs_dev_data *const dev_data = dev->data; in i2c_sam_twihs_isr()
226 Twihs *const twihs = dev_cfg->regs; in i2c_sam_twihs_isr()
227 struct twihs_msg *msg = &dev_data->msg; in i2c_sam_twihs_isr()
231 isr_status = twihs->TWIHS_SR & twihs->TWIHS_IMR; in i2c_sam_twihs_isr()
235 msg->twihs_sr = isr_status; in i2c_sam_twihs_isr()
242 msg->buf[msg->idx++] = twihs->TWIHS_RHR; in i2c_sam_twihs_isr()
244 if (msg->idx == msg->len - 1U) { in i2c_sam_twihs_isr()
246 twihs->TWIHS_CR = TWIHS_CR_STOP; in i2c_sam_twihs_isr()
252 if (msg->idx == msg->len) { in i2c_sam_twihs_isr()
253 if (msg->flags & I2C_MSG_STOP) { in i2c_sam_twihs_isr()
255 twihs->TWIHS_CR = TWIHS_CR_STOP; in i2c_sam_twihs_isr()
257 twihs->TWIHS_IDR = TWIHS_IDR_TXRDY; in i2c_sam_twihs_isr()
263 twihs->TWIHS_THR = msg->buf[msg->idx++]; in i2c_sam_twihs_isr()
276 twihs->TWIHS_IDR = twihs->TWIHS_IMR; in i2c_sam_twihs_isr()
278 k_sem_give(&dev_data->sem); in i2c_sam_twihs_isr()
283 const struct i2c_sam_twihs_dev_cfg *const dev_cfg = dev->config; in i2c_sam_twihs_initialize()
284 struct i2c_sam_twihs_dev_data *const dev_data = dev->data; in i2c_sam_twihs_initialize()
285 Twihs *const twihs = dev_cfg->regs; in i2c_sam_twihs_initialize()
290 dev_cfg->irq_config(); in i2c_sam_twihs_initialize()
293 k_sem_init(&dev_data->sem, 0, 1); in i2c_sam_twihs_initialize()
296 ret = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT); in i2c_sam_twihs_initialize()
301 /* Enable TWIHS clock in PMC */ in i2c_sam_twihs_initialize()
303 (clock_control_subsys_t)&dev_cfg->clock_cfg); in i2c_sam_twihs_initialize()
306 twihs->TWIHS_CR = TWIHS_CR_SWRST; in i2c_sam_twihs_initialize()
308 bitrate_cfg = i2c_map_dt_bitrate(dev_cfg->bitrate); in i2c_sam_twihs_initialize()
312 LOG_ERR("Failed to initialize %s device", dev->name); in i2c_sam_twihs_initialize()
316 /* Enable module's IRQ */ in i2c_sam_twihs_initialize()
317 irq_enable(dev_cfg->irq_id); in i2c_sam_twihs_initialize()
319 LOG_INF("Device %s initialized", dev->name); in i2c_sam_twihs_initialize()