Skip to content

Commit

Permalink
MIPS: Add support for PIC32MZDA platform
Browse files Browse the repository at this point in the history
This adds support for the Microchip PIC32 MIPS microcontroller with the
specific variant PIC32MZDA. PIC32MZDA is based on the MIPS m14KEc core
and boots using device tree.

This includes an early pin setup and early clock setup needed prior to
device tree being initialized. In additon, an interface is provided to
synchronize access to registers shared across several peripherals.

Signed-off-by: Joshua Henderson <joshua.henderson@microchip.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/12097/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  • Loading branch information
Joshua Henderson authored and Ralf Baechle committed Jan 24, 2016
1 parent 9b9c2cd commit 2572f00
Show file tree
Hide file tree
Showing 22 changed files with 1,476 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/mips/Kbuild.platforms
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ platforms += mti-malta
platforms += mti-sead3
platforms += netlogic
platforms += paravirt
platforms += pic32
platforms += pistachio
platforms += pmcs-msp71xx
platforms += pnx833x
Expand Down
9 changes: 9 additions & 0 deletions arch/mips/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ config MIPS_MALTA
This enables support for the MIPS Technologies Malta evaluation
board.

config MACH_PIC32
bool "Microchip PIC32 Family"
help
This enables support for the Microchip PIC32 family of platforms.

Microchip PIC32 is a family of general-purpose 32 bit MIPS core
microcontrollers.

config MIPS_SEAD3
bool "MIPS SEAD3 board"
select BOOT_ELF32
Expand Down Expand Up @@ -980,6 +988,7 @@ source "arch/mips/jazz/Kconfig"
source "arch/mips/jz4740/Kconfig"
source "arch/mips/lantiq/Kconfig"
source "arch/mips/lasat/Kconfig"
source "arch/mips/pic32/Kconfig"
source "arch/mips/pistachio/Kconfig"
source "arch/mips/pmcs-msp71xx/Kconfig"
source "arch/mips/ralink/Kconfig"
Expand Down
32 changes: 32 additions & 0 deletions arch/mips/include/asm/mach-pic32/cpu-feature-overrides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Joshua Henderson <joshua.henderson@microchip.com>
* Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#ifndef __ASM_MACH_PIC32_CPU_FEATURE_OVERRIDES_H
#define __ASM_MACH_PIC32_CPU_FEATURE_OVERRIDES_H

/*
* CPU feature overrides for PIC32 boards
*/
#ifdef CONFIG_CPU_MIPS32
#define cpu_has_vint 1
#define cpu_has_veic 0
#define cpu_has_tlb 1
#define cpu_has_4kex 1
#define cpu_has_4k_cache 1
#define cpu_has_fpu 0
#define cpu_has_counter 1
#define cpu_has_llsc 1
#define cpu_has_nofpuex 0
#define cpu_icache_snoops_remote_store 1
#endif

#ifdef CONFIG_CPU_MIPS64
#error This platform does not support 64bit.
#endif

#endif /* __ASM_MACH_PIC32_CPU_FEATURE_OVERRIDES_H */
22 changes: 22 additions & 0 deletions arch/mips/include/asm/mach-pic32/irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Joshua Henderson <joshua.henderson@microchip.com>
* Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License (Version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef __ASM_MACH_PIC32_IRQ_H
#define __ASM_MACH_PIC32_IRQ_H

#define NR_IRQS 256
#define MIPS_CPU_IRQ_BASE 0

#include_next <irq.h>

#endif /* __ASM_MACH_PIC32_IRQ_H */
44 changes: 44 additions & 0 deletions arch/mips/include/asm/mach-pic32/pic32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Joshua Henderson <joshua.henderson@microchip.com>
* Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License (Version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef _ASM_MACH_PIC32_H
#define _ASM_MACH_PIC32_H

#include <linux/io.h>

/*
* PIC32 register offsets for SET/CLR/INV where supported.
*/
#define PIC32_CLR(_reg) ((_reg) + 0x04)
#define PIC32_SET(_reg) ((_reg) + 0x08)
#define PIC32_INV(_reg) ((_reg) + 0x0C)

/*
* PIC32 Base Register Offsets
*/
#define PIC32_BASE_CONFIG 0x1f800000
#define PIC32_BASE_OSC 0x1f801200
#define PIC32_BASE_RESET 0x1f801240
#define PIC32_BASE_PPS 0x1f801400
#define PIC32_BASE_UART 0x1f822000
#define PIC32_BASE_PORT 0x1f860000
#define PIC32_BASE_DEVCFG2 0x1fc4ff44

/*
* Register unlock sequence required for some register access.
*/
void pic32_syskey_unlock_debug(const char *fn, const ulong ln);
#define pic32_syskey_unlock() \
pic32_syskey_unlock_debug(__func__, __LINE__)

#endif /* _ASM_MACH_PIC32_H */
24 changes: 24 additions & 0 deletions arch/mips/include/asm/mach-pic32/spaces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Joshua Henderson <joshua.henderson@microchip.com>
* Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License (Version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef _ASM_MACH_PIC32_SPACES_H
#define _ASM_MACH_PIC32_SPACES_H

#ifdef CONFIG_PIC32MZDA
#define PHYS_OFFSET _AC(0x08000000, UL)
#define UNCAC_BASE _AC(0xa8000000, UL)
#endif

#include <asm/mach-generic/spaces.h>

#endif /* __ASM_MACH_PIC32_SPACES_H */
35 changes: 35 additions & 0 deletions arch/mips/pic32/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if MACH_PIC32

choice
prompt "Machine Type"

config PIC32MZDA
bool "Microchip PIC32MZDA Platform"
select BOOT_ELF32
select BOOT_RAW
select CEVT_R4K
select CSRC_R4K
select DMA_NONCOHERENT
select SYS_HAS_CPU_MIPS32_R2
select SYS_HAS_EARLY_PRINTK
select SYS_SUPPORTS_32BIT_KERNEL
select SYS_SUPPORTS_LITTLE_ENDIAN
select ARCH_REQUIRE_GPIOLIB
select HAVE_MACH_CLKDEV
select COMMON_CLK
select CLKDEV_LOOKUP
select LIBFDT
select USE_OF
select PINCTRL
select PIC32_EVIC
help
Support for the Microchip PIC32MZDA microcontroller.

This is a 32-bit microcontroller with support for external or
internally packaged DDR2 memory up to 128MB.

For more information, see <http://www.microchip.com/>.

endchoice

endif # MACH_PIC32
6 changes: 6 additions & 0 deletions arch/mips/pic32/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Joshua Henderson, <joshua.henderson@microchip.com>
# Copyright (C) 2015 Microchip Technology, Inc. All rights reserved.
#
obj-$(CONFIG_MACH_PIC32) += common/
obj-$(CONFIG_PIC32MZDA) += pic32mzda/
7 changes: 7 additions & 0 deletions arch/mips/pic32/Platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# PIC32MZDA
#
platform-$(CONFIG_PIC32MZDA) += pic32/
cflags-$(CONFIG_PIC32MZDA) += -I$(srctree)/arch/mips/include/asm/mach-pic32
load-$(CONFIG_PIC32MZDA) += 0xffffffff88000000
all-$(CONFIG_PIC32MZDA) := $(COMPRESSION_FNAME).bin
5 changes: 5 additions & 0 deletions arch/mips/pic32/common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Joshua Henderson, <joshua.henderson@microchip.com>
# Copyright (C) 2015 Microchip Technology, Inc. All rights reserved.
#
obj-y = reset.o irq.o
21 changes: 21 additions & 0 deletions arch/mips/pic32/common/irq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Joshua Henderson <joshua.henderson@microchip.com>
* Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License (Version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <linux/init.h>
#include <linux/irqchip.h>
#include <asm/irq.h>

void __init arch_init_irq(void)
{
irqchip_init();
}
62 changes: 62 additions & 0 deletions arch/mips/pic32/common/reset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Joshua Henderson <joshua.henderson@microchip.com>
* Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
*
* This program is free software; you can distribute it and/or modify it
* under the terms of the GNU General Public License (Version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <linux/init.h>
#include <linux/pm.h>
#include <asm/reboot.h>
#include <asm/mach-pic32/pic32.h>

#define PIC32_RSWRST 0x10

static void pic32_halt(void)
{
while (1) {
__asm__(".set push;\n"
".set arch=r4000;\n"
"wait;\n"
".set pop;\n"
);
}
}

static void pic32_machine_restart(char *command)
{
void __iomem *reg =
ioremap(PIC32_BASE_RESET + PIC32_RSWRST, sizeof(u32));

pic32_syskey_unlock();

/* magic write/read */
__raw_writel(1, reg);
(void)__raw_readl(reg);

pic32_halt();
}

static void pic32_machine_halt(void)
{
local_irq_disable();

pic32_halt();
}

static int __init mips_reboot_setup(void)
{
_machine_restart = pic32_machine_restart;
_machine_halt = pic32_machine_halt;
pm_power_off = pic32_machine_halt;

return 0;
}

arch_initcall(mips_reboot_setup);
9 changes: 9 additions & 0 deletions arch/mips/pic32/pic32mzda/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Joshua Henderson, <joshua.henderson@microchip.com>
# Copyright (C) 2015 Microchip Technology, Inc. All rights reserved.
#
obj-y := init.o time.o config.o

obj-$(CONFIG_EARLY_PRINTK) += early_console.o \
early_pin.o \
early_clk.o
Loading

0 comments on commit 2572f00

Please sign in to comment.