Message ID | 26fc95f280808909616ebb7a1e2a472443377ec1.1617367359.git.alistair.francis@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add the SiFive PWM device | expand |
On Fri, Apr 2, 2021 at 8:45 PM Alistair Francis <alistair.francis@wdc.com> wrote: > > Signed-off-by: Alistair Francis <alistair.francis@wdc.com> > --- > include/hw/riscv/sifive_u.h | 14 +++++++++++++- > hw/riscv/sifive_u.c | 23 ++++++++++++++++++++++- > 2 files changed, 35 insertions(+), 2 deletions(-) > > diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h > index 2656b39808..6e0779562d 100644 > --- a/include/hw/riscv/sifive_u.h > +++ b/include/hw/riscv/sifive_u.h > @@ -27,6 +27,7 @@ > #include "hw/misc/sifive_u_otp.h" > #include "hw/misc/sifive_u_prci.h" > #include "hw/ssi/sifive_spi.h" > +#include "hw/timer/sifive_u_pwm.h" > > #define TYPE_RISCV_U_SOC "riscv.sifive.u.soc" > #define RISCV_U_SOC(obj) \ > @@ -49,6 +50,7 @@ typedef struct SiFiveUSoCState { > SiFiveSPIState spi0; > SiFiveSPIState spi2; > CadenceGEMState gem; > + SiFiveUPwmState pwm[2]; > > uint32_t serial; > char *cpu_type; > @@ -92,7 +94,9 @@ enum { > SIFIVE_U_DEV_FLASH0, > SIFIVE_U_DEV_DRAM, > SIFIVE_U_DEV_GEM, > - SIFIVE_U_DEV_GEM_MGMT > + SIFIVE_U_DEV_GEM_MGMT, > + SIFIVE_U_DEV_PWM0, > + SIFIVE_U_DEV_PWM1 > }; > > enum { > @@ -126,6 +130,14 @@ enum { > SIFIVE_U_PDMA_IRQ5 = 28, > SIFIVE_U_PDMA_IRQ6 = 29, > SIFIVE_U_PDMA_IRQ7 = 30, > + SIFIVE_U_DEV_PWM0_0 = 42, These should be named as SIFIVE_U_PWM0_IRQ0, etc. > + SIFIVE_U_DEV_PWM0_1 = 43, > + SIFIVE_U_DEV_PWM0_2 = 44, > + SIFIVE_U_DEV_PWM0_3 = 45, > + SIFIVE_U_DEV_PWM1_0 = 46, > + SIFIVE_U_DEV_PWM1_1 = 47, > + SIFIVE_U_DEV_PWM1_2 = 48, > + SIFIVE_U_DEV_PWM1_3 = 49, > SIFIVE_U_QSPI0_IRQ = 51, > SIFIVE_U_GEM_IRQ = 53 > }; > diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c > index 7b59942369..ba36a91ef8 100644 Missing update on supported device lists at the beginning of this file > --- a/hw/riscv/sifive_u.c > +++ b/hw/riscv/sifive_u.c > @@ -74,6 +74,8 @@ static const MemMapEntry sifive_u_memmap[] = { > [SIFIVE_U_DEV_PRCI] = { 0x10000000, 0x1000 }, > [SIFIVE_U_DEV_UART0] = { 0x10010000, 0x1000 }, > [SIFIVE_U_DEV_UART1] = { 0x10011000, 0x1000 }, > + [SIFIVE_U_DEV_PWM0] = { 0x10020000, 0x1000 }, > + [SIFIVE_U_DEV_PWM1] = { 0x10021000, 0x1000 }, > [SIFIVE_U_DEV_QSPI0] = { 0x10040000, 0x1000 }, > [SIFIVE_U_DEV_QSPI2] = { 0x10050000, 0x1000 }, > [SIFIVE_U_DEV_GPIO] = { 0x10060000, 0x1000 }, > @@ -757,6 +759,8 @@ static void sifive_u_soc_instance_init(Object *obj) > object_initialize_child(obj, "pdma", &s->dma, TYPE_SIFIVE_PDMA); > object_initialize_child(obj, "spi0", &s->spi0, TYPE_SIFIVE_SPI); > object_initialize_child(obj, "spi2", &s->spi2, TYPE_SIFIVE_SPI); > + object_initialize_child(obj, "pwm0", &s->pwm[0], TYPE_SIFIVE_U_PWM); > + object_initialize_child(obj, "pwm1", &s->pwm[1], TYPE_SIFIVE_U_PWM); > } > > static void sifive_u_soc_realize(DeviceState *dev, Error **errp) > @@ -769,7 +773,7 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) > MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1); > char *plic_hart_config; > size_t plic_hart_config_len; > - int i; > + int i, j; > NICInfo *nd = &nd_table[0]; > > qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1); > @@ -896,6 +900,23 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) > sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem), 0, > qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_GEM_IRQ)); > > + /* PWM */ > + for (i = 0; i < 2; i++) { > + if (!sysbus_realize(SYS_BUS_DEVICE(&s->pwm[i]), errp)) { > + return; > + } > + sysbus_mmio_map(SYS_BUS_DEVICE(&s->pwm[i]), 0, > + memmap[SIFIVE_U_DEV_PWM0].base + (0x1000 * i)); > + > + /* Connect PWM interrupts to the PLIC */ > + for (j = 0; j < SIFIVE_U_PWM_IRQS; j++) { > + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pwm[i]), j, > + qdev_get_gpio_in(DEVICE(s->plic), > + SIFIVE_U_DEV_PWM0_0 + > + (i * SIFIVE_PDMA_IRQS) + j)); > + } > + } > + > create_unimplemented_device("riscv.sifive.u.gem-mgmt", > memmap[SIFIVE_U_DEV_GEM_MGMT].base, memmap[SIFIVE_U_DEV_GEM_MGMT].size); > The generation of the PWM device tree fragment part is missing. Probably we need another patch to update the document on the support status of PWM devices, and if possible how to test this, e.g.: in Linux? Regards, Bin
diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h index 2656b39808..6e0779562d 100644 --- a/include/hw/riscv/sifive_u.h +++ b/include/hw/riscv/sifive_u.h @@ -27,6 +27,7 @@ #include "hw/misc/sifive_u_otp.h" #include "hw/misc/sifive_u_prci.h" #include "hw/ssi/sifive_spi.h" +#include "hw/timer/sifive_u_pwm.h" #define TYPE_RISCV_U_SOC "riscv.sifive.u.soc" #define RISCV_U_SOC(obj) \ @@ -49,6 +50,7 @@ typedef struct SiFiveUSoCState { SiFiveSPIState spi0; SiFiveSPIState spi2; CadenceGEMState gem; + SiFiveUPwmState pwm[2]; uint32_t serial; char *cpu_type; @@ -92,7 +94,9 @@ enum { SIFIVE_U_DEV_FLASH0, SIFIVE_U_DEV_DRAM, SIFIVE_U_DEV_GEM, - SIFIVE_U_DEV_GEM_MGMT + SIFIVE_U_DEV_GEM_MGMT, + SIFIVE_U_DEV_PWM0, + SIFIVE_U_DEV_PWM1 }; enum { @@ -126,6 +130,14 @@ enum { SIFIVE_U_PDMA_IRQ5 = 28, SIFIVE_U_PDMA_IRQ6 = 29, SIFIVE_U_PDMA_IRQ7 = 30, + SIFIVE_U_DEV_PWM0_0 = 42, + SIFIVE_U_DEV_PWM0_1 = 43, + SIFIVE_U_DEV_PWM0_2 = 44, + SIFIVE_U_DEV_PWM0_3 = 45, + SIFIVE_U_DEV_PWM1_0 = 46, + SIFIVE_U_DEV_PWM1_1 = 47, + SIFIVE_U_DEV_PWM1_2 = 48, + SIFIVE_U_DEV_PWM1_3 = 49, SIFIVE_U_QSPI0_IRQ = 51, SIFIVE_U_GEM_IRQ = 53 }; diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 7b59942369..ba36a91ef8 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -74,6 +74,8 @@ static const MemMapEntry sifive_u_memmap[] = { [SIFIVE_U_DEV_PRCI] = { 0x10000000, 0x1000 }, [SIFIVE_U_DEV_UART0] = { 0x10010000, 0x1000 }, [SIFIVE_U_DEV_UART1] = { 0x10011000, 0x1000 }, + [SIFIVE_U_DEV_PWM0] = { 0x10020000, 0x1000 }, + [SIFIVE_U_DEV_PWM1] = { 0x10021000, 0x1000 }, [SIFIVE_U_DEV_QSPI0] = { 0x10040000, 0x1000 }, [SIFIVE_U_DEV_QSPI2] = { 0x10050000, 0x1000 }, [SIFIVE_U_DEV_GPIO] = { 0x10060000, 0x1000 }, @@ -757,6 +759,8 @@ static void sifive_u_soc_instance_init(Object *obj) object_initialize_child(obj, "pdma", &s->dma, TYPE_SIFIVE_PDMA); object_initialize_child(obj, "spi0", &s->spi0, TYPE_SIFIVE_SPI); object_initialize_child(obj, "spi2", &s->spi2, TYPE_SIFIVE_SPI); + object_initialize_child(obj, "pwm0", &s->pwm[0], TYPE_SIFIVE_U_PWM); + object_initialize_child(obj, "pwm1", &s->pwm[1], TYPE_SIFIVE_U_PWM); } static void sifive_u_soc_realize(DeviceState *dev, Error **errp) @@ -769,7 +773,7 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1); char *plic_hart_config; size_t plic_hart_config_len; - int i; + int i, j; NICInfo *nd = &nd_table[0]; qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1); @@ -896,6 +900,23 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem), 0, qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_GEM_IRQ)); + /* PWM */ + for (i = 0; i < 2; i++) { + if (!sysbus_realize(SYS_BUS_DEVICE(&s->pwm[i]), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->pwm[i]), 0, + memmap[SIFIVE_U_DEV_PWM0].base + (0x1000 * i)); + + /* Connect PWM interrupts to the PLIC */ + for (j = 0; j < SIFIVE_U_PWM_IRQS; j++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pwm[i]), j, + qdev_get_gpio_in(DEVICE(s->plic), + SIFIVE_U_DEV_PWM0_0 + + (i * SIFIVE_PDMA_IRQS) + j)); + } + } + create_unimplemented_device("riscv.sifive.u.gem-mgmt", memmap[SIFIVE_U_DEV_GEM_MGMT].base, memmap[SIFIVE_U_DEV_GEM_MGMT].size);
Signed-off-by: Alistair Francis <alistair.francis@wdc.com> --- include/hw/riscv/sifive_u.h | 14 +++++++++++++- hw/riscv/sifive_u.c | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-)