From patchwork Wed Jan 13 15:10:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 12017093 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 E2407C433E9 for ; Wed, 13 Jan 2021 15:15:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC4DF23383 for ; Wed, 13 Jan 2021 15:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726011AbhAMPOy (ORCPT ); Wed, 13 Jan 2021 10:14:54 -0500 Received: from mout.gmx.net ([212.227.17.22]:36917 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbhAMPOx (ORCPT ); Wed, 13 Jan 2021 10:14:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610550801; bh=Ua1mWCOr4LTqZEzaZB63R+wqOSGeuV/pZ/FWoM0VPhU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=EjvCz0Bzav/NqkqTtJzHKx36Ytz1dIlrN4OtdOKLQ7lrtMJIWjfAwYShEo3kYxpby rGw0FNPn+d4BpdgELueNGgafVv78YmVQ2ZjzR8edq5kGXEMKLuo2k2zETpuUpNJ66R g+qYRHoPVR3MnxgRmRHHc6qNvv/b1q9VP+cT1yXQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.203.161.65]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Ma24y-1kTvNN1sNI-00W2Ab; Wed, 13 Jan 2021 16:13:21 +0100 Date: Wed, 13 Jan 2021 17:10:07 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de Subject: [PATCH 1/6 v6] Revert "MIPS: Remove unused R4300 CPU support" Message-Id: <20210113171007.27fe6b22bf30839c74023e50@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:qEW1+u/+y2sdnrGz4ReJAylgtnG5VCfaELmb/dxS3TmTWxKPOVZ KX7jJNO9F5PoM+gN6I8MuxScKXFpWiH8tWWAwy02ywdSXQT4Slmw85Chdiu2LoTkZCHmx+C OgsWvW+3gcAqvptNTKxYUN58W0Uhh/9UwY2S10EUvln1HxFJ9KF6TIkbaD6Z1Kf0Vcxy0NF UCCujY5cklVEvYv0UmA6g== X-UI-Out-Filterresults: notjunk:1;V03:K0:dX4YoNjPAPQ=:HZdAPqeUL6W4Li7lDseIjm PetUgWdvF9/jumvm0y3M1DqpSlLjJBxERhzD+xsFtEYddaCrMoimuzFBjCcSnc5gunVXs/Rd/ E5lhggtnBHvkvHYFdCpqk9w1S8mweX1/vO5ifMQc+RxJKwnjv+jMpF047CZmYCCn2mAS3wLI7 QQqkxvk7Jwtu3wUMdvMMuJMc4RqQ9Xo3Qe+x7ufOUQDaHEC14ySYwMIDhz08Vq0Tzde4AoN9O zFywn1uz8T4JodcVObMsdrcyp3UmF+yJVJgqq+cA2a3SfeoRZu1IoAzzpYhSJJc1uFxHFzhVM +C3lAkLeJ0mF+p/eZ7phbG3PZUm1oZgOQzmeTPSjoeoTDvZj6qxJjMWh32Kt7FFM7hiasZc2B Iiwq0uwe4wxieN5XhngpW2QkkBoJ8OWSfF8YYXl2YQrv8YSLgc9nSxswCnCJK6Y2oxYiE+m8D f5EE1M9LxGG4SSf+4lQB5RH9X+KFa03Fxdn4T3OpUgHEmcQRPtwGDBS9+QvAyLZtmTtg+xL23 YKIgrb/B9mLNGgoCzFz1V4z1Dg9/Y168d1rhPu/UTGELCIgKwQfDz3hVuGZx3V71oBogGYHMv iXxZRXOgWgf3X9zzxnrEWSOqPu9Gbf+9WhHMdCWzOeLr6/sKXOh0TQjUGYPagcCIvQIlvkqxd MYkuIxcYQZ8tgP9acJlgjqtWSnKpGk68IXSFgOaWpMs2fC8KYm1++4vtS/ZPVzX2/dDTwlBNw O8tFn5FByAk798F19VTqQh9mFou6BykU7pm5xLh9eQn6jaKXE/W+yjWPjUbCYj0wm3EfuEZHS 9gPRNkaFuKqTzFdHaI74PvgJmPkMS3Pf6sSZV9XihQiNHl7UugH3oU+yGgpnYub23Uo5OHA0E rDUAIyDFd+eyuWAfQ71w== 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 Wed Jan 13 15:11:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 12017095 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 1053EC43381 for ; Wed, 13 Jan 2021 15:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC9E82339F for ; Wed, 13 Jan 2021 15:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727098AbhAMPO5 (ORCPT ); Wed, 13 Jan 2021 10:14:57 -0500 Received: from mout.gmx.net ([212.227.17.22]:41283 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbhAMPO4 (ORCPT ); Wed, 13 Jan 2021 10:14:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610550803; bh=T/6b+3todXSSG5409OuwHyo42/2sCdV+KtuJQSRBK+g=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=FWh3nXwg2U7kY3/f+i1LZYv1f88MH7Z7Ak+jLDQe6RZ+IIj9EJnKHnuiHhyXo1/i4 +d+rev25knhfNDIRWLlOsHGgfslPC+Y5kdo3uWMKRqUQBFAK/1V4g0lXZmjTv0HHwf Ny9cVoEpYCJKuC7D7FXQl4UekeF/Ul2KpCWapoqE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.203.161.65]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MKsnF-1keacQ01sr-00LDuL; Wed, 13 Jan 2021 16:13:23 +0100 Date: Wed, 13 Jan 2021 17:11:23 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de Subject: [PATCH 2/6 v6] mips: Add N64 machine type Message-Id: <20210113171123.7c819ee9cb9f07f0a4e80e5a@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:0UMD4F8XDgJO3tszpN6bdNHvtfSQ8SsGfpA4VQecV0JQxho6KeM uQyy23qVazc9VxYHjC1isBgHwSYw+8rqVFVgxN+Ec8N4fk2+rv7oWsw4FmLAjzgYwOvrrNO Jh8itf9cMnV0M4oJD6xcmU4qIA2heI+NdXchUtRaoIx1T6DSEGLdW1M7hCAcN1AYvIPINAM gCXNh5q9TtCmjn1Qg8GPA== X-UI-Out-Filterresults: notjunk:1;V03:K0:TM496gGslcA=:POk1WtZTaDLzW33DloGENu Qfpcz0LO+PFjVJ0KgmXQ++dx5gHq6Yfxr3rcV1NK2IT4KQJwR4uY+3zAlDyyx8lXwxCg8fihU Gn8q7ozkX0yhyA5TjSZ6DwE2lKZ3D36ITCX2P2E/mk6lAXGVymC6K2kLexXrGiB8/YXZU90cE sbExgLZmi1n9AXUb4P5NfUaj2bDHxvHODrXIARAZtvVkeyIO93p6NaPpMDwHU3rUiyL5w+Z2+ xto5fmz499g8VpaRZAikEKkdh32Vmlq7hgPp3qwl6PcELLgA2PwokOxdG77H8pLE7poklflSF KGd6anCkb4cEVDhrnnkrbAj3Y8YIrsdO8CHFWgnA5JKeeTb/wIlKrVoUc0AIFzQ1c6CGMfYTU iylBMdCH0TaC9BRZRjMP9UoKQzNchy8QYjctV5GFbNYO7k7EQ5ghrmi4OARKXuag8+3SzjzQZ iHvxg1dbGszm+yc/E9RmVxT9bljqoYw0+v7wr0UclvvZ161vTh6Qq+qfcvcBRJrL242eaaTkH YjqnGOrJw15J90U9yfdH1g1vvaswkob/26A+5C8m2ucyZcZtvF9VPbPxEuAULyvZAcHXd+V7C xl84oOKXffjaFqhsLs8VyQPUZGWZcxVhMkPFipaLfk/WOlJ0vIZJWEMpkn+2jnJJ/oBvJKQ2/ MZb0FyfVSh+D5t86VzrSxb6UHuO2H94j0bA8IPBhISiNn7+mXiV1S8/p+FhQ6Jrv04zfCy7yX r85aBu7l/YaoGinBfp2jzwV10B67+TU1TxsdB9zlS521Bmy6M20L8pO004uqlT16t5UZM+JZs odiMxSCsDlJu5ogJq81Q/qKhxs26Ky290OOkfeS6wFuWQvL4ABRqH4tphU++CvI2Q1bPJ45VW K4L+Q+A+aAYaEgE4FCOA== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Add support for the Nintendo 64. 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/mach-n64/kmalloc.h | 8 ++ arch/mips/n64/Makefile | 6 ++ arch/mips/n64/Platform | 7 ++ arch/mips/n64/init.c | 164 +++++++++++++++++++++++++++++++ arch/mips/n64/irq.c | 16 +++ 8 files changed, 223 insertions(+) create mode 100644 arch/mips/include/asm/mach-n64/irq.h create mode 100644 arch/mips/include/asm/mach-n64/kmalloc.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..7e260fc --- /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 + +#define NR_IRQS 8 + +#include + +#endif /* __ASM_MACH_N64_IRQ_H */ diff --git a/arch/mips/include/asm/mach-n64/kmalloc.h b/arch/mips/include/asm/mach-n64/kmalloc.h new file mode 100644 index 0000000..e8b8d0b --- /dev/null +++ b/arch/mips/include/asm/mach-n64/kmalloc.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MACH_N64_KMALLOC_H +#define __ASM_MACH_N64_KMALLOC_H + +/* The default of 128 bytes wastes too much, use 32 (the largest cacheline, I) */ +#define ARCH_DMA_MINALIGN L1_CACHE_BYTES + +#endif /* __ASM_MACH_N64_KMALLOC_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..dfbd864 --- /dev/null +++ b/arch/mips/n64/init.c @@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Nintendo 64 init. + * + * Copyright (C) 2021 Lauri Kasanen + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define IO_MEM_RESOURCE_START 0UL +#define IO_MEM_RESOURCE_END 0x1fffffffUL + +/* + * System-specifc irq names for clarity + */ +#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) + +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(); +} + +#define W 320 +#define H 240 +#define REG_BASE ((u32 *) CKSEG1ADDR(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 +}; + +#define MI_REG_BASE 0x4300000 +#define NUM_MI_REGS 4 +#define AI_REG_BASE 0x4500000 +#define NUM_AI_REGS 6 +#define PI_REG_BASE 0x4600000 +#define NUM_PI_REGS 5 +#define SI_REG_BASE 0x4800000 +#define NUM_SI_REGS 7 + +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[3]; + void *orig; + unsigned long phys; + unsigned i; + + memset(res, 0, sizeof(struct resource) * 3); + res[0].flags = IORESOURCE_MEM; + res[0].start = MI_REG_BASE; + res[0].end = MI_REG_BASE + NUM_MI_REGS * 4 - 1; + + res[1].flags = IORESOURCE_MEM; + res[1].start = AI_REG_BASE; + res[1].end = AI_REG_BASE + NUM_AI_REGS * 4 - 1; + + res[2].flags = IORESOURCE_IRQ; + res[2].start = RCP_IRQ; + res[2].end = RCP_IRQ; + + platform_device_register_simple("n64audio", -1, res, 3); + + memset(&res[0], 0, sizeof(res[0])); + res[0].flags = IORESOURCE_MEM; + res[0].start = PI_REG_BASE; + res[0].end = PI_REG_BASE + NUM_PI_REGS * 4 - 1; + + platform_device_register_simple("n64cart", -1, res, 1); + + memset(&res[0], 0, sizeof(res[0])); + res[0].flags = IORESOURCE_MEM; + res[0].start = SI_REG_BASE; + res[0].end = SI_REG_BASE + NUM_SI_REGS * 4 - 1; + + platform_device_register_simple("n64joy", -1, res, 1); + + /* 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], 0, sizeof(res[0])); + res[0].flags = IORESOURCE_MEM; + res[0].name = simplefb_resname; + res[0].start = phys; + res[0].end = phys + W * H * 2 - 1; + + platform_device_register_resndata(NULL, "simple-framebuffer", 0, + &res[0], 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..1861e96 --- /dev/null +++ b/arch/mips/n64/irq.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * N64 IRQ + * + * Copyright (C) 2021 Lauri Kasanen + */ +#include +#include +#include + +#include + +void __init arch_init_irq(void) +{ + mips_cpu_irq_init(); +} From patchwork Wed Jan 13 15:11:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 12017097 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 3D189C4332D for ; Wed, 13 Jan 2021 15:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0052623383 for ; Wed, 13 Jan 2021 15:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727106AbhAMPO7 (ORCPT ); Wed, 13 Jan 2021 10:14:59 -0500 Received: from mout.gmx.net ([212.227.15.18]:39473 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbhAMPO6 (ORCPT ); Wed, 13 Jan 2021 10:14:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610550804; bh=BdwxHxrB1Im1p2gJdU7lopAgVR1ZdU52H6JL1Np4VBE=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=Rk58TbNP00KDrJOkxum5OeOFQan7ybTPitUFawylIpG5BislvkpT1j5r9jNHX2lRX n8imEzDqlCRRFurs8hrEJxVgdM1+09sjWE6Dnr4t/jvkL8DRf2ACyGhbW5IEdoF/qq J4iuupBMDeUv27F+CYzWqpVuXX53xSA5+Mpe224w= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.203.161.65]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N9dsV-1juagr2Rdd-015bWP; Wed, 13 Jan 2021 16:13:24 +0100 Date: Wed, 13 Jan 2021 17:11:59 +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 v6] fbdev/simplefb: Add the N64's mode Message-Id: <20210113171159.ed46ea46b7af0cc6cf2a85d8@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:LwetTB+MxlEVHEKm7us3JYdkzhTBNZNn+rYCBtcsE3BxifyJLM/ uOFWf1RFlL5IwAB4zbhfsZU0faUgyL336vvUBAXBf18sEN9IZdwaKvC+4w/ZYIJs8uTy0zy hY5GWxrT02g6Bit1jhoOAQ8LDKBZN2LyfTfe+t1KZUPvObcfTJ5oq5+YUxxSn3MnypQ/b9p Qdqm0LLosCyw5DqD+Y7RQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:+VujxkjW69o=:g9uhkoSra1LLU4UF51Y9JF 4Nvi7yc4n7mvSRwmOCo+qDDtG/g+CEJZgWxp8mYxQSJVODVkKu8f9A1GVotRmGY72/L6w/pMN ce5ozqVo2IPdliNr854bv5snJDHop5GkJHlDqiYjIRYOs+Xg01k7Vdcx73nIq46Y/lx6kugkj d1CaIcg1+I62UbbRobksgVVuaeZ6ufD+6qc/sa5pic58r2XJUWtMsUnMAjf0efKunhI121kmg WgrToa3XSRXiC8suIaoLUA4FTrN7UxBRNsJHHI3v7vDfLPZURpD/NT7CLcajSNRPRqM38I7NM r3Mm4H+TIcjgk//CIZcpK4J88kjyEgXyc4aftLwdIgDyZ8qnfS/p+Bg6bNf08uWp4OXsYya8x k+tDdw4VWFcmNWhWf3MqlV4BJDyoWhyiC6Rwf7YlFqZjv7f57Tl4WZAjGgElT/0OLZzFR04+p Fpg6heQBsAKh4aQsssHQtpPGu/EGqVF7nRVxh1dyLvAhUieHGT3Aq7YnoE697mKVAcMt82w36 uYL4uq3ElVAbAYJyxhSXfePXxdlANDG+4E1kTfFMUPJR3HTAOgp1Nst/2Q8ZpMleUGqbJ8ziy JRsi2d27E6159crkHOwkzWqmamPGjASbGeE4Amy2Xh1TCVDTwcVCyWhg1zvaHFJ7kYpbyj79b pIkP4FyAXSXCbv0z5VY9IEmHn7pFkCEKABwXQoKKBItg/EQmJphiFubpTZwxHZ2vdmsAhEW0a TV/P1WUYTFC6Yb8+AgzRyWnzf9zV2tZZgywAVF7V4ATxbR4n0fypmHJK68K+xYS2l4y2LYSyp go01CiZBLGPwJtkfiEQYg97HJj+7IFXGLjZyZpZhhq52ztSMXfx5o5G5LrZcFkdn89Kxi6Rz/ 8T1SV7cPbIEwuXBZF/hw== 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(+) -- 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 Wed Jan 13 15:12:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 12017099 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 6DE62C43331 for ; Wed, 13 Jan 2021 15:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DB6D23383 for ; Wed, 13 Jan 2021 15:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727170AbhAMPPC (ORCPT ); Wed, 13 Jan 2021 10:15:02 -0500 Received: from mout.gmx.net ([212.227.15.18]:46697 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbhAMPPB (ORCPT ); Wed, 13 Jan 2021 10:15:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610550806; bh=V2H1LQMFORpJ3T6RKLvfoJKZ/snyAYsiqh5441bb8M0=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=beyjTFwbog9PcAPws51tsITMe7r/2iD6biAw71LRCXYK107F6gTNRvbsBXRPTIJpA HhVG0ZhKRLjZbkh54K/WqWjvWBfXuhd2ExPQIgHZkiu4+2ElHQTH01H++4P3FobO7A ER0sDf3M9Re/QztL+cOTZHKTRBEed04HIV4/CkPI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.203.161.65]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N3KTo-1jzncq0Rta-010NLP; Wed, 13 Jan 2021 16:13:26 +0100 Date: Wed, 13 Jan 2021 17:12:36 +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 v6] input: Add N64 controller driver Message-Id: <20210113171236.c22d14ff656dba3d21910c45@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:s/Q5eAR5yB2r0cnHgQgNVEapiWggeDm3m22VvyO64NrVM8Pd8M0 ps6eFDLqO7q4dcH93WU8fv4oZBXQ26bAVUoDmYkv0MUcQFHD+FfG2TOYN/LcA+NueBO4Tal eNhl34Tgc9DHelq279ykIm/jZ4Vea1qL0Vy5TbHNUcNg+WNyAKSLqnj899kCDR5DnvaXhk7 biyG+kKq+aW/85z7bLxtg== X-UI-Out-Filterresults: notjunk:1;V03:K0:UYyUa50UhtU=:2phw2q0QiJFLABflJds36h 49cqwL6szlM/7ECruWFEacRCDJw8t5ozJgfDpaYK5CV2GU3guj7dIh4YmZpcSS38SX/oJxosP 1L6uPBdl48A7BMAoDsvDgoOzh5P3AdSLOxmEdHuTBz5k8aJo5RQS/jJ6BUKdF8DYvrXUuy8YH 5W7iy7AsGPD9eaoRg76gGGfv9poSv+7ZcpJ0C3Zbox8OC+lKq6rNXQ2TN/G9uYVqyv3tUCAcD VJkw9LrlfqOXSk06YNMA4OuY4KpUxv3YEF7wi+i3kXw026KKMTBa35E0bOhdeHxLBcjrKmH5p GkuRUY2MCkXsEgEQF7DxYpJCOg4SYNI66i3Hrex2CdWCbzbap6wkOy2K/UOcBoi3X9ZmymJq8 MP5hLsi2beMymKVZ0Ohuw0QDbZRoVWApvUmaxjiLiMX5GmLAUm+4cq/4UwBW1XSDVR9ts6p0S kYLg8ueR2pu/n7/pJNfmO0GC45Bh84g6pDxL1HrSioVdj2VRGmMIKlA+CDsMP1mipjzUxdb5k CM53TGOxWRYzZLDrhM5dewBpTtR/qCEgfZtSzLhHPF9H5fkdnSzV3mQRdTdpv42v8srHg7K6/ veSoFzakcJbjRDCsWNPLaNbWleklfdMjvPlAcVaDGWU4Il9eZ8qxlYBXBOEs+arBV9XboHLe8 86HI+mY+VA078ME6VhgvcsllIZlrOjEN69zVPpyAZ2xV43okDayu/1RO8X+ueLorLjAf7S7Vj DRJ0oYtOhgD5mxDlIN4kNBBou5O1IgEs/wrBSoL25FGhB/LRZE7UsMq2U69fjtt7Bog28ciEZ P6N1vLCzYxZra9qUPSeFV/e8DpBYKXfcL8n/sXp2M+Vc0QLdUXOR9GPlTp2kpwJSJRf7PMJax gCudQODQ/iOgoTmWSqGQ== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This adds support for the four built-in controller ports on the Nintendo 64 console. The N64 controller includes an analog stick, a d-pad, and several buttons. No module support as the target has only 8mb ram. Signed-off-by: Lauri Kasanen --- drivers/input/joystick/Kconfig | 6 + drivers/input/joystick/Makefile | 2 +- drivers/input/joystick/n64joy.c | 345 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 352 insertions(+), 1 deletion(-) create mode 100644 drivers/input/joystick/n64joy.c -- 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..e7650c5 --- /dev/null +++ b/drivers/input/joystick/n64joy.c @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for the four N64 controllers. + * + * Copyright (c) 2021 Lauri Kasanen + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#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 SI_DRAM_REG 0 +#define SI_READ_REG 1 +#define SI_WRITE_REG 4 +#define SI_STATUS_REG 6 + +#define SI_STATUS_DMA_BUSY BIT(0) +#define SI_STATUS_IO_BUSY BIT(1) + +#define N64_CONTROLLER_ID 0x0500 + +#define MAX_CONTROLLERS 4 + +static const char *n64joy_phys[MAX_CONTROLLERS] = { + "n64joy/port0", + "n64joy/port1", + "n64joy/port2", + "n64joy/port3", +}; + +struct n64joy_priv { + u64 si_buf[8] ____cacheline_aligned; + struct timer_list timer; + struct mutex n64joy_mutex; + struct input_dev *n64joy_dev[MAX_CONTROLLERS]; + u32 __iomem *reg_base; + u8 n64joy_opened; +}; + +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(u32 __iomem *reg_base, const u8 reg, const u32 value) +{ + writel(value, reg_base + reg); +} + +static u32 n64joy_read_reg(u32 __iomem *reg_base, const u8 reg) +{ + return readl(reg_base + reg); +} + +static void n64joy_wait_si_dma(u32 __iomem *reg_base) +{ + while (n64joy_read_reg(reg_base, SI_STATUS_REG) & + (SI_STATUS_DMA_BUSY | SI_STATUS_IO_BUSY)) + cpu_relax(); +} + +static void n64joy_exec_pif(struct n64joy_priv *priv, const u64 in[8]) +{ + unsigned long flags; + + dma_cache_wback_inv((unsigned long) in, 8 * 8); + dma_cache_inv((unsigned long) priv->si_buf, 8 * 8); + + local_irq_save(flags); + + n64joy_wait_si_dma(priv->reg_base); + + barrier(); + n64joy_write_reg(priv->reg_base, SI_DRAM_REG, virt_to_phys(in)); + barrier(); + n64joy_write_reg(priv->reg_base, SI_WRITE_REG, PIF_RAM); + barrier(); + + n64joy_wait_si_dma(priv->reg_base); + + barrier(); + n64joy_write_reg(priv->reg_base, SI_DRAM_REG, virt_to_phys(priv->si_buf)); + barrier(); + n64joy_write_reg(priv->reg_base, SI_READ_REG, PIF_RAM); + barrier(); + + n64joy_wait_si_dma(priv->reg_base); + + 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; + struct n64joy_priv *priv = container_of(t, struct n64joy_priv, timer); + struct input_dev *dev; + u32 i; + + n64joy_exec_pif(priv, polldata); + + data = (struct joydata *) priv->si_buf; + + for (i = 0; i < MAX_CONTROLLERS; i++) { + if (!priv->n64joy_dev[i]) + continue; + + dev = priv->n64joy_dev[i]; + + // d-pad + input_report_key(dev, BTN_DPAD_UP, data[i].up); + input_report_key(dev, BTN_DPAD_DOWN, data[i].down); + input_report_key(dev, BTN_DPAD_LEFT, data[i].left); + input_report_key(dev, BTN_DPAD_RIGHT, data[i].right); + + // c buttons + input_report_key(dev, BTN_FORWARD, data[i].c_up); + input_report_key(dev, BTN_BACK, data[i].c_down); + input_report_key(dev, BTN_LEFT, data[i].c_left); + input_report_key(dev, BTN_RIGHT, data[i].c_right); + + // matching buttons + input_report_key(dev, BTN_START, data[i].start); + input_report_key(dev, BTN_Z, data[i].z); + + // remaining ones: a, b, l, r + input_report_key(dev, BTN_0, data[i].a); + input_report_key(dev, BTN_1, data[i].b); + input_report_key(dev, BTN_2, data[i].l); + input_report_key(dev, BTN_3, data[i].r); + + input_report_abs(dev, ABS_X, data[i].x); + input_report_abs(dev, ABS_Y, data[i].y); + + input_sync(dev); + } + + mod_timer(&priv->timer, jiffies + msecs_to_jiffies(16)); +} + +static int n64joy_open(struct input_dev *dev) +{ + struct n64joy_priv *priv = input_get_drvdata(dev); + int err; + + err = mutex_lock_interruptible(&priv->n64joy_mutex); + if (err) + return err; + + if (!priv->n64joy_opened) { + // Could use the vblank irq, but it's not important if the poll + // point slightly changes. + timer_setup(&priv->timer, n64joy_poll, 0); + mod_timer(&priv->timer, jiffies + msecs_to_jiffies(16)); + } + + priv->n64joy_opened++; + + mutex_unlock(&priv->n64joy_mutex); + return err; +} + +static void n64joy_close(struct input_dev *dev) +{ + struct n64joy_priv *priv = input_get_drvdata(dev); + + mutex_lock(&priv->n64joy_mutex); + if (!--priv->n64joy_opened) + del_timer_sync(&priv->timer); + mutex_unlock(&priv->n64joy_mutex); +} + +static const u64 __initconst scandata[] ____cacheline_aligned = { + 0xff010300ffffffff, + 0xff010300ffffffff, + 0xff010300ffffffff, + 0xff010300ffffffff, + 0xfe00000000000000, + 0, + 0, + 1 +}; + +/* + * The target device is embedded and RAM-constrained. We save RAM + * by initializing in __init code that gets dropped late in boot. + * For the same reason there is no module or unloading support. + */ +static int __init n64joy_probe(struct platform_device *pdev) +{ + const struct joydata *data; + struct resource *res; + struct n64joy_priv *priv; + struct input_dev *dev; + unsigned long len; + int err = 0; + u32 i, j, found = 0; + + priv = kzalloc(sizeof(struct n64joy_priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + mutex_init(&priv->n64joy_mutex); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + len = res->end - res->start + 1; + priv->reg_base = ioremap(res->start, len); + + // The controllers are not hotpluggable, so we can scan in init + n64joy_exec_pif(priv, scandata); + + data = (struct joydata *) priv->si_buf; + + for (i = 0; i < MAX_CONTROLLERS; i++) { + if (!data[i].err && data[i].data >> 16 == N64_CONTROLLER_ID) { + found++; + + dev = priv->n64joy_dev[i] = input_allocate_device(); + if (!priv->n64joy_dev[i]) { + err = -ENOMEM; + goto fail; + } + + input_set_drvdata(dev, priv); + + dev->name = "N64 controller"; + dev->phys = n64joy_phys[i]; + dev->id.bustype = BUS_HOST; + dev->id.vendor = 0; + dev->id.product = data[i].data >> 16; + dev->id.version = 0; + + dev->open = n64joy_open; + dev->close = n64joy_close; + + // d-pad + input_set_capability(dev, EV_KEY, BTN_DPAD_UP); + input_set_capability(dev, EV_KEY, BTN_DPAD_DOWN); + input_set_capability(dev, EV_KEY, BTN_DPAD_LEFT); + input_set_capability(dev, EV_KEY, BTN_DPAD_RIGHT); + // c buttons + input_set_capability(dev, EV_KEY, BTN_LEFT); + input_set_capability(dev, EV_KEY, BTN_RIGHT); + input_set_capability(dev, EV_KEY, BTN_FORWARD); + input_set_capability(dev, EV_KEY, BTN_BACK); + // matching buttons + input_set_capability(dev, EV_KEY, BTN_START); + input_set_capability(dev, EV_KEY, BTN_Z); + // remaining ones: a, b, l, r + input_set_capability(dev, EV_KEY, BTN_0); + input_set_capability(dev, EV_KEY, BTN_1); + input_set_capability(dev, EV_KEY, BTN_2); + input_set_capability(dev, EV_KEY, BTN_3); + + for (j = 0; j < 2; j++) { + input_set_abs_params(dev, ABS_X + j, + S8_MIN, S8_MAX, 0, 0); + } + + err = input_register_device(dev); + if (err) { + input_free_device(dev); + goto fail; + } + } + } + + pr_info("%u controller(s) connected\n", found); + + if (!found) + return -ENODEV; + + return 0; +fail: + iounmap(priv->reg_base); + + for (i = 0; i < MAX_CONTROLLERS; i++) { + if (!priv->n64joy_dev[i]) + continue; + input_unregister_device(priv->n64joy_dev[i]); + } + return err; +} + +static struct platform_driver n64joy_driver = { + .driver = { + .name = "n64joy", + }, +}; + +static int __init n64joy_init(void) +{ + return platform_driver_probe(&n64joy_driver, n64joy_probe); +} + +module_init(n64joy_init); From patchwork Wed Jan 13 15:13:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 12017103 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 29E05C433E6 for ; Wed, 13 Jan 2021 15:15:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8CC0233EA for ; Wed, 13 Jan 2021 15:15:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726428AbhAMPPs (ORCPT ); Wed, 13 Jan 2021 10:15:48 -0500 Received: from mout.gmx.net ([212.227.17.20]:50377 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726110AbhAMPPr (ORCPT ); Wed, 13 Jan 2021 10:15:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610550808; bh=ih038vNom860+Luq7dptmrljH8GSyARXxRKYyPbV81o=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=dT8d2bbM5qXgVwSGTvphCadVgX6kJmTVjFOXq6PEXZlDB62dhU4DrPNk6N6LK9AA4 qFg5jTulFlqU0dyVdPegRgEyQu11Hk4lwKDqAHS/ow7wFeq/sHSaSclc6do+qydhMt Cak7XELZfMMNK+CbOfNxTzWrtNIYifdwNNfd/T+U= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.203.161.65]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MOzSu-1kaTsZ3dmu-00PNyc; Wed, 13 Jan 2021 16:13:28 +0100 Date: Wed, 13 Jan 2021 17:13:22 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, Takashi Iwai , perex@perex.cz Subject: [PATCH 5/6 v6] sound: Add n64 driver Message-Id: <20210113171322.77105fa8f92826e6b716631a@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:jq1+PRkeakZUHKHbapl05DsnKim5wBrSEBSPH+Jx8ccFkqOCW4e klD42KFpjLjx/aCqHBcj5ItqJymc0v1UJxLPMPN4gCh3R7DOvXYA165gtnDJ2kLuH2gmXv6 jNaXiWH8CoEbu/0AdMs47VG2bdPfahfX+TdFJPRXcz7cMGnIn0IqbIje1J8BeaPW75eQeNe sLin0wjFewzgswmnX0JSg== X-UI-Out-Filterresults: notjunk:1;V03:K0:CvVfkDNIykc=:AsWB2Be8XKQy9MFoEZh/y+ 7Vwl8cjhFvDJgNxHVoT/lxrnTBnXCxcrBs3nroB1CYjUtuElf+IsXXY9ipo1FUBfPAPtqrdDv yf3wT/IEznW5lBiZVVFsfkCIEulI2CzDm+rmGKWTq9mGiyH2EFyhBPEdYrunNKKJLUhXH+7Fd egjHmf//HJC/ZZ0iiu2HFPTmcgAAevVABOLZAS8EOduSkq9uQtniobbJcfPeEnWJmTo6T5PgF 5hTSt76SzBNeHW5KFHzUaYuyTfguACXvrSK9WvJw25rmbhow3VSTNAtgJrRYezx8BNGjQ8rPg SQFpNstfU1pM5NH20H1hL+nCBzvHe0RG3qeZoJhhEjBWpohT9jQB4oEnP5OGJ4stsaQaYT4Q3 cz6j5RRYKxOOaAMVyl4I2H4uk/6SclVzx6yGSeT6Z1n4mXW0/GWL0rtdl/nv+2LIwNKV1W7jf 0RKU5ut9RGI8PEV4Mfldc15YgrHSsMWPO2SgW09ldy9u5Rx1RzoWIj2jytvF2kwL4Um3zQqtQ LZUqfBO/dCzA4ebX3Ut7xagL2Wxu0N8P0psqWGlbktOa0WXYjeFtmrHHxPFigxBzvF4lZHbhs c2Z6pp3uVcmXhDidn1DampLyGatMW0PZNKwnVhl94tLGiv/hpvNDfXtlFH26FYlsuKRpuc4CX 5PoF1GF0F24SScr3PoH5BxPNHhcJP8BX5O5v9BzT1jemtz53bSatE3GMfQuYqd+jWfYrozg+n NiUOLU1NQcxBt1gmGVHD7T7R8AKP0n5xfbTP9iW3t1Pj+uMJZ5THqe60hSht8bSPhyCgPMSIm veVi/r+vA4cOq5bV5VKteUBsdQlE4gFUUAQSiDRk3cXT8+wFxBDJgSsnkosGCc5GCG2N33zdw b6HX23nGSLUfkuAfmBKw== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This adds support for the Nintendo 64 console's sound. Signed-off-by: Lauri Kasanen Reviewed-by: Takashi Iwai --- sound/mips/Kconfig | 7 + sound/mips/Makefile | 1 + sound/mips/snd-n64.c | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 390 insertions(+) create mode 100644 sound/mips/snd-n64.c v6: moved irq before register -- 2.6.2 diff --git a/sound/mips/Kconfig b/sound/mips/Kconfig index b497b80..c484b1e 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 && SND=y + 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..faaf497 --- /dev/null +++ b/sound/mips/snd-n64.c @@ -0,0 +1,382 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sound driver for Nintendo 64. + * + * Copyright 2021 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 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_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 { + u32 __iomem *ai_reg_base; + u32 __iomem *mi_reg_base; + + void *ring_base; + dma_addr_t ring_base_dma; + + struct snd_card *card; + + struct { + struct snd_pcm_substream *substream; + int pos, nextpos; + u32 writesize; + u32 bufsize; + spinlock_t lock; + } chan; +}; + +static void n64audio_write_reg(struct n64audio *priv, const u8 reg, const u32 value) +{ + writel(value, priv->ai_reg_base + reg); +} + +static void n64mi_write_reg(struct n64audio *priv, const u8 reg, const u32 value) +{ + writel(value, priv->mi_reg_base + reg); +} + +static u32 n64mi_read_reg(struct n64audio *priv, const u8 reg) +{ + return readl(priv->mi_reg_base + reg); +} + +static void n64audio_push(struct n64audio *priv) +{ + struct snd_pcm_runtime *runtime = priv->chan.substream->runtime; + unsigned long flags; + u32 count; + + spin_lock_irqsave(&priv->chan.lock, flags); + + count = priv->chan.writesize; + + memcpy(priv->ring_base + priv->chan.nextpos, + runtime->dma_area + priv->chan.nextpos, count); + + /* + * The hw registers are double-buffered, and the IRQ fires essentially + * one period behind. The core only allows one period's distance, so we + * keep a private DMA buffer to afford two. + */ + n64audio_write_reg(priv, AI_ADDR_REG, priv->ring_base_dma + priv->chan.nextpos); + barrier(); + n64audio_write_reg(priv, AI_LEN_REG, count); + + priv->chan.nextpos += count; + priv->chan.nextpos %= priv->chan.bufsize; + + runtime->delay = runtime->period_size; + + spin_unlock_irqrestore(&priv->chan.lock, flags); +} + +static irqreturn_t n64audio_isr(int irq, void *dev_id) +{ + struct n64audio *priv = dev_id; + const u32 intrs = n64mi_read_reg(priv, MI_INTR_REG); + unsigned long flags; + + // Check it's ours + if (!(intrs & MI_INTR_AI)) + return IRQ_NONE; + + n64audio_write_reg(priv, AI_STATUS_REG, 1); + + if (priv->chan.substream && snd_pcm_running(priv->chan.substream)) { + spin_lock_irqsave(&priv->chan.lock, flags); + + priv->chan.pos = priv->chan.nextpos; + + spin_unlock_irqrestore(&priv->chan.lock, flags); + + snd_pcm_period_elapsed(priv->chan.substream); + if (priv->chan.substream && snd_pcm_running(priv->chan.substream)) + n64audio_push(priv); + } + + 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 = 3, + // 3 periods lets the double-buffering hw read one buffer behind safely + .periods_max = 128, +}; + +static int hw_rule_period_size(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_interval *c = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_PERIOD_SIZE); + int changed = 0; + + /* + * The DMA unit has errata on (start + len) & 0x3fff == 0x2000. + * This constraint makes sure that the period size is not a power of two, + * which combined with dma_alloc_coherent aligning the buffer to the largest + * PoT <= size guarantees it won't be hit. + */ + + if (is_power_of_2(c->min)) { + c->min += 2; + changed = 1; + } + if (is_power_of_2(c->max)) { + c->max -= 2; + changed = 1; + } + if (snd_interval_checkempty(c)) { + c->empty = 1; + return -EINVAL; + } + + return changed; +} + +static int n64audio_pcm_open(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + int err; + + runtime->hw = n64audio_pcm_hw; + err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); + if (err < 0) + return err; + + err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 2); + if (err < 0) + return err; + + err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, + hw_rule_period_size, NULL, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); + if (err < 0) + return err; + + return 0; +} + +static int n64audio_pcm_prepare(struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct n64audio *priv = substream->pcm->private_data; + u32 rate; + + rate = ((2 * AI_NTSC_DACRATE / runtime->rate) + 1) / 2 - 1; + + n64audio_write_reg(priv, AI_RATE_REG, rate); + + rate /= 66; + if (rate > 16) + rate = 16; + n64audio_write_reg(priv, AI_BITCLOCK_REG, rate - 1); + + spin_lock_irq(&priv->chan.lock); + + /* 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_irq(&priv->chan.lock); + return 0; +} + +static int n64audio_pcm_trigger(struct snd_pcm_substream *substream, + int cmd) +{ + struct n64audio *priv = substream->pcm->private_data; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + n64audio_push(substream->pcm->private_data); + n64audio_write_reg(priv, AI_CONTROL_REG, 1); + n64mi_write_reg(priv, MI_MASK_REG, MI_MASK_SET_AI); + break; + case SNDRV_PCM_TRIGGER_STOP: + n64audio_write_reg(priv, AI_CONTROL_REG, 0); + n64mi_write_reg(priv, 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 *priv = substream->pcm->private_data; + + return bytes_to_frames(substream->runtime, + priv->chan.pos); +} + +static int n64audio_pcm_close(struct snd_pcm_substream *substream) +{ + struct n64audio *priv = substream->pcm->private_data; + + priv->chan.substream = NULL; + + return 0; +} + +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, +}; + +/* + * The target device is embedded and RAM-constrained. We save RAM + * by initializing in __init code that gets dropped late in boot. + * For the same reason there is no module or unloading support. + */ +static int __init n64audio_probe(struct platform_device *pdev) +{ + struct snd_card *card; + struct snd_pcm *pcm; + struct n64audio *priv; + struct resource *res; + unsigned long len; + int err; + + err = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, + SNDRV_DEFAULT_STR1, + THIS_MODULE, sizeof(*priv), &card); + if (err < 0) + return err; + + priv = card->private_data; + + spin_lock_init(&priv->chan.lock); + + 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) { + err = -ENOMEM; + goto fail_card; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + len = res->end - res->start + 1; + priv->mi_reg_base = ioremap(res->start, len); + if (!priv->mi_reg_base) { + err = -EINVAL; + goto fail_dma_alloc; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + len = res->end - res->start + 1; + priv->ai_reg_base = ioremap(res->start, len); + if (!priv->ai_reg_base) { + err = -EINVAL; + goto fail_mi_ioremap; + } + + err = snd_pcm_new(card, "N64 Audio", 0, 1, 0, &pcm); + if (err < 0) + goto fail_ioremaps; + + 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, card->dev, 0, 0); + + strcpy(card->driver, "N64 Audio"); + strcpy(card->shortname, "N64 Audio"); + strcpy(card->longname, "N64 Audio"); + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (request_irq(res->start, n64audio_isr, + IRQF_SHARED, "N64 Audio", priv)) { + err = -EBUSY; + goto fail_ioremaps; + } + + err = snd_card_register(card); + if (err < 0) + goto fail_ioremaps; + + return 0; + +fail_ioremaps: + iounmap(priv->ai_reg_base); +fail_mi_ioremap: + iounmap(priv->mi_reg_base); + +fail_dma_alloc: + dma_free_coherent(card->dev, 32 * 1024, priv->ring_base, priv->ring_base_dma); + +fail_card: + snd_card_free(card); + return err; +} + +static struct platform_driver n64audio_driver = { + .driver = { + .name = "n64audio", + }, +}; + +static int __init n64audio_init(void) +{ + return platform_driver_probe(&n64audio_driver, n64audio_probe); +} + +module_init(n64audio_init); From patchwork Wed Jan 13 15:13:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lauri Kasanen X-Patchwork-Id: 12017101 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 CC77AC433E0 for ; Wed, 13 Jan 2021 15:15:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7223123383 for ; Wed, 13 Jan 2021 15:15:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726238AbhAMPPI (ORCPT ); Wed, 13 Jan 2021 10:15:08 -0500 Received: from mout.gmx.net ([212.227.17.20]:45289 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbhAMPPG (ORCPT ); Wed, 13 Jan 2021 10:15:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610550810; bh=h04l1+sWPKPAwhjVSAZUr5CU46wuJzYkH3K+JynbfOM=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=cphnYPpFTCFu0NbkmAaowLeNV6hQ2vsDZkMqbVzio94z6seVbzeSzYk5T/Eo6Mj5a UZ8quHor+BQoodmUGuf1Hsqhd8Ucg8hAkyejAtA0189iMe0ddRa/q3jdLcU1QlyAuD g3g9wTPSkaiyhz5QuAvyjUTtZ7Nb0cBaBF2AEBFg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Valinor ([82.203.161.65]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MLiCu-1kiAzB2u5w-00HgPM; Wed, 13 Jan 2021 16:13:29 +0100 Date: Wed, 13 Jan 2021 17:13:59 +0200 From: Lauri Kasanen To: linux-mips@vger.kernel.org Cc: tsbogend@alpha.franken.de, axboe@kernel.dk, linux-block@vger.kernel.org, Keith Busch Subject: [PATCH 6/6 v6] block: Add n64 cart driver Message-Id: <20210113171359.489f6a94ecbaa9244f10e26e@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:HftX1ENzjFmWj4iceLdAhmGTnD0GerpMr/W7B9mdG3287f5cR4T PsnblnEFVT3LD434gyqpjpL8E/+VDbe6tucSRCwyQwFkxxP6wsPT8egvh9xOEHQ5RIRIsou QKzl8zlnR3fU7iGMOG/eWtmNLceAbebmxhh0nd3zMM2TgH+LInY+wGPMNFYjROuT534Sj/x FbUXS1l7pwqXMrYZbYNaw== X-UI-Out-Filterresults: notjunk:1;V03:K0:/eQoRQHhqwU=:jSrTbdtCLSG6uiSz6kHQgR TjQL2GY60BWwr804hzmnhJ+3r+sB9q5IGsi+jcb11KU8clCfCegNpEr1AQn4zgcGLRZ3gQjKz aNYorXMdsRTlZacTU4XokDf6eUC+c5FI3Yaoo0w/wcZ207uVysm2TlTCoqbb1JULZyDGuYQlC A9+RBpz6LSfjBBt9zlie45AdpGlbc4H38DJpXpSsGQuW5xbTxdzbBhAhpTmOQC6vV9dq95fFX c2kNfBvngRYKgqEHrGYf8TXOAPCymkxGgWKpK9cRaOnXd3UMupSHmY+rjzYfOkACZxEK2SxYT lQVkAR8chu8rTdA7SO25NTHQ7oogCmFrJ7kzOWAO6gj/2o4Uon1UYeAGHLJh/Arjom7BEDju2 uCgcVODq7RT6vIA2TS8wxgqpI3rRIu7nrMAeyQ0cD7KzFkdzSjuxeLBOCJ3ApRvMWjGiSZfIY ZzGnSEcJoGCyqhZCEY1jixJQOPdFIhhNl+yP4RB/f5n1ZZDhX6LzqHi/SmIh0HM1eUtSGKszZ 9v72jvSXsoMbR/Hyut/lk7PCnLIEftxfG8kfr5Hj7fv25apk0vl9+XNQZdNKWxvN07ZGMoS0x /y18ShvHcjl0fo2JGKcFk3E4pBIC+1lgV/przQ8CMHdry+mkMDUTkQzUl3mQkawuYhzdsrD/W ZfvkxifgmLOYOpPO/VZUSZbOcMi24KMBaVZlr8lH856oVeahUy3BPDXKiy7UM0l1YhKBxKS2X 3rh3kUvcRhJ/xWHNcu50KGPAN17Oj1Wr2AemXkqhvkSgnJ1DeHPYzSpaVuynfbGwQzvhzMVIq rjqBwHf98jDBj/WZ3bN+pe6AdZU3YW+sTIf07KrNMN9Scy8fLd6CkrCJDQ3LRNg3oCpOLP4kE 7RsLGcvDWTv7qOtY1wHA== Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org This adds support for the Nintendo 64 console's carts. Carts are a read-only media ranging from 8mb to 64mb. Only one cart can be connected at once, and switching it requires a reboot. No module support to save RAM, as the target has 8mb RAM. Signed-off-by: Lauri Kasanen --- drivers/block/Kconfig | 6 ++ drivers/block/Makefile | 1 + drivers/block/n64cart.c | 217 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 drivers/block/n64cart.c -- 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..f8c17b0 --- /dev/null +++ b/drivers/block/n64cart.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for the N64 cart. + * + * Copyright (c) 2021 Lauri Kasanen + */ + +#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 u32 __iomem *reg_base; + +#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) +{ + writel(value, reg_base + reg); +} + +static u32 n64cart_read_reg(const u8 reg) +{ + return 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)) + cpu_relax(); +} + +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) + 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) +{ + struct request *req = bd->rq; + blk_status_t err; + + blk_mq_start_request(req); + + do { + err = get_seg(req); + } while (blk_update_request(req, err, blk_rq_cur_bytes(req))); + + 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, +}; + +/* + * The target device is embedded and RAM-constrained. We save RAM + * by initializing in __init code that gets dropped late in boot. + * For the same reason there is no module or unloading support. + */ +static int __init n64cart_probe(struct platform_device *pdev) +{ + struct resource *res; + unsigned long len; + 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, 1, + BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING); + 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; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + len = res->end - res->start + 1; + reg_base = ioremap(res->start, len); + + 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); + set_disk_ro(disk, 1); + + 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; +} + +static struct platform_driver n64cart_driver = { + .driver = { + .name = "n64cart", + }, +}; + +static int __init n64cart_init(void) +{ + return platform_driver_probe(&n64cart_driver, n64cart_probe); +} + +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);