From patchwork Thu Oct 16 16:48:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 5092791 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 995B09F30B for ; Thu, 16 Oct 2014 16:52:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2F07520136 for ; Thu, 16 Oct 2014 16:52:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FB23201CD for ; Thu, 16 Oct 2014 16:52:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751491AbaJPQty (ORCPT ); Thu, 16 Oct 2014 12:49:54 -0400 Received: from bhuna.collabora.co.uk ([93.93.135.160]:34959 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751347AbaJPQtw (ORCPT ); Thu, 16 Oct 2014 12:49:52 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: javier) with ESMTPSA id 6D0D6600588 From: Javier Martinez Canillas To: Mark Brown Cc: Lee Jones , Doug Anderson , Chanwoo Choi , Olof Johansson , Chris Zhong , Krzysztof Kozlowski , Abhilash Kesavan , linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Javier Martinez Canillas Subject: [PATCH v2 1/7] regulator: max77802: Add .{get,set}_mode callbacks Date: Thu, 16 Oct 2014 18:48:47 +0200 Message-Id: <1413478133-2577-2-git-send-email-javier.martinez@collabora.co.uk> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1413478133-2577-1-git-send-email-javier.martinez@collabora.co.uk> References: <1413478133-2577-1-git-send-email-javier.martinez@collabora.co.uk> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some max77802 LDOs (1, 3, 20 and 21) support to be configured in Low Power Mode during system normal operation. Add function handlers for the .get_mode and .set_mode operations to set the mode on these LDOs. Signed-off-by: Javier Martinez Canillas --- Changes since v1: - Use a static inline function instead of a macro to map the modes. Suggested by Mark Brown. - Don't have multiple standard modes mapping onto a single hw mode. Suggested by Mark Brown. drivers/regulator/max77802.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c index 8425c0d..6eabb95 100644 --- a/drivers/regulator/max77802.c +++ b/drivers/regulator/max77802.c @@ -70,6 +70,12 @@ struct max77802_regulator_prv { unsigned int opmode[MAX77802_REG_MAX]; }; +static inline int max77802_map_mode(int mode) +{ + return mode == MAX77802_OPMODE_NORMAL ? + REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY; +} + static int max77802_get_opmode_shift(int id) { if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 && @@ -105,6 +111,44 @@ static int max77802_set_suspend_disable(struct regulator_dev *rdev) } /* + * Some LDOs support Low Power Mode while the system is running. + * + * LDOs 1, 3, 20, 21. + */ +static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode) +{ + struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); + int id = rdev_get_id(rdev); + unsigned int val; + int shift = max77802_get_opmode_shift(id); + + switch (mode) { + case REGULATOR_MODE_STANDBY: + val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */ + break; + case REGULATOR_MODE_NORMAL: + val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */ + break; + default: + dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", + rdev->desc->name, mode); + return -EINVAL; + } + + max77802->opmode[id] = val; + return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, + rdev->desc->enable_mask, val << shift); +} + +static unsigned max77802_get_mode(struct regulator_dev *rdev) +{ + struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); + int id = rdev_get_id(rdev); + + return max77802_map_mode(max77802->opmode[id]); +} + +/* * Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state * (Enable Control Logic1 by PWRREQ) * @@ -268,6 +312,8 @@ static struct regulator_ops max77802_ldo_ops_logic2 = { .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_voltage_time_sel = regulator_set_voltage_time_sel, + .set_mode = max77802_set_mode, + .get_mode = max77802_get_mode, .set_suspend_mode = max77802_ldo_set_suspend_mode_logic2, };