periphery: bus api update (#50)
[sifive-blocks.git] / src / main / scala / devices / spi / SPIPeriphery.scala
index dd76d15db4df1ca8149bef39a53c55f0b8cb2478..37fe3d9081beff59aa9106bc287b09c6acc952c9 100644 (file)
@@ -3,18 +3,19 @@ package sifive.blocks.devices.spi
 
 import Chisel._
 import freechips.rocketchip.config.Field
-import freechips.rocketchip.coreplex.{HasPeripheryBus, HasInterruptBus}
+import freechips.rocketchip.subsystem.BaseSubsystem
 import freechips.rocketchip.diplomacy.{LazyModule,LazyModuleImp,BufferParams}
 import freechips.rocketchip.tilelink.{TLFragmenter,TLBuffer}
 import freechips.rocketchip.util.HeterogeneousBag
 
 case object PeripherySPIKey extends Field[Seq[SPIParams]]
 
-trait HasPeripherySPI extends HasPeripheryBus with HasInterruptBus {
+trait HasPeripherySPI { this: BaseSubsystem =>
   val spiParams = p(PeripherySPIKey)  
-  val spis = spiParams map { params =>
-    val spi = LazyModule(new TLSPI(pbus.beatBytes, params))
-    spi.rnode := pbus.toVariableWidthSlaves
+  val spis = spiParams.zipWithIndex.map { case(params, i) =>
+    val name = Some(s"spi_$i")
+    val spi = LazyModule(new TLSPI(pbus.beatBytes, params)).suggestName(name)
+    pbus.toVariableWidthSlave(name) { spi.rnode }
     ibus.fromSync := spi.intnode
     spi
   }
@@ -36,15 +37,16 @@ trait HasPeripherySPIModuleImp extends LazyModuleImp with HasPeripherySPIBundle
 
 case object PeripherySPIFlashKey extends Field[Seq[SPIFlashParams]]
 
-trait HasPeripherySPIFlash extends HasPeripheryBus with HasInterruptBus {
+trait HasPeripherySPIFlash { this: BaseSubsystem =>
   val spiFlashParams = p(PeripherySPIFlashKey)  
-  val qspis = spiFlashParams map { params =>
+  val qspis = spiFlashParams.zipWithIndex.map { case(params, i) =>
+    val name = Some(s"qspi_$i")
     val qspi = LazyModule(new TLSPIFlash(pbus.beatBytes, params))
-    qspi.rnode := pbus.toVariableWidthSlaves
-    (qspi.fnode
-      := TLFragmenter(1, pbus.blockBytes)
-      := TLBuffer(BufferParams(params.fBufferDepth), BufferParams.none)
-      := pbus.toFixedWidthSlaves)
+    pbus.toVariableWidthSlave(name) { qspi.rnode }
+    qspi.fnode := pbus.toFixedWidthSlave(name) {
+      TLFragmenter(1, pbus.blockBytes) :=
+        TLBuffer(BufferParams(params.fBufferDepth), BufferParams.none)
+    }
     ibus.fromSync := qspi.intnode
     qspi
   }