Root/target/linux/adm5120/files/arch/mips/adm5120/common/adm5120.c

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

Archive Download this file



interactive