linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: serial: max310x: Support open-drain configuration for GPIOs
@ 2017-12-22 20:29 Jan Kundrát
  2017-12-28 23:38 ` Linus Walleij
  2018-01-09 15:37 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kundrát @ 2017-12-22 20:29 UTC (permalink / raw)
  To: linux-gpio
  Cc: Greg Kroah-Hartman, linux-serial, Alexander Shiyan, Linus Walleij

The push-pull vs. open-drain are the only supported output modes. The
inputs are always unconditionally equipped with weak pull-downs. That's
the only mode, so there's probably no point in exporting that. I wonder
if it's worthwhile to provide a custom dbg_show method to indicate the
current status of the outputs, though.

This patch and [1] for i2c-gpio together make it possible to bit-bang an
I2C bus over GPIOs of an UART which is connected via SPI :). Yes, this
is crazy, but it's fast enough (while on a 26Mhz SPI HW bus with a
dual-core 1.6GHz CPU) to drive an I2C bus at 200kHz, according to my
scope.

[1] https://patchwork.ozlabs.org/patch/852591/

Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
---
My suggestion is for this patch to go in via the tty/serial tree; I plan
to send more patches to this driver (and some of them are alreay in
tty-next). --jkt

---
 drivers/tty/serial/max310x.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index d0e55f8456a5..c44387d0625a 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1187,6 +1187,27 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip,
 	return 0;
 }
 
+static int max310x_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
+				   unsigned long config)
+{
+	struct max310x_port *s = gpiochip_get_data(chip);
+	struct uart_port *port = &s->p[offset / 4].port;
+
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_DRIVE_OPEN_DRAIN:
+		max310x_port_update(port, MAX310X_GPIOCFG_REG,
+				1 << ((offset % 4) + 4),
+				1 << ((offset % 4) + 4));
+		return 0;
+	case PIN_CONFIG_DRIVE_PUSH_PULL:
+		max310x_port_update(port, MAX310X_GPIOCFG_REG,
+				1 << ((offset % 4) + 4), 0);
+		return 0;
+	default:
+		return -ENOTSUPP;
+	}
+}
+
 static void max310x_gpio_irq_mask(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
@@ -1426,6 +1447,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
 	s->gpio.get		= max310x_gpio_get;
 	s->gpio.direction_output= max310x_gpio_direction_output;
 	s->gpio.set		= max310x_gpio_set;
+	s->gpio.set_config	= max310x_gpio_set_config;
 	s->gpio.base		= -1;
 	s->gpio.ngpio		= devtype->nr * 4;
 	s->gpio.can_sleep	= 1;
-- 
2.14.3



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

* [PATCH v2] gpio: serial: max310x: Support open-drain configuration for GPIOs
  2018-01-09 15:37 ` Greg Kroah-Hartman
@ 2017-12-22 20:29   ` Jan Kundrát
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kundrát @ 2017-12-22 20:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-serial, linux-gpio, Alexander Shiyan, Linus Walleij

The push-pull vs. open-drain are the only supported output modes. The
inputs are always unconditionally equipped with weak pull-downs. That's
the only mode, so there's probably no point in exporting that. I wonder
if it's worthwhile to provide a custom dbg_show method to indicate the
current status of the outputs, though.

This patch and [1] for i2c-gpio together make it possible to bit-bang an
I2C bus over GPIOs of an UART which is connected via SPI :). Yes, this
is crazy, but it's fast enough (while on a 26Mhz SPI HW bus with a
dual-core 1.6GHz CPU) to drive an I2C bus at 200kHz, according to my
scope.

[1] https://patchwork.ozlabs.org/patch/852591/

Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/tty/serial/max310x.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 97576ff791db..39f635812077 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1159,6 +1159,27 @@ static int max310x_gpio_direction_output(struct gpio_chip *chip,
 
 	return 0;
 }
+
+static int max310x_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
+				   unsigned long config)
+{
+	struct max310x_port *s = gpiochip_get_data(chip);
+	struct uart_port *port = &s->p[offset / 4].port;
+
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_DRIVE_OPEN_DRAIN:
+		max310x_port_update(port, MAX310X_GPIOCFG_REG,
+				1 << ((offset % 4) + 4),
+				1 << ((offset % 4) + 4));
+		return 0;
+	case PIN_CONFIG_DRIVE_PUSH_PULL:
+		max310x_port_update(port, MAX310X_GPIOCFG_REG,
+				1 << ((offset % 4) + 4), 0);
+		return 0;
+	default:
+		return -ENOTSUPP;
+	}
+}
 #endif
 
 static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
@@ -1302,6 +1323,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
 	s->gpio.get		= max310x_gpio_get;
 	s->gpio.direction_output= max310x_gpio_direction_output;
 	s->gpio.set		= max310x_gpio_set;
+	s->gpio.set_config	= max310x_gpio_set_config;
 	s->gpio.base		= -1;
 	s->gpio.ngpio		= devtype->nr * 4;
 	s->gpio.can_sleep	= 1;
-- 
2.14.3



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

* Re: [PATCH] gpio: serial: max310x: Support open-drain configuration for GPIOs
  2017-12-22 20:29 [PATCH] gpio: serial: max310x: Support open-drain configuration for GPIOs Jan Kundrát
@ 2017-12-28 23:38 ` Linus Walleij
  2018-01-09 15:37 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2017-12-28 23:38 UTC (permalink / raw)
  To: Jan Kundrát
  Cc: linux-gpio, Greg Kroah-Hartman, linux-serial, Alexander Shiyan

On Fri, Dec 22, 2017 at 9:29 PM, Jan Kundrát <jan.kundrat@cesnet.cz> wrote:

> The push-pull vs. open-drain are the only supported output modes. The
> inputs are always unconditionally equipped with weak pull-downs. That's
> the only mode, so there's probably no point in exporting that. I wonder
> if it's worthwhile to provide a custom dbg_show method to indicate the
> current status of the outputs, though.
>
> This patch and [1] for i2c-gpio together make it possible to bit-bang an
> I2C bus over GPIOs of an UART which is connected via SPI :). Yes, this
> is crazy, but it's fast enough (while on a 26Mhz SPI HW bus with a
> dual-core 1.6GHz CPU) to drive an I2C bus at 200kHz, according to my
> scope.
>
> [1] https://patchwork.ozlabs.org/patch/852591/
>
> Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
> ---
> My suggestion is for this patch to go in via the tty/serial tree; I plan
> to send more patches to this driver (and some of them are alreay in
> tty-next). --jkt

OK Greg can pick this.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

(Looks very useful for hardware hacking, by the way.)

Yours,
Linus Walleij

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

* Re: [PATCH] gpio: serial: max310x: Support open-drain configuration for GPIOs
  2017-12-22 20:29 [PATCH] gpio: serial: max310x: Support open-drain configuration for GPIOs Jan Kundrát
  2017-12-28 23:38 ` Linus Walleij
@ 2018-01-09 15:37 ` Greg Kroah-Hartman
  2017-12-22 20:29   ` [PATCH v2] " Jan Kundrát
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2018-01-09 15:37 UTC (permalink / raw)
  To: Jan Kundrát
  Cc: linux-gpio, linux-serial, Alexander Shiyan, Linus Walleij

On Fri, Dec 22, 2017 at 09:29:44PM +0100, Jan Kundrát wrote:
> The push-pull vs. open-drain are the only supported output modes. The
> inputs are always unconditionally equipped with weak pull-downs. That's
> the only mode, so there's probably no point in exporting that. I wonder
> if it's worthwhile to provide a custom dbg_show method to indicate the
> current status of the outputs, though.
> 
> This patch and [1] for i2c-gpio together make it possible to bit-bang an
> I2C bus over GPIOs of an UART which is connected via SPI :). Yes, this
> is crazy, but it's fast enough (while on a 26Mhz SPI HW bus with a
> dual-core 1.6GHz CPU) to drive an I2C bus at 200kHz, according to my
> scope.
> 
> [1] https://patchwork.ozlabs.org/patch/852591/
> 
> Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> My suggestion is for this patch to go in via the tty/serial tree; I plan
> to send more patches to this driver (and some of them are alreay in
> tty-next). --jkt

Doesn't apply to my tty-next branch, so I can't apply it, please rebase
and resend.

thanks,

greg k-h

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

end of thread, other threads:[~2018-01-09 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-22 20:29 [PATCH] gpio: serial: max310x: Support open-drain configuration for GPIOs Jan Kundrát
2017-12-28 23:38 ` Linus Walleij
2018-01-09 15:37 ` Greg Kroah-Hartman
2017-12-22 20:29   ` [PATCH v2] " Jan Kundrát

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).