tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8830 / glb.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <common.h>
17 #include <asm/io.h>
18 #include <asm/errno.h>
19 #include <ubi_uboot.h>
20 #include <asm/sizes.h>
21
22 #define rounddown(x, y) (                               \
23 {                                                       \
24         typeof(x) __x = (x);                            \
25         __x - (__x % (y));                              \
26 }                                                       \
27 )
28
29 /* vars definitions for controller REGS_GLB */
30 #define REG_GLB_SET(A)                  ( A + 0x1000 )
31 #define REG_GLB_CLR(A)                  ( A + 0x2000 )
32
33 u32 sci_glb_read(u32 reg, u32 msk)
34 {
35         return __raw_readl(reg) & msk;
36 }
37
38 int sci_glb_write(u32 reg, u32 val, u32 msk)
39 {
40         unsigned long flags, hw_flags;
41         __raw_writel((__raw_readl(reg) & ~msk) | val, reg);
42         return 0;
43 }
44
45 static int __is_glb(u32 reg)
46 {
47         //return rounddown(reg, SZ_64K) == rounddown(GREG_BASE, SZ_64K) || rounddown(reg, SZ_64K) == rounddown(AHB_GEN_CTL_BEGIN, SZ_64K);
48         return 1;
49 }
50
51 int sci_glb_set(u32 reg, u32 bit)
52 {
53         if (__is_glb(reg))
54                 __raw_writel(bit, REG_GLB_SET(reg));
55         else
56                 WARN_ON(1);
57         return 0;
58 }
59
60 int sci_glb_clr(u32 reg, u32 bit)
61 {
62         if (__is_glb(reg))
63                 __raw_writel(bit, REG_GLB_CLR(reg));
64         else
65                 WARN_ON(1);
66         return 0;
67 }
68