Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1961308pxb; Fri, 5 Mar 2021 04:11:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSLDomADtdZi48f01DENyXlj42LxQuSlhcbEuuo0tW0OEt8TzYN9eJ60aIdfa1LXWqmoy6 X-Received: by 2002:a05:6402:438f:: with SMTP id o15mr8865966edc.123.1614946308771; Fri, 05 Mar 2021 04:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614946308; cv=none; d=google.com; s=arc-20160816; b=WRVYzqGV1n9yFoN2Q7iae2pjrgo4Ew9Za1IxvZ7Y918MX83FDWIUX6RB6HXkZHHT0o bJJMIrd/FFTgYGgPpYICz72zeaiPD0m5zOhfDVBVNunjIBf0oTUjpbsNauQJKTX010bo Y1FK42I1T0bUtbRtewUcyLk0j9fDCikxRpBOT2kxFzf75qFqLZmtC8vcms61s4kBOQoG zCl++di1z8VkcsjzxDrpU4AZwFtJ9p+pl6YgZ6CoHEDwINtpkgWWdVM5SU30m0GiNEHr ncFgXgDsYTRPgiAvI5Q/NW681juIxg/B7adIASsYdfaOzhCLCGVZdN8J2bMX+stf9mqj 3GIg== 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=y5OqLuh5cxnuRBXumPtCBONKJ+Uf5eGDOgUUJNqzkFo=; b=t2rV0CuSd/xNjmpV1TCgl4EgpLMXDrEyZdquz1wHoS/E/KR+Wl9UKpiaLw3fSeEj3V ZFQ2FpObV249HJhUs7oyxgCTroJMG5vbgdJFC/F3uMgOB9MufrTFIQ5FWY2MTrSZ3s6n kr4nvQaKyRnSVwOC3EeTisQBanXxxJf6TWRCk9DUdPbNNT70z94jD93XcjpRX24Vg3HF 3kLvf1W+swplYaL9c5ZRirQXGwnUSddYm5j8ZQfOBhOofwXm1rf0okZai6u7faughPBN rwQmksI67svg6IyX5QVqhpLyjZ1C1xHp5Ab5FyAF7cDtuCK7jM2BThVqNoiZT9E4aslm r++A== 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 ko24si1195468ejc.407.2021.03.05.04.11.07; Fri, 05 Mar 2021 04:11:48 -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 S229672AbhCEMKD (ORCPT + 99 others); Fri, 5 Mar 2021 07:10:03 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:58621 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229682AbhCEMJh (ORCPT ); Fri, 5 Mar 2021 07:09:37 -0500 X-UUID: 00f3fbecb40b4ecab4a806d0c5056bcb-20210305 X-UUID: 00f3fbecb40b4ecab4a806d0c5056bcb-20210305 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] 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 1828173682; Fri, 05 Mar 2021 20:09:34 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 5 Mar 2021 20:09:33 +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; Fri, 5 Mar 2021 20:09:33 +0800 From: Mark-PK Tsai To: Marc Zyngier CC: Mark-PK Tsai , Daniel Palmer , Thomas Gleixner , Jason Cooper , Matthias Brugger , , , , Subject: [PATCH] irqchip/irq-mst: Support polarity configuration Date: Fri, 5 Mar 2021 20:09:30 +0800 Message-ID: <20210305120930.14297-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 | 87 ++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-mst-intc.c b/drivers/irqchip/irq-mst-intc.c index 143657b0cf28..979a4d55bcb1 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,16 @@ 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) { + 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 +107,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 +214,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 +270,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