From patchwork Sat Dec 1 15:41:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152640 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4934607ljp; Sat, 1 Dec 2018 07:53:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/XQ/UaPJlPCwBE6dihOF5XQBinec3Vsn7RkTm8E5K1YHOccFQ+R0kZg9Atd96fxDYRQopT3 X-Received: by 2002:a62:ab0d:: with SMTP id p13mr9655252pff.211.1543679606625; Sat, 01 Dec 2018 07:53:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543679606; cv=none; d=google.com; s=arc-20160816; b=vWvFsU0/DapKBzs7gvr+9vwbUP7+4Dutls/+J6dOyWUEggJEDVxEyNCwiNPqGvgztv bY1bckESBfNuZxfSkBlIw/zFb2NysOx9pPfBcqCsQnpbaI05pI/Z6mifZwXFng768pPL tj5W73vD6T3qBEU7vNzOO/Ve2daGX7kLq3qAuB+LEzqGkgKYpU3PJ7DsO459yZf6s+1i +UpAwz5KjoPdEiDYIJy2XRuXlai+S1GBmhsGIYRTn7G6FW+FfaaVW87g3led4Jk6JXdM 4m3+6mUQ8hweDEPie1+2CwAg/xTVDI9bdcEiDfvWKmgj56Qa06PnBf1kL5DPiR+tKib0 Xz6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dKBvHfafiQ4kCpEJu7bit7Ossq558os4BIrgEwZdU7g=; b=AGe3+2UIUB2qYflxfI7Nqw7Imj0t3TrhvQqgAP8RlWXS+m0wzcOwuF0kMkVRmkCI5O ApJXeHsO8/rWbVxiWeA5LWWTElJmBsqBaUoBE29Qhm7cRLNEg/6v7+tECKd91d2bjdAB jloPV81TkFJVyNQgHSf0NAoQX1QelCZEihJwryE7CiKnyLONHCSJYHe6WhW5Jt3XEGFP BDJHVaateUZ4zUiZLVFCPCqYPg8zvPyhHOxlMCho6lnsCLLatE7iBNOk5V/0vA7oNUUN Are409ecrsD3WjH/FwPODyaw4Qfo4OwruFPV5tzqRQH5oU4MYjVxaeFEpxOqy8IG/e20 gZxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I2pzSeKI; 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 d90si8955723pld.148.2018.12.01.07.53.26; Sat, 01 Dec 2018 07:53:26 -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=I2pzSeKI; 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 S1727356AbeLBDGM (ORCPT + 32 others); Sat, 1 Dec 2018 22:06:12 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41976 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727293AbeLBDGL (ORCPT ); Sat, 1 Dec 2018 22:06:11 -0500 Received: by mail-lf1-f66.google.com with SMTP id c16so6199677lfj.8 for ; Sat, 01 Dec 2018 07:53:21 -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 :mime-version:content-transfer-encoding; bh=dKBvHfafiQ4kCpEJu7bit7Ossq558os4BIrgEwZdU7g=; b=I2pzSeKIFvN8gmFrIykZ6uJTglYZyR5CRTkfC6bB7qEWQ/YcmlGR9CFfgqi0Sz2Jon hje/27hhg52448csivuTpbC+pr5wBzOBVAj5B6Z7KSFKhnx7FW/OucIKyv0ByliW5LSy /PkkIJgF96tKcUsMm9AYCbnNMM7eRuzlfUUOs= 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:mime-version:content-transfer-encoding; bh=dKBvHfafiQ4kCpEJu7bit7Ossq558os4BIrgEwZdU7g=; b=FrfeH65nVUCfWQako3+HzfM8jqA3s6CvW0Nz4pXrnWL3n9X+LcIUj2DNkpC6wMYZ38 ybSEyRwC+jhllyAS3Lz7oeV6U9wuZbXcCx0a+NZjx8W1d/Q1FR4nYXeyk/ithNNQ17wZ Z68JxnkME+FvauOdsB8ESCcoinlW+/I2lXav8o9Lpl3Ov5NiEn5p4P2bJalflmwQrewm zWvvqr0NC/wouR1i0+ZistVZaK8AQ+l88MxB4hchsoxWkpWdgM3f2gADPnej9kBuJRwt YQ8sg9lTeCokRz5DLd9o6bqRgMfIPXDC5cr0HwZRYAZEtsdv8vl5oRqp938aR3t16PrU ClVA== X-Gm-Message-State: AA+aEWZeIkpQ+APG+8F+zOYC6KrG2D5+g/73ZlAGunIwwmY2mRHL/AWs jzbA1yyn7NAipTPz2andKSOVIg== X-Received: by 2002:a19:d70f:: with SMTP id o15mr6031149lfg.134.1543679600779; Sat, 01 Dec 2018 07:53:20 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 13-v6sm1365426ljj.49.2018.12.01.07.53.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Dec 2018 07:53:19 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij Subject: [PATCH 09/13 v2] gpio: Add devm_gpiod_unhinge() Date: Sat, 1 Dec 2018 16:41:47 +0100 Message-Id: <20181201154151.14890-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181201154151.14890-1-linus.walleij@linaro.org> References: <20181201154151.14890-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a function named devm_gpiod_unhinge() that removes the resource management from a GPIO descriptor. I am not sure if this is the best anglosaxon name for the function, no other managed resources have an equivalent currently, but I chose "unhinge" as the closest intuitive thing I could imagine that fits Rusty Russell's API design criterions "the obvious use is the correct one" and "the name tells you how to use it". The idea came out of a remark from Mark Brown that it should be possible to handle over management of a resource from devres to the regulator core, and indeed we can do that. Cc: Bartosz Golaszewski Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - New patch to be able to hand over GPIO descriptors to the regulator core. - Mark: feel free to apply this to the regulator tree with the regulator tree with the rest. --- Documentation/driver-model/devres.txt | 1 + drivers/gpio/gpiolib-devres.c | 17 +++++++++++++++++ include/linux/gpio/consumer.h | 10 ++++++++++ 3 files changed, 28 insertions(+) -- 2.19.1 Reviewed-by: Bartosz Golaszewski diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 43681ca0837f..fc4cc24dfb97 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -254,6 +254,7 @@ GPIO devm_gpiod_get_index_optional() devm_gpiod_get_optional() devm_gpiod_put() + devm_gpiod_unhinge() devm_gpiochip_add_data() devm_gpiochip_remove() devm_gpio_request() diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c index 01959369360b..5864e758d7f2 100644 --- a/drivers/gpio/gpiolib-devres.c +++ b/drivers/gpio/gpiolib-devres.c @@ -320,6 +320,23 @@ void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) } EXPORT_SYMBOL(devm_gpiod_put); +/** + * devm_gpiod_unhinge - Remove resource management from a gpio descriptor + * @dev: GPIO consumer + * @desc: GPIO descriptor to remove resource management from + * + * Remove resource management from a GPIO descriptor. This is needed when + * you want to hand over lifecycle management of a descriptor to another + * mechanism. + */ + +void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc) +{ + WARN_ON(devres_destroy(dev, devm_gpiod_release, + devm_gpiod_match, desc)); +} +EXPORT_SYMBOL(devm_gpiod_unhinge); + /** * devm_gpiod_put_array - Resource-managed gpiod_put_array() * @dev: GPIO consumer diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 348885f2f3d3..8aebcf822082 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -104,6 +104,7 @@ struct gpio_descs *__must_check devm_gpiod_get_array_optional(struct device *dev, const char *con_id, enum gpiod_flags flags); void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); +void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc); void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); int gpiod_get_direction(struct gpio_desc *desc); @@ -249,6 +250,15 @@ static inline void gpiod_put(struct gpio_desc *desc) WARN_ON(1); } +static inline void devm_gpiod_unhinge(struct device *dev, + struct gpio_desc *desc) +{ + might_sleep(); + + /* GPIO can never have been requested */ + WARN_ON(1); +} + static inline void gpiod_put_array(struct gpio_descs *descs) { might_sleep();