From patchwork Mon Jan 4 13:43:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 11996791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4508CC433DB for ; Mon, 4 Jan 2021 13:43:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06C93207B1 for ; Mon, 4 Jan 2021 13:43:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725830AbhADNn0 (ORCPT ); Mon, 4 Jan 2021 08:43:26 -0500 Received: from mout.gmx.net ([212.227.15.18]:49203 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbhADNn0 (ORCPT ); Mon, 4 Jan 2021 08:43:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609767711; bh=Ua1mWCOr4LTqZEzaZB63R+wqOSGeuV/pZ/FWoM0VPhU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=XXVA98H338CGlNh0jAaSwxv9QPyaCWoBJXpSuXxmOcUB0ViwMTcUcgBNUJCc8wdHx lzCDTO1FhQnolhtc3xQxsw1X1h8Op4LyS+Xlg9nxYch4xNqKCi5JNpeMuSt937ukVl A022gXPvqw1zqMW5etTp7epzSb/uODWj1wHnq7wg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.128.181.212]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MuUj2-1k5HKf1KMc-00rZ1N; Mon, 04 Jan 2021 14:41:51 +0100 Date: Mon, 4 Jan 2021 15:43:24 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de Subject: [PATCH 1/6] Revert "MIPS: Remove unused R4300 CPU support" Message-Id: <20210104154324.3a9bc605ad06f9e923edc71f@gmx.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K1:qSihf0RbTxq0atQcjyjdGnvf6znumx/nJD6Aa1tcfDfwZlGaSBp y+3cQpUiiY36HZkD0wTzMIkoBWbjTT4cqKHPy3xvLo75Rcs2D4SoKGx2gjn2GjKHfsX8GmJ d/cp6eHU/JZbAfCGCohDtJGvXDuaoYaTJrAc6eLcxPkacpau9tw7ezjVcB92Ea+qj0S0Irk j5gWhbqi+gVm6Drh5NQUA== X-UI-Out-Filterresults: notjunk:1;V03:K0:GohQ31yBFJY=:xzRDRzygj8EHcf/k6PKLTt kBovM5U0rgmTWnQJJ4yXobtMKiyOV2UU/khBhaPZ6+I8UELheiKxjyj2mP6kqn9HjQtyIMDgb 6xUNU3hHV1M+u5Xxis6afOtsbblQUI12wHkua+T9jMqSlsrC+TLPgt+rmJjAYlEXAShm5iMyt EHwNYZlP/dzyGdOke+HIfuDQ3/qvEXNGGrWM3Cy7OzleIR00EZRFY4BdqUfgcxiRDTggyyEUC bgQn6kBlTy6YKbjx/1gqlJYeVwT8e6NQlErzXHeDWlCJHsPClZGpDvEWGTSoA7g6SPJXKxF5W 5IDbNfOa5S8A9VMAIA69UoXoOlHLEkM1lwH4SO8uosBZ/AG0gZ/BMnfBDXyFIJJComRCCsUlt 3X13w93loj9Q+A48BIxKaa/xjOv81ghMGkMOoSpr2UqDMeA9vsku7erMuhWAv43ir1xvDc6yD Z/KTVR1b3Pt3kuPR+S0y/IHt1MextftVi+341eUA325SiBTZ1jLjLUZcKlCWR9CjBig9D2NX1 N0lJ/3CxYQpXDCkH4gKLcE5yu+nEddiKkv7dGHcyoz7cOjFtycPTR1S6MudkiCsG9wRU3zSps VAZdv5hgwXPd1ml3qXPiAsolyuId4M2GyaLoqGoUdnNR4Y5EgFkNJFrZQBMGGMdLz4JpXoaYu JUHSycJb0pRxI/OGf1CGIJbTPTY0HlrdXFchYm+WkrLGe50x5zyWEY5gAw4Zgj9emBHaRbsvg WHTTGyz8vm1yYPPbTTvniaLVGiT5amr26b6/szJdecTAhF+TphfgOQfCpEivSoUSOApYNc/qz y8aAh6IE77s2/smKAPcgU51fEt5lWKDBzo1U46sm87u3NoeZ/xVX0u6fBX+mmypK1NpF65GVy ZtfdPquHOAu6C+g/qlrw== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This reverts commit f9065b54d437c4660e3d974ad9ce5188c068cd76. We're adding Nintendo 64 support, so the VR4300 is no longer unused. Signed-off-by: Lauri Kasanen --- arch/mips/Kconfig | 12 ++++++++++++ arch/mips/Makefile | 1 + arch/mips/include/asm/cpu-type.h | 5 +++++ arch/mips/include/asm/cpu.h | 2 +- arch/mips/include/asm/vermagic.h | 2 ++ arch/mips/kernel/cpu-probe.c | 9 +++++++++ arch/mips/kernel/idle.c | 1 + arch/mips/mm/c-r4k.c | 1 + arch/mips/mm/tlbex.c | 1 + 9 files changed, 33 insertions(+), 1 deletion(-) -- 2.6.2 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 2000bb2..4b52588 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -1661,6 +1661,15 @@ config CPU_VR41XX kernel built with this option will not run on any other type of processor or vice versa. +config CPU_R4300 + bool "R4300" + depends on SYS_HAS_CPU_R4300 + select CPU_SUPPORTS_32BIT_KERNEL + select CPU_SUPPORTS_64BIT_KERNEL + select CPU_HAS_LOAD_STORE_LR + help + MIPS Technologies R4300-series processors. + config CPU_R4X00 bool "R4x00" depends on SYS_HAS_CPU_R4X00 @@ -1995,6 +2004,9 @@ config SYS_HAS_CPU_TX39XX config SYS_HAS_CPU_VR41XX bool +config SYS_HAS_CPU_R4300 + bool + config SYS_HAS_CPU_R4X00 bool diff --git a/arch/mips/Makefile b/arch/mips/Makefile index 0d0f29d..d7d8c20 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -141,6 +141,7 @@ cflags-y += -fno-stack-check # cflags-$(CONFIG_CPU_R3000) += -march=r3000 cflags-$(CONFIG_CPU_TX39XX) += -march=r3900 +cflags-$(CONFIG_CPU_R4300) += -march=r4300 -Wa,--trap cflags-$(CONFIG_CPU_VR41XX) += -march=r4100 -Wa,--trap cflags-$(CONFIG_CPU_R4X00) += -march=r4600 -Wa,--trap cflags-$(CONFIG_CPU_TX49XX) += -march=r4600 -Wa,--trap diff --git a/arch/mips/include/asm/cpu-type.h b/arch/mips/include/asm/cpu-type.h index 3288cef..2be5d7b 100644 --- a/arch/mips/include/asm/cpu-type.h +++ b/arch/mips/include/asm/cpu-type.h @@ -122,6 +122,11 @@ static inline int __pure __get_cpu_type(const int cpu_type) case CPU_VR4181A: #endif +#ifdef CONFIG_SYS_HAS_CPU_R4300 + case CPU_R4300: + case CPU_R4310: +#endif + #ifdef CONFIG_SYS_HAS_CPU_R4X00 case CPU_R4000PC: case CPU_R4000SC: diff --git a/arch/mips/include/asm/cpu.h b/arch/mips/include/asm/cpu.h index c9222cc..9e6211e 100644 --- a/arch/mips/include/asm/cpu.h +++ b/arch/mips/include/asm/cpu.h @@ -302,7 +302,7 @@ enum cpu_type_enum { /* * R4000 class processors */ - CPU_R4000PC, CPU_R4000SC, CPU_R4000MC, CPU_R4200, + CPU_R4000PC, CPU_R4000SC, CPU_R4000MC, CPU_R4200, CPU_R4300, CPU_R4310, CPU_R4400PC, CPU_R4400SC, CPU_R4400MC, CPU_R4600, CPU_R4640, CPU_R4650, CPU_R4700, CPU_R5000, CPU_R5500, CPU_NEVADA, CPU_R10000, CPU_R12000, CPU_R14000, CPU_R16000, CPU_VR41XX, CPU_VR4111, CPU_VR4121, diff --git a/arch/mips/include/asm/vermagic.h b/arch/mips/include/asm/vermagic.h index 4d2dae0..371c187 100644 --- a/arch/mips/include/asm/vermagic.h +++ b/arch/mips/include/asm/vermagic.h @@ -26,6 +26,8 @@ #define MODULE_PROC_FAMILY "TX39XX " #elif defined CONFIG_CPU_VR41XX #define MODULE_PROC_FAMILY "VR41XX " +#elif defined CONFIG_CPU_R4300 +#define MODULE_PROC_FAMILY "R4300 " #elif defined CONFIG_CPU_R4X00 #define MODULE_PROC_FAMILY "R4X00 " #elif defined CONFIG_CPU_TX49XX diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c index e685369..84f7034 100644 --- a/arch/mips/kernel/cpu-probe.c +++ b/arch/mips/kernel/cpu-probe.c @@ -1154,6 +1154,15 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) break; } break; + case PRID_IMP_R4300: + c->cputype = CPU_R4300; + __cpu_name[cpu] = "R4300"; + set_isa(c, MIPS_CPU_ISA_III); + c->fpu_msk31 |= FPU_CSR_CONDX; + c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR | + MIPS_CPU_LLSC; + c->tlbsize = 32; + break; case PRID_IMP_R4600: c->cputype = CPU_R4600; __cpu_name[cpu] = "R4600"; diff --git a/arch/mips/kernel/idle.c b/arch/mips/kernel/idle.c index 18e69eb..1aca3b4 100644 --- a/arch/mips/kernel/idle.c +++ b/arch/mips/kernel/idle.c @@ -151,6 +151,7 @@ void __init check_wait(void) cpu_wait = r39xx_wait; break; case CPU_R4200: +/* case CPU_R4300: */ case CPU_R4600: case CPU_R4640: case CPU_R4650: diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c index 9cede7c..da7796e 100644 --- a/arch/mips/mm/c-r4k.c +++ b/arch/mips/mm/c-r4k.c @@ -1164,6 +1164,7 @@ static void probe_pcache(void) case CPU_R4400PC: case CPU_R4400SC: case CPU_R4400MC: + case CPU_R4300: icache_size = 1 << (12 + ((config & CONF_IC) >> 9)); c->icache.linesz = 16 << ((config & CONF_IB) >> 5); c->icache.ways = 1; diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c index a7521b8..0fb1db8 100644 --- a/arch/mips/mm/tlbex.c +++ b/arch/mips/mm/tlbex.c @@ -549,6 +549,7 @@ void build_tlb_write_entry(u32 **p, struct uasm_label **l, tlbw(p); break; + case CPU_R4300: case CPU_5KC: case CPU_TX49XX: case CPU_PR4450: From patchwork Mon Jan 4 13:43:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 11996793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3004C433DB for ; Mon, 4 Jan 2021 13:44:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 986DC207B1 for ; Mon, 4 Jan 2021 13:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbhADNnz (ORCPT ); Mon, 4 Jan 2021 08:43:55 -0500 Received: from mout.gmx.net ([212.227.15.19]:34003 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbhADNnz (ORCPT ); Mon, 4 Jan 2021 08:43:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609767740; bh=7/8SFtQFQZ9J5RdoPAEE4o18g4xoje7EMEu4dh4R6ug=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=VGXZ6am3YiUZd1fy1ZsB7Z5Tsf1MfPxY/zqWQgxvfEAOkCwzlVGIl0SuXFrp+BvaV nMmnnNe5fm/3HnZ0a4ZSxJQ3QTVhHJdDpOJ3nHUCAy4QSj5k2PWtA7S2AFLlb0OzoU vG2v1Pnu3Z5X3Z0rsQK74K7ZqMb6/jj2R+k6vb4g= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.128.181.212]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MHXFr-1kixiM2oIT-00DWwI; Mon, 04 Jan 2021 14:42:19 +0100 Date: Mon, 4 Jan 2021 15:43:57 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de Subject: [PATCH 2/6] mips: Add N64 machine type Message-Id: <20210104154357.6cf126150407ba4839630177@gmx.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K1:OJQzYlAQHGvqglhzmMNYAoNi/+B4rR+IEp7KJrljjbZ79+SgfB1 +9e5q17kWg6JckSicw9p21whxskThRB+unmUT4gqF73PgKOJT6mi84ibVY99lntDvUJcUaH nLSqKRklLNRkzzDXHfzzuTMJl/AxBPyuBEhSDIxYAALlJbT3qYPm7rmxCV78SblRHAkuU0G lNWytrkNzObwHAZHY3vpQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:9MZtAmzKUHE=:rzyc0jc63jrfWCOg7VP7mS A0tbpXtM6U/J/m3sRV0vsU4Q/Xs25eEGg7KieQ6BdJuI4mOZXWpxKjOzZBQFRkAcht2cJA9Z3 XP7z+6VZuLLQgXkVlEAXbpnql0NkJpqiKp6NvDaX8WWLiuENcbZE5sbdl1W+RAeKw+PwLZM7p hVzTLRA/BeRjXVpS/WAMA39MHAb0Ug/jps7/f/H1BsMioC23X9R88imgUzpBEQWTTYYq+S5AW GZngwkWhD178H/OHkNJx07GGTQKXblO2oK4GTy1CE7nvrDLy0CGudc3x0CrS7lwJvZ5BZiL+r iFT649lQkvNtlBzYMflHqN6AWvMYUvqnlA7ryC9rJVQOXCwbuu/IkjUFa+a9T/FTORnwVreC/ 5JcpTxF/nx4OcgVdysZ4aUjCP9u3djh1l9xrOdAnf76CIQovIIrKutgPKTzRbnwyvs9k7AZQy G659fu0cQvDF6KvTyQJkA4uAoYv3IjvRfiqD274D6AWkXtpcFKkiJzhFgBph64InMyNa9Fcwi yNhYwydjgRSoyLkPB8vi7wi52jK3uUe8hR1qOwzxD/91W6W+iCeRSJhQMAqjW/VvAJFJwM8Ot +UqnpqRV/ZRvtXPMvdWlXY2YThFr36C/bAJuK1JsdyfeLsl7RmnR5N7V1nUVILHp22CQhCNHJ 7Oh0pNTS7cOfGhmsxHCQ9nqdTmX8xS62QrM8lg1/ebGx0DfsHRFMMDjoB5RAE7F2GW2u+Yu6K VX5/hf7r+inqvZEL6IbhMBArqOwwQU3Z3j6mTFqdXyRihl/lJy3CaL/uLjprEGBNqoq2HODqY XEHxxCLQbv0r5Q7Gwn7aNNr/XT6WHYBuX8DERnrry7n6cxXbezGocShpr3y5YAi9IxlKx/u57 aX9+bZoX8IcVBWo/fvdw== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Signed-off-by: Lauri Kasanen --- arch/mips/Kbuild.platforms | 1 + arch/mips/Kconfig | 12 ++++ arch/mips/include/asm/mach-n64/irq.h | 9 +++ arch/mips/include/asm/n64/irq.h | 26 ++++++++ arch/mips/n64/Makefile | 6 ++ arch/mips/n64/Platform | 7 +++ arch/mips/n64/init.c | 119 +++++++++++++++++++++++++++++++++++ arch/mips/n64/irq.c | 16 +++++ 8 files changed, 196 insertions(+) create mode 100644 arch/mips/include/asm/mach-n64/irq.h create mode 100644 arch/mips/include/asm/n64/irq.h create mode 100644 arch/mips/n64/Makefile create mode 100644 arch/mips/n64/Platform create mode 100644 arch/mips/n64/init.c create mode 100644 arch/mips/n64/irq.c -- 2.6.2 diff --git a/arch/mips/Kbuild.platforms b/arch/mips/Kbuild.platforms index 5483e38..e4f6e49 100644 --- a/arch/mips/Kbuild.platforms +++ b/arch/mips/Kbuild.platforms @@ -18,6 +18,7 @@ platform-$(CONFIG_MACH_LOONGSON2EF) += loongson2ef/ platform-$(CONFIG_MACH_LOONGSON32) += loongson32/ platform-$(CONFIG_MACH_LOONGSON64) += loongson64/ platform-$(CONFIG_MIPS_MALTA) += mti-malta/ +platform-$(CONFIG_MACH_NINTENDO64) += n64/ platform-$(CONFIG_NLM_COMMON) += netlogic/ platform-$(CONFIG_PIC32MZDA) += pic32/ platform-$(CONFIG_MACH_PISTACHIO) += pistachio/ diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 4b52588..1b0aae0 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -605,6 +605,18 @@ config MACH_VR41XX select SYS_SUPPORTS_MIPS16 select GPIOLIB +config MACH_NINTENDO64 + bool "Nintendo 64 console" + select CEVT_R4K + select CSRC_R4K + select SYS_HAS_CPU_R4300 + select SYS_SUPPORTS_BIG_ENDIAN + select SYS_SUPPORTS_ZBOOT + select SYS_SUPPORTS_32BIT_KERNEL + select SYS_SUPPORTS_64BIT_KERNEL + select DMA_NONCOHERENT + select IRQ_MIPS_CPU + config RALINK bool "Ralink based machines" select CEVT_R4K diff --git a/arch/mips/include/asm/mach-n64/irq.h b/arch/mips/include/asm/mach-n64/irq.h new file mode 100644 index 0000000..4d4a1ea --- /dev/null +++ b/arch/mips/include/asm/mach-n64/irq.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MACH_N64_IRQ_H +#define __ASM_MACH_N64_IRQ_H + +#include /* for MIPS_CPU_IRQ_BASE */ + +#include + +#endif /* __ASM_MACH_N64_IRQ_H */ diff --git a/arch/mips/include/asm/n64/irq.h b/arch/mips/include/asm/n64/irq.h new file mode 100644 index 0000000..00f89ca --- /dev/null +++ b/arch/mips/include/asm/n64/irq.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Interrupt numbers for N64 + * + * Copyright (C) 2020 Lauri Kasanen + */ +#ifndef __N64_IRQ_H +#define __N64_IRQ_H + +#define NR_IRQS 8 + +/* + * CPU core Interrupt Numbers + */ +#define MIPS_CPU_IRQ_BASE 0 +#define MIPS_CPU_IRQ(x) (MIPS_CPU_IRQ_BASE + (x)) +#define MIPS_SOFTINT0_IRQ MIPS_CPU_IRQ(0) +#define MIPS_SOFTINT1_IRQ MIPS_CPU_IRQ(1) +#define RCP_IRQ MIPS_CPU_IRQ(2) +#define CART_IRQ MIPS_CPU_IRQ(3) +#define PRENMI_IRQ MIPS_CPU_IRQ(4) +#define RDBR_IRQ MIPS_CPU_IRQ(5) +#define RDBW_IRQ MIPS_CPU_IRQ(6) +#define TIMER_IRQ MIPS_CPU_IRQ(7) + +#endif /* __N64_IRQ_H */ diff --git a/arch/mips/n64/Makefile b/arch/mips/n64/Makefile new file mode 100644 index 0000000..b64a05a --- /dev/null +++ b/arch/mips/n64/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Nintendo 64 +# + +obj-y := init.o irq.o diff --git a/arch/mips/n64/Platform b/arch/mips/n64/Platform new file mode 100644 index 0000000..2464783 --- /dev/null +++ b/arch/mips/n64/Platform @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Nintendo 64 +# + +cflags-$(CONFIG_MACH_NINTENDO64) += -I$(srctree)/arch/mips/include/asm/mach-n64 +load-$(CONFIG_MACH_NINTENDO64) += 0xffffffff80101000 diff --git a/arch/mips/n64/init.c b/arch/mips/n64/init.c new file mode 100644 index 0000000..47f29d6 --- /dev/null +++ b/arch/mips/n64/init.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Nintendo 64 init. + * + * Copyright (C) 2020 Lauri Kasanen + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define IO_MEM_RESOURCE_START 0UL +#define IO_MEM_RESOURCE_END 0x1fffffffUL + +static void __init iomem_resource_init(void) +{ + iomem_resource.start = IO_MEM_RESOURCE_START; + iomem_resource.end = IO_MEM_RESOURCE_END; +} + +const char *get_system_type(void) +{ + return "Nintendo 64"; +} + +void __init prom_init(void) +{ + fw_init_cmdline(); +} + +void __init prom_free_prom_memory(void) +{ +} + +#define W 320 +#define H 240 +#define REG_BASE ((u32 *) TO_UNCAC(0x4400000)) + +static void __init n64rdp_write_reg(const u8 reg, const u32 value) +{ + __raw_writel(value, REG_BASE + reg); +} + +#undef REG_BASE + +static const u32 ntsc_320[] __initconst = { + 0x00013212, 0x00000000, 0x00000140, 0x00000200, + 0x00000000, 0x03e52239, 0x0000020d, 0x00000c15, + 0x0c150c15, 0x006c02ec, 0x002501ff, 0x000e0204, + 0x00000200, 0x00000400 +}; + +static int __init n64_platform_init(void) +{ + static const char simplefb_resname[] = "FB"; + static const struct simplefb_platform_data mode = { + .width = W, + .height = H, + .stride = W * 2, + .format = "r5g5b5a1" + }; + struct resource res; + void *orig; + unsigned long phys; + unsigned i; + + platform_device_register_simple("n64audio", -1, NULL, 0); + + /* The framebuffer needs 64-byte alignment */ + orig = kzalloc(W * H * 2 + 63, GFP_DMA | GFP_KERNEL); + if (!orig) + return -ENOMEM; + phys = virt_to_phys(orig); + phys += 63; + phys &= ~63; + + for (i = 0; i < ARRAY_SIZE(ntsc_320); i++) { + if (i == 1) + n64rdp_write_reg(i, phys); + else + n64rdp_write_reg(i, ntsc_320[i]); + } + + /* setup IORESOURCE_MEM as framebuffer memory */ + memset(&res, 0, sizeof(res)); + res.flags = IORESOURCE_MEM; + res.name = simplefb_resname; + res.start = phys; + res.end = phys + W * H * 2 - 1; + + platform_device_register_resndata(NULL, "simple-framebuffer", 0, + &res, 1, &mode, sizeof(mode)); + + return 0; +} + +#undef W +#undef H + +arch_initcall(n64_platform_init); + +void __init plat_mem_setup(void) +{ + iomem_resource_init(); + memblock_add(0x0, 8 * 1024 * 1024); // Bootloader blocks the 4mb config +} + +void __init plat_time_init(void) +{ + // 93.75 MHz cpu, count register runs at half rate + mips_hpt_frequency = 93750000 / 2; +} diff --git a/arch/mips/n64/irq.c b/arch/mips/n64/irq.c new file mode 100644 index 0000000..9f833cb --- /dev/null +++ b/arch/mips/n64/irq.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * N64 IRQ + * + * Copyright (C) 2020 Lauri Kasanen + */ +#include +#include +#include + +#include + +void __init arch_init_irq(void) +{ + mips_cpu_irq_init(); +} From patchwork Mon Jan 4 13:46:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 11996795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACB6FC433DB for ; Mon, 4 Jan 2021 13:46:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80673207BC for ; Mon, 4 Jan 2021 13:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726950AbhADNqO (ORCPT ); Mon, 4 Jan 2021 08:46:14 -0500 Received: from mout.gmx.net ([212.227.15.19]:33459 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725921AbhADNqO (ORCPT ); Mon, 4 Jan 2021 08:46:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609767881; bh=eIQR0/N3yU5g3Ck+QxO7wW/o9Eq3Bvh+w1VitRCoW7Q=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=QYgftcepcw0rVG1d+G0KTaj5YuZId3nihP2xlRAhIqILlfL1ruHIUlkgU4w4Xs27e EZwMXt3EEo8vHBsmJkLu5aC8pAiCF5gRJanUveOtE9t1X/7ELPvwJoye60bnXZaBk8 HoWqVAHA+vyZibAmu4DqhjPhv1BQkGegFkrjmnNc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.128.181.212]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MbRk3-1kPH8L3gWv-00bpB1; Mon, 04 Jan 2021 14:44:41 +0100 Date: Mon, 4 Jan 2021 15:46:18 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, hdegoede@redhat.com, linux-fbdev@vger.kernel.org Subject: [PATCH 3/6] fbdev/simplefb: Add the N64's mode Message-Id: <20210104154618.06e1df16b234498bf9145223@gmx.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K1:visL/lvIkrIc9DmTqd2atVUszYVVQmgl5wMOW8XIE9PuySJzy0f bPvCR2pzMUii0hkJ3bX0Zziv+jWjmjLALp5jQdPYpJ0RhJmMwqEqHOnsrq8m8MhzWIkViPo ens4stMxGba11x+kbVJkDw4mjw3A7i2u9e4EDHk1qXV3L2LevnRLB+/DVFwwQMjSBbq2urU EtB7P2QR2hhIKiyQP2+nA== X-UI-Out-Filterresults: notjunk:1;V03:K0:ryceb86etHc=:p7kEia0It8kqPjswEqchNR mRwhNaDUH3tariPmg4eGY90zSjmuwXLP7fU5CY98piOIWYQfhq4FZTz7i2jBlDmmPoa9lqC4X pUBzfMb5yHlqgPA6LAKN+NZOLKqU39e6eyk0NUBZOOaxZv0E3pkJQEQhOokL4UMzsJEzln7Ql OIM0KhyuY1nwaFbknbK9mkJPM3dIcOAK+lwCi0OTTC5zEXy1+25O+PAuIH9mmpWJ+5gqpHDv8 AkvL5C1V5gX4gztyVaK34dTUo3BtTEJY7ZOGvsvsdFXVshFLlaYr3zgyXUwau1GQivfCrO8jZ Q/yxmxeHfusX7h+gHIDbObAi0ggZhteFzPbe1L3fAmOoUxjSr9m+nskpw+uksCb6GaLbnr5Kv c9AVLhdE3lDhTodDN1W3VWfI9Iy3jMZP0M/VQBrgdl/dJ7XqYxCZ5wVnHAdL91AH4sCa5EZqC bCKoqMqGI3fG2xKljrvA5bAh0ZGSevFZR7BrOE0ugNESnI9R+kedqkR+BdLoO0rYMemF7Mmjl 8aZu3wgdYeuIJgtm1PZ1uZ538lorMQyOPWKWgTwBwH3divylLJMOBHpNng98uG4y+LIrFNnL9 voFbsmU3Bg+WhQIqcHUGCW1PU97U8HCaOBFVVQkTe1hRj5CFFw7ACNjmghwqegKqdg0o0N6I/ ambySFLqekZ1fr7mcM9TJuZcKLIzi78RCLY6sGEyJ6dCWM0JAZ450o22uW2A4LqOnym4BrqEx xi33YifojXf9ou3BW2sxwGvudWa9+Vh4p0cwGh86cjrczqBIBtzk61RRHwIfDHOzeBPPHz3ap YKp+7CS8sjfGIHXIhdLmrGbYkMJT3I8GSiHbDlodxhmoBjx8458vLbCUE6GouFJkbQYHY0Jp8 6KeUWnPHPDaxlNwyMARQ== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org By keeping it separate for the platform, we save 748 bytes. This brings simplefb to 2.5kb from 3.2kb, when a native fb driver was 1.5kb. Signed-off-by: Lauri Kasanen --- include/linux/platform_data/simplefb.h | 7 +++++++ 1 file changed, 7 insertions(+) fb folks: the rest of the series is on linux-mips. I'm not sure which tree what goes through. -- 2.6.2 diff --git a/include/linux/platform_data/simplefb.h b/include/linux/platform_data/simplefb.h index ca83376..c9d4f2c 100644 --- a/include/linux/platform_data/simplefb.h +++ b/include/linux/platform_data/simplefb.h @@ -13,6 +13,12 @@ #include /* format array, use it to initialize a "struct simplefb_format" array */ +#ifdef CONFIG_MACH_NINTENDO64 +#define SIMPLEFB_FORMATS \ +{ \ + { "r5g5b5a1", 16, {11, 5}, {6, 5}, {1, 5}, {0, 1}, DRM_FORMAT_RGBA5551 }, \ +} +#else #define SIMPLEFB_FORMATS \ { \ { "r5g6b5", 16, {11, 5}, {5, 6}, {0, 5}, {0, 0}, DRM_FORMAT_RGB565 }, \ @@ -25,6 +31,7 @@ { "x2r10g10b10", 32, {20, 10}, {10, 10}, {0, 10}, {0, 0}, DRM_FORMAT_XRGB2101010 }, \ { "a2r10g10b10", 32, {20, 10}, {10, 10}, {0, 10}, {30, 2}, DRM_FORMAT_ARGB2101010 }, \ } +#endif /* * Data-Format for Simple-Framebuffers From patchwork Mon Jan 4 13:48:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 11996819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAA1FC433E6 for ; Mon, 4 Jan 2021 13:48:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3580207BC for ; Mon, 4 Jan 2021 13:48:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbhADNsK (ORCPT ); Mon, 4 Jan 2021 08:48:10 -0500 Received: from mout.gmx.net ([212.227.15.15]:49137 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbhADNsI (ORCPT ); Mon, 4 Jan 2021 08:48:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609767993; bh=Ps2UI3hai1euXkSADfSbCtM1X7/CHjhU4zDFMCxSNWk=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=R8CRE7ey7P0shuiJ1Yab8jzRnp3IrQqQZcrZJ25j0K8YR9yc6aa5h13bxqT+puU0I A1DGQk6qWPdq3GBJwz+Ixq143QROTDB3LtqpkU9ku5nbZXPPY6n1TQoQpacdCz2vaV z/AxFp7xxQfTxTaozFqPbleETaJmTaIUijbk17LE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.128.181.212]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1McYCl-1kQNIC13tt-00cvOq; Mon, 04 Jan 2021 14:46:33 +0100 Date: Mon, 4 Jan 2021 15:48:11 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, dmitry.torokhov@gmail.com, linux-input@vger.kernel.org Subject: [PATCH 4/6] input: Add N64 controller driver Message-Id: <20210104154811.ced3a894cddc4d309827307c@gmx.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K1:bH2j6ody6wedHUCOw/jhz+FO5QkqoJh/LrL1xvzvyJlJf+ttPSd lMX+liEweien1N3xePLgOHbTAd0TMod6SImN66NjXbbkzu0LuVXK+dQU3KIFSAeiklN8DhD 0uytiMmEoVT2urkiZqYzPM0JfxPE4g7gSDR8vyXbBS0w7PrxvIy4SSWrI9cIU/bdxTCqv+N g49ulxJUhDryXtHvgda2Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:06JiRpPuHHQ=:h+JrRdDk4lR296d5QBO646 YsmzIgBzXM1lnYmDmMiPJohIGszL5vO6MaAwTrJJhiRi/FYJRniZvjUUEFVFBylVdkuyVSvLv jN1X+1RPlpDr7IP6xxc6MOwJO1yv7x45K3ZgWrdbiV4ocv3xHXSEjwGx6iLQawtsvWxsskctd MlHxTgWxfZQ/Ib82sy4Fuovexx8VtrgktU8xsgpLcuW/du6pdqN8MeuDD+zXdjnwkrsZJ8iNr cgD6u5/6tYUXSqP1rgqgmiEtQohNHHeprEAbrt7HoMa3GLi/lgXS4b44d2jr11KrQKI/qV/6N dAlFemQvdmrH6yl8HosrQqFcaP88utMzQ8soHTvFP8vA/TZqX4Smd8ptVE0cioxGdCrFQkqdj UC4eMdJP4q5/fFgW+pCUOQo4in4GMxBCXbSD8JzYOdwS9aqJP7p1jV0rI2lv7/8vUCmjUcjyf 4Uu0exHloPXA4rakt/c5XJdx0umue6IolkqlEsGBayXEsvwvFnUvxf60Yz6ZQKxA8BW4znnzP R6FROHxWPajYmMZyhqOiqv8y9n+GqhbFuD0eu2mWlVe93jXo/WiB8Q3gxuElVlJnZspXWRM0e bpHi9rzGa1LaUPs3Oe3PxmGAxTrF0haERmSo+cLRSDn9JmBTCrLqpJhPnH+lmspjZ527Q9Rr6 hZYEeNjXBvfRgqdFFvQZRDq3nWayX4VonCm7V6aX/39w51LAMrOus/JbK7ceykI1ZxqOVMrNG A3Kgo3pzLEv78uiUOAwbmYNE1hThY87c5ZmyogrDPGklexA58jxTfX8NO6M5dbYJV8NPIsBTK YyD4TEYjrU403xGPfWfnhc/BxqnN4e47y/JkqDjCD3lU6An6dqzRKMlGmElQBEklWEC3okN2Y ByDcWFs211WoMWYDpxxg== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Signed-off-by: Lauri Kasanen --- drivers/input/joystick/Kconfig | 6 + drivers/input/joystick/Makefile | 2 +- drivers/input/joystick/n64joy.c | 300 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 drivers/input/joystick/n64joy.c input folks: rest of the series is on linux-mips. Being mips-specific, not sure which tree this should go to. -- 2.6.2 diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig index b080f0c..e1a8128 100644 --- a/drivers/input/joystick/Kconfig +++ b/drivers/input/joystick/Kconfig @@ -382,4 +382,10 @@ config JOYSTICK_FSIA6B To compile this driver as a module, choose M here: the module will be called fsia6b. +config JOYSTICK_N64 + bool "N64 controller" + depends on MACH_NINTENDO64 + help + Support for the four N64 controllers. + endif diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile index 58232b3..31d720c 100644 --- a/drivers/input/joystick/Makefile +++ b/drivers/input/joystick/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o obj-$(CONFIG_JOYSTICK_MAPLE) += maplecontrol.o +obj-$(CONFIG_JOYSTICK_N64) += n64joy.o obj-$(CONFIG_JOYSTICK_PSXPAD_SPI) += psxpad-spi.o obj-$(CONFIG_JOYSTICK_PXRC) += pxrc.o obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o @@ -37,4 +38,3 @@ obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o - diff --git a/drivers/input/joystick/n64joy.c b/drivers/input/joystick/n64joy.c new file mode 100644 index 0000000..477a4f7 --- /dev/null +++ b/drivers/input/joystick/n64joy.c @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for the four N64 controllers. + * + * Copyright (c) 2020 Lauri Kasanen + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +MODULE_AUTHOR("Lauri Kasanen "); +MODULE_DESCRIPTION("Driver for N64 controllers"); +MODULE_LICENSE("GPL"); + +#define PIF_RAM 0x1fc007c0 +#define REG_BASE ((u32 *) TO_UNCAC(0x4800000)) + +#define SI_DRAM_REG 0 +#define SI_READ_REG 1 +#define SI_WRITE_REG 4 +#define SI_STATUS_REG 6 + +#define SI_STATUS_DMA_BUSY (1 << 0) +#define SI_STATUS_IO_BUSY (1 << 1) + +#define N64_CONTROLLER_ID 0x0500 + +static struct input_dev *n64joy_dev[4]; +static const char *n64joy_phys[4] = { + "n64joy/port0", + "n64joy/port1", + "n64joy/port2", + "n64joy/port3", +}; + +static u8 n64joy_opened; +static DEFINE_MUTEX(n64joy_mutex); +static struct timer_list timer; + +static u64 si_buf[8] ____cacheline_aligned; + +struct joydata { + unsigned: 16; // unused + unsigned err: 2; + unsigned: 14; // unused + + union { + u32 data; + + struct { + unsigned a: 1; + unsigned b: 1; + unsigned z: 1; + unsigned start: 1; + unsigned up: 1; + unsigned down: 1; + unsigned left: 1; + unsigned right: 1; + unsigned: 2; // unused + unsigned l: 1; + unsigned r: 1; + unsigned c_up: 1; + unsigned c_down: 1; + unsigned c_left: 1; + unsigned c_right: 1; + signed x: 8; + signed y: 8; + }; + }; +}; + +static void n64joy_write_reg(const u8 reg, const u32 value) +{ + __raw_writel(value, REG_BASE + reg); +} + +static u32 n64joy_read_reg(const u8 reg) +{ + return __raw_readl(REG_BASE + reg); +} + +static void n64joy_wait_si_dma(void) +{ + while (n64joy_read_reg(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_BUSY)) + ; +} + +static void n64joy_exec_pif(const u64 in[8]) +{ + unsigned long flags; + + dma_cache_wback_inv((unsigned long) in, 8 * 8); + dma_cache_inv((unsigned long) si_buf, 8 * 8); + + local_irq_save(flags); + + n64joy_wait_si_dma(); + + barrier(); + n64joy_write_reg(SI_DRAM_REG, virt_to_phys(in)); + barrier(); + n64joy_write_reg(SI_WRITE_REG, PIF_RAM); + barrier(); + + n64joy_wait_si_dma(); + + barrier(); + n64joy_write_reg(SI_DRAM_REG, virt_to_phys(si_buf)); + barrier(); + n64joy_write_reg(SI_READ_REG, PIF_RAM); + barrier(); + + n64joy_wait_si_dma(); + + local_irq_restore(flags); +} + +static const u64 polldata[] ____cacheline_aligned = { + 0xff010401ffffffff, + 0xff010401ffffffff, + 0xff010401ffffffff, + 0xff010401ffffffff, + 0xfe00000000000000, + 0, + 0, + 1 +}; + +static void n64joy_poll(struct timer_list *t) +{ + const struct joydata *data; + u32 i; + + n64joy_exec_pif(polldata); + + data = (struct joydata *) si_buf; + + for (i = 0; i < 4; i++) { + if (!n64joy_dev[i]) + continue; + + // d-pad + input_report_key(n64joy_dev[i], BTN_DPAD_UP, data[i].up); + input_report_key(n64joy_dev[i], BTN_DPAD_DOWN, data[i].down); + input_report_key(n64joy_dev[i], BTN_DPAD_LEFT, data[i].left); + input_report_key(n64joy_dev[i], BTN_DPAD_RIGHT, data[i].right); + + // c buttons + input_report_key(n64joy_dev[i], BTN_FORWARD, data[i].c_up); + input_report_key(n64joy_dev[i], BTN_BACK, data[i].c_down); + input_report_key(n64joy_dev[i], BTN_LEFT, data[i].c_left); + input_report_key(n64joy_dev[i], BTN_RIGHT, data[i].c_right); + + // matching buttons + input_report_key(n64joy_dev[i], BTN_START, data[i].start); + input_report_key(n64joy_dev[i], BTN_Z, data[i].z); + + // remaining ones: a, b, l, r + input_report_key(n64joy_dev[i], BTN_0, data[i].a); + input_report_key(n64joy_dev[i], BTN_1, data[i].b); + input_report_key(n64joy_dev[i], BTN_2, data[i].l); + input_report_key(n64joy_dev[i], BTN_3, data[i].r); + + input_report_abs(n64joy_dev[i], ABS_X, data[i].x); + input_report_abs(n64joy_dev[i], ABS_Y, data[i].y); + + input_sync(n64joy_dev[i]); + } + + mod_timer(&timer, jiffies + msecs_to_jiffies(16)); +} + +static int n64joy_open(struct input_dev *dev) +{ + int err; + + err = mutex_lock_interruptible(&n64joy_mutex); + if (err) + return err; + + if (!n64joy_opened) { + // Could use the vblank irq, but it's not important if the poll + // point slightly changes. + timer_setup(&timer, n64joy_poll, 0); + mod_timer(&timer, jiffies + msecs_to_jiffies(16)); + } + + n64joy_opened++; + + mutex_unlock(&n64joy_mutex); + return err; +} + +static void n64joy_close(struct input_dev *dev) +{ + mutex_lock(&n64joy_mutex); + if (!--n64joy_opened) + del_timer_sync(&timer); + mutex_unlock(&n64joy_mutex); +} + +static const u64 __initconst scandata[] ____cacheline_aligned = { + 0xff010300ffffffff, + 0xff010300ffffffff, + 0xff010300ffffffff, + 0xff010300ffffffff, + 0xfe00000000000000, + 0, + 0, + 1 +}; + +static int __init n64joy_init(void) +{ + const struct joydata *data; + int err = 0; + u32 i, j, found = 0; + + // The controllers are not hotpluggable, so we can scan in init + n64joy_exec_pif(scandata); + + data = (struct joydata *) si_buf; + + memset(n64joy_dev, 0, 4 * sizeof(void *)); + + for (i = 0; i < 4; i++) { + if (!data[i].err && data[i].data >> 16 == N64_CONTROLLER_ID) { + found++; + + n64joy_dev[i] = input_allocate_device(); + if (!n64joy_dev[i]) { + err = -ENOMEM; + goto fail; + } + + n64joy_dev[i]->name = "N64 controller"; + n64joy_dev[i]->phys = n64joy_phys[i]; + n64joy_dev[i]->id.bustype = BUS_HOST; + n64joy_dev[i]->id.vendor = 0; + n64joy_dev[i]->id.product = data[i].data >> 16; + n64joy_dev[i]->id.version = 0; + + n64joy_dev[i]->open = n64joy_open; + n64joy_dev[i]->close = n64joy_close; + + n64joy_dev[i]->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); + n64joy_dev[i]->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y); + + // d-pad + n64joy_dev[i]->keybit[BIT_WORD(BTN_DPAD_UP)] = BIT_MASK(BTN_DPAD_UP) | + BIT_MASK(BTN_DPAD_DOWN) | BIT_MASK(BTN_DPAD_LEFT) | + BIT_MASK(BTN_DPAD_RIGHT); + // c buttons + n64joy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] |= BIT_MASK(BTN_LEFT) | + BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_FORWARD) | BIT_MASK(BTN_BACK); + // matching buttons + n64joy_dev[i]->keybit[BIT_WORD(BTN_GAMEPAD)] |= BIT_MASK(BTN_START) | + BIT_MASK(BTN_Z); + // remaining ones: a, b, l, r + n64joy_dev[i]->keybit[BIT_WORD(BTN_0)] |= BIT_MASK(BTN_0) | + BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3); + + for (j = 0; j < 2; j++) { + input_set_abs_params(n64joy_dev[i], ABS_X + j, + S8_MIN, S8_MAX, 0, 0); + } + + err = input_register_device(n64joy_dev[i]); + if (err) { + input_free_device(n64joy_dev[i]); + goto fail; + } + } + } + + pr_info("n64joy: %u controller(s) connected\n", found); + + if (!found) + return -ENODEV; + + return 0; +fail: + for (i = 0; i < 4; i++) { + if (!n64joy_dev[i]) + continue; + input_unregister_device(n64joy_dev[i]); + } + return err; +} + +module_init(n64joy_init); From patchwork Mon Jan 4 13:49:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 11996821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D847C433DB for ; Mon, 4 Jan 2021 13:50:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63E0D207B1 for ; Mon, 4 Jan 2021 13:50:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725840AbhADNuF (ORCPT ); Mon, 4 Jan 2021 08:50:05 -0500 Received: from mout.gmx.net ([212.227.15.18]:52689 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbhADNuF (ORCPT ); Mon, 4 Jan 2021 08:50:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609768076; bh=s/TKkzX2osRLbUUSRE5qim2OuxdiXml5MnKBsf0Ltgc=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=Bo+Q1pu1F7fYPn1GQ5bP7uS/NqdB2Rgb1Lg1oaBjZBJ1UCMXTXhAiUq4SbOinX1i0 wb522+u+WXRANsZew9N+P9u6d5u/afIkb06pNWK7wCRWhNcA2TXYouW4MQLX8zqxTQ HNgmP4fgLSzzcH9lV+KQVXtmjSZvwT9iCMPOzH5E= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.128.181.212]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MN5iZ-1kfiJ71V7V-00J35x; Mon, 04 Jan 2021 14:47:56 +0100 Date: Mon, 4 Jan 2021 15:49:34 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, perex@perex.cz, tiwai@suse.com Subject: [PATCH 5/6] sound: Add n64 driver Message-Id: <20210104154934.1c5ed81f4d37c8a3e131a6bc@gmx.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K1:M3CAx7tGBZLjHacV2m3TGrsNhWDjcDLbL0Mr/IHk3QzbU3myOKH nGkdOAfec27lj5/5f8WWtaviWiJi7IX0ggk7PJIFbA9JlF9W8WY+mU42ENPzhxEzj2vE4Vz +RWiN+PxAdMNrtzquLxJOW0Ux4V6YvopG7EG0lmhYNDb8SFDLKZrzskIuzngyPqNUJRE+2u vBEp2f0orYzNASoidfeKQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:6WB8927Ph0o=:MhaWrCJGmSfZg6LgzhWw89 s7mWS7V3+yd4X2jVbbfZpzioQJYJooCpGCUjrtuWRB7nx/cxzoME30o7AvpiXs8nfUd8NKtRU gvbSfElqc9Tauyq3Abdr102WYVTkLbQRweGhrBZg/NEW+Z5TItVASdODCPYq8ZScf0dbe4qdq EjsjXp4A1ywNVxGH7XEl8utT/AxtYX6FVqscASRq5UsATJ7qzV6ZlUXdvHd4bUNXvQRTCIYDO wdzox5o+PI8yeEbMIJZ0+P7+vbIQy9E5hgUh1viPA+/YmOMNW1xOAYi/XzobM+/bdJQHZahxE FL81Z+Vn0l1GVWiVKIM0YYzYUNAQ2uIwf3251hHM1BwpCPYCS4yQxoQ2UsPapI4XnGn0P6Kcq lDqJP5UTGXQDNR5Uw6YbGyFx+53d2E9Wxhjphtc5+oZYmD21WbImwk1pV/C5MNPCI1F7QafkT QfxGYg+PHh2zf5BR/mItmIttRQzlxdE43/4sXoD3tKIPrPddhIbGlJ6HC8k8e0v66Iru7Mgoi VYgdTWvKVjYxjLi1T/Itjxz/YMIkd552ZZy7IA/BfAc7xPKmcfrnnXdAatiKQKISZ5ABGy8HL mH2f1YAviov49o0R+qdN3ufuHM4YkFsyB3bfBPpaeBVuPqgZYi6IyZfQmihrZp94hwUxyPKZd u30U91HSNOVR459QQQW0Iec/TJud9vSOzSuyJQNAhxDTaR8PxnwR1mQarGz04eUIZDm4BL1VA DNgKso8JV0VyVCvIUqOuflOIP2wH7Yqq43JgvnG7+So1bLtRw4DglIcbRZJjUrKXYzb8T3oKO r6afB364D2StpLOBiSZCkwaaeM0OzE3MSc2bp2OiR/G07pO+vY59wLiB9MEpwsaW+gBalOzGK eVarHYxyvq6YpbkufthQ== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The sound DMA unit has errata on certain alignments, which is why we can't use alsa's DMA buffer directly. Signed-off-by: Lauri Kasanen --- sound/mips/Kconfig | 7 ++ sound/mips/Makefile | 1 + sound/mips/snd-n64.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 sound/mips/snd-n64.c sound folks: rest of the series is on linux-mips. Being a mips-specific driver, not sure which tree it should go to. -- 2.6.2 diff --git a/sound/mips/Kconfig b/sound/mips/Kconfig index b497b80..c8b4db5 100644 --- a/sound/mips/Kconfig +++ b/sound/mips/Kconfig @@ -24,5 +24,12 @@ config SND_SGI_HAL2 help Sound support for the SGI Indy and Indigo2 Workstation. +config SND_N64 + bool "N64 Audio" + depends on MACH_NINTENDO64 + select SND_PCM + help + Sound support for the N64. + endif # SND_MIPS diff --git a/sound/mips/Makefile b/sound/mips/Makefile index ccc364e..7c86268 100644 --- a/sound/mips/Makefile +++ b/sound/mips/Makefile @@ -9,3 +9,4 @@ snd-sgi-hal2-objs := hal2.o # Toplevel Module Dependency obj-$(CONFIG_SND_SGI_O2) += snd-sgi-o2.o obj-$(CONFIG_SND_SGI_HAL2) += snd-sgi-hal2.o +obj-$(CONFIG_SND_N64) += snd-n64.o diff --git a/sound/mips/snd-n64.c b/sound/mips/snd-n64.c new file mode 100644 index 0000000..d7b3ea6 --- /dev/null +++ b/sound/mips/snd-n64.c @@ -0,0 +1,297 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sound driver for Nintendo 64. + * + * Copyright 2020 Lauri Kasanen + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +MODULE_AUTHOR("Lauri Kasanen "); +MODULE_DESCRIPTION("N64 Audio"); +MODULE_LICENSE("GPL"); + +#define AI_NTSC_DACRATE 48681812 +#define AI_STATUS_BUSY (1 << 30) +#define AI_STATUS_FULL (1 << 31) + +#define REG_BASE ((u32 *) TO_UNCAC(0x4500000)) + +#define AI_ADDR_REG 0 +#define AI_LEN_REG 1 +#define AI_CONTROL_REG 2 +#define AI_STATUS_REG 3 +#define AI_RATE_REG 4 +#define AI_BITCLOCK_REG 5 + +#define MI_REG_BASE ((u32 *) TO_UNCAC(0x4300000)) + +#define MI_INTR_REG 2 +#define MI_MASK_REG 3 + +#define MI_INTR_AI 0x04 + +#define MI_MASK_CLR_AI 0x0010 +#define MI_MASK_SET_AI 0x0020 + + +struct n64audio_t { + struct snd_card *card; + + void *ring_base; + dma_addr_t ring_base_dma; + + struct { + struct snd_pcm_substream *substream; + int pos, nextpos; + u32 writesize; + u32 bufsize; + spinlock_t lock; + } chan; +}; + +static void n64audio_write_reg(const u8 reg, const u32 value) +{ + __raw_writel(value, REG_BASE + reg); +} + +static void n64mi_write_reg(const u8 reg, const u32 value) +{ + __raw_writel(value, MI_REG_BASE + reg); +} + +static u32 n64mi_read_reg(const u8 reg) +{ + return __raw_readl(MI_REG_BASE + reg); +} + +static void n64audio_push(struct n64audio_t *priv, uint8_t irq) +{ + struct snd_pcm_runtime *runtime = priv->chan.substream->runtime; + unsigned long flags; + u32 count; + + count = priv->chan.writesize; + count &= ~7; + + spin_lock_irqsave(&priv->chan.lock, flags); + + memcpy(priv->ring_base, runtime->dma_area + priv->chan.nextpos, count); + + n64audio_write_reg(AI_ADDR_REG, priv->ring_base_dma); + n64audio_write_reg(AI_LEN_REG, count); + + priv->chan.nextpos += count; + priv->chan.nextpos %= priv->chan.bufsize; + if (irq) + priv->chan.pos = priv->chan.nextpos; + + spin_unlock_irqrestore(&priv->chan.lock, flags); +} + +static irqreturn_t n64audio_isr(int irq, void *dev_id) +{ + struct n64audio_t *priv = dev_id; + + // Check it's ours + const u32 intrs = n64mi_read_reg(MI_INTR_REG); + if (!(intrs & MI_INTR_AI)) + return IRQ_NONE; + + n64audio_write_reg(AI_STATUS_REG, 1); + + n64audio_push(priv, 1); + snd_pcm_period_elapsed(priv->chan.substream); + + return IRQ_HANDLED; +} + +static const struct snd_pcm_hardware n64audio_pcm_hw = { + .info = (SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_BLOCK_TRANSFER), + .formats = SNDRV_PCM_FMTBIT_S16_BE, + .rates = SNDRV_PCM_RATE_8000_48000, + .rate_min = 8000, + .rate_max = 48000, + .channels_min = 2, + .channels_max = 2, + .buffer_bytes_max = 32768, + .period_bytes_min = 1024, + .period_bytes_max = 32768, + .periods_min = 1, + .periods_max = 128, +}; + +static int n64audio_pcm_open(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + + runtime->hw = n64audio_pcm_hw; + return 0; +} + +static int n64audio_pcm_prepare(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct n64audio_t *priv = substream->pcm->private_data; + unsigned long flags; + u32 rate; + + rate = ((2 * AI_NTSC_DACRATE / runtime->rate) + 1) / 2 - 1; + + n64audio_write_reg(AI_RATE_REG, rate); + + rate /= 66; + if (rate > 16) + rate = 16; + n64audio_write_reg(AI_BITCLOCK_REG, rate - 1); + + spin_lock_irqsave(&priv->chan.lock, flags); + + /* Setup the pseudo-dma transfer pointers. */ + priv->chan.pos = 0; + priv->chan.nextpos = 0; + priv->chan.substream = substream; + priv->chan.writesize = snd_pcm_lib_period_bytes(substream); + priv->chan.bufsize = snd_pcm_lib_buffer_bytes(substream); + + spin_unlock_irqrestore(&priv->chan.lock, flags); + return 0; +} + +static int n64audio_pcm_trigger(struct snd_pcm_substream *substream, + int cmd) +{ + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + n64audio_push(substream->pcm->private_data, 0); + n64audio_write_reg(AI_CONTROL_REG, 1); + n64mi_write_reg(MI_MASK_REG, MI_MASK_SET_AI); + break; + case SNDRV_PCM_TRIGGER_STOP: + n64audio_write_reg(AI_CONTROL_REG, 0); + n64mi_write_reg(MI_MASK_REG, MI_MASK_CLR_AI); + break; + default: + return -EINVAL; + } + return 0; +} + +static snd_pcm_uframes_t n64audio_pcm_pointer(struct snd_pcm_substream *substream) +{ + struct n64audio_t *priv = substream->pcm->private_data; + + return bytes_to_frames(substream->runtime, + priv->chan.pos); +} + +static int n64audio_pcm_close(struct snd_pcm_substream *substream) +{ + return 0; // Nothing to do, but the kernel crashes if close() doesn't exist +} + +static const struct snd_pcm_ops n64audio_pcm_ops = { + .open = n64audio_pcm_open, + .prepare = n64audio_pcm_prepare, + .trigger = n64audio_pcm_trigger, + .pointer = n64audio_pcm_pointer, + .close = n64audio_pcm_close, +}; + +static int __init n64audio_probe(struct platform_device *pdev) +{ + struct snd_card *card; + struct snd_pcm *pcm; + struct n64audio_t *priv; + int err; + + err = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, + SNDRV_DEFAULT_STR1, + THIS_MODULE, 0, &card); + if (err < 0) + return err; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (priv == NULL) { + err = -ENOMEM; + goto fail_card; + } + + priv->card = card; + priv->ring_base = dma_alloc_coherent(card->dev, 32 * 1024, + &priv->ring_base_dma, + GFP_DMA | GFP_KERNEL); + if (!priv->ring_base) + goto fail_alloc; + + if (request_irq(RCP_IRQ, n64audio_isr, + IRQF_SHARED, "N64 Audio", priv)) { + err = -EBUSY; + goto fail_alloc; + } + + spin_lock_init(&priv->chan.lock); + + err = snd_pcm_new(card, "N64 Audio", 0, 1, 0, &pcm); + if (err < 0) + goto fail_alloc; + + pcm->private_data = priv; + strcpy(pcm->name, "N64 Audio"); + + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &n64audio_pcm_ops); + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0); + + strcpy(card->driver, "N64 Audio"); + strcpy(card->shortname, "N64 Audio"); + strcpy(card->longname, "N64 Audio"); + + err = snd_card_register(card); + if (err < 0) + goto fail_alloc; + + platform_set_drvdata(pdev, priv); + + return 0; + +fail_alloc: + kfree(priv); + +fail_card: + snd_card_free(card); + return err; +} + +static struct platform_driver n64audio_driver = { + .driver = { + .name = "n64audio", + }, +}; + +static int __init n64audio_init(void) +{ + int ret; + + ret = platform_driver_probe(&n64audio_driver, n64audio_probe); + + return ret; +} + +fs_initcall(n64audio_init); From patchwork Mon Jan 4 13:50:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 11996823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72F4AC433E0 for ; Mon, 4 Jan 2021 13:50:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42D3021BE5 for ; Mon, 4 Jan 2021 13:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726258AbhADNu1 (ORCPT ); Mon, 4 Jan 2021 08:50:27 -0500 Received: from mout.gmx.net ([212.227.15.19]:58265 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbhADNu0 (ORCPT ); Mon, 4 Jan 2021 08:50:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609768133; bh=4s4uHfoiw+kWXyg9AYWxLbRJd1TFBbZadA4Yeaxj6iA=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=i/2+z7R0RjvEYQ1RyfNp7BpQe01j4DWu+JRhDcPUtQ0AfnmL5Qyc7AEbW1QzPmk3M 9+4GF4+/rlaO+a4Nc0k3EmaPsSQAUvmkxSbHSyOrd8ZioSoW2U6J3DgoLMlZ+HhYrH lDwSi4u57E1on2q5gt7uXKdDd7+TpIuhvX5eUUnk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.128.181.212]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1Mkpf3-1kH3sI1Np1-00mJ2c; Mon, 04 Jan 2021 14:48:53 +0100 Date: Mon, 4 Jan 2021 15:50:31 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, axboe@kernel.dk, linux-block@vger.kernel.org Subject: [PATCH 6/6] block: Add n64 cart driver Message-Id: <20210104155031.9b4e39ff48a6d7accc93461d@gmx.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.18.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 X-Provags-ID: V03:K1:IwAitH4acIw64klRva/iFd2DgcCsW2pnIO7gEBlpGVEOOPMOA9F UVx15Y7sO0vsgdfAizzo4vDgdrblImylr6iaJW1UHvs+UO4pd5QjaooYnBC8J8vHj/c7QaB 0uu4mNV7CFJG6luWlSlTXfJRJBzXqNPGxU0LvjpQR/kIUw6r2cVks+urK8Gmegg+Ilr6sdu Ndk4yd9UAEtwuZW3A1ifA== X-UI-Out-Filterresults: notjunk:1;V03:K0:x0dBXb01Dho=:+onAcGopx1Ta6Hcld4k2// t9IAF0Z1TJIlLmFpQonmnEI1M3Q2mKVD9TtwfQhC9GBBEQ7r+gKw5QACTFwxTEEj97OA8xczH a+GgXeNxniQ9J7bGKTfKCkiEGUvWCb3D4mWbdRo5UJe83wezodIIcLOH7wlF0S1F3N/aJdiYZ yYStlYjkoJVvqD7KY+6JAIM5n04b8dWTWdOWYElwmOux4qwuXhnT2CMqkyKZyd4DAKerv1Xmy l1Jk1flaJB3J5nTKlGPPqpLNhIm1Gwx+yplGUoEDnetnP6BrcW+JGWdV+qNXHhR2Uun3gekun na6/66Ll7/WjiVYH9TxCVjN7YqprHkH2eAPjxvEuznaJ1kGUhlekipCqTfU+VrW2vGcRPLvTF WMyuH9fb2YtbG9EI8ijQzEGsYXoN76RP5IL7Bgc/pQKt9TTufHI9XaHh+QO3DJSFI8sqhn5CH dQldn3T+A4e02ZqinKAh2TUpeGjdg1QDWB/HZYnCRzKeIp3YJwKcJIfFTJCOlpU8LH4FbIkiA byNriO+YmfovMMtzGnRwrdQxQQR31zujElHu5C3l9Bbgpt76GgUjzDFRB66xUICdXlQA2nS2W oVaOWNJs/hESG8mqTMeG7xcWYhFaficGry5Q/EqG5ldv3/XWDyjIRkvnnI8kwkDo9XGrrVipP Xvo5OcVJ5+Tv01dnlkpkKaCFR9bRC/hiTdlu2B1TkbFhGi4MC68FZrnvzue+f9o06uqXUe4YK B7VFg6oreRqVPvqBfpHI8SA9/x0S1DtswNPaYrJTX68Mv3f6lI0csOKRwuZZ0Ol3jRsfg8fiH w5Hch7M/Kx5bzJHpYvBxxVRRLNolAGT46/zHsq3c6QRQBVDn41hLSGMqtz9EHQCilwtm4OXQz /EIjS4PvUCSRTAogF7ow== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Signed-off-by: Lauri Kasanen --- drivers/block/Kconfig | 6 ++ drivers/block/Makefile | 1 + drivers/block/n64cart.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/block/n64cart.c block folks: rest of the series is on linux-mips. Being a mips-specific driver, not sure which tree it should go to. -- 2.6.2 diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index ecceaaa..924d768 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -72,6 +72,12 @@ config AMIGA_Z2RAM To compile this driver as a module, choose M here: the module will be called z2ram. +config N64CART + bool "N64 cart support" + depends on MACH_NINTENDO64 + help + Support for the N64 cart. + config CDROM tristate select BLK_SCSI_REQUEST diff --git a/drivers/block/Makefile b/drivers/block/Makefile index e1f6311..b9642cf 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_PS3_DISK) += ps3disk.o obj-$(CONFIG_PS3_VRAM) += ps3vram.o obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o +obj-$(CONFIG_N64CART) += n64cart.o obj-$(CONFIG_BLK_DEV_RAM) += brd.o obj-$(CONFIG_BLK_DEV_LOOP) += loop.o obj-$(CONFIG_XILINX_SYSACE) += xsysace.o diff --git a/drivers/block/n64cart.c b/drivers/block/n64cart.c new file mode 100644 index 0000000..ae2ad4f --- /dev/null +++ b/drivers/block/n64cart.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for the N64 cart. + * + * Copyright (c) 2020 Lauri Kasanen + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +MODULE_AUTHOR("Lauri Kasanen "); +MODULE_DESCRIPTION("Driver for the N64 cart"); +MODULE_LICENSE("GPL"); + +#define BUFSIZE (64 * 1024) + +static unsigned int start, size; +static int major; +static struct request_queue *queue; +static struct blk_mq_tag_set tag_set; +static struct gendisk *disk; + +static void *buf; +static dma_addr_t dma_addr; + +static DEFINE_SPINLOCK(n64cart_lock); + +#define REG_BASE ((u32 *) TO_UNCAC(0x4600000)) + +#define PI_DRAM_REG 0 +#define PI_CART_REG 1 +#define PI_READ_REG 2 +#define PI_WRITE_REG 3 +#define PI_STATUS_REG 4 + +#define PI_STATUS_DMA_BUSY (1 << 0) +#define PI_STATUS_IO_BUSY (1 << 1) + +static void n64cart_write_reg(const u8 reg, const u32 value) +{ + __raw_writel(value, REG_BASE + reg); +} + +static u32 n64cart_read_reg(const u8 reg) +{ + return __raw_readl(REG_BASE + reg); +} + +static void n64cart_wait_dma(void) +{ + while (n64cart_read_reg(PI_STATUS_REG) & + (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) + ; +} + +static blk_status_t get_seg(struct request *req) +{ + u32 bstart = blk_rq_pos(req) * 512; + u32 len = blk_rq_cur_bytes(req); + void *dst = bio_data(req->bio); + + if (bstart + len > size || rq_data_dir(req) == WRITE) + return BLK_STS_IOERR; + + bstart += start; + + while (len) { + const u32 curlen = len < BUFSIZE ? len : BUFSIZE; + + dma_cache_inv((unsigned long) buf, curlen); + + n64cart_wait_dma(); + + barrier(); + n64cart_write_reg(PI_DRAM_REG, dma_addr); + barrier(); + n64cart_write_reg(PI_CART_REG, (bstart | 0x10000000) & 0x1FFFFFFF); + barrier(); + n64cart_write_reg(PI_WRITE_REG, curlen - 1); + barrier(); + + n64cart_wait_dma(); + + memcpy(dst, buf, curlen); + + len -= curlen; + dst += curlen; + bstart += curlen; + } + + return BLK_STS_OK; +} + +static blk_status_t n64cart_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) +{ + unsigned long flags; + struct request *req = bd->rq; + blk_status_t err; + + blk_mq_start_request(req); + + spin_lock_irqsave(&n64cart_lock, flags); + + do { + err = get_seg(req); + } while (blk_update_request(req, err, blk_rq_cur_bytes(req))); + + spin_unlock_irqrestore(&n64cart_lock, flags); + blk_mq_end_request(req, BLK_STS_OK); + return BLK_STS_OK; +} + +static const struct blk_mq_ops n64cart_mq_ops = { + .queue_rq = n64cart_queue_rq, +}; + +static const struct block_device_operations n64cart_fops = { + .owner = THIS_MODULE, +}; + +static int __init n64cart_init(void) +{ + int err; + + if (!start || !size) { + pr_err("n64cart: start and size not specified\n"); + return -ENODEV; + } + + if (size & 4095) { + pr_err("n64cart: size must be a multiple of 4K\n"); + return -ENODEV; + } + + major = register_blkdev(0, "n64cart"); + if (major <= 0) { + pr_err("n64cart: unable to get major number\n"); + return -EBUSY; + } + + queue = blk_mq_init_sq_queue(&tag_set, &n64cart_mq_ops, 16, + BLK_MQ_F_SHOULD_MERGE); + if (IS_ERR(queue)) { + err = PTR_ERR(queue); + goto fail_reg; + } + + buf = kmalloc(BUFSIZE, GFP_DMA | GFP_KERNEL); + if (!buf) { + err = -ENOMEM; + goto fail_queue; + } + dma_addr = virt_to_phys(buf); + + disk = alloc_disk(1); + if (!disk) { + err = -ENOMEM; + goto fail_dma; + } + + disk->major = major; + disk->first_minor = 0; + disk->queue = queue; + disk->flags = GENHD_FL_NO_PART_SCAN; + disk->fops = &n64cart_fops; + strcpy(disk->disk_name, "n64cart"); + + set_capacity(disk, size / 512); + + blk_queue_flag_set(QUEUE_FLAG_NONROT, queue); + blk_queue_physical_block_size(queue, 4096); + blk_queue_logical_block_size(queue, 4096); + + add_disk(disk); + + pr_info("n64cart: %u kb disk\n", size / 1024); + + return 0; +fail_dma: + kfree(buf); +fail_queue: + blk_cleanup_queue(queue); +fail_reg: + unregister_blkdev(major, "n64cart"); + return err; +} + +module_param(start, uint, 0); +MODULE_PARM_DESC(start, "Start address of the cart block data"); + +module_param(size, uint, 0); +MODULE_PARM_DESC(size, "Size of the cart block data, in bytes"); + +module_init(n64cart_init);