xref: /linux/arch/arm/mach-tegra/tegra.c (revision 24fa5af81059af90c723bec6aacc3cd2b2809d14)
1 /*
2  * NVIDIA Tegra SoC device tree board support
3  *
4  * Copyright (C) 2011, 2013, NVIDIA Corporation
5  * Copyright (C) 2010 Secret Lab Technologies, Ltd.
6  * Copyright (C) 2010 Google, Inc.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  */
18 
19 #include <linux/clk.h>
20 #include <linux/clk/tegra.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/init.h>
23 #include <linux/io.h>
24 #include <linux/irqchip.h>
25 #include <linux/irqdomain.h>
26 #include <linux/kernel.h>
27 #include <linux/of_address.h>
28 #include <linux/of_fdt.h>
29 #include <linux/of.h>
30 #include <linux/of_platform.h>
31 #include <linux/pda_power.h>
32 #include <linux/platform_device.h>
33 #include <linux/serial_8250.h>
34 #include <linux/slab.h>
35 #include <linux/sys_soc.h>
36 #include <linux/usb/tegra_usb_phy.h>
37 
38 #include <soc/tegra/fuse.h>
39 
40 #include <asm/hardware/cache-l2x0.h>
41 #include <asm/mach/arch.h>
42 #include <asm/mach/time.h>
43 #include <asm/mach-types.h>
44 #include <asm/setup.h>
45 #include <asm/trusted_foundations.h>
46 
47 #include "board.h"
48 #include "common.h"
49 #include "cpuidle.h"
50 #include "iomap.h"
51 #include "irq.h"
52 #include "pmc.h"
53 #include "pm.h"
54 #include "reset.h"
55 #include "sleep.h"
56 
57 /*
58  * Storage for debug-macro.S's state.
59  *
60  * This must be in .data not .bss so that it gets initialized each time the
61  * kernel is loaded. The data is declared here rather than debug-macro.S so
62  * that multiple inclusions of debug-macro.S point at the same data.
63  */
64 u32 tegra_uart_config[3] = {
65 	/* Debug UART initialization required */
66 	1,
67 	/* Debug UART physical address */
68 	0,
69 	/* Debug UART virtual address */
70 	0,
71 };
72 
73 static void __init tegra_init_early(void)
74 {
75 	of_register_trusted_foundations();
76 	tegra_cpu_reset_handler_init();
77 	tegra_powergate_init();
78 }
79 
80 static void __init tegra_dt_init_irq(void)
81 {
82 	tegra_pmc_init_irq();
83 	tegra_init_irq();
84 	irqchip_init();
85 	tegra_legacy_irq_syscore_init();
86 }
87 
88 static void __init tegra_dt_init(void)
89 {
90 	struct soc_device_attribute *soc_dev_attr;
91 	struct soc_device *soc_dev;
92 	struct device *parent = NULL;
93 
94 	tegra_pmc_init();
95 
96 	tegra_clocks_apply_init_table();
97 
98 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
99 	if (!soc_dev_attr)
100 		goto out;
101 
102 	soc_dev_attr->family = kasprintf(GFP_KERNEL, "Tegra");
103 	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d",
104 					   tegra_sku_info.revision);
105 	soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%u", tegra_get_chip_id());
106 
107 	soc_dev = soc_device_register(soc_dev_attr);
108 	if (IS_ERR(soc_dev)) {
109 		kfree(soc_dev_attr->family);
110 		kfree(soc_dev_attr->revision);
111 		kfree(soc_dev_attr->soc_id);
112 		kfree(soc_dev_attr);
113 		goto out;
114 	}
115 
116 	parent = soc_device_to_device(soc_dev);
117 
118 	/*
119 	 * Finished with the static registrations now; fill in the missing
120 	 * devices
121 	 */
122 out:
123 	of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
124 }
125 
126 static void __init paz00_init(void)
127 {
128 	if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
129 		tegra_paz00_wifikill_init();
130 }
131 
132 static struct {
133 	char *machine;
134 	void (*init)(void);
135 } board_init_funcs[] = {
136 	{ "compal,paz00", paz00_init },
137 };
138 
139 static void __init tegra_dt_init_late(void)
140 {
141 	int i;
142 
143 	tegra_init_suspend();
144 	tegra_cpuidle_init();
145 	tegra_powergate_debugfs_init();
146 
147 	for (i = 0; i < ARRAY_SIZE(board_init_funcs); i++) {
148 		if (of_machine_is_compatible(board_init_funcs[i].machine)) {
149 			board_init_funcs[i].init();
150 			break;
151 		}
152 	}
153 }
154 
155 static const char * const tegra_dt_board_compat[] = {
156 	"nvidia,tegra124",
157 	"nvidia,tegra114",
158 	"nvidia,tegra30",
159 	"nvidia,tegra20",
160 	NULL
161 };
162 
163 DT_MACHINE_START(TEGRA_DT, "NVIDIA Tegra SoC (Flattened Device Tree)")
164 	.l2c_aux_val	= 0x3c400001,
165 	.l2c_aux_mask	= 0xc20fc3fe,
166 	.smp		= smp_ops(tegra_smp_ops),
167 	.map_io		= tegra_map_common_io,
168 	.init_early	= tegra_init_early,
169 	.init_irq	= tegra_dt_init_irq,
170 	.init_machine	= tegra_dt_init,
171 	.init_late	= tegra_dt_init_late,
172 	.restart	= tegra_pmc_restart,
173 	.dt_compat	= tegra_dt_board_compat,
174 MACHINE_END
175