Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3548365pxb; Mon, 24 Jan 2022 11:58:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzn6/ICBudZABLJs+KG6vWvQVln3u4j1P0rdErPGgD/CeOk/LQBfi51k7w4iQgP5qqH7R16 X-Received: by 2002:a05:6a00:228c:b0:4c3:40a:74c6 with SMTP id f12-20020a056a00228c00b004c3040a74c6mr15432193pfe.32.1643054314028; Mon, 24 Jan 2022 11:58:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054314; cv=none; d=google.com; s=arc-20160816; b=LjGzf5IJHl6xH1PbKea82c+Nd3i4AvwSI8V6xvTM2H6/PCBVC1/nytylfZHQHgl87D +ln1X9hxmBOjQ0JM1YlZlAoKbg10SSTXEfLe+N/4wgmKFosKUmHxffSvcewvpb9fcqET yoQw3NlF7EPtvF77ysavtQv0G9oCvLxqC8JAILASGVBIYZH7YBQgA4ymmGHl+Rx4BCo1 7Yg60T+LeM0BOtmGzlevhFei5eEERNVB/umea/LOSBRsqmjUeMzUb8R+emEMpm5+rvv7 9/yZ+X90+EHWUgjyw1jSU9JEji9EwIr6+H7hxv+7DvlzuKa1YY7mclj2Guj7I2MLh/M4 aNqg== 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=Lx8XLojAz+lvgHjhEfSQbp61yiXB0VFQE0V075J9tKg=; b=oyT0Z39ygzA4Lmq4T2gXgVLev80J1ifBAyi3nv39A/W/UOgN9otCo6k/kwCEdQ+e6z ZZ+UIDC4g2UjYWva9v7dxXuREhtSKwvV2lJOadbOmTE58/0Vh1vbJqPbBKnxnXQooaDW oIHL0ty+0JnRF2YppPr6wsumxaQU9dTR8Nmihwi3OJmrQHUfYh70VdelnSTD7kYaXieP epbKs73UXbg3tgy10r2wOr623HMVyDpJqbK8TRiB0S8oit0zvGCEYOfoTkdc54xmDBwq 9lafohw758XDqd09/YMMQ+teqfDOQCChf5MFK9UoKKZ8rJs2XxGIdxpyPM86XsEIErIm 4I1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gk3BE7J3; 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 t189si7010875pgd.166.2022.01.24.11.58.20; Mon, 24 Jan 2022 11:58:34 -0800 (PST) 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=gk3BE7J3; 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 S1343888AbiAXS4E (ORCPT + 99 others); Mon, 24 Jan 2022 13:56:04 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:53188 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344233AbiAXSyB (ORCPT ); Mon, 24 Jan 2022 13:54:01 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4986E61507; Mon, 24 Jan 2022 18:54:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B35BC340E5; Mon, 24 Jan 2022 18:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050440; bh=P8JodIRX2uzjywT3FD6+DpyuTrOHA3GSKST3Iwdgot4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gk3BE7J3Qp7aXxCQgrXnMZg1iEG78agJP06QMFsRB1RrCMa9sk+2kSADFy07yHF1T FyoBfbMYWbbjnTRLKxfK31hZEIlT/bbwNnwgOiwSwREv2qZB0bM9yzhfXIv2VYEtDu H4AQU2qY5pP58fljuWTRdG6wtwt4MDlEPVRLh+gk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joakim Tjernlund , Scott Wood , Wolfram Sang , Sasha Levin Subject: [PATCH 4.4 090/114] i2c: mpc: Correct I2C reset procedure Date: Mon, 24 Jan 2022 19:43:05 +0100 Message-Id: <20220124183929.891467756@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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: Joakim Tjernlund [ Upstream commit ebe82cf92cd4825c3029434cabfcd2f1780e64be ] Current I2C reset procedure is broken in two ways: 1) It only generate 1 START instead of 9 STARTs and STOP. 2) It leaves the bus Busy so every I2C xfer after the first fixup calls the reset routine again, for every xfer there after. This fixes both errors. Signed-off-by: Joakim Tjernlund Acked-by: Scott Wood Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-mpc.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 2e083a71c2215..988ea9df6654c 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -107,23 +107,30 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id) /* Sometimes 9th clock pulse isn't generated, and slave doesn't release * the bus, because it wants to send ACK. * Following sequence of enabling/disabling and sending start/stop generates - * the 9 pulses, so it's all OK. + * the 9 pulses, each with a START then ending with STOP, so it's all OK. */ static void mpc_i2c_fixup(struct mpc_i2c *i2c) { int k; - u32 delay_val = 1000000 / i2c->real_clk + 1; - - if (delay_val < 2) - delay_val = 2; + unsigned long flags; for (k = 9; k; k--) { writeccr(i2c, 0); - writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN); + writeb(0, i2c->base + MPC_I2C_SR); /* clear any status bits */ + writeccr(i2c, CCR_MEN | CCR_MSTA); /* START */ + readb(i2c->base + MPC_I2C_DR); /* init xfer */ + udelay(15); /* let it hit the bus */ + local_irq_save(flags); /* should not be delayed further */ + writeccr(i2c, CCR_MEN | CCR_MSTA | CCR_RSTA); /* delay SDA */ readb(i2c->base + MPC_I2C_DR); - writeccr(i2c, CCR_MEN); - udelay(delay_val << 1); + if (k != 1) + udelay(5); + local_irq_restore(flags); } + writeccr(i2c, CCR_MEN); /* Initiate STOP */ + readb(i2c->base + MPC_I2C_DR); + udelay(15); /* Let STOP propagate */ + writeccr(i2c, 0); } static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) -- 2.34.1