Lines Matching refs:i2c_dev
120 static void owl_i2c_reset(struct owl_i2c_dev *i2c_dev) in owl_i2c_reset() argument
122 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, in owl_i2c_reset()
125 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, in owl_i2c_reset()
129 writel(0, i2c_dev->base + OWL_I2C_REG_STAT); in owl_i2c_reset()
132 static int owl_i2c_reset_fifo(struct owl_i2c_dev *i2c_dev) in owl_i2c_reset_fifo() argument
137 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_FIFOCTL, in owl_i2c_reset_fifo()
143 val = readl(i2c_dev->base + OWL_I2C_REG_FIFOCTL); in owl_i2c_reset_fifo()
150 dev_err(&i2c_dev->adap.dev, "FIFO reset timeout\n"); in owl_i2c_reset_fifo()
157 static void owl_i2c_set_freq(struct owl_i2c_dev *i2c_dev) in owl_i2c_set_freq() argument
161 val = DIV_ROUND_UP(i2c_dev->clk_rate, i2c_dev->bus_freq * 16); in owl_i2c_set_freq()
164 writel(OWL_I2C_DIV_FACTOR(val), i2c_dev->base + OWL_I2C_REG_CLKDIV); in owl_i2c_set_freq()
167 static void owl_i2c_xfer_data(struct owl_i2c_dev *i2c_dev) in owl_i2c_xfer_data() argument
169 struct i2c_msg *msg = i2c_dev->msg; in owl_i2c_xfer_data()
172 i2c_dev->err = 0; in owl_i2c_xfer_data()
175 fifostat = readl(i2c_dev->base + OWL_I2C_REG_FIFOSTAT); in owl_i2c_xfer_data()
177 i2c_dev->err = -ENXIO; in owl_i2c_xfer_data()
179 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_FIFOSTAT, in owl_i2c_xfer_data()
185 stat = readl(i2c_dev->base + OWL_I2C_REG_STAT); in owl_i2c_xfer_data()
187 i2c_dev->err = -EIO; in owl_i2c_xfer_data()
189 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_STAT, in owl_i2c_xfer_data()
196 while ((readl(i2c_dev->base + OWL_I2C_REG_FIFOSTAT) & in owl_i2c_xfer_data()
197 OWL_I2C_FIFOSTAT_RFE) && i2c_dev->msg_ptr < msg->len) { in owl_i2c_xfer_data()
198 msg->buf[i2c_dev->msg_ptr++] = readl(i2c_dev->base + in owl_i2c_xfer_data()
203 while (!(readl(i2c_dev->base + OWL_I2C_REG_FIFOSTAT) & in owl_i2c_xfer_data()
204 OWL_I2C_FIFOSTAT_TFF) && i2c_dev->msg_ptr < msg->len) { in owl_i2c_xfer_data()
205 writel(msg->buf[i2c_dev->msg_ptr++], in owl_i2c_xfer_data()
206 i2c_dev->base + OWL_I2C_REG_TXDAT); in owl_i2c_xfer_data()
213 struct owl_i2c_dev *i2c_dev = _dev; in owl_i2c_interrupt() local
215 spin_lock(&i2c_dev->lock); in owl_i2c_interrupt()
217 owl_i2c_xfer_data(i2c_dev); in owl_i2c_interrupt()
220 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_STAT, in owl_i2c_interrupt()
223 complete_all(&i2c_dev->msg_complete); in owl_i2c_interrupt()
224 spin_unlock(&i2c_dev->lock); in owl_i2c_interrupt()
236 struct owl_i2c_dev *i2c_dev = i2c_get_adapdata(adap); in owl_i2c_check_bus_busy() local
241 while (readl(i2c_dev->base + OWL_I2C_REG_STAT) & OWL_I2C_STAT_BBB) { in owl_i2c_check_bus_busy()
254 struct owl_i2c_dev *i2c_dev = i2c_get_adapdata(adap); in owl_i2c_xfer_common() local
261 spin_lock_irqsave(&i2c_dev->lock, flags); in owl_i2c_xfer_common()
264 owl_i2c_reset(i2c_dev); in owl_i2c_xfer_common()
267 owl_i2c_set_freq(i2c_dev); in owl_i2c_xfer_common()
273 spin_unlock_irqrestore(&i2c_dev->lock, flags); in owl_i2c_xfer_common()
276 ret = owl_i2c_reset_fifo(i2c_dev); in owl_i2c_xfer_common()
285 spin_lock_irqsave(&i2c_dev->lock, flags); in owl_i2c_xfer_common()
288 val = readl(i2c_dev->base + OWL_I2C_REG_STAT); in owl_i2c_xfer_common()
291 writel(val, i2c_dev->base + OWL_I2C_REG_STAT); in owl_i2c_xfer_common()
297 reinit_completion(&i2c_dev->msg_complete); in owl_i2c_xfer_common()
300 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, in owl_i2c_xfer_common()
318 writel(addr, i2c_dev->base + OWL_I2C_REG_TXDAT); in owl_i2c_xfer_common()
323 i2c_dev->base + OWL_I2C_REG_TXDAT); in owl_i2c_xfer_common()
332 i2c_dev->msg = msg; in owl_i2c_xfer_common()
333 i2c_dev->msg_ptr = 0; in owl_i2c_xfer_common()
336 writel(msg->len, i2c_dev->base + OWL_I2C_REG_DATCNT); in owl_i2c_xfer_common()
339 writel(addr, i2c_dev->base + OWL_I2C_REG_TXDAT); in owl_i2c_xfer_common()
345 if (readl(i2c_dev->base + OWL_I2C_REG_FIFOSTAT) & in owl_i2c_xfer_common()
350 i2c_dev->base + OWL_I2C_REG_TXDAT); in owl_i2c_xfer_common()
353 i2c_dev->msg_ptr = idx; in owl_i2c_xfer_common()
358 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_FIFOCTL, in owl_i2c_xfer_common()
361 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_FIFOCTL, in owl_i2c_xfer_common()
365 writel(i2c_cmd, i2c_dev->base + OWL_I2C_REG_CMD); in owl_i2c_xfer_common()
367 spin_unlock_irqrestore(&i2c_dev->lock, flags); in owl_i2c_xfer_common()
371 ret = readl_poll_timeout_atomic(i2c_dev->base + OWL_I2C_REG_FIFOSTAT, in owl_i2c_xfer_common()
376 time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, in owl_i2c_xfer_common()
382 spin_lock_irqsave(&i2c_dev->lock, flags); in owl_i2c_xfer_common()
387 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, in owl_i2c_xfer_common()
394 owl_i2c_xfer_data(i2c_dev); in owl_i2c_xfer_common()
396 ret = i2c_dev->err < 0 ? i2c_dev->err : num; in owl_i2c_xfer_common()
399 spin_unlock_irqrestore(&i2c_dev->lock, flags); in owl_i2c_xfer_common()
403 owl_i2c_update_reg(i2c_dev->base + OWL_I2C_REG_CTL, in owl_i2c_xfer_common()
438 struct owl_i2c_dev *i2c_dev; in owl_i2c_probe() local
441 i2c_dev = devm_kzalloc(dev, sizeof(*i2c_dev), GFP_KERNEL); in owl_i2c_probe()
442 if (!i2c_dev) in owl_i2c_probe()
445 i2c_dev->base = devm_platform_ioremap_resource(pdev, 0); in owl_i2c_probe()
446 if (IS_ERR(i2c_dev->base)) in owl_i2c_probe()
447 return PTR_ERR(i2c_dev->base); in owl_i2c_probe()
454 &i2c_dev->bus_freq)) in owl_i2c_probe()
455 i2c_dev->bus_freq = I2C_MAX_STANDARD_MODE_FREQ; in owl_i2c_probe()
458 if (i2c_dev->bus_freq != I2C_MAX_STANDARD_MODE_FREQ && in owl_i2c_probe()
459 i2c_dev->bus_freq != I2C_MAX_FAST_MODE_FREQ) { in owl_i2c_probe()
460 dev_err(dev, "invalid clock-frequency %d\n", i2c_dev->bus_freq); in owl_i2c_probe()
464 i2c_dev->clk = devm_clk_get(dev, NULL); in owl_i2c_probe()
465 if (IS_ERR(i2c_dev->clk)) { in owl_i2c_probe()
467 return PTR_ERR(i2c_dev->clk); in owl_i2c_probe()
470 ret = clk_prepare_enable(i2c_dev->clk); in owl_i2c_probe()
474 i2c_dev->clk_rate = clk_get_rate(i2c_dev->clk); in owl_i2c_probe()
475 if (!i2c_dev->clk_rate) { in owl_i2c_probe()
481 init_completion(&i2c_dev->msg_complete); in owl_i2c_probe()
482 spin_lock_init(&i2c_dev->lock); in owl_i2c_probe()
483 i2c_dev->adap.owner = THIS_MODULE; in owl_i2c_probe()
484 i2c_dev->adap.algo = &owl_i2c_algorithm; in owl_i2c_probe()
485 i2c_dev->adap.timeout = OWL_I2C_TIMEOUT; in owl_i2c_probe()
486 i2c_dev->adap.quirks = &owl_i2c_quirks; in owl_i2c_probe()
487 i2c_dev->adap.dev.parent = dev; in owl_i2c_probe()
488 i2c_dev->adap.dev.of_node = dev->of_node; in owl_i2c_probe()
489 snprintf(i2c_dev->adap.name, sizeof(i2c_dev->adap.name), in owl_i2c_probe()
491 i2c_set_adapdata(&i2c_dev->adap, i2c_dev); in owl_i2c_probe()
493 platform_set_drvdata(pdev, i2c_dev); in owl_i2c_probe()
496 i2c_dev); in owl_i2c_probe()
502 return i2c_add_adapter(&i2c_dev->adap); in owl_i2c_probe()
505 clk_disable_unprepare(i2c_dev->clk); in owl_i2c_probe()