[MIPS] Fix and cleanup the mess that a dozen prom_printf variants are.
[powerpc.git] / arch / mips / sni / sniprom.c
index d1d0f1f..643366e 100644 (file)
@@ -9,9 +9,12 @@
  * Copyright (C) 2005-2006 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
  */
 
+#define DEBUG
+
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/string.h>
+#include <linux/console.h>
 
 #include <asm/addrspace.h>
 #include <asm/sni.h>
 #define PROM_ENTRY(x)          (PROM_VEC + (x))
 
 
-#undef DEBUG
-#ifdef DEBUG
-#define DBG_PRINTF(x...)     prom_printf(x)
-#else
-#define DBG_PRINTF(x...)
-#endif
-
 static int *(*__prom_putchar)(int)        = (int *(*)(int))PROM_ENTRY(PROM_PUTCHAR);
+
+void prom_putchar(char c)
+{
+       __prom_putchar(c);
+}
+
 static char *(*__prom_getenv)(char *)     = (char *(*)(char *))PROM_ENTRY(PROM_GETENV);
 static void (*__prom_get_memconf)(void *) = (void (*)(void *))PROM_ENTRY(PROM_GET_MEMCONF);
 
@@ -47,29 +49,8 @@ char *prom_getenv (char *s)
        return __prom_getenv(s);
 }
 
-void prom_printf(char *fmt, ...)
+void __init prom_free_prom_memory(void)
 {
-       va_list args;
-       char ppbuf[1024];
-       char *bptr;
-
-       va_start(args, fmt);
-       vsprintf(ppbuf, fmt, args);
-
-       bptr = ppbuf;
-
-       while (*bptr != 0) {
-               if (*bptr == '\n')
-                       __prom_putchar('\r');
-
-               __prom_putchar(*bptr++);
-       }
-       va_end(args);
-}
-
-unsigned long prom_free_prom_memory(void)
-{
-       return 0;
 }
 
 /*
@@ -94,15 +75,15 @@ static void sni_idprom_dump(void)
 {
        int     i;
 
-       prom_printf("SNI IDProm dump (first 128byte):\n");
-       for(i=0;i<128;i++) {
+       pr_debug("SNI IDProm dump:\n");
+       for (i = 0; i < 256; i++) {
                if (i%16 == 0)
-                       prom_printf("%04x ", i);
+                       pr_debug("%04x ", i);
 
-               prom_printf("%02x ", *(unsigned char *) (SNI_IDPROM_BASE+i));
+               printk("%02x ", *(unsigned char *) (SNI_IDPROM_BASE + i));
 
-               if (i%16 == 15)
-                       prom_printf("\n");
+               if (i % 16 == 15)
+                       printk("\n");
        }
 }
 #endif
@@ -119,34 +100,142 @@ static void sni_mem_init(void )
        } memconf[8];
 
        /* MemSIZE from prom in 16MByte chunks */
-       memsize=*((unsigned char *) SNI_IDPROM_MEMSIZE) * 16;
+       memsize = *((unsigned char *) SNI_IDPROM_MEMSIZE) * 16;
 
-       DBG_PRINTF("IDProm memsize: %lu MByte\n", memsize);
+       pr_debug("IDProm memsize: %lu MByte\n", memsize);
 
        /* get memory bank layout from prom */
        __prom_get_memconf(&memconf);
 
-       DBG_PRINTF("prom_get_mem_conf memory configuration:\n");
-       for(i=0;i<8 && memconf[i].size;i++) {
-               prom_printf("Bank%d: %08x @ %08x\n", i,
+       pr_debug("prom_get_mem_conf memory configuration:\n");
+       for (i = 0;i < 8 && memconf[i].size; i++) {
+               if (sni_brd_type == SNI_BRD_PCI_TOWER ||
+                   sni_brd_type == SNI_BRD_PCI_TOWER_CPLUS) {
+                       if (memconf[i].base >= 0x20000000 &&
+                           memconf[i].base <  0x30000000) {
+                               memconf[i].base -= 0x20000000;
+                       }
+       }
+               pr_debug("Bank%d: %08x @ %08x\n", i,
                        memconf[i].size, memconf[i].base);
                add_memory_region(memconf[i].base, memconf[i].size, BOOT_MEM_RAM);
        }
 }
 
+static void __init sni_console_setup(void)
+{
+       char *ctype;
+       char *cdev;
+       char *baud;
+       int port;
+       static char options[8];
+
+       cdev = prom_getenv ("console_dev");
+       if (strncmp (cdev, "tty", 3) == 0) {
+               ctype = prom_getenv ("console");
+               switch (*ctype) {
+               default:
+               case 'l':
+                       port = 0;
+                       baud = prom_getenv("lbaud");
+                       break;
+               case 'r':
+                       port = 1;
+                       baud = prom_getenv("rbaud");
+                       break;
+               }
+               if (baud)
+                       strcpy(options, baud);
+               add_preferred_console("ttyS", port, baud ? options : NULL);
+       }
+}
+
 void __init prom_init(void)
 {
        int argc = fw_arg0;
        char **argv = (void *)fw_arg1;
-       unsigned int sni_brd_type = *(unsigned char *) SNI_IDPROM_BRDTYPE;
        int i;
-
-       DBG_PRINTF("Found SNI brdtype %02x\n", sni_brd_type);
+       int cputype;
+
+       sni_brd_type = *(unsigned char *)SNI_IDPROM_BRDTYPE;
+       cputype = *(unsigned char *)SNI_IDPROM_CPUTYPE;
+       switch (sni_brd_type) {
+       case SNI_BRD_TOWER_OASIC:
+               switch (cputype) {
+               case SNI_CPU_M8030:
+                       systype = "RM400-330";
+                       break;
+               case SNI_CPU_M8031:
+                       systype = "RM400-430";
+                       break;
+               case SNI_CPU_M8037:
+                       systype = "RM400-530";
+                       break;
+               case SNI_CPU_M8034:
+                       systype = "RM400-730";
+                       break;
+               default:
+                       systype = "RM400-xxx";
+                       break;
+               }
+               break;
+       case SNI_BRD_MINITOWER:
+               switch (cputype) {
+               case SNI_CPU_M8021:
+               case SNI_CPU_M8043:
+                       systype = "RM400-120";
+                       break;
+               case SNI_CPU_M8040:
+                       systype = "RM400-220";
+                       break;
+               case SNI_CPU_M8053:
+                       systype = "RM400-225";
+                       break;
+               case SNI_CPU_M8050:
+                       systype = "RM400-420";
+                       break;
+               default:
+                       systype = "RM400-xxx";
+                       break;
+               }
+               break;
+       case SNI_BRD_PCI_TOWER:
+               systype = "RM400-Cxx";
+               break;
+       case SNI_BRD_RM200:
+               systype = "RM200-xxx";
+               break;
+       case SNI_BRD_PCI_MTOWER:
+               systype = "RM300-Cxx";
+               break;
+       case SNI_BRD_PCI_DESKTOP:
+               switch (read_c0_prid() & 0xff00) {
+               case PRID_IMP_R4600:
+               case PRID_IMP_R4700:
+                       systype = "RM200-C20";
+                       break;
+               case PRID_IMP_R5000:
+                       systype = "RM200-C40";
+                       break;
+               default:
+                       systype = "RM200-Cxx";
+                       break;
+               }
+               break;
+       case SNI_BRD_PCI_TOWER_CPLUS:
+               systype = "RM400-Exx";
+               break;
+       case SNI_BRD_PCI_MTOWER_CPLUS:
+               systype = "RM300-Exx";
+               break;
+       }
+       pr_debug("Found SNI brdtype %02x name %s\n", sni_brd_type,systype);
 
 #ifdef DEBUG
        sni_idprom_dump();
 #endif
        sni_mem_init();
+       sni_console_setup();
 
        /* copy prom cmdline parameters to kernel cmdline */
        for (i = 1; i < argc; i++) {