treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / i2c / busses / i2c-pxa.c
blob466e4f681d7a4eefd4f1316d21bcb39b7ea680be
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * i2c_adap_pxa.c
5 * I2C adapter for the PXA I2C bus access.
7 * Copyright (C) 2002 Intrinsyc Software Inc.
8 * Copyright (C) 2004-2005 Deep Blue Solutions Ltd.
10 * History:
11 * Apr 2002: Initial version [CS]
12 * Jun 2002: Properly separated algo/adap [FB]
13 * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
14 * Jan 2003: added limited signal handling [Kai-Uwe Bloem]
15 * Sep 2004: Major rework to ensure efficient bus handling [RMK]
16 * Dec 2004: Added support for PXA27x and slave device probing [Liam Girdwood]
17 * Feb 2005: Rework slave mode handling [RMK]
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/init.h>
23 #include <linux/time.h>
24 #include <linux/sched.h>
25 #include <linux/delay.h>
26 #include <linux/errno.h>
27 #include <linux/interrupt.h>
28 #include <linux/of.h>
29 #include <linux/of_device.h>
30 #include <linux/platform_device.h>
31 #include <linux/err.h>
32 #include <linux/clk.h>
33 #include <linux/slab.h>
34 #include <linux/io.h>
35 #include <linux/platform_data/i2c-pxa.h>
37 #include <asm/irq.h>
39 struct pxa_reg_layout {
40 u32 ibmr;
41 u32 idbr;
42 u32 icr;
43 u32 isr;
44 u32 isar;
45 u32 ilcr;
46 u32 iwcr;
47 u32 fm;
48 u32 hs;
51 enum pxa_i2c_types {
52 REGS_PXA2XX,
53 REGS_PXA3XX,
54 REGS_CE4100,
55 REGS_PXA910,
56 REGS_A3700,
59 #define ICR_BUSMODE_FM (1 << 16) /* shifted fast mode for armada-3700 */
60 #define ICR_BUSMODE_HS (1 << 17) /* shifted high speed mode for armada-3700 */
63 * I2C registers definitions
65 static struct pxa_reg_layout pxa_reg_layout[] = {
66 [REGS_PXA2XX] = {
67 .ibmr = 0x00,
68 .idbr = 0x08,
69 .icr = 0x10,
70 .isr = 0x18,
71 .isar = 0x20,
73 [REGS_PXA3XX] = {
74 .ibmr = 0x00,
75 .idbr = 0x04,
76 .icr = 0x08,
77 .isr = 0x0c,
78 .isar = 0x10,
80 [REGS_CE4100] = {
81 .ibmr = 0x14,
82 .idbr = 0x0c,
83 .icr = 0x00,
84 .isr = 0x04,
85 /* no isar register */
87 [REGS_PXA910] = {
88 .ibmr = 0x00,
89 .idbr = 0x08,
90 .icr = 0x10,
91 .isr = 0x18,
92 .isar = 0x20,
93 .ilcr = 0x28,
94 .iwcr = 0x30,
96 [REGS_A3700] = {
97 .ibmr = 0x00,
98 .idbr = 0x04,
99 .icr = 0x08,
100 .isr = 0x0c,
101 .isar = 0x10,
102 .fm = ICR_BUSMODE_FM,
103 .hs = ICR_BUSMODE_HS,
107 static const struct platform_device_id i2c_pxa_id_table[] = {
108 { "pxa2xx-i2c", REGS_PXA2XX },
109 { "pxa3xx-pwri2c", REGS_PXA3XX },
110 { "ce4100-i2c", REGS_CE4100 },
111 { "pxa910-i2c", REGS_PXA910 },
112 { "armada-3700-i2c", REGS_A3700 },
113 { },
115 MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
118 * I2C bit definitions
121 #define ICR_START (1 << 0) /* start bit */
122 #define ICR_STOP (1 << 1) /* stop bit */
123 #define ICR_ACKNAK (1 << 2) /* send ACK(0) or NAK(1) */
124 #define ICR_TB (1 << 3) /* transfer byte bit */
125 #define ICR_MA (1 << 4) /* master abort */
126 #define ICR_SCLE (1 << 5) /* master clock enable */
127 #define ICR_IUE (1 << 6) /* unit enable */
128 #define ICR_GCD (1 << 7) /* general call disable */
129 #define ICR_ITEIE (1 << 8) /* enable tx interrupts */
130 #define ICR_IRFIE (1 << 9) /* enable rx interrupts */
131 #define ICR_BEIE (1 << 10) /* enable bus error ints */
132 #define ICR_SSDIE (1 << 11) /* slave STOP detected int enable */
133 #define ICR_ALDIE (1 << 12) /* enable arbitration interrupt */
134 #define ICR_SADIE (1 << 13) /* slave address detected int enable */
135 #define ICR_UR (1 << 14) /* unit reset */
136 #define ICR_FM (1 << 15) /* fast mode */
137 #define ICR_HS (1 << 16) /* High Speed mode */
138 #define ICR_GPIOEN (1 << 19) /* enable GPIO mode for SCL in HS */
140 #define ISR_RWM (1 << 0) /* read/write mode */
141 #define ISR_ACKNAK (1 << 1) /* ack/nak status */
142 #define ISR_UB (1 << 2) /* unit busy */
143 #define ISR_IBB (1 << 3) /* bus busy */
144 #define ISR_SSD (1 << 4) /* slave stop detected */
145 #define ISR_ALD (1 << 5) /* arbitration loss detected */
146 #define ISR_ITE (1 << 6) /* tx buffer empty */
147 #define ISR_IRF (1 << 7) /* rx buffer full */
148 #define ISR_GCAD (1 << 8) /* general call address detected */
149 #define ISR_SAD (1 << 9) /* slave address detected */
150 #define ISR_BED (1 << 10) /* bus error no ACK/NAK */
152 /* bit field shift & mask */
153 #define ILCR_SLV_SHIFT 0
154 #define ILCR_SLV_MASK (0x1FF << ILCR_SLV_SHIFT)
155 #define ILCR_FLV_SHIFT 9
156 #define ILCR_FLV_MASK (0x1FF << ILCR_FLV_SHIFT)
157 #define ILCR_HLVL_SHIFT 18
158 #define ILCR_HLVL_MASK (0x1FF << ILCR_HLVL_SHIFT)
159 #define ILCR_HLVH_SHIFT 27
160 #define ILCR_HLVH_MASK (0x1F << ILCR_HLVH_SHIFT)
162 #define IWCR_CNT_SHIFT 0
163 #define IWCR_CNT_MASK (0x1F << IWCR_CNT_SHIFT)
164 #define IWCR_HS_CNT1_SHIFT 5
165 #define IWCR_HS_CNT1_MASK (0x1F << IWCR_HS_CNT1_SHIFT)
166 #define IWCR_HS_CNT2_SHIFT 10
167 #define IWCR_HS_CNT2_MASK (0x1F << IWCR_HS_CNT2_SHIFT)
169 struct pxa_i2c {
170 spinlock_t lock;
171 wait_queue_head_t wait;
172 struct i2c_msg *msg;
173 unsigned int msg_num;
174 unsigned int msg_idx;
175 unsigned int msg_ptr;
176 unsigned int slave_addr;
177 unsigned int req_slave_addr;
179 struct i2c_adapter adap;
180 struct clk *clk;
181 #ifdef CONFIG_I2C_PXA_SLAVE
182 struct i2c_client *slave;
183 #endif
185 unsigned int irqlogidx;
186 u32 isrlog[32];
187 u32 icrlog[32];
189 void __iomem *reg_base;
190 void __iomem *reg_ibmr;
191 void __iomem *reg_idbr;
192 void __iomem *reg_icr;
193 void __iomem *reg_isr;
194 void __iomem *reg_isar;
195 void __iomem *reg_ilcr;
196 void __iomem *reg_iwcr;
198 unsigned long iobase;
199 unsigned long iosize;
201 int irq;
202 unsigned int use_pio :1;
203 unsigned int fast_mode :1;
204 unsigned int high_mode:1;
205 unsigned char master_code;
206 unsigned long rate;
207 bool highmode_enter;
208 u32 fm_mask;
209 u32 hs_mask;
212 #define _IBMR(i2c) ((i2c)->reg_ibmr)
213 #define _IDBR(i2c) ((i2c)->reg_idbr)
214 #define _ICR(i2c) ((i2c)->reg_icr)
215 #define _ISR(i2c) ((i2c)->reg_isr)
216 #define _ISAR(i2c) ((i2c)->reg_isar)
217 #define _ILCR(i2c) ((i2c)->reg_ilcr)
218 #define _IWCR(i2c) ((i2c)->reg_iwcr)
221 * I2C Slave mode address
223 #define I2C_PXA_SLAVE_ADDR 0x1
225 #ifdef DEBUG
227 struct bits {
228 u32 mask;
229 const char *set;
230 const char *unset;
232 #define PXA_BIT(m, s, u) { .mask = m, .set = s, .unset = u }
234 static inline void
235 decode_bits(const char *prefix, const struct bits *bits, int num, u32 val)
237 printk("%s %08x: ", prefix, val);
238 while (num--) {
239 const char *str = val & bits->mask ? bits->set : bits->unset;
240 if (str)
241 printk("%s ", str);
242 bits++;
246 static const struct bits isr_bits[] = {
247 PXA_BIT(ISR_RWM, "RX", "TX"),
248 PXA_BIT(ISR_ACKNAK, "NAK", "ACK"),
249 PXA_BIT(ISR_UB, "Bsy", "Rdy"),
250 PXA_BIT(ISR_IBB, "BusBsy", "BusRdy"),
251 PXA_BIT(ISR_SSD, "SlaveStop", NULL),
252 PXA_BIT(ISR_ALD, "ALD", NULL),
253 PXA_BIT(ISR_ITE, "TxEmpty", NULL),
254 PXA_BIT(ISR_IRF, "RxFull", NULL),
255 PXA_BIT(ISR_GCAD, "GenCall", NULL),
256 PXA_BIT(ISR_SAD, "SlaveAddr", NULL),
257 PXA_BIT(ISR_BED, "BusErr", NULL),
260 static void decode_ISR(unsigned int val)
262 decode_bits(KERN_DEBUG "ISR", isr_bits, ARRAY_SIZE(isr_bits), val);
263 printk("\n");
266 static const struct bits icr_bits[] = {
267 PXA_BIT(ICR_START, "START", NULL),
268 PXA_BIT(ICR_STOP, "STOP", NULL),
269 PXA_BIT(ICR_ACKNAK, "ACKNAK", NULL),
270 PXA_BIT(ICR_TB, "TB", NULL),
271 PXA_BIT(ICR_MA, "MA", NULL),
272 PXA_BIT(ICR_SCLE, "SCLE", "scle"),
273 PXA_BIT(ICR_IUE, "IUE", "iue"),
274 PXA_BIT(ICR_GCD, "GCD", NULL),
275 PXA_BIT(ICR_ITEIE, "ITEIE", NULL),
276 PXA_BIT(ICR_IRFIE, "IRFIE", NULL),
277 PXA_BIT(ICR_BEIE, "BEIE", NULL),
278 PXA_BIT(ICR_SSDIE, "SSDIE", NULL),
279 PXA_BIT(ICR_ALDIE, "ALDIE", NULL),
280 PXA_BIT(ICR_SADIE, "SADIE", NULL),
281 PXA_BIT(ICR_UR, "UR", "ur"),
284 #ifdef CONFIG_I2C_PXA_SLAVE
285 static void decode_ICR(unsigned int val)
287 decode_bits(KERN_DEBUG "ICR", icr_bits, ARRAY_SIZE(icr_bits), val);
288 printk("\n");
290 #endif
292 static unsigned int i2c_debug = DEBUG;
294 static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
296 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno,
297 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
300 #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
302 static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
304 unsigned int i;
305 struct device *dev = &i2c->adap.dev;
307 dev_err(dev, "slave_0x%x error: %s\n",
308 i2c->req_slave_addr >> 1, why);
309 dev_err(dev, "msg_num: %d msg_idx: %d msg_ptr: %d\n",
310 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
311 dev_err(dev, "IBMR: %08x IDBR: %08x ICR: %08x ISR: %08x\n",
312 readl(_IBMR(i2c)), readl(_IDBR(i2c)), readl(_ICR(i2c)),
313 readl(_ISR(i2c)));
314 dev_dbg(dev, "log: ");
315 for (i = 0; i < i2c->irqlogidx; i++)
316 pr_debug("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
318 pr_debug("\n");
321 #else /* ifdef DEBUG */
323 #define i2c_debug 0
325 #define show_state(i2c) do { } while (0)
326 #define decode_ISR(val) do { } while (0)
327 #define decode_ICR(val) do { } while (0)
328 #define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0)
330 #endif /* ifdef DEBUG / else */
332 static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
333 static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
335 static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
337 return !(readl(_ICR(i2c)) & ICR_SCLE);
340 static void i2c_pxa_abort(struct pxa_i2c *i2c)
342 int i = 250;
344 if (i2c_pxa_is_slavemode(i2c)) {
345 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__);
346 return;
349 while ((i > 0) && (readl(_IBMR(i2c)) & 0x1) == 0) {
350 unsigned long icr = readl(_ICR(i2c));
352 icr &= ~ICR_START;
353 icr |= ICR_ACKNAK | ICR_STOP | ICR_TB;
355 writel(icr, _ICR(i2c));
357 show_state(i2c);
359 mdelay(1);
360 i --;
363 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
364 _ICR(i2c));
367 static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
369 int timeout = DEF_TIMEOUT;
371 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
372 if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
373 timeout += 4;
375 msleep(2);
376 show_state(i2c);
379 if (timeout < 0)
380 show_state(i2c);
382 return timeout < 0 ? I2C_RETRY : 0;
385 static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
387 unsigned long timeout = jiffies + HZ*4;
389 while (time_before(jiffies, timeout)) {
390 if (i2c_debug > 1)
391 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
392 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
394 if (readl(_ISR(i2c)) & ISR_SAD) {
395 if (i2c_debug > 0)
396 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__);
397 goto out;
400 /* wait for unit and bus being not busy, and we also do a
401 * quick check of the i2c lines themselves to ensure they've
402 * gone high...
404 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && readl(_IBMR(i2c)) == 3) {
405 if (i2c_debug > 0)
406 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
407 return 1;
410 msleep(1);
413 if (i2c_debug > 0)
414 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
415 out:
416 return 0;
419 static int i2c_pxa_set_master(struct pxa_i2c *i2c)
421 if (i2c_debug)
422 dev_dbg(&i2c->adap.dev, "setting to bus master\n");
424 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) {
425 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__);
426 if (!i2c_pxa_wait_master(i2c)) {
427 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__);
428 return I2C_RETRY;
432 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
433 return 0;
436 #ifdef CONFIG_I2C_PXA_SLAVE
437 static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
439 unsigned long timeout = jiffies + HZ*1;
441 /* wait for stop */
443 show_state(i2c);
445 while (time_before(jiffies, timeout)) {
446 if (i2c_debug > 1)
447 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
448 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
450 if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 ||
451 (readl(_ISR(i2c)) & ISR_SAD) != 0 ||
452 (readl(_ICR(i2c)) & ICR_SCLE) == 0) {
453 if (i2c_debug > 1)
454 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
455 return 1;
458 msleep(1);
461 if (i2c_debug > 0)
462 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
463 return 0;
467 * clear the hold on the bus, and take of anything else
468 * that has been configured
470 static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
472 show_state(i2c);
474 if (errcode < 0) {
475 udelay(100); /* simple delay */
476 } else {
477 /* we need to wait for the stop condition to end */
479 /* if we where in stop, then clear... */
480 if (readl(_ICR(i2c)) & ICR_STOP) {
481 udelay(100);
482 writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c));
485 if (!i2c_pxa_wait_slave(i2c)) {
486 dev_err(&i2c->adap.dev, "%s: wait timedout\n",
487 __func__);
488 return;
492 writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c));
493 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
495 if (i2c_debug) {
496 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c)));
497 decode_ICR(readl(_ICR(i2c)));
500 #else
501 #define i2c_pxa_set_slave(i2c, err) do { } while (0)
502 #endif
504 static void i2c_pxa_reset(struct pxa_i2c *i2c)
506 pr_debug("Resetting I2C Controller Unit\n");
508 /* abort any transfer currently under way */
509 i2c_pxa_abort(i2c);
511 /* reset according to 9.8 */
512 writel(ICR_UR, _ICR(i2c));
513 writel(I2C_ISR_INIT, _ISR(i2c));
514 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
516 if (i2c->reg_isar && IS_ENABLED(CONFIG_I2C_PXA_SLAVE))
517 writel(i2c->slave_addr, _ISAR(i2c));
519 /* set control register values */
520 writel(I2C_ICR_INIT | (i2c->fast_mode ? i2c->fm_mask : 0), _ICR(i2c));
521 writel(readl(_ICR(i2c)) | (i2c->high_mode ? i2c->hs_mask : 0), _ICR(i2c));
523 #ifdef CONFIG_I2C_PXA_SLAVE
524 dev_info(&i2c->adap.dev, "Enabling slave mode\n");
525 writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c));
526 #endif
528 i2c_pxa_set_slave(i2c, 0);
530 /* enable unit */
531 writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c));
532 udelay(100);
536 #ifdef CONFIG_I2C_PXA_SLAVE
538 * PXA I2C Slave mode
541 static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
543 if (isr & ISR_BED) {
544 /* what should we do here? */
545 } else {
546 u8 byte = 0;
548 if (i2c->slave != NULL)
549 i2c_slave_event(i2c->slave, I2C_SLAVE_READ_PROCESSED,
550 &byte);
552 writel(byte, _IDBR(i2c));
553 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */
557 static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
559 u8 byte = readl(_IDBR(i2c));
561 if (i2c->slave != NULL)
562 i2c_slave_event(i2c->slave, I2C_SLAVE_WRITE_RECEIVED, &byte);
564 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
567 static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
569 int timeout;
571 if (i2c_debug > 0)
572 dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n",
573 (isr & ISR_RWM) ? 'r' : 't');
575 if (i2c->slave != NULL) {
576 if (isr & ISR_RWM) {
577 u8 byte = 0;
579 i2c_slave_event(i2c->slave, I2C_SLAVE_READ_REQUESTED,
580 &byte);
581 writel(byte, _IDBR(i2c));
582 } else {
583 i2c_slave_event(i2c->slave, I2C_SLAVE_WRITE_REQUESTED,
584 NULL);
589 * slave could interrupt in the middle of us generating a
590 * start condition... if this happens, we'd better back off
591 * and stop holding the poor thing up
593 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
594 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
596 timeout = 0x10000;
598 while (1) {
599 if ((readl(_IBMR(i2c)) & 2) == 2)
600 break;
602 timeout--;
604 if (timeout <= 0) {
605 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
606 break;
610 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
613 static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
615 if (i2c_debug > 2)
616 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n");
618 if (i2c->slave != NULL)
619 i2c_slave_event(i2c->slave, I2C_SLAVE_STOP, NULL);
621 if (i2c_debug > 2)
622 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n");
625 * If we have a master-mode message waiting,
626 * kick it off now that the slave has completed.
628 if (i2c->msg)
629 i2c_pxa_master_complete(i2c, I2C_RETRY);
632 static int i2c_pxa_slave_reg(struct i2c_client *slave)
634 struct pxa_i2c *i2c = slave->adapter->algo_data;
636 if (i2c->slave)
637 return -EBUSY;
639 if (!i2c->reg_isar)
640 return -EAFNOSUPPORT;
642 i2c->slave = slave;
643 i2c->slave_addr = slave->addr;
645 writel(i2c->slave_addr, _ISAR(i2c));
647 return 0;
650 static int i2c_pxa_slave_unreg(struct i2c_client *slave)
652 struct pxa_i2c *i2c = slave->adapter->algo_data;
654 WARN_ON(!i2c->slave);
656 i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
657 writel(i2c->slave_addr, _ISAR(i2c));
659 i2c->slave = NULL;
661 return 0;
663 #else
664 static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
666 if (isr & ISR_BED) {
667 /* what should we do here? */
668 } else {
669 writel(0, _IDBR(i2c));
670 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
674 static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
676 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
679 static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
681 int timeout;
684 * slave could interrupt in the middle of us generating a
685 * start condition... if this happens, we'd better back off
686 * and stop holding the poor thing up
688 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
689 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
691 timeout = 0x10000;
693 while (1) {
694 if ((readl(_IBMR(i2c)) & 2) == 2)
695 break;
697 timeout--;
699 if (timeout <= 0) {
700 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
701 break;
705 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
708 static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
710 if (i2c->msg)
711 i2c_pxa_master_complete(i2c, I2C_RETRY);
713 #endif
716 * PXA I2C Master mode
719 static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
721 unsigned int addr = (msg->addr & 0x7f) << 1;
723 if (msg->flags & I2C_M_RD)
724 addr |= 1;
726 return addr;
729 static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
731 u32 icr;
734 * Step 1: target slave address into IDBR
736 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
737 i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
740 * Step 2: initiate the write.
742 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
743 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
746 static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
748 u32 icr;
751 * Clear the STOP and ACK flags
753 icr = readl(_ICR(i2c));
754 icr &= ~(ICR_STOP | ICR_ACKNAK);
755 writel(icr, _ICR(i2c));
758 static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
760 /* make timeout the same as for interrupt based functions */
761 long timeout = 2 * DEF_TIMEOUT;
764 * Wait for the bus to become free.
766 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
767 udelay(1000);
768 show_state(i2c);
771 if (timeout < 0) {
772 show_state(i2c);
773 dev_err(&i2c->adap.dev,
774 "i2c_pxa: timeout waiting for bus free\n");
775 return I2C_RETRY;
779 * Set master mode.
781 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
783 return 0;
787 * PXA I2C send master code
788 * 1. Load master code to IDBR and send it.
789 * Note for HS mode, set ICR [GPIOEN].
790 * 2. Wait until win arbitration.
792 static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c)
794 u32 icr;
795 long timeout;
797 spin_lock_irq(&i2c->lock);
798 i2c->highmode_enter = true;
799 writel(i2c->master_code, _IDBR(i2c));
801 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
802 icr |= ICR_GPIOEN | ICR_START | ICR_TB | ICR_ITEIE;
803 writel(icr, _ICR(i2c));
805 spin_unlock_irq(&i2c->lock);
806 timeout = wait_event_timeout(i2c->wait,
807 i2c->highmode_enter == false, HZ * 1);
809 i2c->highmode_enter = false;
811 return (timeout == 0) ? I2C_RETRY : 0;
814 static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
815 struct i2c_msg *msg, int num)
817 unsigned long timeout = 500000; /* 5 seconds */
818 int ret = 0;
820 ret = i2c_pxa_pio_set_master(i2c);
821 if (ret)
822 goto out;
824 i2c->msg = msg;
825 i2c->msg_num = num;
826 i2c->msg_idx = 0;
827 i2c->msg_ptr = 0;
828 i2c->irqlogidx = 0;
830 i2c_pxa_start_message(i2c);
832 while (i2c->msg_num > 0 && --timeout) {
833 i2c_pxa_handler(0, i2c);
834 udelay(10);
837 i2c_pxa_stop_message(i2c);
840 * We place the return code in i2c->msg_idx.
842 ret = i2c->msg_idx;
844 out:
845 if (timeout == 0) {
846 i2c_pxa_scream_blue_murder(i2c, "timeout");
847 ret = I2C_RETRY;
850 return ret;
854 * We are protected by the adapter bus mutex.
856 static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
858 long timeout;
859 int ret;
862 * Wait for the bus to become free.
864 ret = i2c_pxa_wait_bus_not_busy(i2c);
865 if (ret) {
866 dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n");
867 goto out;
871 * Set master mode.
873 ret = i2c_pxa_set_master(i2c);
874 if (ret) {
875 dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret);
876 goto out;
879 if (i2c->high_mode) {
880 ret = i2c_pxa_send_mastercode(i2c);
881 if (ret) {
882 dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n");
883 goto out;
887 spin_lock_irq(&i2c->lock);
889 i2c->msg = msg;
890 i2c->msg_num = num;
891 i2c->msg_idx = 0;
892 i2c->msg_ptr = 0;
893 i2c->irqlogidx = 0;
895 i2c_pxa_start_message(i2c);
897 spin_unlock_irq(&i2c->lock);
900 * The rest of the processing occurs in the interrupt handler.
902 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
903 i2c_pxa_stop_message(i2c);
906 * We place the return code in i2c->msg_idx.
908 ret = i2c->msg_idx;
910 if (!timeout && i2c->msg_num) {
911 i2c_pxa_scream_blue_murder(i2c, "timeout");
912 ret = I2C_RETRY;
915 out:
916 return ret;
919 static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
920 struct i2c_msg msgs[], int num)
922 struct pxa_i2c *i2c = adap->algo_data;
923 int ret, i;
925 /* If the I2C controller is disabled we need to reset it
926 (probably due to a suspend/resume destroying state). We do
927 this here as we can then avoid worrying about resuming the
928 controller before its users. */
929 if (!(readl(_ICR(i2c)) & ICR_IUE))
930 i2c_pxa_reset(i2c);
932 for (i = adap->retries; i >= 0; i--) {
933 ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
934 if (ret != I2C_RETRY)
935 goto out;
937 if (i2c_debug)
938 dev_dbg(&adap->dev, "Retrying transmission\n");
939 udelay(100);
941 i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
942 ret = -EREMOTEIO;
943 out:
944 i2c_pxa_set_slave(i2c, ret);
945 return ret;
949 * i2c_pxa_master_complete - complete the message and wake up.
951 static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
953 i2c->msg_ptr = 0;
954 i2c->msg = NULL;
955 i2c->msg_idx ++;
956 i2c->msg_num = 0;
957 if (ret)
958 i2c->msg_idx = ret;
959 if (!i2c->use_pio)
960 wake_up(&i2c->wait);
963 static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
965 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
967 again:
969 * If ISR_ALD is set, we lost arbitration.
971 if (isr & ISR_ALD) {
973 * Do we need to do anything here? The PXA docs
974 * are vague about what happens.
976 i2c_pxa_scream_blue_murder(i2c, "ALD set");
979 * We ignore this error. We seem to see spurious ALDs
980 * for seemingly no reason. If we handle them as I think
981 * they should, we end up causing an I2C error, which
982 * is painful for some systems.
984 return; /* ignore */
987 if ((isr & ISR_BED) &&
988 (!((i2c->msg->flags & I2C_M_IGNORE_NAK) &&
989 (isr & ISR_ACKNAK)))) {
990 int ret = BUS_ERROR;
993 * I2C bus error - either the device NAK'd us, or
994 * something more serious happened. If we were NAK'd
995 * on the initial address phase, we can retry.
997 if (isr & ISR_ACKNAK) {
998 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0)
999 ret = I2C_RETRY;
1000 else
1001 ret = XFER_NAKED;
1003 i2c_pxa_master_complete(i2c, ret);
1004 } else if (isr & ISR_RWM) {
1006 * Read mode. We have just sent the address byte, and
1007 * now we must initiate the transfer.
1009 if (i2c->msg_ptr == i2c->msg->len - 1 &&
1010 i2c->msg_idx == i2c->msg_num - 1)
1011 icr |= ICR_STOP | ICR_ACKNAK;
1013 icr |= ICR_ALDIE | ICR_TB;
1014 } else if (i2c->msg_ptr < i2c->msg->len) {
1016 * Write mode. Write the next data byte.
1018 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c));
1020 icr |= ICR_ALDIE | ICR_TB;
1023 * If this is the last byte of the last message or last byte
1024 * of any message with I2C_M_STOP (e.g. SCCB), send a STOP.
1026 if ((i2c->msg_ptr == i2c->msg->len) &&
1027 ((i2c->msg->flags & I2C_M_STOP) ||
1028 (i2c->msg_idx == i2c->msg_num - 1)))
1029 icr |= ICR_STOP;
1031 } else if (i2c->msg_idx < i2c->msg_num - 1) {
1033 * Next segment of the message.
1035 i2c->msg_ptr = 0;
1036 i2c->msg_idx ++;
1037 i2c->msg++;
1040 * If we aren't doing a repeated start and address,
1041 * go back and try to send the next byte. Note that
1042 * we do not support switching the R/W direction here.
1044 if (i2c->msg->flags & I2C_M_NOSTART)
1045 goto again;
1048 * Write the next address.
1050 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
1051 i2c->req_slave_addr = i2c_pxa_addr_byte(i2c->msg);
1054 * And trigger a repeated start, and send the byte.
1056 icr &= ~ICR_ALDIE;
1057 icr |= ICR_START | ICR_TB;
1058 } else {
1059 if (i2c->msg->len == 0) {
1061 * Device probes have a message length of zero
1062 * and need the bus to be reset before it can
1063 * be used again.
1065 i2c_pxa_reset(i2c);
1067 i2c_pxa_master_complete(i2c, 0);
1070 i2c->icrlog[i2c->irqlogidx-1] = icr;
1072 writel(icr, _ICR(i2c));
1073 show_state(i2c);
1076 static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
1078 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
1081 * Read the byte.
1083 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c));
1085 if (i2c->msg_ptr < i2c->msg->len) {
1087 * If this is the last byte of the last
1088 * message, send a STOP.
1090 if (i2c->msg_ptr == i2c->msg->len - 1)
1091 icr |= ICR_STOP | ICR_ACKNAK;
1093 icr |= ICR_ALDIE | ICR_TB;
1094 } else {
1095 i2c_pxa_master_complete(i2c, 0);
1098 i2c->icrlog[i2c->irqlogidx-1] = icr;
1100 writel(icr, _ICR(i2c));
1103 #define VALID_INT_SOURCE (ISR_SSD | ISR_ALD | ISR_ITE | ISR_IRF | \
1104 ISR_SAD | ISR_BED)
1105 static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
1107 struct pxa_i2c *i2c = dev_id;
1108 u32 isr = readl(_ISR(i2c));
1110 if (!(isr & VALID_INT_SOURCE))
1111 return IRQ_NONE;
1113 if (i2c_debug > 2 && 0) {
1114 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
1115 __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
1116 decode_ISR(isr);
1119 if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog))
1120 i2c->isrlog[i2c->irqlogidx++] = isr;
1122 show_state(i2c);
1125 * Always clear all pending IRQs.
1127 writel(isr & VALID_INT_SOURCE, _ISR(i2c));
1129 if (isr & ISR_SAD)
1130 i2c_pxa_slave_start(i2c, isr);
1131 if (isr & ISR_SSD)
1132 i2c_pxa_slave_stop(i2c);
1134 if (i2c_pxa_is_slavemode(i2c)) {
1135 if (isr & ISR_ITE)
1136 i2c_pxa_slave_txempty(i2c, isr);
1137 if (isr & ISR_IRF)
1138 i2c_pxa_slave_rxfull(i2c, isr);
1139 } else if (i2c->msg && (!i2c->highmode_enter)) {
1140 if (isr & ISR_ITE)
1141 i2c_pxa_irq_txempty(i2c, isr);
1142 if (isr & ISR_IRF)
1143 i2c_pxa_irq_rxfull(i2c, isr);
1144 } else if ((isr & ISR_ITE) && i2c->highmode_enter) {
1145 i2c->highmode_enter = false;
1146 wake_up(&i2c->wait);
1147 } else {
1148 i2c_pxa_scream_blue_murder(i2c, "spurious irq");
1151 return IRQ_HANDLED;
1155 static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
1157 struct pxa_i2c *i2c = adap->algo_data;
1158 int ret, i;
1160 for (i = adap->retries; i >= 0; i--) {
1161 ret = i2c_pxa_do_xfer(i2c, msgs, num);
1162 if (ret != I2C_RETRY)
1163 goto out;
1165 if (i2c_debug)
1166 dev_dbg(&adap->dev, "Retrying transmission\n");
1167 udelay(100);
1169 i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
1170 ret = -EREMOTEIO;
1171 out:
1172 i2c_pxa_set_slave(i2c, ret);
1173 return ret;
1176 static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
1178 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
1179 I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;
1182 static const struct i2c_algorithm i2c_pxa_algorithm = {
1183 .master_xfer = i2c_pxa_xfer,
1184 .functionality = i2c_pxa_functionality,
1185 #ifdef CONFIG_I2C_PXA_SLAVE
1186 .reg_slave = i2c_pxa_slave_reg,
1187 .unreg_slave = i2c_pxa_slave_unreg,
1188 #endif
1191 static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
1192 .master_xfer = i2c_pxa_pio_xfer,
1193 .functionality = i2c_pxa_functionality,
1194 #ifdef CONFIG_I2C_PXA_SLAVE
1195 .reg_slave = i2c_pxa_slave_reg,
1196 .unreg_slave = i2c_pxa_slave_unreg,
1197 #endif
1200 static const struct of_device_id i2c_pxa_dt_ids[] = {
1201 { .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX },
1202 { .compatible = "mrvl,pwri2c", .data = (void *)REGS_PXA3XX },
1203 { .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA910 },
1204 { .compatible = "marvell,armada-3700-i2c", .data = (void *)REGS_A3700 },
1207 MODULE_DEVICE_TABLE(of, i2c_pxa_dt_ids);
1209 static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
1210 enum pxa_i2c_types *i2c_types)
1212 struct device_node *np = pdev->dev.of_node;
1213 const struct of_device_id *of_id =
1214 of_match_device(i2c_pxa_dt_ids, &pdev->dev);
1216 if (!of_id)
1217 return 1;
1219 /* For device tree we always use the dynamic or alias-assigned ID */
1220 i2c->adap.nr = -1;
1222 if (of_get_property(np, "mrvl,i2c-polling", NULL))
1223 i2c->use_pio = 1;
1224 if (of_get_property(np, "mrvl,i2c-fast-mode", NULL))
1225 i2c->fast_mode = 1;
1227 *i2c_types = (enum pxa_i2c_types)(of_id->data);
1229 return 0;
1232 static int i2c_pxa_probe_pdata(struct platform_device *pdev,
1233 struct pxa_i2c *i2c,
1234 enum pxa_i2c_types *i2c_types)
1236 struct i2c_pxa_platform_data *plat = dev_get_platdata(&pdev->dev);
1237 const struct platform_device_id *id = platform_get_device_id(pdev);
1239 *i2c_types = id->driver_data;
1240 if (plat) {
1241 i2c->use_pio = plat->use_pio;
1242 i2c->fast_mode = plat->fast_mode;
1243 i2c->high_mode = plat->high_mode;
1244 i2c->master_code = plat->master_code;
1245 if (!i2c->master_code)
1246 i2c->master_code = 0xe;
1247 i2c->rate = plat->rate;
1249 return 0;
1252 static int i2c_pxa_probe(struct platform_device *dev)
1254 struct i2c_pxa_platform_data *plat = dev_get_platdata(&dev->dev);
1255 enum pxa_i2c_types i2c_type;
1256 struct pxa_i2c *i2c;
1257 struct resource *res = NULL;
1258 int ret, irq;
1260 i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL);
1261 if (!i2c)
1262 return -ENOMEM;
1264 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
1265 i2c->reg_base = devm_ioremap_resource(&dev->dev, res);
1266 if (IS_ERR(i2c->reg_base))
1267 return PTR_ERR(i2c->reg_base);
1269 irq = platform_get_irq(dev, 0);
1270 if (irq < 0) {
1271 dev_err(&dev->dev, "no irq resource: %d\n", irq);
1272 return irq;
1275 /* Default adapter num to device id; i2c_pxa_probe_dt can override. */
1276 i2c->adap.nr = dev->id;
1278 ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type);
1279 if (ret > 0)
1280 ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
1281 if (ret < 0)
1282 return ret;
1284 i2c->adap.owner = THIS_MODULE;
1285 i2c->adap.retries = 5;
1287 spin_lock_init(&i2c->lock);
1288 init_waitqueue_head(&i2c->wait);
1290 strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name));
1292 i2c->clk = devm_clk_get(&dev->dev, NULL);
1293 if (IS_ERR(i2c->clk)) {
1294 dev_err(&dev->dev, "failed to get the clk: %ld\n", PTR_ERR(i2c->clk));
1295 return PTR_ERR(i2c->clk);
1298 i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
1299 i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
1300 i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr;
1301 i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr;
1302 i2c->fm_mask = pxa_reg_layout[i2c_type].fm ? : ICR_FM;
1303 i2c->hs_mask = pxa_reg_layout[i2c_type].hs ? : ICR_HS;
1305 if (i2c_type != REGS_CE4100)
1306 i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar;
1308 if (i2c_type == REGS_PXA910) {
1309 i2c->reg_ilcr = i2c->reg_base + pxa_reg_layout[i2c_type].ilcr;
1310 i2c->reg_iwcr = i2c->reg_base + pxa_reg_layout[i2c_type].iwcr;
1313 i2c->iobase = res->start;
1314 i2c->iosize = resource_size(res);
1316 i2c->irq = irq;
1318 i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
1319 i2c->highmode_enter = false;
1321 if (plat) {
1322 i2c->adap.class = plat->class;
1325 if (i2c->high_mode) {
1326 if (i2c->rate) {
1327 clk_set_rate(i2c->clk, i2c->rate);
1328 pr_info("i2c: <%s> set rate to %ld\n",
1329 i2c->adap.name, clk_get_rate(i2c->clk));
1330 } else
1331 pr_warn("i2c: <%s> clock rate not set\n",
1332 i2c->adap.name);
1335 clk_prepare_enable(i2c->clk);
1337 if (i2c->use_pio) {
1338 i2c->adap.algo = &i2c_pxa_pio_algorithm;
1339 } else {
1340 i2c->adap.algo = &i2c_pxa_algorithm;
1341 ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler,
1342 IRQF_SHARED | IRQF_NO_SUSPEND,
1343 dev_name(&dev->dev), i2c);
1344 if (ret) {
1345 dev_err(&dev->dev, "failed to request irq: %d\n", ret);
1346 goto ereqirq;
1350 i2c_pxa_reset(i2c);
1352 i2c->adap.algo_data = i2c;
1353 i2c->adap.dev.parent = &dev->dev;
1354 #ifdef CONFIG_OF
1355 i2c->adap.dev.of_node = dev->dev.of_node;
1356 #endif
1358 ret = i2c_add_numbered_adapter(&i2c->adap);
1359 if (ret < 0)
1360 goto ereqirq;
1362 platform_set_drvdata(dev, i2c);
1364 #ifdef CONFIG_I2C_PXA_SLAVE
1365 dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n",
1366 i2c->slave_addr);
1367 #else
1368 dev_info(&i2c->adap.dev, " PXA I2C adapter\n");
1369 #endif
1370 return 0;
1372 ereqirq:
1373 clk_disable_unprepare(i2c->clk);
1374 return ret;
1377 static int i2c_pxa_remove(struct platform_device *dev)
1379 struct pxa_i2c *i2c = platform_get_drvdata(dev);
1381 i2c_del_adapter(&i2c->adap);
1383 clk_disable_unprepare(i2c->clk);
1385 return 0;
1388 #ifdef CONFIG_PM
1389 static int i2c_pxa_suspend_noirq(struct device *dev)
1391 struct pxa_i2c *i2c = dev_get_drvdata(dev);
1393 clk_disable(i2c->clk);
1395 return 0;
1398 static int i2c_pxa_resume_noirq(struct device *dev)
1400 struct pxa_i2c *i2c = dev_get_drvdata(dev);
1402 clk_enable(i2c->clk);
1403 i2c_pxa_reset(i2c);
1405 return 0;
1408 static const struct dev_pm_ops i2c_pxa_dev_pm_ops = {
1409 .suspend_noirq = i2c_pxa_suspend_noirq,
1410 .resume_noirq = i2c_pxa_resume_noirq,
1413 #define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops)
1414 #else
1415 #define I2C_PXA_DEV_PM_OPS NULL
1416 #endif
1418 static struct platform_driver i2c_pxa_driver = {
1419 .probe = i2c_pxa_probe,
1420 .remove = i2c_pxa_remove,
1421 .driver = {
1422 .name = "pxa2xx-i2c",
1423 .pm = I2C_PXA_DEV_PM_OPS,
1424 .of_match_table = i2c_pxa_dt_ids,
1426 .id_table = i2c_pxa_id_table,
1429 static int __init i2c_adap_pxa_init(void)
1431 return platform_driver_register(&i2c_pxa_driver);
1434 static void __exit i2c_adap_pxa_exit(void)
1436 platform_driver_unregister(&i2c_pxa_driver);
1439 MODULE_LICENSE("GPL");
1440 MODULE_ALIAS("platform:pxa2xx-i2c");
1442 subsys_initcall(i2c_adap_pxa_init);
1443 module_exit(i2c_adap_pxa_exit);