From a477a8729ca0232ca41d1463a1d95f49a5a1dbc9 Mon Sep 17 00:00:00 2001
From: Catherine <whitequark@whitequark.org>
Date: Sun, 22 Dec 2024 02:20:05 +0000
Subject: [PATCH] applet.interface.qspi_controller: pull up IO0/IO1 also.

This prevents reading 50/60 Hz noise from devices that do not drive
their outputs (e.g. a QSPI flash that boots in QPI mode).
---
 .../applet/interface/qspi_controller/__init__.py    | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/software/glasgow/applet/interface/qspi_controller/__init__.py b/software/glasgow/applet/interface/qspi_controller/__init__.py
index 4140a2809..cd5fa656f 100644
--- a/software/glasgow/applet/interface/qspi_controller/__init__.py
+++ b/software/glasgow/applet/interface/qspi_controller/__init__.py
@@ -264,9 +264,16 @@ def build(self, target, args):
 
     async def run(self, device, args):
         iface = await device.demultiplexer.claim_interface(self, self.mux_interface, args,
-            # Pull IO2 and IO3 high, since on QSPI flashes these correspond to WP# and HOLD#,
-            # and will interfere with operation in SPI mode. For other devices this is benign.
-            pull_high={args.pin_set_io[2], args.pin_set_io[3]})
+            pull_high={
+                # Pull IO2 and IO3 high, since on QSPI flashes these correspond to WP# and HOLD#,
+                # and will interfere with operation in SPI mode. For other devices this is benign.
+                args.pin_set_io[2], args.pin_set_io[3],
+                # Also pull IO0 and IO1 high. This prevents noise from changing bus state when
+                # the device is not selected (which should be benign but could cause issues with
+                # non-compliant devices). In addition, pulling IO1 up prevents reading garbage data
+                # from devices that do not drive it when selected.
+                args.pin_set_io[0], args.pin_set_io[1],
+            })
         qspi_iface = QSPIControllerInterface(iface, self.logger)
         return qspi_iface