1 /* SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 StarFive Technology Co., Ltd.
8 #include <linux/kern_levels.h>
12 #define USE_CSIDPHY_ONE_CLK_MODE 1
33 extern unsigned int stdbg_level;
34 extern unsigned int stdbg_mask;
36 #define ST_MODULE2STRING(__module) ({ \
44 __str = "st_csiphy"; \
62 __str = "st_sensor"; \
72 #define st_debug(module, __fmt, arg...) \
74 if (stdbg_level > ST_INFO) { \
75 if (stdbg_mask & module) \
76 pr_err("[%s] debug: " __fmt, \
77 ST_MODULE2STRING(module), \
82 #define st_info(module, __fmt, arg...) \
84 if (stdbg_level > ST_WARN) { \
85 if (stdbg_mask & module) \
86 pr_err("[%s] info: " __fmt, \
87 ST_MODULE2STRING(module), \
92 #define st_warn(module, __fmt, arg...) \
94 if (stdbg_level > ST_ERR) { \
95 if (stdbg_mask & module) \
96 pr_err("[%s] warn: " __fmt, \
97 ST_MODULE2STRING(module), \
102 #define st_err(module, __fmt, arg...) \
104 if (stdbg_level > ST_NONE) { \
105 if (stdbg_mask & module) \
106 pr_err("[%s] error: " __fmt, \
107 ST_MODULE2STRING(module), \
112 #define st_err_ratelimited(module, fmt, ...) \
114 static DEFINE_RATELIMIT_STATE(_rs, \
115 DEFAULT_RATELIMIT_INTERVAL, \
116 DEFAULT_RATELIMIT_BURST); \
117 if (__ratelimit(&_rs) && (stdbg_level > ST_NONE)) { \
118 if (stdbg_mask & module) \
119 pr_err("[%s] error: " fmt, \
120 ST_MODULE2STRING(module), \
125 #define set_bits(p, v, b, m) (((p) & ~(m)) | ((v) << (b)))
127 static inline u32 reg_read(void __iomem *base, u32 reg)
129 return ioread32(base + reg);
132 static inline void reg_write(void __iomem *base, u32 reg, u32 val)
134 iowrite32(val, base + reg);
137 static inline void reg_set_bit(void __iomem *base, u32 reg, u32 mask, u32 val)
141 value = ioread32(base + reg) & ~mask;
144 iowrite32(val, base + reg);
147 static inline void reg_set(void __iomem *base, u32 reg, u32 mask)
149 iowrite32(ioread32(base + reg) | mask, base + reg);
152 static inline void reg_clear(void __iomem *base, u32 reg, u32 mask)
154 iowrite32(ioread32(base + reg) & ~mask, base + reg);
157 static inline void reg_set_highest_bit(void __iomem *base, u32 reg)
161 val = ioread32(base + reg);
163 val |= (0x1 & 0x1) << 31;
164 iowrite32(val, base + reg);
167 static inline void reg_clr_highest_bit(void __iomem *base, u32 reg)
171 val = ioread32(base + reg);
173 val |= (0x0 & 0x1) << 31;
174 iowrite32(val, base + reg);
177 static inline void print_reg(unsigned int module, void __iomem *base, u32 reg)
179 //st_debug(module, "REG 0x%x = 0x%x\n",
180 // base + reg, ioread32(base + reg));
183 #endif /* STF_COMMON_H */