Lines Matching refs:id
131 #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
132 #define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
228 static void cdns_i2c_clear_bus_hold(struct cdns_i2c *id) in cdns_i2c_clear_bus_hold() argument
235 static inline bool cdns_is_holdquirk(struct cdns_i2c *id, bool hold_wrkaround) in cdns_is_holdquirk() argument
238 (id->curr_recv_count == CDNS_I2C_FIFO_DEPTH + 1)); in cdns_is_holdquirk()
242 static void cdns_i2c_set_mode(enum cdns_i2c_mode mode, struct cdns_i2c *id) in cdns_i2c_set_mode() argument
251 id->dev_mode = mode; in cdns_i2c_set_mode()
252 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_set_mode()
257 cdns_i2c_writereg(id->ctrl_reg_diva_divb | in cdns_i2c_set_mode()
270 cdns_i2c_writereg(id->ctrl_reg_diva_divb & in cdns_i2c_set_mode()
275 cdns_i2c_writereg(id->slave->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_set_mode()
285 static void cdns_i2c_slave_rcv_data(struct cdns_i2c *id) in cdns_i2c_slave_rcv_data() argument
291 if (id->slave_state == CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_slave_rcv_data()
292 id->slave_state = CDNS_I2C_SLAVE_STATE_RECV; in cdns_i2c_slave_rcv_data()
293 i2c_slave_event(id->slave, I2C_SLAVE_WRITE_REQUESTED, NULL); in cdns_i2c_slave_rcv_data()
302 i2c_slave_event(id->slave, I2C_SLAVE_WRITE_RECEIVED, &data); in cdns_i2c_slave_rcv_data()
306 static void cdns_i2c_slave_send_data(struct cdns_i2c *id) in cdns_i2c_slave_send_data() argument
311 if (id->slave_state == CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_slave_send_data()
312 id->slave_state = CDNS_I2C_SLAVE_STATE_SEND; in cdns_i2c_slave_send_data()
313 i2c_slave_event(id->slave, I2C_SLAVE_READ_REQUESTED, &data); in cdns_i2c_slave_send_data()
315 i2c_slave_event(id->slave, I2C_SLAVE_READ_PROCESSED, &data); in cdns_i2c_slave_send_data()
333 struct cdns_i2c *id = ptr; in cdns_i2c_slave_isr() local
350 cdns_i2c_slave_send_data(id); in cdns_i2c_slave_isr()
353 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
354 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
359 cdns_i2c_slave_rcv_data(id); in cdns_i2c_slave_isr()
362 cdns_i2c_slave_rcv_data(id); in cdns_i2c_slave_isr()
363 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
364 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
371 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
372 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
394 struct cdns_i2c *id = ptr; in cdns_i2c_master_isr() local
401 id->err_status = 0; in cdns_i2c_master_isr()
414 if (id->recv_count > id->curr_recv_count) in cdns_i2c_master_isr()
417 hold_quirk = (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) && updatetx; in cdns_i2c_master_isr()
420 if (id->p_recv_buf && in cdns_i2c_master_isr()
426 if (id->recv_count > 0) { in cdns_i2c_master_isr()
427 *(id->p_recv_buf)++ = in cdns_i2c_master_isr()
429 id->recv_count--; in cdns_i2c_master_isr()
430 id->curr_recv_count--; in cdns_i2c_master_isr()
437 if (id->recv_count <= CDNS_I2C_FIFO_DEPTH && in cdns_i2c_master_isr()
438 !id->bus_hold_flag) in cdns_i2c_master_isr()
439 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
442 dev_err(id->adap.dev.parent, in cdns_i2c_master_isr()
444 id->err_status |= CDNS_I2C_IXR_TO; in cdns_i2c_master_isr()
448 if (cdns_is_holdquirk(id, hold_quirk)) in cdns_i2c_master_isr()
459 if (cdns_is_holdquirk(id, hold_quirk)) { in cdns_i2c_master_isr()
462 (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH)) in cdns_i2c_master_isr()
469 if (((int)(id->recv_count) - CDNS_I2C_FIFO_DEPTH) > in cdns_i2c_master_isr()
473 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE + in cdns_i2c_master_isr()
476 cdns_i2c_writereg(id->recv_count - in cdns_i2c_master_isr()
479 id->curr_recv_count = id->recv_count; in cdns_i2c_master_isr()
481 } else if (id->recv_count && !hold_quirk && in cdns_i2c_master_isr()
482 !id->curr_recv_count) { in cdns_i2c_master_isr()
485 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_master_isr()
488 if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) { in cdns_i2c_master_isr()
491 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE; in cdns_i2c_master_isr()
493 cdns_i2c_writereg(id->recv_count, in cdns_i2c_master_isr()
495 id->curr_recv_count = id->recv_count; in cdns_i2c_master_isr()
500 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->recv_count) { in cdns_i2c_master_isr()
501 if (!id->bus_hold_flag) in cdns_i2c_master_isr()
502 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
510 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->p_recv_buf) { in cdns_i2c_master_isr()
515 if (id->send_count) { in cdns_i2c_master_isr()
518 if (id->send_count > avail_bytes) in cdns_i2c_master_isr()
521 bytes_to_send = id->send_count; in cdns_i2c_master_isr()
525 (*(id->p_send_buf)++), in cdns_i2c_master_isr()
527 id->send_count--; in cdns_i2c_master_isr()
537 if (!id->send_count && !id->bus_hold_flag) in cdns_i2c_master_isr()
538 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
544 id->err_status |= isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; in cdns_i2c_master_isr()
545 if (id->err_status) in cdns_i2c_master_isr()
549 complete(&id->xfer_done); in cdns_i2c_master_isr()
567 struct cdns_i2c *id = ptr; in cdns_i2c_isr() local
569 if (id->dev_mode == CDNS_I2C_MODE_SLAVE) in cdns_i2c_isr()
579 static void cdns_i2c_mrecv(struct cdns_i2c *id) in cdns_i2c_mrecv() argument
589 id->p_recv_buf = id->p_msg->buf; in cdns_i2c_mrecv()
590 id->recv_count = id->p_msg->len; in cdns_i2c_mrecv()
596 if (id->p_msg->flags & I2C_M_RECV_LEN) in cdns_i2c_mrecv()
597 id->recv_count = I2C_SMBUS_BLOCK_MAX + 1; in cdns_i2c_mrecv()
599 id->curr_recv_count = id->recv_count; in cdns_i2c_mrecv()
605 if (id->recv_count > CDNS_I2C_FIFO_DEPTH) in cdns_i2c_mrecv()
620 if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) { in cdns_i2c_mrecv()
623 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE; in cdns_i2c_mrecv()
625 cdns_i2c_writereg(id->recv_count, CDNS_I2C_XFER_SIZE_OFFSET); in cdns_i2c_mrecv()
629 if (!id->bus_hold_flag && in cdns_i2c_mrecv()
630 ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && in cdns_i2c_mrecv()
631 (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) { in cdns_i2c_mrecv()
634 if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) in cdns_i2c_mrecv()
639 addr = id->p_msg->addr; in cdns_i2c_mrecv()
672 static void cdns_i2c_msend(struct cdns_i2c *id) in cdns_i2c_msend() argument
679 id->p_recv_buf = NULL; in cdns_i2c_msend()
680 id->p_send_buf = id->p_msg->buf; in cdns_i2c_msend()
681 id->send_count = id->p_msg->len; in cdns_i2c_msend()
692 if (id->send_count > CDNS_I2C_FIFO_DEPTH) in cdns_i2c_msend()
708 if (id->send_count > avail_bytes) in cdns_i2c_msend()
711 bytes_to_send = id->send_count; in cdns_i2c_msend()
714 cdns_i2c_writereg((*(id->p_send_buf)++), CDNS_I2C_DATA_OFFSET); in cdns_i2c_msend()
715 id->send_count--; in cdns_i2c_msend()
722 if (!id->bus_hold_flag && !id->send_count) in cdns_i2c_msend()
723 cdns_i2c_clear_bus_hold(id); in cdns_i2c_msend()
725 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_msend()
740 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_reset() local
760 static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, in cdns_i2c_process_msg() argument
766 id->p_msg = msg; in cdns_i2c_process_msg()
767 id->err_status = 0; in cdns_i2c_process_msg()
768 reinit_completion(&id->xfer_done); in cdns_i2c_process_msg()
784 cdns_i2c_mrecv(id); in cdns_i2c_process_msg()
786 cdns_i2c_msend(id); in cdns_i2c_process_msg()
789 time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout); in cdns_i2c_process_msg()
792 dev_err(id->adap.dev.parent, in cdns_i2c_process_msg()
801 if (id->err_status & CDNS_I2C_IXR_ARB_LOST) in cdns_i2c_process_msg()
822 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_xfer() local
828 ret = pm_runtime_resume_and_get(id->dev); in cdns_i2c_master_xfer()
834 if (id->dev_mode == CDNS_I2C_MODE_SLAVE) { in cdns_i2c_master_xfer()
835 if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) in cdns_i2c_master_xfer()
839 cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); in cdns_i2c_master_xfer()
852 hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); in cdns_i2c_master_xfer()
873 id->bus_hold_flag = 1; in cdns_i2c_master_xfer()
878 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
884 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
886 ret = cdns_i2c_process_msg(id, msgs, adap); in cdns_i2c_master_xfer()
891 if (id->err_status) { in cdns_i2c_master_xfer()
894 if (id->err_status & CDNS_I2C_IXR_NACK) { in cdns_i2c_master_xfer()
910 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); in cdns_i2c_master_xfer()
913 pm_runtime_mark_last_busy(id->dev); in cdns_i2c_master_xfer()
914 pm_runtime_put_autosuspend(id->dev); in cdns_i2c_master_xfer()
941 struct cdns_i2c *id = container_of(slave->adapter, struct cdns_i2c, in cdns_reg_slave() local
944 if (id->slave) in cdns_reg_slave()
950 ret = pm_runtime_resume_and_get(id->dev); in cdns_reg_slave()
955 id->slave = slave; in cdns_reg_slave()
958 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); in cdns_reg_slave()
965 struct cdns_i2c *id = container_of(slave->adapter, struct cdns_i2c, in cdns_unreg_slave() local
968 pm_runtime_put(id->dev); in cdns_unreg_slave()
971 id->slave = NULL; in cdns_unreg_slave()
974 cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); in cdns_unreg_slave()
1065 static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id) in cdns_i2c_setclk() argument
1070 unsigned long fscl = id->i2c_clk; in cdns_i2c_setclk()
1076 ctrl_reg = id->ctrl_reg; in cdns_i2c_setclk()
1080 id->ctrl_reg = ctrl_reg; in cdns_i2c_setclk()
1083 id->ctrl_reg_diva_divb = ctrl_reg & (CDNS_I2C_CR_DIVA_MASK | in cdns_i2c_setclk()
1109 struct cdns_i2c *id = to_cdns_i2c(nb); in cdns_i2c_clk_notifier_cb() local
1111 if (pm_runtime_suspended(id->dev)) in cdns_i2c_clk_notifier_cb()
1118 unsigned long fscl = id->i2c_clk; in cdns_i2c_clk_notifier_cb()
1124 dev_warn(id->adap.dev.parent, in cdns_i2c_clk_notifier_cb()
1131 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
1136 id->input_clk = ndata->new_rate; in cdns_i2c_clk_notifier_cb()
1139 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
1144 cdns_i2c_setclk(ndata->old_rate, id); in cdns_i2c_clk_notifier_cb()
1175 static void cdns_i2c_init(struct cdns_i2c *id) in cdns_i2c_init() argument
1177 cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); in cdns_i2c_init()
1240 struct cdns_i2c *id; in cdns_i2c_probe() local
1244 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); in cdns_i2c_probe()
1245 if (!id) in cdns_i2c_probe()
1248 id->dev = &pdev->dev; in cdns_i2c_probe()
1249 platform_set_drvdata(pdev, id); in cdns_i2c_probe()
1254 id->quirks = data->quirks; in cdns_i2c_probe()
1257 id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem); in cdns_i2c_probe()
1258 if (IS_ERR(id->membase)) in cdns_i2c_probe()
1259 return PTR_ERR(id->membase); in cdns_i2c_probe()
1264 id->irq = ret; in cdns_i2c_probe()
1266 id->adap.owner = THIS_MODULE; in cdns_i2c_probe()
1267 id->adap.dev.of_node = pdev->dev.of_node; in cdns_i2c_probe()
1268 id->adap.algo = &cdns_i2c_algo; in cdns_i2c_probe()
1269 id->adap.timeout = CDNS_I2C_TIMEOUT; in cdns_i2c_probe()
1270 id->adap.retries = 3; /* Default retry value. */ in cdns_i2c_probe()
1271 id->adap.algo_data = id; in cdns_i2c_probe()
1272 id->adap.dev.parent = &pdev->dev; in cdns_i2c_probe()
1273 init_completion(&id->xfer_done); in cdns_i2c_probe()
1274 snprintf(id->adap.name, sizeof(id->adap.name), in cdns_i2c_probe()
1277 id->clk = devm_clk_get(&pdev->dev, NULL); in cdns_i2c_probe()
1278 if (IS_ERR(id->clk)) in cdns_i2c_probe()
1279 return dev_err_probe(&pdev->dev, PTR_ERR(id->clk), in cdns_i2c_probe()
1282 ret = clk_prepare_enable(id->clk); in cdns_i2c_probe()
1286 pm_runtime_set_autosuspend_delay(id->dev, CNDS_I2C_PM_TIMEOUT); in cdns_i2c_probe()
1287 pm_runtime_use_autosuspend(id->dev); in cdns_i2c_probe()
1288 pm_runtime_set_active(id->dev); in cdns_i2c_probe()
1289 pm_runtime_enable(id->dev); in cdns_i2c_probe()
1291 id->clk_rate_change_nb.notifier_call = cdns_i2c_clk_notifier_cb; in cdns_i2c_probe()
1292 if (clk_notifier_register(id->clk, &id->clk_rate_change_nb)) in cdns_i2c_probe()
1294 id->input_clk = clk_get_rate(id->clk); in cdns_i2c_probe()
1297 &id->i2c_clk); in cdns_i2c_probe()
1298 if (ret || (id->i2c_clk > I2C_MAX_FAST_MODE_FREQ)) in cdns_i2c_probe()
1299 id->i2c_clk = I2C_MAX_STANDARD_MODE_FREQ; in cdns_i2c_probe()
1303 id->dev_mode = CDNS_I2C_MODE_MASTER; in cdns_i2c_probe()
1304 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_probe()
1306 id->ctrl_reg = CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS; in cdns_i2c_probe()
1308 ret = cdns_i2c_setclk(id->input_clk, id); in cdns_i2c_probe()
1310 dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk); in cdns_i2c_probe()
1315 ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0, in cdns_i2c_probe()
1316 DRIVER_NAME, id); in cdns_i2c_probe()
1318 dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); in cdns_i2c_probe()
1321 cdns_i2c_init(id); in cdns_i2c_probe()
1323 ret = i2c_add_adapter(&id->adap); in cdns_i2c_probe()
1328 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); in cdns_i2c_probe()
1333 clk_disable_unprepare(id->clk); in cdns_i2c_probe()
1349 struct cdns_i2c *id = platform_get_drvdata(pdev); in cdns_i2c_remove() local
1355 i2c_del_adapter(&id->adap); in cdns_i2c_remove()
1356 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_remove()
1357 clk_disable_unprepare(id->clk); in cdns_i2c_remove()