From patchwork Wed Nov 28 12:59:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Green X-Patchwork-Id: 1816121 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 1F7743FD1A for ; Wed, 28 Nov 2012 12:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754974Ab2K1M7p (ORCPT ); Wed, 28 Nov 2012 07:59:45 -0500 Received: from warmcat.com ([87.106.134.80]:59171 "EHLO warmcat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754963Ab2K1M7p (ORCPT ); Wed, 28 Nov 2012 07:59:45 -0500 Subject: [try#1 PATCH 2/7] regulator: core: add default device asset handlers To: linux-omap@vger.kernel.org, linux-usb@vger.kernel.org From: Andy Green Cc: gregkh@linuxfoundation.org, rogerq@ti.com, keshava_mgowda@ti.com, balbi@ti.com, stern@rowland.harvard.edu Date: Wed, 28 Nov 2012 12:59:39 +0000 Message-ID: <20121128125939.29569.72105.stgit@build.warmcat.com> In-Reply-To: <20121128124744.29569.52739.stgit@build.warmcat.com> References: <20121128124744.29569.52739.stgit@build.warmcat.com> User-Agent: StGit/0.16-2-g0d85 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org This adds default device_asset handlers for struct regulator. If you want an associated regulator asset of a device to be powered before probe, and depowered after removal, these callbacks will take care of everything including get and put. By defining them here in regulator core, code duplication at the usages is nipped in the bud. Signed-off-by: Andy Green --- drivers/regulator/core.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/regulator/machine.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e872c8b..1834e41 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3495,6 +3495,40 @@ void regulator_unregister(struct regulator_dev *rdev) } EXPORT_SYMBOL_GPL(regulator_unregister); +/* + * Default handlers for regulator asset preprobe and postremoval + */ +int regulator_asset_default_preprobe(struct device *device, + struct device_asset *asset) +{ + struct regulator **reg = (struct regulator **)&asset->asset; + int n; + + *reg = regulator_get(device, asset->name); + if (IS_ERR(*reg)) + return PTR_ERR(*reg); + n = regulator_enable(*reg); + if (n < 0) + regulator_put(*reg); + + dev_info(device, "Enabled regulator asset %s\n", asset->name); + + return n; +} +EXPORT_SYMBOL_GPL(regulator_asset_default_preprobe); + +void regulator_asset_default_postremove(struct device *device, + struct device_asset *asset) +{ + struct regulator *reg = asset->asset; + + dev_info(device, "Disabling post-remove asset %s\n", asset->name); + + regulator_disable(reg); + regulator_put(reg); +} +EXPORT_SYMBOL_GPL(regulator_asset_default_postremove); + /** * regulator_suspend_prepare - prepare regulators for system wide suspend * @state: system suspend state diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 36adbc8..151a330 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -191,9 +191,39 @@ int regulator_suspend_prepare(suspend_state_t state); int regulator_suspend_finish(void); #ifdef CONFIG_REGULATOR +/** + * regulator_asset_default_preprobe: default probe handler for regulator assets + * @device: the device whose assets we are enabling just before probing it + * @asset: the named regulator asset we are going to get and enable + * + * You can give this as the handler for .pre_probe callback in device_asset to + * deal with pre-enabling/get of a device's named regulator assets + */ +int regulator_asset_default_preprobe(struct device *device, + struct device_asset *asset); +/** + * regulator_asset_default_postremove: default remove handler for reg assets + * @device: the device whose assets we are disabling just after removing it + * @asset: the regulator asset we are going to disable and put + * + * You can give this as the handler for .post_remove callback in device_asset + * to deal with post-disabling/put of a device's regulator assets + */ +void regulator_asset_default_postremove(struct device *device, + struct device_asset *asset); + void regulator_has_full_constraints(void); void regulator_use_dummy_regulator(void); #else +static inline int regulator_asset_default_preprobe(struct device *device, + struct device_asset *asset) +{ + return 0; +} +static inline void regulator_asset_default_postremove(struct device *device, + struct device_asset *asset) +{ +} static inline void regulator_has_full_constraints(void) { }