Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3726281imm; Mon, 1 Oct 2018 03:32:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV62gKV6FTGui+1UdR87hdNdXitOCfPqQ7rE6GmM2zyJUpSCZxqjzLdkPATJJciOFvE7s7gYj X-Received: by 2002:a17:902:a985:: with SMTP id bh5-v6mr11102992plb.193.1538389966108; Mon, 01 Oct 2018 03:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538389966; cv=none; d=google.com; s=arc-20160816; b=XfAfMImuvWfQ+qHJQ/0cu0W+OEb2i+zbR73LcydEjuSGYXUWYpYaUIW6ZZaXQL94Gn V/sCXtAY7DBDCFhLSeYldM+aAuq4VPaulcZrlAOxaFz0p4CSXxfOhdw2RZypUFaLhlEe pcn4OV9m8hxjE5dOTeQNeP7boe7drU7GPx0PUkAhZN6OQiz6jovGk94xEwW8p1MzMJJe McSdu8XqpL1drAnScefpWPIi/KxvJklQrQ871xFSA4pyXSAJWW4R/kBFb81kiCZJQbe9 C41CYKB8lm2ESzQQry5LHBZOsludoN0YPNwwSm8DUdd229JE0ZeVzM+oUUnPaqkKXK3p y3cw== 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=lv5fgwVngiSUCZ65IESqPJcG9y3aI8hBjWgPOfOBa3o=; b=gB9HAc2UfVbYx2vZ9e/xF4V/HyK5k+8JG8HF4H7oAtrJTAUf5Qz4iw6lSokjTBagFT 28NfKS4AVyIi/t87T9H2cfce7mRNuFLRHcWjbewMKXW22Go4J+KpDBFfOfp9C4wpN8fP 0LHuh6rXNcxWJj8KzYrKLy7/uYj2EN4Bxud0xN0Zx4ZF9WA/GwRnzZrA3KGUhqxq03Ie G7Cx1ByD4fJp67Qt4jU6m54pfFZRxnXivEvUjEKjwS+biL0Hvqp2VJgmeZNrIcOPCXUv AHMVndLhkNPdHqBXBKp4BYnUmtvUCYZp+UBGe0HL8xE9+G0hXWJ/fvEDhCFbumz9SxYp H1BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WAllNThr; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k20-v6si8209650pgh.168.2018.10.01.03.32.31; Mon, 01 Oct 2018 03:32:46 -0700 (PDT) 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=pass header.i=@gmail.com header.s=20161025 header.b=WAllNThr; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729280AbeJARHb (ORCPT + 99 others); Mon, 1 Oct 2018 13:07:31 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53339 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729095AbeJARH3 (ORCPT ); Mon, 1 Oct 2018 13:07:29 -0400 Received: by mail-wm1-f65.google.com with SMTP id b19-v6so8205267wme.3; Mon, 01 Oct 2018 03:30:21 -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=lv5fgwVngiSUCZ65IESqPJcG9y3aI8hBjWgPOfOBa3o=; b=WAllNThrKjrHE3iAEPkzNM6UZAHVYcLBnVNrDRjbtMLthkl0ftZ7/UxSP67oR4eLvb TSlsnjw5xrmVMEjhOJYpP5Ga9VNdyq5nNiM3JtS3au56l9UisEJMFnbIAJhlye0qmYDD otwOp0qiAUZJDsqRAFG8xBcVhkvygzcCA1AErF9Eu0DM1dmTO9nXNp7P5UIe/ETFcV0Y yQLp5WEhWNa0qUBfN7eRCKUaGRiJi5aAtyiJZjmY6QlwBEwx/tf3AbJuUDEiEqz6CBLB cwRomLgPGF0iafpnszpGt3dRB4OPuqsugbYLNFiR0UIqZLR06codfuCy3IL7eRq+0Djf cvQw== 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=lv5fgwVngiSUCZ65IESqPJcG9y3aI8hBjWgPOfOBa3o=; b=S10/cD9yruuFzkdEAu/dWxmmgKtR9Gs25zvfpJ4uacveKhL9Ex/wei+E18CLFtIdRJ Mw1NtaUAZTptQ1IX58Ouoyu/GcAcAdYOEcvTqKIaH91EhYQqWVJjFV5wiEaO8I1VcJuM /QuCQjPEkXeWsgJzjmMW1Y/5Pfl5AaCleoazEjKSUu1Z3jR6nSgSTKTKEMe0JntMoDKq ouleM7Vqq4eU1/xmoZJtm/QGHd1yZykLh1u7anVOxa5eBCvIxYwFY1PaetSei9jwET1B HNho+1YAhnwWkXD5CiHIRKhqFrAWWFpjHmjlgtPaT1TrKU9CTm4YJL+r/6qrqyW/z8V+ 4ATQ== X-Gm-Message-State: ABuFfoiY08VwPhQjZ31AwyBNPJGo7JqTPDtWxTdcy5DLO0akb24yMW+0 JVpciPO5JgtTzFcH7ALR/cg= X-Received: by 2002:a1c:ed1a:: with SMTP id l26-v6mr8806025wmh.61.1538389820465; Mon, 01 Oct 2018 03:30:20 -0700 (PDT) Received: from laptop.localdomain ([37.122.159.87]) by smtp.gmail.com with ESMTPSA id g8-v6sm2461169wmf.45.2018.10.01.03.30.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 03:30:19 -0700 (PDT) From: Yasha Cherikovsky To: Ralf Baechle , Paul Burton , James Hogan , Thomas Gleixner , Jason Cooper , Marc Zyngier , Daniel Lezcano , Rob Herring , Mark Rutland , linux-mips@linux-mips.org, devicetree@vger.kernel.org Cc: Yasha Cherikovsky , linux-kernel@vger.kernel.org Subject: [RFC v2 3/7] irqchip/rtl8186: Add RTL8186 interrupt controller driver Date: Mon, 1 Oct 2018 13:29:48 +0300 Message-Id: <20181001102952.7913-4-yasha.che3@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001102952.7913-1-yasha.che3@gmail.com> References: <20181001102952.7913-1-yasha.che3@gmail.com> 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 The Realtek RTL8186 SoC is a MIPS based SoC used in some home routers [1][2]. This adds a driver to handle the interrupt controller on this SoC. [1] https://www.linux-mips.org/wiki/Realtek_SOC#Realtek_RTL8186 [2] https://wikidevi.com/wiki/Realtek_RTL8186 Signed-off-by: Yasha Cherikovsky Cc: Ralf Baechle Cc: Paul Burton Cc: James Hogan Cc: Thomas Gleixner Cc: Jason Cooper Cc: Marc Zyngier Cc: Rob Herring Cc: Mark Rutland Cc: linux-mips@linux-mips.org Cc: devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/irqchip/Kconfig | 5 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-rtl8186.c | 107 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 drivers/irqchip/irq-rtl8186.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index e9233db16e03..83099905a871 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -371,4 +371,9 @@ config QCOM_PDC Power Domain Controller driver to manage and configure wakeup IRQs for Qualcomm Technologies Inc (QTI) mobile chips. +config RTL8186_IRQ + bool + depends on MACH_RTL8186 + select IRQ_DOMAIN + endmenu diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index 15f268f646bf..2e0bb859a8f4 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -87,3 +87,4 @@ obj-$(CONFIG_MESON_IRQ_GPIO) += irq-meson-gpio.o obj-$(CONFIG_GOLDFISH_PIC) += irq-goldfish-pic.o obj-$(CONFIG_NDS32) += irq-ativic32.o obj-$(CONFIG_QCOM_PDC) += qcom-pdc.o +obj-$(CONFIG_RTL8186_IRQ) += irq-rtl8186.o diff --git a/drivers/irqchip/irq-rtl8186.c b/drivers/irqchip/irq-rtl8186.c new file mode 100644 index 000000000000..3eb6b947d5a0 --- /dev/null +++ b/drivers/irqchip/irq-rtl8186.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Realtek RTL8186 SoC interrupt controller driver. + * + * Copyright (C) 2018 Yasha Cherikovsky + */ + +#include +#include +#include +#include +#include +#include +#include + +#define RTL8186_NR_IRQS 11 + +#define GIMR 0x00 +#define GISR 0x04 + +static struct { + void __iomem *base; + struct irq_domain *domain; +} intc; + + +asmlinkage void plat_irq_dispatch(void) +{ + u32 hwirq, virq; + u32 gimr = readl(intc.base + GIMR); + u32 gisr = readl(intc.base + GISR); + u32 pending = gimr & gisr & ((1 << RTL8186_NR_IRQS) - 1); + + if (!pending) { + spurious_interrupt(); + return; + } + + while (pending) { + hwirq = fls(pending) - 1; + virq = irq_linear_revmap(intc.domain, hwirq); + do_IRQ(virq); + pending &= ~BIT(hwirq); + } +} + +static void rtl8186_irq_mask(struct irq_data *data) +{ + unsigned long irq = data->hwirq; + + writel(readl(intc.base + GIMR) & (~(BIT(irq))), intc.base + GIMR); +} + +static void rtl8186_irq_unmask(struct irq_data *data) +{ + unsigned long irq = data->hwirq; + + writel((readl(intc.base + GIMR) | (BIT(irq))), intc.base + GIMR); +} + +static struct irq_chip rtl8186_irq_chip = { + .name = "RTL8186", + .irq_mask = rtl8186_irq_mask, + .irq_unmask = rtl8186_irq_unmask, +}; + +static int rtl8186_intc_irq_domain_map(struct irq_domain *d, unsigned int virq, + irq_hw_number_t hw) +{ + irq_set_chip_and_handler(virq, &rtl8186_irq_chip, handle_level_irq); + return 0; +} + +static const struct irq_domain_ops rtl8186_irq_ops = { + .map = rtl8186_intc_irq_domain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static int __init rtl8186_intc_of_init(struct device_node *node, + struct device_node *parent) +{ + intc.base = of_io_request_and_map(node, 0, of_node_full_name(node)); + + if (IS_ERR(intc.base)) + panic("%pOF: unable to map resource", node); + + intc.domain = irq_domain_add_linear(node, RTL8186_NR_IRQS, + &rtl8186_irq_ops, NULL); + + if (!intc.domain) + panic("%pOF: unable to create IRQ domain\n", node); + + /* Start with all interrupts disabled */ + writel(0, intc.base + GIMR); + + /* + * Enable all hardware interrupts in CP0 status register. + * Software interrupts are disabled. + */ + set_c0_status(ST0_IM); + clear_c0_status(STATUSF_IP0 | STATUSF_IP1); + clear_c0_cause(CAUSEF_IP); + + return 0; +} + +IRQCHIP_DECLARE(rtl8186_intc, "realtek,rtl8186-intc", rtl8186_intc_of_init); -- 2.19.0