Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4921730pxv; Tue, 27 Jul 2021 21:35:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVbUPeepteTeWXMS9HQlgp9BEyjh4UKyfaTS7c81PFRjFneTldDBfGMe/TDGgbhi284XbK X-Received: by 2002:a17:906:3fc2:: with SMTP id k2mr25440348ejj.440.1627446930094; Tue, 27 Jul 2021 21:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627446930; cv=none; d=google.com; s=arc-20160816; b=JPczH09qheubiTQUih2NAFz/CBdiyIN8AWYqTeoPHpR62VcwzzBjO1d84H3MJcj39s 9HwBvcRC+vym3gJsB2TeHRcPa2po3B9dYDgaWaRzTvI9l1yUP3STL8OwBF9ahMtULfE5 YzOxM7m2fV/Czbmtui7UNcFM5eLPRTj+aIgowjhHM/l2pkpXcq+QZNuRcWExieEzEHKC /kv2BzmIR5n+VyYdXhSzM0iSv2ok89b/qoNJdXjoHPEW6lIdkvP5u2n4n2AbBlJ/CD+a GRAjD2aZQN7101VWhcUjnnTH8BThg4yVWhOuTofbDmk6DTwOXXnBJvWaFgRsIPoGTMLW lUng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=w3eqHGMGnZrc4/+v+wtfBYqAmtbWxOwgb0eJIVdMEG0=; b=A1hRWYnOWcHsS/yTtLIIXNkFJwk/zVWdB9Cu+Pde8CGfUtrF3qZejty9tJ091YqloS bL0IRpX/k/E8AsaDXkg4hEp1R5o9aqVL5LdA8RkJXrzqZj7yh4871b/e1ZLpfIc6B7N+ VZ4BY0s/C6Gv4sJ5Gae9hF8icVuJWMcX9/yHCQv3tsN1R4X0w8YnaI7eJrtH8XooeaZO bsSIHOeHBuxW8OG8lHKaSVSKFF1ESO44bzZZ/zisVwHQ7FGLtion/8k6adHbjTnn18P1 uWoUVpZGmpynkgNIzsYXiw5OAngYzRVS21Kv62iKxZHwXS/6WBxDcgJqheLOO+FbxKI9 GVEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@quicinc.com header.s=qcdkim header.b=yfAFOHQG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca14si4798954ejb.64.2021.07.27.21.35.07; Tue, 27 Jul 2021 21:35: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=fail header.i=@quicinc.com header.s=qcdkim header.b=yfAFOHQG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233987AbhG1Ear (ORCPT + 99 others); Wed, 28 Jul 2021 00:30:47 -0400 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:13787 "EHLO alexa-out-sd-02.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233902AbhG1Eap (ORCPT ); Wed, 28 Jul 2021 00:30:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1627446644; x=1658982644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Q9cKJpllo1DhhME1a3XXJiNfVwTF4UKgzs2i3F4Z3Zw=; b=yfAFOHQG93DrLpy+0wgnRwOb3ZInHHhJUlBw6IbuvtqfuwMsxxl1ca0n lu3P9mjDRsGmjOBT28tdv7tFN4A+zUqa/8ZyJDIk82FDOww9MwYnLbecy Tw7/b0HQ4kd+bNHLsP5DRUsTbblNTxM4M90P7EOb8ihT1ruHzU2RKyG5l Q=; Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by alexa-out-sd-02.qualcomm.com with ESMTP; 27 Jul 2021 21:30:44 -0700 X-QCInternal: smtphost Received: from nasanexm03e.na.qualcomm.com ([10.85.0.48]) by ironmsg02-sd.qualcomm.com with ESMTP/TLS/AES256-SHA; 27 Jul 2021 21:30:43 -0700 Received: from fenglinw-gv.qualcomm.com (10.80.80.8) by nasanexm03e.na.qualcomm.com (10.85.0.48) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 27 Jul 2021 21:30:42 -0700 From: Fenglin Wu To: , , "Stephen Boyd" CC: , , Subject: [spmi-pmic-arb fixes and optimization patches V1 2/9] spmi: pmic-arb: do not ack and clear peripheral interrupts in cleanup_irq Date: Wed, 28 Jul 2021 12:30:02 +0800 Message-ID: <1627446609-9064-3-git-send-email-quic_fenglinw@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1627446609-9064-1-git-send-email-quic_fenglinw@quicinc.com> References: <1627446609-9064-1-git-send-email-quic_fenglinw@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanexm03g.na.qualcomm.com (10.85.0.49) To nasanexm03e.na.qualcomm.com (10.85.0.48) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Subbaraman Narayanamurthy Currently, cleanup_irq() is invoked when a peripheral's interrupt fires and there is no mapping present in the interrupt domain of spmi interrupt controller. The cleanup_irq clears the arbiter bit, clears the pmic interrupt and disables it at the pmic in that order. The last disable in cleanup_irq races with request_irq() in that it stomps over the enable issued by request_irq. Fix this by not writing to the pmic in cleanup_irq. The latched bit will be left set in the pmic, which will not send us more interrupts even if the enable bit stays enabled. When a client wants to request an interrupt, use the activate callback on the irq_domain to clear latched bit. This ensures that the latched, if set due to the above changes in cleanup_irq or when the bootloader leaves it set, gets cleaned up, paving way for upcoming interrupts to trigger. With this, there is a possibility of unwanted triggering of interrupt right after the latched bit is cleared - the interrupt may be left enabled too. To avoid that, clear the enable first followed by clearing the latched bit in the activate callback. Signed-off-by: Subbaraman Narayanamurthy [collinsd@codeaurora.org: fix merge conflict] Signed-off-by: David Collins Signed-off-by: Fenglin Wu --- drivers/spmi/spmi-pmic-arb.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 295e19f..4d7ad004 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -492,16 +492,6 @@ static void cleanup_irq(struct spmi_pmic_arb *pmic_arb, u16 apid, int id) dev_err_ratelimited(&pmic_arb->spmic->dev, "%s apid=%d sid=0x%x per=0x%x irq=%d\n", __func__, apid, sid, per, id); writel_relaxed(irq_mask, pmic_arb->ver_ops->irq_clear(pmic_arb, apid)); - - if (pmic_arb_write_cmd(pmic_arb->spmic, SPMI_CMD_EXT_WRITEL, sid, - (per << 8) + QPNPINT_REG_LATCHED_CLR, &irq_mask, 1)) - dev_err_ratelimited(&pmic_arb->spmic->dev, "failed to ack irq_mask = 0x%x for ppid = %x\n", - irq_mask, ppid); - - if (pmic_arb_write_cmd(pmic_arb->spmic, SPMI_CMD_EXT_WRITEL, sid, - (per << 8) + QPNPINT_REG_EN_CLR, &irq_mask, 1)) - dev_err_ratelimited(&pmic_arb->spmic->dev, "failed to ack irq_mask = 0x%x for ppid = %x\n", - irq_mask, ppid); } static void periph_interrupt(struct spmi_pmic_arb *pmic_arb, u16 apid) @@ -667,6 +657,7 @@ static int qpnpint_irq_domain_activate(struct irq_domain *domain, u16 apid = hwirq_to_apid(d->hwirq); u16 sid = hwirq_to_sid(d->hwirq); u16 irq = hwirq_to_irq(d->hwirq); + u8 buf; if (pmic_arb->apid_data[apid].irq_ee != pmic_arb->ee) { dev_err(&pmic_arb->spmic->dev, "failed to xlate sid = %#x, periph = %#x, irq = %u: ee=%u but owner=%u\n", @@ -675,6 +666,10 @@ static int qpnpint_irq_domain_activate(struct irq_domain *domain, return -ENODEV; } + buf = BIT(irq); + qpnpint_spmi_write(d, QPNPINT_REG_EN_CLR, &buf, 1); + qpnpint_spmi_write(d, QPNPINT_REG_LATCHED_CLR, &buf, 1); + return 0; } -- Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.