From patchwork Sat May 18 09:37:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 244747 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 C7D7B2C0099 for ; Sat, 18 May 2013 19:39:36 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E78194A050; Sat, 18 May 2013 11:39:12 +0200 (CEST) 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 5jbKHNPCQEVZ; Sat, 18 May 2013 11:39:12 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4ADB24A094; Sat, 18 May 2013 11:38:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 278124A040 for ; Sat, 18 May 2013 11:38:19 +0200 (CEST) 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 1aoU4xe6O6pc for ; Sat, 18 May 2013 11:38:17 +0200 (CEST) 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 pollux.denx.de (host-82-135-33-74.customer.m-online.net [82.135.33.74]) by theia.denx.de (Postfix) with ESMTP id CE0744A03A for ; Sat, 18 May 2013 11:38:10 +0200 (CEST) Received: by pollux.denx.de (Postfix, from userid 515) id 1E93B7F9A; Sat, 18 May 2013 11:38:04 +0200 (CEST) From: Heiko Schocher To: u-boot@lists.denx.de Date: Sat, 18 May 2013 11:37:59 +0200 Message-Id: <1368869881-4398-9-git-send-email-hs@denx.de> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1368869881-4398-1-git-send-email-hs@denx.de> References: <1368869881-4398-1-git-send-email-hs@denx.de> MIME-Version: 1.0 Cc: Heiko Schocher Subject: [U-Boot] =?utf-8?q?=5BPATCH_v4_08/10=5D_tegra=3A_i2c=3A_Enable_ne?= =?utf-8?q?w_CONFIG=5FSYS=5FI2C_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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Simon Glass This enables CONFIG_SYS_I2C on Tegra, updating existing boards and the Tegra i2c driver to support this. Signed-off-by: Simon Glass Signed-off-by: Heiko Schocher --- - changes for v2: new in v2 posted from Simon Glass here: http://patchwork.ozlabs.org/patch/195568/ added to this patchserie, changes: - rebased to current head - add "struct i2c_adapter *adap" to the i2c adapter functions. - rework tegra_i2c_get_bus() - add missing adapters in tegra_i2c_adap[] - replace CONFIG_SYS_MAX_I2C_BUS through TEGRA_I2C_NUM_CONTROLLERS - rename CONFIG_TEGRA_I2C to CONFIG_SYS_I2C_TEGRA - changes for v3: - adapt to the new introduced U_BOOT_I2C_ADAP_COMPLETE define - add changes for dalmore and cardhu boards - adapt README - adapt commit message - patch has 1 checkpatch warning: WARNING: Avoid CamelCase: #1274: FILE: drivers/i2c/ppc4xx_i2c.c:128: + divisor = (get_OPB_freq() - 1) / 10000000; This should be fixed in a seperate step, as it affects a lot of boards... --- README | 5 +++ board/nvidia/common/board.c | 4 +- drivers/i2c/Makefile | 2 +- drivers/i2c/tegra_i2c.c | 80 +++++++++++++++---------------------- include/configs/beaver.h | 5 +-- include/configs/cardhu.h | 3 +- include/configs/dalmore.h | 3 +- include/configs/seaboard.h | 5 +-- include/configs/tegra-common-post.h | 4 +- include/configs/trimslice.h | 5 +-- include/configs/whistler.h | 5 +-- 11 Dateien geändert, 54 Zeilen hinzugefügt(+), 67 Zeilen entfernt(-) diff --git a/README b/README index 58eb83e..f44d601 100644 --- a/README +++ b/README @@ -1927,6 +1927,11 @@ CBFS (Coreboot Filesystem) support CONFIG_SYS_FSL_I2C2_SLAVE for the slave address of the second bus. + - drivers/i2c/tegra_i2c.c: + - activate this driver with CONFIG_SYS_I2C_TEGRA + - This driver adds 4 i2c buses with a fix speed from + 100000 and the slave addr 0! + additional defines: CONFIG_SYS_NUM_I2C_BUSES diff --git a/board/nvidia/common/board.c b/board/nvidia/common/board.c index 8d7a227..a4b9126 100644 --- a/board/nvidia/common/board.c +++ b/board/nvidia/common/board.c @@ -150,7 +150,7 @@ int board_init(void) power_det_init(); -#ifdef CONFIG_TEGRA_I2C +#ifdef CONFIG_SYS_I2C_TEGRA #ifndef CONFIG_SYS_I2C_INIT_BOARD #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards" #endif @@ -164,7 +164,7 @@ int board_init(void) debug("Memory controller init failed: %d\n", err); # endif # endif /* CONFIG_TEGRA_PMU */ -#endif /* CONFIG_TEGRA_I2C */ +#endif /* CONFIG_SYS_I2C_TEGRA */ #ifdef CONFIG_USB_EHCI_TEGRA pin_mux_usb(); diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 2162173..564d061 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -39,7 +39,6 @@ COBJS-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o COBJS-$(CONFIG_PPC4XX_I2C) += ppc4xx_i2c.o COBJS-$(CONFIG_DRIVER_S3C24X0_I2C) += s3c24x0_i2c.o COBJS-$(CONFIG_S3C44B0_I2C) += s3c44b0_i2c.o -COBJS-$(CONFIG_TEGRA_I2C) += tegra_i2c.o COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o COBJS-$(CONFIG_U8500_I2C) += u8500_i2c.o COBJS-$(CONFIG_SH_I2C) += sh_i2c.o @@ -47,6 +46,7 @@ COBJS-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o COBJS-$(CONFIG_SYS_I2C) += i2c_core.o COBJS-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o COBJS-$(CONFIG_SYS_I2C_SOFT) += soft_i2c.o +COBJS-$(CONFIG_SYS_I2C_TEGRA) += tegra_i2c.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/i2c/tegra_i2c.c b/drivers/i2c/tegra_i2c.c index 8fa1cda..9bf71a6 100644 --- a/drivers/i2c/tegra_i2c.c +++ b/drivers/i2c/tegra_i2c.c @@ -35,8 +35,6 @@ DECLARE_GLOBAL_DATA_PTR; -static unsigned int i2c_bus_num; - /* Information about i2c controller */ struct i2c_bus { int id; @@ -332,38 +330,25 @@ static int tegra_i2c_read_data(struct i2c_bus *bus, u32 addr, u8 *data, * @param bus_num Bus number to check / return * @return pointer to bus, if valid, else NULL */ -static struct i2c_bus *tegra_i2c_get_bus(unsigned int bus_num) +static struct i2c_bus *tegra_i2c_get_bus(struct i2c_adapter *adap) { struct i2c_bus *bus; - if (bus_num >= TEGRA_I2C_NUM_CONTROLLERS) { - debug("%s: Invalid bus number %u\n", __func__, bus_num); - return NULL; - } - bus = &i2c_controllers[bus_num]; + bus = &i2c_controllers[adap->hwadapnr]; if (!bus->inited) { - debug("%s: Bus %u not available\n", __func__, bus_num); + debug("%s: Bus %u not available\n", __func__, adap->hwadapnr); return NULL; } return bus; } -unsigned int i2c_get_bus_speed(void) -{ - struct i2c_bus *bus; - - bus = tegra_i2c_get_bus(i2c_bus_num); - if (!bus) - return 0; - return bus->speed; -} - -int i2c_set_bus_speed(unsigned int speed) +static unsigned int tegra_i2c_set_bus_speed(struct i2c_adapter *adap, + unsigned int speed) { struct i2c_bus *bus; - bus = tegra_i2c_get_bus(i2c_bus_num); + bus = tegra_i2c_get_bus(adap); if (!bus) return 0; bus->speed = speed; @@ -482,7 +467,7 @@ void i2c_init_board(void) return; } -void i2c_init(int speed, int slaveaddr) +static void tegra_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr) { /* This will override the speed selected in the fdt for that port */ debug("i2c_init(speed=%u, slaveaddr=0x%x)\n", speed, slaveaddr); @@ -532,14 +517,14 @@ int i2c_read_data(struct i2c_bus *bus, uchar chip, uchar *buffer, int len) } /* Probe to see if a chip is present. */ -int i2c_probe(uchar chip) +static int tegra_i2c_probe(struct i2c_adapter *adap, uchar chip) { struct i2c_bus *bus; int rc; uchar reg; debug("i2c_probe: addr=0x%x\n", chip); - bus = tegra_i2c_get_bus(i2c_get_bus_num()); + bus = tegra_i2c_get_bus(adap); if (!bus) return 1; reg = 0; @@ -558,7 +543,8 @@ static int i2c_addr_ok(const uint addr, const int alen) } /* Read bytes */ -int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) +static int tegra_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, + int alen, uchar *buffer, int len) { struct i2c_bus *bus; uint offset; @@ -566,7 +552,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) debug("i2c_read: chip=0x%x, addr=0x%x, len=0x%x\n", chip, addr, len); - bus = tegra_i2c_get_bus(i2c_bus_num); + bus = tegra_i2c_get_bus(adap); if (!bus) return 1; if (!i2c_addr_ok(addr, alen)) { @@ -596,7 +582,8 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) } /* Write bytes */ -int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) +static int tegra_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, + int alen, uchar *buffer, int len) { struct i2c_bus *bus; uint offset; @@ -604,7 +591,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) debug("i2c_write: chip=0x%x, addr=0x%x, len=0x%x\n", chip, addr, len); - bus = tegra_i2c_get_bus(i2c_bus_num); + bus = tegra_i2c_get_bus(adap); if (!bus) return 1; if (!i2c_addr_ok(addr, alen)) { @@ -625,30 +612,11 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) return 0; } -#if defined(CONFIG_I2C_MULTI_BUS) -/* - * Functions for multiple I2C bus handling - */ -unsigned int i2c_get_bus_num(void) -{ - return i2c_bus_num; -} - -int i2c_set_bus_num(unsigned int bus) -{ - if (bus >= TEGRA_I2C_NUM_CONTROLLERS || !i2c_controllers[bus].inited) - return -1; - i2c_bus_num = bus; - - return 0; -} -#endif - int tegra_i2c_get_dvc_bus_num(void) { int i; - for (i = 0; i < CONFIG_SYS_MAX_I2C_BUS; i++) { + for (i = 0; i < TEGRA_I2C_NUM_CONTROLLERS; i++) { struct i2c_bus *bus = &i2c_controllers[i]; if (bus->inited && bus->is_dvc) @@ -657,3 +625,19 @@ int tegra_i2c_get_dvc_bus_num(void) return -1; } + +/* + * Register soft i2c adapters + */ +U_BOOT_I2C_ADAP_COMPLETE(tegra0, tegra_i2c_init, tegra_i2c_probe, + tegra_i2c_read, tegra_i2c_write, + tegra_i2c_set_bus_speed, 100000, 0, 0) +U_BOOT_I2C_ADAP_COMPLETE(tegra1, tegra_i2c_init, tegra_i2c_probe, + tegra_i2c_read, tegra_i2c_write, + tegra_i2c_set_bus_speed, 100000, 0, 1) +U_BOOT_I2C_ADAP_COMPLETE(tegra2, tegra_i2c_init, tegra_i2c_probe, + tegra_i2c_read, tegra_i2c_write, + tegra_i2c_set_bus_speed, 100000, 0, 2) +U_BOOT_I2C_ADAP_COMPLETE(tegra3, tegra_i2c_init, tegra_i2c_probe, + tegra_i2c_read, tegra_i2c_write, + tegra_i2c_set_bus_speed, 100000, 0, 3) diff --git a/include/configs/beaver.h b/include/configs/beaver.h index 058da4f..dce08d5 100644 --- a/include/configs/beaver.h +++ b/include/configs/beaver.h @@ -41,12 +41,11 @@ #define CONFIG_BOARD_EARLY_INIT_F /* I2C */ -#define CONFIG_TEGRA_I2C +#define CONFIG_SYS_I2C_TEGRA #define CONFIG_SYS_I2C_INIT_BOARD -#define CONFIG_I2C_MULTI_BUS -#define CONFIG_SYS_MAX_I2C_BUS TEGRA_I2C_NUM_CONTROLLERS #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_CMD_I2C +#define CONFIG_SYS_I2C /* SD/MMC */ #define CONFIG_MMC diff --git a/include/configs/cardhu.h b/include/configs/cardhu.h index 6a99175..4c67446 100644 --- a/include/configs/cardhu.h +++ b/include/configs/cardhu.h @@ -40,12 +40,13 @@ #define CONFIG_BOARD_EARLY_INIT_F /* I2C */ -#define CONFIG_TEGRA_I2C +#define CONFIG_SYS_I2C_TEGRA #define CONFIG_SYS_I2C_INIT_BOARD #define CONFIG_I2C_MULTI_BUS #define CONFIG_SYS_MAX_I2C_BUS TEGRA_I2C_NUM_CONTROLLERS #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_CMD_I2C +#define CONFIG_SYS_I2C /* SD/MMC */ #define CONFIG_MMC diff --git a/include/configs/dalmore.h b/include/configs/dalmore.h index 7b68f7c..f76f93f 100644 --- a/include/configs/dalmore.h +++ b/include/configs/dalmore.h @@ -43,12 +43,13 @@ #define CONFIG_BOARD_EARLY_INIT_F /* I2C */ -#define CONFIG_TEGRA_I2C +#define CONFIG_SYS_I2C_TEGRA #define CONFIG_SYS_I2C_INIT_BOARD #define CONFIG_I2C_MULTI_BUS #define CONFIG_SYS_MAX_I2C_BUS TEGRA_I2C_NUM_CONTROLLERS #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_CMD_I2C +#define CONFIG_SYS_I2C /* SD/MMC */ #define CONFIG_MMC diff --git a/include/configs/seaboard.h b/include/configs/seaboard.h index f66173e..58bf60a 100644 --- a/include/configs/seaboard.h +++ b/include/configs/seaboard.h @@ -57,12 +57,11 @@ #define CONFIG_BOARD_LATE_INIT /* Make sure LCD init is complete */ /* I2C */ -#define CONFIG_TEGRA_I2C +#define CONFIG_SYS_I2C_TEGRA #define CONFIG_SYS_I2C_INIT_BOARD -#define CONFIG_I2C_MULTI_BUS -#define CONFIG_SYS_MAX_I2C_BUS 4 #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_CMD_I2C +#define CONFIG_SYS_I2C /* SD/MMC */ #define CONFIG_MMC diff --git a/include/configs/tegra-common-post.h b/include/configs/tegra-common-post.h index bf18699..6edca5e 100644 --- a/include/configs/tegra-common-post.h +++ b/include/configs/tegra-common-post.h @@ -163,8 +163,8 @@ #endif /* remove I2C support */ -#ifdef CONFIG_TEGRA_I2C -#undef CONFIG_TEGRA_I2C +#ifdef CONFIG_SYS_I2C_TEGRA +#undef CONFIG_SYS_I2C_TEGRA #endif #ifdef CONFIG_CMD_I2C #undef CONFIG_CMD_I2C diff --git a/include/configs/trimslice.h b/include/configs/trimslice.h index b925314..209c60e 100644 --- a/include/configs/trimslice.h +++ b/include/configs/trimslice.h @@ -54,12 +54,11 @@ #define CONFIG_CMD_SF /* I2C */ -#define CONFIG_TEGRA_I2C +#define CONFIG_SYS_I2C_TEGRA #define CONFIG_SYS_I2C_INIT_BOARD -#define CONFIG_I2C_MULTI_BUS -#define CONFIG_SYS_MAX_I2C_BUS 4 #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_CMD_I2C +#define CONFIG_SYS_I2C /* SD/MMC */ #define CONFIG_MMC diff --git a/include/configs/whistler.h b/include/configs/whistler.h index 9542c7e..11a7904 100644 --- a/include/configs/whistler.h +++ b/include/configs/whistler.h @@ -46,12 +46,11 @@ #define CONFIG_BOARD_EARLY_INIT_F /* I2C */ -#define CONFIG_TEGRA_I2C +#define CONFIG_SYS_I2C_TEGRA #define CONFIG_SYS_I2C_INIT_BOARD -#define CONFIG_I2C_MULTI_BUS -#define CONFIG_SYS_MAX_I2C_BUS 4 #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_CMD_I2C +#define CONFIG_SYS_I2C /* SD/MMC */ #define CONFIG_MMC