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)  * Joshua Henderson, joshua.henderson@microchip.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2015 Microchip Technology Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_data/sdhci-pic32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/fw/fw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/mips-boards/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "pic32mzda.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) const char *get_system_type(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	return "PIC32MZDA";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static ulong get_fdtaddr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	ulong ftaddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (fw_passed_dtb && !fw_arg2 && !fw_arg3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		return (ulong)fw_passed_dtb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (__dtb_start < __dtb_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		ftaddr = (ulong)__dtb_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return ftaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) void __init plat_mem_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	void *dtb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	dtb = (void *)get_fdtaddr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (!dtb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		pr_err("pic32: no DTB found.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 * Load the builtin device tree. This causes the chosen node to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 * parsed resulting in our memory appearing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	__dt_setup_arch(dtb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	pr_info("Found following command lines\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	pr_info(" boot_command_line: %s\n", boot_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	pr_info(" arcs_cmdline     : %s\n", arcs_cmdline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #ifdef CONFIG_CMDLINE_BOOL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	pr_info(" builtin_cmdline  : %s\n", CONFIG_CMDLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (dtb != __dtb_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #ifdef CONFIG_EARLY_PRINTK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	fw_init_early_console(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	pic32_config_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static __init void pic32_init_cmdline(int argc, char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned int count = COMMAND_LINE_SIZE - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	char *dst = &(arcs_cmdline[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	for (i = 1; i < argc && count; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		src = argv[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		while (*src && count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			*dst++ = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			--count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		*dst++ = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (i > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		--dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	*dst = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) void __init prom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	pic32_init_cmdline((int)fw_arg0, (char **)fw_arg1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void __init prom_free_prom_memory(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) void __init device_tree_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!initial_boot_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	unflatten_and_copy_device_tree();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static struct pic32_sdhci_platform_data sdhci_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.setup_dma = pic32_set_sdhci_adma_fifo_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static struct of_dev_auxdata pic32_auxdata_lookup[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	OF_DEV_AUXDATA("microchip,pic32mzda-sdhci", 0, "sdhci", &sdhci_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	{ /* sentinel */}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int __init pic32_of_prepare_platform_data(struct of_dev_auxdata *lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct device_node *root, *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	root = of_find_node_by_path("/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	for (; lookup->compatible; lookup++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		np = of_find_compatible_node(NULL, NULL, lookup->compatible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			lookup->name = (char *)np->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			if (lookup->phys_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			if (!of_address_to_resource(np, 0, &res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				lookup->phys_addr = res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int __init plat_of_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (!of_have_populated_dt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		panic("Device tree not present");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	pic32_of_prepare_platform_data(pic32_auxdata_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (of_platform_default_populate(NULL, pic32_auxdata_lookup, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		panic("Failed to populate DT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) arch_initcall(plat_of_setup);