From patchwork Tue Nov 20 12:19:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Wilczek X-Patchwork-Id: 200315 X-Patchwork-Delegate: hs@denx.de 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 0AC1D2C0082 for ; Tue, 20 Nov 2012 23:20:36 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A76344A0F3; Tue, 20 Nov 2012 13:20:24 +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 c1oCgU7iUITG; Tue, 20 Nov 2012 13:20:24 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BCAFC4A0C7; Tue, 20 Nov 2012 13:20:01 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C33514A0A8 for ; Tue, 20 Nov 2012 13:19:55 +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 e9KZ0vQS47Fe for ; Tue, 20 Nov 2012 13:19:53 +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 mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by theia.denx.de (Postfix) with ESMTP id 74D974A08E for ; Tue, 20 Nov 2012 13:19:48 +0100 (CET) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MDS00ERBCW6S5L0@mailout1.samsung.com> for u-boot@lists.denx.de; Tue, 20 Nov 2012 21:19:46 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-a4-50ab75624513 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id D6.0D.01231.2657BA05; Tue, 20 Nov 2012 21:19:46 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDS0002RCVY5R00@mmp2.samsung.com> for u-boot@lists.denx.de; Tue, 20 Nov 2012 21:19:46 +0900 (KST) From: Piotr Wilczek To: u-boot@lists.denx.de Date: Tue, 20 Nov 2012 13:19:06 +0100 Message-id: <1353413947-25976-6-git-send-email-p.wilczek@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1353413947-25976-1-git-send-email-p.wilczek@samsung.com> References: <1352967325-26426-1-git-send-email-p.wilczek@samsung.com> <1353413947-25976-1-git-send-email-p.wilczek@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKJMWRmVeSWpSXmKPExsVy+t9jQd2k0tUBBpd/mFq83dvJ7sDocfbO DsYAxigum5TUnMyy1CJ9uwSujGtz37EU3Iyu+P9kEVsD426vLkZODgkBE4kvu/azQ9hiEhfu rWfrYuTiEBKYzihxY+E/dghnMZPEszOLGEGq2AS0JZa/eQNmiwhISPzqv8oIUsQssJRJ4ty9 /2AJYYEAiT0bz7GB2CwCqhLzv39lBrF5BVwlOnb9h1onL/H0fh9YDaeAm8SRzmao1Y2MEo8u tTFNYORdwMiwilE0tSC5oDgpPddQrzgxt7g0L10vOT93EyPY88+kdjCubLA4xCjAwajEw/sw YVWAEGtiWXFl7iFGCQ5mJRHe+MLVAUK8KYmVValF+fFFpTmpxYcYpTlYlMR5mz1SAoQE0hNL UrNTUwtSi2CyTBycUg2MS9Ujbb/yPPCvz7bpebTNWLq61laipDhx6d2ZbvsLju0PnWLPX3zu 6dKoozuC91+/qWkmx7alqy/0TsbB+vn9+n/bwlIm+bNmvv+yja0q+0zko2bOvadZKj7kX9/t erPv0ZO+mH3b7Dd1KK5+kpI1gfWMd1BET6JJ3imuO8WWBnLbt+5+xrRKiaU4I9FQi7moOBEA 54TIO/gBAAA= Cc: Stephen Warren , Piotr Wilczek , Kyungmin Park , Tom Rini , Heiko Schocher Subject: [U-Boot] [PATCH v2 5/6] drivers:i2c:s3c24x0: modify driver for new I2C framework X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 This patch modifies s3c24x0 driver for the new I2C framework. Configs of VCMA9.h and smdk5250.h boards are modified but not tested. Signed-off-by: Piotr Wilczek Signed-off-by: Kyungmin Park CC: Minkyu Kang --- Changes for v2: - changed i2c related names to s3c24x0 driver specfic: CONFIG_MAX_I2C_NUM -> CONFIG_SYS_I2C_S3C24X0_MAX_NUM CONFIG_DRIVER_S3C24X0_I2C -> CONFIG_SYS_I2C_S3C24X0 CONFIG_SYS_I2C_SPEED/SLAVE -> CONFIG_SYS_I2C_S3C24X0_SPEED/SLAVE - removed CONFIG_HARD_I2C - removed g_current_bus and i2c_{get/set}_bus_num() functions - changed function get_base_i2c(void) to get_base_i2c(int bus) - made all functions static --- board/samsung/smdk5250/smdk5250.c | 4 +- drivers/i2c/Makefile | 2 +- drivers/i2c/i2c_core.c | 5 + drivers/i2c/s3c24x0_i2c.c | 164 ++++++++++++++++++++++++++---------- include/configs/VCMA9.h | 11 ++- include/configs/smdk5250.h | 13 ++-- 6 files changed, 140 insertions(+), 59 deletions(-) diff --git a/board/samsung/smdk5250/smdk5250.c b/board/samsung/smdk5250/smdk5250.c index a5816e4..0bc161a 100644 --- a/board/samsung/smdk5250/smdk5250.c +++ b/board/samsung/smdk5250/smdk5250.c @@ -178,7 +178,7 @@ static int board_i2c_init(void) { int i, err; - for (i = 0; i < CONFIG_MAX_I2C_NUM; i++) { + for (i = 0; i < CONFIG_SYS_I2C_S3C24X0_MAX_NUM; i++) { err = exynos_pinmux_config((PERIPH_ID_I2C0 + i), PINMUX_FLAG_NONE); if (err) { @@ -186,7 +186,7 @@ static int board_i2c_init(void) return err; } } - i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); + i2c_init(CONFIG_SYS_I2C_S3C24X0_SPEED, CONFIG_SYS_I2C_S3C24X0_SLAVE); return 0; } #endif diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 2162173..09279d0 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -37,7 +37,7 @@ COBJS-$(CONFIG_DRIVER_OMAP24XX_I2C) += omap24xx_i2c.o COBJS-$(CONFIG_DRIVER_OMAP34XX_I2C) += omap24xx_i2c.o COBJS-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o COBJS-$(CONFIG_PPC4XX_I2C) += ppc4xx_i2c.o -COBJS-$(CONFIG_DRIVER_S3C24X0_I2C) += s3c24x0_i2c.o +COBJS-$(CONFIG_SYS_I2C_S3C24X0) += s3c24x0_i2c.o COBJS-$(CONFIG_S3C44B0_I2C) += s3c44b0_i2c.o COBJS-$(CONFIG_TEGRA_I2C) += tegra_i2c.o COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o diff --git a/drivers/i2c/i2c_core.c b/drivers/i2c/i2c_core.c index d3b5a8d..143a062 100644 --- a/drivers/i2c/i2c_core.c +++ b/drivers/i2c/i2c_core.c @@ -10,6 +10,10 @@ extern struct i2c_adapter fsl_i2c_adap[]; #endif +#ifdef CONFIG_SYS_I2C_S3C24X0 +extern struct i2c_adapter s3c24x0_i2c_adap[]; +#endif + #ifdef CONFIG_SYS_I2C_SOFT extern struct i2c_adapter soft_i2c_adap[]; #endif @@ -214,6 +218,7 @@ unsigned int i2c_get_bus_num(void) */ int i2c_set_bus_num(unsigned int bus) { + #ifndef CONFIG_SYS_I2C_DIRECT_BUS int i; uint8_t buf; diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c index 90d297a..101fd08 100644 --- a/drivers/i2c/s3c24x0_i2c.c +++ b/drivers/i2c/s3c24x0_i2c.c @@ -37,8 +37,6 @@ #include #include "s3c24x0_i2c.h" -#ifdef CONFIG_HARD_I2C - #define I2C_WRITE 0 #define I2C_READ 1 @@ -59,9 +57,6 @@ #define I2C_TIMEOUT 1 /* 1 second */ - -static unsigned int g_current_bus; /* Stores Current I2C Bus */ - #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5) static int GetI2CSDA(void) { @@ -119,17 +114,17 @@ static void ReadWriteByte(struct s3c24x0_i2c *i2c) writel(readl(&i2c->iiccon) & ~I2CCON_IRPND, &i2c->iiccon); } -static struct s3c24x0_i2c *get_base_i2c(void) +static struct s3c24x0_i2c *get_base_i2c(int bus) { #ifdef CONFIG_EXYNOS4 struct s3c24x0_i2c *i2c = (struct s3c24x0_i2c *)(samsung_get_base_i2c() + (EXYNOS4_I2C_SPACING - * g_current_bus)); + * bus)); return i2c; #elif defined CONFIG_EXYNOS5 struct s3c24x0_i2c *i2c = (struct s3c24x0_i2c *)(samsung_get_base_i2c() + (EXYNOS5_I2C_SPACING - * g_current_bus)); + * bus)); return i2c; #else return s3c24x0_get_base_i2c(); @@ -163,34 +158,7 @@ static void i2c_ch_init(struct s3c24x0_i2c *i2c, int speed, int slaveadd) writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat); } -/* - * MULTI BUS I2C support - */ - -#ifdef CONFIG_I2C_MULTI_BUS -int i2c_set_bus_num(unsigned int bus) -{ - struct s3c24x0_i2c *i2c; - - if ((bus < 0) || (bus >= CONFIG_MAX_I2C_NUM)) { - debug("Bad bus: %d\n", bus); - return -1; - } - - g_current_bus = bus; - i2c = get_base_i2c(); - i2c_ch_init(i2c, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); - - return 0; -} - -unsigned int i2c_get_bus_num(void) -{ - return g_current_bus; -} -#endif - -void i2c_init(int speed, int slaveadd) +static void s3c24x0_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd) { struct s3c24x0_i2c *i2c; #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5) @@ -198,9 +166,7 @@ void i2c_init(int speed, int slaveadd) #endif int i; - /* By default i2c channel 0 is the current bus */ - g_current_bus = 0; - i2c = get_base_i2c(); + i2c = get_base_i2c(adap->hwadapnr); /* wait for some time to give previous transfer a chance to finish */ i = I2C_TIMEOUT * 1000; @@ -415,12 +381,12 @@ static int i2c_transfer(struct s3c24x0_i2c *i2c, return result; } -int i2c_probe(uchar chip) +static int s3c24x0_i2c_probe(struct i2c_adapter *adap, uchar chip) { struct s3c24x0_i2c *i2c; uchar buf[1]; - i2c = get_base_i2c(); + i2c = get_base_i2c(adap->hwadapnr); buf[0] = 0; /* @@ -431,7 +397,8 @@ int i2c_probe(uchar chip) return i2c_transfer(i2c, I2C_READ, chip << 1, 0, 0, buf, 1) != I2C_OK; } -int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) +static int s3c24x0_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, + int alen, uchar *buffer, int len) { struct s3c24x0_i2c *i2c; uchar xaddr[4]; @@ -465,7 +432,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) chip |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); #endif - i2c = get_base_i2c(); + i2c = get_base_i2c(adap->hwadapnr); ret = i2c_transfer(i2c, I2C_READ, chip << 1, &xaddr[4 - alen], alen, buffer, len); if (ret != 0) { @@ -475,7 +442,8 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) return 0; } -int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) +static int s3c24x0_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, + int alen, uchar *buffer, int len) { struct s3c24x0_i2c *i2c; uchar xaddr[4]; @@ -507,9 +475,113 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) chip |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW); #endif - i2c = get_base_i2c(); + i2c = get_base_i2c(adap->hwadapnr); return (i2c_transfer (i2c, I2C_WRITE, chip << 1, &xaddr[4 - alen], alen, buffer, len) != 0); } -#endif /* CONFIG_HARD_I2C */ + +struct i2c_adapter s3c24x0_i2c_adap[] = { + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 0, + .name = "s3c24x0-i2c" + }, +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 1 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 1, + .name = "s3c24x0-i2c#1" + }, +#endif +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 2 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 2, + .name = "s3c24x0-i2c#2" + }, +#endif +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 3 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 3, + .name = "s3c24x0-i2c#3" + }, +#endif +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 4 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 4, + .name = "s3c24x0-i2c#4" + }, +#endif +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 5 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 5, + .name = "s3c24x0-i2c#5" + }, +#endif +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 6 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 6, + .name = "s3c24x0-i2c#6" + }, +#endif +#if CONFIG_SYS_I2C_S3C24X0_MAX_NUM > 7 + { + .init = s3c24x0_i2c_init, + .probe = s3c24x0_i2c_probe, + .read = s3c24x0_i2c_read, + .write = s3c24x0_i2c_write, + .speed = CONFIG_SYS_I2C_S3C24X0_SPEED, + .slaveaddr = CONFIG_SYS_I2C_S3C24X0_SLAVE, + .init_done = 0, + .hwadapnr = 7, + .name = "s3c24x0-i2c#7" + }, +#endif +}; diff --git a/include/configs/VCMA9.h b/include/configs/VCMA9.h index fb7d922..23c9285 100644 --- a/include/configs/VCMA9.h +++ b/include/configs/VCMA9.h @@ -88,12 +88,15 @@ * the MPL VCMA9 is equipped with an ATMEL 24C256 EEPROM at * address 0x50 with 16bit addressing */ -#define CONFIG_HARD_I2C /* I2C with hardware support */ -#define CONFIG_SYS_I2C_SPEED 100000 /* I2C speed */ -#define CONFIG_SYS_I2C_SLAVE 0x7F /* I2C slave addr */ +#define CONFIG_SYS_I2C_S3C24X0_SPEED 100000 /* I2C speed */ +#define CONFIG_SYS_I2C_S3C24X0_SLAVE 0x7F /* I2C slave addr */ /* we use the built-in I2C controller */ -#define CONFIG_DRIVER_S3C24X0_I2C +#define CONFIG_SYS_I2C_S3C24X0 + +#define CONFIG_SYS_I2C +#define CONFIG_SYS_I2C_ADAPTERS {&s3c24x0_i2c_adap[0]} +#define CONFIG_SYS_NUM_I2C_ADAPTERS 1 #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 diff --git a/include/configs/smdk5250.h b/include/configs/smdk5250.h index c0f8622..2de5d5c 100644 --- a/include/configs/smdk5250.h +++ b/include/configs/smdk5250.h @@ -196,13 +196,14 @@ /* I2C */ #define CONFIG_SYS_I2C_INIT_BOARD -#define CONFIG_HARD_I2C #define CONFIG_CMD_I2C -#define CONFIG_SYS_I2C_SPEED 100000 /* 100 Kbps */ -#define CONFIG_DRIVER_S3C24X0_I2C -#define CONFIG_I2C_MULTI_BUS -#define CONFIG_MAX_I2C_NUM 8 -#define CONFIG_SYS_I2C_SLAVE 0x0 +#define CONFIG_SYS_I2C +#define CONFIG_SYS_I2C_S3C24X0 +#define CONFIG_SYS_I2C_S3C24X0_MAX_NUM 8 +#define CONFIG_SYS_I2C_S3C24X0_SPEED 100000 /* 100 Kbps */ +#define CONFIG_SYS_I2C_S3C24X0_SLAVE 0x0 +#define CONFIG_SYS_I2C_ADAPTERS {&s3c24x0_i2c_adap[0]} +#define CONFIG_SYS_NUM_I2C_ADAPTERS 1 /* Ethernet Controllor Driver */ #ifdef CONFIG_CMD_NET