29
29
#include <linux/errno.h>
30
30
#include <linux/interrupt.h>
31
31
#include <linux/i2c-pxa.h>
32
#include <linux/of_i2c.h>
32
33
#include <linux/platform_device.h>
33
34
#include <linux/err.h>
34
35
#include <linux/clk.h>
35
36
#include <linux/slab.h>
36
37
#include <linux/io.h>
38
#include <linux/i2c/pxa-i2c.h>
38
40
#include <asm/irq.h>
42
#ifndef CONFIG_HAVE_CLK
43
#define clk_get(dev, id) NULL
44
#define clk_put(clk) do { } while (0)
45
#define clk_disable(clk) do { } while (0)
46
#define clk_enable(clk) do { } while (0)
49
struct pxa_reg_layout {
42
* I2C register offsets will be shifted 0 or 1 bit left, depending on
64
* I2C registers definitions
45
#define REG_SHIFT_0 (0 << 0)
46
#define REG_SHIFT_1 (1 << 0)
47
#define REG_SHIFT(d) ((d) & 0x1)
66
static struct pxa_reg_layout pxa_reg_layout[] = {
86
/* no isar register */
49
90
static const struct platform_device_id i2c_pxa_id_table[] = {
50
{ "pxa2xx-i2c", REG_SHIFT_1 },
51
{ "pxa3xx-pwri2c", REG_SHIFT_0 },
91
{ "pxa2xx-i2c", REGS_PXA2XX },
92
{ "pxa3xx-pwri2c", REGS_PXA3XX },
93
{ "ce4100-i2c", REGS_CE4100 },
54
96
MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
57
* I2C registers and bit definitions
65
102
#define ICR_START (1 << 0) /* start bit */
66
103
#define ICR_STOP (1 << 1) /* stop bit */
121
162
unsigned int fast_mode :1;
124
#define _IBMR(i2c) ((i2c)->reg_base + (0x0 << (i2c)->reg_shift))
125
#define _IDBR(i2c) ((i2c)->reg_base + (0x4 << (i2c)->reg_shift))
126
#define _ICR(i2c) ((i2c)->reg_base + (0x8 << (i2c)->reg_shift))
127
#define _ISR(i2c) ((i2c)->reg_base + (0xc << (i2c)->reg_shift))
128
#define _ISAR(i2c) ((i2c)->reg_base + (0x10 << (i2c)->reg_shift))
165
#define _IBMR(i2c) ((i2c)->reg_ibmr)
166
#define _IDBR(i2c) ((i2c)->reg_idbr)
167
#define _ICR(i2c) ((i2c)->reg_icr)
168
#define _ISR(i2c) ((i2c)->reg_isr)
169
#define _ISAR(i2c) ((i2c)->reg_isar)
131
172
* I2C Slave mode address
418
459
writel(I2C_ISR_INIT, _ISR(i2c));
419
460
writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
421
writel(i2c->slave_addr, _ISAR(i2c));
463
writel(i2c->slave_addr, _ISAR(i2c));
423
465
/* set control register values */
424
466
writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c));
915
959
writel(icr, _ICR(i2c));
962
#define VALID_INT_SOURCE (ISR_SSD | ISR_ALD | ISR_ITE | ISR_IRF | \
918
964
static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
920
966
struct pxa_i2c *i2c = dev_id;
921
967
u32 isr = readl(_ISR(i2c));
969
if (!(isr & VALID_INT_SOURCE))
923
972
if (i2c_debug > 2 && 0) {
924
973
dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
925
974
__func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
935
984
* Always clear all pending IRQs.
937
writel(isr & (ISR_SSD|ISR_ALD|ISR_ITE|ISR_IRF|ISR_SAD|ISR_BED), _ISR(i2c));
986
writel(isr & VALID_INT_SOURCE, _ISR(i2c));
939
988
if (isr & ISR_SAD)
940
989
i2c_pxa_slave_start(i2c, isr);
1047
i2c->reg_shift = REG_SHIFT(id->driver_data);
1098
i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
1099
i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
1100
i2c->reg_icr = i2c->reg_base + pxa_reg_layout[i2c_type].icr;
1101
i2c->reg_isr = i2c->reg_base + pxa_reg_layout[i2c_type].isr;
1102
if (i2c_type != REGS_CE4100)
1103
i2c->reg_isar = i2c->reg_base + pxa_reg_layout[i2c_type].isar;
1049
1105
i2c->iobase = res->start;
1050
1106
i2c->iosize = resource_size(res);
1072
1128
i2c->adap.algo = &i2c_pxa_pio_algorithm;
1074
1130
i2c->adap.algo = &i2c_pxa_algorithm;
1075
ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED,
1131
ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
1076
1132
i2c->adap.name, i2c);
1083
1139
i2c->adap.algo_data = i2c;
1084
1140
i2c->adap.dev.parent = &dev->dev;
1142
i2c->adap.dev.of_node = dev->dev.of_node;
1086
ret = i2c_add_numbered_adapter(&i2c->adap);
1145
if (i2c_type == REGS_CE4100)
1146
ret = i2c_add_adapter(&i2c->adap);
1148
ret = i2c_add_numbered_adapter(&i2c->adap);
1088
1150
printk(KERN_INFO "I2C: Failed to add bus\n");
1153
of_i2c_register_devices(&i2c->adap);
1092
1155
platform_set_drvdata(dev, i2c);