0abb961fd10e43a8e6ed2cfba024b8882973e33b
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files / arch / mips / adm5120 / adm5120_info.c
1 /*
2 * $Id$
3 *
4 * Copyright (C) 2007 OpenWrt.org
5 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/io.h>
28
29 #include <asm/bootinfo.h>
30 #include <asm/addrspace.h>
31
32 #include <adm5120_info.h>
33 #include <adm5120_defs.h>
34 #include <adm5120_switch.h>
35
36 unsigned int adm5120_product_code;
37 unsigned int adm5120_revision;
38 unsigned int adm5120_package;
39 unsigned int adm5120_nand_boot;
40 unsigned long adm5120_speed;
41
42 /*
43 * CPU settings detection
44 */
45 #define CODE_GET_PC(c) ((c) & CODE_PC_MASK)
46 #define CODE_GET_REV(c) (((c) >> CODE_REV_SHIFT) & CODE_REV_MASK)
47 #define CODE_GET_PK(c) (((c) >> CODE_PK_SHIFT) & CODE_PK_MASK)
48 #define CODE_GET_CLKS(c) (((c) >> CODE_CLKS_SHIFT) & CODE_CLKS_MASK)
49 #define CODE_GET_NAB(c) (((c) & CODE_NAB) != 0)
50
51 void adm5120_ndelay(u32 ns)
52 {
53 u32 t;
54
55 SW_WRITE_REG(TIMER, TIMER_PERIOD_DEFAULT);
56 SW_WRITE_REG(TIMER_INT, (TIMER_INT_TOS | TIMER_INT_TOM));
57
58 t = (ns+640) / 640;
59 t &= TIMER_PERIOD_MASK;
60 SW_WRITE_REG(TIMER, t | TIMER_TE);
61
62 /* wait until the timer expires */
63 do {
64 t = SW_READ_REG(TIMER_INT);
65 } while ((t & TIMER_INT_TOS) == 0);
66
67 /* leave the timer disabled */
68 SW_WRITE_REG(TIMER, TIMER_PERIOD_DEFAULT);
69 SW_WRITE_REG(TIMER_INT, (TIMER_INT_TOS | TIMER_INT_TOM));
70 }
71
72 void __init adm5120_soc_init(void)
73 {
74 u32 code;
75 u32 clks;
76
77 code = SW_READ_REG(CODE);
78
79 adm5120_product_code = CODE_GET_PC(code);
80 adm5120_revision = CODE_GET_REV(code);
81 adm5120_package = (CODE_GET_PK(code) == CODE_PK_BGA) ?
82 ADM5120_PACKAGE_BGA : ADM5120_PACKAGE_PQFP;
83 adm5120_nand_boot = CODE_GET_NAB(code);
84
85 clks = CODE_GET_CLKS(code);
86 adm5120_speed = ADM5120_SPEED_175;
87 if (clks & 1)
88 adm5120_speed += 25000000;
89 if (clks & 2)
90 adm5120_speed += 50000000;
91 }