Received: by 10.223.176.46 with SMTP id f43csp4481063wra; Tue, 23 Jan 2018 09:59:01 -0800 (PST) X-Google-Smtp-Source: AH8x225frQfbo0RTXAMiNFXBeq6bC8/zPi7rMKNyhpPwCTxbFsXSno5FzQTjjtzOi5zctxSVwG4e X-Received: by 10.107.178.70 with SMTP id b67mr4675102iof.139.1516730341751; Tue, 23 Jan 2018 09:59:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516730341; cv=none; d=google.com; s=arc-20160816; b=qbj8wFEpMjqgXML7N0CISWOp45B/JoOn5XM9y2xZC+cb4CcZsWrjP5t9psGm9Tz+a0 +REOHEYP1MjEHbsu/gC2j9cyquYdv9qfJ1DZcKHlzrSKC/HVLlzHF/unWZ6Oq1vIfpdQ UVefcwrGx6kD+GKQwJ/5crcQZrGSDDwauorlkDgU6vmlM2vt+V3y4JbjgoxVt0XaGo/s 72cLoRXCIri/j4ni9sndeDnYU/W1fhSeyAxS1Rvf8k7GZfeKH5+yOeZk36GV4B7rfdMk nNb+tASvQycz6p78d8+qMdgL0Ry9/9FMUTzc7EuCf7TL52MfGyepchfVkYRiFHNdAXgh y7sA== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=5FBFec/Rw0Lr/gxSFUtV+nNMwGKP791vozuaSXI6GTE=; b=a4GQ1S7Nkz+ZNYWAwWXcaPRo4Y82sUj0cFEwrcnSXTHM9nmHMVHj///5NMz3dj6Vss zVd69bvyTiaEuk7FyOAm6BVIG34wMwpthnhDb9KZjptPc/ztW1eoFPI1InPxwmfA+JlB twLbbsUmbC04ypv7WIN3ko1XT8QFTltbEse4MabgZLTKbZ7RKx9jPli/N0XNIVCoBnRz oDKcRsw54A0hrdHQTrKgU2Ae2ZEgkICp1OlkUiwnYQ7H9AxUY05WtDoqkVPbO9V8b+VP gIy2TPbYC9Comnqn1gCeFDDAz5mrV9r92xDCD/tcQ6bi40IyoyB13jZy5lGWFr+xyFnG QOvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=PPA0HnVQ; dkim=pass header.i=@codeaurora.org header.s=default header.b=lGOOnRRM; 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 j68si8860393itg.5.2018.01.23.09.58.49; Tue, 23 Jan 2018 09:59:01 -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=@codeaurora.org header.s=default header.b=PPA0HnVQ; dkim=pass header.i=@codeaurora.org header.s=default header.b=lGOOnRRM; 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 S1752019AbeAWR5t (ORCPT + 99 others); Tue, 23 Jan 2018 12:57:49 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:60422 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751840AbeAWR5q (ORCPT ); Tue, 23 Jan 2018 12:57:46 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 017B86074C; Tue, 23 Jan 2018 17:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516730266; bh=W1VYohvKYaaBAuHXBzXb5bhb5U1BJr/olDWQTJ351A0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PPA0HnVQ2N6ZSXiRNQzC0oNP+WWyS00eD60a4RK5aVg00PGXyyKhG0DdXAfuUKahB RNH/QTpHlrgidMApHpImTSkpJP2gceQ6yjHhKjw/F53jai0nSNbtEh4+nPr3JdMiSW yTdd1OeFQeCsUEVB7litn1yzXCFR4/NlksvBnsbc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7F2DB60541; Tue, 23 Jan 2018 17:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1516730265; bh=W1VYohvKYaaBAuHXBzXb5bhb5U1BJr/olDWQTJ351A0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lGOOnRRMllThSinw6JKT/zHK74QX2W/Py8dW33vedJs/1CJAM9uqZItNEWoAw9eq3 cZyXSerYmowFjp9eTLLwAq67j6fijwRhHTB1LCByR7uFOXyWzenHSpCWeY2j8AxRR/ a2ISBTsZjnInuSyHZ2bVO0MKQaKcg1qVQVwav+OU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7F2DB60541 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org From: Lina Iyer To: tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, rnayak@codeaurora.org, asathyak@codeaurora.org, Lina Iyer Subject: [PATCH RFC 1/4] drivers: irqchip: pdc: add support for PDC interrupt controller Date: Tue, 23 Jan 2018 10:56:53 -0700 Message-Id: <20180123175656.11942-2-ilina@codeaurora.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180123175656.11942-1-ilina@codeaurora.org> References: <20180123175656.11942-1-ilina@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From : Archana Sathyakumar The Power Domain Controller (PDC) hardware block on Qualcomm SoCs houses an interrupt controller along with other domain control functions to handle interrupt related functions like handle falling edge or active low which are not detected at the GIC and handle wakeup interrupts. The interrupt controller is on an always-on domain for the purpose of waking up the processor, but only a subset of the processor's interrupts are routed through the PDC to the GIC. The PDC powers on the processor's domain, bringing the domain out of low power mode and replays the pending interrupts so the GIC may wake up the processor. Signed-off-by: Archana Sathyakumar Signed-off-by: Lina Iyer [Lina: Split out DT bindings target data and initialization changes] --- drivers/irqchip/Kconfig | 9 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/qcom-pdc.c | 282 +++++++++++++++++++++++++++++++++++++++++++++ drivers/irqchip/qcom-pdc.h | 30 +++++ 4 files changed, 322 insertions(+) create mode 100644 drivers/irqchip/qcom-pdc.c create mode 100644 drivers/irqchip/qcom-pdc.h diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index c70476b34a53..9d54151157d5 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -343,4 +343,13 @@ config MESON_IRQ_GPIO help Support Meson SoC Family GPIO Interrupt Multiplexer +config QCOM_PDC + bool "QCOM PDC" + depends on ARCH_QCOM + select IRQ_DOMAIN + select IRQ_DOMAIN_HIERARCHY + help + Power Domain Controller driver to manage and configure wakeup + IRQs for Qualcomm Technologies Inc.'s (QTI) mobile SoCs. + endmenu diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index d2df34a54d38..280723d83916 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -84,3 +84,4 @@ obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o obj-$(CONFIG_IRQ_UNIPHIER_AIDET) += irq-uniphier-aidet.o obj-$(CONFIG_ARCH_SYNQUACER) += irq-sni-exiu.o obj-$(CONFIG_MESON_IRQ_GPIO) += irq-meson-gpio.o +obj-$(CONFIG_QCOM_PDC) += qcom-pdc.o diff --git a/drivers/irqchip/qcom-pdc.c b/drivers/irqchip/qcom-pdc.c new file mode 100644 index 000000000000..57f1348bd81c --- /dev/null +++ b/drivers/irqchip/qcom-pdc.c @@ -0,0 +1,282 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qcom-pdc.h" + +#define PDC_MAX_IRQS 126 + +#define CLEAR_INTR(reg, intr) (reg & ~(1 << intr)) +#define ENABLE_INTR(reg, intr) (reg | (1 << intr)) + +#define IRQ_ENABLE_BANK 0x10 +#define IRQ_i_CFG 0x110 + +static DEFINE_SPINLOCK(pdc_lock); +static void __iomem *pdc_base; + +static int get_pdc_pin(irq_hw_number_t hwirq, void *data) +{ + int i; + struct pdc_pin *pdc_data = (struct pdc_pin *) data; + + for (i = 0; pdc_data[i].pin >= 0; i++) { + if (pdc_data[i].hwirq == hwirq) + return pdc_data[i].pin; + } + + return -EINVAL; +} + +static inline void pdc_enable_intr(struct irq_data *d, bool on) +{ + int pin_out = get_pdc_pin(d->hwirq, d->chip_data); + unsigned int index, mask; + u32 enable, r_enable; + unsigned long flags; + + if (pin_out < 0) + return; + + index = pin_out / 32; + mask = pin_out % 32; + spin_lock_irqsave(&pdc_lock, flags); + enable = readl_relaxed(pdc_base + IRQ_ENABLE_BANK + (index * + sizeof(uint32_t))); + enable = on ? ENABLE_INTR(enable, mask) : CLEAR_INTR(enable, mask); + writel_relaxed(enable, pdc_base + IRQ_ENABLE_BANK + (index * + sizeof(uint32_t))); + do { + r_enable = readl_relaxed(pdc_base + IRQ_ENABLE_BANK + + (index * sizeof(uint32_t))); + if (r_enable == enable) + break; + udelay(5); + } while (1); + spin_unlock_irqrestore(&pdc_lock, flags); + WARN_ON(r_enable != enable); +} + +static void qcom_pdc_gic_mask(struct irq_data *d) +{ + pdc_enable_intr(d, false); + irq_chip_mask_parent(d); +} + +static void qcom_pdc_gic_unmask(struct irq_data *d) +{ + pdc_enable_intr(d, true); + irq_chip_unmask_parent(d); +} + +static void qcom_pdc_gic_enable(struct irq_data *d) +{ + pdc_enable_intr(d, true); + irq_chip_enable_parent(d); +} + +static void qcom_pdc_gic_disable(struct irq_data *d) +{ + pdc_enable_intr(d, false); + irq_chip_disable_parent(d); +} + +/* + * GIC does not handle falling edge or active low. To allow falling edge and + * active low interrupts to be handled at GIC, PDC has an inverter that inverts + * falling edge into a rising edge and active low into an active high. + * For the inverter to work, the polarity bit in the IRQ_CONFIG register has to + * set as per the table below. + * (polarity, falling edge, rising edge ) ORIG POL CONV POLARITY + * 3'b0 00 Level sensitive active low (~~~|_____) (___|~~~~~) LOW + * 3'b0 10 Falling edge sensitive (~~~|__|~~) (___|~~|__) LOW + * 3'b1 00 Level senstive active High (___|~~~~~) (___|~~~~~) HIGH + * 3'b1 10 Rising edge sensitive (___|~~|__) (___|~~|__) HIGH + */ +enum pdc_irq_config_bits { + POLARITY_LOW = 0, // b000 + FALLING_EDGE = 2, // b010 + POLARITY_HIGH = 4, // b100 + RISING_EDGE = 6, // b110 +}; + +static int qcom_pdc_gic_set_type(struct irq_data *d, unsigned int type) +{ + int pin_out = get_pdc_pin(d->hwirq, d->chip_data); + u32 pdc_type = 0, config; + + if (pin_out < 0) + goto fwd_to_parent; + + switch (type) { + case IRQ_TYPE_EDGE_RISING: + pdc_type = RISING_EDGE; + break; + case IRQ_TYPE_EDGE_FALLING: + pdc_type = FALLING_EDGE; + break; + case IRQ_TYPE_LEVEL_HIGH: + pdc_type = POLARITY_HIGH; + break; + case IRQ_TYPE_LEVEL_LOW: + pdc_type = POLARITY_LOW; + break; + default: + pdc_type = POLARITY_HIGH; + break; + } + writel_relaxed(pdc_type, pdc_base + IRQ_i_CFG + + (pin_out * sizeof(uint32_t))); + + do { + config = readl_relaxed(pdc_base + IRQ_i_CFG + + (pin_out * sizeof(uint32_t))); + if (config == pdc_type) + break; + udelay(5); + } while (1); + + /* + * If type is edge triggered, forward that as Rising edge as PDC + * takes care of converting falling edge to rising edge signal + */ + if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) + type = IRQ_TYPE_EDGE_RISING; + + /* + * If type is level, then forward that as level high as PDC + * takes care of converting falling edge to rising edge signal + */ + if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) + type = IRQ_TYPE_LEVEL_HIGH; + +fwd_to_parent: + return irq_chip_set_type_parent(d, type); +} + +static struct irq_chip qcom_pdc_gic_chip = { + .name = "pdc-gic", + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = qcom_pdc_gic_mask, + .irq_enable = qcom_pdc_gic_enable, + .irq_unmask = qcom_pdc_gic_unmask, + .irq_disable = qcom_pdc_gic_disable, + .irq_retrigger = irq_chip_retrigger_hierarchy, + .irq_set_type = qcom_pdc_gic_set_type, + .flags = IRQCHIP_MASK_ON_SUSPEND | + IRQCHIP_SET_TYPE_MASKED | + IRQCHIP_SKIP_SET_WAKE, + .irq_set_vcpu_affinity = irq_chip_set_vcpu_affinity_parent, +#ifdef CONFIG_SMP + .irq_set_affinity = irq_chip_set_affinity_parent, +#endif +}; + +static int qcom_pdc_translate(struct irq_domain *d, + struct irq_fwspec *fwspec, unsigned long *hwirq, unsigned int *type) +{ + return d->parent->ops->translate(d->parent, fwspec, hwirq, type); +} + +static int qcom_pdc_alloc(struct irq_domain *domain, + unsigned int virq, unsigned int nr_irqs, void *data) +{ + struct irq_fwspec *fwspec = data; + struct irq_fwspec parent_fwspec; + irq_hw_number_t hwirq; + int i; + unsigned int type; + int ret; + + ret = qcom_pdc_translate(domain, fwspec, &hwirq, &type); + if (ret) + return -EINVAL; + + for (i = 0; i < nr_irqs; i++) + irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i, + &qcom_pdc_gic_chip, domain->host_data); + + parent_fwspec = *fwspec; + parent_fwspec.fwnode = domain->parent->fwnode; + + return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, + &parent_fwspec); +} + +static const struct irq_domain_ops qcom_pdc_ops = { + .translate = qcom_pdc_translate, + .alloc = qcom_pdc_alloc, + .free = irq_domain_free_irqs_common, +}; + +static const struct of_device_id pdc_table[] = { + { } +}; +MODULE_DEVICE_TABLE(of, pdc_table); + +int qcom_pdc_init(struct device_node *node, struct device_node *parent) +{ + struct irq_domain *parent_domain, *pdc_domain; + const struct pdc_pin *data; + const struct of_device_id *id; + int ret; + + id = of_match_node(pdc_table, node); + if (id) + data = id->data; + else + return -ENODEV; + + pdc_base = of_iomap(node, 0); + if (!pdc_base) { + pr_err("%s(): unable to map PDC registers\n", node->full_name); + return -ENXIO; + } + + parent_domain = irq_find_host(parent); + if (!parent_domain) { + pr_err("unable to obtain PDC parent domain\n"); + ret = -ENXIO; + goto failure; + } + + pdc_domain = irq_domain_add_hierarchy(parent_domain, 0, PDC_MAX_IRQS, + node, &qcom_pdc_ops, (void *)data); + if (!pdc_domain) { + pr_err("GIC domain add failed\n"); + ret = -ENOMEM; + goto failure; + } + + pdc_domain->name = "qcom,pdc"; + return 0; + +failure: + iounmap(pdc_base); + return ret; +} diff --git a/drivers/irqchip/qcom-pdc.h b/drivers/irqchip/qcom-pdc.h new file mode 100644 index 000000000000..b5b64390175e --- /dev/null +++ b/drivers/irqchip/qcom-pdc.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only 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. + * + */ + +#ifndef __QCOM_PDC_H__ +#define __QCOM_PDC_H__ + +#include + +/** + * pdc_pin: Mapping of PDC port to hwirq + * + * @pin: PDC port for the IRQ + * @hwirq: hw IRQ number + */ +struct pdc_pin { + int pin; + irq_hw_number_t hwirq; +}; + +#endif /* __QCOM_PDC_H__ */ -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project