Lines Matching +full:num +full:- +full:transfer +full:- +full:bits

7  * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under
84 #define I2C_REG_RX(a) ((a)->ioaddr) /* Rx FIFO reg (RO) */
85 #define I2C_REG_TX(a) ((a)->ioaddr) /* Tx FIFO reg (WO) */
86 #define I2C_REG_STS(a) ((a)->ioaddr + 0x04) /* Status reg (RO) */
87 #define I2C_REG_CTL(a) ((a)->ioaddr + 0x08) /* Ctl reg */
88 #define I2C_REG_CKL(a) ((a)->ioaddr + 0x0c) /* Clock divider low */
89 #define I2C_REG_CKH(a) ((a)->ioaddr + 0x10) /* Clock divider high */
90 #define I2C_REG_ADR(a) ((a)->ioaddr + 0x14) /* I2C address */
91 #define I2C_REG_RFL(a) ((a)->ioaddr + 0x18) /* Rx FIFO level (RO) */
92 #define I2C_REG_TFL(a) ((a)->ioaddr + 0x1c) /* Tx FIFO level (RO) */
93 #define I2C_REG_RXB(a) ((a)->ioaddr + 0x20) /* Num of bytes Rx-ed (RO) */
94 #define I2C_REG_TXB(a) ((a)->ioaddr + 0x24) /* Num of bytes Tx-ed (RO) */
95 #define I2C_REG_TXS(a) ((a)->ioaddr + 0x28) /* Tx slave FIFO (RO) */
96 #define I2C_REG_STFL(a) ((a)->ioaddr + 0x2c) /* Tx slave FIFO level (RO) */
100 long timeout = data->timeout; in wait_timeout()
104 timeout--; in wait_timeout()
111 long timeout = data->timeout; in wait_reset()
115 timeout--; in wait_reset()
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()
133 timer->expires = jiffies + expires; in i2c_pnx_arm_timer()
139 * i2c_pnx_start - start a device
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()
154 "%s: Invalid slave address %x. Only 7-bit addresses are supported\n", in i2c_pnx_start()
155 alg_data->adapter.name, slave_addr); in i2c_pnx_start()
156 return -EINVAL; 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()
167 return -EBUSY; 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()
173 return -EIO; 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()
190 dev_dbg(&alg_data->adapter.dev, "%s(): exit\n", __func__); in i2c_pnx_start()
196 * i2c_pnx_stop - stop a device
206 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_stop()
217 timeout--; in i2c_pnx_stop()
220 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_stop()
225 * i2c_pnx_master_xmit - transmit data to slave
234 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", 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()
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()
254 dev_err(&alg_data->adapter.dev, 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()
271 /* zero-sized transfer */ 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()
282 "%s(): Waking up xfer routine after zero-xfer.\n", 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()
295 * i2c_pnx_master_rcv - receive data from slave
305 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", 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()
318 "%s(): Write dummy data to fill Rx-fifo...\n", in i2c_pnx_master_rcv()
321 if (alg_data->mif.order == 1) { in i2c_pnx_master_rcv()
338 * write a (dummy) byte to the Tx-FIFO. 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()
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()
358 dev_err(&alg_data->adapter.dev, 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()
384 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
389 alg_data->mif.mode); in i2c_pnx_interrupt()
394 /* We lost arbitration in the midst of a transfer */ in i2c_pnx_interrupt()
395 alg_data->mif.ret = -EIO; 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()
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()
428 * - Master Tx needs data. in i2c_pnx_interrupt()
429 * - There is data in the Rx-fifo in i2c_pnx_interrupt()
436 if (alg_data->mif.mode == I2C_SMBUS_WRITE) { in i2c_pnx_interrupt()
438 } else if (alg_data->mif.mode == I2C_SMBUS_READ) { in i2c_pnx_interrupt()
444 /* Clear TDI and AFI bits */ in i2c_pnx_interrupt()
448 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
461 dev_err(&alg_data->adapter.dev, in i2c_pnx_timeout()
474 alg_data->mif.ret = -EIO; in i2c_pnx_timeout()
475 complete(&alg_data->mif.complete); in i2c_pnx_timeout()
483 dev_err(&alg_data->adapter.dev, in bus_reset_if_active()
485 alg_data->adapter.name); in bus_reset_if_active()
490 /* If there is data in the fifo's after transfer, in bus_reset_if_active()
504 * i2c_pnx_xfer - generic transfer entry point
507 * @num: number of messages
509 * Initiates the transfer
512 i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) in i2c_pnx_xfer() argument
516 struct i2c_pnx_algo_data *alg_data = adap->algo_data; in i2c_pnx_xfer()
519 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
521 __func__, num, ioread32(I2C_REG_STS(alg_data))); in i2c_pnx_xfer()
526 for (i = 0; rc >= 0 && i < num; i++) { in i2c_pnx_xfer()
530 addr = pmsg->addr; in i2c_pnx_xfer()
532 if (pmsg->flags & I2C_M_TEN) { in i2c_pnx_xfer()
533 dev_err(&alg_data->adapter.dev, in i2c_pnx_xfer()
534 "%s: 10 bits addr not supported!\n", in i2c_pnx_xfer()
535 alg_data->adapter.name); in i2c_pnx_xfer()
536 rc = -EINVAL; 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()
554 init_completion(&alg_data->mif.complete); in i2c_pnx_xfer()
561 /* Put start-code and slave-address on the bus. */ 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()
575 /* Clear TDI and AFI bits in case they are set. */ in i2c_pnx_xfer()
577 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
579 alg_data->adapter.name); in i2c_pnx_xfer()
583 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
585 alg_data->adapter.name); 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()
600 if (completed != num) in i2c_pnx_xfer()
601 return ((rc < 0) ? rc : -EREMOTEIO); in i2c_pnx_xfer()
603 return num; in i2c_pnx_xfer()
621 clk_disable_unprepare(alg_data->clk); in i2c_pnx_controller_suspend()
630 return clk_prepare_enable(alg_data->clk); in i2c_pnx_controller_resume()
649 alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL); in i2c_pnx_probe()
651 return -ENOMEM; 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()
663 if (pdev->dev.of_node) { in i2c_pnx_probe()
664 of_property_read_u32(pdev->dev.of_node, "clock-frequency", in i2c_pnx_probe()
671 * of_property_read_u32(pdev->dev.of_node, "timeout", in i2c_pnx_probe()
672 * &alg_data->timeout); 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()
683 "%s", pdev->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()
702 * set to 0.5*(f_sys/f_i2c)-2=0.5*(20e6/100e3)-2=98. The actual value in i2c_pnx_probe()
708 tmp = (freq / speed) / 2 - 2; in i2c_pnx_probe()
716 ret = -ENODEV; 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()
723 ret = alg_data->irq; in i2c_pnx_probe()
726 ret = devm_request_irq(&pdev->dev, alg_data->irq, i2c_pnx_interrupt, in i2c_pnx_probe()
727 0, pdev->name, alg_data); in i2c_pnx_probe()
732 ret = i2c_add_numbered_adapter(&alg_data->adapter); in i2c_pnx_probe()
736 dev_dbg(&pdev->dev, "%s: Master at %pap, irq %d.\n", in i2c_pnx_probe()
737 alg_data->adapter.name, &res->start, alg_data->irq); in i2c_pnx_probe()
742 clk_disable_unprepare(alg_data->clk); in i2c_pnx_probe()
750 i2c_del_adapter(&alg_data->adapter); in i2c_pnx_remove()
751 clk_disable_unprepare(alg_data->clk); in i2c_pnx_remove()
758 { .compatible = "nxp,pnx-i2c" },
766 .name = "pnx-i2c",
786 MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses");
788 MODULE_ALIAS("platform:pnx-i2c");