linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V4 0/2] Add Inverter controller for gpio configuration
@ 2019-06-28  5:20 Harish Jenny K N
  2019-06-28  5:20 ` [PATCH V4 1/2] gpio: inverter: " Harish Jenny K N
  2019-06-28  5:20 ` [PATCH V4 2/2] gpio: inverter: document the inverter bindings Harish Jenny K N
  0 siblings, 2 replies; 6+ messages in thread
From: Harish Jenny K N @ 2019-06-28  5:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, Harish Jenny K N, Balasubramani Vivekanandan

The purpose of this patchset is to provide a new inverter
gpio controller to configure the polarity of the gpio pins.
This driver enables the consumers to directly use the gpio pin
without worrying about the hardware level polarity configuration.
Polarity configuration will be done by the inverter gpio controller
based on device tree information.

This is created after the discussion in the thread
"gpio: set active-state of GPIO lines using device tree"
https://www.spinics.net/lists/linux-gpio/msg38829.html
to model inverters in the device tree to describe the hardware.

Thanks,
Harish.

---

Changes in V4:
- Addressed further review findings from Linus Walleij.

Changes in V3:
- Addressed review findings from Linus Walleij
to not use GPIO_ACTIVE_LOW.

Changes in V2:
- Addressed review findings from Linus Walleij, Phil Reid,
  Geert Uytterhoeven and Enrico Weigelt
- Implement can_sleep changes
- Changes not included
  Wrap some functions like .set_multiple/.get_multiple/.set_config.
 Reason: Not completely certain of the necessity in this driver
especially given gpio_chip_set_multiple and gpio_chip_get_multiple
functions in gpiolib handles when the callbacks are not set.
Also not sure of using gpiochip_generic_config as a callback function
or with some other implementation.

  Please let me know if they need to be implemented.

Harish Jenny K N (2):
  gpio: inverter: Add Inverter controller for gpio configuration
  gpio: inverter: document the inverter bindings

 .../devicetree/bindings/gpio/gpio-inverter.txt     |  29 +++++
 drivers/gpio/Kconfig                               |   9 ++
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-inverter.c                       | 128 +++++++++++++++++++++
 4 files changed, 167 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-inverter.txt
 create mode 100644 drivers/gpio/gpio-inverter.c

--
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V4 1/2] gpio: inverter: Add Inverter controller for gpio configuration
  2019-06-28  5:20 [PATCH V4 0/2] Add Inverter controller for gpio configuration Harish Jenny K N
@ 2019-06-28  5:20 ` Harish Jenny K N
  2019-06-28  8:55   ` Linus Walleij
  2019-06-28  5:20 ` [PATCH V4 2/2] gpio: inverter: document the inverter bindings Harish Jenny K N
  1 sibling, 1 reply; 6+ messages in thread
From: Harish Jenny K N @ 2019-06-28  5:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, Harish Jenny K N, Balasubramani Vivekanandan

Provides a new inverter gpio controller to configure the polarity
of the gpio pins. This driver enables the consumers to directly
use the gpio pin without worrying about the hardware level
polarity configuration. Polarity configuration will be done by
the inverter gpio controller based on device tree information.

Signed-off-by: Balasubramani Vivekanandan <balasubramani_vivekanandan@mentor.com>
Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 drivers/gpio/Kconfig         |   9 +++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-inverter.c | 128 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 drivers/gpio/gpio-inverter.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index acd40eb..8978047 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -77,6 +77,15 @@ config GPIO_GENERIC
 	depends on HAS_IOMEM # Only for IOMEM drivers
 	tristate

+config GPIO_INVERTER
+	tristate "Inverter GPIO controller for handling hardware inverters"
+	depends on OF_GPIO
+	help
+	 Enabling this configuration provides an inverter gpio controller to
+	 configure the polarity of the gpio pins.
+	 This enables the consumers to directly use the gpio pin without
+	 worrying about the hardware level polarity configuration.
+
 # put drivers in the right section, in alphabetical order

 # This symbol is selected by both I2C and SPI expanders
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 6700eee..b951b73 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_GPIO_HLWD)		+= gpio-hlwd.o
 obj-$(CONFIG_HTC_EGPIO)		+= gpio-htc-egpio.o
 obj-$(CONFIG_GPIO_ICH)		+= gpio-ich.o
 obj-$(CONFIG_GPIO_IOP)		+= gpio-iop.o
+obj-$(CONFIG_GPIO_INVERTER)	+= gpio-inverter.o
 obj-$(CONFIG_GPIO_IXP4XX)	+= gpio-ixp4xx.o
 obj-$(CONFIG_GPIO_IT87)		+= gpio-it87.o
 obj-$(CONFIG_GPIO_JANZ_TTL)	+= gpio-janz-ttl.o
diff --git a/drivers/gpio/gpio-inverter.c b/drivers/gpio/gpio-inverter.c
new file mode 100644
index 0000000..4883b33
--- /dev/null
+++ b/drivers/gpio/gpio-inverter.c
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Inverter GPIO controller for configuring the gpio polarity
+ *
+ * Copyright (c) 2019 Mentor Graphics Inc.
+ * Developed using gpiolib and gpio documentation as reference
+ *
+ */
+
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+struct gpio_inverter {
+	struct gpio_chip gpiochip;
+	int count;
+	struct gpio_desc *gpios[];
+};
+
+static int gpio_inverter_direction_input(struct gpio_chip *chip,
+					 unsigned int offset)
+{
+	struct gpio_inverter *inv = gpiochip_get_data(chip);
+
+	return gpiod_direction_input(inv->gpios[offset]);
+}
+
+static int gpio_inverter_direction_output(struct gpio_chip *chip,
+					  unsigned int offset, int value)
+{
+	struct gpio_inverter *inv = gpiochip_get_data(chip);
+
+	return gpiod_direction_output(inv->gpios[offset], value);
+}
+
+static int gpio_inverter_get(struct gpio_chip *chip,
+			     unsigned int offset)
+{
+	struct gpio_inverter *inv = gpiochip_get_data(chip);
+
+	return !gpiod_get_value(inv->gpios[offset]);
+}
+
+static void gpio_inverter_set(struct gpio_chip *chip,
+			      unsigned int offset, int value)
+{
+	struct gpio_inverter *inv = gpiochip_get_data(chip);
+
+	return gpiod_set_value(inv->gpios[offset], !value);
+}
+
+static int gpio_inverter_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct gpio_inverter *inv;
+	struct gpio_chip *gpio_chip;
+	struct gpio_desc *gpio;
+	int index = 0;
+	int count;
+	int ret;
+
+	count = gpiod_count(dev, "inverted");
+	if (count <= 0)
+		return count ? count : -ENOENT;
+
+	inv = devm_kzalloc(dev, struct_size(inv, gpios, count), GFP_KERNEL);
+	if (!inv)
+		return -ENOMEM;
+
+	inv->count = count;
+	gpio_chip = &inv->gpiochip;
+
+	platform_set_drvdata(pdev, inv);
+
+	while (index < count) {
+		gpio = devm_gpiod_get_index(dev, "inverted", index, GPIOD_ASIS);
+
+		if (gpio == ERR_PTR(-ENOENT))
+			return -EPROBE_DEFER;
+
+		if (IS_ERR(gpio))
+			return PTR_ERR(gpio);
+
+		inv->gpios[index++] = gpio;
+
+		if (!gpio_chip->can_sleep && gpiod_cansleep(gpio))
+			gpio_chip->can_sleep = true;
+	}
+
+	gpio_chip->direction_input = gpio_inverter_direction_input;
+	gpio_chip->direction_output = gpio_inverter_direction_output;
+	gpio_chip->get = gpio_inverter_get;
+	gpio_chip->set = gpio_inverter_set;
+	gpio_chip->label = dev_name(dev);
+	gpio_chip->parent = dev;
+	gpio_chip->owner = THIS_MODULE;
+	gpio_chip->base = -1;
+	gpio_chip->ngpio = count;
+
+	ret = devm_gpiochip_add_data(dev, gpio_chip, inv);
+	if (ret) {
+		dev_err(dev, "failed to add gpio controller\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id gpio_inverter_match[] = {
+	{ .compatible =	"gpio-inverter", }, { },
+};
+
+static struct platform_driver gpio_inverter_driver = {
+	.probe = gpio_inverter_probe,
+	.driver = {
+		.name = "gpio-inverter",
+		.of_match_table = of_match_ptr(gpio_inverter_match),
+	}
+};
+
+module_platform_driver(gpio_inverter_driver);
+
+MODULE_AUTHOR("Harish Jenny K N <harish_kandiga@mentor.com>");
+MODULE_AUTHOR("Balasubramani Vivekanandan <balasubramani_vivekanandan@mentor.com>");
+MODULE_DESCRIPTION("Inverter GPIO controller for configuring the gpio polarity");
+MODULE_LICENSE("GPL v2");
--
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH V4 2/2] gpio: inverter: document the inverter bindings
  2019-06-28  5:20 [PATCH V4 0/2] Add Inverter controller for gpio configuration Harish Jenny K N
  2019-06-28  5:20 ` [PATCH V4 1/2] gpio: inverter: " Harish Jenny K N
@ 2019-06-28  5:20 ` Harish Jenny K N
  1 sibling, 0 replies; 6+ messages in thread
From: Harish Jenny K N @ 2019-06-28  5:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, Harish Jenny K N, Balasubramani Vivekanandan

Document the device tree binding for the inverter gpio
controller to configure the polarity of the gpio pins
used by the consumers.

Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 .../devicetree/bindings/gpio/gpio-inverter.txt     | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-inverter.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-inverter.txt b/Documentation/devicetree/bindings/gpio/gpio-inverter.txt
new file mode 100644
index 0000000..8bb6b2e
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-inverter.txt
@@ -0,0 +1,29 @@
+GPIO-INVERTER
+======
+This binding defines the gpio-inverter. The gpio-inverter is a driver that
+allows to properly describe the gpio polarities on the hardware.
+
+Please refer to gpio.txt for generic information regarding GPIO bindings.
+
+Required properties:
+- compatible : "gpio-inverter".
+- gpio-controller: Marks the port as GPIO controller.
+- #gpio-cells: One. This is the pin number.
+- inverted-gpios: Array of GPIO pins required from consumers, whose polarity
+  has to be inverted in the driver.
+Note: gpio flag should be set as GPIO_ACTIVE_HIGH. Using GPIO_ACTICE_LOW will
+cause double inversion.
+
+Optional properties:
+- gpio-line-names: Refer to gpio.txt for details regarding this property.
+
+Example:
+
+gpio_inv: gpio-inv {
+	compatible = "gpio-inverter";
+	gpio-controller;
+	#gpio-cells = <1>;
+	inverted-gpios = <&gpio5 24 GPIO_ACTIVE_HIGH>,
+	<&gpio7 0 GPIO_ACTIVE_HIGH>, <&gpio7 1 GPIO_ACTIVE_HIGH>;
+	gpio-line-names = "JTAG_DNL_EN", "lvds-pwrdwn", "lcd-on";
+};
--
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH V4 1/2] gpio: inverter: Add Inverter controller for gpio configuration
  2019-06-28  5:20 ` [PATCH V4 1/2] gpio: inverter: " Harish Jenny K N
@ 2019-06-28  8:55   ` Linus Walleij
  2019-06-28  9:15     ` Harish Jenny K N
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2019-06-28  8:55 UTC (permalink / raw)
  To: Harish Jenny K N
  Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
	Balasubramani Vivekanandan

On Fri, Jun 28, 2019 at 6:20 AM Harish Jenny K N
<harish_kandiga@mentor.com> wrote:

> Provides a new inverter gpio controller to configure the polarity
> of the gpio pins. This driver enables the consumers to directly
> use the gpio pin without worrying about the hardware level
> polarity configuration. Polarity configuration will be done by
> the inverter gpio controller based on device tree information.
>
> Signed-off-by: Balasubramani Vivekanandan <balasubramani_vivekanandan@mentor.com>
> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>

This code is finished, very nice.

We still need some review from the DT people before I
apply it.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V4 1/2] gpio: inverter: Add Inverter controller for gpio configuration
  2019-06-28  8:55   ` Linus Walleij
@ 2019-06-28  9:15     ` Harish Jenny K N
  2019-06-28  9:22       ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Harish Jenny K N @ 2019-06-28  9:15 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
	Balasubramani Vivekanandan


On 28/06/19 2:25 PM, Linus Walleij wrote:
> On Fri, Jun 28, 2019 at 6:20 AM Harish Jenny K N
> <harish_kandiga@mentor.com> wrote:
>
>> Provides a new inverter gpio controller to configure the polarity
>> of the gpio pins. This driver enables the consumers to directly
>> use the gpio pin without worrying about the hardware level
>> polarity configuration. Polarity configuration will be done by
>> the inverter gpio controller based on device tree information.
>>
>> Signed-off-by: Balasubramani Vivekanandan <balasubramani_vivekanandan@mentor.com>
>> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
> This code is finished, very nice.


Thanks.

>
> We still need some review from the DT people before I
> apply it.


Are the DT people in the same mailing list or do I need to send review request separately ?

Regards,

Harish Jenny K N



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V4 1/2] gpio: inverter: Add Inverter controller for gpio configuration
  2019-06-28  9:15     ` Harish Jenny K N
@ 2019-06-28  9:22       ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2019-06-28  9:22 UTC (permalink / raw)
  To: Harish Jenny K N
  Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
	Balasubramani Vivekanandan

On Fri, Jun 28, 2019 at 10:16 AM Harish Jenny K N
<harish_kandiga@mentor.com> wrote:
> On 28/06/19 2:25 PM, Linus Walleij wrote:

> > We still need some review from the DT people before I
> > apply it.
>
> Are the DT people in the same mailing list or do I need to send review request separately ?

Ah I see why you don't get any review on that part.
Make sure to send the DT binding patch to
devicetree@vger.kernel.org

You can just resend that one patch if you like.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-28  9:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-28  5:20 [PATCH V4 0/2] Add Inverter controller for gpio configuration Harish Jenny K N
2019-06-28  5:20 ` [PATCH V4 1/2] gpio: inverter: " Harish Jenny K N
2019-06-28  8:55   ` Linus Walleij
2019-06-28  9:15     ` Harish Jenny K N
2019-06-28  9:22       ` Linus Walleij
2019-06-28  5:20 ` [PATCH V4 2/2] gpio: inverter: document the inverter bindings Harish Jenny K N

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).