Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (c) 2011 Picochip Ltd., Jamie Iles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * All enquiries to support@picochip.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/mach/arch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/mach/map.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define PHYS_TO_IO(x)			(((x) & 0x00ffffff) | 0xfe000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define PICOXCELL_PERIPH_BASE		0x80000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PICOXCELL_PERIPH_LENGTH		SZ_4M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define WDT_CTRL_REG_EN_MASK		(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define WDT_CTRL_REG_OFFS		(0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define WDT_TIMEOUT_REG_OFFS		(0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static void __iomem *wdt_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  * The machine restart method can be called from an atomic context so we won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * be able to ioremap the regs then.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void picoxcell_setup_restart(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	struct device_node *np = of_find_compatible_node(NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 							 "snps,dw-apb-wdg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (WARN(!np, "unable to setup watchdog restart"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	wdt_regs = of_iomap(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	WARN(!wdt_regs, "failed to remap watchdog regs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static struct map_desc io_map __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	.virtual	= PHYS_TO_IO(PICOXCELL_PERIPH_BASE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	.pfn		= __phys_to_pfn(PICOXCELL_PERIPH_BASE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	.length		= PICOXCELL_PERIPH_LENGTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	.type		= MT_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static void __init picoxcell_map_io(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	iotable_init(&io_map, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static void __init picoxcell_init_machine(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	picoxcell_setup_restart();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static const char *picoxcell_dt_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	"picochip,pc3x2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	"picochip,pc3x3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void picoxcell_wdt_restart(enum reboot_mode mode, const char *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	 * Configure the watchdog to reset with the shortest possible timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	 * and give it chance to do the reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	if (wdt_regs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 		/* No sleeping, possibly atomic. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		mdelay(500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	.map_io		= picoxcell_map_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	.init_machine	= picoxcell_init_machine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	.dt_compat	= picoxcell_dt_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	.restart	= picoxcell_wdt_restart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) MACHINE_END