From patchwork Sun May 1 10:36:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 66985 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp568855qge; Sun, 1 May 2016 03:39:36 -0700 (PDT) X-Received: by 10.66.78.73 with SMTP id z9mr42600346paw.4.1462099175904; Sun, 01 May 2016 03:39:35 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si15239427pfj.249.2016.05.01.03.39.35; Sun, 01 May 2016 03:39:35 -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=@nifty.com; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752597AbcEAKj0 (ORCPT + 29 others); Sun, 1 May 2016 06:39:26 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:22158 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752436AbcEAKjU (ORCPT ); Sun, 1 May 2016 06:39:20 -0400 Received: from grover.sesame (FL1-119-242-215-193.osk.mesh.ad.jp [119.242.215.193]) (authenticated) by conuserg-07.nifty.com with ESMTP id u41AbfDm016707; Sun, 1 May 2016 19:38:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com u41AbfDm016707 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1462099082; bh=sfKJ+II+qiAsqwADl9BQm4fIZ/nesdG7k7stO66akVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=id4ZQ8LuCVzO4f+BYSPloN9GKrsRiPpeD/0trZn5hNWfZ//gO5Go/cwkosdlfxtkf 1liMYd/pgO4ifTpdA+g0BulprEuhlVsLrGjRBU1RPCy7cs5cqC4hnbvZxuYnmTbvCo XFXrBnyfzZBJgJ3IYs4fqbujATdB6+KspmCNBgfXlLObJbrGp2cxyy9a/VERGaakuR FhJJRcMMZ4japKyblcscvy7tyauLpoFZz+w5zmCqqLZhsWrA7OVkQjfokodsNFmCT8 wk/xcncdMB9WMTU/ErcJ5d7f+3mPcdeDmx4nRhDQ9D6L4pk8olW6YLThfGRCIeD+X5 ROBUbTR3UWTsw== X-Nifty-SrcIP: [119.242.215.193] From: Masahiro Yamada To: Philipp Zabel Cc: linux-arm-kernel@lists.infradead.org, Masahiro Yamada , linux-doc@vger.kernel.org, Stephen Boyd , Jonathan Corbet , linux-kernel@vger.kernel.org, Laxman Dewangan Subject: [PATCH 1/7] reset: add devm_reset_controller_register API Date: Sun, 1 May 2016 19:36:57 +0900 Message-Id: <1462099023-11819-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462099023-11819-1-git-send-email-yamada.masahiro@socionext.com> References: <1462099023-11819-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a device managed API for reset_controller_register(). This helps in reducing code in .remove callbacks and sometimes dropping .remove callbacks entirely. Signed-off-by: Masahiro Yamada --- Documentation/driver-model/devres.txt | 4 ++++ drivers/reset/core.c | 37 +++++++++++++++++++++++++++++++++++ include/linux/reset-controller.h | 4 ++++ 3 files changed, 45 insertions(+) -- 1.9.1 diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 108d455..5270435 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -340,6 +340,10 @@ REGULATOR devm_regulator_put() devm_regulator_register() +RESET + devm_reset_control_get() + devm_reset_controller_register() + SLAVE DMA ENGINE devm_acpi_dma_controller_register() diff --git a/drivers/reset/core.c b/drivers/reset/core.c index f15f150..181b05d 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -82,6 +82,43 @@ void reset_controller_unregister(struct reset_controller_dev *rcdev) } EXPORT_SYMBOL_GPL(reset_controller_unregister); +static void devm_reset_controller_release(struct device *dev, void *res) +{ + reset_controller_unregister(*(struct reset_controller_dev **)res); +} + +/** + * devm_reset_controller_register - resource managed reset_controller_register() + * @dev: device that is registering this reset controller + * @rcdev: a pointer to the initialized reset controller device + * + * Managed reset_controller_register(). For reset controllers registered by + * this function, reset_controller_unregister() is automatically called on + * driver detach. See reset_controller_register() for more information. + */ +int devm_reset_controller_register(struct device *dev, + struct reset_controller_dev *rcdev) +{ + struct reset_controller_dev **rcdevp; + int ret; + + rcdevp = devres_alloc(devm_reset_controller_release, sizeof(*rcdevp), + GFP_KERNEL); + if (!rcdevp) + return -ENOMEM; + + ret = reset_controller_register(rcdev); + if (!ret) { + *rcdevp = rcdev; + devres_add(dev, rcdevp); + } else { + devres_free(rcdevp); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_reset_controller_register); + /** * reset_control_reset - reset the controlled device * @rstc: reset controller diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h index a3a5bcd..a4eaf1c 100644 --- a/include/linux/reset-controller.h +++ b/include/linux/reset-controller.h @@ -51,4 +51,8 @@ struct reset_controller_dev { int reset_controller_register(struct reset_controller_dev *rcdev); void reset_controller_unregister(struct reset_controller_dev *rcdev); +struct device; +int devm_reset_controller_register(struct device *dev, + struct reset_controller_dev *rcdev); + #endif