Lines Matching refs:alg_data
126 struct i2c_pnx_algo_data *alg_data) in i2c_pnx_start() argument
128 dev_dbg(&alg_data->adapter.dev, "%s(): addr 0x%x mode %d\n", __func__, in i2c_pnx_start()
129 slave_addr, alg_data->mif.mode); in i2c_pnx_start()
133 dev_err(&alg_data->adapter.dev, in i2c_pnx_start()
135 alg_data->adapter.name, slave_addr); in i2c_pnx_start()
140 if (wait_timeout(alg_data)) { in i2c_pnx_start()
142 dev_err(&alg_data->adapter.dev, in i2c_pnx_start()
144 alg_data->adapter.name, slave_addr, in i2c_pnx_start()
145 ioread32(I2C_REG_CTL(alg_data)), in i2c_pnx_start()
146 ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_start()
148 } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) { in i2c_pnx_start()
150 dev_err(&alg_data->adapter.dev, in i2c_pnx_start()
152 alg_data->adapter.name, slave_addr); in i2c_pnx_start()
160 iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi, in i2c_pnx_start()
161 I2C_REG_STS(alg_data)); in i2c_pnx_start()
163 dev_dbg(&alg_data->adapter.dev, "%s(): sending %#x\n", __func__, in i2c_pnx_start()
164 (slave_addr << 1) | start_bit | alg_data->mif.mode); in i2c_pnx_start()
167 iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode, in i2c_pnx_start()
168 I2C_REG_TX(alg_data)); in i2c_pnx_start()
170 dev_dbg(&alg_data->adapter.dev, "%s(): exit\n", __func__); in i2c_pnx_start()
181 static void i2c_pnx_stop(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_stop() argument
186 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_stop()
187 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_stop()
190 iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data)); in i2c_pnx_stop()
194 (ioread32(I2C_REG_STS(alg_data)) & mstatus_active)) { in i2c_pnx_stop()
200 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_stop()
201 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_stop()
210 static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_master_xmit() argument
214 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_master_xmit()
215 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_xmit()
217 if (alg_data->mif.len > 0) { in i2c_pnx_master_xmit()
219 val = *alg_data->mif.buf++; in i2c_pnx_master_xmit()
221 if (alg_data->mif.len == 1) in i2c_pnx_master_xmit()
224 alg_data->mif.len--; in i2c_pnx_master_xmit()
225 iowrite32(val, I2C_REG_TX(alg_data)); in i2c_pnx_master_xmit()
227 dev_dbg(&alg_data->adapter.dev, "%s(): xmit %#x [%d]\n", in i2c_pnx_master_xmit()
228 __func__, val, alg_data->mif.len + 1); in i2c_pnx_master_xmit()
230 if (alg_data->mif.len == 0) { in i2c_pnx_master_xmit()
231 if (alg_data->last) { in i2c_pnx_master_xmit()
233 if (wait_timeout(alg_data)) in i2c_pnx_master_xmit()
234 dev_err(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
238 iowrite32(ioread32(I2C_REG_CTL(alg_data)) & in i2c_pnx_master_xmit()
240 I2C_REG_CTL(alg_data)); in i2c_pnx_master_xmit()
242 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
246 complete(&alg_data->mif.complete); in i2c_pnx_master_xmit()
248 } else if (alg_data->mif.len == 0) { in i2c_pnx_master_xmit()
250 i2c_pnx_stop(alg_data); in i2c_pnx_master_xmit()
253 iowrite32(ioread32(I2C_REG_CTL(alg_data)) & in i2c_pnx_master_xmit()
255 I2C_REG_CTL(alg_data)); in i2c_pnx_master_xmit()
257 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
261 complete(&alg_data->mif.complete); in i2c_pnx_master_xmit()
264 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_master_xmit()
265 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_xmit()
276 static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_master_rcv() argument
281 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_master_rcv()
282 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_rcv()
287 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { in i2c_pnx_master_rcv()
292 if (alg_data->mif.order) { in i2c_pnx_master_rcv()
293 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_rcv()
297 if (alg_data->mif.order == 1) { in i2c_pnx_master_rcv()
305 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
308 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
316 iowrite32(val, I2C_REG_TX(alg_data)); in i2c_pnx_master_rcv()
317 alg_data->mif.order--; in i2c_pnx_master_rcv()
323 if (alg_data->mif.len > 0) { in i2c_pnx_master_rcv()
324 val = ioread32(I2C_REG_RX(alg_data)); in i2c_pnx_master_rcv()
325 *alg_data->mif.buf++ = (u8) (val & 0xff); in i2c_pnx_master_rcv()
326 dev_dbg(&alg_data->adapter.dev, "%s(): rcv 0x%x [%d]\n", in i2c_pnx_master_rcv()
327 __func__, val, alg_data->mif.len); in i2c_pnx_master_rcv()
329 alg_data->mif.len--; in i2c_pnx_master_rcv()
330 if (alg_data->mif.len == 0) { in i2c_pnx_master_rcv()
331 if (alg_data->last) in i2c_pnx_master_rcv()
333 if (wait_timeout(alg_data)) in i2c_pnx_master_rcv()
334 dev_err(&alg_data->adapter.dev, in i2c_pnx_master_rcv()
338 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
341 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_master_rcv()
343 complete(&alg_data->mif.complete); in i2c_pnx_master_rcv()
347 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_master_rcv()
348 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_master_rcv()
355 struct i2c_pnx_algo_data *alg_data = dev_id; in i2c_pnx_interrupt() local
358 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
361 ioread32(I2C_REG_STS(alg_data)), in i2c_pnx_interrupt()
362 ioread32(I2C_REG_CTL(alg_data)), in i2c_pnx_interrupt()
363 alg_data->mif.mode); in i2c_pnx_interrupt()
364 stat = ioread32(I2C_REG_STS(alg_data)); in i2c_pnx_interrupt()
369 alg_data->mif.ret = -EIO; in i2c_pnx_interrupt()
372 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
375 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
377 complete(&alg_data->mif.complete); in i2c_pnx_interrupt()
380 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
383 i2c_pnx_stop(alg_data); in i2c_pnx_interrupt()
386 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
389 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_interrupt()
392 alg_data->mif.ret = -EIO; in i2c_pnx_interrupt()
394 complete(&alg_data->mif.complete); in i2c_pnx_interrupt()
406 if (alg_data->mif.mode == I2C_SMBUS_WRITE) { in i2c_pnx_interrupt()
407 i2c_pnx_master_xmit(alg_data); in i2c_pnx_interrupt()
408 } else if (alg_data->mif.mode == I2C_SMBUS_READ) { in i2c_pnx_interrupt()
409 i2c_pnx_master_rcv(alg_data); in i2c_pnx_interrupt()
415 stat = ioread32(I2C_REG_STS(alg_data)); in i2c_pnx_interrupt()
416 iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data)); in i2c_pnx_interrupt()
418 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
420 __func__, ioread32(I2C_REG_STS(alg_data)), in i2c_pnx_interrupt()
421 ioread32(I2C_REG_CTL(alg_data))); in i2c_pnx_interrupt()
426 static void i2c_pnx_timeout(struct i2c_pnx_algo_data *alg_data) in i2c_pnx_timeout() argument
430 dev_err(&alg_data->adapter.dev, in i2c_pnx_timeout()
432 ioread32(I2C_REG_STS(alg_data)), in i2c_pnx_timeout()
433 ioread32(I2C_REG_CTL(alg_data))); in i2c_pnx_timeout()
436 ctl = ioread32(I2C_REG_CTL(alg_data)); in i2c_pnx_timeout()
438 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_timeout()
441 iowrite32(ctl, I2C_REG_CTL(alg_data)); in i2c_pnx_timeout()
442 wait_reset(alg_data); in i2c_pnx_timeout()
443 alg_data->mif.ret = -EIO; in i2c_pnx_timeout()
446 static inline void bus_reset_if_active(struct i2c_pnx_algo_data *alg_data) in bus_reset_if_active() argument
450 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) { in bus_reset_if_active()
451 dev_err(&alg_data->adapter.dev, in bus_reset_if_active()
453 alg_data->adapter.name); in bus_reset_if_active()
454 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, in bus_reset_if_active()
455 I2C_REG_CTL(alg_data)); in bus_reset_if_active()
456 wait_reset(alg_data); in bus_reset_if_active()
461 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, in bus_reset_if_active()
462 I2C_REG_CTL(alg_data)); in bus_reset_if_active()
463 wait_reset(alg_data); in bus_reset_if_active()
465 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, in bus_reset_if_active()
466 I2C_REG_CTL(alg_data)); in bus_reset_if_active()
467 wait_reset(alg_data); in bus_reset_if_active()
484 struct i2c_pnx_algo_data *alg_data = adap->algo_data; in i2c_pnx_xfer() local
488 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
490 __func__, num, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_xfer()
492 bus_reset_if_active(alg_data); in i2c_pnx_xfer()
502 dev_err(&alg_data->adapter.dev, in i2c_pnx_xfer()
504 alg_data->adapter.name); in i2c_pnx_xfer()
509 alg_data->mif.buf = pmsg->buf; in i2c_pnx_xfer()
510 alg_data->mif.len = pmsg->len; in i2c_pnx_xfer()
511 alg_data->mif.order = pmsg->len; in i2c_pnx_xfer()
512 alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ? in i2c_pnx_xfer()
514 alg_data->mif.ret = 0; in i2c_pnx_xfer()
515 alg_data->last = (i == num - 1); in i2c_pnx_xfer()
517 dev_dbg(&alg_data->adapter.dev, "%s(): mode %d, %d bytes\n", in i2c_pnx_xfer()
518 __func__, alg_data->mif.mode, alg_data->mif.len); in i2c_pnx_xfer()
522 init_completion(&alg_data->mif.complete); in i2c_pnx_xfer()
525 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie | in i2c_pnx_xfer()
527 I2C_REG_CTL(alg_data)); in i2c_pnx_xfer()
530 rc = i2c_pnx_start(addr, alg_data); in i2c_pnx_xfer()
535 time_left = wait_for_completion_timeout(&alg_data->mif.complete, in i2c_pnx_xfer()
536 alg_data->timeout); in i2c_pnx_xfer()
538 i2c_pnx_timeout(alg_data); in i2c_pnx_xfer()
540 if (!(rc = alg_data->mif.ret)) in i2c_pnx_xfer()
542 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
547 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) { in i2c_pnx_xfer()
548 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
550 alg_data->adapter.name); in i2c_pnx_xfer()
551 iowrite32(stat, I2C_REG_STS(alg_data)); in i2c_pnx_xfer()
553 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) { in i2c_pnx_xfer()
554 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
556 alg_data->adapter.name); in i2c_pnx_xfer()
557 iowrite32(stat, I2C_REG_STS(alg_data)); in i2c_pnx_xfer()
561 bus_reset_if_active(alg_data); in i2c_pnx_xfer()
564 alg_data->mif.buf = NULL; in i2c_pnx_xfer()
565 alg_data->mif.len = 0; in i2c_pnx_xfer()
566 alg_data->mif.order = 0; in i2c_pnx_xfer()
568 dev_dbg(&alg_data->adapter.dev, "%s(): exiting, stat = %x\n", in i2c_pnx_xfer()
569 __func__, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_xfer()
589 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev); in i2c_pnx_controller_suspend() local
591 clk_disable_unprepare(alg_data->clk); in i2c_pnx_controller_suspend()
598 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev); in i2c_pnx_controller_resume() local
600 return clk_prepare_enable(alg_data->clk); in i2c_pnx_controller_resume()
611 struct i2c_pnx_algo_data *alg_data; in i2c_pnx_probe() local
616 alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL); in i2c_pnx_probe()
617 if (!alg_data) in i2c_pnx_probe()
620 platform_set_drvdata(pdev, alg_data); in i2c_pnx_probe()
622 alg_data->adapter.dev.parent = &pdev->dev; in i2c_pnx_probe()
623 alg_data->adapter.algo = &pnx_algorithm; in i2c_pnx_probe()
624 alg_data->adapter.algo_data = alg_data; in i2c_pnx_probe()
625 alg_data->adapter.nr = pdev->id; in i2c_pnx_probe()
627 alg_data->timeout = msecs_to_jiffies(I2C_PNX_TIMEOUT_DEFAULT); in i2c_pnx_probe()
628 if (alg_data->timeout <= 1) in i2c_pnx_probe()
629 alg_data->timeout = 2; in i2c_pnx_probe()
632 alg_data->adapter.dev.of_node = of_node_get(pdev->dev.of_node); in i2c_pnx_probe()
646 alg_data->clk = devm_clk_get(&pdev->dev, NULL); in i2c_pnx_probe()
647 if (IS_ERR(alg_data->clk)) in i2c_pnx_probe()
648 return PTR_ERR(alg_data->clk); in i2c_pnx_probe()
650 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name), in i2c_pnx_probe()
654 alg_data->ioaddr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in i2c_pnx_probe()
655 if (IS_ERR(alg_data->ioaddr)) in i2c_pnx_probe()
656 return PTR_ERR(alg_data->ioaddr); in i2c_pnx_probe()
658 ret = clk_prepare_enable(alg_data->clk); in i2c_pnx_probe()
662 freq = clk_get_rate(alg_data->clk); in i2c_pnx_probe()
678 iowrite32(tmp, I2C_REG_CKH(alg_data)); in i2c_pnx_probe()
679 iowrite32(tmp, I2C_REG_CKL(alg_data)); in i2c_pnx_probe()
681 iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data)); in i2c_pnx_probe()
682 if (wait_reset(alg_data)) { in i2c_pnx_probe()
686 init_completion(&alg_data->mif.complete); in i2c_pnx_probe()
688 alg_data->irq = platform_get_irq(pdev, 0); in i2c_pnx_probe()
689 if (alg_data->irq < 0) { in i2c_pnx_probe()
690 ret = alg_data->irq; in i2c_pnx_probe()
693 ret = devm_request_irq(&pdev->dev, alg_data->irq, i2c_pnx_interrupt, in i2c_pnx_probe()
694 0, pdev->name, alg_data); in i2c_pnx_probe()
699 ret = i2c_add_numbered_adapter(&alg_data->adapter); in i2c_pnx_probe()
704 alg_data->adapter.name, &res->start, alg_data->irq); in i2c_pnx_probe()
709 clk_disable_unprepare(alg_data->clk); in i2c_pnx_probe()
715 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); in i2c_pnx_remove() local
717 i2c_del_adapter(&alg_data->adapter); in i2c_pnx_remove()
718 clk_disable_unprepare(alg_data->clk); in i2c_pnx_remove()