blob: 39b8d77bf35c884965da60d741d157486b1d304d [file] [log] [blame]
Bryan Wud24ecfc2007-05-01 23:26:32 +02001/*
Mike Frysingerbd584992008-04-22 22:16:48 +02002 * Blackfin On-Chip Two Wire Interface Driver
Bryan Wud24ecfc2007-05-01 23:26:32 +02003 *
Mike Frysingerbd584992008-04-22 22:16:48 +02004 * Copyright 2005-2007 Analog Devices Inc.
Bryan Wud24ecfc2007-05-01 23:26:32 +02005 *
Mike Frysingerbd584992008-04-22 22:16:48 +02006 * Enter bugs at http://blackfin.uclinux.org/
Bryan Wud24ecfc2007-05-01 23:26:32 +02007 *
Mike Frysingerbd584992008-04-22 22:16:48 +02008 * Licensed under the GPL-2 or later.
Bryan Wud24ecfc2007-05-01 23:26:32 +02009 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Mike Frysinger6df263c2009-06-14 01:55:37 -040016#include <linux/io.h>
Bryan Wud24ecfc2007-05-01 23:26:32 +020017#include <linux/mm.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>
Michael Hennerich540ac552011-01-11 00:25:08 -050023#include <linux/delay.h>
Bryan Wud24ecfc2007-05-01 23:26:32 +020024
25#include <asm/blackfin.h>
Bryan Wu74d362e2008-04-22 22:16:48 +020026#include <asm/portmux.h>
Bryan Wud24ecfc2007-05-01 23:26:32 +020027#include <asm/irq.h>
Sonic Zhangc9d87ed2012-06-13 16:22:45 +080028#include <asm/bfin_twi.h>
Bryan Wud24ecfc2007-05-01 23:26:32 +020029
Bryan Wud24ecfc2007-05-01 23:26:32 +020030/* SMBus mode*/
Sonic Zhang4dd39bb2008-04-22 22:16:47 +020031#define TWI_I2C_MODE_STANDARD 1
32#define TWI_I2C_MODE_STANDARDSUB 2
33#define TWI_I2C_MODE_COMBINED 3
34#define TWI_I2C_MODE_REPEAT 4
Bryan Wud24ecfc2007-05-01 23:26:32 +020035
36struct bfin_twi_iface {
Bryan Wud24ecfc2007-05-01 23:26:32 +020037 int irq;
38 spinlock_t lock;
39 char read_write;
40 u8 command;
41 u8 *transPtr;
42 int readNum;
43 int writeNum;
44 int cur_mode;
45 int manual_stop;
46 int result;
Bryan Wud24ecfc2007-05-01 23:26:32 +020047 struct i2c_adapter adap;
48 struct completion complete;
Sonic Zhang4dd39bb2008-04-22 22:16:47 +020049 struct i2c_msg *pmsg;
50 int msg_num;
51 int cur_msg;
Michael Hennerich958585f2008-07-27 14:41:54 +080052 u16 saved_clkdiv;
53 u16 saved_control;
Bryan Wuaa3d0202008-04-22 22:16:48 +020054 void __iomem *regs_base;
Bryan Wud24ecfc2007-05-01 23:26:32 +020055};
56
Bryan Wuaa3d0202008-04-22 22:16:48 +020057
58#define DEFINE_TWI_REG(reg, off) \
59static inline u16 read_##reg(struct bfin_twi_iface *iface) \
60 { return bfin_read16(iface->regs_base + (off)); } \
61static inline void write_##reg(struct bfin_twi_iface *iface, u16 v) \
62 { bfin_write16(iface->regs_base + (off), v); }
63
64DEFINE_TWI_REG(CLKDIV, 0x00)
65DEFINE_TWI_REG(CONTROL, 0x04)
66DEFINE_TWI_REG(SLAVE_CTL, 0x08)
67DEFINE_TWI_REG(SLAVE_STAT, 0x0C)
68DEFINE_TWI_REG(SLAVE_ADDR, 0x10)
69DEFINE_TWI_REG(MASTER_CTL, 0x14)
70DEFINE_TWI_REG(MASTER_STAT, 0x18)
71DEFINE_TWI_REG(MASTER_ADDR, 0x1C)
72DEFINE_TWI_REG(INT_STAT, 0x20)
73DEFINE_TWI_REG(INT_MASK, 0x24)
74DEFINE_TWI_REG(FIFO_CTL, 0x28)
75DEFINE_TWI_REG(FIFO_STAT, 0x2C)
76DEFINE_TWI_REG(XMT_DATA8, 0x80)
77DEFINE_TWI_REG(XMT_DATA16, 0x84)
78DEFINE_TWI_REG(RCV_DATA8, 0x88)
79DEFINE_TWI_REG(RCV_DATA16, 0x8C)
Bryan Wud24ecfc2007-05-01 23:26:32 +020080
Bryan Wu74d362e2008-04-22 22:16:48 +020081static const u16 pin_req[2][3] = {
82 {P_TWI0_SCL, P_TWI0_SDA, 0},
83 {P_TWI1_SCL, P_TWI1_SDA, 0},
84};
85
Sonic Zhang5481d072010-03-22 03:23:18 -040086static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
87 unsigned short twi_int_status)
Bryan Wud24ecfc2007-05-01 23:26:32 +020088{
Bryan Wuaa3d0202008-04-22 22:16:48 +020089 unsigned short mast_stat = read_MASTER_STAT(iface);
Bryan Wud24ecfc2007-05-01 23:26:32 +020090
91 if (twi_int_status & XMTSERV) {
92 /* Transmit next data */
93 if (iface->writeNum > 0) {
Sonic Zhang5481d072010-03-22 03:23:18 -040094 SSYNC();
Bryan Wuaa3d0202008-04-22 22:16:48 +020095 write_XMT_DATA8(iface, *(iface->transPtr++));
Bryan Wud24ecfc2007-05-01 23:26:32 +020096 iface->writeNum--;
97 }
98 /* start receive immediately after complete sending in
99 * combine mode.
100 */
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200101 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200102 write_MASTER_CTL(iface,
Sonic Zhang28a377c2012-06-13 16:22:44 +0800103 read_MASTER_CTL(iface) | MDIR);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200104 else if (iface->manual_stop)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200105 write_MASTER_CTL(iface,
106 read_MASTER_CTL(iface) | STOP);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200107 else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
Frank Shew94327d02009-05-19 07:23:49 -0400108 iface->cur_msg + 1 < iface->msg_num) {
109 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
110 write_MASTER_CTL(iface,
Sonic Zhang28a377c2012-06-13 16:22:44 +0800111 read_MASTER_CTL(iface) | MDIR);
Frank Shew94327d02009-05-19 07:23:49 -0400112 else
113 write_MASTER_CTL(iface,
Sonic Zhang28a377c2012-06-13 16:22:44 +0800114 read_MASTER_CTL(iface) & ~MDIR);
Frank Shew94327d02009-05-19 07:23:49 -0400115 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200116 }
117 if (twi_int_status & RCVSERV) {
118 if (iface->readNum > 0) {
119 /* Receive next data */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200120 *(iface->transPtr) = read_RCV_DATA8(iface);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200121 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
122 /* Change combine mode into sub mode after
123 * read first data.
124 */
125 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
126 /* Get read number from first byte in block
127 * combine mode.
128 */
129 if (iface->readNum == 1 && iface->manual_stop)
130 iface->readNum = *iface->transPtr + 1;
131 }
132 iface->transPtr++;
133 iface->readNum--;
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800134 }
135
136 if (iface->readNum == 0) {
137 if (iface->manual_stop) {
138 /* Temporary workaround to avoid possible bus stall -
139 * Flush FIFO before issuing the STOP condition
140 */
141 read_RCV_DATA16(iface);
Frank Shew94327d02009-05-19 07:23:49 -0400142 write_MASTER_CTL(iface,
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800143 read_MASTER_CTL(iface) | STOP);
144 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
145 iface->cur_msg + 1 < iface->msg_num) {
146 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
147 write_MASTER_CTL(iface,
Sonic Zhang28a377c2012-06-13 16:22:44 +0800148 read_MASTER_CTL(iface) | MDIR);
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800149 else
150 write_MASTER_CTL(iface,
Sonic Zhang28a377c2012-06-13 16:22:44 +0800151 read_MASTER_CTL(iface) & ~MDIR);
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800152 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200153 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200154 }
155 if (twi_int_status & MERR) {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200156 write_INT_MASK(iface, 0);
157 write_MASTER_STAT(iface, 0x3e);
158 write_MASTER_CTL(iface, 0);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200159 iface->result = -EIO;
Michael Hennerich5cfafc12010-03-22 03:23:17 -0400160
161 if (mast_stat & LOSTARB)
162 dev_dbg(&iface->adap.dev, "Lost Arbitration\n");
163 if (mast_stat & ANAK)
164 dev_dbg(&iface->adap.dev, "Address Not Acknowledged\n");
165 if (mast_stat & DNAK)
166 dev_dbg(&iface->adap.dev, "Data Not Acknowledged\n");
167 if (mast_stat & BUFRDERR)
168 dev_dbg(&iface->adap.dev, "Buffer Read Error\n");
169 if (mast_stat & BUFWRERR)
170 dev_dbg(&iface->adap.dev, "Buffer Write Error\n");
171
Michael Hennerich540ac552011-01-11 00:25:08 -0500172 /* Faulty slave devices, may drive SDA low after a transfer
173 * finishes. To release the bus this code generates up to 9
174 * extra clocks until SDA is released.
175 */
176
177 if (read_MASTER_STAT(iface) & SDASEN) {
178 int cnt = 9;
179 do {
180 write_MASTER_CTL(iface, SCLOVR);
181 udelay(6);
182 write_MASTER_CTL(iface, 0);
183 udelay(6);
184 } while ((read_MASTER_STAT(iface) & SDASEN) && cnt--);
185
186 write_MASTER_CTL(iface, SDAOVR | SCLOVR);
187 udelay(6);
188 write_MASTER_CTL(iface, SDAOVR);
189 udelay(6);
190 write_MASTER_CTL(iface, 0);
191 }
192
Sonic Zhangf0ac1312010-03-22 03:23:20 -0400193 /* If it is a quick transfer, only address without data,
194 * not an err, return 1.
Bryan Wud24ecfc2007-05-01 23:26:32 +0200195 */
Sonic Zhangf0ac1312010-03-22 03:23:20 -0400196 if (iface->cur_mode == TWI_I2C_MODE_STANDARD &&
197 iface->transPtr == NULL &&
198 (twi_int_status & MCOMP) && (mast_stat & DNAK))
199 iface->result = 1;
200
Bryan Wud24ecfc2007-05-01 23:26:32 +0200201 complete(&iface->complete);
202 return;
203 }
204 if (twi_int_status & MCOMP) {
Sonic Zhang2ee74eb2012-06-13 16:22:43 +0800205 if (twi_int_status & (XMTSERV | RCVSERV) &&
206 (read_MASTER_CTL(iface) & MEN) == 0 &&
Sonic Zhang4a651632011-06-23 17:07:54 -0400207 (iface->cur_mode == TWI_I2C_MODE_REPEAT ||
208 iface->cur_mode == TWI_I2C_MODE_COMBINED)) {
209 iface->result = -1;
210 write_INT_MASK(iface, 0);
211 write_MASTER_CTL(iface, 0);
212 } else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
Bryan Wud24ecfc2007-05-01 23:26:32 +0200213 if (iface->readNum == 0) {
214 /* set the read number to 1 and ask for manual
215 * stop in block combine mode
216 */
217 iface->readNum = 1;
218 iface->manual_stop = 1;
Bryan Wuaa3d0202008-04-22 22:16:48 +0200219 write_MASTER_CTL(iface,
220 read_MASTER_CTL(iface) | (0xff << 6));
Bryan Wud24ecfc2007-05-01 23:26:32 +0200221 } else {
222 /* set the readd number in other
223 * combine mode.
224 */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200225 write_MASTER_CTL(iface,
226 (read_MASTER_CTL(iface) &
Bryan Wud24ecfc2007-05-01 23:26:32 +0200227 (~(0xff << 6))) |
Bryan Wuaa3d0202008-04-22 22:16:48 +0200228 (iface->readNum << 6));
Bryan Wud24ecfc2007-05-01 23:26:32 +0200229 }
230 /* remove restart bit and enable master receive */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200231 write_MASTER_CTL(iface,
232 read_MASTER_CTL(iface) & ~RSTART);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200233 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
Sonic Zhang28a377c2012-06-13 16:22:44 +0800234 iface->cur_msg + 1 < iface->msg_num) {
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200235 iface->cur_msg++;
236 iface->transPtr = iface->pmsg[iface->cur_msg].buf;
237 iface->writeNum = iface->readNum =
238 iface->pmsg[iface->cur_msg].len;
239 /* Set Transmit device address */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200240 write_MASTER_ADDR(iface,
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200241 iface->pmsg[iface->cur_msg].addr);
242 if (iface->pmsg[iface->cur_msg].flags & I2C_M_RD)
243 iface->read_write = I2C_SMBUS_READ;
244 else {
245 iface->read_write = I2C_SMBUS_WRITE;
246 /* Transmit first data */
247 if (iface->writeNum > 0) {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200248 write_XMT_DATA8(iface,
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200249 *(iface->transPtr++));
250 iface->writeNum--;
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200251 }
252 }
253
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800254 if (iface->pmsg[iface->cur_msg].len <= 255) {
255 write_MASTER_CTL(iface,
Sonic Zhang57a8f322009-05-19 07:21:58 -0400256 (read_MASTER_CTL(iface) &
257 (~(0xff << 6))) |
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800258 (iface->pmsg[iface->cur_msg].len << 6));
259 iface->manual_stop = 0;
260 } else {
Sonic Zhang57a8f322009-05-19 07:21:58 -0400261 write_MASTER_CTL(iface,
262 (read_MASTER_CTL(iface) |
263 (0xff << 6)));
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200264 iface->manual_stop = 1;
265 }
Sonic Zhang28a377c2012-06-13 16:22:44 +0800266 /* remove restart bit before last message */
267 if (iface->cur_msg + 1 == iface->msg_num)
268 write_MASTER_CTL(iface,
269 read_MASTER_CTL(iface) & ~RSTART);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200270 } else {
271 iface->result = 1;
Bryan Wuaa3d0202008-04-22 22:16:48 +0200272 write_INT_MASK(iface, 0);
273 write_MASTER_CTL(iface, 0);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200274 }
Sonic Zhanga20a64d2012-06-13 16:22:41 +0800275 complete(&iface->complete);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200276 }
277}
278
279/* Interrupt handler */
280static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
281{
282 struct bfin_twi_iface *iface = dev_id;
283 unsigned long flags;
Sonic Zhang5481d072010-03-22 03:23:18 -0400284 unsigned short twi_int_status;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200285
286 spin_lock_irqsave(&iface->lock, flags);
Sonic Zhang5481d072010-03-22 03:23:18 -0400287 while (1) {
288 twi_int_status = read_INT_STAT(iface);
289 if (!twi_int_status)
290 break;
291 /* Clear interrupt status */
292 write_INT_STAT(iface, twi_int_status);
293 bfin_twi_handle_interrupt(iface, twi_int_status);
294 SSYNC();
295 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200296 spin_unlock_irqrestore(&iface->lock, flags);
297 return IRQ_HANDLED;
298}
299
Bryan Wud24ecfc2007-05-01 23:26:32 +0200300/*
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400301 * One i2c master transfer
Bryan Wud24ecfc2007-05-01 23:26:32 +0200302 */
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400303static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
Bryan Wud24ecfc2007-05-01 23:26:32 +0200304 struct i2c_msg *msgs, int num)
305{
306 struct bfin_twi_iface *iface = adap->algo_data;
307 struct i2c_msg *pmsg;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200308 int rc = 0;
309
Bryan Wuaa3d0202008-04-22 22:16:48 +0200310 if (!(read_CONTROL(iface) & TWI_ENA))
Bryan Wud24ecfc2007-05-01 23:26:32 +0200311 return -ENXIO;
312
Sonic Zhanga25733d2012-06-13 16:22:42 +0800313 if (read_MASTER_STAT(iface) & BUSBUSY)
314 return -EAGAIN;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200315
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200316 iface->pmsg = msgs;
317 iface->msg_num = num;
318 iface->cur_msg = 0;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200319
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200320 pmsg = &msgs[0];
321 if (pmsg->flags & I2C_M_TEN) {
322 dev_err(&adap->dev, "10 bits addr not supported!\n");
323 return -EINVAL;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200324 }
325
Sonic Zhang28a377c2012-06-13 16:22:44 +0800326 if (iface->msg_num > 1)
327 iface->cur_mode = TWI_I2C_MODE_REPEAT;
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200328 iface->manual_stop = 0;
329 iface->transPtr = pmsg->buf;
330 iface->writeNum = iface->readNum = pmsg->len;
331 iface->result = 0;
Hans Schillstromafc13b72008-04-22 22:16:48 +0200332 init_completion(&(iface->complete));
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200333 /* Set Transmit device address */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200334 write_MASTER_ADDR(iface, pmsg->addr);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200335
336 /* FIFO Initiation. Data in FIFO should be
337 * discarded before start a new operation.
338 */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200339 write_FIFO_CTL(iface, 0x3);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200340 SSYNC();
Bryan Wuaa3d0202008-04-22 22:16:48 +0200341 write_FIFO_CTL(iface, 0);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200342 SSYNC();
343
344 if (pmsg->flags & I2C_M_RD)
345 iface->read_write = I2C_SMBUS_READ;
346 else {
347 iface->read_write = I2C_SMBUS_WRITE;
348 /* Transmit first data */
349 if (iface->writeNum > 0) {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200350 write_XMT_DATA8(iface, *(iface->transPtr++));
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200351 iface->writeNum--;
352 SSYNC();
353 }
354 }
355
356 /* clear int stat */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200357 write_INT_STAT(iface, MERR | MCOMP | XMTSERV | RCVSERV);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200358
359 /* Interrupt mask . Enable XMT, RCV interrupt */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200360 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200361 SSYNC();
362
363 if (pmsg->len <= 255)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200364 write_MASTER_CTL(iface, pmsg->len << 6);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200365 else {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200366 write_MASTER_CTL(iface, 0xff << 6);
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200367 iface->manual_stop = 1;
368 }
369
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200370 /* Master enable */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200371 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
Sonic Zhang28a377c2012-06-13 16:22:44 +0800372 (iface->msg_num > 1 ? RSTART : 0) |
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200373 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
374 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
375 SSYNC();
376
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400377 while (!iface->result) {
378 if (!wait_for_completion_timeout(&iface->complete,
379 adap->timeout)) {
380 iface->result = -1;
381 dev_err(&adap->dev, "master transfer timeout\n");
382 }
383 }
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200384
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400385 if (iface->result == 1)
386 rc = iface->cur_msg + 1;
Sonic Zhang4dd39bb2008-04-22 22:16:47 +0200387 else
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400388 rc = iface->result;
389
390 return rc;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200391}
392
393/*
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400394 * Generic i2c master transfer entrypoint
Bryan Wud24ecfc2007-05-01 23:26:32 +0200395 */
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400396static int bfin_twi_master_xfer(struct i2c_adapter *adap,
397 struct i2c_msg *msgs, int num)
398{
Sonic Zhangbe2f80f2010-03-22 03:23:19 -0400399 return bfin_twi_do_master_xfer(adap, msgs, num);
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400400}
401
402/*
403 * One I2C SMBus transfer
404 */
405int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
Bryan Wud24ecfc2007-05-01 23:26:32 +0200406 unsigned short flags, char read_write,
407 u8 command, int size, union i2c_smbus_data *data)
408{
409 struct bfin_twi_iface *iface = adap->algo_data;
410 int rc = 0;
411
Bryan Wuaa3d0202008-04-22 22:16:48 +0200412 if (!(read_CONTROL(iface) & TWI_ENA))
Bryan Wud24ecfc2007-05-01 23:26:32 +0200413 return -ENXIO;
414
Sonic Zhanga25733d2012-06-13 16:22:42 +0800415 if (read_MASTER_STAT(iface) & BUSBUSY)
416 return -EAGAIN;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200417
418 iface->writeNum = 0;
419 iface->readNum = 0;
420
421 /* Prepare datas & select mode */
422 switch (size) {
423 case I2C_SMBUS_QUICK:
424 iface->transPtr = NULL;
425 iface->cur_mode = TWI_I2C_MODE_STANDARD;
426 break;
427 case I2C_SMBUS_BYTE:
428 if (data == NULL)
429 iface->transPtr = NULL;
430 else {
431 if (read_write == I2C_SMBUS_READ)
432 iface->readNum = 1;
433 else
434 iface->writeNum = 1;
435 iface->transPtr = &data->byte;
436 }
437 iface->cur_mode = TWI_I2C_MODE_STANDARD;
438 break;
439 case I2C_SMBUS_BYTE_DATA:
440 if (read_write == I2C_SMBUS_READ) {
441 iface->readNum = 1;
442 iface->cur_mode = TWI_I2C_MODE_COMBINED;
443 } else {
444 iface->writeNum = 1;
445 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
446 }
447 iface->transPtr = &data->byte;
448 break;
449 case I2C_SMBUS_WORD_DATA:
450 if (read_write == I2C_SMBUS_READ) {
451 iface->readNum = 2;
452 iface->cur_mode = TWI_I2C_MODE_COMBINED;
453 } else {
454 iface->writeNum = 2;
455 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
456 }
457 iface->transPtr = (u8 *)&data->word;
458 break;
459 case I2C_SMBUS_PROC_CALL:
460 iface->writeNum = 2;
461 iface->readNum = 2;
462 iface->cur_mode = TWI_I2C_MODE_COMBINED;
463 iface->transPtr = (u8 *)&data->word;
464 break;
465 case I2C_SMBUS_BLOCK_DATA:
466 if (read_write == I2C_SMBUS_READ) {
467 iface->readNum = 0;
468 iface->cur_mode = TWI_I2C_MODE_COMBINED;
469 } else {
470 iface->writeNum = data->block[0] + 1;
471 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
472 }
473 iface->transPtr = data->block;
474 break;
Michael Henneriche0cd2dd2009-05-27 09:24:10 +0000475 case I2C_SMBUS_I2C_BLOCK_DATA:
476 if (read_write == I2C_SMBUS_READ) {
477 iface->readNum = data->block[0];
478 iface->cur_mode = TWI_I2C_MODE_COMBINED;
479 } else {
480 iface->writeNum = data->block[0];
481 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
482 }
483 iface->transPtr = (u8 *)&data->block[1];
484 break;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200485 default:
486 return -1;
487 }
488
489 iface->result = 0;
490 iface->manual_stop = 0;
491 iface->read_write = read_write;
492 iface->command = command;
Hans Schillstromafc13b72008-04-22 22:16:48 +0200493 init_completion(&(iface->complete));
Bryan Wud24ecfc2007-05-01 23:26:32 +0200494
495 /* FIFO Initiation. Data in FIFO should be discarded before
496 * start a new operation.
497 */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200498 write_FIFO_CTL(iface, 0x3);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200499 SSYNC();
Bryan Wuaa3d0202008-04-22 22:16:48 +0200500 write_FIFO_CTL(iface, 0);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200501
502 /* clear int stat */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200503 write_INT_STAT(iface, MERR | MCOMP | XMTSERV | RCVSERV);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200504
505 /* Set Transmit device address */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200506 write_MASTER_ADDR(iface, addr);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200507 SSYNC();
508
Bryan Wud24ecfc2007-05-01 23:26:32 +0200509 switch (iface->cur_mode) {
510 case TWI_I2C_MODE_STANDARDSUB:
Bryan Wuaa3d0202008-04-22 22:16:48 +0200511 write_XMT_DATA8(iface, iface->command);
512 write_INT_MASK(iface, MCOMP | MERR |
Bryan Wud24ecfc2007-05-01 23:26:32 +0200513 ((iface->read_write == I2C_SMBUS_READ) ?
514 RCVSERV : XMTSERV));
515 SSYNC();
516
517 if (iface->writeNum + 1 <= 255)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200518 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200519 else {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200520 write_MASTER_CTL(iface, 0xff << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200521 iface->manual_stop = 1;
522 }
523 /* Master enable */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200524 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
Bryan Wud24ecfc2007-05-01 23:26:32 +0200525 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
526 break;
527 case TWI_I2C_MODE_COMBINED:
Bryan Wuaa3d0202008-04-22 22:16:48 +0200528 write_XMT_DATA8(iface, iface->command);
529 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200530 SSYNC();
531
532 if (iface->writeNum > 0)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200533 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200534 else
Bryan Wuaa3d0202008-04-22 22:16:48 +0200535 write_MASTER_CTL(iface, 0x1 << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200536 /* Master enable */
Sonic Zhang28a377c2012-06-13 16:22:44 +0800537 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | RSTART |
Bryan Wud24ecfc2007-05-01 23:26:32 +0200538 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
539 break;
540 default:
Bryan Wuaa3d0202008-04-22 22:16:48 +0200541 write_MASTER_CTL(iface, 0);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200542 if (size != I2C_SMBUS_QUICK) {
543 /* Don't access xmit data register when this is a
544 * read operation.
545 */
546 if (iface->read_write != I2C_SMBUS_READ) {
547 if (iface->writeNum > 0) {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200548 write_XMT_DATA8(iface,
549 *(iface->transPtr++));
Bryan Wud24ecfc2007-05-01 23:26:32 +0200550 if (iface->writeNum <= 255)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200551 write_MASTER_CTL(iface,
552 iface->writeNum << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200553 else {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200554 write_MASTER_CTL(iface,
555 0xff << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200556 iface->manual_stop = 1;
557 }
558 iface->writeNum--;
559 } else {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200560 write_XMT_DATA8(iface, iface->command);
561 write_MASTER_CTL(iface, 1 << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200562 }
563 } else {
564 if (iface->readNum > 0 && iface->readNum <= 255)
Bryan Wuaa3d0202008-04-22 22:16:48 +0200565 write_MASTER_CTL(iface,
566 iface->readNum << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200567 else if (iface->readNum > 255) {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200568 write_MASTER_CTL(iface, 0xff << 6);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200569 iface->manual_stop = 1;
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400570 } else
Bryan Wud24ecfc2007-05-01 23:26:32 +0200571 break;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200572 }
573 }
Bryan Wuaa3d0202008-04-22 22:16:48 +0200574 write_INT_MASK(iface, MCOMP | MERR |
Bryan Wud24ecfc2007-05-01 23:26:32 +0200575 ((iface->read_write == I2C_SMBUS_READ) ?
576 RCVSERV : XMTSERV));
577 SSYNC();
578
579 /* Master enable */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200580 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
Bryan Wud24ecfc2007-05-01 23:26:32 +0200581 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
582 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
583 break;
584 }
585 SSYNC();
586
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400587 while (!iface->result) {
588 if (!wait_for_completion_timeout(&iface->complete,
589 adap->timeout)) {
590 iface->result = -1;
591 dev_err(&adap->dev, "smbus transfer timeout\n");
592 }
593 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200594
595 rc = (iface->result >= 0) ? 0 : -1;
596
Bryan Wud24ecfc2007-05-01 23:26:32 +0200597 return rc;
598}
599
600/*
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400601 * Generic I2C SMBus transfer entrypoint
602 */
603int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
604 unsigned short flags, char read_write,
605 u8 command, int size, union i2c_smbus_data *data)
606{
Sonic Zhangbe2f80f2010-03-22 03:23:19 -0400607 return bfin_twi_do_smbus_xfer(adap, addr, flags,
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400608 read_write, command, size, data);
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400609}
610
611/*
Bryan Wud24ecfc2007-05-01 23:26:32 +0200612 * Return what the adapter supports
613 */
614static u32 bfin_twi_functionality(struct i2c_adapter *adap)
615{
616 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
617 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
618 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |
Michael Henneriche0cd2dd2009-05-27 09:24:10 +0000619 I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200620}
621
Bryan Wud24ecfc2007-05-01 23:26:32 +0200622static struct i2c_algorithm bfin_twi_algorithm = {
623 .master_xfer = bfin_twi_master_xfer,
624 .smbus_xfer = bfin_twi_smbus_xfer,
625 .functionality = bfin_twi_functionality,
626};
627
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200628static int i2c_bfin_twi_suspend(struct device *dev)
Bryan Wud24ecfc2007-05-01 23:26:32 +0200629{
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200630 struct bfin_twi_iface *iface = dev_get_drvdata(dev);
Michael Hennerich958585f2008-07-27 14:41:54 +0800631
632 iface->saved_clkdiv = read_CLKDIV(iface);
633 iface->saved_control = read_CONTROL(iface);
634
635 free_irq(iface->irq, iface);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200636
637 /* Disable TWI */
Michael Hennerich958585f2008-07-27 14:41:54 +0800638 write_CONTROL(iface, iface->saved_control & ~TWI_ENA);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200639
640 return 0;
641}
642
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200643static int i2c_bfin_twi_resume(struct device *dev)
Bryan Wud24ecfc2007-05-01 23:26:32 +0200644{
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200645 struct bfin_twi_iface *iface = dev_get_drvdata(dev);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200646
Michael Hennerich958585f2008-07-27 14:41:54 +0800647 int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200648 0, to_platform_device(dev)->name, iface);
Michael Hennerich958585f2008-07-27 14:41:54 +0800649 if (rc) {
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200650 dev_err(dev, "Can't get IRQ %d !\n", iface->irq);
Michael Hennerich958585f2008-07-27 14:41:54 +0800651 return -ENODEV;
652 }
653
654 /* Resume TWI interface clock as specified */
655 write_CLKDIV(iface, iface->saved_clkdiv);
656
657 /* Resume TWI */
658 write_CONTROL(iface, iface->saved_control);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200659
660 return 0;
661}
662
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200663static SIMPLE_DEV_PM_OPS(i2c_bfin_twi_pm,
664 i2c_bfin_twi_suspend, i2c_bfin_twi_resume);
665
Bryan Wuaa3d0202008-04-22 22:16:48 +0200666static int i2c_bfin_twi_probe(struct platform_device *pdev)
Bryan Wud24ecfc2007-05-01 23:26:32 +0200667{
Bryan Wuaa3d0202008-04-22 22:16:48 +0200668 struct bfin_twi_iface *iface;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200669 struct i2c_adapter *p_adap;
Bryan Wuaa3d0202008-04-22 22:16:48 +0200670 struct resource *res;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200671 int rc;
Michael Hennerich9528d1c2009-05-18 08:14:41 -0400672 unsigned int clkhilow;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200673
Bryan Wuaa3d0202008-04-22 22:16:48 +0200674 iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL);
675 if (!iface) {
676 dev_err(&pdev->dev, "Cannot allocate memory\n");
677 rc = -ENOMEM;
678 goto out_error_nomem;
679 }
680
Bryan Wud24ecfc2007-05-01 23:26:32 +0200681 spin_lock_init(&(iface->lock));
Bryan Wuaa3d0202008-04-22 22:16:48 +0200682
683 /* Find and map our resources */
684 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
685 if (res == NULL) {
686 dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
687 rc = -ENOENT;
688 goto out_error_get_res;
689 }
690
Linus Walleijc6ffdde2009-06-14 00:20:36 +0200691 iface->regs_base = ioremap(res->start, resource_size(res));
Bryan Wuaa3d0202008-04-22 22:16:48 +0200692 if (iface->regs_base == NULL) {
693 dev_err(&pdev->dev, "Cannot map IO\n");
694 rc = -ENXIO;
695 goto out_error_ioremap;
696 }
697
698 iface->irq = platform_get_irq(pdev, 0);
699 if (iface->irq < 0) {
700 dev_err(&pdev->dev, "No IRQ specified\n");
701 rc = -ENOENT;
702 goto out_error_no_irq;
703 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200704
Bryan Wud24ecfc2007-05-01 23:26:32 +0200705 p_adap = &iface->adap;
Bryan Wuaa3d0202008-04-22 22:16:48 +0200706 p_adap->nr = pdev->id;
707 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
Bryan Wud24ecfc2007-05-01 23:26:32 +0200708 p_adap->algo = &bfin_twi_algorithm;
709 p_adap->algo_data = iface;
Jean Delvaree1995f62009-01-07 14:29:16 +0100710 p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
Bryan Wuaa3d0202008-04-22 22:16:48 +0200711 p_adap->dev.parent = &pdev->dev;
Sonic Zhangdd7319a2010-03-22 03:23:16 -0400712 p_adap->timeout = 5 * HZ;
713 p_adap->retries = 3;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200714
Bryan Wu74d362e2008-04-22 22:16:48 +0200715 rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi");
716 if (rc) {
717 dev_err(&pdev->dev, "Can't setup pin mux!\n");
718 goto out_error_pin_mux;
719 }
720
Bryan Wud24ecfc2007-05-01 23:26:32 +0200721 rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
Yong Zhang43110512011-09-21 17:28:33 +0800722 0, pdev->name, iface);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200723 if (rc) {
Bryan Wuaa3d0202008-04-22 22:16:48 +0200724 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
725 rc = -ENODEV;
726 goto out_error_req_irq;
Bryan Wud24ecfc2007-05-01 23:26:32 +0200727 }
728
729 /* Set TWI internal clock as 10MHz */
Sonic Zhangac07fb42009-12-21 09:28:30 -0500730 write_CONTROL(iface, ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200731
Michael Hennerich9528d1c2009-05-18 08:14:41 -0400732 /*
733 * We will not end up with a CLKDIV=0 because no one will specify
Sonic Zhangac07fb42009-12-21 09:28:30 -0500734 * 20kHz SCL or less in Kconfig now. (5 * 1000 / 20 = 250)
Michael Hennerich9528d1c2009-05-18 08:14:41 -0400735 */
Sonic Zhangac07fb42009-12-21 09:28:30 -0500736 clkhilow = ((10 * 1000 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ) + 1) / 2;
Michael Hennerich9528d1c2009-05-18 08:14:41 -0400737
Bryan Wud24ecfc2007-05-01 23:26:32 +0200738 /* Set Twi interface clock as specified */
Michael Hennerich9528d1c2009-05-18 08:14:41 -0400739 write_CLKDIV(iface, (clkhilow << 8) | clkhilow);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200740
741 /* Enable TWI */
Bryan Wuaa3d0202008-04-22 22:16:48 +0200742 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200743 SSYNC();
744
Kalle Pokki991dee52008-01-27 18:14:52 +0100745 rc = i2c_add_numbered_adapter(p_adap);
Bryan Wuaa3d0202008-04-22 22:16:48 +0200746 if (rc < 0) {
747 dev_err(&pdev->dev, "Can't add i2c adapter!\n");
748 goto out_error_add_adapter;
749 }
Bryan Wud24ecfc2007-05-01 23:26:32 +0200750
Bryan Wuaa3d0202008-04-22 22:16:48 +0200751 platform_set_drvdata(pdev, iface);
752
Bryan Wufa6ad222008-04-22 22:16:48 +0200753 dev_info(&pdev->dev, "Blackfin BF5xx on-chip I2C TWI Contoller, "
754 "regs_base@%p\n", iface->regs_base);
Bryan Wuaa3d0202008-04-22 22:16:48 +0200755
756 return 0;
757
758out_error_add_adapter:
759 free_irq(iface->irq, iface);
760out_error_req_irq:
761out_error_no_irq:
Bryan Wu74d362e2008-04-22 22:16:48 +0200762 peripheral_free_list(pin_req[pdev->id]);
763out_error_pin_mux:
Bryan Wuaa3d0202008-04-22 22:16:48 +0200764 iounmap(iface->regs_base);
765out_error_ioremap:
766out_error_get_res:
767 kfree(iface);
768out_error_nomem:
Bryan Wud24ecfc2007-05-01 23:26:32 +0200769 return rc;
770}
771
772static int i2c_bfin_twi_remove(struct platform_device *pdev)
773{
774 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
775
776 platform_set_drvdata(pdev, NULL);
777
778 i2c_del_adapter(&(iface->adap));
779 free_irq(iface->irq, iface);
Bryan Wu74d362e2008-04-22 22:16:48 +0200780 peripheral_free_list(pin_req[pdev->id]);
Bryan Wuaa3d0202008-04-22 22:16:48 +0200781 iounmap(iface->regs_base);
782 kfree(iface);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200783
784 return 0;
785}
786
787static struct platform_driver i2c_bfin_twi_driver = {
788 .probe = i2c_bfin_twi_probe,
789 .remove = i2c_bfin_twi_remove,
Bryan Wud24ecfc2007-05-01 23:26:32 +0200790 .driver = {
791 .name = "i2c-bfin-twi",
792 .owner = THIS_MODULE,
Rafael J. Wysocki85777ad2012-07-11 21:23:31 +0200793 .pm = &i2c_bfin_twi_pm,
Bryan Wud24ecfc2007-05-01 23:26:32 +0200794 },
795};
796
797static int __init i2c_bfin_twi_init(void)
798{
Bryan Wud24ecfc2007-05-01 23:26:32 +0200799 return platform_driver_register(&i2c_bfin_twi_driver);
800}
801
802static void __exit i2c_bfin_twi_exit(void)
803{
804 platform_driver_unregister(&i2c_bfin_twi_driver);
805}
806
Michael Hennerich74f56c42011-01-11 00:25:09 -0500807subsys_initcall(i2c_bfin_twi_init);
Bryan Wud24ecfc2007-05-01 23:26:32 +0200808module_exit(i2c_bfin_twi_exit);
Bryan Wufa6ad222008-04-22 22:16:48 +0200809
810MODULE_AUTHOR("Bryan Wu, Sonic Zhang");
811MODULE_DESCRIPTION("Blackfin BF5xx on-chip I2C TWI Contoller Driver");
812MODULE_LICENSE("GPL");
Kay Sieversadd8eda2008-04-22 22:16:49 +0200813MODULE_ALIAS("platform:i2c-bfin-twi");