From patchwork Fri Dec 22 20:29:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Kundr=C3=A1t?= X-Patchwork-Id: 857626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=cesnet.cz header.i=@cesnet.cz header.b="P7OS+nm2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zGHWp4jr0z9rxj for ; Wed, 10 Jan 2018 03:23:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758826AbeAIQXt (ORCPT ); Tue, 9 Jan 2018 11:23:49 -0500 Received: from office2.cesnet.cz ([195.113.144.244]:44368 "EHLO office2.cesnet.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756854AbeAIQXs (ORCPT ); Tue, 9 Jan 2018 11:23:48 -0500 Received: from localhost (unknown [IPv6:2001:718:1:2c:7565:7aca:2c52:2b4e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id 6D58B400065; Tue, 9 Jan 2018 17:23:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2; t=1515515026; bh=Fcv9SIrwgNw4wg4COYjTWrYsMIBrb2qnIP7wK0EUps4=; h=Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:From:Date:Subject:To:Cc; b=P7OS+nm2qM2SPRzWJpYiUoFJlqhyeF52WbrJTEtGhBAR/fDM0QkAq8O1DF4/wVuUf LaZD9khajshewBQK09Dd72cwmxSMRdKzth1ATOVOf1iic0nVDOZk9PWJNoFQXVhAX4 4chsA2i12VJ1f5c8/0PS8W3+BALjwZcWsnhl7zrw= Message-Id: In-Reply-To: <20180109153721.GA17957@kroah.com> References: <20180109153721.GA17957@kroah.com> From: =?utf-8?q?Jan_Kundr=C3=A1t?= Date: Fri, 22 Dec 2017 21:29:44 +0100 Subject: [PATCH v2] gpio: serial: max310x: Support open-drain configuration for GPIOs MIME-Version: 1.0 To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, linux-gpio@vger.kernel.org, Alexander Shiyan , Linus Walleij Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 Reviewed-by: Linus Walleij --- 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;