Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 1 | /* |
Hiroshi Doyu | 1b14f3a | 2013-02-13 19:15:50 +0200 | [diff] [blame] | 2 | * NVIDIA Tegra SoC device tree board support |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 3 | * |
Hiroshi Doyu | 1b14f3a | 2013-02-13 19:15:50 +0200 | [diff] [blame] | 4 | * Copyright (C) 2011, 2013, NVIDIA Corporation |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 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 | |
Stephen Warren | 1711b1e | 2012-10-23 11:52:53 -0600 | [diff] [blame] | 19 | #include <linux/clocksource.h> |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/serial_8250.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/irqdomain.h> |
| 27 | #include <linux/of.h> |
| 28 | #include <linux/of_address.h> |
| 29 | #include <linux/of_fdt.h> |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 30 | #include <linux/of_platform.h> |
| 31 | #include <linux/pda_power.h> |
| 32 | #include <linux/io.h> |
Danny Huang | d591fdf | 2013-03-14 08:48:40 +0800 | [diff] [blame] | 33 | #include <linux/slab.h> |
| 34 | #include <linux/sys_soc.h> |
Stephen Warren | bab53ce | 2012-08-27 14:22:48 -0700 | [diff] [blame] | 35 | #include <linux/usb/tegra_usb_phy.h> |
Stephen Warren | d220707 | 2013-08-20 15:17:35 -0600 | [diff] [blame] | 36 | #include <linux/clk-provider.h> |
Stephen Warren | 441f199 | 2013-03-25 13:22:24 -0600 | [diff] [blame] | 37 | #include <linux/clk/tegra.h> |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 38 | #include <linux/irqchip.h> |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 39 | |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 40 | #include <asm/hardware/cache-l2x0.h> |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 41 | #include <asm/mach-types.h> |
| 42 | #include <asm/mach/arch.h> |
| 43 | #include <asm/mach/time.h> |
| 44 | #include <asm/setup.h> |
| 45 | |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 46 | #include "apbio.h" |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 47 | #include "board.h" |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 48 | #include "common.h" |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 49 | #include "cpuidle.h" |
Danny Huang | d591fdf | 2013-03-14 08:48:40 +0800 | [diff] [blame] | 50 | #include "fuse.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 51 | #include "iomap.h" |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 52 | #include "irq.h" |
Stephen Warren | d220707 | 2013-08-20 15:17:35 -0600 | [diff] [blame] | 53 | #include "pmc.h" |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 54 | #include "pm.h" |
| 55 | #include "reset.h" |
| 56 | #include "sleep.h" |
| 57 | |
| 58 | /* |
| 59 | * Storage for debug-macro.S's state. |
| 60 | * |
| 61 | * This must be in .data not .bss so that it gets initialized each time the |
| 62 | * kernel is loaded. The data is declared here rather than debug-macro.S so |
| 63 | * that multiple inclusions of debug-macro.S point at the same data. |
| 64 | */ |
| 65 | u32 tegra_uart_config[4] = { |
| 66 | /* Debug UART initialization required */ |
| 67 | 1, |
| 68 | /* Debug UART physical address */ |
| 69 | 0, |
| 70 | /* Debug UART virtual address */ |
| 71 | 0, |
| 72 | /* Scratch space for debug macro */ |
| 73 | 0, |
| 74 | }; |
| 75 | |
| 76 | static void __init tegra_init_cache(void) |
| 77 | { |
| 78 | #ifdef CONFIG_CACHE_L2X0 |
| 79 | int ret; |
| 80 | void __iomem *p = IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x3000; |
| 81 | u32 aux_ctrl, cache_type; |
| 82 | |
| 83 | cache_type = readl(p + L2X0_CACHE_TYPE); |
| 84 | aux_ctrl = (cache_type & 0x700) << (17-8); |
| 85 | aux_ctrl |= 0x7C400001; |
| 86 | |
| 87 | ret = l2x0_of_init(aux_ctrl, 0x8200c3fe); |
| 88 | if (!ret) |
| 89 | l2x0_saved_regs_addr = virt_to_phys(&l2x0_saved_regs); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | static void __init tegra_init_early(void) |
| 94 | { |
| 95 | tegra_cpu_reset_handler_init(); |
| 96 | tegra_apb_io_init(); |
| 97 | tegra_init_fuse(); |
| 98 | tegra_init_cache(); |
| 99 | tegra_powergate_init(); |
| 100 | tegra_hotplug_init(); |
| 101 | } |
| 102 | |
| 103 | static void __init tegra_dt_init_irq(void) |
| 104 | { |
| 105 | tegra_pmc_init_irq(); |
| 106 | tegra_init_irq(); |
| 107 | irqchip_init(); |
| 108 | tegra_legacy_irq_syscore_init(); |
| 109 | } |
Stephen Warren | bab53ce | 2012-08-27 14:22:48 -0700 | [diff] [blame] | 110 | |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 111 | static void __init tegra_dt_init(void) |
| 112 | { |
Danny Huang | d591fdf | 2013-03-14 08:48:40 +0800 | [diff] [blame] | 113 | struct soc_device_attribute *soc_dev_attr; |
| 114 | struct soc_device *soc_dev; |
| 115 | struct device *parent = NULL; |
| 116 | |
Stephen Warren | d220707 | 2013-08-20 15:17:35 -0600 | [diff] [blame] | 117 | tegra_pmc_init(); |
| 118 | |
Stephen Warren | 441f199 | 2013-03-25 13:22:24 -0600 | [diff] [blame] | 119 | tegra_clocks_apply_init_table(); |
| 120 | |
Danny Huang | d591fdf | 2013-03-14 08:48:40 +0800 | [diff] [blame] | 121 | soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); |
| 122 | if (!soc_dev_attr) |
| 123 | goto out; |
| 124 | |
| 125 | soc_dev_attr->family = kasprintf(GFP_KERNEL, "Tegra"); |
| 126 | soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d", tegra_revision); |
| 127 | soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", tegra_chip_id); |
| 128 | |
| 129 | soc_dev = soc_device_register(soc_dev_attr); |
| 130 | if (IS_ERR(soc_dev)) { |
| 131 | kfree(soc_dev_attr->family); |
| 132 | kfree(soc_dev_attr->revision); |
| 133 | kfree(soc_dev_attr->soc_id); |
| 134 | kfree(soc_dev_attr); |
| 135 | goto out; |
| 136 | } |
| 137 | |
| 138 | parent = soc_device_to_device(soc_dev); |
| 139 | |
Stephen Warren | a58116f | 2011-12-16 15:12:32 -0700 | [diff] [blame] | 140 | /* |
| 141 | * Finished with the static registrations now; fill in the missing |
| 142 | * devices |
| 143 | */ |
Danny Huang | d591fdf | 2013-03-14 08:48:40 +0800 | [diff] [blame] | 144 | out: |
Tuomas Tynkkynen | 5fed682 | 2013-07-25 21:38:04 +0300 | [diff] [blame] | 145 | of_platform_populate(NULL, of_default_bus_match_table, NULL, parent); |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 146 | } |
| 147 | |
Stephen Warren | d220707 | 2013-08-20 15:17:35 -0600 | [diff] [blame] | 148 | static void __init tegra_dt_init_time(void) |
| 149 | { |
| 150 | of_clk_init(NULL); |
| 151 | clocksource_of_init(); |
| 152 | } |
| 153 | |
Stephen Warren | b64a02c | 2012-05-02 16:05:44 -0600 | [diff] [blame] | 154 | static void __init paz00_init(void) |
| 155 | { |
Hiroshi Doyu | 1b14f3a | 2013-02-13 19:15:50 +0200 | [diff] [blame] | 156 | if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC)) |
| 157 | tegra_paz00_wifikill_init(); |
Stephen Warren | b64a02c | 2012-05-02 16:05:44 -0600 | [diff] [blame] | 158 | } |
Stephen Warren | b64a02c | 2012-05-02 16:05:44 -0600 | [diff] [blame] | 159 | |
Stephen Warren | c554dee | 2012-05-02 13:43:26 -0600 | [diff] [blame] | 160 | static struct { |
| 161 | char *machine; |
| 162 | void (*init)(void); |
| 163 | } board_init_funcs[] = { |
Stephen Warren | b64a02c | 2012-05-02 16:05:44 -0600 | [diff] [blame] | 164 | { "compal,paz00", paz00_init }, |
Stephen Warren | c554dee | 2012-05-02 13:43:26 -0600 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | static void __init tegra_dt_init_late(void) |
| 168 | { |
| 169 | int i; |
| 170 | |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 171 | tegra_init_suspend(); |
| 172 | tegra_cpuidle_init(); |
| 173 | tegra_powergate_debugfs_init(); |
Stephen Warren | c554dee | 2012-05-02 13:43:26 -0600 | [diff] [blame] | 174 | |
| 175 | for (i = 0; i < ARRAY_SIZE(board_init_funcs); i++) { |
| 176 | if (of_machine_is_compatible(board_init_funcs[i].machine)) { |
| 177 | board_init_funcs[i].init(); |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
Hiroshi Doyu | 1b14f3a | 2013-02-13 19:15:50 +0200 | [diff] [blame] | 183 | static const char * const tegra_dt_board_compat[] = { |
| 184 | "nvidia,tegra114", |
| 185 | "nvidia,tegra30", |
Stephen Warren | c5444f3 | 2012-02-27 18:26:16 -0700 | [diff] [blame] | 186 | "nvidia,tegra20", |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 187 | NULL |
| 188 | }; |
| 189 | |
Hiroshi Doyu | 1b14f3a | 2013-02-13 19:15:50 +0200 | [diff] [blame] | 190 | DT_MACHINE_START(TEGRA_DT, "NVIDIA Tegra SoC (Flattened Device Tree)") |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 191 | .map_io = tegra_map_common_io, |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 192 | .smp = smp_ops(tegra_smp_ops), |
Hiroshi Doyu | 7469688 | 2013-02-13 19:15:48 +0200 | [diff] [blame] | 193 | .init_early = tegra_init_early, |
pdeschrijver@nvidia.com | 0d4f747 | 2011-11-29 18:29:19 -0700 | [diff] [blame] | 194 | .init_irq = tegra_dt_init_irq, |
Stephen Warren | d220707 | 2013-08-20 15:17:35 -0600 | [diff] [blame] | 195 | .init_time = tegra_dt_init_time, |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 196 | .init_machine = tegra_dt_init, |
Stephen Warren | c554dee | 2012-05-02 13:43:26 -0600 | [diff] [blame] | 197 | .init_late = tegra_dt_init_late, |
Stephen Warren | 51100bd | 2013-08-20 15:47:38 -0600 | [diff] [blame^] | 198 | .restart = tegra_pmc_restart, |
Hiroshi Doyu | 1b14f3a | 2013-02-13 19:15:50 +0200 | [diff] [blame] | 199 | .dt_compat = tegra_dt_board_compat, |
Grant Likely | 8e267f3 | 2011-07-19 17:26:54 -0600 | [diff] [blame] | 200 | MACHINE_END |