On MikroTik RB91x board series a reset key shares SoC gpio
line #15 with NAND ALE and NAND IO7. So we need a custom
gpio driver to manage this non-trivial connection schema.
Also rb91x-nand needs to have an ability to disable a polling
of the key while it works with NAND.
While we've been integrating rb91x-key into a firmware, we've
figured out that:
* In the gpio-latch driver we need to add a "cansleep" suffix to
several gpiolib calls,
* When gpio-latch and rb91x-nand fail to get a gpio and an error
is -EPROBE_DEFER, they shouldn't report about this, since this
actually is not an error and occurs when the gpio-latch probe
function is called before the rb91x-key probe.
We fix these related things here too.
Signed-off-by: Denis Kalashnikov
---
Changelog:
v1 --> v2:
* Remove support for kernel 5.4,
* gpio-latch and rb91x-nand don't report about -EPROBE_DEFER.
---
target/linux/ath79/config-5.10| 1 +
...9342_mikrotik_routerboard-912uag-2hpnd.dts | 23 +-
.../ath79/files/drivers/gpio/gpio-latch.c | 10 +-
.../ath79/files/drivers/gpio/gpio-rb91x-key.c | 218 ++
.../files/drivers/mtd/nand/raw/rb91x_nand.c | 18 +-
target/linux/ath79/mikrotik/config-default| 1 +
.../patches-5.10/939-mikrotik-rb91x.patch | 19 ++
7 files changed, 282 insertions(+), 8 deletions(-)
create mode 100644 target/linux/ath79/files/drivers/gpio/gpio-rb91x-key.c
diff --git a/target/linux/ath79/config-5.10 b/target/linux/ath79/config-5.10
index 12f51b08ce..53f444c68b 100644
--- a/target/linux/ath79/config-5.10
+++ b/target/linux/ath79/config-5.10
@@ -74,6 +74,7 @@ CONFIG_GPIO_74X164=y
CONFIG_GPIO_ATH79=y
CONFIG_GPIO_GENERIC=y
# CONFIG_GPIO_LATCH is not set
+# CONFIG_GPIO_RB91X_KEY is not set
CONFIG_HANDLE_DOMAIN_IRQ=y
CONFIG_HARDWARE_WATCHPOINTS=y
CONFIG_HAS_DMA=y
diff --git
a/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912uag-2hpnd.dts
b/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912uag-2hpnd.dts
index 77a0d29113..b7ab1cacdb 100644
--- a/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912uag-2hpnd.dts
+++ b/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912uag-2hpnd.dts
@@ -16,6 +16,13 @@
led-upgrade = _power;
};
+ gpio_key: gpio_key {
+ compatible = "mikrotik,gpio-rb91x-key";
+ gpio-controller;
+ #gpio-cells = <2>;
+ gpio = < 15 GPIO_ACTIVE_HIGH>;
+ };
+
gpio_latch: gpio_latch {
compatible = "gpio-latch";
gpio-controller;
@@ -27,7 +34,7 @@
<0>, /* Not connected */
< 13 GPIO_ACTIVE_HIGH>,
< 14 GPIO_ACTIVE_HIGH>,
- < 15 GPIO_ACTIVE_HIGH>,
+ <_key 0 GPIO_ACTIVE_HIGH>,
< 11 GPIO_ACTIVE_LOW>; /* Latch Enable */
};
@@ -40,7 +47,8 @@
<_latch 6 GPIO_ACTIVE_HIGH>, /* Command Latch
Enable (CLE) */
<_latch 7 GPIO_ACTIVE_HIGH>, /* Address Latch
Enable (ALE) */
< 12 GPIO_ACTIVE_LOW>, /* Read/Write Enable
(nRW) */
- <_latch 8 GPIO_ACTIVE_LOW>; /* Latch Enable (nLE)
*/
+ <_latch 8 GPIO_ACTIVE_LOW>, /* Latch Enable (nLE)
*/
+ <_key 2 GPIO_ACTIVE_HIGH>; /* Key poll disable */
partitions {
compatible = "fixed-partitions";
@@ -64,6 +72,17 @@
};
};
+ keys {
+ compatible = "gpio-keys-polled";
+ poll-interval = <20>;
+
+ button@0 {
+ label = "reset";
+ linux,code = ;
+ gpios = <_key 1 GPIO_ACTIVE_LOW>;
+ };
+ };
+
leds {
compatible = "gpio-leds";
diff --git a/target/linux/ath79/files/drivers/gpio/gpio-latch.c
b/target/linux/ath79/files/drivers/gpio/gpio-latch.c
index f3545a663e..976e683230 100644
--- a/target/linux/ath79/files/drivers/gpio/gpio-latch.c
+++ b/target/linux/ath79/files/drivers/gpio/gpio-latch.c
@@ -62,7 +62,7 @@ gpio_latch_get(struct gpio_chip *gc, unsigned offset)
int ret;
gpio_latch_lock(glc, false);
- ret = gpiod_get_value(glc->gpios[offset]);
+ ret = gpiod_get_raw_value_cansleep(glc->gpios[offset]);
gpio_latch_unlock(glc, false);
return ret;
@@ -81,7 +81,7 @@ gpio_latch_set(struct gpio_chip *gc, unsigned offset, int
value)
}
gpio_latch_lock(glc, enable_latch);
- gpiod_set_raw_value(glc->gpios[offset], value);
+ gpiod_set_raw_value_cansleep(glc->gpios[offset], value);
gpio_latch_unlock(glc, disable_latch);
}
@@ -133,8 +133,10 @@ static int gpio_latch_probe(struct platform_device *pdev)
glc->gpios[i] = devm_gpiod_get_index_optional(dev, NULL, i,
GPIOD_OUT_LOW);