From patchwork Tue Feb 11 02:50:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 3624671 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E6993BF418 for ; Tue, 11 Feb 2014 02:50:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DFBA0201F7 for ; Tue, 11 Feb 2014 02:50:25 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC1C9201F4 for ; Tue, 11 Feb 2014 02:50:24 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WD3QQ-0001LJ-1L; Tue, 11 Feb 2014 02:50:18 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WD3QN-00056G-Lf; Tue, 11 Feb 2014 02:50:15 +0000 Received: from co1ehsobe002.messaging.microsoft.com ([216.32.180.185] helo=co1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WD3QK-00055s-Gl for linux-arm-kernel@lists.infradead.org; Tue, 11 Feb 2014 02:50:13 +0000 Received: from mail156-co1-R.bigfish.com (10.243.78.246) by CO1EHSOBE020.bigfish.com (10.243.66.83) with Microsoft SMTP Server id 14.1.225.22; Tue, 11 Feb 2014 02:49:49 +0000 Received: from mail156-co1 (localhost [127.0.0.1]) by mail156-co1-R.bigfish.com (Postfix) with ESMTP id 884367A0ACF; Tue, 11 Feb 2014 02:49:49 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 3 X-BigFish: VS3(zcb8kzzz1f42h2148h208ch1ee6h1de0h1fdah2073h2146h1202h1e76h2189h1d1ah1d2ah21bch1fc6hzz1de098h8275dh1de097hz2dh87h2a8h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh2222h224fh1fb3h1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e23h1fe8h1ff5h2218h2216h226dh22d0h24afh2327h2336h2438h2461h2487h24d7h2516h2545h255eh1151h1155h) X-FB-DOMAIN-IP-MATCH: fail Received: from mail156-co1 (localhost.localdomain [127.0.0.1]) by mail156-co1 (MessageSwitch) id 1392086988370645_3565; Tue, 11 Feb 2014 02:49:48 +0000 (UTC) Received: from CO1EHSMHS029.bigfish.com (unknown [10.243.78.246]) by mail156-co1.bigfish.com (Postfix) with ESMTP id A8570AC0054; Tue, 11 Feb 2014 02:49:46 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO1EHSMHS029.bigfish.com (10.243.66.39) with Microsoft SMTP Server (TLS) id 14.16.227.3; Tue, 11 Feb 2014 02:49:41 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.3.158.2; Tue, 11 Feb 2014 02:49:38 +0000 Received: from S2101-09.ap.freescale.net ([10.192.185.43]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id s1B2nXVo002115; Mon, 10 Feb 2014 19:49:33 -0700 From: Shawn Guo To: Subject: [PATCH] bus: imx-weim: support weim-cs-gpr for imx6q-weim Date: Tue, 11 Feb 2014 10:50:11 +0800 Message-ID: <1392087011-31629-1-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-OriginatorOrg: sigmatel.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% X-FOPE-CONNECTOR: Id%0$Dn%FREESCALE.MAIL.ONMICROSOFT.COM$RO%1$TLS%0$FQDN%$TlsDn% X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140210_215012_699605_16F790E3 X-CRM114-Status: GOOD ( 18.89 ) X-Spam-Score: -0.7 (/) Cc: Huang Shijie , Philippe De Muyter , Shawn Guo , kernel@pengutronix.de, devicetree@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD,UNPARSEABLE_RELAY,UNRESOLVED_TEMPLATE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For imx6q-weim type of device, there might a WEIM CS space configuration register in General Purpose Register controller, e.g. IOMUXC_GPR1 on i.MX6Q. Depending on which configuration of the following 4 is chosen for given system, IOMUXC_GPR1[11:0] should be set up as 0x5, 0x1b, 0x4b or 0x249 correspondingly. CS0(128M) CS1(0M) CS2(0M) CS3(0M) CS0(64M) CS1(64M) CS2(0M) CS3(0M) CS0(64M) CS1(32M) CS2(32M) CS3(0M) CS0(32M) CS1(32M) CS2(32M) CS3(32M) The patch creates a table in the driver for above configurations, and detects which one is being used for the booting system by looking at 'ranges' property of WEIM node. Thus the WEIM CS GPR can be set up automatically at boot time. Signed-off-by: Shawn Guo --- Documentation/devicetree/bindings/bus/imx-weim.txt | 6 ++ drivers/bus/imx-weim.c | 83 ++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/Documentation/devicetree/bindings/bus/imx-weim.txt b/Documentation/devicetree/bindings/bus/imx-weim.txt index 0fd76c4..d114460f 100644 --- a/Documentation/devicetree/bindings/bus/imx-weim.txt +++ b/Documentation/devicetree/bindings/bus/imx-weim.txt @@ -19,6 +19,12 @@ Required properties: 0 +Optional properties: + + - fsl,weim-cs-gpr: Should be the phandle to the General Purpose Register + controller that contains WEIM CS GPR register, e.g. + IOMUXC_GPR1 on i.MX6Q. + Timing property for child nodes. It is mandatory, not optional. - fsl,weim-cs-timing: The timing array, contains timing values for the diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 3ef58c8..9c8a522 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include struct imx_weim_devtype { unsigned int cs_count; @@ -56,6 +59,83 @@ static const struct of_device_id weim_id_table[] = { }; MODULE_DEVICE_TABLE(of, weim_id_table); +struct imx6q_weim_gpr { + u32 cssize[4]; + u32 gprval; +}; + +static const struct imx6q_weim_gpr imx6q_weim_gpr_data[] __initconst = { + { + /* CS0(128M) CS1(0M) CS2(0M) CS3(0M) */ + .cssize = { 128, 0, 0, 0 }, + .gprval = 0x5, + }, { + /* CS0(64M) CS1(64M) CS2(0M) CS3(0M) */ + .cssize = { 64, 64, 0, 0 }, + .gprval = 0x1b, + }, { + /* CS0(64M) CS1(32M) CS2(32M) CS3(0M) */ + .cssize = { 64, 32, 32, 0 }, + .gprval = 0x4b, + }, { + /* CS0(64M) CS1(32M) CS2(32M) CS3(0M) */ + .cssize = { 32, 32, 32, 32 }, + .gprval = 0x249, + }, +}; + +static int __init imx6q_weim_gpr_setup(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + const struct property *prop; + struct regmap *gpr; + u32 cssize[4] = { 0, 0, 0, 0 }; + int len; + int ret; + int i; + + gpr = syscon_regmap_lookup_by_phandle(np, "fsl,weim-cs-gpr"); + if (IS_ERR(gpr)) { + dev_dbg(&pdev->dev, "No weim-cs-gpr to set up\n"); + return 0; + } + + prop = of_find_property(np, "ranges", &len); + if (prop == NULL) + return -ENOENT; + if (len % (sizeof(u32) * 4)) + return -EINVAL; + + for (i = 0; i < len / (sizeof(u32) * 4); i++) { + int cs; + /* read cs index */ + ret = of_property_read_u32_index(np, "ranges", i * 4, &cs); + if (ret) + return ret; + /* read cs size */ + ret = of_property_read_u32_index(np, "ranges", i * 4 + 3, + &cssize[cs]); + if (ret) + return ret; + /* turn to MB */ + cssize[cs] >>= 20; + } + + for (i = 0; i < ARRAY_SIZE(imx6q_weim_gpr_data); i++) { + ret = memcmp(cssize, imx6q_weim_gpr_data[i].cssize, + sizeof(cssize)); + if (ret == 0) { + /* Find it. Set up IOMUXC_GPR1[11:0] with the gprval. */ + regmap_update_bits(gpr, IOMUXC_GPR1, 0xfff, + imx6q_weim_gpr_data[i].gprval); + return 0; + } + } + + dev_err(&pdev->dev, "Invalid 'ranges' configuration\n"); + return -EINVAL; +} + /* Parse and set the timing for this device. */ static int __init weim_timing_setup(struct device_node *np, void __iomem *base, const struct imx_weim_devtype *devtype) @@ -92,6 +172,9 @@ static int __init weim_parse_dt(struct platform_device *pdev, struct device_node *child; int ret; + if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx6q-weim")) + imx6q_weim_gpr_setup(pdev); + for_each_child_of_node(pdev->dev.of_node, child) { if (!child->name) continue;