Lines Matching +full:im +full:-

4  * SPDX-License-Identifier: (GPL-2.0+ OR MIT)
94 writel(count, i2c_dev->base + I2C_COUNT); in sprd_i2c_set_count()
99 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_send_stop()
102 writel(tmp & ~STP_EN, i2c_dev->base + I2C_CTL); in sprd_i2c_send_stop()
104 writel(tmp | STP_EN, i2c_dev->base + I2C_CTL); in sprd_i2c_send_stop()
109 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_clear_start()
111 writel(tmp & ~I2C_START, i2c_dev->base + I2C_CTL); in sprd_i2c_clear_start()
116 u32 tmp = readl(i2c_dev->base + I2C_STATUS); in sprd_i2c_clear_ack()
118 writel(tmp & ~I2C_RX_ACK, i2c_dev->base + I2C_STATUS); in sprd_i2c_clear_ack()
123 u32 tmp = readl(i2c_dev->base + I2C_STATUS); in sprd_i2c_clear_irq()
125 writel(tmp & ~I2C_INT, i2c_dev->base + I2C_STATUS); in sprd_i2c_clear_irq()
130 writel(I2C_RST, i2c_dev->base + ADDR_RST); in sprd_i2c_reset_fifo()
135 writel(m->addr << 1, i2c_dev->base + I2C_ADDR_CFG); in sprd_i2c_set_devaddr()
143 writeb(buf[i], i2c_dev->base + I2C_TX); in sprd_i2c_write_bytes()
151 buf[i] = readb(i2c_dev->base + I2C_RX); in sprd_i2c_read_bytes()
156 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_set_full_thld()
160 writel(tmp, i2c_dev->base + I2C_CTL); in sprd_i2c_set_full_thld()
165 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_set_empty_thld()
169 writel(tmp, i2c_dev->base + I2C_CTL); in sprd_i2c_set_empty_thld()
174 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_set_fifo_full_int()
181 writel(tmp, i2c_dev->base + I2C_CTL); in sprd_i2c_set_fifo_full_int()
186 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_set_fifo_empty_int()
193 writel(tmp, i2c_dev->base + I2C_CTL); in sprd_i2c_set_fifo_empty_int()
198 u32 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_opt_start()
200 writel(tmp | I2C_START, i2c_dev->base + I2C_CTL); in sprd_i2c_opt_start()
205 u32 cmd = readl(i2c_dev->base + I2C_CTL) & ~I2C_MODE; in sprd_i2c_opt_mode()
207 writel(cmd | rw << 3, i2c_dev->base + I2C_CTL); in sprd_i2c_opt_mode()
212 u32 i2c_count = i2c_dev->count; in sprd_i2c_data_transfer()
214 struct i2c_msg *msg = i2c_dev->msg; in sprd_i2c_data_transfer()
216 if (msg->flags & I2C_M_RD) { in sprd_i2c_data_transfer()
217 sprd_i2c_read_bytes(i2c_dev, i2c_dev->buf, I2C_FIFO_FULL_THLD); in sprd_i2c_data_transfer()
218 i2c_dev->count -= I2C_FIFO_FULL_THLD; in sprd_i2c_data_transfer()
219 i2c_dev->buf += I2C_FIFO_FULL_THLD; in sprd_i2c_data_transfer()
226 if (i2c_dev->count >= I2C_FIFO_FULL_THLD) in sprd_i2c_data_transfer()
229 sprd_i2c_write_bytes(i2c_dev, i2c_dev->buf, need_tran); in sprd_i2c_data_transfer()
230 i2c_dev->buf += need_tran; in sprd_i2c_data_transfer()
231 i2c_dev->count -= need_tran; in sprd_i2c_data_transfer()
246 struct sprd_i2c *i2c_dev = i2c_adap->algo_data; in sprd_i2c_handle_msg()
248 i2c_dev->msg = msg; in sprd_i2c_handle_msg()
249 i2c_dev->buf = msg->buf; in sprd_i2c_handle_msg()
250 i2c_dev->count = msg->len; in sprd_i2c_handle_msg()
252 reinit_completion(&i2c_dev->complete); in sprd_i2c_handle_msg()
255 sprd_i2c_set_count(i2c_dev, msg->len); in sprd_i2c_handle_msg()
257 if (msg->flags & I2C_M_RD) { in sprd_i2c_handle_msg()
269 if (msg->flags & I2C_M_RD) in sprd_i2c_handle_msg()
276 wait_for_completion(&i2c_dev->complete); in sprd_i2c_handle_msg()
278 return i2c_dev->err; in sprd_i2c_handle_msg()
284 struct sprd_i2c *i2c_dev = i2c_adap->algo_data; in sprd_i2c_master_xfer()
285 int im, ret; in sprd_i2c_master_xfer() local
287 ret = pm_runtime_get_sync(i2c_dev->dev); in sprd_i2c_master_xfer()
291 for (im = 0; im < num - 1; im++) { in sprd_i2c_master_xfer()
292 ret = sprd_i2c_handle_msg(i2c_adap, &msgs[im], 0); in sprd_i2c_master_xfer()
297 ret = sprd_i2c_handle_msg(i2c_adap, &msgs[im++], 1); in sprd_i2c_master_xfer()
300 pm_runtime_mark_last_busy(i2c_dev->dev); in sprd_i2c_master_xfer()
301 pm_runtime_put_autosuspend(i2c_dev->dev); in sprd_i2c_master_xfer()
303 return ret < 0 ? ret : im; in sprd_i2c_master_xfer()
318 u32 apb_clk = i2c_dev->src_clk; in sprd_i2c_set_clk()
321 * prescale = freq_i2c / (4 * freq_scl) - 1; in sprd_i2c_set_clk()
323 u32 i2c_dvd = apb_clk / (4 * freq) - 1; in sprd_i2c_set_clk()
336 writel(div0, i2c_dev->base + ADDR_DVD0); in sprd_i2c_set_clk()
337 writel(div1, i2c_dev->base + ADDR_DVD1); in sprd_i2c_set_clk()
341 writel((6 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD); in sprd_i2c_set_clk()
343 writel((4 * apb_clk) / 1000000, i2c_dev->base + ADDR_STA0_DVD); in sprd_i2c_set_clk()
350 writel(tmp, i2c_dev->base + I2C_CTL); in sprd_i2c_enable()
355 sprd_i2c_set_clk(i2c_dev, i2c_dev->bus_freq); in sprd_i2c_enable()
359 tmp = readl(i2c_dev->base + I2C_CTL); in sprd_i2c_enable()
360 writel(tmp | I2C_EN | I2C_INT_EN, i2c_dev->base + I2C_CTL); in sprd_i2c_enable()
366 struct i2c_msg *msg = i2c_dev->msg; in sprd_i2c_isr_thread()
367 bool ack = !(readl(i2c_dev->base + I2C_STATUS) & I2C_RX_ACK); in sprd_i2c_isr_thread()
370 if (msg->flags & I2C_M_RD) in sprd_i2c_isr_thread()
371 i2c_tran = i2c_dev->count >= I2C_FIFO_FULL_THLD; in sprd_i2c_isr_thread()
373 i2c_tran = i2c_dev->count; in sprd_i2c_isr_thread()
388 i2c_dev->err = 0; in sprd_i2c_isr_thread()
392 * return -EIO to notify users. in sprd_i2c_isr_thread()
395 i2c_dev->err = -EIO; in sprd_i2c_isr_thread()
396 else if (msg->flags & I2C_M_RD && i2c_dev->count) in sprd_i2c_isr_thread()
397 sprd_i2c_read_bytes(i2c_dev, i2c_dev->buf, i2c_dev->count); in sprd_i2c_isr_thread()
402 complete(&i2c_dev->complete); in sprd_i2c_isr_thread()
410 struct i2c_msg *msg = i2c_dev->msg; in sprd_i2c_isr()
411 bool ack = !(readl(i2c_dev->base + I2C_STATUS) & I2C_RX_ACK); in sprd_i2c_isr()
414 if (msg->flags & I2C_M_RD) in sprd_i2c_isr()
415 i2c_tran = i2c_dev->count >= I2C_FIFO_FULL_THLD; in sprd_i2c_isr()
417 i2c_tran = i2c_dev->count; in sprd_i2c_isr()
445 clk_i2c = devm_clk_get(i2c_dev->dev, "i2c"); in sprd_i2c_clk_init()
447 dev_warn(i2c_dev->dev, "i2c%d can't get the i2c clock\n", in sprd_i2c_clk_init()
448 i2c_dev->adap.nr); in sprd_i2c_clk_init()
452 clk_parent = devm_clk_get(i2c_dev->dev, "source"); in sprd_i2c_clk_init()
454 dev_warn(i2c_dev->dev, "i2c%d can't get the source clock\n", in sprd_i2c_clk_init()
455 i2c_dev->adap.nr); in sprd_i2c_clk_init()
460 i2c_dev->src_clk = clk_get_rate(clk_i2c); in sprd_i2c_clk_init()
462 i2c_dev->src_clk = 26000000; in sprd_i2c_clk_init()
464 dev_dbg(i2c_dev->dev, "i2c%d set source clock is %d\n", in sprd_i2c_clk_init()
465 i2c_dev->adap.nr, i2c_dev->src_clk); in sprd_i2c_clk_init()
467 i2c_dev->clk = devm_clk_get(i2c_dev->dev, "enable"); in sprd_i2c_clk_init()
468 if (IS_ERR(i2c_dev->clk)) { in sprd_i2c_clk_init()
469 dev_err(i2c_dev->dev, "i2c%d can't get the enable clock\n", in sprd_i2c_clk_init()
470 i2c_dev->adap.nr); in sprd_i2c_clk_init()
471 return PTR_ERR(i2c_dev->clk); in sprd_i2c_clk_init()
479 struct device *dev = &pdev->dev; in sprd_i2c_probe()
484 pdev->id = of_alias_get_id(dev->of_node, "i2c"); in sprd_i2c_probe()
488 return -ENOMEM; in sprd_i2c_probe()
490 i2c_dev->base = devm_platform_ioremap_resource(pdev, 0); in sprd_i2c_probe()
491 if (IS_ERR(i2c_dev->base)) in sprd_i2c_probe()
492 return PTR_ERR(i2c_dev->base); in sprd_i2c_probe()
494 i2c_dev->irq = platform_get_irq(pdev, 0); in sprd_i2c_probe()
495 if (i2c_dev->irq < 0) in sprd_i2c_probe()
496 return i2c_dev->irq; in sprd_i2c_probe()
498 i2c_set_adapdata(&i2c_dev->adap, i2c_dev); in sprd_i2c_probe()
499 init_completion(&i2c_dev->complete); in sprd_i2c_probe()
500 snprintf(i2c_dev->adap.name, sizeof(i2c_dev->adap.name), in sprd_i2c_probe()
501 "%s", "sprd-i2c"); in sprd_i2c_probe()
503 i2c_dev->bus_freq = I2C_MAX_STANDARD_MODE_FREQ; in sprd_i2c_probe()
504 i2c_dev->adap.owner = THIS_MODULE; in sprd_i2c_probe()
505 i2c_dev->dev = dev; in sprd_i2c_probe()
506 i2c_dev->adap.retries = 3; in sprd_i2c_probe()
507 i2c_dev->adap.algo = &sprd_i2c_algo; in sprd_i2c_probe()
508 i2c_dev->adap.algo_data = i2c_dev; in sprd_i2c_probe()
509 i2c_dev->adap.dev.parent = dev; in sprd_i2c_probe()
510 i2c_dev->adap.nr = pdev->id; in sprd_i2c_probe()
511 i2c_dev->adap.dev.of_node = dev->of_node; in sprd_i2c_probe()
513 if (!of_property_read_u32(dev->of_node, "clock-frequency", &prop)) in sprd_i2c_probe()
514 i2c_dev->bus_freq = prop; in sprd_i2c_probe()
517 if (i2c_dev->bus_freq != I2C_MAX_STANDARD_MODE_FREQ && in sprd_i2c_probe()
518 i2c_dev->bus_freq != I2C_MAX_FAST_MODE_FREQ) in sprd_i2c_probe()
519 return -EINVAL; in sprd_i2c_probe()
527 ret = clk_prepare_enable(i2c_dev->clk); in sprd_i2c_probe()
533 pm_runtime_set_autosuspend_delay(i2c_dev->dev, SPRD_I2C_PM_TIMEOUT); in sprd_i2c_probe()
534 pm_runtime_use_autosuspend(i2c_dev->dev); in sprd_i2c_probe()
535 pm_runtime_set_active(i2c_dev->dev); in sprd_i2c_probe()
536 pm_runtime_enable(i2c_dev->dev); in sprd_i2c_probe()
538 ret = pm_runtime_get_sync(i2c_dev->dev); in sprd_i2c_probe()
542 ret = devm_request_threaded_irq(dev, i2c_dev->irq, in sprd_i2c_probe()
545 pdev->name, i2c_dev); in sprd_i2c_probe()
547 dev_err(&pdev->dev, "failed to request irq %d\n", i2c_dev->irq); in sprd_i2c_probe()
551 ret = i2c_add_numbered_adapter(&i2c_dev->adap); in sprd_i2c_probe()
553 dev_err(&pdev->dev, "add adapter failed\n"); in sprd_i2c_probe()
557 pm_runtime_mark_last_busy(i2c_dev->dev); in sprd_i2c_probe()
558 pm_runtime_put_autosuspend(i2c_dev->dev); in sprd_i2c_probe()
562 pm_runtime_put_noidle(i2c_dev->dev); in sprd_i2c_probe()
563 pm_runtime_disable(i2c_dev->dev); in sprd_i2c_probe()
564 clk_disable_unprepare(i2c_dev->clk); in sprd_i2c_probe()
573 ret = pm_runtime_get_sync(i2c_dev->dev); in sprd_i2c_remove()
577 i2c_del_adapter(&i2c_dev->adap); in sprd_i2c_remove()
578 clk_disable_unprepare(i2c_dev->clk); in sprd_i2c_remove()
580 pm_runtime_put_noidle(i2c_dev->dev); in sprd_i2c_remove()
581 pm_runtime_disable(i2c_dev->dev); in sprd_i2c_remove()
590 i2c_mark_adapter_suspended(&i2c_dev->adap); in sprd_i2c_suspend_noirq()
598 i2c_mark_adapter_resumed(&i2c_dev->adap); in sprd_i2c_resume_noirq()
606 clk_disable_unprepare(i2c_dev->clk); in sprd_i2c_runtime_suspend()
616 ret = clk_prepare_enable(i2c_dev->clk); in sprd_i2c_runtime_resume()
634 { .compatible = "sprd,sc9860-i2c", },
642 .name = "sprd-i2c",