Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3289195pxf; Mon, 15 Mar 2021 06:22:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCEFGJx51kfz4j9GXc7k2OIRFSTSHhzhHd1DsV2Wm5HiYiL2Xi0muByIsZecMOMm2ZfzqP X-Received: by 2002:a05:6402:b2d:: with SMTP id bo13mr29690420edb.120.1615814554123; Mon, 15 Mar 2021 06:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615814554; cv=none; d=google.com; s=arc-20160816; b=uONZj8pTJGOoLHjvTMCPw4pNFxMWCkKjGclBaOfNVIu+KCxxJwbCTiAJmQUUnyieaX 6wcHgJEJWYcGKvUcYOGUvxPm/IDSVxHlyJ0NRIZFbIVfb28mzv909yKiv+4oTzY2KQQB NwfLGfUJrphxpkr8+ml16BXBk+wSesVQ291FS9rU4oUXE7qc4UVQLzudMWmfJ7KVrYBE rswqeHYJgGhqr7r0ty7fENzeQKSrJS2camLU6Rxd8f9oej2IKex82LCkk6w8XUcAmHr+ qDOf6CvaPuMqIPKyIo16aZ0RkdGVU1/E7Y4dBzI3AwKAs4Y4cdm8VebSlr9v+JB5S0b/ sWmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=ZfwOnpxitDmh3msBKj119UrWQhFO6DqGt5gkY6c9Ma8=; b=OJJDqc7E7lFQrRs5ibqaT3iuXNvoPgUj3QrWR0OKEJH9RB/7CTpJT96AUmTeRJ7EYm MchGhU6DfYomGFMNc/3rm0kBGWs2tcKTwlDJTbBS5zorDh8c9BQdX0wiTR6EUWs9up8Z wxZCPt2fOf6c/sOQGUP+XrKWBASnQrH0R9iCfbQD6RVvdUbSU39CKJt7s0EWCUV1M5wb 3HwQ5ZmHOjLqlDxecDJg5fD24SoRqNbqkFGUHTl80Vm9ujAHsDCz40lfvzNhfsbIQF2N nTCbasTCK1qHOmO8T2UZUDORgqUs1JdX1tEwhZP5ZL5w9+7yMPA++/u3VRZNUzxfnYVl F1jQ== ARC-Authentication-Results: i=1; mx.google.com; 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=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qq23si11435556ejb.505.2021.03.15.06.22.11; Mon, 15 Mar 2021 06:22:34 -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; 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=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbhCONTL (ORCPT + 99 others); Mon, 15 Mar 2021 09:19:11 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:35193 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229815AbhCONSy (ORCPT ); Mon, 15 Mar 2021 09:18:54 -0400 X-UUID: b94396fd39be487289a9bf11a0e5cd36-20210315 X-UUID: b94396fd39be487289a9bf11a0e5cd36-20210315 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 919804783; Mon, 15 Mar 2021 21:18:50 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 21:18:50 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 15 Mar 2021 21:18:49 +0800 From: Mark-PK Tsai To: Marc Zyngier CC: Mark-PK Tsai , Daniel Palmer , Thomas Gleixner , Matthias Brugger , , , , Subject: [PATCH v4] irqchip/irq-mst: Support polarity configuration Date: Mon, 15 Mar 2021 21:18:48 +0800 Message-ID: <20210315131848.31840-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support irq polarity configuration and save and restore the config when system suspend and resume. Signed-off-by: Mark-PK Tsai --- drivers/irqchip/irq-mst-intc.c | 94 ++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-mst-intc.c b/drivers/irqchip/irq-mst-intc.c index 143657b0cf28..a2ab3f837b96 100644 --- a/drivers/irqchip/irq-mst-intc.c +++ b/drivers/irqchip/irq-mst-intc.c @@ -13,15 +13,27 @@ #include #include #include +#include -#define INTC_MASK 0x0 -#define INTC_EOI 0x20 +#define MST_INTC_MAX_IRQS 64 + +#define INTC_MASK 0x0 +#define INTC_REV_POLARITY 0x10 +#define INTC_EOI 0x20 + +#ifdef CONFIG_PM_SLEEP +static LIST_HEAD(mst_intc_list); +#endif struct mst_intc_chip_data { raw_spinlock_t lock; unsigned int irq_start, nr_irqs; void __iomem *base; bool no_eoi; +#ifdef CONFIG_PM_SLEEP + struct list_head entry; + u16 saved_polarity_conf[DIV_ROUND_UP(MST_INTC_MAX_IRQS, 16)]; +#endif }; static void mst_set_irq(struct irq_data *d, u32 offset) @@ -78,6 +90,20 @@ static void mst_intc_eoi_irq(struct irq_data *d) irq_chip_eoi_parent(d); } +static int mst_irq_chip_set_type(struct irq_data *data, unsigned int type) +{ + if (type != IRQ_TYPE_EDGE_RISING && type != IRQ_TYPE_EDGE_FALLING && + type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_LEVEL_LOW) + return -EINVAL; + + if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_EDGE_FALLING) + mst_set_irq(data, INTC_REV_POLARITY); + + type = IRQ_TYPE_LEVEL_HIGH; + + return irq_chip_set_type_parent(data, type); +} + static struct irq_chip mst_intc_chip = { .name = "mst-intc", .irq_mask = mst_intc_mask_irq, @@ -87,13 +113,62 @@ static struct irq_chip mst_intc_chip = { .irq_set_irqchip_state = irq_chip_set_parent_state, .irq_set_affinity = irq_chip_set_affinity_parent, .irq_set_vcpu_affinity = irq_chip_set_vcpu_affinity_parent, - .irq_set_type = irq_chip_set_type_parent, + .irq_set_type = mst_irq_chip_set_type, .irq_retrigger = irq_chip_retrigger_hierarchy, .flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND, }; +#ifdef CONFIG_PM_SLEEP +static void mst_intc_polarity_save(struct mst_intc_chip_data *cd) +{ + int i; + void __iomem *addr = cd->base + INTC_REV_POLARITY; + + for (i = 0; i < DIV_ROUND_UP(cd->nr_irqs, 16); i++) + cd->saved_polarity_conf[i] = readw_relaxed(addr + i * 4); +} + +static void mst_intc_polarity_restore(struct mst_intc_chip_data *cd) +{ + int i; + void __iomem *addr = cd->base + INTC_REV_POLARITY; + + for (i = 0; i < DIV_ROUND_UP(cd->nr_irqs, 16); i++) + writew_relaxed(cd->saved_polarity_conf[i], addr + i * 4); +} + +static void mst_irq_resume(void) +{ + struct mst_intc_chip_data *cd; + + list_for_each_entry(cd, &mst_intc_list, entry) + mst_intc_polarity_restore(cd); +} + +static int mst_irq_suspend(void) +{ + struct mst_intc_chip_data *cd; + + list_for_each_entry(cd, &mst_intc_list, entry) + mst_intc_polarity_save(cd); + return 0; +} + +static struct syscore_ops mst_irq_syscore_ops = { + .suspend = mst_irq_suspend, + .resume = mst_irq_resume, +}; + +static int __init mst_irq_pm_init(void) +{ + register_syscore_ops(&mst_irq_syscore_ops); + return 0; +} +late_initcall(mst_irq_pm_init); +#endif + static int mst_intc_domain_translate(struct irq_domain *d, struct irq_fwspec *fwspec, unsigned long *hwirq, @@ -145,6 +220,15 @@ static int mst_intc_domain_alloc(struct irq_domain *domain, unsigned int virq, parent_fwspec = *fwspec; parent_fwspec.fwnode = domain->parent->fwnode; parent_fwspec.param[1] = cd->irq_start + hwirq; + + /* + * mst-intc latch the interrupt request if it's edge triggered, + * so the output signal to parent GIC is always level sensitive. + * And if the irq signal is active low, configure it to active high + * to meet GIC SPI spec in mst_irq_chip_set_type via REV_POLARITY bit. + */ + parent_fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH; + return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &parent_fwspec); } @@ -193,6 +277,10 @@ static int __init mst_intc_of_init(struct device_node *dn, return -ENOMEM; } +#ifdef CONFIG_PM_SLEEP + INIT_LIST_HEAD(&cd->entry); + list_add_tail(&cd->entry, &mst_intc_list); +#endif return 0; } -- 2.18.0