From patchwork Thu Nov 29 07:09:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajeshwari Shinde X-Patchwork-Id: 13281 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 A5E0024251 for ; Thu, 29 Nov 2012 07:03:40 +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 5AD7BA18DC6 for ; Thu, 29 Nov 2012 07:03:40 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so9592492ieb.11 for ; Wed, 28 Nov 2012 23:03:40 -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=+pIzExX59e7Dsr6IEHNQiGD1Hl1x2tVsyRIGTZXcKWI=; b=GXW+KkQ2XhR8yYKAK7/CnIGge8E9o0AE4CWjcwc24l9Vlaw1cc6rY8YjDdvd4w/B4Q RnckpPAEKshqAQVMb+Lsygu7u2J3Qz09BThK3iY/U1cahU24zlWFxXoSn2MyoyyGlVBn 9qCnJWM/lLzHiCLEyKpPgubhlIxmZsITA61vmcHsLD1/k5H/3zcSbQkvgU4Aa5PM0/IE sxWJNbBYytHbhFuvCLOXD47a0JCBcqXX3uiacW2R6BowahSfNYEtpRJXASwW3ZC6ZzEQ nU0L4sjaCdGPcsYqqueWwA2CQAfDM+NxpHj1loMAqQtGAUpkX4e03SCPAf1jNmZjmbAv JzMg== Received: by 10.50.213.34 with SMTP id np2mr21890052igc.57.1354172620118; Wed, 28 Nov 2012 23:03:40 -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 n20csp802659igt; Wed, 28 Nov 2012 23:03:39 -0800 (PST) Received: by 10.68.230.105 with SMTP id sx9mr65878314pbc.44.1354172619309; Wed, 28 Nov 2012 23:03:39 -0800 (PST) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTP id f9si1205990paw.121.2012.11.28.23.03.38; Wed, 28 Nov 2012 23:03:39 -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 epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0ME800GM4M9TFPQ0@mailout1.samsung.com>; Thu, 29 Nov 2012 16:03:37 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.125]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 31.44.12699.9C807B05; Thu, 29 Nov 2012 16:03:37 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-f8-50b708c997ba Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id B0.44.12699.9C807B05; Thu, 29 Nov 2012 16:03:37 +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 <0ME800LB8M9M7580@mmp1.samsung.com>; Thu, 29 Nov 2012 16:03:37 +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 V4] I2C: Driver changes for FDT support Date: Thu, 29 Nov 2012 12:39:50 +0530 Message-id: <1354172991-1005-6-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1354172991-1005-1-git-send-email-rajeshwari.s@samsung.com> References: <1354172991-1005-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLLMWRmVeSWpSXmKPExsWyRsSkVvckx/YAg7k31S0err/JYjHl8BcW ByaPO9f2sAUwRnHZpKTmZJalFunbJXBlnDrazVQwQa3i/v1OpgbG+XJdjJwcEgImEis3NTFD 2GISF+6tZwOxhQSWMkpM+BTexcgBVnN5XmYXIxdQeBGjxOkPTewQNROZJFqmF4HYbAJGEltP TmMEsUUEJCR+9V8Fs5kFMiRuf1jCAjJHWMBaYmunD4jJIqAqsegqK0gFr4C7xPL/N9ggLlCQ ODb1K1icU8BD4kzDN6hr3CWm3bkONpFFQEDi2+RDLBCXyUpsOsAMcpmEwG02iStT21gg5khK HFxxg2UCo/ACRoZVjKKpBckFxUnpuUZ6xYm5xaV56XrJ+bmbGIFhePrfM+kdjKsaLA4xCnAw KvHwbrTcFiDEmlhWXJl7iFGCg1lJhFfzD1CINyWxsiq1KD++qDQntfgQow/QJROZpUST84Ex klcSb2hsYm5qbGppZGRmaopDWEmct9kjJUBIID2xJDU7NbUgtQhmHBMHp1QDo/1Ny5vxqctf 1ibfW1i6vME4dUl9flbuKoY3HrmnskOsJp+JufbMa8U6r3/v5q7IZO6zuzQtxrrwoYOS9eOc euu5efyTMpIb2ds5l0rH7M4Tu1wgd1RheoZYXPjP0gnhXVfzVxrPeDHnLkdxw0+3+7OW1k07 VBJz5HKgd3FocO8iy79ZJfpXlViKMxINtZiLihMBxEFy+3ACAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeLIzCtJLcpLzFFi42I5/e+xgO5Jju0BBq+2yVg8XH+TxWLK4S8s Dkwed67tYQtgjGpgtMlITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw1DW0tDBXUshLzE21VXLx CdB1y8wBmq2kUJaYUwoUCkgsLlbSt8M0ITTETdcCpjFC1zckCK7HyAANJKxhzDh1tJupYIJa xf37nUwNjPPluhg5OCQETCQuz8vsYuQEMsUkLtxbz9bFyMUhJLCIUeL0hyZ2kISQwEQmiZbp RSA2m4CRxNaT0xhBbBEBCYlf/VfBbGaBDInbH5awgMwUFrCW2NrpA2KyCKhKLLrKClLBK+Au sfz/DTaIVQoSx6Z+BYtzCnhInGn4xgaxyV1i2p3rjBMYeRcwMqxiFE0tSC4oTkrPNdIrTswt Ls1L10vOz93ECA7zZ9I7GFc1WBxiFOBgVOLh3Wi5LUCINbGsuDL3EKMEB7OSCK/mH6AQb0pi ZVVqUX58UWlOavEhRh+goyYyS4km5wNjMK8k3tDYxNzU2NTSxMLEzBKHsJI4b7NHSoCQQHpi SWp2ampBahHMOCYOTqkGxo3es65KLJRMnu15nr22ydNgfm3ZgV5LtdK7lxcK7zJe/rXybwOv u+dLa6v0ndvesHFo20X2nd/4iXtBTB7Dpfo9exyLL8c+eZvtetlr/s7lddPXz8n4J55z7HO9 5pr02/FXi6OdlqqrvI08fi3TdkpAyCrTMMHAB+VP5K8tWjrtK1P9weTb9UosxRmJhlrMRcWJ APO0fH+gAgAA X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQnmBIOc9/ssE1wVDffju2T6SFtRcuHBxvYVobZPoJP+JyE0VGnXmP63CRBgVH6eAmX0nnqe 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 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. Changes in V4: - Renamed decode_periph_id to pinmux_decode_periph_id. 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..94a093e 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 = 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_ */