[PATCH 2/2] Blackifn I2C/TWI driver: add platform_resource interface to support multi-port TWI controllers and remove old I2C BF54x porting

2007-10-11 Thread Bryan Wu
Signed-off-by: Bryan Wu <[EMAIL PROTECTED]>
---
 drivers/i2c/busses/Kconfig   |6 +-
 drivers/i2c/busses/i2c-bfin-twi.c|  246 ++
 include/asm-blackfin/mach-bf548/cdefBF54x_base.h |   33 ---
 3 files changed, 160 insertions(+), 125 deletions(-)

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 9f3a4cd..dc14449 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -92,10 +92,10 @@ config I2C_AU1550
 
 config I2C_BLACKFIN_TWI
tristate "Blackfin TWI I2C support"
-   depends on BF534 || BF536 || BF537 || BF54x
+   depends on I2C && (BF534 || BF536 || BF537 || BF54x)
help
  This is the TWI I2C device driver for Blackfin 534/536/537/54x.
- This driver can also be built as a module.  If so, the module
+ This driver can also be built as a module. If so, the module
  will be called i2c-bfin-twi.
 
 config I2C_BLACKFIN_TWI_CLK_KHZ
@@ -104,7 +104,7 @@ config I2C_BLACKFIN_TWI_CLK_KHZ
range 10 400
default 50
help
- The unit of the TWI clock is kHz.
+ The unit of the TWI clock is kilo HZ.
 
 config I2C_ELEKTOR
tristate "Elektor ISA card"
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c 
b/drivers/i2c/busses/i2c-bfin-twi.c
index d636a84..394b1f4 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -7,6 +7,10 @@
  *
  * Copyright (c) 2005-2007 Analog Devices, Inc.
  *
+ * Modified:
+ * Aug 01, 2007 add platform_resource interface to support multi-port
+ *  TWI controllers. (Bryan Wu <[EMAIL PROTECTED]>)
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -65,41 +69,64 @@ struct bfin_twi_iface {
int cur_msg;
 };
 
-static struct bfin_twi_iface twi_iface;
+static u32 twi_regs_base;
+
+#define DEFINE_TWI_REG(reg, off) \
+static inline u16 read_##reg(void) \
+   { return bfin_read16(twi_regs_base + off); } \
+static inline void write_##reg(u16 v) \
+   {bfin_write16(twi_regs_base + off, v); }
+
+DEFINE_TWI_REG(CLKDIV, 0x00)
+DEFINE_TWI_REG(CONTROL, 0x04)
+DEFINE_TWI_REG(SLAVE_CTL, 0x08)
+DEFINE_TWI_REG(SLAVE_STAT, 0x0C)
+DEFINE_TWI_REG(SLAVE_ADDR, 0x10)
+DEFINE_TWI_REG(MASTER_CTL, 0x14)
+DEFINE_TWI_REG(MASTER_STAT, 0x18)
+DEFINE_TWI_REG(MASTER_ADDR, 0x1C)
+DEFINE_TWI_REG(INT_STAT, 0x20)
+DEFINE_TWI_REG(INT_MASK, 0x24)
+DEFINE_TWI_REG(FIFO_CTL, 0x28)
+DEFINE_TWI_REG(FIFO_STAT, 0x2C)
+DEFINE_TWI_REG(XMT_DATA8, 0x80)
+DEFINE_TWI_REG(XMT_DATA16, 0x84)
+DEFINE_TWI_REG(RCV_DATA8, 0x88)
+DEFINE_TWI_REG(RCV_DATA16, 0x8C)
 
 static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
 {
-   unsigned short twi_int_status = bfin_read_TWI_INT_STAT();
-   unsigned short mast_stat = bfin_read_TWI_MASTER_STAT();
+   unsigned short twi_int_status = read_INT_STAT();
+   unsigned short mast_stat = read_MASTER_STAT();
 
if (twi_int_status & XMTSERV) {
/* Transmit next data */
if (iface->writeNum > 0) {
-   bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
+   write_XMT_DATA8(*(iface->transPtr++));
iface->writeNum--;
}
/* start receive immediately after complete sending in
 * combine mode.
 */
else if (iface->cur_mode == TWI_I2C_MODE_COMBINED)
-   bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
+   write_MASTER_CTL(read_MASTER_CTL()
| MDIR | RSTART);
else if (iface->manual_stop)
-   bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
+   write_MASTER_CTL(read_MASTER_CTL()
| STOP);
else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
iface->cur_msg+1 < iface->msg_num)
-   bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
+   write_MASTER_CTL(read_MASTER_CTL()
| RSTART);
SSYNC();
/* Clear status */
-   bfin_write_TWI_INT_STAT(XMTSERV);
+   write_INT_STAT(XMTSERV);
SSYNC();
}
if (twi_int_status & RCVSERV) {
if (iface->readNum > 0) {
/* Receive next data */
-   *(iface->transPtr) = bfin_read_TWI_RCV_DATA8();
+   *(iface->transPtr) = read_RCV_DATA8();
if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
/* Change combine mode into sub mode after
 * read 

[PATCH 2/2] Blackifn I2C/TWI driver: add platform_resource interface to support multi-port TWI controllers and remove old I2C BF54x porting

2007-10-11 Thread Bryan Wu
Signed-off-by: Bryan Wu [EMAIL PROTECTED]
---
 drivers/i2c/busses/Kconfig   |6 +-
 drivers/i2c/busses/i2c-bfin-twi.c|  246 ++
 include/asm-blackfin/mach-bf548/cdefBF54x_base.h |   33 ---
 3 files changed, 160 insertions(+), 125 deletions(-)

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 9f3a4cd..dc14449 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -92,10 +92,10 @@ config I2C_AU1550
 
 config I2C_BLACKFIN_TWI
tristate Blackfin TWI I2C support
-   depends on BF534 || BF536 || BF537 || BF54x
+   depends on I2C  (BF534 || BF536 || BF537 || BF54x)
help
  This is the TWI I2C device driver for Blackfin 534/536/537/54x.
- This driver can also be built as a module.  If so, the module
+ This driver can also be built as a module. If so, the module
  will be called i2c-bfin-twi.
 
 config I2C_BLACKFIN_TWI_CLK_KHZ
@@ -104,7 +104,7 @@ config I2C_BLACKFIN_TWI_CLK_KHZ
range 10 400
default 50
help
- The unit of the TWI clock is kHz.
+ The unit of the TWI clock is kilo HZ.
 
 config I2C_ELEKTOR
tristate Elektor ISA card
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c 
b/drivers/i2c/busses/i2c-bfin-twi.c
index d636a84..394b1f4 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -7,6 +7,10 @@
  *
  * Copyright (c) 2005-2007 Analog Devices, Inc.
  *
+ * Modified:
+ * Aug 01, 2007 add platform_resource interface to support multi-port
+ *  TWI controllers. (Bryan Wu [EMAIL PROTECTED])
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -65,41 +69,64 @@ struct bfin_twi_iface {
int cur_msg;
 };
 
-static struct bfin_twi_iface twi_iface;
+static u32 twi_regs_base;
+
+#define DEFINE_TWI_REG(reg, off) \
+static inline u16 read_##reg(void) \
+   { return bfin_read16(twi_regs_base + off); } \
+static inline void write_##reg(u16 v) \
+   {bfin_write16(twi_regs_base + off, v); }
+
+DEFINE_TWI_REG(CLKDIV, 0x00)
+DEFINE_TWI_REG(CONTROL, 0x04)
+DEFINE_TWI_REG(SLAVE_CTL, 0x08)
+DEFINE_TWI_REG(SLAVE_STAT, 0x0C)
+DEFINE_TWI_REG(SLAVE_ADDR, 0x10)
+DEFINE_TWI_REG(MASTER_CTL, 0x14)
+DEFINE_TWI_REG(MASTER_STAT, 0x18)
+DEFINE_TWI_REG(MASTER_ADDR, 0x1C)
+DEFINE_TWI_REG(INT_STAT, 0x20)
+DEFINE_TWI_REG(INT_MASK, 0x24)
+DEFINE_TWI_REG(FIFO_CTL, 0x28)
+DEFINE_TWI_REG(FIFO_STAT, 0x2C)
+DEFINE_TWI_REG(XMT_DATA8, 0x80)
+DEFINE_TWI_REG(XMT_DATA16, 0x84)
+DEFINE_TWI_REG(RCV_DATA8, 0x88)
+DEFINE_TWI_REG(RCV_DATA16, 0x8C)
 
 static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
 {
-   unsigned short twi_int_status = bfin_read_TWI_INT_STAT();
-   unsigned short mast_stat = bfin_read_TWI_MASTER_STAT();
+   unsigned short twi_int_status = read_INT_STAT();
+   unsigned short mast_stat = read_MASTER_STAT();
 
if (twi_int_status  XMTSERV) {
/* Transmit next data */
if (iface-writeNum  0) {
-   bfin_write_TWI_XMT_DATA8(*(iface-transPtr++));
+   write_XMT_DATA8(*(iface-transPtr++));
iface-writeNum--;
}
/* start receive immediately after complete sending in
 * combine mode.
 */
else if (iface-cur_mode == TWI_I2C_MODE_COMBINED)
-   bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
+   write_MASTER_CTL(read_MASTER_CTL()
| MDIR | RSTART);
else if (iface-manual_stop)
-   bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
+   write_MASTER_CTL(read_MASTER_CTL()
| STOP);
else if (iface-cur_mode == TWI_I2C_MODE_REPEAT 
iface-cur_msg+1  iface-msg_num)
-   bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
+   write_MASTER_CTL(read_MASTER_CTL()
| RSTART);
SSYNC();
/* Clear status */
-   bfin_write_TWI_INT_STAT(XMTSERV);
+   write_INT_STAT(XMTSERV);
SSYNC();
}
if (twi_int_status  RCVSERV) {
if (iface-readNum  0) {
/* Receive next data */
-   *(iface-transPtr) = bfin_read_TWI_RCV_DATA8();
+   *(iface-transPtr) = read_RCV_DATA8();
if (iface-cur_mode == TWI_I2C_MODE_COMBINED) {
/* Change combine mode into sub mode after
 * read first data.
@@ -114,33 +141,33 @@