Received: by 10.223.176.46 with SMTP id f43csp2676108wra; Mon, 22 Jan 2018 01:23:03 -0800 (PST) X-Google-Smtp-Source: AH8x227EY3vVSUa5XMHzm6s/WvKLcKKt15KbzFoVljHpKnflQA1PfZAaHmo0OUIgrAUqr8SdWG2C X-Received: by 10.98.220.195 with SMTP id c64mr7831117pfl.47.1516612983380; Mon, 22 Jan 2018 01:23:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516612983; cv=none; d=google.com; s=arc-20160816; b=NdEpYBWF13xS/5RxD/AIEdlm84EEWEoFUOeqeO5c7FaUn9EIIAVgY7oF0UIDVjyEIy KXyk9aCdkUTVguglgBDk87RuwDBeqH8Q6WUHQz5pMYqm399aEjC2GRp8oajenCCGvnn8 Ohz/SoHbb7p0jt0SVAsg/56LVTWfTxZRutpkiDFbkb3ckWfY6j/NXBu9BHnMlgsWB8cM 8s235v/UBKW2MEXYvWLDTBXHUOnOskN3JjwIJ3gJQgWB5T6GEGpOextnV71P/EMU0pPE 9V1x/pxzRGaYMyCVrco/Q/umc6GSyzErLpiGMPFEwuc4WaM8ymGajp+OB1y/nGjF+7az ZtNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Ypt+7wj5cWlXoZj1GR8PcXBAEf4j4Vx//jbMr/fTtUk=; b=NupQs4W2ddvcM8Pg1dGGWf1MO4cRZn3OuuqhGfWc2gzd2MFXPD7HDqA5ApEdx2RhEu xuucUpYNzBNZQJyHeobve/q9ixbJBx4Noa0CtncbisXrPnn4p/f9rb6Ehd8DX04QzqY+ 9XgKP1NhqRvN9DyAdjYJEm6vITt+TC280oBGAILTU3oytNePi0k6uSwgMmLCnL1qreOu 3EKWWNm3DPv2NHWd3lz5q+Q6IBqQ8k7lRhHX0Yf4tSzzfkCOB6O1hz4Kb7Pm75s1TCXN hUN0vWdUiSpLugze2AtvQGtOZcQuaExdO8G8BPYfn1EHdQWgzCNeoA9NwyAnaqs/5PpK yWbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@prevas.dk header.s=ironport1 header.b=hspbrMty; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p71si14994836pfi.105.2018.01.22.01.22.49; Mon, 22 Jan 2018 01:23:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@prevas.dk header.s=ironport1 header.b=hspbrMty; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752003AbeAVJWS (ORCPT + 99 others); Mon, 22 Jan 2018 04:22:18 -0500 Received: from mail01.prevas.se ([62.95.78.3]:5860 "EHLO mail01.prevas.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbeAVJVx (ORCPT ); Mon, 22 Jan 2018 04:21:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=prevas.dk; i=@prevas.dk; l=7857; q=dns/txt; s=ironport1; t=1516612913; x=1548148913; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=+bue+XCKutzh0Hjdey6wThnNyagfCnydTOySm8GlBlI=; b=hspbrMtycJ7fUI68YygCea8NJcgZHSCcm6rC5W6sqooGthp0gCGdjcES i/2cExelIjIUt9QQHnIGuuSMKJ8B3nPW50Ny61aZ30b2MUeh//tPkVqmB DoN4WhpdwsmawL4hLUl9B6PSLGpV7WVaNaKPR+eJJM0NjELyjcc/fkRN4 g=; X-IronPort-AV: E=Sophos;i="5.46,396,1511823600"; d="scan'208";a="3106808" Received: from vmprevas4.prevas.se (HELO smtp.prevas.se) ([172.16.8.104]) by ironport1.prevas.se with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2018 10:21:51 +0100 Received: from prevas-ravi.prevas.se (172.16.8.31) by smtp.prevas.se (172.16.8.104) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 22 Jan 2018 10:21:51 +0100 From: Rasmus Villemoes To: Rob Herring , Shawn Guo , Thomas Gleixner , Jason Cooper , Marc Zyngier CC: Andy Tang , Alexander Stein , Rasmus Villemoes , Subject: [PATCH v3 1/2] irqchip: add support for Layerscape external interrupt lines Date: Mon, 22 Jan 2018 10:21:32 +0100 Message-ID: <20180122092133.23177-1-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.15.1 In-Reply-To: <1513758631-19909-1-git-send-email-rasmus.villemoes@prevas.dk> References: <1513758631-19909-1-git-send-email-rasmus.villemoes@prevas.dk> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.16.8.31] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The LS1021A allows inverting the polarity of six interrupt lines IRQ[0:5] via the scfg_intpcr register, effectively allowing IRQ_TYPE_LEVEL_LOW and IRQ_TYPE_EDGE_FALLING for those. We just need to check the type, set the relevant bit in INTPCR accordingly, and fixup the type argument before calling the GIC's irq_set_type. In fact, the power-on-reset value of the INTPCR register on the LS1021A is so that all six lines have their polarity inverted. Hence any hardware connected to those lines is unusable without this: If the line is indeed active low, the generic GIC code will reject an irq spec with IRQ_TYPE_LEVEL_LOW, while if the line is active high, we must obviously disable the polarity inversion (writing 0 to the relevant bit) before unmasking the interrupt. Some other Layerscape SOCs (LS1043A, LS1046A) reportedly have a similar feature, just with a different number of external interrupt lines (and a different POR value for the INTPCR register). This driver should be prepared for supporting those by properly filling out the device tree node, but I don't have the full reference manual, nor the hardware to be able to test it. I do know, from a tiny clipout from one of the other reference manuals I was shown, that 1U< --- Changes since v2 (all addressing comments from Rob Herring): - use fsl,bit-reverse rather than bit-reverse - make the dts node a child of the scfg node - make the node name "interrupt-controller" drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-ls-extirq.c | 173 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 drivers/irqchip/irq-ls-extirq.c diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index b842dfdc903f..32d7160680fe 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -75,6 +75,7 @@ obj-$(CONFIG_MVEBU_ICU) += irq-mvebu-icu.o obj-$(CONFIG_MVEBU_ODMI) += irq-mvebu-odmi.o obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o +obj-$(CONFIG_SOC_LS1021A) += irq-ls-extirq.o obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o diff --git a/drivers/irqchip/irq-ls-extirq.c b/drivers/irqchip/irq-ls-extirq.c new file mode 100644 index 000000000000..ac84ad053b51 --- /dev/null +++ b/drivers/irqchip/irq-ls-extirq.c @@ -0,0 +1,173 @@ +#define pr_fmt(fmt) "irq-ls-extirq: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXIRQ 12 + +struct extirq_chip_data { + struct regmap *syscon; + u32 intpcr; + bool bit_reverse; + u32 nirq; + u32 parent_irq[MAXIRQ]; +}; + +static int +ls_extirq_set_type(struct irq_data *data, unsigned int type) +{ + irq_hw_number_t hwirq = data->hwirq; + struct extirq_chip_data *chip_data = data->chip_data; + u32 value, mask; + + if (chip_data->bit_reverse) + mask = 1U << (31 - hwirq); + else + mask = 1U << hwirq; + + switch (type) { + case IRQ_TYPE_LEVEL_LOW: + type = IRQ_TYPE_LEVEL_HIGH; + value = mask; + break; + case IRQ_TYPE_EDGE_FALLING: + type = IRQ_TYPE_EDGE_RISING; + value = mask; + break; + case IRQ_TYPE_LEVEL_HIGH: + case IRQ_TYPE_EDGE_RISING: + value = 0; + break; + default: + return -EINVAL; + } + + regmap_update_bits(chip_data->syscon, chip_data->intpcr, mask, value); + + data = data->parent_data; + return data->chip->irq_set_type(data, type); +} + +static struct irq_chip extirq_chip = { + .name = "extirq", + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_eoi = irq_chip_eoi_parent, + .irq_set_type = ls_extirq_set_type, + .irq_retrigger = irq_chip_retrigger_hierarchy, + .irq_set_affinity = irq_chip_set_affinity_parent, + .flags = IRQCHIP_SET_TYPE_MASKED, +}; + +static int +ls_extirq_domain_translate(struct irq_domain *d, struct irq_fwspec *fwspec, + unsigned long *hwirq, unsigned int *type) +{ + if (!is_of_node(fwspec->fwnode)) + return -EINVAL; + + if (fwspec->param_count != 3) + return -EINVAL; + + /* No PPI should point to this domain */ + if (fwspec->param[0] != GIC_SPI) + return -EINVAL; + + *hwirq = fwspec->param[1]; + *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; + return 0; +} + +static int +ls_extirq_domain_alloc(struct irq_domain *domain, unsigned int virq, + unsigned int nr_irqs, void *arg) +{ + irq_hw_number_t hwirq; + struct irq_fwspec *fwspec = arg; + struct irq_fwspec gic_fwspec; + struct extirq_chip_data *chip_data = domain->host_data; + + if (fwspec->param_count != 3) + return -EINVAL; + + if (fwspec->param[0] != GIC_SPI) + return -EINVAL; + + hwirq = fwspec->param[1]; + if (hwirq >= chip_data->nirq) + return -EINVAL; + + irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &extirq_chip, + chip_data); + + gic_fwspec.fwnode = domain->parent->fwnode; + gic_fwspec.param_count = 3; + gic_fwspec.param[0] = GIC_SPI; + gic_fwspec.param[1] = chip_data->parent_irq[hwirq]; + gic_fwspec.param[2] = fwspec->param[2]; + + return irq_domain_alloc_irqs_parent(domain, virq, 1, &gic_fwspec); +} + +static const struct irq_domain_ops extirq_domain_ops = { + .translate = ls_extirq_domain_translate, + .alloc = ls_extirq_domain_alloc, + .free = irq_domain_free_irqs_common, +}; + +static int __init +ls_extirq_of_init(struct device_node *node, struct device_node *parent) +{ + + struct irq_domain *domain, *domain_parent; + struct extirq_chip_data *chip_data; + int ret; + + domain_parent = irq_find_host(parent); + if (!domain_parent) { + pr_err("interrupt-parent not found\n"); + return -EINVAL; + } + + chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL); + if (!chip_data) + return -ENOMEM; + + chip_data->syscon = syscon_node_to_regmap(node->parent); + ret = of_property_read_u32(node, "offset", &chip_data->intpcr); + + if (IS_ERR(chip_data->syscon)) + ret = PTR_ERR(chip_data->syscon); + if (ret) + goto out_free_chip; + + ret = of_property_read_variable_u32_array(node, "interrupts", chip_data->parent_irq, + 1, ARRAY_SIZE(chip_data->parent_irq)); + if (ret < 0) + goto out_free_chip; + chip_data->nirq = ret; + chip_data->bit_reverse = of_property_read_bool(node, "fsl,bit-reverse"); + + domain = irq_domain_add_hierarchy(domain_parent, 0, chip_data->nirq, node, + &extirq_domain_ops, chip_data); + if (!domain) { + ret = -ENOMEM; + goto out_free_chip; + } + + return 0; + +out_free_chip: + kfree(chip_data); + return ret; +} + +IRQCHIP_DECLARE(ls1021a_extirq, "fsl,ls1021a-extirq", ls_extirq_of_init); -- 2.15.1