Lines Matching refs:i2c_imx
301 static inline int is_imx1_i2c(struct imx_i2c_struct *i2c_imx) in is_imx1_i2c() argument
303 return i2c_imx->hwdata->devtype == IMX1_I2C; in is_imx1_i2c()
306 static inline int is_vf610_i2c(struct imx_i2c_struct *i2c_imx) in is_vf610_i2c() argument
308 return i2c_imx->hwdata->devtype == VF610_I2C; in is_vf610_i2c()
312 struct imx_i2c_struct *i2c_imx, unsigned int reg) in imx_i2c_write_reg() argument
314 writeb(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); in imx_i2c_write_reg()
317 static inline unsigned char imx_i2c_read_reg(struct imx_i2c_struct *i2c_imx, in imx_i2c_read_reg() argument
320 return readb(i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); in imx_i2c_read_reg()
323 static void i2c_imx_clear_irq(struct imx_i2c_struct *i2c_imx, unsigned int bits) in i2c_imx_clear_irq() argument
332 temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ bits; in i2c_imx_clear_irq()
333 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR); in i2c_imx_clear_irq()
337 static void i2c_imx_reset_regs(struct imx_i2c_struct *i2c_imx) in i2c_imx_reset_regs() argument
339 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, in i2c_imx_reset_regs()
340 i2c_imx, IMX_I2C_I2CR); in i2c_imx_reset_regs()
341 i2c_imx_clear_irq(i2c_imx, I2SR_IIF | I2SR_IAL); in i2c_imx_reset_regs()
345 static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, in i2c_imx_dma_request() argument
350 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_request()
366 (IMX_I2C_I2DR << i2c_imx->hwdata->regshift); in i2c_imx_dma_request()
385 (IMX_I2C_I2DR << i2c_imx->hwdata->regshift); in i2c_imx_dma_request()
395 i2c_imx->dma = dma; in i2c_imx_dma_request()
412 struct imx_i2c_struct *i2c_imx = (struct imx_i2c_struct *)arg; in i2c_imx_dma_callback() local
413 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_callback()
420 static int i2c_imx_dma_xfer(struct imx_i2c_struct *i2c_imx, in i2c_imx_dma_xfer() argument
423 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_xfer()
425 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_xfer()
445 txdesc->callback_param = i2c_imx; in i2c_imx_dma_xfer()
463 static void i2c_imx_dma_free(struct imx_i2c_struct *i2c_imx) in i2c_imx_dma_free() argument
465 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_free()
479 static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool atomic) in i2c_imx_bus_busy() argument
485 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); in i2c_imx_bus_busy()
489 i2c_imx_clear_irq(i2c_imx, I2SR_IAL); in i2c_imx_bus_busy()
494 i2c_imx->stopped = 0; in i2c_imx_bus_busy()
498 i2c_imx->stopped = 1; in i2c_imx_bus_busy()
502 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_bus_busy()
515 static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic) in i2c_imx_trx_complete() argument
518 void __iomem *addr = i2c_imx->base + (IMX_I2C_I2SR << i2c_imx->hwdata->regshift); in i2c_imx_trx_complete()
532 i2c_imx->i2csr = regval; in i2c_imx_trx_complete()
533 i2c_imx_clear_irq(i2c_imx, I2SR_IIF | I2SR_IAL); in i2c_imx_trx_complete()
535 wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10); in i2c_imx_trx_complete()
538 if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) { in i2c_imx_trx_complete()
539 dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__); in i2c_imx_trx_complete()
544 if (i2c_imx->i2csr & I2SR_IAL) { in i2c_imx_trx_complete()
545 dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__); in i2c_imx_trx_complete()
546 i2c_imx_clear_irq(i2c_imx, I2SR_IAL); in i2c_imx_trx_complete()
548 i2c_imx->i2csr = 0; in i2c_imx_trx_complete()
552 dev_dbg(&i2c_imx->adapter.dev, "<%s> TRX complete\n", __func__); in i2c_imx_trx_complete()
553 i2c_imx->i2csr = 0; in i2c_imx_trx_complete()
557 static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx) in i2c_imx_acked() argument
559 if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) { in i2c_imx_acked()
560 dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__); in i2c_imx_acked()
564 dev_dbg(&i2c_imx->adapter.dev, "<%s> ACK received\n", __func__); in i2c_imx_acked()
568 static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, in i2c_imx_set_clk() argument
571 struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; in i2c_imx_set_clk()
575 if (i2c_imx->hwdata->has_err007805 && i2c_imx->bitrate > 384000) { in i2c_imx_set_clk()
576 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_set_clk()
578 i2c_imx->bitrate); in i2c_imx_set_clk()
579 i2c_imx->bitrate = 384000; in i2c_imx_set_clk()
583 if (i2c_imx->cur_clk == i2c_clk_rate) in i2c_imx_set_clk()
586 i2c_imx->cur_clk = i2c_clk_rate; in i2c_imx_set_clk()
588 div = DIV_ROUND_UP(i2c_clk_rate, i2c_imx->bitrate); in i2c_imx_set_clk()
591 else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div) in i2c_imx_set_clk()
592 i = i2c_imx->hwdata->ndivs - 1; in i2c_imx_set_clk()
598 i2c_imx->ifdr = i2c_clk_div[i].val; in i2c_imx_set_clk()
606 i2c_imx->disable_delay = DIV_ROUND_UP(500000U * i2c_clk_div[i].div, in i2c_imx_set_clk()
610 dev_dbg(&i2c_imx->adapter.dev, "I2C_CLK=%d, REQ DIV=%d\n", in i2c_imx_set_clk()
612 dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n", in i2c_imx_set_clk()
621 struct imx_i2c_struct *i2c_imx = container_of(nb, in i2c_imx_clk_notifier_call() local
626 i2c_imx_set_clk(i2c_imx, ndata->new_rate); in i2c_imx_clk_notifier_call()
631 static int i2c_imx_start(struct imx_i2c_struct *i2c_imx, bool atomic) in i2c_imx_start() argument
636 imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR); in i2c_imx_start()
638 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); in i2c_imx_start()
639 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode, i2c_imx, IMX_I2C_I2CR); in i2c_imx_start()
648 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_start()
650 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_start()
651 result = i2c_imx_bus_busy(i2c_imx, 1, atomic); in i2c_imx_start()
660 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_start()
664 static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx, bool atomic) in i2c_imx_stop() argument
668 if (!i2c_imx->stopped) { in i2c_imx_stop()
670 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_stop()
672 i2c_imx->stopped = 1; in i2c_imx_stop()
674 if (i2c_imx->dma) in i2c_imx_stop()
676 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_stop()
678 if (is_imx1_i2c(i2c_imx)) { in i2c_imx_stop()
683 udelay(i2c_imx->disable_delay); in i2c_imx_stop()
686 if (!i2c_imx->stopped) in i2c_imx_stop()
687 i2c_imx_bus_busy(i2c_imx, 0, atomic); in i2c_imx_stop()
690 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN; in i2c_imx_stop()
691 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_stop()
699 static void i2c_imx_enable_bus_idle(struct imx_i2c_struct *i2c_imx) in i2c_imx_enable_bus_idle() argument
701 if (is_vf610_i2c(i2c_imx)) { in i2c_imx_enable_bus_idle()
704 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_IBIC); in i2c_imx_enable_bus_idle()
706 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_IBIC); in i2c_imx_enable_bus_idle()
710 static void i2c_imx_slave_event(struct imx_i2c_struct *i2c_imx, in i2c_imx_slave_event() argument
713 i2c_slave_event(i2c_imx->slave, event, val); in i2c_imx_slave_event()
714 i2c_imx->last_slave_event = event; in i2c_imx_slave_event()
717 static void i2c_imx_slave_finish_op(struct imx_i2c_struct *i2c_imx) in i2c_imx_slave_finish_op() argument
721 while (i2c_imx->last_slave_event != I2C_SLAVE_STOP) { in i2c_imx_slave_finish_op()
722 switch (i2c_imx->last_slave_event) { in i2c_imx_slave_finish_op()
724 i2c_imx_slave_event(i2c_imx, I2C_SLAVE_READ_PROCESSED, in i2c_imx_slave_finish_op()
731 i2c_imx_slave_event(i2c_imx, I2C_SLAVE_STOP, &val); in i2c_imx_slave_finish_op()
741 static irqreturn_t i2c_imx_slave_handle(struct imx_i2c_struct *i2c_imx, in i2c_imx_slave_handle() argument
747 i2c_imx_clear_irq(i2c_imx, I2SR_IAL); in i2c_imx_slave_handle()
754 i2c_imx_slave_finish_op(i2c_imx); in i2c_imx_slave_handle()
763 i2c_imx_slave_finish_op(i2c_imx); in i2c_imx_slave_handle()
765 dev_dbg(&i2c_imx->adapter.dev, "read requested"); in i2c_imx_slave_handle()
766 i2c_imx_slave_event(i2c_imx, in i2c_imx_slave_handle()
771 imx_i2c_write_reg(ctl, i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_handle()
774 imx_i2c_write_reg(value, i2c_imx, IMX_I2C_I2DR); in i2c_imx_slave_handle()
776 dev_dbg(&i2c_imx->adapter.dev, "write requested"); in i2c_imx_slave_handle()
777 i2c_imx_slave_event(i2c_imx, in i2c_imx_slave_handle()
782 imx_i2c_write_reg(ctl, i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_handle()
784 imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_slave_handle()
787 value = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_slave_handle()
788 i2c_imx_slave_event(i2c_imx, in i2c_imx_slave_handle()
792 imx_i2c_write_reg(ctl, i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_handle()
794 i2c_imx_slave_event(i2c_imx, in i2c_imx_slave_handle()
797 imx_i2c_write_reg(value, i2c_imx, IMX_I2C_I2DR); in i2c_imx_slave_handle()
800 imx_i2c_write_reg(ctl, i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_handle()
801 imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_slave_handle()
804 i2c_imx_slave_event(i2c_imx, in i2c_imx_slave_handle()
807 i2c_imx_slave_finish_op(i2c_imx); in i2c_imx_slave_handle()
819 hrtimer_try_to_cancel(&i2c_imx->slave_timer); in i2c_imx_slave_handle()
820 hrtimer_forward_now(&i2c_imx->slave_timer, I2C_IMX_CHECK_DELAY); in i2c_imx_slave_handle()
821 hrtimer_restart(&i2c_imx->slave_timer); in i2c_imx_slave_handle()
827 struct imx_i2c_struct *i2c_imx = container_of(t, struct imx_i2c_struct, in i2c_imx_slave_timeout() local
832 spin_lock_irqsave(&i2c_imx->slave_lock, flags); in i2c_imx_slave_timeout()
833 status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); in i2c_imx_slave_timeout()
834 ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_timeout()
835 i2c_imx_slave_handle(i2c_imx, status, ctl); in i2c_imx_slave_timeout()
836 spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); in i2c_imx_slave_timeout()
840 static void i2c_imx_slave_init(struct imx_i2c_struct *i2c_imx) in i2c_imx_slave_init() argument
845 imx_i2c_write_reg((i2c_imx->slave->addr << 1), i2c_imx, IMX_I2C_IADR); in i2c_imx_slave_init()
847 i2c_imx_reset_regs(i2c_imx); in i2c_imx_slave_init()
850 temp = i2c_imx->hwdata->i2cr_ien_opcode; in i2c_imx_slave_init()
851 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_init()
855 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_slave_init()
857 i2c_imx_enable_bus_idle(i2c_imx); in i2c_imx_slave_init()
862 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(client->adapter); in i2c_imx_reg_slave() local
865 if (i2c_imx->slave) in i2c_imx_reg_slave()
868 i2c_imx->slave = client; in i2c_imx_reg_slave()
869 i2c_imx->last_slave_event = I2C_SLAVE_STOP; in i2c_imx_reg_slave()
872 ret = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); in i2c_imx_reg_slave()
874 dev_err(&i2c_imx->adapter.dev, "failed to resume i2c controller"); in i2c_imx_reg_slave()
878 i2c_imx_slave_init(i2c_imx); in i2c_imx_reg_slave()
885 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(client->adapter); in i2c_imx_unreg_slave() local
888 if (!i2c_imx->slave) in i2c_imx_unreg_slave()
892 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR); in i2c_imx_unreg_slave()
894 i2c_imx_reset_regs(i2c_imx); in i2c_imx_unreg_slave()
896 i2c_imx->slave = NULL; in i2c_imx_unreg_slave()
899 ret = pm_runtime_put_sync(i2c_imx->adapter.dev.parent); in i2c_imx_unreg_slave()
901 dev_err(&i2c_imx->adapter.dev, "failed to suspend i2c controller"); in i2c_imx_unreg_slave()
906 static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned int status) in i2c_imx_master_isr() argument
909 i2c_imx->i2csr = status; in i2c_imx_master_isr()
910 wake_up(&i2c_imx->queue); in i2c_imx_master_isr()
917 struct imx_i2c_struct *i2c_imx = dev_id; in i2c_imx_isr() local
921 spin_lock_irqsave(&i2c_imx->slave_lock, flags); in i2c_imx_isr()
922 status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); in i2c_imx_isr()
923 ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_isr()
926 i2c_imx_clear_irq(i2c_imx, I2SR_IIF); in i2c_imx_isr()
927 if (i2c_imx->slave) { in i2c_imx_isr()
931 ret = i2c_imx_slave_handle(i2c_imx, in i2c_imx_isr()
933 spin_unlock_irqrestore(&i2c_imx->slave_lock, in i2c_imx_isr()
937 i2c_imx_slave_finish_op(i2c_imx); in i2c_imx_isr()
939 spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); in i2c_imx_isr()
940 return i2c_imx_master_isr(i2c_imx, status); in i2c_imx_isr()
942 spin_unlock_irqrestore(&i2c_imx->slave_lock, flags); in i2c_imx_isr()
947 static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx, in i2c_imx_dma_write() argument
954 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_write()
955 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_write()
961 result = i2c_imx_dma_xfer(i2c_imx, msgs); in i2c_imx_dma_write()
965 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_write()
967 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_write()
973 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_write()
975 &i2c_imx->dma->cmd_complete, in i2c_imx_dma_write()
984 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); in i2c_imx_dma_write()
995 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_write()
997 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_write()
1001 i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_write()
1002 result = i2c_imx_trx_complete(i2c_imx, false); in i2c_imx_dma_write()
1006 return i2c_imx_acked(i2c_imx); in i2c_imx_dma_write()
1009 static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, in i2c_imx_dma_read() argument
1016 struct imx_i2c_dma *dma = i2c_imx->dma; in i2c_imx_dma_read()
1017 struct device *dev = &i2c_imx->adapter.dev; in i2c_imx_dma_read()
1025 result = i2c_imx_dma_xfer(i2c_imx, msgs); in i2c_imx_dma_read()
1030 &i2c_imx->dma->cmd_complete, in i2c_imx_dma_read()
1039 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); in i2c_imx_dma_read()
1050 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1052 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1055 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1057 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1059 msgs->buf[msgs->len-2] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_read()
1061 result = i2c_imx_trx_complete(i2c_imx, false); in i2c_imx_dma_read()
1071 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1073 i2c_imx->stopped = 1; in i2c_imx_dma_read()
1075 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1076 if (!i2c_imx->stopped) in i2c_imx_dma_read()
1077 i2c_imx_bus_busy(i2c_imx, 0, false); in i2c_imx_dma_read()
1086 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1088 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_dma_read()
1090 msgs->buf[msgs->len-1] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_dma_read()
1095 static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, in i2c_imx_write() argument
1100 dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", in i2c_imx_write()
1104 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); in i2c_imx_write()
1105 result = i2c_imx_trx_complete(i2c_imx, atomic); in i2c_imx_write()
1108 result = i2c_imx_acked(i2c_imx); in i2c_imx_write()
1111 dev_dbg(&i2c_imx->adapter.dev, "<%s> write data\n", __func__); in i2c_imx_write()
1115 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_write()
1118 imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR); in i2c_imx_write()
1119 result = i2c_imx_trx_complete(i2c_imx, atomic); in i2c_imx_write()
1122 result = i2c_imx_acked(i2c_imx); in i2c_imx_write()
1129 static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, in i2c_imx_read() argument
1135 int use_dma = i2c_imx->dma && msgs->flags & I2C_M_DMA_SAFE && in i2c_imx_read()
1138 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1143 imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); in i2c_imx_read()
1144 result = i2c_imx_trx_complete(i2c_imx, atomic); in i2c_imx_read()
1147 result = i2c_imx_acked(i2c_imx); in i2c_imx_read()
1151 dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); in i2c_imx_read()
1154 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1165 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1166 imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ in i2c_imx_read()
1168 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); in i2c_imx_read()
1171 return i2c_imx_dma_read(i2c_imx, msgs, is_lastmsg); in i2c_imx_read()
1177 result = i2c_imx_trx_complete(i2c_imx, atomic); in i2c_imx_read()
1186 len = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_read()
1189 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1200 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1202 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1204 i2c_imx->stopped = 1; in i2c_imx_read()
1206 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1207 if (!i2c_imx->stopped) in i2c_imx_read()
1208 i2c_imx_bus_busy(i2c_imx, 0, atomic); in i2c_imx_read()
1217 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1219 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1222 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1224 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1226 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_read()
1231 msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); in i2c_imx_read()
1232 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_read()
1245 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); in i2c_imx_xfer_common() local
1248 result = i2c_imx_start(i2c_imx, atomic); in i2c_imx_xfer_common()
1254 if (!atomic && i2c_imx->adapter.bus_recovery_info) { in i2c_imx_xfer_common()
1255 i2c_recover_bus(&i2c_imx->adapter); in i2c_imx_xfer_common()
1256 result = i2c_imx_start(i2c_imx, atomic); in i2c_imx_xfer_common()
1269 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1271 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_xfer_common()
1273 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); in i2c_imx_xfer_common()
1274 result = i2c_imx_bus_busy(i2c_imx, 1, atomic); in i2c_imx_xfer_common()
1278 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1282 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); in i2c_imx_xfer_common()
1283 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1289 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); in i2c_imx_xfer_common()
1290 dev_dbg(&i2c_imx->adapter.dev, in i2c_imx_xfer_common()
1299 result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, atomic); in i2c_imx_xfer_common()
1302 i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD && in i2c_imx_xfer_common()
1304 result = i2c_imx_dma_write(i2c_imx, &msgs[i]); in i2c_imx_xfer_common()
1306 result = i2c_imx_write(i2c_imx, &msgs[i], atomic); in i2c_imx_xfer_common()
1314 i2c_imx_stop(i2c_imx, atomic); in i2c_imx_xfer_common()
1316 dev_dbg(&i2c_imx->adapter.dev, "<%s> exit with: %s: %d\n", __func__, in i2c_imx_xfer_common()
1320 if (i2c_imx->slave) in i2c_imx_xfer_common()
1321 i2c_imx_slave_init(i2c_imx); in i2c_imx_xfer_common()
1329 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); in i2c_imx_xfer() local
1332 result = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1338 pm_runtime_mark_last_busy(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1339 pm_runtime_put_autosuspend(i2c_imx->adapter.dev.parent); in i2c_imx_xfer()
1347 struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); in i2c_imx_xfer_atomic() local
1350 result = clk_enable(i2c_imx->clk); in i2c_imx_xfer_atomic()
1356 clk_disable(i2c_imx->clk); in i2c_imx_xfer_atomic()
1368 static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, in i2c_imx_init_recovery_info() argument
1371 struct i2c_bus_recovery_info *bri = &i2c_imx->rinfo; in i2c_imx_init_recovery_info()
1377 i2c_imx->adapter.bus_recovery_info = bri; in i2c_imx_init_recovery_info()
1398 struct imx_i2c_struct *i2c_imx; in i2c_imx_probe() local
1415 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(*i2c_imx), GFP_KERNEL); in i2c_imx_probe()
1416 if (!i2c_imx) in i2c_imx_probe()
1419 spin_lock_init(&i2c_imx->slave_lock); in i2c_imx_probe()
1420 hrtimer_init(&i2c_imx->slave_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in i2c_imx_probe()
1421 i2c_imx->slave_timer.function = i2c_imx_slave_timeout; in i2c_imx_probe()
1425 i2c_imx->hwdata = match; in i2c_imx_probe()
1427 i2c_imx->hwdata = (struct imx_i2c_hwdata *) in i2c_imx_probe()
1431 strscpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name)); in i2c_imx_probe()
1432 i2c_imx->adapter.owner = THIS_MODULE; in i2c_imx_probe()
1433 i2c_imx->adapter.algo = &i2c_imx_algo; in i2c_imx_probe()
1434 i2c_imx->adapter.dev.parent = &pdev->dev; in i2c_imx_probe()
1435 i2c_imx->adapter.nr = pdev->id; in i2c_imx_probe()
1436 i2c_imx->adapter.dev.of_node = pdev->dev.of_node; in i2c_imx_probe()
1437 i2c_imx->base = base; in i2c_imx_probe()
1438 ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev)); in i2c_imx_probe()
1441 i2c_imx->clk = devm_clk_get_enabled(&pdev->dev, NULL); in i2c_imx_probe()
1442 if (IS_ERR(i2c_imx->clk)) in i2c_imx_probe()
1443 return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk), in i2c_imx_probe()
1447 init_waitqueue_head(&i2c_imx->queue); in i2c_imx_probe()
1450 i2c_set_adapdata(&i2c_imx->adapter, i2c_imx); in i2c_imx_probe()
1453 platform_set_drvdata(pdev, i2c_imx); in i2c_imx_probe()
1465 ret = request_irq(irq, i2c_imx_isr, IRQF_SHARED, pdev->name, i2c_imx); in i2c_imx_probe()
1472 i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; in i2c_imx_probe()
1474 "clock-frequency", &i2c_imx->bitrate); in i2c_imx_probe()
1476 i2c_imx->bitrate = pdata->bitrate; in i2c_imx_probe()
1477 i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call; in i2c_imx_probe()
1478 clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_probe()
1479 i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk)); in i2c_imx_probe()
1481 i2c_imx_reset_regs(i2c_imx); in i2c_imx_probe()
1484 ret = i2c_imx_init_recovery_info(i2c_imx, pdev); in i2c_imx_probe()
1490 ret = i2c_add_numbered_adapter(&i2c_imx->adapter); in i2c_imx_probe()
1497 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq); in i2c_imx_probe()
1498 dev_dbg(&i2c_imx->adapter.dev, "device resources: %pR\n", res); in i2c_imx_probe()
1499 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", in i2c_imx_probe()
1500 i2c_imx->adapter.name); in i2c_imx_probe()
1501 dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); in i2c_imx_probe()
1504 i2c_imx_dma_request(i2c_imx, phy_addr); in i2c_imx_probe()
1509 clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_probe()
1510 free_irq(irq, i2c_imx); in i2c_imx_probe()
1521 struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); in i2c_imx_remove() local
1526 hrtimer_cancel(&i2c_imx->slave_timer); in i2c_imx_remove()
1529 dev_dbg(&i2c_imx->adapter.dev, "adapter removed\n"); in i2c_imx_remove()
1530 i2c_del_adapter(&i2c_imx->adapter); in i2c_imx_remove()
1532 if (i2c_imx->dma) in i2c_imx_remove()
1533 i2c_imx_dma_free(i2c_imx); in i2c_imx_remove()
1537 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR); in i2c_imx_remove()
1538 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR); in i2c_imx_remove()
1539 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR); in i2c_imx_remove()
1540 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR); in i2c_imx_remove()
1543 clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); in i2c_imx_remove()
1546 free_irq(irq, i2c_imx); in i2c_imx_remove()
1554 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); in i2c_imx_runtime_suspend() local
1556 clk_disable(i2c_imx->clk); in i2c_imx_runtime_suspend()
1563 struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); in i2c_imx_runtime_resume() local
1566 ret = clk_enable(i2c_imx->clk); in i2c_imx_runtime_resume()