[board][nelson] add selina device configuration

This adds the necessary radar bringup to the boardfile.

Change-Id: Ibaa85360c652a2048517426ab09c5eb59a1759bc
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/404869
Reviewed-by: Braden Kell <bradenkell@google.com>
Testability-Review: Braden Kell <bradenkell@google.com>
Commit-Queue: Sam Hansen <hansens@google.com>
diff --git a/src/devices/board/drivers/nelson/BUILD.gn b/src/devices/board/drivers/nelson/BUILD.gn
index 2d93661..dbe508d 100644
--- a/src/devices/board/drivers/nelson/BUILD.gn
+++ b/src/devices/board/drivers/nelson/BUILD.gn
@@ -29,6 +29,7 @@
     "nelson-pwm.cc",
     "nelson-sdio.cc",
     "nelson-securemem.cc",
+    "nelson-selina.cc",
     "nelson-spi.cc",
     "nelson-sysmem.cc",
     "nelson-tee.cc",
diff --git a/src/devices/board/drivers/nelson/nelson-gpio.cc b/src/devices/board/drivers/nelson/nelson-gpio.cc
index 1c14513..5058d97 100644
--- a/src/devices/board/drivers/nelson/nelson-gpio.cc
+++ b/src/devices/board/drivers/nelson/nelson-gpio.cc
@@ -98,6 +98,9 @@
     // For Bluetooth.
     {GPIO_SOC_WIFI_LPO_32k768},
     {GPIO_SOC_BT_REG_ON},
+    // For radar sensor.
+    {GPIO_SELINA_RESET},
+    {GPIO_SELINA_IRQ},
 };
 
 static const pbus_metadata_t gpio_metadata[] = {
diff --git a/src/devices/board/drivers/nelson/nelson-gpios.h b/src/devices/board/drivers/nelson/nelson-gpios.h
index e407ad8..78e06bc 100644
--- a/src/devices/board/drivers/nelson/nelson-gpios.h
+++ b/src/devices/board/drivers/nelson/nelson-gpios.h
@@ -26,6 +26,8 @@
 #define GPIO_SPICC1_SS0 S905D3_GPIOH(6)
 #define GPIO_SOC_WIFI_LPO_32k768 S905D3_GPIOX(16)
 #define GPIO_SOC_BT_REG_ON S905D3_GPIOX(17)
+#define GPIO_SELINA_RESET S905D3_GPIOH(2)
+#define GPIO_SELINA_IRQ S905D3_GPIOH(3)
 
 }  // namespace nelson
 
diff --git a/src/devices/board/drivers/nelson/nelson-selina.cc b/src/devices/board/drivers/nelson/nelson-selina.cc
new file mode 100644
index 0000000..67fbfb5
--- /dev/null
+++ b/src/devices/board/drivers/nelson/nelson-selina.cc
@@ -0,0 +1,66 @@
+// Copyright 2020 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "nelson-gpios.h"
+#include "nelson.h"
+
+#include <ddk/binding.h>
+#include <ddk/debug.h>
+#include <ddk/platform-defs.h>
+#include <zircon/status.h>
+
+namespace nelson {
+
+static constexpr zx_bind_inst_t root_match[] = {
+  BI_MATCH(),
+};
+
+static constexpr zx_bind_inst_t gpio_match[] = {
+  BI_ABORT_IF(NE, BIND_PROTOCOL, ZX_PROTOCOL_GPIO),
+  BI_MATCH_IF(EQ, BIND_GPIO_PIN, GPIO_SELINA_IRQ),
+};
+
+static constexpr zx_bind_inst_t spi_match[] = {
+  BI_ABORT_IF(NE, BIND_PROTOCOL, ZX_PROTOCOL_SPI),
+  BI_ABORT_IF(NE, BIND_PLATFORM_DEV_VID, PDEV_VID_INFINEON),
+  BI_ABORT_IF(NE, BIND_PLATFORM_DEV_PID, PDEV_PID_INFINEON_BGT60TR13C),
+  BI_MATCH_IF(EQ, BIND_PLATFORM_DEV_DID, PDEV_DID_RADAR_SENSOR),
+};
+
+static constexpr device_fragment_part_t gpio_fragment[] = {
+  {countof(root_match), root_match},
+  {countof(gpio_match), gpio_match},
+};
+
+static constexpr device_fragment_part_t spi_fragment[] = {
+  {countof(root_match), root_match},
+  {countof(spi_match), spi_match},
+};
+
+static constexpr device_fragment_t fragments[] = {
+  {countof(gpio_fragment), gpio_fragment},
+  {countof(spi_fragment), spi_fragment},
+};
+
+static constexpr zx_device_prop_t props[] = {
+  {BIND_PLATFORM_DEV_VID, 0, PDEV_VID_GENERIC},
+  {BIND_PLATFORM_DEV_PID, 0, PDEV_PID_NELSON},
+  {BIND_PLATFORM_DEV_DID, 0, PDEV_DID_RADAR_SENSOR},
+};
+
+static composite_device_desc_t composite_dev = []() {
+  composite_device_desc_t desc = {};
+  desc.props = props;
+  desc.props_count = countof(props);
+  desc.fragments = fragments;
+  desc.fragments_count = countof(fragments);
+  desc.coresident_device_index = 1;
+  return desc;
+}();
+
+zx_status_t Nelson::SelinaInit() {
+  return DdkAddComposite("selina", &composite_dev);
+}
+
+}  // namespace nelson
diff --git a/src/devices/board/drivers/nelson/nelson-spi.cc b/src/devices/board/drivers/nelson/nelson-spi.cc
index 7d72608..e01008d 100644
--- a/src/devices/board/drivers/nelson/nelson-spi.cc
+++ b/src/devices/board/drivers/nelson/nelson-spi.cc
@@ -130,6 +130,9 @@
     // SPICC1 clock enable @200MHz (fclk_div2(1GHz) / N(5)).  For final SCLK frequency, see
     // CONREG[16:18] in the SPI controller.  This clock config produces a SCLK frequency of 50MHz
     // assuming a default value for CONREG[16:18].
+    //
+    // Some timing instability was observed which may have been an individual board artifact.  To
+    // debug, consider configuring the SCLK=25MHz (i.e. set spicc1_cli_div(10)).
     buf->Write32(spicc1_clk_sel_fclk_div2 | spicc1_clk_en | spicc1_clk_div(5), HHI_SPICC_CLK_CNTL);
   }
 
diff --git a/src/devices/board/drivers/nelson/nelson.cc b/src/devices/board/drivers/nelson/nelson.cc
index 084b673..bd7c842 100644
--- a/src/devices/board/drivers/nelson/nelson.cc
+++ b/src/devices/board/drivers/nelson/nelson.cc
@@ -101,6 +101,10 @@
     zxlogf(ERROR, "SpiInit failed: %d", status);
   }
 
+  if ((status = SelinaInit()) != ZX_OK) {
+    zxlogf(ERROR, "SelinaInit failed: %d\n", status);
+  }
+
   if ((status = MaliInit()) != ZX_OK) {
     zxlogf(ERROR, "MaliInit failed: %d", status);
   }
diff --git a/src/devices/board/drivers/nelson/nelson.h b/src/devices/board/drivers/nelson/nelson.h
index 01ab38d..b4da77f 100644
--- a/src/devices/board/drivers/nelson/nelson.h
+++ b/src/devices/board/drivers/nelson/nelson.h
@@ -118,6 +118,7 @@
   zx_status_t SdioInit();
   zx_status_t Start();
   zx_status_t SecureMemInit();
+  zx_status_t SelinaInit();
   zx_status_t SpiInit();
   zx_status_t SysmemInit();
   zx_status_t TeeInit();