Skip to contentSkip to conversation

Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller

PATCH Superseded Peter A. G. Crosthwaite 3 participants 12 messages Jun 4, 2012 – Jun 6, 2012

Subsystems (2)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller

Patch 1 Enhances SSI bus support to properly support multiple attached devices. An api is provided for SSI/SPI masters to select a particular device attached to the bus.

Patch 2 is a device model for the m25p80 style SPI flash chip.

Patch 3 is the Xilinx XPS SPI contoller. Its a sysbus device that instantiates a ssi bus, and interfaces the two (as per the controllers functionality)

Patch 4 instantiates the XPS SPI controller in the petalogix ML605 reference platform and connects two m25p80s to it.

Patch 5 updates the stellaris machine model to use the multi slave SSI support

CHANGELOG:
changed from v3:
addressed reviewer comments from P Maydell and S Hajnoczi
added patch 5 (re Paul Brooks request)
changed from v2:
folded former SPI bus functionality into existing SSI infrastructure (suggested - Paul Brook) (all patches) made m25p80 use async io (suggested - Stefan Hajnoczi) (2/4)
instantiated two spi flashes instead of one in ml605 ref design (4/4)
changed from v1:
minor sylistic changes (1/4)
converted spi api to modified txrx style (1-3/4)
heavily refactored m25p80 model (2/4)

Peter A. G. Crosthwaite (5):
SSI: Built in multiple device support
m25p80: initial verion
xilinx_spi: initial version
petalogix-ml605: added spi controller with m25p80
stellaris: Updated spi bus implementation

 Makefile.target                          |    2 +
 default-configs/microblaze-softmmu.mak   |    1 +
 default-configs/microblazeel-softmmu.mak |    1 +
 hw/m25p80.c                              |  557 ++++++++++++++++++++++++++++++
 hw/petalogix_ml605_mmu.c                 |   23 ++
 hw/spitz.c                               |    8 +-
 hw/ssi.c                                 |  107 +++++-
 hw/ssi.h                                 |   28 ++-
 hw/stellaris.c                           |   21 +-
 hw/tosa.c                                |    2 +-
 hw/xilinx_spi.c                          |  481 ++++++++++++++++++++++++++
 hw/z2.c                                  |    2 +-
 12 files changed, 1196 insertions(+), 37 deletions(-)
 create mode 100644 hw/m25p80.c
 create mode 100644 hw/xilinx_spi.c
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH v4 1/5 SSI: Built in multiple device support

Added support for multiple devices attached to a single SSI bus (Previously SSI masters with multiple slaves were emulated as multiple point to point SSI busses)

---
changed from v3:
added ssi_create_slave_noinit
changed from v2:
This patch is new (totally rewitten replacement of (1/4) from v2)

 hw/spitz.c     |    8 ++--
 hw/ssi.c       |  107 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 hw/ssi.h       |   28 ++++++++++++--
 hw/stellaris.c |    6 ++--
 hw/tosa.c      |    2 +-
 hw/z2.c        |    2 +-
 6 files changed, 125 insertions(+), 28 deletions(-)
hw/spitz.c +4 -4
index 1d6d2b0..f63a9bf 100644
@@ -669,18 +669,18 @@ static void spitz_ssp_attach(PXA2xxState *cpu)
     DeviceState *dev;
     void *bus;
 
-    mux = ssi_create_slave(cpu->ssp[CORGI_SSP_PORT - 1], "corgi-ssp");
+    mux = ssi_create_slave(cpu->ssp[CORGI_SSP_PORT - 1], "corgi-ssp", 0);
 
     bus = qdev_get_child_bus(mux, "ssi0");
-    ssi_create_slave(bus, "spitz-lcdtg");
+    ssi_create_slave(bus, "spitz-lcdtg", 0);
 
     bus = qdev_get_child_bus(mux, "ssi1");
-    dev = ssi_create_slave(bus, "ads7846");
+    dev = ssi_create_slave(bus, "ads7846", 0);
     qdev_connect_gpio_out(dev, 0,
                           qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_TP_INT));
 
     bus = qdev_get_child_bus(mux, "ssi2");
-    max1111 = ssi_create_slave(bus, "max1111");
+    max1111 = ssi_create_slave(bus, "max1111", 0);
     max111x_set_input(max1111, MAX1111_BATT_VOLT, SPITZ_BATTERY_VOLT);
     max111x_set_input(max1111, MAX1111_BATT_TEMP, 0);
     max111x_set_input(max1111, MAX1111_ACIN_VOLT, SPITZ_CHARGEON_ACIN);
hw/ssi.c +92 -15

162 lines not on this page · raw message

hw/ssi.h +24 -4
index 06657d7..7f0ea36 100644
@@ -1,10 +1,10 @@
 /* QEMU Synchronous Serial Interface support.  */
 
-/* In principle SSI is a point-point interface.  As such the qemu
-   implementation has a single slave device on a "bus".
+/* In principle SSI is a point-point interface.
    However it is fairly common for boards to have multiple slaves
    connected to a single master, and select devices with an external
-   chip select.  This is implemented in qemu by having an explicit mux device.
+   chip select. SSI busses can therefore have any number of slaves,
+   of which a master can select using ssi_select_slave().
    It is assumed that master and slave are both using the same transfer width.
    */
 
@@ -29,22 +29,42 @@ typedef struct SSISlaveClass {
 
     int (*init)(SSISlave *dev);
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
+    int (*set_cs)(SSISlave *dev, int state);
 } SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
+
+    int32_t slave_select;
 };
 
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
-DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
+DeviceState *ssi_create_slave(SSIBus *bus, const char *name,
+                                                    int32_t slave_select);
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name,
+                                                    int32_t slave_select);
 
 /* Master interface.  */
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
 
+#define SSI_SLAVE_SELECT_NONE (-1)
+
+void ssi_select_slave(SSIBus *bus, int32_t selected_slave);
+
 uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
 
+extern const VMStateDescription vmstate_ssi_slave;
+
+#define VMSTATE_SSI_SLAVE(_field, _state) {                          \
+    .name       = (stringify(_field)),                               \
+    .size       = sizeof(SSISlave),                                  \
+    .vmsd       = &vmstate_ssi_slave,                                \
+    .flags      = VMS_STRUCT,                                        \
+    .offset     = vmstate_offset_value(_state, _field, SSISlave),    \
+}
+
 /* max111x.c */
 void max111x_set_input(DeviceState *dev, int line, uint8_t value);
 
hw/stellaris.c +3 -3
index 562fbbf..e0600a1 100644
@@ -1309,14 +1309,14 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
             void *bus;
 
             bus = qdev_get_child_bus(dev, "ssi");
-            mux = ssi_create_slave(bus, "evb6965-ssi");
+            mux = ssi_create_slave(bus, "evb6965-ssi", 0);
             gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
 
             bus = qdev_get_child_bus(mux, "ssi0");
-            ssi_create_slave(bus, "ssi-sd");
+            ssi_create_slave(bus, "ssi-sd", 0);
 
             bus = qdev_get_child_bus(mux, "ssi1");
-            dev = ssi_create_slave(bus, "ssd0323");
+            dev = ssi_create_slave(bus, "ssd0323", 0);
             gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
 
             /* Make sure the select pin is high.  */
hw/tosa.c +1 -1
index 6baa17d..3986810 100644
@@ -196,7 +196,7 @@ static void tosa_tg_init(PXA2xxState *cpu)
 {
     i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
     i2c_create_slave(bus, "tosa_dac", DAC_BASE);
-    ssi_create_slave(cpu->ssp[1], "tosa-ssp");
+    ssi_create_slave(cpu->ssp[1], "tosa-ssp", 0);
 }
 
 
hw/z2.c +1 -1
index 654ac55..2a0ecf5 100644
@@ -346,7 +346,7 @@ static void z2_init(ram_addr_t ram_size,
 
     type_register_static(&zipit_lcd_info);
     type_register_static(&aer915_info);
-    z2_lcd = ssi_create_slave(cpu->ssp[1], "zipit-lcd");
+    z2_lcd = ssi_create_slave(cpu->ssp[1], "zipit-lcd", 0);
     bus = pxa2xx_i2c_bus(cpu->i2c[0]);
     i2c_create_slave(bus, "aer915", 0x55);
     wm = i2c_create_slave(bus, "wm8750", 0x1b);
Signature · 1 line
1.7.3.2
#2 lore raw

PATCH v4 2/5 m25p80: initial verion

In reply to Peter A. G. Crosthwaite

Added device model for m25p80 SPI flash

---
changed from v3:
changed licence to v2 or later (PMM review)
generalised device model - rather than being fixed to the fl064k, it can handle a wide range of m25p80 devices refactored erase commands (previously they were fl064k specific and used spansions broken terminology) typdef'd strcuts and enums
fixed some camel casing
added comment to explain why bdrv_sync_complete is a nop (PMM review)
removed hardcoded "512" for BDRV_SECTOR_SIZE
flash_sync_area: use bdrv_aio_writev instead of bdrv_write flash_chip_erase/flash_block_erase32k/flash_sector_erase: consolidated to one function
decode_new_cmd: fixed multi-statement lines (PMM review)
CHIP_ERASE->BULK_ERASE
init: drive_get -> drive_get_next (PMM review)
changed from v2:
updated for SSI slave interface
used async io (suggested - Stefan Hajnoczi)
changed from v1:
converted spi api to modified txrx style
factored out lots of common code and inlined overly short single call functions.
undated for txrx style spi interface

 Makefile.target |    1 +
 hw/m25p80.c     |  557 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 558 insertions(+), 0 deletions(-)
 create mode 100644 hw/m25p80.c
Makefile.target +1 -0
index 1582904..77feb83 100644
@@ -292,6 +292,7 @@ obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o mips_fulong2e.o
 obj-microblaze-y = petalogix_s3adsp1800_mmu.o
 obj-microblaze-y += petalogix_ml605_mmu.o
 obj-microblaze-y += microblaze_boot.o
+obj-microblaze-y += m25p80.o
 
 obj-microblaze-y += microblaze_pic_cpu.o
 obj-microblaze-y += xilinx_intc.o
hw/m25p80.c new file +557 -0

557 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#3 lore raw

PATCH v4 3/5 xilinx_spi: initial version

In reply to Peter A. G. Crosthwaite

device model for xilinx XPS SPI controller (v2.0)

---
changed from v3:
typedef'd struct XilinxSPI
changed unsigned int -> uin32_t
removed unused vars (c_fifo_exist and cmd_ongoing)
txfifo_reset removed duplicate s->regs[R_SPISR] &= ~SR_TX_FULL (PMM review)
reset: changed to Device Class style reset
reset: stope the ptimer (pmm review)
xlx_spi_update_irq: dont -> don't (PMM review)
init: set irq_line to 1 (force refresh on vmsd load)
init: dropped call to reset
implemetned vmsd
changed from v2:
converted spi api to ssi api
changed from v1:
converted spi api to modified txrx style

 Makefile.target |    1 +
 hw/xilinx_spi.c |  481 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 482 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spi.c
Makefile.target +1 -0
index 77feb83..4471317 100644
@@ -293,6 +293,7 @@ obj-microblaze-y = petalogix_s3adsp1800_mmu.o
 obj-microblaze-y += petalogix_ml605_mmu.o
 obj-microblaze-y += microblaze_boot.o
 obj-microblaze-y += m25p80.o
+obj-microblaze-y += xilinx_spi.o
 
 obj-microblaze-y += microblaze_pic_cpu.o
 obj-microblaze-y += xilinx_intc.o
hw/xilinx_spi.c new file +481 -0

481 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#4 lore raw

PATCH v4 4/5 petalogix-ml605: added spi controller with m25p80

In reply to Peter A. G. Crosthwaite

Added spi controller to the reference design, with a single cs line and a m25p80 style spi-flash connected

---
changed from v3:
set spi flashes as being fl06k
changed from v2:
changed spi -> ssi
added two spi flashes to machine model instead of one

 default-configs/microblaze-softmmu.mak   |    1 +
 default-configs/microblazeel-softmmu.mak |    1 +
 hw/petalogix_ml605_mmu.c                 |   23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+), 0 deletions(-)
default-configs/microblaze-softmmu.mak +1 -0
index 613edab..e9f2a29 100644
@@ -3,3 +3,4 @@
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
+CONFIG_SSI=y
default-configs/microblazeel-softmmu.mak +1 -0
index 4b40fb2..00c1a87 100644
@@ -3,3 +3,4 @@
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
+CONFIG_SSI=y
hw/petalogix_ml605_mmu.c +23 -0
index 31a4348..01af0da 100644
@@ -36,6 +36,7 @@
 #include "blockdev.h"
 #include "pc.h"
 #include "exec-memory.h"
+#include "ssi.h"
 
 #include "microblaze_boot.h"
 #include "microblaze_pic_cpu.h"
@@ -54,6 +55,8 @@
 #define AXIENET_BASEADDR 0x82780000
 #define AXIDMA_BASEADDR 0x84600000
 
+#define NUM_SPI_FLASHES 2
+
 static void machine_cpu_reset(CPUMBState *env)
 {
     env->pvr.regs[10] = 0x0e000000; /* virtex 6 */
@@ -75,6 +78,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
 {
     MemoryRegion *address_space_mem = get_system_memory();
     DeviceState *dev;
+    SysBusDevice *busdev;
     CPUMBState *env;
     DriveInfo *dinfo;
     int i;
@@ -131,6 +135,25 @@ petalogix_ml605_init(ram_addr_t ram_size,
                                      irq[1], irq[0], 100 * 1000000);
     }
 
+    {
+        void *spi;
+
+        dev = qdev_create(NULL, "xilinx,spi");
+        qdev_prop_set_uint8(dev, "num-cs", NUM_SPI_FLASHES);
+        qdev_init_nofail(dev);
+        busdev = sysbus_from_qdev(dev);
+        sysbus_mmio_map(busdev, 0, 0x40a00000);
+        sysbus_connect_irq(busdev, 0, irq[4]);
+
+        spi = qdev_get_child_bus(dev, "spi");
+
+        for (i = 0; i < NUM_SPI_FLASHES; i++) {
+            dev = ssi_create_slave_no_init(spi, "m25p80", i);
+            qdev_prop_set_string(dev, "partname", (char *)"s25fl064k");
+            qdev_init_nofail(dev);
+        }
+    }
+
     microblaze_load_kernel(env, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
                                                             machine_cpu_reset);
 
Signature · 1 line
1.7.3.2
#5 lore raw

PATCH v4 5/5 stellaris: Updated spi bus implementation

In reply to Peter A. G. Crosthwaite

Setup the stellaris_ssi_bus device to use a single multi-slave ssi bus instead of two busses.

---
changed from v3:
This patch is new

 hw/stellaris.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)
hw/stellaris.c +7 -10
index e0600a1..07a4187 100644
@@ -1164,22 +1164,21 @@ static int stellaris_adc_init(SysBusDevice *dev)
 typedef struct {
     SSISlave ssidev;
     qemu_irq irq;
-    int current_dev;
-    SSIBus *bus[2];
+    SSIBus *bus;
 } stellaris_ssi_bus_state;
 
 static void stellaris_ssi_bus_select(void *opaque, int irq, int level)
 {
     stellaris_ssi_bus_state *s = (stellaris_ssi_bus_state *)opaque;
 
-    s->current_dev = level;
+    ssi_select_slave(s->bus, (uint32_t)level);
 }
 
 static uint32_t stellaris_ssi_bus_transfer(SSISlave *dev, uint32_t val)
 {
     stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);
 
-    return ssi_transfer(s->bus[s->current_dev], val);
+    return ssi_transfer(s->bus, val);
 }
 
 static const VMStateDescription vmstate_stellaris_ssi_bus = {
@@ -1188,7 +1187,6 @@ static const VMStateDescription vmstate_stellaris_ssi_bus = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
-        VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -1197,8 +1195,7 @@ static int stellaris_ssi_bus_init(SSISlave *dev)
 {
     stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);
 
-    s->bus[0] = ssi_create_bus(&dev->qdev, "ssi0");
-    s->bus[1] = ssi_create_bus(&dev->qdev, "ssi1");
+    s->bus = ssi_create_bus(&dev->qdev, "ssi");
     qdev_init_gpio_in(&dev->qdev, stellaris_ssi_bus_select, 1);
 
     vmstate_register(&dev->qdev, -1, &vmstate_stellaris_ssi_bus, s);
@@ -1312,11 +1309,11 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
             mux = ssi_create_slave(bus, "evb6965-ssi", 0);
             gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
 
-            bus = qdev_get_child_bus(mux, "ssi0");
+            bus = qdev_get_child_bus(mux, "ssi");
+
             ssi_create_slave(bus, "ssi-sd", 0);
 
-            bus = qdev_get_child_bus(mux, "ssi1");
-            dev = ssi_create_slave(bus, "ssd0323", 0);
+            dev = ssi_create_slave(bus, "ssd0323", 1);
             gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
 
             /* Make sure the select pin is high.  */
Signature · 1 line
1.7.3.2
#6 lore raw

Re: [Qemu-devel] [PATCH V4 5/5] stellaris: Updated spi bus implementation

Regression tested using Paul Brooks test vector:

peterc@PetaLogix-ws2:~/Petalogix/Internal/plgx_install/qemu-upstream-regression/third-party/stellaris-test$ qemu-system-arm -M lm3s6965evb -serial stdio -kernel sd_card.bin -sd
sdcard.img
VNC server running on `127.0.0.1:5900'

SD Card Example Program
Type 'help' for help.

/> ls
Open
SD: Unknown CMD8
listing

----A 2012/04/25 17:44 12 README.TXT

1 File(s), 12 bytes total
0 Dir(s), 61182K bytes free

/> cat README.TXT
Hello World

Gui based test works as well.

Quoted 16 lines · Peter A. G. Crosthwaite

Setup the stellaris_ssi_bus device to use a single multi-slave ssi bus instead of two busses.

---
changed from v3:
This patch is new

 hw/stellaris.c |   17 +++++++----------

 1 files changed, 7 insertions(+), 10 deletions(-)
hw/stellaris.c +0 -0
index e0600a1..07a4187 100644

hw/stellaris.c static int stellaris_adc_init(SysBusDevice *dev) · line 1166

Quoted 3 lines
hw/stellaris.c +0 -0
@@ -1164,22 +1164,21 @@ static int stellaris_adc_init(SysBusDevice *dev)
  typedef struct {
     SSISlave ssidev;
     qemu_irq irq;

Just curiously, AFAICT, this irq is completely dead. Paul can it be removed in a trivial patch or is there some GPIO related black magic occurring here?

Quoted 58 lines
hw/stellaris.c +7 -11
-    int current_dev;
-    SSIBus *bus[2];
+    SSIBus *bus;
  } stellaris_ssi_bus_state;
 
  static void stellaris_ssi_bus_select(void *opaque, int irq, int level)
  {
     stellaris_ssi_bus_state *s = (stellaris_ssi_bus_state *)opaque;
 
-    s->current_dev = level;
+    ssi_select_slave(s->bus, (uint32_t)level);
  }
 
  static uint32_t stellaris_ssi_bus_transfer(SSISlave *dev, uint32_t val)
  {
     stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);
 
-    return ssi_transfer(s->bus[s->current_dev], val);
+    return ssi_transfer(s->bus, val);
  }
 
  static const VMStateDescription vmstate_stellaris_ssi_bus = {
@@ -1188,7 +1187,6 @@ static const VMStateDescription vmstate_stellaris_ssi_bus = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
-        VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
  };
@@ -1197,8 +1195,7 @@ static int stellaris_ssi_bus_init(SSISlave *dev)
  {
     stellaris_ssi_bus_state *s = FROM_SSI_SLAVE(stellaris_ssi_bus_state, dev);
 
-    s->bus[0] = ssi_create_bus(&dev->qdev, "ssi0");
-    s->bus[1] = ssi_create_bus(&dev->qdev, "ssi1");
+    s->bus = ssi_create_bus(&dev->qdev, "ssi");
     qdev_init_gpio_in(&dev->qdev, stellaris_ssi_bus_select, 1);
 
     vmstate_register(&dev->qdev, -1, &vmstate_stellaris_ssi_bus, s);
@@ -1312,11 +1309,11 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
             mux = ssi_create_slave(bus, "evb6965-ssi", 0);
             gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
 
-            bus = qdev_get_child_bus(mux, "ssi0");
+            bus = qdev_get_child_bus(mux, "ssi");
+
             ssi_create_slave(bus, "ssi-sd", 0);
 
-            bus = qdev_get_child_bus(mux, "ssi1");
-            dev = ssi_create_slave(bus, "ssd0323", 0);
+            dev = ssi_create_slave(bus, "ssd0323", 1);
             gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
 
             /* Make sure the select pin is high.  */
--

1.7.3.2

#7 lore raw
In reply to Peter A. G. Crosthwaite
Quoted 10 lines

Patch 1 Enhances SSI bus support to properly support multiple attached devices. An api is provided for SSI/SPI masters to select a particular device attached to the bus.

Patch 2 is a device model for the m25p80 style SPI flash chip.

Patch 3 is the Xilinx XPS SPI contoller. Its a sysbus device that instantiates a ssi bus, and interfaces the two (as per the controllers functionality)

Quoted 5 lines

Patch 4 instantiates the XPS SPI controller in the petalogix ML605 reference platform and connects two m25p80s to it.

Patch 5 updates the stellaris machine model to use the multi slave SSI support

I'm still not convinced modelling this as a multipoint bus is a good idea. If nothing else you've failed to model the case where multiple slaves are selected simultanously. Given the chip selects are actual wires, not part of the bus itself, I think multiple point-point busses are a better fit.

For the stellaris device we still have the synthetic mux device and intermediate bus.

Paul

#8 lore raw

Hi Paul,

Responses inline below.

Quoted 13 lines · Paul Brook
Quoted 13 lines

Patch 1 Enhances SSI bus support to properly support multiple attached devices. An api is provided for SSI/SPI masters to select a particular device attached to the bus.

Patch 2 is a device model for the m25p80 style SPI flash chip.

Patch 3 is  the Xilinx XPS SPI contoller. Its a sysbus device that instantiates a ssi bus, and interfaces the two (as per the controllers functionality)

Patch 4 instantiates the XPS SPI controller in the petalogix ML605 reference platform and connects two m25p80s to it.

Quoted 6 lines
Quoted 2 lines

Patch 5 updates the stellaris machine model to use the multi slave SSI support

I'm still not convinced modelling this as a multipoint bus is a good idea.  If nothing else you've failed to model the case where multiple slaves are selected simultanously.

The bus can easily be changed such that multiple devices are selectable at once to get your desired multi device behaviour. AFAICT though nothing in QEMU behaves like this ATM.

 Given the chip selects are actual wires, not part of

Quoted 5 lines

the bus itself, I think multiple point-point busses are a better fit.

For the stellaris device we still have the synthetic mux device and intermediate bus.

Yes, because in your stellaris architecture, the SSI controller (pl022) is point to point so that exactly matches the hardware.

In the microblaze controller in this series, the controller has inbuilt muxing with one-hot CS behavior. To implement with point to point, I would have to dynamically create a number of sub-busses (driven by a qdev property). I would also have to have a device within a device to model the internal mux which increases my code volume significantly. Also you end up with this little piece of ugliness in your machine model and device model:

hw/petalogix_ml605_mmu.c +3 -2
index 01af0da..394a80e 100644
@@ -145,10 +145,11 @@ petalogix_ml605_init(ram_addr_t ram_size,
         sysbus_mmio_map(busdev, 0, 0x40a00000);
         sysbus_connect_irq(busdev, 0, irq[4]);
 
-        spi = qdev_get_child_bus(dev, "spi");
 
         for (i = 0; i < NUM_SPI_FLASHES; i++) {
-            dev = ssi_create_slave_no_init(spi, "m25p80", i);
+            sprintf(sub_bus_name, "spi%d", i);
+            spi = qdev_get_child_bus(dev, sub_bus_name);
+            dev = ssi_create_slave_no_init(spi, "m25p80");
             qdev_prop_set_string(dev, "partname", (char *)"s25fl064k");
             qdev_init_nofail(dev);
         }
hw/xilinx_spi.c +5 -2
index cae88ad..6c81f70 100644
@@ -420,8 +420,11 @@ static int xilinx_spi_init(SysBusDevice *dev)
     s->irqline = -1;
     ptimer_set_freq(s->ptimer, 10 * 1000 * 1000);
 
-    s->spi = ssi_create_bus(&dev->qdev, "spi");
-
+    char sub_bus_name;
+    for (i = 0; i < num_cs; i++) {
+        sprintf(sub_bus_name, "spi%d", i);
+        s->spi[i] = ssi_create_bus(&dev->qdev, sub_bus_name);
+    }
     return 0;
 }
 

The multi-slave bus is a direct superset on point-to-point. There is nothing stopping anyone from using it as p2p. Its just things are very ugly for SPI controllers with integrated muxes to treat everything as point to point.

Regards,
Peter

Quoted 2 lines

Paul

#9 lore raw
Quoted 7 lines
Quoted 3 lines

I'm still not convinced modelling this as a multipoint bus is a good idea. If nothing else you've failed to model the case where multiple slaves are selected simultanously.

The bus can easily be changed such that multiple devices are selectable at once to get your desired multi device behaviour. AFAICT though nothing in QEMU behaves like this ATM.

By my reading your xilinx device *should* behave like this.

Quoted 9 lines
Quoted 5 lines

Given the chip selects are actual wires, not part of
the bus itself, I think multiple point-point busses are a better fit.

For the stellaris device we still have the synthetic mux device and intermediate bus.

Yes, because in your stellaris architecture, the SSI controller (pl022) is point to point so that exactly matches the hardware.

Quoted 7 lines

In the microblaze controller in this series, the controller has inbuilt muxing with one-hot CS behavior. To implement with point to point, I would have to dynamically create a number of sub-busses (driven by a qdev property). I would also have to have a device within a device to model the internal mux which increases my code volume significantly. Also you end up with this little piece of ugliness in your machine model and device model:

I don't see why would would need a separate mux device.

One of my issues is that you've made this a device property. A SPI device has no concept of address. This really is a property of the controller.

Quoted 4 lines

The multi-slave bus is a direct superset on point-to-point. There is nothing stopping anyone from using it as p2p. Its just things are very ugly for SPI controllers with integrated muxes to treat everything as point to point.

IMHO the resulting tree device is better with multiple point-point links. I'm hoping the hardcoded board descriptions (i.e. everything using ssi_create_slave) will go away sooner rather than later. Having two m25p80 devices that are indistinguishable apart from one minor property seems undesirable.

Paul

#10 lore raw
In reply to Paul Brook

Hi Paul,

Quoted 13 lines · Paul Brook
Quoted 13 lines

Patch 1 Enhances SSI bus support to properly support multiple attached devices. An api is provided for SSI/SPI masters to select a particular device attached to the bus.

Patch 2 is a device model for the m25p80 style SPI flash chip.

Patch 3 is  the Xilinx XPS SPI contoller. Its a sysbus device that instantiates a ssi bus, and interfaces the two (as per the controllers functionality)

Patch 4 instantiates the XPS SPI controller in the petalogix ML605 reference platform and connects two m25p80s to it.

Quoted 8 lines
Quoted 2 lines

Patch 5 updates the stellaris machine model to use the multi slave SSI support

I'm still not convinced modelling this as a multipoint bus is a good idea.  If nothing else you've failed to model the case where multiple slaves are selected simultanously.  Given the chip selects are actual wires, not part of the bus itself, I think multiple point-point busses are a better fit.

On 5th April, when we first RFC'd our SPI layer support, you said to Peter:

==
I don't believe there is any difference between SSI and SPI. It's the exact same thing - the same way that many devices support a "two-wire interface" that is actually just I2C with a different name.

The behavior of the CS pin varies between devices. It sounds like you need a bit of extra logic not present in the current ssi code. You should fix that, not invent a whole new bus.
==

He's gone and done exactly that, indeed generalised it with the proposed changes to SSI.

If you don't like how he's done the Stellaris change then feel free to NACK that specific patch, but otherwise it seems this generic SSI set should be good to go now?

Thanks,

John
--
John Williams, PhD, B. Eng, B. IT
PetaLogix - Linux Solutions for a Reconfigurable World
w: www.petalogix.com  p: +61-7-30090663  f: +61-7-30090663

#11 lore raw
Quoted 7 lines

On 5th April, when we first RFC'd our SPI layer support, you said to Peter:

==
I don't believe there is any difference between SSI and SPI. It's the exact same thing - the same way that many devices support a "two-wire interface" that is actually just I2C with a different name.

Quoted 7 lines

The behavior of the CS pin varies between devices. It sounds like you need a bit of extra logic not present in the current ssi code. You should fix that, not invent a whole new bus.
==

He's gone and done exactly that, indeed generalised it with the proposed changes to SSI.

No. There are two changes. Modelling the CS line in the SPI bus, and having SSI be a multipoint bus rather than point-point.

Paul