Skip to contentSkip to conversation

Allwinner A10 SPI controller emulation

PATCH Applied Strahinja Jankovic 2 participants 4 messages Oct 1, 2024 – Oct 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Allwinner A10 SPI controller emulation

This patch set introduces the SPI controller emulation for Allwinner A10 SoC and Cubieboard.

Only master-mode functionality of the SPI controller is implemented.

Since U-Boot and Linux SPI drivers for Allwinner A10 perform only byte-wide CPU access to the transmit and receive registers of the controller, the emulated controller does not implement DMA handling, and supports only byte-wide access to transmit and receive registers (half-word and word access will be treated as byte access).

* diff from v1:

- split patch into two parts, one implementing the peripheral and another for integrating peripheral into Allwinner A10 description
- fixed issue with CS level handling when channel is not selected (idle mode); this was discovered when CS level handling was converted to a separate function
- updated read and write register handling to log error when byte and half-word access not aligned to 4-byte boundary is performed
- updated SPDX license tags for both header and c files
- various minor fixes suggested in review

Strahinja Jankovic (2):
hw/ssi: Allwinner A10 SPI emulation {hw/arm,docs/system/arm}: Add SPI to Allwinner A10

 docs/system/arm/cubieboard.rst     |   1 +
 hw/arm/Kconfig                     |   1 +
 hw/arm/allwinner-a10.c             |   8 +
 hw/ssi/Kconfig                     |   4 +
 hw/ssi/allwinner-a10-spi.c         | 561 +++++++++++++++++++++++++++++
 hw/ssi/meson.build                 |   1 +
 hw/ssi/trace-events                |  10 +
 include/hw/arm/allwinner-a10.h     |   2 +
 include/hw/ssi/allwinner-a10-spi.h |  57 +++
 9 files changed, 645 insertions(+)
 create mode 100644 hw/ssi/allwinner-a10-spi.c
 create mode 100644 include/hw/ssi/allwinner-a10-spi.h
Signature · 1 line
2.39.5
#1 lore raw

PATCH v2 1/2 hw/ssi: Allwinner A10 SPI emulation

This patch implements Allwinner A10 SPI controller emulation. Only master-mode functionality is implemented.

Since U-Boot and Linux SPI drivers for Allwinner A10 perform only byte-wide CPU access (no DMA) to the transmit and receive registers of the peripheral, the emulated controller does not implement DMA control, and supports only byte-wide access to transmit and receive registers (half-word and word accesses will be treated as byte accesses).

---
 hw/ssi/Kconfig                     |   4 +
 hw/ssi/allwinner-a10-spi.c         | 561 +++++++++++++++++++++++++++++
 hw/ssi/meson.build                 |   1 +
 hw/ssi/trace-events                |  10 +
 include/hw/ssi/allwinner-a10-spi.h |  57 +++
 5 files changed, 633 insertions(+)
 create mode 100644 hw/ssi/allwinner-a10-spi.c
 create mode 100644 include/hw/ssi/allwinner-a10-spi.h
hw/ssi/Kconfig +4 -0
index 8d180de7cf..1bd56463c1 100644
@@ -28,3 +28,7 @@ config BCM2835_SPI
 config PNV_SPI
     bool
     select SSI
+
+config ALLWINNER_A10_SPI
+    bool
+    select SSI
hw/ssi/allwinner-a10-spi.c new file +561 -0

561 lines not on this page · raw message

hw/ssi/meson.build +1 -0
index b7ad7fca3b..0fb0b68617 100644
@@ -1,3 +1,4 @@
+system_ss.add(when: 'CONFIG_ALLWINNER_A10_SPI', if_true: files('allwinner-a10-spi.c'))
 system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_smc.c'))
 system_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-spi.c'))
 system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_fiu.c', 'npcm_pspi.c'))
hw/ssi/trace-events +10 -0
index 089d269994..2f36cf96b8 100644
@@ -53,3 +53,13 @@ pnv_spi_rx_read_N2frame(void) ""
 pnv_spi_shift_rx(uint8_t byte, uint32_t index) "byte = 0x%2.2x into RDR from payload index %d"
 pnv_spi_sequencer_stop_requested(const char* reason) "due to %s"
 pnv_spi_RDR_match(const char* result) "%s"
+
+# allwinner_a10_spi.c
+allwinner_a10_spi_update_irq(uint32_t level) "IRQ level is %d"
+allwinner_a10_spi_flush_txfifo_begin(uint32_t tx, uint32_t rx) "Begin: TX Fifo Size = %d, RX Fifo Size = %d"
+allwinner_a10_spi_flush_txfifo_end(uint32_t tx, uint32_t rx) "End: TX Fifo Size = %d, RX Fifo Size = %d"
+allwinner_a10_spi_burst_length(uint32_t len) "Burst length = %d"
+allwinner_a10_spi_tx(uint8_t byte) "write 0x%02x"
+allwinner_a10_spi_rx(uint8_t byte) "read 0x%02x"
+allwinner_a10_spi_read(const char* regname, uint32_t value) "reg[%s] => 0x%08x"
+allwinner_a10_spi_write(const char* regname, uint32_t value) "reg[%s] <= 0x%08x"
include/hw/ssi/allwinner-a10-spi.h new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.39.5
#2 lore raw

PATCH v2 2/2 {hw/arm,docs/system/arm}: Add SPI to Allwinner A10

In reply to Strahinja Jankovic

The Allwinner A10 SPI controller is added to the Allwinner A10 description, so it is available when Cubieboard is emulated.

Update the documentation for Cubieboard to indicate SPI availability.

---
 docs/system/arm/cubieboard.rst | 1 +
 hw/arm/Kconfig                 | 1 +
 hw/arm/allwinner-a10.c         | 8 ++++++++
 include/hw/arm/allwinner-a10.h | 2 ++
 4 files changed, 12 insertions(+)
docs/system/arm/cubieboard.rst +1 -0
index 58c4a2d3ea..90d24c73a1 100644
@@ -15,4 +15,5 @@ Emulated devices:
 - USB controller
 - SATA controller
 - TWI (I2C) controller
+- SPI controller
 - Watchdog timer
hw/arm/Kconfig +1 -0
index 1ad60da7aa..933b0a059c 100644
@@ -398,6 +398,7 @@ config ALLWINNER_A10
     select ALLWINNER_WDT
     select ALLWINNER_EMAC
     select ALLWINNER_I2C
+    select ALLWINNER_A10_SPI
     select AXP2XX_PMU
     select SERIAL
     select UNIMP
hw/arm/allwinner-a10.c +8 -0
index 57d5d80159..30852dd038 100644
@@ -35,6 +35,7 @@
 #define AW_A10_PIC_REG_BASE     0x01c20400
 #define AW_A10_PIT_REG_BASE     0x01c20c00
 #define AW_A10_UART0_REG_BASE   0x01c28000
+#define AW_A10_SPI0_BASE        0x01c05000
 #define AW_A10_EMAC_BASE        0x01c0b000
 #define AW_A10_EHCI_BASE        0x01c14000
 #define AW_A10_OHCI_BASE        0x01c14400
@@ -80,6 +81,8 @@ static void aw_a10_init(Object *obj)
 
     object_initialize_child(obj, "i2c0", &s->i2c0, TYPE_AW_I2C);
 
+    object_initialize_child(obj, "spi0", &s->spi0, TYPE_AW_A10_SPI);
+
     for (size_t i = 0; i < AW_A10_NUM_USB; i++) {
         object_initialize_child(obj, "ehci[*]", &s->ehci[i],
                                 TYPE_PLATFORM_EHCI);
@@ -195,6 +198,11 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c0), 0, AW_A10_I2C0_BASE);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c0), 0, qdev_get_gpio_in(dev, 7));
 
+    /* SPI */
+    sysbus_realize(SYS_BUS_DEVICE(&s->spi0), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi0), 0, AW_A10_SPI0_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi0), 0, qdev_get_gpio_in(dev, 10));
+
     /* WDT */
     sysbus_realize(SYS_BUS_DEVICE(&s->wdt), &error_fatal);
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->wdt), 0, AW_A10_WDT_BASE, 1);
include/hw/arm/allwinner-a10.h +2 -0
index 67a9a17b86..e5815b0d12 100644
@@ -12,6 +12,7 @@
 #include "hw/misc/allwinner-a10-ccm.h"
 #include "hw/misc/allwinner-a10-dramc.h"
 #include "hw/i2c/allwinner-i2c.h"
+#include "hw/ssi/allwinner-a10-spi.h"
 #include "hw/watchdog/allwinner-wdt.h"
 #include "sysemu/block-backend.h"
 
@@ -40,6 +41,7 @@ struct AwA10State {
     AllwinnerAHCIState sata;
     AwSdHostState mmc0;
     AWI2CState i2c0;
+    AWA10SPIState spi0;
     AwRtcState rtc;
     AwWdtState wdt;
     MemoryRegion sram_a;
Signature · 1 line
2.39.5
#3 lore raw
In reply to Strahinja Jankovic
Quoted 11 lines · Strahinja Jankovic

This patch set introduces the SPI controller emulation for Allwinner A10 SoC and Cubieboard.

Only master-mode functionality of the SPI controller is implemented.

Since U-Boot and Linux SPI drivers for Allwinner A10 perform only byte-wide CPU access to the transmit and receive registers of the controller, the emulated controller does not implement DMA handling, and supports only byte-wide access to transmit and receive registers (half-word and word access will be treated as byte access).

Applied to target-arm.next, thanks.

-- PMM