2 * TI OMAP2 32kHz sync timer emulation.
4 * Copyright (C) 2007-2008 Nokia Corporation
5 * Written by Andrzej Zaborowski <andrew@openedhand.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) any later version of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "qemu/timer.h"
23 #include "hw/arm/omap.h"
24 struct omap_synctimer_s
{
30 /* 32-kHz Sync Timer of the OMAP2 */
31 static uint32_t omap_synctimer_read(struct omap_synctimer_s
*s
) {
32 return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
), 0x8000,
33 NANOSECONDS_PER_SECOND
);
36 void omap_synctimer_reset(struct omap_synctimer_s
*s
)
38 s
->val
= omap_synctimer_read(s
);
41 static uint32_t omap_synctimer_readw(void *opaque
, hwaddr addr
)
43 struct omap_synctimer_s
*s
= (struct omap_synctimer_s
*) opaque
;
46 case 0x00: /* 32KSYNCNT_REV */
50 return omap_synctimer_read(s
) - s
->val
;
57 static uint32_t omap_synctimer_readh(void *opaque
, hwaddr addr
)
59 struct omap_synctimer_s
*s
= (struct omap_synctimer_s
*) opaque
;
65 ret
= omap_synctimer_readw(opaque
, addr
);
71 static void omap_synctimer_write(void *opaque
, hwaddr addr
,
77 static const MemoryRegionOps omap_synctimer_ops
= {
85 omap_badwidth_write32
,
90 .endianness
= DEVICE_NATIVE_ENDIAN
,
93 struct omap_synctimer_s
*omap_synctimer_init(struct omap_target_agent_s
*ta
,
94 struct omap_mpu_state_s
*mpu
, omap_clk fclk
, omap_clk iclk
)
96 struct omap_synctimer_s
*s
= g_malloc0(sizeof(*s
));
98 omap_synctimer_reset(s
);
99 memory_region_init_io(&s
->iomem
, NULL
, &omap_synctimer_ops
, s
, "omap.synctimer",
100 omap_l4_region_size(ta
, 0));
101 omap_l4_attach(ta
, 0, &s
->iomem
);