2 * Freescale STMP37XX/STMP378X SoC register access interfaces
4 * The SoC registers may be accessed via:
6 * - single 32 bit address, or
7 * - four 32 bit addresses - general purpose, set, clear and toggle bits
9 * Multiple IP blocks (e.g. SSP, UART) provide identical register sets per
12 * Embedded Alley Solutions, Inc <source@embeddedalley.com>
14 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
15 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
19 * The code contained herein is licensed under the GNU General Public
20 * License. You may obtain a copy of the GNU General Public License
21 * Version 2 or later at the following locations:
23 * http://www.opensource.org/licenses/gpl-license.html
24 * http://www.gnu.org/copyleft/gpl.html
26 #ifndef __ASM_PLAT_STMP3XXX_REGS_H
27 #define __ASM_PLAT_STMP3XXX_REGS_H
35 #define REGS_BASE STMP3XXX_REGS_BASE
37 #define HW_STMP3xxx_SET 0x04
38 #define HW_STMP3xxx_CLR 0x08
39 #define HW_STMP3xxx_TOG 0x0c
42 #define HW_REGISTER_FUNCS(id, base, offset, regset, rd, wr) \
43 static const u32 id##_OFFSET = offset; \
44 static inline u32 id##_RD_NB(const void __iomem *regbase) { \
46 printk(KERN_ERR"%s: cannot READ at %p+%x\n", \
47 #id, regbase, offset); \
48 return __raw_readl(regbase + offset); \
50 static inline void id##_WR_NB(void __iomem *regbase, u32 v) { \
52 printk(KERN_ERR"%s: cannot WRITE at %p+%x\n", \
53 #id, regbase, offset); \
54 __raw_writel(v, regbase + offset); \
56 static inline void id##_SET_NB(void __iomem *regbase, u32 v) { \
58 printk(KERN_ERR"%s: cannot SET at %p+%x\n", \
59 #id, regbase, offset); \
61 __raw_writel(v, regbase + \
62 offset + HW_STMP3xxx_SET); \
64 __raw_writel(v | __raw_readl(regbase + offset), \
67 static inline void id##_CLR_NB(void __iomem *regbase, u32 v) { \
69 printk(KERN_ERR"%s: cannot CLR at %p+%x\n", \
70 #id, regbase, offset); \
72 __raw_writel(v, regbase + \
73 offset + HW_STMP3xxx_CLR); \
76 ~v & __raw_readl(regbase + offset), \
79 static inline void id##_TOG_NB(void __iomem *regbase, u32 v) { \
81 printk(KERN_ERR"%s: cannot TOG at %p+%x\n", \
82 #id, regbase, offset); \
84 __raw_writel(v, regbase + \
85 offset + HW_STMP3xxx_TOG); \
87 __raw_writel(v ^ __raw_readl(regbase + offset), \
90 static inline u32 id##_RD(void) { return id##_RD_NB(base); } \
91 static inline void id##_WR(u32 v) { id##_WR_NB(base, v); } \
92 static inline void id##_SET(u32 v) { id##_SET_NB(base, v); } \
93 static inline void id##_CLR(u32 v) { id##_CLR_NB(base, v); } \
94 static inline void id##_TOG(u32 v) { id##_TOG_NB(base, v); }
96 #define HW_REGISTER_FUNCS_INDEXED(id, base, offset, regset, rd, wr, step)\
97 static inline u32 id##_OFFSET(int i) { \
98 return offset + i * step; \
100 static inline u32 id##_RD_NB(const void __iomem *regbase, int i) {\
102 printk(KERN_ERR"%s(%d): can't READ at %p+%x\n", \
103 #id, i, regbase, offset + i * step); \
104 return __raw_readl(regbase + offset + i * step); \
106 static inline void id##_WR_NB(void __iomem *regbase, int i, u32 v) {\
108 printk(KERN_ERR"%s(%d): can't WRITE at %p+%x\n",\
109 #id, i, regbase, offset + i * step); \
110 __raw_writel(v, regbase + offset + i * step); \
112 static inline void id##_SET_NB(void __iomem *regbase, int i, u32 v) {\
114 printk(KERN_ERR"%s(%d): can't SET at %p+%x\n", \
115 #id, i, regbase, offset + i * step); \
117 __raw_writel(v, regbase + offset + \
118 i * step + HW_STMP3xxx_SET); \
120 __raw_writel(v | __raw_readl(regbase + \
121 offset + i * step), \
122 regbase + offset + i * step); \
124 static inline void id##_CLR_NB(void __iomem *regbase, int i, u32 v) {\
126 printk(KERN_ERR"%s(%d): cannot CLR at %p+%x\n", \
127 #id, i, regbase, offset + i * step); \
129 __raw_writel(v, regbase + offset + \
130 i * step + HW_STMP3xxx_CLR); \
132 __raw_writel(~v & __raw_readl(regbase + \
133 offset + i * step), \
134 regbase + offset + i * step); \
136 static inline void id##_TOG_NB(void __iomem *regbase, int i, u32 v) {\
138 printk(KERN_ERR"%s(%d): cannot TOG at %p+%x\n", \
139 #id, i, regbase, offset + i * step); \
141 __raw_writel(v, regbase + offset + \
142 i * step + HW_STMP3xxx_TOG); \
144 __raw_writel(v ^ __raw_readl(regbase + offset \
146 regbase + offset + i * step); \
148 static inline u32 id##_RD(int i) \
150 return id##_RD_NB(base, i); \
152 static inline void id##_WR(int i, u32 v) \
154 id##_WR_NB(base, i, v); \
156 static inline void id##_SET(int i, u32 v) \
158 id##_SET_NB(base, i, v); \
160 static inline void id##_CLR(int i, u32 v) \
162 id##_CLR_NB(base, i, v); \
164 static inline void id##_TOG(int i, u32 v) \
166 id##_TOG_NB(base, i, v); \
169 #define HW_REGISTER_WO(id, base, offset)\
170 HW_REGISTER_FUNCS(id, base, offset, 1, 0, 1)
171 #define HW_REGISTER_RO(id, base, offset)\
172 HW_REGISTER_FUNCS(id, base, offset, 1, 1, 0)
173 #define HW_REGISTER(id, base, offset) \
174 HW_REGISTER_FUNCS(id, base, offset, 1, 1, 1)
175 #define HW_REGISTER_0(id, base, offset) \
176 HW_REGISTER_FUNCS(id, base, offset, 0, 1, 1)
177 #define HW_REGISTER_INDEXED(id, base, offset, step) \
178 HW_REGISTER_FUNCS_INDEXED(id, base, offset, 1, 1, 1, step)
179 #define HW_REGISTER_RO_INDEXED(id, base, offset, step) \
180 HW_REGISTER_FUNCS_INDEXED(id, base, offset, 1, 1, 0, step)
181 #define HW_REGISTER_0_INDEXED(id, base, offset, step) \
182 HW_REGISTER_FUNCS_INDEXED(id, base, offset, 0, 1, 1, step)
183 #else /* __ASSEMBLER__ */
184 #define HW_REGISTER_FUNCS(id, base, offset, regset, rd, wr)
185 #define HW_REGISTER_FUNCS_INDEXED(id, base, offset, regset, rd, wr, step)
186 #define HW_REGISTER_WO(id, base, offset)
187 #define HW_REGISTER_RO(id, base, offset)
188 #define HW_REGISTER(id, base, offset)
189 #define HW_REGISTER_0(id, base, offset)
190 #define HW_REGISTER_INDEXED(id, base, offset, step)
191 #define HW_REGISTER_RO_INDEXED(id, base, offset, step)
192 #define HW_REGISTER_0_INDEXED(id, base, offset, step)
193 #endif /* __ASSEMBLER__ */
195 #endif /* __ASM_PLAT_STMP3XXX_REGS_H */