]> git.sur5r.net Git - u-boot/blobdiff - board/trab/trab.c
Merge with /home/wd/git/u-boot/custodian/u-boot-ppc4xx
[u-boot] / board / trab / trab.c
index 3f9b198698648957209e71c31bd56cbee30330ea..d8a726b226fd62a61f52658e7d10c9c38fe62166 100644 (file)
 /* #define DEBUG */
 
 #include <common.h>
-#include <cmd_bsp.h>
 #include <malloc.h>
 #include <s3c2400.h>
+#include <command.h>
 
-/* ------------------------------------------------------------------------- */
+DECLARE_GLOBAL_DATA_PTR;
 
+#ifdef CFG_BRIGHTNESS
+static void spi_init(void);
+static void wait_transmit_done(void);
+static void tsc2000_write(unsigned int page, unsigned int reg,
+                                                 unsigned int data);
+static void tsc2000_set_brightness(void);
+#endif
 #ifdef CONFIG_MODEM_SUPPORT
 static int key_pressed(void);
 extern void disable_putc(void);
@@ -42,15 +49,13 @@ extern int do_mdm_init; /* defined in common/main.c */
  * is that timers are not available yet, so we use a manually timed
  * loop.
  */
-#define KBD_MDELAY     100000  /* 1000 */
-static void mdelay_no_timer (int msec)
+#define KBD_MDELAY     5000
+static void udelay_no_timer (int usec)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        int i;
-       int delay = msec * 3;
+       int delay = usec * 3;
 
-       for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = 145;
+       for (i = 0; i < delay; i ++) gd->bd->bi_arch_number = MACH_TYPE_TRAB;
 }
 #endif /* CONFIG_MODEM_SUPPORT */
 
@@ -60,67 +65,62 @@ static void mdelay_no_timer (int msec)
 
 int board_init ()
 {
-       DECLARE_GLOBAL_DATA_PTR;
+#if defined(CONFIG_VFD)
+       extern int vfd_init_clocks(void);
+#endif
+       S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
+       S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
 
        /* memory and cpu-speed are setup before relocation */
 #ifdef CONFIG_TRAB_50MHZ
        /* change the clock to be 50 MHz 1:1:1 */
        /* MDIV:0x5c PDIV:4 SDIV:2 */
-       rMPLLCON = 0x5c042;
-       rCLKDIVN = 0;
+       clk_power->MPLLCON = 0x5c042;
+       clk_power->CLKDIVN = 0;
 #else
        /* change the clock to be 133 MHz 1:2:4 */
        /* MDIV:0x7d PDIV:4 SDIV:1 */
-       rMPLLCON = 0x7d041;
-       rCLKDIVN = 3;
+       clk_power->MPLLCON = 0x7d041;
+       clk_power->CLKDIVN = 3;
 #endif
 
        /* set up the I/O ports */
-       rPACON = 0x3ffff;
-       rPBCON = 0xaaaaaaaa;
-       rPBUP  = 0xffff;
+       gpio->PACON = 0x3ffff;
+       gpio->PBCON = 0xaaaaaaaa;
+       gpio->PBUP  = 0xffff;
        /* INPUT nCTS0 nRTS0 TXD[1] TXD[0] RXD[1] RXD[0]        */
        /*  00,    10,      10,      10,      10,      10,      10      */
-       rPFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
+       gpio->PFCON = (2<<0) | (2<<2) | (2<<4) | (2<<6) | (2<<8) | (2<<10);
 #ifdef CONFIG_HWFLOW
        /* do not pull up RXD0, RXD1, TXD0, TXD1, CTS0, RTS0 */
-       rPFUP  = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
+       gpio->PFUP  = (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5);
 #else
        /* do not pull up RXD0, RXD1, TXD0, TXD1 */
-       rPFUP  = (1<<0) | (1<<1) | (1<<2) | (1<<3);
+       gpio->PFUP  = (1<<0) | (1<<1) | (1<<2) | (1<<3);
 #endif
-       rPGCON = 0x0;
-       rPGUP  = 0x0;
-       rOPENCR= 0x0;
+       gpio->PGCON = 0x0;
+       gpio->PGUP  = 0x0;
+       gpio->OPENCR= 0x0;
+
+       /* suppress flicker of the VFDs */
+       gpio->MISCCR = 0x40;
+       gpio->PFCON |= (2<<12);
 
-       /* arch number of SAMSUNG-Board */
-       /* MACH_TYPE_SMDK2400 */
-       /* XXX this isn't really correct, but keep it for now */
-       gd->bd->bi_arch_number = 145;
+       gd->bd->bi_arch_number = MACH_TYPE_TRAB;
 
        /* adress of boot parameters */
        gd->bd->bi_boot_params = 0x0c000100;
 
-#ifdef CONFIG_MODEM_SUPPORT
-       /* This stuff is needed to get interrupts on stop-position
-        * contact events.
-        * (Copied from the LCD initialization routine.)
-        */
-       if (rLCDCON1 == 0)
-       {
-               rPCCON = (rPCCON & 0xFFFFFF00)| 0x000000AA;
-               rPDCON = (rPDCON & 0xFFFFFF03)| 0x000000A8;
-#if 0
-               rPDCON = (rPDCON & 0xFFFFFF00)| 0x000000AA;
-#endif
-               rLCDCON2 = 0x000DC000;
-               rLCDCON3 = 0x0051000A;
-               rLCDCON4 = 0x00000001;
-               rLCDCON5 = 0x00000440;
-               rLCDCON1 = 0x00000B75;
-       }
+       /* Make sure both buzzers are turned off */
+       gpio->PDCON |= 0x5400;
+       gpio->PDDAT &= ~0xE0;
 
-       mdelay_no_timer (KBD_MDELAY);
+#ifdef CONFIG_VFD
+       vfd_init_clocks();
+#endif /* CONFIG_VFD */
+
+#ifdef CONFIG_MODEM_SUPPORT
+       udelay_no_timer (KBD_MDELAY);
 
        if (key_pressed()) {
                disable_putc(); /* modem doesn't understand banner etc */
@@ -128,13 +128,16 @@ int board_init ()
        }
 #endif /* CONFIG_MODEM_SUPPORT */
 
+#ifdef CONFIG_DRIVER_S3C24X0_I2C
+       /* Configure I/O ports PG5 und PG6 for I2C */
+       gpio->PGCON = (gpio->PGCON & 0x003c00) | 0x003c00;
+#endif /* CONFIG_DRIVER_S3C24X0_I2C */
+
        return 0;
 }
 
 int dram_init (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
        gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
        return 0;
@@ -149,15 +152,36 @@ int dram_init (void)
 
 #define KBD_DATA       (((*(volatile ulong *)0x04020000) >> 16) & 0xF)
 
-static uchar *key_match (ulong);
+static char *key_match (ulong);
 
 int misc_init_r (void)
 {
        ulong kbd_data = KBD_DATA;
-       uchar keybd_env[KEYBD_KEY_NUM + 1];
-       uchar *str;
+       char *str;
+       char keybd_env[KEYBD_KEY_NUM + 1];
        int i;
 
+#ifdef CONFIG_VERSION_VARIABLE
+       {
+               /* Set version variable. Please note, that this variable is
+                * also set in main_loop() later in the boot process. The
+                * version variable has to be set this early, because so it
+                * could be used in script files on an usb stick, which
+                * might be called during do_auto_update() */
+               extern char version_string[];
+
+               setenv ("ver", version_string);
+       }
+#endif /* CONFIG_VERSION_VARIABLE */
+
+#ifdef CONFIG_AUTO_UPDATE
+       {
+               extern int do_auto_update(void);
+               /* this has priority over all else */
+               do_auto_update();
+       }
+#endif
+
        for (i = 0; i < KEYBD_KEY_NUM; ++i) {
                keybd_env[i] = '0' + ((kbd_data >> i) & 1);
        }
@@ -175,6 +199,9 @@ int misc_init_r (void)
                free (str);
        }
 
+#ifdef CFG_BRIGHTNESS
+       tsc2000_set_brightness();
+#endif
        return (0);
 }
 
@@ -183,7 +210,7 @@ int misc_init_r (void)
 static uchar kbd_magic_prefix[] = "key_magic";
 static uchar kbd_command_prefix[] = "key_cmd";
 
-static int compare_magic (ulong kbd_data, uchar *str)
+static int compare_magic (ulong kbd_data, char *str)
 {
        uchar key_mask;
 
@@ -229,12 +256,12 @@ static int compare_magic (ulong kbd_data, uchar *str)
  * Note: the string points to static environment data and must be
  * saved before you call any function that modifies the environment.
  */
-static uchar *key_match (ulong kbd_data)
+static char *key_match (ulong kbd_data)
 {
-       uchar magic[sizeof (kbd_magic_prefix) + 1];
-       uchar cmd_name[sizeof (kbd_command_prefix) + 1];
-       uchar *suffix;
-       uchar *kbd_magic_keys;
+       char magic[sizeof (kbd_magic_prefix) + 1];
+       char cmd_name[sizeof (kbd_command_prefix) + 1];
+       char *suffix;
+       char *kbd_magic_keys;
 
        /*
         * The following string defines the characters that can pe appended
@@ -279,7 +306,7 @@ static uchar *key_match (ulong kbd_data)
 int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
        ulong kbd_data = KBD_DATA;
-       uchar keybd_env[KEYBD_KEY_NUM + 1];
+       char keybd_env[KEYBD_KEY_NUM + 1];
        int i;
 
        puts ("Keys:");
@@ -293,9 +320,103 @@ int do_kbd (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
        return 0;
 }
 
+U_BOOT_CMD(
+       kbd,    1,      1,      do_kbd,
+       "kbd     - read keyboard status\n",
+       NULL
+);
+
 #ifdef CONFIG_MODEM_SUPPORT
 static int key_pressed(void)
 {
        return (compare_magic(KBD_DATA, CONFIG_MODEM_KEY_MAGIC) == 0);
 }
 #endif /* CONFIG_MODEM_SUPPORT */
+
+#ifdef CFG_BRIGHTNESS
+
+static inline void SET_CS_TOUCH(void)
+{
+       S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
+
+       gpio->PDDAT &= 0x5FF;
+}
+
+static inline void CLR_CS_TOUCH(void)
+{
+       S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
+
+       gpio->PDDAT |= 0x200;
+}
+
+static void spi_init(void)
+{
+       S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
+       S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
+       int i;
+
+       /* Configure I/O ports. */
+       gpio->PDCON = (gpio->PDCON & 0xF3FFFF) | 0x040000;
+       gpio->PGCON = (gpio->PGCON & 0x0F3FFF) | 0x008000;
+       gpio->PGCON = (gpio->PGCON & 0x0CFFFF) | 0x020000;
+       gpio->PGCON = (gpio->PGCON & 0x03FFFF) | 0x080000;
+
+       CLR_CS_TOUCH();
+
+       spi->ch[0].SPPRE = 0x1F; /* Baudrate ca. 514kHz */
+       spi->ch[0].SPPIN = 0x01;  /* SPI-MOSI holds Level after last bit */
+       spi->ch[0].SPCON = 0x1A;  /* Polling, Prescaler, Master, CPOL=0, CPHA=1 */
+
+       /* Dummy byte ensures clock to be low. */
+       for (i = 0; i < 10; i++) {
+               spi->ch[0].SPTDAT = 0xFF;
+       }
+       wait_transmit_done();
+}
+
+static void wait_transmit_done(void)
+{
+       S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
+
+       while (!(spi->ch[0].SPSTA & 0x01)); /* wait until transfer is done */
+}
+
+static void tsc2000_write(unsigned int page, unsigned int reg,
+                                                 unsigned int data)
+{
+       S3C24X0_SPI * const spi = S3C24X0_GetBase_SPI();
+       unsigned int command;
+
+       SET_CS_TOUCH();
+       command = 0x0000;
+       command |= (page << 11);
+       command |= (reg << 5);
+
+       spi->ch[0].SPTDAT = (command & 0xFF00) >> 8;
+       wait_transmit_done();
+       spi->ch[0].SPTDAT = (command & 0x00FF);
+       wait_transmit_done();
+       spi->ch[0].SPTDAT = (data & 0xFF00) >> 8;
+       wait_transmit_done();
+       spi->ch[0].SPTDAT = (data & 0x00FF);
+       wait_transmit_done();
+
+       CLR_CS_TOUCH();
+}
+
+static void tsc2000_set_brightness(void)
+{
+       char tmp[10];
+       int i, br;
+
+       spi_init();
+       tsc2000_write(1, 2, 0x0); /* Power up DAC */
+
+       i = getenv_r("brightness", tmp, sizeof(tmp));
+       br = (i > 0)
+               ? (int) simple_strtoul (tmp, NULL, 10)
+               : CFG_BRIGHTNESS;
+
+       tsc2000_write(0, 0xb, br & 0xff);
+}
+#endif