From patchwork Wed Feb 6 10:53:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14586 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A40F02423C for ; Wed, 6 Feb 2013 10:55:03 +0000 (UTC) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by fiordland.canonical.com (Postfix) with ESMTP id 40896A18929 for ; Wed, 6 Feb 2013 10:55:03 +0000 (UTC) Received: by mail-vb0-f43.google.com with SMTP id fs19so736877vbb.30 for ; Wed, 06 Feb 2013 02:55:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=jB+pXtiRBdua9IQLeKm+PBL/bdZK8F6xX3ymtr0t0Sk=; b=d9Njr6I0lPrgzJvnCMOjY9Bw+jQp1GncgTy2HXX/Xw+/crWN+vo81fSRSWBo25Ygne Ol/XCQEBoBqMHyKVYa4VepW/lUa467azu6nfeED/qey/zyI00TgPd3Mc+KpfOAhGobLx DinoDnopKoLCQQM/cgdqo97d5EHzOIGfHhw8mOHWhc9rLa5TUDMwxt9RJAd8wbm7f5br TDfe3d+fQRy/uRNCjZO7rfse+hX7QuD45o9PbeUA3dz2pD4CF7i9oY8cLzWKZvDBMCEQ SsYaDDAJ2CJ/X1cRLTkPWmU+5L+0KuhNPgCHyE0rWr7AP54UCJFq62DMhcSv+gbnxEBf RF1w== X-Received: by 10.220.149.200 with SMTP id u8mr30578263vcv.7.1360148102717; Wed, 06 Feb 2013 02:55:02 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.252.8 with SMTP id zo8csp12927vec; Wed, 6 Feb 2013 02:54:59 -0800 (PST) X-Received: by 10.180.90.106 with SMTP id bv10mr4133313wib.12.1360148088605; Wed, 06 Feb 2013 02:54:48 -0800 (PST) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by mx.google.com with ESMTPS id g10si511050wiz.54.2013.02.06.02.54.48 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 02:54:48 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.177 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.177; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.177 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f177.google.com with SMTP id hm14so1417170wib.10 for ; Wed, 06 Feb 2013 02:54:48 -0800 (PST) X-Received: by 10.194.118.166 with SMTP id kn6mr13884103wjb.18.1360148082034; Wed, 06 Feb 2013 02:54:42 -0800 (PST) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id be1sm2406649wib.10.2013.02.06.02.54.40 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 02:54:41 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: broonie@opensource.wolfsonmicro.com, linus.walleij@linaro.org, Emeric Vigier , =?UTF-8?q?Ludovic=20Barr=C3=A9?= , Lee Jones Subject: [PATCH 02/49] regulator: ab8500: Add set_mode/get_mode support Date: Wed, 6 Feb 2013 10:53:24 +0000 Message-Id: <1360148051-7560-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1360148051-7560-1-git-send-email-lee.jones@linaro.org> References: <1360148051-7560-1-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm2KxVmm2oxyuH++xdToHzQlDCNtWD5lrOw5DuT0h3n5S+AiHLxqzSCjSbT9YCqY5761Uk1 From: Emeric Vigier Signed-off-by: Ludovic BarrĂ© Signed-off-by: Emeric Vigier Signed-off-by: Lee Jones Reviewed-by: Bengt JONSSON --- drivers/regulator/ab8500.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index 4d9d556..8426c8e 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c @@ -33,6 +33,8 @@ * @update_bank: bank to control on/off * @update_reg: register to control on/off * @update_mask: mask to enable/disable regulator + * @update_val: bits holding the regulator current mode + * @update_val_idle: bits to enable the regulator in idle (low power) mode * @update_val_enable: bits to enable the regulator in normal (high power) mode * @voltage_bank: bank to control regulator voltage * @voltage_reg: register to control regulator voltage @@ -47,6 +49,8 @@ struct ab8500_regulator_info { u8 update_bank; u8 update_reg; u8 update_mask; + u8 update_val; + u8 update_val_idle; u8 update_val_enable; u8 voltage_bank; u8 voltage_reg; @@ -146,6 +150,63 @@ static int ab8500_regulator_disable(struct regulator_dev *rdev) return ret; } +static int ab8500_regulator_set_mode(struct regulator_dev *rdev, unsigned int mode) +{ + struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); + + if (info == NULL) { + dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); + return -EINVAL; + } + + /* + * update_val_enable is protected by mutex + * into regulator/core.c layout + */ + switch (mode) { + case REGULATOR_MODE_NORMAL: + info->update_val = info->update_val_enable; + break; + case REGULATOR_MODE_IDLE: + info->update_val = info->update_val_idle; + break; + default: + return -EINVAL; + } + + return ab8500_regulator_enable(rdev); +} + +static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev) +{ + struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); + int ret; + u8 regval; + + if (info == NULL) { + dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); + return -EINVAL; + } + + ret = abx500_get_register_interruptible(info->dev, + info->update_bank, info->update_reg, ®val); + if (ret < 0) { + dev_err(rdev_get_dev(rdev), + "couldn't read 0x%x register\n", info->update_reg); + return ret; + } + + regval &=info->update_mask; + if (regval == info->update_val_enable) + ret = REGULATOR_MODE_NORMAL; + else if (regval == info->update_val_idle) + ret = REGULATOR_MODE_IDLE; + else + ret = -EINVAL; + + return ret; +} + static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) { int ret; @@ -249,6 +310,8 @@ static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, static struct regulator_ops ab8500_regulator_ops = { .enable = ab8500_regulator_enable, .disable = ab8500_regulator_disable, + .set_mode = ab8500_regulator_set_mode, + .get_mode = ab8500_regulator_get_mode, .is_enabled = ab8500_regulator_is_enabled, .get_voltage_sel = ab8500_regulator_get_voltage_sel, .set_voltage_sel = ab8500_regulator_set_voltage_sel, @@ -284,6 +347,8 @@ static struct ab8500_regulator_info .update_bank = 0x04, .update_reg = 0x09, .update_mask = 0x03, + .update_val = 0x01, + .update_val_idle = 0x03, .update_val_enable = 0x01, .voltage_bank = 0x04, .voltage_reg = 0x1f, @@ -302,6 +367,8 @@ static struct ab8500_regulator_info .update_bank = 0x04, .update_reg = 0x09, .update_mask = 0x0c, + .update_val = 0x04, + .update_val_idle = 0x0c, .update_val_enable = 0x04, .voltage_bank = 0x04, .voltage_reg = 0x20, @@ -320,6 +387,8 @@ static struct ab8500_regulator_info .update_bank = 0x04, .update_reg = 0x0a, .update_mask = 0x03, + .update_val = 0x01, + .update_val_idle = 0x03, .update_val_enable = 0x01, .voltage_bank = 0x04, .voltage_reg = 0x21, @@ -338,6 +407,8 @@ static struct ab8500_regulator_info .update_bank = 0x03, .update_reg = 0x80, .update_mask = 0x44, + .update_val = 0x04, + .update_val_idle = 0x44, .update_val_enable = 0x04, .voltage_bank = 0x03, .voltage_reg = 0x80,