2 * Blackfin On-Chip Two Wire Interface Driver
4 * Copyright 2005-2007 Analog Devices Inc.
6 * Enter bugs at http://blackfin.uclinux.org/
8 * Licensed under the GPL-2 or later.
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/i2c.h>
15 #include <linux/slab.h>
18 #include <linux/timer.h>
19 #include <linux/spinlock.h>
20 #include <linux/completion.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <linux/delay.h>
25 #include <asm/blackfin.h>
26 #include <asm/portmux.h>
30 #define TWI_I2C_MODE_STANDARD 1
31 #define TWI_I2C_MODE_STANDARDSUB 2
32 #define TWI_I2C_MODE_COMBINED 3
33 #define TWI_I2C_MODE_REPEAT 4
35 struct bfin_twi_iface
{
46 struct i2c_adapter adap
;
47 struct completion complete
;
53 void __iomem
*regs_base
;
57 #define DEFINE_TWI_REG(reg, off) \
58 static inline u16 read_##reg(struct bfin_twi_iface *iface) \
59 { return bfin_read16(iface->regs_base + (off)); } \
60 static inline void write_##reg(struct bfin_twi_iface *iface, u16 v) \
61 { bfin_write16(iface->regs_base + (off), v); }
63 DEFINE_TWI_REG(CLKDIV
, 0x00)
64 DEFINE_TWI_REG(CONTROL
, 0x04)
65 DEFINE_TWI_REG(SLAVE_CTL
, 0x08)
66 DEFINE_TWI_REG(SLAVE_STAT
, 0x0C)
67 DEFINE_TWI_REG(SLAVE_ADDR
, 0x10)
68 DEFINE_TWI_REG(MASTER_CTL
, 0x14)
69 DEFINE_TWI_REG(MASTER_STAT
, 0x18)
70 DEFINE_TWI_REG(MASTER_ADDR
, 0x1C)
71 DEFINE_TWI_REG(INT_STAT
, 0x20)
72 DEFINE_TWI_REG(INT_MASK
, 0x24)
73 DEFINE_TWI_REG(FIFO_CTL
, 0x28)
74 DEFINE_TWI_REG(FIFO_STAT
, 0x2C)
75 DEFINE_TWI_REG(XMT_DATA8
, 0x80)
76 DEFINE_TWI_REG(XMT_DATA16
, 0x84)
77 DEFINE_TWI_REG(RCV_DATA8
, 0x88)
78 DEFINE_TWI_REG(RCV_DATA16
, 0x8C)
80 static const u16 pin_req
[2][3] = {
81 {P_TWI0_SCL
, P_TWI0_SDA
, 0},
82 {P_TWI1_SCL
, P_TWI1_SDA
, 0},
85 static void bfin_twi_handle_interrupt(struct bfin_twi_iface
*iface
,
86 unsigned short twi_int_status
)
88 unsigned short mast_stat
= read_MASTER_STAT(iface
);
90 if (twi_int_status
& XMTSERV
) {
91 /* Transmit next data */
92 if (iface
->writeNum
> 0) {
94 write_XMT_DATA8(iface
, *(iface
->transPtr
++));
97 /* start receive immediately after complete sending in
100 else if (iface
->cur_mode
== TWI_I2C_MODE_COMBINED
)
101 write_MASTER_CTL(iface
,
102 read_MASTER_CTL(iface
) | MDIR
| RSTART
);
103 else if (iface
->manual_stop
)
104 write_MASTER_CTL(iface
,
105 read_MASTER_CTL(iface
) | STOP
);
106 else if (iface
->cur_mode
== TWI_I2C_MODE_REPEAT
&&
107 iface
->cur_msg
+ 1 < iface
->msg_num
) {
108 if (iface
->pmsg
[iface
->cur_msg
+ 1].flags
& I2C_M_RD
)
109 write_MASTER_CTL(iface
,
110 read_MASTER_CTL(iface
) | RSTART
| MDIR
);
112 write_MASTER_CTL(iface
,
113 (read_MASTER_CTL(iface
) | RSTART
) & ~MDIR
);
116 if (twi_int_status
& RCVSERV
) {
117 if (iface
->readNum
> 0) {
118 /* Receive next data */
119 *(iface
->transPtr
) = read_RCV_DATA8(iface
);
120 if (iface
->cur_mode
== TWI_I2C_MODE_COMBINED
) {
121 /* Change combine mode into sub mode after
124 iface
->cur_mode
= TWI_I2C_MODE_STANDARDSUB
;
125 /* Get read number from first byte in block
128 if (iface
->readNum
== 1 && iface
->manual_stop
)
129 iface
->readNum
= *iface
->transPtr
+ 1;
133 } else if (iface
->manual_stop
) {
134 write_MASTER_CTL(iface
,
135 read_MASTER_CTL(iface
) | STOP
);
136 } else if (iface
->cur_mode
== TWI_I2C_MODE_REPEAT
&&
137 iface
->cur_msg
+ 1 < iface
->msg_num
) {
138 if (iface
->pmsg
[iface
->cur_msg
+ 1].flags
& I2C_M_RD
)
139 write_MASTER_CTL(iface
,
140 read_MASTER_CTL(iface
) | RSTART
| MDIR
);
142 write_MASTER_CTL(iface
,
143 (read_MASTER_CTL(iface
) | RSTART
) & ~MDIR
);
146 if (twi_int_status
& MERR
) {
147 write_INT_MASK(iface
, 0);
148 write_MASTER_STAT(iface
, 0x3e);
149 write_MASTER_CTL(iface
, 0);
150 iface
->result
= -EIO
;
152 if (mast_stat
& LOSTARB
)
153 dev_dbg(&iface
->adap
.dev
, "Lost Arbitration\n");
154 if (mast_stat
& ANAK
)
155 dev_dbg(&iface
->adap
.dev
, "Address Not Acknowledged\n");
156 if (mast_stat
& DNAK
)
157 dev_dbg(&iface
->adap
.dev
, "Data Not Acknowledged\n");
158 if (mast_stat
& BUFRDERR
)
159 dev_dbg(&iface
->adap
.dev
, "Buffer Read Error\n");
160 if (mast_stat
& BUFWRERR
)
161 dev_dbg(&iface
->adap
.dev
, "Buffer Write Error\n");
163 /* Faulty slave devices, may drive SDA low after a transfer
164 * finishes. To release the bus this code generates up to 9
165 * extra clocks until SDA is released.
168 if (read_MASTER_STAT(iface
) & SDASEN
) {
171 write_MASTER_CTL(iface
, SCLOVR
);
173 write_MASTER_CTL(iface
, 0);
175 } while ((read_MASTER_STAT(iface
) & SDASEN
) && cnt
--);
177 write_MASTER_CTL(iface
, SDAOVR
| SCLOVR
);
179 write_MASTER_CTL(iface
, SDAOVR
);
181 write_MASTER_CTL(iface
, 0);
184 /* If it is a quick transfer, only address without data,
185 * not an err, return 1.
187 if (iface
->cur_mode
== TWI_I2C_MODE_STANDARD
&&
188 iface
->transPtr
== NULL
&&
189 (twi_int_status
& MCOMP
) && (mast_stat
& DNAK
))
192 complete(&iface
->complete
);
195 if (twi_int_status
& MCOMP
) {
196 if ((read_MASTER_CTL(iface
) & MEN
) == 0 &&
197 (iface
->cur_mode
== TWI_I2C_MODE_REPEAT
||
198 iface
->cur_mode
== TWI_I2C_MODE_COMBINED
)) {
200 write_INT_MASK(iface
, 0);
201 write_MASTER_CTL(iface
, 0);
202 } else if (iface
->cur_mode
== TWI_I2C_MODE_COMBINED
) {
203 if (iface
->readNum
== 0) {
204 /* set the read number to 1 and ask for manual
205 * stop in block combine mode
208 iface
->manual_stop
= 1;
209 write_MASTER_CTL(iface
,
210 read_MASTER_CTL(iface
) | (0xff << 6));
212 /* set the readd number in other
215 write_MASTER_CTL(iface
,
216 (read_MASTER_CTL(iface
) &
218 (iface
->readNum
<< 6));
220 /* remove restart bit and enable master receive */
221 write_MASTER_CTL(iface
,
222 read_MASTER_CTL(iface
) & ~RSTART
);
223 } else if (iface
->cur_mode
== TWI_I2C_MODE_REPEAT
&&
224 iface
->cur_msg
+1 < iface
->msg_num
) {
226 iface
->transPtr
= iface
->pmsg
[iface
->cur_msg
].buf
;
227 iface
->writeNum
= iface
->readNum
=
228 iface
->pmsg
[iface
->cur_msg
].len
;
229 /* Set Transmit device address */
230 write_MASTER_ADDR(iface
,
231 iface
->pmsg
[iface
->cur_msg
].addr
);
232 if (iface
->pmsg
[iface
->cur_msg
].flags
& I2C_M_RD
)
233 iface
->read_write
= I2C_SMBUS_READ
;
235 iface
->read_write
= I2C_SMBUS_WRITE
;
236 /* Transmit first data */
237 if (iface
->writeNum
> 0) {
238 write_XMT_DATA8(iface
,
239 *(iface
->transPtr
++));
244 if (iface
->pmsg
[iface
->cur_msg
].len
<= 255)
245 write_MASTER_CTL(iface
,
246 (read_MASTER_CTL(iface
) &
248 (iface
->pmsg
[iface
->cur_msg
].len
<< 6));
250 write_MASTER_CTL(iface
,
251 (read_MASTER_CTL(iface
) |
253 iface
->manual_stop
= 1;
255 /* remove restart bit and enable master receive */
256 write_MASTER_CTL(iface
,
257 read_MASTER_CTL(iface
) & ~RSTART
);
260 write_INT_MASK(iface
, 0);
261 write_MASTER_CTL(iface
, 0);
264 complete(&iface
->complete
);
267 /* Interrupt handler */
268 static irqreturn_t
bfin_twi_interrupt_entry(int irq
, void *dev_id
)
270 struct bfin_twi_iface
*iface
= dev_id
;
272 unsigned short twi_int_status
;
274 spin_lock_irqsave(&iface
->lock
, flags
);
276 twi_int_status
= read_INT_STAT(iface
);
279 /* Clear interrupt status */
280 write_INT_STAT(iface
, twi_int_status
);
281 bfin_twi_handle_interrupt(iface
, twi_int_status
);
284 spin_unlock_irqrestore(&iface
->lock
, flags
);
289 * One i2c master transfer
291 static int bfin_twi_do_master_xfer(struct i2c_adapter
*adap
,
292 struct i2c_msg
*msgs
, int num
)
294 struct bfin_twi_iface
*iface
= adap
->algo_data
;
295 struct i2c_msg
*pmsg
;
298 if (!(read_CONTROL(iface
) & TWI_ENA
))
301 while (read_MASTER_STAT(iface
) & BUSBUSY
)
305 iface
->msg_num
= num
;
309 if (pmsg
->flags
& I2C_M_TEN
) {
310 dev_err(&adap
->dev
, "10 bits addr not supported!\n");
314 iface
->cur_mode
= TWI_I2C_MODE_REPEAT
;
315 iface
->manual_stop
= 0;
316 iface
->transPtr
= pmsg
->buf
;
317 iface
->writeNum
= iface
->readNum
= pmsg
->len
;
319 init_completion(&(iface
->complete
));
320 /* Set Transmit device address */
321 write_MASTER_ADDR(iface
, pmsg
->addr
);
323 /* FIFO Initiation. Data in FIFO should be
324 * discarded before start a new operation.
326 write_FIFO_CTL(iface
, 0x3);
328 write_FIFO_CTL(iface
, 0);
331 if (pmsg
->flags
& I2C_M_RD
)
332 iface
->read_write
= I2C_SMBUS_READ
;
334 iface
->read_write
= I2C_SMBUS_WRITE
;
335 /* Transmit first data */
336 if (iface
->writeNum
> 0) {
337 write_XMT_DATA8(iface
, *(iface
->transPtr
++));
344 write_INT_STAT(iface
, MERR
| MCOMP
| XMTSERV
| RCVSERV
);
346 /* Interrupt mask . Enable XMT, RCV interrupt */
347 write_INT_MASK(iface
, MCOMP
| MERR
| RCVSERV
| XMTSERV
);
350 if (pmsg
->len
<= 255)
351 write_MASTER_CTL(iface
, pmsg
->len
<< 6);
353 write_MASTER_CTL(iface
, 0xff << 6);
354 iface
->manual_stop
= 1;
358 write_MASTER_CTL(iface
, read_MASTER_CTL(iface
) | MEN
|
359 ((iface
->read_write
== I2C_SMBUS_READ
) ? MDIR
: 0) |
360 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ
> 100) ? FAST
: 0));
363 while (!iface
->result
) {
364 if (!wait_for_completion_timeout(&iface
->complete
,
367 dev_err(&adap
->dev
, "master transfer timeout\n");
371 if (iface
->result
== 1)
372 rc
= iface
->cur_msg
+ 1;
380 * Generic i2c master transfer entrypoint
382 static int bfin_twi_master_xfer(struct i2c_adapter
*adap
,
383 struct i2c_msg
*msgs
, int num
)
385 return bfin_twi_do_master_xfer(adap
, msgs
, num
);
389 * One I2C SMBus transfer
391 int bfin_twi_do_smbus_xfer(struct i2c_adapter
*adap
, u16 addr
,
392 unsigned short flags
, char read_write
,
393 u8 command
, int size
, union i2c_smbus_data
*data
)
395 struct bfin_twi_iface
*iface
= adap
->algo_data
;
398 if (!(read_CONTROL(iface
) & TWI_ENA
))
401 while (read_MASTER_STAT(iface
) & BUSBUSY
)
407 /* Prepare datas & select mode */
409 case I2C_SMBUS_QUICK
:
410 iface
->transPtr
= NULL
;
411 iface
->cur_mode
= TWI_I2C_MODE_STANDARD
;
415 iface
->transPtr
= NULL
;
417 if (read_write
== I2C_SMBUS_READ
)
421 iface
->transPtr
= &data
->byte
;
423 iface
->cur_mode
= TWI_I2C_MODE_STANDARD
;
425 case I2C_SMBUS_BYTE_DATA
:
426 if (read_write
== I2C_SMBUS_READ
) {
428 iface
->cur_mode
= TWI_I2C_MODE_COMBINED
;
431 iface
->cur_mode
= TWI_I2C_MODE_STANDARDSUB
;
433 iface
->transPtr
= &data
->byte
;
435 case I2C_SMBUS_WORD_DATA
:
436 if (read_write
== I2C_SMBUS_READ
) {
438 iface
->cur_mode
= TWI_I2C_MODE_COMBINED
;
441 iface
->cur_mode
= TWI_I2C_MODE_STANDARDSUB
;
443 iface
->transPtr
= (u8
*)&data
->word
;
445 case I2C_SMBUS_PROC_CALL
:
448 iface
->cur_mode
= TWI_I2C_MODE_COMBINED
;
449 iface
->transPtr
= (u8
*)&data
->word
;
451 case I2C_SMBUS_BLOCK_DATA
:
452 if (read_write
== I2C_SMBUS_READ
) {
454 iface
->cur_mode
= TWI_I2C_MODE_COMBINED
;
456 iface
->writeNum
= data
->block
[0] + 1;
457 iface
->cur_mode
= TWI_I2C_MODE_STANDARDSUB
;
459 iface
->transPtr
= data
->block
;
461 case I2C_SMBUS_I2C_BLOCK_DATA
:
462 if (read_write
== I2C_SMBUS_READ
) {
463 iface
->readNum
= data
->block
[0];
464 iface
->cur_mode
= TWI_I2C_MODE_COMBINED
;
466 iface
->writeNum
= data
->block
[0];
467 iface
->cur_mode
= TWI_I2C_MODE_STANDARDSUB
;
469 iface
->transPtr
= (u8
*)&data
->block
[1];
476 iface
->manual_stop
= 0;
477 iface
->read_write
= read_write
;
478 iface
->command
= command
;
479 init_completion(&(iface
->complete
));
481 /* FIFO Initiation. Data in FIFO should be discarded before
482 * start a new operation.
484 write_FIFO_CTL(iface
, 0x3);
486 write_FIFO_CTL(iface
, 0);
489 write_INT_STAT(iface
, MERR
| MCOMP
| XMTSERV
| RCVSERV
);
491 /* Set Transmit device address */
492 write_MASTER_ADDR(iface
, addr
);
495 switch (iface
->cur_mode
) {
496 case TWI_I2C_MODE_STANDARDSUB
:
497 write_XMT_DATA8(iface
, iface
->command
);
498 write_INT_MASK(iface
, MCOMP
| MERR
|
499 ((iface
->read_write
== I2C_SMBUS_READ
) ?
503 if (iface
->writeNum
+ 1 <= 255)
504 write_MASTER_CTL(iface
, (iface
->writeNum
+ 1) << 6);
506 write_MASTER_CTL(iface
, 0xff << 6);
507 iface
->manual_stop
= 1;
510 write_MASTER_CTL(iface
, read_MASTER_CTL(iface
) | MEN
|
511 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ
>100) ? FAST
: 0));
513 case TWI_I2C_MODE_COMBINED
:
514 write_XMT_DATA8(iface
, iface
->command
);
515 write_INT_MASK(iface
, MCOMP
| MERR
| RCVSERV
| XMTSERV
);
518 if (iface
->writeNum
> 0)
519 write_MASTER_CTL(iface
, (iface
->writeNum
+ 1) << 6);
521 write_MASTER_CTL(iface
, 0x1 << 6);
523 write_MASTER_CTL(iface
, read_MASTER_CTL(iface
) | MEN
|
524 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ
>100) ? FAST
: 0));
527 write_MASTER_CTL(iface
, 0);
528 if (size
!= I2C_SMBUS_QUICK
) {
529 /* Don't access xmit data register when this is a
532 if (iface
->read_write
!= I2C_SMBUS_READ
) {
533 if (iface
->writeNum
> 0) {
534 write_XMT_DATA8(iface
,
535 *(iface
->transPtr
++));
536 if (iface
->writeNum
<= 255)
537 write_MASTER_CTL(iface
,
538 iface
->writeNum
<< 6);
540 write_MASTER_CTL(iface
,
542 iface
->manual_stop
= 1;
546 write_XMT_DATA8(iface
, iface
->command
);
547 write_MASTER_CTL(iface
, 1 << 6);
550 if (iface
->readNum
> 0 && iface
->readNum
<= 255)
551 write_MASTER_CTL(iface
,
552 iface
->readNum
<< 6);
553 else if (iface
->readNum
> 255) {
554 write_MASTER_CTL(iface
, 0xff << 6);
555 iface
->manual_stop
= 1;
560 write_INT_MASK(iface
, MCOMP
| MERR
|
561 ((iface
->read_write
== I2C_SMBUS_READ
) ?
566 write_MASTER_CTL(iface
, read_MASTER_CTL(iface
) | MEN
|
567 ((iface
->read_write
== I2C_SMBUS_READ
) ? MDIR
: 0) |
568 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ
> 100) ? FAST
: 0));
573 while (!iface
->result
) {
574 if (!wait_for_completion_timeout(&iface
->complete
,
577 dev_err(&adap
->dev
, "smbus transfer timeout\n");
581 rc
= (iface
->result
>= 0) ? 0 : -1;
587 * Generic I2C SMBus transfer entrypoint
589 int bfin_twi_smbus_xfer(struct i2c_adapter
*adap
, u16 addr
,
590 unsigned short flags
, char read_write
,
591 u8 command
, int size
, union i2c_smbus_data
*data
)
593 return bfin_twi_do_smbus_xfer(adap
, addr
, flags
,
594 read_write
, command
, size
, data
);
598 * Return what the adapter supports
600 static u32
bfin_twi_functionality(struct i2c_adapter
*adap
)
602 return I2C_FUNC_SMBUS_QUICK
| I2C_FUNC_SMBUS_BYTE
|
603 I2C_FUNC_SMBUS_BYTE_DATA
| I2C_FUNC_SMBUS_WORD_DATA
|
604 I2C_FUNC_SMBUS_BLOCK_DATA
| I2C_FUNC_SMBUS_PROC_CALL
|
605 I2C_FUNC_I2C
| I2C_FUNC_SMBUS_I2C_BLOCK
;
608 static struct i2c_algorithm bfin_twi_algorithm
= {
609 .master_xfer
= bfin_twi_master_xfer
,
610 .smbus_xfer
= bfin_twi_smbus_xfer
,
611 .functionality
= bfin_twi_functionality
,
614 static int i2c_bfin_twi_suspend(struct platform_device
*pdev
, pm_message_t state
)
616 struct bfin_twi_iface
*iface
= platform_get_drvdata(pdev
);
618 iface
->saved_clkdiv
= read_CLKDIV(iface
);
619 iface
->saved_control
= read_CONTROL(iface
);
621 free_irq(iface
->irq
, iface
);
624 write_CONTROL(iface
, iface
->saved_control
& ~TWI_ENA
);
629 static int i2c_bfin_twi_resume(struct platform_device
*pdev
)
631 struct bfin_twi_iface
*iface
= platform_get_drvdata(pdev
);
633 int rc
= request_irq(iface
->irq
, bfin_twi_interrupt_entry
,
634 0, pdev
->name
, iface
);
636 dev_err(&pdev
->dev
, "Can't get IRQ %d !\n", iface
->irq
);
640 /* Resume TWI interface clock as specified */
641 write_CLKDIV(iface
, iface
->saved_clkdiv
);
644 write_CONTROL(iface
, iface
->saved_control
);
649 static int i2c_bfin_twi_probe(struct platform_device
*pdev
)
651 struct bfin_twi_iface
*iface
;
652 struct i2c_adapter
*p_adap
;
653 struct resource
*res
;
655 unsigned int clkhilow
;
657 iface
= kzalloc(sizeof(struct bfin_twi_iface
), GFP_KERNEL
);
659 dev_err(&pdev
->dev
, "Cannot allocate memory\n");
661 goto out_error_nomem
;
664 spin_lock_init(&(iface
->lock
));
666 /* Find and map our resources */
667 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
669 dev_err(&pdev
->dev
, "Cannot get IORESOURCE_MEM\n");
671 goto out_error_get_res
;
674 iface
->regs_base
= ioremap(res
->start
, resource_size(res
));
675 if (iface
->regs_base
== NULL
) {
676 dev_err(&pdev
->dev
, "Cannot map IO\n");
678 goto out_error_ioremap
;
681 iface
->irq
= platform_get_irq(pdev
, 0);
682 if (iface
->irq
< 0) {
683 dev_err(&pdev
->dev
, "No IRQ specified\n");
685 goto out_error_no_irq
;
688 p_adap
= &iface
->adap
;
689 p_adap
->nr
= pdev
->id
;
690 strlcpy(p_adap
->name
, pdev
->name
, sizeof(p_adap
->name
));
691 p_adap
->algo
= &bfin_twi_algorithm
;
692 p_adap
->algo_data
= iface
;
693 p_adap
->class = I2C_CLASS_HWMON
| I2C_CLASS_SPD
;
694 p_adap
->dev
.parent
= &pdev
->dev
;
695 p_adap
->timeout
= 5 * HZ
;
698 rc
= peripheral_request_list(pin_req
[pdev
->id
], "i2c-bfin-twi");
700 dev_err(&pdev
->dev
, "Can't setup pin mux!\n");
701 goto out_error_pin_mux
;
704 rc
= request_irq(iface
->irq
, bfin_twi_interrupt_entry
,
705 0, pdev
->name
, iface
);
707 dev_err(&pdev
->dev
, "Can't get IRQ %d !\n", iface
->irq
);
709 goto out_error_req_irq
;
712 /* Set TWI internal clock as 10MHz */
713 write_CONTROL(iface
, ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F);
716 * We will not end up with a CLKDIV=0 because no one will specify
717 * 20kHz SCL or less in Kconfig now. (5 * 1000 / 20 = 250)
719 clkhilow
= ((10 * 1000 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ
) + 1) / 2;
721 /* Set Twi interface clock as specified */
722 write_CLKDIV(iface
, (clkhilow
<< 8) | clkhilow
);
725 write_CONTROL(iface
, read_CONTROL(iface
) | TWI_ENA
);
728 rc
= i2c_add_numbered_adapter(p_adap
);
730 dev_err(&pdev
->dev
, "Can't add i2c adapter!\n");
731 goto out_error_add_adapter
;
734 platform_set_drvdata(pdev
, iface
);
736 dev_info(&pdev
->dev
, "Blackfin BF5xx on-chip I2C TWI Contoller, "
737 "regs_base@%p\n", iface
->regs_base
);
741 out_error_add_adapter
:
742 free_irq(iface
->irq
, iface
);
745 peripheral_free_list(pin_req
[pdev
->id
]);
747 iounmap(iface
->regs_base
);
755 static int i2c_bfin_twi_remove(struct platform_device
*pdev
)
757 struct bfin_twi_iface
*iface
= platform_get_drvdata(pdev
);
759 platform_set_drvdata(pdev
, NULL
);
761 i2c_del_adapter(&(iface
->adap
));
762 free_irq(iface
->irq
, iface
);
763 peripheral_free_list(pin_req
[pdev
->id
]);
764 iounmap(iface
->regs_base
);
770 static struct platform_driver i2c_bfin_twi_driver
= {
771 .probe
= i2c_bfin_twi_probe
,
772 .remove
= i2c_bfin_twi_remove
,
773 .suspend
= i2c_bfin_twi_suspend
,
774 .resume
= i2c_bfin_twi_resume
,
776 .name
= "i2c-bfin-twi",
777 .owner
= THIS_MODULE
,
781 static int __init
i2c_bfin_twi_init(void)
783 return platform_driver_register(&i2c_bfin_twi_driver
);
786 static void __exit
i2c_bfin_twi_exit(void)
788 platform_driver_unregister(&i2c_bfin_twi_driver
);
791 subsys_initcall(i2c_bfin_twi_init
);
792 module_exit(i2c_bfin_twi_exit
);
794 MODULE_AUTHOR("Bryan Wu, Sonic Zhang");
795 MODULE_DESCRIPTION("Blackfin BF5xx on-chip I2C TWI Contoller Driver");
796 MODULE_LICENSE("GPL");
797 MODULE_ALIAS("platform:i2c-bfin-twi");