8ac7577771b8b1a3d13ed8d84c349cf404ac73b9
[openwrt-10.03/.git] / target / linux / ar7 / files / arch / mips / ar7 / setup.c
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2006, 2007 OpenWrt.org
5  *
6  * Carsten Langgaard, carstenl@mips.com
7  * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
8  *
9  *  This program is free software; you can distribute it and/or modify it
10  *  under the terms of the GNU General Public License (Version 2) as
11  *  published by the Free Software Foundation.
12  *
13  *  This program is distributed in the hope it will be useful, but WITHOUT
14  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16  *  for more details.
17  *
18  *  You should have received a copy of the GNU General Public License along
19  *  with this program; if not, write to the Free Software Foundation, Inc.,
20  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
21  */
22 #include <linux/init.h>
23 #include <linux/ioport.h>
24 #include <linux/pm.h>
25
26 #include <asm/mips-boards/prom.h>
27 #include <asm/reboot.h>
28 #include <asm/time.h>
29 #include <asm/ar7/ar7.h>
30
31 extern void ar7_time_init(void);
32 static void ar7_machine_restart(char *command);
33 static void ar7_machine_halt(void);
34 static void ar7_machine_power_off(void);
35
36 static void ar7_machine_restart(char *command)
37 {
38         u32 *softres_reg = (u32 *)ioremap(AR7_REGS_RESET +
39                                           AR7_RESET_SOFTWARE, 1);
40         writel(1, softres_reg);
41 }
42
43 static void ar7_machine_halt(void)
44 {
45         while (1);
46 }
47
48 static void ar7_machine_power_off(void)
49 {
50         u32 *power_reg = (u32 *)ioremap(AR7_REGS_POWER, 1);
51         u32 power_state = readl(power_reg) | (3 << 30);
52         writel(power_state, power_reg);
53         ar7_machine_halt();
54 }
55
56 const char *get_system_type(void)
57 {
58         u16 chip_id = ar7_chip_id();
59         switch (chip_id) {
60         case AR7_CHIP_7300:
61                 return "TI AR7 (TNETD7300)";
62         case AR7_CHIP_7100:
63                 return "TI AR7 (TNETD7100)";
64         case AR7_CHIP_7200:
65                 return "TI AR7 (TNETD7200)";
66         default:
67                 return "TI AR7 (Unknown)";
68         }
69 }
70
71 static int __init ar7_init_console(void)
72 {
73         return 0;
74 }
75
76 /*
77  * Initializes basic routines and structures pointers, memory size (as
78  * given by the bios and saves the command line.
79  */
80
81 extern void ar7_init_clocks(void);
82
83 void __init plat_mem_setup(void)
84 {
85         unsigned long io_base;
86
87         _machine_restart = ar7_machine_restart;
88         _machine_halt = ar7_machine_halt;
89         pm_power_off = ar7_machine_power_off;
90         board_time_init = ar7_time_init;
91         panic_timeout = 3;
92
93         io_base = (unsigned long)ioremap(AR7_REGS_BASE, 0x10000);
94         if (!io_base) panic("Can't remap IO base!\n");
95         set_io_port_base(io_base);
96
97         prom_meminit();
98         ar7_init_clocks();
99
100         ioport_resource.start = 0;
101         ioport_resource.end   = ~0;
102         iomem_resource.start  = 0;
103         iomem_resource.end    = ~0;
104
105         printk("%s, ID: 0x%04x, Revision: 0x%02x\n", get_system_type(), 
106                 ar7_chip_id(), ar7_chip_rev());
107 }
108
109 console_initcall(ar7_init_console);