From patchwork Fri Nov 23 12:01:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 13153 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 C90C023DFE for ; Fri, 23 Nov 2012 12:00:29 +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 5F384A180A7 for ; Fri, 23 Nov 2012 12:00:29 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so1708399ieb.11 for ; Fri, 23 Nov 2012 04:00:28 -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=Zvkrz1c/k9BbORHOAI899NKP+g9FSuOcDj4jPjGz0gI=; b=cmU7CdHFrj8PK1U3uHoe4Zb/2rlB3bTlMaVWAAjB6rbl7u4aQfO8f+3+OL+iuN6/l0 76agmYv5GeV6A1nyMAxJN8AMusa3ED4twci42PnpoIz2VG21dpQGGLhDOeHQjhzpJ7wR dVdq8svrtjZxeuyxQ21/If7k4/jXP1QL0ZCpMra4deC4VC5e/bshkTtxsgx6ESKo2uED PLHKCpN79aWAaI27/tbuoEPtiqy+xu9MlVTBG0bSQn0E7L9HGVIjpFrgBs4xicRbKeVD jBAmzL3VkdaMNPv65GyO9eDlw9IwoDoj8IyvA0Em6MHIJd2SkXnNg8E/eGs5AliPVchL f0Cg== Received: by 10.50.213.69 with SMTP id nq5mr5830569igc.70.1353672028796; Fri, 23 Nov 2012 04:00:28 -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 n20csp341610igt; Fri, 23 Nov 2012 04:00:28 -0800 (PST) Received: by 10.68.252.133 with SMTP id zs5mr13456699pbc.152.1353672028024; Fri, 23 Nov 2012 04:00:28 -0800 (PST) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTP id az5si8289223pbd.114.2012.11.23.04.00.27; Fri, 23 Nov 2012 04:00:28 -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 <0MDX00DWOVY35MP0@mailout1.samsung.com> for patches@linaro.org; Fri, 23 Nov 2012 20:59:08 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.124]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 89.0D.01231.C056FA05; Fri, 23 Nov 2012 20:59:08 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-b4-50af650c695e Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 29.0D.01231.C056FA05; Fri, 23 Nov 2012 20:59:08 +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 <0MDX00GYHVRX36B0@mmp1.samsung.com> for patches@linaro.org; Fri, 23 Nov 2012 20:59:08 +0900 (KST) From: Rajeshwari Shinde To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, hs@denx.de Subject: [PATCH 5/6 V3] I2C: Driver changes for FDT support Date: Fri, 23 Nov 2012 17:31:46 +0530 Message-id: <1353672107-12904-6-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1353672107-12904-1-git-send-email-rajeshwari.s@samsung.com> References: <1353672107-12904-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJLMWRmVeSWpSXmKPExsWyRsSkRpcndX2AwZV/chZTDn9hcWD0uHNt D1sAYxSXTUpqTmZZapG+XQJXxuzTM9kK2lUr7s16zdrAuFW2i5GTQ0LAROLlvB42CFtM4sK9 9WC2kMBSRomvj2u6GDnAarp2B3UxcgGFFzFK/G5pYYNwVjBJvNk5nwWkgU3ASGLryWmMILaI gITEr/6rYDazgJfEttPfmUBsYQFrib8bvoLVswioSkx+2QUW5xXwkFjS8JYd4ggFiWNTv7KC 2JwCnhJ3dqxjBzlCCKim+WAFRKuAxLfJh1ggbpOV2HSAGaLzMpvElPt5ELakxMEVN1gmMAov YGRYxSiaWpBcUJyUnmuoV5yYW1yal66XnJ+7iREYfqf/PZPawbiyweIQowAHoxIPr2HZugAh 1sSy4srcQ4wSHMxKIrzlfusDhHhTEiurUovy44tKc1KLDzH6AB0ykVlKNDkfGBt5JfGGxibm psamlkZGZqamOISVxHmbPVIChATSE0tSs1NTC1KLYMYxcXBKNTDaa5YZRTk+/zZx2c5OyW92 SsULYz6H3U3n+TNDuVhTWfLtnN9XM3x/NjZUZT382Bq2Srttv4esd96RKXnKbsYXXj9ec3q3 Y1WLzDEv9WvLhHs7cl5I52eGbJKJ1D+ml5cW3aZkrtGzbra9pk3DWgX9xFcBn/MUuTtb7uVc rchR/HNR913KYSWW4oxEQy3mouJEACMv8ulsAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeLIzCtJLcpLzFFi42I5/e+xgC5P6voAgwOXBCymHP7C4sDocefa HrYAxqgGRpuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wc oLFKCmWJOaVAoYDE4mIlfTtME0JD3HQtYBojdH1DguB6jAzQQMIaxozZp2eyFbSrVtyb9Zq1 gXGrbBcjB4eEgIlE1+6gLkZOIFNM4sK99WxdjFwcQgKLGCV+t7RAOSuYJN7snM8CUsUmYCSx 9eQ0RhBbREBC4lf/VTCbWcBLYtvp70wgtrCAtcTfDV/B6lkEVCUmv+wCi/MKeEgsaXjLDrFN QeLY1K+sIDangKfEnR3r2EEOEgKqaT5YMYGRdwEjwypG0dSC5ILipPRcQ73ixNzi0rx0veT8 3E2M4AB/JrWDcWWDxSFGAQ5GJR5ew7J1AUKsiWXFlbmHGCU4mJVEeMv91gcI8aYkVlalFuXH F5XmpBYfYvQBOmois5Rocj4w+vJK4g2NTcxNjU0tTSxMzCxxCCuJ8zZ7pAQICaQnlqRmp6YW pBbBjGPi4JRqYOSsL1hQI8hm33bR29/tY4PKxv6+mhLtrJs3pGqdrdNMW9bcEVu3+6/Gr9dn Hh4rWSB3aNlEhWOyvHntXtmtvx/w5fWr9B9Pir13Ue2cvfnPMyU7nY9uYzmgOPd1kfn6prUl LUrPRV/dLUt9aH7VaF4UAxNnpPVK4QRB4+LprsKhn6ZzyXzWV2Ipzkg01GIuKk4EAHTxAE2d AgAA X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQnVn1hrgVD23KW+alkzy/bHVWKa8oTKFxz1x3ytW/fn5b9HVd2hbiKCE0ARj6k28Xh3DBuZ Functions added to get the I2C bus number and reset I2C bus using FDT node. Signed-off-by: Rajeshwari Shinde Acked-by: Simon Glass --- 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. Chnages in V3: - peripheral id decoded based on interrupts. - removed compat id check in i2c_get_bus_num_fdt. 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 9bc4c7f..c270ff0 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,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 = 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_ */