From 4cadcb6b5f90bf0e9d0d23ad7552a0857dc593e7 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:09 +0000 Subject: hw/sd/omap_mmc: Do a minimal conversion to QDev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do a minimal conversion of the omap_mmc device model to QDev. In this commit we do the bare minimum to produce a working device: * add the SysBusDevice parent_obj and the usual type boilerplate * omap_mmc_init() now returns a DeviceState* * reset is handled by sysbus reset, so the SoC reset function doesn't need to call omap_mmc_reset() any more * code that should obviously be in init/realize is moved there from omap_mmc_init() We leave various pieces of cleanup to later commits: * rationalizing 'struct omap_mmc_s *' to 'OMAPMMCState *' * using gpio lines rather than having omap_mmc_init() directly set s->irq, s->dma * switching away from the legacy SD API and instead having the SD card plugged into a bus Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-2-peter.maydell@linaro.org> [PMD: Do not add omap_mmc_realize()] Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/omap_mmc.c | 75 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 14 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 1d4e30e6b7..fec2cfd4d6 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -21,11 +21,15 @@ #include "qemu/osdep.h" #include "qemu/log.h" +#include "qapi/error.h" #include "hw/irq.h" +#include "hw/sysbus.h" #include "hw/arm/omap.h" #include "hw/sd/sdcard_legacy.h" -struct omap_mmc_s { +typedef struct omap_mmc_s { + SysBusDevice parent_obj; + qemu_irq irq; qemu_irq *dma; qemu_irq coverswitch; @@ -66,7 +70,7 @@ struct omap_mmc_s { int cdet_enable; int cdet_state; qemu_irq cdet; -}; +} OMAPMMCState; static void omap_mmc_interrupts_update(struct omap_mmc_s *s) { @@ -297,7 +301,7 @@ static void omap_mmc_pseudo_reset(struct omap_mmc_s *host) host->fifo_len = 0; } -void omap_mmc_reset(struct omap_mmc_s *host) +static void omap_mmc_reset(struct omap_mmc_s *host) { host->last_cmd = 0; memset(host->rsp, 0, sizeof(host->rsp)); @@ -328,7 +332,9 @@ void omap_mmc_reset(struct omap_mmc_s *host) * into any bus, and we must reset it manually. When omap_mmc is * QOMified this must move into the QOM reset function. */ - device_cold_reset(DEVICE(host->card)); + if (host->card) { + device_cold_reset(DEVICE(host->card)); + } } static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size) @@ -583,29 +589,70 @@ static const MemoryRegionOps omap_mmc_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -struct omap_mmc_s *omap_mmc_init(hwaddr base, - MemoryRegion *sysmem, - BlockBackend *blk, - qemu_irq irq, qemu_irq dma[], omap_clk clk) +DeviceState *omap_mmc_init(hwaddr base, + MemoryRegion *sysmem, + BlockBackend *blk, + qemu_irq irq, qemu_irq dma[], omap_clk clk) { - struct omap_mmc_s *s = g_new0(struct omap_mmc_s, 1); + DeviceState *dev; + OMAPMMCState *s; + + dev = qdev_new(TYPE_OMAP_MMC); + s = OMAP_MMC(dev); + sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal); s->irq = irq; s->dma = dma; s->clk = clk; - s->lines = 1; /* TODO: needs to be settable per-board */ - s->rev = 1; - memory_region_init_io(&s->iomem, NULL, &omap_mmc_ops, s, "omap.mmc", 0x800); - memory_region_add_subregion(sysmem, base, &s->iomem); + memory_region_add_subregion(sysmem, base, + sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0)); /* Instantiate the storage */ s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); } + return dev; +} + +static void omap_mmc_reset_hold(Object *obj, ResetType type) +{ + OMAPMMCState *s = OMAP_MMC(obj); omap_mmc_reset(s); +} - return s; +static void omap_mmc_initfn(Object *obj) +{ + OMAPMMCState *s = OMAP_MMC(obj); + + /* In theory these could be settable per-board */ + s->lines = 1; + s->rev = 1; + + memory_region_init_io(&s->iomem, obj, &omap_mmc_ops, s, "omap.mmc", 0x800); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); +} + +static void omap_mmc_class_init(ObjectClass *oc, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(oc); + + rc->phases.hold = omap_mmc_reset_hold; } + +static const TypeInfo omap_mmc_info = { + .name = TYPE_OMAP_MMC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(OMAPMMCState), + .instance_init = omap_mmc_initfn, + .class_init = omap_mmc_class_init, +}; + +static void omap_mmc_register_types(void) +{ + type_register_static(&omap_mmc_info); +} + +type_init(omap_mmc_register_types) -- cgit 1.4.1 From 408ccf5fd60a281b90f846d48d1cf36a14c04232 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:10 +0000 Subject: hw/sd/omap_mmc: Convert remaining 'struct omap_mmc_s' uses to OMAPMMCState MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mechanically convert the remaining uses of 'struct omap_mmc_s' to 'OMAPMMCState'. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-3-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/omap_mmc.c | 20 ++++++++++---------- include/hw/arm/omap.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index fec2cfd4d6..0f17479ecb 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -27,7 +27,7 @@ #include "hw/arm/omap.h" #include "hw/sd/sdcard_legacy.h" -typedef struct omap_mmc_s { +typedef struct OMAPMMCState { SysBusDevice parent_obj; qemu_irq irq; @@ -72,12 +72,12 @@ typedef struct omap_mmc_s { qemu_irq cdet; } OMAPMMCState; -static void omap_mmc_interrupts_update(struct omap_mmc_s *s) +static void omap_mmc_interrupts_update(OMAPMMCState *s) { qemu_set_irq(s->irq, !!(s->status & s->mask)); } -static void omap_mmc_fifolevel_update(struct omap_mmc_s *host) +static void omap_mmc_fifolevel_update(OMAPMMCState *host) { if (!host->transfer && !host->fifo_len) { host->status &= 0xf3ff; @@ -125,7 +125,7 @@ typedef enum { SD_TYPE_ADTC = 3, /* addressed with data transfer */ } MMCCmdType; -static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir, +static void omap_mmc_command(OMAPMMCState *host, int cmd, int dir, MMCCmdType type, int busy, sd_rsp_type_t resptype, int init) { @@ -234,7 +234,7 @@ static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir, host->status |= 0x0001; } -static void omap_mmc_transfer(struct omap_mmc_s *host) +static void omap_mmc_transfer(OMAPMMCState *host) { uint8_t value; @@ -289,19 +289,19 @@ static void omap_mmc_transfer(struct omap_mmc_s *host) static void omap_mmc_update(void *opaque) { - struct omap_mmc_s *s = opaque; + OMAPMMCState *s = opaque; omap_mmc_transfer(s); omap_mmc_fifolevel_update(s); omap_mmc_interrupts_update(s); } -static void omap_mmc_pseudo_reset(struct omap_mmc_s *host) +static void omap_mmc_pseudo_reset(OMAPMMCState *host) { host->status = 0; host->fifo_len = 0; } -static void omap_mmc_reset(struct omap_mmc_s *host) +static void omap_mmc_reset(OMAPMMCState *host) { host->last_cmd = 0; memset(host->rsp, 0, sizeof(host->rsp)); @@ -340,7 +340,7 @@ static void omap_mmc_reset(struct omap_mmc_s *host) static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size) { uint16_t i; - struct omap_mmc_s *s = opaque; + OMAPMMCState *s = opaque; if (size != 2) { return omap_badwidth_read16(opaque, offset); @@ -433,7 +433,7 @@ static void omap_mmc_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { int i; - struct omap_mmc_s *s = opaque; + OMAPMMCState *s = opaque; if (size != 2) { omap_badwidth_write16(opaque, offset, value); diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index 6339c5a581..7d1a1afc4f 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -530,7 +530,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem, /* omap_mmc.c */ #define TYPE_OMAP_MMC "omap-mmc" -OBJECT_DECLARE_SIMPLE_TYPE(omap_mmc_s, OMAP_MMC) +OBJECT_DECLARE_SIMPLE_TYPE(OMAPMMCState, OMAP_MMC) DeviceState *omap_mmc_init(hwaddr base, MemoryRegion *sysmem, -- cgit 1.4.1 From 68b48857640e4ffce96bdf691de5cb68e96595bf Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:11 +0000 Subject: hw/sd/omap_mmc: Convert output qemu_irqs to gpio and sysbus IRQ APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The omap_mmc device has three outbound qemu_irq lines: * one actual interrupt line * two which connect to the DMA controller and are signalled for TX and RX DMA Convert these to a sysbus IRQ and two named GPIO outputs. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-4-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/omap_mmc.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 0f17479ecb..43203a76c5 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -31,7 +31,8 @@ typedef struct OMAPMMCState { SysBusDevice parent_obj; qemu_irq irq; - qemu_irq *dma; + qemu_irq dma_tx_gpio; + qemu_irq dma_rx_gpio; qemu_irq coverswitch; MemoryRegion iomem; omap_clk clk; @@ -87,22 +88,22 @@ static void omap_mmc_fifolevel_update(OMAPMMCState *host) if (host->fifo_len > host->af_level && host->ddir) { if (host->rx_dma) { host->status &= 0xfbff; - qemu_irq_raise(host->dma[1]); + qemu_irq_raise(host->dma_rx_gpio); } else host->status |= 0x0400; } else { host->status &= 0xfbff; - qemu_irq_lower(host->dma[1]); + qemu_irq_lower(host->dma_rx_gpio); } if (host->fifo_len < host->ae_level && !host->ddir) { if (host->tx_dma) { host->status &= 0xf7ff; - qemu_irq_raise(host->dma[0]); + qemu_irq_raise(host->dma_tx_gpio); } else host->status |= 0x0800; } else { - qemu_irq_lower(host->dma[0]); + qemu_irq_lower(host->dma_tx_gpio); host->status &= 0xf7ff; } } @@ -601,12 +602,13 @@ DeviceState *omap_mmc_init(hwaddr base, s = OMAP_MMC(dev); sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal); - s->irq = irq; - s->dma = dma; s->clk = clk; memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0)); + qdev_connect_gpio_out_named(dev, "dma-tx", 0, dma[0]); + qdev_connect_gpio_out_named(dev, "dma-rx", 0, dma[1]); + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); /* Instantiate the storage */ s->card = sd_init(blk, false); @@ -633,6 +635,10 @@ static void omap_mmc_initfn(Object *obj) memory_region_init_io(&s->iomem, obj, &omap_mmc_ops, s, "omap.mmc", 0x800); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); + + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); + qdev_init_gpio_out_named(DEVICE(obj), &s->dma_tx_gpio, "dma-tx", 1); + qdev_init_gpio_out_named(DEVICE(obj), &s->dma_rx_gpio, "dma-rx", 1); } static void omap_mmc_class_init(ObjectClass *oc, void *data) -- cgit 1.4.1 From 0c90811231a9afc67d5d1119d3db0dcc8552f54d Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:12 +0000 Subject: hw/sd/omap_mmc: Convert to SDBus API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert the OMAP MMC controller to the new SDBus API: * the controller creates an SDBus bus * instead of sd_foo functions on the SDState object, call sdbus_foo functions on the SDBus * the board code creates a proper TYPE_SD_CARD object and attaches it to the controller's SDBus, instead of the controller creating a card directly via sd_init() that never gets attached to any bus * because the SD card object is on a bus, it gets reset automatically by the "traverse the qbus tree resetting things" code, and we don't need to manually reset the card from the controller reset function Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-5-peter.maydell@linaro.org> [PMD: Include "hw/sd/sd.h" instead of "hw/sd/sdcard_legacy.h", create bus in omap_mmc_initfn() instead of omap_mmc_realize()] Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/omap1.c | 10 +++++++++- hw/sd/omap_mmc.c | 31 ++++++++++--------------------- include/hw/arm/omap.h | 1 - 3 files changed, 19 insertions(+), 23 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index ea07b9aa31..15ba0a0d0c 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -29,6 +29,7 @@ #include "hw/qdev-properties.h" #include "hw/arm/boot.h" #include "hw/arm/omap.h" +#include "hw/sd/sd.h" #include "system/blockdev.h" #include "system/system.h" #include "hw/arm/soc_dma.h" @@ -3981,11 +3982,18 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram, warn_report("missing SecureDigital device"); } s->mmc = omap_mmc_init(0xfffb7800, system_memory, - dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN), &s->drq[OMAP_DMA_MMC_TX], omap_findclk(s, "mmc_ck")); + if (dinfo) { + DeviceState *card = qdev_new(TYPE_SD_CARD); + qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo), + &error_fatal); + qdev_realize_and_unref(card, qdev_get_child_bus(s->mmc, "sd-bus"), + &error_fatal); + } + s->mpuio = omap_mpuio_init(system_memory, 0xfffb5000, qdev_get_gpio_in(s->ih[1], OMAP_INT_KEYBOARD), qdev_get_gpio_in(s->ih[1], OMAP_INT_MPUIO), diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 43203a76c5..1bc8290f9d 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -25,18 +25,19 @@ #include "hw/irq.h" #include "hw/sysbus.h" #include "hw/arm/omap.h" -#include "hw/sd/sdcard_legacy.h" +#include "hw/sd/sd.h" typedef struct OMAPMMCState { SysBusDevice parent_obj; + SDBus sdbus; + qemu_irq irq; qemu_irq dma_tx_gpio; qemu_irq dma_rx_gpio; qemu_irq coverswitch; MemoryRegion iomem; omap_clk clk; - SDState *card; uint16_t last_cmd; uint16_t sdio; uint16_t rsp[8]; @@ -158,7 +159,7 @@ static void omap_mmc_command(OMAPMMCState *host, int cmd, int dir, request.arg = host->arg; request.crc = 0; /* FIXME */ - rsplen = sd_do_command(host->card, &request, response); + rsplen = sdbus_do_command(&host->sdbus, &request, response); /* TODO: validate CRCs */ switch (resptype) { @@ -247,10 +248,10 @@ static void omap_mmc_transfer(OMAPMMCState *host) if (host->fifo_len > host->af_level) break; - value = sd_read_byte(host->card); + value = sdbus_read_byte(&host->sdbus); host->fifo[(host->fifo_start + host->fifo_len) & 31] = value; if (-- host->blen_counter) { - value = sd_read_byte(host->card); + value = sdbus_read_byte(&host->sdbus); host->fifo[(host->fifo_start + host->fifo_len) & 31] |= value << 8; host->blen_counter --; @@ -262,10 +263,10 @@ static void omap_mmc_transfer(OMAPMMCState *host) break; value = host->fifo[host->fifo_start] & 0xff; - sd_write_byte(host->card, value); + sdbus_write_byte(&host->sdbus, value); if (-- host->blen_counter) { value = host->fifo[host->fifo_start] >> 8; - sd_write_byte(host->card, value); + sdbus_write_byte(&host->sdbus, value); host->blen_counter --; } @@ -328,14 +329,6 @@ static void omap_mmc_reset(OMAPMMCState *host) host->clkdiv = 0; omap_mmc_pseudo_reset(host); - - /* Since we're still using the legacy SD API the card is not plugged - * into any bus, and we must reset it manually. When omap_mmc is - * QOMified this must move into the QOM reset function. - */ - if (host->card) { - device_cold_reset(DEVICE(host->card)); - } } static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size) @@ -592,7 +585,6 @@ static const MemoryRegionOps omap_mmc_ops = { DeviceState *omap_mmc_init(hwaddr base, MemoryRegion *sysmem, - BlockBackend *blk, qemu_irq irq, qemu_irq dma[], omap_clk clk) { DeviceState *dev; @@ -610,11 +602,6 @@ DeviceState *omap_mmc_init(hwaddr base, qdev_connect_gpio_out_named(dev, "dma-rx", 0, dma[1]); sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); - /* Instantiate the storage */ - s->card = sd_init(blk, false); - if (s->card == NULL) { - exit(1); - } return dev; } @@ -639,6 +626,8 @@ static void omap_mmc_initfn(Object *obj) sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); qdev_init_gpio_out_named(DEVICE(obj), &s->dma_tx_gpio, "dma-tx", 1); qdev_init_gpio_out_named(DEVICE(obj), &s->dma_rx_gpio, "dma-rx", 1); + + qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(obj), "sd-bus"); } static void omap_mmc_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index 7d1a1afc4f..d20c55a895 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -534,7 +534,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(OMAPMMCState, OMAP_MMC) DeviceState *omap_mmc_init(hwaddr base, MemoryRegion *sysmem, - BlockBackend *blk, qemu_irq irq, qemu_irq dma[], omap_clk clk); /* omap_i2c.c */ -- cgit 1.4.1 From 3102d81fc707550675be7af0c49da7c4299e9af9 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:13 +0000 Subject: hw/sd/omap_mmc: Use similar API for "wire up omap_clk" to other OMAP devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The approach we've settled on for handling the omap_clk wiring for OMAP devices converted to QDev is to have a function omap_foo_set_clk() whose implementation just sets the field directly in the device's state struct. (See the "TODO" comment near the top of omap.h.) Make omap_mmc do the same. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-6-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/omap_mmc.c | 9 ++++++++- include/hw/arm/omap.h | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 1bc8290f9d..c6b8cf65d7 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -583,6 +583,13 @@ static const MemoryRegionOps omap_mmc_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +void omap_mmc_set_clk(DeviceState *dev, omap_clk clk) +{ + OMAPMMCState *s = OMAP_MMC(dev); + + s->clk = clk; +} + DeviceState *omap_mmc_init(hwaddr base, MemoryRegion *sysmem, qemu_irq irq, qemu_irq dma[], omap_clk clk) @@ -594,7 +601,7 @@ DeviceState *omap_mmc_init(hwaddr base, s = OMAP_MMC(dev); sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal); - s->clk = clk; + omap_mmc_set_clk(dev, clk); memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0)); diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h index d20c55a895..7cb87ea89c 100644 --- a/include/hw/arm/omap.h +++ b/include/hw/arm/omap.h @@ -535,6 +535,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(OMAPMMCState, OMAP_MMC) DeviceState *omap_mmc_init(hwaddr base, MemoryRegion *sysmem, qemu_irq irq, qemu_irq dma[], omap_clk clk); +/* TODO: clock framework (see above) */ +void omap_mmc_set_clk(DeviceState *dev, omap_clk clk); + /* omap_i2c.c */ I2CBus *omap_i2c_bus(DeviceState *omap_i2c); -- cgit 1.4.1 From 9c2fce87fc5218c0181abd9d8eb1dd7858103375 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:14 +0000 Subject: hw/arm/omap1: Inline creation of MMC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our style for other conversions of OMAP devices to qdev has been to inline the creation and wiring into omap310_mpu_init() -- see for instance the handling of omap-intc, omap-gpio and omap_i2c. Do the same for omap-mmc. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-7-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/omap1.c | 15 +++++++++++---- hw/sd/omap_mmc.c | 22 ---------------------- 2 files changed, 11 insertions(+), 26 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index 15ba0a0d0c..ca2eb0d157 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -3981,10 +3981,17 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram, if (!dinfo && !qtest_enabled()) { warn_report("missing SecureDigital device"); } - s->mmc = omap_mmc_init(0xfffb7800, system_memory, - qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN), - &s->drq[OMAP_DMA_MMC_TX], - omap_findclk(s, "mmc_ck")); + + s->mmc = qdev_new(TYPE_OMAP_MMC); + sysbus_realize_and_unref(SYS_BUS_DEVICE(s->mmc), &error_fatal); + omap_mmc_set_clk(s->mmc, omap_findclk(s, "mmc_ck")); + + memory_region_add_subregion(system_memory, 0xfffb7800, + sysbus_mmio_get_region(SYS_BUS_DEVICE(s->mmc), 0)); + qdev_connect_gpio_out_named(s->mmc, "dma-tx", 0, s->drq[OMAP_DMA_MMC_TX]); + qdev_connect_gpio_out_named(s->mmc, "dma-rx", 0, s->drq[OMAP_DMA_MMC_RX]); + sysbus_connect_irq(SYS_BUS_DEVICE(s->mmc), 0, + qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN)); if (dinfo) { DeviceState *card = qdev_new(TYPE_SD_CARD); diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index c6b8cf65d7..a8b541ca78 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -590,28 +590,6 @@ void omap_mmc_set_clk(DeviceState *dev, omap_clk clk) s->clk = clk; } -DeviceState *omap_mmc_init(hwaddr base, - MemoryRegion *sysmem, - qemu_irq irq, qemu_irq dma[], omap_clk clk) -{ - DeviceState *dev; - OMAPMMCState *s; - - dev = qdev_new(TYPE_OMAP_MMC); - s = OMAP_MMC(dev); - sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal); - - omap_mmc_set_clk(dev, clk); - - memory_region_add_subregion(sysmem, base, - sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0)); - qdev_connect_gpio_out_named(dev, "dma-tx", 0, dma[0]); - qdev_connect_gpio_out_named(dev, "dma-rx", 0, dma[1]); - sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); - - return dev; -} - static void omap_mmc_reset_hold(Object *obj, ResetType type) { OMAPMMCState *s = OMAP_MMC(obj); -- cgit 1.4.1 From d44515d1862139d0456ed71209088fd3c0cf438e Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:15 +0000 Subject: hw/sd/omap_mmc: Remove unused coverswitch qemu_irq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The coverswitch qemu_irq is never connected to anything, and the only thing we do with it is set it in omap_mmc_reset(). Remove it. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-8-peter.maydell@linaro.org> [PMD: Remove unused 'coverswitch' field] Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/omap_mmc.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index a8b541ca78..18016a2f2e 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -35,7 +35,6 @@ typedef struct OMAPMMCState { qemu_irq irq; qemu_irq dma_tx_gpio; qemu_irq dma_rx_gpio; - qemu_irq coverswitch; MemoryRegion iomem; omap_clk clk; uint16_t last_cmd; @@ -70,7 +69,6 @@ typedef struct OMAPMMCState { int cdet_wakeup; int cdet_enable; - int cdet_state; qemu_irq cdet; } OMAPMMCState; @@ -325,7 +323,6 @@ static void omap_mmc_reset(OMAPMMCState *host) host->transfer = 0; host->cdet_wakeup = 0; host->cdet_enable = 0; - qemu_set_irq(host->coverswitch, host->cdet_state); host->clkdiv = 0; omap_mmc_pseudo_reset(host); -- cgit 1.4.1 From 1671542fcefe6e00c4e039ecf1799a164f596b61 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 28 Jan 2025 10:45:16 +0000 Subject: hw/sd/omap_mmc: Untabify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a very old source file, and still has some lingering hard-coded tabs; untabify it. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20250128104519.3981448-9-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/omap_mmc.c | 124 +++++++++++++++++++++++++++---------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) (limited to 'hw/sd/omap_mmc.c') diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c index 18016a2f2e..bbe7b971bb 100644 --- a/hw/sd/omap_mmc.c +++ b/hw/sd/omap_mmc.c @@ -109,11 +109,11 @@ static void omap_mmc_fifolevel_update(OMAPMMCState *host) /* These must match the encoding of the MMC_CMD Response field */ typedef enum { - sd_nore = 0, /* no response */ - sd_r1, /* normal response command */ - sd_r2, /* CID, CSD registers */ - sd_r3, /* OCR register */ - sd_r6 = 6, /* Published RCA response */ + sd_nore = 0, /* no response */ + sd_r1, /* normal response command */ + sd_r2, /* CID, CSD registers */ + sd_r3, /* OCR register */ + sd_r6 = 6, /* Published RCA response */ sd_r1b = -1, } sd_rsp_type_t; @@ -229,7 +229,7 @@ static void omap_mmc_command(OMAPMMCState *host, int cmd, int dir, if (timeout) host->status |= 0x0080; else if (cmd == 12) - host->status |= 0x0005; /* Makes it more real */ + host->status |= 0x0005; /* Makes it more real */ else host->status |= 0x0001; } @@ -338,32 +338,32 @@ static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size) } switch (offset) { - case 0x00: /* MMC_CMD */ + case 0x00: /* MMC_CMD */ return s->last_cmd; - case 0x04: /* MMC_ARGL */ + case 0x04: /* MMC_ARGL */ return s->arg & 0x0000ffff; - case 0x08: /* MMC_ARGH */ + case 0x08: /* MMC_ARGH */ return s->arg >> 16; - case 0x0c: /* MMC_CON */ + case 0x0c: /* MMC_CON */ return (s->dw << 15) | (s->mode << 12) | (s->enable << 11) | (s->be << 10) | s->clkdiv; - case 0x10: /* MMC_STAT */ + case 0x10: /* MMC_STAT */ return s->status; - case 0x14: /* MMC_IE */ + case 0x14: /* MMC_IE */ return s->mask; - case 0x18: /* MMC_CTO */ + case 0x18: /* MMC_CTO */ return s->cto; - case 0x1c: /* MMC_DTO */ + case 0x1c: /* MMC_DTO */ return s->dto; - case 0x20: /* MMC_DATA */ + case 0x20: /* MMC_DATA */ /* TODO: support 8-bit access */ i = s->fifo[s->fifo_start]; if (s->fifo_len == 0) { @@ -378,42 +378,42 @@ static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size) omap_mmc_interrupts_update(s); return i; - case 0x24: /* MMC_BLEN */ + case 0x24: /* MMC_BLEN */ return s->blen_counter; - case 0x28: /* MMC_NBLK */ + case 0x28: /* MMC_NBLK */ return s->nblk_counter; - case 0x2c: /* MMC_BUF */ + case 0x2c: /* MMC_BUF */ return (s->rx_dma << 15) | (s->af_level << 8) | (s->tx_dma << 7) | s->ae_level; - case 0x30: /* MMC_SPI */ + case 0x30: /* MMC_SPI */ return 0x0000; - case 0x34: /* MMC_SDIO */ + case 0x34: /* MMC_SDIO */ return (s->cdet_wakeup << 2) | (s->cdet_enable) | s->sdio; - case 0x38: /* MMC_SYST */ + case 0x38: /* MMC_SYST */ return 0x0000; - case 0x3c: /* MMC_REV */ + case 0x3c: /* MMC_REV */ return s->rev; - case 0x40: /* MMC_RSP0 */ - case 0x44: /* MMC_RSP1 */ - case 0x48: /* MMC_RSP2 */ - case 0x4c: /* MMC_RSP3 */ - case 0x50: /* MMC_RSP4 */ - case 0x54: /* MMC_RSP5 */ - case 0x58: /* MMC_RSP6 */ - case 0x5c: /* MMC_RSP7 */ + case 0x40: /* MMC_RSP0 */ + case 0x44: /* MMC_RSP1 */ + case 0x48: /* MMC_RSP2 */ + case 0x4c: /* MMC_RSP3 */ + case 0x50: /* MMC_RSP4 */ + case 0x54: /* MMC_RSP5 */ + case 0x58: /* MMC_RSP6 */ + case 0x5c: /* MMC_RSP7 */ return s->rsp[(offset - 0x40) >> 2]; /* OMAP2-specific */ - case 0x60: /* MMC_IOSR */ - case 0x64: /* MMC_SYSC */ + case 0x60: /* MMC_IOSR */ + case 0x64: /* MMC_SYSC */ return 0; - case 0x68: /* MMC_SYSS */ - return 1; /* RSTD */ + case 0x68: /* MMC_SYSS */ + return 1; /* RSTD */ } OMAP_BAD_REG(offset); @@ -432,7 +432,7 @@ static void omap_mmc_write(void *opaque, hwaddr offset, } switch (offset) { - case 0x00: /* MMC_CMD */ + case 0x00: /* MMC_CMD */ if (!s->enable) break; @@ -447,17 +447,17 @@ static void omap_mmc_write(void *opaque, hwaddr offset, omap_mmc_update(s); break; - case 0x04: /* MMC_ARGL */ + case 0x04: /* MMC_ARGL */ s->arg &= 0xffff0000; s->arg |= 0x0000ffff & value; break; - case 0x08: /* MMC_ARGH */ + case 0x08: /* MMC_ARGH */ s->arg &= 0x0000ffff; s->arg |= value << 16; break; - case 0x0c: /* MMC_CON */ + case 0x0c: /* MMC_CON */ s->dw = (value >> 15) & 1; s->mode = (value >> 12) & 3; s->enable = (value >> 11) & 1; @@ -477,27 +477,27 @@ static void omap_mmc_write(void *opaque, hwaddr offset, omap_mmc_pseudo_reset(s); break; - case 0x10: /* MMC_STAT */ + case 0x10: /* MMC_STAT */ s->status &= ~value; omap_mmc_interrupts_update(s); break; - case 0x14: /* MMC_IE */ + case 0x14: /* MMC_IE */ s->mask = value & 0x7fff; omap_mmc_interrupts_update(s); break; - case 0x18: /* MMC_CTO */ + case 0x18: /* MMC_CTO */ s->cto = value & 0xff; if (s->cto > 0xfd && s->rev <= 1) printf("MMC: CTO of 0xff and 0xfe cannot be used!\n"); break; - case 0x1c: /* MMC_DTO */ + case 0x1c: /* MMC_DTO */ s->dto = value & 0xffff; break; - case 0x20: /* MMC_DATA */ + case 0x20: /* MMC_DATA */ /* TODO: support 8-bit access */ if (s->fifo_len == 32) break; @@ -508,18 +508,18 @@ static void omap_mmc_write(void *opaque, hwaddr offset, omap_mmc_interrupts_update(s); break; - case 0x24: /* MMC_BLEN */ + case 0x24: /* MMC_BLEN */ s->blen = (value & 0x07ff) + 1; s->blen_counter = s->blen; break; - case 0x28: /* MMC_NBLK */ + case 0x28: /* MMC_NBLK */ s->nblk = (value & 0x07ff) + 1; s->nblk_counter = s->nblk; s->blen_counter = s->blen; break; - case 0x2c: /* MMC_BUF */ + case 0x2c: /* MMC_BUF */ s->rx_dma = (value >> 15) & 1; s->af_level = (value >> 8) & 0x1f; s->tx_dma = (value >> 7) & 1; @@ -534,38 +534,38 @@ static void omap_mmc_write(void *opaque, hwaddr offset, break; /* SPI, SDIO and TEST modes unimplemented */ - case 0x30: /* MMC_SPI (OMAP1 only) */ + case 0x30: /* MMC_SPI (OMAP1 only) */ break; - case 0x34: /* MMC_SDIO */ + case 0x34: /* MMC_SDIO */ s->sdio = value & (s->rev >= 2 ? 0xfbf3 : 0x2020); s->cdet_wakeup = (value >> 9) & 1; s->cdet_enable = (value >> 2) & 1; break; - case 0x38: /* MMC_SYST */ + case 0x38: /* MMC_SYST */ break; - case 0x3c: /* MMC_REV */ - case 0x40: /* MMC_RSP0 */ - case 0x44: /* MMC_RSP1 */ - case 0x48: /* MMC_RSP2 */ - case 0x4c: /* MMC_RSP3 */ - case 0x50: /* MMC_RSP4 */ - case 0x54: /* MMC_RSP5 */ - case 0x58: /* MMC_RSP6 */ - case 0x5c: /* MMC_RSP7 */ + case 0x3c: /* MMC_REV */ + case 0x40: /* MMC_RSP0 */ + case 0x44: /* MMC_RSP1 */ + case 0x48: /* MMC_RSP2 */ + case 0x4c: /* MMC_RSP3 */ + case 0x50: /* MMC_RSP4 */ + case 0x54: /* MMC_RSP5 */ + case 0x58: /* MMC_RSP6 */ + case 0x5c: /* MMC_RSP7 */ OMAP_RO_REG(offset); break; /* OMAP2-specific */ - case 0x60: /* MMC_IOSR */ + case 0x60: /* MMC_IOSR */ if (value & 0xf) printf("MMC: SDIO bits used!\n"); break; - case 0x64: /* MMC_SYSC */ - if (value & (1 << 2)) /* SRTS */ + case 0x64: /* MMC_SYSC */ + if (value & (1 << 2)) /* SRTS */ omap_mmc_reset(s); break; - case 0x68: /* MMC_SYSS */ + case 0x68: /* MMC_SYSS */ OMAP_RO_REG(offset); break; -- cgit 1.4.1