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: 9262709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DE77D6048F for ; Thu, 4 Aug 2016 05:34:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7DE728068 for ; Thu, 4 Aug 2016 05:34:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 968192810E; Thu, 4 Aug 2016 05:34:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B50628068 for ; Thu, 4 Aug 2016 05:34:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932363AbcHDFeI (ORCPT ); Thu, 4 Aug 2016 01:34:08 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34301 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932168AbcHDFeG (ORCPT ); Thu, 4 Aug 2016 01:34:06 -0400 Received: by mail-pa0-f49.google.com with SMTP id fi15so80310161pac.1 for ; Wed, 03 Aug 2016 22:32:58 -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=cqJ8CVhKehqSTpm5yxkJ/obpjL2JkYlmS9WNKw0H4lVLY614bXTb00gvds+/D/Pm2J MIuqByTy7Q4vlwd0RVE1LhqRKN75qXmjv3+cd/EpTF0uV10jx/lVqo2laQpyn6Df+9NB KocMBzkfRjst2rJrqXzhCfihWSPMXq0iBODGlEbDUWtWaV1v7sKwotTM9DyIZ879x59a cHTr4SY+i2gqmmX+oy+b36SMW0brMOoStcc99u72VKIHc+wWoOLV4KUS4n65elZ4OjqB M2NyUap0AyJTRPKBqlzub5z/qSS1UTo7Qv16IQd7cHkkQwnZ2dvlv7rH3eCtUwvxNmoS IhZw== X-Gm-Message-State: AEkoouupvr5sjE9ek46fzrtt/xIeieW2pu2Rh4vnfIDY9k3ii3nsp4ImGsGoqQUswXhoV9zO 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide managed resource version of reboot_mode_register() and reboot_mode_unregister() to simplify implementations. Cc: John Stultz Signed-off-by: Bjorn Andersson Tested-by: John Stultz --- 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(+) 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