sparc: leon2: Updates for generic board initialization
[oweals/u-boot.git] / arch / sparc / cpu / leon3 / cpu_init.c
index f23ecb89be73f4b82814ea103ab6d6b69cfc145d..9c7665783cb27930fa2ce0c06e93c131cb9878e9 100644 (file)
@@ -11,6 +11,9 @@
 #include <asm/asi.h>
 #include <asm/leon.h>
 #include <ambapp.h>
+#include <grlib/irqmp.h>
+#include <grlib/gptimer.h>
+#include <debug_uart.h>
 
 #include <config.h>
 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/* reset CPU (jump to 0, without reset) */
-void start(void);
-
-/* find & initialize the memory controller */
-int init_memory_ctrl(void);
-
 ambapp_dev_irqmp *irqmp = NULL;
-ambapp_dev_mctrl memctrl;
 ambapp_dev_gptimer *gptimer = NULL;
 unsigned int gptimer_irq = 0;
-int leon3_snooping_avail = 0;
-
-struct {
-       gd_t gd_area;
-       bd_t bd;
-} global_data;
 
 /*
  * Breath some life into the CPU...
@@ -52,22 +42,35 @@ struct {
  */
 void cpu_init_f(void)
 {
+#ifdef CONFIG_DEBUG_UART
+       debug_uart_init();
+#endif
+}
 
+/* If cache snooping is available in hardware the result will be set
+ * to 0x800000, otherwise 0.
+ */
+static unsigned int snoop_detect(void)
+{
+       unsigned int result;
+       asm("lda [%%g0] 2, %0" : "=r"(result));
+       return result & 0x00800000;
 }
 
-/* Routine called from start.S,
- *
- * Run from FLASH/PROM:
- *  - memory controller has already been setup up, stack can be used
- *  - global variables available for read/writing
- *  - constants avaiable
-        */
-void cpu_init_f2(void)
+int arch_cpu_init(void)
 {
+       gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
+       gd->bus_clk = CONFIG_SYS_CLK_FREQ;
+       gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
+
+       gd->arch.snooping_available = snoop_detect();
+
        /* Initialize the AMBA Plug & Play bus structure, the bus
         * structure represents the AMBA bus that the CPU is located at.
         */
        ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb);
+
+       return 0;
 }
 
 /*
@@ -76,7 +79,7 @@ void cpu_init_f2(void)
 int cpu_init_r(void)
 {
        ambapp_apbdev apbdev;
-       int index, cpu;
+       int index, cpu, ntimers, i;
        ambapp_dev_gptimer *timer = NULL;
        unsigned int bus_freq;
 
@@ -121,6 +124,14 @@ int cpu_init_r(void)
                timer->scalar = timer->scalar_reload =
                    (((bus_freq / 1000) + 500) / 1000) - 1;
 
+               /* Clear All Timers */
+               ntimers = timer->config & 0x7;
+               for (i = 0; i < ntimers; i++) {
+                       timer->e[i].ctrl = GPTIMER_CTRL_IP;
+                       timer->e[i].rld = 0;
+                       timer->e[i].ctrl = GPTIMER_CTRL_LD;
+               }
+
                index++;
        }
        if (!gptimer) {
@@ -150,8 +161,8 @@ int timer_interrupt_init_cpu(void)
        gptimer->e[0].val = 0;
        gptimer->e[0].rld = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1;
        gptimer->e[0].ctrl =
-           (LEON3_GPTIMER_EN |
-            LEON3_GPTIMER_RL | LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
+           (GPTIMER_CTRL_EN | GPTIMER_CTRL_RS |
+            GPTIMER_CTRL_LD | GPTIMER_CTRL_IE);
 
        return gptimer_irq;
 }