Lines Matching refs:id

122 #define cdns_i2c_readreg(offset)       readl_relaxed(id->membase + offset)
123 #define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
181 static void cdns_i2c_clear_bus_hold(struct cdns_i2c *id) in cdns_i2c_clear_bus_hold() argument
188 static inline bool cdns_is_holdquirk(struct cdns_i2c *id, bool hold_wrkaround) in cdns_is_holdquirk() argument
191 (id->curr_recv_count == CDNS_I2C_FIFO_DEPTH + 1)); in cdns_is_holdquirk()
209 struct cdns_i2c *id = ptr; in cdns_i2c_isr() local
227 updatetx = id->recv_count > id->curr_recv_count; in cdns_i2c_isr()
230 if (id->p_recv_buf && in cdns_i2c_isr()
241 if ((id->recv_count < CDNS_I2C_FIFO_DEPTH) && in cdns_i2c_isr()
242 !id->bus_hold_flag) in cdns_i2c_isr()
243 cdns_i2c_clear_bus_hold(id); in cdns_i2c_isr()
245 *(id->p_recv_buf)++ = in cdns_i2c_isr()
247 id->recv_count--; in cdns_i2c_isr()
248 id->curr_recv_count--; in cdns_i2c_isr()
250 if (cdns_is_holdquirk(id, updatetx)) in cdns_i2c_isr()
261 if (cdns_is_holdquirk(id, updatetx)) { in cdns_i2c_isr()
264 (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH)) in cdns_i2c_isr()
271 if (((int)(id->recv_count) - CDNS_I2C_FIFO_DEPTH) > in cdns_i2c_isr()
275 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE + in cdns_i2c_isr()
278 cdns_i2c_writereg(id->recv_count - in cdns_i2c_isr()
281 id->curr_recv_count = id->recv_count; in cdns_i2c_isr()
286 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->recv_count) { in cdns_i2c_isr()
287 if (!id->bus_hold_flag) in cdns_i2c_isr()
288 cdns_i2c_clear_bus_hold(id); in cdns_i2c_isr()
296 if ((isr_status & CDNS_I2C_IXR_COMP) && !id->p_recv_buf) { in cdns_i2c_isr()
301 if (id->send_count) { in cdns_i2c_isr()
304 if (id->send_count > avail_bytes) in cdns_i2c_isr()
307 bytes_to_send = id->send_count; in cdns_i2c_isr()
311 (*(id->p_send_buf)++), in cdns_i2c_isr()
313 id->send_count--; in cdns_i2c_isr()
323 if (!id->send_count && !id->bus_hold_flag) in cdns_i2c_isr()
324 cdns_i2c_clear_bus_hold(id); in cdns_i2c_isr()
330 id->err_status = isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; in cdns_i2c_isr()
331 if (id->err_status) in cdns_i2c_isr()
335 complete(&id->xfer_done); in cdns_i2c_isr()
344 static void cdns_i2c_mrecv(struct cdns_i2c *id) in cdns_i2c_mrecv() argument
349 id->p_recv_buf = id->p_msg->buf; in cdns_i2c_mrecv()
350 id->recv_count = id->p_msg->len; in cdns_i2c_mrecv()
361 if (id->p_msg->flags & I2C_M_RECV_LEN) in cdns_i2c_mrecv()
362 id->recv_count = I2C_SMBUS_BLOCK_MAX + id->p_msg->len; in cdns_i2c_mrecv()
364 id->curr_recv_count = id->recv_count; in cdns_i2c_mrecv()
370 if (id->recv_count > CDNS_I2C_FIFO_DEPTH) in cdns_i2c_mrecv()
385 if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) { in cdns_i2c_mrecv()
388 id->curr_recv_count = CDNS_I2C_TRANSFER_SIZE; in cdns_i2c_mrecv()
390 cdns_i2c_writereg(id->recv_count, CDNS_I2C_XFER_SIZE_OFFSET); in cdns_i2c_mrecv()
394 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_mrecv()
397 if (!id->bus_hold_flag && in cdns_i2c_mrecv()
398 ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && in cdns_i2c_mrecv()
399 (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) in cdns_i2c_mrecv()
400 cdns_i2c_clear_bus_hold(id); in cdns_i2c_mrecv()
408 static void cdns_i2c_msend(struct cdns_i2c *id) in cdns_i2c_msend() argument
415 id->p_recv_buf = NULL; in cdns_i2c_msend()
416 id->p_send_buf = id->p_msg->buf; in cdns_i2c_msend()
417 id->send_count = id->p_msg->len; in cdns_i2c_msend()
428 if (id->send_count > CDNS_I2C_FIFO_DEPTH) in cdns_i2c_msend()
444 if (id->send_count > avail_bytes) in cdns_i2c_msend()
447 bytes_to_send = id->send_count; in cdns_i2c_msend()
450 cdns_i2c_writereg((*(id->p_send_buf)++), CDNS_I2C_DATA_OFFSET); in cdns_i2c_msend()
451 id->send_count--; in cdns_i2c_msend()
458 if (!id->bus_hold_flag && !id->send_count) in cdns_i2c_msend()
459 cdns_i2c_clear_bus_hold(id); in cdns_i2c_msend()
461 cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, in cdns_i2c_msend()
476 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_reset() local
496 static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, in cdns_i2c_process_msg() argument
502 id->p_msg = msg; in cdns_i2c_process_msg()
503 id->err_status = 0; in cdns_i2c_process_msg()
504 reinit_completion(&id->xfer_done); in cdns_i2c_process_msg()
520 cdns_i2c_mrecv(id); in cdns_i2c_process_msg()
522 cdns_i2c_msend(id); in cdns_i2c_process_msg()
525 msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk); in cdns_i2c_process_msg()
533 time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); in cdns_i2c_process_msg()
536 dev_err(id->adap.dev.parent, in cdns_i2c_process_msg()
545 if (id->err_status & CDNS_I2C_IXR_ARB_LOST) in cdns_i2c_process_msg()
569 struct cdns_i2c *id = adap->algo_data; in cdns_i2c_master_xfer() local
572 ret = pm_runtime_get_sync(id->dev); in cdns_i2c_master_xfer()
581 hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT); in cdns_i2c_master_xfer()
602 id->bus_hold_flag = 1; in cdns_i2c_master_xfer()
607 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
613 id->bus_hold_flag = 0; in cdns_i2c_master_xfer()
615 ret = cdns_i2c_process_msg(id, msgs, adap); in cdns_i2c_master_xfer()
620 if (id->err_status) { in cdns_i2c_master_xfer()
623 if (id->err_status & CDNS_I2C_IXR_NACK) { in cdns_i2c_master_xfer()
634 pm_runtime_mark_last_busy(id->dev); in cdns_i2c_master_xfer()
635 pm_runtime_put_autosuspend(id->dev); in cdns_i2c_master_xfer()
733 static int cdns_i2c_setclk(unsigned long clk_in, struct cdns_i2c *id) in cdns_i2c_setclk() argument
738 unsigned long fscl = id->i2c_clk; in cdns_i2c_setclk()
773 struct cdns_i2c *id = to_cdns_i2c(nb); in cdns_i2c_clk_notifier_cb() local
775 if (pm_runtime_suspended(id->dev)) in cdns_i2c_clk_notifier_cb()
782 unsigned long fscl = id->i2c_clk; in cdns_i2c_clk_notifier_cb()
788 dev_warn(id->adap.dev.parent, in cdns_i2c_clk_notifier_cb()
795 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
800 id->input_clk = ndata->new_rate; in cdns_i2c_clk_notifier_cb()
803 cdns_i2c_setclk(ndata->new_rate, id); in cdns_i2c_clk_notifier_cb()
808 cdns_i2c_setclk(ndata->old_rate, id); in cdns_i2c_clk_notifier_cb()
883 struct cdns_i2c *id; in cdns_i2c_probe() local
887 id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); in cdns_i2c_probe()
888 if (!id) in cdns_i2c_probe()
891 id->dev = &pdev->dev; in cdns_i2c_probe()
892 platform_set_drvdata(pdev, id); in cdns_i2c_probe()
897 id->quirks = data->quirks; in cdns_i2c_probe()
901 id->membase = devm_ioremap_resource(&pdev->dev, r_mem); in cdns_i2c_probe()
902 if (IS_ERR(id->membase)) in cdns_i2c_probe()
903 return PTR_ERR(id->membase); in cdns_i2c_probe()
908 id->irq = ret; in cdns_i2c_probe()
910 id->adap.owner = THIS_MODULE; in cdns_i2c_probe()
911 id->adap.dev.of_node = pdev->dev.of_node; in cdns_i2c_probe()
912 id->adap.algo = &cdns_i2c_algo; in cdns_i2c_probe()
913 id->adap.timeout = CDNS_I2C_TIMEOUT; in cdns_i2c_probe()
914 id->adap.retries = 3; /* Default retry value. */ in cdns_i2c_probe()
915 id->adap.algo_data = id; in cdns_i2c_probe()
916 id->adap.dev.parent = &pdev->dev; in cdns_i2c_probe()
917 init_completion(&id->xfer_done); in cdns_i2c_probe()
918 snprintf(id->adap.name, sizeof(id->adap.name), in cdns_i2c_probe()
921 id->clk = devm_clk_get(&pdev->dev, NULL); in cdns_i2c_probe()
922 if (IS_ERR(id->clk)) { in cdns_i2c_probe()
924 return PTR_ERR(id->clk); in cdns_i2c_probe()
926 ret = clk_prepare_enable(id->clk); in cdns_i2c_probe()
930 pm_runtime_enable(id->dev); in cdns_i2c_probe()
931 pm_runtime_set_autosuspend_delay(id->dev, CNDS_I2C_PM_TIMEOUT); in cdns_i2c_probe()
932 pm_runtime_use_autosuspend(id->dev); in cdns_i2c_probe()
933 pm_runtime_set_active(id->dev); in cdns_i2c_probe()
935 id->clk_rate_change_nb.notifier_call = cdns_i2c_clk_notifier_cb; in cdns_i2c_probe()
936 if (clk_notifier_register(id->clk, &id->clk_rate_change_nb)) in cdns_i2c_probe()
938 id->input_clk = clk_get_rate(id->clk); in cdns_i2c_probe()
941 &id->i2c_clk); in cdns_i2c_probe()
942 if (ret || (id->i2c_clk > CDNS_I2C_SPEED_MAX)) in cdns_i2c_probe()
943 id->i2c_clk = CDNS_I2C_SPEED_DEFAULT; in cdns_i2c_probe()
948 ret = cdns_i2c_setclk(id->input_clk, id); in cdns_i2c_probe()
950 dev_err(&pdev->dev, "invalid SCL clock: %u Hz\n", id->i2c_clk); in cdns_i2c_probe()
955 ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0, in cdns_i2c_probe()
956 DRIVER_NAME, id); in cdns_i2c_probe()
958 dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); in cdns_i2c_probe()
971 ret = i2c_add_adapter(&id->adap); in cdns_i2c_probe()
976 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); in cdns_i2c_probe()
981 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_probe()
982 clk_disable_unprepare(id->clk); in cdns_i2c_probe()
998 struct cdns_i2c *id = platform_get_drvdata(pdev); in cdns_i2c_remove() local
1000 i2c_del_adapter(&id->adap); in cdns_i2c_remove()
1001 clk_notifier_unregister(id->clk, &id->clk_rate_change_nb); in cdns_i2c_remove()
1002 clk_disable_unprepare(id->clk); in cdns_i2c_remove()