Lines Matching +full:filt +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0+
26 #define DRIVER_NAME "imx-lpi2c"
116 writel(enable, lpi2c_imx->base + LPI2C_MIER); in lpi2c_imx_intctrl()
125 temp = readl(lpi2c_imx->base + LPI2C_MSR); in lpi2c_imx_bus_busy()
129 writel(temp, lpi2c_imx->base + LPI2C_MSR); in lpi2c_imx_bus_busy()
130 return -EAGAIN; in lpi2c_imx_bus_busy()
137 dev_dbg(&lpi2c_imx->adapter.dev, "bus not work\n"); in lpi2c_imx_bus_busy()
138 if (lpi2c_imx->adapter.bus_recovery_info) in lpi2c_imx_bus_busy()
139 i2c_recover_bus(&lpi2c_imx->adapter); in lpi2c_imx_bus_busy()
140 return -ETIMEDOUT; in lpi2c_imx_bus_busy()
150 unsigned int bitrate = lpi2c_imx->bitrate; in lpi2c_imx_set_mode()
164 lpi2c_imx->mode = mode; in lpi2c_imx_set_mode()
172 temp = readl(lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_start()
174 writel(temp, lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_start()
175 writel(0x7f00, lpi2c_imx->base + LPI2C_MSR); in lpi2c_imx_start()
178 writel(temp, lpi2c_imx->base + LPI2C_MTDR); in lpi2c_imx_start()
188 writel(GEN_STOP << 8, lpi2c_imx->base + LPI2C_MTDR); in lpi2c_imx_stop()
191 temp = readl(lpi2c_imx->base + LPI2C_MSR); in lpi2c_imx_stop()
196 dev_dbg(&lpi2c_imx->adapter.dev, "stop timeout\n"); in lpi2c_imx_stop()
197 if (lpi2c_imx->adapter.bus_recovery_info) in lpi2c_imx_stop()
198 i2c_recover_bus(&lpi2c_imx->adapter); in lpi2c_imx_stop()
209 u8 prescale, filt, sethold, datavd; in lpi2c_imx_config() local
216 clk_rate = lpi2c_imx->rate_per; in lpi2c_imx_config()
218 if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST) in lpi2c_imx_config()
219 filt = 0; in lpi2c_imx_config()
221 filt = 2; in lpi2c_imx_config()
224 clk_cycle = clk_rate / ((1 << prescale) * lpi2c_imx->bitrate) in lpi2c_imx_config()
225 - 3 - (filt >> 1); in lpi2c_imx_config()
227 clklo = clk_cycle - clkhi; in lpi2c_imx_config()
233 return -EINVAL; in lpi2c_imx_config()
236 if (lpi2c_imx->mode == ULTRA_FAST) in lpi2c_imx_config()
242 if (lpi2c_imx->mode == ULTRA_FAST) in lpi2c_imx_config()
245 writel(temp, lpi2c_imx->base + LPI2C_MCFGR1); in lpi2c_imx_config()
248 temp = (filt << 16) | (filt << 24); in lpi2c_imx_config()
249 writel(temp, lpi2c_imx->base + LPI2C_MCFGR2); in lpi2c_imx_config()
256 if (lpi2c_imx->mode == HS) in lpi2c_imx_config()
257 writel(temp, lpi2c_imx->base + LPI2C_MCCR1); in lpi2c_imx_config()
259 writel(temp, lpi2c_imx->base + LPI2C_MCCR0); in lpi2c_imx_config()
269 ret = pm_runtime_resume_and_get(lpi2c_imx->adapter.dev.parent); in lpi2c_imx_master_enable()
274 writel(temp, lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_master_enable()
275 writel(0, lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_master_enable()
281 temp = readl(lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_master_enable()
283 writel(temp, lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_master_enable()
288 pm_runtime_mark_last_busy(lpi2c_imx->adapter.dev.parent); in lpi2c_imx_master_enable()
289 pm_runtime_put_autosuspend(lpi2c_imx->adapter.dev.parent); in lpi2c_imx_master_enable()
298 temp = readl(lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_master_disable()
300 writel(temp, lpi2c_imx->base + LPI2C_MCR); in lpi2c_imx_master_disable()
302 pm_runtime_mark_last_busy(lpi2c_imx->adapter.dev.parent); in lpi2c_imx_master_disable()
303 pm_runtime_put_autosuspend(lpi2c_imx->adapter.dev.parent); in lpi2c_imx_master_disable()
312 time_left = wait_for_completion_timeout(&lpi2c_imx->complete, HZ); in lpi2c_imx_msg_complete()
314 return time_left ? 0 : -ETIMEDOUT; in lpi2c_imx_msg_complete()
323 txcnt = readl(lpi2c_imx->base + LPI2C_MFSR) & 0xff; in lpi2c_imx_txfifo_empty()
325 if (readl(lpi2c_imx->base + LPI2C_MSR) & MSR_NDF) { in lpi2c_imx_txfifo_empty()
326 dev_dbg(&lpi2c_imx->adapter.dev, "NDF detected\n"); in lpi2c_imx_txfifo_empty()
327 return -EIO; in lpi2c_imx_txfifo_empty()
331 dev_dbg(&lpi2c_imx->adapter.dev, "txfifo empty timeout\n"); in lpi2c_imx_txfifo_empty()
332 if (lpi2c_imx->adapter.bus_recovery_info) in lpi2c_imx_txfifo_empty()
333 i2c_recover_bus(&lpi2c_imx->adapter); in lpi2c_imx_txfifo_empty()
334 return -ETIMEDOUT; in lpi2c_imx_txfifo_empty()
345 writel(lpi2c_imx->txfifosize >> 1, lpi2c_imx->base + LPI2C_MFCR); in lpi2c_imx_set_tx_watermark()
352 remaining = lpi2c_imx->msglen - lpi2c_imx->delivered; in lpi2c_imx_set_rx_watermark()
354 if (remaining > (lpi2c_imx->rxfifosize >> 1)) in lpi2c_imx_set_rx_watermark()
355 temp = lpi2c_imx->rxfifosize >> 1; in lpi2c_imx_set_rx_watermark()
359 writel(temp << 16, lpi2c_imx->base + LPI2C_MFCR); in lpi2c_imx_set_rx_watermark()
366 txcnt = readl(lpi2c_imx->base + LPI2C_MFSR) & 0xff; in lpi2c_imx_write_txfifo()
368 while (txcnt < lpi2c_imx->txfifosize) { in lpi2c_imx_write_txfifo()
369 if (lpi2c_imx->delivered == lpi2c_imx->msglen) in lpi2c_imx_write_txfifo()
372 data = lpi2c_imx->tx_buf[lpi2c_imx->delivered++]; in lpi2c_imx_write_txfifo()
373 writel(data, lpi2c_imx->base + LPI2C_MTDR); in lpi2c_imx_write_txfifo()
377 if (lpi2c_imx->delivered < lpi2c_imx->msglen) in lpi2c_imx_write_txfifo()
380 complete(&lpi2c_imx->complete); in lpi2c_imx_write_txfifo()
389 data = readl(lpi2c_imx->base + LPI2C_MRDR); in lpi2c_imx_read_rxfifo()
393 lpi2c_imx->rx_buf[lpi2c_imx->delivered++] = data & 0xff; in lpi2c_imx_read_rxfifo()
398 * data read. Add it to msgs->len. in lpi2c_imx_read_rxfifo()
400 if (lpi2c_imx->block_data) { in lpi2c_imx_read_rxfifo()
401 blocklen = lpi2c_imx->rx_buf[0]; in lpi2c_imx_read_rxfifo()
402 lpi2c_imx->msglen += blocklen; in lpi2c_imx_read_rxfifo()
405 remaining = lpi2c_imx->msglen - lpi2c_imx->delivered; in lpi2c_imx_read_rxfifo()
408 complete(&lpi2c_imx->complete); in lpi2c_imx_read_rxfifo()
416 if (lpi2c_imx->block_data) { in lpi2c_imx_read_rxfifo()
417 lpi2c_imx->block_data = 0; in lpi2c_imx_read_rxfifo()
420 writel(temp, lpi2c_imx->base + LPI2C_MTDR); in lpi2c_imx_read_rxfifo()
421 } else if (!(lpi2c_imx->delivered & 0xff)) { in lpi2c_imx_read_rxfifo()
422 temp = (remaining > CHUNK_DATA ? CHUNK_DATA : remaining) - 1; in lpi2c_imx_read_rxfifo()
424 writel(temp, lpi2c_imx->base + LPI2C_MTDR); in lpi2c_imx_read_rxfifo()
433 lpi2c_imx->tx_buf = msgs->buf; in lpi2c_imx_write()
443 lpi2c_imx->rx_buf = msgs->buf; in lpi2c_imx_read()
444 lpi2c_imx->block_data = msgs->flags & I2C_M_RECV_LEN; in lpi2c_imx_read()
447 temp = msgs->len > CHUNK_DATA ? CHUNK_DATA - 1 : msgs->len - 1; in lpi2c_imx_read()
449 writel(temp, lpi2c_imx->base + LPI2C_MTDR); in lpi2c_imx_read()
468 goto disable; in lpi2c_imx_xfer()
474 lpi2c_imx->rx_buf = NULL; in lpi2c_imx_xfer()
475 lpi2c_imx->tx_buf = NULL; in lpi2c_imx_xfer()
476 lpi2c_imx->delivered = 0; in lpi2c_imx_xfer()
477 lpi2c_imx->msglen = msgs[i].len; in lpi2c_imx_xfer()
478 init_completion(&lpi2c_imx->complete); in lpi2c_imx_xfer()
499 temp = readl(lpi2c_imx->base + LPI2C_MSR); in lpi2c_imx_xfer()
501 result = -EIO; in lpi2c_imx_xfer()
503 disable: in lpi2c_imx_xfer()
506 dev_dbg(&lpi2c_imx->adapter.dev, "<%s> exit with: %s: %d\n", __func__, in lpi2c_imx_xfer()
519 enabled = readl(lpi2c_imx->base + LPI2C_MIER); in lpi2c_imx_isr()
522 temp = readl(lpi2c_imx->base + LPI2C_MSR); in lpi2c_imx_isr()
526 complete(&lpi2c_imx->complete); in lpi2c_imx_isr()
538 struct i2c_bus_recovery_info *bri = &lpi2c_imx->rinfo; in lpi2c_imx_init_recovery_info()
540 bri->pinctrl = devm_pinctrl_get(&pdev->dev); in lpi2c_imx_init_recovery_info()
541 if (IS_ERR(bri->pinctrl)) in lpi2c_imx_init_recovery_info()
542 return PTR_ERR(bri->pinctrl); in lpi2c_imx_init_recovery_info()
544 lpi2c_imx->adapter.bus_recovery_info = bri; in lpi2c_imx_init_recovery_info()
561 { .compatible = "fsl,imx7ulp-lpi2c" },
572 lpi2c_imx = devm_kzalloc(&pdev->dev, sizeof(*lpi2c_imx), GFP_KERNEL); in lpi2c_imx_probe()
574 return -ENOMEM; in lpi2c_imx_probe()
576 lpi2c_imx->base = devm_platform_ioremap_resource(pdev, 0); in lpi2c_imx_probe()
577 if (IS_ERR(lpi2c_imx->base)) in lpi2c_imx_probe()
578 return PTR_ERR(lpi2c_imx->base); in lpi2c_imx_probe()
584 lpi2c_imx->adapter.owner = THIS_MODULE; in lpi2c_imx_probe()
585 lpi2c_imx->adapter.algo = &lpi2c_imx_algo; in lpi2c_imx_probe()
586 lpi2c_imx->adapter.dev.parent = &pdev->dev; in lpi2c_imx_probe()
587 lpi2c_imx->adapter.dev.of_node = pdev->dev.of_node; in lpi2c_imx_probe()
588 strscpy(lpi2c_imx->adapter.name, pdev->name, in lpi2c_imx_probe()
589 sizeof(lpi2c_imx->adapter.name)); in lpi2c_imx_probe()
591 ret = devm_clk_bulk_get_all(&pdev->dev, &lpi2c_imx->clks); in lpi2c_imx_probe()
593 return dev_err_probe(&pdev->dev, ret, "can't get I2C peripheral clock\n"); in lpi2c_imx_probe()
594 lpi2c_imx->num_clks = ret; in lpi2c_imx_probe()
596 ret = of_property_read_u32(pdev->dev.of_node, in lpi2c_imx_probe()
597 "clock-frequency", &lpi2c_imx->bitrate); in lpi2c_imx_probe()
599 lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; in lpi2c_imx_probe()
601 ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr, 0, in lpi2c_imx_probe()
602 pdev->name, lpi2c_imx); in lpi2c_imx_probe()
604 return dev_err_probe(&pdev->dev, ret, "can't claim irq %d\n", irq); in lpi2c_imx_probe()
606 i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx); in lpi2c_imx_probe()
609 ret = clk_bulk_prepare_enable(lpi2c_imx->num_clks, lpi2c_imx->clks); in lpi2c_imx_probe()
617 ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk); in lpi2c_imx_probe()
619 return dev_err_probe(&pdev->dev, ret, in lpi2c_imx_probe()
622 lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk); in lpi2c_imx_probe()
623 if (!lpi2c_imx->rate_per) in lpi2c_imx_probe()
624 return dev_err_probe(&pdev->dev, -EINVAL, in lpi2c_imx_probe()
627 pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); in lpi2c_imx_probe()
628 pm_runtime_use_autosuspend(&pdev->dev); in lpi2c_imx_probe()
629 pm_runtime_get_noresume(&pdev->dev); in lpi2c_imx_probe()
630 pm_runtime_set_active(&pdev->dev); in lpi2c_imx_probe()
631 pm_runtime_enable(&pdev->dev); in lpi2c_imx_probe()
633 temp = readl(lpi2c_imx->base + LPI2C_PARAM); in lpi2c_imx_probe()
634 lpi2c_imx->txfifosize = 1 << (temp & 0x0f); in lpi2c_imx_probe()
635 lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f); in lpi2c_imx_probe()
640 if (ret == -EPROBE_DEFER) in lpi2c_imx_probe()
643 ret = i2c_add_adapter(&lpi2c_imx->adapter); in lpi2c_imx_probe()
647 pm_runtime_mark_last_busy(&pdev->dev); in lpi2c_imx_probe()
648 pm_runtime_put_autosuspend(&pdev->dev); in lpi2c_imx_probe()
650 dev_info(&lpi2c_imx->adapter.dev, "LPI2C adapter registered\n"); in lpi2c_imx_probe()
655 pm_runtime_put(&pdev->dev); in lpi2c_imx_probe()
656 pm_runtime_disable(&pdev->dev); in lpi2c_imx_probe()
657 pm_runtime_dont_use_autosuspend(&pdev->dev); in lpi2c_imx_probe()
666 i2c_del_adapter(&lpi2c_imx->adapter); in lpi2c_imx_remove()
668 pm_runtime_disable(&pdev->dev); in lpi2c_imx_remove()
669 pm_runtime_dont_use_autosuspend(&pdev->dev); in lpi2c_imx_remove()
676 clk_bulk_disable(lpi2c_imx->num_clks, lpi2c_imx->clks); in lpi2c_runtime_suspend()
688 ret = clk_bulk_enable(lpi2c_imx->num_clks, lpi2c_imx->clks); in lpi2c_runtime_resume()