From: Gabriel Costa <gabriel291075@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, f4bug@amsat.org,
Gabriel Augusto Costa <gabriel291075@gmail.com>
Subject: [Qemu-devel] [PATCH v5 1/5]arm: kinetis_k64_mcg
Date: Thu, 26 Oct 2017 06:34:08 -0400 [thread overview]
Message-ID: <1509014053-28134-2-git-send-email-costa@advantech.ca> (raw)
In-Reply-To: <1509014053-28134-1-git-send-email-costa@advantech.ca>
From: Gabriel Augusto Costa <gabriel291075@gmail.com>
This Patch include kinetis_k64_mcg.c and .h
mcg means Multipurpose Clock Generator (MCG)
More information about this peripheral can be found at:
pag 579, K64P144M120SF5RM.pdf.
Signed-off-by: Gabriel Augusto Costa <gabriel291075@gmail.com>
---
hw/misc/kinetis_k64_mcg.c | 208 ++++++++++++++++++++++++++++++++++++++
include/hw/misc/kinetis_k64_mcg.h | 43 ++++++++
2 files changed, 251 insertions(+)
create mode 100644 hw/misc/kinetis_k64_mcg.c
create mode 100644 include/hw/misc/kinetis_k64_mcg.h
diff --git a/hw/misc/kinetis_k64_mcg.c b/hw/misc/kinetis_k64_mcg.c
new file mode 100644
index 0000000..654f96b
--- /dev/null
+++ b/hw/misc/kinetis_k64_mcg.c
@@ -0,0 +1,208 @@
+/*
+ * Kinetis K64 peripheral microcontroller emulation.
+ *
+ * Copyright (c) 2017 Advantech Wireless
+ * Written by Gabriel Costa <gabriel291075@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or
+ * (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "qemu/log.h"
+#include "hw/misc/kinetis_k64_mcg.h"
+
+static const VMStateDescription vmstate_kinetis_k64_mcg = {
+ .name = TYPE_KINETIS_K64_MCG,
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT8(C1, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C2, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C3, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C4, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C5, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C6, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(S, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(SC, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(ATCVH, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(ATCVL, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C7, kinetis_k64_mcg_state),
+ VMSTATE_UINT8(C8, kinetis_k64_mcg_state),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static void kinetis_k64_mcg_reset(DeviceState *dev)
+{
+ kinetis_k64_mcg_state *s = KINETIS_K64_MCG(dev);
+
+ s->C1 = 0x04;
+ s->C2 = 0x80;
+ s->C3 = 0x00;
+ s->C4 = 0x00;
+ s->C5 = 0x00;
+ s->C6 = 0x00;
+ s->S = 0x10;
+ s->SC = 0x02;
+ s->ATCVH = 0x00;
+ s->ATCVL = 0x00;
+ s->C7 = 0x00;
+ s->C8 = 0x80;
+}
+
+static void kinetis_k64_mcg_write(void *opaque, hwaddr offset, uint64_t value,
+ unsigned size)
+{
+ kinetis_k64_mcg_state *s = (kinetis_k64_mcg_state *)opaque;
+
+ value &= 0xFF;
+
+ switch (offset) {
+ case 0x00:
+ if (value & 1 << 2) { /*IREFS*/
+ s->S = 0;
+ s->S |= 1 << 3; /*10 Enconding 2 - External ref clk is selected*/
+ }
+ if ((s->C1 & 0x80) && (value >> 6 == 0)) {
+ s->S |= 1 << 2; /*11 Enconding 3 - Output of the PLL is selected*/
+ }
+ s->C1 = value;
+ break;
+ case 0x01:
+ s->C2 = value;
+ break;
+ case 0x02:
+ s->C3 = value;
+ break;
+ case 0x03:
+ s->C4 = value;
+ break;
+ case 0x04:
+ s->C5 = value;
+ if (s->C5 & 1 << 6) { /*PLLCLKEN0*/
+ s->S |= 1 << 6; /*LOCK0*/
+ }
+ break;
+ case 0x05:
+ s->C6 = value;
+ if (s->C6 & 1 << 6) { /*PLLS*/
+ s->S |= 1 << 5; /*PLLST*/
+ }
+ break;
+ case 0x06:
+ s->S = value;
+ break;
+ case 0x08:
+ s->SC = value;
+ break;
+ case 0x0A:
+ s->ATCVH = value;
+ break;
+ case 0x0B:
+ s->ATCVL = value;
+ break;
+ case 0x0C:
+ s->C7 = value;
+ break;
+ case 0x0D:
+ s->C8 = value;
+ break;
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "kinetis_k64_mcg: write at bad offset 0x%x\n", (int)offset);
+ }
+}
+
+static uint64_t kinetis_k64_mcg_read(void *opaque, hwaddr offset, unsigned size)
+{
+ kinetis_k64_mcg_state *s = (kinetis_k64_mcg_state *)opaque;
+ uint8_t value;
+
+ switch (offset) {
+ case 0x00:
+ value = s->C1;
+ break;
+ case 0x01:
+ value = s->C2;
+ break;
+ case 0x02:
+ value = s->C3;
+ break;
+ case 0x03:
+ value = s->C4;
+ break;
+ case 0x04:
+ value = s->C5;
+ break;
+ case 0x05:
+ value = s->C6;
+ break;
+ case 0x06:
+ value = s->S;
+ break;
+ case 0x08:
+ value = s->SC;
+ break;
+ case 0x0A:
+ value = s->ATCVH;
+ break;
+ case 0x0B:
+ value = s->ATCVL;
+ break;
+ case 0x0C:
+ value = s->C7;
+ break;
+ case 0x0D:
+ value = s->C8;
+ break;
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "kinetis_k64_mcg: read at bad offset 0x%x\n", (int)offset);
+ return 0;
+ }
+ return value;
+}
+
+static const MemoryRegionOps kinetis_k64_mcg_ops = {
+ .read = kinetis_k64_mcg_read,
+ .write = kinetis_k64_mcg_write,
+ .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static void kinetis_k64_mcg_init(Object *obj)
+{
+ kinetis_k64_mcg_state *s = KINETIS_K64_MCG(obj);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+
+ memory_region_init_io(&s->iomem, obj, &kinetis_k64_mcg_ops, s,
+ TYPE_KINETIS_K64_MCG, 0x1000);
+ sysbus_init_mmio(sbd, &s->iomem);
+ sysbus_init_irq(sbd, &s->irq);
+}
+
+static void kinetis_k64_mcg_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->vmsd = &vmstate_kinetis_k64_mcg;
+ dc->reset = kinetis_k64_mcg_reset;
+ dc->desc = "Kinetis K64 series MCG";
+}
+
+static const TypeInfo kinetis_k64_mcg_info = {
+ .name = TYPE_KINETIS_K64_MCG,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(kinetis_k64_mcg_state),
+ .instance_init = kinetis_k64_mcg_init,
+ .class_init = kinetis_k64_mcg_class_init,
+};
+
+static void kinetis_k64_mcg_register_types(void)
+{
+ type_register_static(&kinetis_k64_mcg_info);
+}
+
+type_init(kinetis_k64_mcg_register_types)
diff --git a/include/hw/misc/kinetis_k64_mcg.h b/include/hw/misc/kinetis_k64_mcg.h
new file mode 100644
index 0000000..3f105c5
--- /dev/null
+++ b/include/hw/misc/kinetis_k64_mcg.h
@@ -0,0 +1,43 @@
+/*
+ * Kinetis K64 peripheral microcontroller emulation.
+ *
+ * Copyright (c) 2017 Advantech Wireless
+ * Written by Gabriel Costa <gabriel291075@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or
+ * (at your option) any later version.
+ */
+
+#ifndef KINETIS_MCG_H
+#define KINETIS_MCG_H
+
+#include "hw/sysbus.h"
+#include "hw/hw.h"
+
+#define TYPE_KINETIS_K64_MCG "kinetis_k64_mcg"
+#define KINETIS_K64_MCG(obj) \
+ OBJECT_CHECK(kinetis_k64_mcg_state, (obj), TYPE_KINETIS_K64_MCG)
+
+typedef struct {
+ SysBusDevice parent_obj;
+
+ MemoryRegion iomem;
+
+ uint8_t C1;
+ uint8_t C2;
+ uint8_t C3;
+ uint8_t C4;
+ uint8_t C5;
+ uint8_t C6;
+ uint8_t S;
+ uint8_t SC;
+ uint8_t ATCVH;
+ uint8_t ATCVL;
+ uint8_t C7;
+ uint8_t C8;
+
+ qemu_irq irq;
+} kinetis_k64_mcg_state;
+
+#endif
--
2.1.4
next prev parent reply other threads:[~2017-10-26 14:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-26 10:34 [Qemu-devel] [PATCH v5 0/5]arm: kinetis_k64 Gabriel Costa
2017-10-26 10:34 ` Gabriel Costa [this message]
2017-10-27 13:13 ` [Qemu-devel] [PATCH v5 1/5]arm: kinetis_k64_mcg KONRAD Frederic
2017-10-26 10:34 ` [Qemu-devel] [PATCH v5 3/5]arm: kinetis_k64_system Gabriel Costa
2017-10-27 13:20 ` KONRAD Frederic
2017-10-27 14:39 ` Gabriel Costa
2017-10-26 10:34 ` [Qemu-devel] [PATCH v5 4/5]arm: kinetis_k64_uart Gabriel Costa
2017-10-27 13:26 ` KONRAD Frederic
2017-10-27 15:18 ` Gabriel Costa
2017-10-26 10:34 ` [Qemu-devel] [PATCH v5 5/5]arm: mk64fn1m0 Gabriel Costa
2017-10-26 10:34 ` [Qemu-devel] [PATCH v6]arm: Makefiles to kinetis k64 platform Gabriel Costa
2017-10-26 15:04 ` no-reply
2017-10-26 15:27 ` no-reply
2017-10-27 13:07 ` KONRAD Frederic
2017-10-27 14:25 ` Gabriel Costa
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=1509014053-28134-2-git-send-email-costa@advantech.ca \
--to=gabriel291075@gmail.com \
--cc=f4bug@amsat.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.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).