clearfog: kernel: rework spidev handling for OCM
This is all about how to get spidev to export a SPI device to userspace.
We switched to a udev-style control last fall, but one upstream patch
which was supposed to provide auto-driver-bind in response to a udev
rule which sets the `driver_override` attribute has not been merged yet.
See [1] for reasons why it might not get merged, ever.
Adjust the userspace to bind a driver from within udev.
[1] https://www.spinics.net/lists/linux-spi/msg16384.html
Change-Id: I26f839ece7881baf56b8f0705623024e117a3a02
diff --git a/board/czechlight/clearfog/linux.fragment b/board/czechlight/clearfog/linux.fragment
index f2249a3..2da25d2 100644
--- a/board/czechlight/clearfog/linux.fragment
+++ b/board/czechlight/clearfog/linux.fragment
@@ -39,3 +39,5 @@
CONFIG_MV643XX_ETH=n
CONFIG_KEYBOARD_ATKBD=N
CONFIG_INPUT_MOUSE=N
+
+CONFIG_LOCALVERSION="-9-g0cd0cb35cf72"
diff --git a/board/czechlight/clearfog/overlay/usr/lib/udev/rules.d/40-spi-lumentum-ocm.rules b/board/czechlight/clearfog/overlay/usr/lib/udev/rules.d/40-spi-lumentum-ocm.rules
index 0a6b2f5..206c375 100644
--- a/board/czechlight/clearfog/overlay/usr/lib/udev/rules.d/40-spi-lumentum-ocm.rules
+++ b/board/czechlight/clearfog/overlay/usr/lib/udev/rules.d/40-spi-lumentum-ocm.rules
@@ -1 +1,2 @@
-ACTION=="add|change", SUBSYSTEM=="spi", ENV{MODALIAS}=="spi:lumentum-ocm", ATTR{driver_override}+="spidev"
+# cannot use ATTR{driver_override}+="spidev" because it apparently only runs after the PROGRAM
+ACTION=="add|change", SUBSYSTEM=="spi", ENV{MODALIAS}=="spi:lumentum-ocm", PROGRAM+="/bin/sh -c 'echo spidev > %S%p/driver_override && echo %k > %S%p/subsystem/drivers/spidev/bind'"
diff --git a/board/czechlight/clearfog/patches/linux.patch b/board/czechlight/clearfog/patches/linux.patch
index d975bf6..fe205b1 100644
--- a/board/czechlight/clearfog/patches/linux.patch
+++ b/board/czechlight/clearfog/patches/linux.patch
@@ -487,28 +487,3 @@
/*
* Only map one page for direct access. This is enough for the
* simple TX transfer which only writes to the first word.
-diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
-index 9a7def7c3237..1c618bd5b55c 100644
---- a/drivers/spi/spi.c
-+++ b/drivers/spi/spi.c
-@@ -75,6 +75,7 @@ static ssize_t driver_override_store(struct device *dev,
- const char *end = memchr(buf, '\n', count);
- const size_t len = end ? end - buf : count;
- const char *driver_override, *old;
-+ int ret;
-
- /* We need to keep extra room for a newline when displaying value */
- if (len >= (PAGE_SIZE - 1))
-@@ -96,6 +97,12 @@ static ssize_t driver_override_store(struct device *dev,
- device_unlock(dev);
- kfree(old);
-
-+ /* Attach device to new driver if it's not already attached */
-+ ret = device_attach(dev);
-+ if (ret < 0 && ret != -EPROBE_DEFER)
-+ dev_warn(dev, "device attach to '%s' failed (%d)\n",
-+ spi->driver_override, ret);
-+
- return count;
- }
-