gen_devtree: Add LPC and mailbox nodes

Change-Id: I5a819de05702c6dd06d931a0821ab73a2497c55c
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/gen_devtree.pl b/gen_devtree.pl
index bb7c9b7..2b58203 100755
--- a/gen_devtree.pl
+++ b/gen_devtree.pl
@@ -38,6 +38,7 @@
     printUsage();
 }
 
+my $g_pnorNodeName = undef;
 my %g_configuration = %{ LoadFile($configFile) };
 
 my $g_targetObj = Targets->new;
@@ -70,9 +71,11 @@
 printRootNodeEnd($f, 0);
 
 printNodes($f, 0, getBMCFlashNodes());
-
 printNodes($f, 0, getOtherFlashNodes());
 
+printNode($f, 0, "lpc_ctrl", getLPCNode());
+printNode($f, 0, "mbox", getMBoxNode());
+
 printNodes($f, 0, getI2CNodes());
 printNodes($f, 0, getMacNodes());
 printNodes($f, 0, getUARTNodes());
@@ -436,13 +439,18 @@
 
     foreach my $unit (@units) {
 
-        my %node = getAST2500SpiMasterNode($unit);
+        my ($node, $foundPNOR) = getAST2500SpiMasterNode($unit);
 
-        if (keys %node) {
+        if (keys %$node) {
             my %spiNode;
             my $nodeName = "spi$unit";
-            $spiNode{$nodeName} = { %node };
+            $spiNode{$nodeName} = { %$node };
             push @nodes, { %spiNode };
+
+            #Save off the PNOR SPI node name for use by LPC node
+            if ($foundPNOR) {
+                $g_pnorNodeName = $nodeName;
+            }
         }
     }
 
@@ -467,6 +475,7 @@
     my $spiNum = shift;
     my %spiMaster;
     my $chipSelect = 0;
+    my $foundPNOR = 0;
 
     my $connections = $g_targetObj->findConnections($g_bmc, "SPI", "FLASH");
 
@@ -500,13 +509,63 @@
                                                       "SPI_FUNCTION");
             if ($function eq "PNOR") {
                 $spiMaster{$flashName}{label} = "pnor";
+                $foundPNOR = 1;
             }
 
             $chipSelect++;
         }
     }
 
-    return %spiMaster;
+    return (\%spiMaster, $foundPNOR);
+}
+
+
+#Returns a hash that represents the mbox node.
+#This node is used by the LPC mailbox device driver.
+#Only present if the LPC mailbox is enabled in the config file.
+#Node looks like:
+#  &mbox {
+#    status = "okay";
+#  }
+sub getMBoxNode
+{
+    my %node;
+    if (exists $g_configuration{"lpc-host-spi-flash-mailbox"}) {
+        $node{status} = "okay";
+    }
+
+    return %node;
+}
+
+
+#Returns a hash that represents the LPC node.
+#Only present if the LPC mailbox is enabled in the config file.
+#Node looks like:
+#  &lpc_ctrl {
+#     flash = <&spi1>;
+#     memory-region = <&flash_memory>;
+#     status = "okay";
+#};
+sub getLPCNode
+{
+    my %node;
+    if (exists $g_configuration{"lpc-host-spi-flash-mailbox"}) {
+
+        $node{status} = "okay";
+
+        #Point to the reserved-memory region label
+        $node{"memory-region"} = "<(ref)" .
+                                 HOST_SPI_FLASH_MEM_REGION_NODE_LABEL . ">";
+
+        if (not defined $g_pnorNodeName) {
+            die "The PNOR SPI flash node cannot be found but is required " .
+                "if the LPC mailbox is enabled.\n";
+        }
+
+        $node{flash} = "<(ref)$g_pnorNodeName>";
+    }
+
+    return %node;
 }