From patchwork Mon May 28 12:25:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 921508 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="NQimBw6W"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40vbyh3kgKz9s0q for ; Mon, 28 May 2018 22:39:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F35D5C21D9A; Mon, 28 May 2018 12:34:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAD_ENC_HEADER, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1C641C21E47; Mon, 28 May 2018 12:29:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BA028C21DD9; Mon, 28 May 2018 12:22:57 +0000 (UTC) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0054.outbound.protection.outlook.com [104.47.0.54]) by lists.denx.de (Postfix) with ESMTPS id E5FAAC21E3A for ; Mon, 28 May 2018 12:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pOhIrpErup03srnW0YERFtW4HBpHMZxe8Bjfd/cafoY=; b=NQimBw6WW6WvjaDNqeJAMryI7b0/Pnz/7b63E2sxvxKyYJb944w1d0V0rbkkNK5CYMLsYsB3xhDrPqSwmsnbQxfMhDV+nFmkkDYO0YT+c8naXQtptt36zxNyjzeK5wmvxE4Dvp1w3vbYvX4XwLsHUiTxBCnQNlN36r55vDiooK4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peng.fan@nxp.com; Received: from linux-u7w5.ap.freescale.net.net (92.121.68.129) by VI1PR04MB3006.eurprd04.prod.outlook.com (2603:10a6:802:9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Mon, 28 May 2018 12:22:48 +0000 From: Peng Fan To: sbabic@denx.de, fabio.estevam@nxp.com Date: Mon, 28 May 2018 20:25:11 +0800 Message-Id: <20180528122526.20597-27-peng.fan@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180528122526.20597-1-peng.fan@nxp.com> References: <20180528122526.20597-1-peng.fan@nxp.com> MIME-Version: 1.0 X-Originating-IP: [92.121.68.129] X-ClientProxiedBy: HK2PR02CA0175.apcprd02.prod.outlook.com (2603:1096:201:21::11) To VI1PR04MB3006.eurprd04.prod.outlook.com (2603:10a6:802:9::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR04MB3006; X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB3006; 3:q1UOSI1Lzvbj6e8EbtJm7awW2pOjpOoOxPRmOrhw72ptnZjXrl21uFKnsJjv1sJvPamQZVeLXvcnQ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CecrWUqRzMICdmaEsiAzzfPEcM8+pu0fOtLh0IAWaeo4gLH6Bco+cTSjGDCu/lMU1g0GzeLX8PN15mmbXPmDdkesCn5HDsVsh4fBSXqy7p+wplWVzfeGK8m0+0pm/kQn6UtJ8IJS3PE6DzHsmyFLLQlaScQS3jdVDW0TkMrWZz2iYM950obEhOHnl2SDUZX4/32+W346K8/cvjVLU5qAWV8uAiYfalze+640gDV8YnJBNPibMiuqq6iiVrxX3jOU7Hhy5gexlKR+o0Z; 4:RwVhoBSeiXo8pRITYEGRMbGIUyqnR0TBp0LSBfsfWqpOip4fOFNyeZXVtBhbWtiXzim34IsTxt88ZLheCiK7uOtewo5WTgnNypfTGc7RXUCUuxQVJ+KK3jnjCMX9fDj48PVeYRbXxqYAzs1PEZt29MCKCZZuxVHG8hm0iTafjnnJ64BbIQ12s2/P6i2EW/PAJMqWYjytuEk2W8f4xZgAOx3ahDqnu+kAzKyYqCYv6za5CCgEMgDNLXH9Gyw6XAkd2OQALz5HAqXDgcl4NwHSMUu3JVD22OcAmS1aBZLvyZbgSo2neu9aWl9HhojOqsT/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:VI1PR04MB3006; BCL:0; PCL:0; RULEID:; SRVR:VI1PR04MB3006; X-Forefront-PRVS: 06860EDC7B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(396003)(39860400002)(376002)(346002)(199004)(189003)(36756003)(97736004)(6636002)(6666003)(68736007)(86362001)(8676002)(44832011)(8936002)(81166006)(81156014)(47776003)(11346002)(956004)(2616005)(476003)(446003)(25786009)(486006)(48376002)(106356001)(105586002)(186003)(50466002)(16526019)(2906002)(6512007)(53936002)(1076002)(66066001)(26005)(51416003)(478600001)(305945005)(54906003)(50226002)(6486002)(5660300001)(6116002)(76176011)(3846002)(16586007)(52116002)(6506007)(4326008)(316002)(7736002)(386003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB3006; H:linux-u7w5.ap.freescale.net.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR04MB3006; 23:dl7p5uB5FY4QB7NusuZuSdFCpGUxew5u6bO0aRrfF?= aSoDVCNdWgvXky4osxcmClrtm/QMcaBb1Kmlhj/dFhrygISbmOzyfnY06M/jUh23KDWsEi7OIpMsdUVri5EAfwPPSgAcox30aiHH3fl0PWuPUVy7XID9k5n2QyhUacOJqfnRkpG2LS1OzXN6r7GgGt/hL3n3PlMfH7ZiXinOYDkqH5WIXkuDqLwpPqoL4MUm7hQmSsnG3gKwdsO/4FBH0QFDQt0arPL5C+gPRszR+f8dKPN9OPTv2vE28+aM+MLCH/C/2QhExNRr0JX6uR17fqUZnsN6ni+cW1UHOu48hXvDMSf2D1u59x7B0Cs0nIBx9kanb+OcB97I+cqQ6vg2mJ5d449o1q6nL0hwf1WpmB9xxeVzsqZKesJs3w4wYMLpCT1LgH7g1tLPFgLHP3bCPLk7743ysNF+x0tWjN/yfhRxa26PP8BO/90LY5yfIWF/3p6eZTLtdS0SeWFMa/7tWDmApVUrPe4JchPWydKKgxfGUJpeimYqyq54qLbXMgNihbHTpi+ptSI2Nb4fjGQLJgGhPI1yZryuG41gXPhUG4Fdr37lTDFvJn18eZbKvW72TKg4GrriVcMx6b6Yq9kgwFqiLG4WeXXJXHI4Au8lMQB6btR2HIstD0oyVWDy1G6Uy7w6J9WTR9Q7CYxhA7N9drtooYnJDw5toPzV4HfIy8XjQ1tWxsdwdDZSPeaaQXMEc4EvbW1LMGaErqpFup5RhlA40fCqEMSJuwKS9m45RVetEsUDGyt65146CMbHpMGXNS1xTeV0+owiQPzaGTlpPQgsxwgDZtYyEnlCaJQLayoy11CJ8A4It6R3z/IliBcZ9fk+dX+9YBSE0h0RhgTKJ9pnAI/MvQjXYRzqo/AnSygU8w40T2+HnBB/J+ziPDDVxfjTD/APcwkBfkHvLKNBWAntlp21s2AgYNwCnY9hfTL7AQLNn661AQoHVUmwcc904r3kTmnTMObqOKvp2HZV6EEzPoU5NkEzhsCowQ7Hw03ICpBz3DkktsBDs0wVqJXxReDR07abcqStt2L4B7+FKavziXkQT+242FfIOIYQHAKva3oyW2v3SKVhI/lmM5VK+2tQQ+fJzehhdafU3oha8zZSygSexdhItGyk7EoIa/0iY0daRIuHCdhlE7xgMfAFd3mz1VUj1TIJzCvVhd/J/J/HP9NJMOHdIgc5TZ0URGTEj/UJdKnJyNNqYP+gfjQ+0U= X-Microsoft-Antispam-Message-Info: xi3apcU1J+r6bzAfgJOh/IBr1cV3KJqE05NwQyvfAhZ05KeGuZkCakmGdXtChhudiNzbytzmhOU2KOWtJYIrAlWRgVuFVkeXueTax80WD7qlD7f7znVvHwFZ/gjPsSkKXj/ArB0ITW5kzAGLFtNxvhnQhjQcjCAKHYtW4KtE59r2cx0+bxNWvsn9TMl2i++o X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB3006; 6:5pTZbrWDgqdD7wg6h04FdXogErRfA/TL/a8KXvOpyVrcO3TzWQC+cr4KffYWKoei40OGhRtNxgEfiQLWV2GAemzgBMRNCb3NssIb0wDMnbyJYAIgUm7eAYwqBxtVlTcrULhqFaODR7e06XBrMyWNOoOhJ2qgCQQhaMLIrZjq/idKWJMtG/zd3e/EJchdajOj1AhpGnGdGKKALySuwwIxcHdEEz93qeLqAmnan/Y4T1//FXA744UkxtCyIB84iYJQjfVZ3p70kACxktVwX1AP2jsmUcqlSudYbIJIMhtN/Qi9wg15w6L+Tn+1hl1uPAjJmr3pDEUaC3eiuA2PpghRQzeQAcjzxiWylQq6Ul3x/2IqREhiy+emaLJPRWHifrIcn5vPc7a0Z/d5cx8LVMGZItl5tLA8dXyNWkf+r2pSScNcALtsuc+AU0gHTWa7ej2eOst4nnL6ySVZygp7aRlahw==; 5:OP6dfQIrw33xNdTrNhZ7LKb8oRvOr9M7PIltP8BPVgK9SeBljnmk9EojjqoOfZ0VShpKcUC0tKzTv/mKQ+EFkfChr490PWCAd7IU0M2sVs+UILPNxFnZI5NCau87gFzzQB8EmjzLyi07QmP3eEtkF0DwudBoGlZoNIH4nQVe+YY=; 24:kmpAys5P2UlpjHFgDpxue2dGEkXSZ4dsEWkOYqh2ul6ef93AaZZHKGlgSA0qIdhBmPAE8OoFqcj1/UuWF110MRCnvleqoJO7hPD3yBHz8WA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB3006; 7:fxz09629bJPBTZqrzhXNMKlnzdGMud0+XLgzXOBmT1VbqxJDicVYhBU0cipvm4IvZeXTpn0XIbxa9CBJybL2141GrBJbP1WR35gqtvCf2Z85yBa0P9zzTcNyfSe90CttIGl4SeP8FzslMOmmLkrHs6HxUaCt7fcXRygwBbzQsHVL64eXG3aICvHS+DeTHfrFEcLGlPGGrpYWknpCF38Ebge7FuOKofktXoBoGh4yEqSODrKdRC3le93yQ2y8AKIX X-MS-Office365-Filtering-Correlation-Id: 2a17c6bf-34bd-4392-4611-08d5c495bada X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2018 12:22:48.4018 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a17c6bf-34bd-4392-4611-08d5c495bada X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB3006 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 26/41] lpi2c: Add bus busy error handling X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Ye Li When doing "i2c dev 4; i2c probe" with ENET daughter card connected on iMX8QXP MEK board, we met a i2c bus busy issue, that the BBF of lpi2c always show busy, but the master is idle, and stop is detected (SDF set). This patch addes a handling to re-init the lpi2c master for this case. Then the issue can be worked around. Signed-off-by: Ye Li Acked-by: Peng Fan Cc: Heiko Schocher Reviewed-by: Heiko Schocher --- drivers/i2c/imx_lpi2c.c | 53 +++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c index 585787a35c..ff07ca34aa 100644 --- a/drivers/i2c/imx_lpi2c.c +++ b/drivers/i2c/imx_lpi2c.c @@ -18,6 +18,8 @@ #define LPI2C_NACK_TOUT_MS 1 #define LPI2C_TIMEOUT_MS 100 +static int bus_i2c_init(struct udevice *bus, int speed); + /* Weak linked function for overridden by some SoC power function */ int __weak init_i2c_power(unsigned i2c_num) { @@ -91,8 +93,9 @@ static int bus_i2c_wait_for_tx_ready(struct imx_lpi2c_reg *regs) return result; } -static int bus_i2c_send(struct imx_lpi2c_reg *regs, u8 *txbuf, int len) +static int bus_i2c_send(struct udevice *bus, u8 *txbuf, int len) { + struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus); lpi2c_status_t result = LPI2C_SUCESS; /* empty tx */ @@ -111,8 +114,9 @@ static int bus_i2c_send(struct imx_lpi2c_reg *regs, u8 *txbuf, int len) return result; } -static int bus_i2c_receive(struct imx_lpi2c_reg *regs, u8 *rxbuf, int len) +static int bus_i2c_receive(struct udevice *bus, u8 *rxbuf, int len) { + struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus); lpi2c_status_t result = LPI2C_SUCESS; u32 val; ulong start_time = get_timer(0); @@ -153,15 +157,24 @@ static int bus_i2c_receive(struct imx_lpi2c_reg *regs, u8 *rxbuf, int len) return result; } -static int bus_i2c_start(struct imx_lpi2c_reg *regs, u8 addr, u8 dir) +static int bus_i2c_start(struct udevice *bus, u8 addr, u8 dir) { lpi2c_status_t result; + struct imx_lpi2c_reg *regs = + (struct imx_lpi2c_reg *)devfdt_get_addr(bus); u32 val; result = imx_lpci2c_check_busy_bus(regs); if (result) { debug("i2c: start check busy bus: 0x%x\n", result); - return result; + + /* Try to init the lpi2c then check the bus busy again */ + bus_i2c_init(bus, 100000); + result = imx_lpci2c_check_busy_bus(regs); + if (result) { + printf("i2c: Error check busy bus: 0x%x\n", result); + return result; + } } /* clear all status flags */ writel(0x7f00, ®s->msr); @@ -181,9 +194,11 @@ static int bus_i2c_start(struct imx_lpi2c_reg *regs, u8 addr, u8 dir) return result; } -static int bus_i2c_stop(struct imx_lpi2c_reg *regs) +static int bus_i2c_stop(struct udevice *bus) { lpi2c_status_t result; + struct imx_lpi2c_reg *regs = + (struct imx_lpi2c_reg *)devfdt_get_addr(bus); u32 status; ulong start_time; @@ -217,28 +232,28 @@ static int bus_i2c_stop(struct imx_lpi2c_reg *regs) return result; } -static int bus_i2c_read(struct imx_lpi2c_reg *regs, u32 chip, u8 *buf, int len) +static int bus_i2c_read(struct udevice *bus, u32 chip, u8 *buf, int len) { lpi2c_status_t result; - result = bus_i2c_start(regs, chip, 1); + result = bus_i2c_start(bus, chip, 1); if (result) return result; - result = bus_i2c_receive(regs, buf, len); + result = bus_i2c_receive(bus, buf, len); if (result) return result; return result; } -static int bus_i2c_write(struct imx_lpi2c_reg *regs, u32 chip, u8 *buf, int len) +static int bus_i2c_write(struct udevice *bus, u32 chip, u8 *buf, int len) { lpi2c_status_t result; - result = bus_i2c_start(regs, chip, 0); + result = bus_i2c_start(bus, chip, 0); if (result) return result; - result = bus_i2c_send(regs, buf, len); + result = bus_i2c_send(bus, buf, len); if (result) return result; @@ -353,18 +368,16 @@ static int bus_i2c_init(struct udevice *bus, int speed) static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip, u32 chip_flags) { - struct imx_lpi2c_reg *regs; lpi2c_status_t result; - regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus); - result = bus_i2c_start(regs, chip, 0); + result = bus_i2c_start(bus, chip, 0); if (result) { - bus_i2c_stop(regs); + bus_i2c_stop(bus); bus_i2c_init(bus, 100000); return result; } - result = bus_i2c_stop(regs); + result = bus_i2c_stop(bus); if (result) bus_i2c_init(bus, 100000); @@ -373,16 +386,14 @@ static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip, static int imx_lpi2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) { - struct imx_lpi2c_reg *regs; int ret = 0, ret_stop; - regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus); for (; nmsgs > 0; nmsgs--, msg++) { debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len); if (msg->flags & I2C_M_RD) - ret = bus_i2c_read(regs, msg->addr, msg->buf, msg->len); + ret = bus_i2c_read(bus, msg->addr, msg->buf, msg->len); else { - ret = bus_i2c_write(regs, msg->addr, msg->buf, + ret = bus_i2c_write(bus, msg->addr, msg->buf, msg->len); if (ret) break; @@ -392,7 +403,7 @@ static int imx_lpi2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) if (ret) debug("i2c_write: error sending\n"); - ret_stop = bus_i2c_stop(regs); + ret_stop = bus_i2c_stop(bus); if (ret_stop) debug("i2c_xfer: stop bus error\n");