[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH rc5 21/32] hw/misc: avr: Add limited support for power reduction
From: |
Aleksandar Markovic |
Subject: |
[PATCH rc5 21/32] hw/misc: avr: Add limited support for power reduction device |
Date: |
Fri, 7 Feb 2020 02:57:49 +0100 |
From: Michael Rolnik <address@hidden>
This is a simple device of just one register, and whenever this
register is written to it calls qemu_set_irq function for each
of 8 bits/IRQs. It is used to implement AVR Power Reduction.
[AM: Remove word 'Atmel' from filenames and all elements of code]
Suggested-by: Aleksandar Markovic <address@hidden>
Signed-off-by: Michael Rolnik <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
[rth: Squash include fix and file rename from f4bug]
Signed-off-by: Richard Henderson <address@hidden>
Signed-off-by: Aleksandar Markovic <address@hidden>
Reviewed-by: Alex Bennée <address@hidden>
---
include/hw/misc/avr_power.h | 46 ++++++++++++++++++
hw/misc/avr_power.c | 113 ++++++++++++++++++++++++++++++++++++++++++++
MAINTAINERS | 2 +
hw/misc/Kconfig | 3 ++
hw/misc/Makefile.objs | 2 +
hw/misc/trace-events | 4 ++
6 files changed, 170 insertions(+)
create mode 100644 include/hw/misc/avr_power.h
create mode 100644 hw/misc/avr_power.c
diff --git a/include/hw/misc/avr_power.h b/include/hw/misc/avr_power.h
new file mode 100644
index 0000000..434ac23
--- /dev/null
+++ b/include/hw/misc/avr_power.h
@@ -0,0 +1,46 @@
+/*
+ * 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_AVR_POWER_H
+#define HW_MISC_AVR_POWER_H
+
+#include "hw/sysbus.h"
+#include "hw/hw.h"
+
+
+#define TYPE_AVR_MASK "avr-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_AVR_POWER_H */
diff --git a/hw/misc/avr_power.c b/hw/misc/avr_power.c
new file mode 100644
index 0000000..65ff7c4
--- /dev/null
+++ b/hw/misc/avr_power.c
@@ -0,0 +1,113 @@
+/*
+ * 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/avr_power.h"
+#include "qemu/log.h"
+#include "hw/qdev-properties.h"
+#include "hw/irq.h"
+#include "trace.h"
+
+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;
+
+ trace_avr_power_read(s->val);
+
+ 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;
+
+ trace_avr_power_write(val8);
+ 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/MAINTAINERS b/MAINTAINERS
index 576038b..9ba3b49 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -916,6 +916,8 @@ F: include/hw/char/avr_usart.h
F: hw/char/avr_usart.c
F: include/hw/timer/avr_timer16.h
F: hw/timer/avr_timer16.c
+F: include/hw/misc/avr_power.h
+F: hw/misc/avr_power.c
CRIS Machines
-------------
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index bdd77d8..92c397c 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -131,4 +131,7 @@ config MAC_VIA
select MOS6522
select ADB
+config AVR_POWER
+ bool
+
source macio/Kconfig
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index da993f4..df8e457 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_AVR_POWER) += avr_power.o
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index 7f0f5df..f716881 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -179,3 +179,7 @@ via1_rtc_cmd_pram_read(int addr, int value) "addr=%u
value=0x%02x"
via1_rtc_cmd_pram_write(int addr, int value) "addr=%u value=0x%02x"
via1_rtc_cmd_pram_sect_read(int sector, int offset, int addr, int value)
"sector=%u offset=%u addr=%d value=0x%02x"
via1_rtc_cmd_pram_sect_write(int sector, int offset, int addr, int value)
"sector=%u offset=%u addr=%d value=0x%02x"
+
+# avr_power.c
+avr_power_read(uint8_t value) "power_reduc read value:%u"
+avr_power_write(uint8_t value) "power_reduc write value:%u"
--
2.7.4
- [PATCH rc5 27/32] tests/machine-none: Add AVR support, (continued)
- [PATCH rc5 27/32] tests/machine-none: Add AVR support, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 23/32] hw/avr: Add support for loading ELF/raw binaries, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 25/32] hw/avr: Add limited support for some Arduino boards, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 22/32] target/avr: Register AVR support with the rest of QEMU, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 28/32] tests/boot-serial: Test some Arduino boards (AVR based), Aleksandar Markovic, 2020/02/06
- [PATCH rc5 32/32] target/avr: Add section into QEMU documentation, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 29/32] tests/acceptance: Test the Arduino MEGA2560 board, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 10/32] target/avr: Add instruction translation - Register definitions, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 31/32] target/avr: Simplify sections in MAINTAINERS file, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 09/32] target/avr: Add instruction helpers, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 21/32] hw/misc: avr: Add limited support for power reduction device,
Aleksandar Markovic <=
- [PATCH rc5 11/32] target/avr: Add instruction translation - Arithmetic and Logic Instructions, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 26/32] target/avr: Update build system, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 19/32] hw/char: avr: Add limited support for USART peripheral, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 24/32] hw/avr: Add some ATmega microcontrollers, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 13/32] target/avr: Add instruction translation - Data Transfer Instructions, Aleksandar Markovic, 2020/02/06
- [PATCH rc5 20/32] hw/timer: avr: Add limited support for 16-bit timer peripheral, Aleksandar Markovic, 2020/02/06