From patchwork Tue Sep 12 12:49:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 138522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp785408vqx; Tue, 12 Sep 2023 18:20:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxpthPSiQERCpSvASBU0HAoRJMMjHlWE56WxGth02yEgDkWdQmU0K3xPSosy1KVE35XBXX X-Received: by 2002:a17:902:9891:b0:1bc:224a:45c1 with SMTP id s17-20020a170902989100b001bc224a45c1mr1331366plp.55.1694568009452; Tue, 12 Sep 2023 18:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694568009; cv=none; d=google.com; s=arc-20160816; b=fmjw0e+A77UH8dfFp6lWtRHnqM9qsY1x+v4ASPu7dxJfdUaM9us5ZVHbyAxjIeOHYm wy+CkUAZFs+SqShGOztLyWtZdhIiGxmQOIHDIynedi6USX9iLWPQVLBOvFwhKwnD9YV2 1HceP/N7d03BUApLB+rI/M/lN54V7ai1bN3X1wqfUjmvrx0OJGbqtIPgzB31y0Hdl0ar DDSyCYwzTx5zOfmlfEwYZR32rwhBS56DOeOGSyi2xwS3ABhJHf9+xk9QU90kJEOqAbGM p7hv+6ZtLX2GZL/L8+za4ROXM0Z5Xdw9Acpgplv2nUrQ/JyITJKHNiA+x1tilHPuUbIf wx5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ghSylTAjDTfYpuicOmkRLAyqu3UlP7E8gE4e1blAsfM=; fh=2Ku1ln/JvjzY6BVjT7StHc0w+DnFcYa20tTMAsZc5EI=; b=1CW1cYgJOPodcwbrYR72ENVq9JrXCcw7Dpb60IqkabIsUBPjWMOl36PYmJpXDJm4i3 ZrC22SiatZFQti900A3UVaeuN19mkKwsBN865tjvPk2nNqMzmi8qx69VAJ3rqhPirbk/ b9QMXCylztkI0FAvtxUpvUssE4bnjEDHVysdLiN/DAAS7ZfIEUpq92QA+BCAAJJpgv4Z MflNwAzNOwKJwOgpGQ8vaEKwgj/JaELdTammpQRU2NsQZoZ+3UWx8w7WHAFRv1rG3xhb +FeimvT+4mkNE2O/nwvnJ5i7skmoaaq7c0QxgLpMh0HRJP7cJdrF9Dks5kw5GtZVS52a DOFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=afXR8d06; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u11-20020a170902e80b00b001bb9533b968si2930039plg.408.2023.09.12.18.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:20:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=afXR8d06; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BEB19848B330; Tue, 12 Sep 2023 05:50:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235278AbjILMuG (ORCPT + 37 others); Tue, 12 Sep 2023 08:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbjILMt6 (ORCPT ); Tue, 12 Sep 2023 08:49:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5A2510D7 for ; Tue, 12 Sep 2023 05:49:54 -0700 (PDT) Date: Tue, 12 Sep 2023 12:49:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694522993; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ghSylTAjDTfYpuicOmkRLAyqu3UlP7E8gE4e1blAsfM=; b=afXR8d06ECgesYSB990BBdnizZoRI6cjfyKKToFrziZCiOXoLOq5LhZ4E3ZeQkwYjWfgbL WFm+/CS7ayNhUlQDiaerY0CFPJ0zPYIGOUjTge1sIfWqN5garfW5cqxUR8kO8yq8XG2Xyf 9aK9ROgryLluOL/swPc5pBjmmPh2Nxw78TzTTliypM8st71f1HI1BS6TLwu3gwD+jkIqm/ aFht0aleerQg0sVGjDG4o3Ed4aId1vQ0RhQTnZVfzpMPqdp+EdSjMcAlCLYr6XZAfrxyZ+ d2u/nWaA78cuigGzAaA0rSJUrrENbv5MEbYoZ9cf6qK7FPjSYTFtPRhO3Ydq9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694522993; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ghSylTAjDTfYpuicOmkRLAyqu3UlP7E8gE4e1blAsfM=; b=oOknAry+X/qq0vhni2f7xD3y0qfExBx9FexOamUgEilyZj/+tEfcRyTUhwVQyabR1nLiBb AAdCAYoCP5mCl4Ag== From: "irqchip-bot for Neil Armstrong" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-kernel@vger.kernel.org Subject: [irqchip: irq/irqchip-fixes] irqchip/qcom-pdc: Add support for v3.2 HW Cc: Dmitry Baryshkov , Maulik Shah , Neil Armstrong , Konrad Dybcio , Marc Zyngier , tglx@linutronix.de In-Reply-To: <20230905-topic-sm8x50-upstream-pdc-ver-v4-1-fc633c7df84b@linaro.org> References: <20230905-topic-sm8x50-upstream-pdc-ver-v4-1-fc633c7df84b@linaro.org> MIME-Version: 1.0 Message-ID: <169452299250.27769.12946603076037629467.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 05:50:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776883345288869049 X-GMAIL-MSGID: 1776883345288869049 The following commit has been merged into the irq/irqchip-fixes branch of irqchip: Commit-ID: 5873d380f4c0ff23ec7d0d1780107e46a4637c0e Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/5873d380f4c0ff23ec7d0d1780107e46a4637c0e Author: Neil Armstrong AuthorDate: Tue, 05 Sep 2023 15:19:25 +02:00 Committer: Marc Zyngier CommitterDate: Tue, 12 Sep 2023 13:38:08 +01:00 irqchip/qcom-pdc: Add support for v3.2 HW Starting from HW version 3.2 the IRQ_ENABLE bit has moved to the IRQ_i_CFG register and requires a change of the driver to avoid writing into an undefined register address. Get the HW version from registers and set the IRQ_ENABLE bit to the correct register depending on the HW version. Signed-off-by: Dmitry Baryshkov Reviewed-by: Maulik Shah Signed-off-by: Neil Armstrong Acked-by: Konrad Dybcio Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20230905-topic-sm8x50-upstream-pdc-ver-v4-1-fc633c7df84b@linaro.org --- drivers/irqchip/qcom-pdc.c | 69 +++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/drivers/irqchip/qcom-pdc.c b/drivers/irqchip/qcom-pdc.c index a32c0d2..74b2f12 100644 --- a/drivers/irqchip/qcom-pdc.c +++ b/drivers/irqchip/qcom-pdc.c @@ -22,9 +22,20 @@ #define PDC_MAX_GPIO_IRQS 256 +/* Valid only on HW version < 3.2 */ #define IRQ_ENABLE_BANK 0x10 #define IRQ_i_CFG 0x110 +/* Valid only on HW version >= 3.2 */ +#define IRQ_i_CFG_IRQ_ENABLE 3 + +#define IRQ_i_CFG_TYPE_MASK GENMASK(2, 0) + +#define PDC_VERSION_REG 0x1000 + +/* Notable PDC versions */ +#define PDC_VERSION_3_2 0x30200 + struct pdc_pin_region { u32 pin_base; u32 parent_base; @@ -37,6 +48,7 @@ static DEFINE_RAW_SPINLOCK(pdc_lock); static void __iomem *pdc_base; static struct pdc_pin_region *pdc_region; static int pdc_region_cnt; +static unsigned int pdc_version; static void pdc_reg_write(int reg, u32 i, u32 val) { @@ -48,20 +60,32 @@ static u32 pdc_reg_read(int reg, u32 i) return readl_relaxed(pdc_base + reg + i * sizeof(u32)); } -static void pdc_enable_intr(struct irq_data *d, bool on) +static void __pdc_enable_intr(int pin_out, bool on) { - int pin_out = d->hwirq; unsigned long enable; - unsigned long flags; - u32 index, mask; - index = pin_out / 32; - mask = pin_out % 32; + if (pdc_version < PDC_VERSION_3_2) { + u32 index, mask; + + index = pin_out / 32; + mask = pin_out % 32; + + enable = pdc_reg_read(IRQ_ENABLE_BANK, index); + __assign_bit(mask, &enable, on); + pdc_reg_write(IRQ_ENABLE_BANK, index, enable); + } else { + enable = pdc_reg_read(IRQ_i_CFG, pin_out); + __assign_bit(IRQ_i_CFG_IRQ_ENABLE, &enable, on); + pdc_reg_write(IRQ_i_CFG, pin_out, enable); + } +} + +static void pdc_enable_intr(struct irq_data *d, bool on) +{ + unsigned long flags; raw_spin_lock_irqsave(&pdc_lock, flags); - enable = pdc_reg_read(IRQ_ENABLE_BANK, index); - __assign_bit(mask, &enable, on); - pdc_reg_write(IRQ_ENABLE_BANK, index, enable); + __pdc_enable_intr(d->hwirq, on); raw_spin_unlock_irqrestore(&pdc_lock, flags); } @@ -142,6 +166,7 @@ static int qcom_pdc_gic_set_type(struct irq_data *d, unsigned int type) } old_pdc_type = pdc_reg_read(IRQ_i_CFG, d->hwirq); + pdc_type |= (old_pdc_type & ~IRQ_i_CFG_TYPE_MASK); pdc_reg_write(IRQ_i_CFG, d->hwirq, pdc_type); ret = irq_chip_set_type_parent(d, type); @@ -246,7 +271,6 @@ static const struct irq_domain_ops qcom_pdc_ops = { static int pdc_setup_pin_mapping(struct device_node *np) { int ret, n, i; - u32 irq_index, reg_index, val; n = of_property_count_elems_of_size(np, "qcom,pdc-ranges", sizeof(u32)); if (n <= 0 || n % 3) @@ -276,29 +300,38 @@ static int pdc_setup_pin_mapping(struct device_node *np) if (ret) return ret; - for (i = 0; i < pdc_region[n].cnt; i++) { - reg_index = (i + pdc_region[n].pin_base) >> 5; - irq_index = (i + pdc_region[n].pin_base) & 0x1f; - val = pdc_reg_read(IRQ_ENABLE_BANK, reg_index); - val &= ~BIT(irq_index); - pdc_reg_write(IRQ_ENABLE_BANK, reg_index, val); - } + for (i = 0; i < pdc_region[n].cnt; i++) + __pdc_enable_intr(i + pdc_region[n].pin_base, 0); } return 0; } +#define QCOM_PDC_SIZE 0x30000 + static int qcom_pdc_init(struct device_node *node, struct device_node *parent) { struct irq_domain *parent_domain, *pdc_domain; + resource_size_t res_size; + struct resource res; int ret; - pdc_base = of_iomap(node, 0); + /* compat with old sm8150 DT which had very small region for PDC */ + if (of_address_to_resource(node, 0, &res)) + return -EINVAL; + + res_size = max_t(resource_size_t, resource_size(&res), QCOM_PDC_SIZE); + if (res_size > resource_size(&res)) + pr_warn("%pOF: invalid reg size, please fix DT\n", node); + + pdc_base = ioremap(res.start, res_size); if (!pdc_base) { pr_err("%pOF: unable to map PDC registers\n", node); return -ENXIO; } + pdc_version = pdc_reg_read(PDC_VERSION_REG, 0); + parent_domain = irq_find_host(parent); if (!parent_domain) { pr_err("%pOF: unable to find PDC's parent domain\n", node);