From patchwork Tue Apr 30 04:47:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuanhua Han X-Patchwork-Id: 10922819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B710E933 for ; Tue, 30 Apr 2019 04:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A32BF279E0 for ; Tue, 30 Apr 2019 04:45:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95EB828898; Tue, 30 Apr 2019 04:45:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 245FA279E0 for ; Tue, 30 Apr 2019 04:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=HJMTSPcIai8Vq5uqxU1CCqPJwNUtMpimhC3IdGgl6BU=; b=MnL XxRRLGeOMzhe13bnuKeEWYc21T6BimegLrOF1YlOZYZecgJqP8n5z4vKeSaPd31QDblrwEhdnbVcH ma7EGguEql8dmbuHGQdDI+YygplrenaCdu8ShInlw6zxPX/rvB6oUxdSpLBi1/rz1136TzCjlowWV 4yeLI2sM6AZSJxrLLY/OctRVdVu69eMHPKCjIZw9imRRSV+ARkJGmnICt7M2Ovm89Vknjxs949Yzd Y3glRsYKtRCD46ghhGXjVW4M8OV8GhImtEo6ptiMr2+aNceiAxkO33Uld3Aw6UHT2LUlWYPpg/T+g ekf5wrZ9zjCPcnOiCVm9XUN/ugGjMWg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hLKeQ-0007dL-Gg; Tue, 30 Apr 2019 04:45:54 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hLKeM-0007cZ-HT for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2019 04:45:52 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 384E41A00B5; Tue, 30 Apr 2019 06:45:49 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 6648D1A0013; Tue, 30 Apr 2019 06:45:40 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 09031402D9; Tue, 30 Apr 2019 12:45:29 +0800 (SGT) From: Chuanhua Han To: shawnguo@kernel.org, s.hauer@pengutronix.de, leoyang.li@nxp.com, robh+dt@kernel.org, mark.rutland@arm.com Subject: [PATCH 1/2] i2c: imx: I2C Driver doesn't consider I2C_IPGCLK_SEL RCW bit when using ls1046a SoC Date: Tue, 30 Apr 2019 12:47:18 +0800 Message-Id: <20190430044719.30720-1-chuanhua.han@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190429_214550_857942_AC392BE0 X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, sumit.batra@nxp.com, eha@deif.com, Chuanhua Han , linux-kernel@vger.kernel.org, linux@rempel-privat.de, wsa+renesas@sang-engineering.com, linux-imx@nxp.com, u.kleine-koenig@pengutronix.de, l.stach@pengutronix.de, festevam@gmail.com, peda@axentia.se, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The current kernel driver does not consider I2C_IPGCLK_SEL (424 bit of RCW) in deciding i2c_clk_rate in function i2c_imx_set_clk() { 0 Platform clock/4, 1 Platform clock/2}. When using ls1046a SoC, this populates incorrect value in IBFD register if I2C_IPGCLK_SEL = 0, which generates half of the desired Clock. Therefore, if ls1046a SoC is used, we need to set the i2c clock according to the corresponding RCW. Signed-off-by: Sumit Batra Signed-off-by: Chuanhua Han --- drivers/i2c/busses/i2c-imx.c | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 422f1a445b55..7186cf3c7d24 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -45,6 +45,8 @@ #include #include #include +#include +#include /* This will be the driver name the kernel reports */ #define DRIVER_NAME "imx-i2c" @@ -109,6 +111,21 @@ #define I2C_PM_TIMEOUT 10 /* ms */ +/* 14-1 Since array index starts from 0 */ +#define RCW_I2C_IPGCLK_WORD (14 - 1) +/* + * Set mask for RCW 424th bit, reading from DCFG_CCSR RCW Status Registers + * Since this register in RM depicted as big endian, + * so consider 31st bit as LSB for creating the mask. + */ +#define RCW_I2C_IPGCLK_MASK 0x800000 +int i2c_ipgclk_sel = 1; + +static const struct soc_device_attribute ls1046a_soc[] = { + {.family = "QorIQ LS1046A"}, + { /* sentinel */ } +}; + /* * sorted list of clock divider, register value pairs * taken from table 26-5, p.26-9, Freescale i.MX @@ -304,6 +321,11 @@ static const struct platform_device_id imx_i2c_devtype[] = { }; MODULE_DEVICE_TABLE(platform, imx_i2c_devtype); +static const struct of_device_id guts_device_ids[] = { + { .compatible = "fsl,qoriq-device-config", }, + {} +}; + static const struct of_device_id i2c_imx_dt_ids[] = { { .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, }, { .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, }, @@ -533,6 +555,9 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, unsigned int div; int i; + if (!i2c_ipgclk_sel) + i2c_clk_rate = i2c_clk_rate / 2; + /* Divider value calculation */ if (i2c_imx->cur_clk == i2c_clk_rate) return; @@ -551,6 +576,10 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, /* Store divider value */ i2c_imx->ifdr = i2c_clk_div[i].val; + pr_alert("[%s] CLK Rate=%u Bitrate =%u Div =%u Value =%d\n", + __func__, i2c_clk_rate, i2c_imx->bitrate, + div, i2c_clk_div[i].val); + /* * There dummy delay is calculated. * It should be about one I2C clock period long. @@ -1116,6 +1145,9 @@ static int i2c_imx_probe(struct platform_device *pdev) int irq, ret; dma_addr_t phy_addr; u32 mul_value; + struct device_node *guts_node; + static struct ccsr_guts __iomem *guts_regs; + u32 rcw_reg; dev_dbg(&pdev->dev, "<%s>\n", __func__); @@ -1135,6 +1167,38 @@ static int i2c_imx_probe(struct platform_device *pdev) if (!i2c_imx) return -ENOMEM; + if (soc_device_match(ls1046a_soc)) { + /* + * Make device node for GUTS/DCFG (global utilities block) + * to read RCW. + */ + guts_node = of_find_matching_node(NULL, guts_device_ids); + if (!guts_node) { + dev_err(&pdev->dev, "Could not find GUTS node\n"); + return -ENODEV; + } + /* + * Memory (IO) MAP the DCFG registers(for RCW) to + * be used in kernel virtual address space. + */ + guts_regs = of_iomap(guts_node, 0); + of_node_put(guts_node); + if (!guts_regs) { + dev_err(&pdev->dev, "IOREMAP of GUTS node failed\n"); + return -ENOMEM; + } + /* Read rcw bit 424 (starting from 0) */ + rcw_reg = ioread32be(&guts_regs->rcwsr[RCW_I2C_IPGCLK_WORD]); + pr_alert("RCW REG[%d]=0x%x\n", RCW_I2C_IPGCLK_WORD, rcw_reg); + if (rcw_reg & RCW_I2C_IPGCLK_MASK) { + pr_alert("Div by 2 Case Detected in RCW\n"); + i2c_ipgclk_sel = 1; + } else { + pr_alert("Div by 4 Case Detected in RCW\n"); + i2c_ipgclk_sel = 0; + } + } + if (of_id) { i2c_imx->hwdata = of_id->data; ret = of_property_read_u32(pdev->dev.of_node, From patchwork Tue Apr 30 04:47:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuanhua Han X-Patchwork-Id: 10922821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF6F6933 for ; Tue, 30 Apr 2019 04:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE405279E0 for ; Tue, 30 Apr 2019 04:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B185F28898; Tue, 30 Apr 2019 04:46:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 680A7279E0 for ; Tue, 30 Apr 2019 04:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=diOHdssX+HkPkIA4ZVWY8cil6z4si8fYVJFCDBhgLM0=; b=hhXLKTvxd+IQjgCRXNRWSW7b/r mX56vCWX3w/t/ce8LmZ7JMqT/yygA7FxTHDU99opJ1xaGFYlBOTTTq0X7s2HlHnTIsVdxSQz5K2dq Y0v7cCRzPPvAKgu3JzlG2VMTQM3rAJeGRJeDtXMHfrAFnP3/Fo7zIdH16AG+oore01x+K1PnBbyyq MbdjtuljDVEhAuUr9jEwFTFP05r9MZmPFzq3+ikGPQPsOhhbQ48k1vLLQHgik22R3vQB+f7NkDzoT IGv8ufWMsxeXTrr/V5lkL3aEawtR/vu7BLzbcBUxX/pxA4VpgQqOvknvchmpGbADdP0a7qjCx1Q0i Q1r3D29Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hLKee-0007rs-Ba; Tue, 30 Apr 2019 04:46:08 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hLKeN-0007ck-PG for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2019 04:45:53 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 886691A00DF; Tue, 30 Apr 2019 06:45:50 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 2C5E71A0014; Tue, 30 Apr 2019 06:45:42 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id B9C7E4030F; Tue, 30 Apr 2019 12:45:31 +0800 (SGT) From: Chuanhua Han To: shawnguo@kernel.org, s.hauer@pengutronix.de, leoyang.li@nxp.com, robh+dt@kernel.org, mark.rutland@arm.com Subject: [PATCH 2/2] arm64: dts: fsl: ls1046a: Add the guts node in dts Date: Tue, 30 Apr 2019 12:47:19 +0800 Message-Id: <20190430044719.30720-2-chuanhua.han@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190430044719.30720-1-chuanhua.han@nxp.com> References: <20190430044719.30720-1-chuanhua.han@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190429_214551_954461_FD9A12AA X-CRM114-Status: UNSURE ( 7.04 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, sumit.batra@nxp.com, eha@deif.com, Chuanhua Han , linux-kernel@vger.kernel.org, linux@rempel-privat.de, wsa+renesas@sang-engineering.com, linux-imx@nxp.com, u.kleine-koenig@pengutronix.de, l.stach@pengutronix.de, festevam@gmail.com, peda@axentia.se, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For NXP ls1046a SoC, the i2c clock needs to be configured with the appropriate bit of RCW, so we add the guts node (GUTS/DCFG global utilities block) for the driver to read. Signed-off-by: Sumit Batra Signed-off-by: Chuanhua Han --- arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi index 373310e4c0ea..f88599df18bb 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi @@ -205,6 +205,11 @@ status = "disabled"; }; + guts: global-utilities@1ee0000 { + compatible = "fsl,qoriq-device-config"; + reg = <0x0 0x1ee0000 0x0 0x1000>; + }; + qspi: spi@1550000 { compatible = "fsl,ls1021a-qspi"; #address-cells = <1>;