blob: ea14d380fc0cd51beb66d8ef049999d7bb563420 [file] [log] [blame]
Grant Likely8e267f32011-07-19 17:26:54 -06001/*
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +02002 * NVIDIA Tegra SoC device tree board support
Grant Likely8e267f32011-07-19 17:26:54 -06003 *
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +02004 * Copyright (C) 2011, 2013, NVIDIA Corporation
Grant Likely8e267f32011-07-19 17:26:54 -06005 * 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/kernel.h>
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/serial_8250.h>
23#include <linux/clk.h>
24#include <linux/dma-mapping.h>
25#include <linux/irqdomain.h>
26#include <linux/of.h>
27#include <linux/of_address.h>
28#include <linux/of_fdt.h>
Grant Likely8e267f32011-07-19 17:26:54 -060029#include <linux/of_platform.h>
30#include <linux/pda_power.h>
31#include <linux/io.h>
Danny Huangd591fdf2013-03-14 08:48:40 +080032#include <linux/slab.h>
33#include <linux/sys_soc.h>
Stephen Warrenbab53ce2012-08-27 14:22:48 -070034#include <linux/usb/tegra_usb_phy.h>
Stephen Warren441f1992013-03-25 13:22:24 -060035#include <linux/clk/tegra.h>
Stephen Warren51100bd2013-08-20 15:47:38 -060036#include <linux/irqchip.h>
Grant Likely8e267f32011-07-19 17:26:54 -060037
Stephen Warren51100bd2013-08-20 15:47:38 -060038#include <asm/hardware/cache-l2x0.h>
Grant Likely8e267f32011-07-19 17:26:54 -060039#include <asm/mach-types.h>
40#include <asm/mach/arch.h>
41#include <asm/mach/time.h>
42#include <asm/setup.h>
43
Stephen Warren51100bd2013-08-20 15:47:38 -060044#include "apbio.h"
Grant Likely8e267f32011-07-19 17:26:54 -060045#include "board.h"
Marc Zyngiera1725732011-09-08 13:15:22 +010046#include "common.h"
Stephen Warren51100bd2013-08-20 15:47:38 -060047#include "cpuidle.h"
Danny Huangd591fdf2013-03-14 08:48:40 +080048#include "fuse.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060049#include "iomap.h"
Stephen Warren51100bd2013-08-20 15:47:38 -060050#include "irq.h"
Stephen Warrend2207072013-08-20 15:17:35 -060051#include "pmc.h"
Stephen Warren51100bd2013-08-20 15:47:38 -060052#include "pm.h"
53#include "reset.h"
54#include "sleep.h"
55
56/*
57 * Storage for debug-macro.S's state.
58 *
59 * This must be in .data not .bss so that it gets initialized each time the
60 * kernel is loaded. The data is declared here rather than debug-macro.S so
61 * that multiple inclusions of debug-macro.S point at the same data.
62 */
Stephen Warren2f1d70a2013-11-05 14:10:53 -070063u32 tegra_uart_config[3] = {
Stephen Warren51100bd2013-08-20 15:47:38 -060064 /* Debug UART initialization required */
65 1,
66 /* Debug UART physical address */
67 0,
68 /* Debug UART virtual address */
69 0,
Stephen Warren51100bd2013-08-20 15:47:38 -060070};
71
72static void __init tegra_init_cache(void)
73{
74#ifdef CONFIG_CACHE_L2X0
75 int ret;
76 void __iomem *p = IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x3000;
77 u32 aux_ctrl, cache_type;
78
79 cache_type = readl(p + L2X0_CACHE_TYPE);
80 aux_ctrl = (cache_type & 0x700) << (17-8);
81 aux_ctrl |= 0x7C400001;
82
83 ret = l2x0_of_init(aux_ctrl, 0x8200c3fe);
84 if (!ret)
85 l2x0_saved_regs_addr = virt_to_phys(&l2x0_saved_regs);
86#endif
87}
88
89static void __init tegra_init_early(void)
90{
Stephen Warren51100bd2013-08-20 15:47:38 -060091 tegra_apb_io_init();
92 tegra_init_fuse();
Alexandre Courbotcd198d62013-11-12 13:03:16 -070093 tegra_cpu_reset_handler_init();
Stephen Warren51100bd2013-08-20 15:47:38 -060094 tegra_init_cache();
95 tegra_powergate_init();
96 tegra_hotplug_init();
97}
98
99static void __init tegra_dt_init_irq(void)
100{
101 tegra_pmc_init_irq();
102 tegra_init_irq();
103 irqchip_init();
104 tegra_legacy_irq_syscore_init();
105}
Stephen Warrenbab53ce2012-08-27 14:22:48 -0700106
Grant Likely8e267f32011-07-19 17:26:54 -0600107static void __init tegra_dt_init(void)
108{
Danny Huangd591fdf2013-03-14 08:48:40 +0800109 struct soc_device_attribute *soc_dev_attr;
110 struct soc_device *soc_dev;
111 struct device *parent = NULL;
112
Stephen Warrend2207072013-08-20 15:17:35 -0600113 tegra_pmc_init();
114
Stephen Warren441f1992013-03-25 13:22:24 -0600115 tegra_clocks_apply_init_table();
116
Danny Huangd591fdf2013-03-14 08:48:40 +0800117 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
118 if (!soc_dev_attr)
119 goto out;
120
121 soc_dev_attr->family = kasprintf(GFP_KERNEL, "Tegra");
122 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d", tegra_revision);
123 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", tegra_chip_id);
124
125 soc_dev = soc_device_register(soc_dev_attr);
126 if (IS_ERR(soc_dev)) {
127 kfree(soc_dev_attr->family);
128 kfree(soc_dev_attr->revision);
129 kfree(soc_dev_attr->soc_id);
130 kfree(soc_dev_attr);
131 goto out;
132 }
133
134 parent = soc_device_to_device(soc_dev);
135
Stephen Warrena58116f2011-12-16 15:12:32 -0700136 /*
137 * Finished with the static registrations now; fill in the missing
138 * devices
139 */
Danny Huangd591fdf2013-03-14 08:48:40 +0800140out:
Tuomas Tynkkynen5fed6822013-07-25 21:38:04 +0300141 of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
Grant Likely8e267f32011-07-19 17:26:54 -0600142}
143
Stephen Warrenb64a02c2012-05-02 16:05:44 -0600144static void __init paz00_init(void)
145{
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +0200146 if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
147 tegra_paz00_wifikill_init();
Stephen Warrenb64a02c2012-05-02 16:05:44 -0600148}
Stephen Warrenb64a02c2012-05-02 16:05:44 -0600149
Stephen Warrenc554dee2012-05-02 13:43:26 -0600150static struct {
151 char *machine;
152 void (*init)(void);
153} board_init_funcs[] = {
Stephen Warrenb64a02c2012-05-02 16:05:44 -0600154 { "compal,paz00", paz00_init },
Stephen Warrenc554dee2012-05-02 13:43:26 -0600155};
156
157static void __init tegra_dt_init_late(void)
158{
159 int i;
160
Stephen Warren51100bd2013-08-20 15:47:38 -0600161 tegra_init_suspend();
162 tegra_cpuidle_init();
163 tegra_powergate_debugfs_init();
Stephen Warrenc554dee2012-05-02 13:43:26 -0600164
165 for (i = 0; i < ARRAY_SIZE(board_init_funcs); i++) {
166 if (of_machine_is_compatible(board_init_funcs[i].machine)) {
167 board_init_funcs[i].init();
168 break;
169 }
170 }
171}
172
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +0200173static const char * const tegra_dt_board_compat[] = {
Joseph Lo73944472013-10-08 12:50:03 +0800174 "nvidia,tegra124",
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +0200175 "nvidia,tegra114",
176 "nvidia,tegra30",
Stephen Warrenc5444f32012-02-27 18:26:16 -0700177 "nvidia,tegra20",
Grant Likely8e267f32011-07-19 17:26:54 -0600178 NULL
179};
180
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +0200181DT_MACHINE_START(TEGRA_DT, "NVIDIA Tegra SoC (Flattened Device Tree)")
Grant Likely8e267f32011-07-19 17:26:54 -0600182 .map_io = tegra_map_common_io,
Marc Zyngiera1725732011-09-08 13:15:22 +0100183 .smp = smp_ops(tegra_smp_ops),
Hiroshi Doyu74696882013-02-13 19:15:48 +0200184 .init_early = tegra_init_early,
pdeschrijver@nvidia.com0d4f7472011-11-29 18:29:19 -0700185 .init_irq = tegra_dt_init_irq,
Grant Likely8e267f32011-07-19 17:26:54 -0600186 .init_machine = tegra_dt_init,
Stephen Warrenc554dee2012-05-02 13:43:26 -0600187 .init_late = tegra_dt_init_late,
Stephen Warren51100bd2013-08-20 15:47:38 -0600188 .restart = tegra_pmc_restart,
Hiroshi Doyu1b14f3a2013-02-13 19:15:50 +0200189 .dt_compat = tegra_dt_board_compat,
Grant Likely8e267f32011-07-19 17:26:54 -0600190MACHINE_END