Lines Matching +full:i2c +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0-only
5 * I2C adapter for the PXA I2C bus access.
8 * Copyright (C) 2004-2005 Deep Blue Solutions Ltd.
13 * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
14 * Jan 2003: added limited signal handling [Kai-Uwe Bloem]
24 #include <linux/i2c.h>
34 #include <linux/platform_data/i2c-pxa.h>
38 /* I2C register field definitions */
39 #define IBMR_SDAS (1 << 0)
42 #define ICR_START (1 << 0) /* start bit */
44 #define ICR_ACKNAK (1 << 2) /* send ACK(0) or NAK(1) */
59 #define ICR_A3700_FM (1 << 16) /* fast mode for armada-3700 */
60 #define ICR_A3700_HS (1 << 17) /* high speed mode for armada-3700 */
63 #define ISR_RWM (1 << 0) /* read/write mode */
75 #define ILCR_SLV_SHIFT 0
76 #define ILCR_SLV_MASK (0x1FF << ILCR_SLV_SHIFT)
78 #define ILCR_FLV_MASK (0x1FF << ILCR_FLV_SHIFT)
80 #define ILCR_HLVL_MASK (0x1FF << ILCR_HLVL_SHIFT)
82 #define ILCR_HLVH_MASK (0x1F << ILCR_HLVH_SHIFT)
84 #define IWCR_CNT_SHIFT 0
85 #define IWCR_CNT_MASK (0x1F << IWCR_CNT_SHIFT)
87 #define IWCR_HS_CNT1_MASK (0x1F << IWCR_HS_CNT1_SHIFT)
89 #define IWCR_HS_CNT2_MASK (0x1F << IWCR_HS_CNT2_SHIFT)
92 * looking at a multi-master environment
96 #define NO_SLAVE (-ENXIO)
97 #define BUS_ERROR (-EREMOTEIO)
98 #define XFER_NAKED (-ECONNREFUSED)
99 #define I2C_RETRY (-2000) /* an error has occurred retry transmit */
103 * 15 FM 0 (100 kHz operation)
104 * 14 UR 0 (No unit reset)
105 * 13 SADIE 0 (Disables the unit from interrupting on slave addresses
107 * 12 ALDIE 0 (Disables the unit from interrupt when it loses arbitration
109 * 11 SSDIE 0 (Disables interrupts from a slave stop detected, in slave mode)
112 * 8 ITEIE 1 (Enables the I2C unit to interrupt when transmit buffer empty)
113 * 7 GCD 1 (Disables i2c unit response to general call messages as a slave)
114 * 6 IUE 0 (Disable unit until we change settings)
115 * 5 SCLE 1 (Enables the i2c clock output for master mode (drives SCL)
116 * 4 MA 0 (Only send stop with the ICR stop bit)
117 * 3 TB 0 (We are not transmitting a byte initially)
118 * 2 ACKNAK 0 (Send an ACK after the unit receives a byte)
119 * 1 STOP 0 (Do not send a STOP)
120 * 0 START 0 (Do not send a START)
124 /* I2C status register init values
133 #define I2C_ISR_INIT 0x7FF /* status register init */
155 /* I2C register layout definitions */
158 .ibmr = 0x00,
159 .idbr = 0x08,
160 .icr = 0x10,
161 .isr = 0x18,
162 .isar = 0x20,
167 .ibmr = 0x00,
168 .idbr = 0x04,
169 .icr = 0x08,
170 .isr = 0x0c,
171 .isar = 0x10,
176 .ibmr = 0x14,
177 .idbr = 0x0c,
178 .icr = 0x00,
179 .isr = 0x04,
185 .ibmr = 0x00,
186 .idbr = 0x08,
187 .icr = 0x10,
188 .isr = 0x18,
189 .isar = 0x20,
190 .ilcr = 0x28,
191 .iwcr = 0x30,
196 .ibmr = 0x00,
197 .idbr = 0x04,
198 .icr = 0x08,
199 .isr = 0x0c,
200 .isar = 0x10,
207 { .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX },
209 { .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA910 },
210 { .compatible = "marvell,armada-3700-i2c", .data = (void *)REGS_A3700 },
216 { "pxa2xx-i2c", REGS_PXA2XX },
217 { "pxa3xx-pwri2c", REGS_PXA3XX },
218 { "ce4100-i2c", REGS_CE4100 },
219 { "pxa910-i2c", REGS_PXA910 },
220 { "armada-3700-i2c", REGS_A3700 },
273 #define _IBMR(i2c) ((i2c)->reg_ibmr) argument
274 #define _IDBR(i2c) ((i2c)->reg_idbr) argument
275 #define _ICR(i2c) ((i2c)->reg_icr) argument
276 #define _ISR(i2c) ((i2c)->reg_isr) argument
277 #define _ISAR(i2c) ((i2c)->reg_isar) argument
278 #define _ILCR(i2c) ((i2c)->reg_ilcr) argument
279 #define _IWCR(i2c) ((i2c)->reg_iwcr) argument
282 * I2C Slave mode address
284 #define I2C_PXA_SLAVE_ADDR 0x1
299 while (num--) { in decode_bits()
300 const char *str = val & bits->mask ? bits->set : bits->unset; in decode_bits()
354 static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname) in i2c_pxa_show_state() argument
356 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno, in i2c_pxa_show_state()
357 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_show_state()
360 #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__) argument
362 static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) in i2c_pxa_scream_blue_murder() argument
365 struct device *dev = &i2c->adap.dev; in i2c_pxa_scream_blue_murder()
368 i2c->req_slave_addr >> 1, why); in i2c_pxa_scream_blue_murder()
370 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); in i2c_pxa_scream_blue_murder()
372 readl(_IBMR(i2c)), readl(_IDBR(i2c)), readl(_ICR(i2c)), in i2c_pxa_scream_blue_murder()
373 readl(_ISR(i2c))); in i2c_pxa_scream_blue_murder()
375 for (i = 0; i < i2c->irqlogidx; i++) in i2c_pxa_scream_blue_murder()
376 pr_cont(" [%03x:%05x]", i2c->isrlog[i], i2c->icrlog[i]); in i2c_pxa_scream_blue_murder()
382 #define i2c_debug 0
384 #define show_state(i2c) do { } while (0) argument
385 #define decode_ISR(val) do { } while (0)
386 #define decode_ICR(val) do { } while (0)
387 #define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0) argument
391 static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
393 static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) in i2c_pxa_is_slavemode() argument
395 return !(readl(_ICR(i2c)) & ICR_SCLE); in i2c_pxa_is_slavemode()
398 static void i2c_pxa_abort(struct pxa_i2c *i2c) in i2c_pxa_abort() argument
402 if (i2c_pxa_is_slavemode(i2c)) { in i2c_pxa_abort()
403 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__); in i2c_pxa_abort()
407 while ((i > 0) && (readl(_IBMR(i2c)) & IBMR_SDAS) == 0) { in i2c_pxa_abort()
408 unsigned long icr = readl(_ICR(i2c)); in i2c_pxa_abort()
413 writel(icr, _ICR(i2c)); in i2c_pxa_abort()
415 show_state(i2c); in i2c_pxa_abort()
418 i --; in i2c_pxa_abort()
421 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP), in i2c_pxa_abort()
422 _ICR(i2c)); in i2c_pxa_abort()
425 static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c) in i2c_pxa_wait_bus_not_busy() argument
431 isr = readl(_ISR(i2c)); in i2c_pxa_wait_bus_not_busy()
433 return 0; in i2c_pxa_wait_bus_not_busy()
438 if (!timeout--) in i2c_pxa_wait_bus_not_busy()
442 show_state(i2c); in i2c_pxa_wait_bus_not_busy()
445 show_state(i2c); in i2c_pxa_wait_bus_not_busy()
450 static int i2c_pxa_wait_master(struct pxa_i2c *i2c) in i2c_pxa_wait_master() argument
456 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_wait_master()
457 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_wait_master()
459 if (readl(_ISR(i2c)) & ISR_SAD) { in i2c_pxa_wait_master()
460 if (i2c_debug > 0) in i2c_pxa_wait_master()
461 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__); in i2c_pxa_wait_master()
466 * quick check of the i2c lines themselves to ensure they've in i2c_pxa_wait_master()
469 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && in i2c_pxa_wait_master()
470 readl(_IBMR(i2c)) == (IBMR_SCLS | IBMR_SDAS)) { in i2c_pxa_wait_master()
471 if (i2c_debug > 0) in i2c_pxa_wait_master()
472 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); in i2c_pxa_wait_master()
479 if (i2c_debug > 0) in i2c_pxa_wait_master()
480 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__); in i2c_pxa_wait_master()
482 return 0; in i2c_pxa_wait_master()
485 static int i2c_pxa_set_master(struct pxa_i2c *i2c) in i2c_pxa_set_master() argument
488 dev_dbg(&i2c->adap.dev, "setting to bus master\n"); in i2c_pxa_set_master()
490 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) { in i2c_pxa_set_master()
491 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__); in i2c_pxa_set_master()
492 if (!i2c_pxa_wait_master(i2c)) { in i2c_pxa_set_master()
493 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__); in i2c_pxa_set_master()
498 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c)); in i2c_pxa_set_master()
499 return 0; in i2c_pxa_set_master()
503 static int i2c_pxa_wait_slave(struct pxa_i2c *i2c) in i2c_pxa_wait_slave() argument
509 show_state(i2c); in i2c_pxa_wait_slave()
513 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_wait_slave()
514 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_wait_slave()
516 if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 || in i2c_pxa_wait_slave()
517 (readl(_ISR(i2c)) & ISR_SAD) != 0 || in i2c_pxa_wait_slave()
518 (readl(_ICR(i2c)) & ICR_SCLE) == 0) { in i2c_pxa_wait_slave()
520 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); in i2c_pxa_wait_slave()
527 if (i2c_debug > 0) in i2c_pxa_wait_slave()
528 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__); in i2c_pxa_wait_slave()
529 return 0; in i2c_pxa_wait_slave()
536 static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode) in i2c_pxa_set_slave() argument
538 show_state(i2c); in i2c_pxa_set_slave()
540 if (errcode < 0) { in i2c_pxa_set_slave()
546 if (readl(_ICR(i2c)) & ICR_STOP) { in i2c_pxa_set_slave()
548 writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c)); in i2c_pxa_set_slave()
551 if (!i2c_pxa_wait_slave(i2c)) { in i2c_pxa_set_slave()
552 dev_err(&i2c->adap.dev, "%s: wait timedout\n", in i2c_pxa_set_slave()
558 writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c)); in i2c_pxa_set_slave()
559 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c)); in i2c_pxa_set_slave()
562 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c))); in i2c_pxa_set_slave()
563 decode_ICR(readl(_ICR(i2c))); in i2c_pxa_set_slave()
567 #define i2c_pxa_set_slave(i2c, err) do { } while (0) argument
570 static void i2c_pxa_do_reset(struct pxa_i2c *i2c) in i2c_pxa_do_reset() argument
573 writel(ICR_UR, _ICR(i2c)); in i2c_pxa_do_reset()
574 writel(I2C_ISR_INIT, _ISR(i2c)); in i2c_pxa_do_reset()
575 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c)); in i2c_pxa_do_reset()
577 if (i2c->reg_isar && IS_ENABLED(CONFIG_I2C_PXA_SLAVE)) in i2c_pxa_do_reset()
578 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_do_reset()
581 writel(I2C_ICR_INIT | (i2c->fast_mode ? i2c->fm_mask : 0), _ICR(i2c)); in i2c_pxa_do_reset()
582 writel(readl(_ICR(i2c)) | (i2c->high_mode ? i2c->hs_mask : 0), _ICR(i2c)); in i2c_pxa_do_reset()
585 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); in i2c_pxa_do_reset()
586 writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c)); in i2c_pxa_do_reset()
589 i2c_pxa_set_slave(i2c, 0); in i2c_pxa_do_reset()
592 static void i2c_pxa_enable(struct pxa_i2c *i2c) in i2c_pxa_enable() argument
595 writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c)); in i2c_pxa_enable()
599 static void i2c_pxa_reset(struct pxa_i2c *i2c) in i2c_pxa_reset() argument
601 pr_debug("Resetting I2C Controller Unit\n"); in i2c_pxa_reset()
604 i2c_pxa_abort(i2c); in i2c_pxa_reset()
605 i2c_pxa_do_reset(i2c); in i2c_pxa_reset()
606 i2c_pxa_enable(i2c); in i2c_pxa_reset()
612 * PXA I2C Slave mode
615 static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_txempty() argument
620 u8 byte = 0; in i2c_pxa_slave_txempty()
622 if (i2c->slave != NULL) in i2c_pxa_slave_txempty()
623 i2c_slave_event(i2c->slave, I2C_SLAVE_READ_PROCESSED, in i2c_pxa_slave_txempty()
626 writel(byte, _IDBR(i2c)); in i2c_pxa_slave_txempty()
627 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */ in i2c_pxa_slave_txempty()
631 static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_rxfull() argument
633 u8 byte = readl(_IDBR(i2c)); in i2c_pxa_slave_rxfull()
635 if (i2c->slave != NULL) in i2c_pxa_slave_rxfull()
636 i2c_slave_event(i2c->slave, I2C_SLAVE_WRITE_RECEIVED, &byte); in i2c_pxa_slave_rxfull()
638 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); in i2c_pxa_slave_rxfull()
641 static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_start() argument
645 if (i2c_debug > 0) in i2c_pxa_slave_start()
646 dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n", in i2c_pxa_slave_start()
649 if (i2c->slave != NULL) { in i2c_pxa_slave_start()
651 u8 byte = 0; in i2c_pxa_slave_start()
653 i2c_slave_event(i2c->slave, I2C_SLAVE_READ_REQUESTED, in i2c_pxa_slave_start()
655 writel(byte, _IDBR(i2c)); in i2c_pxa_slave_start()
657 i2c_slave_event(i2c->slave, I2C_SLAVE_WRITE_REQUESTED, in i2c_pxa_slave_start()
667 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c)); in i2c_pxa_slave_start()
668 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); in i2c_pxa_slave_start()
670 timeout = 0x10000; in i2c_pxa_slave_start()
673 if ((readl(_IBMR(i2c)) & IBMR_SCLS) == IBMR_SCLS) in i2c_pxa_slave_start()
676 timeout--; in i2c_pxa_slave_start()
678 if (timeout <= 0) { in i2c_pxa_slave_start()
679 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n"); in i2c_pxa_slave_start()
684 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c)); in i2c_pxa_slave_start()
687 static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) in i2c_pxa_slave_stop() argument
690 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n"); in i2c_pxa_slave_stop()
692 if (i2c->slave != NULL) in i2c_pxa_slave_stop()
693 i2c_slave_event(i2c->slave, I2C_SLAVE_STOP, NULL); in i2c_pxa_slave_stop()
696 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n"); in i2c_pxa_slave_stop()
699 * If we have a master-mode message waiting, in i2c_pxa_slave_stop()
702 if (i2c->msg) in i2c_pxa_slave_stop()
703 i2c_pxa_master_complete(i2c, I2C_RETRY); in i2c_pxa_slave_stop()
708 struct pxa_i2c *i2c = slave->adapter->algo_data; in i2c_pxa_slave_reg() local
710 if (i2c->slave) in i2c_pxa_slave_reg()
711 return -EBUSY; in i2c_pxa_slave_reg()
713 if (!i2c->reg_isar) in i2c_pxa_slave_reg()
714 return -EAFNOSUPPORT; in i2c_pxa_slave_reg()
716 i2c->slave = slave; in i2c_pxa_slave_reg()
717 i2c->slave_addr = slave->addr; in i2c_pxa_slave_reg()
719 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_slave_reg()
721 return 0; in i2c_pxa_slave_reg()
726 struct pxa_i2c *i2c = slave->adapter->algo_data; in i2c_pxa_slave_unreg() local
728 WARN_ON(!i2c->slave); in i2c_pxa_slave_unreg()
730 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; in i2c_pxa_slave_unreg()
731 writel(i2c->slave_addr, _ISAR(i2c)); in i2c_pxa_slave_unreg()
733 i2c->slave = NULL; in i2c_pxa_slave_unreg()
735 return 0; in i2c_pxa_slave_unreg()
738 static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_txempty() argument
743 writel(0, _IDBR(i2c)); in i2c_pxa_slave_txempty()
744 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); in i2c_pxa_slave_txempty()
748 static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_rxfull() argument
750 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c)); in i2c_pxa_slave_rxfull()
753 static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_slave_start() argument
762 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c)); in i2c_pxa_slave_start()
763 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c)); in i2c_pxa_slave_start()
765 timeout = 0x10000; in i2c_pxa_slave_start()
768 if ((readl(_IBMR(i2c)) & IBMR_SCLS) == IBMR_SCLS) in i2c_pxa_slave_start()
771 timeout--; in i2c_pxa_slave_start()
773 if (timeout <= 0) { in i2c_pxa_slave_start()
774 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n"); in i2c_pxa_slave_start()
779 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c)); in i2c_pxa_slave_start()
782 static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) in i2c_pxa_slave_stop() argument
784 if (i2c->msg) in i2c_pxa_slave_stop()
785 i2c_pxa_master_complete(i2c, I2C_RETRY); in i2c_pxa_slave_stop()
790 * PXA I2C Master mode
793 static inline void i2c_pxa_start_message(struct pxa_i2c *i2c) in i2c_pxa_start_message() argument
800 i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg); in i2c_pxa_start_message()
801 writel(i2c->req_slave_addr, _IDBR(i2c)); in i2c_pxa_start_message()
806 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE); in i2c_pxa_start_message()
807 writel(icr | ICR_START | ICR_TB, _ICR(i2c)); in i2c_pxa_start_message()
810 static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c) in i2c_pxa_stop_message() argument
815 icr = readl(_ICR(i2c)); in i2c_pxa_stop_message()
817 writel(icr, _ICR(i2c)); in i2c_pxa_stop_message()
821 * PXA I2C send master code
826 static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c) in i2c_pxa_send_mastercode() argument
831 spin_lock_irq(&i2c->lock); in i2c_pxa_send_mastercode()
832 i2c->highmode_enter = true; in i2c_pxa_send_mastercode()
833 writel(i2c->master_code, _IDBR(i2c)); in i2c_pxa_send_mastercode()
835 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE); in i2c_pxa_send_mastercode()
837 writel(icr, _ICR(i2c)); in i2c_pxa_send_mastercode()
839 spin_unlock_irq(&i2c->lock); in i2c_pxa_send_mastercode()
840 time_left = wait_event_timeout(i2c->wait, in i2c_pxa_send_mastercode()
841 i2c->highmode_enter == false, HZ * 1); in i2c_pxa_send_mastercode()
843 i2c->highmode_enter = false; in i2c_pxa_send_mastercode()
845 return (time_left == 0) ? I2C_RETRY : 0; in i2c_pxa_send_mastercode()
849 * i2c_pxa_master_complete - complete the message and wake up.
851 static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret) in i2c_pxa_master_complete() argument
853 i2c->msg_ptr = 0; in i2c_pxa_master_complete()
854 i2c->msg = NULL; in i2c_pxa_master_complete()
855 i2c->msg_idx ++; in i2c_pxa_master_complete()
856 i2c->msg_num = 0; in i2c_pxa_master_complete()
858 i2c->msg_idx = ret; in i2c_pxa_master_complete()
859 if (!i2c->use_pio) in i2c_pxa_master_complete()
860 wake_up(&i2c->wait); in i2c_pxa_master_complete()
863 static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_irq_txempty() argument
865 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); in i2c_pxa_irq_txempty()
876 i2c_pxa_scream_blue_murder(i2c, "ALD set"); in i2c_pxa_irq_txempty()
881 * they should, we end up causing an I2C error, which in i2c_pxa_irq_txempty()
888 (!((i2c->msg->flags & I2C_M_IGNORE_NAK) && in i2c_pxa_irq_txempty()
893 * I2C bus error - either the device NAK'd us, or in i2c_pxa_irq_txempty()
898 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0) in i2c_pxa_irq_txempty()
903 i2c_pxa_master_complete(i2c, ret); in i2c_pxa_irq_txempty()
909 if (i2c->msg_ptr == i2c->msg->len - 1 && in i2c_pxa_irq_txempty()
910 i2c->msg_idx == i2c->msg_num - 1) in i2c_pxa_irq_txempty()
914 } else if (i2c->msg_ptr < i2c->msg->len) { in i2c_pxa_irq_txempty()
918 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c)); in i2c_pxa_irq_txempty()
926 if ((i2c->msg_ptr == i2c->msg->len) && in i2c_pxa_irq_txempty()
927 ((i2c->msg->flags & I2C_M_STOP) || in i2c_pxa_irq_txempty()
928 (i2c->msg_idx == i2c->msg_num - 1))) in i2c_pxa_irq_txempty()
931 } else if (i2c->msg_idx < i2c->msg_num - 1) { in i2c_pxa_irq_txempty()
935 i2c->msg_ptr = 0; in i2c_pxa_irq_txempty()
936 i2c->msg_idx ++; in i2c_pxa_irq_txempty()
937 i2c->msg++; in i2c_pxa_irq_txempty()
944 if (i2c->msg->flags & I2C_M_NOSTART) in i2c_pxa_irq_txempty()
950 i2c->req_slave_addr = i2c_8bit_addr_from_msg(i2c->msg); in i2c_pxa_irq_txempty()
951 writel(i2c->req_slave_addr, _IDBR(i2c)); in i2c_pxa_irq_txempty()
959 if (i2c->msg->len == 0) in i2c_pxa_irq_txempty()
961 i2c_pxa_master_complete(i2c, 0); in i2c_pxa_irq_txempty()
964 i2c->icrlog[i2c->irqlogidx-1] = icr; in i2c_pxa_irq_txempty()
966 writel(icr, _ICR(i2c)); in i2c_pxa_irq_txempty()
967 show_state(i2c); in i2c_pxa_irq_txempty()
970 static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr) in i2c_pxa_irq_rxfull() argument
972 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); in i2c_pxa_irq_rxfull()
977 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c)); in i2c_pxa_irq_rxfull()
979 if (i2c->msg_ptr < i2c->msg->len) { in i2c_pxa_irq_rxfull()
984 if (i2c->msg_ptr == i2c->msg->len - 1) in i2c_pxa_irq_rxfull()
989 i2c_pxa_master_complete(i2c, 0); in i2c_pxa_irq_rxfull()
992 i2c->icrlog[i2c->irqlogidx-1] = icr; in i2c_pxa_irq_rxfull()
994 writel(icr, _ICR(i2c)); in i2c_pxa_irq_rxfull()
1001 struct pxa_i2c *i2c = dev_id; in i2c_pxa_handler() local
1002 u32 isr = readl(_ISR(i2c)); in i2c_pxa_handler()
1007 if (i2c_debug > 2 && 0) { in i2c_pxa_handler()
1008 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n", in i2c_pxa_handler()
1009 __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c))); in i2c_pxa_handler()
1013 if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog)) in i2c_pxa_handler()
1014 i2c->isrlog[i2c->irqlogidx++] = isr; in i2c_pxa_handler()
1016 show_state(i2c); in i2c_pxa_handler()
1021 writel(isr & VALID_INT_SOURCE, _ISR(i2c)); in i2c_pxa_handler()
1024 i2c_pxa_slave_start(i2c, isr); in i2c_pxa_handler()
1026 i2c_pxa_slave_stop(i2c); in i2c_pxa_handler()
1028 if (i2c_pxa_is_slavemode(i2c)) { in i2c_pxa_handler()
1030 i2c_pxa_slave_txempty(i2c, isr); in i2c_pxa_handler()
1032 i2c_pxa_slave_rxfull(i2c, isr); in i2c_pxa_handler()
1033 } else if (i2c->msg && (!i2c->highmode_enter)) { in i2c_pxa_handler()
1035 i2c_pxa_irq_txempty(i2c, isr); in i2c_pxa_handler()
1037 i2c_pxa_irq_rxfull(i2c, isr); in i2c_pxa_handler()
1038 } else if ((isr & ISR_ITE) && i2c->highmode_enter) { in i2c_pxa_handler()
1039 i2c->highmode_enter = false; in i2c_pxa_handler()
1040 wake_up(&i2c->wait); in i2c_pxa_handler()
1042 i2c_pxa_scream_blue_murder(i2c, "spurious irq"); in i2c_pxa_handler()
1051 static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) in i2c_pxa_do_xfer() argument
1059 ret = i2c_pxa_wait_bus_not_busy(i2c); in i2c_pxa_do_xfer()
1061 dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n"); in i2c_pxa_do_xfer()
1062 i2c_recover_bus(&i2c->adap); in i2c_pxa_do_xfer()
1069 ret = i2c_pxa_set_master(i2c); in i2c_pxa_do_xfer()
1071 dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret); in i2c_pxa_do_xfer()
1075 if (i2c->high_mode) { in i2c_pxa_do_xfer()
1076 ret = i2c_pxa_send_mastercode(i2c); in i2c_pxa_do_xfer()
1078 dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n"); in i2c_pxa_do_xfer()
1083 spin_lock_irq(&i2c->lock); in i2c_pxa_do_xfer()
1085 i2c->msg = msg; in i2c_pxa_do_xfer()
1086 i2c->msg_num = num; in i2c_pxa_do_xfer()
1087 i2c->msg_idx = 0; in i2c_pxa_do_xfer()
1088 i2c->msg_ptr = 0; in i2c_pxa_do_xfer()
1089 i2c->irqlogidx = 0; in i2c_pxa_do_xfer()
1091 i2c_pxa_start_message(i2c); in i2c_pxa_do_xfer()
1093 spin_unlock_irq(&i2c->lock); in i2c_pxa_do_xfer()
1098 time_left = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); in i2c_pxa_do_xfer()
1099 i2c_pxa_stop_message(i2c); in i2c_pxa_do_xfer()
1102 * We place the return code in i2c->msg_idx. in i2c_pxa_do_xfer()
1104 ret = i2c->msg_idx; in i2c_pxa_do_xfer()
1106 if (!time_left && i2c->msg_num) { in i2c_pxa_do_xfer()
1107 i2c_pxa_scream_blue_murder(i2c, "timeout with active message"); in i2c_pxa_do_xfer()
1108 i2c_recover_bus(&i2c->adap); in i2c_pxa_do_xfer()
1116 static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c, in i2c_pxa_internal_xfer() argument
1123 for (i = 0; ; ) { in i2c_pxa_internal_xfer()
1124 ret = xfer(i2c, msgs, num); in i2c_pxa_internal_xfer()
1127 if (++i >= i2c->adap.retries) in i2c_pxa_internal_xfer()
1131 dev_dbg(&i2c->adap.dev, "Retrying transmission\n"); in i2c_pxa_internal_xfer()
1135 i2c_pxa_scream_blue_murder(i2c, "exhausted retries"); in i2c_pxa_internal_xfer()
1136 ret = -EREMOTEIO; in i2c_pxa_internal_xfer()
1138 i2c_pxa_set_slave(i2c, ret); in i2c_pxa_internal_xfer()
1145 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_xfer() local
1147 return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_xfer); in i2c_pxa_xfer()
1165 /* Non-interrupt mode support */
1166 static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c) in i2c_pxa_pio_set_master() argument
1174 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) in i2c_pxa_pio_set_master()
1177 if (timeout < 0) { in i2c_pxa_pio_set_master()
1178 show_state(i2c); in i2c_pxa_pio_set_master()
1179 dev_err(&i2c->adap.dev, in i2c_pxa_pio_set_master()
1187 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c)); in i2c_pxa_pio_set_master()
1189 return 0; in i2c_pxa_pio_set_master()
1192 static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, in i2c_pxa_do_pio_xfer() argument
1196 int ret = 0; in i2c_pxa_do_pio_xfer()
1198 ret = i2c_pxa_pio_set_master(i2c); in i2c_pxa_do_pio_xfer()
1202 i2c->msg = msg; in i2c_pxa_do_pio_xfer()
1203 i2c->msg_num = num; in i2c_pxa_do_pio_xfer()
1204 i2c->msg_idx = 0; in i2c_pxa_do_pio_xfer()
1205 i2c->msg_ptr = 0; in i2c_pxa_do_pio_xfer()
1206 i2c->irqlogidx = 0; in i2c_pxa_do_pio_xfer()
1208 i2c_pxa_start_message(i2c); in i2c_pxa_do_pio_xfer()
1210 while (i2c->msg_num > 0 && --timeout) { in i2c_pxa_do_pio_xfer()
1211 i2c_pxa_handler(0, i2c); in i2c_pxa_do_pio_xfer()
1215 i2c_pxa_stop_message(i2c); in i2c_pxa_do_pio_xfer()
1218 * We place the return code in i2c->msg_idx. in i2c_pxa_do_pio_xfer()
1220 ret = i2c->msg_idx; in i2c_pxa_do_pio_xfer()
1223 if (timeout == 0) { in i2c_pxa_do_pio_xfer()
1224 i2c_pxa_scream_blue_murder(i2c, "timeout (do_pio_xfer)"); in i2c_pxa_do_pio_xfer()
1234 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_pio_xfer() local
1236 /* If the I2C controller is disabled we need to reset it in i2c_pxa_pio_xfer()
1240 if (!(readl(_ICR(i2c)) & ICR_IUE)) in i2c_pxa_pio_xfer()
1241 i2c_pxa_reset(i2c); in i2c_pxa_pio_xfer()
1243 return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_pio_xfer); in i2c_pxa_pio_xfer()
1255 static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, in i2c_pxa_probe_dt() argument
1258 struct device_node *np = pdev->dev.of_node; in i2c_pxa_probe_dt()
1260 if (!pdev->dev.of_node) in i2c_pxa_probe_dt()
1263 /* For device tree we always use the dynamic or alias-assigned ID */ in i2c_pxa_probe_dt()
1264 i2c->adap.nr = -1; in i2c_pxa_probe_dt()
1266 i2c->use_pio = of_property_read_bool(np, "mrvl,i2c-polling"); in i2c_pxa_probe_dt()
1267 i2c->fast_mode = of_property_read_bool(np, "mrvl,i2c-fast-mode"); in i2c_pxa_probe_dt()
1269 *i2c_types = (enum pxa_i2c_types)device_get_match_data(&pdev->dev); in i2c_pxa_probe_dt()
1271 return 0; in i2c_pxa_probe_dt()
1275 struct pxa_i2c *i2c, in i2c_pxa_probe_pdata() argument
1278 struct i2c_pxa_platform_data *plat = dev_get_platdata(&pdev->dev); in i2c_pxa_probe_pdata()
1281 *i2c_types = id->driver_data; in i2c_pxa_probe_pdata()
1283 i2c->use_pio = plat->use_pio; in i2c_pxa_probe_pdata()
1284 i2c->fast_mode = plat->fast_mode; in i2c_pxa_probe_pdata()
1285 i2c->high_mode = plat->high_mode; in i2c_pxa_probe_pdata()
1286 i2c->master_code = plat->master_code; in i2c_pxa_probe_pdata()
1287 if (!i2c->master_code) in i2c_pxa_probe_pdata()
1288 i2c->master_code = 0xe; in i2c_pxa_probe_pdata()
1289 i2c->rate = plat->rate; in i2c_pxa_probe_pdata()
1291 return 0; in i2c_pxa_probe_pdata()
1296 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_prepare_recovery() local
1297 u32 ibmr = readl(_IBMR(i2c)); in i2c_pxa_prepare_recovery()
1300 * Program the GPIOs to reflect the current I2C bus state while in i2c_pxa_prepare_recovery()
1303 gpiod_set_value(i2c->recovery.scl_gpiod, ibmr & IBMR_SCLS); in i2c_pxa_prepare_recovery()
1304 gpiod_set_value(i2c->recovery.sda_gpiod, ibmr & IBMR_SDAS); in i2c_pxa_prepare_recovery()
1306 WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery)); in i2c_pxa_prepare_recovery()
1311 struct pxa_i2c *i2c = adap->algo_data; in i2c_pxa_unprepare_recovery() local
1315 * The bus should now be free. Clear up the I2C controller before in i2c_pxa_unprepare_recovery()
1318 isr = readl(_ISR(i2c)); in i2c_pxa_unprepare_recovery()
1320 dev_dbg(&i2c->adap.dev, in i2c_pxa_unprepare_recovery()
1321 "recovery: resetting controller, ISR=0x%08x\n", isr); in i2c_pxa_unprepare_recovery()
1322 i2c_pxa_do_reset(i2c); in i2c_pxa_unprepare_recovery()
1325 WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default)); in i2c_pxa_unprepare_recovery()
1327 dev_dbg(&i2c->adap.dev, "recovery: IBMR 0x%08x ISR 0x%08x\n", in i2c_pxa_unprepare_recovery()
1328 readl(_IBMR(i2c)), readl(_ISR(i2c))); in i2c_pxa_unprepare_recovery()
1330 i2c_pxa_enable(i2c); in i2c_pxa_unprepare_recovery()
1333 static int i2c_pxa_init_recovery(struct pxa_i2c *i2c) in i2c_pxa_init_recovery() argument
1335 struct i2c_bus_recovery_info *bri = &i2c->recovery; in i2c_pxa_init_recovery()
1336 struct device *dev = i2c->adap.dev.parent; in i2c_pxa_init_recovery()
1345 return 0; in i2c_pxa_init_recovery()
1347 i2c->pinctrl = devm_pinctrl_get(dev); in i2c_pxa_init_recovery()
1348 if (PTR_ERR(i2c->pinctrl) == -ENODEV) in i2c_pxa_init_recovery()
1349 i2c->pinctrl = NULL; in i2c_pxa_init_recovery()
1350 if (IS_ERR(i2c->pinctrl)) in i2c_pxa_init_recovery()
1351 return PTR_ERR(i2c->pinctrl); in i2c_pxa_init_recovery()
1353 if (!i2c->pinctrl) in i2c_pxa_init_recovery()
1354 return 0; in i2c_pxa_init_recovery()
1356 i2c->pinctrl_default = pinctrl_lookup_state(i2c->pinctrl, in i2c_pxa_init_recovery()
1358 i2c->pinctrl_recovery = pinctrl_lookup_state(i2c->pinctrl, "recovery"); in i2c_pxa_init_recovery()
1360 if (IS_ERR(i2c->pinctrl_default) || IS_ERR(i2c->pinctrl_recovery)) { in i2c_pxa_init_recovery()
1362 PTR_ERR(i2c->pinctrl_default), in i2c_pxa_init_recovery()
1363 PTR_ERR(i2c->pinctrl_recovery)); in i2c_pxa_init_recovery()
1364 return 0; in i2c_pxa_init_recovery()
1369 * I2C bus. Do this carefully. in i2c_pxa_init_recovery()
1371 bri->scl_gpiod = devm_gpiod_get(dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN); in i2c_pxa_init_recovery()
1372 if (bri->scl_gpiod == ERR_PTR(-EPROBE_DEFER)) in i2c_pxa_init_recovery()
1373 return -EPROBE_DEFER; in i2c_pxa_init_recovery()
1374 if (IS_ERR(bri->scl_gpiod)) { in i2c_pxa_init_recovery()
1376 bri->scl_gpiod); in i2c_pxa_init_recovery()
1377 return 0; in i2c_pxa_init_recovery()
1384 gpiod_direction_output(bri->scl_gpiod, 0); in i2c_pxa_init_recovery()
1386 bri->sda_gpiod = devm_gpiod_get(dev, "sda", GPIOD_OUT_HIGH_OPEN_DRAIN); in i2c_pxa_init_recovery()
1390 gpiod_direction_output(bri->scl_gpiod, 1); in i2c_pxa_init_recovery()
1392 if (bri->sda_gpiod == ERR_PTR(-EPROBE_DEFER)) in i2c_pxa_init_recovery()
1393 return -EPROBE_DEFER; in i2c_pxa_init_recovery()
1395 if (IS_ERR(bri->sda_gpiod)) { in i2c_pxa_init_recovery()
1397 bri->sda_gpiod); in i2c_pxa_init_recovery()
1398 return 0; in i2c_pxa_init_recovery()
1401 bri->prepare_recovery = i2c_pxa_prepare_recovery; in i2c_pxa_init_recovery()
1402 bri->unprepare_recovery = i2c_pxa_unprepare_recovery; in i2c_pxa_init_recovery()
1403 bri->recover_bus = i2c_generic_scl_recovery; in i2c_pxa_init_recovery()
1405 i2c->adap.bus_recovery_info = bri; in i2c_pxa_init_recovery()
1412 * avoid glitching the I2C bus. in i2c_pxa_init_recovery()
1414 pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery); in i2c_pxa_init_recovery()
1416 return pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default); in i2c_pxa_init_recovery()
1421 struct i2c_pxa_platform_data *plat = dev_get_platdata(&dev->dev); in i2c_pxa_probe()
1423 struct pxa_i2c *i2c; in i2c_pxa_probe() local
1427 i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); in i2c_pxa_probe()
1428 if (!i2c) in i2c_pxa_probe()
1429 return -ENOMEM; in i2c_pxa_probe()
1432 i2c->adap.nr = dev->id; in i2c_pxa_probe()
1433 i2c->adap.owner = THIS_MODULE; in i2c_pxa_probe()
1434 i2c->adap.retries = 5; in i2c_pxa_probe()
1435 i2c->adap.algo_data = i2c; in i2c_pxa_probe()
1436 i2c->adap.dev.parent = &dev->dev; in i2c_pxa_probe()
1438 i2c->adap.dev.of_node = dev->dev.of_node; in i2c_pxa_probe()
1441 i2c->reg_base = devm_platform_get_and_ioremap_resource(dev, 0, &res); in i2c_pxa_probe()
1442 if (IS_ERR(i2c->reg_base)) in i2c_pxa_probe()
1443 return PTR_ERR(i2c->reg_base); in i2c_pxa_probe()
1445 irq = platform_get_irq(dev, 0); in i2c_pxa_probe()
1446 if (irq < 0) in i2c_pxa_probe()
1449 ret = i2c_pxa_init_recovery(i2c); in i2c_pxa_probe()
1453 ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type); in i2c_pxa_probe()
1454 if (ret > 0) in i2c_pxa_probe()
1455 ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); in i2c_pxa_probe()
1456 if (ret < 0) in i2c_pxa_probe()
1459 spin_lock_init(&i2c->lock); in i2c_pxa_probe()
1460 init_waitqueue_head(&i2c->wait); in i2c_pxa_probe()
1462 strscpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); in i2c_pxa_probe()
1464 i2c->clk = devm_clk_get(&dev->dev, NULL); in i2c_pxa_probe()
1465 if (IS_ERR(i2c->clk)) in i2c_pxa_probe()
1466 return dev_err_probe(&dev->dev, PTR_ERR(i2c->clk), in i2c_pxa_probe()
1469 i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; in i2c_pxa_probe()
1470 i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr; in i2c_pxa_probe()
1471 i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr; in i2c_pxa_probe()
1472 i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr; in i2c_pxa_probe()
1473 i2c->fm_mask = pxa_reg_layout[i2c_type].fm; in i2c_pxa_probe()
1474 i2c->hs_mask = pxa_reg_layout[i2c_type].hs; in i2c_pxa_probe()
1477 i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar; in i2c_pxa_probe()
1480 i2c->reg_ilcr = i2c->reg_base + pxa_reg_layout[i2c_type].ilcr; in i2c_pxa_probe()
1481 i2c->reg_iwcr = i2c->reg_base + pxa_reg_layout[i2c_type].iwcr; in i2c_pxa_probe()
1484 i2c->iobase = res->start; in i2c_pxa_probe()
1485 i2c->iosize = resource_size(res); in i2c_pxa_probe()
1487 i2c->irq = irq; in i2c_pxa_probe()
1489 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; in i2c_pxa_probe()
1490 i2c->highmode_enter = false; in i2c_pxa_probe()
1493 i2c->adap.class = plat->class; in i2c_pxa_probe()
1496 if (i2c->high_mode) { in i2c_pxa_probe()
1497 if (i2c->rate) { in i2c_pxa_probe()
1498 clk_set_rate(i2c->clk, i2c->rate); in i2c_pxa_probe()
1499 pr_info("i2c: <%s> set rate to %ld\n", in i2c_pxa_probe()
1500 i2c->adap.name, clk_get_rate(i2c->clk)); in i2c_pxa_probe()
1502 pr_warn("i2c: <%s> clock rate not set\n", in i2c_pxa_probe()
1503 i2c->adap.name); in i2c_pxa_probe()
1506 clk_prepare_enable(i2c->clk); in i2c_pxa_probe()
1508 if (i2c->use_pio) { in i2c_pxa_probe()
1509 i2c->adap.algo = &i2c_pxa_pio_algorithm; in i2c_pxa_probe()
1511 i2c->adap.algo = &i2c_pxa_algorithm; in i2c_pxa_probe()
1512 ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler, in i2c_pxa_probe()
1514 dev_name(&dev->dev), i2c); in i2c_pxa_probe()
1516 dev_err(&dev->dev, "failed to request irq: %d\n", ret); in i2c_pxa_probe()
1521 i2c_pxa_reset(i2c); in i2c_pxa_probe()
1523 ret = i2c_add_numbered_adapter(&i2c->adap); in i2c_pxa_probe()
1524 if (ret < 0) in i2c_pxa_probe()
1527 platform_set_drvdata(dev, i2c); in i2c_pxa_probe()
1530 dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n", in i2c_pxa_probe()
1531 i2c->slave_addr); in i2c_pxa_probe()
1533 dev_info(&i2c->adap.dev, " PXA I2C adapter\n"); in i2c_pxa_probe()
1535 return 0; in i2c_pxa_probe()
1538 clk_disable_unprepare(i2c->clk); in i2c_pxa_probe()
1544 struct pxa_i2c *i2c = platform_get_drvdata(dev); in i2c_pxa_remove() local
1546 i2c_del_adapter(&i2c->adap); in i2c_pxa_remove()
1548 clk_disable_unprepare(i2c->clk); in i2c_pxa_remove()
1553 struct pxa_i2c *i2c = dev_get_drvdata(dev); in i2c_pxa_suspend_noirq() local
1555 clk_disable(i2c->clk); in i2c_pxa_suspend_noirq()
1557 return 0; in i2c_pxa_suspend_noirq()
1562 struct pxa_i2c *i2c = dev_get_drvdata(dev); in i2c_pxa_resume_noirq() local
1564 clk_enable(i2c->clk); in i2c_pxa_resume_noirq()
1565 i2c_pxa_reset(i2c); in i2c_pxa_resume_noirq()
1567 return 0; in i2c_pxa_resume_noirq()
1579 .name = "pxa2xx-i2c",
1596 MODULE_DESCRIPTION("Intel PXA2XX I2C adapter");