From fd56eb635b41f10c64bbbb321a7a8d46df29f3ae Mon Sep 17 00:00:00 2001 From: Martijn de Vos Date: Fri, 7 Jul 2023 22:48:18 +0200 Subject: [PATCH] Got NOR up and running on both SPI0 and SPI1 --- hw/arm/ipod_touch_2g.c | 6 +++++- hw/arm/ipod_touch_mipi_dsi.c | 1 + hw/arm/ipod_touch_nor_spi.c | 4 ++-- hw/arm/ipod_touch_spi.c | 7 +++++-- include/hw/arm/ipod_touch_2g.h | 2 ++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hw/arm/ipod_touch_2g.c b/hw/arm/ipod_touch_2g.c index 1f96d7671a..2b0218e71d 100644 --- a/hw/arm/ipod_touch_2g.c +++ b/hw/arm/ipod_touch_2g.c @@ -244,10 +244,14 @@ static void ipod_touch_machine_init(MachineState *machine) set_spi_base(0); dev = sysbus_create_simple("ipodtouch.spi", SPI0_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI0_IRQ)); IPodTouchSPIState *spi0_state = IPOD_TOUCH_SPI(dev); + nms->spi0_state = spi0_state; strcpy(spi0_state->nor->nor_path, nms->nor_path); set_spi_base(1); - sysbus_create_simple("ipodtouch.spi", SPI1_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI1_IRQ)); + dev = sysbus_create_simple("ipodtouch.spi", SPI1_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI1_IRQ)); + IPodTouchSPIState *spi1_state = IPOD_TOUCH_SPI(dev); + nms->spi1_state = spi1_state; + strcpy(spi1_state->nor->nor_path, nms->nor_path); set_spi_base(2); sysbus_create_simple("ipodtouch.spi", SPI2_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI2_IRQ)); diff --git a/hw/arm/ipod_touch_mipi_dsi.c b/hw/arm/ipod_touch_mipi_dsi.c index 38b373c250..6969cd50f4 100644 --- a/hw/arm/ipod_touch_mipi_dsi.c +++ b/hw/arm/ipod_touch_mipi_dsi.c @@ -12,6 +12,7 @@ static uint64_t ipod_touch_mipi_dsi_read(void *opaque, hwaddr addr, unsigned siz case REG_INTSRC: return rDSIM_INTSRC_RxDatDone; case REG_RXFIFO: + return 0; if(!s->return_panel_id) { s->return_panel_id = true; // TODO this should be rewritten as a proper queue! diff --git a/hw/arm/ipod_touch_nor_spi.c b/hw/arm/ipod_touch_nor_spi.c index 0dbf4b5866..28a33d8c81 100644 --- a/hw/arm/ipod_touch_nor_spi.c +++ b/hw/arm/ipod_touch_nor_spi.c @@ -13,7 +13,7 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value) { IPodTouchNORSPIState *s = IPOD_TOUCH_NOR_SPI(dev); - //printf("NOR SPI received value 0x%08x\n", value); + printf("NOR SPI received value 0x%08x\n", value); if(value == NOR_GET_JEDECID) { printf("RECEIVED JEDCID VALUE\n"); } @@ -36,6 +36,7 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value) if(value == NOR_GET_STATUS_CMD) { s->in_buf_size = 1; s->out_buf_size = 1; + s->out_buf[0] = 0; } else if(value == NOR_READ_DATA_CMD) { printf("Received read command!\n"); @@ -43,7 +44,6 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value) s->out_buf_size = 4096; } else if(value == NOR_GET_JEDECID) { - printf("WILL RETURN JEDCID\n"); s->in_buf_size = 1; s->out_buf_size = 3; s->out_buf[0] = 0x1F; // vendor: atmel, device: 0x02 -> AT25DF081A diff --git a/hw/arm/ipod_touch_spi.c b/hw/arm/ipod_touch_spi.c index 9440cbcdb5..380812363c 100644 --- a/hw/arm/ipod_touch_spi.c +++ b/hw/arm/ipod_touch_spi.c @@ -284,14 +284,17 @@ static void ipod_touch_spi_realize(DeviceState *dev, struct Error **errp) fifo8_create(&s->rx_fifo, R_FIFO_DEPTH); // create the peripheral + IPodTouchNORSPIState *nor; switch(s->base) { case 0: ssi_create_peripheral(s->spi, TYPE_IPOD_TOUCH_NOR_SPI); - IPodTouchNORSPIState *nor = IPOD_TOUCH_NOR_SPI(dev); + nor = IPOD_TOUCH_NOR_SPI(dev); s->nor = nor; break; case 1: - //ssi_create_peripheral(s->spi, TYPE_IPOD_TOUCH_LCD_PANEL); + ssi_create_peripheral(s->spi, TYPE_IPOD_TOUCH_NOR_SPI); + nor = IPOD_TOUCH_NOR_SPI(dev); + s->nor = nor; break; case 2: { diff --git a/include/hw/arm/ipod_touch_2g.h b/include/hw/arm/ipod_touch_2g.h index 699ae0a951..2e095fd72a 100644 --- a/include/hw/arm/ipod_touch_2g.h +++ b/include/hw/arm/ipod_touch_2g.h @@ -115,6 +115,8 @@ typedef struct { IPodTouchClockState *clock0; IPodTouchClockState *clock1; IPodTouchTimerState *timer1; + IPodTouchSPIState *spi0_state; + IPodTouchSPIState *spi1_state; IPodTouchChipIDState *chipid_state; IPodTouchGPIOState *gpio_state; IPodTouchSYSICState *sysic;