From patchwork Wed Nov 14 09:11:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 12831 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D977523F56 for ; Wed, 14 Nov 2012 09:10:18 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 62E12A18E9B for ; Wed, 14 Nov 2012 09:10:18 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so247136iej.11 for ; Wed, 14 Nov 2012 01:10:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :dlp-filter:x-mtr:x-brightmail-tracker:x-brightmail-tracker :x-cfilter-loop:x-gm-message-state; bh=y1bqK2iiLYyK3q8o+o7eg6scwYSwcJG8zArYqMbR90A=; b=DTqwSZQNvNxuLnsDpvduRbOLlSp5XFTW1OfYDsX2V4vZ0aT7gwYhWEK7QNHk2XHC0G kMQ0Ayurn2Xr03x1UP9VoscLkwBX2h2vC7CdBFnriMDeLNt2VmTNex18co7M2VHCRX1f FBx+7cMGIpPIPkDgZ4CdR4/ynktmKWyW+Ipfxpy5eFHPxljgzmxa9EPGhIPCwr1Zu7Ch qrTK5gNVLBj3TEp/tjUuTIC97JAyTFp7XtL+RoytCdXc1JiaoxW1PrOTPBAzq94JdeSn 7JmcSfdHov02j0Y7cEDWQ4bp8XUuLfCDWF3DWS/jr6u8RQiIu+Bwfzzhj54jKewj917T Kwww== Received: by 10.50.161.169 with SMTP id xt9mr1141886igb.62.1352884217833; Wed, 14 Nov 2012 01:10:17 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp632149igt; Wed, 14 Nov 2012 01:10:17 -0800 (PST) Received: by 10.68.209.166 with SMTP id mn6mr48450872pbc.95.1352884216930; Wed, 14 Nov 2012 01:10:16 -0800 (PST) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTP id bo5si17332078pab.189.2012.11.14.01.10.16; Wed, 14 Nov 2012 01:10:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.24 as permitted sender) client-ip=203.254.224.24; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.24 as permitted sender) smtp.mail=rajeshwari.s@samsung.com 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 <0MDH00E2603YB920@mailout1.samsung.com>; Wed, 14 Nov 2012 18:09:39 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.125]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 3A.29.01231.3DF53A05; Wed, 14 Nov 2012 18:09:39 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-b3-50a35fd36bf2 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id D9.29.01231.3DF53A05; Wed, 14 Nov 2012 18:09:39 +0900 (KST) Received: from rajeshwari-linux.sisodomain.com ([107.108.215.115]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDG00I7CZWU0Z70@mmp2.samsung.com>; Wed, 14 Nov 2012 18:09:39 +0900 (KST) From: Rajeshwari Shinde To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org, hs@denx.de Subject: [PATCH 5/6 V2] I2C: Driver changes for FDT support Date: Wed, 14 Nov 2012 14:41:18 +0530 Message-id: <1352884279-24067-6-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1352884279-24067-1-git-send-email-rajeshwari.s@samsung.com> References: <1352884279-24067-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrILMWRmVeSWpSXmKPExsWyRsSkVvdy/OIAg+ZXlhYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgyjm6MLDisVvF34QO2BsYncl2MnBwSAiYSXXtPMELY YhIX7q1n62Lk4hASWMooMf/GOWaYot4VRxkhEtMZJc5c/MkE4Uxkkmh6s5MVpIpNwEhi68lp YKNEBCQkfvVfBbOZBTIkbn9YwgJiCwtYS2y6PAEsziKgKjH3+X12EJtXwEPi/qNbrBDbFCSO Tf0KZnMKeEr8f9ADZgsB1UzesZ0NoldA4tvkQ0AzOYDqZSU2HWAGuUdC4DqbxNlPU1kg5khK HFxxg2UCo/ACRoZVjKKpBckFxUnpuYZ6xYm5xaV56XrJ+bmbGIHhePrfM6kdjCsbLA4xCnAw KvHwfmxdFCDEmlhWXJl7iFGCg1lJhDfWanGAEG9KYmVValF+fFFpTmrxIUYfoEsmMkuJJucD YyWvJN7Q2MTc1NjU0sjIzNQUh7CSOG+zR0qAkEB6YklqdmpqQWoRzDgmDk6pBkbJHTnxL1Sm q/n5h3kbWs4NvSiTzVHdrHn82tZPApM3Smi+/T9zfuqFzNlVHgs/tk/0vnTCIP7Kyb7cu/f5 t63+Zf60ce2DDY/fmTyY/qRz65H/ix31+viM2hPnCFqd+702mq3C9N+/it3FF53SfM/F3lG5 s8J68eLmsLapq3uuP1CU2v4ud8sdJZbijERDLeai4kQAh6qqhnQCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRmVeSWpSXmKPExsVy+t9jQd3L8YsDDLZ+0rF4uP4mi8WUw19Y HJg87lzbwxbAGNXAaJORmpiSWqSQmpecn5KZl26r5B0c7xxvamZgqGtoaWGupJCXmJtqq+Ti E6DrlpkDNFtJoSwxpxQoFJBYXKykb4dpQmiIm64FTGOErm9IEFyPkQEaSFjDmHF0Y2TBYbWK vwsfsDUwPpHrYuTkkBAwkehdcZQRwhaTuHBvPVsXIxeHkMB0RokzF38yQTgTmSSa3uxkBali EzCS2HpyGliHiICExK/+q2A2s0CGxO0PS1hAbGEBa4lNlyeAxVkEVCXmPr/PDmLzCnhI3H90 ixVim4LEsalfwWxOAU+J/w96wGwhoJrJO7azTWDkXcDIsIpRNLUguaA4KT3XUK84Mbe4NC9d Lzk/dxMjONifSe1gXNlgcYhRgINRiYf3Y+uiACHWxLLiytxDjBIczEoivLFWiwOEeFMSK6tS i/Lji0pzUosPMfoAXTWRWUo0OR8YiXkl8YbGJuamxqaWJhYmZpY4hJXEeZs9UgKEBNITS1Kz U1MLUotgxjFxcEo1MOYG5GU2dDRPn6GQfJlFyC//4dfzUu53jvR9lhJhmBJiKpbF93vRraPs GVLnOHoLXE+Ffbu3pmXDg/BOW8c5V7JlJ13wllPNEGTivDfv7e0bLj2zL4U8dsx7phIWduO1 aSJLdrTaLJVuw1v5zdO2Bl2Q+Lhj7ZtDfX7hdsV/7mpLzJmXqN67U4mlOCPRUIu5qDgRAD+r fyKjAgAA X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQmzkxtg9Ae2aXc662vgAywPnmjRjmC4O6G9harslAXBf8xoOh4AVCh1dWTFp1SAcYohGjkQ Functions added to get the I2C bus number and reset I2C bus using FDT node. Signed-off-by: Simon Glass Signed-off-by: Rajeshwari Shinde Reviewed-by: Heiko Schocher Acked-by: Heiko Schocher --- Changes in V2: - Added periph id to I2C bus structure. - Modified i2c_get_bus_num_fdt function to compare with node. - Board i2c init moved to driver in case of FDT. drivers/i2c/s3c24x0_i2c.c | 90 ++++++++++++++++++++++++++++++++++++++++++++- drivers/i2c/s3c24x0_i2c.h | 8 ++++ include/i2c.h | 26 +++++++++++++ 3 files changed, 123 insertions(+), 1 deletions(-) diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c index 9bc4c7f..840585d 100644 --- a/drivers/i2c/s3c24x0_i2c.c +++ b/drivers/i2c/s3c24x0_i2c.c @@ -27,9 +27,11 @@ */ #include +#include #ifdef CONFIG_EXYNOS5 #include #include +#include #else #include #endif @@ -60,7 +62,14 @@ #define I2C_TIMEOUT 1 /* 1 second */ -static unsigned int g_current_bus; /* Stores Current I2C Bus */ +/* + * For SPL boot some boards need i2c before SDRAM is initialised so force + * variables to live in SRAM + */ +static unsigned int g_current_bus __attribute__((section(".data"))); +static struct s3c24x0_i2c_bus i2c_bus[CONFIG_MAX_I2C_NUM] + __attribute__((section(".data"))); +static int i2c_busses __attribute__((section(".data"))); #ifndef CONFIG_EXYNOS5 static int GetI2CSDA(void) @@ -507,4 +516,83 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) (i2c, I2C_WRITE, chip << 1, &xaddr[4 - alen], alen, buffer, len) != 0); } + +#ifdef CONFIG_OF_CONTROL +void board_i2c_init(const void *blob) +{ + + int node_list[CONFIG_MAX_I2C_NUM]; + int count, i; + + count = fdtdec_find_aliases_for_id(blob, "i2c", + COMPAT_SAMSUNG_S3C2440_I2C, node_list, + CONFIG_MAX_I2C_NUM); + for (i = 0; i < count; i++) { + struct s3c24x0_i2c_bus *bus; + int node = node_list[i]; + + if (node < 0) + continue; + bus = &i2c_bus[i]; + bus->regs = (struct s3c24x0_i2c *) + fdtdec_get_addr(blob, node, "reg"); + bus->id = (enum periph_id) + fdtdec_get_int(blob, node, "samsung,periph-id", -1); + bus->node = node; + bus->bus_num = i2c_busses++; + exynos_pinmux_config(bus->id, 0); + } + +} + +static struct s3c24x0_i2c_bus *get_bus(unsigned int bus_idx) +{ + if (bus_idx < i2c_busses) + return &i2c_bus[bus_idx]; + debug("Undefined bus: %d\n", bus_idx); + return NULL; +} + +int i2c_get_bus_num_fdt(const void *blob, int node) +{ + enum fdt_compat_id compat; + int i; + + compat = fdtdec_lookup(blob, node); + if (compat != COMPAT_SAMSUNG_S3C2440_I2C) { + debug("%s: Not a supported I2C node\n", __func__); + return -1; + } + for (i = 0; i < i2c_busses; i++) { + if (node == i2c_bus[i].node) + return i; + } + + debug("%s: Can't find any matched I2C bus\n", __func__); + return -1; +} + +int i2c_reset_port_fdt(const void *blob, int node) +{ + struct s3c24x0_i2c_bus *i2c; + + int bus; + + bus = i2c_get_bus_num_fdt(blob, node); + if (bus < 0) { + debug("could not get bus for node %d\n", node); + return -1; + } + i2c = get_bus(bus); + if (!i2c) { + debug("get_bus() failed for node node %d\n", node); + return -1; + } + + i2c_ch_init(i2c->regs, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); + + return 0; +} +#endif + #endif /* CONFIG_HARD_I2C */ diff --git a/drivers/i2c/s3c24x0_i2c.h b/drivers/i2c/s3c24x0_i2c.h index 2dd4b06..1243bf1 100644 --- a/drivers/i2c/s3c24x0_i2c.h +++ b/drivers/i2c/s3c24x0_i2c.h @@ -30,4 +30,12 @@ struct s3c24x0_i2c { u32 iicds; u32 iiclc; }; + +struct s3c24x0_i2c_bus { + int node; /* device tree node */ + int bus_num; /* i2c bus number */ + struct s3c24x0_i2c *regs; + enum periph_id id; +}; + #endif /* _S3C24X0_I2C_H */ diff --git a/include/i2c.h b/include/i2c.h index 16f099d..efb097f 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -262,4 +262,30 @@ extern int get_multi_scl_pin(void); extern int get_multi_sda_pin(void); extern int multi_i2c_init(void); #endif + +/** + * Get FDT values for i2c bus. + * + * @param blob Device tree blbo + * @return the number of I2C bus + */ +void board_i2c_init(const void *blob); + +/** + * Find the I2C bus number by given a FDT I2C node. + * + * @param blob Device tree blbo + * @param node FDT I2C node to find + * @return the number of I2C bus (zero based), or -1 on error + */ +int i2c_get_bus_num_fdt(const void *blob, int node); + +/** + * Reset the I2C bus represented by the given a FDT I2C node. + * + * @param blob Device tree blbo + * @param node FDT I2C node to find + * @return 0 if port was reset, -1 if not found + */ +int i2c_reset_port_fdt(const void *blob, int node); #endif /* _I2C_H_ */