blob: a61d9062bf7b725e5b6b8ebb5dd824b7053f1ac8 [file] [log] [blame]
Russell Kingb652b432005-06-15 12:38:14 +01001/*
2 * i2c_adap_pxa.c
3 *
4 * I2C adapter for the PXA I2C bus access.
5 *
6 * Copyright (C) 2002 Intrinsyc Software Inc.
7 * Copyright (C) 2004-2005 Deep Blue Solutions Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * History:
14 * Apr 2002: Initial version [CS]
Daniel Mack3ad2f3f2010-02-03 08:01:28 +080015 * Jun 2002: Properly separated algo/adap [FB]
Russell Kingb652b432005-06-15 12:38:14 +010016 * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
17 * Jan 2003: added limited signal handling [Kai-Uwe Bloem]
18 * Sep 2004: Major rework to ensure efficient bus handling [RMK]
19 * Dec 2004: Added support for PXA27x and slave device probing [Liam Girdwood]
20 * Feb 2005: Rework slave mode handling [RMK]
21 */
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/i2c.h>
Russell Kingb652b432005-06-15 12:38:14 +010025#include <linux/init.h>
26#include <linux/time.h>
27#include <linux/sched.h>
28#include <linux/delay.h>
29#include <linux/errno.h>
30#include <linux/interrupt.h>
31#include <linux/i2c-pxa.h>
Haojian Zhuang63fe1222012-03-01 13:04:44 +080032#include <linux/of.h>
33#include <linux/of_device.h>
Sebastian Andrzej Siewiorbaa8cab2011-02-23 12:38:20 +010034#include <linux/of_i2c.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010035#include <linux/platform_device.h>
Russell Kingc3cef3f2007-08-20 10:19:10 +010036#include <linux/err.h>
37#include <linux/clk.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
H Hartley Sweeten21782182010-05-21 18:41:01 +020039#include <linux/io.h>
Sebastian Andrzej Siewiorb4593962011-02-23 12:38:16 +010040#include <linux/i2c/pxa-i2c.h>
Russell Kingb652b432005-06-15 12:38:14 +010041
Russell Kingb652b432005-06-15 12:38:14 +010042#include <asm/irq.h>
Eric Miao283afa02008-09-08 14:15:08 +080043
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010044struct pxa_reg_layout {
45 u32 ibmr;
46 u32 idbr;
47 u32 icr;
48 u32 isr;
49 u32 isar;
50};
51
52enum pxa_i2c_types {
53 REGS_PXA2XX,
54 REGS_PXA3XX,
Sebastian Andrzej Siewior7e94dd12011-03-02 11:26:53 +010055 REGS_CE4100,
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010056};
57
Eric Miao283afa02008-09-08 14:15:08 +080058/*
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010059 * I2C registers definitions
Eric Miaof23d4912009-04-13 14:43:25 +080060 */
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010061static struct pxa_reg_layout pxa_reg_layout[] = {
62 [REGS_PXA2XX] = {
63 .ibmr = 0x00,
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010064 .idbr = 0x08,
65 .icr = 0x10,
66 .isr = 0x18,
67 .isar = 0x20,
68 },
Vasily Khoruzhick23e74a82011-03-13 15:53:28 +020069 [REGS_PXA3XX] = {
70 .ibmr = 0x00,
71 .idbr = 0x04,
72 .icr = 0x08,
73 .isr = 0x0c,
74 .isar = 0x10,
75 },
Sebastian Andrzej Siewior7e94dd12011-03-02 11:26:53 +010076 [REGS_CE4100] = {
77 .ibmr = 0x14,
78 .idbr = 0x0c,
79 .icr = 0x00,
80 .isr = 0x04,
81 /* no isar register */
82 },
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010083};
Eric Miaof23d4912009-04-13 14:43:25 +080084
85static const struct platform_device_id i2c_pxa_id_table[] = {
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010086 { "pxa2xx-i2c", REGS_PXA2XX },
87 { "pxa3xx-pwri2c", REGS_PXA3XX },
Sebastian Andrzej Siewior7e94dd12011-03-02 11:26:53 +010088 { "ce4100-i2c", REGS_CE4100 },
Eric Miaof23d4912009-04-13 14:43:25 +080089 { },
90};
91MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
92
93/*
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +010094 * I2C bit definitions
Eric Miao283afa02008-09-08 14:15:08 +080095 */
Eric Miao283afa02008-09-08 14:15:08 +080096
97#define ICR_START (1 << 0) /* start bit */
98#define ICR_STOP (1 << 1) /* stop bit */
99#define ICR_ACKNAK (1 << 2) /* send ACK(0) or NAK(1) */
100#define ICR_TB (1 << 3) /* transfer byte bit */
101#define ICR_MA (1 << 4) /* master abort */
102#define ICR_SCLE (1 << 5) /* master clock enable */
103#define ICR_IUE (1 << 6) /* unit enable */
104#define ICR_GCD (1 << 7) /* general call disable */
105#define ICR_ITEIE (1 << 8) /* enable tx interrupts */
106#define ICR_IRFIE (1 << 9) /* enable rx interrupts */
107#define ICR_BEIE (1 << 10) /* enable bus error ints */
108#define ICR_SSDIE (1 << 11) /* slave STOP detected int enable */
109#define ICR_ALDIE (1 << 12) /* enable arbitration interrupt */
110#define ICR_SADIE (1 << 13) /* slave address detected int enable */
111#define ICR_UR (1 << 14) /* unit reset */
112#define ICR_FM (1 << 15) /* fast mode */
Leilei Shang9d3dda52013-06-07 14:38:17 +0800113#define ICR_HS (1 << 16) /* High Speed mode */
114#define ICR_GPIOEN (1 << 19) /* enable GPIO mode for SCL in HS */
Eric Miao283afa02008-09-08 14:15:08 +0800115
116#define ISR_RWM (1 << 0) /* read/write mode */
117#define ISR_ACKNAK (1 << 1) /* ack/nak status */
118#define ISR_UB (1 << 2) /* unit busy */
119#define ISR_IBB (1 << 3) /* bus busy */
120#define ISR_SSD (1 << 4) /* slave stop detected */
121#define ISR_ALD (1 << 5) /* arbitration loss detected */
122#define ISR_ITE (1 << 6) /* tx buffer empty */
123#define ISR_IRF (1 << 7) /* rx buffer full */
124#define ISR_GCAD (1 << 8) /* general call address detected */
125#define ISR_SAD (1 << 9) /* slave address detected */
126#define ISR_BED (1 << 10) /* bus error no ACK/NAK */
Russell Kingb652b432005-06-15 12:38:14 +0100127
128struct pxa_i2c {
129 spinlock_t lock;
130 wait_queue_head_t wait;
131 struct i2c_msg *msg;
132 unsigned int msg_num;
133 unsigned int msg_idx;
134 unsigned int msg_ptr;
135 unsigned int slave_addr;
136
137 struct i2c_adapter adap;
Russell Kingc3cef3f2007-08-20 10:19:10 +0100138 struct clk *clk;
Russell Kingb652b432005-06-15 12:38:14 +0100139#ifdef CONFIG_I2C_PXA_SLAVE
140 struct i2c_slave_client *slave;
141#endif
142
143 unsigned int irqlogidx;
144 u32 isrlog[32];
145 u32 icrlog[32];
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100146
147 void __iomem *reg_base;
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +0100148 void __iomem *reg_ibmr;
149 void __iomem *reg_idbr;
150 void __iomem *reg_icr;
151 void __iomem *reg_isr;
152 void __iomem *reg_isar;
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100153
154 unsigned long iobase;
155 unsigned long iosize;
156
157 int irq;
Jonathan Cameronc46c9482008-10-03 15:07:36 +0100158 unsigned int use_pio :1;
159 unsigned int fast_mode :1;
Leilei Shang9d3dda52013-06-07 14:38:17 +0800160 unsigned int high_mode:1;
161 unsigned char master_code;
162 unsigned long rate;
163 bool highmode_enter;
Russell Kingb652b432005-06-15 12:38:14 +0100164};
165
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +0100166#define _IBMR(i2c) ((i2c)->reg_ibmr)
167#define _IDBR(i2c) ((i2c)->reg_idbr)
168#define _ICR(i2c) ((i2c)->reg_icr)
169#define _ISR(i2c) ((i2c)->reg_isr)
170#define _ISAR(i2c) ((i2c)->reg_isar)
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100171
Russell Kingb652b432005-06-15 12:38:14 +0100172/*
173 * I2C Slave mode address
174 */
175#define I2C_PXA_SLAVE_ADDR 0x1
176
Russell Kingb652b432005-06-15 12:38:14 +0100177#ifdef DEBUG
178
179struct bits {
180 u32 mask;
181 const char *set;
182 const char *unset;
183};
Jiri Slabyed113992007-10-18 23:40:28 -0700184#define PXA_BIT(m, s, u) { .mask = m, .set = s, .unset = u }
Russell Kingb652b432005-06-15 12:38:14 +0100185
186static inline void
187decode_bits(const char *prefix, const struct bits *bits, int num, u32 val)
188{
189 printk("%s %08x: ", prefix, val);
190 while (num--) {
191 const char *str = val & bits->mask ? bits->set : bits->unset;
192 if (str)
193 printk("%s ", str);
194 bits++;
195 }
196}
197
198static const struct bits isr_bits[] = {
Jiri Slabyed113992007-10-18 23:40:28 -0700199 PXA_BIT(ISR_RWM, "RX", "TX"),
200 PXA_BIT(ISR_ACKNAK, "NAK", "ACK"),
201 PXA_BIT(ISR_UB, "Bsy", "Rdy"),
202 PXA_BIT(ISR_IBB, "BusBsy", "BusRdy"),
203 PXA_BIT(ISR_SSD, "SlaveStop", NULL),
204 PXA_BIT(ISR_ALD, "ALD", NULL),
205 PXA_BIT(ISR_ITE, "TxEmpty", NULL),
206 PXA_BIT(ISR_IRF, "RxFull", NULL),
207 PXA_BIT(ISR_GCAD, "GenCall", NULL),
208 PXA_BIT(ISR_SAD, "SlaveAddr", NULL),
209 PXA_BIT(ISR_BED, "BusErr", NULL),
Russell Kingb652b432005-06-15 12:38:14 +0100210};
211
212static void decode_ISR(unsigned int val)
213{
Russell King6fd60fa2005-09-08 21:04:58 +0100214 decode_bits(KERN_DEBUG "ISR", isr_bits, ARRAY_SIZE(isr_bits), val);
Russell Kingb652b432005-06-15 12:38:14 +0100215 printk("\n");
216}
217
218static const struct bits icr_bits[] = {
Jiri Slabyed113992007-10-18 23:40:28 -0700219 PXA_BIT(ICR_START, "START", NULL),
220 PXA_BIT(ICR_STOP, "STOP", NULL),
221 PXA_BIT(ICR_ACKNAK, "ACKNAK", NULL),
222 PXA_BIT(ICR_TB, "TB", NULL),
223 PXA_BIT(ICR_MA, "MA", NULL),
224 PXA_BIT(ICR_SCLE, "SCLE", "scle"),
225 PXA_BIT(ICR_IUE, "IUE", "iue"),
226 PXA_BIT(ICR_GCD, "GCD", NULL),
227 PXA_BIT(ICR_ITEIE, "ITEIE", NULL),
228 PXA_BIT(ICR_IRFIE, "IRFIE", NULL),
229 PXA_BIT(ICR_BEIE, "BEIE", NULL),
230 PXA_BIT(ICR_SSDIE, "SSDIE", NULL),
231 PXA_BIT(ICR_ALDIE, "ALDIE", NULL),
232 PXA_BIT(ICR_SADIE, "SADIE", NULL),
233 PXA_BIT(ICR_UR, "UR", "ur"),
Russell Kingb652b432005-06-15 12:38:14 +0100234};
235
Holger Schurigd6a7b5f2008-02-11 16:51:41 +0100236#ifdef CONFIG_I2C_PXA_SLAVE
Russell Kingb652b432005-06-15 12:38:14 +0100237static void decode_ICR(unsigned int val)
238{
Russell King6fd60fa2005-09-08 21:04:58 +0100239 decode_bits(KERN_DEBUG "ICR", icr_bits, ARRAY_SIZE(icr_bits), val);
Russell Kingb652b432005-06-15 12:38:14 +0100240 printk("\n");
241}
Holger Schurigd6a7b5f2008-02-11 16:51:41 +0100242#endif
Russell Kingb652b432005-06-15 12:38:14 +0100243
244static unsigned int i2c_debug = DEBUG;
245
246static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
247{
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100248 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno,
249 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
Russell Kingb652b432005-06-15 12:38:14 +0100250}
251
Harvey Harrison08882d22008-04-22 22:16:47 +0200252#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
Russell Kingb652b432005-06-15 12:38:14 +0100253
254static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
255{
256 unsigned int i;
Frank Seidel154d22b2009-03-28 21:34:42 +0100257 printk(KERN_ERR "i2c: error: %s\n", why);
258 printk(KERN_ERR "i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
Russell Kingb652b432005-06-15 12:38:14 +0100259 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
Frank Seidel154d22b2009-03-28 21:34:42 +0100260 printk(KERN_ERR "i2c: ICR: %08x ISR: %08x\n",
261 readl(_ICR(i2c)), readl(_ISR(i2c)));
262 printk(KERN_DEBUG "i2c: log: ");
Russell Kingb652b432005-06-15 12:38:14 +0100263 for (i = 0; i < i2c->irqlogidx; i++)
264 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
265 printk("\n");
266}
267
Wolfram Sang0d813d92009-11-03 12:53:41 +0100268#else /* ifdef DEBUG */
269
270#define i2c_debug 0
271
272#define show_state(i2c) do { } while (0)
273#define decode_ISR(val) do { } while (0)
274#define decode_ICR(val) do { } while (0)
275#define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0)
276
277#endif /* ifdef DEBUG / else */
278
279static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
280static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
281
Russell Kingb652b432005-06-15 12:38:14 +0100282static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
283{
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100284 return !(readl(_ICR(i2c)) & ICR_SCLE);
Russell Kingb652b432005-06-15 12:38:14 +0100285}
286
287static void i2c_pxa_abort(struct pxa_i2c *i2c)
288{
Dmitry Baryshkov387fa6a2008-08-18 14:38:48 +0100289 int i = 250;
Russell Kingb652b432005-06-15 12:38:14 +0100290
291 if (i2c_pxa_is_slavemode(i2c)) {
Russell King6fd60fa2005-09-08 21:04:58 +0100292 dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100293 return;
294 }
295
Dmitry Baryshkov387fa6a2008-08-18 14:38:48 +0100296 while ((i > 0) && (readl(_IBMR(i2c)) & 0x1) == 0) {
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100297 unsigned long icr = readl(_ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100298
299 icr &= ~ICR_START;
300 icr |= ICR_ACKNAK | ICR_STOP | ICR_TB;
301
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100302 writel(icr, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100303
304 show_state(i2c);
305
Dmitry Baryshkov387fa6a2008-08-18 14:38:48 +0100306 mdelay(1);
307 i --;
Russell Kingb652b432005-06-15 12:38:14 +0100308 }
309
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100310 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
311 _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100312}
313
314static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
315{
316 int timeout = DEF_TIMEOUT;
317
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100318 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
319 if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
Russell Kingb652b432005-06-15 12:38:14 +0100320 timeout += 4;
321
322 msleep(2);
323 show_state(i2c);
324 }
325
Roel Kluind10db3a2009-04-23 16:27:39 +0200326 if (timeout < 0)
Russell Kingb652b432005-06-15 12:38:14 +0100327 show_state(i2c);
328
Roel Kluind10db3a2009-04-23 16:27:39 +0200329 return timeout < 0 ? I2C_RETRY : 0;
Russell Kingb652b432005-06-15 12:38:14 +0100330}
331
332static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
333{
334 unsigned long timeout = jiffies + HZ*4;
335
336 while (time_before(jiffies, timeout)) {
337 if (i2c_debug > 1)
Russell King6fd60fa2005-09-08 21:04:58 +0100338 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100339 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
Russell Kingb652b432005-06-15 12:38:14 +0100340
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100341 if (readl(_ISR(i2c)) & ISR_SAD) {
Russell Kingb652b432005-06-15 12:38:14 +0100342 if (i2c_debug > 0)
Russell King6fd60fa2005-09-08 21:04:58 +0100343 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100344 goto out;
345 }
346
347 /* wait for unit and bus being not busy, and we also do a
348 * quick check of the i2c lines themselves to ensure they've
349 * gone high...
350 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100351 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && readl(_IBMR(i2c)) == 3) {
Russell Kingb652b432005-06-15 12:38:14 +0100352 if (i2c_debug > 0)
Russell King6fd60fa2005-09-08 21:04:58 +0100353 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100354 return 1;
355 }
356
357 msleep(1);
358 }
359
360 if (i2c_debug > 0)
Russell King6fd60fa2005-09-08 21:04:58 +0100361 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100362 out:
363 return 0;
364}
365
366static int i2c_pxa_set_master(struct pxa_i2c *i2c)
367{
368 if (i2c_debug)
Russell King6fd60fa2005-09-08 21:04:58 +0100369 dev_dbg(&i2c->adap.dev, "setting to bus master\n");
Russell Kingb652b432005-06-15 12:38:14 +0100370
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100371 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) {
Russell King6fd60fa2005-09-08 21:04:58 +0100372 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100373 if (!i2c_pxa_wait_master(i2c)) {
Russell King6fd60fa2005-09-08 21:04:58 +0100374 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100375 return I2C_RETRY;
376 }
377 }
378
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100379 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100380 return 0;
381}
382
383#ifdef CONFIG_I2C_PXA_SLAVE
384static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
385{
386 unsigned long timeout = jiffies + HZ*1;
387
388 /* wait for stop */
389
390 show_state(i2c);
391
392 while (time_before(jiffies, timeout)) {
393 if (i2c_debug > 1)
Russell King6fd60fa2005-09-08 21:04:58 +0100394 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100395 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
Russell Kingb652b432005-06-15 12:38:14 +0100396
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100397 if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 ||
398 (readl(_ISR(i2c)) & ISR_SAD) != 0 ||
399 (readl(_ICR(i2c)) & ICR_SCLE) == 0) {
Russell Kingb652b432005-06-15 12:38:14 +0100400 if (i2c_debug > 1)
Russell King6fd60fa2005-09-08 21:04:58 +0100401 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100402 return 1;
403 }
404
405 msleep(1);
406 }
407
408 if (i2c_debug > 0)
Russell King6fd60fa2005-09-08 21:04:58 +0100409 dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100410 return 0;
411}
412
413/*
414 * clear the hold on the bus, and take of anything else
415 * that has been configured
416 */
417static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
418{
419 show_state(i2c);
420
421 if (errcode < 0) {
422 udelay(100); /* simple delay */
423 } else {
424 /* we need to wait for the stop condition to end */
425
426 /* if we where in stop, then clear... */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100427 if (readl(_ICR(i2c)) & ICR_STOP) {
Russell Kingb652b432005-06-15 12:38:14 +0100428 udelay(100);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100429 writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100430 }
431
432 if (!i2c_pxa_wait_slave(i2c)) {
Russell King6fd60fa2005-09-08 21:04:58 +0100433 dev_err(&i2c->adap.dev, "%s: wait timedout\n",
434 __func__);
Russell Kingb652b432005-06-15 12:38:14 +0100435 return;
436 }
437 }
438
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100439 writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c));
440 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100441
442 if (i2c_debug) {
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100443 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c)));
444 decode_ICR(readl(_ICR(i2c)));
Russell Kingb652b432005-06-15 12:38:14 +0100445 }
446}
447#else
448#define i2c_pxa_set_slave(i2c, err) do { } while (0)
449#endif
450
451static void i2c_pxa_reset(struct pxa_i2c *i2c)
452{
453 pr_debug("Resetting I2C Controller Unit\n");
454
455 /* abort any transfer currently under way */
456 i2c_pxa_abort(i2c);
457
458 /* reset according to 9.8 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100459 writel(ICR_UR, _ICR(i2c));
460 writel(I2C_ISR_INIT, _ISR(i2c));
461 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100462
Sebastian Andrzej Siewior7e94dd12011-03-02 11:26:53 +0100463 if (i2c->reg_isar)
464 writel(i2c->slave_addr, _ISAR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100465
466 /* set control register values */
Jonathan Cameronc46c9482008-10-03 15:07:36 +0100467 writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c));
Leilei Shang9d3dda52013-06-07 14:38:17 +0800468 writel(readl(_ICR(i2c)) | (i2c->high_mode ? ICR_HS : 0), _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100469
470#ifdef CONFIG_I2C_PXA_SLAVE
Russell King6fd60fa2005-09-08 21:04:58 +0100471 dev_info(&i2c->adap.dev, "Enabling slave mode\n");
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100472 writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100473#endif
474
475 i2c_pxa_set_slave(i2c, 0);
476
477 /* enable unit */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100478 writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100479 udelay(100);
480}
481
482
483#ifdef CONFIG_I2C_PXA_SLAVE
484/*
Russell Kingb652b432005-06-15 12:38:14 +0100485 * PXA I2C Slave mode
486 */
487
488static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
489{
490 if (isr & ISR_BED) {
491 /* what should we do here? */
492 } else {
Russell King84b5abe2006-10-28 22:30:17 +0100493 int ret = 0;
494
495 if (i2c->slave != NULL)
496 ret = i2c->slave->read(i2c->slave->data);
Russell Kingb652b432005-06-15 12:38:14 +0100497
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100498 writel(ret, _IDBR(i2c));
499 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */
Russell Kingb652b432005-06-15 12:38:14 +0100500 }
501}
502
503static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
504{
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100505 unsigned int byte = readl(_IDBR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100506
507 if (i2c->slave != NULL)
508 i2c->slave->write(i2c->slave->data, byte);
509
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100510 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100511}
512
513static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
514{
515 int timeout;
516
517 if (i2c_debug > 0)
Russell King6fd60fa2005-09-08 21:04:58 +0100518 dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n",
Russell Kingb652b432005-06-15 12:38:14 +0100519 (isr & ISR_RWM) ? 'r' : 't');
520
521 if (i2c->slave != NULL)
522 i2c->slave->event(i2c->slave->data,
523 (isr & ISR_RWM) ? I2C_SLAVE_EVENT_START_READ : I2C_SLAVE_EVENT_START_WRITE);
524
525 /*
526 * slave could interrupt in the middle of us generating a
527 * start condition... if this happens, we'd better back off
528 * and stop holding the poor thing up
529 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100530 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
531 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100532
533 timeout = 0x10000;
534
535 while (1) {
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100536 if ((readl(_IBMR(i2c)) & 2) == 2)
Russell Kingb652b432005-06-15 12:38:14 +0100537 break;
538
539 timeout--;
540
541 if (timeout <= 0) {
Russell King6fd60fa2005-09-08 21:04:58 +0100542 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
Russell Kingb652b432005-06-15 12:38:14 +0100543 break;
544 }
545 }
546
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100547 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100548}
549
550static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
551{
552 if (i2c_debug > 2)
Russell King6fd60fa2005-09-08 21:04:58 +0100553 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n");
Russell Kingb652b432005-06-15 12:38:14 +0100554
555 if (i2c->slave != NULL)
556 i2c->slave->event(i2c->slave->data, I2C_SLAVE_EVENT_STOP);
557
558 if (i2c_debug > 2)
Russell King6fd60fa2005-09-08 21:04:58 +0100559 dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n");
Russell Kingb652b432005-06-15 12:38:14 +0100560
561 /*
562 * If we have a master-mode message waiting,
563 * kick it off now that the slave has completed.
564 */
565 if (i2c->msg)
566 i2c_pxa_master_complete(i2c, I2C_RETRY);
567}
568#else
569static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
570{
571 if (isr & ISR_BED) {
572 /* what should we do here? */
573 } else {
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100574 writel(0, _IDBR(i2c));
575 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100576 }
577}
578
579static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
580{
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100581 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100582}
583
584static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
585{
586 int timeout;
587
588 /*
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
592 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100593 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
594 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100595
596 timeout = 0x10000;
597
598 while (1) {
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100599 if ((readl(_IBMR(i2c)) & 2) == 2)
Russell Kingb652b432005-06-15 12:38:14 +0100600 break;
601
602 timeout--;
603
604 if (timeout <= 0) {
Russell King6fd60fa2005-09-08 21:04:58 +0100605 dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
Russell Kingb652b432005-06-15 12:38:14 +0100606 break;
607 }
608 }
609
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100610 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100611}
612
613static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
614{
615 if (i2c->msg)
616 i2c_pxa_master_complete(i2c, I2C_RETRY);
617}
618#endif
619
620/*
621 * PXA I2C Master mode
622 */
623
624static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
625{
626 unsigned int addr = (msg->addr & 0x7f) << 1;
627
628 if (msg->flags & I2C_M_RD)
629 addr |= 1;
630
631 return addr;
632}
633
634static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
635{
636 u32 icr;
637
638 /*
639 * Step 1: target slave address into IDBR
640 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100641 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100642
643 /*
644 * Step 2: initiate the write.
645 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100646 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
647 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100648}
649
Jean Delvare7d054812007-05-01 23:26:33 +0200650static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
651{
652 u32 icr;
653
654 /*
655 * Clear the STOP and ACK flags
656 */
657 icr = readl(_ICR(i2c));
658 icr &= ~(ICR_STOP | ICR_ACKNAK);
Russell King0cfe61e2007-05-10 03:15:32 -0700659 writel(icr, _ICR(i2c));
Jean Delvare7d054812007-05-01 23:26:33 +0200660}
661
Mike Rapoportb7a36702008-01-27 18:14:50 +0100662static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
663{
664 /* make timeout the same as for interrupt based functions */
665 long timeout = 2 * DEF_TIMEOUT;
666
667 /*
668 * Wait for the bus to become free.
669 */
670 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
671 udelay(1000);
672 show_state(i2c);
673 }
674
Roel Kluind10db3a2009-04-23 16:27:39 +0200675 if (timeout < 0) {
Mike Rapoportb7a36702008-01-27 18:14:50 +0100676 show_state(i2c);
677 dev_err(&i2c->adap.dev,
678 "i2c_pxa: timeout waiting for bus free\n");
679 return I2C_RETRY;
680 }
681
682 /*
683 * Set master mode.
684 */
685 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
686
687 return 0;
688}
689
Leilei Shang9d3dda52013-06-07 14:38:17 +0800690/*
691 * PXA I2C send master code
692 * 1. Load master code to IDBR and send it.
693 * Note for HS mode, set ICR [GPIOEN].
694 * 2. Wait until win arbitration.
695 */
696static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c)
697{
698 u32 icr;
699 long timeout;
700
701 spin_lock_irq(&i2c->lock);
702 i2c->highmode_enter = true;
703 writel(i2c->master_code, _IDBR(i2c));
704
705 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
706 icr |= ICR_GPIOEN | ICR_START | ICR_TB | ICR_ITEIE;
707 writel(icr, _ICR(i2c));
708
709 spin_unlock_irq(&i2c->lock);
710 timeout = wait_event_timeout(i2c->wait,
711 i2c->highmode_enter == false, HZ * 1);
712
713 i2c->highmode_enter = false;
714
715 return (timeout == 0) ? I2C_RETRY : 0;
716}
717
Mike Rapoportb7a36702008-01-27 18:14:50 +0100718static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
719 struct i2c_msg *msg, int num)
720{
721 unsigned long timeout = 500000; /* 5 seconds */
722 int ret = 0;
723
724 ret = i2c_pxa_pio_set_master(i2c);
725 if (ret)
726 goto out;
727
728 i2c->msg = msg;
729 i2c->msg_num = num;
730 i2c->msg_idx = 0;
731 i2c->msg_ptr = 0;
732 i2c->irqlogidx = 0;
733
734 i2c_pxa_start_message(i2c);
735
Roel Kluina746b572009-02-24 19:19:48 +0100736 while (i2c->msg_num > 0 && --timeout) {
Mike Rapoportb7a36702008-01-27 18:14:50 +0100737 i2c_pxa_handler(0, i2c);
738 udelay(10);
739 }
740
741 i2c_pxa_stop_message(i2c);
742
743 /*
744 * We place the return code in i2c->msg_idx.
745 */
746 ret = i2c->msg_idx;
747
748out:
749 if (timeout == 0)
750 i2c_pxa_scream_blue_murder(i2c, "timeout");
751
752 return ret;
753}
754
Russell Kingb652b432005-06-15 12:38:14 +0100755/*
Jean Delvare3fb9a652006-01-18 23:17:01 +0100756 * We are protected by the adapter bus mutex.
Russell Kingb652b432005-06-15 12:38:14 +0100757 */
758static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
759{
760 long timeout;
761 int ret;
762
763 /*
764 * Wait for the bus to become free.
765 */
766 ret = i2c_pxa_wait_bus_not_busy(i2c);
767 if (ret) {
Russell King6fd60fa2005-09-08 21:04:58 +0100768 dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n");
Russell Kingb652b432005-06-15 12:38:14 +0100769 goto out;
770 }
771
772 /*
773 * Set master mode.
774 */
775 ret = i2c_pxa_set_master(i2c);
776 if (ret) {
Russell King6fd60fa2005-09-08 21:04:58 +0100777 dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret);
Russell Kingb652b432005-06-15 12:38:14 +0100778 goto out;
779 }
780
Leilei Shang9d3dda52013-06-07 14:38:17 +0800781 if (i2c->high_mode) {
782 ret = i2c_pxa_send_mastercode(i2c);
783 if (ret) {
784 dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n");
785 goto out;
786 }
787 }
788
Russell Kingb652b432005-06-15 12:38:14 +0100789 spin_lock_irq(&i2c->lock);
790
791 i2c->msg = msg;
792 i2c->msg_num = num;
793 i2c->msg_idx = 0;
794 i2c->msg_ptr = 0;
795 i2c->irqlogidx = 0;
796
797 i2c_pxa_start_message(i2c);
798
799 spin_unlock_irq(&i2c->lock);
800
801 /*
802 * The rest of the processing occurs in the interrupt handler.
803 */
804 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
Jean Delvare7d054812007-05-01 23:26:33 +0200805 i2c_pxa_stop_message(i2c);
Russell Kingb652b432005-06-15 12:38:14 +0100806
807 /*
808 * We place the return code in i2c->msg_idx.
809 */
810 ret = i2c->msg_idx;
811
Sebastian Andrzej Siewior93c92cf2011-02-23 12:38:19 +0100812 if (!timeout && i2c->msg_num) {
Russell Kingb652b432005-06-15 12:38:14 +0100813 i2c_pxa_scream_blue_murder(i2c, "timeout");
Sebastian Andrzej Siewior93c92cf2011-02-23 12:38:19 +0100814 ret = I2C_RETRY;
815 }
Russell Kingb652b432005-06-15 12:38:14 +0100816
817 out:
818 return ret;
819}
820
Mike Rapoportb7a36702008-01-27 18:14:50 +0100821static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
822 struct i2c_msg msgs[], int num)
823{
824 struct pxa_i2c *i2c = adap->algo_data;
825 int ret, i;
826
827 /* If the I2C controller is disabled we need to reset it
828 (probably due to a suspend/resume destroying state). We do
829 this here as we can then avoid worrying about resuming the
830 controller before its users. */
831 if (!(readl(_ICR(i2c)) & ICR_IUE))
832 i2c_pxa_reset(i2c);
833
834 for (i = adap->retries; i >= 0; i--) {
835 ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
836 if (ret != I2C_RETRY)
837 goto out;
838
839 if (i2c_debug)
840 dev_dbg(&adap->dev, "Retrying transmission\n");
841 udelay(100);
842 }
843 i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
844 ret = -EREMOTEIO;
845 out:
846 i2c_pxa_set_slave(i2c, ret);
847 return ret;
848}
849
Russell Kingb652b432005-06-15 12:38:14 +0100850/*
851 * i2c_pxa_master_complete - complete the message and wake up.
852 */
853static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
854{
855 i2c->msg_ptr = 0;
856 i2c->msg = NULL;
857 i2c->msg_idx ++;
858 i2c->msg_num = 0;
859 if (ret)
860 i2c->msg_idx = ret;
Mike Rapoportb7a36702008-01-27 18:14:50 +0100861 if (!i2c->use_pio)
862 wake_up(&i2c->wait);
Russell Kingb652b432005-06-15 12:38:14 +0100863}
864
865static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
866{
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100867 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
Russell Kingb652b432005-06-15 12:38:14 +0100868
869 again:
870 /*
871 * If ISR_ALD is set, we lost arbitration.
872 */
873 if (isr & ISR_ALD) {
874 /*
875 * Do we need to do anything here? The PXA docs
876 * are vague about what happens.
877 */
878 i2c_pxa_scream_blue_murder(i2c, "ALD set");
879
880 /*
881 * We ignore this error. We seem to see spurious ALDs
882 * for seemingly no reason. If we handle them as I think
883 * they should, we end up causing an I2C error, which
884 * is painful for some systems.
885 */
886 return; /* ignore */
887 }
888
889 if (isr & ISR_BED) {
890 int ret = BUS_ERROR;
891
892 /*
893 * I2C bus error - either the device NAK'd us, or
894 * something more serious happened. If we were NAK'd
895 * on the initial address phase, we can retry.
896 */
897 if (isr & ISR_ACKNAK) {
898 if (i2c->msg_ptr == 0 && i2c->msg_idx == 0)
899 ret = I2C_RETRY;
900 else
901 ret = XFER_NAKED;
902 }
903 i2c_pxa_master_complete(i2c, ret);
904 } else if (isr & ISR_RWM) {
905 /*
906 * Read mode. We have just sent the address byte, and
907 * now we must initiate the transfer.
908 */
909 if (i2c->msg_ptr == i2c->msg->len - 1 &&
910 i2c->msg_idx == i2c->msg_num - 1)
911 icr |= ICR_STOP | ICR_ACKNAK;
912
913 icr |= ICR_ALDIE | ICR_TB;
914 } else if (i2c->msg_ptr < i2c->msg->len) {
915 /*
916 * Write mode. Write the next data byte.
917 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100918 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100919
920 icr |= ICR_ALDIE | ICR_TB;
921
922 /*
923 * If this is the last byte of the last message, send
924 * a STOP.
925 */
926 if (i2c->msg_ptr == i2c->msg->len &&
927 i2c->msg_idx == i2c->msg_num - 1)
928 icr |= ICR_STOP;
929 } else if (i2c->msg_idx < i2c->msg_num - 1) {
930 /*
931 * Next segment of the message.
932 */
933 i2c->msg_ptr = 0;
934 i2c->msg_idx ++;
935 i2c->msg++;
936
937 /*
938 * If we aren't doing a repeated start and address,
939 * go back and try to send the next byte. Note that
940 * we do not support switching the R/W direction here.
941 */
942 if (i2c->msg->flags & I2C_M_NOSTART)
943 goto again;
944
945 /*
946 * Write the next address.
947 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100948 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100949
950 /*
951 * And trigger a repeated start, and send the byte.
952 */
953 icr &= ~ICR_ALDIE;
954 icr |= ICR_START | ICR_TB;
955 } else {
956 if (i2c->msg->len == 0) {
957 /*
958 * Device probes have a message length of zero
959 * and need the bus to be reset before it can
960 * be used again.
961 */
962 i2c_pxa_reset(i2c);
963 }
964 i2c_pxa_master_complete(i2c, 0);
965 }
966
967 i2c->icrlog[i2c->irqlogidx-1] = icr;
968
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100969 writel(icr, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100970 show_state(i2c);
971}
972
973static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
974{
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100975 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
Russell Kingb652b432005-06-15 12:38:14 +0100976
977 /*
978 * Read the byte.
979 */
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100980 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100981
982 if (i2c->msg_ptr < i2c->msg->len) {
983 /*
984 * If this is the last byte of the last
985 * message, send a STOP.
986 */
987 if (i2c->msg_ptr == i2c->msg->len - 1)
988 icr |= ICR_STOP | ICR_ACKNAK;
989
990 icr |= ICR_ALDIE | ICR_TB;
991 } else {
992 i2c_pxa_master_complete(i2c, 0);
993 }
994
995 i2c->icrlog[i2c->irqlogidx-1] = icr;
996
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +0100997 writel(icr, _ICR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +0100998}
999
Sebastian Andrzej Siewiorc66dc522011-02-23 12:38:18 +01001000#define VALID_INT_SOURCE (ISR_SSD | ISR_ALD | ISR_ITE | ISR_IRF | \
1001 ISR_SAD | ISR_BED)
David Howells7d12e782006-10-05 14:55:46 +01001002static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
Russell Kingb652b432005-06-15 12:38:14 +01001003{
1004 struct pxa_i2c *i2c = dev_id;
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001005 u32 isr = readl(_ISR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +01001006
Vasily Khoruzhick97491ba2011-03-13 15:53:29 +02001007 if (!(isr & VALID_INT_SOURCE))
Sebastian Andrzej Siewiorc66dc522011-02-23 12:38:18 +01001008 return IRQ_NONE;
1009
Russell Kingb652b432005-06-15 12:38:14 +01001010 if (i2c_debug > 2 && 0) {
Russell King6fd60fa2005-09-08 21:04:58 +01001011 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001012 __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
Russell Kingb652b432005-06-15 12:38:14 +01001013 decode_ISR(isr);
1014 }
1015
Tobias Klauser7e3d7db2006-01-09 23:19:51 +01001016 if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog))
Russell Kingb652b432005-06-15 12:38:14 +01001017 i2c->isrlog[i2c->irqlogidx++] = isr;
1018
1019 show_state(i2c);
1020
1021 /*
1022 * Always clear all pending IRQs.
1023 */
Vasily Khoruzhick97491ba2011-03-13 15:53:29 +02001024 writel(isr & VALID_INT_SOURCE, _ISR(i2c));
Russell Kingb652b432005-06-15 12:38:14 +01001025
1026 if (isr & ISR_SAD)
1027 i2c_pxa_slave_start(i2c, isr);
1028 if (isr & ISR_SSD)
1029 i2c_pxa_slave_stop(i2c);
1030
1031 if (i2c_pxa_is_slavemode(i2c)) {
1032 if (isr & ISR_ITE)
1033 i2c_pxa_slave_txempty(i2c, isr);
1034 if (isr & ISR_IRF)
1035 i2c_pxa_slave_rxfull(i2c, isr);
Leilei Shang9d3dda52013-06-07 14:38:17 +08001036 } else if (i2c->msg && (!i2c->highmode_enter)) {
Russell Kingb652b432005-06-15 12:38:14 +01001037 if (isr & ISR_ITE)
1038 i2c_pxa_irq_txempty(i2c, isr);
1039 if (isr & ISR_IRF)
1040 i2c_pxa_irq_rxfull(i2c, isr);
Leilei Shang9d3dda52013-06-07 14:38:17 +08001041 } else if ((isr & ISR_ITE) && i2c->highmode_enter) {
1042 i2c->highmode_enter = false;
1043 wake_up(&i2c->wait);
Russell Kingb652b432005-06-15 12:38:14 +01001044 } else {
1045 i2c_pxa_scream_blue_murder(i2c, "spurious irq");
1046 }
1047
1048 return IRQ_HANDLED;
1049}
1050
1051
1052static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
1053{
1054 struct pxa_i2c *i2c = adap->algo_data;
1055 int ret, i;
1056
1057 for (i = adap->retries; i >= 0; i--) {
1058 ret = i2c_pxa_do_xfer(i2c, msgs, num);
1059 if (ret != I2C_RETRY)
1060 goto out;
1061
1062 if (i2c_debug)
Russell King6fd60fa2005-09-08 21:04:58 +01001063 dev_dbg(&adap->dev, "Retrying transmission\n");
Russell Kingb652b432005-06-15 12:38:14 +01001064 udelay(100);
1065 }
1066 i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
1067 ret = -EREMOTEIO;
1068 out:
1069 i2c_pxa_set_slave(i2c, ret);
1070 return ret;
1071}
1072
Russell Kingda16e322005-09-14 22:54:45 +01001073static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
1074{
1075 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
1076}
1077
Jean Delvare8f9082c2006-09-03 22:39:46 +02001078static const struct i2c_algorithm i2c_pxa_algorithm = {
Russell Kingb652b432005-06-15 12:38:14 +01001079 .master_xfer = i2c_pxa_xfer,
Russell Kingda16e322005-09-14 22:54:45 +01001080 .functionality = i2c_pxa_functionality,
Russell Kingb652b432005-06-15 12:38:14 +01001081};
1082
Mike Rapoportb7a36702008-01-27 18:14:50 +01001083static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
1084 .master_xfer = i2c_pxa_pio_xfer,
1085 .functionality = i2c_pxa_functionality,
1086};
1087
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001088static struct of_device_id i2c_pxa_dt_ids[] = {
1089 { .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX },
1090 { .compatible = "mrvl,pwri2c", .data = (void *)REGS_PXA3XX },
1091 { .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA2XX },
1092 {}
1093};
1094MODULE_DEVICE_TABLE(of, i2c_pxa_dt_ids);
1095
1096static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
1097 enum pxa_i2c_types *i2c_types)
1098{
1099 struct device_node *np = pdev->dev.of_node;
1100 const struct of_device_id *of_id =
1101 of_match_device(i2c_pxa_dt_ids, &pdev->dev);
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001102
1103 if (!of_id)
1104 return 1;
Doug Andersonfe69c552013-03-01 06:57:32 +00001105
1106 /* For device tree we always use the dynamic or alias-assigned ID */
1107 i2c->adap.nr = -1;
1108
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001109 if (of_get_property(np, "mrvl,i2c-polling", NULL))
1110 i2c->use_pio = 1;
1111 if (of_get_property(np, "mrvl,i2c-fast-mode", NULL))
1112 i2c->fast_mode = 1;
1113 *i2c_types = (u32)(of_id->data);
1114 return 0;
1115}
1116
1117static int i2c_pxa_probe_pdata(struct platform_device *pdev,
1118 struct pxa_i2c *i2c,
1119 enum pxa_i2c_types *i2c_types)
1120{
1121 struct i2c_pxa_platform_data *plat = pdev->dev.platform_data;
1122 const struct platform_device_id *id = platform_get_device_id(pdev);
1123
1124 *i2c_types = id->driver_data;
1125 if (plat) {
1126 i2c->use_pio = plat->use_pio;
1127 i2c->fast_mode = plat->fast_mode;
Leilei Shang9d3dda52013-06-07 14:38:17 +08001128 i2c->high_mode = plat->high_mode;
1129 i2c->master_code = plat->master_code;
1130 if (!i2c->master_code)
1131 i2c->master_code = 0xe;
1132 i2c->rate = plat->rate;
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001133 }
1134 return 0;
1135}
1136
Russell King3ae5eae2005-11-09 22:32:44 +00001137static int i2c_pxa_probe(struct platform_device *dev)
Russell Kingb652b432005-06-15 12:38:14 +01001138{
Russell King3ae5eae2005-11-09 22:32:44 +00001139 struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001140 enum pxa_i2c_types i2c_type;
1141 struct pxa_i2c *i2c;
1142 struct resource *res = NULL;
1143 int ret, irq;
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001144
Enrico Scholz6776f3d2007-05-21 12:29:40 +01001145 i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001146 if (!i2c) {
1147 ret = -ENOMEM;
1148 goto emalloc;
1149 }
1150
Doug Andersonfe69c552013-03-01 06:57:32 +00001151 /* Default adapter num to device id; i2c_pxa_probe_dt can override. */
1152 i2c->adap.nr = dev->id;
1153
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001154 ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type);
1155 if (ret > 0)
1156 ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
1157 if (ret < 0)
1158 goto eclk;
1159
1160 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
1161 irq = platform_get_irq(dev, 0);
1162 if (res == NULL || irq < 0) {
1163 ret = -ENODEV;
1164 goto eclk;
1165 }
1166
1167 if (!request_mem_region(res->start, resource_size(res), res->name)) {
1168 ret = -ENOMEM;
1169 goto eclk;
1170 }
1171
Enrico Scholz6776f3d2007-05-21 12:29:40 +01001172 i2c->adap.owner = THIS_MODULE;
Enrico Scholz6776f3d2007-05-21 12:29:40 +01001173 i2c->adap.retries = 5;
1174
1175 spin_lock_init(&i2c->lock);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001176 init_waitqueue_head(&i2c->wait);
Enrico Scholz6776f3d2007-05-21 12:29:40 +01001177
Doug Andersonfe69c552013-03-01 06:57:32 +00001178 strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name));
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001179
Russell Kinge0d8b132008-11-11 17:52:32 +00001180 i2c->clk = clk_get(&dev->dev, NULL);
Russell Kingc3cef3f2007-08-20 10:19:10 +01001181 if (IS_ERR(i2c->clk)) {
1182 ret = PTR_ERR(i2c->clk);
1183 goto eclk;
1184 }
1185
Linus Walleijc6ffdde2009-06-14 00:20:36 +02001186 i2c->reg_base = ioremap(res->start, resource_size(res));
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001187 if (!i2c->reg_base) {
1188 ret = -EIO;
1189 goto eremap;
1190 }
Sebastian Andrzej Siewiord6668c72011-02-23 12:38:15 +01001191
1192 i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
1193 i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
1194 i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr;
1195 i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr;
Sebastian Andrzej Siewior7e94dd12011-03-02 11:26:53 +01001196 if (i2c_type != REGS_CE4100)
1197 i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar;
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001198
1199 i2c->iobase = res->start;
Linus Walleijc6ffdde2009-06-14 00:20:36 +02001200 i2c->iosize = resource_size(res);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001201
1202 i2c->irq = irq;
Russell Kingb652b432005-06-15 12:38:14 +01001203
1204 i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
Leilei Shang9d3dda52013-06-07 14:38:17 +08001205 i2c->highmode_enter = false;
Russell Kingb652b432005-06-15 12:38:14 +01001206
Russell Kingb652b432005-06-15 12:38:14 +01001207 if (plat) {
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001208#ifdef CONFIG_I2C_PXA_SLAVE
Russell Kingb652b432005-06-15 12:38:14 +01001209 i2c->slave_addr = plat->slave_addr;
Russell Kingbeea4942006-11-07 21:03:20 +00001210 i2c->slave = plat->slave;
Russell Kingb652b432005-06-15 12:38:14 +01001211#endif
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001212 i2c->adap.class = plat->class;
1213 }
Russell Kingb652b432005-06-15 12:38:14 +01001214
Leilei Shang9d3dda52013-06-07 14:38:17 +08001215 if (i2c->high_mode) {
1216 if (i2c->rate) {
1217 clk_set_rate(i2c->clk, i2c->rate);
1218 pr_info("i2c: <%s> set rate to %ld\n",
1219 i2c->adap.name, clk_get_rate(i2c->clk));
1220 } else
1221 pr_warn("i2c: <%s> clock rate not set\n",
1222 i2c->adap.name);
1223 }
1224
Daniel Drake7a10f472013-06-17 11:30:36 -04001225 clk_prepare_enable(i2c->clk);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001226
Mike Rapoportb7a36702008-01-27 18:14:50 +01001227 if (i2c->use_pio) {
1228 i2c->adap.algo = &i2c_pxa_pio_algorithm;
1229 } else {
1230 i2c->adap.algo = &i2c_pxa_algorithm;
Sebastian Andrzej Siewiorc66dc522011-02-23 12:38:18 +01001231 ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
Doug Andersonfe69c552013-03-01 06:57:32 +00001232 dev_name(&dev->dev), i2c);
Mike Rapoportb7a36702008-01-27 18:14:50 +01001233 if (ret)
1234 goto ereqirq;
1235 }
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001236
Russell Kingb652b432005-06-15 12:38:14 +01001237 i2c_pxa_reset(i2c);
1238
1239 i2c->adap.algo_data = i2c;
Russell King3ae5eae2005-11-09 22:32:44 +00001240 i2c->adap.dev.parent = &dev->dev;
Sebastian Andrzej Siewiorbaa8cab2011-02-23 12:38:20 +01001241#ifdef CONFIG_OF
1242 i2c->adap.dev.of_node = dev->dev.of_node;
1243#endif
Russell Kingb652b432005-06-15 12:38:14 +01001244
Grant Likely488bf312011-07-25 17:49:43 +02001245 ret = i2c_add_numbered_adapter(&i2c->adap);
Russell Kingb652b432005-06-15 12:38:14 +01001246 if (ret < 0) {
1247 printk(KERN_INFO "I2C: Failed to add bus\n");
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001248 goto eadapt;
Russell Kingb652b432005-06-15 12:38:14 +01001249 }
Sebastian Andrzej Siewiorbaa8cab2011-02-23 12:38:20 +01001250 of_i2c_register_devices(&i2c->adap);
Russell Kingb652b432005-06-15 12:38:14 +01001251
Russell King3ae5eae2005-11-09 22:32:44 +00001252 platform_set_drvdata(dev, i2c);
Russell Kingb652b432005-06-15 12:38:14 +01001253
1254#ifdef CONFIG_I2C_PXA_SLAVE
1255 printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n",
Jean Delvare22e965c2009-01-07 14:29:16 +01001256 dev_name(&i2c->adap.dev), i2c->slave_addr);
Russell Kingb652b432005-06-15 12:38:14 +01001257#else
1258 printk(KERN_INFO "I2C: %s: PXA I2C adapter\n",
Jean Delvare22e965c2009-01-07 14:29:16 +01001259 dev_name(&i2c->adap.dev));
Russell Kingb652b432005-06-15 12:38:14 +01001260#endif
1261 return 0;
1262
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001263eadapt:
Mike Rapoportb7a36702008-01-27 18:14:50 +01001264 if (!i2c->use_pio)
1265 free_irq(irq, i2c);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001266ereqirq:
Daniel Drake7a10f472013-06-17 11:30:36 -04001267 clk_disable_unprepare(i2c->clk);
Wolfram Sanga92b36e2008-02-24 20:03:42 +01001268 iounmap(i2c->reg_base);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001269eremap:
Russell Kingc3cef3f2007-08-20 10:19:10 +01001270 clk_put(i2c->clk);
1271eclk:
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001272 kfree(i2c);
1273emalloc:
Linus Walleijc6ffdde2009-06-14 00:20:36 +02001274 release_mem_region(res->start, resource_size(res));
Russell Kingb652b432005-06-15 12:38:14 +01001275 return ret;
1276}
1277
Dmitry Torokhov0a6d2242013-02-19 22:50:10 +00001278static int i2c_pxa_remove(struct platform_device *dev)
Russell Kingb652b432005-06-15 12:38:14 +01001279{
Russell King3ae5eae2005-11-09 22:32:44 +00001280 struct pxa_i2c *i2c = platform_get_drvdata(dev);
Russell Kingb652b432005-06-15 12:38:14 +01001281
Russell Kingb652b432005-06-15 12:38:14 +01001282 i2c_del_adapter(&i2c->adap);
Mike Rapoportb7a36702008-01-27 18:14:50 +01001283 if (!i2c->use_pio)
1284 free_irq(i2c->irq, i2c);
Russell Kingc3cef3f2007-08-20 10:19:10 +01001285
Daniel Drake7a10f472013-06-17 11:30:36 -04001286 clk_disable_unprepare(i2c->clk);
Russell Kingc3cef3f2007-08-20 10:19:10 +01001287 clk_put(i2c->clk);
Russell Kingc3cef3f2007-08-20 10:19:10 +01001288
Wolfram Sanga92b36e2008-02-24 20:03:42 +01001289 iounmap(i2c->reg_base);
Guennadi Liakhovetskia7b4e552007-02-08 09:43:26 +01001290 release_mem_region(i2c->iobase, i2c->iosize);
1291 kfree(i2c);
Russell Kingb652b432005-06-15 12:38:14 +01001292
1293 return 0;
1294}
1295
Russell Kinge7d48fa2008-08-26 10:40:50 +01001296#ifdef CONFIG_PM
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001297static int i2c_pxa_suspend_noirq(struct device *dev)
Russell Kinge7d48fa2008-08-26 10:40:50 +01001298{
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001299 struct platform_device *pdev = to_platform_device(dev);
1300 struct pxa_i2c *i2c = platform_get_drvdata(pdev);
1301
Russell Kinge7d48fa2008-08-26 10:40:50 +01001302 clk_disable(i2c->clk);
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001303
Russell Kinge7d48fa2008-08-26 10:40:50 +01001304 return 0;
1305}
1306
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001307static int i2c_pxa_resume_noirq(struct device *dev)
Russell Kinge7d48fa2008-08-26 10:40:50 +01001308{
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001309 struct platform_device *pdev = to_platform_device(dev);
1310 struct pxa_i2c *i2c = platform_get_drvdata(pdev);
Russell Kinge7d48fa2008-08-26 10:40:50 +01001311
1312 clk_enable(i2c->clk);
1313 i2c_pxa_reset(i2c);
1314
1315 return 0;
1316}
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001317
Alexey Dobriyan47145212009-12-14 18:00:08 -08001318static const struct dev_pm_ops i2c_pxa_dev_pm_ops = {
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001319 .suspend_noirq = i2c_pxa_suspend_noirq,
1320 .resume_noirq = i2c_pxa_resume_noirq,
1321};
1322
1323#define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops)
Russell Kinge7d48fa2008-08-26 10:40:50 +01001324#else
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001325#define I2C_PXA_DEV_PM_OPS NULL
Russell Kinge7d48fa2008-08-26 10:40:50 +01001326#endif
1327
Russell King3ae5eae2005-11-09 22:32:44 +00001328static struct platform_driver i2c_pxa_driver = {
Russell Kingb652b432005-06-15 12:38:14 +01001329 .probe = i2c_pxa_probe,
Dmitry Torokhov0a6d2242013-02-19 22:50:10 +00001330 .remove = i2c_pxa_remove,
Russell King3ae5eae2005-11-09 22:32:44 +00001331 .driver = {
1332 .name = "pxa2xx-i2c",
Wolfram Sanga92b36e2008-02-24 20:03:42 +01001333 .owner = THIS_MODULE,
Magnus Damm57f4d4f2009-07-08 13:22:39 +02001334 .pm = I2C_PXA_DEV_PM_OPS,
Haojian Zhuang63fe1222012-03-01 13:04:44 +08001335 .of_match_table = i2c_pxa_dt_ids,
Russell King3ae5eae2005-11-09 22:32:44 +00001336 },
Eric Miaof23d4912009-04-13 14:43:25 +08001337 .id_table = i2c_pxa_id_table,
Russell Kingb652b432005-06-15 12:38:14 +01001338};
1339
1340static int __init i2c_adap_pxa_init(void)
1341{
Russell King3ae5eae2005-11-09 22:32:44 +00001342 return platform_driver_register(&i2c_pxa_driver);
Russell Kingb652b432005-06-15 12:38:14 +01001343}
1344
Wolfram Sanga92b36e2008-02-24 20:03:42 +01001345static void __exit i2c_adap_pxa_exit(void)
Russell Kingb652b432005-06-15 12:38:14 +01001346{
Holger Schurigd6a7b5f2008-02-11 16:51:41 +01001347 platform_driver_unregister(&i2c_pxa_driver);
Russell Kingb652b432005-06-15 12:38:14 +01001348}
1349
Richard Purdieece5f7b2006-01-12 16:30:23 +00001350MODULE_LICENSE("GPL");
Kay Sieversadd8eda2008-04-22 22:16:49 +02001351MODULE_ALIAS("platform:pxa2xx-i2c");
Richard Purdieece5f7b2006-01-12 16:30:23 +00001352
Uli Luckas47a9b132008-07-14 22:38:30 +02001353subsys_initcall(i2c_adap_pxa_init);
Russell Kingb652b432005-06-15 12:38:14 +01001354module_exit(i2c_adap_pxa_exit);