From: Ash Logan <ash@heyquark.com>
To: krzysztof.kozlowski+dt@linaro.org, paulus@samba.org,
mpe@ellerman.id.au, christophe.leroy@csgroup.eu,
robh+dt@kernel.org, benh@kernel.crashing.org,
segher@kernel.crashing.org, pali@kernel.org
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
j.ne@posteo.net, linkmauve@linkmauve.fr,
rw-r-r-0644@protonmail.com, devicetree@vger.kernel.org,
joel@jms.id.au
Subject: [PATCH v4 07/11] powerpc: wiiu: espresso interrupt controller support
Date: Sat, 19 Nov 2022 22:30:37 +1100 [thread overview]
Message-ID: <20221119113041.284419-8-ash@heyquark.com> (raw)
In-Reply-To: <20221119113041.284419-1-ash@heyquark.com>
Add support for the "Espresso" interrupt controller in the Nintendo Wii
U.
Signed-off-by: Ash Logan <ash@heyquark.com>
Co-developed-by: Roberto Van Eeden <rw-r-r-0644@protonmail.com>
Signed-off-by: Roberto Van Eeden <rw-r-r-0644@protonmail.com>
---
arch/powerpc/platforms/wiiu/Makefile | 1 +
arch/powerpc/platforms/wiiu/espresso-pic.c | 183 +++++++++++++++++++++
arch/powerpc/platforms/wiiu/espresso-pic.h | 59 +++++++
3 files changed, 243 insertions(+)
create mode 100644 arch/powerpc/platforms/wiiu/espresso-pic.c
create mode 100644 arch/powerpc/platforms/wiiu/espresso-pic.h
diff --git a/arch/powerpc/platforms/wiiu/Makefile b/arch/powerpc/platforms/wiiu/Makefile
index b1e0e1307f6e..aabf4b43e806 100644
--- a/arch/powerpc/platforms/wiiu/Makefile
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_WIIU) += espresso-pic.o
obj-$(CONFIG_LATTEIPC_UDBG) += udbg_latteipc.o
diff --git a/arch/powerpc/platforms/wiiu/espresso-pic.c b/arch/powerpc/platforms/wiiu/espresso-pic.c
new file mode 100644
index 000000000000..1aa5d88002d5
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/espresso-pic.c
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Nintendo Wii U "Espresso" interrupt controller support
+ * Copyright (C) 2022 The linux-wiiu Team
+ *
+ * Based on flipper-pic.c
+ * Copyright (C) 2004-2009 The GameCube Linux Team
+ * Copyright (C) 2007-2009 Albert Herranz
+ */
+
+#define DRV_MODULE_NAME "espresso-pic"
+#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/io.h>
+#include "espresso-pic.h"
+
+static DEFINE_PER_CPU(struct espresso_pic *, espresso_pic_cpu);
+
+/*
+ * IRQ chip operations
+ */
+
+static void espresso_pic_mask_and_ack(struct irq_data *d)
+{
+ struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+ u32 mask = 1 << irqd_to_hwirq(d);
+
+ out_be32(&pic->icr, mask);
+ clrbits32(&pic->imr, mask);
+}
+
+static void espresso_pic_ack(struct irq_data *d)
+{
+ struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+ u32 mask = 1 << irqd_to_hwirq(d);
+
+ out_be32(&pic->icr, mask);
+}
+
+static void espresso_pic_mask(struct irq_data *d)
+{
+ struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+ u32 mask = 1 << irqd_to_hwirq(d);
+
+ clrbits32(&pic->imr, mask);
+}
+
+static void espresso_pic_unmask(struct irq_data *d)
+{
+ struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+ u32 mask = 1 << irqd_to_hwirq(d);
+
+ setbits32(&pic->imr, mask);
+}
+
+static struct irq_chip espresso_pic_chip = {
+ .name = "espresso-pic",
+ .irq_ack = espresso_pic_ack,
+ .irq_mask_ack = espresso_pic_mask_and_ack,
+ .irq_mask = espresso_pic_mask,
+ .irq_unmask = espresso_pic_unmask,
+};
+
+/*
+ * Domain Ops
+ */
+
+static int espresso_pic_match(struct irq_domain *h, struct device_node *node,
+ enum irq_domain_bus_token bus_token)
+{
+ if (h->fwnode == &node->fwnode) {
+ pr_debug("espresso-pic: %s IRQ matches with this driver\n",
+ node->name);
+ return 1;
+ }
+ return 0;
+}
+
+static int espresso_pic_alloc(struct irq_domain *h, unsigned int virq,
+ unsigned int nr_irqs, void *arg)
+{
+ unsigned int i;
+ struct irq_fwspec *fwspec = arg;
+ irq_hw_number_t hwirq = fwspec->param[0];
+
+ for (i = 0; i < nr_irqs; i++) {
+ irq_set_chip_data(virq + i, h->host_data);
+ irq_set_status_flags(virq + i, IRQ_LEVEL);
+ irq_set_chip_and_handler(virq + i, &espresso_pic_chip,
+ handle_level_irq);
+ irq_domain_set_hwirq_and_chip(h, virq + i, hwirq + i,
+ &espresso_pic_chip, h->host_data);
+ }
+ return 0;
+}
+
+static void espresso_pic_free(struct irq_domain *h, unsigned int virq,
+ unsigned int nr_irqs)
+{
+ pr_debug("free\n");
+}
+
+const struct irq_domain_ops espresso_pic_ops = {
+ .match = espresso_pic_match,
+ .alloc = espresso_pic_alloc,
+ .free = espresso_pic_free,
+};
+
+/* Store irq domain for espresso_pic_get_irq (the function gets no arguments) */
+static struct irq_domain *espresso_irq_domain;
+
+unsigned int espresso_pic_get_irq(void)
+{
+ struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+ u32 irq_status, irq;
+
+ irq_status = in_be32(&pic->icr) & in_be32(&pic->imr);
+
+ if (irq_status == 0)
+ return 0; /* No IRQs pending */
+
+ /* Return first IRQ */
+ irq = __ffs(irq_status);
+ return irq_linear_revmap(espresso_irq_domain, irq);
+}
+
+void __init espresso_pic_init(void)
+{
+ struct device_node *np =
+ of_find_compatible_node(NULL, NULL, "nintendo,espresso-pic");
+ struct irq_domain *host;
+ struct resource res;
+ void __iomem *regbase;
+ unsigned int cpu;
+
+ if (!np) {
+ pr_err("could not find device node\n");
+ return;
+ }
+
+ if (of_address_to_resource(np, 0, &res) != 0) {
+ pr_err("could not find resource address\n");
+ goto out;
+ }
+
+ regbase = ioremap(res.start, resource_size(&res));
+ if (IS_ERR(regbase)) {
+ pr_err("could not map controller\n");
+ goto out;
+ }
+
+ for_each_present_cpu(cpu) {
+ struct espresso_pic **pic = per_cpu_ptr(&espresso_pic_cpu, cpu);
+
+ /* Compute pic address */
+ *pic = regbase + (sizeof(struct espresso_pic) * cpu);
+
+ /* Mask and Ack all IRQs */
+ out_be32(&(*pic)->imr, 0);
+ out_be32(&(*pic)->icr, 0xFFFFFFFF);
+ }
+
+ host = irq_domain_add_linear(np, ESPRESSO_NR_IRQS, &espresso_pic_ops,
+ NULL);
+ if (!host) {
+ pr_err("failed to allocate irq_domain\n");
+ goto out;
+ }
+
+ /* Save irq domain for espresso_pic_get_irq */
+ espresso_irq_domain = host;
+
+ irq_set_default_host(host);
+
+out:
+ of_node_put(np);
+}
diff --git a/arch/powerpc/platforms/wiiu/espresso-pic.h b/arch/powerpc/platforms/wiiu/espresso-pic.h
new file mode 100644
index 000000000000..b5b4e44ad60e
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/espresso-pic.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Nintendo Wii U "Espresso" interrupt controller support
+ * Copyright (C) 2022 The linux-wiiu Team
+ */
+
+#ifndef __ESPRESSO_PIC_H
+#define __ESPRESSO_PIC_H
+
+/*
+ * Instead of using COS custom IRQ remapping, the normal IRQ mapping is used:
+ *
+ * IRQ Description
+ * -------------------------------------------
+ * 0 Error
+ * 1 Unused
+ * 2 Unused
+ * 3 Audio Interface (TV)
+ * 4 Unused
+ * 5 DSP Accelerator
+ * 6 DSP
+ * 7 DSP DMA
+ * 8 Unused
+ * 9 Unused
+ * 10 GPIPPC (?)
+ * 11 Unused
+ * 12 Audio Interface (Gamepad)
+ * 13 I2C
+ * 14 Unused
+ * 15 Unused
+ * 16 Unused
+ * 17 Unused
+ * 18 Unused
+ * 19 Unused
+ * 20 Unused
+ * 21 Unused
+ * 22 Unused
+ * 23 GX2
+ * 24 Latte IRQ Controller
+ * 25 Unused
+ * 26 IPC (CPU2)
+ * 27 Unused
+ * 28 IPC (CPU1)
+ * 29 Unused
+ * 30 IPC (CPU0)
+ * 31 Unused
+ */
+
+struct espresso_pic {
+ __be32 icr; /* Triggered IRQs */
+ __be32 imr; /* Allowed IRQs */
+} __packed;
+
+#define ESPRESSO_NR_IRQS 32
+
+unsigned int espresso_pic_get_irq(void);
+void espresso_pic_init(void);
+
+#endif
--
2.38.1
next prev parent reply other threads:[~2022-11-19 11:32 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 4:43 [PATCH 00/12] powerpc: Nintendo Wii U support Ash Logan
2022-03-02 4:43 ` [PATCH 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-03-02 13:28 ` Rob Herring
2022-03-02 4:43 ` [PATCH 02/12] powerpc: wiiu: device tree Ash Logan
2022-03-02 13:36 ` Rob Herring
2022-03-03 2:41 ` Ash Logan
2022-03-02 4:43 ` [PATCH 03/12] powerpc: wiiu: bootwrapper support Ash Logan
2022-03-02 4:43 ` [PATCH 04/12] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-03-02 4:43 ` [PATCH 05/12] powerpc: wiiu: declare as non-coherent Ash Logan
2022-03-02 4:44 ` [PATCH 06/12] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-03-02 4:44 ` [PATCH 07/12] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-03-02 4:44 ` [PATCH 08/12] powerpc: wiiu: latte " Ash Logan
2022-03-02 4:44 ` [PATCH 09/12] powerpc: espresso processor support Ash Logan
2022-03-02 4:44 ` [PATCH 10/12] powerpc: wiiu: platform support Ash Logan
2022-03-02 4:44 ` [PATCH 11/12] powerpc: wiiu: don't enforce flat memory Ash Logan
2022-05-13 22:43 ` Pali Rohár
2022-05-20 3:41 ` Ash Logan
2022-05-20 8:04 ` Pali Rohár
2022-05-20 10:44 ` Ash Logan
2022-05-20 12:30 ` Pali Rohár
2022-06-09 22:24 ` Pali Rohár
2022-08-08 18:40 ` Pali Rohár
2022-09-08 15:25 ` Christophe Leroy
2022-09-08 15:35 ` Pali Rohár
2022-09-08 20:17 ` Fragmented physical memory on powerpc/32 Pali Rohár
2022-09-10 9:39 ` Christophe Leroy
2022-09-12 14:48 ` Mike Rapoport
2022-09-12 21:16 ` Pali Rohár
2022-09-13 6:11 ` Christophe Leroy
2022-09-13 12:36 ` Christophe Leroy
2022-09-14 9:32 ` Mike Rapoport
2022-09-14 9:43 ` Christophe Leroy
2022-09-14 15:55 ` Mike Rapoport
2022-09-14 19:56 ` Pali Rohár
2022-03-02 4:44 ` [PATCH 12/12] powerpc: wiiu: Add minimal default config Ash Logan
2022-06-22 13:10 ` [PATCH v2 00/12] powerpc: Nintendo Wii U support Ash Logan
2022-06-22 13:10 ` [PATCH v2 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-06-22 13:10 ` [PATCH v2 02/12] powerpc: wiiu: device tree Ash Logan
2022-06-22 13:10 ` [PATCH v2 03/12] powerpc: wiiu: bootwrapper support Ash Logan
2022-06-22 13:10 ` [PATCH v2 04/12] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-06-22 13:10 ` [PATCH v2 05/12] powerpc: wiiu: declare as non-coherent Ash Logan
2022-06-22 13:10 ` [PATCH v2 06/12] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-06-27 0:15 ` kernel test robot
2022-06-22 13:10 ` [PATCH v2 07/12] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-06-22 13:10 ` [PATCH v2 08/12] powerpc: wiiu: latte " Ash Logan
2022-06-27 2:51 ` kernel test robot
2022-06-22 13:10 ` [PATCH v2 09/12] powerpc: espresso processor support Ash Logan
2022-06-22 13:10 ` [PATCH v2 10/12] powerpc: wiiu: platform support Ash Logan
2022-06-22 13:10 ` [PATCH v2 11/12] powerpc: wiiu: don't enforce flat memory Ash Logan
2022-06-22 13:10 ` [PATCH v2 12/12] powerpc: wiiu: Add minimal default config Ash Logan
2022-06-28 13:31 ` [PATCH v3 00/12] powerpc: Nintendo Wii U support Ash Logan
2022-06-28 13:31 ` [PATCH v3 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-06-29 9:52 ` Krzysztof Kozlowski
2022-06-28 13:31 ` [PATCH v3 02/12] powerpc: wiiu: device tree Ash Logan
2022-06-29 9:58 ` Krzysztof Kozlowski
2022-06-29 16:13 ` Segher Boessenkool
2022-06-29 18:13 ` Krzysztof Kozlowski
2022-06-29 20:28 ` Segher Boessenkool
2022-06-28 13:31 ` [PATCH v3 03/12] powerpc: wiiu: bootwrapper support Ash Logan
2022-06-28 13:31 ` [PATCH v3 04/12] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-06-28 13:31 ` [PATCH v3 05/12] powerpc: wiiu: declare as non-coherent Ash Logan
2022-06-28 13:31 ` [PATCH v3 06/12] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-06-28 13:31 ` [PATCH v3 07/12] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-06-28 13:31 ` [PATCH v3 08/12] powerpc: wiiu: latte " Ash Logan
2022-06-28 13:31 ` [PATCH v3 09/12] powerpc: espresso processor support Ash Logan
2022-06-28 13:31 ` [PATCH v3 10/12] powerpc: wiiu: platform support Ash Logan
2022-06-28 13:31 ` [PATCH v3 11/12] powerpc: wiiu: don't enforce flat memory Ash Logan
2022-06-28 13:31 ` [PATCH v3 12/12] powerpc: wiiu: add minimal default config Ash Logan
2022-11-15 14:47 ` [PATCH v3 00/12] powerpc: Nintendo Wii U support Christophe Leroy
2022-11-19 11:30 ` [PATCH v4 00/11] " Ash Logan
2022-11-19 11:30 ` [PATCH v4 01/11] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-11-19 21:36 ` Rob Herring
2022-11-20 15:30 ` Rob Herring
2024-02-20 16:20 ` Christophe Leroy
2024-02-20 16:24 ` Krzysztof Kozlowski
2022-11-19 11:30 ` [PATCH v4 02/11] powerpc: wiiu: device tree Ash Logan
2022-11-19 11:30 ` [PATCH v4 03/11] powerpc: wiiu: bootwrapper support Ash Logan
2022-11-19 11:30 ` [PATCH v4 04/11] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-11-19 11:30 ` [PATCH v4 05/11] powerpc: wiiu: declare as non-coherent Ash Logan
2022-11-19 11:30 ` [PATCH v4 06/11] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-11-19 11:30 ` Ash Logan [this message]
2022-11-19 11:30 ` [PATCH v4 08/11] powerpc: wiiu: latte interrupt controller support Ash Logan
2022-11-19 11:30 ` [PATCH v4 09/11] powerpc: espresso processor support Ash Logan
2022-11-19 11:30 ` [PATCH v4 10/11] powerpc: wiiu: platform support Ash Logan
2022-11-19 11:30 ` [PATCH v4 11/11] powerpc: wiiu: add minimal default config Ash Logan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221119113041.284419-8-ash@heyquark.com \
--to=ash@heyquark.com \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@csgroup.eu \
--cc=devicetree@vger.kernel.org \
--cc=j.ne@posteo.net \
--cc=joel@jms.id.au \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linkmauve@linkmauve.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=pali@kernel.org \
--cc=paulus@samba.org \
--cc=robh+dt@kernel.org \
--cc=rw-r-r-0644@protonmail.com \
--cc=segher@kernel.crashing.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).