All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio: Add driver for SPI serializers
@ 2015-12-11 19:46 ` Andrew F. Davis
  0 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-11 19:46 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-gpio, devicetree, linux-kernel, Andrew F. Davis

Hello all,

This series adds a GPI(General Purpose Input) driver for generic
parallel-in/serial-out shift registers, such as the SN65HVS882
that this driver was tested on. This should also work for the rest
of the SN65HVS88x series as well as other 74x165 style devices.

Thanks,
Andrew

Andrew F. Davis (2):
  dt-bindings: GPIO: Add generic serializer binding
  gpio: Add driver for SPI serializers

 .../devicetree/bindings/gpio/gpio-pisosr.txt       |  34 ++++
 drivers/gpio/Kconfig                               |   6 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-pisosr.c                         | 182 +++++++++++++++++++++
 4 files changed, 223 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-pisosr.txt
 create mode 100644 drivers/gpio/gpio-pisosr.c

-- 
2.6.4


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

* [PATCH 0/2] gpio: Add driver for SPI serializers
@ 2015-12-11 19:46 ` Andrew F. Davis
  0 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-11 19:46 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-gpio, devicetree, linux-kernel, Andrew F. Davis

Hello all,

This series adds a GPI(General Purpose Input) driver for generic
parallel-in/serial-out shift registers, such as the SN65HVS882
that this driver was tested on. This should also work for the rest
of the SN65HVS88x series as well as other 74x165 style devices.

Thanks,
Andrew

Andrew F. Davis (2):
  dt-bindings: GPIO: Add generic serializer binding
  gpio: Add driver for SPI serializers

 .../devicetree/bindings/gpio/gpio-pisosr.txt       |  34 ++++
 drivers/gpio/Kconfig                               |   6 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-pisosr.c                         | 182 +++++++++++++++++++++
 4 files changed, 223 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-pisosr.txt
 create mode 100644 drivers/gpio/gpio-pisosr.c

-- 
2.6.4


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

* [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-11 19:46 ` Andrew F. Davis
@ 2015-12-11 19:46   ` Andrew F. Davis
  -1 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-11 19:46 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-gpio, devicetree, linux-kernel, Andrew F. Davis

Add binding for generic parallel-in/serial-out shift register devices
used as GPIO.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 .../devicetree/bindings/gpio/gpio-pisosr.txt       | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-pisosr.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-pisosr.txt b/Documentation/devicetree/bindings/gpio/gpio-pisosr.txt
new file mode 100644
index 0000000..e69e8ec
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-pisosr.txt
@@ -0,0 +1,34 @@
+Generic Parallel-in/Serial-out Shift Register GPIO Driver
+
+This binding describes generic parallel-in/serial-out shift register
+devices that can be used for GPI (General Purpose Input). This includes
+SN74165 serial-out shift registers and the SN65HVS88x series of
+industrial serializers.
+
+Required properties:
+ - compatible		: Should be "pisosr-gpio".
+ - gpio-controller	: Marks the device node as a GPIO controller.
+ - #gpio-cells		: Should be two. For consumer use see gpio.txt.
+
+Optional properties:
+ - ngpios		: Number of GPIO lines, default is 8.
+ - load-gpios		: GPIO pin specifier attached to load enable, this
+			  pin is pulsed before reading from the device to
+			  load input pin values into the the device.
+
+For other required and optional properties of SPI slave
+nodes please refer to ../spi/spi-bus.txt.
+
+Example:
+
+	sn65hvs882@0 {
+		compatible = "pisosr-gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+
+		load-gpios = <&gpio2 23 GPIO_ACTIVE_LOW>;
+
+		reg = <0>;
+		spi-max-frequency = <1000000>;
+		spi-cpol;
+	};
-- 
2.6.4

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

* [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
@ 2015-12-11 19:46   ` Andrew F. Davis
  0 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-11 19:46 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-gpio, devicetree, linux-kernel, Andrew F. Davis

Add binding for generic parallel-in/serial-out shift register devices
used as GPIO.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 .../devicetree/bindings/gpio/gpio-pisosr.txt       | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-pisosr.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-pisosr.txt b/Documentation/devicetree/bindings/gpio/gpio-pisosr.txt
new file mode 100644
index 0000000..e69e8ec
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-pisosr.txt
@@ -0,0 +1,34 @@
+Generic Parallel-in/Serial-out Shift Register GPIO Driver
+
+This binding describes generic parallel-in/serial-out shift register
+devices that can be used for GPI (General Purpose Input). This includes
+SN74165 serial-out shift registers and the SN65HVS88x series of
+industrial serializers.
+
+Required properties:
+ - compatible		: Should be "pisosr-gpio".
+ - gpio-controller	: Marks the device node as a GPIO controller.
+ - #gpio-cells		: Should be two. For consumer use see gpio.txt.
+
+Optional properties:
+ - ngpios		: Number of GPIO lines, default is 8.
+ - load-gpios		: GPIO pin specifier attached to load enable, this
+			  pin is pulsed before reading from the device to
+			  load input pin values into the the device.
+
+For other required and optional properties of SPI slave
+nodes please refer to ../spi/spi-bus.txt.
+
+Example:
+
+	sn65hvs882@0 {
+		compatible = "pisosr-gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+
+		load-gpios = <&gpio2 23 GPIO_ACTIVE_LOW>;
+
+		reg = <0>;
+		spi-max-frequency = <1000000>;
+		spi-cpol;
+	};
-- 
2.6.4


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

* [PATCH 2/2] gpio: Add driver for SPI serializers
  2015-12-11 19:46 ` Andrew F. Davis
@ 2015-12-11 19:46   ` Andrew F. Davis
  -1 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-11 19:46 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-gpio, devicetree, linux-kernel, Andrew F. Davis

Add generic parallel-in/serial-out shift register GPIO driver.

This includes SPI compatible devices like SN74165 serial-out shift
registers and the SN65HVS88x series of industrial serializers that can
be read over the SPI bus and used for GPI (General Purpose Input).

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 drivers/gpio/Kconfig       |   6 ++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-pisosr.c | 182 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 189 insertions(+)
 create mode 100644 drivers/gpio/gpio-pisosr.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 30d8bd3..95615b1 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1021,6 +1021,12 @@ config GPIO_MC33880
 	  SPI driver for Freescale MC33880 high-side/low-side switch.
 	  This provides GPIO interface supporting inputs and outputs.
 
+config GPIO_PISOSR
+	tristate "Generic parallel-in/serial-out shift register"
+	help
+	  GPIO driver for SPI compatible parallel-in/serial-out shift
+	  registers. These are input only devices.
+
 endmenu
 
 menu "SPI or I2C GPIO expanders"
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 548e9b5..ee26102 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -75,6 +75,7 @@ obj-$(CONFIG_GPIO_OMAP)		+= gpio-omap.o
 obj-$(CONFIG_GPIO_PCA953X)	+= gpio-pca953x.o
 obj-$(CONFIG_GPIO_PCF857X)	+= gpio-pcf857x.o
 obj-$(CONFIG_GPIO_PCH)		+= gpio-pch.o
+obj-$(CONFIG_GPIO_PISOSR)	+= gpio-pisosr.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_PXA)		+= gpio-pxa.o
 obj-$(CONFIG_GPIO_RC5T583)	+= gpio-rc5t583.o
diff --git a/drivers/gpio/gpio-pisosr.c b/drivers/gpio/gpio-pisosr.c
new file mode 100644
index 0000000..e89cd59
--- /dev/null
+++ b/drivers/gpio/gpio-pisosr.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *	Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/spi/spi.h>
+
+#define DEFAULT_NGPIO 8
+
+struct pisosr_gpio {
+	struct gpio_chip chip;
+	struct spi_device *spi;
+	u8 *buffer;
+	size_t buffer_size;
+	struct gpio_desc *load_gpio;
+	struct mutex lock;
+};
+
+static inline struct pisosr_gpio *to_pisosr_gpio(struct gpio_chip *chip)
+{
+	return container_of(chip, struct pisosr_gpio, chip);
+}
+
+static int pisosr_gpio_refresh(struct pisosr_gpio *gpio)
+{
+	int ret;
+
+	mutex_lock(&gpio->lock);
+
+	if (gpio->load_gpio) {
+		gpiod_set_value(gpio->load_gpio, 1);
+		udelay(1); /* registers load time (~10ns) */
+		gpiod_set_value(gpio->load_gpio, 0);
+		udelay(1); /* registers recovery time (~5ns) */
+	}
+
+	ret = spi_read(gpio->spi, gpio->buffer, gpio->buffer_size);
+	if (ret)
+		return ret;
+
+	mutex_unlock(&gpio->lock);
+
+	return 0;
+}
+
+static int pisosr_gpio_get_direction(struct gpio_chip *chip,
+				     unsigned offset)
+{
+	return GPIOF_DIR_IN;
+}
+
+static int pisosr_gpio_direction_input(struct gpio_chip *chip,
+				       unsigned offset)
+{
+	/* This device always input */
+	return 0;
+}
+
+static int pisosr_gpio_direction_output(struct gpio_chip *chip,
+					unsigned offset, int value)
+{
+	/* This device is input only */
+	return -EINVAL;
+}
+
+static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+	struct pisosr_gpio *gpio = to_pisosr_gpio(chip);
+
+	/* Refresh may not always be needed */
+	pisosr_gpio_refresh(gpio);
+
+	return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1;
+}
+
+static struct gpio_chip template_chip = {
+	.label			= "pisosr-gpio",
+	.owner			= THIS_MODULE,
+	.get_direction		= pisosr_gpio_get_direction,
+	.direction_input	= pisosr_gpio_direction_input,
+	.direction_output	= pisosr_gpio_direction_output,
+	.get			= pisosr_gpio_get,
+	.base			= -1,
+	.ngpio			= DEFAULT_NGPIO,
+	.can_sleep		= true,
+};
+
+static int pisosr_gpio_probe(struct spi_device *spi)
+{
+	struct pisosr_gpio *gpio;
+	struct device_node *np = spi->dev.of_node;
+	int ret;
+
+	gpio = devm_kzalloc(&spi->dev, sizeof(*gpio), GFP_KERNEL);
+	if (!gpio)
+		return -ENOMEM;
+
+	spi_set_drvdata(spi, gpio);
+
+	gpio->chip = template_chip;
+	gpio->chip.parent = &spi->dev;
+	of_property_read_u16(np, "ngpios", &gpio->chip.ngpio);
+
+	gpio->spi = spi;
+
+	gpio->buffer_size = DIV_ROUND_UP(gpio->chip.ngpio, 8);
+	gpio->buffer = devm_kzalloc(&spi->dev, gpio->buffer_size, GFP_KERNEL);
+	if (!gpio->buffer)
+		return -ENOMEM;
+
+	gpio->load_gpio = devm_gpiod_get(&spi->dev, "load", GPIOD_OUT_LOW);
+	if (IS_ERR(gpio->load_gpio)) {
+		ret = PTR_ERR(gpio->load_gpio);
+		if (ret != -ENOENT && ret != -ENOSYS) {
+			if (ret != -EPROBE_DEFER)
+				dev_err(&spi->dev, "Unable to allocate reset gpio\n");
+			return ret;
+		}
+		gpio->load_gpio = NULL;
+	}
+
+	mutex_init(&gpio->lock);
+
+	ret = gpiochip_add(&gpio->chip);
+	if (ret < 0) {
+		dev_err(&spi->dev, "Unable to register gpiochip\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int pisosr_gpio_remove(struct spi_device *spi)
+{
+	struct pisosr_gpio *gpio = spi_get_drvdata(spi);
+
+	gpiochip_remove(&gpio->chip);
+
+	mutex_destroy(&gpio->lock);
+
+	return 0;
+}
+
+static const struct spi_device_id pisosr_gpio_id_table[] = {
+	{ "pisosr-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(spi, pisosr_gpio_id_table);
+
+static const struct of_device_id pisosr_gpio_of_match_table[] = {
+	{ .compatible = "pisosr-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, pisosr_gpio_of_match_table);
+
+static struct spi_driver pisosr_gpio_driver = {
+	.driver = {
+		.name = "pisosr-gpio",
+		.of_match_table = pisosr_gpio_of_match_table,
+	},
+	.probe = pisosr_gpio_probe,
+	.remove = pisosr_gpio_remove,
+	.id_table = pisosr_gpio_id_table,
+};
+module_spi_driver(pisosr_gpio_driver);
+
+MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
+MODULE_DESCRIPTION("SPI Compatible PISO Shift Register GPIO Driver");
+MODULE_LICENSE("GPL v2");
-- 
2.6.4

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

* [PATCH 2/2] gpio: Add driver for SPI serializers
@ 2015-12-11 19:46   ` Andrew F. Davis
  0 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-11 19:46 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: linux-gpio, devicetree, linux-kernel, Andrew F. Davis

Add generic parallel-in/serial-out shift register GPIO driver.

This includes SPI compatible devices like SN74165 serial-out shift
registers and the SN65HVS88x series of industrial serializers that can
be read over the SPI bus and used for GPI (General Purpose Input).

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 drivers/gpio/Kconfig       |   6 ++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-pisosr.c | 182 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 189 insertions(+)
 create mode 100644 drivers/gpio/gpio-pisosr.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 30d8bd3..95615b1 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1021,6 +1021,12 @@ config GPIO_MC33880
 	  SPI driver for Freescale MC33880 high-side/low-side switch.
 	  This provides GPIO interface supporting inputs and outputs.
 
+config GPIO_PISOSR
+	tristate "Generic parallel-in/serial-out shift register"
+	help
+	  GPIO driver for SPI compatible parallel-in/serial-out shift
+	  registers. These are input only devices.
+
 endmenu
 
 menu "SPI or I2C GPIO expanders"
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 548e9b5..ee26102 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -75,6 +75,7 @@ obj-$(CONFIG_GPIO_OMAP)		+= gpio-omap.o
 obj-$(CONFIG_GPIO_PCA953X)	+= gpio-pca953x.o
 obj-$(CONFIG_GPIO_PCF857X)	+= gpio-pcf857x.o
 obj-$(CONFIG_GPIO_PCH)		+= gpio-pch.o
+obj-$(CONFIG_GPIO_PISOSR)	+= gpio-pisosr.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
 obj-$(CONFIG_GPIO_PXA)		+= gpio-pxa.o
 obj-$(CONFIG_GPIO_RC5T583)	+= gpio-rc5t583.o
diff --git a/drivers/gpio/gpio-pisosr.c b/drivers/gpio/gpio-pisosr.c
new file mode 100644
index 0000000..e89cd59
--- /dev/null
+++ b/drivers/gpio/gpio-pisosr.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *	Andrew F. Davis <afd@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether expressed or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License version 2 for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/spi/spi.h>
+
+#define DEFAULT_NGPIO 8
+
+struct pisosr_gpio {
+	struct gpio_chip chip;
+	struct spi_device *spi;
+	u8 *buffer;
+	size_t buffer_size;
+	struct gpio_desc *load_gpio;
+	struct mutex lock;
+};
+
+static inline struct pisosr_gpio *to_pisosr_gpio(struct gpio_chip *chip)
+{
+	return container_of(chip, struct pisosr_gpio, chip);
+}
+
+static int pisosr_gpio_refresh(struct pisosr_gpio *gpio)
+{
+	int ret;
+
+	mutex_lock(&gpio->lock);
+
+	if (gpio->load_gpio) {
+		gpiod_set_value(gpio->load_gpio, 1);
+		udelay(1); /* registers load time (~10ns) */
+		gpiod_set_value(gpio->load_gpio, 0);
+		udelay(1); /* registers recovery time (~5ns) */
+	}
+
+	ret = spi_read(gpio->spi, gpio->buffer, gpio->buffer_size);
+	if (ret)
+		return ret;
+
+	mutex_unlock(&gpio->lock);
+
+	return 0;
+}
+
+static int pisosr_gpio_get_direction(struct gpio_chip *chip,
+				     unsigned offset)
+{
+	return GPIOF_DIR_IN;
+}
+
+static int pisosr_gpio_direction_input(struct gpio_chip *chip,
+				       unsigned offset)
+{
+	/* This device always input */
+	return 0;
+}
+
+static int pisosr_gpio_direction_output(struct gpio_chip *chip,
+					unsigned offset, int value)
+{
+	/* This device is input only */
+	return -EINVAL;
+}
+
+static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+	struct pisosr_gpio *gpio = to_pisosr_gpio(chip);
+
+	/* Refresh may not always be needed */
+	pisosr_gpio_refresh(gpio);
+
+	return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1;
+}
+
+static struct gpio_chip template_chip = {
+	.label			= "pisosr-gpio",
+	.owner			= THIS_MODULE,
+	.get_direction		= pisosr_gpio_get_direction,
+	.direction_input	= pisosr_gpio_direction_input,
+	.direction_output	= pisosr_gpio_direction_output,
+	.get			= pisosr_gpio_get,
+	.base			= -1,
+	.ngpio			= DEFAULT_NGPIO,
+	.can_sleep		= true,
+};
+
+static int pisosr_gpio_probe(struct spi_device *spi)
+{
+	struct pisosr_gpio *gpio;
+	struct device_node *np = spi->dev.of_node;
+	int ret;
+
+	gpio = devm_kzalloc(&spi->dev, sizeof(*gpio), GFP_KERNEL);
+	if (!gpio)
+		return -ENOMEM;
+
+	spi_set_drvdata(spi, gpio);
+
+	gpio->chip = template_chip;
+	gpio->chip.parent = &spi->dev;
+	of_property_read_u16(np, "ngpios", &gpio->chip.ngpio);
+
+	gpio->spi = spi;
+
+	gpio->buffer_size = DIV_ROUND_UP(gpio->chip.ngpio, 8);
+	gpio->buffer = devm_kzalloc(&spi->dev, gpio->buffer_size, GFP_KERNEL);
+	if (!gpio->buffer)
+		return -ENOMEM;
+
+	gpio->load_gpio = devm_gpiod_get(&spi->dev, "load", GPIOD_OUT_LOW);
+	if (IS_ERR(gpio->load_gpio)) {
+		ret = PTR_ERR(gpio->load_gpio);
+		if (ret != -ENOENT && ret != -ENOSYS) {
+			if (ret != -EPROBE_DEFER)
+				dev_err(&spi->dev, "Unable to allocate reset gpio\n");
+			return ret;
+		}
+		gpio->load_gpio = NULL;
+	}
+
+	mutex_init(&gpio->lock);
+
+	ret = gpiochip_add(&gpio->chip);
+	if (ret < 0) {
+		dev_err(&spi->dev, "Unable to register gpiochip\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int pisosr_gpio_remove(struct spi_device *spi)
+{
+	struct pisosr_gpio *gpio = spi_get_drvdata(spi);
+
+	gpiochip_remove(&gpio->chip);
+
+	mutex_destroy(&gpio->lock);
+
+	return 0;
+}
+
+static const struct spi_device_id pisosr_gpio_id_table[] = {
+	{ "pisosr-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(spi, pisosr_gpio_id_table);
+
+static const struct of_device_id pisosr_gpio_of_match_table[] = {
+	{ .compatible = "pisosr-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, pisosr_gpio_of_match_table);
+
+static struct spi_driver pisosr_gpio_driver = {
+	.driver = {
+		.name = "pisosr-gpio",
+		.of_match_table = pisosr_gpio_of_match_table,
+	},
+	.probe = pisosr_gpio_probe,
+	.remove = pisosr_gpio_remove,
+	.id_table = pisosr_gpio_id_table,
+};
+module_spi_driver(pisosr_gpio_driver);
+
+MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
+MODULE_DESCRIPTION("SPI Compatible PISO Shift Register GPIO Driver");
+MODULE_LICENSE("GPL v2");
-- 
2.6.4


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

* Re: [PATCH 0/2] gpio: Add driver for SPI serializers
  2015-12-11 19:46 ` Andrew F. Davis
                   ` (2 preceding siblings ...)
  (?)
@ 2015-12-11 21:43 ` Linus Walleij
  -1 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2015-12-11 21:43 UTC (permalink / raw)
  To: Andrew F. Davis, Mark Brown, linux-spi
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio, devicetree, linux-kernel

On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:

> This series adds a GPI(General Purpose Input) driver for generic
> parallel-in/serial-out shift registers, such as the SN65HVS882
> that this driver was tested on. This should also work for the rest
> of the SN65HVS88x series as well as other 74x165 style devices.

Pretty interesting, I'd like you to CC SPI maintainer Mark Brown
on this patch series, and the SPI mailing list.

Looking closer at the code.

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-11 19:46   ` Andrew F. Davis
  (?)
@ 2015-12-11 21:48   ` Linus Walleij
  2015-12-14 16:41     ` Andrew F. Davis
  -1 siblings, 1 reply; 26+ messages in thread
From: Linus Walleij @ 2015-12-11 21:48 UTC (permalink / raw)
  To: Andrew F. Davis, linux-spi, Mark Brown
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio, devicetree, linux-kernel

On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:

> Add binding for generic parallel-in/serial-out shift register devices
> used as GPIO.
>
> Signed-off-by: Andrew F. Davis <afd@ti.com>

> +Generic Parallel-in/Serial-out Shift Register GPIO Driver
> +
> +This binding describes generic parallel-in/serial-out shift register
> +devices that can be used for GPI (General Purpose Input). This includes
> +SN74165 serial-out shift registers and the SN65HVS88x series of
> +industrial serializers.
> +
> +Required properties:
> + - compatible          : Should be "pisosr-gpio".

I think it should also define compatible strings on the "vendor,device"
format apart from the generic compatible. Sooner or later we may need
to differentiate them and then that comes in handy.

> + - gpio-controller     : Marks the device node as a GPIO controller.
> + - #gpio-cells         : Should be two. For consumer use see gpio.txt.
> +
> +Optional properties:
> + - ngpios              : Number of GPIO lines, default is 8.

If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
don't need to have this in the device tree but instead it can be
determined from the compatible string?

In that case do that.

> + - load-gpios          : GPIO pin specifier attached to load enable, this
> +                         pin is pulsed before reading from the device to
> +                         load input pin values into the the device.

OK seems necessary.

Yours,
Linus Walleij

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

* Re: [PATCH 2/2] gpio: Add driver for SPI serializers
  2015-12-11 19:46   ` Andrew F. Davis
@ 2015-12-11 22:09       ` Linus Walleij
  -1 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2015-12-11 22:09 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
	linux-spi-u79uwXL29TY76Z2rM5mHXA

On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:

> Add generic parallel-in/serial-out shift register GPIO driver.
>
> This includes SPI compatible devices like SN74165 serial-out shift
> registers and the SN65HVS88x series of industrial serializers that can
> be read over the SPI bus and used for GPI (General Purpose Input).
>
> Signed-off-by: Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org>
(...)
> +#include <linux/delay.h>
> +#include <linux/gpio.h>

Use #include <linux/gpio/driver.h> instead.

> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/spi/spi.h>
> +
> +#define DEFAULT_NGPIO 8
> +
> +struct pisosr_gpio {
> +       struct gpio_chip chip;
> +       struct spi_device *spi;
> +       u8 *buffer;
> +       size_t buffer_size;
> +       struct gpio_desc *load_gpio;
> +       struct mutex lock;
> +};

Add kerneldoc to this struct.

> +static inline struct pisosr_gpio *to_pisosr_gpio(struct gpio_chip *chip)
> +{
> +       return container_of(chip, struct pisosr_gpio, chip);
> +}

We are doing away with this, but I can fix up the driver by a separate
patch later of we merge it.

> +static int pisosr_gpio_refresh(struct pisosr_gpio *gpio)
> +{
> +       int ret;
> +
> +       mutex_lock(&gpio->lock);
> +
> +       if (gpio->load_gpio) {
> +               gpiod_set_value(gpio->load_gpio, 1);
> +               udelay(1); /* registers load time (~10ns) */
> +               gpiod_set_value(gpio->load_gpio, 0);
> +               udelay(1); /* registers recovery time (~5ns) */


So aren't these load/recovery times dependent on the device?
I think these should come from the compatible string.

> +static int pisosr_gpio_get_direction(struct gpio_chip *chip,
> +                                    unsigned offset)
> +{
> +       return GPIOF_DIR_IN;
> +}

Just return 1, GPIOF_DIR_IN is for the external API.

> +static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset)
> +{
> +       struct pisosr_gpio *gpio = to_pisosr_gpio(chip);
> +
> +       /* Refresh may not always be needed */
> +       pisosr_gpio_refresh(gpio);
> +
> +       return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1;
> +}

This looks like a good reason to implement .get_multiple() in the
same way that we have .set_multiple(), so you agree?

But it's not like I'm requiring you to engineer all that. Just an
academic reflection of the fact.

> +static int pisosr_gpio_probe(struct spi_device *spi)
> +{
> +       struct pisosr_gpio *gpio;
> +       struct device_node *np = spi->dev.of_node;
> +       int ret;


To match and get a pointer to a compatible-string-specific data variant,
look at the example in drivers/mfd/tc3589x.c

> +       gpio = devm_kzalloc(&spi->dev, sizeof(*gpio), GFP_KERNEL);
> +       if (!gpio)
> +               return -ENOMEM;
> +
> +       spi_set_drvdata(spi, gpio);
> +
> +       gpio->chip = template_chip;
> +       gpio->chip.parent = &spi->dev;
> +       of_property_read_u16(np, "ngpios", &gpio->chip.ngpio);

As I wrote elsewhere, should come from the variant data, based on the
compatible string. ngpios is in case you're not using all of them and
need to restrict the number of used GPIOs. Usually this only applies to
on-SoC GPIOs that are unrouted.

> +       gpio->spi = spi;
> +
> +       gpio->buffer_size = DIV_ROUND_UP(gpio->chip.ngpio, 8);
> +       gpio->buffer = devm_kzalloc(&spi->dev, gpio->buffer_size, GFP_KERNEL);
> +       if (!gpio->buffer)
> +               return -ENOMEM;
> +
> +       gpio->load_gpio = devm_gpiod_get(&spi->dev, "load", GPIOD_OUT_LOW);
> +       if (IS_ERR(gpio->load_gpio)) {
> +               ret = PTR_ERR(gpio->load_gpio);
> +               if (ret != -ENOENT && ret != -ENOSYS) {
> +                       if (ret != -EPROBE_DEFER)
> +                               dev_err(&spi->dev, "Unable to allocate reset gpio\n");

Reset gpio? Really? Load GPIO?

Apart from that it looks good.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/2] gpio: Add driver for SPI serializers
@ 2015-12-11 22:09       ` Linus Walleij
  0 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2015-12-11 22:09 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio, devicetree, linux-kernel,
	Mark Brown, linux-spi

On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:

> Add generic parallel-in/serial-out shift register GPIO driver.
>
> This includes SPI compatible devices like SN74165 serial-out shift
> registers and the SN65HVS88x series of industrial serializers that can
> be read over the SPI bus and used for GPI (General Purpose Input).
>
> Signed-off-by: Andrew F. Davis <afd@ti.com>
(...)
> +#include <linux/delay.h>
> +#include <linux/gpio.h>

Use #include <linux/gpio/driver.h> instead.

> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/spi/spi.h>
> +
> +#define DEFAULT_NGPIO 8
> +
> +struct pisosr_gpio {
> +       struct gpio_chip chip;
> +       struct spi_device *spi;
> +       u8 *buffer;
> +       size_t buffer_size;
> +       struct gpio_desc *load_gpio;
> +       struct mutex lock;
> +};

Add kerneldoc to this struct.

> +static inline struct pisosr_gpio *to_pisosr_gpio(struct gpio_chip *chip)
> +{
> +       return container_of(chip, struct pisosr_gpio, chip);
> +}

We are doing away with this, but I can fix up the driver by a separate
patch later of we merge it.

> +static int pisosr_gpio_refresh(struct pisosr_gpio *gpio)
> +{
> +       int ret;
> +
> +       mutex_lock(&gpio->lock);
> +
> +       if (gpio->load_gpio) {
> +               gpiod_set_value(gpio->load_gpio, 1);
> +               udelay(1); /* registers load time (~10ns) */
> +               gpiod_set_value(gpio->load_gpio, 0);
> +               udelay(1); /* registers recovery time (~5ns) */


So aren't these load/recovery times dependent on the device?
I think these should come from the compatible string.

> +static int pisosr_gpio_get_direction(struct gpio_chip *chip,
> +                                    unsigned offset)
> +{
> +       return GPIOF_DIR_IN;
> +}

Just return 1, GPIOF_DIR_IN is for the external API.

> +static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset)
> +{
> +       struct pisosr_gpio *gpio = to_pisosr_gpio(chip);
> +
> +       /* Refresh may not always be needed */
> +       pisosr_gpio_refresh(gpio);
> +
> +       return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1;
> +}

This looks like a good reason to implement .get_multiple() in the
same way that we have .set_multiple(), so you agree?

But it's not like I'm requiring you to engineer all that. Just an
academic reflection of the fact.

> +static int pisosr_gpio_probe(struct spi_device *spi)
> +{
> +       struct pisosr_gpio *gpio;
> +       struct device_node *np = spi->dev.of_node;
> +       int ret;


To match and get a pointer to a compatible-string-specific data variant,
look at the example in drivers/mfd/tc3589x.c

> +       gpio = devm_kzalloc(&spi->dev, sizeof(*gpio), GFP_KERNEL);
> +       if (!gpio)
> +               return -ENOMEM;
> +
> +       spi_set_drvdata(spi, gpio);
> +
> +       gpio->chip = template_chip;
> +       gpio->chip.parent = &spi->dev;
> +       of_property_read_u16(np, "ngpios", &gpio->chip.ngpio);

As I wrote elsewhere, should come from the variant data, based on the
compatible string. ngpios is in case you're not using all of them and
need to restrict the number of used GPIOs. Usually this only applies to
on-SoC GPIOs that are unrouted.

> +       gpio->spi = spi;
> +
> +       gpio->buffer_size = DIV_ROUND_UP(gpio->chip.ngpio, 8);
> +       gpio->buffer = devm_kzalloc(&spi->dev, gpio->buffer_size, GFP_KERNEL);
> +       if (!gpio->buffer)
> +               return -ENOMEM;
> +
> +       gpio->load_gpio = devm_gpiod_get(&spi->dev, "load", GPIOD_OUT_LOW);
> +       if (IS_ERR(gpio->load_gpio)) {
> +               ret = PTR_ERR(gpio->load_gpio);
> +               if (ret != -ENOENT && ret != -ENOSYS) {
> +                       if (ret != -EPROBE_DEFER)
> +                               dev_err(&spi->dev, "Unable to allocate reset gpio\n");

Reset gpio? Really? Load GPIO?

Apart from that it looks good.

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-11 21:48   ` Linus Walleij
@ 2015-12-14 16:41     ` Andrew F. Davis
  2015-12-14 22:36       ` Rob Herring
  2015-12-17  8:28       ` Geert Uytterhoeven
  0 siblings, 2 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-14 16:41 UTC (permalink / raw)
  To: Linus Walleij, linux-spi, Mark Brown
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio, devicetree, linux-kernel

On 12/11/2015 03:48 PM, Linus Walleij wrote:
> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:
>
>> Add binding for generic parallel-in/serial-out shift register devices
>> used as GPIO.
>>
>> Signed-off-by: Andrew F. Davis <afd@ti.com>
>
>> +Generic Parallel-in/Serial-out Shift Register GPIO Driver
>> +
>> +This binding describes generic parallel-in/serial-out shift register
>> +devices that can be used for GPI (General Purpose Input). This includes
>> +SN74165 serial-out shift registers and the SN65HVS88x series of
>> +industrial serializers.
>> +
>> +Required properties:
>> + - compatible          : Should be "pisosr-gpio".
>
> I think it should also define compatible strings on the "vendor,device"
> format apart from the generic compatible. Sooner or later we may need
> to differentiate them and then that comes in handy.
>

Would it be better to wait until/if this issue arises? This driver
targets the generic features, as these parts are very generic and
have been produced by many companies since the 70s I'm not sure
if privileging any of them makes much sense.

What I'm worried about looks to have happened with the gpio-74x164
driver, this is kind of the companion device to mine (74164 / 74165)
and should work with any 74164 compatible shift register (possibly 100s
of versions of them), but the compatible string that was added is
"fairchild,74hc595", a relatively new device by a single manufacturer.
The problem this has is then that boards will use this compatible string
even if the parts are not actually the Fairchild version, just to get
the match, when they should be using a generic string.

>> + - gpio-controller     : Marks the device node as a GPIO controller.
>> + - #gpio-cells         : Should be two. For consumer use see gpio.txt.
>> +
>> +Optional properties:
>> + - ngpios              : Number of GPIO lines, default is 8.
>
> If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
> don't need to have this in the device tree but instead it can be
> determined from the compatible string?
>
> In that case do that.
>

These devices can be daisy-chained together, so three 8bit registers
look exactly like one 24bit register. The only way to know this is
from the physical wiring of the board, not from the part number.

Thanks,
Andrew

>> + - load-gpios          : GPIO pin specifier attached to load enable, this
>> +                         pin is pulsed before reading from the device to
>> +                         load input pin values into the the device.
>
> OK seems necessary.
>
> Yours,
> Linus Walleij
>

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

* Re: [PATCH 2/2] gpio: Add driver for SPI serializers
  2015-12-11 22:09       ` Linus Walleij
@ 2015-12-14 16:47           ` Andrew F. Davis
  -1 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-14 16:47 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
	linux-spi-u79uwXL29TY76Z2rM5mHXA

On 12/11/2015 04:09 PM, Linus Walleij wrote:
> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:
>
>> Add generic parallel-in/serial-out shift register GPIO driver.
>>
>> This includes SPI compatible devices like SN74165 serial-out shift
>> registers and the SN65HVS88x series of industrial serializers that can
>> be read over the SPI bus and used for GPI (General Purpose Input).
>>
>> Signed-off-by: Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org>
> (...)
>> +#include <linux/delay.h>
>> +#include <linux/gpio.h>
>
> Use #include <linux/gpio/driver.h> instead.
>

ACK

>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/spi/spi.h>
>> +
>> +#define DEFAULT_NGPIO 8
>> +
>> +struct pisosr_gpio {
>> +       struct gpio_chip chip;
>> +       struct spi_device *spi;
>> +       u8 *buffer;
>> +       size_t buffer_size;
>> +       struct gpio_desc *load_gpio;
>> +       struct mutex lock;
>> +};
>
> Add kerneldoc to this struct.
>

Will do.

>> +static inline struct pisosr_gpio *to_pisosr_gpio(struct gpio_chip *chip)
>> +{
>> +       return container_of(chip, struct pisosr_gpio, chip);
>> +}
>
> We are doing away with this, but I can fix up the driver by a separate
> patch later of we merge it.
>

That will work, thanks.

>> +static int pisosr_gpio_refresh(struct pisosr_gpio *gpio)
>> +{
>> +       int ret;
>> +
>> +       mutex_lock(&gpio->lock);
>> +
>> +       if (gpio->load_gpio) {
>> +               gpiod_set_value(gpio->load_gpio, 1);
>> +               udelay(1); /* registers load time (~10ns) */
>> +               gpiod_set_value(gpio->load_gpio, 0);
>> +               udelay(1); /* registers recovery time (~5ns) */
>
>
> So aren't these load/recovery times dependent on the device?
> I think these should come from the compatible string.
>

Yes, but they are all under 20ns or so, I just put the smallest
reasonable delay to keep a fast host from going under this limit.
(although I doubt any could)

>> +static int pisosr_gpio_get_direction(struct gpio_chip *chip,
>> +                                    unsigned offset)
>> +{
>> +       return GPIOF_DIR_IN;
>> +}
>
> Just return 1, GPIOF_DIR_IN is for the external API.
>

ACK

>> +static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset)
>> +{
>> +       struct pisosr_gpio *gpio = to_pisosr_gpio(chip);
>> +
>> +       /* Refresh may not always be needed */
>> +       pisosr_gpio_refresh(gpio);
>> +
>> +       return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1;
>> +}
>
> This looks like a good reason to implement .get_multiple() in the
> same way that we have .set_multiple(), so you agree?
>
> But it's not like I'm requiring you to engineer all that. Just an
> academic reflection of the fact.
>

I was disappointed when I saw only set_multiple, so this would
be something nice to have, I'll look into it.

>> +static int pisosr_gpio_probe(struct spi_device *spi)
>> +{
>> +       struct pisosr_gpio *gpio;
>> +       struct device_node *np = spi->dev.of_node;
>> +       int ret;
>
>
> To match and get a pointer to a compatible-string-specific data variant,
> look at the example in drivers/mfd/tc3589x.c
>

ACK

>> +       gpio = devm_kzalloc(&spi->dev, sizeof(*gpio), GFP_KERNEL);
>> +       if (!gpio)
>> +               return -ENOMEM;
>> +
>> +       spi_set_drvdata(spi, gpio);
>> +
>> +       gpio->chip = template_chip;
>> +       gpio->chip.parent = &spi->dev;
>> +       of_property_read_u16(np, "ngpios", &gpio->chip.ngpio);
>
> As I wrote elsewhere, should come from the variant data, based on the
> compatible string. ngpios is in case you're not using all of them and
> need to restrict the number of used GPIOs. Usually this only applies to
> on-SoC GPIOs that are unrouted.
>

(See my reply to your previous comment on this)

>> +       gpio->spi = spi;
>> +
>> +       gpio->buffer_size = DIV_ROUND_UP(gpio->chip.ngpio, 8);
>> +       gpio->buffer = devm_kzalloc(&spi->dev, gpio->buffer_size, GFP_KERNEL);
>> +       if (!gpio->buffer)
>> +               return -ENOMEM;
>> +
>> +       gpio->load_gpio = devm_gpiod_get(&spi->dev, "load", GPIOD_OUT_LOW);
>> +       if (IS_ERR(gpio->load_gpio)) {
>> +               ret = PTR_ERR(gpio->load_gpio);
>> +               if (ret != -ENOENT && ret != -ENOSYS) {
>> +                       if (ret != -EPROBE_DEFER)
>> +                               dev_err(&spi->dev, "Unable to allocate reset gpio\n");
>
> Reset gpio? Really? Load GPIO?
>

Ops, copy/paste error I think.

Thanks,
Andrew

> Apart from that it looks good.
>
> Yours,
> Linus Walleij
>
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/2] gpio: Add driver for SPI serializers
@ 2015-12-14 16:47           ` Andrew F. Davis
  0 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-14 16:47 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio, devicetree, linux-kernel,
	Mark Brown, linux-spi

On 12/11/2015 04:09 PM, Linus Walleij wrote:
> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:
>
>> Add generic parallel-in/serial-out shift register GPIO driver.
>>
>> This includes SPI compatible devices like SN74165 serial-out shift
>> registers and the SN65HVS88x series of industrial serializers that can
>> be read over the SPI bus and used for GPI (General Purpose Input).
>>
>> Signed-off-by: Andrew F. Davis <afd@ti.com>
> (...)
>> +#include <linux/delay.h>
>> +#include <linux/gpio.h>
>
> Use #include <linux/gpio/driver.h> instead.
>

ACK

>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/spi/spi.h>
>> +
>> +#define DEFAULT_NGPIO 8
>> +
>> +struct pisosr_gpio {
>> +       struct gpio_chip chip;
>> +       struct spi_device *spi;
>> +       u8 *buffer;
>> +       size_t buffer_size;
>> +       struct gpio_desc *load_gpio;
>> +       struct mutex lock;
>> +};
>
> Add kerneldoc to this struct.
>

Will do.

>> +static inline struct pisosr_gpio *to_pisosr_gpio(struct gpio_chip *chip)
>> +{
>> +       return container_of(chip, struct pisosr_gpio, chip);
>> +}
>
> We are doing away with this, but I can fix up the driver by a separate
> patch later of we merge it.
>

That will work, thanks.

>> +static int pisosr_gpio_refresh(struct pisosr_gpio *gpio)
>> +{
>> +       int ret;
>> +
>> +       mutex_lock(&gpio->lock);
>> +
>> +       if (gpio->load_gpio) {
>> +               gpiod_set_value(gpio->load_gpio, 1);
>> +               udelay(1); /* registers load time (~10ns) */
>> +               gpiod_set_value(gpio->load_gpio, 0);
>> +               udelay(1); /* registers recovery time (~5ns) */
>
>
> So aren't these load/recovery times dependent on the device?
> I think these should come from the compatible string.
>

Yes, but they are all under 20ns or so, I just put the smallest
reasonable delay to keep a fast host from going under this limit.
(although I doubt any could)

>> +static int pisosr_gpio_get_direction(struct gpio_chip *chip,
>> +                                    unsigned offset)
>> +{
>> +       return GPIOF_DIR_IN;
>> +}
>
> Just return 1, GPIOF_DIR_IN is for the external API.
>

ACK

>> +static int pisosr_gpio_get(struct gpio_chip *chip, unsigned offset)
>> +{
>> +       struct pisosr_gpio *gpio = to_pisosr_gpio(chip);
>> +
>> +       /* Refresh may not always be needed */
>> +       pisosr_gpio_refresh(gpio);
>> +
>> +       return (gpio->buffer[offset / 8] >> (offset % 8)) & 0x1;
>> +}
>
> This looks like a good reason to implement .get_multiple() in the
> same way that we have .set_multiple(), so you agree?
>
> But it's not like I'm requiring you to engineer all that. Just an
> academic reflection of the fact.
>

I was disappointed when I saw only set_multiple, so this would
be something nice to have, I'll look into it.

>> +static int pisosr_gpio_probe(struct spi_device *spi)
>> +{
>> +       struct pisosr_gpio *gpio;
>> +       struct device_node *np = spi->dev.of_node;
>> +       int ret;
>
>
> To match and get a pointer to a compatible-string-specific data variant,
> look at the example in drivers/mfd/tc3589x.c
>

ACK

>> +       gpio = devm_kzalloc(&spi->dev, sizeof(*gpio), GFP_KERNEL);
>> +       if (!gpio)
>> +               return -ENOMEM;
>> +
>> +       spi_set_drvdata(spi, gpio);
>> +
>> +       gpio->chip = template_chip;
>> +       gpio->chip.parent = &spi->dev;
>> +       of_property_read_u16(np, "ngpios", &gpio->chip.ngpio);
>
> As I wrote elsewhere, should come from the variant data, based on the
> compatible string. ngpios is in case you're not using all of them and
> need to restrict the number of used GPIOs. Usually this only applies to
> on-SoC GPIOs that are unrouted.
>

(See my reply to your previous comment on this)

>> +       gpio->spi = spi;
>> +
>> +       gpio->buffer_size = DIV_ROUND_UP(gpio->chip.ngpio, 8);
>> +       gpio->buffer = devm_kzalloc(&spi->dev, gpio->buffer_size, GFP_KERNEL);
>> +       if (!gpio->buffer)
>> +               return -ENOMEM;
>> +
>> +       gpio->load_gpio = devm_gpiod_get(&spi->dev, "load", GPIOD_OUT_LOW);
>> +       if (IS_ERR(gpio->load_gpio)) {
>> +               ret = PTR_ERR(gpio->load_gpio);
>> +               if (ret != -ENOENT && ret != -ENOSYS) {
>> +                       if (ret != -EPROBE_DEFER)
>> +                               dev_err(&spi->dev, "Unable to allocate reset gpio\n");
>
> Reset gpio? Really? Load GPIO?
>

Ops, copy/paste error I think.

Thanks,
Andrew

> Apart from that it looks good.
>
> Yours,
> Linus Walleij
>

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-14 16:41     ` Andrew F. Davis
@ 2015-12-14 22:36       ` Rob Herring
  2015-12-14 23:19         ` Andrew F. Davis
  2015-12-17  8:28       ` Geert Uytterhoeven
  1 sibling, 1 reply; 26+ messages in thread
From: Rob Herring @ 2015-12-14 22:36 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Linus Walleij, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On Mon, Dec 14, 2015 at 10:41 AM, Andrew F. Davis <afd@ti.com> wrote:
> On 12/11/2015 03:48 PM, Linus Walleij wrote:
>>
>> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:
>>
>>> Add binding for generic parallel-in/serial-out shift register devices
>>> used as GPIO.
>>>
>>> Signed-off-by: Andrew F. Davis <afd@ti.com>
>>
>>
>>> +Generic Parallel-in/Serial-out Shift Register GPIO Driver
>>> +
>>> +This binding describes generic parallel-in/serial-out shift register
>>> +devices that can be used for GPI (General Purpose Input). This includes
>>> +SN74165 serial-out shift registers and the SN65HVS88x series of
>>> +industrial serializers.
>>> +
>>> +Required properties:
>>> + - compatible          : Should be "pisosr-gpio".
>>
>>
>> I think it should also define compatible strings on the "vendor,device"
>> format apart from the generic compatible. Sooner or later we may need
>> to differentiate them and then that comes in handy.
>>
>
> Would it be better to wait until/if this issue arises? This driver
> targets the generic features, as these parts are very generic and
> have been produced by many companies since the 70s I'm not sure
> if privileging any of them makes much sense.
>
> What I'm worried about looks to have happened with the gpio-74x164
> driver, this is kind of the companion device to mine (74164 / 74165)
> and should work with any 74164 compatible shift register (possibly 100s
> of versions of them), but the compatible string that was added is
> "fairchild,74hc595", a relatively new device by a single manufacturer.
> The problem this has is then that boards will use this compatible string
> even if the parts are not actually the Fairchild version, just to get
> the match, when they should be using a generic string.

I agree the generic version is fine (or find who made the first part
;)). What "pisosr" is is not very obvious though. Having 74165 in the
compatible would make it somewhat more obvious it is a standard logic
part.

>>> +Optional properties:
>>> + - ngpios              : Number of GPIO lines, default is 8.
>>
>>
>> If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
>> don't need to have this in the device tree but instead it can be
>> determined from the compatible string?
>>
>> In that case do that.
>>
>
> These devices can be daisy-chained together, so three 8bit registers
> look exactly like one 24bit register. The only way to know this is
> from the physical wiring of the board, not from the part number.

Then you should say it must be multiple of 8 (or are there other lengths?).

Rob

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-14 22:36       ` Rob Herring
@ 2015-12-14 23:19         ` Andrew F. Davis
       [not found]           ` <566F4E9B.8090202-l0cyMroinI0@public.gmane.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-14 23:19 UTC (permalink / raw)
  To: Rob Herring
  Cc: Linus Walleij, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On 12/14/2015 04:36 PM, Rob Herring wrote:
> On Mon, Dec 14, 2015 at 10:41 AM, Andrew F. Davis <afd@ti.com> wrote:
>> On 12/11/2015 03:48 PM, Linus Walleij wrote:
>>>
>>> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:
>>>
>>>> Add binding for generic parallel-in/serial-out shift register devices
>>>> used as GPIO.
>>>>
>>>> Signed-off-by: Andrew F. Davis <afd@ti.com>
>>>
>>>
>>>> +Generic Parallel-in/Serial-out Shift Register GPIO Driver
>>>> +
>>>> +This binding describes generic parallel-in/serial-out shift register
>>>> +devices that can be used for GPI (General Purpose Input). This includes
>>>> +SN74165 serial-out shift registers and the SN65HVS88x series of
>>>> +industrial serializers.
>>>> +
>>>> +Required properties:
>>>> + - compatible          : Should be "pisosr-gpio".
>>>
>>>
>>> I think it should also define compatible strings on the "vendor,device"
>>> format apart from the generic compatible. Sooner or later we may need
>>> to differentiate them and then that comes in handy.
>>>
>>
>> Would it be better to wait until/if this issue arises? This driver
>> targets the generic features, as these parts are very generic and
>> have been produced by many companies since the 70s I'm not sure
>> if privileging any of them makes much sense.
>>
>> What I'm worried about looks to have happened with the gpio-74x164
>> driver, this is kind of the companion device to mine (74164 / 74165)
>> and should work with any 74164 compatible shift register (possibly 100s
>> of versions of them), but the compatible string that was added is
>> "fairchild,74hc595", a relatively new device by a single manufacturer.
>> The problem this has is then that boards will use this compatible string
>> even if the parts are not actually the Fairchild version, just to get
>> the match, when they should be using a generic string.
>
> I agree the generic version is fine (or find who made the first part
> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
> compatible would make it somewhat more obvious it is a standard logic
> part.
>

A quick search shows shift-registers being made from vacuum tubes for
the Colossus! Those might work with this driver if you could match the
voltage to an SPI bus... :)

I agree about the name not being very good, but I'm not sure about
74165 ether as it is also just a single part number. The idea was to
have a non-part number compatible string for any shift-register you
can hook to the SPI line. That way when we have boards with a sn65x882
or something we wont have to call it a 74165. But I guess that's why
it's a "compatible:" string, and not "is-a:" string.

>>>> +Optional properties:
>>>> + - ngpios              : Number of GPIO lines, default is 8.
>>>
>>>
>>> If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
>>> don't need to have this in the device tree but instead it can be
>>> determined from the compatible string?
>>>
>>> In that case do that.
>>>
>>
>> These devices can be daisy-chained together, so three 8bit registers
>> look exactly like one 24bit register. The only way to know this is
>> from the physical wiring of the board, not from the part number.
>
> Then you should say it must be multiple of 8 (or are there other lengths?).
>

Some are 4bit, you can even just hook a single flip-flop to the SPI bus for
a single bit (or multiples) of input.

Andrew

> Rob
>

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-14 23:19         ` Andrew F. Davis
@ 2015-12-16 16:29               ` Rob Herring
  0 siblings, 0 replies; 26+ messages in thread
From: Rob Herring @ 2015-12-16 16:29 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Linus Walleij, linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
	Alexandre Courbot, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Mon, Dec 14, 2015 at 5:19 PM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:
> On 12/14/2015 04:36 PM, Rob Herring wrote:
>>
>> On Mon, Dec 14, 2015 at 10:41 AM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:
>>>
>>> On 12/11/2015 03:48 PM, Linus Walleij wrote:
>>>>
>>>>
>>>> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:

[...]

>>>>> + - compatible          : Should be "pisosr-gpio".
>>>>
>>>>
>>>>
>>>> I think it should also define compatible strings on the "vendor,device"
>>>> format apart from the generic compatible. Sooner or later we may need
>>>> to differentiate them and then that comes in handy.
>>>>
>>>
>>> Would it be better to wait until/if this issue arises? This driver
>>> targets the generic features, as these parts are very generic and
>>> have been produced by many companies since the 70s I'm not sure
>>> if privileging any of them makes much sense.
>>>
>>> What I'm worried about looks to have happened with the gpio-74x164
>>> driver, this is kind of the companion device to mine (74164 / 74165)
>>> and should work with any 74164 compatible shift register (possibly 100s
>>> of versions of them), but the compatible string that was added is
>>> "fairchild,74hc595", a relatively new device by a single manufacturer.
>>> The problem this has is then that boards will use this compatible string
>>> even if the parts are not actually the Fairchild version, just to get
>>> the match, when they should be using a generic string.
>>
>>
>> I agree the generic version is fine (or find who made the first part
>> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
>> compatible would make it somewhat more obvious it is a standard logic
>> part.
>>
>
> A quick search shows shift-registers being made from vacuum tubes for
> the Colossus! Those might work with this driver if you could match the
> voltage to an SPI bus... :)
>
> I agree about the name not being very good, but I'm not sure about
> 74165 ether as it is also just a single part number. The idea was to
> have a non-part number compatible string for any shift-register you
> can hook to the SPI line. That way when we have boards with a sn65x882
> or something we wont have to call it a 74165. But I guess that's why
> it's a "compatible:" string, and not "is-a:" string.

If there are a couple then I think it is okay. If there are 10s then
maybe not. Perhaps logic-pisosr or discrete-pisosr?

>>>>> +Optional properties:
>>>>> + - ngpios              : Number of GPIO lines, default is 8.
>>>>
>>>>
>>>>
>>>> If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
>>>> don't need to have this in the device tree but instead it can be
>>>> determined from the compatible string?
>>>>
>>>> In that case do that.
>>>>
>>>
>>> These devices can be daisy-chained together, so three 8bit registers
>>> look exactly like one 24bit register. The only way to know this is
>>> from the physical wiring of the board, not from the part number.
>>
>>
>> Then you should say it must be multiple of 8 (or are there other
>> lengths?).
>>
>
> Some are 4bit, you can even just hook a single flip-flop to the SPI bus for
> a single bit (or multiples) of input.

One would hope you would just connect the CS signal directly to that
input for 1-bit... I guess you could be out of GPIOs and only have a
free output only CS signal.

Rob
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
@ 2015-12-16 16:29               ` Rob Herring
  0 siblings, 0 replies; 26+ messages in thread
From: Rob Herring @ 2015-12-16 16:29 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Linus Walleij, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On Mon, Dec 14, 2015 at 5:19 PM, Andrew F. Davis <afd@ti.com> wrote:
> On 12/14/2015 04:36 PM, Rob Herring wrote:
>>
>> On Mon, Dec 14, 2015 at 10:41 AM, Andrew F. Davis <afd@ti.com> wrote:
>>>
>>> On 12/11/2015 03:48 PM, Linus Walleij wrote:
>>>>
>>>>
>>>> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:

[...]

>>>>> + - compatible          : Should be "pisosr-gpio".
>>>>
>>>>
>>>>
>>>> I think it should also define compatible strings on the "vendor,device"
>>>> format apart from the generic compatible. Sooner or later we may need
>>>> to differentiate them and then that comes in handy.
>>>>
>>>
>>> Would it be better to wait until/if this issue arises? This driver
>>> targets the generic features, as these parts are very generic and
>>> have been produced by many companies since the 70s I'm not sure
>>> if privileging any of them makes much sense.
>>>
>>> What I'm worried about looks to have happened with the gpio-74x164
>>> driver, this is kind of the companion device to mine (74164 / 74165)
>>> and should work with any 74164 compatible shift register (possibly 100s
>>> of versions of them), but the compatible string that was added is
>>> "fairchild,74hc595", a relatively new device by a single manufacturer.
>>> The problem this has is then that boards will use this compatible string
>>> even if the parts are not actually the Fairchild version, just to get
>>> the match, when they should be using a generic string.
>>
>>
>> I agree the generic version is fine (or find who made the first part
>> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
>> compatible would make it somewhat more obvious it is a standard logic
>> part.
>>
>
> A quick search shows shift-registers being made from vacuum tubes for
> the Colossus! Those might work with this driver if you could match the
> voltage to an SPI bus... :)
>
> I agree about the name not being very good, but I'm not sure about
> 74165 ether as it is also just a single part number. The idea was to
> have a non-part number compatible string for any shift-register you
> can hook to the SPI line. That way when we have boards with a sn65x882
> or something we wont have to call it a 74165. But I guess that's why
> it's a "compatible:" string, and not "is-a:" string.

If there are a couple then I think it is okay. If there are 10s then
maybe not. Perhaps logic-pisosr or discrete-pisosr?

>>>>> +Optional properties:
>>>>> + - ngpios              : Number of GPIO lines, default is 8.
>>>>
>>>>
>>>>
>>>> If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
>>>> don't need to have this in the device tree but instead it can be
>>>> determined from the compatible string?
>>>>
>>>> In that case do that.
>>>>
>>>
>>> These devices can be daisy-chained together, so three 8bit registers
>>> look exactly like one 24bit register. The only way to know this is
>>> from the physical wiring of the board, not from the part number.
>>
>>
>> Then you should say it must be multiple of 8 (or are there other
>> lengths?).
>>
>
> Some are 4bit, you can even just hook a single flip-flop to the SPI bus for
> a single bit (or multiples) of input.

One would hope you would just connect the CS signal directly to that
input for 1-bit... I guess you could be out of GPIOs and only have a
free output only CS signal.

Rob

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-14 16:41     ` Andrew F. Davis
  2015-12-14 22:36       ` Rob Herring
@ 2015-12-17  8:28       ` Geert Uytterhoeven
       [not found]         ` <CAMuHMdUVS6zRAMyES1171N94WK53mF5dd7ADYqrnaegsu2U4dQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 26+ messages in thread
From: Geert Uytterhoeven @ 2015-12-17  8:28 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Linus Walleij, linux-spi, Mark Brown, Alexandre Courbot,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	linux-gpio, devicetree, linux-kernel

On Mon, Dec 14, 2015 at 5:41 PM, Andrew F. Davis <afd@ti.com> wrote:
> What I'm worried about looks to have happened with the gpio-74x164
> driver, this is kind of the companion device to mine (74164 / 74165)
> and should work with any 74164 compatible shift register (possibly 100s
> of versions of them), but the compatible string that was added is
> "fairchild,74hc595", a relatively new device by a single manufacturer.

In hindsight, that probably should have been "motorola,mc74hc595" instead.
Recently I read that Motorola invented the 74hc59x for their "new" SPI bus
as that time, as the 74164 is not 100% SPI-compatible.

Given the limitations of the '164 for SPI, is the same true for '165, and
should it be "[...]74[...]597" instead?

> The problem this has is then that boards will use this compatible string
> even if the parts are not actually the Fairchild version, just to get
> the match, when they should be using a generic string.

They're all supposed to be "compatible".
Personally, I wouldn't object to just "74595", cfr. "ns16550a".

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-17  8:28       ` Geert Uytterhoeven
@ 2015-12-17  8:29             ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2015-12-17  8:29 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Linus Walleij, linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
	Alexandre Courbot, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Thu, Dec 17, 2015 at 9:28 AM, Geert Uytterhoeven
<geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org> wrote:
> Given the limitations of the '164 for SPI, is the same true for '165, and
> should it be "[...]74[...]597" instead?

Forget it, this driver is not about SPI.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
@ 2015-12-17  8:29             ` Geert Uytterhoeven
  0 siblings, 0 replies; 26+ messages in thread
From: Geert Uytterhoeven @ 2015-12-17  8:29 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Linus Walleij, linux-spi, Mark Brown, Alexandre Courbot,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	linux-gpio, devicetree, linux-kernel

On Thu, Dec 17, 2015 at 9:28 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Given the limitations of the '164 for SPI, is the same true for '165, and
> should it be "[...]74[...]597" instead?

Forget it, this driver is not about SPI.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-14 23:19         ` Andrew F. Davis
@ 2015-12-22  9:51               ` Linus Walleij
  0 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2015-12-22  9:51 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Rob Herring, linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
	Alexandre Courbot, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tue, Dec 15, 2015 at 12:19 AM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:
> [Rob]
>> I agree the generic version is fine (or find who made the first part
>> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
>> compatible would make it somewhat more obvious it is a standard logic
>> part.
>>
>
> A quick search shows shift-registers being made from vacuum tubes for
> the Colossus! Those might work with this driver if you could match the
> voltage to an SPI bus... :)
>
> I agree about the name not being very good, but I'm not sure about
> 74165 ether as it is also just a single part number.

We can add many compatible strings so it's not an issue.
"ti,74165" works for me as TI invented the 74xx series.

> The idea was to
> have a non-part number compatible string for any shift-register you
> can hook to the SPI line.

Again, one does not exclude the other. I'm happy with a generic
compatible *and* "ti,74165".

> That way when we have boards with a sn65x882
> or something we wont have to call it a 74165. But I guess that's why
> it's a "compatible:" string, and not "is-a:" string.

Compatible ranges from the specific to the more generic
so compatible = "ti,74165", "pisosr"; is just fine. Something
will match if there is a suitable driver. The OS may choose to
provide something part-specific or something more generic.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
@ 2015-12-22  9:51               ` Linus Walleij
  0 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2015-12-22  9:51 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Rob Herring, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On Tue, Dec 15, 2015 at 12:19 AM, Andrew F. Davis <afd@ti.com> wrote:
> [Rob]
>> I agree the generic version is fine (or find who made the first part
>> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
>> compatible would make it somewhat more obvious it is a standard logic
>> part.
>>
>
> A quick search shows shift-registers being made from vacuum tubes for
> the Colossus! Those might work with this driver if you could match the
> voltage to an SPI bus... :)
>
> I agree about the name not being very good, but I'm not sure about
> 74165 ether as it is also just a single part number.

We can add many compatible strings so it's not an issue.
"ti,74165" works for me as TI invented the 74xx series.

> The idea was to
> have a non-part number compatible string for any shift-register you
> can hook to the SPI line.

Again, one does not exclude the other. I'm happy with a generic
compatible *and* "ti,74165".

> That way when we have boards with a sn65x882
> or something we wont have to call it a 74165. But I guess that's why
> it's a "compatible:" string, and not "is-a:" string.

Compatible ranges from the specific to the more generic
so compatible = "ti,74165", "pisosr"; is just fine. Something
will match if there is a suitable driver. The OS may choose to
provide something part-specific or something more generic.

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-16 16:29               ` Rob Herring
  (?)
@ 2015-12-30 16:59               ` Andrew F. Davis
  -1 siblings, 0 replies; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-30 16:59 UTC (permalink / raw)
  To: Rob Herring
  Cc: Linus Walleij, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On 12/16/2015 10:29 AM, Rob Herring wrote:
> On Mon, Dec 14, 2015 at 5:19 PM, Andrew F. Davis <afd@ti.com> wrote:
>> On 12/14/2015 04:36 PM, Rob Herring wrote:
>>>
>>> On Mon, Dec 14, 2015 at 10:41 AM, Andrew F. Davis <afd@ti.com> wrote:
>>>>
>>>> On 12/11/2015 03:48 PM, Linus Walleij wrote:
>>>>>
>>>>>
>>>>> On Fri, Dec 11, 2015 at 8:46 PM, Andrew F. Davis <afd@ti.com> wrote:
>
> [...]
>
>>>>>> + - compatible          : Should be "pisosr-gpio".
>>>>>
>>>>>
>>>>>
>>>>> I think it should also define compatible strings on the "vendor,device"
>>>>> format apart from the generic compatible. Sooner or later we may need
>>>>> to differentiate them and then that comes in handy.
>>>>>
>>>>
>>>> Would it be better to wait until/if this issue arises? This driver
>>>> targets the generic features, as these parts are very generic and
>>>> have been produced by many companies since the 70s I'm not sure
>>>> if privileging any of them makes much sense.
>>>>
>>>> What I'm worried about looks to have happened with the gpio-74x164
>>>> driver, this is kind of the companion device to mine (74164 / 74165)
>>>> and should work with any 74164 compatible shift register (possibly 100s
>>>> of versions of them), but the compatible string that was added is
>>>> "fairchild,74hc595", a relatively new device by a single manufacturer.
>>>> The problem this has is then that boards will use this compatible string
>>>> even if the parts are not actually the Fairchild version, just to get
>>>> the match, when they should be using a generic string.
>>>
>>>
>>> I agree the generic version is fine (or find who made the first part
>>> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
>>> compatible would make it somewhat more obvious it is a standard logic
>>> part.
>>>
>>
>> A quick search shows shift-registers being made from vacuum tubes for
>> the Colossus! Those might work with this driver if you could match the
>> voltage to an SPI bus... :)
>>
>> I agree about the name not being very good, but I'm not sure about
>> 74165 ether as it is also just a single part number. The idea was to
>> have a non-part number compatible string for any shift-register you
>> can hook to the SPI line. That way when we have boards with a sn65x882
>> or something we wont have to call it a 74165. But I guess that's why
>> it's a "compatible:" string, and not "is-a:" string.
>
> If there are a couple then I think it is okay. If there are 10s then
> maybe not. Perhaps logic-pisosr or discrete-pisosr?
>

My concern as well, there are a lot of them, and every device doesn't
need its own string, so why privilege the name of any that don't have
anything different.

I'd like to leave the named ones for odd cases that needs special
handling.

>>>>>> +Optional properties:
>>>>>> + - ngpios              : Number of GPIO lines, default is 8.
>>>>>
>>>>>
>>>>>
>>>>> If you didn't do "pisosr-gpio" but instead "foo,sn74165", maybe you
>>>>> don't need to have this in the device tree but instead it can be
>>>>> determined from the compatible string?
>>>>>
>>>>> In that case do that.
>>>>>
>>>>
>>>> These devices can be daisy-chained together, so three 8bit registers
>>>> look exactly like one 24bit register. The only way to know this is
>>>> from the physical wiring of the board, not from the part number.
>>>
>>>
>>> Then you should say it must be multiple of 8 (or are there other
>>> lengths?).
>>>
>>
>> Some are 4bit, you can even just hook a single flip-flop to the SPI bus for
>> a single bit (or multiples) of input.
>
> One would hope you would just connect the CS signal directly to that
> input for 1-bit... I guess you could be out of GPIOs and only have a
> free output only CS signal.
>

Interesting use-case idea :), I'm more worried about a device with any
prime number of pins where multiples will fail, not that I have ever
seen one.

Andrew

> Rob
>

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-22  9:51               ` Linus Walleij
  (?)
@ 2015-12-30 17:05               ` Andrew F. Davis
       [not found]                 ` <56840ED0.6070205-l0cyMroinI0@public.gmane.org>
  -1 siblings, 1 reply; 26+ messages in thread
From: Andrew F. Davis @ 2015-12-30 17:05 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Rob Herring, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On 12/22/2015 03:51 AM, Linus Walleij wrote:
> On Tue, Dec 15, 2015 at 12:19 AM, Andrew F. Davis <afd@ti.com> wrote:
>> [Rob]
>>> I agree the generic version is fine (or find who made the first part
>>> ;)). What "pisosr" is is not very obvious though. Having 74165 in the
>>> compatible would make it somewhat more obvious it is a standard logic
>>> part.
>>>
>>
>> A quick search shows shift-registers being made from vacuum tubes for
>> the Colossus! Those might work with this driver if you could match the
>> voltage to an SPI bus... :)
>>
>> I agree about the name not being very good, but I'm not sure about
>> 74165 ether as it is also just a single part number.
>
> We can add many compatible strings so it's not an issue.
> "ti,74165" works for me as TI invented the 74xx series.
>

Free advertising for our parts :)

>> The idea was to
>> have a non-part number compatible string for any shift-register you
>> can hook to the SPI line.
>
> Again, one does not exclude the other. I'm happy with a generic
> compatible *and* "ti,74165".
>
>> That way when we have boards with a sn65x882
>> or something we wont have to call it a 74165. But I guess that's why
>> it's a "compatible:" string, and not "is-a:" string.
>
> Compatible ranges from the specific to the more generic
> so compatible = "ti,74165", "pisosr"; is just fine. Something
> will match if there is a suitable driver. The OS may choose to
> provide something part-specific or something more generic.
>

And so we won't need to have "ti,74165" in the driver itself,
if we just have "pisosr", then dts files can use what ever they
like to correctly identify the part then fall back to pisosr.

compatible = "company,random_numbers_of_exact_part_actually_on_board", "pisosr";

Andrew

> Yours,
> Linus Walleij
>

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
  2015-12-30 17:05               ` Andrew F. Davis
@ 2016-01-27 13:57                     ` Linus Walleij
  0 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2016-01-27 13:57 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Rob Herring, linux-spi-u79uwXL29TY76Z2rM5mHXA, Mark Brown,
	Alexandre Courbot, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Wed, Dec 30, 2015 at 6:05 PM, Andrew F. Davis <afd-l0cyMroinI0@public.gmane.org> wrote:
> [Me]
>> Compatible ranges from the specific to the more generic
>> so compatible = "ti,74165", "pisosr"; is just fine. Something
>> will match if there is a suitable driver. The OS may choose to
>> provide something part-specific or something more generic.
>>
>
> And so we won't need to have "ti,74165" in the driver itself,
> if we just have "pisosr", then dts files can use what ever they
> like to correctly identify the part then fall back to pisosr.
>
> compatible = "company,random_numbers_of_exact_part_actually_on_board",
> "pisosr";

Exactly. Sorry for slow replies.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding
@ 2016-01-27 13:57                     ` Linus Walleij
  0 siblings, 0 replies; 26+ messages in thread
From: Linus Walleij @ 2016-01-27 13:57 UTC (permalink / raw)
  To: Andrew F. Davis
  Cc: Rob Herring, linux-spi, Mark Brown, Alexandre Courbot,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, linux-gpio,
	devicetree, linux-kernel

On Wed, Dec 30, 2015 at 6:05 PM, Andrew F. Davis <afd@ti.com> wrote:
> [Me]
>> Compatible ranges from the specific to the more generic
>> so compatible = "ti,74165", "pisosr"; is just fine. Something
>> will match if there is a suitable driver. The OS may choose to
>> provide something part-specific or something more generic.
>>
>
> And so we won't need to have "ti,74165" in the driver itself,
> if we just have "pisosr", then dts files can use what ever they
> like to correctly identify the part then fall back to pisosr.
>
> compatible = "company,random_numbers_of_exact_part_actually_on_board",
> "pisosr";

Exactly. Sorry for slow replies.

Yours,
Linus Walleij

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

end of thread, other threads:[~2016-01-27 13:57 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-11 19:46 [PATCH 0/2] gpio: Add driver for SPI serializers Andrew F. Davis
2015-12-11 19:46 ` Andrew F. Davis
2015-12-11 19:46 ` [PATCH 1/2] dt-bindings: GPIO: Add generic serializer binding Andrew F. Davis
2015-12-11 19:46   ` Andrew F. Davis
2015-12-11 21:48   ` Linus Walleij
2015-12-14 16:41     ` Andrew F. Davis
2015-12-14 22:36       ` Rob Herring
2015-12-14 23:19         ` Andrew F. Davis
     [not found]           ` <566F4E9B.8090202-l0cyMroinI0@public.gmane.org>
2015-12-16 16:29             ` Rob Herring
2015-12-16 16:29               ` Rob Herring
2015-12-30 16:59               ` Andrew F. Davis
2015-12-22  9:51             ` Linus Walleij
2015-12-22  9:51               ` Linus Walleij
2015-12-30 17:05               ` Andrew F. Davis
     [not found]                 ` <56840ED0.6070205-l0cyMroinI0@public.gmane.org>
2016-01-27 13:57                   ` Linus Walleij
2016-01-27 13:57                     ` Linus Walleij
2015-12-17  8:28       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdUVS6zRAMyES1171N94WK53mF5dd7ADYqrnaegsu2U4dQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-17  8:29           ` Geert Uytterhoeven
2015-12-17  8:29             ` Geert Uytterhoeven
2015-12-11 19:46 ` [PATCH 2/2] gpio: Add driver for SPI serializers Andrew F. Davis
2015-12-11 19:46   ` Andrew F. Davis
     [not found]   ` <1449863184-29668-3-git-send-email-afd-l0cyMroinI0@public.gmane.org>
2015-12-11 22:09     ` Linus Walleij
2015-12-11 22:09       ` Linus Walleij
     [not found]       ` <CACRpkda0zAg_vAWd6nZLpWqZo4u5kLbBCCJ4WzO-fP08=CBQTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-14 16:47         ` Andrew F. Davis
2015-12-14 16:47           ` Andrew F. Davis
2015-12-11 21:43 ` [PATCH 0/2] " Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.