Skip to content

Commit d14be99

Browse files
author
Laurent Pinchart
committed
clocksource: sh_cmt: Replace hardcoded register values with macros
Define symbolic macros for all used registers bits. Signed-off-by: Laurent Pinchart <[email protected]>
1 parent 2cda3ac commit d14be99

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

drivers/clocksource/sh_cmt.c

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ struct sh_cmt_device {
114114
unsigned int num_channels;
115115
};
116116

117+
#define SH_CMT16_CMCSR_CMF (1 << 7)
118+
#define SH_CMT16_CMCSR_CMIE (1 << 6)
119+
#define SH_CMT16_CMCSR_CKS8 (0 << 0)
120+
#define SH_CMT16_CMCSR_CKS32 (1 << 0)
121+
#define SH_CMT16_CMCSR_CKS128 (2 << 0)
122+
#define SH_CMT16_CMCSR_CKS512 (3 << 0)
123+
#define SH_CMT16_CMCSR_CKS_MASK (3 << 0)
124+
125+
#define SH_CMT32_CMCSR_CMF (1 << 15)
126+
#define SH_CMT32_CMCSR_OVF (1 << 14)
127+
#define SH_CMT32_CMCSR_WRFLG (1 << 13)
128+
#define SH_CMT32_CMCSR_STTF (1 << 12)
129+
#define SH_CMT32_CMCSR_STPF (1 << 11)
130+
#define SH_CMT32_CMCSR_SSIE (1 << 10)
131+
#define SH_CMT32_CMCSR_CMS (1 << 9)
132+
#define SH_CMT32_CMCSR_CMM (1 << 8)
133+
#define SH_CMT32_CMCSR_CMTOUT_IE (1 << 7)
134+
#define SH_CMT32_CMCSR_CMR_NONE (0 << 4)
135+
#define SH_CMT32_CMCSR_CMR_DMA (1 << 4)
136+
#define SH_CMT32_CMCSR_CMR_IRQ (2 << 4)
137+
#define SH_CMT32_CMCSR_CMR_MASK (3 << 4)
138+
#define SH_CMT32_CMCSR_DBGIVD (1 << 3)
139+
#define SH_CMT32_CMCSR_CKS_RCLK8 (4 << 0)
140+
#define SH_CMT32_CMCSR_CKS_RCLK32 (5 << 0)
141+
#define SH_CMT32_CMCSR_CKS_RCLK128 (6 << 0)
142+
#define SH_CMT32_CMCSR_CKS_RCLK1 (7 << 0)
143+
#define SH_CMT32_CMCSR_CKS_MASK (7 << 0)
144+
117145
static unsigned long sh_cmt_read16(void __iomem *base, unsigned long offs)
118146
{
119147
return ioread16(base + (offs << 1));
@@ -140,8 +168,8 @@ static const struct sh_cmt_info sh_cmt_info[] = {
140168
[SH_CMT_16BIT] = {
141169
.model = SH_CMT_16BIT,
142170
.width = 16,
143-
.overflow_bit = 0x80,
144-
.clear_bits = ~0x80,
171+
.overflow_bit = SH_CMT16_CMCSR_CMF,
172+
.clear_bits = ~SH_CMT16_CMCSR_CMF,
145173
.read_control = sh_cmt_read16,
146174
.write_control = sh_cmt_write16,
147175
.read_count = sh_cmt_read16,
@@ -150,8 +178,8 @@ static const struct sh_cmt_info sh_cmt_info[] = {
150178
[SH_CMT_32BIT] = {
151179
.model = SH_CMT_32BIT,
152180
.width = 32,
153-
.overflow_bit = 0x8000,
154-
.clear_bits = ~0xc000,
181+
.overflow_bit = SH_CMT32_CMCSR_CMF,
182+
.clear_bits = ~(SH_CMT32_CMCSR_CMF | SH_CMT32_CMCSR_OVF),
155183
.read_control = sh_cmt_read16,
156184
.write_control = sh_cmt_write16,
157185
.read_count = sh_cmt_read32,
@@ -160,8 +188,8 @@ static const struct sh_cmt_info sh_cmt_info[] = {
160188
[SH_CMT_32BIT_FAST] = {
161189
.model = SH_CMT_32BIT_FAST,
162190
.width = 32,
163-
.overflow_bit = 0x8000,
164-
.clear_bits = ~0xc000,
191+
.overflow_bit = SH_CMT32_CMCSR_CMF,
192+
.clear_bits = ~(SH_CMT32_CMCSR_CMF | SH_CMT32_CMCSR_OVF),
165193
.read_control = sh_cmt_read16,
166194
.write_control = sh_cmt_write16,
167195
.read_count = sh_cmt_read32,
@@ -170,8 +198,8 @@ static const struct sh_cmt_info sh_cmt_info[] = {
170198
[SH_CMT_48BIT] = {
171199
.model = SH_CMT_48BIT,
172200
.width = 32,
173-
.overflow_bit = 0x8000,
174-
.clear_bits = ~0xc000,
201+
.overflow_bit = SH_CMT32_CMCSR_CMF,
202+
.clear_bits = ~(SH_CMT32_CMCSR_CMF | SH_CMT32_CMCSR_OVF),
175203
.read_control = sh_cmt_read32,
176204
.write_control = sh_cmt_write32,
177205
.read_count = sh_cmt_read32,
@@ -180,8 +208,8 @@ static const struct sh_cmt_info sh_cmt_info[] = {
180208
[SH_CMT_48BIT_GEN2] = {
181209
.model = SH_CMT_48BIT_GEN2,
182210
.width = 32,
183-
.overflow_bit = 0x8000,
184-
.clear_bits = ~0xc000,
211+
.overflow_bit = SH_CMT32_CMCSR_CMF,
212+
.clear_bits = ~(SH_CMT32_CMCSR_CMF | SH_CMT32_CMCSR_OVF),
185213
.read_control = sh_cmt_read32,
186214
.write_control = sh_cmt_write32,
187215
.read_count = sh_cmt_read32,
@@ -295,10 +323,14 @@ static int sh_cmt_enable(struct sh_cmt_channel *ch, unsigned long *rate)
295323
/* configure channel, periodic mode and maximum timeout */
296324
if (ch->cmt->info->width == 16) {
297325
*rate = clk_get_rate(ch->cmt->clk) / 512;
298-
sh_cmt_write_cmcsr(ch, 0x43);
326+
sh_cmt_write_cmcsr(ch, SH_CMT16_CMCSR_CMIE |
327+
SH_CMT16_CMCSR_CKS512);
299328
} else {
300329
*rate = clk_get_rate(ch->cmt->clk) / 8;
301-
sh_cmt_write_cmcsr(ch, 0x01a4);
330+
sh_cmt_write_cmcsr(ch, SH_CMT32_CMCSR_CMM |
331+
SH_CMT32_CMCSR_CMTOUT_IE |
332+
SH_CMT32_CMCSR_CMR_IRQ |
333+
SH_CMT32_CMCSR_CKS_RCLK8);
302334
}
303335

304336
sh_cmt_write_cmcor(ch, 0xffffffff);

0 commit comments

Comments
 (0)