Rename getenv_r() into getenv_f()
[oweals/u-boot.git] / board / esd / vom405 / vom405.c
index 1b1479f43fddec996e7180e7e3d13e2404a460d7..f665a3ec41e1371495111cb20c57139343902787 100644 (file)
 
 #include <common.h>
 #include <asm/processor.h>
+#include <asm/io.h>
 #include <command.h>
 #include <malloc.h>
+#include <sja1000.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 extern void lxt971_no_sleep(void);
 
-/* fpga configuration data - not compressed, generated by bin2c */
-const unsigned char fpgadata[] =
+/*
+ * generate a short spike on the CAN tx line
+ * to bring the couplers in sync
+ */
+void init_coupler(u32 addr)
 {
-#include "fpgadata.c"
-};
-int filesize = sizeof(fpgadata);
+       struct sja1000_basic_s *ctrl = (struct sja1000_basic_s *)addr;
+
+       /* reset */
+       out_8(&ctrl->cr, CR_RR);
+
+       /* dominant */
+       out_8(&ctrl->btr0, 0x00); /* btr setup is required */
+       out_8(&ctrl->btr1, 0x14); /* we use 1Mbit/s */
+       out_8(&ctrl->oc, OC_TP1 | OC_TN1 | OC_POL1 |
+             OC_TP0 | OC_TN0 | OC_POL0 | OC_MODE1);
+       out_8(&ctrl->cr, 0x00);
+
+       /* delay */
+       in_8(&ctrl->cr);
+       in_8(&ctrl->cr);
+       in_8(&ctrl->cr);
+       in_8(&ctrl->cr);
+
+       /* reset */
+       out_8(&ctrl->cr, CR_RR);
+}
 
 int board_early_init_f (void)
 {
@@ -51,25 +74,27 @@ int board_early_init_f (void)
         * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
         * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
         */
-       mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
-       mtdcr(uicer, 0x00000000);       /* disable all ints */
-       mtdcr(uiccr, 0x00000000);       /* set all to be non-critical*/
-       mtdcr(uicpr, 0xFFFFFF80);       /* set int polarities */
-       mtdcr(uictr, 0x10000000);       /* set int trigger levels */
-       mtdcr(uicvcr, 0x00000001);      /* set vect base=0,INT0 highest priority*/
-       mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
+       mtdcr(UIC0SR, 0xFFFFFFFF);       /* clear all ints */
+       mtdcr(UIC0ER, 0x00000000);       /* disable all ints */
+       mtdcr(UIC0CR, 0x00000000);       /* set all to be non-critical*/
+       mtdcr(UIC0PR, 0xFFFFFF80);       /* set int polarities */
+       mtdcr(UIC0TR, 0x10000000);       /* set int trigger levels */
+       mtdcr(UIC0VCR, 0x00000001);      /* set vect base=0,INT0 highest priority*/
+       mtdcr(UIC0SR, 0xFFFFFFFF);       /* clear all ints */
 
        /*
         * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
         */
-       mtebc (epcr, 0xa8400000); /* ebc always driven */
+       mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
 
        /*
         * Reset CPLD via GPIO12 (CS3) pin
         */
-       out32(GPIO0_OR, in32(GPIO0_OR) & ~(0x80000000 >> 12));
+       out_be32((void *)GPIO0_OR,
+                in_be32((void *)GPIO0_OR) & ~(0x80000000 >> 12));
        udelay(1000); /* wait 1ms */
-       out32(GPIO0_OR, in32(GPIO0_OR) | (0x80000000 >> 12));
+       out_be32((void *)GPIO0_OR,
+                in_be32((void *)GPIO0_OR) | (0x80000000 >> 12));
        udelay(1000); /* wait 1ms */
 
        return 0;
@@ -81,6 +106,12 @@ int misc_init_r (void)
        gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
        gd->bd->bi_flashoffset = 0;
 
+       /*
+        * Init magnetic coupler
+        */
+       if (!getenv("noinitcoupler"))
+               init_coupler(CAN_BA);
+
        return (0);
 }
 
@@ -90,10 +121,10 @@ int misc_init_r (void)
 int checkboard (void)
 {
        char str[64];
-       int i = getenv_("serial#", str, sizeof(str));
+       int i = getenv_f("serial#", str, sizeof(str));
        int flashcnt;
        int delay;
-       volatile unsigned char *led_reg = (unsigned char *)((ulong)CAN_BA + 0x1000);
+       u8 *led_reg = (u8 *)(CAN_BA + 0x1000);
 
        puts ("Board: ");
 
@@ -103,20 +134,20 @@ int checkboard (void)
                puts(str);
        }
 
-       printf(" (PLD-Version=%02d)\n", *led_reg);
+       printf(" (PLD-Version=%02d)\n", in_8(led_reg));
 
        /*
         * Flash LEDs
         */
        for (flashcnt = 0; flashcnt < 3; flashcnt++) {
-               *led_reg = 0x40;        /* LED_B..D off */
+               out_8(led_reg, 0x40);        /* LED_B..D off */
                for (delay = 0; delay < 100; delay++)
                        udelay(1000);
-               *led_reg = 0x47;        /* LED_B..D on */
+               out_8(led_reg, 0x47);        /* LED_B..D on */
                for (delay = 0; delay < 50; delay++)
                        udelay(1000);
        }
-       *led_reg = 0x40;
+       out_8(led_reg, 0x40);
 
        return 0;
 }