Lines Matching +full:uniphier +full:- +full:fi2c

1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright (C) 2015-2016 Socionext Inc.
23 u32 dttx; /* send FIFO (write-only) */
24 #define dtrx dttx /* receive FIFO (read-only) */
74 writel(I2C_RST_RST, &priv->regs->rst); in uniphier_fi2c_reset()
82 ret = readl_poll_timeout(&priv->regs->sr, val, !(val & I2C_SR_DB), 100); in uniphier_fi2c_check_bus_busy()
84 dev_dbg(priv->dev, "error: device busy too long. reset...\n"); in uniphier_fi2c_check_bus_busy()
98 return -EINVAL; in uniphier_fi2c_probe()
100 priv->regs = devm_ioremap(dev, addr, SZ_128); in uniphier_fi2c_probe()
101 if (!priv->regs) in uniphier_fi2c_probe()
102 return -ENOMEM; in uniphier_fi2c_probe()
104 priv->fioclk = FIOCLK; in uniphier_fi2c_probe()
106 priv->dev = dev; in uniphier_fi2c_probe()
111 writel(I2C_BRST_FOEN | I2C_BRST_RSCLO, &priv->regs->brst); in uniphier_fi2c_probe()
122 ret = readl_poll_timeout(&priv->regs->intr, irq, irq & flags, in wait_for_irq()
123 priv->timeout); in wait_for_irq()
125 dev_dbg(priv->dev, "error: time out\n"); in wait_for_irq()
130 dev_dbg(priv->dev, "error: arbitration lost\n"); in wait_for_irq()
136 dev_dbg(priv->dev, "error: no answer\n"); in wait_for_irq()
147 dev_dbg(priv->dev, "stop condition\n"); in issue_stop()
148 writel(I2C_CR_MST | I2C_CR_STO, &priv->regs->cr); in issue_stop()
152 dev_dbg(priv->dev, "error: device busy after operation\n"); in issue_stop()
162 struct uniphier_fi2c_regs __iomem *regs = priv->regs; in uniphier_fi2c_transmit()
164 dev_dbg(priv->dev, "%s: addr = %x, len = %d\n", __func__, addr, len); in uniphier_fi2c_transmit()
166 writel(I2C_DTTX_CMD | addr << 1, &regs->dttx); in uniphier_fi2c_transmit()
168 writel(irq_flags, &regs->ie); in uniphier_fi2c_transmit()
169 writel(irq_flags, &regs->ic); in uniphier_fi2c_transmit()
171 dev_dbg(priv->dev, "start condition\n"); in uniphier_fi2c_transmit()
172 writel(I2C_CR_MST | I2C_CR_STA, &regs->cr); in uniphier_fi2c_transmit()
178 while (len--) { in uniphier_fi2c_transmit()
179 dev_dbg(priv->dev, "sending %x\n", *buf); in uniphier_fi2c_transmit()
180 writel(*buf++, &regs->dttx); in uniphier_fi2c_transmit()
182 writel(irq_flags, &regs->ic); in uniphier_fi2c_transmit()
190 writel(irq_flags, &regs->ic); in uniphier_fi2c_transmit()
203 struct uniphier_fi2c_regs __iomem *regs = priv->regs; in uniphier_fi2c_receive()
205 dev_dbg(priv->dev, "%s: addr = %x, len = %d\n", __func__, addr, len); in uniphier_fi2c_receive()
214 writel(I2C_DTTX_CMD | I2C_DTTX_RD | addr << 1, &regs->dttx); in uniphier_fi2c_receive()
216 writel(0, &regs->rbc); in uniphier_fi2c_receive()
217 writel(irq_flags, &regs->ie); in uniphier_fi2c_receive()
218 writel(irq_flags, &regs->ic); in uniphier_fi2c_receive()
220 dev_dbg(priv->dev, "start condition\n"); in uniphier_fi2c_receive()
222 &regs->cr); in uniphier_fi2c_receive()
224 while (len--) { in uniphier_fi2c_receive()
229 *buf++ = readl(&regs->dtrx); in uniphier_fi2c_receive()
230 dev_dbg(priv->dev, "received %x\n", *(buf - 1)); in uniphier_fi2c_receive()
233 writel(I2C_CR_MST | I2C_CR_NACK, &regs->cr); in uniphier_fi2c_receive()
235 writel(irq_flags, &regs->ic); in uniphier_fi2c_receive()
239 writel(irq_flags, &regs->ic); in uniphier_fi2c_receive()
258 for (; nmsgs > 0; nmsgs--, msg++) { in uniphier_fi2c_xfer()
262 if (msg->flags & I2C_M_RD) in uniphier_fi2c_xfer()
263 ret = uniphier_fi2c_receive(priv, msg->addr, msg->len, in uniphier_fi2c_xfer()
264 msg->buf, &stop); in uniphier_fi2c_xfer()
266 ret = uniphier_fi2c_transmit(priv, msg->addr, msg->len, in uniphier_fi2c_xfer()
267 msg->buf, &stop); in uniphier_fi2c_xfer()
281 struct uniphier_fi2c_regs __iomem *regs = priv->regs; in uniphier_fi2c_set_bus_speed()
285 return -EINVAL; in uniphier_fi2c_set_bus_speed()
292 writel(I2C_BRST_RSCLO, &regs->brst); in uniphier_fi2c_set_bus_speed()
294 clk_count = priv->fioclk / speed; in uniphier_fi2c_set_bus_speed()
296 writel(clk_count, &regs->cyc); in uniphier_fi2c_set_bus_speed()
297 writel(clk_count / 2, &regs->lctl); in uniphier_fi2c_set_bus_speed()
298 writel(clk_count / 2, &regs->ssut); in uniphier_fi2c_set_bus_speed()
299 writel(clk_count / 16, &regs->dsut); in uniphier_fi2c_set_bus_speed()
301 writel(I2C_BRST_FOEN | I2C_BRST_RSCLO, &regs->brst); in uniphier_fi2c_set_bus_speed()
308 priv->timeout = 100000000L / speed; in uniphier_fi2c_set_bus_speed()
319 { .compatible = "socionext,uniphier-fi2c" },
324 .name = "uniphier-fi2c",