qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, me@xcancerberox.com.ar, S.E.Harris@kent.ac.uk,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	dovgaluk@ispras.ru, imammedo@redhat.com, mrolnik@gmail.com,
	aleksandar.m.mail@gmail.com
Subject: [PATCH rc1 13/24] hw/misc: Add Atmel power device
Date: Wed, 22 Jan 2020 14:02:56 -1000	[thread overview]
Message-ID: <20200123000307.11541-14-richard.henderson@linaro.org> (raw)
In-Reply-To: <20200123000307.11541-1-richard.henderson@linaro.org>

From: Michael Rolnik <mrolnik@gmail.com>

This is a simple device of just one register, whenver this register is
written it calls qemu_set_irq function for each of 8 bits/IRQs..
It is used to implement AVR Power Reduction

Signed-off-by: Michael Rolnik <mrolnik@gmail.com>
Message-Id: <20200118191416.19934-14-mrolnik@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
[rth: Squash include fix and file rename from f4bug, which was:]
Suggested-by: Aleksandar Markovic <aleksandar.m.mail@gmail.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/hw/misc/atmel_power.h |  46 ++++++++++++++
 hw/misc/atmel_power.c         | 112 ++++++++++++++++++++++++++++++++++
 hw/misc/Kconfig               |   3 +
 hw/misc/Makefile.objs         |   2 +
 4 files changed, 163 insertions(+)
 create mode 100644 include/hw/misc/atmel_power.h
 create mode 100644 hw/misc/atmel_power.c

diff --git a/include/hw/misc/atmel_power.h b/include/hw/misc/atmel_power.h
new file mode 100644
index 0000000000..5366e9693f
--- /dev/null
+++ b/include/hw/misc/atmel_power.h
@@ -0,0 +1,46 @@
+/*
+ * Atmel AVR Power Reduction Management
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef HW_MISC_ATMEL_POWER_H
+#define HW_MISC_ATMEL_POWER_H
+
+#include "hw/sysbus.h"
+#include "hw/hw.h"
+
+
+#define TYPE_AVR_MASK "atmel-power"
+#define AVR_MASK(obj) OBJECT_CHECK(AVRMaskState, (obj), TYPE_AVR_MASK)
+
+typedef struct {
+    /* <private> */
+    SysBusDevice parent_obj;
+
+    /* <public> */
+    MemoryRegion iomem;
+
+    uint8_t val;
+    qemu_irq irq[8];
+} AVRMaskState;
+
+#endif /* HW_MISC_ATMEL_POWER_H */
diff --git a/hw/misc/atmel_power.c b/hw/misc/atmel_power.c
new file mode 100644
index 0000000000..adab729f66
--- /dev/null
+++ b/hw/misc/atmel_power.c
@@ -0,0 +1,112 @@
+/*
+ * Atmel AVR Power Reduction Management
+ *
+ * Copyright (c) 2019 Michael Rolnik
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/misc/atmel_power.h"
+#include "qemu/log.h"
+#include "hw/qdev-properties.h"
+#include "hw/irq.h"
+
+#define DB_PRINT(fmt, args...) /* Nothing */
+/*#define DB_PRINT(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)*/
+
+static void avr_mask_reset(DeviceState *dev)
+{
+    AVRMaskState *s = AVR_MASK(dev);
+
+    s->val = 0x00;
+
+    for (int i = 0; i < 8; i++) {
+        qemu_set_irq(s->irq[i], 0);
+    }
+}
+
+static uint64_t avr_mask_read(void *opaque, hwaddr offset, unsigned size)
+{
+    assert(size == 1);
+    assert(offset == 0);
+    AVRMaskState *s = opaque;
+
+    return (uint64_t)s->val;
+}
+
+static void avr_mask_write(void *opaque, hwaddr offset,
+                              uint64_t val64, unsigned size)
+{
+    assert(size == 1);
+    assert(offset == 0);
+    AVRMaskState *s = opaque;
+    uint8_t val8 = val64;
+
+    DB_PRINT("write %d to offset %d", val8, (uint8_t)offset);
+
+    s->val = val8;
+    for (int i = 0; i < 8; i++) {
+        qemu_set_irq(s->irq[i], (val8 & (1 << i)) != 0);
+    }
+}
+
+static const MemoryRegionOps avr_mask_ops = {
+    .read = avr_mask_read,
+    .write = avr_mask_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {.max_access_size = 1}
+};
+
+static void avr_mask_init(Object *dev)
+{
+    AVRMaskState *s = AVR_MASK(dev);
+    SysBusDevice *busdev = SYS_BUS_DEVICE(dev);
+
+    memory_region_init_io(&s->iomem, dev, &avr_mask_ops, s, TYPE_AVR_MASK,
+            0x01);
+    sysbus_init_mmio(busdev, &s->iomem);
+
+    for (int i = 0; i < 8; i++) {
+        sysbus_init_irq(busdev, &s->irq[i]);
+    }
+    s->val = 0x00;
+}
+
+static void avr_mask_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->reset = avr_mask_reset;
+}
+
+static const TypeInfo avr_mask_info = {
+    .name          = TYPE_AVR_MASK,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(AVRMaskState),
+    .class_init    = avr_mask_class_init,
+    .instance_init = avr_mask_init,
+};
+
+static void avr_mask_register_types(void)
+{
+    type_register_static(&avr_mask_info);
+}
+
+type_init(avr_mask_register_types)
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index bdd77d8020..3a3c32e1b0 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -131,4 +131,7 @@ config MAC_VIA
     select MOS6522
     select ADB
 
+config ATMEL_POWER
+    bool
+
 source macio/Kconfig
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index da993f45b7..e605964f4b 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -85,3 +85,5 @@ common-obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o
 obj-$(CONFIG_MAC_VIA) += mac_via.o
 
 common-obj-$(CONFIG_GRLIB) += grlib_ahb_apb_pnp.o
+
+obj-$(CONFIG_ATMEL_POWER) += atmel_power.o
-- 
2.20.1



  parent reply	other threads:[~2020-01-23  0:19 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23  0:02 [PATCH rc1 00/24] target/avr merger Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 01/24] target/avr: Add outward facing interfaces and core CPU logic Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 02/24] target/avr: Add instruction helpers Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 03/24] target/avr: Add instruction translation - Registers definition Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 04/24] target/avr: Add instruction translation - Arithmetic and Logic Instructions Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 05/24] target/avr: Add instruction translation - Branch Instructions Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 06/24] target/avr: Add instruction translation - Data Transfer Instructions Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 07/24] target/avr: Add instruction translation - Bit and Bit-test Instructions Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 08/24] target/avr: Add instruction translation - MCU Control Instructions Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 09/24] target/avr: Add instruction translation - CPU main translation function Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 10/24] target/avr: Add instruction disassembly function Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 11/24] hw/char: Add limited support for Atmel USART peripheral Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 12/24] hw/timer: Add limited support for Atmel 16 bit timer peripheral Richard Henderson
2020-01-23  4:49   ` Thomas Huth
2020-01-23 17:29     ` Philippe Mathieu-Daudé
2020-01-23  0:02 ` Richard Henderson [this message]
2020-01-23  0:02 ` [PATCH rc1 14/24] target/avr: Add section about AVR into QEMU documentation Richard Henderson
2020-01-23  4:56   ` Thomas Huth
2020-01-24  0:33     ` Philippe Mathieu-Daudé
2020-01-23  0:02 ` [PATCH rc1 15/24] target/avr: Register AVR support with the rest of QEMU Richard Henderson
2020-01-23  0:02 ` [PATCH rc1 16/24] target/avr: Add machine none test Richard Henderson
2020-01-23  5:02   ` Thomas Huth
2020-01-23  0:03 ` [PATCH rc1 17/24] target/avr: Update MAINTAINERS file Richard Henderson
2020-01-23  0:03 ` [PATCH rc1 18/24] hw/avr: Introduce ATMEL_ATMEGA_MCU config Richard Henderson
2020-01-23  5:04   ` Thomas Huth
2020-01-23 17:27     ` Philippe Mathieu-Daudé
2020-01-23  0:03 ` [PATCH rc1 19/24] hw/avr: Add some ATmega microcontrollers Richard Henderson
2020-01-23 23:40   ` Philippe Mathieu-Daudé
2020-01-23  0:03 ` [PATCH rc1 20/24] hw/avr: Add some Arduino boards Richard Henderson
2020-01-23  0:03 ` [PATCH rc1 21/24] target/avr: Update build system Richard Henderson
2020-01-23  0:03 ` [PATCH rc1 22/24] tests/boot-serial-test: Test some Arduino boards (AVR based) Richard Henderson
2020-01-23  0:03 ` [PATCH rc1 23/24] tests/acceptance: Test the Arduino MEGA2560 board Richard Henderson
2020-01-23  0:03 ` [PATCH rc1 24/24] .travis.yml: Run the AVR acceptance tests Richard Henderson
2020-01-23  5:12 ` [PATCH rc1 00/24] target/avr merger Thomas Huth
2020-01-23 11:56   ` Michael Rolnik
2020-01-23 17:36     ` Thomas Huth

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=20200123000307.11541-14-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=S.E.Harris@kent.ac.uk \
    --cc=aleksandar.m.mail@gmail.com \
    --cc=dovgaluk@ispras.ru \
    --cc=f4bug@amsat.org \
    --cc=imammedo@redhat.com \
    --cc=me@xcancerberox.com.ar \
    --cc=mrolnik@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /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).