From: Antony Pavlov <antonynpavlov@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Alex Dumitrache" <broscutamaker@gmail.com>,
"Peter Crosthwaite" <peter.crosthwaite@xilinx.com>,
"Giovanni Condello" <condellog@gmail.com>,
g3gg0 <georg.hofstetter@lx-networking.de>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Paul Brook" <paul@codesourcery.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
"Antony Pavlov" <antonynpavlov@gmail.com>
Subject: [Qemu-devel] [RFC v5 3/5] hw/arm/digic: add timer support
Date: Sat, 7 Sep 2013 11:04:25 +0400 [thread overview]
Message-ID: <1378537467-13471-4-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1378537467-13471-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
hw/arm/digic.c | 28 ++++++++++++
hw/timer/Makefile.objs | 1 +
hw/timer/digic-timer.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++
hw/timer/digic-timer.h | 36 ++++++++++++++++
include/hw/arm/digic.h | 6 +++
5 files changed, 185 insertions(+)
create mode 100644 hw/timer/digic-timer.c
create mode 100644 hw/timer/digic-timer.h
diff --git a/hw/arm/digic.c b/hw/arm/digic.c
index 0d38872..4a8e67a 100644
--- a/hw/arm/digic.c
+++ b/hw/arm/digic.c
@@ -22,24 +22,52 @@
#include "hw/arm/digic.h"
+#define DIGIC4_TIMER_BASE(n) (0xc0210000 + (n) * 0x100)
+
static void digic_init(Object *obj)
{
DigicState *s = DIGIC(obj);
+ DeviceState *dev;
+ int i;
object_initialize(&s->cpu, sizeof(s->cpu), "arm946-" TYPE_ARM_CPU);
object_property_add_child(obj, "cpu", OBJECT(&s->cpu), NULL);
+
+ for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
+#define DIGIC_TIMER_NAME_MLEN 11
+ char name[DIGIC_TIMER_NAME_MLEN];
+
+ object_initialize(&s->timer[i], sizeof(s->timer[i]), TYPE_DIGIC_TIMER);
+ dev = DEVICE(&s->timer[i]);
+ qdev_set_parent_bus(dev, sysbus_get_default());
+ snprintf(name, DIGIC_TIMER_NAME_MLEN, "timer[%d]", i);
+ object_property_add_child(obj, name, OBJECT(&s->timer[i]), NULL);
+ }
}
static void digic_realize(DeviceState *dev, Error **errp)
{
DigicState *s = DIGIC(dev);
Error *err = NULL;
+ SysBusDevice *sbd;
+ int i;
object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
if (err != NULL) {
error_propagate(errp, err);
return;
}
+
+ for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
+ object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
+ return;
+ }
+
+ sbd = SYS_BUS_DEVICE(&s->timer[i]);
+ sysbus_mmio_map(sbd, 0, DIGIC4_TIMER_BASE(i));
+ }
}
static void digic_class_init(ObjectClass *oc, void *data)
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
index eca5905..5479aee 100644
--- a/hw/timer/Makefile.objs
+++ b/hw/timer/Makefile.objs
@@ -25,5 +25,6 @@ obj-$(CONFIG_OMAP) += omap_synctimer.o
obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o
obj-$(CONFIG_SH4) += sh_timer.o
obj-$(CONFIG_TUSB6010) += tusb6010.o
+obj-$(CONFIG_DIGIC) += digic-timer.o
obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
diff --git a/hw/timer/digic-timer.c b/hw/timer/digic-timer.c
new file mode 100644
index 0000000..8f5c62a
--- /dev/null
+++ b/hw/timer/digic-timer.c
@@ -0,0 +1,114 @@
+/*
+ * QEMU model of the Canon DIGIC timer block.
+ *
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * This model is based on reverse engineering efforts
+ * made by CHDK (http://chdk.wikia.com) and
+ * Magic Lantern (http://www.magiclantern.fm) projects
+ * contributors.
+ *
+ * See "Timer/Clock Module" docs here:
+ * http://magiclantern.wikia.com/wiki/Register_Map
+ *
+ * The QEMU model of the OSTimer in PKUnity SoC by Guan Xuetao
+ * is used as a template.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include "hw/sysbus.h"
+#include "hw/ptimer.h"
+#include "qemu/main-loop.h"
+
+#include "hw/timer/digic-timer.h"
+
+# define DIGIC_TIMER_CONTROL 0x00
+# define DIGIC_TIMER_VALUE 0x0c
+
+static uint64_t digic_timer_read(void *opaque, hwaddr offset, unsigned size)
+{
+ DigicTimerState *s = opaque;
+ uint32_t ret = 0;
+
+ switch (offset) {
+ case DIGIC_TIMER_VALUE:
+ ret = (uint32_t)ptimer_get_count(s->ptimer);
+ ret &= 0xffff;
+ break;
+ default:
+ qemu_log_mask(LOG_UNIMP,
+ "digic-timer: read access to unknown register 0x"
+ TARGET_FMT_plx, offset);
+ }
+
+ return ret;
+}
+
+static void digic_timer_write(void *opaque, hwaddr offset,
+ uint64_t value, unsigned size)
+{
+ DigicTimerState *s = opaque;
+
+ /* FIXME: without documentation every write just starts timer */
+ ptimer_set_limit(s->ptimer, 0x0000ffff, 1);
+ ptimer_run(s->ptimer, 1);
+}
+
+static const MemoryRegionOps digic_timer_ops = {
+ .read = digic_timer_read,
+ .write = digic_timer_write,
+ .impl = {
+ .min_access_size = 4,
+ .max_access_size = 4,
+ },
+ .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static void digic_timer_tick(void *opaque)
+{
+ DigicTimerState *s = opaque;
+
+ ptimer_run(s->ptimer, 1);
+}
+
+static void digic_timer_init(Object *obj)
+{
+ DigicTimerState *s = DIGIC_TIMER(obj);
+
+ s->bh = qemu_bh_new(digic_timer_tick, s);
+ s->ptimer = ptimer_init(s->bh);
+
+ /*
+ * FIXME: there is no documentation on Digic timer
+ * frequency setup so let it always run at 1 MHz
+ */
+ ptimer_set_freq(s->ptimer, 1 * 1000 * 1000);
+
+ memory_region_init_io(&s->iomem, OBJECT(s), &digic_timer_ops, s,
+ TYPE_DIGIC_TIMER, 0x100);
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static const TypeInfo digic_timer_info = {
+ .name = TYPE_DIGIC_TIMER,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(DigicTimerState),
+ .instance_init = digic_timer_init,
+};
+
+static void digic_timer_register_type(void)
+{
+ type_register_static(&digic_timer_info);
+}
+
+type_init(digic_timer_register_type)
diff --git a/hw/timer/digic-timer.h b/hw/timer/digic-timer.h
new file mode 100644
index 0000000..daf271d
--- /dev/null
+++ b/hw/timer/digic-timer.h
@@ -0,0 +1,36 @@
+/*
+ * Canon DIGIC timer block declarations.
+ *
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef HW_TIMER_DIGIC_TIMER_H
+#define HW_TIMER_DIGIC_TIMER_H
+
+#include "hw/sysbus.h"
+#include "qemu/typedefs.h"
+#include "hw/ptimer.h"
+
+#define TYPE_DIGIC_TIMER "digic-timer"
+#define DIGIC_TIMER(obj) OBJECT_CHECK(DigicTimerState, (obj), TYPE_DIGIC_TIMER)
+
+typedef struct DigicTimerState {
+ SysBusDevice parent_obj;
+
+ MemoryRegion iomem;
+ QEMUBH *bh;
+ ptimer_state *ptimer;
+} DigicTimerState;
+
+#endif /* HW_TIMER_DIGIC_TIMER_H */
diff --git a/include/hw/arm/digic.h b/include/hw/arm/digic.h
index b7d16fb..177a06d 100644
--- a/include/hw/arm/digic.h
+++ b/include/hw/arm/digic.h
@@ -20,16 +20,22 @@
#include "cpu.h"
+#include "hw/timer/digic-timer.h"
+
#define TYPE_DIGIC "digic"
#define DIGIC(obj) OBJECT_CHECK(DigicState, (obj), TYPE_DIGIC)
+#define DIGIC4_NB_TIMERS 3
+
typedef struct DigicState {
/*< private >*/
DeviceState parent_obj;
/*< public >*/
ARMCPU cpu;
+
+ DigicTimerState timer[DIGIC4_NB_TIMERS];
} DigicState;
#endif /* HW_ARM_DIGIC_H */
--
1.8.4.rc3
next prev parent reply other threads:[~2013-09-07 7:07 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-07 7:04 [Qemu-devel] [RFC v5 0/5] hw/arm: add initial support for Canon DIGIC SoC Antony Pavlov
2013-09-07 7:04 ` [Qemu-devel] [RFC v5 1/5] hw/arm: add very " Antony Pavlov
2013-09-13 14:48 ` Andreas Färber
2013-09-07 7:04 ` [Qemu-devel] [RFC v5 2/5] hw/arm/digic: prepare DIGIC-based boards support Antony Pavlov
2013-10-17 18:01 ` Peter Maydell
2013-10-17 18:51 ` Georg Hofstetter
2013-10-17 19:17 ` Peter Maydell
2013-10-20 0:13 ` Georg Hofstetter
2013-10-22 11:26 ` Antony Pavlov
2013-12-04 20:22 ` Antony Pavlov
2013-12-04 20:29 ` Peter Maydell
2013-12-04 21:20 ` Antony Pavlov
2013-12-04 21:34 ` Peter Maydell
2013-12-05 0:20 ` Peter Crosthwaite
2013-12-05 8:02 ` Peter Maydell
2013-12-05 0:25 ` Peter Crosthwaite
2013-12-05 7:59 ` Peter Maydell
2013-12-07 0:55 ` [Qemu-devel] [RFC 0/2] ARM: make possible to use high vectors for reset exception Antony Pavlov
2013-12-07 0:55 ` [Qemu-devel] [RFC 1/2] ARM: cpu: add "hivecs" property (high vectors on reset) Antony Pavlov
2013-12-07 1:00 ` Peter Crosthwaite
2013-12-07 20:44 ` Antony Pavlov
2013-12-07 22:14 ` Peter Crosthwaite
2013-12-07 1:14 ` Peter Maydell
2013-12-07 0:55 ` [Qemu-devel] [RFC 2/2] ARM: arm_cpu_reset: make possible to use high vectors for reset_exc Antony Pavlov
2013-12-07 1:08 ` Peter Crosthwaite
2013-12-07 20:49 ` Antony Pavlov
2013-12-07 21:03 ` Peter Maydell
2013-09-07 7:04 ` Antony Pavlov [this message]
2013-10-17 17:51 ` [Qemu-devel] [RFC v5 3/5] hw/arm/digic: add timer support Peter Maydell
2013-09-07 7:04 ` [Qemu-devel] [RFC v5 4/5] hw/arm/digic: add UART support Antony Pavlov
2013-10-17 17:54 ` Peter Maydell
2013-10-22 10:48 ` Antony Pavlov
2013-09-07 7:04 ` [Qemu-devel] [RFC v5 5/5] hw/arm/digic: add NOR ROM support Antony Pavlov
2013-10-17 18:00 ` Peter Maydell
2013-09-13 14:37 ` [Qemu-devel] [RFC v5 0/5] hw/arm: add initial support for Canon DIGIC SoC Antony Pavlov
2013-09-20 9:01 ` [Qemu-devel] [RFC v5 0/5] hw/arm: add initial support for Canon DIGIC SoC: ping-ping Antony Pavlov
2013-09-28 10:41 ` [Qemu-devel] [RFC v5 0/5] hw/arm: add initial support for Canon DIGIC SoC: ping-ping-ping Antony Pavlov
2013-09-28 10:50 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1378537467-13471-4-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=afaerber@suse.de \
--cc=broscutamaker@gmail.com \
--cc=condellog@gmail.com \
--cc=georg.hofstetter@lx-networking.de \
--cc=paul@codesourcery.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).