From patchwork Thu Dec 27 06:03:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 13706 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 26F2923F74 for ; Thu, 27 Dec 2012 05:56:55 +0000 (UTC) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by fiordland.canonical.com (Postfix) with ESMTP id BF093A18423 for ; Thu, 27 Dec 2012 05:56:54 +0000 (UTC) Received: by mail-vb0-f41.google.com with SMTP id l22so9562452vbn.28 for ; Wed, 26 Dec 2012 21:56:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :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=yJi+kTgQT8/cJKypzn0UDaepumWzBgEeAQEyfHTQgQk=; b=Kx0Ny98Y5RR/pOSRy8g/85yreuaFNrWd1gWLpHz+VCfhY0VO+JKwzZnJ1dyOTHFgVf PoJi+G+tTMKnquhkP7k1bahQ690ZRKZx6of+vptGMZcG6RBlze9hD/aP6qvrEjoxgY/u MQIa88rVYEJLMZTfe9VgR8sLZ++JZnPR9ecCUp978FdZEvAx+koGkOPLhUa22wJqwl3W m55eXia4lX4/L5wPrj44Bv8PiJD6S2hhQIGe23oo+abkWIgdiNajE8w/GlLKPoUhwu8W YMZ0LVBYqz8TJMjDzMB+xC4CLUwdlsrytBkOdOm8tU3VyX6oI08YeJwBXV5gVwREBFAp UOeA== X-Received: by 10.220.238.139 with SMTP id ks11mr44069931vcb.49.1356587814270; Wed, 26 Dec 2012 21:56:54 -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.58.214.195 with SMTP id oc3csp4978vec; Wed, 26 Dec 2012 21:56:53 -0800 (PST) X-Received: by 10.66.90.1 with SMTP id bs1mr87268084pab.19.1356587811202; Wed, 26 Dec 2012 21:56:51 -0800 (PST) Received: from mailout3.samsung.com (mailout3.samsung.com. [203.254.224.33]) by mx.google.com with ESMTP id rg4si27976898pbc.353.2012.12.26.21.56.50; Wed, 26 Dec 2012 21:56:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.33 as permitted sender) client-ip=203.254.224.33; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of rajeshwari.s@samsung.com designates 203.254.224.33 as permitted sender) smtp.mail=rajeshwari.s@samsung.com Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MFO006YMDRMKSN0@mailout3.samsung.com>; Thu, 27 Dec 2012 14:56:44 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.126]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 62.D7.01231.C13EBD05; Thu, 27 Dec 2012 14:56:44 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-d0-50dbe31c1748 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C1.D7.01231.C13EBD05; Thu, 27 Dec 2012 14:56:44 +0900 (KST) Received: from rajeshwari-linux.sisodomain.com ([107.108.215.115]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MFO009UDDU79J90@mmp1.samsung.com>; Thu, 27 Dec 2012 14:56:44 +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 Subject: [PATCH 05/16 V2] I2C: Driver changes for FDT support Date: Thu, 27 Dec 2012 11:33:12 +0530 Message-id: <1356588203-24838-6-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1356588203-24838-1-git-send-email-rajeshwari.s@samsung.com> References: <1356588203-24838-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsWyRsSkTlfm8e0Agzu/NS0err/JYjHl8BcW ByaPO9f2sAUwRnHZpKTmZJalFunbJXBl3Ni6iangoErFnr/yDYzzZLsYOTkkBEwkOjevYYGw xSQu3FvPBmILCSxllDj0Them5tGqM+xdjFxA8UWMEnv2d7JAFE1kknh8UhzEZhMwkth6choj iC0iICHxq/8qmM0sECPxev8PsKHCArYSe/dcBLNZBFQlOq69AKvhFfCQmDL/D9QRChLHpn5l BbE5BTwlJlxZxgixy0Piy57zUL0CEt8mHwKq5wCql5XYdIAZ5DYJgdtsEqc6e5gh5khKHFxx g2UCo/ACRoZVjKKpBckFxUnpuYZ6xYm5xaV56XrJ+bmbGIGhePrfM6kdjCsbLA4xCnAwKvHw KlrfDhBiTSwrrsw9xCjBwawkwjt9M1CINyWxsiq1KD++qDQntfgQow/QJROZpUST84FxklcS b2hsYm5qbGppZGRmaopDWEmct9kjJUBIID2xJDU7NbUgtQhmHBMHp1QDo93MJbtNKmX1C85o R9wNt/67neOmyaMmWeOWfbdOB4lYKP/wYTrg5b6jnu9Q3Lbw6rR5lqkBv09l3zh8d7vwjRPq nNaNlxfqH71pXPRoeUsLt6D0+ddHJ7gZn7PSXGUY52UasNZ1w9bEN2a3K/b/urv777sZ6rEL 3VPu7a7r29u4ufn6+S0XvimxFGckGmoxFxUnAgA8MsX8cgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeLIzCtJLcpLzFFi42I5/e+xgK7M49sBBhNnylo8XH+TxWLK4S8s Dkwed67tYQtgjGpgtMlITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw1DW0tDBXUshLzE21VXLx CdB1y8wBmq2kUJaYUwoUCkgsLlbSt8M0ITTETdcCpjFC1zckCK7HyAANJKxhzLixdRNTwUGV ij1/5RsY58l2MXJySAiYSDxadYYdwhaTuHBvPVsXIxeHkMAiRok9+ztZQBJCAhOZJB6fFAex 2QSMJLaenMYIYosISEj86r8KZjMLxEi83v+DDcQWFrCV2LvnIpjNIqAq0XHtBVgNr4CHxJT5 f1gglilIHJv6lRXE5hTwlJhwZRkjxC4PiS97zrNNYORdwMiwilE0tSC5oDgpPddQrzgxt7g0 L10vOT93EyM41J9J7WBc2WBxiFGAg1GJh1fR+naAEGtiWXFl7iFGCQ5mJRHe6ZuBQrwpiZVV qUX58UWlOanFhxh9gK6ayCwlmpwPjMO8knhDYxNzU2NTSxMLEzNLHMJK4rzNHikBQgLpiSWp 2ampBalFMOOYODilGhjTC9aUnetcr/ft9sN3E/QL5ETD/plOO/XjdULEqzqj1tfXfKvawm9l My6XEv8l/OVZ7S77HVULM/hPrlmwx+mD7d9+7w+dK1bJugTUHpj4l6Ezr2uzvWrI/OQFnF4q JpkHzCYJaKT4Seb0WZf92z8/5dj92edaJJVfng43WvtcZ/Kz7TnrM18qsRRnJBpqMRcVJwIA I7pd7aICAAA= X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQn/sDm9b8C8WNijPMaMC2Hr9JwMu5hjnQwzzan/Mv0DJ+Qgw9e/06bEUzplaYFSSCtgSCbS Functions added to get the I2C bus number and reset I2C bus using FDT node. Signed-off-by: Rajeshwari Shinde Acked-by: Simon Glass Acked-by: Heiko Schocher --- Changes since V1: - Removed unnecessary blank lines and added wherever required. drivers/i2c/s3c24x0_i2c.c | 83 ++++++++++++++++++++++++++++++++++++++++++++- drivers/i2c/s3c24x0_i2c.h | 8 ++++ include/i2c.h | 26 ++++++++++++++ 3 files changed, 116 insertions(+), 1 deletions(-) diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c index 90d297a..7ec01ec 100644 --- a/drivers/i2c/s3c24x0_i2c.c +++ b/drivers/i2c/s3c24x0_i2c.c @@ -27,9 +27,11 @@ */ #include +#include #if (defined CONFIG_EXYNOS4 || defined 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"))); #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5) static int GetI2CSDA(void) @@ -512,4 +521,76 @@ 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 = pinmux_decode_periph_id(blob, node); + 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(int node) +{ + int i; + + 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(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..c60d075 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(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_ */