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