From patchwork Thu Nov 8 05:30:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 12751 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 749F123E00 for ; Thu, 8 Nov 2012 05:28:54 +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 0F0D3A187E2 for ; Thu, 8 Nov 2012 05:28:53 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so3502473iej.11 for ; Wed, 07 Nov 2012 21:28:53 -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=RBDTWH6jah/3j/C+lqfYw82uoLb3UzGEYLl76m06LQg=; b=Fyv1Is4egS4l5faBt2j4seow04cJC4MRtK3yM0SwRS7HSBjwIHqTmf19a71j6i3gDv JlJINmJ6nvVWQCtnJGB02kUE9Eb/L6wcLvKKYHinltmx302wclXYx81jg0W9stVmC0Nn oiKzKJpfDQ6DS5/DpNvxNgTUawmT/S4QDJl/9pCj9HSTtHza/CyY75S4wi+uuZInELJY hEVcJuV/yXJGBgdtWMmLIQIguJUHCkSWWQBqEs58sLkP2lP0YD8JnzUVWs0jMfwqvWxG r/r+ZO0Ht6Hh+AZRgTmgOWZg6tYPMiLdV7NHExZTezs4pgFKo69URrNt75aX/Q54NydV Vxjg== Received: by 10.43.7.132 with SMTP id oo4mr6171047icb.6.1352352533468; Wed, 07 Nov 2012 21:28:53 -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 n20csp325081igt; Wed, 7 Nov 2012 21:28:53 -0800 (PST) Received: by 10.66.85.69 with SMTP id f5mr19116977paz.50.1352352532796; Wed, 07 Nov 2012 21:28:52 -0800 (PST) Received: from mailout4.samsung.com (mailout4.samsung.com. [203.254.224.34]) by mx.google.com with ESMTP id zo3si34176992pbc.300.2012.11.07.21.28.52; Wed, 07 Nov 2012 21:28:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.34 as permitted sender) client-ip=203.254.224.34; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.34 as permitted sender) smtp.mail=rajeshwari.s@samsung.com Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MD5000OILVR7AL0@mailout4.samsung.com>; Thu, 08 Nov 2012 14:28:45 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.123]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 18.D0.12699.D034B905; Thu, 08 Nov 2012 14:28:45 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-9f-509b430dc4f1 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 67.D0.12699.D034B905; Thu, 08 Nov 2012 14:28:45 +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 <0MD500D18LOC2U10@mmp2.samsung.com>; Thu, 08 Nov 2012 14:28:45 +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] I2C: Driver changes for FDT support Date: Thu, 08 Nov 2012 11:00:02 +0530 Message-id: <1352352603-17114-6-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1352352603-17114-1-git-send-email-rajeshwari.s@samsung.com> References: <1352352603-17114-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsWyRsSkWpfXeXaAwbtrChYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgyXs/5yFZwXKXi79N9LA2M82S7GDk5JARMJFbtvMYC YYtJXLi3nq2LkYtDSGApo8TL84+BHA6wop9zWCDi0xklbqz4zgzhTGSSODDvE1g3m4CRxNaT 0xhBbBEBCYlf/VfBbGaBDInbH5aA1QgLWEicedHDDjKURUBV4thETRCTV8BDYsM2DYgbFCSO Tf3KCmJzCnhKrPv4HWyKEFDJr/2T2UFsFgEBiW+TD7FAnCYrsekA2DUSArfZJPZfmsYKMUdS 4uCKGywTGIUXMDKsYhRNLUguKE5KzzXSK07MLS7NS9dLzs/dxAgMxdP/nknvYFzVYHGIUYCD UYmHV0NydoAQa2JZcWXuIUYJDmYlEd4pR2YFCPGmJFZWpRblxxeV5qQWH2L0AbpkIrOUaHI+ ME7ySuINjU3MTY1NLY2MzExNcQgrifM2e6QECAmkJ5akZqemFqQWwYxj4uCUamDc+lK7Vt3k uOI+fp+3ZZX9j/rWzjt7RKOo0t0pVuV8isghnews3oYND/nd178KE1f1aV73sCHx2XfTaWcT Nn7cH7pTevqr+c2pRhMen7JOq5h4eVJ5puHK52t6/Y+6n+fcxPh83zvT5phHHkn+z3yClmy+ /7vCfaehrd6RVLYm7uqq7zsO879WYinOSDTUYi4qTgQAx3K97nICAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeLIzCtJLcpLzFFi42I5/e+xoC6v8+wAg/edghYP199ksZhy+AuL A5PHnWt72AIYoxoYbTJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwMdQ0tLcyVFPISc1NtlVx8 AnTdMnOAZisplCXmlAKFAhKLi5X07TBNCA1x07WAaYzQ9Q0JgusxMkADCWsYM17P+chWcFyl 4u/TfSwNjPNkuxg5OCQETCR+zmHpYuQEMsUkLtxbz9bFyMUhJDCdUeLGiu/MEM5EJokD8z6B VbEJGElsPTmNEcQWEZCQ+NV/FcxmFsiQuP1hCViNsICFxJkXPewgC1gEVCWOTdQEMXkFPCQ2 bNOA2KUgcWzqV1YQm1PAU2Ldx+9gU4SASn7tn8w+gZF3ASPDKkbR1ILkguKk9FwjveLE3OLS vHS95PzcTYzgQH8mvYNxVYPFIUYBDkYlHl4NydkBQqyJZcWVuYcYJTiYlUR4pxyZFSDEm5JY WZValB9fVJqTWnyI0QfoponMUqLJ+cAozCuJNzQ2MTc1NrU0sTAxs8QhrCTO2+yREiAkkJ5Y kpqdmlqQWgQzjomDU6qBseCx2vSIBQlnQyJFuK8YH4w7XbyUWWZN/aeUFrVOMW/e9s+FtcEu C/w0z76bsrTOppGnyZC12bOi+r35jseKvfPaFjyU5+gt8tv/o7K4PXLt89qXJjt6KxdZxBh4 z1ive2FX04vJ+Z0V6xZM4fMv/HIrRvua7NfJh+8f2rm3rVRQeP8a6b23lFiKMxINtZiLihMB 7NPmRqECAAA= X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQnb1sDDqoP+zByp+UktZk2bZFVfuVgmUGi5tRxofX3euPoensi+HHYDY1VcwWIcsx6TLmVv 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 --- drivers/i2c/s3c24x0_i2c.c | 89 ++++++++++++++++++++++++++++++++++++++++++++- drivers/i2c/s3c24x0_i2c.h | 7 ++++ include/i2c.h | 28 ++++++++++++++ 3 files changed, 123 insertions(+), 1 deletions(-) diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c index 9bc4c7f..952f76c 100644 --- a/drivers/i2c/s3c24x0_i2c.c +++ b/drivers/i2c/s3c24x0_i2c.c @@ -27,6 +27,7 @@ */ #include +#include #ifdef CONFIG_EXYNOS5 #include #include @@ -60,7 +61,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 +515,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 +unsigned int i2c_fdt_bus_values(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->node = node; + bus->bus_num = i2c_busses++; + } + + return count; +} + +static struct s3c24x0_i2c_bus *get_bus(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; + fdt_addr_t reg; + int i; + + compat = fdtdec_lookup(blob, node); + if (compat != COMPAT_SAMSUNG_S3C2440_I2C) { + debug("%s: Not a supported I2C node\n", __func__); + return -1; + } + reg = fdtdec_get_addr(blob, node, "reg"); + for (i = 0; i < i2c_busses; i++) { + if (reg == (fdt_addr_t)(uintptr_t)i2c_bus[i].regs) + 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..bdd5514 100644 --- a/drivers/i2c/s3c24x0_i2c.h +++ b/drivers/i2c/s3c24x0_i2c.h @@ -30,4 +30,11 @@ 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; +}; + #endif /* _S3C24X0_I2C_H */ diff --git a/include/i2c.h b/include/i2c.h index 16f099d..52be093 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -262,4 +262,32 @@ extern int get_multi_scl_pin(void); extern int get_multi_sda_pin(void); extern int multi_i2c_init(void); #endif + +#ifdef CONFIG_OF_CONTROL +/** + * Get FDT values for i2c bus. + * + * @param blob Device tree blbo + * @return the number of I2C bus + */ +unsigned int i2c_fdt_bus_values(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 #endif /* _I2C_H_ */