Lines Matching refs:id
134 #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
135 #define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
237 static void cdns_i2c_clear_bus_hold(struct cdns_i2c *id) in cdns_i2c_clear_bus_hold() argument
244 static inline bool cdns_is_holdquirk(struct cdns_i2c *id, bool hold_wrkaround) in cdns_is_holdquirk() argument
247 (id->curr_recv_count == id->fifo_depth + 1)); in cdns_is_holdquirk()
251 static void cdns_i2c_set_mode(enum cdns_i2c_mode mode, struct cdns_i2c *id) in cdns_i2c_set_mode() argument
260 id->dev_mode = mode; in cdns_i2c_set_mode()
261 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_set_mode()
266 cdns_i2c_writereg(id->ctrl_reg_diva_divb | in cdns_i2c_set_mode()
279 cdns_i2c_writereg(id->ctrl_reg_diva_divb & in cdns_i2c_set_mode()
284 cdns_i2c_writereg(id->slave->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_set_mode()
294 static void cdns_i2c_slave_rcv_data(struct cdns_i2c *id) in cdns_i2c_slave_rcv_data() argument
300 if (id->slave_state == CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_slave_rcv_data()
301 id->slave_state = CDNS_I2C_SLAVE_STATE_RECV; in cdns_i2c_slave_rcv_data()
302 i2c_slave_event(id->slave, I2C_SLAVE_WRITE_REQUESTED, NULL); in cdns_i2c_slave_rcv_data()
311 i2c_slave_event(id->slave, I2C_SLAVE_WRITE_RECEIVED, &data); in cdns_i2c_slave_rcv_data()
315 static void cdns_i2c_slave_send_data(struct cdns_i2c *id) in cdns_i2c_slave_send_data() argument
320 if (id->slave_state == CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_slave_send_data()
321 id->slave_state = CDNS_I2C_SLAVE_STATE_SEND; in cdns_i2c_slave_send_data()
322 i2c_slave_event(id->slave, I2C_SLAVE_READ_REQUESTED, &data); in cdns_i2c_slave_send_data()
324 i2c_slave_event(id->slave, I2C_SLAVE_READ_PROCESSED, &data); in cdns_i2c_slave_send_data()
342 struct cdns_i2c *id = ptr; in cdns_i2c_slave_isr() local
359 cdns_i2c_slave_send_data(id); in cdns_i2c_slave_isr()
362 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
363 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
368 cdns_i2c_slave_rcv_data(id); in cdns_i2c_slave_isr()
371 cdns_i2c_slave_rcv_data(id); in cdns_i2c_slave_isr()
372 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
373 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
380 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
381 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
403 struct cdns_i2c *id = ptr; in cdns_i2c_master_isr() local
410 id->err_status = 0; in cdns_i2c_master_isr()
422 updatetx = id->recv_count > id->curr_recv_count; in cdns_i2c_master_isr()
425 if (id->p_recv_buf && in cdns_i2c_master_isr()
431 if (id->recv_count > 0) { in cdns_i2c_master_isr()
432 *(id->p_recv_buf)++ = in cdns_i2c_master_isr()
434 id->recv_count--; in cdns_i2c_master_isr()
435 id->curr_recv_count--; in cdns_i2c_master_isr()
442 if (id->recv_count <= id->fifo_depth && in cdns_i2c_master_isr()
443 !id->bus_hold_flag) in cdns_i2c_master_isr()
444 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
447 dev_err(id->adap.dev.parent, in cdns_i2c_master_isr()
449 id->err_status |= CDNS_I2C_IXR_TO; in cdns_i2c_master_isr()
453 if (cdns_is_holdquirk(id, updatetx)) in cdns_i2c_master_isr()
464 if (cdns_is_holdquirk(id, updatetx)) { in cdns_i2c_master_isr()
467 (id->curr_recv_count - id->fifo_depth)) in cdns_i2c_master_isr()
474 if (((int)(id->recv_count) - id->fifo_depth) > in cdns_i2c_master_isr()
475 id->transfer_size) { in cdns_i2c_master_isr()
476 cdns_i2c_writereg(id->transfer_size, in cdns_i2c_master_isr()
478 id->curr_recv_count = id->transfer_size + in cdns_i2c_master_isr()
479 id->fifo_depth; in cdns_i2c_master_isr()
481 cdns_i2c_writereg(id->recv_count - in cdns_i2c_master_isr()
482 id->fifo_depth, in cdns_i2c_master_isr()
484 id->curr_recv_count = id->recv_count; in cdns_i2c_master_isr()
489 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->recv_count) { in cdns_i2c_master_isr()
490 if (!id->bus_hold_flag) in cdns_i2c_master_isr()
491 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
499 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->p_recv_buf) { in cdns_i2c_master_isr()
504 if (id->send_count) { in cdns_i2c_master_isr()
505 avail_bytes = id->fifo_depth - in cdns_i2c_master_isr()
507 if (id->send_count > avail_bytes) in cdns_i2c_master_isr()
510 bytes_to_send = id->send_count; in cdns_i2c_master_isr()
514 (*(id->p_send_buf)++), in cdns_i2c_master_isr()
516 id->send_count--; in cdns_i2c_master_isr()
526 if (!id->send_count && !id->bus_hold_flag) in cdns_i2c_master_isr()
527 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
533 id->err_status |= isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; in cdns_i2c_master_isr()
534 if (id->err_status) in cdns_i2c_master_isr()
538 complete(&id->xfer_done); in cdns_i2c_master_isr()
556 struct cdns_i2c *id = ptr; in cdns_i2c_isr() local
558 if (id->dev_mode == CDNS_I2C_MODE_SLAVE) in cdns_i2c_isr()
568 static void cdns_i2c_mrecv(struct cdns_i2c *id) in cdns_i2c_mrecv() argument
578 id->p_recv_buf = id->p_msg->buf; in cdns_i2c_mrecv()
579 id->recv_count = id->p_msg->len; in cdns_i2c_mrecv()
590 if (id->p_msg->flags & I2C_M_RECV_LEN) in cdns_i2c_mrecv()
591 id->recv_count = I2C_SMBUS_BLOCK_MAX + id->p_msg->len; in cdns_i2c_mrecv()
593 id->curr_recv_count = id->recv_count; in cdns_i2c_mrecv()
599 if (id->recv_count > id->fifo_depth) in cdns_i2c_mrecv()
614 if (id->recv_count > id->transfer_size) { in cdns_i2c_mrecv()
615 cdns_i2c_writereg(id->transfer_size, in cdns_i2c_mrecv()
617 id->curr_recv_count = id->transfer_size; in cdns_i2c_mrecv()
619 cdns_i2c_writereg(id->recv_count, CDNS_I2C_XFER_SIZE_OFFSET); in cdns_i2c_mrecv()
623 if (!id->bus_hold_flag && id->recv_count <= id->fifo_depth) { in cdns_i2c_mrecv()
626 if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) in cdns_i2c_mrecv()
631 addr = id->p_msg->addr; in cdns_i2c_mrecv()
665 static void cdns_i2c_msend(struct cdns_i2c *id) in cdns_i2c_msend() argument
672 id->p_recv_buf = NULL; in cdns_i2c_msend()
673 id->p_send_buf = id->p_msg->buf; in cdns_i2c_msend()
674 id->send_count = id->p_msg->len; in cdns_i2c_msend()
685 if (id->send_count > id->fifo_depth) in cdns_i2c_msend()
698 avail_bytes = id->fifo_depth - in cdns_i2c_msend()
701 if (id->send_count > avail_bytes) in cdns_i2c_msend()
704 bytes_to_send = id->send_count; in cdns_i2c_msend()
707 cdns_i2c_writereg((*(id->p_send_buf)++), CDNS_I2C_DATA_OFFSET); in cdns_i2c_msend()
708 id->send_count--; in cdns_i2c_msend()
715 if (!id->bus_hold_flag && !id->send_count) in cdns_i2c_msend()
716 cdns_i2c_clear_bus_hold(id); in cdns_i2c_msend()
718 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_msend()
733 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_reset() local
753 static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, in cdns_i2c_process_msg() argument
759 id->p_msg = msg; in cdns_i2c_process_msg()
760 id->err_status = 0; in cdns_i2c_process_msg()
761 reinit_completion(&id->xfer_done); in cdns_i2c_process_msg()
777 cdns_i2c_mrecv(id); in cdns_i2c_process_msg()
779 cdns_i2c_msend(id); in cdns_i2c_process_msg()
782 msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk); in cdns_i2c_process_msg()
790 time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); in cdns_i2c_process_msg()
793 dev_err(id->adap.dev.parent, in cdns_i2c_process_msg()
802 if (id->err_status & CDNS_I2C_IXR_ARB_LOST) in cdns_i2c_process_msg()
826 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_xfer() local
832 ret = pm_runtime_resume_and_get(id->dev); in cdns_i2c_master_xfer()
838 if (id->dev_mode == CDNS_I2C_MODE_SLAVE) { in cdns_i2c_master_xfer()
839 if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_master_xfer()
845 cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); in cdns_i2c_master_xfer()
854 ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, in cdns_i2c_master_xfer()
860 if (id->adap.bus_recovery_info) in cdns_i2c_master_xfer()
865 hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); in cdns_i2c_master_xfer()
886 id->bus_hold_flag = 1; in cdns_i2c_master_xfer()
891 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
897 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
899 ret = cdns_i2c_process_msg(id, msgs, adap); in cdns_i2c_master_xfer()
904 if (id->err_status) { in cdns_i2c_master_xfer()
907 if (id->err_status & CDNS_I2C_IXR_NACK) { in cdns_i2c_master_xfer()
923 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); in cdns_i2c_master_xfer()
926 pm_runtime_mark_last_busy(id->dev); in cdns_i2c_master_xfer()
927 pm_runtime_put_autosuspend(id->dev); in cdns_i2c_master_xfer()
954 struct cdns_i2c *id = container_of(slave->adapter, struct cdns_i2c, in cdns_reg_slave() local
957 if (id->slave) in cdns_reg_slave()
963 ret = pm_runtime_resume_and_get(id->dev); in cdns_reg_slave()
968 id->slave = slave; in cdns_reg_slave()
971 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); in cdns_reg_slave()
978 struct cdns_i2c *id = container_of(slave->adapter, struct cdns_i2c, in cdns_unreg_slave() local
981 pm_runtime_put(id->dev); in cdns_unreg_slave()
984 id->slave = NULL; in cdns_unreg_slave()
987 cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); in cdns_unreg_slave()
1077 static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id) in cdns_i2c_setclk() argument
1082 unsigned long fscl = id->i2c_clk; in cdns_i2c_setclk()
1088 ctrl_reg = id->ctrl_reg; in cdns_i2c_setclk()
1092 id->ctrl_reg = ctrl_reg; in cdns_i2c_setclk()
1095 id->ctrl_reg_diva_divb = ctrl_reg & (CDNS_I2C_CR_DIVA_MASK | in cdns_i2c_setclk()
1121 struct cdns_i2c *id = to_cdns_i2c(nb); in cdns_i2c_clk_notifier_cb() local
1123 if (pm_runtime_suspended(id->dev)) in cdns_i2c_clk_notifier_cb()
1130 unsigned long fscl = id->i2c_clk; in cdns_i2c_clk_notifier_cb()
1136 dev_warn(id->adap.dev.parent, in cdns_i2c_clk_notifier_cb()
1143 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
1148 id->input_clk = ndata->new_rate; in cdns_i2c_clk_notifier_cb()
1151 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
1156 cdns_i2c_setclk(ndata->old_rate, id); in cdns_i2c_clk_notifier_cb()
1187 static void cdns_i2c_init(struct cdns_i2c *id) in cdns_i2c_init() argument
1189 cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); in cdns_i2c_init()
1246 static void cdns_i2c_detect_transfer_size(struct cdns_i2c *id) in cdns_i2c_detect_transfer_size() argument
1265 id->transfer_size = CDNS_I2C_TRANSFER_SIZE(val); in cdns_i2c_detect_transfer_size()
1283 struct cdns_i2c *id; in cdns_i2c_probe() local
1287 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); in cdns_i2c_probe()
1288 if (!id) in cdns_i2c_probe()
1291 id->dev = &pdev->dev; in cdns_i2c_probe()
1292 platform_set_drvdata(pdev, id); in cdns_i2c_probe()
1297 id->quirks = data->quirks; in cdns_i2c_probe()
1300 id->rinfo.pinctrl = devm_pinctrl_get(&pdev->dev); in cdns_i2c_probe()
1301 if (IS_ERR(id->rinfo.pinctrl)) { in cdns_i2c_probe()
1302 int err = PTR_ERR(id->rinfo.pinctrl); in cdns_i2c_probe()
1308 id->adap.bus_recovery_info = &id->rinfo; in cdns_i2c_probe()
1311 id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem); in cdns_i2c_probe()
1312 if (IS_ERR(id->membase)) in cdns_i2c_probe()
1313 return PTR_ERR(id->membase); in cdns_i2c_probe()
1319 id->adap.owner = THIS_MODULE; in cdns_i2c_probe()
1320 id->adap.dev.of_node = pdev->dev.of_node; in cdns_i2c_probe()
1321 id->adap.algo = &cdns_i2c_algo; in cdns_i2c_probe()
1322 id->adap.timeout = CDNS_I2C_TIMEOUT; in cdns_i2c_probe()
1323 id->adap.retries = 3; /* Default retry value. */ in cdns_i2c_probe()
1324 id->adap.algo_data = id; in cdns_i2c_probe()
1325 id->adap.dev.parent = &pdev->dev; in cdns_i2c_probe()
1326 init_completion(&id->xfer_done); in cdns_i2c_probe()
1327 snprintf(id->adap.name, sizeof(id->adap.name), in cdns_i2c_probe()
1330 id->clk = devm_clk_get(&pdev->dev, NULL); in cdns_i2c_probe()
1331 if (IS_ERR(id->clk)) in cdns_i2c_probe()
1332 return dev_err_probe(&pdev->dev, PTR_ERR(id->clk), in cdns_i2c_probe()
1335 id->reset = devm_reset_control_get_optional_shared(&pdev->dev, NULL); in cdns_i2c_probe()
1336 if (IS_ERR(id->reset)) in cdns_i2c_probe()
1337 return dev_err_probe(&pdev->dev, PTR_ERR(id->reset), in cdns_i2c_probe()
1340 ret = clk_prepare_enable(id->clk); in cdns_i2c_probe()
1344 ret = reset_control_deassert(id->reset); in cdns_i2c_probe()
1351 pm_runtime_set_autosuspend_delay(id->dev, CNDS_I2C_PM_TIMEOUT); in cdns_i2c_probe()
1352 pm_runtime_use_autosuspend(id->dev); in cdns_i2c_probe()
1353 pm_runtime_set_active(id->dev); in cdns_i2c_probe()
1354 pm_runtime_enable(id->dev); in cdns_i2c_probe()
1356 id->clk_rate_change_nb.notifier_call = cdns_i2c_clk_notifier_cb; in cdns_i2c_probe()
1357 if (clk_notifier_register(id->clk, &id->clk_rate_change_nb)) in cdns_i2c_probe()
1359 id->input_clk = clk_get_rate(id->clk); in cdns_i2c_probe()
1362 &id->i2c_clk); in cdns_i2c_probe()
1363 if (ret || (id->i2c_clk > I2C_MAX_FAST_MODE_FREQ)) in cdns_i2c_probe()
1364 id->i2c_clk = I2C_MAX_STANDARD_MODE_FREQ; in cdns_i2c_probe()
1368 id->dev_mode = CDNS_I2C_MODE_MASTER; in cdns_i2c_probe()
1369 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_probe()
1371 id->ctrl_reg = CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS; in cdns_i2c_probe()
1373 id->fifo_depth = CDNS_I2C_FIFO_DEPTH_DEFAULT; in cdns_i2c_probe()
1374 of_property_read_u32(pdev->dev.of_node, "fifo-depth", &id->fifo_depth); in cdns_i2c_probe()
1376 cdns_i2c_detect_transfer_size(id); in cdns_i2c_probe()
1378 ret = cdns_i2c_setclk(id->input_clk, id); in cdns_i2c_probe()
1380 dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk); in cdns_i2c_probe()
1386 DRIVER_NAME, id); in cdns_i2c_probe()
1391 cdns_i2c_init(id); in cdns_i2c_probe()
1393 ret = i2c_add_adapter(&id->adap); in cdns_i2c_probe()
1398 id->i2c_clk / 1000, (unsigned long)r_mem->start, irq); in cdns_i2c_probe()
1403 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_probe()
1404 reset_control_assert(id->reset); in cdns_i2c_probe()
1406 clk_disable_unprepare(id->clk); in cdns_i2c_probe()
1422 struct cdns_i2c *id = platform_get_drvdata(pdev); in cdns_i2c_remove() local
1428 i2c_del_adapter(&id->adap); in cdns_i2c_remove()
1429 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_remove()
1430 reset_control_assert(id->reset); in cdns_i2c_remove()
1431 clk_disable_unprepare(id->clk); in cdns_i2c_remove()