From patchwork Fri Dec 14 11:56: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: 13571 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 42B3623FC0 for ; Fri, 14 Dec 2012 11:54:06 +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 D057CA19569 for ; Fri, 14 Dec 2012 11:54:05 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so5705383ieb.11 for ; Fri, 14 Dec 2012 03:54:05 -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=CRnvHIRflWKX7enD/KoWm274bThWW8ivUcm7UDu9KNw=; b=QLPppLJujfryxj4IFjSG6gTm+853PG5pJMKua+2BBYPCzqMoKZG/lrDwtX3unVYSii /joE5gwBzKzFMJg8gp03CYpGLfdEtrLgpEPVTesBQiGd+ucfS02vd1ncXkt+VJNJUjUc WORnzfgQimVrzmsamIdXGz7fQCTO9Ji+KEyCir++WEtljCdsbY6UbWLCSt7evtDevNfO wfxAO2dDbNmNATifXHN+4D8oeNl5KxAHScPuza5nOhZyGvBuPjr1/aNhguYSiv5+4ENl 5QAXkeRoqGzUScEAeM5aGZwBDrCqboUg7HtJNdkLBlp68Q7xb/gzQkLCeohuh3KBHgnS zlKA== Received: by 10.50.173.34 with SMTP id bh2mr1222656igc.70.1355486045299; Fri, 14 Dec 2012 03:54:05 -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 n20csp67252igt; Fri, 14 Dec 2012 03:54:04 -0800 (PST) Received: by 10.66.73.165 with SMTP id m5mr15048533pav.78.1355486044245; Fri, 14 Dec 2012 03:54:04 -0800 (PST) Received: from mailout4.samsung.com (mailout4.samsung.com. [203.254.224.34]) by mx.google.com with ESMTP id pj1si4649120pbc.342.2012.12.14.03.54.03; Fri, 14 Dec 2012 03:54:04 -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 epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MF000AK3RPT8I40@mailout4.samsung.com>; Fri, 14 Dec 2012 20:54:03 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.126]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id AC.44.01231.A531BC05; Fri, 14 Dec 2012 20:54:02 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-f7-50cb135af6fa Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 5C.44.01231.A531BC05; Fri, 14 Dec 2012 20:54:02 +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 <0MF000GYFRKI4870@mmp2.samsung.com>; Fri, 14 Dec 2012 20:54:02 +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] I2C: Driver changes for FDT support Date: Fri, 14 Dec 2012 17:26:18 +0530 Message-id: <1355486189-432-5-git-send-email-rajeshwari.s@samsung.com> X-Mailer: git-send-email 1.7.4.4 In-reply-to: <1355486189-432-1-git-send-email-rajeshwari.s@samsung.com> References: <1355486189-432-1-git-send-email-rajeshwari.s@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRmVeSWpSXmKPExsWyRsSkTjdK+HSAwcGHVhYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgyDj/YwV5wX7ni69tPbA2MJ2W6GDk5JARMJF7Mv8ME YYtJXLi3nq2LkYtDSGApo8SE5ScYYYrWdP5ghkhMZ5TYfHcplDORSWLGoedsIFVsAkYSW09O A+sQEZCQ+NV/FcxmFoiReL3/B1iNsICVxLKFIM2cHCwCqhKzjrSC2bwCbhInW+6zQ2xTkDg2 9SsriM0p4C5x8s09sBohoJoVPcvYIHoFJL5NPsTSxcgBVC8rsekA2D0SAtfZJN7cXs4GMUdS 4uCKGywTGIUXMDKsYhRNLUguKE5KzzXUK07MLS7NS9dLzs/dxAgMyNP/nkntYFzZYHGIUYCD UYmH96PQqQAh1sSy4srcQ4wSHMxKIrySR4BCvCmJlVWpRfnxRaU5qcWHGH2ALpnILCWanA+M lrySeENjE3NTY1NLIyMzU1McwkrivM0eKQFCAumJJanZqakFqUUw45g4OKUaGMPVKg68c7op Ol3eb+XdaK4JPAsqe73luW3epVmu3Jp63VnEqPtP5IGNU3XcZxT2rT4o7b19UsnWLecKp222 KUu15BW5bper2/uxgdnt35ZLKkpL0v01GbifTj9zv+2Y+pQXSqdKfsyxOWifbMWRYB8U5n9K tfUvF8OE+Lt3r3UKL8lmKLh3V4mlOCPRUIu5qDgRAFWB5D51AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRmVeSWpSXmKPExsVy+t9jQd0o4dMBBj2TdC0err/JYjHl8BcW ByaPO9f2sAUwRjUw2mSkJqakFimk5iXnp2TmpdsqeQfHO8ebmhkY6hpaWpgrKeQl5qbaKrn4 BOi6ZeYAzVZSKEvMKQUKBSQWFyvp22GaEBripmsB0xih6xsSBNdjZIAGEtYwZhx+sIO94L5y xde3n9gaGE/KdDFyckgImEis6fzBDGGLSVy4t56ti5GLQ0hgOqPE5rtLmSGciUwSMw49ZwOp YhMwkth6chojiC0iICHxq/8qmM0sECPxev8PsBphASuJZQuXgk1lEVCVmHWkFczmFXCTONly nx1im4LEsalfWUFsTgF3iZNv7oHVCAHVrOhZxjaBkXcBI8MqRtHUguSC4qT0XEO94sTc4tK8 dL3k/NxNjOBwfya1g3Flg8UhRgEORiUe3o9CpwKEWBPLiitzDzFKcDArifBKHgEK8aYkVlal FuXHF5XmpBYfYvQBumois5Rocj4wFvNK4g2NTcxNjU0tTSxMzCxxCCuJ8zZ7pAQICaQnlqRm p6YWpBbBjGPi4JRqYDzevvT2Yr5Fpt+rXTZovbC75XNishbnlU071meGrLkQlPSytV6m5+SU dKmLDjPldc+d85mS26n6r663Z/9JkVz+bhNXxxNd4j78ajwdq+Y8PF5VNSFGep17xov4J88v sOu/POTs1LFr/bu6871e1Uuu7LF4s81tWYbgcXsTabfD+i1W+ll3bZVYijMSDbWYi4oTAUK3 U9ikAgAA X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQnBWLlJeJ1y5QnuDJYHbWV5vBOowYKCxbKtuO6RhZQjByHW1HMKDH//9hbEkl15AUH8AyzA 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 V1: -Rebased on latest u-boot-samsung 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_ */