Lines Matching full:id
135 #define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
136 #define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
229 * @id: Pointer to driver data struct
233 static void cdns_i2c_clear_bus_hold(struct cdns_i2c *id) in cdns_i2c_clear_bus_hold() argument
240 static inline bool cdns_is_holdquirk(struct cdns_i2c *id, bool hold_wrkaround) in cdns_is_holdquirk() argument
243 (id->curr_recv_count == CDNS_I2C_FIFO_DEPTH + 1)); in cdns_is_holdquirk()
247 static void cdns_i2c_set_mode(enum cdns_i2c_mode mode, struct cdns_i2c *id) in cdns_i2c_set_mode() argument
256 id->dev_mode = mode; in cdns_i2c_set_mode()
257 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_set_mode()
262 cdns_i2c_writereg(id->ctrl_reg_diva_divb | in cdns_i2c_set_mode()
275 cdns_i2c_writereg(id->ctrl_reg_diva_divb & in cdns_i2c_set_mode()
280 cdns_i2c_writereg(id->slave->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_set_mode()
290 static void cdns_i2c_slave_rcv_data(struct cdns_i2c *id) in cdns_i2c_slave_rcv_data() argument
296 if (id->slave_state == CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_slave_rcv_data()
297 id->slave_state = CDNS_I2C_SLAVE_STATE_RECV; in cdns_i2c_slave_rcv_data()
298 i2c_slave_event(id->slave, I2C_SLAVE_WRITE_REQUESTED, NULL); in cdns_i2c_slave_rcv_data()
307 i2c_slave_event(id->slave, I2C_SLAVE_WRITE_RECEIVED, &data); in cdns_i2c_slave_rcv_data()
311 static void cdns_i2c_slave_send_data(struct cdns_i2c *id) in cdns_i2c_slave_send_data() argument
316 if (id->slave_state == CDNS_I2C_SLAVE_STATE_IDLE) { in cdns_i2c_slave_send_data()
317 id->slave_state = CDNS_I2C_SLAVE_STATE_SEND; in cdns_i2c_slave_send_data()
318 i2c_slave_event(id->slave, I2C_SLAVE_READ_REQUESTED, &data); in cdns_i2c_slave_send_data()
320 i2c_slave_event(id->slave, I2C_SLAVE_READ_PROCESSED, &data); in cdns_i2c_slave_send_data()
338 struct cdns_i2c *id = ptr; in cdns_i2c_slave_isr() local
355 cdns_i2c_slave_send_data(id); in cdns_i2c_slave_isr()
358 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
359 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
364 cdns_i2c_slave_rcv_data(id); in cdns_i2c_slave_isr()
367 cdns_i2c_slave_rcv_data(id); in cdns_i2c_slave_isr()
368 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
369 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
376 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_slave_isr()
377 i2c_slave_event(id->slave, I2C_SLAVE_STOP, NULL); in cdns_i2c_slave_isr()
399 struct cdns_i2c *id = ptr; in cdns_i2c_master_isr() local
406 id->err_status = 0; in cdns_i2c_master_isr()
418 updatetx = id->recv_count > id->curr_recv_count; in cdns_i2c_master_isr()
421 if (id->p_recv_buf && in cdns_i2c_master_isr()
427 if (id->recv_count > 0) { in cdns_i2c_master_isr()
428 *(id->p_recv_buf)++ = in cdns_i2c_master_isr()
430 id->recv_count--; in cdns_i2c_master_isr()
431 id->curr_recv_count--; in cdns_i2c_master_isr()
438 if (id->recv_count <= CDNS_I2C_FIFO_DEPTH && in cdns_i2c_master_isr()
439 !id->bus_hold_flag) in cdns_i2c_master_isr()
440 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
443 dev_err(id->adap.dev.parent, in cdns_i2c_master_isr()
445 id->err_status |= CDNS_I2C_IXR_TO; in cdns_i2c_master_isr()
449 if (cdns_is_holdquirk(id, updatetx)) in cdns_i2c_master_isr()
460 if (cdns_is_holdquirk(id, updatetx)) { in cdns_i2c_master_isr()
463 (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH)) in cdns_i2c_master_isr()
470 if (((int)(id->recv_count) - CDNS_I2C_FIFO_DEPTH) > in cdns_i2c_master_isr()
474 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE + in cdns_i2c_master_isr()
477 cdns_i2c_writereg(id->recv_count - in cdns_i2c_master_isr()
480 id->curr_recv_count = id->recv_count; in cdns_i2c_master_isr()
485 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->recv_count) { in cdns_i2c_master_isr()
486 if (!id->bus_hold_flag) in cdns_i2c_master_isr()
487 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
495 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->p_recv_buf) { in cdns_i2c_master_isr()
500 if (id->send_count) { in cdns_i2c_master_isr()
503 if (id->send_count > avail_bytes) in cdns_i2c_master_isr()
506 bytes_to_send = id->send_count; in cdns_i2c_master_isr()
510 (*(id->p_send_buf)++), in cdns_i2c_master_isr()
512 id->send_count--; in cdns_i2c_master_isr()
522 if (!id->send_count && !id->bus_hold_flag) in cdns_i2c_master_isr()
523 cdns_i2c_clear_bus_hold(id); in cdns_i2c_master_isr()
529 id->err_status |= isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; in cdns_i2c_master_isr()
530 if (id->err_status) in cdns_i2c_master_isr()
534 complete(&id->xfer_done); in cdns_i2c_master_isr()
552 struct cdns_i2c *id = ptr; in cdns_i2c_isr() local
554 if (id->dev_mode == CDNS_I2C_MODE_SLAVE) in cdns_i2c_isr()
562 * @id: pointer to the i2c device structure
564 static void cdns_i2c_mrecv(struct cdns_i2c *id) in cdns_i2c_mrecv() argument
574 id->p_recv_buf = id->p_msg->buf; in cdns_i2c_mrecv()
575 id->recv_count = id->p_msg->len; in cdns_i2c_mrecv()
586 if (id->p_msg->flags & I2C_M_RECV_LEN) in cdns_i2c_mrecv()
587 id->recv_count = I2C_SMBUS_BLOCK_MAX + id->p_msg->len; in cdns_i2c_mrecv()
589 id->curr_recv_count = id->recv_count; in cdns_i2c_mrecv()
595 if (id->recv_count > CDNS_I2C_FIFO_DEPTH) in cdns_i2c_mrecv()
610 if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) { in cdns_i2c_mrecv()
613 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE; in cdns_i2c_mrecv()
615 cdns_i2c_writereg(id->recv_count, CDNS_I2C_XFER_SIZE_OFFSET); in cdns_i2c_mrecv()
619 if (!id->bus_hold_flag && in cdns_i2c_mrecv()
620 ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && in cdns_i2c_mrecv()
621 (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) { in cdns_i2c_mrecv()
624 if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) in cdns_i2c_mrecv()
629 addr = id->p_msg->addr; in cdns_i2c_mrecv()
660 * @id: pointer to the i2c device
662 static void cdns_i2c_msend(struct cdns_i2c *id) in cdns_i2c_msend() argument
669 id->p_recv_buf = NULL; in cdns_i2c_msend()
670 id->p_send_buf = id->p_msg->buf; in cdns_i2c_msend()
671 id->send_count = id->p_msg->len; in cdns_i2c_msend()
682 if (id->send_count > CDNS_I2C_FIFO_DEPTH) in cdns_i2c_msend()
698 if (id->send_count > avail_bytes) in cdns_i2c_msend()
701 bytes_to_send = id->send_count; in cdns_i2c_msend()
704 cdns_i2c_writereg((*(id->p_send_buf)++), CDNS_I2C_DATA_OFFSET); in cdns_i2c_msend()
705 id->send_count--; in cdns_i2c_msend()
712 if (!id->bus_hold_flag && !id->send_count) in cdns_i2c_msend()
713 cdns_i2c_clear_bus_hold(id); in cdns_i2c_msend()
715 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_msend()
730 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_reset() local
750 static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, in cdns_i2c_process_msg() argument
756 id->p_msg = msg; in cdns_i2c_process_msg()
757 id->err_status = 0; in cdns_i2c_process_msg()
758 reinit_completion(&id->xfer_done); in cdns_i2c_process_msg()
774 cdns_i2c_mrecv(id); in cdns_i2c_process_msg()
776 cdns_i2c_msend(id); in cdns_i2c_process_msg()
779 msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk); in cdns_i2c_process_msg()
787 time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); in cdns_i2c_process_msg()
790 dev_err(id->adap.dev.parent, in cdns_i2c_process_msg()
799 if (id->err_status & CDNS_I2C_IXR_ARB_LOST) in cdns_i2c_process_msg()
823 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_xfer() local
829 ret = pm_runtime_resume_and_get(id->dev); in cdns_i2c_master_xfer()
835 if (id->dev_mode == CDNS_I2C_MODE_SLAVE) { in cdns_i2c_master_xfer()
836 if (id->slave_state != CDNS_I2C_SLAVE_STATE_IDLE) in cdns_i2c_master_xfer()
840 cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); in cdns_i2c_master_xfer()
849 ret = readl_relaxed_poll_timeout(id->membase + CDNS_I2C_SR_OFFSET, in cdns_i2c_master_xfer()
855 if (id->adap.bus_recovery_info) in cdns_i2c_master_xfer()
860 hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); in cdns_i2c_master_xfer()
881 id->bus_hold_flag = 1; in cdns_i2c_master_xfer()
886 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
892 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
894 ret = cdns_i2c_process_msg(id, msgs, adap); in cdns_i2c_master_xfer()
899 if (id->err_status) { in cdns_i2c_master_xfer()
902 if (id->err_status & CDNS_I2C_IXR_NACK) { in cdns_i2c_master_xfer()
918 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); in cdns_i2c_master_xfer()
921 pm_runtime_mark_last_busy(id->dev); in cdns_i2c_master_xfer()
922 pm_runtime_put_autosuspend(id->dev); in cdns_i2c_master_xfer()
949 struct cdns_i2c *id = container_of(slave->adapter, struct cdns_i2c, in cdns_reg_slave() local
952 if (id->slave) in cdns_reg_slave()
958 ret = pm_runtime_resume_and_get(id->dev); in cdns_reg_slave()
963 id->slave = slave; in cdns_reg_slave()
966 cdns_i2c_set_mode(CDNS_I2C_MODE_SLAVE, id); in cdns_reg_slave()
973 struct cdns_i2c *id = container_of(slave->adapter, struct cdns_i2c, in cdns_unreg_slave() local
976 pm_runtime_put(id->dev); in cdns_unreg_slave()
979 id->slave = NULL; in cdns_unreg_slave()
982 cdns_i2c_set_mode(CDNS_I2C_MODE_MASTER, id); in cdns_unreg_slave()
1060 * @id: Pointer to the I2C device structure
1073 static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id) in cdns_i2c_setclk() argument
1078 unsigned long fscl = id->i2c_clk; in cdns_i2c_setclk()
1084 ctrl_reg = id->ctrl_reg; in cdns_i2c_setclk()
1088 id->ctrl_reg = ctrl_reg; in cdns_i2c_setclk()
1091 id->ctrl_reg_diva_divb = ctrl_reg & (CDNS_I2C_CR_DIVA_MASK | in cdns_i2c_setclk()
1117 struct cdns_i2c *id = to_cdns_i2c(nb); in cdns_i2c_clk_notifier_cb() local
1119 if (pm_runtime_suspended(id->dev)) in cdns_i2c_clk_notifier_cb()
1126 unsigned long fscl = id->i2c_clk; in cdns_i2c_clk_notifier_cb()
1132 dev_warn(id->adap.dev.parent, in cdns_i2c_clk_notifier_cb()
1139 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
1144 id->input_clk = ndata->new_rate; in cdns_i2c_clk_notifier_cb()
1147 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
1152 cdns_i2c_setclk(ndata->old_rate, id); in cdns_i2c_clk_notifier_cb()
1178 * @id: Device private data structure
1183 static void cdns_i2c_init(struct cdns_i2c *id) in cdns_i2c_init() argument
1185 cdns_i2c_writereg(id->ctrl_reg, CDNS_I2C_CR_OFFSET); in cdns_i2c_init()
1248 struct cdns_i2c *id; in cdns_i2c_probe() local
1252 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); in cdns_i2c_probe()
1253 if (!id) in cdns_i2c_probe()
1256 id->dev = &pdev->dev; in cdns_i2c_probe()
1257 platform_set_drvdata(pdev, id); in cdns_i2c_probe()
1262 id->quirks = data->quirks; in cdns_i2c_probe()
1265 id->rinfo.pinctrl = devm_pinctrl_get(&pdev->dev); in cdns_i2c_probe()
1266 if (IS_ERR(id->rinfo.pinctrl)) { in cdns_i2c_probe()
1267 int err = PTR_ERR(id->rinfo.pinctrl); in cdns_i2c_probe()
1273 id->adap.bus_recovery_info = &id->rinfo; in cdns_i2c_probe()
1276 id->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &r_mem); in cdns_i2c_probe()
1277 if (IS_ERR(id->membase)) in cdns_i2c_probe()
1278 return PTR_ERR(id->membase); in cdns_i2c_probe()
1283 id->irq = ret; in cdns_i2c_probe()
1285 id->adap.owner = THIS_MODULE; in cdns_i2c_probe()
1286 id->adap.dev.of_node = pdev->dev.of_node; in cdns_i2c_probe()
1287 id->adap.algo = &cdns_i2c_algo; in cdns_i2c_probe()
1288 id->adap.timeout = CDNS_I2C_TIMEOUT; in cdns_i2c_probe()
1289 id->adap.retries = 3; /* Default retry value. */ in cdns_i2c_probe()
1290 id->adap.algo_data = id; in cdns_i2c_probe()
1291 id->adap.dev.parent = &pdev->dev; in cdns_i2c_probe()
1292 init_completion(&id->xfer_done); in cdns_i2c_probe()
1293 snprintf(id->adap.name, sizeof(id->adap.name), in cdns_i2c_probe()
1296 id->clk = devm_clk_get(&pdev->dev, NULL); in cdns_i2c_probe()
1297 if (IS_ERR(id->clk)) in cdns_i2c_probe()
1298 return dev_err_probe(&pdev->dev, PTR_ERR(id->clk), in cdns_i2c_probe()
1301 ret = clk_prepare_enable(id->clk); in cdns_i2c_probe()
1305 pm_runtime_set_autosuspend_delay(id->dev, CNDS_I2C_PM_TIMEOUT); in cdns_i2c_probe()
1306 pm_runtime_use_autosuspend(id->dev); in cdns_i2c_probe()
1307 pm_runtime_set_active(id->dev); in cdns_i2c_probe()
1308 pm_runtime_enable(id->dev); in cdns_i2c_probe()
1310 id->clk_rate_change_nb.notifier_call = cdns_i2c_clk_notifier_cb; in cdns_i2c_probe()
1311 if (clk_notifier_register(id->clk, &id->clk_rate_change_nb)) in cdns_i2c_probe()
1313 id->input_clk = clk_get_rate(id->clk); in cdns_i2c_probe()
1316 &id->i2c_clk); in cdns_i2c_probe()
1317 if (ret || (id->i2c_clk > I2C_MAX_FAST_MODE_FREQ)) in cdns_i2c_probe()
1318 id->i2c_clk = I2C_MAX_STANDARD_MODE_FREQ; in cdns_i2c_probe()
1322 id->dev_mode = CDNS_I2C_MODE_MASTER; in cdns_i2c_probe()
1323 id->slave_state = CDNS_I2C_SLAVE_STATE_IDLE; in cdns_i2c_probe()
1325 id->ctrl_reg = CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS; in cdns_i2c_probe()
1327 ret = cdns_i2c_setclk(id->input_clk, id); in cdns_i2c_probe()
1329 dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk); in cdns_i2c_probe()
1334 ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0, in cdns_i2c_probe()
1335 DRIVER_NAME, id); in cdns_i2c_probe()
1337 dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); in cdns_i2c_probe()
1340 cdns_i2c_init(id); in cdns_i2c_probe()
1342 ret = i2c_add_adapter(&id->adap); in cdns_i2c_probe()
1347 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); in cdns_i2c_probe()
1352 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_probe()
1353 clk_disable_unprepare(id->clk); in cdns_i2c_probe()
1369 struct cdns_i2c *id = platform_get_drvdata(pdev); in cdns_i2c_remove() local
1375 i2c_del_adapter(&id->adap); in cdns_i2c_remove()
1376 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_remove()
1377 clk_disable_unprepare(id->clk); in cdns_i2c_remove()