diff mbox series

[14/20] hw/rx/rx62n: RX62N Add MTU module

Message ID 20200827123859.81793-15-ysato@users.sourceforge.jp
State New
Headers show
Series RX target update | expand

Commit Message

Yoshinori Sato Aug. 27, 2020, 12:38 p.m. UTC
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
 include/hw/rx/rx62n.h |  3 +++
 hw/rx/rx62n.c         | 28 ++++++++++++++++++++++++++++
 hw/rx/Kconfig         |  1 +
 3 files changed, 32 insertions(+)

Comments

Philippe Mathieu-Daudé Sept. 8, 2020, 9:12 p.m. UTC | #1
On 8/27/20 2:38 PM, Yoshinori Sato wrote:
> Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
> ---
>  include/hw/rx/rx62n.h |  3 +++
>  hw/rx/rx62n.c         | 28 ++++++++++++++++++++++++++++
>  hw/rx/Kconfig         |  1 +
>  3 files changed, 32 insertions(+)
> 
> diff --git a/include/hw/rx/rx62n.h b/include/hw/rx/rx62n.h
> index f463148799..170c8cb6fc 100644
> --- a/include/hw/rx/rx62n.h
> +++ b/include/hw/rx/rx62n.h
> @@ -28,6 +28,7 @@
>  #include "hw/intc/rx_icu.h"
>  #include "hw/timer/renesas_tmr8.h"
>  #include "hw/timer/renesas_timer.h"
> +#include "hw/timer/renesas_mtu.h"
>  #include "hw/char/renesas_sci.h"
>  #include "hw/rx/rx62n-cpg.h"
>  #include "qemu/units.h"
> @@ -45,6 +46,7 @@
>  #define RX62N_NR_TMR    2
>  #define RX62N_NR_CMT    2
>  #define RX62N_NR_SCI    6
> +#define RX62N_NR_MTU    2
>  
>  typedef struct RX62NClass {
>      /*< private >*/
> @@ -70,6 +72,7 @@ typedef struct RX62NState {
>      RXICUState icu;
>      RenesasTMR8State tmr[RX62N_NR_TMR];
>      RenesasCMTState cmt[RX62N_NR_CMT];
> +    RenesasMTU2State mtu[RX62N_NR_MTU];
>      RSCIAState sci[RX62N_NR_SCI];
>      RX62NCPGState cpg;
>  
> diff --git a/hw/rx/rx62n.c b/hw/rx/rx62n.c
> index f61383a4c2..344be846bc 100644
> --- a/hw/rx/rx62n.c
> +++ b/hw/rx/rx62n.c
> @@ -46,6 +46,7 @@
>  #define RX62N_ICU_BASE  0x00087000
>  #define RX62N_TMR_BASE  0x00088200
>  #define RX62N_CMT_BASE  0x00088000
> +#define RX62N_MTU_BASE  0x00088600
>  #define RX62N_SCI_BASE  0x00088240
>  #define RX62N_CPG_BASE  0x00080010
>  
> @@ -55,6 +56,7 @@
>   */
>  #define RX62N_TMR_IRQ   174
>  #define RX62N_CMT_IRQ   28
> +#define RX62N_MTU_IRQ   114
>  #define RX62N_SCI_IRQ   214
>  
>  /*
> @@ -187,6 +189,30 @@ static void register_cmt(RX62NState *s, int unit)
>                            qdev_get_clock_out(DEVICE(&s->cpg), ckname));
>  }
>  
> +static void register_mtu(RX62NState *s, int unit)
> +{
> +    SysBusDevice *mtu;
> +    int i, irqbase;
> +    char ckname[16];
> +
> +    object_initialize_child(OBJECT(s), "mtu[*]", &s->mtu[unit],
> +                            TYPE_RENESAS_MTU2);
> +    mtu = SYS_BUS_DEVICE(&s->mtu[unit]);
> +    qdev_prop_set_uint32(DEVICE(mtu), "unit", unit);
> +
> +    sysbus_mmio_map(mtu, 0, RX62N_MTU_BASE + 0x100 + unit * 0x400);
> +    sysbus_mmio_map(mtu, 1, RX62N_MTU_BASE + unit * 0x400);
> +    sysbus_mmio_map(mtu, 2, RX62N_MTU_BASE + 0x280 + unit * 0x400);
> +    irqbase = RX62N_MTU_IRQ + MTU_NR_IRQ * unit;
> +    for (i = 0; i < MTU_NR_IRQ; i++) {
> +        sysbus_connect_irq(mtu, i, s->irq[irqbase + i]);
> +    }
> +    sysbus_realize(mtu, &error_abort);
> +    snprintf(ckname, sizeof(ckname), "pck_mtu-%d", unit);
> +    qdev_connect_clock_in(DEVICE(mtu), "pck",
> +                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));

Moving sysbus_realize() after qdev_connect_clock_in():
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> +}
> +
>  static void register_sci(RX62NState *s, int unit)
>  {
>      SysBusDevice *sci;
> @@ -248,6 +274,8 @@ static void rx62n_realize(DeviceState *dev, Error **errp)
>      register_tmr(s, 1);
>      register_cmt(s, 0);
>      register_cmt(s, 1);
> +    register_mtu(s, 0);
> +    register_mtu(s, 1);
>      register_sci(s, 0);
>      sysbus_realize(SYS_BUS_DEVICE(&s->cpg), &error_abort);
>  }
> diff --git a/hw/rx/Kconfig b/hw/rx/Kconfig
> index d1812870ea..887a5782bb 100644
> --- a/hw/rx/Kconfig
> +++ b/hw/rx/Kconfig
> @@ -4,6 +4,7 @@ config RX62N_MCU
>      select RENESAS_TMR8
>      select RENESAS_TIMER
>      select RENESAS_SCI
> +    select RENESAS_MTU
>  
>  config RX_GDBSIM
>      bool
>
diff mbox series

Patch

diff --git a/include/hw/rx/rx62n.h b/include/hw/rx/rx62n.h
index f463148799..170c8cb6fc 100644
--- a/include/hw/rx/rx62n.h
+++ b/include/hw/rx/rx62n.h
@@ -28,6 +28,7 @@ 
 #include "hw/intc/rx_icu.h"
 #include "hw/timer/renesas_tmr8.h"
 #include "hw/timer/renesas_timer.h"
+#include "hw/timer/renesas_mtu.h"
 #include "hw/char/renesas_sci.h"
 #include "hw/rx/rx62n-cpg.h"
 #include "qemu/units.h"
@@ -45,6 +46,7 @@ 
 #define RX62N_NR_TMR    2
 #define RX62N_NR_CMT    2
 #define RX62N_NR_SCI    6
+#define RX62N_NR_MTU    2
 
 typedef struct RX62NClass {
     /*< private >*/
@@ -70,6 +72,7 @@  typedef struct RX62NState {
     RXICUState icu;
     RenesasTMR8State tmr[RX62N_NR_TMR];
     RenesasCMTState cmt[RX62N_NR_CMT];
+    RenesasMTU2State mtu[RX62N_NR_MTU];
     RSCIAState sci[RX62N_NR_SCI];
     RX62NCPGState cpg;
 
diff --git a/hw/rx/rx62n.c b/hw/rx/rx62n.c
index f61383a4c2..344be846bc 100644
--- a/hw/rx/rx62n.c
+++ b/hw/rx/rx62n.c
@@ -46,6 +46,7 @@ 
 #define RX62N_ICU_BASE  0x00087000
 #define RX62N_TMR_BASE  0x00088200
 #define RX62N_CMT_BASE  0x00088000
+#define RX62N_MTU_BASE  0x00088600
 #define RX62N_SCI_BASE  0x00088240
 #define RX62N_CPG_BASE  0x00080010
 
@@ -55,6 +56,7 @@ 
  */
 #define RX62N_TMR_IRQ   174
 #define RX62N_CMT_IRQ   28
+#define RX62N_MTU_IRQ   114
 #define RX62N_SCI_IRQ   214
 
 /*
@@ -187,6 +189,30 @@  static void register_cmt(RX62NState *s, int unit)
                           qdev_get_clock_out(DEVICE(&s->cpg), ckname));
 }
 
+static void register_mtu(RX62NState *s, int unit)
+{
+    SysBusDevice *mtu;
+    int i, irqbase;
+    char ckname[16];
+
+    object_initialize_child(OBJECT(s), "mtu[*]", &s->mtu[unit],
+                            TYPE_RENESAS_MTU2);
+    mtu = SYS_BUS_DEVICE(&s->mtu[unit]);
+    qdev_prop_set_uint32(DEVICE(mtu), "unit", unit);
+
+    sysbus_mmio_map(mtu, 0, RX62N_MTU_BASE + 0x100 + unit * 0x400);
+    sysbus_mmio_map(mtu, 1, RX62N_MTU_BASE + unit * 0x400);
+    sysbus_mmio_map(mtu, 2, RX62N_MTU_BASE + 0x280 + unit * 0x400);
+    irqbase = RX62N_MTU_IRQ + MTU_NR_IRQ * unit;
+    for (i = 0; i < MTU_NR_IRQ; i++) {
+        sysbus_connect_irq(mtu, i, s->irq[irqbase + i]);
+    }
+    sysbus_realize(mtu, &error_abort);
+    snprintf(ckname, sizeof(ckname), "pck_mtu-%d", unit);
+    qdev_connect_clock_in(DEVICE(mtu), "pck",
+                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));
+}
+
 static void register_sci(RX62NState *s, int unit)
 {
     SysBusDevice *sci;
@@ -248,6 +274,8 @@  static void rx62n_realize(DeviceState *dev, Error **errp)
     register_tmr(s, 1);
     register_cmt(s, 0);
     register_cmt(s, 1);
+    register_mtu(s, 0);
+    register_mtu(s, 1);
     register_sci(s, 0);
     sysbus_realize(SYS_BUS_DEVICE(&s->cpg), &error_abort);
 }
diff --git a/hw/rx/Kconfig b/hw/rx/Kconfig
index d1812870ea..887a5782bb 100644
--- a/hw/rx/Kconfig
+++ b/hw/rx/Kconfig
@@ -4,6 +4,7 @@  config RX62N_MCU
     select RENESAS_TMR8
     select RENESAS_TIMER
     select RENESAS_SCI
+    select RENESAS_MTU
 
 config RX_GDBSIM
     bool