2007-05-02 05:26:32 +08:00
|
|
|
/*
|
2008-04-23 04:16:48 +08:00
|
|
|
* Blackfin On-Chip Two Wire Interface Driver
|
2007-05-02 05:26:32 +08:00
|
|
|
*
|
2008-04-23 04:16:48 +08:00
|
|
|
* Copyright 2005-2007 Analog Devices Inc.
|
2007-05-02 05:26:32 +08:00
|
|
|
*
|
2008-04-23 04:16:48 +08:00
|
|
|
* Enter bugs at http://blackfin.uclinux.org/
|
2007-05-02 05:26:32 +08:00
|
|
|
*
|
2008-04-23 04:16:48 +08:00
|
|
|
* Licensed under the GPL-2 or later.
|
2007-05-02 05:26:32 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-06-14 13:55:37 +08:00
|
|
|
#include <linux/io.h>
|
2007-05-02 05:26:32 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
2011-01-11 13:25:08 +08:00
|
|
|
#include <linux/delay.h>
|
2014-01-28 16:55:21 +08:00
|
|
|
#include <linux/i2c/bfin_twi.h>
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
#include <asm/irq.h>
|
2014-01-28 16:55:21 +08:00
|
|
|
#include <asm/portmux.h>
|
2012-06-13 16:22:45 +08:00
|
|
|
#include <asm/bfin_twi.h>
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
/* SMBus mode*/
|
2008-04-23 04:16:47 +08:00
|
|
|
#define TWI_I2C_MODE_STANDARD 1
|
|
|
|
#define TWI_I2C_MODE_STANDARDSUB 2
|
|
|
|
#define TWI_I2C_MODE_COMBINED 3
|
|
|
|
#define TWI_I2C_MODE_REPEAT 4
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2010-03-22 15:23:18 +08:00
|
|
|
static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
|
|
|
|
unsigned short twi_int_status)
|
2007-05-02 05:26:32 +08:00
|
|
|
{
|
2008-04-23 04:16:48 +08:00
|
|
|
unsigned short mast_stat = read_MASTER_STAT(iface);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
if (twi_int_status & XMTSERV) {
|
2013-05-28 18:41:09 +08:00
|
|
|
if (iface->writeNum <= 0) {
|
|
|
|
/* start receive immediately after complete sending in
|
|
|
|
* combine mode.
|
|
|
|
*/
|
|
|
|
if (iface->cur_mode == TWI_I2C_MODE_COMBINED)
|
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) | MDIR);
|
|
|
|
else if (iface->manual_stop)
|
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) | STOP);
|
|
|
|
else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
|
|
|
|
iface->cur_msg + 1 < iface->msg_num) {
|
|
|
|
if (iface->pmsg[iface->cur_msg + 1].flags &
|
|
|
|
I2C_M_RD)
|
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) |
|
|
|
|
MDIR);
|
|
|
|
else
|
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) &
|
|
|
|
~MDIR);
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
/* Transmit next data */
|
2013-05-28 18:41:09 +08:00
|
|
|
while (iface->writeNum > 0 &&
|
|
|
|
(read_FIFO_STAT(iface) & XMTSTAT) != XMT_FULL) {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface, *(iface->transPtr++));
|
2007-05-02 05:26:32 +08:00
|
|
|
iface->writeNum--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (twi_int_status & RCVSERV) {
|
2013-05-28 18:41:09 +08:00
|
|
|
while (iface->readNum > 0 &&
|
|
|
|
(read_FIFO_STAT(iface) & RCVSTAT)) {
|
2007-05-02 05:26:32 +08:00
|
|
|
/* Receive next data */
|
2008-04-23 04:16:48 +08:00
|
|
|
*(iface->transPtr) = read_RCV_DATA8(iface);
|
2007-05-02 05:26:32 +08:00
|
|
|
if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
|
|
|
|
/* Change combine mode into sub mode after
|
|
|
|
* read first data.
|
|
|
|
*/
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
|
|
|
|
/* Get read number from first byte in block
|
|
|
|
* combine mode.
|
|
|
|
*/
|
|
|
|
if (iface->readNum == 1 && iface->manual_stop)
|
|
|
|
iface->readNum = *iface->transPtr + 1;
|
|
|
|
}
|
|
|
|
iface->transPtr++;
|
|
|
|
iface->readNum--;
|
2012-06-13 16:22:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (iface->readNum == 0) {
|
|
|
|
if (iface->manual_stop) {
|
|
|
|
/* Temporary workaround to avoid possible bus stall -
|
|
|
|
* Flush FIFO before issuing the STOP condition
|
|
|
|
*/
|
|
|
|
read_RCV_DATA16(iface);
|
2009-05-19 19:23:49 +08:00
|
|
|
write_MASTER_CTL(iface,
|
2012-06-13 16:22:41 +08:00
|
|
|
read_MASTER_CTL(iface) | STOP);
|
|
|
|
} else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
|
|
|
|
iface->cur_msg + 1 < iface->msg_num) {
|
|
|
|
if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
|
|
|
|
write_MASTER_CTL(iface,
|
2012-06-13 16:22:44 +08:00
|
|
|
read_MASTER_CTL(iface) | MDIR);
|
2012-06-13 16:22:41 +08:00
|
|
|
else
|
|
|
|
write_MASTER_CTL(iface,
|
2012-06-13 16:22:44 +08:00
|
|
|
read_MASTER_CTL(iface) & ~MDIR);
|
2012-06-13 16:22:41 +08:00
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (twi_int_status & MERR) {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_INT_MASK(iface, 0);
|
|
|
|
write_MASTER_STAT(iface, 0x3e);
|
|
|
|
write_MASTER_CTL(iface, 0);
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->result = -EIO;
|
2010-03-22 15:23:17 +08:00
|
|
|
|
|
|
|
if (mast_stat & LOSTARB)
|
|
|
|
dev_dbg(&iface->adap.dev, "Lost Arbitration\n");
|
|
|
|
if (mast_stat & ANAK)
|
|
|
|
dev_dbg(&iface->adap.dev, "Address Not Acknowledged\n");
|
|
|
|
if (mast_stat & DNAK)
|
|
|
|
dev_dbg(&iface->adap.dev, "Data Not Acknowledged\n");
|
|
|
|
if (mast_stat & BUFRDERR)
|
|
|
|
dev_dbg(&iface->adap.dev, "Buffer Read Error\n");
|
|
|
|
if (mast_stat & BUFWRERR)
|
|
|
|
dev_dbg(&iface->adap.dev, "Buffer Write Error\n");
|
|
|
|
|
2011-01-11 13:25:08 +08:00
|
|
|
/* Faulty slave devices, may drive SDA low after a transfer
|
|
|
|
* finishes. To release the bus this code generates up to 9
|
|
|
|
* extra clocks until SDA is released.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (read_MASTER_STAT(iface) & SDASEN) {
|
|
|
|
int cnt = 9;
|
|
|
|
do {
|
|
|
|
write_MASTER_CTL(iface, SCLOVR);
|
|
|
|
udelay(6);
|
|
|
|
write_MASTER_CTL(iface, 0);
|
|
|
|
udelay(6);
|
|
|
|
} while ((read_MASTER_STAT(iface) & SDASEN) && cnt--);
|
|
|
|
|
|
|
|
write_MASTER_CTL(iface, SDAOVR | SCLOVR);
|
|
|
|
udelay(6);
|
|
|
|
write_MASTER_CTL(iface, SDAOVR);
|
|
|
|
udelay(6);
|
|
|
|
write_MASTER_CTL(iface, 0);
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:23:20 +08:00
|
|
|
/* If it is a quick transfer, only address without data,
|
|
|
|
* not an err, return 1.
|
2007-05-02 05:26:32 +08:00
|
|
|
*/
|
2010-03-22 15:23:20 +08:00
|
|
|
if (iface->cur_mode == TWI_I2C_MODE_STANDARD &&
|
|
|
|
iface->transPtr == NULL &&
|
|
|
|
(twi_int_status & MCOMP) && (mast_stat & DNAK))
|
|
|
|
iface->result = 1;
|
|
|
|
|
2007-05-02 05:26:32 +08:00
|
|
|
complete(&iface->complete);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (twi_int_status & MCOMP) {
|
2012-06-13 16:22:43 +08:00
|
|
|
if (twi_int_status & (XMTSERV | RCVSERV) &&
|
|
|
|
(read_MASTER_CTL(iface) & MEN) == 0 &&
|
2011-06-24 05:07:54 +08:00
|
|
|
(iface->cur_mode == TWI_I2C_MODE_REPEAT ||
|
|
|
|
iface->cur_mode == TWI_I2C_MODE_COMBINED)) {
|
|
|
|
iface->result = -1;
|
|
|
|
write_INT_MASK(iface, 0);
|
|
|
|
write_MASTER_CTL(iface, 0);
|
|
|
|
} else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
|
2007-05-02 05:26:32 +08:00
|
|
|
if (iface->readNum == 0) {
|
|
|
|
/* set the read number to 1 and ask for manual
|
|
|
|
* stop in block combine mode
|
|
|
|
*/
|
|
|
|
iface->readNum = 1;
|
|
|
|
iface->manual_stop = 1;
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) | (0xff << 6));
|
2007-05-02 05:26:32 +08:00
|
|
|
} else {
|
|
|
|
/* set the readd number in other
|
|
|
|
* combine mode.
|
|
|
|
*/
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
(read_MASTER_CTL(iface) &
|
2007-05-02 05:26:32 +08:00
|
|
|
(~(0xff << 6))) |
|
2008-04-23 04:16:48 +08:00
|
|
|
(iface->readNum << 6));
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
/* remove restart bit and enable master receive */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) & ~RSTART);
|
2008-04-23 04:16:47 +08:00
|
|
|
} else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
|
2012-06-13 16:22:44 +08:00
|
|
|
iface->cur_msg + 1 < iface->msg_num) {
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->cur_msg++;
|
|
|
|
iface->transPtr = iface->pmsg[iface->cur_msg].buf;
|
|
|
|
iface->writeNum = iface->readNum =
|
|
|
|
iface->pmsg[iface->cur_msg].len;
|
|
|
|
/* Set Transmit device address */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_ADDR(iface,
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->pmsg[iface->cur_msg].addr);
|
|
|
|
if (iface->pmsg[iface->cur_msg].flags & I2C_M_RD)
|
|
|
|
iface->read_write = I2C_SMBUS_READ;
|
|
|
|
else {
|
|
|
|
iface->read_write = I2C_SMBUS_WRITE;
|
|
|
|
/* Transmit first data */
|
|
|
|
if (iface->writeNum > 0) {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface,
|
2008-04-23 04:16:47 +08:00
|
|
|
*(iface->transPtr++));
|
|
|
|
iface->writeNum--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 16:22:41 +08:00
|
|
|
if (iface->pmsg[iface->cur_msg].len <= 255) {
|
|
|
|
write_MASTER_CTL(iface,
|
2009-05-19 19:21:58 +08:00
|
|
|
(read_MASTER_CTL(iface) &
|
|
|
|
(~(0xff << 6))) |
|
2012-06-13 16:22:41 +08:00
|
|
|
(iface->pmsg[iface->cur_msg].len << 6));
|
|
|
|
iface->manual_stop = 0;
|
|
|
|
} else {
|
2009-05-19 19:21:58 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
(read_MASTER_CTL(iface) |
|
|
|
|
(0xff << 6)));
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->manual_stop = 1;
|
|
|
|
}
|
2012-06-13 16:22:44 +08:00
|
|
|
/* remove restart bit before last message */
|
|
|
|
if (iface->cur_msg + 1 == iface->msg_num)
|
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
read_MASTER_CTL(iface) & ~RSTART);
|
2007-05-02 05:26:32 +08:00
|
|
|
} else {
|
|
|
|
iface->result = 1;
|
2008-04-23 04:16:48 +08:00
|
|
|
write_INT_MASK(iface, 0);
|
|
|
|
write_MASTER_CTL(iface, 0);
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
2012-06-13 16:22:41 +08:00
|
|
|
complete(&iface->complete);
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt handler */
|
|
|
|
static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct bfin_twi_iface *iface = dev_id;
|
|
|
|
unsigned long flags;
|
2010-03-22 15:23:18 +08:00
|
|
|
unsigned short twi_int_status;
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&iface->lock, flags);
|
2010-03-22 15:23:18 +08:00
|
|
|
while (1) {
|
|
|
|
twi_int_status = read_INT_STAT(iface);
|
|
|
|
if (!twi_int_status)
|
|
|
|
break;
|
|
|
|
/* Clear interrupt status */
|
|
|
|
write_INT_STAT(iface, twi_int_status);
|
|
|
|
bfin_twi_handle_interrupt(iface, twi_int_status);
|
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
spin_unlock_irqrestore(&iface->lock, flags);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-03-22 15:23:16 +08:00
|
|
|
* One i2c master transfer
|
2007-05-02 05:26:32 +08:00
|
|
|
*/
|
2010-03-22 15:23:16 +08:00
|
|
|
static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
|
2007-05-02 05:26:32 +08:00
|
|
|
struct i2c_msg *msgs, int num)
|
|
|
|
{
|
|
|
|
struct bfin_twi_iface *iface = adap->algo_data;
|
|
|
|
struct i2c_msg *pmsg;
|
|
|
|
int rc = 0;
|
|
|
|
|
2008-04-23 04:16:48 +08:00
|
|
|
if (!(read_CONTROL(iface) & TWI_ENA))
|
2007-05-02 05:26:32 +08:00
|
|
|
return -ENXIO;
|
|
|
|
|
2012-06-13 16:22:42 +08:00
|
|
|
if (read_MASTER_STAT(iface) & BUSBUSY)
|
|
|
|
return -EAGAIN;
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->pmsg = msgs;
|
|
|
|
iface->msg_num = num;
|
|
|
|
iface->cur_msg = 0;
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:47 +08:00
|
|
|
pmsg = &msgs[0];
|
|
|
|
if (pmsg->flags & I2C_M_TEN) {
|
|
|
|
dev_err(&adap->dev, "10 bits addr not supported!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2012-06-13 16:22:44 +08:00
|
|
|
if (iface->msg_num > 1)
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_REPEAT;
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->manual_stop = 0;
|
|
|
|
iface->transPtr = pmsg->buf;
|
|
|
|
iface->writeNum = iface->readNum = pmsg->len;
|
|
|
|
iface->result = 0;
|
2008-04-23 04:16:48 +08:00
|
|
|
init_completion(&(iface->complete));
|
2008-04-23 04:16:47 +08:00
|
|
|
/* Set Transmit device address */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_ADDR(iface, pmsg->addr);
|
2008-04-23 04:16:47 +08:00
|
|
|
|
|
|
|
/* FIFO Initiation. Data in FIFO should be
|
|
|
|
* discarded before start a new operation.
|
|
|
|
*/
|
2008-04-23 04:16:48 +08:00
|
|
|
write_FIFO_CTL(iface, 0x3);
|
|
|
|
write_FIFO_CTL(iface, 0);
|
2008-04-23 04:16:47 +08:00
|
|
|
|
|
|
|
if (pmsg->flags & I2C_M_RD)
|
|
|
|
iface->read_write = I2C_SMBUS_READ;
|
|
|
|
else {
|
|
|
|
iface->read_write = I2C_SMBUS_WRITE;
|
|
|
|
/* Transmit first data */
|
|
|
|
if (iface->writeNum > 0) {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface, *(iface->transPtr++));
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->writeNum--;
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
2008-04-23 04:16:47 +08:00
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:47 +08:00
|
|
|
/* clear int stat */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_INT_STAT(iface, MERR | MCOMP | XMTSERV | RCVSERV);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:47 +08:00
|
|
|
/* Interrupt mask . Enable XMT, RCV interrupt */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:47 +08:00
|
|
|
if (pmsg->len <= 255)
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, pmsg->len << 6);
|
2008-04-23 04:16:47 +08:00
|
|
|
else {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, 0xff << 6);
|
2008-04-23 04:16:47 +08:00
|
|
|
iface->manual_stop = 1;
|
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:47 +08:00
|
|
|
/* Master enable */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
|
2012-06-13 16:22:44 +08:00
|
|
|
(iface->msg_num > 1 ? RSTART : 0) |
|
2008-04-23 04:16:47 +08:00
|
|
|
((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
|
|
|
|
((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
|
|
|
|
|
2010-03-22 15:23:16 +08:00
|
|
|
while (!iface->result) {
|
|
|
|
if (!wait_for_completion_timeout(&iface->complete,
|
|
|
|
adap->timeout)) {
|
|
|
|
iface->result = -1;
|
|
|
|
dev_err(&adap->dev, "master transfer timeout\n");
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2010-03-22 15:23:16 +08:00
|
|
|
if (iface->result == 1)
|
|
|
|
rc = iface->cur_msg + 1;
|
2008-04-23 04:16:47 +08:00
|
|
|
else
|
2010-03-22 15:23:16 +08:00
|
|
|
rc = iface->result;
|
|
|
|
|
|
|
|
return rc;
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-03-22 15:23:16 +08:00
|
|
|
* Generic i2c master transfer entrypoint
|
2007-05-02 05:26:32 +08:00
|
|
|
*/
|
2010-03-22 15:23:16 +08:00
|
|
|
static int bfin_twi_master_xfer(struct i2c_adapter *adap,
|
|
|
|
struct i2c_msg *msgs, int num)
|
|
|
|
{
|
2010-03-22 15:23:19 +08:00
|
|
|
return bfin_twi_do_master_xfer(adap, msgs, num);
|
2010-03-22 15:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One I2C SMBus transfer
|
|
|
|
*/
|
|
|
|
int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
|
2007-05-02 05:26:32 +08:00
|
|
|
unsigned short flags, char read_write,
|
|
|
|
u8 command, int size, union i2c_smbus_data *data)
|
|
|
|
{
|
|
|
|
struct bfin_twi_iface *iface = adap->algo_data;
|
|
|
|
int rc = 0;
|
|
|
|
|
2008-04-23 04:16:48 +08:00
|
|
|
if (!(read_CONTROL(iface) & TWI_ENA))
|
2007-05-02 05:26:32 +08:00
|
|
|
return -ENXIO;
|
|
|
|
|
2012-06-13 16:22:42 +08:00
|
|
|
if (read_MASTER_STAT(iface) & BUSBUSY)
|
|
|
|
return -EAGAIN;
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
iface->writeNum = 0;
|
|
|
|
iface->readNum = 0;
|
|
|
|
|
|
|
|
/* Prepare datas & select mode */
|
|
|
|
switch (size) {
|
|
|
|
case I2C_SMBUS_QUICK:
|
|
|
|
iface->transPtr = NULL;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARD;
|
|
|
|
break;
|
|
|
|
case I2C_SMBUS_BYTE:
|
|
|
|
if (data == NULL)
|
|
|
|
iface->transPtr = NULL;
|
|
|
|
else {
|
|
|
|
if (read_write == I2C_SMBUS_READ)
|
|
|
|
iface->readNum = 1;
|
|
|
|
else
|
|
|
|
iface->writeNum = 1;
|
|
|
|
iface->transPtr = &data->byte;
|
|
|
|
}
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARD;
|
|
|
|
break;
|
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
|
|
|
if (read_write == I2C_SMBUS_READ) {
|
|
|
|
iface->readNum = 1;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_COMBINED;
|
|
|
|
} else {
|
|
|
|
iface->writeNum = 1;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
|
|
|
|
}
|
|
|
|
iface->transPtr = &data->byte;
|
|
|
|
break;
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
|
|
|
if (read_write == I2C_SMBUS_READ) {
|
|
|
|
iface->readNum = 2;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_COMBINED;
|
|
|
|
} else {
|
|
|
|
iface->writeNum = 2;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
|
|
|
|
}
|
|
|
|
iface->transPtr = (u8 *)&data->word;
|
|
|
|
break;
|
|
|
|
case I2C_SMBUS_PROC_CALL:
|
|
|
|
iface->writeNum = 2;
|
|
|
|
iface->readNum = 2;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_COMBINED;
|
|
|
|
iface->transPtr = (u8 *)&data->word;
|
|
|
|
break;
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
|
|
|
if (read_write == I2C_SMBUS_READ) {
|
|
|
|
iface->readNum = 0;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_COMBINED;
|
|
|
|
} else {
|
|
|
|
iface->writeNum = data->block[0] + 1;
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
|
|
|
|
}
|
|
|
|
iface->transPtr = data->block;
|
|
|
|
break;
|
2009-05-27 17:24:10 +08:00
|
|
|
case I2C_SMBUS_I2C_BLOCK_DATA:
|
|
|
|
if (read_write == I2C_SMBUS_READ) {
|
|
|
|
iface->readNum = data->block[0];
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_COMBINED;
|
|
|
|
} else {
|
|
|
|
iface->writeNum = data->block[0];
|
|
|
|
iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
|
|
|
|
}
|
|
|
|
iface->transPtr = (u8 *)&data->block[1];
|
|
|
|
break;
|
2007-05-02 05:26:32 +08:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface->result = 0;
|
|
|
|
iface->manual_stop = 0;
|
|
|
|
iface->read_write = read_write;
|
|
|
|
iface->command = command;
|
2008-04-23 04:16:48 +08:00
|
|
|
init_completion(&(iface->complete));
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
/* FIFO Initiation. Data in FIFO should be discarded before
|
|
|
|
* start a new operation.
|
|
|
|
*/
|
2008-04-23 04:16:48 +08:00
|
|
|
write_FIFO_CTL(iface, 0x3);
|
|
|
|
write_FIFO_CTL(iface, 0);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
/* clear int stat */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_INT_STAT(iface, MERR | MCOMP | XMTSERV | RCVSERV);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
/* Set Transmit device address */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_ADDR(iface, addr);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
switch (iface->cur_mode) {
|
|
|
|
case TWI_I2C_MODE_STANDARDSUB:
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface, iface->command);
|
|
|
|
write_INT_MASK(iface, MCOMP | MERR |
|
2007-05-02 05:26:32 +08:00
|
|
|
((iface->read_write == I2C_SMBUS_READ) ?
|
|
|
|
RCVSERV : XMTSERV));
|
|
|
|
|
|
|
|
if (iface->writeNum + 1 <= 255)
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
else {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, 0xff << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
iface->manual_stop = 1;
|
|
|
|
}
|
|
|
|
/* Master enable */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
|
2007-05-02 05:26:32 +08:00
|
|
|
((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
|
|
|
|
break;
|
|
|
|
case TWI_I2C_MODE_COMBINED:
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface, iface->command);
|
|
|
|
write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
if (iface->writeNum > 0)
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
else
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, 0x1 << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
/* Master enable */
|
2012-06-13 16:22:44 +08:00
|
|
|
write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | RSTART |
|
2007-05-02 05:26:32 +08:00
|
|
|
((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
|
|
|
|
break;
|
|
|
|
default:
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, 0);
|
2007-05-02 05:26:32 +08:00
|
|
|
if (size != I2C_SMBUS_QUICK) {
|
|
|
|
/* Don't access xmit data register when this is a
|
|
|
|
* read operation.
|
|
|
|
*/
|
|
|
|
if (iface->read_write != I2C_SMBUS_READ) {
|
|
|
|
if (iface->writeNum > 0) {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface,
|
|
|
|
*(iface->transPtr++));
|
2007-05-02 05:26:32 +08:00
|
|
|
if (iface->writeNum <= 255)
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
iface->writeNum << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
else {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
0xff << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
iface->manual_stop = 1;
|
|
|
|
}
|
|
|
|
iface->writeNum--;
|
|
|
|
} else {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_XMT_DATA8(iface, iface->command);
|
|
|
|
write_MASTER_CTL(iface, 1 << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (iface->readNum > 0 && iface->readNum <= 255)
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface,
|
|
|
|
iface->readNum << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
else if (iface->readNum > 255) {
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, 0xff << 6);
|
2007-05-02 05:26:32 +08:00
|
|
|
iface->manual_stop = 1;
|
2010-03-22 15:23:16 +08:00
|
|
|
} else
|
2007-05-02 05:26:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-23 04:16:48 +08:00
|
|
|
write_INT_MASK(iface, MCOMP | MERR |
|
2007-05-02 05:26:32 +08:00
|
|
|
((iface->read_write == I2C_SMBUS_READ) ?
|
|
|
|
RCVSERV : XMTSERV));
|
|
|
|
|
|
|
|
/* Master enable */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
|
2007-05-02 05:26:32 +08:00
|
|
|
((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
|
|
|
|
((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:23:16 +08:00
|
|
|
while (!iface->result) {
|
|
|
|
if (!wait_for_completion_timeout(&iface->complete,
|
|
|
|
adap->timeout)) {
|
|
|
|
iface->result = -1;
|
|
|
|
dev_err(&adap->dev, "smbus transfer timeout\n");
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
rc = (iface->result >= 0) ? 0 : -1;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:23:16 +08:00
|
|
|
/*
|
|
|
|
* Generic I2C SMBus transfer entrypoint
|
|
|
|
*/
|
|
|
|
int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
|
|
|
|
unsigned short flags, char read_write,
|
|
|
|
u8 command, int size, union i2c_smbus_data *data)
|
|
|
|
{
|
2010-03-22 15:23:19 +08:00
|
|
|
return bfin_twi_do_smbus_xfer(adap, addr, flags,
|
2010-03-22 15:23:16 +08:00
|
|
|
read_write, command, size, data);
|
|
|
|
}
|
|
|
|
|
2007-05-02 05:26:32 +08:00
|
|
|
/*
|
|
|
|
* Return what the adapter supports
|
|
|
|
*/
|
|
|
|
static u32 bfin_twi_functionality(struct i2c_adapter *adap)
|
|
|
|
{
|
|
|
|
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
|
|
|
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
|
|
|
I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |
|
2009-05-27 17:24:10 +08:00
|
|
|
I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_algorithm bfin_twi_algorithm = {
|
|
|
|
.master_xfer = bfin_twi_master_xfer,
|
|
|
|
.smbus_xfer = bfin_twi_smbus_xfer,
|
|
|
|
.functionality = bfin_twi_functionality,
|
|
|
|
};
|
|
|
|
|
2013-07-15 10:30:57 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2012-07-12 03:23:31 +08:00
|
|
|
static int i2c_bfin_twi_suspend(struct device *dev)
|
2007-05-02 05:26:32 +08:00
|
|
|
{
|
2012-07-12 03:23:31 +08:00
|
|
|
struct bfin_twi_iface *iface = dev_get_drvdata(dev);
|
2008-07-27 14:41:54 +08:00
|
|
|
|
|
|
|
iface->saved_clkdiv = read_CLKDIV(iface);
|
|
|
|
iface->saved_control = read_CONTROL(iface);
|
|
|
|
|
|
|
|
free_irq(iface->irq, iface);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
/* Disable TWI */
|
2008-07-27 14:41:54 +08:00
|
|
|
write_CONTROL(iface, iface->saved_control & ~TWI_ENA);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-12 03:23:31 +08:00
|
|
|
static int i2c_bfin_twi_resume(struct device *dev)
|
2007-05-02 05:26:32 +08:00
|
|
|
{
|
2012-07-12 03:23:31 +08:00
|
|
|
struct bfin_twi_iface *iface = dev_get_drvdata(dev);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-07-27 14:41:54 +08:00
|
|
|
int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
|
2012-07-12 03:23:31 +08:00
|
|
|
0, to_platform_device(dev)->name, iface);
|
2008-07-27 14:41:54 +08:00
|
|
|
if (rc) {
|
2012-07-12 03:23:31 +08:00
|
|
|
dev_err(dev, "Can't get IRQ %d !\n", iface->irq);
|
2008-07-27 14:41:54 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resume TWI interface clock as specified */
|
|
|
|
write_CLKDIV(iface, iface->saved_clkdiv);
|
|
|
|
|
|
|
|
/* Resume TWI */
|
|
|
|
write_CONTROL(iface, iface->saved_control);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-12 03:23:31 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(i2c_bfin_twi_pm,
|
|
|
|
i2c_bfin_twi_suspend, i2c_bfin_twi_resume);
|
2013-07-15 10:30:57 +08:00
|
|
|
#define I2C_BFIN_TWI_PM_OPS (&i2c_bfin_twi_pm)
|
|
|
|
#else
|
|
|
|
#define I2C_BFIN_TWI_PM_OPS NULL
|
|
|
|
#endif
|
2012-07-12 03:23:31 +08:00
|
|
|
|
2008-04-23 04:16:48 +08:00
|
|
|
static int i2c_bfin_twi_probe(struct platform_device *pdev)
|
2007-05-02 05:26:32 +08:00
|
|
|
{
|
2008-04-23 04:16:48 +08:00
|
|
|
struct bfin_twi_iface *iface;
|
2007-05-02 05:26:32 +08:00
|
|
|
struct i2c_adapter *p_adap;
|
2008-04-23 04:16:48 +08:00
|
|
|
struct resource *res;
|
2007-05-02 05:26:32 +08:00
|
|
|
int rc;
|
2009-05-18 20:14:41 +08:00
|
|
|
unsigned int clkhilow;
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2014-06-03 13:02:06 +08:00
|
|
|
iface = devm_kzalloc(&pdev->dev, sizeof(struct bfin_twi_iface),
|
|
|
|
GFP_KERNEL);
|
2008-04-23 04:16:48 +08:00
|
|
|
if (!iface) {
|
|
|
|
dev_err(&pdev->dev, "Cannot allocate memory\n");
|
2014-06-03 13:02:06 +08:00
|
|
|
return -ENOMEM;
|
2008-04-23 04:16:48 +08:00
|
|
|
}
|
|
|
|
|
2007-05-02 05:26:32 +08:00
|
|
|
spin_lock_init(&(iface->lock));
|
2008-04-23 04:16:48 +08:00
|
|
|
|
|
|
|
/* Find and map our resources */
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-06-03 13:02:06 +08:00
|
|
|
iface->regs_base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(iface->regs_base)) {
|
2008-04-23 04:16:48 +08:00
|
|
|
dev_err(&pdev->dev, "Cannot map IO\n");
|
2014-06-03 13:02:06 +08:00
|
|
|
return PTR_ERR(iface->regs_base);
|
2008-04-23 04:16:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
iface->irq = platform_get_irq(pdev, 0);
|
|
|
|
if (iface->irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "No IRQ specified\n");
|
2014-06-03 13:02:06 +08:00
|
|
|
return -ENOENT;
|
2008-04-23 04:16:48 +08:00
|
|
|
}
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
p_adap = &iface->adap;
|
2008-04-23 04:16:48 +08:00
|
|
|
p_adap->nr = pdev->id;
|
|
|
|
strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
|
2007-05-02 05:26:32 +08:00
|
|
|
p_adap->algo = &bfin_twi_algorithm;
|
|
|
|
p_adap->algo_data = iface;
|
2014-07-10 19:46:24 +08:00
|
|
|
p_adap->class = I2C_CLASS_DEPRECATED;
|
2008-04-23 04:16:48 +08:00
|
|
|
p_adap->dev.parent = &pdev->dev;
|
2010-03-22 15:23:16 +08:00
|
|
|
p_adap->timeout = 5 * HZ;
|
|
|
|
p_adap->retries = 3;
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2013-07-30 15:59:33 +08:00
|
|
|
rc = peripheral_request_list(
|
2013-09-09 13:32:25 +08:00
|
|
|
dev_get_platdata(&pdev->dev),
|
2013-07-30 15:59:33 +08:00
|
|
|
"i2c-bfin-twi");
|
2008-04-23 04:16:48 +08:00
|
|
|
if (rc) {
|
|
|
|
dev_err(&pdev->dev, "Can't setup pin mux!\n");
|
2014-06-03 13:02:06 +08:00
|
|
|
return -EBUSY;
|
2008-04-23 04:16:48 +08:00
|
|
|
}
|
|
|
|
|
2014-06-03 13:02:06 +08:00
|
|
|
rc = devm_request_irq(&pdev->dev, iface->irq, bfin_twi_interrupt_entry,
|
2011-09-21 17:28:33 +08:00
|
|
|
0, pdev->name, iface);
|
2007-05-02 05:26:32 +08:00
|
|
|
if (rc) {
|
2008-04-23 04:16:48 +08:00
|
|
|
dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
|
|
|
|
rc = -ENODEV;
|
2014-06-03 13:02:06 +08:00
|
|
|
goto out_error;
|
2007-05-02 05:26:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set TWI internal clock as 10MHz */
|
2009-12-21 22:28:30 +08:00
|
|
|
write_CONTROL(iface, ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2009-05-18 20:14:41 +08:00
|
|
|
/*
|
|
|
|
* We will not end up with a CLKDIV=0 because no one will specify
|
2009-12-21 22:28:30 +08:00
|
|
|
* 20kHz SCL or less in Kconfig now. (5 * 1000 / 20 = 250)
|
2009-05-18 20:14:41 +08:00
|
|
|
*/
|
2009-12-21 22:28:30 +08:00
|
|
|
clkhilow = ((10 * 1000 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ) + 1) / 2;
|
2009-05-18 20:14:41 +08:00
|
|
|
|
2007-05-02 05:26:32 +08:00
|
|
|
/* Set Twi interface clock as specified */
|
2009-05-18 20:14:41 +08:00
|
|
|
write_CLKDIV(iface, (clkhilow << 8) | clkhilow);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
/* Enable TWI */
|
2008-04-23 04:16:48 +08:00
|
|
|
write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-01-28 01:14:52 +08:00
|
|
|
rc = i2c_add_numbered_adapter(p_adap);
|
2008-04-23 04:16:48 +08:00
|
|
|
if (rc < 0) {
|
|
|
|
dev_err(&pdev->dev, "Can't add i2c adapter!\n");
|
2014-06-03 13:02:06 +08:00
|
|
|
goto out_error;
|
2008-04-23 04:16:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, iface);
|
2007-05-02 05:26:32 +08:00
|
|
|
|
2008-04-23 04:16:48 +08:00
|
|
|
dev_info(&pdev->dev, "Blackfin BF5xx on-chip I2C TWI Contoller, "
|
|
|
|
"regs_base@%p\n", iface->regs_base);
|
2008-04-23 04:16:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-06-03 13:02:06 +08:00
|
|
|
out_error:
|
2013-09-09 13:32:25 +08:00
|
|
|
peripheral_free_list(dev_get_platdata(&pdev->dev));
|
2007-05-02 05:26:32 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2c_bfin_twi_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
i2c_del_adapter(&(iface->adap));
|
2013-09-09 13:32:25 +08:00
|
|
|
peripheral_free_list(dev_get_platdata(&pdev->dev));
|
2007-05-02 05:26:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver i2c_bfin_twi_driver = {
|
|
|
|
.probe = i2c_bfin_twi_probe,
|
|
|
|
.remove = i2c_bfin_twi_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "i2c-bfin-twi",
|
|
|
|
.owner = THIS_MODULE,
|
2013-07-15 10:30:57 +08:00
|
|
|
.pm = I2C_BFIN_TWI_PM_OPS,
|
2007-05-02 05:26:32 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init i2c_bfin_twi_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&i2c_bfin_twi_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit i2c_bfin_twi_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&i2c_bfin_twi_driver);
|
|
|
|
}
|
|
|
|
|
2011-01-11 13:25:09 +08:00
|
|
|
subsys_initcall(i2c_bfin_twi_init);
|
2007-05-02 05:26:32 +08:00
|
|
|
module_exit(i2c_bfin_twi_exit);
|
2008-04-23 04:16:48 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Bryan Wu, Sonic Zhang");
|
|
|
|
MODULE_DESCRIPTION("Blackfin BF5xx on-chip I2C TWI Contoller Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-23 04:16:49 +08:00
|
|
|
MODULE_ALIAS("platform:i2c-bfin-twi");
|