Commit bd92aa013e8fcd17328ec8e060477761cf3380d9

Authored by Wu Zhangjin
Committed by Ralf Baechle
1 parent f54a40ee6b

MIPS: Loongson: Split the implementation of prom and setup parts

This patch split the old initilization and setup implementation to
several file, one file one logic function.

the other main changes include:

	1. as the script/checkpatch.pl suggests, use strict_strtol instead
	of simple_strtol in arch/mips/lemote/lm2e/cmdline.c

	2. use the existed macros in asm/mips-boards/bonito64.h as the
	arguments of set_io_port_base() and remove the un-needed ones in
	asm/mach-lemote/pci.h

Signed-off-by: Wu Zhangjin <wuzj@lemote.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

Showing 10 changed files with 208 additions and 126 deletions Side-by-side Diff

arch/mips/include/asm/mach-lemote/pci.h
... ... @@ -25,7 +25,6 @@
25 25 #define LOONGSON2E_PCI_MEM_START 0x14000000UL
26 26 #define LOONGSON2E_PCI_MEM_END 0x1fffffffUL
27 27 #define LOONGSON2E_PCI_IO_START 0x00004000UL
28   -#define LOONGSON2E_IO_PORT_BASE 0x1fd00000UL
29 28  
30 29 #endif /* !_LEMOTE_PCI_H_ */
arch/mips/lemote/lm2e/Makefile
... ... @@ -2,7 +2,8 @@
2 2 # Makefile for Lemote Fulong mini-PC board.
3 3 #
4 4  
5   -obj-y += setup.o prom.o reset.o irq.o pci.o bonito-irq.o mem.o
  5 +obj-y += setup.o init.o reset.o irq.o pci.o bonito-irq.o mem.o \
  6 + env.o cmdline.o time.o machtype.o
6 7  
7 8 #
8 9 # Early printk support
arch/mips/lemote/lm2e/cmdline.c
  1 +/*
  2 + * Based on Ocelot Linux port, which is
  3 + * Copyright 2001 MontaVista Software Inc.
  4 + * Author: jsun@mvista.com or jsun@junsun.net
  5 + *
  6 + * Copyright 2003 ICT CAS
  7 + * Author: Michael Guo <guoyi@ict.ac.cn>
  8 + *
  9 + * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
  10 + * Author: Fuxin Zhang, zhangfx@lemote.com
  11 + *
  12 + * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
  13 + * Author: Wu Zhangjin, wuzj@lemote.com
  14 + *
  15 + * This program is free software; you can redistribute it and/or modify it
  16 + * under the terms of the GNU General Public License as published by the
  17 + * Free Software Foundation; either version 2 of the License, or (at your
  18 + * option) any later version.
  19 + */
  20 +#include <linux/io.h>
  21 +#include <linux/init.h>
  22 +
  23 +#include <asm/bootinfo.h>
  24 +
  25 +int prom_argc;
  26 +/* pmon passes arguments in 32bit pointers */
  27 +int *_prom_argv;
  28 +
  29 +void __init prom_init_cmdline(void)
  30 +{
  31 + int i;
  32 + long l;
  33 +
  34 + /* firmware arguments are initialized in head.S */
  35 + prom_argc = fw_arg0;
  36 + _prom_argv = (int *)fw_arg1;
  37 +
  38 + /* arg[0] is "g", the rest is boot parameters */
  39 + arcs_cmdline[0] = '\0';
  40 + for (i = 1; i < prom_argc; i++) {
  41 + l = (long)_prom_argv[i];
  42 + if (strlen(arcs_cmdline) + strlen(((char *)l) + 1)
  43 + >= sizeof(arcs_cmdline))
  44 + break;
  45 + strcat(arcs_cmdline, ((char *)l));
  46 + strcat(arcs_cmdline, " ");
  47 + }
  48 +
  49 + if ((strstr(arcs_cmdline, "console=")) == NULL)
  50 + strcat(arcs_cmdline, " console=ttyS0,115200");
  51 + if ((strstr(arcs_cmdline, "root=")) == NULL)
  52 + strcat(arcs_cmdline, " root=/dev/hda1");
  53 +}
arch/mips/lemote/lm2e/env.c
  1 +/*
  2 + * Based on Ocelot Linux port, which is
  3 + * Copyright 2001 MontaVista Software Inc.
  4 + * Author: jsun@mvista.com or jsun@junsun.net
  5 + *
  6 + * Copyright 2003 ICT CAS
  7 + * Author: Michael Guo <guoyi@ict.ac.cn>
  8 + *
  9 + * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
  10 + * Author: Fuxin Zhang, zhangfx@lemote.com
  11 + *
  12 + * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
  13 + * Author: Wu Zhangjin, wuzj@lemote.com
  14 + *
  15 + * This program is free software; you can redistribute it and/or modify it
  16 + * under the terms of the GNU General Public License as published by the
  17 + * Free Software Foundation; either version 2 of the License, or (at your
  18 + * option) any later version.
  19 + */
  20 +
  21 +#include <linux/io.h>
  22 +#include <linux/init.h>
  23 +
  24 +#include <asm/bootinfo.h>
  25 +
  26 +unsigned long bus_clock, cpu_clock_freq;
  27 +unsigned long memsize, highmemsize;
  28 +
  29 +/* pmon passes arguments in 32bit pointers */
  30 +int *_prom_envp;
  31 +
  32 +#define parse_even_earlier(res, option, p) \
  33 +do { \
  34 + if (strncmp(option, (char *)p, strlen(option)) == 0) \
  35 + strict_strtol((char *)p + strlen(option"="), \
  36 + 10, &res); \
  37 +} while (0)
  38 +
  39 +void __init prom_init_env(void)
  40 +{
  41 + long l;
  42 +
  43 + /* firmware arguments are initialized in head.S */
  44 + _prom_envp = (int *)fw_arg2;
  45 +
  46 + l = (long)*_prom_envp;
  47 + while (l != 0) {
  48 + parse_even_earlier(bus_clock, "busclock", l);
  49 + parse_even_earlier(cpu_clock_freq, "cpuclock", l);
  50 + parse_even_earlier(memsize, "memsize", l);
  51 + parse_even_earlier(highmemsize, "highmemsize", l);
  52 + _prom_envp++;
  53 + l = (long)*_prom_envp;
  54 + }
  55 + if (memsize == 0)
  56 + memsize = 256;
  57 +
  58 + pr_info("busclock=%ld, cpuclock=%ld, memsize=%ld, highmemsize=%ld\n",
  59 + bus_clock, cpu_clock_freq, memsize, highmemsize);
  60 +}
arch/mips/lemote/lm2e/init.c
  1 +/*
  2 + * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
  3 + * Author: Wu Zhangjin, wuzj@lemote.com
  4 + *
  5 + * This program is free software; you can redistribute it and/or modify it
  6 + * under the terms of the GNU General Public License as published by the
  7 + * Free Software Foundation; either version 2 of the License, or (at your
  8 + * option) any later version.
  9 + */
  10 +
  11 +#include <linux/init.h>
  12 +#include <linux/bootmem.h>
  13 +
  14 +#include <asm/bootinfo.h>
  15 +#include <asm/mips-boards/bonito64.h>
  16 +
  17 +extern void __init prom_init_cmdline(void);
  18 +extern void __init prom_init_env(void);
  19 +extern void __init prom_init_memory(void);
  20 +
  21 +void __init prom_init(void)
  22 +{
  23 + /* init base address of io space */
  24 + set_io_port_base((unsigned long)
  25 + ioremap(BONITO_PCIIO_BASE, BONITO_PCIIO_SIZE));
  26 +
  27 + prom_init_cmdline();
  28 + prom_init_env();
  29 + prom_init_memory();
  30 +}
  31 +
  32 +void __init prom_free_prom_memory(void)
  33 +{
  34 +}
arch/mips/lemote/lm2e/machtype.c
  1 +/*
  2 + * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
  3 + * Author: Wu Zhangjin, wuzj@lemote.com
  4 + *
  5 + * This program is free software; you can redistribute it and/or modify it
  6 + * under the terms of the GNU General Public License as published by the
  7 + * Free Software Foundation; either version 2 of the License, or (at your
  8 + * option) any later version.
  9 + */
  10 +
  11 +const char *get_system_type(void)
  12 +{
  13 + return "lemote-fulong";
  14 +}
arch/mips/lemote/lm2e/mem.c
... ... @@ -8,6 +8,19 @@
8 8 #include <linux/fcntl.h>
9 9 #include <linux/mm.h>
10 10  
  11 +#include <asm/bootinfo.h>
  12 +
  13 +extern unsigned long memsize, highmemsize;
  14 +
  15 +void __init prom_init_memory(void)
  16 +{
  17 + add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
  18 +#ifdef CONFIG_64BIT
  19 + if (highmemsize > 0)
  20 + add_memory_region(0x20000000, highmemsize << 20, BOOT_MEM_RAM);
  21 +#endif /* CONFIG_64BIT */
  22 +}
  23 +
11 24 /* override of arch/mips/mm/cache.c: __uncached_access */
12 25 int __uncached_access(struct file *file, unsigned long addr)
13 26 {
arch/mips/lemote/lm2e/prom.c
1   -/*
2   - * Based on Ocelot Linux port, which is
3   - * Copyright 2001 MontaVista Software Inc.
4   - * Author: jsun@mvista.com or jsun@junsun.net
5   - *
6   - * Copyright 2003 ICT CAS
7   - * Author: Michael Guo <guoyi@ict.ac.cn>
8   - *
9   - * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
10   - * Author: Fuxin Zhang, zhangfx@lemote.com
11   - *
12   - * This program is free software; you can redistribute it and/or modify it
13   - * under the terms of the GNU General Public License as published by the
14   - * Free Software Foundation; either version 2 of the License, or (at your
15   - * option) any later version.
16   - */
17   -#include <linux/init.h>
18   -#include <linux/bootmem.h>
19   -#include <asm/bootinfo.h>
20   -
21   -extern unsigned long bus_clock;
22   -extern unsigned long cpu_clock_freq;
23   -extern unsigned int memsize, highmemsize;
24   -
25   -static int argc;
26   -/* pmon passes arguments in 32bit pointers */
27   -static int *arg;
28   -static int *env;
29   -
30   -const char *get_system_type(void)
31   -{
32   - return "lemote-fulong";
33   -}
34   -
35   -void __init prom_init_cmdline(void)
36   -{
37   - int i;
38   - long l;
39   -
40   - /* arg[0] is "g", the rest is boot parameters */
41   - arcs_cmdline[0] = '\0';
42   - for (i = 1; i < argc; i++) {
43   - l = (long)arg[i];
44   - if (strlen(arcs_cmdline) + strlen(((char *)l) + 1)
45   - >= sizeof(arcs_cmdline))
46   - break;
47   - strcat(arcs_cmdline, ((char *)l));
48   - strcat(arcs_cmdline, " ");
49   - }
50   -}
51   -
52   -void __init prom_init(void)
53   -{
54   - long l;
55   - argc = fw_arg0;
56   - arg = (int *)fw_arg1;
57   - env = (int *)fw_arg2;
58   -
59   - prom_init_cmdline();
60   -
61   - if ((strstr(arcs_cmdline, "console=")) == NULL)
62   - strcat(arcs_cmdline, " console=ttyS0,115200");
63   - if ((strstr(arcs_cmdline, "root=")) == NULL)
64   - strcat(arcs_cmdline, " root=/dev/hda1");
65   -
66   -#define parse_even_earlier(res, option, p) \
67   -do { \
68   - if (strncmp(option, (char *)p, strlen(option)) == 0) \
69   - res = simple_strtol((char *)p + strlen(option"="), \
70   - NULL, 10); \
71   -} while (0)
72   -
73   - l = (long)*env;
74   - while (l != 0) {
75   - parse_even_earlier(bus_clock, "busclock", l);
76   - parse_even_earlier(cpu_clock_freq, "cpuclock", l);
77   - parse_even_earlier(memsize, "memsize", l);
78   - parse_even_earlier(highmemsize, "highmemsize", l);
79   - env++;
80   - l = (long)*env;
81   - }
82   - if (memsize == 0)
83   - memsize = 256;
84   -
85   - pr_info("busclock=%ld, cpuclock=%ld,memsize=%d,highmemsize=%d\n",
86   - bus_clock, cpu_clock_freq, memsize, highmemsize);
87   -}
88   -
89   -void __init prom_free_prom_memory(void)
90   -{
91   -}
arch/mips/lemote/lm2e/setup.c
... ... @@ -26,37 +26,16 @@
26 26 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 27 *
28 28 */
29   -#include <linux/bootmem.h>
30 29 #include <linux/init.h>
31   -#include <linux/irq.h>
  30 +#include <linux/module.h>
32 31  
33   -#include <asm/bootinfo.h>
34   -#include <asm/mc146818-time.h>
35   -#include <asm/time.h>
36 32 #include <asm/wbflush.h>
37   -#include <asm/mach-lemote/pci.h>
38 33  
39 34 #ifdef CONFIG_VT
40 35 #include <linux/console.h>
41 36 #include <linux/screen_info.h>
42 37 #endif
43 38  
44   -unsigned long cpu_clock_freq;
45   -unsigned long bus_clock;
46   -unsigned int memsize;
47   -unsigned int highmemsize = 0;
48   -
49   -void __init plat_time_init(void)
50   -{
51   - /* setup mips r4k timer */
52   - mips_hpt_frequency = cpu_clock_freq / 2;
53   -}
54   -
55   -unsigned long read_persistent_clock(void)
56   -{
57   - return mc146818_get_cmos_time();
58   -}
59   -
60 39 void (*__wbflush)(void);
61 40 EXPORT_SYMBOL(__wbflush);
62 41  
63 42  
... ... @@ -73,18 +52,8 @@
73 52  
74 53 void __init plat_mem_setup(void)
75 54 {
76   - set_io_port_base((unsigned long)ioremap(LOONGSON2E_IO_PORT_BASE,
77   - IO_SPACE_LIMIT - LOONGSON2E_PCI_IO_START + 1));
78   -
79 55 __wbflush = wbflush_loongson2e;
80 56  
81   - add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
82   -#ifdef CONFIG_64BIT
83   - if (highmemsize > 0) {
84   - add_memory_region(0x20000000, highmemsize << 20, BOOT_MEM_RAM);
85   - }
86   -#endif
87   -
88 57 #ifdef CONFIG_VT
89 58 #if defined(CONFIG_VGA_CONSOLE)
90 59 conswitchp = &vga_con;
... ... @@ -104,6 +73,5 @@
104 73 conswitchp = &dummy_con;
105 74 #endif
106 75 #endif
107   -
108 76 }
arch/mips/lemote/lm2e/time.c
  1 +/*
  2 + * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
  3 + * Author: Fuxin Zhang, zhangfx@lemote.com
  4 + *
  5 + * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
  6 + * Author: Wu Zhangjin, wuzj@lemote.com
  7 + *
  8 + * This program is free software; you can redistribute it and/or modify it
  9 + * under the terms of the GNU General Public License as published by the
  10 + * Free Software Foundation; either version 2 of the License, or (at your
  11 + * option) any later version.
  12 + */
  13 +
  14 +#include <linux/init.h>
  15 +
  16 +#include <asm/mc146818-time.h>
  17 +#include <asm/time.h>
  18 +
  19 +extern unsigned long cpu_clock_freq;
  20 +
  21 +void __init plat_time_init(void)
  22 +{
  23 + /* setup mips r4k timer */
  24 + mips_hpt_frequency = cpu_clock_freq / 2;
  25 +}
  26 +
  27 +unsigned long read_persistent_clock(void)
  28 +{
  29 + return mc146818_get_cmos_time();
  30 +}