Lines Matching refs:i2c

272 #define _IBMR(i2c)	((i2c)->reg_ibmr)  argument
273 #define _IDBR(i2c) ((i2c)->reg_idbr) argument
274 #define _ICR(i2c) ((i2c)->reg_icr) argument
275 #define _ISR(i2c) ((i2c)->reg_isr) argument
276 #define _ISAR(i2c) ((i2c)->reg_isar) argument
277 #define _ILCR(i2c) ((i2c)->reg_ilcr) argument
278 #define _IWCR(i2c) ((i2c)->reg_iwcr) argument
353 static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname) in i2c_pxa_show_state() argument
355 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno, in i2c_pxa_show_state()
356 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_show_state()
359 #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__) argument
361 static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) in i2c_pxa_scream_blue_murder() argument
364 struct device *dev = &i2c->adap.dev; in i2c_pxa_scream_blue_murder()
367 i2c->req_slave_addr >> 1, why); in i2c_pxa_scream_blue_murder()
369 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); in i2c_pxa_scream_blue_murder()
371 readl(_IBMR(i2c)), readl(_IDBR(i2c)), readl(_ICR(i2c)), in i2c_pxa_scream_blue_murder()
372 readl(_ISR(i2c))); in i2c_pxa_scream_blue_murder()
374 for (i = 0; i < i2c->irqlogidx; i++) in i2c_pxa_scream_blue_murder()
375 pr_cont(" [%03x:%05x]", i2c->isrlog[i], i2c->icrlog[i]); in i2c_pxa_scream_blue_murder()
383 #define show_state(i2c) do { } while (0) argument
386 #define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0) argument
390 static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
392 static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) in i2c_pxa_is_slavemode() argument
394 return !(readl(_ICR(i2c)) & ICR_SCLE); in i2c_pxa_is_slavemode()
397 static void i2c_pxa_abort(struct pxa_i2c *i2c) in i2c_pxa_abort() argument
401 if (i2c_pxa_is_slavemode(i2c)) { in i2c_pxa_abort()
402 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__); in i2c_pxa_abort()
406 while ((i > 0) && (readl(_IBMR(i2c)) & IBMR_SDAS) == 0) { in i2c_pxa_abort()
407 unsigned long icr = readl(_ICR(i2c)); in i2c_pxa_abort()
412 writel(icr, _ICR(i2c)); in i2c_pxa_abort()
414 show_state(i2c); in i2c_pxa_abort()
420 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP), in i2c_pxa_abort()
421 _ICR(i2c)); in i2c_pxa_abort()
424 static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c) in i2c_pxa_wait_bus_not_busy() argument
430 isr = readl(_ISR(i2c)); in i2c_pxa_wait_bus_not_busy()
441 show_state(i2c); in i2c_pxa_wait_bus_not_busy()
444 show_state(i2c); in i2c_pxa_wait_bus_not_busy()
449 static int i2c_pxa_wait_master(struct pxa_i2c *i2c) in i2c_pxa_wait_master() argument
455 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_wait_master()
456 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_wait_master()
458 if (readl(_ISR(i2c)) & ISR_SAD) { in i2c_pxa_wait_master()
460 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__); in i2c_pxa_wait_master()
468 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && in i2c_pxa_wait_master()
469 readl(_IBMR(i2c)) == (IBMR_SCLS | IBMR_SDAS)) { in i2c_pxa_wait_master()
471 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); in i2c_pxa_wait_master()
479 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__); in i2c_pxa_wait_master()
484 static int i2c_pxa_set_master(struct pxa_i2c *i2c) in i2c_pxa_set_master() argument
487 dev_dbg(&i2c->adap.dev, "setting to bus master\n"); in i2c_pxa_set_master()
489 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) { in i2c_pxa_set_master()
490 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__); in i2c_pxa_set_master()
491 if (!i2c_pxa_wait_master(i2c)) { in i2c_pxa_set_master()
492 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__); in i2c_pxa_set_master()
497 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c)); in i2c_pxa_set_master()
502 static int i2c_pxa_wait_slave(struct pxa_i2c *i2c) in i2c_pxa_wait_slave() argument
508 show_state(i2c); in i2c_pxa_wait_slave()
512 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_wait_slave()
513 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_wait_slave()
515 if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 || in i2c_pxa_wait_slave()
516 (readl(_ISR(i2c)) & ISR_SAD) != 0 || in i2c_pxa_wait_slave()
517 (readl(_ICR(i2c)) & ICR_SCLE) == 0) { in i2c_pxa_wait_slave()
519 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); in i2c_pxa_wait_slave()
527 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__); in i2c_pxa_wait_slave()
535 static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode) in i2c_pxa_set_slave() argument
537 show_state(i2c); in i2c_pxa_set_slave()
545 if (readl(_ICR(i2c)) & ICR_STOP) { in i2c_pxa_set_slave()
547 writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c)); in i2c_pxa_set_slave()
550 if (!i2c_pxa_wait_slave(i2c)) { in i2c_pxa_set_slave()
551 dev_err(&i2c->adap.dev, "%s: wait timedout\n", in i2c_pxa_set_slave()
557 writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c)); in i2c_pxa_set_slave()
558 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c)); in i2c_pxa_set_slave()
561 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c))); in i2c_pxa_set_slave()
562 decode_ICR(readl(_ICR(i2c))); in i2c_pxa_set_slave()
566 #define i2c_pxa_set_slave(i2c, err) do { } while (0) argument
569 static void i2c_pxa_do_reset(struct pxa_i2c *i2c) in i2c_pxa_do_reset() argument
572 writel(ICR_UR, _ICR(i2c)); in i2c_pxa_do_reset()
573 writel(I2C_ISR_INIT, _ISR(i2c)); in i2c_pxa_do_reset()
574 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c)); in i2c_pxa_do_reset()
576 if (i2c->reg_isar && IS_ENABLED(CONFIG_I2C_PXA_SLAVE)) in i2c_pxa_do_reset()
577 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_do_reset()
580 writel(I2C_ICR_INIT | (i2c->fast_mode ? i2c->fm_mask : 0), _ICR(i2c)); in i2c_pxa_do_reset()
581 writel(readl(_ICR(i2c)) | (i2c->high_mode ? i2c->hs_mask : 0), _ICR(i2c)); in i2c_pxa_do_reset()
584 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); in i2c_pxa_do_reset()
585 writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c)); in i2c_pxa_do_reset()
588 i2c_pxa_set_slave(i2c, 0); in i2c_pxa_do_reset()
591 static void i2c_pxa_enable(struct pxa_i2c *i2c) in i2c_pxa_enable() argument
594 writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c)); in i2c_pxa_enable()
598 static void i2c_pxa_reset(struct pxa_i2c *i2c) in i2c_pxa_reset() argument
603 i2c_pxa_abort(i2c); in i2c_pxa_reset()
604 i2c_pxa_do_reset(i2c); in i2c_pxa_reset()
605 i2c_pxa_enable(i2c); in i2c_pxa_reset()
614 static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_txempty() argument
621 if (i2c->slave != NULL) in i2c_pxa_slave_txempty()
622 i2c_slave_event(i2c->slave, I2C_SLAVE_READ_PROCESSED, in i2c_pxa_slave_txempty()
625 writel(byte, _IDBR(i2c)); in i2c_pxa_slave_txempty()
626 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */ in i2c_pxa_slave_txempty()
630 static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_rxfull() argument
632 u8 byte = readl(_IDBR(i2c)); in i2c_pxa_slave_rxfull()
634 if (i2c->slave != NULL) in i2c_pxa_slave_rxfull()
635 i2c_slave_event(i2c->slave, I2C_SLAVE_WRITE_RECEIVED, &byte); in i2c_pxa_slave_rxfull()
637 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); in i2c_pxa_slave_rxfull()
640 static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_start() argument
645 dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n", in i2c_pxa_slave_start()
648 if (i2c->slave != NULL) { in i2c_pxa_slave_start()
652 i2c_slave_event(i2c->slave, I2C_SLAVE_READ_REQUESTED, in i2c_pxa_slave_start()
654 writel(byte, _IDBR(i2c)); in i2c_pxa_slave_start()
656 i2c_slave_event(i2c->slave, I2C_SLAVE_WRITE_REQUESTED, in i2c_pxa_slave_start()
666 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c)); in i2c_pxa_slave_start()
667 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); in i2c_pxa_slave_start()
672 if ((readl(_IBMR(i2c)) & IBMR_SCLS) == IBMR_SCLS) in i2c_pxa_slave_start()
678 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n"); in i2c_pxa_slave_start()
683 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c)); in i2c_pxa_slave_start()
686 static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) in i2c_pxa_slave_stop() argument
689 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n"); in i2c_pxa_slave_stop()
691 if (i2c->slave != NULL) in i2c_pxa_slave_stop()
692 i2c_slave_event(i2c->slave, I2C_SLAVE_STOP, NULL); in i2c_pxa_slave_stop()
695 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n"); in i2c_pxa_slave_stop()
701 if (i2c->msg) in i2c_pxa_slave_stop()
702 i2c_pxa_master_complete(i2c, I2C_RETRY); in i2c_pxa_slave_stop()
707 struct pxa_i2c *i2c = slave->adapter->algo_data; in i2c_pxa_slave_reg() local
709 if (i2c->slave) in i2c_pxa_slave_reg()
712 if (!i2c->reg_isar) in i2c_pxa_slave_reg()
715 i2c->slave = slave; in i2c_pxa_slave_reg()
716 i2c->slave_addr = slave->addr; in i2c_pxa_slave_reg()
718 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_slave_reg()
725 struct pxa_i2c *i2c = slave->adapter->algo_data; in i2c_pxa_slave_unreg() local
727 WARN_ON(!i2c->slave); in i2c_pxa_slave_unreg()
729 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; in i2c_pxa_slave_unreg()
730 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_slave_unreg()
732 i2c->slave = NULL; in i2c_pxa_slave_unreg()
737 static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_txempty() argument
742 writel(0, _IDBR(i2c)); in i2c_pxa_slave_txempty()
743 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); in i2c_pxa_slave_txempty()
747 static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_rxfull() argument
749 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c)); in i2c_pxa_slave_rxfull()
752 static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_start() argument
761 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c)); in i2c_pxa_slave_start()
762 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c)); in i2c_pxa_slave_start()
767 if ((readl(_IBMR(i2c)) & IBMR_SCLS) == IBMR_SCLS) in i2c_pxa_slave_start()
773 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n"); in i2c_pxa_slave_start()
778 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c)); in i2c_pxa_slave_start()
781 static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) in i2c_pxa_slave_stop() argument
783 if (i2c->msg) in i2c_pxa_slave_stop()
784 i2c_pxa_master_complete(i2c, I2C_RETRY); in i2c_pxa_slave_stop()
792 static inline void i2c_pxa_start_message(struct pxa_i2c *i2c) in i2c_pxa_start_message() argument
799 i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg); in i2c_pxa_start_message()
800 writel(i2c->req_slave_addr, _IDBR(i2c)); in i2c_pxa_start_message()
805 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE); in i2c_pxa_start_message()
806 writel(icr | ICR_START | ICR_TB, _ICR(i2c)); in i2c_pxa_start_message()
809 static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c) in i2c_pxa_stop_message() argument
814 icr = readl(_ICR(i2c)); in i2c_pxa_stop_message()
816 writel(icr, _ICR(i2c)); in i2c_pxa_stop_message()
825 static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c) in i2c_pxa_send_mastercode() argument
830 spin_lock_irq(&i2c->lock); in i2c_pxa_send_mastercode()
831 i2c->highmode_enter = true; in i2c_pxa_send_mastercode()
832 writel(i2c->master_code, _IDBR(i2c)); in i2c_pxa_send_mastercode()
834 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE); in i2c_pxa_send_mastercode()
836 writel(icr, _ICR(i2c)); in i2c_pxa_send_mastercode()
838 spin_unlock_irq(&i2c->lock); in i2c_pxa_send_mastercode()
839 timeout = wait_event_timeout(i2c->wait, in i2c_pxa_send_mastercode()
840 i2c->highmode_enter == false, HZ * 1); in i2c_pxa_send_mastercode()
842 i2c->highmode_enter = false; in i2c_pxa_send_mastercode()
850 static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret) in i2c_pxa_master_complete() argument
852 i2c->msg_ptr = 0; in i2c_pxa_master_complete()
853 i2c->msg = NULL; in i2c_pxa_master_complete()
854 i2c->msg_idx ++; in i2c_pxa_master_complete()
855 i2c->msg_num = 0; in i2c_pxa_master_complete()
857 i2c->msg_idx = ret; in i2c_pxa_master_complete()
858 if (!i2c->use_pio) in i2c_pxa_master_complete()
859 wake_up(&i2c->wait); in i2c_pxa_master_complete()
862 static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_irq_txempty() argument
864 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); in i2c_pxa_irq_txempty()
875 i2c_pxa_scream_blue_murder(i2c, "ALD set"); in i2c_pxa_irq_txempty()
887 (!((i2c->msg->flags & I2C_M_IGNORE_NAK) && in i2c_pxa_irq_txempty()
897 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0) in i2c_pxa_irq_txempty()
902 i2c_pxa_master_complete(i2c, ret); in i2c_pxa_irq_txempty()
908 if (i2c->msg_ptr == i2c->msg->len - 1 && in i2c_pxa_irq_txempty()
909 i2c->msg_idx == i2c->msg_num - 1) in i2c_pxa_irq_txempty()
913 } else if (i2c->msg_ptr < i2c->msg->len) { in i2c_pxa_irq_txempty()
917 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c)); in i2c_pxa_irq_txempty()
925 if ((i2c->msg_ptr == i2c->msg->len) && in i2c_pxa_irq_txempty()
926 ((i2c->msg->flags & I2C_M_STOP) || in i2c_pxa_irq_txempty()
927 (i2c->msg_idx == i2c->msg_num - 1))) in i2c_pxa_irq_txempty()
930 } else if (i2c->msg_idx < i2c->msg_num - 1) { in i2c_pxa_irq_txempty()
934 i2c->msg_ptr = 0; in i2c_pxa_irq_txempty()
935 i2c->msg_idx ++; in i2c_pxa_irq_txempty()
936 i2c->msg++; in i2c_pxa_irq_txempty()
943 if (i2c->msg->flags & I2C_M_NOSTART) in i2c_pxa_irq_txempty()
949 i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg); in i2c_pxa_irq_txempty()
950 writel(i2c->req_slave_addr, _IDBR(i2c)); in i2c_pxa_irq_txempty()
958 if (i2c->msg->len == 0) in i2c_pxa_irq_txempty()
960 i2c_pxa_master_complete(i2c, 0); in i2c_pxa_irq_txempty()
963 i2c->icrlog[i2c->irqlogidx-1] = icr; in i2c_pxa_irq_txempty()
965 writel(icr, _ICR(i2c)); in i2c_pxa_irq_txempty()
966 show_state(i2c); in i2c_pxa_irq_txempty()
969 static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_irq_rxfull() argument
971 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); in i2c_pxa_irq_rxfull()
976 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c)); in i2c_pxa_irq_rxfull()
978 if (i2c->msg_ptr < i2c->msg->len) { in i2c_pxa_irq_rxfull()
983 if (i2c->msg_ptr == i2c->msg->len - 1) in i2c_pxa_irq_rxfull()
988 i2c_pxa_master_complete(i2c, 0); in i2c_pxa_irq_rxfull()
991 i2c->icrlog[i2c->irqlogidx-1] = icr; in i2c_pxa_irq_rxfull()
993 writel(icr, _ICR(i2c)); in i2c_pxa_irq_rxfull()
1000 struct pxa_i2c *i2c = dev_id; in i2c_pxa_handler() local
1001 u32 isr = readl(_ISR(i2c)); in i2c_pxa_handler()
1007 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_handler()
1008 __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_handler()
1012 if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog)) in i2c_pxa_handler()
1013 i2c->isrlog[i2c->irqlogidx++] = isr; in i2c_pxa_handler()
1015 show_state(i2c); in i2c_pxa_handler()
1020 writel(isr & VALID_INT_SOURCE, _ISR(i2c)); in i2c_pxa_handler()
1023 i2c_pxa_slave_start(i2c, isr); in i2c_pxa_handler()
1025 i2c_pxa_slave_stop(i2c); in i2c_pxa_handler()
1027 if (i2c_pxa_is_slavemode(i2c)) { in i2c_pxa_handler()
1029 i2c_pxa_slave_txempty(i2c, isr); in i2c_pxa_handler()
1031 i2c_pxa_slave_rxfull(i2c, isr); in i2c_pxa_handler()
1032 } else if (i2c->msg && (!i2c->highmode_enter)) { in i2c_pxa_handler()
1034 i2c_pxa_irq_txempty(i2c, isr); in i2c_pxa_handler()
1036 i2c_pxa_irq_rxfull(i2c, isr); in i2c_pxa_handler()
1037 } else if ((isr & ISR_ITE) && i2c->highmode_enter) { in i2c_pxa_handler()
1038 i2c->highmode_enter = false; in i2c_pxa_handler()
1039 wake_up(&i2c->wait); in i2c_pxa_handler()
1041 i2c_pxa_scream_blue_murder(i2c, "spurious irq"); in i2c_pxa_handler()
1050 static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) in i2c_pxa_do_xfer() argument
1058 ret = i2c_pxa_wait_bus_not_busy(i2c); in i2c_pxa_do_xfer()
1060 dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n"); in i2c_pxa_do_xfer()
1061 i2c_recover_bus(&i2c->adap); in i2c_pxa_do_xfer()
1068 ret = i2c_pxa_set_master(i2c); in i2c_pxa_do_xfer()
1070 dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret); in i2c_pxa_do_xfer()
1074 if (i2c->high_mode) { in i2c_pxa_do_xfer()
1075 ret = i2c_pxa_send_mastercode(i2c); in i2c_pxa_do_xfer()
1077 dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n"); in i2c_pxa_do_xfer()
1082 spin_lock_irq(&i2c->lock); in i2c_pxa_do_xfer()
1084 i2c->msg = msg; in i2c_pxa_do_xfer()
1085 i2c->msg_num = num; in i2c_pxa_do_xfer()
1086 i2c->msg_idx = 0; in i2c_pxa_do_xfer()
1087 i2c->msg_ptr = 0; in i2c_pxa_do_xfer()
1088 i2c->irqlogidx = 0; in i2c_pxa_do_xfer()
1090 i2c_pxa_start_message(i2c); in i2c_pxa_do_xfer()
1092 spin_unlock_irq(&i2c->lock); in i2c_pxa_do_xfer()
1097 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); in i2c_pxa_do_xfer()
1098 i2c_pxa_stop_message(i2c); in i2c_pxa_do_xfer()
1103 ret = i2c->msg_idx; in i2c_pxa_do_xfer()
1105 if (!timeout && i2c->msg_num) { in i2c_pxa_do_xfer()
1106 i2c_pxa_scream_blue_murder(i2c, "timeout with active message"); in i2c_pxa_do_xfer()
1107 i2c_recover_bus(&i2c->adap); in i2c_pxa_do_xfer()
1115 static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c, in i2c_pxa_internal_xfer() argument
1123 ret = xfer(i2c, msgs, num); in i2c_pxa_internal_xfer()
1126 if (++i >= i2c->adap.retries) in i2c_pxa_internal_xfer()
1130 dev_dbg(&i2c->adap.dev, "Retrying transmission\n"); in i2c_pxa_internal_xfer()
1134 i2c_pxa_scream_blue_murder(i2c, "exhausted retries"); in i2c_pxa_internal_xfer()
1137 i2c_pxa_set_slave(i2c, ret); in i2c_pxa_internal_xfer()
1144 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_xfer() local
1146 return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_xfer); in i2c_pxa_xfer()
1165 static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c) in i2c_pxa_pio_set_master() argument
1173 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) in i2c_pxa_pio_set_master()
1177 show_state(i2c); in i2c_pxa_pio_set_master()
1178 dev_err(&i2c->adap.dev, in i2c_pxa_pio_set_master()
1186 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c)); in i2c_pxa_pio_set_master()
1191 static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, in i2c_pxa_do_pio_xfer() argument
1197 ret = i2c_pxa_pio_set_master(i2c); in i2c_pxa_do_pio_xfer()
1201 i2c->msg = msg; in i2c_pxa_do_pio_xfer()
1202 i2c->msg_num = num; in i2c_pxa_do_pio_xfer()
1203 i2c->msg_idx = 0; in i2c_pxa_do_pio_xfer()
1204 i2c->msg_ptr = 0; in i2c_pxa_do_pio_xfer()
1205 i2c->irqlogidx = 0; in i2c_pxa_do_pio_xfer()
1207 i2c_pxa_start_message(i2c); in i2c_pxa_do_pio_xfer()
1209 while (i2c->msg_num > 0 && --timeout) { in i2c_pxa_do_pio_xfer()
1210 i2c_pxa_handler(0, i2c); in i2c_pxa_do_pio_xfer()
1214 i2c_pxa_stop_message(i2c); in i2c_pxa_do_pio_xfer()
1219 ret = i2c->msg_idx; in i2c_pxa_do_pio_xfer()
1223 i2c_pxa_scream_blue_murder(i2c, "timeout (do_pio_xfer)"); in i2c_pxa_do_pio_xfer()
1233 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_pio_xfer() local
1239 if (!(readl(_ICR(i2c)) & ICR_IUE)) in i2c_pxa_pio_xfer()
1240 i2c_pxa_reset(i2c); in i2c_pxa_pio_xfer()
1242 return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_pio_xfer); in i2c_pxa_pio_xfer()
1254 static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, in i2c_pxa_probe_dt() argument
1265 i2c->adap.nr = -1; in i2c_pxa_probe_dt()
1267 i2c->use_pio = of_property_read_bool(np, "mrvl,i2c-polling"); in i2c_pxa_probe_dt()
1268 i2c->fast_mode = of_property_read_bool(np, "mrvl,i2c-fast-mode"); in i2c_pxa_probe_dt()
1276 struct pxa_i2c *i2c, in i2c_pxa_probe_pdata() argument
1284 i2c->use_pio = plat->use_pio; in i2c_pxa_probe_pdata()
1285 i2c->fast_mode = plat->fast_mode; in i2c_pxa_probe_pdata()
1286 i2c->high_mode = plat->high_mode; in i2c_pxa_probe_pdata()
1287 i2c->master_code = plat->master_code; in i2c_pxa_probe_pdata()
1288 if (!i2c->master_code) in i2c_pxa_probe_pdata()
1289 i2c->master_code = 0xe; in i2c_pxa_probe_pdata()
1290 i2c->rate = plat->rate; in i2c_pxa_probe_pdata()
1297 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_prepare_recovery() local
1298 u32 ibmr = readl(_IBMR(i2c)); in i2c_pxa_prepare_recovery()
1304 gpiod_set_value(i2c->recovery.scl_gpiod, ibmr & IBMR_SCLS); in i2c_pxa_prepare_recovery()
1305 gpiod_set_value(i2c->recovery.sda_gpiod, ibmr & IBMR_SDAS); in i2c_pxa_prepare_recovery()
1307 WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery)); in i2c_pxa_prepare_recovery()
1312 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_unprepare_recovery() local
1319 isr = readl(_ISR(i2c)); in i2c_pxa_unprepare_recovery()
1321 dev_dbg(&i2c->adap.dev, in i2c_pxa_unprepare_recovery()
1323 i2c_pxa_do_reset(i2c); in i2c_pxa_unprepare_recovery()
1326 WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default)); in i2c_pxa_unprepare_recovery()
1328 dev_dbg(&i2c->adap.dev, "recovery: IBMR 0x%08x ISR 0x%08x\n", in i2c_pxa_unprepare_recovery()
1329 readl(_IBMR(i2c)), readl(_ISR(i2c))); in i2c_pxa_unprepare_recovery()
1331 i2c_pxa_enable(i2c); in i2c_pxa_unprepare_recovery()
1334 static int i2c_pxa_init_recovery(struct pxa_i2c *i2c) in i2c_pxa_init_recovery() argument
1336 struct i2c_bus_recovery_info *bri = &i2c->recovery; in i2c_pxa_init_recovery()
1337 struct device *dev = i2c->adap.dev.parent; in i2c_pxa_init_recovery()
1348 i2c->pinctrl = devm_pinctrl_get(dev); in i2c_pxa_init_recovery()
1349 if (PTR_ERR(i2c->pinctrl) == -ENODEV) in i2c_pxa_init_recovery()
1350 i2c->pinctrl = NULL; in i2c_pxa_init_recovery()
1351 if (IS_ERR(i2c->pinctrl)) in i2c_pxa_init_recovery()
1352 return PTR_ERR(i2c->pinctrl); in i2c_pxa_init_recovery()
1354 if (!i2c->pinctrl) in i2c_pxa_init_recovery()
1357 i2c->pinctrl_default = pinctrl_lookup_state(i2c->pinctrl, in i2c_pxa_init_recovery()
1359 i2c->pinctrl_recovery = pinctrl_lookup_state(i2c->pinctrl, "recovery"); in i2c_pxa_init_recovery()
1361 if (IS_ERR(i2c->pinctrl_default) || IS_ERR(i2c->pinctrl_recovery)) { in i2c_pxa_init_recovery()
1363 PTR_ERR(i2c->pinctrl_default), in i2c_pxa_init_recovery()
1364 PTR_ERR(i2c->pinctrl_recovery)); in i2c_pxa_init_recovery()
1406 i2c->adap.bus_recovery_info = bri; in i2c_pxa_init_recovery()
1415 pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery); in i2c_pxa_init_recovery()
1417 return pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default); in i2c_pxa_init_recovery()
1424 struct pxa_i2c *i2c; in i2c_pxa_probe() local
1428 i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); in i2c_pxa_probe()
1429 if (!i2c) in i2c_pxa_probe()
1433 i2c->adap.nr = dev->id; in i2c_pxa_probe()
1434 i2c->adap.owner = THIS_MODULE; in i2c_pxa_probe()
1435 i2c->adap.retries = 5; in i2c_pxa_probe()
1436 i2c->adap.algo_data = i2c; in i2c_pxa_probe()
1437 i2c->adap.dev.parent = &dev->dev; in i2c_pxa_probe()
1439 i2c->adap.dev.of_node = dev->dev.of_node; in i2c_pxa_probe()
1442 i2c->reg_base = devm_platform_get_and_ioremap_resource(dev, 0, &res); in i2c_pxa_probe()
1443 if (IS_ERR(i2c->reg_base)) in i2c_pxa_probe()
1444 return PTR_ERR(i2c->reg_base); in i2c_pxa_probe()
1450 ret = i2c_pxa_init_recovery(i2c); in i2c_pxa_probe()
1454 ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type); in i2c_pxa_probe()
1456 ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); in i2c_pxa_probe()
1460 spin_lock_init(&i2c->lock); in i2c_pxa_probe()
1461 init_waitqueue_head(&i2c->wait); in i2c_pxa_probe()
1463 strscpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); in i2c_pxa_probe()
1465 i2c->clk = devm_clk_get(&dev->dev, NULL); in i2c_pxa_probe()
1466 if (IS_ERR(i2c->clk)) in i2c_pxa_probe()
1467 return dev_err_probe(&dev->dev, PTR_ERR(i2c->clk), in i2c_pxa_probe()
1470 i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; in i2c_pxa_probe()
1471 i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr; in i2c_pxa_probe()
1472 i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr; in i2c_pxa_probe()
1473 i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr; in i2c_pxa_probe()
1474 i2c->fm_mask = pxa_reg_layout[i2c_type].fm; in i2c_pxa_probe()
1475 i2c->hs_mask = pxa_reg_layout[i2c_type].hs; in i2c_pxa_probe()
1478 i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar; in i2c_pxa_probe()
1481 i2c->reg_ilcr = i2c->reg_base + pxa_reg_layout[i2c_type].ilcr; in i2c_pxa_probe()
1482 i2c->reg_iwcr = i2c->reg_base + pxa_reg_layout[i2c_type].iwcr; in i2c_pxa_probe()
1485 i2c->iobase = res->start; in i2c_pxa_probe()
1486 i2c->iosize = resource_size(res); in i2c_pxa_probe()
1488 i2c->irq = irq; in i2c_pxa_probe()
1490 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; in i2c_pxa_probe()
1491 i2c->highmode_enter = false; in i2c_pxa_probe()
1494 i2c->adap.class = plat->class; in i2c_pxa_probe()
1497 if (i2c->high_mode) { in i2c_pxa_probe()
1498 if (i2c->rate) { in i2c_pxa_probe()
1499 clk_set_rate(i2c->clk, i2c->rate); in i2c_pxa_probe()
1501 i2c->adap.name, clk_get_rate(i2c->clk)); in i2c_pxa_probe()
1504 i2c->adap.name); in i2c_pxa_probe()
1507 clk_prepare_enable(i2c->clk); in i2c_pxa_probe()
1509 if (i2c->use_pio) { in i2c_pxa_probe()
1510 i2c->adap.algo = &i2c_pxa_pio_algorithm; in i2c_pxa_probe()
1512 i2c->adap.algo = &i2c_pxa_algorithm; in i2c_pxa_probe()
1515 dev_name(&dev->dev), i2c); in i2c_pxa_probe()
1522 i2c_pxa_reset(i2c); in i2c_pxa_probe()
1524 ret = i2c_add_numbered_adapter(&i2c->adap); in i2c_pxa_probe()
1528 platform_set_drvdata(dev, i2c); in i2c_pxa_probe()
1531 dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n", in i2c_pxa_probe()
1532 i2c->slave_addr); in i2c_pxa_probe()
1534 dev_info(&i2c->adap.dev, " PXA I2C adapter\n"); in i2c_pxa_probe()
1539 clk_disable_unprepare(i2c->clk); in i2c_pxa_probe()
1545 struct pxa_i2c *i2c = platform_get_drvdata(dev); in i2c_pxa_remove() local
1547 i2c_del_adapter(&i2c->adap); in i2c_pxa_remove()
1549 clk_disable_unprepare(i2c->clk); in i2c_pxa_remove()
1554 struct pxa_i2c *i2c = dev_get_drvdata(dev); in i2c_pxa_suspend_noirq() local
1556 clk_disable(i2c->clk); in i2c_pxa_suspend_noirq()
1563 struct pxa_i2c *i2c = dev_get_drvdata(dev); in i2c_pxa_resume_noirq() local
1565 clk_enable(i2c->clk); in i2c_pxa_resume_noirq()
1566 i2c_pxa_reset(i2c); in i2c_pxa_resume_noirq()