Lines Matching +full:idle +full:- +full:timeout +full:- +full:ms
4 * SPDX-License-Identifier: Apache-2.0
29 /* I2C timeout is 10 ms (WAIT_INTERVAL * WAIT_COUNT) */
33 /* Line High Timeout is 2.5 ms (WAIT_LINE_HIGH_USEC * WAIT_LINE_HIGH_COUNT) */
73 * i2c_baud_clk_period/bus_clk_period - 2 = (low_period + hi_period)
74 * bus_clk_reg (16MHz/100KHz -2) = 0x4F + 0x4F
75 * (16MHz/400KHz -2) = 0x0F + 0x17
76 * (16MHz/1MHz -2) = 0x05 + 0x09
105 (const struct i2c_xec_config *const) (dev->config); in i2c_xec_reset_config()
107 (struct i2c_xec_data *const) (dev->data); in i2c_xec_reset_config()
108 uint32_t ba = config->base_addr; in i2c_xec_reset_config()
111 z_mchp_xec_pcr_periph_reset(config->pcr_idx, config->pcr_bitpos); in i2c_xec_reset_config()
121 (config->port_sel & in i2c_xec_reset_config()
126 * and Timeout Scaling register in i2c_xec_reset_config()
128 MCHP_I2C_SMB_BUS_CLK(ba) = xec_cfg_params[data->speed_id].bus_clk; in i2c_xec_reset_config()
129 MCHP_I2C_SMB_DATA_TM(ba) = xec_cfg_params[data->speed_id].data_timing; in i2c_xec_reset_config()
131 xec_cfg_params[data->speed_id].start_hold_time; in i2c_xec_reset_config()
132 MCHP_I2C_SMB_TMTSC(ba) = xec_cfg_params[data->speed_id].timeout_scale; in i2c_xec_reset_config()
146 return -ETIMEDOUT; in xec_spin_yield()
188 (const struct i2c_xec_config *const) (dev->config); in recover_from_error()
189 uint32_t ba = config->base_addr; in recover_from_error()
198 (const struct i2c_xec_config *const) (dev->config); in wait_bus_free()
201 uint32_t ba = config->base_addr; in wait_bus_free()
214 return -EBUSY; in wait_bus_free()
221 * Wait with timeout for I2C controller to finish transmit/receive of one
227 * Reset controller and return -EBUSY
229 * Return -EPERM. We lost bus to another controller. No reset.
232 * NACK Issue STOP, wait for bus minimum idle time, return -EIO.
233 * Timeout:
234 * Reset controller and return -ETIMEDOUT
237 * Bus Minimum Idle time has expired.
242 (const struct i2c_xec_config *const) (dev->config); in wait_completion()
245 uint32_t ba = config->base_addr; in wait_completion()
253 return -EBUSY; in wait_completion()
260 return -EPERM; in wait_completion()
264 /* PIN -> 0 indicates I2C is done */ in wait_completion()
275 return -EIO; in wait_completion()
296 (const struct i2c_xec_config *const)(dev->config); in check_lines_high()
299 if (gpio_port_get_raw(config->sda_gpio.port, &sda)) { in check_lines_high()
300 LOG_ERR("gpio_port_get_raw for %s SDA failed", dev->name); in check_lines_high()
305 if (config->sda_gpio.port == config->scl_gpio.port) { in check_lines_high()
308 if (gpio_port_get_raw(config->scl_gpio.port, &scl)) { in check_lines_high()
310 dev->name); in check_lines_high()
315 return (sda & BIT(config->sda_gpio.pin)) && (scl & BIT(config->scl_gpio.pin)); in check_lines_high()
323 (struct i2c_xec_data *const) (dev->data); in i2c_xec_configure()
326 return -ENOTSUP; in i2c_xec_configure()
330 return -ENOTSUP; in i2c_xec_configure()
335 data->speed_id = SPEED_100KHZ_BUS; in i2c_xec_configure()
338 data->speed_id = SPEED_400KHZ_BUS; in i2c_xec_configure()
341 data->speed_id = SPEED_1MHZ_BUS; in i2c_xec_configure()
344 return -EINVAL; in i2c_xec_configure()
356 (const struct i2c_xec_config *const) (dev->config); in i2c_xec_poll_write()
358 (struct i2c_xec_data *const) (dev->data); in i2c_xec_poll_write()
359 uint32_t ba = config->base_addr; in i2c_xec_poll_write()
363 if (data->timeout_seen == 1) { in i2c_xec_poll_write()
367 data->timeout_seen = 1; in i2c_xec_poll_write()
369 __func__, dev->name, ret); in i2c_xec_poll_write()
372 data->timeout_seen = 0; in i2c_xec_poll_write()
378 LOG_DBG("%s: %s Force Stop", __func__, dev->name); in i2c_xec_poll_write()
385 data->pending_stop = 0; in i2c_xec_poll_write()
387 /* If the timeout had occurred while the master was reading in i2c_xec_poll_write()
391 if (data->previously_in_read == 1) { in i2c_xec_poll_write()
392 data->previously_in_read = 0; in i2c_xec_poll_write()
395 return -EBUSY; in i2c_xec_poll_write()
398 if ((data->pending_stop == 0) || (data->error_seen == 1)) { in i2c_xec_poll_write()
403 __func__, dev->name); in i2c_xec_poll_write()
404 data->error_seen = 1; in i2c_xec_poll_write()
405 return -EBUSY; in i2c_xec_poll_write()
411 if (data->error_seen) { in i2c_xec_poll_write()
413 __func__, dev->name); in i2c_xec_poll_write()
414 data->error_seen = 0; in i2c_xec_poll_write()
421 data->error_seen = 1; in i2c_xec_poll_write()
423 __func__, dev->name, ret); in i2c_xec_poll_write()
440 case -EIO: in i2c_xec_poll_write()
442 __func__, addr >> 1, dev->name); in i2c_xec_poll_write()
446 data->error_seen = 1; in i2c_xec_poll_write()
448 __func__, dev->name, ret); in i2c_xec_poll_write()
462 case -EIO: in i2c_xec_poll_write()
464 __func__, addr >> 1, dev->name); in i2c_xec_poll_write()
467 case -ETIMEDOUT: in i2c_xec_poll_write()
468 data->timeout_seen = 1; in i2c_xec_poll_write()
469 LOG_ERR("%s: Clk stretch Timeout - Slave 0x%x on %s", in i2c_xec_poll_write()
470 __func__, addr >> 1, dev->name); in i2c_xec_poll_write()
474 data->error_seen = 1; in i2c_xec_poll_write()
476 __func__, dev->name, ret); in i2c_xec_poll_write()
489 data->pending_stop = 0; in i2c_xec_poll_write()
491 data->pending_stop = 1; in i2c_xec_poll_write()
501 (const struct i2c_xec_config *const) (dev->config); in i2c_xec_poll_read()
503 (struct i2c_xec_data *const) (dev->data); in i2c_xec_poll_read()
504 uint32_t ba = config->base_addr; in i2c_xec_poll_read()
508 if (data->timeout_seen == 1) { in i2c_xec_poll_read()
512 data->timeout_seen = 1; in i2c_xec_poll_read()
514 __func__, dev->name, ret); in i2c_xec_poll_read()
517 data->timeout_seen = 0; in i2c_xec_poll_read()
523 LOG_DBG("%s: %s Force Stop", __func__, dev->name); in i2c_xec_poll_read()
530 return -EBUSY; in i2c_xec_poll_read()
533 if (!(msg.flags & I2C_MSG_RESTART) || (data->error_seen == 1)) { in i2c_xec_poll_read()
538 __func__, dev->name); in i2c_xec_poll_read()
539 data->error_seen = 1; in i2c_xec_poll_read()
540 return -EBUSY; in i2c_xec_poll_read()
546 if (data->error_seen) { in i2c_xec_poll_read()
548 __func__, dev->name); in i2c_xec_poll_read()
549 data->error_seen = 0; in i2c_xec_poll_read()
556 data->error_seen = 1; in i2c_xec_poll_read()
558 __func__, dev->name, ret); in i2c_xec_poll_read()
577 case -EIO: in i2c_xec_poll_read()
578 data->error_seen = 1; in i2c_xec_poll_read()
580 __func__, addr >> 1, dev->name); in i2c_xec_poll_read()
583 case -ETIMEDOUT: in i2c_xec_poll_read()
584 data->previously_in_read = 1; in i2c_xec_poll_read()
585 data->timeout_seen = 1; in i2c_xec_poll_read()
586 LOG_ERR("%s: Clk stretch Timeout - Slave 0x%x on %s", in i2c_xec_poll_read()
587 __func__, addr >> 1, dev->name); in i2c_xec_poll_read()
591 data->error_seen = 1; in i2c_xec_poll_read()
593 __func__, dev->name, ret); in i2c_xec_poll_read()
611 case -EIO: in i2c_xec_poll_read()
613 __func__, addr >> 1, dev->name); in i2c_xec_poll_read()
616 case -ETIMEDOUT: in i2c_xec_poll_read()
617 data->previously_in_read = 1; in i2c_xec_poll_read()
618 data->timeout_seen = 1; in i2c_xec_poll_read()
619 LOG_ERR("%s: Clk stretch Timeout - Slave 0x%x on %s", in i2c_xec_poll_read()
620 __func__, addr >> 1, dev->name); in i2c_xec_poll_read()
624 data->error_seen = 1; in i2c_xec_poll_read()
626 __func__, dev->name, ret); in i2c_xec_poll_read()
630 if (i == (msg.len - 1)) { in i2c_xec_poll_read()
638 data->pending_stop = 0; in i2c_xec_poll_read()
640 } else if (i == (msg.len - 2)) { in i2c_xec_poll_read()
656 struct i2c_xec_data *data = dev->data; in i2c_xec_transfer()
658 if (data->slave_attached) { in i2c_xec_transfer()
659 LOG_ERR("%s Device is registered as slave", dev->name); in i2c_xec_transfer()
660 return -EBUSY; in i2c_xec_transfer()
669 LOG_ERR("%s Write error: %d", dev->name, ret); in i2c_xec_transfer()
675 LOG_ERR("%s Read error: %d", dev->name, ret); in i2c_xec_transfer()
688 (const struct i2c_xec_config *const) (dev->config); in i2c_xec_bus_isr()
689 struct i2c_xec_data *data = dev->data; in i2c_xec_bus_isr()
690 const struct i2c_target_callbacks *slave_cb = data->slave_cfg->callbacks; in i2c_xec_bus_isr()
691 uint32_t ba = config->base_addr; in i2c_xec_bus_isr()
698 if (!data->slave_attached) { in i2c_xec_bus_isr()
707 if (slave_cb->stop) { in i2c_xec_bus_isr()
708 slave_cb->stop(data->slave_cfg); in i2c_xec_bus_isr()
716 if (slave_cb->stop) { in i2c_xec_bus_isr()
717 slave_cb->stop(data->slave_cfg); in i2c_xec_bus_isr()
730 data->slave_read = false; in i2c_xec_bus_isr()
731 if (slave_cb->write_requested) { in i2c_xec_bus_isr()
732 slave_cb->write_requested(data->slave_cfg); in i2c_xec_bus_isr()
737 data->slave_read = true; in i2c_xec_bus_isr()
738 if (slave_cb->read_requested) { in i2c_xec_bus_isr()
739 slave_cb->read_requested(data->slave_cfg, &val); in i2c_xec_bus_isr()
747 if (data->slave_read) { in i2c_xec_bus_isr()
752 if (slave_cb->read_processed) { in i2c_xec_bus_isr()
753 slave_cb->read_processed(data->slave_cfg, &val); in i2c_xec_bus_isr()
760 if (slave_cb->write_received) { in i2c_xec_bus_isr()
761 slave_cb->write_received(data->slave_cfg, val); in i2c_xec_bus_isr()
766 MCHP_GIRQ_SRC(config->girq_id) = BIT(config->girq_bit); in i2c_xec_bus_isr()
774 const struct i2c_xec_config *cfg = dev->config; in i2c_xec_target_register()
775 struct i2c_xec_data *data = dev->data; in i2c_xec_target_register()
776 uint32_t ba = cfg->base_addr; in i2c_xec_target_register()
781 return -EINVAL; in i2c_xec_target_register()
784 if (data->slave_attached) { in i2c_xec_target_register()
785 return -EBUSY; in i2c_xec_target_register()
799 data->slave_cfg = config; in i2c_xec_target_register()
802 MCHP_I2C_SMB_OWN_ADDR(ba) = data->slave_cfg->address; in i2c_xec_target_register()
805 data->slave_attached = true; in i2c_xec_target_register()
808 MCHP_GIRQ_SRC(cfg->girq_id) = BIT(cfg->girq_bit); in i2c_xec_target_register()
809 MCHP_GIRQ_ENSET(cfg->girq_id) = BIT(cfg->girq_bit); in i2c_xec_target_register()
817 const struct i2c_xec_config *cfg = dev->config; in i2c_xec_target_unregister()
818 struct i2c_xec_data *data = dev->data; in i2c_xec_target_unregister()
820 if (!data->slave_attached) { in i2c_xec_target_unregister()
821 return -EINVAL; in i2c_xec_target_unregister()
824 data->slave_attached = false; in i2c_xec_target_unregister()
826 MCHP_GIRQ_ENCLR(cfg->girq_id) = BIT(cfg->girq_bit); in i2c_xec_target_unregister()
846 const struct i2c_xec_config *cfg = dev->config; in i2c_xec_init()
848 (struct i2c_xec_data *const) (dev->data); in i2c_xec_init()
851 data->pending_stop = 0; in i2c_xec_init()
852 data->slave_attached = false; in i2c_xec_init()
854 ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in i2c_xec_init()
860 if (!gpio_is_ready_dt(&cfg->sda_gpio)) { in i2c_xec_init()
861 LOG_ERR("%s GPIO device is not ready for SDA GPIO", dev->name); in i2c_xec_init()
862 return -ENODEV; in i2c_xec_init()
865 if (!gpio_is_ready_dt(&cfg->scl_gpio)) { in i2c_xec_init()
866 LOG_ERR("%s GPIO device is not ready for SCL GPIO", dev->name); in i2c_xec_init()
867 return -ENODEV; in i2c_xec_init()
875 LOG_ERR("%s configure failed %d", dev->name, ret); in i2c_xec_init()
881 (const struct i2c_xec_config *const) (dev->config); in i2c_xec_init()
883 config->irq_config_func(); in i2c_xec_init()