mirror of
https://git.openwrt.org/openwrt/openwrt.git
synced 2025-05-23 14:48:07 +00:00
Manually rebuild pending patches: - 103-kbuild-export-SUBARCH.patch - 141-jffs2-add-RENAME_EXCHANGE-support.patch - 200-ARM-9404-1-arm32-fix-boot-hang-with-HAVE_LD_DEAD_COD.patch - 203-kallsyms_uncompressed.patch - 270-platform-mikrotik-build-bits.patch - 308-mips32r2_tune.patch - 330-MIPS-kexec-Accept-command-line-parameters-from-users.patch - 402-mtd-spi-nor-write-support-for-minor-aligned-partitions.patch - 451-block-partitions-populate-fwnode.patch - 476-mtd-spi-nor-add-eon-en25q128.patch - 477-mtd-spi-nor-add-eon-en25qx128a.patch - 479-mtd-spi-nor-add-xtx-xt25f128b.patch - 481-mtd-spi-nor-add-support-for-Gigadevice-GD25D05.patch - 482-mtd-spi-nor-add-gd25q512.patch - 484-mtd-spi-nor-add-esmt-f25l16pa.patch - 485-mtd-spi-nor-add-xmc-xm25qh128c.patch - 488-mtd-spi-nor-add-xmc-xm25qh64c.patch - 490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch - 497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch - 498-mtd-spi-nor-locking-support-for-MX25L6405D.patch - 510-block-add-uImage.FIT-subimage-block-driver.patch - 530-jffs2_make_lzma_available.patch - 630-packet_socket_type.patch - 666-Add-support-for-MAP-E-FMRs-mesh-mode.patch - 681-net-remove-NETIF_F_GSO_FRAGLIST-from-NETIF_F_GSO_SOF.patch - 700-netfilter-nft_flow_offload-handle-netdevice-events-f.patch - 702-net-ethernet-mtk_eth_soc-enable-threaded-NAPI.patch - 706-net-phy-populate-host_interfaces-when-attaching-PHY.patch - 711-03-net-dsa-qca8k-add-support-for-port_change_master.patch - 734-net-ethernet-mediatek-enlarge-DMA-reserve-buffer.patch - 736-03-net-ethernet-mtk_eth_soc-improve-keeping-track-of-of.patch - 737-net-ethernet-mtk_eth_soc-add-paths-and-SerDes-modes-.patch - 739-03-net-pcs-pcs-mtk-lynxi-add-platform-driver-for-MT7988.patch - 801-gpio-gpio-cascade-add-generic-GPIO-cascade.patch - 809-01-nvmem-core-generalize-mac-base-cells-handling.patch - 811-pci_disable_usb_common_quirks.patch - 834-ledtrig-libata.patch - 892-leds-Add-LED1202-I2C-driver.patch - 920-mangle_bootargs.patch Co-authored-by: Aditya Nugraha <vortexilation@gmail.com> Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com> [ improve commit title + minor fixes ] Link: https://github.com/openwrt/openwrt/pull/16547 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
218 lines
7.1 KiB
Diff
218 lines
7.1 KiB
Diff
From fc23ea48ba52c24f201fe5ca0132ee1a3de5a70a Mon Sep 17 00:00:00 2001
|
|
From: Mauri Sandberg <maukka@ext.kapsi.fi>
|
|
Date: Thu, 25 Mar 2021 11:48:05 +0200
|
|
Subject: [PATCH 2/2] gpio: gpio-cascade: add generic GPIO cascade
|
|
|
|
Adds support for building cascades of GPIO lines. That is, it allows
|
|
setups when there is one upstream line and multiple cascaded lines, out
|
|
of which one can be chosen at a time. The status of the upstream line
|
|
can be conveyed to the selected cascaded line or, vice versa, the status
|
|
of the cascaded line can be conveyed to the upstream line.
|
|
|
|
A multiplexer is being used to select, which cascaded GPIO line is being
|
|
used at any given time.
|
|
|
|
At the moment only input direction is supported. In future it should be
|
|
possible to add support for output direction, too.
|
|
|
|
Signed-off-by: Mauri Sandberg <maukka@ext.kapsi.fi>
|
|
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
|
|
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
|
|
---
|
|
v7 -> v8:
|
|
- rearrange members in struct gpio_cascade
|
|
- cosmetic changes in file header and in one function declaration
|
|
- added Reviewed-by tags by Linus and Andy
|
|
v6 -> v7:
|
|
- In Kconfig add info about module name
|
|
- adhere to new convention that allows lines longer than 80 chars
|
|
- use dev_probe_err with upstream gpio line too
|
|
- refactor for cleaner exit of probe function.
|
|
v5 -> v6:
|
|
- In Kconfig, remove dependency to OF_GPIO and select only MULTIPLEXER
|
|
- refactor code preferring one-liners
|
|
- clean up prints, removing them from success-path.
|
|
- don't explicitly set gpio_chip.of_node as it's done in the GPIO library
|
|
- use devm_gpiochip_add_data instead of gpiochip_add
|
|
v4 -> v5:
|
|
- renamed gpio-mux-input -> gpio-cascade. refactored code accordingly
|
|
here and there and changed to use new bindings and compatible string
|
|
- ambigious and vague 'pin' was rename to 'upstream_line'
|
|
- dropped Tested-by and Reviewed-by due to changes in bindings
|
|
- dropped Reported-by suggested by an automatic bot as it was not really
|
|
appropriate to begin with
|
|
- functionally it's the same as v4
|
|
v3 -> v4:
|
|
- Changed author email
|
|
- Included Tested-by and Reviewed-by from Drew
|
|
v2 -> v3:
|
|
- use managed device resources
|
|
- update Kconfig description
|
|
v1 -> v2:
|
|
- removed .owner from platform_driver as per test bot's instruction
|
|
- added MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE
|
|
- added gpio_mux_input_get_direction as it's recommended for all chips
|
|
- removed because this is input only chip: gpio_mux_input_set_value
|
|
- removed because they are not needed for input/output only chips:
|
|
gpio_mux_input_direction_input
|
|
gpio_mux_input_direction_output
|
|
- fixed typo in an error message
|
|
- added info message about successful registration
|
|
- removed can_sleep flag as this does not sleep while getting GPIO value
|
|
like I2C or SPI do
|
|
- Updated description in Kconfig
|
|
---
|
|
drivers/gpio/Kconfig | 15 +++++
|
|
drivers/gpio/Makefile | 1 +
|
|
drivers/gpio/gpio-cascade.c | 117 ++++++++++++++++++++++++++++++++++++
|
|
3 files changed, 133 insertions(+)
|
|
create mode 100644 drivers/gpio/gpio-cascade.c
|
|
|
|
--- a/drivers/gpio/Kconfig
|
|
+++ b/drivers/gpio/Kconfig
|
|
@@ -1929,4 +1929,19 @@ config GPIO_VIRTUSER
|
|
|
|
endmenu
|
|
|
|
+comment "Other GPIO expanders"
|
|
+
|
|
+config GPIO_CASCADE
|
|
+ tristate "General GPIO cascade"
|
|
+ select MULTIPLEXER
|
|
+ help
|
|
+ Say yes here to enable support for generic GPIO cascade.
|
|
+
|
|
+ This allows building one-to-many cascades of GPIO lines using
|
|
+ different types of multiplexers readily available. At the
|
|
+ moment only input lines are supported.
|
|
+
|
|
+ To build the driver as a module choose 'm' and the resulting module
|
|
+ will be called 'gpio-cascade'.
|
|
+
|
|
endif
|
|
--- a/drivers/gpio/Makefile
|
|
+++ b/drivers/gpio/Makefile
|
|
@@ -45,6 +45,7 @@ obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd
|
|
obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o
|
|
obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
|
|
obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o
|
|
+obj-$(CONFIG_GPIO_CASCADE) += gpio-cascade.o
|
|
obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
|
|
obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o
|
|
obj-$(CONFIG_GPIO_CROS_EC) += gpio-cros-ec.o
|
|
--- /dev/null
|
|
+++ b/drivers/gpio/gpio-cascade.c
|
|
@@ -0,0 +1,112 @@
|
|
+// SPDX-License-Identifier: GPL-2.0-only
|
|
+/*
|
|
+ * A generic GPIO cascade driver
|
|
+ *
|
|
+ * Copyright (C) 2021 Mauri Sandberg <maukka@ext.kapsi.fi>
|
|
+ *
|
|
+ * This allows building cascades of GPIO lines in a manner illustrated
|
|
+ * below:
|
|
+ *
|
|
+ * /|---- Cascaded GPIO line 0
|
|
+ * Upstream | |---- Cascaded GPIO line 1
|
|
+ * GPIO line ----+ | .
|
|
+ * | | .
|
|
+ * \|---- Cascaded GPIO line n
|
|
+ *
|
|
+ * A multiplexer is being used to select, which cascaded line is being
|
|
+ * addressed at any given time.
|
|
+ *
|
|
+ * At the moment only input mode is supported due to lack of means for
|
|
+ * testing output functionality. At least theoretically output should be
|
|
+ * possible with open drain constructions.
|
|
+ */
|
|
+
|
|
+#include <linux/module.h>
|
|
+#include <linux/slab.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/mux/consumer.h>
|
|
+
|
|
+#include <linux/gpio/consumer.h>
|
|
+#include <linux/gpio/driver.h>
|
|
+
|
|
+struct gpio_cascade {
|
|
+ struct gpio_chip gpio_chip;
|
|
+ struct device *parent;
|
|
+ struct mux_control *mux_control;
|
|
+ struct gpio_desc *upstream_line;
|
|
+};
|
|
+
|
|
+static int gpio_cascade_get_direction(struct gpio_chip *gc, unsigned int offset)
|
|
+{
|
|
+ return GPIO_LINE_DIRECTION_IN;
|
|
+}
|
|
+
|
|
+static int gpio_cascade_get_value(struct gpio_chip *gc, unsigned int offset)
|
|
+{
|
|
+ struct gpio_cascade *cas = gpiochip_get_data(gc);
|
|
+ int ret;
|
|
+
|
|
+ ret = mux_control_select(cas->mux_control, offset);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ ret = gpiod_get_value(cas->upstream_line);
|
|
+ mux_control_deselect(cas->mux_control);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+static int gpio_cascade_probe(struct platform_device *pdev)
|
|
+{
|
|
+ struct device *dev = &pdev->dev;
|
|
+ struct gpio_cascade *cas;
|
|
+ struct mux_control *mc;
|
|
+ struct gpio_desc *upstream;
|
|
+ struct gpio_chip *gc;
|
|
+
|
|
+ cas = devm_kzalloc(dev, sizeof(*cas), GFP_KERNEL);
|
|
+ if (!cas)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ mc = devm_mux_control_get(dev, NULL);
|
|
+ if (IS_ERR(mc))
|
|
+ return dev_err_probe(dev, PTR_ERR(mc), "unable to get mux-control\n");
|
|
+
|
|
+ cas->mux_control = mc;
|
|
+ upstream = devm_gpiod_get(dev, "upstream", GPIOD_IN);
|
|
+ if (IS_ERR(upstream))
|
|
+ return dev_err_probe(dev, PTR_ERR(upstream), "unable to claim upstream GPIO line\n");
|
|
+
|
|
+ cas->upstream_line = upstream;
|
|
+ cas->parent = dev;
|
|
+
|
|
+ gc = &cas->gpio_chip;
|
|
+ gc->get = gpio_cascade_get_value;
|
|
+ gc->get_direction = gpio_cascade_get_direction;
|
|
+ gc->base = -1;
|
|
+ gc->ngpio = mux_control_states(mc);
|
|
+ gc->label = dev_name(cas->parent);
|
|
+ gc->parent = cas->parent;
|
|
+ gc->owner = THIS_MODULE;
|
|
+
|
|
+ platform_set_drvdata(pdev, cas);
|
|
+ return devm_gpiochip_add_data(dev, &cas->gpio_chip, cas);
|
|
+}
|
|
+
|
|
+static const struct of_device_id gpio_cascade_id[] = {
|
|
+ { .compatible = "gpio-cascade" },
|
|
+ { /* sentinel */ }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, gpio_cascade_id);
|
|
+
|
|
+static struct platform_driver gpio_cascade_driver = {
|
|
+ .driver = {
|
|
+ .name = "gpio-cascade",
|
|
+ .of_match_table = gpio_cascade_id,
|
|
+ },
|
|
+ .probe = gpio_cascade_probe,
|
|
+};
|
|
+module_platform_driver(gpio_cascade_driver);
|
|
+
|
|
+MODULE_AUTHOR("Mauri Sandberg <maukka@ext.kapsi.fi>");
|
|
+MODULE_DESCRIPTION("Generic GPIO cascade");
|
|
+MODULE_LICENSE("GPL");
|