From patchwork Mon Mar 14 10:16:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Wen X-Patchwork-Id: 86714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6DEA2B6F06 for ; Mon, 14 Mar 2011 21:17:09 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0B9E72812B; Mon, 14 Mar 2011 11:16:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aPEwfXN7fHiy; Mon, 14 Mar 2011 11:16:45 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7C4832813B; Mon, 14 Mar 2011 11:16:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 375AD2812A for ; Mon, 14 Mar 2011 11:16:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s6X0zBSE38LS for ; Mon, 14 Mar 2011 11:16:24 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from dakia2.marvell.com (dakia2.marvell.com [65.219.4.35]) by theia.denx.de (Postfix) with ESMTPS id 9623B2812B for ; Mon, 14 Mar 2011 11:16:22 +0100 (CET) X-ASG-Debug-ID: 1300097780-082d97a00001-4l7tJC Received: from maili.marvell.com (maili.marvell.com [10.68.76.51]) by dakia2.marvell.com with ESMTP id CeMZSHDuEPHTd0pQ; Mon, 14 Mar 2011 03:16:20 -0700 (PDT) X-Barracuda-Envelope-From: leiwen@marvell.com Received: from localhost (unknown [10.38.164.123]) by maili.marvell.com (Postfix) with ESMTP id A495F8A07B; Mon, 14 Mar 2011 03:16:20 -0700 (PDT) From: Lei Wen To: "u-boot@lists.denx.de" , Marek Vasut , Prafulla Wadaskar , Lei Wen X-ASG-Orig-Subj: [PATCH 4/8] I2C: pxa_i2c: add multi bus support Date: Mon, 14 Mar 2011 03:16:14 -0700 X-ASG-Orig-Subj: [PATCH 4/8] I2C: pxa_i2c: add multi bus support Message-Id: <1300097775-15602-4-git-send-email-leiwen@marvell.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1300097775-15602-1-git-send-email-leiwen@marvell.com> References: <1300097775-15602-1-git-send-email-leiwen@marvell.com> X-Barracuda-Connect: maili.marvell.com[10.68.76.51] X-Barracuda-Start-Time: 1300097780 X-Barracuda-URL: http://10.68.76.222:80/cgi-mod/mark.cgi X-Barracuda-Spam-Score: -1002.00 X-Barracuda-Spam-Status: No, SCORE=-1002.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=1000.0 Subject: [U-Boot] [PATCH 4/8] I2C: pxa_i2c: add multi bus support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Lei Wen --- drivers/i2c/pxa_i2c.c | 38 ++++++++++++++++++++++++++++++++++++-- include/configs/dkb.h | 4 +++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/pxa_i2c.c b/drivers/i2c/pxa_i2c.c index 0e37417..17b83ab 100644 --- a/drivers/i2c/pxa_i2c.c +++ b/drivers/i2c/pxa_i2c.c @@ -131,9 +131,38 @@ struct pxa_i2c { u32 isar; }; -static struct pxa_i2c *base = (struct pxa_i2c *)CONFIG_PXA_I2C_REG; #define PXAI2C_AND(reg, val) writel(readl(reg) & val, reg) #define PXAI2C_OR(reg, val) writel(readl(reg) | val, reg) +static struct pxa_i2c *base; + +#ifdef CONFIG_I2C_MULTI_BUS +static u32 i2c_regs[CONFIG_PXA_I2C_NUM] = CONFIG_PXA_I2C_REG; +static unsigned int bus_initialized[CONFIG_PXA_I2C_NUM]; +static unsigned int current_bus = 0; + +int i2c_set_bus_num(unsigned int bus) +{ + if ((bus < 0) || (bus >= CONFIG_PXA_I2C_NUM)) { + printf("Bad bus: %d\n", bus); + return -1; + } + + base = (struct pxa_i2c *)i2c_regs[bus]; + current_bus = bus; + + if(!bus_initialized[current_bus]) { + i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); + bus_initialized[current_bus] = 1; + } + + return 0; +} + +unsigned int i2c_get_bus_num(void) +{ + return current_bus; +} +#endif /** * i2c_pxa_reset: - reset the host controller @@ -311,6 +340,12 @@ i2c_transfer_finish: void i2c_init(int speed, int slaveaddr) { +#ifdef CONFIG_I2C_MULTI_BUS + base = (struct pxa_i2c *)i2c_regs[current_bus]; +#else + base = (struct pxa_i2c *)CONFIG_PXA_I2C_REG; +#endif + #ifdef CONFIG_SYS_I2C_INIT_BOARD u32 icr; /* call board specific i2c bus reset routine before accessing the */ @@ -520,5 +555,4 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) return 0; } - #endif /* CONFIG_HARD_I2C */ diff --git a/include/configs/dkb.h b/include/configs/dkb.h index 75c4b99..b1a2319 100644 --- a/include/configs/dkb.h +++ b/include/configs/dkb.h @@ -62,7 +62,9 @@ */ #define CONFIG_CMD_I2C #define CONFIG_PXA_I2C 1 -#define CONFIG_PXA_I2C_REG 0xd4011000 +#define CONFIG_PXA_I2C_NUM 1 +#define CONFIG_I2C_MULTI_BUS 1 +#define CONFIG_PXA_I2C_REG {0xd4011000} #define CONFIG_HARD_I2C 1 #define CONFIG_SYS_I2C_SPEED 0 #define CONFIG_SYS_I2C_SLAVE 0xfe