[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-2.9 30/30] wdt: aspeed: use scu to get clock fre
From: |
Cédric Le Goater |
Subject: |
[Qemu-devel] [PATCH for-2.9 30/30] wdt: aspeed: use scu to get clock freq |
Date: |
Tue, 29 Nov 2016 18:26:48 +0100 |
Add a link to the object model and a helper routine to retrieve the
value instead of using a constant value.
Signed-off-by: Cédric Le Goater <address@hidden>
Reviewed-by: Joel Stanley <address@hidden>
---
hw/arm/aspeed_soc.c | 2 ++
hw/watchdog/wdt_aspeed.c | 19 +++++++++++++++----
include/hw/watchdog/wdt_aspeed.h | 2 ++
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
index 6df76382f007..712ae9d6c54d 100644
--- a/hw/arm/aspeed_soc.c
+++ b/hw/arm/aspeed_soc.c
@@ -175,6 +175,8 @@ static void aspeed_soc_init(Object *obj)
object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ASPEED_WDT);
object_property_add_child(obj, "wdt", OBJECT(&s->wdt), NULL);
qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default());
+ object_property_add_const_link(OBJECT(&s->wdt), "scu", OBJECT(&s->scu),
+ NULL);
}
static void aspeed_soc_realize(DeviceState *dev, Error **errp)
diff --git a/hw/watchdog/wdt_aspeed.c b/hw/watchdog/wdt_aspeed.c
index cdba3983b7af..01266fb1b76b 100644
--- a/hw/watchdog/wdt_aspeed.c
+++ b/hw/watchdog/wdt_aspeed.c
@@ -7,10 +7,12 @@
#include "qemu/osdep.h"
#include "qemu/log.h"
+#include "qapi/error.h"
#include "sysemu/watchdog.h"
#include "hw/sysbus.h"
#include "qemu/timer.h"
#include "hw/watchdog/wdt_aspeed.h"
+#include "hw/misc/aspeed_scu.h"
#define WDT_IO_REGION_SIZE 0x20
@@ -56,8 +58,6 @@ static uint64_t aspeed_wdt_read(void *opaque, hwaddr offset,
unsigned size)
}
-#define PCLK_HZ 24000000
-
static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
unsigned size)
{
@@ -82,7 +82,7 @@ static void aspeed_wdt_write(void *opaque, hwaddr offset,
uint64_t data,
if (pclk) {
reload = muldiv64(s->reg_reload_value, NANOSECONDS_PER_SECOND,
- PCLK_HZ) ;
+ s->pclk_freq);
} else {
reload = s->reg_reload_value * 1000;
}
@@ -99,7 +99,7 @@ static void aspeed_wdt_write(void *opaque, hwaddr offset,
uint64_t data,
if (pclk) {
reload = muldiv64(s->reg_reload_value, NANOSECONDS_PER_SECOND,
- PCLK_HZ);
+ s->pclk_freq);
} else {
reload = s->reg_reload_value * 1000;
}
@@ -177,10 +177,21 @@ static void aspeed_wdt_realize(DeviceState *dev, Error
**errp)
{
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
AspeedWDTState *s = ASPEED_WDT(dev);
+ Object *obj;
+ Error *err = NULL;
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, aspeed_wdt_timer_expired,
dev);
+ obj = object_property_get_link(OBJECT(dev), "scu", &err);
+ if (!obj) {
+ error_setg(errp, "%s: required link 'scu' not found: %s",
+ __func__, error_get_pretty(err));
+ return;
+ }
+
+ s->pclk_freq = aspeed_scu_get_clk(ASPEED_SCU(obj));
+
memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
TYPE_ASPEED_WDT, WDT_IO_REGION_SIZE);
sysbus_init_mmio(sbd, &s->iomem);
diff --git a/include/hw/watchdog/wdt_aspeed.h b/include/hw/watchdog/wdt_aspeed.h
index dbf45ae968db..0483335ecee5 100644
--- a/include/hw/watchdog/wdt_aspeed.h
+++ b/include/hw/watchdog/wdt_aspeed.h
@@ -36,6 +36,8 @@ typedef struct AspeedWDTState {
uint32_t reg_reload_value;
uint32_t reg_restart;
uint32_t reg_ctrl;
+
+ uint32_t pclk_freq;
} AspeedWDTState;
#endif /* ASPEED_WDT_H */
--
2.7.4
- [Qemu-devel] [PATCH for-2.9 23/30] aspeed/smc: adjust the size of the register region, (continued)
- [Qemu-devel] [PATCH for-2.9 23/30] aspeed/smc: adjust the size of the register region, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 24/30] aspeed: use first SPI flash as a boot ROM, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 25/30] block: add a model option for MTD devices, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 26/30] aspeed/smc: use flash model option, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 27/30] wdt: Add Aspeed watchdog device model, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 28/30] aspeed: add a watchdog controller, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 29/30] aspeed/scu: add a aspeed_scu_get_clk() helper, Cédric Le Goater, 2016/11/29
- [Qemu-devel] [PATCH for-2.9 30/30] wdt: aspeed: use scu to get clock freq,
Cédric Le Goater <=
- [Qemu-devel] [PATCH for-2.9 29/30] aspeed/scu: add a aspeed_scu_get_clk() helper, Cédric Le Goater, 2016/11/29