blob: 9d797561de5fe0eabf56641a5e291c901819fa2b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/drivers/i2c/busses/i2c-s3c2410.c
2 *
3 * Copyright (C) 2004,2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * S3C2410 I2C Controller
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel.h>
24#include <linux/module.h>
25
26#include <linux/i2c.h>
27#include <linux/i2c-id.h>
28#include <linux/init.h>
29#include <linux/time.h>
30#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/delay.h>
32#include <linux/errno.h>
33#include <linux/err.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010034#include <linux/platform_device.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000035#include <linux/clk.h>
Ben Dooks61c7cff2008-07-28 12:04:07 +010036#include <linux/cpufreq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/irq.h>
39#include <asm/io.h>
40
Ben Dooks9498cb72008-10-30 10:14:33 +000041#include <plat/regs-iic.h>
42#include <plat/iic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* i2c controller state */
45
46enum s3c24xx_i2c_state {
47 STATE_IDLE,
48 STATE_START,
49 STATE_READ,
50 STATE_WRITE,
51 STATE_STOP
52};
53
54struct s3c24xx_i2c {
55 spinlock_t lock;
56 wait_queue_head_t wait;
Ben Dooksbe44f012008-10-31 16:10:22 +000057 unsigned int suspended:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 struct i2c_msg *msg;
60 unsigned int msg_num;
61 unsigned int msg_idx;
62 unsigned int msg_ptr;
63
Ben Dookse00a8cd2007-05-01 23:26:35 +020064 unsigned int tx_setup;
Ben Dookse0d1ec92008-10-31 16:10:30 +000065 unsigned int irq;
Ben Dookse00a8cd2007-05-01 23:26:35 +020066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 enum s3c24xx_i2c_state state;
Ben Dooks61c7cff2008-07-28 12:04:07 +010068 unsigned long clkrate;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 void __iomem *regs;
71 struct clk *clk;
72 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 struct resource *ioarea;
74 struct i2c_adapter adap;
Ben Dooks61c7cff2008-07-28 12:04:07 +010075
76#ifdef CONFIG_CPU_FREQ
77 struct notifier_block freq_transition;
78#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070079};
80
Ben Dooks6a039ca2008-10-31 16:10:27 +000081/* default platform data removed, dev should always carry data. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/* s3c24xx_i2c_is2440()
84 *
85 * return true is this is an s3c2440
86*/
87
88static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c)
89{
90 struct platform_device *pdev = to_platform_device(i2c->dev);
91
92 return !strcmp(pdev->name, "s3c2440-i2c");
93}
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/* s3c24xx_i2c_master_complete
96 *
97 * complete the message and wake up the caller, using the given return code,
98 * or zero to mean ok.
99*/
100
101static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret)
102{
103 dev_dbg(i2c->dev, "master_complete %d\n", ret);
104
105 i2c->msg_ptr = 0;
106 i2c->msg = NULL;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000107 i2c->msg_idx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 i2c->msg_num = 0;
109 if (ret)
110 i2c->msg_idx = ret;
111
112 wake_up(&i2c->wait);
113}
114
115static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c)
116{
117 unsigned long tmp;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 tmp = readl(i2c->regs + S3C2410_IICCON);
120 writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
123static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c)
124{
125 unsigned long tmp;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 tmp = readl(i2c->regs + S3C2410_IICCON);
128 writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131/* irq enable/disable functions */
132
133static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c)
134{
135 unsigned long tmp;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 tmp = readl(i2c->regs + S3C2410_IICCON);
138 writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
139}
140
141static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c)
142{
143 unsigned long tmp;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 tmp = readl(i2c->regs + S3C2410_IICCON);
146 writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
147}
148
149
150/* s3c24xx_i2c_message_start
151 *
Ben Dooks3d0911b2008-10-31 16:10:24 +0000152 * put the start of a message onto the bus
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153*/
154
Ben Dooks3d0911b2008-10-31 16:10:24 +0000155static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 struct i2c_msg *msg)
157{
158 unsigned int addr = (msg->addr & 0x7f) << 1;
159 unsigned long stat;
160 unsigned long iiccon;
161
162 stat = 0;
163 stat |= S3C2410_IICSTAT_TXRXEN;
164
165 if (msg->flags & I2C_M_RD) {
166 stat |= S3C2410_IICSTAT_MASTER_RX;
167 addr |= 1;
168 } else
169 stat |= S3C2410_IICSTAT_MASTER_TX;
170
171 if (msg->flags & I2C_M_REV_DIR_ADDR)
172 addr ^= 1;
173
Ben Dooks3d0911b2008-10-31 16:10:24 +0000174 /* todo - check for wether ack wanted or not */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 s3c24xx_i2c_enable_ack(i2c);
176
177 iiccon = readl(i2c->regs + S3C2410_IICCON);
178 writel(stat, i2c->regs + S3C2410_IICSTAT);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
181 writeb(addr, i2c->regs + S3C2410_IICDS);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000182
Ben Dookse00a8cd2007-05-01 23:26:35 +0200183 /* delay here to ensure the data byte has gotten onto the bus
184 * before the transaction is started */
185
186 ndelay(i2c->tx_setup);
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
189 writel(iiccon, i2c->regs + S3C2410_IICCON);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000190
191 stat |= S3C2410_IICSTAT_START;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 writel(stat, i2c->regs + S3C2410_IICSTAT);
193}
194
195static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret)
196{
197 unsigned long iicstat = readl(i2c->regs + S3C2410_IICSTAT);
198
199 dev_dbg(i2c->dev, "STOP\n");
200
201 /* stop the transfer */
Ben Dooks3d0911b2008-10-31 16:10:24 +0000202 iicstat &= ~S3C2410_IICSTAT_START;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 writel(iicstat, i2c->regs + S3C2410_IICSTAT);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 i2c->state = STATE_STOP;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 s3c24xx_i2c_master_complete(i2c, ret);
208 s3c24xx_i2c_disable_irq(i2c);
209}
210
211/* helper functions to determine the current state in the set of
212 * messages we are sending */
213
214/* is_lastmsg()
215 *
Ben Dooks3d0911b2008-10-31 16:10:24 +0000216 * returns TRUE if the current message is the last in the set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217*/
218
219static inline int is_lastmsg(struct s3c24xx_i2c *i2c)
220{
221 return i2c->msg_idx >= (i2c->msg_num - 1);
222}
223
224/* is_msglast
225 *
226 * returns TRUE if we this is the last byte in the current message
227*/
228
229static inline int is_msglast(struct s3c24xx_i2c *i2c)
230{
231 return i2c->msg_ptr == i2c->msg->len-1;
232}
233
234/* is_msgend
235 *
236 * returns TRUE if we reached the end of the current message
237*/
238
239static inline int is_msgend(struct s3c24xx_i2c *i2c)
240{
241 return i2c->msg_ptr >= i2c->msg->len;
242}
243
244/* i2s_s3c_irq_nextbyte
245 *
246 * process an interrupt and work out what to do
247 */
248
249static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
250{
251 unsigned long tmp;
252 unsigned char byte;
253 int ret = 0;
254
255 switch (i2c->state) {
256
257 case STATE_IDLE:
Harvey Harrison08882d22008-04-22 22:16:47 +0200258 dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 goto out;
260 break;
261
262 case STATE_STOP:
Harvey Harrison08882d22008-04-22 22:16:47 +0200263 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000264 s3c24xx_i2c_disable_irq(i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 goto out_ack;
266
267 case STATE_START:
268 /* last thing we did was send a start condition on the
269 * bus, or started a new i2c message
270 */
Ben Dooks3d0911b2008-10-31 16:10:24 +0000271
Ben Dooks63f5c282008-07-01 11:59:42 +0100272 if (iicstat & S3C2410_IICSTAT_LASTBIT &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
274 /* ack was not received... */
275
276 dev_dbg(i2c->dev, "ack was not received\n");
Ben Dooks63f5c282008-07-01 11:59:42 +0100277 s3c24xx_i2c_stop(i2c, -ENXIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 goto out_ack;
279 }
280
281 if (i2c->msg->flags & I2C_M_RD)
282 i2c->state = STATE_READ;
283 else
284 i2c->state = STATE_WRITE;
285
286 /* terminate the transfer if there is nothing to do
Ben Dooks63f5c282008-07-01 11:59:42 +0100287 * as this is used by the i2c probe to find devices. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 if (is_lastmsg(i2c) && i2c->msg->len == 0) {
290 s3c24xx_i2c_stop(i2c, 0);
291 goto out_ack;
292 }
293
294 if (i2c->state == STATE_READ)
295 goto prepare_read;
296
Ben Dooks3d0911b2008-10-31 16:10:24 +0000297 /* fall through to the write state, as we will need to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 * send a byte as well */
299
300 case STATE_WRITE:
301 /* we are writing data to the device... check for the
302 * end of the message, and if so, work out what to do
303 */
304
Ben Dooks27097812008-07-01 11:59:41 +0100305 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
306 if (iicstat & S3C2410_IICSTAT_LASTBIT) {
307 dev_dbg(i2c->dev, "WRITE: No Ack\n");
308
309 s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
310 goto out_ack;
311 }
312 }
313
Ben Dooks3d0911b2008-10-31 16:10:24 +0000314 retry_write:
Ben Dooks27097812008-07-01 11:59:41 +0100315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (!is_msgend(i2c)) {
317 byte = i2c->msg->buf[i2c->msg_ptr++];
318 writeb(byte, i2c->regs + S3C2410_IICDS);
Ben Dookse00a8cd2007-05-01 23:26:35 +0200319
320 /* delay after writing the byte to allow the
321 * data setup time on the bus, as writing the
322 * data to the register causes the first bit
323 * to appear on SDA, and SCL will change as
324 * soon as the interrupt is acknowledged */
325
326 ndelay(i2c->tx_setup);
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 } else if (!is_lastmsg(i2c)) {
329 /* we need to go to the next i2c message */
330
331 dev_dbg(i2c->dev, "WRITE: Next Message\n");
332
333 i2c->msg_ptr = 0;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000334 i2c->msg_idx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 i2c->msg++;
Ben Dooks3d0911b2008-10-31 16:10:24 +0000336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 /* check to see if we need to do another message */
338 if (i2c->msg->flags & I2C_M_NOSTART) {
339
340 if (i2c->msg->flags & I2C_M_RD) {
341 /* cannot do this, the controller
342 * forces us to send a new START
343 * when we change direction */
344
345 s3c24xx_i2c_stop(i2c, -EINVAL);
346 }
347
348 goto retry_write;
349 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /* send the new start */
351 s3c24xx_i2c_message_start(i2c, i2c->msg);
352 i2c->state = STATE_START;
353 }
354
355 } else {
356 /* send stop */
357
358 s3c24xx_i2c_stop(i2c, 0);
359 }
360 break;
361
362 case STATE_READ:
Ben Dooks3d0911b2008-10-31 16:10:24 +0000363 /* we have a byte of data in the data register, do
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * something with it, and then work out wether we are
365 * going to do any more read/write
366 */
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 byte = readb(i2c->regs + S3C2410_IICDS);
369 i2c->msg->buf[i2c->msg_ptr++] = byte;
370
Ben Dooks3d0911b2008-10-31 16:10:24 +0000371 prepare_read:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (is_msglast(i2c)) {
373 /* last byte of buffer */
374
375 if (is_lastmsg(i2c))
376 s3c24xx_i2c_disable_ack(i2c);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 } else if (is_msgend(i2c)) {
379 /* ok, we've read the entire buffer, see if there
380 * is anything else we need to do */
381
382 if (is_lastmsg(i2c)) {
383 /* last message, send stop and complete */
384 dev_dbg(i2c->dev, "READ: Send Stop\n");
385
386 s3c24xx_i2c_stop(i2c, 0);
387 } else {
388 /* go to the next transfer */
389 dev_dbg(i2c->dev, "READ: Next Transfer\n");
390
391 i2c->msg_ptr = 0;
392 i2c->msg_idx++;
393 i2c->msg++;
394 }
395 }
396
397 break;
398 }
399
400 /* acknowlegde the IRQ and get back on with the work */
401
402 out_ack:
Ben Dooks3d0911b2008-10-31 16:10:24 +0000403 tmp = readl(i2c->regs + S3C2410_IICCON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 tmp &= ~S3C2410_IICCON_IRQPEND;
405 writel(tmp, i2c->regs + S3C2410_IICCON);
406 out:
407 return ret;
408}
409
410/* s3c24xx_i2c_irq
411 *
412 * top level IRQ servicing routine
413*/
414
David Howells7d12e782006-10-05 14:55:46 +0100415static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
417 struct s3c24xx_i2c *i2c = dev_id;
418 unsigned long status;
419 unsigned long tmp;
420
421 status = readl(i2c->regs + S3C2410_IICSTAT);
422
423 if (status & S3C2410_IICSTAT_ARBITR) {
Ben Dooks3d0911b2008-10-31 16:10:24 +0000424 /* deal with arbitration loss */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 dev_err(i2c->dev, "deal with arbitration loss\n");
426 }
427
428 if (i2c->state == STATE_IDLE) {
429 dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n");
430
Ben Dooks3d0911b2008-10-31 16:10:24 +0000431 tmp = readl(i2c->regs + S3C2410_IICCON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 tmp &= ~S3C2410_IICCON_IRQPEND;
433 writel(tmp, i2c->regs + S3C2410_IICCON);
434 goto out;
435 }
Ben Dooks3d0911b2008-10-31 16:10:24 +0000436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 /* pretty much this leaves us with the fact that we've
438 * transmitted or received whatever byte we last sent */
439
440 i2s_s3c_irq_nextbyte(i2c, status);
441
442 out:
443 return IRQ_HANDLED;
444}
445
446
447/* s3c24xx_i2c_set_master
448 *
449 * get the i2c bus for a master transaction
450*/
451
452static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
453{
454 unsigned long iicstat;
455 int timeout = 400;
456
457 while (timeout-- > 0) {
458 iicstat = readl(i2c->regs + S3C2410_IICSTAT);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (!(iicstat & S3C2410_IICSTAT_BUSBUSY))
461 return 0;
462
463 msleep(1);
464 }
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 return -ETIMEDOUT;
467}
468
469/* s3c24xx_i2c_doxfer
470 *
471 * this starts an i2c transfer
472*/
473
Ben Dooks3d0911b2008-10-31 16:10:24 +0000474static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
475 struct i2c_msg *msgs, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 unsigned long timeout;
478 int ret;
479
Ben Dooksbe44f012008-10-31 16:10:22 +0000480 if (i2c->suspended)
Ben Dooks61c7cff2008-07-28 12:04:07 +0100481 return -EIO;
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 ret = s3c24xx_i2c_set_master(i2c);
484 if (ret != 0) {
485 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
486 ret = -EAGAIN;
487 goto out;
488 }
489
490 spin_lock_irq(&i2c->lock);
491
492 i2c->msg = msgs;
493 i2c->msg_num = num;
494 i2c->msg_ptr = 0;
495 i2c->msg_idx = 0;
496 i2c->state = STATE_START;
497
498 s3c24xx_i2c_enable_irq(i2c);
499 s3c24xx_i2c_message_start(i2c, msgs);
500 spin_unlock_irq(&i2c->lock);
Ben Dooks3d0911b2008-10-31 16:10:24 +0000501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
503
504 ret = i2c->msg_idx;
505
Ben Dooks3d0911b2008-10-31 16:10:24 +0000506 /* having these next two as dev_err() makes life very
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 * noisy when doing an i2cdetect */
508
509 if (timeout == 0)
510 dev_dbg(i2c->dev, "timeout\n");
511 else if (ret != num)
512 dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
513
514 /* ensure the stop has been through the bus */
515
516 msleep(1);
517
518 out:
519 return ret;
520}
521
522/* s3c24xx_i2c_xfer
523 *
524 * first port of call from the i2c bus code when an message needs
Steven Cole44bbe872005-05-03 18:21:25 -0600525 * transferring across the i2c bus.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526*/
527
528static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
529 struct i2c_msg *msgs, int num)
530{
531 struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
532 int retry;
533 int ret;
534
535 for (retry = 0; retry < adap->retries; retry++) {
536
537 ret = s3c24xx_i2c_doxfer(i2c, msgs, num);
538
539 if (ret != -EAGAIN)
540 return ret;
541
542 dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry);
543
544 udelay(100);
545 }
546
547 return -EREMOTEIO;
548}
549
550/* declare our i2c functionality */
551static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
552{
553 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
554}
555
556/* i2c bus registration info */
557
Jean Delvare8f9082c2006-09-03 22:39:46 +0200558static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .master_xfer = s3c24xx_i2c_xfer,
560 .functionality = s3c24xx_i2c_func,
561};
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563/* s3c24xx_i2c_calcdivisor
564 *
565 * return the divisor settings for a given frequency
566*/
567
568static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted,
569 unsigned int *div1, unsigned int *divs)
570{
571 unsigned int calc_divs = clkin / wanted;
572 unsigned int calc_div1;
573
574 if (calc_divs > (16*16))
575 calc_div1 = 512;
576 else
577 calc_div1 = 16;
578
579 calc_divs += calc_div1-1;
580 calc_divs /= calc_div1;
581
582 if (calc_divs == 0)
583 calc_divs = 1;
584 if (calc_divs > 17)
585 calc_divs = 17;
586
587 *divs = calc_divs;
588 *div1 = calc_div1;
589
590 return clkin / (calc_divs * calc_div1);
591}
592
593/* freq_acceptable
594 *
595 * test wether a frequency is within the acceptable range of error
596*/
597
598static inline int freq_acceptable(unsigned int freq, unsigned int wanted)
599{
600 int diff = freq - wanted;
601
Ben Dooks3d0911b2008-10-31 16:10:24 +0000602 return diff >= -2 && diff <= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
Ben Dooks61c7cff2008-07-28 12:04:07 +0100605/* s3c24xx_i2c_clockrate
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 *
607 * work out a divisor for the user requested frequency setting,
608 * either by the requested frequency, or scanning the acceptable
609 * range of frequencies until something is found
610*/
611
Ben Dooks61c7cff2008-07-28 12:04:07 +0100612static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Ben Dooks6a039ca2008-10-31 16:10:27 +0000614 struct s3c2410_platform_i2c *pdata = i2c->dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 unsigned long clkin = clk_get_rate(i2c->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 unsigned int divs, div1;
Ben Dooks61c7cff2008-07-28 12:04:07 +0100617 u32 iiccon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 int freq;
619 int start, end;
620
Ben Dooks61c7cff2008-07-28 12:04:07 +0100621 i2c->clkrate = clkin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 clkin /= 1000; /* clkin now in KHz */
Ben Dooks3d0911b2008-10-31 16:10:24 +0000623
Ben Dooks61c7cff2008-07-28 12:04:07 +0100624 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq);
626
627 if (pdata->bus_freq != 0) {
628 freq = s3c24xx_i2c_calcdivisor(clkin, pdata->bus_freq/1000,
629 &div1, &divs);
630 if (freq_acceptable(freq, pdata->bus_freq/1000))
631 goto found;
632 }
633
634 /* ok, we may have to search for something suitable... */
635
636 start = (pdata->max_freq == 0) ? pdata->bus_freq : pdata->max_freq;
637 end = pdata->min_freq;
638
639 start /= 1000;
640 end /= 1000;
641
642 /* search loop... */
643
644 for (; start > end; start--) {
645 freq = s3c24xx_i2c_calcdivisor(clkin, start, &div1, &divs);
646 if (freq_acceptable(freq, start))
647 goto found;
648 }
649
650 /* cannot find frequency spec */
651
652 return -EINVAL;
653
654 found:
655 *got = freq;
Ben Dooks61c7cff2008-07-28 12:04:07 +0100656
657 iiccon = readl(i2c->regs + S3C2410_IICCON);
658 iiccon &= ~(S3C2410_IICCON_SCALEMASK | S3C2410_IICCON_TXDIV_512);
659 iiccon |= (divs-1);
660
661 if (div1 == 512)
662 iiccon |= S3C2410_IICCON_TXDIV_512;
663
664 writel(iiccon, i2c->regs + S3C2410_IICCON);
665
Ben Dooksa192f712009-03-27 10:52:13 +0000666 if (s3c24xx_i2c_is2440(i2c)) {
667 unsigned long sda_delay;
668
669 if (pdata->sda_delay) {
670 sda_delay = (freq / 1000) * pdata->sda_delay;
671 sda_delay /= 1000000;
672 sda_delay = DIV_ROUND_UP(sda_delay, 5);
673 if (sda_delay > 3)
674 sda_delay = 3;
675 sda_delay |= S3C2410_IICLC_FILTER_ON;
676 } else
677 sda_delay = 0;
678
679 dev_dbg(i2c->dev, "IICLC=%08lx\n", sda_delay);
680 writel(sda_delay, i2c->regs + S3C2440_IICLC);
681 }
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 return 0;
684}
685
Ben Dooks61c7cff2008-07-28 12:04:07 +0100686#ifdef CONFIG_CPU_FREQ
687
688#define freq_to_i2c(_n) container_of(_n, struct s3c24xx_i2c, freq_transition)
689
690static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb,
691 unsigned long val, void *data)
692{
693 struct s3c24xx_i2c *i2c = freq_to_i2c(nb);
694 unsigned long flags;
695 unsigned int got;
696 int delta_f;
697 int ret;
698
699 delta_f = clk_get_rate(i2c->clk) - i2c->clkrate;
700
701 /* if we're post-change and the input clock has slowed down
702 * or at pre-change and the clock is about to speed up, then
703 * adjust our clock rate. <0 is slow, >0 speedup.
704 */
705
706 if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) ||
707 (val == CPUFREQ_PRECHANGE && delta_f > 0)) {
708 spin_lock_irqsave(&i2c->lock, flags);
709 ret = s3c24xx_i2c_clockrate(i2c, &got);
710 spin_unlock_irqrestore(&i2c->lock, flags);
711
712 if (ret < 0)
713 dev_err(i2c->dev, "cannot find frequency\n");
714 else
715 dev_info(i2c->dev, "setting freq %d\n", got);
716 }
717
718 return 0;
719}
720
721static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
722{
723 i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition;
724
725 return cpufreq_register_notifier(&i2c->freq_transition,
726 CPUFREQ_TRANSITION_NOTIFIER);
727}
728
729static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
730{
731 cpufreq_unregister_notifier(&i2c->freq_transition,
732 CPUFREQ_TRANSITION_NOTIFIER);
733}
734
735#else
736static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
737{
738 return 0;
739}
740
741static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
742{
743}
744#endif
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746/* s3c24xx_i2c_init
747 *
Ben Dooks3d0911b2008-10-31 16:10:24 +0000748 * initialise the controller, set the IO lines and frequency
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749*/
750
751static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
752{
753 unsigned long iicon = S3C2410_IICCON_IRQEN | S3C2410_IICCON_ACKEN;
754 struct s3c2410_platform_i2c *pdata;
755 unsigned int freq;
756
757 /* get the plafrom data */
758
Ben Dooks6a039ca2008-10-31 16:10:27 +0000759 pdata = i2c->dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /* inititalise the gpio */
762
Ben Dooks8be310a2008-10-31 16:10:25 +0000763 if (pdata->cfg_gpio)
764 pdata->cfg_gpio(to_platform_device(i2c->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 /* write slave address */
Ben Dooks3d0911b2008-10-31 16:10:24 +0000767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD);
769
770 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
771
Ben Dooks61c7cff2008-07-28 12:04:07 +0100772 writel(iicon, i2c->regs + S3C2410_IICCON);
773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 /* we need to work out the divisors for the clock... */
775
Ben Dooks61c7cff2008-07-28 12:04:07 +0100776 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
777 writel(0, i2c->regs + S3C2410_IICCON);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 dev_err(i2c->dev, "cannot meet bus frequency required\n");
779 return -EINVAL;
780 }
781
782 /* todo - check that the i2c lines aren't being dragged anywhere */
783
784 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
785 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /* check for s3c2440 i2c controller */
788
Ben Dooksa192f712009-03-27 10:52:13 +0000789 if (s3c24xx_i2c_is2440(i2c))
790 writel(0x0, i2c->regs + S3C2440_IICLC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 return 0;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795/* s3c24xx_i2c_probe
796 *
797 * called by the bus driver when a suitable device is found
798*/
799
Russell King3ae5eae2005-11-09 22:32:44 +0000800static int s3c24xx_i2c_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Ben Dooks692acbd2008-10-31 16:10:28 +0000802 struct s3c24xx_i2c *i2c;
Ben Dooks399dee22008-07-28 12:04:06 +0100803 struct s3c2410_platform_i2c *pdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 struct resource *res;
805 int ret;
806
Ben Dooks6a039ca2008-10-31 16:10:27 +0000807 pdata = pdev->dev.platform_data;
808 if (!pdata) {
809 dev_err(&pdev->dev, "no platform data\n");
810 return -EINVAL;
811 }
Ben Dooks399dee22008-07-28 12:04:06 +0100812
Ben Dooks692acbd2008-10-31 16:10:28 +0000813 i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL);
814 if (!i2c) {
815 dev_err(&pdev->dev, "no memory for state\n");
816 return -ENOMEM;
817 }
818
819 strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
820 i2c->adap.owner = THIS_MODULE;
821 i2c->adap.algo = &s3c24xx_i2c_algorithm;
822 i2c->adap.retries = 2;
823 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
824 i2c->tx_setup = 50;
825
826 spin_lock_init(&i2c->lock);
827 init_waitqueue_head(&i2c->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* find the clock and enable it */
830
Russell King3ae5eae2005-11-09 22:32:44 +0000831 i2c->dev = &pdev->dev;
832 i2c->clk = clk_get(&pdev->dev, "i2c");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (IS_ERR(i2c->clk)) {
Russell King3ae5eae2005-11-09 22:32:44 +0000834 dev_err(&pdev->dev, "cannot get clock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 ret = -ENOENT;
Ben Dooks5b687902007-05-01 23:26:35 +0200836 goto err_noclk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838
Russell King3ae5eae2005-11-09 22:32:44 +0000839 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 clk_enable(i2c->clk);
842
843 /* map the registers */
844
845 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
846 if (res == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000847 dev_err(&pdev->dev, "cannot find IO resource\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 ret = -ENOENT;
Ben Dooks5b687902007-05-01 23:26:35 +0200849 goto err_clk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851
852 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1,
853 pdev->name);
854
855 if (i2c->ioarea == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000856 dev_err(&pdev->dev, "cannot request IO\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 ret = -ENXIO;
Ben Dooks5b687902007-05-01 23:26:35 +0200858 goto err_clk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860
861 i2c->regs = ioremap(res->start, (res->end-res->start)+1);
862
863 if (i2c->regs == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000864 dev_err(&pdev->dev, "cannot map IO\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 ret = -ENXIO;
Ben Dooks5b687902007-05-01 23:26:35 +0200866 goto err_ioarea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868
Ben Dooks3d0911b2008-10-31 16:10:24 +0000869 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n",
870 i2c->regs, i2c->ioarea, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 /* setup info block for the i2c core */
873
874 i2c->adap.algo_data = i2c;
Russell King3ae5eae2005-11-09 22:32:44 +0000875 i2c->adap.dev.parent = &pdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 /* initialise the i2c controller */
878
879 ret = s3c24xx_i2c_init(i2c);
880 if (ret != 0)
Ben Dooks5b687902007-05-01 23:26:35 +0200881 goto err_iomap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 /* find the IRQ for this unit (note, this relies on the init call to
Ben Dooks3d0911b2008-10-31 16:10:24 +0000884 * ensure no current IRQs pending
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 */
886
Ben Dookse0d1ec92008-10-31 16:10:30 +0000887 i2c->irq = ret = platform_get_irq(pdev, 0);
888 if (ret <= 0) {
Russell King3ae5eae2005-11-09 22:32:44 +0000889 dev_err(&pdev->dev, "cannot find IRQ\n");
Ben Dooks5b687902007-05-01 23:26:35 +0200890 goto err_iomap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 }
892
Ben Dookse0d1ec92008-10-31 16:10:30 +0000893 ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED,
894 dev_name(&pdev->dev), i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 if (ret != 0) {
Ben Dookse0d1ec92008-10-31 16:10:30 +0000897 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
Ben Dooks5b687902007-05-01 23:26:35 +0200898 goto err_iomap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
900
Ben Dooks61c7cff2008-07-28 12:04:07 +0100901 ret = s3c24xx_i2c_register_cpufreq(i2c);
902 if (ret < 0) {
903 dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
904 goto err_irq;
905 }
906
Ben Dooks399dee22008-07-28 12:04:06 +0100907 /* Note, previous versions of the driver used i2c_add_adapter()
908 * to add the bus at any number. We now pass the bus number via
909 * the platform data, so if unset it will now default to always
910 * being bus 0.
911 */
912
913 i2c->adap.nr = pdata->bus_num;
914
915 ret = i2c_add_numbered_adapter(&i2c->adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (ret < 0) {
Russell King3ae5eae2005-11-09 22:32:44 +0000917 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
Ben Dooks61c7cff2008-07-28 12:04:07 +0100918 goto err_cpufreq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920
Russell King3ae5eae2005-11-09 22:32:44 +0000921 platform_set_drvdata(pdev, i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Jean Delvare22e965c2009-01-07 14:29:16 +0100923 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev));
Ben Dooks5b687902007-05-01 23:26:35 +0200924 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Ben Dooks61c7cff2008-07-28 12:04:07 +0100926 err_cpufreq:
927 s3c24xx_i2c_deregister_cpufreq(i2c);
928
Ben Dooks5b687902007-05-01 23:26:35 +0200929 err_irq:
Ben Dookse0d1ec92008-10-31 16:10:30 +0000930 free_irq(i2c->irq, i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Ben Dooks5b687902007-05-01 23:26:35 +0200932 err_iomap:
933 iounmap(i2c->regs);
934
935 err_ioarea:
936 release_resource(i2c->ioarea);
937 kfree(i2c->ioarea);
938
939 err_clk:
940 clk_disable(i2c->clk);
941 clk_put(i2c->clk);
942
943 err_noclk:
Ben Dooks692acbd2008-10-31 16:10:28 +0000944 kfree(i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return ret;
946}
947
948/* s3c24xx_i2c_remove
949 *
950 * called when device is removed from the bus
951*/
952
Russell King3ae5eae2005-11-09 22:32:44 +0000953static int s3c24xx_i2c_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Russell King3ae5eae2005-11-09 22:32:44 +0000955 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
Ben Dooks5b687902007-05-01 23:26:35 +0200956
Ben Dooks61c7cff2008-07-28 12:04:07 +0100957 s3c24xx_i2c_deregister_cpufreq(i2c);
958
Ben Dooks5b687902007-05-01 23:26:35 +0200959 i2c_del_adapter(&i2c->adap);
Ben Dookse0d1ec92008-10-31 16:10:30 +0000960 free_irq(i2c->irq, i2c);
Ben Dooks5b687902007-05-01 23:26:35 +0200961
962 clk_disable(i2c->clk);
963 clk_put(i2c->clk);
964
965 iounmap(i2c->regs);
966
967 release_resource(i2c->ioarea);
968 kfree(i2c->ioarea);
Ben Dooks692acbd2008-10-31 16:10:28 +0000969 kfree(i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 return 0;
972}
973
974#ifdef CONFIG_PM
Ben Dooksbe44f012008-10-31 16:10:22 +0000975static int s3c24xx_i2c_suspend_late(struct platform_device *dev,
976 pm_message_t msg)
977{
978 struct s3c24xx_i2c *i2c = platform_get_drvdata(dev);
979 i2c->suspended = 1;
980 return 0;
981}
982
Russell King3ae5eae2005-11-09 22:32:44 +0000983static int s3c24xx_i2c_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
Russell King3ae5eae2005-11-09 22:32:44 +0000985 struct s3c24xx_i2c *i2c = platform_get_drvdata(dev);
Russell King9480e302005-10-28 09:52:56 -0700986
Ben Dooksbe44f012008-10-31 16:10:22 +0000987 i2c->suspended = 0;
988 s3c24xx_i2c_init(i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 return 0;
991}
992
993#else
Ben Dooksbe44f012008-10-31 16:10:22 +0000994#define s3c24xx_i2c_suspend_late NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#define s3c24xx_i2c_resume NULL
996#endif
997
998/* device driver for platform bus bits */
999
Russell King3ae5eae2005-11-09 22:32:44 +00001000static struct platform_driver s3c2410_i2c_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 .probe = s3c24xx_i2c_probe,
1002 .remove = s3c24xx_i2c_remove,
Ben Dooksbe44f012008-10-31 16:10:22 +00001003 .suspend_late = s3c24xx_i2c_suspend_late,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 .resume = s3c24xx_i2c_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001005 .driver = {
1006 .owner = THIS_MODULE,
1007 .name = "s3c2410-i2c",
1008 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009};
1010
Russell King3ae5eae2005-11-09 22:32:44 +00001011static struct platform_driver s3c2440_i2c_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .probe = s3c24xx_i2c_probe,
1013 .remove = s3c24xx_i2c_remove,
Ben Dooksbe44f012008-10-31 16:10:22 +00001014 .suspend_late = s3c24xx_i2c_suspend_late,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .resume = s3c24xx_i2c_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001016 .driver = {
1017 .owner = THIS_MODULE,
1018 .name = "s3c2440-i2c",
1019 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020};
1021
1022static int __init i2c_adap_s3c_init(void)
1023{
1024 int ret;
1025
Russell King3ae5eae2005-11-09 22:32:44 +00001026 ret = platform_driver_register(&s3c2410_i2c_driver);
Russell Kinge32e28e2005-10-30 16:32:27 +00001027 if (ret == 0) {
Russell King3ae5eae2005-11-09 22:32:44 +00001028 ret = platform_driver_register(&s3c2440_i2c_driver);
Russell Kinge32e28e2005-10-30 16:32:27 +00001029 if (ret)
Russell King3ae5eae2005-11-09 22:32:44 +00001030 platform_driver_unregister(&s3c2410_i2c_driver);
Russell Kinge32e28e2005-10-30 16:32:27 +00001031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033 return ret;
1034}
1035
1036static void __exit i2c_adap_s3c_exit(void)
1037{
Russell King3ae5eae2005-11-09 22:32:44 +00001038 platform_driver_unregister(&s3c2410_i2c_driver);
1039 platform_driver_unregister(&s3c2440_i2c_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
1042module_init(i2c_adap_s3c_init);
1043module_exit(i2c_adap_s3c_exit);
1044
1045MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
1046MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1047MODULE_LICENSE("GPL");
Kay Sieversadd8eda2008-04-22 22:16:49 +02001048MODULE_ALIAS("platform:s3c2410-i2c");
Ben Dooksd150a4b2008-07-01 11:59:43 +01001049MODULE_ALIAS("platform:s3c2440-i2c");