Received: by 10.223.164.202 with SMTP id h10csp1192629wrb; Tue, 7 Nov 2017 23:50:28 -0800 (PST) X-Google-Smtp-Source: ABhQp+TZHNpus28fK6uOzh7ySMzWIiY6ykMKuIdqwn6TvMpSkxwFEZ4/gsEsnsZomH/GwyY1IGxr X-Received: by 10.101.66.197 with SMTP id l5mr1508603pgp.240.1510127428746; Tue, 07 Nov 2017 23:50:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510127428; cv=none; d=google.com; s=arc-20160816; b=KLFso3sessPd+QfK+jDsTwBn+kHuxDD1i3eLXWN6EUAvl62DqLxcIAthvS0UWvnEEO gEf9p9p3HvrXzK0TZ9f/W1Iz7BDyzw+o9W+4SolzGYG30Mj1hJW7tGeOXadvWHaT1btr b41t2i2zPJ+6seyAwTA21Fbb8TRdFgSpUmeTw6fcTVSdiDkvEndrj1k2qAXhYlxWTgjZ zYEeQQrztvqhORc03E0y3gro3A6ptJ0HFiVFfn7MIOzylIozvGEBLsUO4h/ItRnxhFzW b6bZVGZdDHBLorbOyclyXQvt12RhjZqbjgES2hgTtu1Bw0x9l1hhPulWHBIBTgoPupqM aJoQ== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=h/0V9kO8jsFikj58eDLvhcS/fQjgbLwNZld5K3te5Xk=; b=DFP+mKLoiT7viCMcCPvjRmpTpWXQgmsRQFHfpO36vWr/MjoU483wCSXoCQZVrT3boM RKb4qjrqPUak5QZl0PY7kpPKsCxxq9ecxWNkEIvWHPXgGK79MBnN/s2xbMURpI+LKjz2 DS5kfNCpqISROHvo9K746Hxmn22dkuKOAX8rQmJqJ2bTNE3XEz9k9jSgSVXIOFPq+fIi rV1VOl25NHcq+1Ct4qndPhWOs923NMP1kgc9fxc57FNlomgvbPJfJkoJrN3fcTidhvH7 XamhR7iidOgxYTNeQg6a0aIgyLF9Eb89fAwxVX1/NFBKQ51Iyh76Hfu2W/2FS7gIb5wq PnkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k6Ej0Avm; 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=NONE 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 s188si3041486pgb.646.2017.11.07.23.50.16; Tue, 07 Nov 2017 23:50:28 -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=pass header.i=@gmail.com header.s=20161025 header.b=k6Ej0Avm; 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=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754682AbdKHGW1 (ORCPT + 91 others); Wed, 8 Nov 2017 01:22:27 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45654 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754436AbdKHGVI (ORCPT ); Wed, 8 Nov 2017 01:21:08 -0500 Received: by mail-pl0-f65.google.com with SMTP id 30so668338pla.2; Tue, 07 Nov 2017 22:21:08 -0800 (PST) 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 :in-reply-to:references; bh=h/0V9kO8jsFikj58eDLvhcS/fQjgbLwNZld5K3te5Xk=; b=k6Ej0Avmtq34SGDbBvY0YHVNMWW9KmKba3B6UDPwJNilsbcZnpi3eyJEJUp5ZncBv9 TvXJmiZSiUzw0ZsRU7lbR8deQsFNJ8uKSoxem+5DuTgyozzRTlPQBKROLt1dCPKTfuzD gfjc+iKWGqrbABQrx/+HMq6IvzYAOo5vYMXl6G9DczMv3wdW1n9HCobfrFBxvxnPSHOX hjDLmoJuIs2d5sNu9+pI0mw19dGejr+YKCa+Dgsd3c+QPxROHkLUVTVhM3RHUcbV2Q3+ xT0Lk6nHE2bdbnqUXEgv46DSJ8kqWqQjOAc4KWswcdStXv8zF4Gawznr3xeqI0BmscNe 8Lbg== 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:in-reply-to:references; bh=h/0V9kO8jsFikj58eDLvhcS/fQjgbLwNZld5K3te5Xk=; b=ktnmQHbkX2C71X1granQLpLwQR/NTBoYk4Kug8stgW5MIqBDa6Bz8FqlOKC3sqGSe0 OwMGcohoYp88Yw+/2JUCaGSqTHYZi1dtkIxtLndCp2IkWpXabzf8Q+u756kUvUsMyFMj Lqufwaw/TFLupWI4k+gIHs7SOSTfuXicamPM9R0CDyQzPemHDpr1Lr8bFQNAesaCotxC lX3IDhd17xDYb0xtMh/XrXwP6TJUl8jOMnkUmfk6BObUVYniwLMjZJdcnbtojAn3kf9I ykBJZuT7km1RvMhTsars5k9iHZVb45HdfXXVnNEV8jot9ezpbTmWzb/x/94o48F/MzSw KkwA== X-Gm-Message-State: AJaThX6xU9x45gXa7dHNlaClexqFEpVUtYqLuYGmqcRG+WY9BprcUrps pPkHG4eLQCvWyhJ4tWKiLAw= X-Received: by 10.159.244.138 with SMTP id y10mr1217792plr.399.1510122067558; Tue, 07 Nov 2017 22:21:07 -0800 (PST) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id a4sm6581339pfj.72.2017.11.07.22.21.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 22:21:06 -0800 (PST) From: Greentime Hu To: greentime@andestech.com, linux-kernel@vger.kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, netdev@vger.kernel.org Cc: green.hu@gmail.com, Rick Chen Subject: [PATCH 28/31] irqchip: Andestech Internal Vector Interrupt Controller driver Date: Wed, 8 Nov 2017 13:55:16 +0800 Message-Id: <4572b290f40d62876b83328331a17c2343710b20.1510118606.git.green.hu@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greentime Hu Signed-off-by: Rick Chen Signed-off-by: Greentime Hu --- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-ativic32.c | 149 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 drivers/irqchip/irq-ativic32.c diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index b842dfd..201ca9f 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -80,3 +80,4 @@ obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o obj-$(CONFIG_IRQ_UNIPHIER_AIDET) += irq-uniphier-aidet.o +obj-$(CONFIG_NDS32) += irq-ativic32.o diff --git a/drivers/irqchip/irq-ativic32.c b/drivers/irqchip/irq-ativic32.c new file mode 100644 index 0000000..d3dae59 --- /dev/null +++ b/drivers/irqchip/irq-ativic32.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2005-2017 Andes Technology Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static void ativic32_ack_irq(struct irq_data *data) +{ + __nds32__mtsr_dsb(1 << data->hwirq, NDS32_SR_INT_PEND2); +} + +static void ativic32_mask_irq(struct irq_data *data) +{ + unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2); + __nds32__mtsr_dsb(int_mask2 & (~(1 << data->hwirq)), NDS32_SR_INT_MASK2); +} + +static void ativic32_mask_ack_irq(struct irq_data *data) +{ + unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2); + __nds32__mtsr_dsb(int_mask2 & (~(1 << data->hwirq)), NDS32_SR_INT_MASK2); + __nds32__mtsr_dsb((1 << data->hwirq), NDS32_SR_INT_PEND2); + +} + +static void ativic32_unmask_irq(struct irq_data *data) +{ + unsigned long int_mask2 = __nds32__mfsr(NDS32_SR_INT_MASK2); + __nds32__mtsr_dsb(int_mask2 | (1 << data->hwirq), NDS32_SR_INT_MASK2); +} + +static int ativic32_set_type(struct irq_data *data, unsigned int flow_type) +{ + printk(KERN_WARNING "interrupt type is not configurable\n"); + return 0; +} + +static struct irq_chip ativic32_chip = { + .name = "ativic32", + .irq_ack = ativic32_ack_irq, + .irq_mask = ativic32_mask_irq, + .irq_mask_ack = ativic32_mask_ack_irq, + .irq_unmask = ativic32_unmask_irq, + .irq_set_type = ativic32_set_type, +}; + +static unsigned int __initdata nivic_map[6] = { 6, 2, 10, 16, 24, 32 }; + +struct irq_domain *root_domain; +static int ativic32_irq_domain_map(struct irq_domain *id, unsigned int virq, + irq_hw_number_t hw) +{ + + unsigned long int_trigger_type; + int_trigger_type = __nds32__mfsr(NDS32_SR_INT_TRIGGER); + if (int_trigger_type & (1 << hw)) + irq_set_chip_and_handler(virq, &ativic32_chip, handle_edge_irq); + else + irq_set_chip_and_handler(virq, &ativic32_chip, handle_level_irq); + + return 0; +} + +static struct irq_domain_ops ativic32_ops = { + .map = ativic32_irq_domain_map, + .xlate = irq_domain_xlate_onecell +}; + +static int get_intr_src(void) +{ + return ((__nds32__mfsr(NDS32_SR_ITYPE)&ITYPE_mskVECTOR) >> ITYPE_offVECTOR) + - NDS32_VECTOR_offINTERRUPT; +} + +asmlinkage void asm_do_IRQ(struct pt_regs *regs) +{ + struct pt_regs *old_regs = set_irq_regs(regs); + int virq; + int irq = get_intr_src(); + + /* + * Some hardware gives randomly wrong interrupts. Rather + * than crashing, do something sensible. + */ + if (unlikely(irq >= NR_IRQS)) { + pr_emerg( "IRQ exceeds NR_IRQS\n"); + BUG(); + } + + irq_enter(); + virq = irq_find_mapping(root_domain, irq); + generic_handle_irq(virq); + irq_exit(); + set_irq_regs(old_regs); + +} + +int __init ativic32_init_irq(struct device_node *node, struct device_node *parent) +{ + unsigned long int_vec_base, nivic, i; + + if (WARN(parent, "non-root ativic32 are not supported")) + return -EINVAL; + + int_vec_base = __nds32__mfsr(NDS32_SR_IVB); + + if (((int_vec_base & IVB_mskIVIC_VER) >> IVB_offIVIC_VER) == 0) { + panic("Unable to use NOINTC option to boot on this cpu\n"); + } + + nivic = (int_vec_base & IVB_mskNIVIC) >> IVB_offNIVIC; + if (nivic >= (sizeof nivic_map / sizeof nivic_map[0])) { + panic + ("The number of input for IVIC Controller is not supported on this cpu\n"); + } + nivic = nivic_map[nivic]; + + root_domain = irq_domain_add_linear(node, nivic, + &ativic32_ops, NULL); + + if (!root_domain) + panic("%s: unable to create IRQ domain\n", node->full_name); + + for(i = 0; i < nivic; i++) + irq_create_mapping(root_domain, i); + + return 0; + +} +IRQCHIP_DECLARE(ativic32, "andestech,ativic32", ativic32_init_irq); -- 1.7.9.5 From 1583524131829184710@xxx Wed Nov 08 18:38:13 +0000 2017 X-GM-THRID: 1583524131829184710 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread