Lines Matching +full:pnx +full:- +full:i2c
2 * Provides I2C support for Philips PNX010x/PNX4008 boards.
7 * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under
17 #include <linux/i2c.h>
82 #define I2C_REG_RX(a) ((a)->ioaddr) /* Rx FIFO reg (RO) */
83 #define I2C_REG_TX(a) ((a)->ioaddr) /* Tx FIFO reg (WO) */
84 #define I2C_REG_STS(a) ((a)->ioaddr + 0x04) /* Status reg (RO) */
85 #define I2C_REG_CTL(a) ((a)->ioaddr + 0x08) /* Ctl reg */
86 #define I2C_REG_CKL(a) ((a)->ioaddr + 0x0c) /* Clock divider low */
87 #define I2C_REG_CKH(a) ((a)->ioaddr + 0x10) /* Clock divider high */
88 #define I2C_REG_ADR(a) ((a)->ioaddr + 0x14) /* I2C address */
89 #define I2C_REG_RFL(a) ((a)->ioaddr + 0x18) /* Rx FIFO level (RO) */
90 #define I2C_REG_TFL(a) ((a)->ioaddr + 0x1c) /* Tx FIFO level (RO) */
91 #define I2C_REG_RXB(a) ((a)->ioaddr + 0x20) /* Num of bytes Rx-ed (RO) */
92 #define I2C_REG_TXB(a) ((a)->ioaddr + 0x24) /* Num of bytes Tx-ed (RO) */
93 #define I2C_REG_TXS(a) ((a)->ioaddr + 0x28) /* Tx slave FIFO (RO) */
94 #define I2C_REG_STFL(a) ((a)->ioaddr + 0x2c) /* Tx slave FIFO level (RO) */
98 long timeout = jiffies_to_msecs(data->timeout); in wait_timeout()
102 timeout--; in wait_timeout()
109 long timeout = jiffies_to_msecs(data->timeout); in wait_reset()
113 timeout--; in wait_reset()
119 * i2c_pnx_start - start a device
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()
134 "%s: Invalid slave address %x. Only 7-bit addresses are supported\n", in i2c_pnx_start()
135 alg_data->adapter.name, slave_addr); in i2c_pnx_start()
136 return -EINVAL; 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()
147 return -EBUSY; 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()
153 return -EIO; in i2c_pnx_start()
157 * OK, I2C is enabled and we have the bus. 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()
170 dev_dbg(&alg_data->adapter.dev, "%s(): exit\n", __func__); in i2c_pnx_start()
176 * i2c_pnx_stop - stop a device
186 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", in i2c_pnx_stop()
197 timeout--; in i2c_pnx_stop()
200 dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", in i2c_pnx_stop()
205 * i2c_pnx_master_xmit - transmit data to slave
214 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", 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()
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()
234 dev_err(&alg_data->adapter.dev, 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()
249 /* zero-sized transfer */ in i2c_pnx_master_xmit()
257 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_master_xmit()
258 "%s(): Waking up xfer routine after zero-xfer.\n", 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()
271 * i2c_pnx_master_rcv - receive data from slave
281 dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", 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()
294 "%s(): Write dummy data to fill Rx-fifo...\n", in i2c_pnx_master_rcv()
297 if (alg_data->mif.order == 1) { in i2c_pnx_master_rcv()
314 * write a (dummy) byte to the Tx-FIFO. 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()
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()
334 dev_err(&alg_data->adapter.dev, 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()
358 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
363 alg_data->mif.mode); in i2c_pnx_interrupt()
369 alg_data->mif.ret = -EIO; 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()
392 alg_data->mif.ret = -EIO; in i2c_pnx_interrupt()
394 complete(&alg_data->mif.complete); in i2c_pnx_interrupt()
398 * - Master Tx needs data. in i2c_pnx_interrupt()
399 * - There is data in the Rx-fifo in i2c_pnx_interrupt()
406 if (alg_data->mif.mode == I2C_SMBUS_WRITE) { in i2c_pnx_interrupt()
408 } else if (alg_data->mif.mode == I2C_SMBUS_READ) { in i2c_pnx_interrupt()
418 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_interrupt()
430 dev_err(&alg_data->adapter.dev, in i2c_pnx_timeout()
443 alg_data->mif.ret = -EIO; in i2c_pnx_timeout()
451 dev_err(&alg_data->adapter.dev, in bus_reset_if_active()
453 alg_data->adapter.name); in bus_reset_if_active()
472 * i2c_pnx_xfer - generic transfer entry point
473 * @adap: pointer to I2C adapter structure
484 struct i2c_pnx_algo_data *alg_data = adap->algo_data; in i2c_pnx_xfer()
488 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
499 addr = pmsg->addr; in i2c_pnx_xfer()
501 if (pmsg->flags & I2C_M_TEN) { in i2c_pnx_xfer()
502 dev_err(&alg_data->adapter.dev, in i2c_pnx_xfer()
504 alg_data->adapter.name); in i2c_pnx_xfer()
505 rc = -EINVAL; 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()
529 /* Put start-code and slave-address on the bus. */ 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()
540 if (!(rc = alg_data->mif.ret)) in i2c_pnx_xfer()
542 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
548 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
550 alg_data->adapter.name); in i2c_pnx_xfer()
554 dev_dbg(&alg_data->adapter.dev, in i2c_pnx_xfer()
556 alg_data->adapter.name); 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()
572 return ((rc < 0) ? rc : -EREMOTEIO); in i2c_pnx_xfer()
591 clk_disable_unprepare(alg_data->clk); in i2c_pnx_controller_suspend()
600 return clk_prepare_enable(alg_data->clk); in i2c_pnx_controller_resume()
616 alg_data = devm_kzalloc(&pdev->dev, sizeof(*alg_data), GFP_KERNEL); in i2c_pnx_probe()
618 return -ENOMEM; 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()
633 if (pdev->dev.of_node) { in i2c_pnx_probe()
634 of_property_read_u32(pdev->dev.of_node, "clock-frequency", in i2c_pnx_probe()
641 * of_property_read_u32(pdev->dev.of_node, "timeout", in i2c_pnx_probe()
642 * &alg_data->timeout); 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()
651 "%s", pdev->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()
669 * set to 0.5*(f_sys/f_i2c)-2=0.5*(20e6/100e3)-2=98. The actual value in i2c_pnx_probe()
675 tmp = (freq / speed) / 2 - 2; in i2c_pnx_probe()
683 ret = -ENODEV; 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()
698 /* Register this adapter with the I2C subsystem */ in i2c_pnx_probe()
699 ret = i2c_add_numbered_adapter(&alg_data->adapter); in i2c_pnx_probe()
703 dev_dbg(&pdev->dev, "%s: Master at %pap, irq %d.\n", 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()
717 i2c_del_adapter(&alg_data->adapter); in i2c_pnx_remove()
718 clk_disable_unprepare(alg_data->clk); in i2c_pnx_remove()
723 { .compatible = "nxp,pnx-i2c" },
731 .name = "pnx-i2c",
751 MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses");
753 MODULE_ALIAS("platform:pnx-i2c");
755 /* We need to make sure I2C is initialized before USB */