From patchwork Thu Aug 4 05:04:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 73238 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1203133qga; Wed, 3 Aug 2016 22:11:37 -0700 (PDT) X-Received: by 10.66.132.105 with SMTP id ot9mr2748281pab.88.1470287497496; Wed, 03 Aug 2016 22:11:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yv2si12653792pac.91.2016.08.03.22.11.37; Wed, 03 Aug 2016 22:11:37 -0700 (PDT) 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; 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 dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932462AbcHDFLX (ORCPT + 27 others); Thu, 4 Aug 2016 01:11:23 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35890 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752312AbcHDFLT (ORCPT ); Thu, 4 Aug 2016 01:11:19 -0400 Received: by mail-pa0-f50.google.com with SMTP id pp5so80048767pac.3 for ; Wed, 03 Aug 2016 22:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=xei6fuHndAMbx5vUODk78Q1006vec7zsBmmK/IFrkks=; b=QJi7cfAbwpDgIKhOs2iKcFZuBG0pwVHj2A0AzqkFZEYZ4YVlZpv169JE3CK8jvZkNd RK8ocjhI7+DyKMxm5FLFAfjvdO9uAZsJjHN7ww0GyyBGl7X76z1nNcP3gotUkapfD4XO 4jgphpO3HZ/LrBjLkloPwomPa/YGvsGCzSlIs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xei6fuHndAMbx5vUODk78Q1006vec7zsBmmK/IFrkks=; b=UNNDdqqZMGpAcWnFlG/em5wGw+DWwCGSclmQ3GuDHG1TNFcK2Qjp8AwnZpVpBbeAVX 2KTb7Ww7Dk9GyOcj/3lvt7YyiOHH8NtMUk0hH71m0kfLvBXbddUQMxV5MLWVbXv0bXMc KXCx4djtwo/9Cbj+xB22h1MQQHNGW+V03cFS8/ZFkdsrOHbll3gh/+rGcesIyiBwHL4u biGGazrnPj5I0fFLucfVbiAe7VtovOMVk4CLq76J1Ha4/LJ6PgFZgrER/1CU9TLi50aq O9yiOzheDP0aCi2GFAeTzk3GQk0GqnEeFCPGUX/IscxXgqlqX6sLdq8QHsLiTe6Vu9JD Shmw== X-Gm-Message-State: AEkoousjHjnAjiTpOkzzLczctguCJke8/ZRemETo83rM0Kv6DhB0job88VAnZefa9BqCjV5i X-Received: by 10.66.248.165 with SMTP id yn5mr124227840pac.44.1470287049428; Wed, 03 Aug 2016 22:04:09 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id e68sm16339277pfk.1.2016.08.03.22.04.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Aug 2016 22:04:08 -0700 (PDT) From: Bjorn Andersson To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , John Stultz Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 1/2] power: reset: reboot-mode: Add managed resource API Date: Wed, 3 Aug 2016 22:04:05 -0700 Message-Id: <1470287046-17437-1-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide managed resource version of reboot_mode_register() and reboot_mode_unregister() to simplify implementations. Cc: John Stultz Signed-off-by: Bjorn Andersson --- John, here's a "pointer" to what I meant with my comment on your sram-reboot-mode patch. Only compile tested though. Documentation/driver-model/devres.txt | 4 +++ drivers/power/reset/reboot-mode.c | 59 +++++++++++++++++++++++++++++++++++ drivers/power/reset/reboot-mode.h | 4 +++ 3 files changed, 67 insertions(+) -- 2.5.0 Tested-by: John Stultz Tested-by: John Stultz diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index f5e522342ee5..fbb9fde1aad3 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -342,6 +342,10 @@ PINCTRL devm_pinctrl_register() devm_pinctrl_unregister() +POWER + devm_reboot_mode_register() + devm_reboot_mode_unregister() + PWM devm_pwm_get() devm_pwm_put() diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c index 2dfbbce0f817..fb512183ace3 100644 --- a/drivers/power/reset/reboot-mode.c +++ b/drivers/power/reset/reboot-mode.c @@ -135,6 +135,65 @@ int reboot_mode_unregister(struct reboot_mode_driver *reboot) } EXPORT_SYMBOL_GPL(reboot_mode_unregister); +static void devm_reboot_mode_release(struct device *dev, void *res) +{ + reboot_mode_unregister(*(struct reboot_mode_driver **)res); +} + +/** + * devm_reboot_mode_register() - resource managed reboot_mode_register() + * @dev: device to associate this resource with + * @reboot: reboot mode driver + * + * Returns: 0 on success or a negative error code on failure. + */ +int devm_reboot_mode_register(struct device *dev, + struct reboot_mode_driver *reboot) +{ + struct reboot_mode_driver **dr; + int rc; + + dr = devres_alloc(devm_reboot_mode_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rc = reboot_mode_register(reboot); + if (rc) { + devres_free(dr); + return rc; + } + + *dr = reboot; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_reboot_mode_register); + +static int devm_reboot_mode_match(struct device *dev, void *res, void *data) +{ + struct reboot_mode_driver **p = res; + + if (WARN_ON(!p || !*p)) + return 0; + + return *p == data; +} + +/** + * devm_reboot_mode_unregister() - resource managed reboot_mode_unregister() + * @dev: device to associate this resource with + * @reboot: reboot mode driver + */ +void devm_reboot_mode_unregister(struct device *dev, + struct reboot_mode_driver *reboot) +{ + WARN_ON(devres_release(dev, + devm_reboot_mode_release, + devm_reboot_mode_match, reboot)); +} +EXPORT_SYMBOL_GPL(devm_reboot_mode_unregister); + MODULE_AUTHOR("Andy Yan