From patchwork Tue Oct 15 10:32:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Ch X-Patchwork-Id: 283568 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 B39B92C016A for ; Tue, 15 Oct 2013 21:30:23 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A13CA4A0B9; Tue, 15 Oct 2013 12:30:20 +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 RMwTCaf5O5or; Tue, 15 Oct 2013 12:30:20 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 77B424A09B; Tue, 15 Oct 2013 12:30:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1BDD34A097 for ; Tue, 15 Oct 2013 12:30:15 +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 3I5KEdExvxi4 for ; Tue, 15 Oct 2013 12:30:09 +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 mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by theia.denx.de (Postfix) with ESMTP id D64384A09F for ; Tue, 15 Oct 2013 12:30:05 +0200 (CEST) Received: from epcpsbgr4.samsung.com (u144.gpu120.samsung.co.kr [203.254.230.144]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MUP00F2LH4VK5P0@mailout2.samsung.com> for u-boot@lists.denx.de; Tue, 15 Oct 2013 19:30:03 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgr4.samsung.com (EPCPMTA) with SMTP id F1.D7.29771.B291D525; Tue, 15 Oct 2013 19:30:03 +0900 (KST) X-AuditID: cbfee690-b7fa36d00000744b-2e-525d192b15ec Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 64.2B.09055.B291D525; Tue, 15 Oct 2013 19:30:03 +0900 (KST) Received: from naveen-linux.sisodomain.com ([107.108.83.161]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MUP00JXSH5YQK20@mmp2.samsung.com>; Tue, 15 Oct 2013 19:30:03 +0900 (KST) From: Naveen Krishna Chatradhi To: hs@denx.de, u-boot@lists.denx.de Date: Tue, 15 Oct 2013 16:02:10 +0530 Message-id: <1381833130-26275-1-git-send-email-ch.naveen@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1380524290-9644-3-git-send-email-ch.naveen@samsung.com> References: <1380524290-9644-3-git-send-email-ch.naveen@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsWyRsSkWldbMjbI4MdaFYuXhzQtdty5z2zR caSF0WLRtv/MFpMXz2e2eLu3k92BzWPerBMsHjtn3WX3OHtnB6NH35ZVjB7Hb2xnCmCN4rJJ Sc3JLEst0rdL4Mq4MXkna8FVqYplG/rZGhjni3YxcnBICJhI3Lsl28XICWSKSVy4t56ti5GL Q0hgKaPEu+5mVoiEicSPq0sZIRLTGSVm3FrDDOH0MElsWLicHaSKTcBM4uCi1WC2iICKxNYv s8BsZoEwic47X5lBbGGBWImrHffA4iwCq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qbWppYmJhZkiasJM57oNU6UEggPbEkNTs1tSC1CGYLEwen VAOjIIfGdyfXPa9zSoz8rrIaz0uPsDQ3OXL2bbyOp41O/HZ3Yzn3iLPGrvXXWJfLXDr+4fJ+ ycNXz698WW35fI5cb+eyx1vXrH+x489J329vJZZs+aRkdODN7w2macqHSwoL1vsf5mH3eH1/ 1+5nH7k7lB02JkaZd786zeR97G3iSaGWJ8yml3iWKbEUZyQaajEXFScCAISuBtLhAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: trini@ti.com, cpgs@samsung.com Subject: [U-Boot] [PATCH 2/3 v4] exynos: i2c: Change FDT bus setup code to enumerate ports correctly 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 From: Simon Glass At present the i2c ports are enumerated in a strange way - the fdtdec_find_aliases_for_id() function is used, but then the ID returned is ignored and the ports are renumbered. The effect is the same provided that the device tree has the ports in the same order, or uses aliases, and has no gaps, but it is not correct. Adjust the code to use the function as intended. This will allows device tree aliases to change the device order if required. As a result, the i2c_busses variable is dropped. We can't be sure that there are no 'holes' in the list of buses, so must check the whole array. Note: it seems that non-FDT operation is now broken in this drive and will need to be reinstated for upstream. Signed-off-by: Simon Glass Reviewed-on: https://gerrit.chromium.org/gerrit/59369 Signed-off-by: Naveen Krishna Chatradhi --- Changes since v1: Nonei Changes since v2: None Changes since v3: None; ran # ./MAKEALL -v samsung drivers/i2c/s3c24x0_i2c.c | 25 ++++++++++++++++++------- drivers/i2c/s3c24x0_i2c.h | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c index c65360d..0e6f241 100644 --- a/drivers/i2c/s3c24x0_i2c.c +++ b/drivers/i2c/s3c24x0_i2c.c @@ -52,7 +52,6 @@ */ static unsigned int g_current_bus __attribute__((section(".data"))); #ifdef CONFIG_OF_CONTROL -static int i2c_busses __attribute__((section(".data"))); static struct s3c24x0_i2c_bus i2c_bus[CONFIG_MAX_I2C_NUM] __attribute__((section(".data"))); #endif @@ -164,8 +163,8 @@ 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); + i2c_bus = get_bus(bus); + if (!i2c_bus) return -1; } @@ -483,19 +482,31 @@ void board_i2c_init(const void *blob) if (node <= 0) continue; bus = &i2c_bus[i]; + bus->active = true; bus->regs = (struct s3c24x0_i2c *) fdtdec_get_addr(blob, node, "reg"); bus->id = pinmux_decode_periph_id(blob, node); bus->node = node; - bus->bus_num = i2c_busses++; + bus->bus_num = i; exynos_pinmux_config(bus->id, 0); } } +/** + * Get a pointer to the given bus index + * + * @bus_idx: Bus index to look up + * @return pointer to bus, or NULL if invalid or not available + */ static struct s3c24x0_i2c_bus *get_bus(unsigned int bus_idx) { - if (bus_idx < i2c_busses) - return &i2c_bus[bus_idx]; + if (bus_idx < ARRAY_SIZE(i2c_bus)) { + struct s3c24x0_i2c_bus *bus; + + bus = &i2c_bus[bus_idx]; + if (bus->active) + return bus; + } debug("Undefined bus: %d\n", bus_idx); return NULL; @@ -505,7 +516,7 @@ int i2c_get_bus_num_fdt(int node) { int i; - for (i = 0; i < i2c_busses; i++) { + for (i = 0; i < ARRAY_SIZE(i2c_bus); i++) { if (node == i2c_bus[i].node) return i; } diff --git a/drivers/i2c/s3c24x0_i2c.h b/drivers/i2c/s3c24x0_i2c.h index b4a337a..882af62 100644 --- a/drivers/i2c/s3c24x0_i2c.h +++ b/drivers/i2c/s3c24x0_i2c.h @@ -16,6 +16,7 @@ struct s3c24x0_i2c { }; struct s3c24x0_i2c_bus { + bool active; /* port is active and available */ int node; /* device tree node */ int bus_num; /* i2c bus number */ struct s3c24x0_i2c *regs;