Skip to contentSkip to conversation

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

PATCH Superseded Peter Crosthwaite 1 participant 15 messages Oct 3, 2012 Arm/Zynq architecture

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

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

This series reworks the SSI bus framework for SPI and add some new SPI controllers and devices:

Patches 1-4 reworks SSI to add chip-select support to SPI devices and allow for multiple SPI devices attached to the

same bus.
Patches 5-6 fix the SPI setup in the stellaris machine model.
Patch 7 is a general FIFO helper API used by the upcomming patches.
Patch 8 is a device model for the m25p80 SPI flash family.
Patches 9 & 11 are the Xilinx SPI flash controller devices
Patches 10 & 12 add SPI controllers to the ML605 and Zynq machine models.
Patch 13 is Maintainerships.
Patch 14 Is a helper function that can SSI controllers can call to automatically connect slave (based on QOM object heirachy) (New v8)

CHANGELOG:
changed from v7:
addressed PMM review (p5)
various minor bugfixes
Added connect children helper
changed from v6:
Address Blue Swirl Review (P8, P11)
changed from v5:
VMSD version bump
various line-by-line review fixes
removed trivial patch (formerly P8)
collapsed former P2-3 into one patch for bisectability
changed from v4 (Major changes):
Completely reworked SPI refactor. Please re-review from scratch.
Added Zynq SPI flash.
Factored out FIFO functionality from SPI flash controller.
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 (13):
ssi: Support for multiple attached devices
ssi: Implemented CS behaviour
ssi: Added create_slave_no_init()
qdev: allow multiple qdev_init_gpio_in() calls hw/stellaris: Removed gpio_out init array.
stellaris: Removed SSI mux
hw: Added generic FIFO API.
m25p80: Initial implementation of SPI flash device
xilinx_spi: Initial impl. of Xilinx SPI controller
petalogix-ml605: added SPI controller with n25q128
xilinx_spips: Xilinx Zynq SPI cntrlr device model
xilinx_zynq: Added SPI controllers + flashes
MAINTAINERS: Added maintainerships for SSI

Peter Crosthwaite (1):
ssi: Add slave autoconnect helper

 MAINTAINERS                              |    8 +
 default-configs/arm-softmmu.mak          |    1 +
 default-configs/microblaze-softmmu.mak   |    2 +
 default-configs/microblazeel-softmmu.mak |    2 +
 hw/Makefile.objs                         |    2 +
 hw/ads7846.c                             |    7 +-
 hw/arm/Makefile.objs                     |    1 +
 hw/fifo.c                                |   78 ++++
 hw/fifo.h                                |   47 +++
 hw/irq.c                                 |   27 +-
 hw/irq.h                                 |   11 +-
 hw/m25p80.c                              |  574 ++++++++++++++++++++++++++++++
 hw/max111x.c                             |    7 +-
 hw/microblaze/Makefile.objs              |    1 +
 hw/petalogix_ml605_mmu.c                 |   27 ++
 hw/qdev.c                                |    6 +-
 hw/spitz.c                               |    8 +-
 hw/ssd0323.c                             |    7 +
 hw/ssi-sd.c                              |    7 +
 hw/ssi.c                                 |  109 +++++-
 hw/ssi.h                                 |   42 +++
 hw/stellaris.c                           |  111 ++-----
 hw/xilinx_spi.c                          |  392 ++++++++++++++++++++
 hw/xilinx_spips.c                        |  354 ++++++++++++++++++
 hw/xilinx_zynq.c                         |   34 ++
 hw/z2.c                                  |    7 +-
 26 files changed, 1746 insertions(+), 126 deletions(-)
 create mode 100644 hw/fifo.c
 create mode 100644 hw/fifo.h
 create mode 100644 hw/m25p80.c
 create mode 100644 hw/xilinx_spi.c
 create mode 100644 hw/xilinx_spips.c
#1 lore raw

PATCH v8 1/14 ssi: Support for multiple attached devices

From: Peter A. G. Crosthwaite <[email protected]>

Removed assertion that only one device is attached to the SSI bus.

When multiple devices are attached, all slaves have their transfer function called for transfers. Each device is responsible for knowing whether or not its CS is active, and if not returning 0. The returned data is the logical or of all responses from the (mulitple) devices.

---

 hw/ssi.c |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)
hw/ssi.c +9 -15
index e5f14a0..35d0a04 100644
@@ -2,6 +2,8 @@
  * QEMU Synchronous Serial Interface support
  *
  * Copyright (c) 2009 CodeSourcery.
+ * Copyright (c) 2012 Peter A.G. Crosthwaite ([email protected])
+ * Copyright (c) 2012 PetaLogix Pty Ltd.
  * Written by Paul Brook
  *
  * This code is licensed under the GNU GPL v2.
@@ -29,14 +31,6 @@ static int ssi_slave_init(DeviceState *dev)
 {
     SSISlave *s = SSI_SLAVE(dev);
     SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
-    SSIBus *bus;
-    BusChild *kid;
-
-    bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
-    kid = QTAILQ_FIRST(&bus->qbus.children);
-    if (kid->child != dev || QTAILQ_NEXT(kid, sibling) != NULL) {
-        hw_error("Too many devices on SSI bus");
-    }
 
     return ssc->init(s);
 }
@@ -74,16 +68,16 @@ SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
 uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
 {
     BusChild *kid;
-    SSISlave *slave;
     SSISlaveClass *ssc;
+    uint32_t r = 0;
 
-    kid = QTAILQ_FIRST(&bus->qbus.children);
-    if (!kid) {
-        return 0;
+    QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+        SSISlave *slave = SSI_SLAVE(kid->child);
+        ssc = SSI_SLAVE_GET_CLASS(slave);
+        r |= ssc->transfer(slave, val);
     }
-    slave = SSI_SLAVE(kid->child);
-    ssc = SSI_SLAVE_GET_CLASS(slave);
-    return ssc->transfer(slave, val);
+
+    return r;
 }
 
 static void ssi_slave_register_types(void)
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v8 2/14 ssi: Implemented CS behaviour

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added default CS behaviour for SSI slaves. SSI devices can set a property to enable CS behaviour which will create a GPIO on the device which is the CS. Tristating of the bus on SSI transfers is implemented.

---
Changed since v5:
Addressed PMM review.
Collapsed into one patch for bisectability (this used to be two patches)

 hw/ads7846.c   |    7 ++++---
 hw/max111x.c   |    7 ++++---
 hw/spitz.c     |    8 +++++---
 hw/ssd0323.c   |    6 ++++++
 hw/ssi-sd.c    |    6 ++++++
 hw/ssi.c       |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/ssi.h       |   37 +++++++++++++++++++++++++++++++++++++
 hw/stellaris.c |    7 ++++---
 hw/z2.c        |    7 ++++---
 9 files changed, 118 insertions(+), 16 deletions(-)
hw/ads7846.c +4 -3
index 41c7f10..2ea9e55 100644
@@ -119,11 +119,12 @@ static int ads7856_post_load(void *opaque, int version_id)
 
 static const VMStateDescription vmstate_ads7846 = {
     .name = "ads7846",
-    .version_id = 0,
-    .minimum_version_id = 0,
-    .minimum_version_id_old = 0,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
     .post_load = ads7856_post_load,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ADS7846State),
         VMSTATE_INT32_ARRAY(input, ADS7846State, 8),
         VMSTATE_INT32(noise, ADS7846State),
         VMSTATE_INT32(cycle, ADS7846State),
hw/max111x.c +4 -3
index 706d89f..67640f1 100644
@@ -99,10 +99,11 @@ static uint32_t max111x_transfer(SSISlave *dev, uint32_t value)
 
 static const VMStateDescription vmstate_max111x = {
     .name = "max111x",
-    .version_id = 0,
-    .minimum_version_id = 0,
-    .minimum_version_id_old = 0,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, MAX111xState),
         VMSTATE_UINT8(tb1, MAX111xState),
         VMSTATE_UINT8(rb2, MAX111xState),
         VMSTATE_UINT8(rb3, MAX111xState),
hw/spitz.c +5 -3
index 20e7835..24346dc 100644
@@ -1083,10 +1083,11 @@ static TypeInfo spitz_keyboard_info = {
 
 static const VMStateDescription vmstate_corgi_ssp_regs = {
     .name = "corgi-ssp",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .minimum_version_id_old = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, CorgiSSPState),
         VMSTATE_UINT32_ARRAY(enable, CorgiSSPState, 3),
         VMSTATE_END_OF_LIST(),
     }
@@ -1115,6 +1116,7 @@ static const VMStateDescription vmstate_spitz_lcdtg_regs = {
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = (VMStateField []) {
+        VMSTATE_SSI_SLAVE(ssidev, SpitzLCDTG),
         VMSTATE_UINT32(bl_intensity, SpitzLCDTG),
         VMSTATE_UINT32(bl_power, SpitzLCDTG),
         VMSTATE_END_OF_LIST(),
hw/ssd0323.c +6 -0
index b101c51..5d05a35 100644
@@ -279,6 +279,7 @@ static void ssd0323_cd(void *opaque, int n, int level)
 
 static void ssd0323_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
@@ -296,10 +297,13 @@ static void ssd0323_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->remap);
     qemu_put_be32(f, s->mode);
     qemu_put_buffer(f, s->framebuffer, sizeof(s->framebuffer));
+
+    qemu_put_be32(f, ss->cs);
 }
 
 static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssd0323_state *s = (ssd0323_state *)opaque;
     int i;
 
@@ -321,6 +325,8 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)
     s->mode = qemu_get_be32(f);
     qemu_get_buffer(f, s->framebuffer, sizeof(s->framebuffer));
 
+    ss->cs = qemu_get_be32(f);
+
     return 0;
 }
 
hw/ssi-sd.c +6 -0
index b519bdb..cbbc645 100644
@@ -197,6 +197,7 @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
 
 static void ssi_sd_save(QEMUFile *f, void *opaque)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -209,10 +210,13 @@ static void ssi_sd_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, s->arglen);
     qemu_put_be32(f, s->response_pos);
     qemu_put_be32(f, s->stopping);
+
+    qemu_put_be32(f, ss->cs);
 }
 
 static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
 {
+    SSISlave *ss = SSI_SLAVE(opaque);
     ssi_sd_state *s = (ssi_sd_state *)opaque;
     int i;
 
@@ -229,6 +233,8 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)
     s->response_pos = qemu_get_be32(f);
     s->stopping = qemu_get_be32(f);
 
+    ss->cs = qemu_get_be32(f);
+
     return 0;
 }
 
hw/ssi.c +48 -1

79 lines not on this page · raw message

hw/ssi.h +37 -0
index 06657d7..65b159d 100644
@@ -23,21 +23,58 @@ typedef struct SSISlave SSISlave;
 #define SSI_SLAVE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
 
+typedef enum {
+    SSI_CS_NONE = 0,
+    SSI_CS_LOW,
+    SSI_CS_HIGH,
+} SSICSMode;
+
 /* Slave devices.  */
 typedef struct SSISlaveClass {
     DeviceClass parent_class;
 
     int (*init)(SSISlave *dev);
+
+    /* if you have standard or no CS behaviour, just override transfer.
+     * This is called when the device cs is active (true by default).
+     */
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
+    /* called when the CS line changes. Optional, devices only need to implement
+     * this if they have side effects associated with the cs line (beyond
+     * tristating the txrx lines).
+     */
+    int (*set_cs)(SSISlave *dev, bool select);
+    /* define whether or not CS exists and is active low/high */
+    SSICSMode cs_polarity;
+
+    /* if you have non-standard CS behaviour override this to take control
+     * of the CS behaviour at the device level. transfer, set_cs, and
+     * cs_polarity are unused if this is overwritten. Transfer_raw will
+     * always be called for the device for every txrx access to the parent bus
+     */
+    uint32_t (*transfer_raw)(SSISlave *dev, uint32_t val);
 } SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
+
+    /* Chip select state */
+    bool cs;
 };
 
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
+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),    \
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
 
 /* Master interface.  */
hw/stellaris.c +4 -3
index 562fbbf..01050d1 100644
@@ -1184,10 +1184,11 @@ static uint32_t stellaris_ssi_bus_transfer(SSISlave *dev, uint32_t val)
 
 static const VMStateDescription vmstate_stellaris_ssi_bus = {
     .name = "stellaris_ssi_bus",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .minimum_version_id_old = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
     .fields      = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, stellaris_ssi_bus_state),
         VMSTATE_INT32(current_dev, stellaris_ssi_bus_state),
         VMSTATE_END_OF_LIST()
     }
hw/z2.c +4 -3
index 289cee9..076fad2 100644
@@ -161,10 +161,11 @@ static int zipit_lcd_init(SSISlave *dev)
 
 static VMStateDescription vmstate_zipit_lcd_state = {
     .name = "zipit-lcd",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .minimum_version_id_old = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
     .fields = (VMStateField[]) {
+        VMSTATE_SSI_SLAVE(ssidev, ZipitLCD),
         VMSTATE_INT32(selected, ZipitLCD),
         VMSTATE_INT32(enabled, ZipitLCD),
         VMSTATE_BUFFER(buf, ZipitLCD),
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH v8 3/14 ssi: Added create_slave_no_init()

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Slave creation function that can be used to create an SSI slave without qdev_init() being called. This give machine models a chance to set properties.

---

 hw/ssi.c |    9 +++++++--
 hw/ssi.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/ssi.c +7 -2
index 2e4f2fe..c47419d 100644
@@ -86,10 +86,15 @@ static TypeInfo ssi_slave_info = {
     .abstract = true,
 };
 
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name)
+{
+    return qdev_create(&bus->qbus, name);
+}
+
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
 {
-    DeviceState *dev;
-    dev = qdev_create(&bus->qbus, name);
+    DeviceState *dev = ssi_create_slave_no_init(bus, name);
+
     qdev_init_nofail(dev);
     return dev;
 }
hw/ssi.h +1 -0
index 65b159d..2bde9f5 100644
@@ -76,6 +76,7 @@ extern const VMStateDescription vmstate_ssi_slave;
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
+DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name);
 
 /* Master interface.  */
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
Signature · 1 line
1.7.0.4
#4 lore raw

PATCH v8 4/14 qdev: allow multiple qdev_init_gpio_in() calls

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Allow multiple qdev_init_gpio_in() calls for the one device. The first call will define GPIOs 0-N-1, the next GPIOs N- ... . Allows different GPIOs to be handled with different handlers. Needed when two levels of the QOM class heirachy both define GPIO functionality, as a single GPIO handler with an index selecter is not possible.

---
changed since v7:
fixed function proto identation s/g_new0/g_new/ for consistency with g_renew fixed free'ing behaviour by g_renewing "p" as well changed since v5:
moved implementation to irq.c as per PMM review

 hw/irq.c  |   27 ++++++++++++++++++++-------
 hw/irq.h  |   11 ++++++++++-
 hw/qdev.c |    6 +++---
 3 files changed, 33 insertions(+), 11 deletions(-)
hw/irq.c +20 -7
index d413a0b..f4e2a78 100644
@@ -38,24 +38,37 @@ void qemu_set_irq(qemu_irq irq, int level)
     irq->handler(irq->opaque, irq->n, level);
 }
 
-qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
+qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
+                           void *opaque, int n)
 {
     qemu_irq *s;
     struct IRQState *p;
     int i;
 
-    s = (qemu_irq *)g_malloc0(sizeof(qemu_irq) * n);
-    p = (struct IRQState *)g_malloc0(sizeof(struct IRQState) * n);
-    for (i = 0; i < n; i++) {
-        p->handler = handler;
-        p->opaque = opaque;
-        p->n = i;
+    if (!old) {
+        n_old = 0;
+    }
+    s = old ? g_renew(qemu_irq, old, n + n_old) : g_new(qemu_irq, n);
+    p = old ? g_renew(struct IRQState, s[0], n + n_old) :
+                g_new(struct IRQState, n);
+    for (i = 0; i < n + n_old; i++) {
+        if (i >= n_old) {
+            p->handler = handler;
+            p->opaque = opaque;
+            p->n = i;
+        }
         s[i] = p;
         p++;
     }
     return s;
 }
 
+qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
+{
+    return qemu_extend_irqs(NULL, 0, handler, opaque, n);
+}
+
+
 void qemu_free_irqs(qemu_irq *s)
 {
     g_free(s[0]);
hw/irq.h +10 -1
index 56c55f0..e640c10 100644
@@ -23,8 +23,17 @@ static inline void qemu_irq_pulse(qemu_irq irq)
     qemu_set_irq(irq, 0);
 }
 
-/* Returns an array of N IRQs.  */
+/* Returns an array of N IRQs. Each IRQ is assigned the argument handler and
+ * opaque data.
+ */
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
+
+/* Extends an Array of IRQs. Old IRQs have their handlers and opaque data
+ * preserved. New IRQs are assigned the argument handler and opaque data.
+ */
+qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
+                                void *opaque, int n);
+
 void qemu_free_irqs(qemu_irq *s);
 
 /* Returns a new IRQ with opposite polarity.  */
hw/qdev.c +3 -3
index b5a52ac..eea9eae 100644
@@ -291,9 +291,9 @@ BusState *qdev_get_parent_bus(DeviceState *dev)
 
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
 {
-    assert(dev->num_gpio_in == 0);
-    dev->num_gpio_in = n;
-    dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
+    dev->gpio_in = qemu_extend_irqs(dev->gpio_in, dev->num_gpio_in, handler,
+                                        dev, n);
+    dev->num_gpio_in += n;
 }
 
 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
Signature · 1 line
1.7.0.4
#5 lore raw

PATCH v8 5/14 hw/stellaris: Removed gpio_out init array.

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

stellaris_init() defines arrays of qemu_irq to decides what each of the GPIO pins are connected to. This is ok for inputs (as an input can only have one source) but is flawed for outputs as an output can connect to any number of sinks. Removed the gpio_out array completely and just replaced its setters with direct calls to qdev_connect_gpio_out().

---

 hw/stellaris.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)
hw/stellaris.c +12 -14
index 01050d1..a7b68f4 100644
@@ -1244,7 +1244,6 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
     qemu_irq *pic;
     DeviceState *gpio_dev[7];
     qemu_irq gpio_in[7][8];
-    qemu_irq gpio_out[7][8];
     qemu_irq adc;
     int sram_size;
     int flash_size;
@@ -1284,8 +1283,9 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
                                                pic[gpio_irq[i]]);
             for (j = 0; j < 8; j++) {
                 gpio_in[i][j] = qdev_get_gpio_in(gpio_dev[i], j);
-                gpio_out[i][j] = NULL;
             }
+        } else {
+            gpio_dev[i] = NULL;
         }
     }
 
@@ -1308,20 +1308,27 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
         if (board->peripherals & BP_OLED_SSI) {
             DeviceState *mux;
             void *bus;
+            qemu_irq select_pin;
 
             bus = qdev_get_child_bus(dev, "ssi");
             mux = ssi_create_slave(bus, "evb6965-ssi");
-            gpio_out[GPIO_D][0] = qdev_get_gpio_in(mux, 0);
+            select_pin = qdev_get_gpio_in(mux, 0);
+            if (gpio_dev[GPIO_D]) {
+                qdev_connect_gpio_out(gpio_dev[GPIO_D], 0, select_pin);
+            }
 
             bus = qdev_get_child_bus(mux, "ssi0");
             ssi_create_slave(bus, "ssi-sd");
 
             bus = qdev_get_child_bus(mux, "ssi1");
             dev = ssi_create_slave(bus, "ssd0323");
-            gpio_out[GPIO_C][7] = qdev_get_gpio_in(dev, 0);
+            if (gpio_dev[GPIO_C]) {
+                qdev_connect_gpio_out(gpio_dev[GPIO_C], 7,
+                                        qdev_get_gpio_in(dev, 0));
+            }
 
             /* Make sure the select pin is high.  */
-            qemu_irq_raise(gpio_out[GPIO_D][0]);
+            qemu_irq_raise(select_pin);
         }
     }
     if (board->dc4 & (1 << 28)) {
@@ -1347,15 +1354,6 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
 
         stellaris_gamepad_init(5, gpad_irq, gpad_keycode);
     }
-    for (i = 0; i < 7; i++) {
-        if (board->dc4 & (1 << i)) {
-            for (j = 0; j < 8; j++) {
-                if (gpio_out[i][j]) {
-                    qdev_connect_gpio_out(gpio_dev[i], j, gpio_out[i][j]);
-                }
-            }
-        }
-    }
 }
 
 /* FIXME: Figure out how to generate these from stellaris_boards.  */
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH v8 7/14 hw: Added generic FIFO API.

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added a FIFO API that can be used to create and operate byte FIFOs.

---

 hw/Makefile.objs |    1 +
 hw/fifo.c        |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/fifo.h        |   47 ++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100644 hw/fifo.c
 create mode 100644 hw/fifo.h
hw/Makefile.objs +1 -0
index ecdbe44..e18ae34 100644
@@ -15,6 +15,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-y += fifo.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
hw/fifo.c new file +78 -0

78 lines not on this page · raw message

hw/fifo.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#6 lore raw

PATCH v8 6/14 stellaris: Removed SSI mux

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Removed the explicit SSI mux and wired the CS line directly up to the SSI devices.

---

 hw/ssd0323.c   |    1 +
 hw/ssi-sd.c    |    1 +
 hw/stellaris.c |   98 ++++++++++----------------------------------------------
 3 files changed, 19 insertions(+), 81 deletions(-)
hw/ssd0323.c +1 -0
index 5d05a35..9c42d64 100644
@@ -354,6 +354,7 @@ static void ssd0323_class_init(ObjectClass *klass, void *data)
 
     k->init = ssd0323_init;
     k->transfer = ssd0323_transfer;
+    k->cs_polarity = SSI_CS_HIGH;
 }
 
 static TypeInfo ssd0323_info = {
hw/ssi-sd.c +1 -0
index cbbc645..c5505ee 100644
@@ -256,6 +256,7 @@ static void ssi_sd_class_init(ObjectClass *klass, void *data)
 
     k->init = ssi_sd_init;
     k->transfer = ssi_sd_transfer;
+    k->cs_polarity = SSI_CS_LOW;
 }
 
 static TypeInfo ssi_sd_info = {
hw/stellaris.c +17 -81

132 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#8 lore raw

PATCH v8 8/14 m25p80: Initial implementation of SPI flash device

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added device model for m25p80 style SPI flash family.

---
changed from v7:
Debug print on select as well as deselect
Fixed data bit reversal
changed from v6:
Addressed Blue Swirl review
Constified TypeInfo
Added missing break
s/assert(false)/abort()
changed from v4:
Added write-1 flag (EEPROM mode).
n25q128 table entry indentation fix.
updated for new SSI interface.
various debug messages cleaned up and added.
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

 default-configs/arm-softmmu.mak          |    1 +
 default-configs/microblaze-softmmu.mak   |    2 +
 default-configs/microblazeel-softmmu.mak |    2 +
 hw/Makefile.objs                         |    1 +
 hw/m25p80.c                              |  574 ++++++++++++++++++++++++++++++
 5 files changed, 580 insertions(+), 0 deletions(-)
 create mode 100644 hw/m25p80.c
default-configs/arm-softmmu.mak +1 -0
index f335a72..2f1a5c9 100644
@@ -22,6 +22,7 @@ CONFIG_ADS7846=y
 CONFIG_MAX111X=y
 CONFIG_SSI=y
 CONFIG_SSI_SD=y
+CONFIG_SSI_M25P80=y
 CONFIG_LAN9118=y
 CONFIG_SMC91C111=y
 CONFIG_DS1338=y
default-configs/microblaze-softmmu.mak +2 -0
index 64c9485..2f442e5 100644
@@ -5,3 +5,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
 CONFIG_XILINX=y
 CONFIG_XILINX_AXI=y
+CONFIG_SSI=y
+CONFIG_SSI_M25P80=y
default-configs/microblazeel-softmmu.mak +2 -0
index a962276..af9a3cd 100644
@@ -5,3 +5,5 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_SERIAL=y
 CONFIG_XILINX=y
 CONFIG_XILINX_AXI=y
+CONFIG_SSI=y
+CONFIG_SSI_M25P80=y
hw/Makefile.objs +1 -0
index e18ae34..7342cf9 100644
@@ -174,6 +174,7 @@ common-obj-y += scsi-disk.o cdrom.o hd-geometry.o block-common.o
 common-obj-y += scsi-generic.o scsi-bus.o
 common-obj-y += hid.o
 common-obj-$(CONFIG_SSI) += ssi.o
+common-obj-$(CONFIG_SSI_M25P80) += m25p80.o
 common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
 common-obj-$(CONFIG_SD) += sd.o
 common-obj-y += bt.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
hw/m25p80.c new file +574 -0

574 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#9 lore raw

PATCH v8 9/14 xilinx_spi: Initial impl. of Xilinx SPI controller

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

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

---
changed from v7:
Fixed device name: s/xilinx,spi/xlnx.xps-spi
Fixed num-ss-bits property name: s/num-cs/num-ss-bits
changed from v4 (Near total rewrite):
removed timer delay. This was innacturate anyways removed for simlicity. updated for new SSI interface.
factored out txrx fifos using fifo.h
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

 hw/microblaze/Makefile.objs |    1 +
 hw/xilinx_spi.c             |  390 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 391 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spi.c
hw/microblaze/Makefile.objs +1 -0
index 274d2c5..3028e65 100644
@@ -1,6 +1,7 @@
 obj-y = petalogix_s3adsp1800_mmu.o
 obj-y += petalogix_ml605_mmu.o
 obj-y += microblaze_boot.o
+obj-y += xilinx_spi.o
 
 obj-y += microblaze_pic_cpu.o
 obj-y += xilinx_ethlite.o
hw/xilinx_spi.c new file +390 -0

390 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#10 lore raw

PATCH v8 10/14 petalogix-ml605: added SPI controller with n25q128

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added SPI controller to the reference design, with two n25q128 spi-flashes connected.

---
Changed since v7:
Increased number of spi flashes to 4
Fixed spi controller qdev name and property names (see prev patch) Changed since v5:
Removed redundant (char*) cast with qdev_get_prop_string

 hw/petalogix_ml605_mmu.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
hw/petalogix_ml605_mmu.c +27 -0
index dced648..b9bfbed 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"
@@ -47,6 +48,8 @@
 
 #define BINARY_DEVICE_TREE_FILE "petalogix-ml605.dtb"
 
+#define NUM_SPI_FLASHES 4
+
 #define MEMORY_BASEADDR 0x50000000
 #define FLASH_BASEADDR 0x86000000
 #define INTC_BASEADDR 0x81800000
@@ -79,6 +82,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
     MemoryRegion *address_space_mem = get_system_memory();
     DeviceState *dev, *dma, *eth0;
     MicroBlazeCPU *cpu;
+    SysBusDevice *busdev;
     CPUMBState *env;
     DriveInfo *dinfo;
     int i;
@@ -139,6 +143,29 @@ petalogix_ml605_init(ram_addr_t ram_size,
     xilinx_axiethernetdma_init(dma, STREAM_SLAVE(eth0),
                                0x84600000, irq[1], irq[0], 100 * 1000000);
 
+    {
+        SSIBus *spi;
+
+        dev = qdev_create(NULL, "xlnx.xps-spi");
+        qdev_prop_set_uint8(dev, "num-ss-bits", 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 = (SSIBus *)qdev_get_child_bus(dev, "spi");
+
+        for (i = 0; i < NUM_SPI_FLASHES; i++) {
+            qemu_irq cs_line;
+
+            dev = ssi_create_slave_no_init(spi, "m25p80");
+            qdev_prop_set_string(dev, "partname", "n25q128");
+            qdev_init_nofail(dev);
+            cs_line = qdev_get_gpio_in(dev, 0);
+            sysbus_connect_irq(busdev, i+1, cs_line);
+        }
+    }
+
     microblaze_load_kernel(cpu, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
                                                             machine_cpu_reset);
 
Signature · 1 line
1.7.0.4
#11 lore raw

PATCH v8 11/14 xilinx_spips: Xilinx Zynq SPI cntrlr device model

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added device model for the Xilinx Zynq SPI controller (SPIPS).

---
Changed from v7:
Fixed &->&& logic on if condition is cs_select logic Fixed MODE_SEL bit field definition
Changed from v6:
Addressed Blue Swirl review s/interupt/interrupt
s/defintion/definition
constified TypeInfo

 hw/arm/Makefile.objs |    1 +
 hw/xilinx_spips.c    |  352 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 353 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spips.c
hw/arm/Makefile.objs +1 -0
index 2b39fb3..6d049e7 100644
@@ -1,6 +1,7 @@
 obj-y = integratorcp.o versatilepb.o arm_pic.o
 obj-y += arm_boot.o
 obj-y += xilinx_zynq.o zynq_slcr.o
+obj-y += xilinx_spips.o
 obj-y += arm_gic.o arm_gic_common.o
 obj-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
hw/xilinx_spips.c new file +352 -0

352 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#12 lore raw

PATCH v8 12/14 xilinx_zynq: Added SPI controllers + flashes

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added the two SPI controllers to the zynq machine model. Attached two SPI flash devices to each controller.

---
changed from v7:
Increased number of spi flashes pre controller to 4 changed from v6:
removed (char*) cast to qdev_prop_set_string argument

 hw/xilinx_zynq.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
hw/xilinx_zynq.c +34 -0
index 7e6c273..fd46ba2 100644
@@ -24,6 +24,9 @@
 #include "flash.h"
 #include "blockdev.h"
 #include "loader.h"
+#include "ssi.h"
+
+#define NUM_SPI_FLASHES 4
 
 #define FLASH_SIZE (64 * 1024 * 1024)
 #define FLASH_SECTOR_SIZE (128 * 1024)
@@ -46,6 +49,34 @@ static void gem_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     sysbus_connect_irq(s, 0, irq);
 }
 
+static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq)
+{
+    DeviceState *dev;
+    SysBusDevice *busdev;
+    SSIBus *spi;
+    int i;
+
+    dev = qdev_create(NULL, "xilinx,spips");
+    qdev_init_nofail(dev);
+    busdev = sysbus_from_qdev(dev);
+    sysbus_mmio_map(busdev, 0, base_addr);
+    sysbus_connect_irq(busdev, 0, irq);
+
+    spi = (SSIBus *)qdev_get_child_bus(dev, "spi");
+
+    for (i = 0; i < NUM_SPI_FLASHES; ++i) {
+        qemu_irq cs_line;
+
+        dev = ssi_create_slave_no_init(spi, "m25p80");
+        qdev_prop_set_string(dev, "partname", "n25q128");
+        qdev_init_nofail(dev);
+
+        cs_line = qdev_get_gpio_in(dev, 0);
+        sysbus_connect_irq(busdev, i+1, cs_line);
+    }
+
+}
+
 static void zynq_init(ram_addr_t ram_size, const char *boot_device,
                         const char *kernel_filename, const char *kernel_cmdline,
                         const char *initrd_filename, const char *cpu_model)
@@ -113,6 +144,9 @@ static void zynq_init(ram_addr_t ram_size, const char *boot_device,
         pic[n] = qdev_get_gpio_in(dev, n);
     }
 
+    zynq_init_spi_flashes(0xE0006000, pic[58-IRQ_OFFSET]);
+    zynq_init_spi_flashes(0xE0007000, pic[81-IRQ_OFFSET]);
+
     sysbus_create_simple("cadence_uart", 0xE0000000, pic[59-IRQ_OFFSET]);
     sysbus_create_simple("cadence_uart", 0xE0001000, pic[82-IRQ_OFFSET]);
 
Signature · 1 line
1.7.0.4
#13 lore raw

PATCH v8 13/14 MAINTAINERS: Added maintainerships for SSI

In reply to Peter Crosthwaite

From: Peter A. G. Crosthwaite <[email protected]>

Added maintainership for SSI, M25P80 and the Xilinx SPI controllers.

---

 MAINTAINERS |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
MAINTAINERS +8 -0
index 29aac4f..e25794b 100644
@@ -268,6 +268,7 @@ S: Maintained
 F: hw/xilinx_zynq.c
 F: hw/zynq_slcr.c
 F: hw/cadence_*
+F: hw/xilinx_spips.c
 
 CRIS Machines
 -------------
@@ -469,6 +470,12 @@ M: Paul Brook <[email protected]>
 S: Odd Fixes
 F: hw/lsi53c895a.c
 
+SSI
+M: Peter Crosthwaite <[email protected]>
+S: Maintained
+F: hw/ssi.*
+F: hw/m25p80.c
+
 USB
 M: Gerd Hoffmann <[email protected]>
 S: Maintained
@@ -517,6 +524,7 @@ F: hw/xilinx_intc.c
 F: hw/xilinx_ethlite.c
 F: hw/xilinx_timer.c
 F: hw/xilinx.h
+F: hw/xilinx_spi.c
 
 Subsystems
 ----------
Signature · 1 line
1.7.0.4
#14 lore raw

PATCH v8 14/14 ssi: Add slave autoconnect helper

In reply to Peter Crosthwaite

Added helper function to automatically connect SPI slaves based on the QOM child nodes of a device. A SSI master device can call this routine to automatically hook-up all child nodes to its SPI bus.

---

 hw/ssi.c          |   33 +++++++++++++++++++++++++++++++++
 hw/ssi.h          |    4 ++++
 hw/xilinx_spi.c   |    6 ++++--
 hw/xilinx_spips.c |    4 +++-
 4 files changed, 44 insertions(+), 3 deletions(-)
hw/ssi.c +33 -0
index c47419d..2b56357 100644
@@ -139,3 +139,36 @@ static void ssi_slave_register_types(void)
 }
 
 type_init(ssi_slave_register_types)
+
+typedef struct SSIAutoConnectArg {
+    qemu_irq **cs_linep;
+    SSIBus *bus;
+} SSIAutoConnectArg;
+
+static int ssi_auto_connect_slave(Object *child, void *opaque)
+{
+    SSIAutoConnectArg *arg = opaque;
+    SSISlave *dev = (SSISlave *)object_dynamic_cast(child, TYPE_SSI_SLAVE);
+    qemu_irq cs_line;
+
+    if (!dev) {
+        return 0;
+    }
+
+    cs_line = qdev_get_gpio_in(DEVICE(dev), 0);
+    qdev_set_parent_bus(DEVICE(dev), &arg->bus->qbus);
+    **arg->cs_linep = cs_line;
+    (*arg->cs_linep)++;
+    return 0;
+}
+
+void ssi_auto_connect_slaves(DeviceState *parent, qemu_irq *cs_line,
+                             SSIBus *bus)
+{
+    SSIAutoConnectArg arg = {
+        .cs_linep = &cs_line,
+        .bus = bus
+    };
+
+    object_child_foreach(OBJECT(parent), ssi_auto_connect_slave, &arg);
+}
hw/ssi.h +4 -0
index 2bde9f5..a05d60b 100644
@@ -83,6 +83,10 @@ SSIBus *ssi_create_bus(DeviceState *parent, const char *name);
 
 uint32_t ssi_transfer(SSIBus *bus, uint32_t val);
 
+/* Automatically connect all children nodes a spi controller as slaves */
+void ssi_auto_connect_slaves(DeviceState *parent, qemu_irq *cs_lines,
+                             SSIBus *bus);
+
 /* max111x.c */
 void max111x_set_input(DeviceState *dev, int line, uint8_t value);
 
hw/xilinx_spi.c +4 -2
index 0ace004..7f405d1 100644
@@ -320,8 +320,12 @@ static int xilinx_spi_init(SysBusDevice *dev)
     XilinxSPI *s = FROM_SYSBUS(typeof(*s), dev);
 
     DB_PRINT("\n");
+
+    s->spi = ssi_create_bus(&dev->qdev, "spi");
+
     sysbus_init_irq(dev, &s->irq);
     s->cs_lines = g_new(qemu_irq, s->num_cs);
+    ssi_auto_connect_slaves(DEVICE(s), s->cs_lines, s->spi);
     for (i = 0; i < s->num_cs; ++i) {
         sysbus_init_irq(dev, &s->cs_lines[i]);
     }
@@ -331,8 +335,6 @@ static int xilinx_spi_init(SysBusDevice *dev)
 
     s->irqline = -1;
 
-    s->spi = ssi_create_bus(&dev->qdev, "spi");
-
     fifo8_create(&s->tx_fifo, FIFO_CAPACITY);
     fifo8_create(&s->rx_fifo, FIFO_CAPACITY);
 
hw/xilinx_spips.c +3 -1
index a886c5d..f64a782 100644
@@ -289,6 +289,9 @@ static int xilinx_spips_init(SysBusDevice *dev)
 
     DB_PRINT("inited device model\n");
 
+    s->spi = ssi_create_bus(&dev->qdev, "spi");
+
+    ssi_auto_connect_slaves(DEVICE(s), s->cs_lines, s->spi);
     sysbus_init_irq(dev, &s->irq);
     for (i = 0; i < NUM_CS_LINES; ++i) {
         sysbus_init_irq(dev, &s->cs_lines[i]);
@@ -298,7 +301,6 @@ static int xilinx_spips_init(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->iomem);
 
     s->irqline = -1;
-    s->spi = ssi_create_bus(&dev->qdev, "spi");
 
     fifo8_create(&s->rx_fifo, RXFF_A);
     fifo8_create(&s->tx_fifo, TXFF_A);
Signature · 1 line
1.7.0.4