Message ID | 20220120135420.20504-1-d.kalashnikov@kodofon.vrn.ru |
---|---|
State | Changes Requested |
Delegated to: | Petr Štetiar |
Headers | show |
Series | [RFC] ath79: MikroTik RB912UAG-2HPnD: add initial value to SSR | expand |
Denis Kalashnikov <denis281089@gmail.com> [2022-01-20 16:54:20]: Hi, > diff --git a/target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch b/target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch > new file mode 100644 > index 0000000000..9dabb181b5 > --- /dev/null > +++ b/target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch > @@ -0,0 +1,20 @@ > +--- a/drivers/gpio/gpio-74x164.c > ++++ b/drivers/gpio/gpio-74x164.c > +@@ -145,6 +145,17 @@ static int gen_74x164_probe(struct spi_d > + chip->gpio_chip.parent = &spi->dev; > + chip->gpio_chip.owner = THIS_MODULE; > + > ++ /* > ++ * Read optional inital value of registers. First byte -- last register. > ++ * E.g. init-data = /bits/ 8 <0x01 0x1f 0x02>; > ++ */ > ++ ret = of_property_read_u8_array(spi->dev.of_node, "init-data", > ++ (u8 *)chip->buffer, (size_t)nregs); > ++ if (ret && ret != -EINVAL /* Not found */) { > ++ dev_err(&spi->dev, "Invalid 'init-data' property.\n"); > ++ return -EINVAL; > ++ } > ++ lets take this through upstream and backport solution accepted there, thanks. Cheers, Petr
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..b8dbe8b784 100644 --- a/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912uag-2hpnd.dts +++ b/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912uag-2hpnd.dts @@ -107,12 +107,6 @@ gpio-export { compatible = "gpio-export"; - beeper { - gpio-export,name = "beeper"; - gpio-export,output = <1>; /* Must be 1 to avoid EMI induced clicking noise */ - gpios = <&ssr 5 GPIO_ACTIVE_HIGH>; - }; - usb_power { gpio-export,name = "power-usb"; gpio-export,output = <1>; @@ -121,7 +115,7 @@ pcie_power { gpio-export,name = "power-pcie"; - gpio-export,output = <0>; + gpio-export,output = <1>; gpios = <&ssr 7 GPIO_ACTIVE_HIGH>; }; }; @@ -175,6 +169,12 @@ registers-number = <1>; reg = <1>; spi-max-frequency = <50000000>; + + /* + bit 7 -- pcie_power, bit 6 -- usb_power, bit 5 -- beeper + power (must be 1 to avoid EMI induced clicking noise) + */ + init-data = /bits/ 8 <0xe0>; }; }; diff --git a/target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch b/target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch new file mode 100644 index 0000000000..9dabb181b5 --- /dev/null +++ b/target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch @@ -0,0 +1,20 @@ +--- a/drivers/gpio/gpio-74x164.c ++++ b/drivers/gpio/gpio-74x164.c +@@ -145,6 +145,17 @@ static int gen_74x164_probe(struct spi_d + chip->gpio_chip.parent = &spi->dev; + chip->gpio_chip.owner = THIS_MODULE; + ++ /* ++ * Read optional inital value of registers. First byte -- last register. ++ * E.g. init-data = /bits/ 8 <0x01 0x1f 0x02>; ++ */ ++ ret = of_property_read_u8_array(spi->dev.of_node, "init-data", ++ (u8 *)chip->buffer, (size_t)nregs); ++ if (ret && ret != -EINVAL /* Not found */) { ++ dev_err(&spi->dev, "Invalid 'init-data' property.\n"); ++ return -EINVAL; ++ } ++ + mutex_init(&chip->lock); + + ret = __gen_74x164_write_config(chip);
From: Denis Kalashnikov <denis281089@gmail.com> ar71xx mach-rb91x.c and others set SSR init value through platform data (this ability is added to upstream drivers/gpio/gpio-74x164.c by 451-gpio-74x164-improve-platform-device-support.patch). When we ported RB912UAG-2HPnD to ath79, we used DTS gpio-exports instead. But this broke some mPCIe cards. To fix this we turn back to gpio-74x164 the ability to get an init value from DTS. Why is using DTS gpio-hog option not good in this case? Since then gpio-export of the hogged line is not working. But we need it, since with pcie_power and usb_power we can reset USB devices, e.g cell modems. Also move SSR beeper pin value from gpio-exports to SSR init value, since user should never change its value. Why did some mPCIe cards not work? RouterBoot leaves USB port power and mPCIe port power lines on the Serial Shift Register =1. In ar71xx firmware doesn't touch them - ssr has the same intial values in march init code. In ath79 we have a DTS instead, where gpio-export is used. When SSR has no explicit default value, it uses 0 and there is a short period when mPCIe and USP power lines are =0 (till gpio-export reasserts them). And MikroTik mPCIe Wi-Fi 5Hz card R11e-5HacT doesn't work: PCI driver when starts logs warning: "PCIe link is down", lspci shows no device, rescan (echo 1 > /sys/bus/pci/rescan) doesn't work. PCI controller (arch/mips/pci-ar724x) starts... and says: "PCIe link is down", remembers this in the internal link_up field and never re-check AR724x_PCI_RESET_LINK_UP register bit. When link_up is false, pci read/write handlers always return error. When I patched it to actually check link status before reading, I had kernel panic with Device bus error when trying to read Vendor ID from config register (see "MIPS: pci-ar724x: avoid data bus error due to a missing PCIe module" Gabor Juhos patch). It seems that we need to somehow reinit the PCI host controller. Or init it after gpio-exports. Or simply don't touch mPCIe power. We prefer the last option. Acknowledgments: Koen Vandeputte <koen.vandeputte@citymesh.com> Reported-by: Thomas Hühn <thomas.huehn@hs-nordhausen.de> Signed-off: Denis Kalashnikov <denis281089@gmail.com> --- ...9342_mikrotik_routerboard-912uag-2hpnd.dts | 14 ++++++------- .../451-gpio-74x164-init-val-support.patch | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 target/linux/ath79/patches-5.10/451-gpio-74x164-init-val-support.patch