Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2658713pxj; Mon, 14 Jun 2021 04:14:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWqXptGQynnK+PZ9CQtGhx7VKQv963+ag7S6C4nGjCQiTOzcAO+8aCIACeRkQjSDyG3LUG X-Received: by 2002:a17:906:e2c7:: with SMTP id gr7mr14537534ejb.20.1623669270401; Mon, 14 Jun 2021 04:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623669270; cv=none; d=google.com; s=arc-20160816; b=PlYo//eDxyDJnFsu7CbUZxZI+FmgQxnp/liQ2WgLo+49h5slcouPj5MOuqJwKpTr+f GnLN6YmGhjmS7oGKneYSNsajGMPV+To1SsZAHYeyfIUuJms8tI00Ns5jFmjbRuKrHNQ6 6lfPMGPuBuTOeh7egwkgE+XxhRZyNLarK3xSxxahve5TqCzEFO6hA8Ou2s2zW2s7Y6mp UrArNx7oeopND2lYQAzcg+ZUQyXH8Vl7IgL9NOweKWK3CB+y8DD6H7+flc2oWMDKztIS U0GT5y1vaPkUPeX6Be7iZwbUv8Kjxz/z96uHTTWZ47SVshvHDbWq5l3f85+aFp8aiaTc NNfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=13yi1tvNO8+VXhYXHbr5borKJEGnb7zPwAamPdgn+MY=; b=R6E5/zc2ibo7WBxXSnzOxWQy3phexOnop0Jh2G2KU+VpFyQx6ajwv/Bkk86Ronsz10 xmi8vHoQGhZaIKIRMC1COoIXhPI9yNoOliMi75GxYug7bh0hDseeAEnfISQo4qREdLVW zfKb/R3ND9YV5elx2L8ut7JiHA5DU2NJLeeUL7kbdminjLhkQoyZBmB3Xio8kYUH0+Oo dixwVnY6UhfxzoQqxDu+00x95xfKgx4zLhlmGRwnsXOy5DoPkHg7uezTjkaiWGhnABvq eScRjIu2x1FrZnVH/Hwv82DRNnB0O+9vBc/qiii4LVF4m3a6tPj5mjhpCEdVrIy4YDu7 25tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YnZCg3gc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx24si11650256ejc.72.2021.06.14.04.14.07; Mon, 14 Jun 2021 04:14:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YnZCg3gc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234681AbhFNLPU (ORCPT + 99 others); Mon, 14 Jun 2021 07:15:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:39216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234738AbhFNLDI (ORCPT ); Mon, 14 Jun 2021 07:03:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 84AE36143D; Mon, 14 Jun 2021 10:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667453; bh=tyn97TXx1BX8TXUEh7mwRv4SbFUY+HG02nTqWPv0ptI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YnZCg3gckEFedxyJ8rUNb9XYA3HdC2rbRICL7hXFEdA7P38dfMXPqMtYWa2BBwqAN HXWeBckdQqx/QeGt178KuRIGT4i67bzRoMMz5vS8Ern1E+8zKvA52qNSL+WobTuO+4 KLoSQiUmEmkxqCg+odMJnFcTokInNPmieY1/D3O4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Packham , Wolfram Sang , Sasha Levin Subject: [PATCH 5.10 044/131] i2c: mpc: implement erratum A-004447 workaround Date: Mon, 14 Jun 2021 12:26:45 +0200 Message-Id: <20210614102654.515868216@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chris Packham [ Upstream commit 8f0cdec8b5fd94135d643662506ee94ae9e98785 ] The P2040/P2041 has an erratum where the normal i2c recovery mechanism does not work. Implement the alternative recovery mechanism documented in the P2040 Chip Errata Rev Q. Signed-off-by: Chris Packham Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-mpc.c | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 6a0d55e9e8e3..af349661fd76 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -49,6 +50,7 @@ #define CCR_MTX 0x10 #define CCR_TXAK 0x08 #define CCR_RSTA 0x04 +#define CCR_RSVD 0x02 #define CSR_MCF 0x80 #define CSR_MAAS 0x40 @@ -70,6 +72,7 @@ struct mpc_i2c { u8 fdr, dfsrr; #endif struct clk *clk_per; + bool has_errata_A004447; }; struct mpc_i2c_divider { @@ -176,6 +179,75 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) return 0; } +static int i2c_mpc_wait_sr(struct mpc_i2c *i2c, int mask) +{ + void __iomem *addr = i2c->base + MPC_I2C_SR; + u8 val; + + return readb_poll_timeout(addr, val, val & mask, 0, 100); +} + +/* + * Workaround for Erratum A004447. From the P2040CE Rev Q + * + * 1. Set up the frequency divider and sampling rate. + * 2. I2CCR - a0h + * 3. Poll for I2CSR[MBB] to get set. + * 4. If I2CSR[MAL] is set (an indication that SDA is stuck low), then go to + * step 5. If MAL is not set, then go to step 13. + * 5. I2CCR - 00h + * 6. I2CCR - 22h + * 7. I2CCR - a2h + * 8. Poll for I2CSR[MBB] to get set. + * 9. Issue read to I2CDR. + * 10. Poll for I2CSR[MIF] to be set. + * 11. I2CCR - 82h + * 12. Workaround complete. Skip the next steps. + * 13. Issue read to I2CDR. + * 14. Poll for I2CSR[MIF] to be set. + * 15. I2CCR - 80h + */ +static void mpc_i2c_fixup_A004447(struct mpc_i2c *i2c) +{ + int ret; + u32 val; + + writeccr(i2c, CCR_MEN | CCR_MSTA); + ret = i2c_mpc_wait_sr(i2c, CSR_MBB); + if (ret) { + dev_err(i2c->dev, "timeout waiting for CSR_MBB\n"); + return; + } + + val = readb(i2c->base + MPC_I2C_SR); + + if (val & CSR_MAL) { + writeccr(i2c, 0x00); + writeccr(i2c, CCR_MSTA | CCR_RSVD); + writeccr(i2c, CCR_MEN | CCR_MSTA | CCR_RSVD); + ret = i2c_mpc_wait_sr(i2c, CSR_MBB); + if (ret) { + dev_err(i2c->dev, "timeout waiting for CSR_MBB\n"); + return; + } + val = readb(i2c->base + MPC_I2C_DR); + ret = i2c_mpc_wait_sr(i2c, CSR_MIF); + if (ret) { + dev_err(i2c->dev, "timeout waiting for CSR_MIF\n"); + return; + } + writeccr(i2c, CCR_MEN | CCR_RSVD); + } else { + val = readb(i2c->base + MPC_I2C_DR); + ret = i2c_mpc_wait_sr(i2c, CSR_MIF); + if (ret) { + dev_err(i2c->dev, "timeout waiting for CSR_MIF\n"); + return; + } + writeccr(i2c, CCR_MEN); + } +} + #if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, @@ -641,7 +713,10 @@ static int fsl_i2c_bus_recovery(struct i2c_adapter *adap) { struct mpc_i2c *i2c = i2c_get_adapdata(adap); - mpc_i2c_fixup(i2c); + if (i2c->has_errata_A004447) + mpc_i2c_fixup_A004447(i2c); + else + mpc_i2c_fixup(i2c); return 0; } @@ -745,6 +820,8 @@ static int fsl_i2c_probe(struct platform_device *op) dev_info(i2c->dev, "timeout %u us\n", mpc_ops.timeout * 1000000 / HZ); platform_set_drvdata(op, i2c); + if (of_property_read_bool(op->dev.of_node, "fsl,i2c-erratum-a004447")) + i2c->has_errata_A004447 = true; i2c->adap = mpc_ops; of_address_to_resource(op->dev.of_node, 0, &res); -- 2.30.2