Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1579875pxb; Mon, 8 Mar 2021 00:43:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNmrfce64HKtJa05+5484+hYVptjYDQ1T9TRQ0/rSbzL2qNewVb6khlHkkzzej/BIPW+7x X-Received: by 2002:a17:906:abcd:: with SMTP id kq13mr14348110ejb.477.1615193000716; Mon, 08 Mar 2021 00:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615193000; cv=none; d=google.com; s=arc-20160816; b=BFa9RzPRu9LbmopwxDaAGzqi0InMx+JCF2de/mWZ0LaB1w/kuTlHLJLfK69Bpmfkae ikF9eZBwrmh80Zy242tajt6Aj/SrEaS6ODAVFoAIjDrJ8dWONLjP4XdsNmOlnk6rVLcC umFSigLE6mgLE7VY9uYyUE7g0f2AKZmJXj7y+kxYeuquqFG3wItfJGxs3uRD4I+Ysz3E f+v1JVmjDCgJlXGoBbCTaRGXxn1iTjc0PArGB+9LxD1LBITuXz3AOYQGvqXHdPX7AdrY O5Yt98ia0GnD689R5vXmBhaliQEHzG3sthJq8TRf9SRHdzdWhPrhJc0DAVZj/j6XDJ34 MNKA== 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=HCCvMogY/IKiH3+1jcjrX/n2j3sbAeUXvYRCTVs3ppE=; b=WfvjrSZ3zHW4lgz/KhPJqLF/UtEajl4icvBgRRx/Z/oLKwdbk+NvA6PTOXR0bs0FYS eZiKCIW2n2pUJzyX3OTZy+wUEj/heH6eK5GDNY6HOpau65hNZMCwwPbk3s4VRQH1ilSK XLAkTX6+DgHPRttAmDNNmbhWtMCg1FcgBEr3nxczJ5PsKffGoTp3zeu0Xwn3BZCAbmo5 qLKtwo1iOpR4C99cBZiuAbpXLMHcWd0UNjK16jzsRO3kMNmHC1S0SO3+pnuJHrjM/nQ/ StNdCecv1a8473q/CE9+bEIRZ9xBvHzL5dDe14DO58n1tCUO4PVMqhmqOeE+qPndlz1D jWNw== 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 h14si6584277ejk.245.2021.03.08.00.42.58; Mon, 08 Mar 2021 00:43:20 -0800 (PST) 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 S234587AbhCHGGA (ORCPT + 99 others); Mon, 8 Mar 2021 01:06:00 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:36604 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232576AbhCHGFv (ORCPT ); Mon, 8 Mar 2021 01:05:51 -0500 X-UUID: 771a5c14809345cd926a2fa294aed30a-20210308 X-UUID: 771a5c14809345cd926a2fa294aed30a-20210308 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] 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 1330262926; Mon, 08 Mar 2021 14:05:42 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 8 Mar 2021 14:05:40 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 8 Mar 2021 14:05:40 +0800 From: Mark-PK Tsai To: Marc Zyngier CC: , Mark-PK Tsai , Daniel Palmer , Thomas Gleixner , Matthias Brugger , , , Subject: [PATCH v2] irqchip/irq-mst: Support polarity configuration Date: Mon, 8 Mar 2021 14:05:38 +0800 Message-ID: <20210308060538.11164-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 | 90 ++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-mst-intc.c b/drivers/irqchip/irq-mst-intc.c index 143657b0cf28..841b9b1c2699 100644 --- a/drivers/irqchip/irq-mst-intc.c +++ b/drivers/irqchip/irq-mst-intc.c @@ -13,15 +13,25 @@ #include #include #include +#include -#define INTC_MASK 0x0 -#define INTC_EOI 0x20 +#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(64, 16)]; +#endif }; static void mst_set_irq(struct irq_data *d, u32 offset) @@ -78,6 +88,19 @@ 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_LEVEL_LOW && type != IRQ_TYPE_LEVEL_HIGH) + return -EINVAL; + + if (type == IRQ_TYPE_LEVEL_LOW) { + 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 +110,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 +217,14 @@ 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; + + /* + * 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 + */ + if (fwspec->param[2] == IRQ_TYPE_LEVEL_LOW) + parent_fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH; + return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &parent_fwspec); } @@ -193,6 +273,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