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