2005-06-15 15:38:14 +04:00
|
|
|
/*
|
|
|
|
* i2c_adap_pxa.c
|
|
|
|
*
|
|
|
|
* I2C adapter for the PXA I2C bus access.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Intrinsyc Software Inc.
|
|
|
|
* Copyright (C) 2004-2005 Deep Blue Solutions Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
* Apr 2002: Initial version [CS]
|
tree-wide: Assorted spelling fixes
In particular, several occurances of funny versions of 'success',
'unknown', 'therefore', 'acknowledge', 'argument', 'achieve', 'address',
'beginning', 'desirable', 'separate' and 'necessary' are fixed.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Joe Perches <joe@perches.com>
Cc: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2010-02-03 03:01:28 +03:00
|
|
|
* Jun 2002: Properly separated algo/adap [FB]
|
2005-06-15 15:38:14 +04:00
|
|
|
* Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
|
|
|
|
* Jan 2003: added limited signal handling [Kai-Uwe Bloem]
|
|
|
|
* Sep 2004: Major rework to ensure efficient bus handling [RMK]
|
|
|
|
* Dec 2004: Added support for PXA27x and slave device probing [Liam Girdwood]
|
|
|
|
* Feb 2005: Rework slave mode handling [RMK]
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/i2c-pxa.h>
|
2012-03-01 09:04:44 +04:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2005-10-29 22:07:23 +04:00
|
|
|
#include <linux/platform_device.h>
|
2007-08-20 13:19:10 +04:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/clk.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 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2010-05-21 20:41:01 +04:00
|
|
|
#include <linux/io.h>
|
2011-02-23 14:38:16 +03:00
|
|
|
#include <linux/i2c/pxa-i2c.h>
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
#include <asm/irq.h>
|
2008-09-08 10:15:08 +04:00
|
|
|
|
2011-02-23 14:38:15 +03:00
|
|
|
struct pxa_reg_layout {
|
|
|
|
u32 ibmr;
|
|
|
|
u32 idbr;
|
|
|
|
u32 icr;
|
|
|
|
u32 isr;
|
|
|
|
u32 isar;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pxa_i2c_types {
|
|
|
|
REGS_PXA2XX,
|
|
|
|
REGS_PXA3XX,
|
2011-03-02 13:26:53 +03:00
|
|
|
REGS_CE4100,
|
2011-02-23 14:38:15 +03:00
|
|
|
};
|
|
|
|
|
2009-04-13 10:43:25 +04:00
|
|
|
/*
|
2011-02-23 14:38:15 +03:00
|
|
|
* I2C registers definitions
|
2009-04-13 10:43:25 +04:00
|
|
|
*/
|
2011-02-23 14:38:15 +03:00
|
|
|
static struct pxa_reg_layout pxa_reg_layout[] = {
|
|
|
|
[REGS_PXA2XX] = {
|
|
|
|
.ibmr = 0x00,
|
|
|
|
.idbr = 0x08,
|
|
|
|
.icr = 0x10,
|
|
|
|
.isr = 0x18,
|
|
|
|
.isar = 0x20,
|
|
|
|
},
|
2011-03-13 16:53:28 +03:00
|
|
|
[REGS_PXA3XX] = {
|
|
|
|
.ibmr = 0x00,
|
|
|
|
.idbr = 0x04,
|
|
|
|
.icr = 0x08,
|
|
|
|
.isr = 0x0c,
|
|
|
|
.isar = 0x10,
|
|
|
|
},
|
2011-03-02 13:26:53 +03:00
|
|
|
[REGS_CE4100] = {
|
|
|
|
.ibmr = 0x14,
|
|
|
|
.idbr = 0x0c,
|
|
|
|
.icr = 0x00,
|
|
|
|
.isr = 0x04,
|
|
|
|
/* no isar register */
|
|
|
|
},
|
2011-02-23 14:38:15 +03:00
|
|
|
};
|
2009-04-13 10:43:25 +04:00
|
|
|
|
|
|
|
static const struct platform_device_id i2c_pxa_id_table[] = {
|
2011-02-23 14:38:15 +03:00
|
|
|
{ "pxa2xx-i2c", REGS_PXA2XX },
|
|
|
|
{ "pxa3xx-pwri2c", REGS_PXA3XX },
|
2011-03-02 13:26:53 +03:00
|
|
|
{ "ce4100-i2c", REGS_CE4100 },
|
2009-04-13 10:43:25 +04:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
|
|
|
|
|
2008-09-08 10:15:08 +04:00
|
|
|
/*
|
2011-02-23 14:38:15 +03:00
|
|
|
* I2C bit definitions
|
2008-09-08 10:15:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define ICR_START (1 << 0) /* start bit */
|
|
|
|
#define ICR_STOP (1 << 1) /* stop bit */
|
|
|
|
#define ICR_ACKNAK (1 << 2) /* send ACK(0) or NAK(1) */
|
|
|
|
#define ICR_TB (1 << 3) /* transfer byte bit */
|
|
|
|
#define ICR_MA (1 << 4) /* master abort */
|
|
|
|
#define ICR_SCLE (1 << 5) /* master clock enable */
|
|
|
|
#define ICR_IUE (1 << 6) /* unit enable */
|
|
|
|
#define ICR_GCD (1 << 7) /* general call disable */
|
|
|
|
#define ICR_ITEIE (1 << 8) /* enable tx interrupts */
|
|
|
|
#define ICR_IRFIE (1 << 9) /* enable rx interrupts */
|
|
|
|
#define ICR_BEIE (1 << 10) /* enable bus error ints */
|
|
|
|
#define ICR_SSDIE (1 << 11) /* slave STOP detected int enable */
|
|
|
|
#define ICR_ALDIE (1 << 12) /* enable arbitration interrupt */
|
|
|
|
#define ICR_SADIE (1 << 13) /* slave address detected int enable */
|
|
|
|
#define ICR_UR (1 << 14) /* unit reset */
|
|
|
|
#define ICR_FM (1 << 15) /* fast mode */
|
2013-06-07 10:38:17 +04:00
|
|
|
#define ICR_HS (1 << 16) /* High Speed mode */
|
|
|
|
#define ICR_GPIOEN (1 << 19) /* enable GPIO mode for SCL in HS */
|
2008-09-08 10:15:08 +04:00
|
|
|
|
|
|
|
#define ISR_RWM (1 << 0) /* read/write mode */
|
|
|
|
#define ISR_ACKNAK (1 << 1) /* ack/nak status */
|
|
|
|
#define ISR_UB (1 << 2) /* unit busy */
|
|
|
|
#define ISR_IBB (1 << 3) /* bus busy */
|
|
|
|
#define ISR_SSD (1 << 4) /* slave stop detected */
|
|
|
|
#define ISR_ALD (1 << 5) /* arbitration loss detected */
|
|
|
|
#define ISR_ITE (1 << 6) /* tx buffer empty */
|
|
|
|
#define ISR_IRF (1 << 7) /* rx buffer full */
|
|
|
|
#define ISR_GCAD (1 << 8) /* general call address detected */
|
|
|
|
#define ISR_SAD (1 << 9) /* slave address detected */
|
|
|
|
#define ISR_BED (1 << 10) /* bus error no ACK/NAK */
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
struct pxa_i2c {
|
|
|
|
spinlock_t lock;
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
struct i2c_msg *msg;
|
|
|
|
unsigned int msg_num;
|
|
|
|
unsigned int msg_idx;
|
|
|
|
unsigned int msg_ptr;
|
|
|
|
unsigned int slave_addr;
|
|
|
|
|
|
|
|
struct i2c_adapter adap;
|
2007-08-20 13:19:10 +04:00
|
|
|
struct clk *clk;
|
2005-06-15 15:38:14 +04:00
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
|
|
|
struct i2c_slave_client *slave;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
unsigned int irqlogidx;
|
|
|
|
u32 isrlog[32];
|
|
|
|
u32 icrlog[32];
|
2007-02-08 11:43:26 +03:00
|
|
|
|
|
|
|
void __iomem *reg_base;
|
2011-02-23 14:38:15 +03:00
|
|
|
void __iomem *reg_ibmr;
|
|
|
|
void __iomem *reg_idbr;
|
|
|
|
void __iomem *reg_icr;
|
|
|
|
void __iomem *reg_isr;
|
|
|
|
void __iomem *reg_isar;
|
2007-02-08 11:43:26 +03:00
|
|
|
|
|
|
|
unsigned long iobase;
|
|
|
|
unsigned long iosize;
|
|
|
|
|
|
|
|
int irq;
|
2008-10-03 18:07:36 +04:00
|
|
|
unsigned int use_pio :1;
|
|
|
|
unsigned int fast_mode :1;
|
2013-06-07 10:38:17 +04:00
|
|
|
unsigned int high_mode:1;
|
|
|
|
unsigned char master_code;
|
|
|
|
unsigned long rate;
|
|
|
|
bool highmode_enter;
|
2005-06-15 15:38:14 +04:00
|
|
|
};
|
|
|
|
|
2011-02-23 14:38:15 +03:00
|
|
|
#define _IBMR(i2c) ((i2c)->reg_ibmr)
|
|
|
|
#define _IDBR(i2c) ((i2c)->reg_idbr)
|
|
|
|
#define _ICR(i2c) ((i2c)->reg_icr)
|
|
|
|
#define _ISR(i2c) ((i2c)->reg_isr)
|
|
|
|
#define _ISAR(i2c) ((i2c)->reg_isar)
|
2007-02-08 11:43:26 +03:00
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
/*
|
|
|
|
* I2C Slave mode address
|
|
|
|
*/
|
|
|
|
#define I2C_PXA_SLAVE_ADDR 0x1
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
struct bits {
|
|
|
|
u32 mask;
|
|
|
|
const char *set;
|
|
|
|
const char *unset;
|
|
|
|
};
|
2007-10-19 10:40:28 +04:00
|
|
|
#define PXA_BIT(m, s, u) { .mask = m, .set = s, .unset = u }
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
decode_bits(const char *prefix, const struct bits *bits, int num, u32 val)
|
|
|
|
{
|
|
|
|
printk("%s %08x: ", prefix, val);
|
|
|
|
while (num--) {
|
|
|
|
const char *str = val & bits->mask ? bits->set : bits->unset;
|
|
|
|
if (str)
|
|
|
|
printk("%s ", str);
|
|
|
|
bits++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct bits isr_bits[] = {
|
2007-10-19 10:40:28 +04:00
|
|
|
PXA_BIT(ISR_RWM, "RX", "TX"),
|
|
|
|
PXA_BIT(ISR_ACKNAK, "NAK", "ACK"),
|
|
|
|
PXA_BIT(ISR_UB, "Bsy", "Rdy"),
|
|
|
|
PXA_BIT(ISR_IBB, "BusBsy", "BusRdy"),
|
|
|
|
PXA_BIT(ISR_SSD, "SlaveStop", NULL),
|
|
|
|
PXA_BIT(ISR_ALD, "ALD", NULL),
|
|
|
|
PXA_BIT(ISR_ITE, "TxEmpty", NULL),
|
|
|
|
PXA_BIT(ISR_IRF, "RxFull", NULL),
|
|
|
|
PXA_BIT(ISR_GCAD, "GenCall", NULL),
|
|
|
|
PXA_BIT(ISR_SAD, "SlaveAddr", NULL),
|
|
|
|
PXA_BIT(ISR_BED, "BusErr", NULL),
|
2005-06-15 15:38:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void decode_ISR(unsigned int val)
|
|
|
|
{
|
2005-09-09 00:04:58 +04:00
|
|
|
decode_bits(KERN_DEBUG "ISR", isr_bits, ARRAY_SIZE(isr_bits), val);
|
2005-06-15 15:38:14 +04:00
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct bits icr_bits[] = {
|
2007-10-19 10:40:28 +04:00
|
|
|
PXA_BIT(ICR_START, "START", NULL),
|
|
|
|
PXA_BIT(ICR_STOP, "STOP", NULL),
|
|
|
|
PXA_BIT(ICR_ACKNAK, "ACKNAK", NULL),
|
|
|
|
PXA_BIT(ICR_TB, "TB", NULL),
|
|
|
|
PXA_BIT(ICR_MA, "MA", NULL),
|
|
|
|
PXA_BIT(ICR_SCLE, "SCLE", "scle"),
|
|
|
|
PXA_BIT(ICR_IUE, "IUE", "iue"),
|
|
|
|
PXA_BIT(ICR_GCD, "GCD", NULL),
|
|
|
|
PXA_BIT(ICR_ITEIE, "ITEIE", NULL),
|
|
|
|
PXA_BIT(ICR_IRFIE, "IRFIE", NULL),
|
|
|
|
PXA_BIT(ICR_BEIE, "BEIE", NULL),
|
|
|
|
PXA_BIT(ICR_SSDIE, "SSDIE", NULL),
|
|
|
|
PXA_BIT(ICR_ALDIE, "ALDIE", NULL),
|
|
|
|
PXA_BIT(ICR_SADIE, "SADIE", NULL),
|
|
|
|
PXA_BIT(ICR_UR, "UR", "ur"),
|
2005-06-15 15:38:14 +04:00
|
|
|
};
|
|
|
|
|
2008-02-11 18:51:41 +03:00
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
2005-06-15 15:38:14 +04:00
|
|
|
static void decode_ICR(unsigned int val)
|
|
|
|
{
|
2005-09-09 00:04:58 +04:00
|
|
|
decode_bits(KERN_DEBUG "ICR", icr_bits, ARRAY_SIZE(icr_bits), val);
|
2005-06-15 15:38:14 +04:00
|
|
|
printk("\n");
|
|
|
|
}
|
2008-02-11 18:51:41 +03:00
|
|
|
#endif
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
static unsigned int i2c_debug = DEBUG;
|
|
|
|
|
|
|
|
static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
|
|
|
|
{
|
2007-02-08 11:43:26 +03:00
|
|
|
dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno,
|
|
|
|
readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2008-04-23 00:16:47 +04:00
|
|
|
#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2009-03-28 23:34:42 +03:00
|
|
|
printk(KERN_ERR "i2c: error: %s\n", why);
|
|
|
|
printk(KERN_ERR "i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
|
2005-06-15 15:38:14 +04:00
|
|
|
i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
|
2009-03-28 23:34:42 +03:00
|
|
|
printk(KERN_ERR "i2c: ICR: %08x ISR: %08x\n",
|
|
|
|
readl(_ICR(i2c)), readl(_ISR(i2c)));
|
|
|
|
printk(KERN_DEBUG "i2c: log: ");
|
2005-06-15 15:38:14 +04:00
|
|
|
for (i = 0; i < i2c->irqlogidx; i++)
|
|
|
|
printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
2009-11-03 14:53:41 +03:00
|
|
|
#else /* ifdef DEBUG */
|
|
|
|
|
|
|
|
#define i2c_debug 0
|
|
|
|
|
|
|
|
#define show_state(i2c) do { } while (0)
|
|
|
|
#define decode_ISR(val) do { } while (0)
|
|
|
|
#define decode_ICR(val) do { } while (0)
|
|
|
|
#define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0)
|
|
|
|
|
|
|
|
#endif /* ifdef DEBUG / else */
|
|
|
|
|
|
|
|
static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
|
|
|
|
static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
|
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
|
|
|
|
{
|
2007-02-08 11:43:26 +03:00
|
|
|
return !(readl(_ICR(i2c)) & ICR_SCLE);
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_abort(struct pxa_i2c *i2c)
|
|
|
|
{
|
2008-08-18 17:38:48 +04:00
|
|
|
int i = 250;
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (i2c_pxa_is_slavemode(i2c)) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-18 17:38:48 +04:00
|
|
|
while ((i > 0) && (readl(_IBMR(i2c)) & 0x1) == 0) {
|
2007-02-08 11:43:26 +03:00
|
|
|
unsigned long icr = readl(_ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
icr &= ~ICR_START;
|
|
|
|
icr |= ICR_ACKNAK | ICR_STOP | ICR_TB;
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(icr, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
show_state(i2c);
|
|
|
|
|
2008-08-18 17:38:48 +04:00
|
|
|
mdelay(1);
|
|
|
|
i --;
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
|
|
|
|
_ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
int timeout = DEF_TIMEOUT;
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
|
|
|
|
if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
|
2005-06-15 15:38:14 +04:00
|
|
|
timeout += 4;
|
|
|
|
|
|
|
|
msleep(2);
|
|
|
|
show_state(i2c);
|
|
|
|
}
|
|
|
|
|
2009-04-23 18:27:39 +04:00
|
|
|
if (timeout < 0)
|
2005-06-15 15:38:14 +04:00
|
|
|
show_state(i2c);
|
|
|
|
|
2009-04-23 18:27:39 +04:00
|
|
|
return timeout < 0 ? I2C_RETRY : 0;
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
unsigned long timeout = jiffies + HZ*4;
|
|
|
|
|
|
|
|
while (time_before(jiffies, timeout)) {
|
|
|
|
if (i2c_debug > 1)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
|
2007-02-08 11:43:26 +03:00
|
|
|
__func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
if (readl(_ISR(i2c)) & ISR_SAD) {
|
2005-06-15 15:38:14 +04:00
|
|
|
if (i2c_debug > 0)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for unit and bus being not busy, and we also do a
|
|
|
|
* quick check of the i2c lines themselves to ensure they've
|
|
|
|
* gone high...
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && readl(_IBMR(i2c)) == 3) {
|
2005-06-15 15:38:14 +04:00
|
|
|
if (i2c_debug > 0)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2c_debug > 0)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2c_pxa_set_master(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
if (i2c_debug)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "setting to bus master\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
if (!i2c_pxa_wait_master(i2c)) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
return I2C_RETRY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
|
|
|
static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
unsigned long timeout = jiffies + HZ*1;
|
|
|
|
|
|
|
|
/* wait for stop */
|
|
|
|
|
|
|
|
show_state(i2c);
|
|
|
|
|
|
|
|
while (time_before(jiffies, timeout)) {
|
|
|
|
if (i2c_debug > 1)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
|
2007-02-08 11:43:26 +03:00
|
|
|
__func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 ||
|
|
|
|
(readl(_ISR(i2c)) & ISR_SAD) != 0 ||
|
|
|
|
(readl(_ICR(i2c)) & ICR_SCLE) == 0) {
|
2005-06-15 15:38:14 +04:00
|
|
|
if (i2c_debug > 1)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2c_debug > 0)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: did not free\n", __func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clear the hold on the bus, and take of anything else
|
|
|
|
* that has been configured
|
|
|
|
*/
|
|
|
|
static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
|
|
|
|
{
|
|
|
|
show_state(i2c);
|
|
|
|
|
|
|
|
if (errcode < 0) {
|
|
|
|
udelay(100); /* simple delay */
|
|
|
|
} else {
|
|
|
|
/* we need to wait for the stop condition to end */
|
|
|
|
|
|
|
|
/* if we where in stop, then clear... */
|
2007-02-08 11:43:26 +03:00
|
|
|
if (readl(_ICR(i2c)) & ICR_STOP) {
|
2005-06-15 15:38:14 +04:00
|
|
|
udelay(100);
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!i2c_pxa_wait_slave(i2c)) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_err(&i2c->adap.dev, "%s: wait timedout\n",
|
|
|
|
__func__);
|
2005-06-15 15:38:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c));
|
|
|
|
writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (i2c_debug) {
|
2007-02-08 11:43:26 +03:00
|
|
|
dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c)));
|
|
|
|
decode_ICR(readl(_ICR(i2c)));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define i2c_pxa_set_slave(i2c, err) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void i2c_pxa_reset(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
pr_debug("Resetting I2C Controller Unit\n");
|
|
|
|
|
|
|
|
/* abort any transfer currently under way */
|
|
|
|
i2c_pxa_abort(i2c);
|
|
|
|
|
|
|
|
/* reset according to 9.8 */
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(ICR_UR, _ICR(i2c));
|
|
|
|
writel(I2C_ISR_INIT, _ISR(i2c));
|
|
|
|
writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2011-03-02 13:26:53 +03:00
|
|
|
if (i2c->reg_isar)
|
|
|
|
writel(i2c->slave_addr, _ISAR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
/* set control register values */
|
2008-10-03 18:07:36 +04:00
|
|
|
writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c));
|
2013-06-07 10:38:17 +04:00
|
|
|
writel(readl(_ICR(i2c)) | (i2c->high_mode ? ICR_HS : 0), _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_info(&i2c->adap.dev, "Enabling slave mode\n");
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
i2c_pxa_set_slave(i2c, 0);
|
|
|
|
|
|
|
|
/* enable unit */
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
|
|
|
/*
|
|
|
|
* PXA I2C Slave mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
|
|
|
if (isr & ISR_BED) {
|
|
|
|
/* what should we do here? */
|
|
|
|
} else {
|
2006-10-29 01:30:17 +04:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (i2c->slave != NULL)
|
|
|
|
ret = i2c->slave->read(i2c->slave->data);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(ret, _IDBR(i2c));
|
|
|
|
writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
2007-02-08 11:43:26 +03:00
|
|
|
unsigned int byte = readl(_IDBR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (i2c->slave != NULL)
|
|
|
|
i2c->slave->write(i2c->slave->data, byte);
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
if (i2c_debug > 0)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "SAD, mode is slave-%cx\n",
|
2005-06-15 15:38:14 +04:00
|
|
|
(isr & ISR_RWM) ? 'r' : 't');
|
|
|
|
|
|
|
|
if (i2c->slave != NULL)
|
|
|
|
i2c->slave->event(i2c->slave->data,
|
|
|
|
(isr & ISR_RWM) ? I2C_SLAVE_EVENT_START_READ : I2C_SLAVE_EVENT_START_WRITE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* slave could interrupt in the middle of us generating a
|
|
|
|
* start condition... if this happens, we'd better back off
|
|
|
|
* and stop holding the poor thing up
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
|
|
|
|
writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
timeout = 0x10000;
|
|
|
|
|
|
|
|
while (1) {
|
2007-02-08 11:43:26 +03:00
|
|
|
if ((readl(_IBMR(i2c)) & 2) == 2)
|
2005-06-15 15:38:14 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
timeout--;
|
|
|
|
|
|
|
|
if (timeout <= 0) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
if (i2c_debug > 2)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop)\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (i2c->slave != NULL)
|
|
|
|
i2c->slave->event(i2c->slave->data, I2C_SLAVE_EVENT_STOP);
|
|
|
|
|
|
|
|
if (i2c_debug > 2)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "ISR: SSD (Slave Stop) acked\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a master-mode message waiting,
|
|
|
|
* kick it off now that the slave has completed.
|
|
|
|
*/
|
|
|
|
if (i2c->msg)
|
|
|
|
i2c_pxa_master_complete(i2c, I2C_RETRY);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
|
|
|
if (isr & ISR_BED) {
|
|
|
|
/* what should we do here? */
|
|
|
|
} else {
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(0, _IDBR(i2c));
|
|
|
|
writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* slave could interrupt in the middle of us generating a
|
|
|
|
* start condition... if this happens, we'd better back off
|
|
|
|
* and stop holding the poor thing up
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
|
|
|
|
writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
timeout = 0x10000;
|
|
|
|
|
|
|
|
while (1) {
|
2007-02-08 11:43:26 +03:00
|
|
|
if ((readl(_IBMR(i2c)) & 2) == 2)
|
2005-06-15 15:38:14 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
timeout--;
|
|
|
|
|
|
|
|
if (timeout <= 0) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_err(&i2c->adap.dev, "timeout waiting for SCL high\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
if (i2c->msg)
|
|
|
|
i2c_pxa_master_complete(i2c, I2C_RETRY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PXA I2C Master mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline unsigned int i2c_pxa_addr_byte(struct i2c_msg *msg)
|
|
|
|
{
|
|
|
|
unsigned int addr = (msg->addr & 0x7f) << 1;
|
|
|
|
|
|
|
|
if (msg->flags & I2C_M_RD)
|
|
|
|
addr |= 1;
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
u32 icr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Step 1: target slave address into IDBR
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step 2: initiate the write.
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
|
|
|
|
writel(icr | ICR_START | ICR_TB, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2007-05-02 01:26:33 +04:00
|
|
|
static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
u32 icr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the STOP and ACK flags
|
|
|
|
*/
|
|
|
|
icr = readl(_ICR(i2c));
|
|
|
|
icr &= ~(ICR_STOP | ICR_ACKNAK);
|
2007-05-10 14:15:32 +04:00
|
|
|
writel(icr, _ICR(i2c));
|
2007-05-02 01:26:33 +04:00
|
|
|
}
|
|
|
|
|
2008-01-27 20:14:50 +03:00
|
|
|
static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
/* make timeout the same as for interrupt based functions */
|
|
|
|
long timeout = 2 * DEF_TIMEOUT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the bus to become free.
|
|
|
|
*/
|
|
|
|
while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
|
|
|
|
udelay(1000);
|
|
|
|
show_state(i2c);
|
|
|
|
}
|
|
|
|
|
2009-04-23 18:27:39 +04:00
|
|
|
if (timeout < 0) {
|
2008-01-27 20:14:50 +03:00
|
|
|
show_state(i2c);
|
|
|
|
dev_err(&i2c->adap.dev,
|
|
|
|
"i2c_pxa: timeout waiting for bus free\n");
|
|
|
|
return I2C_RETRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set master mode.
|
|
|
|
*/
|
|
|
|
writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:38:17 +04:00
|
|
|
/*
|
|
|
|
* PXA I2C send master code
|
|
|
|
* 1. Load master code to IDBR and send it.
|
|
|
|
* Note for HS mode, set ICR [GPIOEN].
|
|
|
|
* 2. Wait until win arbitration.
|
|
|
|
*/
|
|
|
|
static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c)
|
|
|
|
{
|
|
|
|
u32 icr;
|
|
|
|
long timeout;
|
|
|
|
|
|
|
|
spin_lock_irq(&i2c->lock);
|
|
|
|
i2c->highmode_enter = true;
|
|
|
|
writel(i2c->master_code, _IDBR(i2c));
|
|
|
|
|
|
|
|
icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
|
|
|
|
icr |= ICR_GPIOEN | ICR_START | ICR_TB | ICR_ITEIE;
|
|
|
|
writel(icr, _ICR(i2c));
|
|
|
|
|
|
|
|
spin_unlock_irq(&i2c->lock);
|
|
|
|
timeout = wait_event_timeout(i2c->wait,
|
|
|
|
i2c->highmode_enter == false, HZ * 1);
|
|
|
|
|
|
|
|
i2c->highmode_enter = false;
|
|
|
|
|
|
|
|
return (timeout == 0) ? I2C_RETRY : 0;
|
|
|
|
}
|
|
|
|
|
2008-01-27 20:14:50 +03:00
|
|
|
static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
|
|
|
|
struct i2c_msg *msg, int num)
|
|
|
|
{
|
|
|
|
unsigned long timeout = 500000; /* 5 seconds */
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = i2c_pxa_pio_set_master(i2c);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
i2c->msg = msg;
|
|
|
|
i2c->msg_num = num;
|
|
|
|
i2c->msg_idx = 0;
|
|
|
|
i2c->msg_ptr = 0;
|
|
|
|
i2c->irqlogidx = 0;
|
|
|
|
|
|
|
|
i2c_pxa_start_message(i2c);
|
|
|
|
|
2009-02-24 21:19:48 +03:00
|
|
|
while (i2c->msg_num > 0 && --timeout) {
|
2008-01-27 20:14:50 +03:00
|
|
|
i2c_pxa_handler(0, i2c);
|
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c_pxa_stop_message(i2c);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We place the return code in i2c->msg_idx.
|
|
|
|
*/
|
|
|
|
ret = i2c->msg_idx;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (timeout == 0)
|
|
|
|
i2c_pxa_scream_blue_murder(i2c, "timeout");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
/*
|
2006-01-19 01:17:01 +03:00
|
|
|
* We are protected by the adapter bus mutex.
|
2005-06-15 15:38:14 +04:00
|
|
|
*/
|
|
|
|
static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
|
|
|
|
{
|
|
|
|
long timeout;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the bus to become free.
|
|
|
|
*/
|
|
|
|
ret = i2c_pxa_wait_bus_not_busy(i2c);
|
|
|
|
if (ret) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_err(&i2c->adap.dev, "i2c_pxa: timeout waiting for bus free\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set master mode.
|
|
|
|
*/
|
|
|
|
ret = i2c_pxa_set_master(i2c);
|
|
|
|
if (ret) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_err(&i2c->adap.dev, "i2c_pxa_set_master: error %d\n", ret);
|
2005-06-15 15:38:14 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:38:17 +04:00
|
|
|
if (i2c->high_mode) {
|
|
|
|
ret = i2c_pxa_send_mastercode(i2c);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
spin_lock_irq(&i2c->lock);
|
|
|
|
|
|
|
|
i2c->msg = msg;
|
|
|
|
i2c->msg_num = num;
|
|
|
|
i2c->msg_idx = 0;
|
|
|
|
i2c->msg_ptr = 0;
|
|
|
|
i2c->irqlogidx = 0;
|
|
|
|
|
|
|
|
i2c_pxa_start_message(i2c);
|
|
|
|
|
|
|
|
spin_unlock_irq(&i2c->lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The rest of the processing occurs in the interrupt handler.
|
|
|
|
*/
|
|
|
|
timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
|
2007-05-02 01:26:33 +04:00
|
|
|
i2c_pxa_stop_message(i2c);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We place the return code in i2c->msg_idx.
|
|
|
|
*/
|
|
|
|
ret = i2c->msg_idx;
|
|
|
|
|
2011-02-23 14:38:19 +03:00
|
|
|
if (!timeout && i2c->msg_num) {
|
2005-06-15 15:38:14 +04:00
|
|
|
i2c_pxa_scream_blue_murder(i2c, "timeout");
|
2011-02-23 14:38:19 +03:00
|
|
|
ret = I2C_RETRY;
|
|
|
|
}
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-27 20:14:50 +03:00
|
|
|
static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
|
|
|
|
struct i2c_msg msgs[], int num)
|
|
|
|
{
|
|
|
|
struct pxa_i2c *i2c = adap->algo_data;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
/* If the I2C controller is disabled we need to reset it
|
|
|
|
(probably due to a suspend/resume destroying state). We do
|
|
|
|
this here as we can then avoid worrying about resuming the
|
|
|
|
controller before its users. */
|
|
|
|
if (!(readl(_ICR(i2c)) & ICR_IUE))
|
|
|
|
i2c_pxa_reset(i2c);
|
|
|
|
|
|
|
|
for (i = adap->retries; i >= 0; i--) {
|
|
|
|
ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
|
|
|
|
if (ret != I2C_RETRY)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (i2c_debug)
|
|
|
|
dev_dbg(&adap->dev, "Retrying transmission\n");
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
|
|
|
|
ret = -EREMOTEIO;
|
|
|
|
out:
|
|
|
|
i2c_pxa_set_slave(i2c, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
/*
|
|
|
|
* i2c_pxa_master_complete - complete the message and wake up.
|
|
|
|
*/
|
|
|
|
static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
|
|
|
|
{
|
|
|
|
i2c->msg_ptr = 0;
|
|
|
|
i2c->msg = NULL;
|
|
|
|
i2c->msg_idx ++;
|
|
|
|
i2c->msg_num = 0;
|
|
|
|
if (ret)
|
|
|
|
i2c->msg_idx = ret;
|
2008-01-27 20:14:50 +03:00
|
|
|
if (!i2c->use_pio)
|
|
|
|
wake_up(&i2c->wait);
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
2007-02-08 11:43:26 +03:00
|
|
|
u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
again:
|
|
|
|
/*
|
|
|
|
* If ISR_ALD is set, we lost arbitration.
|
|
|
|
*/
|
|
|
|
if (isr & ISR_ALD) {
|
|
|
|
/*
|
|
|
|
* Do we need to do anything here? The PXA docs
|
|
|
|
* are vague about what happens.
|
|
|
|
*/
|
|
|
|
i2c_pxa_scream_blue_murder(i2c, "ALD set");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We ignore this error. We seem to see spurious ALDs
|
|
|
|
* for seemingly no reason. If we handle them as I think
|
|
|
|
* they should, we end up causing an I2C error, which
|
|
|
|
* is painful for some systems.
|
|
|
|
*/
|
|
|
|
return; /* ignore */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isr & ISR_BED) {
|
|
|
|
int ret = BUS_ERROR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I2C bus error - either the device NAK'd us, or
|
|
|
|
* something more serious happened. If we were NAK'd
|
|
|
|
* on the initial address phase, we can retry.
|
|
|
|
*/
|
|
|
|
if (isr & ISR_ACKNAK) {
|
|
|
|
if (i2c->msg_ptr == 0 && i2c->msg_idx == 0)
|
|
|
|
ret = I2C_RETRY;
|
|
|
|
else
|
|
|
|
ret = XFER_NAKED;
|
|
|
|
}
|
|
|
|
i2c_pxa_master_complete(i2c, ret);
|
|
|
|
} else if (isr & ISR_RWM) {
|
|
|
|
/*
|
|
|
|
* Read mode. We have just sent the address byte, and
|
|
|
|
* now we must initiate the transfer.
|
|
|
|
*/
|
|
|
|
if (i2c->msg_ptr == i2c->msg->len - 1 &&
|
|
|
|
i2c->msg_idx == i2c->msg_num - 1)
|
|
|
|
icr |= ICR_STOP | ICR_ACKNAK;
|
|
|
|
|
|
|
|
icr |= ICR_ALDIE | ICR_TB;
|
|
|
|
} else if (i2c->msg_ptr < i2c->msg->len) {
|
|
|
|
/*
|
|
|
|
* Write mode. Write the next data byte.
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
icr |= ICR_ALDIE | ICR_TB;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the last byte of the last message, send
|
|
|
|
* a STOP.
|
|
|
|
*/
|
|
|
|
if (i2c->msg_ptr == i2c->msg->len &&
|
|
|
|
i2c->msg_idx == i2c->msg_num - 1)
|
|
|
|
icr |= ICR_STOP;
|
|
|
|
} else if (i2c->msg_idx < i2c->msg_num - 1) {
|
|
|
|
/*
|
|
|
|
* Next segment of the message.
|
|
|
|
*/
|
|
|
|
i2c->msg_ptr = 0;
|
|
|
|
i2c->msg_idx ++;
|
|
|
|
i2c->msg++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we aren't doing a repeated start and address,
|
|
|
|
* go back and try to send the next byte. Note that
|
|
|
|
* we do not support switching the R/W direction here.
|
|
|
|
*/
|
|
|
|
if (i2c->msg->flags & I2C_M_NOSTART)
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the next address.
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* And trigger a repeated start, and send the byte.
|
|
|
|
*/
|
|
|
|
icr &= ~ICR_ALDIE;
|
|
|
|
icr |= ICR_START | ICR_TB;
|
|
|
|
} else {
|
|
|
|
if (i2c->msg->len == 0) {
|
|
|
|
/*
|
|
|
|
* Device probes have a message length of zero
|
|
|
|
* and need the bus to be reset before it can
|
|
|
|
* be used again.
|
|
|
|
*/
|
|
|
|
i2c_pxa_reset(i2c);
|
|
|
|
}
|
|
|
|
i2c_pxa_master_complete(i2c, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c->icrlog[i2c->irqlogidx-1] = icr;
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(icr, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
show_state(i2c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
|
|
|
|
{
|
2007-02-08 11:43:26 +03:00
|
|
|
u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the byte.
|
|
|
|
*/
|
2007-02-08 11:43:26 +03:00
|
|
|
i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (i2c->msg_ptr < i2c->msg->len) {
|
|
|
|
/*
|
|
|
|
* If this is the last byte of the last
|
|
|
|
* message, send a STOP.
|
|
|
|
*/
|
|
|
|
if (i2c->msg_ptr == i2c->msg->len - 1)
|
|
|
|
icr |= ICR_STOP | ICR_ACKNAK;
|
|
|
|
|
|
|
|
icr |= ICR_ALDIE | ICR_TB;
|
|
|
|
} else {
|
|
|
|
i2c_pxa_master_complete(i2c, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c->icrlog[i2c->irqlogidx-1] = icr;
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
writel(icr, _ICR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2011-02-23 14:38:18 +03:00
|
|
|
#define VALID_INT_SOURCE (ISR_SSD | ISR_ALD | ISR_ITE | ISR_IRF | \
|
|
|
|
ISR_SAD | ISR_BED)
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
|
2005-06-15 15:38:14 +04:00
|
|
|
{
|
|
|
|
struct pxa_i2c *i2c = dev_id;
|
2007-02-08 11:43:26 +03:00
|
|
|
u32 isr = readl(_ISR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2011-03-13 16:53:29 +03:00
|
|
|
if (!(isr & VALID_INT_SOURCE))
|
2011-02-23 14:38:18 +03:00
|
|
|
return IRQ_NONE;
|
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
if (i2c_debug > 2 && 0) {
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
|
2007-02-08 11:43:26 +03:00
|
|
|
__func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
|
2005-06-15 15:38:14 +04:00
|
|
|
decode_ISR(isr);
|
|
|
|
}
|
|
|
|
|
2006-01-10 01:19:51 +03:00
|
|
|
if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog))
|
2005-06-15 15:38:14 +04:00
|
|
|
i2c->isrlog[i2c->irqlogidx++] = isr;
|
|
|
|
|
|
|
|
show_state(i2c);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Always clear all pending IRQs.
|
|
|
|
*/
|
2011-03-13 16:53:29 +03:00
|
|
|
writel(isr & VALID_INT_SOURCE, _ISR(i2c));
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (isr & ISR_SAD)
|
|
|
|
i2c_pxa_slave_start(i2c, isr);
|
|
|
|
if (isr & ISR_SSD)
|
|
|
|
i2c_pxa_slave_stop(i2c);
|
|
|
|
|
|
|
|
if (i2c_pxa_is_slavemode(i2c)) {
|
|
|
|
if (isr & ISR_ITE)
|
|
|
|
i2c_pxa_slave_txempty(i2c, isr);
|
|
|
|
if (isr & ISR_IRF)
|
|
|
|
i2c_pxa_slave_rxfull(i2c, isr);
|
2013-06-07 10:38:17 +04:00
|
|
|
} else if (i2c->msg && (!i2c->highmode_enter)) {
|
2005-06-15 15:38:14 +04:00
|
|
|
if (isr & ISR_ITE)
|
|
|
|
i2c_pxa_irq_txempty(i2c, isr);
|
|
|
|
if (isr & ISR_IRF)
|
|
|
|
i2c_pxa_irq_rxfull(i2c, isr);
|
2013-06-07 10:38:17 +04:00
|
|
|
} else if ((isr & ISR_ITE) && i2c->highmode_enter) {
|
|
|
|
i2c->highmode_enter = false;
|
|
|
|
wake_up(&i2c->wait);
|
2005-06-15 15:38:14 +04:00
|
|
|
} else {
|
|
|
|
i2c_pxa_scream_blue_murder(i2c, "spurious irq");
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
|
|
|
|
{
|
|
|
|
struct pxa_i2c *i2c = adap->algo_data;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
for (i = adap->retries; i >= 0; i--) {
|
|
|
|
ret = i2c_pxa_do_xfer(i2c, msgs, num);
|
|
|
|
if (ret != I2C_RETRY)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (i2c_debug)
|
2005-09-09 00:04:58 +04:00
|
|
|
dev_dbg(&adap->dev, "Retrying transmission\n");
|
2005-06-15 15:38:14 +04:00
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
|
|
|
|
ret = -EREMOTEIO;
|
|
|
|
out:
|
|
|
|
i2c_pxa_set_slave(i2c, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-09-15 01:54:45 +04:00
|
|
|
static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
|
|
|
|
{
|
|
|
|
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
|
|
|
|
}
|
|
|
|
|
2006-09-04 00:39:46 +04:00
|
|
|
static const struct i2c_algorithm i2c_pxa_algorithm = {
|
2005-06-15 15:38:14 +04:00
|
|
|
.master_xfer = i2c_pxa_xfer,
|
2005-09-15 01:54:45 +04:00
|
|
|
.functionality = i2c_pxa_functionality,
|
2005-06-15 15:38:14 +04:00
|
|
|
};
|
|
|
|
|
2008-01-27 20:14:50 +03:00
|
|
|
static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
|
|
|
|
.master_xfer = i2c_pxa_pio_xfer,
|
|
|
|
.functionality = i2c_pxa_functionality,
|
|
|
|
};
|
|
|
|
|
2014-05-15 10:46:11 +04:00
|
|
|
static const struct of_device_id i2c_pxa_dt_ids[] = {
|
2012-03-01 09:04:44 +04:00
|
|
|
{ .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX },
|
|
|
|
{ .compatible = "mrvl,pwri2c", .data = (void *)REGS_PXA3XX },
|
|
|
|
{ .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA2XX },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, i2c_pxa_dt_ids);
|
|
|
|
|
|
|
|
static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
|
|
|
|
enum pxa_i2c_types *i2c_types)
|
2005-06-15 15:38:14 +04:00
|
|
|
{
|
2012-03-01 09:04:44 +04:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
const struct of_device_id *of_id =
|
|
|
|
of_match_device(i2c_pxa_dt_ids, &pdev->dev);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2012-03-01 09:04:44 +04:00
|
|
|
if (!of_id)
|
|
|
|
return 1;
|
2013-03-01 10:57:32 +04:00
|
|
|
|
|
|
|
/* For device tree we always use the dynamic or alias-assigned ID */
|
|
|
|
i2c->adap.nr = -1;
|
|
|
|
|
2012-03-01 09:04:44 +04:00
|
|
|
if (of_get_property(np, "mrvl,i2c-polling", NULL))
|
|
|
|
i2c->use_pio = 1;
|
|
|
|
if (of_get_property(np, "mrvl,i2c-fast-mode", NULL))
|
|
|
|
i2c->fast_mode = 1;
|
|
|
|
*i2c_types = (u32)(of_id->data);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-08 11:43:26 +03:00
|
|
|
|
2012-03-01 09:04:44 +04:00
|
|
|
static int i2c_pxa_probe_pdata(struct platform_device *pdev,
|
|
|
|
struct pxa_i2c *i2c,
|
|
|
|
enum pxa_i2c_types *i2c_types)
|
|
|
|
{
|
2013-07-30 11:59:33 +04:00
|
|
|
struct i2c_pxa_platform_data *plat = dev_get_platdata(&pdev->dev);
|
2012-03-01 09:04:44 +04:00
|
|
|
const struct platform_device_id *id = platform_get_device_id(pdev);
|
|
|
|
|
|
|
|
*i2c_types = id->driver_data;
|
|
|
|
if (plat) {
|
|
|
|
i2c->use_pio = plat->use_pio;
|
|
|
|
i2c->fast_mode = plat->fast_mode;
|
2013-06-07 10:38:17 +04:00
|
|
|
i2c->high_mode = plat->high_mode;
|
|
|
|
i2c->master_code = plat->master_code;
|
|
|
|
if (!i2c->master_code)
|
|
|
|
i2c->master_code = 0xe;
|
|
|
|
i2c->rate = plat->rate;
|
2012-03-01 09:04:44 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int i2c_pxa_probe(struct platform_device *dev)
|
|
|
|
{
|
2013-07-30 11:59:33 +04:00
|
|
|
struct i2c_pxa_platform_data *plat = dev_get_platdata(&dev->dev);
|
2012-03-01 09:04:44 +04:00
|
|
|
enum pxa_i2c_types i2c_type;
|
|
|
|
struct pxa_i2c *i2c;
|
|
|
|
struct resource *res = NULL;
|
|
|
|
int ret, irq;
|
2007-02-08 11:43:26 +03:00
|
|
|
|
2007-05-21 15:29:40 +04:00
|
|
|
i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
|
2007-02-08 11:43:26 +03:00
|
|
|
if (!i2c) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto emalloc;
|
|
|
|
}
|
|
|
|
|
2013-03-01 10:57:32 +04:00
|
|
|
/* Default adapter num to device id; i2c_pxa_probe_dt can override. */
|
|
|
|
i2c->adap.nr = dev->id;
|
|
|
|
|
2012-03-01 09:04:44 +04:00
|
|
|
ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type);
|
|
|
|
if (ret > 0)
|
|
|
|
ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
|
|
|
|
if (ret < 0)
|
|
|
|
goto eclk;
|
|
|
|
|
|
|
|
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
|
|
|
irq = platform_get_irq(dev, 0);
|
|
|
|
if (res == NULL || irq < 0) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto eclk;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!request_mem_region(res->start, resource_size(res), res->name)) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto eclk;
|
|
|
|
}
|
|
|
|
|
2007-05-21 15:29:40 +04:00
|
|
|
i2c->adap.owner = THIS_MODULE;
|
|
|
|
i2c->adap.retries = 5;
|
|
|
|
|
|
|
|
spin_lock_init(&i2c->lock);
|
2007-02-08 11:43:26 +03:00
|
|
|
init_waitqueue_head(&i2c->wait);
|
2007-05-21 15:29:40 +04:00
|
|
|
|
2013-03-01 10:57:32 +04:00
|
|
|
strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name));
|
2007-02-08 11:43:26 +03:00
|
|
|
|
2008-11-11 20:52:32 +03:00
|
|
|
i2c->clk = clk_get(&dev->dev, NULL);
|
2007-08-20 13:19:10 +04:00
|
|
|
if (IS_ERR(i2c->clk)) {
|
|
|
|
ret = PTR_ERR(i2c->clk);
|
|
|
|
goto eclk;
|
|
|
|
}
|
|
|
|
|
2009-06-14 02:20:36 +04:00
|
|
|
i2c->reg_base = ioremap(res->start, resource_size(res));
|
2007-02-08 11:43:26 +03:00
|
|
|
if (!i2c->reg_base) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto eremap;
|
|
|
|
}
|
2011-02-23 14:38:15 +03:00
|
|
|
|
|
|
|
i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
|
|
|
|
i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
|
|
|
|
i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr;
|
|
|
|
i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr;
|
2011-03-02 13:26:53 +03:00
|
|
|
if (i2c_type != REGS_CE4100)
|
|
|
|
i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar;
|
2007-02-08 11:43:26 +03:00
|
|
|
|
|
|
|
i2c->iobase = res->start;
|
2009-06-14 02:20:36 +04:00
|
|
|
i2c->iosize = resource_size(res);
|
2007-02-08 11:43:26 +03:00
|
|
|
|
|
|
|
i2c->irq = irq;
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
|
2013-06-07 10:38:17 +04:00
|
|
|
i2c->highmode_enter = false;
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
if (plat) {
|
2012-03-01 09:04:44 +04:00
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
2005-06-15 15:38:14 +04:00
|
|
|
i2c->slave_addr = plat->slave_addr;
|
2006-11-08 00:03:20 +03:00
|
|
|
i2c->slave = plat->slave;
|
2005-06-15 15:38:14 +04:00
|
|
|
#endif
|
2008-01-27 20:14:50 +03:00
|
|
|
i2c->adap.class = plat->class;
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:38:17 +04:00
|
|
|
if (i2c->high_mode) {
|
|
|
|
if (i2c->rate) {
|
|
|
|
clk_set_rate(i2c->clk, i2c->rate);
|
|
|
|
pr_info("i2c: <%s> set rate to %ld\n",
|
|
|
|
i2c->adap.name, clk_get_rate(i2c->clk));
|
|
|
|
} else
|
|
|
|
pr_warn("i2c: <%s> clock rate not set\n",
|
|
|
|
i2c->adap.name);
|
|
|
|
}
|
|
|
|
|
2013-06-17 19:30:36 +04:00
|
|
|
clk_prepare_enable(i2c->clk);
|
2012-03-01 09:04:44 +04:00
|
|
|
|
2008-01-27 20:14:50 +03:00
|
|
|
if (i2c->use_pio) {
|
|
|
|
i2c->adap.algo = &i2c_pxa_pio_algorithm;
|
|
|
|
} else {
|
|
|
|
i2c->adap.algo = &i2c_pxa_algorithm;
|
2011-02-23 14:38:18 +03:00
|
|
|
ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
|
2013-03-01 10:57:32 +04:00
|
|
|
dev_name(&dev->dev), i2c);
|
2008-01-27 20:14:50 +03:00
|
|
|
if (ret)
|
|
|
|
goto ereqirq;
|
|
|
|
}
|
2007-02-08 11:43:26 +03:00
|
|
|
|
2005-06-15 15:38:14 +04:00
|
|
|
i2c_pxa_reset(i2c);
|
|
|
|
|
|
|
|
i2c->adap.algo_data = i2c;
|
2005-11-10 01:32:44 +03:00
|
|
|
i2c->adap.dev.parent = &dev->dev;
|
2011-02-23 14:38:20 +03:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
i2c->adap.dev.of_node = dev->dev.of_node;
|
|
|
|
#endif
|
2005-06-15 15:38:14 +04:00
|
|
|
|
2011-07-25 19:49:43 +04:00
|
|
|
ret = i2c_add_numbered_adapter(&i2c->adap);
|
2005-06-15 15:38:14 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_INFO "I2C: Failed to add bus\n");
|
2007-02-08 11:43:26 +03:00
|
|
|
goto eadapt;
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2005-11-10 01:32:44 +03:00
|
|
|
platform_set_drvdata(dev, i2c);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_I2C_PXA_SLAVE
|
|
|
|
printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n",
|
2009-01-07 16:29:16 +03:00
|
|
|
dev_name(&i2c->adap.dev), i2c->slave_addr);
|
2005-06-15 15:38:14 +04:00
|
|
|
#else
|
|
|
|
printk(KERN_INFO "I2C: %s: PXA I2C adapter\n",
|
2009-01-07 16:29:16 +03:00
|
|
|
dev_name(&i2c->adap.dev));
|
2005-06-15 15:38:14 +04:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
|
2007-02-08 11:43:26 +03:00
|
|
|
eadapt:
|
2008-01-27 20:14:50 +03:00
|
|
|
if (!i2c->use_pio)
|
|
|
|
free_irq(irq, i2c);
|
2007-02-08 11:43:26 +03:00
|
|
|
ereqirq:
|
2013-06-17 19:30:36 +04:00
|
|
|
clk_disable_unprepare(i2c->clk);
|
2008-02-24 22:03:42 +03:00
|
|
|
iounmap(i2c->reg_base);
|
2007-02-08 11:43:26 +03:00
|
|
|
eremap:
|
2007-08-20 13:19:10 +04:00
|
|
|
clk_put(i2c->clk);
|
|
|
|
eclk:
|
2007-02-08 11:43:26 +03:00
|
|
|
kfree(i2c);
|
|
|
|
emalloc:
|
2009-06-14 02:20:36 +04:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
2005-06-15 15:38:14 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-20 02:50:10 +04:00
|
|
|
static int i2c_pxa_remove(struct platform_device *dev)
|
2005-06-15 15:38:14 +04:00
|
|
|
{
|
2005-11-10 01:32:44 +03:00
|
|
|
struct pxa_i2c *i2c = platform_get_drvdata(dev);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
i2c_del_adapter(&i2c->adap);
|
2008-01-27 20:14:50 +03:00
|
|
|
if (!i2c->use_pio)
|
|
|
|
free_irq(i2c->irq, i2c);
|
2007-08-20 13:19:10 +04:00
|
|
|
|
2013-06-17 19:30:36 +04:00
|
|
|
clk_disable_unprepare(i2c->clk);
|
2007-08-20 13:19:10 +04:00
|
|
|
clk_put(i2c->clk);
|
|
|
|
|
2008-02-24 22:03:42 +03:00
|
|
|
iounmap(i2c->reg_base);
|
2007-02-08 11:43:26 +03:00
|
|
|
release_mem_region(i2c->iobase, i2c->iosize);
|
|
|
|
kfree(i2c);
|
2005-06-15 15:38:14 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-26 13:40:50 +04:00
|
|
|
#ifdef CONFIG_PM
|
2009-07-08 15:22:39 +04:00
|
|
|
static int i2c_pxa_suspend_noirq(struct device *dev)
|
2008-08-26 13:40:50 +04:00
|
|
|
{
|
2009-07-08 15:22:39 +04:00
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct pxa_i2c *i2c = platform_get_drvdata(pdev);
|
|
|
|
|
2008-08-26 13:40:50 +04:00
|
|
|
clk_disable(i2c->clk);
|
2009-07-08 15:22:39 +04:00
|
|
|
|
2008-08-26 13:40:50 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-08 15:22:39 +04:00
|
|
|
static int i2c_pxa_resume_noirq(struct device *dev)
|
2008-08-26 13:40:50 +04:00
|
|
|
{
|
2009-07-08 15:22:39 +04:00
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct pxa_i2c *i2c = platform_get_drvdata(pdev);
|
2008-08-26 13:40:50 +04:00
|
|
|
|
|
|
|
clk_enable(i2c->clk);
|
|
|
|
i2c_pxa_reset(i2c);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-08 15:22:39 +04:00
|
|
|
|
2009-12-15 05:00:08 +03:00
|
|
|
static const struct dev_pm_ops i2c_pxa_dev_pm_ops = {
|
2009-07-08 15:22:39 +04:00
|
|
|
.suspend_noirq = i2c_pxa_suspend_noirq,
|
|
|
|
.resume_noirq = i2c_pxa_resume_noirq,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops)
|
2008-08-26 13:40:50 +04:00
|
|
|
#else
|
2009-07-08 15:22:39 +04:00
|
|
|
#define I2C_PXA_DEV_PM_OPS NULL
|
2008-08-26 13:40:50 +04:00
|
|
|
#endif
|
|
|
|
|
2005-11-10 01:32:44 +03:00
|
|
|
static struct platform_driver i2c_pxa_driver = {
|
2005-06-15 15:38:14 +04:00
|
|
|
.probe = i2c_pxa_probe,
|
2013-02-20 02:50:10 +04:00
|
|
|
.remove = i2c_pxa_remove,
|
2005-11-10 01:32:44 +03:00
|
|
|
.driver = {
|
|
|
|
.name = "pxa2xx-i2c",
|
2008-02-24 22:03:42 +03:00
|
|
|
.owner = THIS_MODULE,
|
2009-07-08 15:22:39 +04:00
|
|
|
.pm = I2C_PXA_DEV_PM_OPS,
|
2012-03-01 09:04:44 +04:00
|
|
|
.of_match_table = i2c_pxa_dt_ids,
|
2005-11-10 01:32:44 +03:00
|
|
|
},
|
2009-04-13 10:43:25 +04:00
|
|
|
.id_table = i2c_pxa_id_table,
|
2005-06-15 15:38:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init i2c_adap_pxa_init(void)
|
|
|
|
{
|
2005-11-10 01:32:44 +03:00
|
|
|
return platform_driver_register(&i2c_pxa_driver);
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2008-02-24 22:03:42 +03:00
|
|
|
static void __exit i2c_adap_pxa_exit(void)
|
2005-06-15 15:38:14 +04:00
|
|
|
{
|
2008-02-11 18:51:41 +03:00
|
|
|
platform_driver_unregister(&i2c_pxa_driver);
|
2005-06-15 15:38:14 +04:00
|
|
|
}
|
|
|
|
|
2006-01-12 19:30:23 +03:00
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-23 00:16:49 +04:00
|
|
|
MODULE_ALIAS("platform:pxa2xx-i2c");
|
2006-01-12 19:30:23 +03:00
|
|
|
|
2008-07-15 00:38:30 +04:00
|
|
|
subsys_initcall(i2c_adap_pxa_init);
|
2005-06-15 15:38:14 +04:00
|
|
|
module_exit(i2c_adap_pxa_exit);
|