Lines Matching refs:alg_data

120 static inline void i2c_pnx_arm_timer(struct i2c_pnx_algo_data *alg_data)  in i2c_pnx_arm_timer()  argument
122 struct timer_list *timer = &alg_data->mif.timer; in i2c_pnx_arm_timer()
123 unsigned long expires = msecs_to_jiffies(alg_data->timeout); in i2c_pnx_arm_timer()
130 dev_dbg(&alg_data->adapter.dev, "Timer armed at %lu plus %lu jiffies.\n", in i2c_pnx_arm_timer()
146 struct i2c_pnx_algo_data *alg_data) in i2c_pnx_start() argument
148 dev_dbg(&alg_data->adapter.dev, "%s(): addr 0x%x mode %d\n", __func__, in i2c_pnx_start()
149 slave_addr, alg_data->mif.mode); in i2c_pnx_start()
153 dev_err(&alg_data->adapter.dev, in i2c_pnx_start()
155 alg_data->adapter.name, slave_addr); in i2c_pnx_start()
160 if (wait_timeout(alg_data)) { in i2c_pnx_start()
162 dev_err(&alg_data->adapter.dev, in i2c_pnx_start()
164 alg_data->adapter.name, slave_addr, in i2c_pnx_start()
165 ioread32(I2C_REG_CTL(alg_data)), in i2c_pnx_start()
166 ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_start()
168 } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) { in i2c_pnx_start()
170 dev_err(&alg_data->adapter.dev, in i2c_pnx_start()
172 alg_data->adapter.name, slave_addr); in i2c_pnx_start()
180 iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi, in i2c_pnx_start()
181 I2C_REG_STS(alg_data)); in i2c_pnx_start()
183 dev_dbg(&alg_data->adapter.dev, "%s(): sending %#x\n", __func__, in i2c_pnx_start()
184 (slave_addr << 1) | start_bit | alg_data->mif.mode); in i2c_pnx_start()
187 iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode, in i2c_pnx_start()
188 I2C_REG_TX(alg_data)); in i2c_pnx_start()
190 dev_dbg(&alg_data->adapter.dev, "%s(): exit\n", __func__); in i2c_pnx_start()
201 static void i2c_pnx_stop(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_stop() argument
206 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_stop()
207 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_stop()
210 iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data)); in i2c_pnx_stop()
214 (ioread32(I2C_REG_STS(alg_data)) & mstatus_active)) { in i2c_pnx_stop()
220 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_stop()
221 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_stop()
230 static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_master_xmit() argument
234 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_master_xmit()
235 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_xmit()
237 if (alg_data->mif.len > 0) { in i2c_pnx_master_xmit()
239 val = *alg_data->mif.buf++; in i2c_pnx_master_xmit()
241 if (alg_data->mif.len == 1) in i2c_pnx_master_xmit()
244 alg_data->mif.len--; in i2c_pnx_master_xmit()
245 iowrite32(val, I2C_REG_TX(alg_data)); in i2c_pnx_master_xmit()
247 dev_dbg(&alg_data->adapter.dev, "%s(): xmit %#x [%d]\n", in i2c_pnx_master_xmit()
248 __func__, val, alg_data->mif.len + 1); in i2c_pnx_master_xmit()
250 if (alg_data->mif.len == 0) { in i2c_pnx_master_xmit()
251 if (alg_data->last) { in i2c_pnx_master_xmit()
253 if (wait_timeout(alg_data)) in i2c_pnx_master_xmit()
254 dev_err(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
258 iowrite32(ioread32(I2C_REG_CTL(alg_data)) & in i2c_pnx_master_xmit()
260 I2C_REG_CTL(alg_data)); in i2c_pnx_master_xmit()
262 del_timer_sync(&alg_data->mif.timer); in i2c_pnx_master_xmit()
264 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
268 complete(&alg_data->mif.complete); in i2c_pnx_master_xmit()
270 } else if (alg_data->mif.len == 0) { in i2c_pnx_master_xmit()
272 i2c_pnx_stop(alg_data); in i2c_pnx_master_xmit()
275 iowrite32(ioread32(I2C_REG_CTL(alg_data)) & in i2c_pnx_master_xmit()
277 I2C_REG_CTL(alg_data)); in i2c_pnx_master_xmit()
280 del_timer_sync(&alg_data->mif.timer); in i2c_pnx_master_xmit()
281 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
285 complete(&alg_data->mif.complete); in i2c_pnx_master_xmit()
288 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_master_xmit()
289 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_xmit()
300 static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_master_rcv() argument
305 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_master_rcv()
306 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_rcv()
311 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { in i2c_pnx_master_rcv()
316 if (alg_data->mif.order) { in i2c_pnx_master_rcv()
317 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_rcv()
321 if (alg_data->mif.order == 1) { in i2c_pnx_master_rcv()
329 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
332 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
340 iowrite32(val, I2C_REG_TX(alg_data)); in i2c_pnx_master_rcv()
341 alg_data->mif.order--; in i2c_pnx_master_rcv()
347 if (alg_data->mif.len > 0) { in i2c_pnx_master_rcv()
348 val = ioread32(I2C_REG_RX(alg_data)); in i2c_pnx_master_rcv()
349 *alg_data->mif.buf++ = (u8) (val & 0xff); in i2c_pnx_master_rcv()
350 dev_dbg(&alg_data->adapter.dev, "%s(): rcv 0x%x [%d]\n", in i2c_pnx_master_rcv()
351 __func__, val, alg_data->mif.len); in i2c_pnx_master_rcv()
353 alg_data->mif.len--; in i2c_pnx_master_rcv()
354 if (alg_data->mif.len == 0) { in i2c_pnx_master_rcv()
355 if (alg_data->last) in i2c_pnx_master_rcv()
357 if (wait_timeout(alg_data)) in i2c_pnx_master_rcv()
358 dev_err(&alg_data->adapter.dev, in i2c_pnx_master_rcv()
362 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
365 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
368 del_timer_sync(&alg_data->mif.timer); in i2c_pnx_master_rcv()
369 complete(&alg_data->mif.complete); in i2c_pnx_master_rcv()
373 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_master_rcv()
374 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_rcv()
381 struct i2c_pnx_algo_data *alg_data = dev_id; in i2c_pnx_interrupt() local
384 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
387 ioread32(I2C_REG_STS(alg_data)), in i2c_pnx_interrupt()
388 ioread32(I2C_REG_CTL(alg_data)), in i2c_pnx_interrupt()
389 alg_data->mif.mode); in i2c_pnx_interrupt()
390 stat = ioread32(I2C_REG_STS(alg_data)); in i2c_pnx_interrupt()
395 alg_data->mif.ret = -EIO; in i2c_pnx_interrupt()
398 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
401 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
404 del_timer_sync(&alg_data->mif.timer); in i2c_pnx_interrupt()
405 complete(&alg_data->mif.complete); in i2c_pnx_interrupt()
408 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
411 i2c_pnx_stop(alg_data); in i2c_pnx_interrupt()
414 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
417 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
420 alg_data->mif.ret = -EIO; in i2c_pnx_interrupt()
423 del_timer_sync(&alg_data->mif.timer); in i2c_pnx_interrupt()
424 complete(&alg_data->mif.complete); in i2c_pnx_interrupt()
436 if (alg_data->mif.mode == I2C_SMBUS_WRITE) { in i2c_pnx_interrupt()
437 i2c_pnx_master_xmit(alg_data); in i2c_pnx_interrupt()
438 } else if (alg_data->mif.mode == I2C_SMBUS_READ) { in i2c_pnx_interrupt()
439 i2c_pnx_master_rcv(alg_data); in i2c_pnx_interrupt()
445 stat = ioread32(I2C_REG_STS(alg_data)); in i2c_pnx_interrupt()
446 iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data)); in i2c_pnx_interrupt()
448 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
450 __func__, ioread32(I2C_REG_STS(alg_data)), in i2c_pnx_interrupt()
451 ioread32(I2C_REG_CTL(alg_data))); in i2c_pnx_interrupt()
458 struct i2c_pnx_algo_data *alg_data = from_timer(alg_data, t, mif.timer); in i2c_pnx_timeout() local
461 dev_err(&alg_data->adapter.dev, in i2c_pnx_timeout()
463 ioread32(I2C_REG_STS(alg_data)), in i2c_pnx_timeout()
464 ioread32(I2C_REG_CTL(alg_data))); in i2c_pnx_timeout()
467 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_timeout()
469 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_timeout()
472 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_timeout()
473 wait_reset(alg_data); in i2c_pnx_timeout()
474 alg_data->mif.ret = -EIO; in i2c_pnx_timeout()
475 complete(&alg_data->mif.complete); in i2c_pnx_timeout()
478 static inline void bus_reset_if_active(struct i2c_pnx_algo_data *alg_data) in bus_reset_if_active() argument
482 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) { in bus_reset_if_active()
483 dev_err(&alg_data->adapter.dev, in bus_reset_if_active()
485 alg_data->adapter.name); in bus_reset_if_active()
486 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, in bus_reset_if_active()
487 I2C_REG_CTL(alg_data)); in bus_reset_if_active()
488 wait_reset(alg_data); in bus_reset_if_active()
493 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, in bus_reset_if_active()
494 I2C_REG_CTL(alg_data)); in bus_reset_if_active()
495 wait_reset(alg_data); in bus_reset_if_active()
497 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, in bus_reset_if_active()
498 I2C_REG_CTL(alg_data)); in bus_reset_if_active()
499 wait_reset(alg_data); in bus_reset_if_active()
516 struct i2c_pnx_algo_data *alg_data = adap->algo_data; in i2c_pnx_xfer() local
519 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
521 __func__, num, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_xfer()
523 bus_reset_if_active(alg_data); in i2c_pnx_xfer()
533 dev_err(&alg_data->adapter.dev, in i2c_pnx_xfer()
535 alg_data->adapter.name); in i2c_pnx_xfer()
540 alg_data->mif.buf = pmsg->buf; in i2c_pnx_xfer()
541 alg_data->mif.len = pmsg->len; in i2c_pnx_xfer()
542 alg_data->mif.order = pmsg->len; in i2c_pnx_xfer()
543 alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ? in i2c_pnx_xfer()
545 alg_data->mif.ret = 0; in i2c_pnx_xfer()
546 alg_data->last = (i == num - 1); in i2c_pnx_xfer()
548 dev_dbg(&alg_data->adapter.dev, "%s(): mode %d, %d bytes\n", in i2c_pnx_xfer()
549 __func__, alg_data->mif.mode, alg_data->mif.len); in i2c_pnx_xfer()
551 i2c_pnx_arm_timer(alg_data); in i2c_pnx_xfer()
554 init_completion(&alg_data->mif.complete); in i2c_pnx_xfer()
557 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie | in i2c_pnx_xfer()
559 I2C_REG_CTL(alg_data)); in i2c_pnx_xfer()
562 rc = i2c_pnx_start(addr, alg_data); in i2c_pnx_xfer()
567 wait_for_completion(&alg_data->mif.complete); in i2c_pnx_xfer()
569 if (!(rc = alg_data->mif.ret)) in i2c_pnx_xfer()
571 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
576 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) { in i2c_pnx_xfer()
577 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
579 alg_data->adapter.name); in i2c_pnx_xfer()
580 iowrite32(stat, I2C_REG_STS(alg_data)); in i2c_pnx_xfer()
582 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) { in i2c_pnx_xfer()
583 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
585 alg_data->adapter.name); in i2c_pnx_xfer()
586 iowrite32(stat, I2C_REG_STS(alg_data)); in i2c_pnx_xfer()
590 bus_reset_if_active(alg_data); in i2c_pnx_xfer()
593 alg_data->mif.buf = NULL; in i2c_pnx_xfer()
594 alg_data->mif.len = 0; in i2c_pnx_xfer()
595 alg_data->mif.order = 0; in i2c_pnx_xfer()
597 dev_dbg(&alg_data->adapter.dev, "%s(): exiting, stat = %x\n", in i2c_pnx_xfer()
598 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_xfer()
619 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev); in i2c_pnx_controller_suspend() local
621 clk_disable_unprepare(alg_data->clk); in i2c_pnx_controller_suspend()
628 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev); in i2c_pnx_controller_resume() local
630 return clk_prepare_enable(alg_data->clk); in i2c_pnx_controller_resume()
644 struct i2c_pnx_algo_data *alg_data; in i2c_pnx_probe() local
649 alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL); in i2c_pnx_probe()
650 if (!alg_data) in i2c_pnx_probe()
653 platform_set_drvdata(pdev, alg_data); in i2c_pnx_probe()
655 alg_data->adapter.dev.parent = &pdev->dev; in i2c_pnx_probe()
656 alg_data->adapter.algo = &pnx_algorithm; in i2c_pnx_probe()
657 alg_data->adapter.algo_data = alg_data; in i2c_pnx_probe()
658 alg_data->adapter.nr = pdev->id; in i2c_pnx_probe()
660 alg_data->timeout = I2C_PNX_TIMEOUT_DEFAULT; in i2c_pnx_probe()
662 alg_data->adapter.dev.of_node = of_node_get(pdev->dev.of_node); in i2c_pnx_probe()
676 alg_data->clk = devm_clk_get(&pdev->dev, NULL); in i2c_pnx_probe()
677 if (IS_ERR(alg_data->clk)) in i2c_pnx_probe()
678 return PTR_ERR(alg_data->clk); in i2c_pnx_probe()
680 timer_setup(&alg_data->mif.timer, i2c_pnx_timeout, 0); in i2c_pnx_probe()
682 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name), in i2c_pnx_probe()
687 alg_data->ioaddr = devm_ioremap_resource(&pdev->dev, res); in i2c_pnx_probe()
688 if (IS_ERR(alg_data->ioaddr)) in i2c_pnx_probe()
689 return PTR_ERR(alg_data->ioaddr); in i2c_pnx_probe()
691 ret = clk_prepare_enable(alg_data->clk); in i2c_pnx_probe()
695 freq = clk_get_rate(alg_data->clk); in i2c_pnx_probe()
711 iowrite32(tmp, I2C_REG_CKH(alg_data)); in i2c_pnx_probe()
712 iowrite32(tmp, I2C_REG_CKL(alg_data)); in i2c_pnx_probe()
714 iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data)); in i2c_pnx_probe()
715 if (wait_reset(alg_data)) { in i2c_pnx_probe()
719 init_completion(&alg_data->mif.complete); in i2c_pnx_probe()
721 alg_data->irq = platform_get_irq(pdev, 0); in i2c_pnx_probe()
722 if (alg_data->irq < 0) { in i2c_pnx_probe()
724 ret = alg_data->irq; in i2c_pnx_probe()
727 ret = devm_request_irq(&pdev->dev, alg_data->irq, i2c_pnx_interrupt, in i2c_pnx_probe()
728 0, pdev->name, alg_data); in i2c_pnx_probe()
733 ret = i2c_add_numbered_adapter(&alg_data->adapter); in i2c_pnx_probe()
738 alg_data->adapter.name, res->start, alg_data->irq); in i2c_pnx_probe()
743 clk_disable_unprepare(alg_data->clk); in i2c_pnx_probe()
749 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); in i2c_pnx_remove() local
751 i2c_del_adapter(&alg_data->adapter); in i2c_pnx_remove()
752 clk_disable_unprepare(alg_data->clk); in i2c_pnx_remove()