Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4687128pxj; Wed, 12 May 2021 10:54:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZWfYAjj3VQRFTs+zcbp/6q3KEQvUJcLDe42kRdhdbDA0CbY7xUAhoUZNMnEf9ycfIaXlT X-Received: by 2002:a50:eb08:: with SMTP id y8mr30890790edp.89.1620842049438; Wed, 12 May 2021 10:54:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842049; cv=none; d=google.com; s=arc-20160816; b=d4YUtJvgxrX89OkuLvydlxhD7P52PO72rER30aTAQfRrv7956HkvV5D5lGHsNFkQyc msYWFr6AaMc207YLHMx+jxMD7Ab04yFAW4iZUyMQN/VkK1GEe3pfipaOR46rbh6jcZXI NxTJVv8quh5EmDHfuOtAIhGRmq4CltdpTnXQnOZqfjv5Y/KBzySu5IwlzLeP+XrAzqWs AVKN4W97NWi7hxCIsXaYIvuFsaIA9q2eLlMDVb8aKBQ58phV9XY2wilsH8xoiWNqlXEz Iw+ZOkxCntb39EoYXZybWVK805ZnSCWz2Uz0sNCt0eHl+wl4ZcpKGTNKn/9EIRZd2DSu 6TlA== 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=N0EXYgJaxzHZyKXTh7yjvIM1slq8N7YUJ5Y8YNCwfW8=; b=ocYnvDwCDzraKXaglOK36OxSz6ozsfwK6+jlagFs9mmLiPTxVK6dGTzwhLDsP0NJIv F/6OCEZ91s+QuS85k930YlA1y1uC0gLI+VF2ow5120zD381kMBBVH1nXXD0eNcKpK2/y OEHWB/WZn9xiZbu1yep1eL1uKQgWFhfJGRvXwr/+vfPxGwHEKeQ7AEr7M1OrkMp89VDD Heg0tLW+sSKxtE8YZGJf5dGf/PA1ZtuVPR8GJEm2o/Tdr50sJk2PwP5q9qExlMzU/tng uZROgwxguf31VXaPuf11356sHTuNAs+3vYsdNDDZQs3hDkLgOCA3vMqqZdJQnKKn1j4V 2Bgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d4BtVRst; 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 q11si577116ejz.231.2021.05.12.10.53.44; Wed, 12 May 2021 10:54:09 -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=d4BtVRst; 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 S238948AbhELRsZ (ORCPT + 99 others); Wed, 12 May 2021 13:48:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:59068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238787AbhELQSz (ORCPT ); Wed, 12 May 2021 12:18:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 09BE461D87; Wed, 12 May 2021 15:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834330; bh=9UeP8We+m4Gx6md/+WvfJYb09b3nl5dZm2zWAqiBTBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d4BtVRstWMl64UY4yXedB3rHqw/PEXy0uD0jUgjDSsgVYYraAPbHgXJKOvN20QsCw 9kRViuvgY2G8y7WuDgZvnASi9677fO71vHCLnGBlHsbvPi/KARBYecA5ay7kNayCPK pyUVlZf7iAnJtKA3NxKhnqGQkQXWa3DzDdYit+74= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wolfram Sang , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Wolfram Sang , Sasha Levin Subject: [PATCH 5.11 501/601] i2c: rcar: protect against supurious interrupts on V3U Date: Wed, 12 May 2021 16:49:38 +0200 Message-Id: <20210512144844.341416977@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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: Wolfram Sang [ Upstream commit 9c975c432bc0aa53a90438fc80b369cb35134a48 ] V3U creates spurious interrupts which we need to handle. This costs time until BUS_PHASE_DATA can be activated which is problematic for Gen2 SoCs and earlier. Because of this we introduce two interrupt handlers here which will call a generic main irq function once the timing critical stuff is done. Signed-off-by: Wolfram Sang Reviewed-by: Niklas Söderlund Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-rcar.c | 57 ++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 3c9c3a6f7ac8..12f6d452c0f7 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -625,20 +625,11 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv) * generated. It turned out that taking a spinlock at the beginning of the ISR * was already causing repeated messages. Thus, this driver was converted to * the now lockless behaviour. Please keep this in mind when hacking the driver. + * R-Car Gen3 seems to have this fixed but earlier versions than R-Car Gen2 are + * likely affected. Therefore, we have different interrupt handler entries. */ -static irqreturn_t rcar_i2c_irq(int irq, void *ptr) +static irqreturn_t rcar_i2c_irq(int irq, struct rcar_i2c_priv *priv, u32 msr) { - struct rcar_i2c_priv *priv = ptr; - u32 msr; - - /* Clear START or STOP immediately, except for REPSTART after read */ - if (likely(!(priv->flags & ID_P_REP_AFTER_RD))) - rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); - - msr = rcar_i2c_read(priv, ICMSR); - - /* Only handle interrupts that are currently enabled */ - msr &= rcar_i2c_read(priv, ICMIER); if (!msr) { if (rcar_i2c_slave_irq(priv)) return IRQ_HANDLED; @@ -682,6 +673,41 @@ out: return IRQ_HANDLED; } +static irqreturn_t rcar_i2c_gen2_irq(int irq, void *ptr) +{ + struct rcar_i2c_priv *priv = ptr; + u32 msr; + + /* Clear START or STOP immediately, except for REPSTART after read */ + if (likely(!(priv->flags & ID_P_REP_AFTER_RD))) + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); + + /* Only handle interrupts that are currently enabled */ + msr = rcar_i2c_read(priv, ICMSR); + msr &= rcar_i2c_read(priv, ICMIER); + + return rcar_i2c_irq(irq, priv, msr); +} + +static irqreturn_t rcar_i2c_gen3_irq(int irq, void *ptr) +{ + struct rcar_i2c_priv *priv = ptr; + u32 msr; + + /* Only handle interrupts that are currently enabled */ + msr = rcar_i2c_read(priv, ICMSR); + msr &= rcar_i2c_read(priv, ICMIER); + + /* + * Clear START or STOP immediately, except for REPSTART after read or + * if a spurious interrupt was detected. + */ + if (likely(!(priv->flags & ID_P_REP_AFTER_RD) && msr)) + rcar_i2c_write(priv, ICMCR, RCAR_BUS_PHASE_DATA); + + return rcar_i2c_irq(irq, priv, msr); +} + static struct dma_chan *rcar_i2c_request_dma_chan(struct device *dev, enum dma_transfer_direction dir, dma_addr_t port_addr) @@ -929,6 +955,7 @@ static int rcar_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; struct device *dev = &pdev->dev; unsigned long irqflags = 0; + irqreturn_t (*irqhandler)(int irq, void *ptr) = rcar_i2c_gen3_irq; int ret; /* Otherwise logic will break because some bytes must always use PIO */ @@ -977,8 +1004,10 @@ static int rcar_i2c_probe(struct platform_device *pdev) rcar_i2c_write(priv, ICSAR, 0); /* Gen2: must be 0 if not using slave */ - if (priv->devtype < I2C_RCAR_GEN3) + if (priv->devtype < I2C_RCAR_GEN3) { irqflags |= IRQF_NO_THREAD; + irqhandler = rcar_i2c_gen2_irq; + } if (priv->devtype == I2C_RCAR_GEN3) { priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); @@ -999,7 +1028,7 @@ static int rcar_i2c_probe(struct platform_device *pdev) priv->flags |= ID_P_HOST_NOTIFY; priv->irq = platform_get_irq(pdev, 0); - ret = devm_request_irq(dev, priv->irq, rcar_i2c_irq, irqflags, dev_name(dev), priv); + ret = devm_request_irq(dev, priv->irq, irqhandler, irqflags, dev_name(dev), priv); if (ret < 0) { dev_err(dev, "cannot get irq %d\n", priv->irq); goto out_pm_disable; -- 2.30.2