[adm5120] improve support of the Infineon EASY 5120-RT Reference Board
[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 modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 *
11 */
12
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/io.h>
17
18 #include <asm/bootinfo.h>
19 #include <asm/addrspace.h>
20
21 #include <adm5120_info.h>
22 #include <adm5120_defs.h>
23 #include <adm5120_switch.h>
24
25 unsigned int adm5120_product_code;
26 unsigned int adm5120_revision;
27 unsigned int adm5120_package;
28 unsigned int adm5120_nand_boot;
29 unsigned long adm5120_speed;
30
31 /*
32 * CPU settings detection
33 */
34 #define CODE_GET_PC(c) ((c) & CODE_PC_MASK)
35 #define CODE_GET_REV(c) (((c) >> CODE_REV_SHIFT) & CODE_REV_MASK)
36 #define CODE_GET_PK(c) (((c) >> CODE_PK_SHIFT) & CODE_PK_MASK)
37 #define CODE_GET_CLKS(c) (((c) >> CODE_CLKS_SHIFT) & CODE_CLKS_MASK)
38 #define CODE_GET_NAB(c) (((c) & CODE_NAB) != 0)
39
40 void adm5120_ndelay(u32 ns)
41 {
42 u32 t;
43
44 SW_WRITE_REG(SWITCH_REG_TIMER, TIMER_PERIOD_DEFAULT);
45 SW_WRITE_REG(SWITCH_REG_TIMER_INT, (TIMER_INT_TOS | TIMER_INT_TOM));
46
47 t = (ns+640) / 640;
48 t &= TIMER_PERIOD_MASK;
49 SW_WRITE_REG(SWITCH_REG_TIMER, t | TIMER_TE);
50
51 /* wait until the timer expires */
52 do {
53 t = SW_READ_REG(SWITCH_REG_TIMER_INT);
54 } while ((t & TIMER_INT_TOS) == 0);
55
56 /* leave the timer disabled */
57 SW_WRITE_REG(SWITCH_REG_TIMER, TIMER_PERIOD_DEFAULT);
58 SW_WRITE_REG(SWITCH_REG_TIMER_INT, (TIMER_INT_TOS | TIMER_INT_TOM));
59 }
60
61 void __init adm5120_soc_init(void)
62 {
63 u32 code;
64 u32 clks;
65
66 code = SW_READ_REG(SWITCH_REG_CODE);
67
68 adm5120_product_code = CODE_GET_PC(code);
69 adm5120_revision = CODE_GET_REV(code);
70 adm5120_package = (CODE_GET_PK(code) == CODE_PK_BGA) ?
71 ADM5120_PACKAGE_BGA : ADM5120_PACKAGE_PQFP;
72 adm5120_nand_boot = CODE_GET_NAB(code);
73
74 clks = CODE_GET_CLKS(code);
75 adm5120_speed = ADM5120_SPEED_175;
76 if (clks & 1)
77 adm5120_speed += 25000000;
78 if (clks & 2)
79 adm5120_speed += 50000000;
80 }