Skip to content

Commit

Permalink
Some initial work on SDIO
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Sep 24, 2022
1 parent 0b62d22 commit c7e9406
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
7 changes: 6 additions & 1 deletion hw/arm/ipod_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ static void ipod_touch_memory_setup(MachineState *machine, MemoryRegion *sysmem,
allocate_ram(sysmem, "iis1", IIS1_MEM_BASE, align_64k_high(0x1));
allocate_ram(sysmem, "iis2", IIS2_MEM_BASE, align_64k_high(0x1));

allocate_ram(sysmem, "sdio", SDIO_MEM_BASE, 4096);
allocate_ram(sysmem, "mpvd", MPVD_MEM_BASE, 0x70000);
allocate_ram(sysmem, "h264bpd", H264BPD_MEM_BASE, 4096);

Expand Down Expand Up @@ -377,6 +376,12 @@ static void ipod_touch_machine_init(MachineState *machine)
nms->gpio_state = gpio_state;
memory_region_add_subregion(sysmem, GPIO_MEM_BASE, &gpio_state->iomem);

// init SDIO
dev = qdev_new("ipodtouch.sdio");
IPodTouchSDIOState *sdio_state = IPOD_TOUCH_SDIO(dev);
nms->sdio_state = sdio_state;
memory_region_add_subregion(sysmem, SDIO_MEM_BASE, &sdio_state->iomem);

dev = exynos4210_uart_create(UART0_MEM_BASE, 256, 0, serial_hd(0), nms->irq[0][24]);
if (!dev) {
printf("Failed to create uart0 device!\n");
Expand Down
85 changes: 85 additions & 0 deletions hw/arm/ipod_touch_sdio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "hw/arm/ipod_touch_sdio.h"

static void ipod_touch_sdio_write(void *opaque, hwaddr addr, uint64_t value, unsigned size)
{
fprintf(stderr, "%s: writing 0x%08x to 0x%08x\n", __func__, value, addr);

IPodTouchSDIOState *s = (struct IPodTouchSDIOState *) opaque;

switch(addr) {
case SDIO_CMD:
s->cmd = value;
break;
case SDIO_ARGU:
s->arg = value;
break;
case SDIO_CSR:
s->csr = value;
break;
case SDIO_IRQMASK:
s->irq_mask = value;
break;
default:
break;
}
}

static uint64_t ipod_touch_sdio_read(void *opaque, hwaddr addr, unsigned size)
{
fprintf(stderr, "%s: offset = 0x%08x\n", __func__, addr);

IPodTouchSDIOState *s = (struct IPodTouchSDIOState *) opaque;

switch (addr) {
case SDIO_CMD:
return s->cmd;
case SDIO_ARGU:
return s->arg;
case SDIO_DSTA:
return (1 << 0) | (1 << 4) ; // 0x1 indicates that the SDIO is ready for a CMD, (1 << 4) that the command is complete
case SDIO_CSR:
return s->csr;
case SDIO_IRQMASK:
return s->irq_mask;
default:
break;
}

return 0;
}

static const MemoryRegionOps ipod_touch_sdio_ops = {
.read = ipod_touch_sdio_read,
.write = ipod_touch_sdio_write,
.endianness = DEVICE_NATIVE_ENDIAN,
};

static void ipod_touch_sdio_init(Object *obj)
{
DeviceState *dev = DEVICE(obj);
IPodTouchSDIOState *s = IPOD_TOUCH_SDIO(obj);
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);

memory_region_init_io(&s->iomem, obj, &ipod_touch_sdio_ops, s, TYPE_IPOD_TOUCH_SDIO, 4096);
sysbus_init_mmio(sbd, &s->iomem);
}

static void ipod_touch_sdio_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
}

static const TypeInfo ipod_touch_sdio_type_info = {
.name = TYPE_IPOD_TOUCH_SDIO,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(IPodTouchSDIOState),
.instance_init = ipod_touch_sdio_init,
.class_init = ipod_touch_sdio_class_init,
};

static void ipod_touch_sdio_register_types(void)
{
type_register_static(&ipod_touch_sdio_type_info);
}

type_init(ipod_touch_sdio_register_types)
2 changes: 1 addition & 1 deletion hw/arm/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ arm_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.
arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c', 'smmuv3.c'))
arm_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c'))
arm_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c'))
arm_ss.add(when: 'CONFIG_IPOD_TOUCH', if_true: files('ipod_touch.c', 'ipod_touch_spi.c', 'ipod_touch_sysic.c', 'ipod_touch_aes.c', 'ipod_touch_sha1.c', 'ipod_touch_usb_otg.c', 'ipod_touch_8900_engine.c', 'ipod_touch_nand.c', 'ipod_touch_nand_ecc.c', 'ipod_touch_pcf50633_pmu.c', 'ipod_touch_adm.c', 'ipod_touch_chipid.c', 'ipod_touch_tvout.c', 'ipod_touch_lcd_panel.c', 'ipod_touch_multitouch.c', 'ipod_touch_lcd.c', 'ipod_touch_lis302dl.c', 'ipod_touch_aes.c', 'ipod_touch_sha1.c', 'ipod_touch_timer.c', 'ipod_touch_clock.c', 'ipod_touch_gpio.c'))
arm_ss.add(when: 'CONFIG_IPOD_TOUCH', if_true: files('ipod_touch.c', 'ipod_touch_spi.c', 'ipod_touch_sysic.c', 'ipod_touch_aes.c', 'ipod_touch_sha1.c', 'ipod_touch_usb_otg.c', 'ipod_touch_8900_engine.c', 'ipod_touch_nand.c', 'ipod_touch_nand_ecc.c', 'ipod_touch_pcf50633_pmu.c', 'ipod_touch_adm.c', 'ipod_touch_chipid.c', 'ipod_touch_tvout.c', 'ipod_touch_lcd_panel.c', 'ipod_touch_multitouch.c', 'ipod_touch_lcd.c', 'ipod_touch_lis302dl.c', 'ipod_touch_aes.c', 'ipod_touch_sha1.c', 'ipod_touch_timer.c', 'ipod_touch_clock.c', 'ipod_touch_gpio.c', 'ipod_touch_sdio.c'))

hw_arch += {'arm': arm_ss}
2 changes: 2 additions & 0 deletions include/hw/arm/ipod_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "hw/arm/ipod_touch_tvout.h"
#include "hw/arm/ipod_touch_lcd.h"
#include "hw/arm/ipod_touch_gpio.h"
#include "hw/arm/ipod_touch_sdio.h"
#include "hw/i2c/ipod_touch_i2c.h"
#include "cpu.h"

Expand Down Expand Up @@ -160,6 +161,7 @@ typedef struct {
IPodTouchTVOutState *tvout3_state;
IPodTouchLCDState *lcd_state;
IPodTouchGPIOState *gpio_state;
IPodTouchSDIOState *sdio_state;
Clock *sysclk;
uint32_t kpc_pa;
uint32_t kbootargs_pa;
Expand Down
29 changes: 29 additions & 0 deletions include/hw/arm/ipod_touch_sdio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef IPOD_TOUCH_SDIO_H
#define IPOD_TOUCH_SDIO_H

#include "qemu/osdep.h"
#include "qemu/module.h"
#include "qemu/timer.h"
#include "hw/sysbus.h"

#define TYPE_IPOD_TOUCH_SDIO "ipodtouch.sdio"
OBJECT_DECLARE_SIMPLE_TYPE(IPodTouchSDIOState, IPOD_TOUCH_SDIO)

#define SDIO_CMD 0x8
#define SDIO_ARGU 0xC
#define SDIO_DSTA 0x18
#define SDIO_CSR 0x34
#define SDIO_IRQMASK 0x3C

typedef struct IPodTouchSDIOState
{
SysBusDevice parent_obj;
MemoryRegion iomem;

uint32_t cmd;
uint32_t arg;
uint32_t csr;
uint32_t irq_mask;
} IPodTouchSDIOState;

#endif

0 comments on commit c7e9406

Please sign in to comment.