[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/5] hw/char/avr_usart: Use the Clock API
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 4/5] hw/char/avr_usart: Use the Clock API |
Date: |
Fri, 14 Aug 2020 18:39:23 +0200 |
Expose the 'xck' clock source. Connect the MCU I/O clock to it.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/char/avr_usart.h | 2 ++
hw/avr/atmega.c | 1 +
hw/char/avr_usart.c | 3 +++
3 files changed, 6 insertions(+)
diff --git a/include/hw/char/avr_usart.h b/include/hw/char/avr_usart.h
index 46d6c76e50..13cfd5ea07 100644
--- a/include/hw/char/avr_usart.h
+++ b/include/hw/char/avr_usart.h
@@ -25,6 +25,7 @@
#include "hw/sysbus.h"
#include "chardev/char-fe.h"
#include "hw/hw.h"
+#include "hw/clock.h"
#define TYPE_AVR_USART "avr-usart"
#define AVR_USART(obj) \
@@ -51,6 +52,7 @@ typedef struct {
/* Baud Rate Registers (low/high byte) */
uint8_t brrh;
uint8_t brrl;
+ Clock *clkin;
/* Receive Complete */
qemu_irq rxc_irq;
diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
index f14b558140..b6e86a4531 100644
--- a/hw/avr/atmega.c
+++ b/hw/avr/atmega.c
@@ -302,6 +302,7 @@ static void atmega_realize(DeviceState *dev, Error **errp)
object_initialize_child(OBJECT(dev), devname, &s->usart[i],
TYPE_AVR_USART);
qdev_prop_set_chr(DEVICE(&s->usart[i]), "chardev", serial_hd(i));
+ qdev_connect_clock_in(DEVICE(&s->usart[i]), "xck", s->ioclk);
sbd = SYS_BUS_DEVICE(&s->usart[i]);
sysbus_realize(sbd, &error_abort);
sysbus_mmio_map(sbd, 0, OFFSET_DATA + mc->dev[USART(i)].addr);
diff --git a/hw/char/avr_usart.c b/hw/char/avr_usart.c
index fd0b488ef9..4a43492082 100644
--- a/hw/char/avr_usart.c
+++ b/hw/char/avr_usart.c
@@ -23,6 +23,7 @@
#include "hw/char/avr_usart.h"
#include "qemu/log.h"
#include "hw/irq.h"
+#include "hw/qdev-clock.h"
#include "hw/qdev-properties.h"
/* Offsets of registers. */
@@ -307,12 +308,14 @@ static void avr_usart_pr(void *opaque, int irq, int level)
static void avr_usart_init(Object *obj)
{
AVRUsartState *s = AVR_USART(obj);
+
sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->rxc_irq);
sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->dre_irq);
sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->txc_irq);
memory_region_init_io(&s->mmio, obj, &avr_usart_ops, s, TYPE_AVR_USART, 7);
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
qdev_init_gpio_in(DEVICE(s), avr_usart_pr, 1);
+ s->clkin = qdev_init_clock_in(DEVICE(obj), "xck", NULL, s);
s->enabled = true;
}
--
2.21.3
- [PATCH 0/5] hw/avr: Start using the Clock API, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 1/5] hw/avr/atmega: Introduce the I/O clock, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 2/5] hw/timer/avr_timer16: Use the Clock API, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 3/5] hw/char/avr_usart: Restrict register definitions to source, Philippe Mathieu-Daudé, 2020/08/14
- [PATCH 4/5] hw/char/avr_usart: Use the Clock API,
Philippe Mathieu-Daudé <=
- [PATCH 5/5] hw/char/avr_usart: Trace baudrate changes, Philippe Mathieu-Daudé, 2020/08/14
- Re: [PATCH 0/5] hw/avr: Start using the Clock API, Michael Rolnik, 2020/08/26