From patchwork Tue Jan 9 00:32:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 857182 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; unprotected) header.d=linaro.org header.i=@linaro.org header.b="LPpTmnwK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zFtSl0NSDz9ryT for ; Tue, 9 Jan 2018 11:34:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755022AbeAIAeq (ORCPT ); Mon, 8 Jan 2018 19:34:46 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:34284 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752907AbeAIAep (ORCPT ); Mon, 8 Jan 2018 19:34:45 -0500 Received: by mail-lf0-f66.google.com with SMTP id h140so14038814lfg.1 for ; Mon, 08 Jan 2018 16:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=8po5DbOU+D2gLBjycWLFcgyH4oDl6KaDXH+9d2m8vS8=; b=LPpTmnwKO3D+Q4t+b1/M+yxC7ZNLvjCyrhAGW+iPKZfRnzK7JOv1n3TCAVpERHNPUA ya001lavZkcoqN4fhbq1meWvLjzi2L51GC1ofkSUOLzLUrcKH0EfoxSNTeR/iKTWg+LX tpS7lryELa3O0wPcqmiCsRiojOVc/PQ+rDCEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8po5DbOU+D2gLBjycWLFcgyH4oDl6KaDXH+9d2m8vS8=; b=PaI3s6qGkdeT2F/gIqjDi2lOsmiJoC5ymw/vPHK5pZTU6UJF90U2mVA93lkFJYtz+d B67dKnH5dAP3wgcs5/auYYUygeKdwpWu11s2EgDJU8RTHj3+nwmuwpswhqee3wHEWsnv S8wpEFk5753Mb8nZ7jjM0bRptY0PO5yT45Vu5SI7v7R3gcFIdruWEAPAix90//wUCfh9 ie7dbtogY/m1JHBuDS2CsJLnMq9K7mou+oImPbicE6erBXkzHVPZez7Qf3hLPNPIdP1g 03wWcLKHdYiiiZA0HNbR4a8gjba2wbpjBpyfGN3xu3ufKgT0G3knJjSA1KJSCTJvwtRT xtTw== X-Gm-Message-State: AKwxytfHDIhbJ/6jmdf+DEsRPhAgT7MlSTdLbnUdq4VIy8pxV3/Ss198 lqAxTc1k6CKPTBBmBeXjZ8FwsA== X-Google-Smtp-Source: ACJfBosx87GYIjrHWYvshyd0JU9dw75F/xkvuxieHkviBO0swnmJT/f5/J/PIDfkydfk+qZ1glihkQ== X-Received: by 10.25.215.223 with SMTP id q92mr5914496lfi.107.1515458083645; Mon, 08 Jan 2018 16:34:43 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id g192sm2342786lfg.69.2018.01.08.16.34.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 16:34:42 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown , linux-gpio@vger.kernel.org, Rob Herring Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 4/4] gpio: of: Add special quirk to parse regulator flags Date: Tue, 9 Jan 2018 01:32:40 +0100 Message-Id: <20180109003240.22924-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org While most GPIOs are indicated to be active low or open drain using their twocell flags, we have legacy regulator bindings to take into account. Add a quirk respecting the special boolean active-high and open drain flags when parsing regulator nodes for GPIOs. This makes it possible to get rid of duplicated inversion semantics handling in the regulator core and any regulator drivers parsing and handling this separately. Unfortunately the old regulator inversion semantics are specified such that the presence or absence of "enable-active-high" solely controls the semantics, so we cannot deprecate this in favor of the phandle-provided inversion flag, instead any such phandle inversion flag provided in the second cell of a GPIO handle must be actively ignored, so we print a warning to contain the situation and make things easy for the users. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-of.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 9686922310a4..37bd3e8f2b0b 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -56,6 +56,42 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, return gpiochip_get_desc(chip, ret); } +static void of_gpio_flags_quirks(struct device_node *np, + enum of_gpio_flags *flags) +{ + /* + * Some GPIO fixed regulator quirks. + * Note that active low is the default. + */ + if (IS_ENABLED(CONFIG_REGULATOR) && + (of_device_is_compatible(np, "reg-fixed-voltage") || + of_device_is_compatible(np, "regulator-gpio"))) { + /* + * The regulator GPIO handles are specified such that the + * presence or absence of "enable-active-high" solely controls + * the polarity of the GPIO line. Any phandle flags must + * be actively ignored. + */ + if (*flags & OF_GPIO_ACTIVE_LOW) { + pr_warn("%s GPIO handle specifies active low - ignored\n", + of_node_full_name(np)); + *flags &= ~OF_GPIO_ACTIVE_LOW; + } + if (!of_property_read_bool(np, "enable-active-high")) + *flags |= OF_GPIO_ACTIVE_LOW; + } + /* + * Legacy open drain handling for fixed voltage regulators. + */ + if (IS_ENABLED(CONFIG_REGULATOR) && + of_device_is_compatible(np, "reg-fixed-voltage") && + of_property_read_bool(np, "gpio-open-drain")) { + *flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN); + pr_info("%s uses legacy open drain flag - update the DTS if you can\n", + of_node_full_name(np)); + } +} + /** * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API * @np: device node to get GPIO from @@ -93,6 +129,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, if (IS_ERR(desc)) goto out; + of_gpio_flags_quirks(np, flags); + pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", __func__, propname, np, index, PTR_ERR_OR_ZERO(desc));