From patchwork Mon Feb 12 13:16:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 128055 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3200843ljc; Mon, 12 Feb 2018 05:17:41 -0800 (PST) X-Google-Smtp-Source: AH8x225eXqGlHZQcIcqzKe5dpHRNJvpeRAOrkPKoP8+KBFCdv84hHb27JVdDEL3QiTuhWWohdl/0 X-Received: by 10.101.74.134 with SMTP id b6mr9402281pgu.137.1518441461731; Mon, 12 Feb 2018 05:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518441461; cv=none; d=google.com; s=arc-20160816; b=Jajq9SVlUMLibza2groEowKPB3Q5vuav6x43DipuLy6I3TZwR+MkTsu6FcbM3WoL9w 2/19o3J4dnZrnOSgyuD0mAsYittMK6Ba/u80Knbnmp0njI/ARuwzytKejY7WfkHK0wYt JJwf/dApX1HYZvETiGwpYf2Z4xrY3mBQVMxz6SNDpzPV5KutIWWLq/nHcPHM3bWYjsdL 8IpPxBeuQQjUol89AVyZoww6fkz48Eky4JrGNQQjZvy66+t+4duSRLmCpEKe+knCuC8n 7+8HgKjk97j2F0dVbIYYyIsu0PWGd16RBTBWcd7avVM/vA5p33K0US7VQvQUCL+1TgOn PrcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=9+ety9xIr/oE/yu+3Y3X18lDgdk1zRmG+8hw4AppQPo=; b=q4DYVj5LDe1VTrQCpLUvUkN8403ft8OLXrg7/ocA3Ng6UC3GPFGV54h26Na+1Wuxkd zkEZ8rb10pLtBlEpgvV08MDWEjN1fHkB7Qyzcf5JafdeZywxYQZk3rxeeYUC7yN5czMW zCBy0fADO6b39vCu8oxTmlvfDWxZc1qd1BagUbFzXYuYGgseoRB00z5+Wu72PLgcP+mV EPi1d8a5FqwCY86jDfSewHE3AdG/UAJzTUASFaX6T4Kfl7gaFXXr2xoE0ux1gldYkL1V qT9VurZAEg8XP5fU1+FOggN3AX0dE6RWeVJpULKmK6pis3QR6krz90Kqvek3UF8BVRT1 Kp4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fF/19+LD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a84si2768073pfk.123.2018.02.12.05.17.41; Mon, 12 Feb 2018 05:17:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fF/19+LD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935229AbeBLNRi (ORCPT + 13 others); Mon, 12 Feb 2018 08:17:38 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:42458 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935210AbeBLNRb (ORCPT ); Mon, 12 Feb 2018 08:17:31 -0500 Received: by mail-lf0-f65.google.com with SMTP id w10so7597912lfc.9 for ; Mon, 12 Feb 2018 05:17:30 -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:in-reply-to:references; bh=9+ety9xIr/oE/yu+3Y3X18lDgdk1zRmG+8hw4AppQPo=; b=fF/19+LD0LumffXyIUjTfoXlNVJWqHNzVPxoomQ3mRxc0Ul9IVNx1gsm/FREw6bHVk A5UIAPhP9o9SvA9BOjBJDw3cAZOlzH7nGAIfRKt2DSudpsXTN2MW8DR7cd3PEzNOtBL3 h9P+PLMKhjrGKFOI/SgU9WNAw1aIe5Bj4VusM= 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:in-reply-to :references; bh=9+ety9xIr/oE/yu+3Y3X18lDgdk1zRmG+8hw4AppQPo=; b=EWDiMRU1IkVLphls2Aue+6A22R94/W9zO8Z9AWoFu8wIty7PJ3lwgAT7scHr5ej48b Pnb3toPw47yEfw2tvq2LFPFVwOjkM1dH4TBdYxDbGeoybrxUL33ddjaO0zDqGthwy4/G 3OZCqdoX++tUPsN/B+bywpa9oca3+wnvAE3S9jWvW/YkAZTYVy0g0JkgJ0XjcZxJcB4Y bf+jIneX3RYV11fc6XPTiSU8to87hQMi2BtQUIPCd9yJRFn2zujoVX1/U00Ph4MaAuGi ReO982MbJAKnLN/VJ0b50PRerEJbcnVvqd+7UFysDHmMqHyv+GRQX47rTs61wq0rm8W+ XUSA== X-Gm-Message-State: APf1xPBcOrm3FvJX4H8LvvAotnyodrPWFRJ35UFp7eFWPgs3WDOXEORD VcprK3XBf3cA2viw0oPaeq1nUg== X-Received: by 10.25.15.170 with SMTP id 42mr1238220lfp.6.1518441449940; Mon, 12 Feb 2018 05:17:29 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r88sm1584648lje.30.2018.02.12.05.17.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 05:17:29 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH 01/21] regulator: core: Support passing an initialized GPIO enable descriptor Date: Mon, 12 Feb 2018 14:16:57 +0100 Message-Id: <20180212131717.27193-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212131717.27193-1-linus.walleij@linaro.org> References: <20180212131717.27193-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We are currently passing a GPIO number from the global GPIO numberspace into the regulator core for handling enable GPIOs. This is not good since it ties into the global GPIO numberspace and uses gpio_to_desc() to overcome this. Start supporting passing an already initialized GPIO descriptor to the core instead: leaf drivers pick their descriptors, associated directly with the device node (or from ACPI or from a board descriptor table) and use that directly without any roundtrip over the global GPIO numberspace. This looks messy since it adds a bunch of extra code in the core, but at the end of the patch series we will delete the handling of the GPIO number and only deal with descriptors so things end up neat. Signed-off-by: Linus Walleij --- drivers/regulator/core.c | 25 ++++++++++++++++--------- include/linux/regulator/driver.h | 3 +++ 2 files changed, 19 insertions(+), 9 deletions(-) -- 2.14.3 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index dd4708c58480..4549b93b0ff9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1937,7 +1937,10 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev, struct gpio_desc *gpiod; int ret; - gpiod = gpio_to_desc(config->ena_gpio); + if (config->ena_gpiod) + gpiod = config->ena_gpiod; + else + gpiod = gpio_to_desc(config->ena_gpio); list_for_each_entry(pin, ®ulator_ena_gpio_list, list) { if (pin->gpiod == gpiod) { @@ -1947,15 +1950,18 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev, } } - ret = gpio_request_one(config->ena_gpio, - GPIOF_DIR_OUT | config->ena_gpio_flags, - rdev_get_name(rdev)); - if (ret) - return ret; + if (!config->ena_gpiod) { + ret = gpio_request_one(config->ena_gpio, + GPIOF_DIR_OUT | config->ena_gpio_flags, + rdev_get_name(rdev)); + if (ret) + return ret; + } pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); if (pin == NULL) { - gpio_free(config->ena_gpio); + if (!config->ena_gpiod) + gpio_free(config->ena_gpio); return -ENOMEM; } @@ -4154,8 +4160,9 @@ regulator_register(const struct regulator_desc *regulator_desc, goto clean; } - if ((config->ena_gpio || config->ena_gpio_initialized) && - gpio_is_valid(config->ena_gpio)) { + if (config->ena_gpiod || + ((config->ena_gpio || config->ena_gpio_initialized) && + gpio_is_valid(config->ena_gpio))) { mutex_lock(®ulator_list_mutex); ret = regulator_ena_gpio_request(rdev, config); mutex_unlock(®ulator_list_mutex); diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 4c00486b7a78..4fc96cb8e5d7 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -19,6 +19,7 @@ #include #include +struct gpio_desc; struct regmap; struct regulator_dev; struct regulator_config; @@ -387,6 +388,7 @@ struct regulator_desc { * initialized, meaning that >= 0 is a valid gpio * identifier and < 0 is a non existent gpio. * @ena_gpio: GPIO controlling regulator enable. + * @ena_gpiod: GPIO descriptor controlling regulator enable. * @ena_gpio_invert: Sense for GPIO enable control. * @ena_gpio_flags: Flags to use when calling gpio_request_one() */ @@ -399,6 +401,7 @@ struct regulator_config { bool ena_gpio_initialized; int ena_gpio; + struct gpio_desc *ena_gpiod; unsigned int ena_gpio_invert:1; unsigned int ena_gpio_flags; };