Lines Matching +full:ch0 +full:- +full:2
2 * Renesas 16bit Compare-match timer
9 * SPDX-License-Identifier: GPL-2.0-or-later
13 * version 2 or later, as published by the Free Software Foundation.
28 #include "hw/qdev-properties.h"
33 * +0 CMSTR - common control
34 * +2 CMCR - ch0
35 * +4 CMCNT - ch0
36 * +6 CMCOR - ch0
37 * +8 CMCR - ch1
38 * +10 CMCNT - ch1
39 * +12 CMCOR - ch1
40 * If we think that the address of CH 0 has an offset of +2,
46 FIELD(CMSTR, STR, 0, 2)
49 FIELD(CMCR, CKS, 0, 2)
51 REG16(CMCNT, 2)
58 if ((cmt->cmstr & (1 << ch)) == 0) { in update_events()
62 next_time = cmt->cmcor[ch] - cmt->cmcnt[ch]; in update_events()
64 next_time /= cmt->input_freq; in update_events()
66 * CKS -> div rate in update_events()
67 * 0 -> 8 (1 << 3) in update_events()
68 * 1 -> 32 (1 << 5) in update_events()
69 * 2 -> 128 (1 << 7) in update_events()
70 * 3 -> 512 (1 << 9) in update_events()
72 next_time *= 1 << (3 + FIELD_EX16(cmt->cmcr[ch], CMCR, CKS) * 2); in update_events()
74 timer_mod(&cmt->timer[ch], next_time); in update_events()
81 if (cmt->cmstr & (1 << ch)) { in read_cmcnt()
82 delta = (now - cmt->tick[ch]); in read_cmcnt()
84 delta /= cmt->input_freq; in read_cmcnt()
85 delta /= 1 << (3 + FIELD_EX16(cmt->cmcr[ch], CMCR, CKS) * 2); in read_cmcnt()
86 cmt->tick[ch] = now; in read_cmcnt()
87 return cmt->cmcnt[ch] + delta; in read_cmcnt()
89 return cmt->cmcnt[ch]; in read_cmcnt()
102 FIELD_EX16(cmt->cmstr, CMSTR, STR)); in cmt_read()
107 offset -= 0x02; in cmt_read()
113 FIELD_EX16(cmt->cmstr, CMCR, CKS)); in cmt_read()
115 FIELD_EX16(cmt->cmstr, CMCR, CMIE)); in cmt_read()
120 return cmt->cmcor[ch]; in cmt_read()
134 timer_del(&cmt->timer[ch]); in start_stop()
144 cmt->cmstr = FIELD_EX16(val, CMSTR, STR); in cmt_write()
145 start_stop(cmt, 0, FIELD_EX16(cmt->cmstr, CMSTR, STR0)); in cmt_write()
146 start_stop(cmt, 1, FIELD_EX16(cmt->cmstr, CMSTR, STR1)); in cmt_write()
150 offset -= 0x02; in cmt_write()
154 cmt->cmcr[ch] = FIELD_DP16(cmt->cmcr[ch], CMCR, CKS, in cmt_write()
156 cmt->cmcr[ch] = FIELD_DP16(cmt->cmcr[ch], CMCR, CMIE, in cmt_write()
159 case 2: in cmt_write()
160 cmt->cmcnt[ch] = val; in cmt_write()
163 cmt->cmcor[ch] = val; in cmt_write()
171 if (FIELD_EX16(cmt->cmstr, CMSTR, STR) & (1 << ch)) { in cmt_write()
182 .min_access_size = 2,
183 .max_access_size = 2,
186 .min_access_size = 2,
187 .max_access_size = 2,
193 cmt->cmcnt[ch] = 0; in timer_events()
194 cmt->tick[ch] = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in timer_events()
196 if (FIELD_EX16(cmt->cmcr[ch], CMCR, CMIE)) { in timer_events()
197 qemu_irq_pulse(cmt->cmi[ch]); in timer_events()
218 cmt->cmstr = 0; in rcmt_reset()
219 cmt->cmcr[0] = cmt->cmcr[1] = 0; in rcmt_reset()
220 cmt->cmcnt[0] = cmt->cmcnt[1] = 0; in rcmt_reset()
221 cmt->cmcor[0] = cmt->cmcor[1] = 0xffff; in rcmt_reset()
230 memory_region_init_io(&cmt->memory, OBJECT(cmt), &cmt_ops, in rcmt_init()
231 cmt, "renesas-cmt", 0x10); in rcmt_init()
232 sysbus_init_mmio(d, &cmt->memory); in rcmt_init()
234 for (i = 0; i < ARRAY_SIZE(cmt->cmi); i++) { in rcmt_init()
235 sysbus_init_irq(d, &cmt->cmi[i]); in rcmt_init()
237 timer_init_ns(&cmt->timer[0], QEMU_CLOCK_VIRTUAL, timer_event0, cmt); in rcmt_init()
238 timer_init_ns(&cmt->timer[1], QEMU_CLOCK_VIRTUAL, timer_event1, cmt); in rcmt_init()
242 .name = "rx-cmt",
257 DEFINE_PROP_UINT64("input-freq", RCMTState, input_freq, 0),
265 dc->vmsd = &vmstate_rcmt; in rcmt_class_init()