Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5558744imu; Mon, 26 Nov 2018 02:06:58 -0800 (PST) X-Google-Smtp-Source: AJdET5dY3B6qdQf8mb4daUhQOOnI0s0pt7SkbOFivQYOlw6pBCTEY6c0b+YJAzh2ZhOFkq3A4Q0R X-Received: by 2002:aa7:8552:: with SMTP id y18mr27707888pfn.83.1543226818626; Mon, 26 Nov 2018 02:06:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543226818; cv=none; d=google.com; s=arc-20160816; b=FiTajD+KGkUmBHGlLXCBWQaB8aNeHSrNdxaegMY/jmu0NbEZ9OuUo6xM7GTY3N/8y5 1WMg74uSp7ZwABvTFZtMKtaN4GDOdvxjs9nrErLHkn9ICHSnbmVTlkUMWcDtc8OHHcfr JqkUyrAi2IvQPAJClkLE2pcV+n5W8Vl+/ZzTj47olm6Xd4136jMpNxDpd7Ek6fWr3D9q V/bQj4ePAXwP+sXYwgVIFwHkybeXNDq7ufp37RaooW9k/jH6jnaI8ua24iq+3pMGLWIy qYe2LLochvXajcCm/3FNvmDubyokAFF0j86xJLZizn4ostg0x8yJbdlZ2pzrpYJEdhiv viow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LPOjwz3SRefXaLa+ZdZNJzitA14O5hmU39Ze2jWtV10=; b=K3GIezekQLTp1h2xJZ1CL5/hwYC2+OuEbo5gPniP0AK/AY09gRhIAv1Ebx5mJxq38j 4CNRFuhbAIEeoP7tYII2u4WJQR4hOXebNLuOUx5dMvVp7WE+FBmRJf6MFH3n4deK2pOT e6+DLFOpIc6/s5V7Yf/GndC96Un/dt0fvnLCQhYMnogDedOVryCSCqoR4f3V+Ek0rgXp u77HV/CGk/YXfZ/Gnhbfc/yKxoi4r4iyIITr6d+mP7GdefIev1PhURyaBkKrAWbFloPs rWM0l4IxN0zKZc7u8BZUmpyBmEEZFAYCk9XImgLbxyRiEks7KaLHed1srnooPEi4+9kB PVMg== ARC-Authentication-Results: i=1; mx.google.com; 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 q8si32713192pli.284.2018.11.26.02.06.24; Mon, 26 Nov 2018 02:06:58 -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; 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 S1726448AbeKZU6H (ORCPT + 99 others); Mon, 26 Nov 2018 15:58:07 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:60838 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeKZU6G (ORCPT ); Mon, 26 Nov 2018 15:58:06 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 433Mvt46zXz1qxkp; Mon, 26 Nov 2018 11:04:26 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 433Mvt2JK3z1qrnB; Mon, 26 Nov 2018 11:04:26 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id HKuSlTjs7H0X; Mon, 26 Nov 2018 11:04:24 +0100 (CET) X-Auth-Info: SnpDlnFQIOHQSkFfu62L3NVqtJZY3IXBjgbWVrACDSI= Received: from xpert.denx.de (unknown [62.91.23.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 26 Nov 2018 11:04:24 +0100 (CET) From: Parthiban Nallathambi To: marc.zyngier@arm.com, tglx@linutronix.de, jason@lakedaemon.net, robh+dt@kernel.org, mark.rutland@arm.com, afaerber@suse.de, catalin.marinas@arm.com, will.deacon@arm.com, manivannan.sadhasivam@linaro.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thomas.liau@actions-semi.com, mp-cs@actions-semi.com, linux@cubietech.com, edgar.righi@lsitec.org.br, laisa.costa@lsitec.org.br, guilherme.simoes@lsitec.org.br, mkzuffo@lsi.usp.br, Parthiban Nallathambi , Saravanan Sekar Subject: [PATCH v3 2/4] drivers/irqchip: Add Actions external interrupts support Date: Mon, 26 Nov 2018 11:03:54 +0100 Message-Id: <20181126100356.2840578-3-pn@denx.de> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181126100356.2840578-1-pn@denx.de> References: <20181126100356.2840578-1-pn@denx.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Actions Semi Owl family SoC's S500, S700 and S900 provides support for 3 external interrupt controllers through SIRQ pins. Each line can be independently configured as interrupt and triggers on either of the edges (raising or falling) or either of the levels (high or low) . Each line can also be masked independently. Signed-off-by: Parthiban Nallathambi Signed-off-by: Saravanan Sekar --- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-owl-sirq.c | 301 +++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 drivers/irqchip/irq-owl-sirq.c diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index 794c13d3ac3d..d8015fc5c1a2 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79) += irq-ath79-misc.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o obj-$(CONFIG_ARCH_EXYNOS) += exynos-combiner.o +obj-$(CONFIG_ARCH_ACTIONS) += irq-owl-sirq.o obj-$(CONFIG_FARADAY_FTINTC010) += irq-ftintc010.o obj-$(CONFIG_ARCH_HIP04) += irq-hip04.o obj-$(CONFIG_ARCH_LPC32XX) += irq-lpc32xx.o diff --git a/drivers/irqchip/irq-owl-sirq.c b/drivers/irqchip/irq-owl-sirq.c new file mode 100644 index 000000000000..cc59e5743cda --- /dev/null +++ b/drivers/irqchip/irq-owl-sirq.c @@ -0,0 +1,301 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Actions Semi Owl SoCs SIRQ interrupt controller driver + * + * Copyright (C) 2014 Actions Semi Inc. + * David Liu + * + * Author: Parthiban Nallathambi + * Author: Saravanan Sekar + */ + +#include +#include +#include +#include + +#define INTC_EXTCTL_PENDING BIT(0) +#define INTC_EXTCTL_CLK_SEL BIT(4) +#define INTC_EXTCTL_EN BIT(5) +#define INTC_EXTCTL_TYPE_MASK GENMASK(6, 7) +#define INTC_EXTCTL_TYPE_HIGH 0 +#define INTC_EXTCTL_TYPE_LOW BIT(6) +#define INTC_EXTCTL_TYPE_RISING BIT(7) +#define INTC_EXTCTL_TYPE_FALLING (BIT(6) | BIT(7)) + +struct owl_sirq_chip_data { + void __iomem *base; + raw_spinlock_t lock; + /* + * Some SoC's share the register for all SIRQ lines, so maintain + * register is shared or not here. This value is from DT. + */ + bool shared_reg; + u32 ext_irq_start; + u32 ext_irq_end; + u16 offset[3]; + u8 trigger; +}; +static struct owl_sirq_chip_data *sirq_data; + +static u32 sirq_read_extctl(struct owl_sirq_chip_data *data, u32 index) +{ + u32 val; + + val = readl_relaxed(data->base + data->offset[index]); + if (data->shared_reg) + val = (val >> (2 - index) * 8) & 0xff; + + return val; +} + +static void sirq_write_extctl(struct owl_sirq_chip_data *data, + u32 extctl, u32 index) +{ + u32 val; + + if (data->shared_reg) { + val = readl_relaxed(data->base + data->offset[index]); + val &= ~(0xff << (2 - index) * 8); + extctl &= 0xff; + extctl = (extctl << (2 - index) * 8) | val; + } + + writel_relaxed(extctl, data->base + data->offset[index]); +} + +static void sirq_clear_set_extctl(struct owl_sirq_chip_data *d, + u32 clear, u32 set, u32 index) +{ + unsigned long flags; + u32 val; + + raw_spin_lock_irqsave(&d->lock, flags); + val = sirq_read_extctl(d, index); + val &= ~clear; + val |= set; + sirq_write_extctl(d, val, index); + raw_spin_unlock_irqrestore(&d->lock, flags); +} + +static void owl_sirq_eoi(struct irq_data *data) +{ + struct owl_sirq_chip_data *chip_data = data->chip_data; + u32 index = data->hwirq - chip_data->ext_irq_start; + + /* + * Software must clear external interrupt pending, when interrupt type + * is edge triggered, so we need per SIRQ based clearing. + */ + if (chip_data->trigger & (1 << index)) + sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING, index); + irq_chip_eoi_parent(data); +} + +static void owl_sirq_mask(struct irq_data *data) +{ + struct owl_sirq_chip_data *chip_data = data->chip_data; + u32 index = data->hwirq - chip_data->ext_irq_start; + + sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, index); + irq_chip_mask_parent(data); +} + +static void owl_sirq_unmask(struct irq_data *data) +{ + struct owl_sirq_chip_data *chip_data = data->chip_data; + u32 index = data->hwirq - chip_data->ext_irq_start; + + sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, index); + irq_chip_unmask_parent(data); +} + +/* PAD_PULLCTL needs to be defined in pinctrl */ +static int owl_sirq_set_type(struct irq_data *data, unsigned int flow_type) +{ + struct owl_sirq_chip_data *chip_data = data->chip_data; + u32 index = data->hwirq - chip_data->ext_irq_start; + u32 type; + + switch (flow_type) { + case IRQF_TRIGGER_LOW: + type = INTC_EXTCTL_TYPE_LOW; + chip_data->trigger &= ~(1 << index); + flow_type = IRQF_TRIGGER_HIGH; + break; + case IRQF_TRIGGER_HIGH: + type = INTC_EXTCTL_TYPE_HIGH; + chip_data->trigger &= ~(1 << index); + break; + case IRQF_TRIGGER_FALLING: + type = INTC_EXTCTL_TYPE_FALLING; + chip_data->trigger |= 1 << index; + flow_type = IRQF_TRIGGER_RISING; + break; + case IRQF_TRIGGER_RISING: + type = INTC_EXTCTL_TYPE_RISING; + chip_data->trigger |= 1 << index; + break; + default: + return -EINVAL; + } + + sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, type, index); + return irq_chip_set_type_parent(data, flow_type); +} + +static struct irq_chip owl_sirq_chip = { + .name = "owl-sirq", + .irq_mask = owl_sirq_mask, + .irq_unmask = owl_sirq_unmask, + .irq_eoi = owl_sirq_eoi, + .irq_set_type = owl_sirq_set_type, + .irq_retrigger = irq_chip_retrigger_hierarchy, +}; + +static int owl_sirq_domain_translate(struct irq_domain *d, + struct irq_fwspec *fwspec, + unsigned long *hwirq, + unsigned int *type) +{ + if (is_of_node(fwspec->fwnode)) { + if (fwspec->param_count != 3) + return -EINVAL; + + /* No PPI should point to this domain */ + if (fwspec->param[0] != 0) + return -EINVAL; + + /* sirq support irq number check */ + if (fwspec->param[1] < sirq_data->ext_irq_start || + fwspec->param[1] > sirq_data->ext_irq_end) + return -EINVAL; + + *hwirq = fwspec->param[1]; + *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; + return 0; + } + + return -EINVAL; +} + +static int owl_sirq_domain_alloc(struct irq_domain *domain, unsigned int virq, + unsigned int nr_irqs, void *arg) +{ + int i, ret; + unsigned int type; + irq_hw_number_t hwirq; + struct irq_fwspec *fwspec = arg; + struct irq_fwspec gic_fwspec = *fwspec; + + if (fwspec->param_count != 3) + return -EINVAL; + + /* sysirq doesn't support PPI */ + if (fwspec->param[0]) + return -EINVAL; + + ret = owl_sirq_domain_translate(domain, arg, &hwirq, &type); + if (ret) + return ret; + + switch (type) { + case IRQ_TYPE_EDGE_RISING: + case IRQ_TYPE_LEVEL_HIGH: + break; + case IRQ_TYPE_EDGE_FALLING: + type = IRQ_TYPE_EDGE_RISING; + break; + case IRQ_TYPE_LEVEL_LOW: + type = IRQ_TYPE_LEVEL_HIGH; + break; + default: + return -EINVAL; + } + + for (i = 0; i < nr_irqs; i++) + irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i, + &owl_sirq_chip, + domain->host_data); + + gic_fwspec.param[2] = type; + gic_fwspec.fwnode = domain->parent->fwnode; + return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &gic_fwspec); +} + + +static const struct irq_domain_ops sirq_domain_ops = { + .translate = owl_sirq_domain_translate, + .alloc = owl_sirq_domain_alloc, + .free = irq_domain_free_irqs_common, +}; + +static int __init owl_sirq_of_init(struct device_node *node, + struct device_node *parent) +{ + struct irq_domain *domain, *domain_parent; + int ret = 0, i, sirq_cnt = 0; + struct owl_sirq_chip_data *chip_data; + + chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL); + if (!chip_data) + return -ENOMEM; + + sirq_data = chip_data; + raw_spin_lock_init(&chip_data->lock); + chip_data->base = of_iomap(node, 0); + if (!chip_data->base) { + pr_err("owl_sirq: unable to map sirq register\n"); + ret = -ENXIO; + goto out_free; + } + + ret = of_property_read_u32_index(node, "actions,ext-irq-range", 0, + &chip_data->ext_irq_start); + if (ret) + goto out_unmap; + + ret = of_property_read_u32_index(node, "actions,ext-irq-range", 1, + &chip_data->ext_irq_end); + if (ret) + goto out_unmap; + + sirq_cnt = chip_data->ext_irq_end - chip_data->ext_irq_start + 1; + chip_data->shared_reg = of_property_read_bool(node, + "actions,sirq-shared-reg"); + for (i = 0; i < sirq_cnt; i++) { + u32 value; + + ret = of_property_read_u32_index(node, "actions,sirq-reg-offset", + i, &value); + if (ret) + goto out_unmap; + + chip_data->offset[i] = (u16)value; + sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_CLK_SEL, i); + } + + domain_parent = irq_find_host(parent); + if (!domain_parent) { + pr_err("owl_sirq: interrupt-parent not found\n"); + goto out_unmap; + } + + domain = irq_domain_add_hierarchy(domain_parent, 0, + sirq_cnt, node, + &sirq_domain_ops, chip_data); + if (!domain) { + ret = -ENOMEM; + goto out_unmap; + } + + return 0; + +out_unmap: + iounmap(chip_data->base); +out_free: + kfree(chip_data); + return ret; +} + +IRQCHIP_DECLARE(owl_sirq, "actions,owl-sirq", owl_sirq_of_init); -- 2.17.2