tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8825 / 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 <asm/arch-sc8825/ldo.h>
20 #include <asm/arch/sc8810_reg_global.h>
21 #include <asm/arch/regs_global.h>
22 #include <asm/arch/regs_cpc.h>
23 #include <asm/arch/analog_reg_v3.h>
24 #include <ubi_uboot.h>
25 #include <asm/sizes.h>
26
27 #define rounddown(x, y) (                               \
28 {                                                       \
29         typeof(x) __x = (x);                            \
30         __x - (__x % (y));                              \
31 }                                                       \
32 )
33
34 /* vars definitions for controller REGS_GLB */
35 #define REG_GLB_SET(A)                  ( A + 0x1000 )
36 #define REG_GLB_CLR(A)                  ( A + 0x2000 )
37
38 u32 sci_glb_read(u32 reg, u32 msk)
39 {
40         return __raw_readl(reg) & msk;
41 }
42
43 int sci_glb_write(u32 reg, u32 val, u32 msk)
44 {
45         unsigned long flags, hw_flags;
46         __raw_writel((__raw_readl(reg) & ~msk) | val, reg);
47         return 0;
48 }
49
50 static int __is_glb(u32 reg)
51 {
52         return rounddown(reg, SZ_64K) == rounddown(GREG_BASE, SZ_64K) ||
53             rounddown(reg, SZ_64K) == rounddown(AHB_GEN_CTL_BEGIN, SZ_64K);
54 }
55
56 int sci_glb_set(u32 reg, u32 bit)
57 {
58         if (__is_glb(reg))
59                 __raw_writel(bit, REG_GLB_SET(reg));
60         else
61                 WARN_ON(1);
62         return 0;
63 }
64
65 int sci_glb_clr(u32 reg, u32 bit)
66 {
67         if (__is_glb(reg))
68                 __raw_writel(bit, REG_GLB_CLR(reg));
69         else
70                 WARN_ON(1);
71         return 0;
72 }
73