Skip to contentSkip to conversation

SPI bus support + Xilinx SPI controller

PATCH New Peter A. G. Crosthwaite 1 participant 5 messages Apr 3, 2012

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

v2 cover SPI bus support + Xilinx SPI controller

Add support for Serial Peripheral interface (SPI) as a proper bus standard. Includes an example device (m25p80 SPI flash), an example controller (Xilinx XPS SPI) and adds it to all to a machine model (petalogix_ml605_mmu.c).

Patch 1 adds the Serial Peripheral Interface (SPI) protocol as a bus and defines a QOM type for slave devices. The approach to doing this is based loosely on the existing I2C QOMification.

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 spi 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 one m25p80 to it.

CHANGELOG:
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 (4):
SPI: initial support
m25p80: initial verion
xilinx_spi: initial version
petalogix-ml605: added spi controller with m25p80

 Makefile.objs            |    2 +-
 Makefile.target          |    2 +
 hw/m25p80.c              |  397 ++++++++++++++++++++++++++++++++++++++
 hw/petalogix_ml605_mmu.c |   19 ++
 hw/spi.c                 |  148 ++++++++++++++
 hw/spi.h                 |   69 +++++++
 hw/xilinx_spi.c          |  482 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 1118 insertions(+), 1 deletions(-)
 create mode 100644 hw/m25p80.c
 create mode 100644 hw/spi.c
 create mode 100644 hw/spi.h
 create mode 100644 hw/xilinx_spi.c
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH v2 1/4 SPI: initial support

Defined SPI bus and SPI slave QOM interfaces. Inspired by and loosely based on existing I2C framework.

---
changed from v1:
minor sylistic changes
converted spi api to modified txrx style

 Makefile.objs |    2 +-
 hw/spi.c      |  148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/spi.h      |   69 ++++++++++++++++++++++++++
 3 files changed, 218 insertions(+), 1 deletions(-)
 create mode 100644 hw/spi.c
 create mode 100644 hw/spi.h
Makefile.objs +1 -1
index 226b01d..45eb20f 100644
@@ -116,7 +116,7 @@ common-obj-$(CONFIG_SSD0323) += ssd0323.o
 common-obj-$(CONFIG_ADS7846) += ads7846.o
 common-obj-$(CONFIG_MAX111X) += max111x.o
 common-obj-$(CONFIG_DS1338) += ds1338.o
-common-obj-y += i2c.o smbus.o smbus_eeprom.o
+common-obj-y += i2c.o smbus.o smbus_eeprom.o spi.o
 common-obj-y += eeprom93xx.o
 common-obj-y += scsi-disk.o cdrom.o
 common-obj-y += scsi-generic.o scsi-bus.o
hw/spi.c new file +148 -0

148 lines not on this page · raw message

hw/spi.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#2 lore raw

PATCH v2 2/4 m25p80: initial verion

In reply to Peter A. G. Crosthwaite

Added device model for m25p80 SPI flash

---
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     |  397 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 398 insertions(+), 0 deletions(-)
 create mode 100644 hw/m25p80.c
Makefile.target +1 -0
index 44b2e83..6c568b4 100644
@@ -320,6 +320,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 +397 -0

397 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#3 lore raw

PATCH v2 3/4 xilinx_spi: initial version

In reply to Peter A. G. Crosthwaite

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

---
changed from v1:
converted spi api to modified txrx style

 Makefile.target |    1 +
 hw/xilinx_spi.c |  482 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 483 insertions(+), 0 deletions(-)
 create mode 100644 hw/xilinx_spi.c
Makefile.target +1 -0
index 6c568b4..be28bfe 100644
@@ -321,6 +321,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 +482 -0

482 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#4 lore raw

PATCH v2 4/4 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

---
 hw/petalogix_ml605_mmu.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
hw/petalogix_ml605_mmu.c +19 -0
index 31a4348..58b90cc 100644
@@ -36,6 +36,7 @@
 #include "blockdev.h"
 #include "pc.h"
 #include "exec-memory.h"
+#include "spi.h"
 
 #include "microblaze_boot.h"
 #include "microblaze_pic_cpu.h"
@@ -75,6 +76,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 +133,23 @@ petalogix_ml605_init(ram_addr_t ram_size,
                                      irq[1], irq[0], 100 * 1000000);
     }
 
+    {
+        SPIBus *spi;
+
+        dev = qdev_create(NULL, "xilinx,spi");
+        qdev_prop_set_uint8(dev, "num-cs", 1);
+        qdev_init_nofail(dev);
+        busdev = sysbus_from_qdev(dev);
+        sysbus_mmio_map(busdev, 0, 0x40a00000);
+        sysbus_connect_irq(busdev, 0, irq[6]);
+
+        spi = FROM_QBUS(SPIBus, qdev_get_child_bus(dev, "spi"));
+
+        dev = qdev_create(NULL, "m25p80");
+        qdev_init_nofail(dev);
+        spi_attach_slave(spi, SPI_SLAVE(dev), 0);
+    }
+
     microblaze_load_kernel(env, ddr_base, ram_size, BINARY_DEVICE_TREE_FILE,
                                                             machine_cpu_reset);
 
Signature · 1 line
1.7.3.2