tegra.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/serial_8250.h>
  22. #include <linux/clk.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/irqdomain.h>
  25. #include <linux/of.h>
  26. #include <linux/of_address.h>
  27. #include <linux/of_fdt.h>
  28. #include <linux/of_platform.h>
  29. #include <linux/pda_power.h>
  30. #include <linux/io.h>
  31. #include <linux/slab.h>
  32. #include <linux/sys_soc.h>
  33. #include <linux/usb/tegra_usb_phy.h>
  34. #include <linux/clk/tegra.h>
  35. #include <linux/irqchip.h>
  36. #include <asm/hardware/cache-l2x0.h>
  37. #include <asm/mach-types.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/time.h>
  40. #include <asm/setup.h>
  41. #include "apbio.h"
  42. #include "board.h"
  43. #include "common.h"
  44. #include "cpuidle.h"
  45. #include "fuse.h"
  46. #include "iomap.h"
  47. #include "irq.h"
  48. #include "pmc.h"
  49. #include "pm.h"
  50. #include "reset.h"
  51. #include "sleep.h"
  52. /*
  53. * Storage for debug-macro.S's state.
  54. *
  55. * This must be in .data not .bss so that it gets initialized each time the
  56. * kernel is loaded. The data is declared here rather than debug-macro.S so
  57. * that multiple inclusions of debug-macro.S point at the same data.
  58. */
  59. u32 tegra_uart_config[4] = {
  60. /* Debug UART initialization required */
  61. 1,
  62. /* Debug UART physical address */
  63. 0,
  64. /* Debug UART virtual address */
  65. 0,
  66. /* Scratch space for debug macro */
  67. 0,
  68. };
  69. static void __init tegra_init_cache(void)
  70. {
  71. #ifdef CONFIG_CACHE_L2X0
  72. int ret;
  73. void __iomem *p = IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x3000;
  74. u32 aux_ctrl, cache_type;
  75. cache_type = readl(p + L2X0_CACHE_TYPE);
  76. aux_ctrl = (cache_type & 0x700) << (17-8);
  77. aux_ctrl |= 0x7C400001;
  78. ret = l2x0_of_init(aux_ctrl, 0x8200c3fe);
  79. if (!ret)
  80. l2x0_saved_regs_addr = virt_to_phys(&l2x0_saved_regs);
  81. #endif
  82. }
  83. static void __init tegra_init_early(void)
  84. {
  85. tegra_apb_io_init();
  86. tegra_init_fuse();
  87. tegra_cpu_reset_handler_init();
  88. tegra_init_cache();
  89. tegra_powergate_init();
  90. tegra_hotplug_init();
  91. }
  92. static void __init tegra_dt_init_irq(void)
  93. {
  94. tegra_pmc_init_irq();
  95. tegra_init_irq();
  96. irqchip_init();
  97. tegra_legacy_irq_syscore_init();
  98. }
  99. static void __init tegra_dt_init(void)
  100. {
  101. struct soc_device_attribute *soc_dev_attr;
  102. struct soc_device *soc_dev;
  103. struct device *parent = NULL;
  104. tegra_pmc_init();
  105. tegra_clocks_apply_init_table();
  106. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  107. if (!soc_dev_attr)
  108. goto out;
  109. soc_dev_attr->family = kasprintf(GFP_KERNEL, "Tegra");
  110. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d", tegra_revision);
  111. soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%d", tegra_chip_id);
  112. soc_dev = soc_device_register(soc_dev_attr);
  113. if (IS_ERR(soc_dev)) {
  114. kfree(soc_dev_attr->family);
  115. kfree(soc_dev_attr->revision);
  116. kfree(soc_dev_attr->soc_id);
  117. kfree(soc_dev_attr);
  118. goto out;
  119. }
  120. parent = soc_device_to_device(soc_dev);
  121. /*
  122. * Finished with the static registrations now; fill in the missing
  123. * devices
  124. */
  125. out:
  126. of_platform_populate(NULL, of_default_bus_match_table, NULL, parent);
  127. }
  128. static void __init paz00_init(void)
  129. {
  130. if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
  131. tegra_paz00_wifikill_init();
  132. }
  133. static struct {
  134. char *machine;
  135. void (*init)(void);
  136. } board_init_funcs[] = {
  137. { "compal,paz00", paz00_init },
  138. };
  139. static void __init tegra_dt_init_late(void)
  140. {
  141. int i;
  142. tegra_init_suspend();
  143. tegra_cpuidle_init();
  144. tegra_powergate_debugfs_init();
  145. for (i = 0; i < ARRAY_SIZE(board_init_funcs); i++) {
  146. if (of_machine_is_compatible(board_init_funcs[i].machine)) {
  147. board_init_funcs[i].init();
  148. break;
  149. }
  150. }
  151. }
  152. static const char * const tegra_dt_board_compat[] = {
  153. "nvidia,tegra124",
  154. "nvidia,tegra114",
  155. "nvidia,tegra30",
  156. "nvidia,tegra20",
  157. NULL
  158. };
  159. DT_MACHINE_START(TEGRA_DT, "NVIDIA Tegra SoC (Flattened Device Tree)")
  160. .map_io = tegra_map_common_io,
  161. .smp = smp_ops(tegra_smp_ops),
  162. .init_early = tegra_init_early,
  163. .init_irq = tegra_dt_init_irq,
  164. .init_machine = tegra_dt_init,
  165. .init_late = tegra_dt_init_late,
  166. .restart = tegra_pmc_restart,
  167. .dt_compat = tegra_dt_board_compat,
  168. MACHINE_END