tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / include / soc / sprd / arch_misc.h
1 /*
2  * Copyright (C) 2013 Spreadtrum Communications Inc.
3  * Copyright (C) steve.zhan
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #define SCX35_ALPHA_TAPOUT      (0x8300aaaa)
18 #define SCX35_ALPHA_TAPOUT_MASK (0xFFFFFFFF)
19
20 #define SCX35_BETA_TAPOUT       (0x8300a001)
21 #define SCX35_BETA_TAPOUT_MASK  (0xFFFFFFFF)
22
23 #define SCX35G_ALPHA_TAPOUT            (0x8730b000)
24 #define SCX35G_ALPHA_TAPOUT_MASK       (0xFFFFF000)
25
26 #define SCX30G2_ALPHA_TAPOUT            (0x8730C000)
27 #define SCX30G2_ALPHA_TAPOUT_MASK       (0xFFFFF000)
28
29 #define SCX9630_ALPHA_TAPOUT            (0x96300000)
30 #define SCX9630_ALPHA_TAPOUT_MASK       (0xFFFFF000)
31
32 #define SCX35L64_ALPHA_TAPOUT            (0x96310000)
33 #define SCX35L64_ALPHA_TAPOUT_MASK       (0xFFFF0000)
34
35 #define SCX9820_ALPHA_TAPOUT            (0x96320000)
36 #define SCX9820_ALPHA_TAPOUT_MASK       (0xFFFF0000)
37
38 #define SCX7720_ALPHA_TAPOUT            (0x88600000)
39 #define SCX7720_ALPHA_TAPOUT_MASK       (0xFFFF0000)
40 /**
41  * sci_get_chip_id - read chip id
42  *
43  *
44  * Return read the chip id
45  */
46 u32 sci_get_chip_id(void);
47
48 /**
49  * sci_get_ana_chip_id - read a-die chip id
50  *
51  * Return the a-die chip id, example: 0X2711A000
52  */
53 u32 sci_get_ana_chip_id(void);
54
55 #define MASK_ANA_VER    ( 0xFFF )
56 enum sci_ana_chip_ver {
57         SC2711AA = 0x000,
58         SC2711AB = 0x000,       /* discard */
59         SC2711AC = 0x002,
60         SC2711BA = 0x100,
61         SC2713CA = 0xA00,
62
63         /* SC2723 */
64         SC2723ES = 0x090,
65         SC2723TS = 0x0C0,
66         //TODO: Add more ana chip version here
67 };
68
69 /**
70  * sci_get_ana_chip_ver - read a-die chip version
71  *
72  * Return the a-die chip version, example: 0X100
73  */
74 int sci_get_ana_chip_ver(void);
75
76 /**
77  * sci_ana_chip_vers_is_compatible
78  *
79  * Check if the given "chip_ver" string matches the a-die chip on board
80  */
81 static inline int sci_ana_chip_ver_is_compatible(enum sci_ana_chip_ver compat)
82 {
83         return sci_get_ana_chip_ver() == (u32)compat;
84 }
85
86 /**
87  *
88  * sc_init_chip_id(void) - read chip id from hardware and save it.
89  *
90  */
91 void __init sc_init_chip_id(void);
92
93 void set_section_ro(unsigned long virt, unsigned long numsections);
94
95
96 #define IS_CPU(name, id, mask)          \
97 static inline int soc_id_is_##name(void)        \
98 {                                               \
99         pr_info("chip id is %x\n",sci_get_chip_id());       \
100         return ((sci_get_chip_id() & mask) == (id & mask));     \
101 }
102
103 IS_CPU(sc8735v0, SCX35_ALPHA_TAPOUT, SCX35_ALPHA_TAPOUT_MASK)
104 IS_CPU(sc8735v1, SCX35_BETA_TAPOUT, SCX35_BETA_TAPOUT_MASK)
105 IS_CPU(sc8735gv0, SCX35G_ALPHA_TAPOUT, SCX35G_ALPHA_TAPOUT_MASK)
106 IS_CPU(sc8730g2v0, SCX30G2_ALPHA_TAPOUT, SCX30G2_ALPHA_TAPOUT_MASK)
107 IS_CPU(sc9631v0, SCX35L64_ALPHA_TAPOUT, SCX35L64_ALPHA_TAPOUT_MASK)
108 IS_CPU(sc9630v0, SCX9630_ALPHA_TAPOUT, SCX9630_ALPHA_TAPOUT_MASK)
109 IS_CPU(sc9820v0, SCX9820_ALPHA_TAPOUT, SCX9820_ALPHA_TAPOUT_MASK)
110 IS_CPU(sc7720v0, SCX7720_ALPHA_TAPOUT, SCX7720_ALPHA_TAPOUT_MASK)
111
112 /*Driver can use this MACRO to distinguish different chip code */
113 #define soc_is_scx35_v0()       soc_id_is_sc8735v0()
114 #define soc_is_scx35_v1()       soc_id_is_sc8735v1()
115 #define soc_is_scx35g_v0()     soc_id_is_sc8735gv0()
116 #define soc_is_scx30g2_v0()     soc_id_is_sc8730g2v0()
117 #define soc_is_scx35l64_v0()     soc_id_is_sc9631v0()
118 #define soc_is_scx9630_v0()     soc_id_is_sc9630v0()
119 #define soc_is_scx9820_v0()     soc_id_is_sc9820v0()
120 #define soc_is_scx7720_v0()     soc_id_is_sc7720v0()
121
122 /**
123 * read value from virtual address. Pls make sure val is not NULL.
124 * return 0 is successful
125 */
126 int sci_read_va(ulong vreg, ulong *val);
127
128 /**
129 * write value to virtual address. if clear_msk is ~0, or_val will fully set to vreg.
130 * return 0 is successful
131 */
132 int sci_write_va(ulong vreg, const ulong or_val, const u32 clear_msk);
133
134 /**
135 * read value from pysical address. Pls make sure val is not NULL.
136 * return 0 is successful
137 */
138 int sci_read_pa(ulong preg, ulong *val);
139
140 /**
141 * write value to pysical address. if clear_msk is ~0, or_val will fully set to paddr.
142 * return 0 is successful
143 */
144 int sci_write_pa(ulong paddr, const ulong or_val, const u32 clear_msk);
145
146 #define SPRD_CHIPID_7715 (0x77150000)
147 #define SPRD_CHIPID_8815 (0X88150000)
148
149 static inline int soc_is_sc7715(void)
150 {
151         unsigned int flag = 0;
152         flag = sci_get_chip_id() & 0xffff0000;
153         if ((SPRD_CHIPID_7715 == flag)
154                         ||(SPRD_CHIPID_8815 == flag))
155         {
156                 return 1;
157         }
158         else
159         {
160                 pr_err("%s error chip id\n", __func__);
161                 return 0;
162         }
163 }