Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1618587pxa; Sun, 16 Aug 2020 05:11:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgNQncBJ42cj8ZvN5jMbl/AA79JSRG8FURm3U4z/2h8qw5J1zLVUpZ4d+REL9mI27wE6W0 X-Received: by 2002:a05:6402:1ca6:: with SMTP id cz6mr10423644edb.310.1597579888366; Sun, 16 Aug 2020 05:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597579888; cv=none; d=google.com; s=arc-20160816; b=IAZKGyw6gkWDLz0x9IazhHP1AUCcib07AU69gB4qjgFVGIv9253pohk1PvTC7I0bgT b9Xb/90PCMjiYFxvVyTbQPgkHBcoHmySoDM7g6i01FN4Ywetp/GjMSZcKMweyFY8I/EE TBMcZZmcVXBAv3Q6eVogWNb5ZpokdlMArRn9l0uEuorFK0S4I0Fg6LpLaAxWCRt5hM9F IPlEJX7paH8nt21jb4jqDVGlyjIAi8Xi37Xl922bvyokjFLg4Mnu1geRJ5c57yacojVA GXqWdnrZfrXWNb9to+SFa+Z3HOhrVHiRZp+XRFS2WzYiaKCN6mj0KcmYAdhNdjWD1ylT vwJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K/Xk9vqsFa2pytcZR9ZEjV+eE9g6nLCPU/rDSAimPno=; b=frz5uDEjVza/lFO/yKPARVVxEeNjEi1JInj0aN8xEcI9jCt1vVwKDGh9RYs/IZgdgv Rw/1IHJE0R+sfn1rUbhC3uBbp7FFf1ikyCscv5V4iRLRw1LTSuxUCIYiOcwqp4SaJh0q W83p6lsjbmAVMZ0OST6HzdE9Tcuz6RuHLhHkL0uPxYXqe3R9Sn93hk9vH9VaR4cHVpRJ I8IkoAPqBIEpN5nV2IPUecrz+XQe7N8ANtay87AaRgrzGuPDqq1vwSntUCGJogp5e1VT Qib4qC4i7hJKu0t/ZmgMeDWnEUPN1BIUr5vc4r9Ok8wGat+9cW+RGHtBmF4jxCcA+S4f 1WWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UzJaLGhH; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lv10si9782642ejb.522.2020.08.16.05.11.04; Sun, 16 Aug 2020 05:11:28 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UzJaLGhH; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729180AbgHPLgl (ORCPT + 99 others); Sun, 16 Aug 2020 07:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729212AbgHPLe3 (ORCPT ); Sun, 16 Aug 2020 07:34:29 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5FEC061389; Sun, 16 Aug 2020 04:34:04 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id w17so10097306edt.8; Sun, 16 Aug 2020 04:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K/Xk9vqsFa2pytcZR9ZEjV+eE9g6nLCPU/rDSAimPno=; b=UzJaLGhHPGRYCf1XSubqG9MTpbrvITheAIv7kV4wyCZcDFRenDGdJWCldDeAiE+TZK JdBLWGN7Yb/KfF6AN6R6rW5D9HL8whMEWVj8f+1p2UhVgmgEY/pWTFjdsiS0nJ0b0gOm CPLU/9IjZ2DpN22S1LQ1VPmx53CjOg7zwjmncaz19Y0xneDuzaKE8BY8mFW8eRuV3GaD FuC7EAl8ru+/srrroweUgR4Jqccjnrf9ucINI8cm4+8zEQ6p/16hArc5bNIyIysuDTAQ 2ppJqL8vJcz4zmePXz5WX3jwthKMx3wcUrlvD+JLIYfoWMi/wRteEzZaCnoKf6Li6D+w 8XKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K/Xk9vqsFa2pytcZR9ZEjV+eE9g6nLCPU/rDSAimPno=; b=bsbjFEsWwm4uRI2lJXk2sko1LgqttW6odazgKxCdmU56MawGc5Vv+gAC3UeJT9/qEa Ki+/nFd1s92Z4pAYS4qzOAWZlh6TWmEdbTiwkMm9dNt33XH/bJpT7GxxUgwmhXlZ1dOc 53XZmf17ZBKAMPPphocpHCy24rRJVyRBw3ssFdVnkI/kbhjfHDqZIK7ms7YxG0jmUwrg VhHqFdyB9wvw0ZCVdlqrlthUNKx8eRAWJnmKhokPXRwkjvScOgQsDDBCzXnSFBPnx6Qo g/GBv67zmKdvkF4BVIHP8N1m3y0Q1qbWCrhxYBR+QSdl1RHa4z3TvqKmJOSVVE6y8MPd yeAA== X-Gm-Message-State: AOAM530wGD0nlkFOTrjO8p6bRRtgDkAXXna3DreHXeV46btxF3i9hWf1 pPsQS33pKQTWFpd7m0AEUUg= X-Received: by 2002:a05:6402:1a46:: with SMTP id bf6mr10296238edb.284.1597577642444; Sun, 16 Aug 2020 04:34:02 -0700 (PDT) Received: from localhost.localdomain ([188.24.144.238]) by smtp.gmail.com with ESMTPSA id p1sm11272945edu.11.2020.08.16.04.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2020 04:34:01 -0700 (PDT) From: Cristian Ciocaltea To: Thomas Gleixner , Jason Cooper , Marc Zyngier , Rob Herring , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Manivannan Sadhasivam Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-actions@lists.infradead.org, Parthiban Nallathambi , Saravanan Sekar Subject: [PATCH v4 2/3] irqchip: Add Actions Semi Owl SIRQ controller Date: Sun, 16 Aug 2020 14:33:55 +0300 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This controller appears on Actions Semi Owl family SoC's S500, S700 and S900 and provides support for 3 external interrupt controllers through dedicated 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. This is based on the patch series submitted by Parthiban Nallathambi: https://lore.kernel.org/lkml/20181126100356.2840578-1-pn@denx.de/ Signed-off-by: Parthiban Nallathambi Signed-off-by: Saravanan Sekar [cristi: optimized DT, various fixes/cleanups/improvements] Signed-off-by: Cristian Ciocaltea --- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++ 2 files changed, 319 insertions(+) create mode 100644 drivers/irqchip/irq-owl-sirq.c diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index 133f9c45744a..b8eb5b8b766d 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79) += irq-ath79-cpu.o obj-$(CONFIG_ATH79) += irq-ath79-misc.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o +obj-$(CONFIG_ARCH_ACTIONS) += irq-owl-sirq.o obj-$(CONFIG_DAVINCI_AINTC) += irq-davinci-aintc.o obj-$(CONFIG_DAVINCI_CP_INTC) += irq-davinci-cp-intc.o obj-$(CONFIG_EXYNOS_IRQ_COMBINER) += exynos-combiner.o diff --git a/drivers/irqchip/irq-owl-sirq.c b/drivers/irqchip/irq-owl-sirq.c new file mode 100644 index 000000000000..29b7ffc40ac7 --- /dev/null +++ b/drivers/irqchip/irq-owl-sirq.c @@ -0,0 +1,318 @@ +// 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 + * Author: Cristian Ciocaltea + */ + +#include +#include +#include +#include + +#define NUM_SIRQ 3 + +#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(7, 6) +#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)) + +/* S900 SIRQ1 & SIRQ2 control register offsets, relative to SIRQ0 */ +#define INTC_EXTCTL1 0x0328 +#define INTC_EXTCTL2 0x032c + +struct owl_sirq_params { + /* INTC_EXTCTL reg shared for all three SIRQ lines */ + bool reg_shared; + /* INTC_EXTCTL reg offsets relative to controller base address */ + u16 reg_offset[NUM_SIRQ]; +}; + +struct owl_sirq_chip_data { + const struct owl_sirq_params *params; + void __iomem *base; + raw_spinlock_t lock; + u32 ext_irqs[NUM_SIRQ]; + u8 trigger; +}; + +/* S500 and S700 SoCs */ +static const struct owl_sirq_params owl_sirq_s500_params = { + .reg_shared = true, + .reg_offset = { 0, 0, 0 }, +}; + +/* S900 SoC */ +static const struct owl_sirq_params owl_sirq_s900_params = { + .reg_shared = false, + .reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 }, +}; + +static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32 index) +{ + u32 val; + + val = readl_relaxed(data->base + data->params->reg_offset[index]); + if (data->params->reg_shared) + val = (val >> (2 - index) * 8) & 0xff; + + return val; +} + +static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data, + u32 extctl, u32 index) +{ + u32 val; + + if (data->params->reg_shared) { + val = readl_relaxed(data->base + data->params->reg_offset[index]); + val &= ~(0xff << (2 - index) * 8); + extctl &= 0xff; + extctl = (extctl << (2 - index) * 8) | val; + } + + writel_relaxed(extctl, data->base + data->params->reg_offset[index]); +} + +static void owl_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 = owl_sirq_read_extctl(d, index); + val &= ~clear; + val |= set; + owl_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 = irq_data_get_irq_chip_data(data); + + /* + * Software must clear external interrupt pending, when interrupt type + * is edge triggered, so we need per SIRQ based clearing. + */ + if (chip_data->trigger & (1 << data->hwirq)) + owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING, + data->hwirq); + + irq_chip_eoi_parent(data); +} + +static void owl_sirq_mask(struct irq_data *data) +{ + struct owl_sirq_chip_data *chip_data = irq_data_get_irq_chip_data(data); + + owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, data->hwirq); + irq_chip_mask_parent(data); +} + +static void owl_sirq_unmask(struct irq_data *data) +{ + struct owl_sirq_chip_data *chip_data = irq_data_get_irq_chip_data(data); + + owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, data->hwirq); + irq_chip_unmask_parent(data); +} + +/* + * GIC does not handle falling edge or active low, hence SIRQ shall be + * programmed to convert falling edge to rising edge signal and active + * low to active high signal. + */ +static int owl_sirq_set_type(struct irq_data *data, unsigned int type) +{ + struct owl_sirq_chip_data *chip_data = irq_data_get_irq_chip_data(data); + u32 sirq_type; + + switch (type) { + case IRQ_TYPE_LEVEL_LOW: + sirq_type = INTC_EXTCTL_TYPE_LOW; + chip_data->trigger &= ~(1 << data->hwirq); + type = IRQ_TYPE_LEVEL_HIGH; + break; + case IRQ_TYPE_LEVEL_HIGH: + sirq_type = INTC_EXTCTL_TYPE_HIGH; + chip_data->trigger &= ~(1 << data->hwirq); + break; + case IRQ_TYPE_EDGE_FALLING: + sirq_type = INTC_EXTCTL_TYPE_FALLING; + chip_data->trigger |= 1 << data->hwirq; + type = IRQ_TYPE_EDGE_RISING; + break; + case IRQ_TYPE_EDGE_RISING: + sirq_type = INTC_EXTCTL_TYPE_RISING; + chip_data->trigger |= 1 << data->hwirq; + break; + default: + WARN_ON(1); + return -EINVAL; + } + + owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, sirq_type, + data->hwirq); + + return irq_chip_set_type_parent(data, 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)) + return -EINVAL; + + if (fwspec->param_count != 2 || fwspec->param[0] >= NUM_SIRQ) + return -EINVAL; + + *hwirq = fwspec->param[0]; + *type = fwspec->param[1]; + + return 0; +} + +static int owl_sirq_domain_alloc(struct irq_domain *domain, unsigned int virq, + unsigned int nr_irqs, void *data) +{ + struct owl_sirq_chip_data *chip_data = domain->host_data; + struct irq_fwspec *fwspec = data; + struct irq_fwspec parent_fwspec; + irq_hw_number_t hwirq; + unsigned int type; + int ret; + + if (WARN_ON(nr_irqs != 1)) + return -EINVAL; + + ret = owl_sirq_domain_translate(domain, fwspec, &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; + } + + irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &owl_sirq_chip, + chip_data); + + parent_fwspec.fwnode = domain->parent->fwnode; + parent_fwspec.param_count = 3; + parent_fwspec.param[0] = 0; /* SPI */ + parent_fwspec.param[1] = chip_data->ext_irqs[hwirq]; + parent_fwspec.param[2] = type; + + return irq_domain_alloc_irqs_parent(domain, virq, 1, &parent_fwspec); +} + +static const struct irq_domain_ops owl_sirq_domain_ops = { + .translate = owl_sirq_domain_translate, + .alloc = owl_sirq_domain_alloc, + .free = irq_domain_free_irqs_common, +}; + +static const struct of_device_id owl_sirq_of_match[] = { + { .compatible = "actions,s500-sirq", .data = &owl_sirq_s500_params }, + { .compatible = "actions,s700-sirq", .data = &owl_sirq_s500_params }, + { .compatible = "actions,s900-sirq", .data = &owl_sirq_s900_params }, + { /* sentinel */ } +}; + +static int __init owl_sirq_of_init(struct device_node *node, + struct device_node *parent) +{ + const struct of_device_id *match; + struct irq_domain *domain, *parent_domain; + struct owl_sirq_chip_data *chip_data; + int ret, i; + + parent_domain = irq_find_host(parent); + if (!parent_domain) { + pr_err("%pOF: failed to find sirq parent domain\n", node); + return -ENXIO; + } + + chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL); + if (!chip_data) + return -ENOMEM; + + match = of_match_node(owl_sirq_of_match, node); + if (!match) { + pr_warn("owl-sirq: assuming S500/S700 compatible controller\n"); + chip_data->params = &owl_sirq_s500_params; + } else { + chip_data->params = match->data; + } + + raw_spin_lock_init(&chip_data->lock); + + chip_data->base = of_iomap(node, 0); + if (!chip_data->base) { + pr_err("%pOF: failed to map sirq registers\n", node); + ret = -ENXIO; + goto out_free; + } + + ret = of_property_read_variable_u32_array(node, "actions,ext-interrupts", + chip_data->ext_irqs, + NUM_SIRQ, NUM_SIRQ); + if (ret < NUM_SIRQ) { + pr_err("%pOF: failed to read sirq interrupts\n", node); + goto out_unmap; + } + + /* Set 24MHz external interrupt clock freq */ + for (i = 0; i < NUM_SIRQ; i++) + owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_CLK_SEL, i); + + domain = irq_domain_add_hierarchy(parent_domain, 0, NUM_SIRQ, node, + &owl_sirq_domain_ops, chip_data); + if (!domain) { + pr_err("%pOF: failed to add domain\n", node); + 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.28.0