setup.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  7. */
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/delay.h>
  11. #include <linux/memblock.h>
  12. #include <linux/ioport.h>
  13. #include <linux/pm.h>
  14. #include <asm/bmips.h>
  15. #include <asm/bootinfo.h>
  16. #include <asm/time.h>
  17. #include <asm/reboot.h>
  18. #include <asm/cacheflush.h>
  19. #include <bcm63xx_board.h>
  20. #include <bcm63xx_cpu.h>
  21. #include <bcm63xx_regs.h>
  22. #include <bcm63xx_io.h>
  23. #include <bcm63xx_gpio.h>
  24. /*
  25. * CBR addr doesn't change and we can cache it.
  26. * For broken SoC/Bootloader CBR addr might also be provided via DT
  27. * with "brcm,bmips-cbr-reg" in the "cpus" node.
  28. */
  29. void __iomem *bmips_cbr_addr __read_mostly;
  30. void bcm63xx_machine_halt(void)
  31. {
  32. pr_info("System halted\n");
  33. while (1)
  34. ;
  35. }
  36. static void bcm6348_a1_reboot(void)
  37. {
  38. u32 reg;
  39. /* soft reset all blocks */
  40. pr_info("soft-resetting all blocks ...\n");
  41. reg = bcm_perf_readl(PERF_SOFTRESET_REG);
  42. reg &= ~SOFTRESET_6348_ALL;
  43. bcm_perf_writel(reg, PERF_SOFTRESET_REG);
  44. mdelay(10);
  45. reg = bcm_perf_readl(PERF_SOFTRESET_REG);
  46. reg |= SOFTRESET_6348_ALL;
  47. bcm_perf_writel(reg, PERF_SOFTRESET_REG);
  48. mdelay(10);
  49. /* Jump to the power on address. */
  50. pr_info("jumping to reset vector.\n");
  51. /* set high vectors (base at 0xbfc00000 */
  52. set_c0_status(ST0_BEV | ST0_ERL);
  53. /* run uncached in kseg0 */
  54. change_c0_config(CONF_CM_CMASK, CONF_CM_UNCACHED);
  55. __flush_cache_all();
  56. /* remove all wired TLB entries */
  57. write_c0_wired(0);
  58. __asm__ __volatile__(
  59. "jr\t%0"
  60. :
  61. : "r" (0xbfc00000));
  62. while (1)
  63. ;
  64. }
  65. void bcm63xx_machine_reboot(void)
  66. {
  67. u32 reg, perf_regs[2] = { 0, 0 };
  68. unsigned int i;
  69. /* mask and clear all external irq */
  70. switch (bcm63xx_get_cpu_id()) {
  71. case BCM3368_CPU_ID:
  72. perf_regs[0] = PERF_EXTIRQ_CFG_REG_3368;
  73. break;
  74. case BCM6328_CPU_ID:
  75. perf_regs[0] = PERF_EXTIRQ_CFG_REG_6328;
  76. break;
  77. case BCM6338_CPU_ID:
  78. perf_regs[0] = PERF_EXTIRQ_CFG_REG_6338;
  79. break;
  80. case BCM6345_CPU_ID:
  81. perf_regs[0] = PERF_EXTIRQ_CFG_REG_6345;
  82. break;
  83. case BCM6348_CPU_ID:
  84. perf_regs[0] = PERF_EXTIRQ_CFG_REG_6348;
  85. break;
  86. case BCM6358_CPU_ID:
  87. perf_regs[0] = PERF_EXTIRQ_CFG_REG_6358;
  88. break;
  89. case BCM6362_CPU_ID:
  90. perf_regs[0] = PERF_EXTIRQ_CFG_REG_6362;
  91. break;
  92. }
  93. for (i = 0; i < 2; i++) {
  94. if (!perf_regs[i])
  95. break;
  96. reg = bcm_perf_readl(perf_regs[i]);
  97. if (BCMCPU_IS_6348()) {
  98. reg &= ~EXTIRQ_CFG_MASK_ALL_6348;
  99. reg |= EXTIRQ_CFG_CLEAR_ALL_6348;
  100. } else {
  101. reg &= ~EXTIRQ_CFG_MASK_ALL;
  102. reg |= EXTIRQ_CFG_CLEAR_ALL;
  103. }
  104. bcm_perf_writel(reg, perf_regs[i]);
  105. }
  106. if (BCMCPU_IS_6348() && (bcm63xx_get_cpu_rev() == 0xa1))
  107. bcm6348_a1_reboot();
  108. pr_info("triggering watchdog soft-reset...\n");
  109. if (BCMCPU_IS_6328()) {
  110. bcm_wdt_writel(1, WDT_SOFTRESET_REG);
  111. } else {
  112. reg = bcm_perf_readl(PERF_SYS_PLL_CTL_REG);
  113. reg |= SYS_PLL_SOFT_RESET;
  114. bcm_perf_writel(reg, PERF_SYS_PLL_CTL_REG);
  115. }
  116. while (1)
  117. ;
  118. }
  119. static void __bcm63xx_machine_reboot(char *p)
  120. {
  121. bcm63xx_machine_reboot();
  122. }
  123. /*
  124. * return system type in /proc/cpuinfo
  125. */
  126. const char *get_system_type(void)
  127. {
  128. static char buf[128];
  129. snprintf(buf, sizeof(buf), "bcm63xx/%s (0x%04x/0x%02X)",
  130. board_get_name(),
  131. bcm63xx_get_cpu_id(), bcm63xx_get_cpu_rev());
  132. return buf;
  133. }
  134. void __init plat_time_init(void)
  135. {
  136. mips_hpt_frequency = bcm63xx_get_cpu_freq() / 2;
  137. }
  138. void __init plat_mem_setup(void)
  139. {
  140. memblock_add(0, bcm63xx_get_memory_size());
  141. _machine_halt = bcm63xx_machine_halt;
  142. _machine_restart = __bcm63xx_machine_reboot;
  143. pm_power_off = bcm63xx_machine_halt;
  144. set_io_port_base(0);
  145. ioport_resource.start = 0;
  146. ioport_resource.end = ~0;
  147. board_setup();
  148. }
  149. static int __init bcm63xx_register_devices(void)
  150. {
  151. /* register gpiochip */
  152. bcm63xx_gpio_init();
  153. return board_register_devices();
  154. }
  155. arch_initcall(bcm63xx_register_devices);