From patchwork Mon Feb 4 11:53:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14455 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 B263623F96 for ; Mon, 4 Feb 2013 11:56:01 +0000 (UTC) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by fiordland.canonical.com (Postfix) with ESMTP id 4B8F1A18477 for ; Mon, 4 Feb 2013 11:56:01 +0000 (UTC) Received: by mail-ve0-f169.google.com with SMTP id 15so2888741vea.0 for ; Mon, 04 Feb 2013 03:56:00 -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=Olp2lEgaTm2iMrtKwblVfagzn3o2rzW2j7hnAFyJB+Y=; b=GKdf/9pHiw90JbRmYYU3qUW+jUu0AIWz+g5H0JSfaN8qCAcK6FvY+sPnpyRuA/lsBG 7ZHM9LPLweuR+nMenV4CeeeizzmGtFSfIWqIeNJSOpgcXdQuESUi6h7wYe34lfzfKwdG Xv/yyKMMmTQDzVhSp4u2tXtHVi34BbxiJttDNO9b43Pkr1yJH4VVbB4L+A7xHX1pIjZi 06LbgQ45NkdDrPwQKjcgn8485ShEk5HZ6zNwIbmj/1HLVgXoiq1SrqEqgGMktd0aWV66 +HvAdARy3iI5z7c04j6oli190yLlNTkJWJVgEPoWxjbmxTcDM5xER4cZuuXQrD1dZVGC gkhQ== X-Received: by 10.52.66.168 with SMTP id g8mr19456721vdt.27.1359978960822; Mon, 04 Feb 2013 03:56:00 -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 zo8csp83021vec; Mon, 4 Feb 2013 03:56:00 -0800 (PST) X-Received: by 10.180.85.103 with SMTP id g7mr9995846wiz.29.1359978959863; Mon, 04 Feb 2013 03:55:59 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by mx.google.com with ESMTPS id em13si3473856wid.31.2013.02.04.03.55.59 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Feb 2013 03:55:59 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.181 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.181; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.181 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-f181.google.com with SMTP id hm6so1502139wib.8 for ; Mon, 04 Feb 2013 03:55:59 -0800 (PST) X-Received: by 10.180.73.212 with SMTP id n20mr9786138wiv.11.1359978959170; Mon, 04 Feb 2013 03:55:59 -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 j9sm12937128wia.5.2013.02.04.03.55.57 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Feb 2013 03:55:58 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org, broonie@opensource.wolfsonmicro.com Cc: Emeric Vigier , =?UTF-8?q?Ludovic=20Barr=C3=A9?= , Lee Jones Subject: [PATCH 06/73] regulator: ab8500: Add set_mode/get_mode support Date: Mon, 4 Feb 2013 11:53:21 +0000 Message-Id: <1359978868-28736-7-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359978868-28736-1-git-send-email-lee.jones@linaro.org> References: <1359978868-28736-1-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnlWS0G+SUjICzGUTRufuK3VmEn2wFoVWuXA9YXfyFmoNLlGbmOlFr8G2oO8tDyzLrXOYFV 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 ba1483b..1854ec3 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,