Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8798C433FE for ; Wed, 26 Oct 2022 07:50:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D55D484FAC; Wed, 26 Oct 2022 09:50:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="SUbvFmPx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0389F80339; Wed, 26 Oct 2022 09:49:59 +0200 (CEST) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D4AD984F7D for ; Wed, 26 Oct 2022 09:49:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Conor.Dooley@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1666770594; x=1698306594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yO5cLzSF/Y2lBPIlQdZ9iDwacJB6bKwllUUBLVth5mw=; b=SUbvFmPxtvWUp/07p7/992aHprq2LM+K3J9yM+7TR+s3wDxojksWmBoU ac09WNPT09l8EUzMb2rNsC31u1+fQbGNEl/PKQ3tC+EvZj2WVPcYSXzRC 6OaDRKyV8zZ+4bVczFfsCA+4k3CXECEz98dLg48EHuOuOsfwIyuerQJep Wr1iPOefekp7rTwWmIenIQLLWV1vu9Za07ECD1o73Db4wLby4WfEdL+6H 0qbnhc7hpII7opnhYnJPphC65rod/eSF7gRzJ1dwZRuMlsjaV6b543lvU najvng8qve+811uT8993ogrIXlob16SmYGDAnTxgJff6P3dML8HaqNUMf w==; X-IronPort-AV: E=Sophos;i="5.95,214,1661842800"; d="scan'208";a="183955435" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Oct 2022 00:49:51 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 26 Oct 2022 00:49:48 -0700 Received: from wendy.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 26 Oct 2022 00:49:47 -0700 From: Conor Dooley To: Heiko Schocher , Leo Yu-Chi Liang , Padmarao Begari , Conor Dooley , CC: Shravan Chippa Subject: [PATCH v1 1/2] i2c: microchip: fix ack sending logic Date: Wed, 26 Oct 2022 08:49:18 +0100 Message-ID: <20221026074918.3657055-2-conor.dooley@microchip.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221026074918.3657055-1-conor.dooley@microchip.com> References: <20221026074918.3657055-1-conor.dooley@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean "Master receive mode" was not correctly sending ACKs/NACKs in the interrupt handler. Bring the handling of M_SLAR_ACK, M_RX_DATA_ACKED & M_RX_DATA_NACKED in line with the Linux driver. Fixes: 0dc0d1e094 ("i2c: Add Microchip PolarFire SoC I2C driver") Reported-by: Shravan Chippa Signed-off-by: Conor Dooley --- drivers/i2c/i2c-microchip.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/i2c-microchip.c b/drivers/i2c/i2c-microchip.c index 12f65d0af7..3a27459386 100644 --- a/drivers/i2c/i2c-microchip.c +++ b/drivers/i2c/i2c-microchip.c @@ -2,8 +2,9 @@ /* * Microchip I2C controller driver * - * Copyright (C) 2021 Microchip Technology Inc. + * Copyright (C) 2021-2022 Microchip Technology Inc. * Padmarao Begari + * Conor Dooley */ #include #include @@ -265,16 +266,27 @@ static int mpfs_i2c_service_handler(struct mpfs_i2c_bus *bus) } break; case STATUS_M_SLAR_ACK: - ctrl = readl(bus->base + MPFS_I2C_CTRL); - ctrl |= CTRL_AA; - writel(ctrl, bus->base + MPFS_I2C_CTRL); - if (bus->msg_len == 0) { + if (bus->msg_len > 1u) { + ctrl = readl(bus->base + MPFS_I2C_CTRL); + ctrl |= CTRL_AA; + writel(ctrl, bus->base + MPFS_I2C_CTRL); + } else if (bus->msg_len == 1u) { + ctrl = readl(bus->base + MPFS_I2C_CTRL); + ctrl &= ~CTRL_AA; + writel(ctrl, bus->base + MPFS_I2C_CTRL); + } else { + ctrl = readl(bus->base + MPFS_I2C_CTRL); + ctrl |= CTRL_AA; + writel(ctrl, bus->base + MPFS_I2C_CTRL); /* On the last byte to be transmitted, send STOP */ mpfs_i2c_stop(bus); finish = true; } break; case STATUS_M_RX_DATA_ACKED: + mpfs_i2c_empty_rx(bus); + break; + case STATUS_M_RX_DATA_NACKED: mpfs_i2c_empty_rx(bus); if (bus->msg_len == 0) { /* On the last byte to be transmitted, send STOP */ @@ -283,7 +295,6 @@ static int mpfs_i2c_service_handler(struct mpfs_i2c_bus *bus) } break; case STATUS_M_TX_DATA_NACK: - case STATUS_M_RX_DATA_NACKED: case STATUS_M_SLAR_NACK: case STATUS_M_SLAW_NACK: bus->msg_err = -ENXIO; -- 2.38.0