From patchwork Wed Feb 6 10:53:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14593 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 E9E892423C for ; Wed, 6 Feb 2013 10:55:13 +0000 (UTC) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by fiordland.canonical.com (Postfix) with ESMTP id 6EF0EA187B7 for ; Wed, 6 Feb 2013 10:55:13 +0000 (UTC) Received: by mail-ve0-f171.google.com with SMTP id b10so1015466vea.16 for ; Wed, 06 Feb 2013 02:55:13 -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:x-gm-message-state; bh=MRsaFOkUOZrHvOZidvwDJFU1XLRAut+AaYlrmub1yMw=; b=bbuaueYqPnwP2ZUlypOcmRrzeHXRxKCdtC1NcZBjuzxqiBFoEyFZTDpZaitf09S3My Cyn9j7L7juxT/CSSmZ8S8uhcfes6zYAZ8iXNkweFFmGMdlYOZXrno/hYB261XdVAGA// DidSyeePd71jrgoXAMnii8CGgFeZaP9sBDhJD8ytANko0XkXQ1dJ+FZowXYqH8mzo+Lw 6k9jVFZidt+qLajNsr1qp4dxjhxV2sehKOofap+KRglQU2hPv07b38hStAAkPUJJbiON 97VJErIJdj5lp6wM62bZ8tfqJqUOv1/63b2kGfJvW70VI4qJoYmcjl2zKYIeQXQ1z6I0 p/bg== X-Received: by 10.58.231.196 with SMTP id ti4mr28435682vec.25.1360148112952; Wed, 06 Feb 2013 02:55:12 -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 zo8csp12951vec; Wed, 6 Feb 2013 02:55:12 -0800 (PST) X-Received: by 10.180.86.36 with SMTP id m4mr4032421wiz.5.1360148095506; Wed, 06 Feb 2013 02:54:55 -0800 (PST) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by mx.google.com with ESMTPS id gb7si508667wib.61.2013.02.06.02.54.54 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 02:54:55 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.171 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.171; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.171 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-f171.google.com with SMTP id hn17so4110882wib.4 for ; Wed, 06 Feb 2013 02:54:54 -0800 (PST) X-Received: by 10.180.85.103 with SMTP id g7mr4082897wiz.29.1360148089603; Wed, 06 Feb 2013 02:54:49 -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.48 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 02:54:49 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: broonie@opensource.wolfsonmicro.com, linus.walleij@linaro.org, Bengt Jonsson , Lee Jones Subject: [PATCH 11/49] regulator: ab8500-ext: Add HW request support Date: Wed, 6 Feb 2013 10:53:33 +0000 Message-Id: <1360148051-7560-12-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> X-Gm-Message-State: ALoCoQkmppmOmZnERLwEdUuNc2n3KcTowsejjp7CjOETElYwSYQwyPL5/HO2UFBr8DWX6glOdXE3 From: Bengt Jonsson Support for HW request is added in the external regulator driver. A flag in the board configuration can be set to let HW control the regulator when there is no SW request. This means that the regulator will be put in high power mode when there is a SW request and in HW-request mode otherwise. Signed-off-by: Bengt Jonsson Signed-off-by: Lee Jones Reviewed-by: Mattias NILSSON Reviewed-by: Jonas ABERG --- drivers/regulator/ab8500-ext.c | 98 +++++++++++++++++++++++++++----------- include/linux/regulator/ab8500.h | 4 ++ 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/drivers/regulator/ab8500-ext.c b/drivers/regulator/ab8500-ext.c index 2157c11..303c02c 100644 --- a/drivers/regulator/ab8500-ext.c +++ b/drivers/regulator/ab8500-ext.c @@ -28,82 +28,123 @@ * @dev: device pointer * @desc: regulator description * @rdev: regulator device + * @cfg: regulator configuration (extension of regulator FW configuration) * @is_enabled: status of regulator (on/off) * @fixed_uV: typical voltage (for fixed voltage supplies) * @update_bank: bank to control on/off * @update_reg: register to control on/off * @update_mask: mask to enable/disable and set mode of regulator * @update_val: bits holding the regulator current mode - * @update_val_en: bits to set EN pin active (LPn pin deactive) + * @update_val_hp: bits to set EN pin active (LPn pin deactive) * normally this means high power mode - * @update_val_en_lp: bits to set EN pin active and LPn pin active - * normally this means low power mode - * @delay: startup delay in ms + * @update_val_lp: bits to set EN pin active and LPn pin active + * normally this means low power mode + * @update_val_hw: bits to set regulator pins in HW control + * SysClkReq pins and logic will choose mode */ struct ab8500_ext_regulator_info { struct device *dev; struct regulator_desc desc; struct regulator_dev *rdev; + struct ab8500_ext_regulator_cfg *cfg; bool is_enabled; int fixed_uV; u8 update_bank; u8 update_reg; u8 update_mask; u8 update_val; - u8 update_val_en; - u8 update_val_en_lp; + u8 update_val_hp; + u8 update_val_lp; + u8 update_val_hw; }; -static int ab8500_ext_regulator_enable(struct regulator_dev *rdev) +static int enable(struct ab8500_ext_regulator_info *info, u8 *regval) { int ret; - struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); - if (info == NULL) { - dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); - return -EINVAL; - } + *regval = info->update_val; + + /* + * To satisfy both HW high power request and SW request, the regulator + * must be on in high power. + */ + if (info->cfg && info->cfg->hwreq) + *regval = info->update_val_hp; ret = abx500_mask_and_set_register_interruptible(info->dev, info->update_bank, info->update_reg, - info->update_mask, info->update_val); + info->update_mask, *regval); if (ret < 0) dev_err(rdev_get_dev(info->rdev), "couldn't set enable bits for regulator\n"); info->is_enabled = true; - dev_dbg(rdev_get_dev(rdev), "%s-enable (bank, reg, mask, value):" - " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", - info->desc.name, info->update_bank, info->update_reg, - info->update_mask, info->update_val); - return ret; } -static int ab8500_ext_regulator_disable(struct regulator_dev *rdev) +static int ab8500_ext_regulator_enable(struct regulator_dev *rdev) { int ret; struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); + u8 regval; if (info == NULL) { dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); return -EINVAL; } + ret = enable(info, ®val); + + dev_dbg(rdev_get_dev(rdev), "%s-enable (bank, reg, mask, value):" + " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", + info->desc.name, info->update_bank, info->update_reg, + info->update_mask, regval); + + return ret; +} + +static int disable(struct ab8500_ext_regulator_info *info, u8 *regval) +{ + int ret; + + *regval = 0x0; + + /* + * Set the regulator in HW request mode if configured + */ + if (info->cfg && info->cfg->hwreq) + *regval = info->update_val_hw; + ret = abx500_mask_and_set_register_interruptible(info->dev, info->update_bank, info->update_reg, - info->update_mask, 0x0); + info->update_mask, *regval); if (ret < 0) dev_err(rdev_get_dev(info->rdev), "couldn't set disable bits for regulator\n"); info->is_enabled = false; + return ret; +} + +static int ab8500_ext_regulator_disable(struct regulator_dev *rdev) +{ + int ret; + struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); + u8 regval; + + if (info == NULL) { + dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); + return -EINVAL; + } + + ret = disable(info, ®val); + dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):" " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", info->desc.name, info->update_bank, info->update_reg, - info->update_mask, 0x0); + info->update_mask, regval); return ret; } @@ -132,7 +173,8 @@ static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev) info->desc.name, info->update_bank, info->update_reg, info->update_mask, regval); - if (regval & info->update_mask) + if (((regval & info->update_mask) == info->update_val_lp) || + ((regval & info->update_mask) == info->update_val_hp)) info->is_enabled = true; else info->is_enabled = false; @@ -240,7 +282,6 @@ static struct regulator_ops ab8500_ext_regulator_ops = { .list_voltage = ab8500_ext_list_voltage, }; - static struct ab8500_ext_regulator_info ab8500_ext_regulator_info[AB8500_NUM_EXT_REGULATORS] = { [AB8500_EXT_SUPPLY1] = { @@ -293,8 +334,9 @@ static struct ab8500_ext_regulator_info .update_reg = 0x08, .update_mask = 0x30, .update_val = 0x10, - .update_val_en = 0x10, - .update_val_en_lp = 0x30, + .update_val_hp = 0x10, + .update_val_lp = 0x30, + .update_val_hw = 0x20, }, }; @@ -334,8 +376,8 @@ int ab8500_ext_regulator_init(struct platform_device *pdev) /* VextSupply3LPn is inverted on AB8500 2.x */ info = &ab8500_ext_regulator_info[AB8500_EXT_SUPPLY3]; info->update_val = 0x30; - info->update_val_en = 0x30; - info->update_val_en_lp = 0x10; + info->update_val_hp = 0x30; + info->update_val_lp = 0x10; } /* register all regulators */ @@ -345,6 +387,8 @@ int ab8500_ext_regulator_init(struct platform_device *pdev) /* assign per-regulator data */ info = &ab8500_ext_regulator_info[i]; info->dev = &pdev->dev; + info->cfg = (struct ab8500_ext_regulator_cfg *) + pdata->ext_regulator[i].driver_data; /* register regulator with framework */ info->rdev = regulator_register(&info->desc, &pdev->dev, diff --git a/include/linux/regulator/ab8500.h b/include/linux/regulator/ab8500.h index cefd9de..0a58db2 100644 --- a/include/linux/regulator/ab8500.h +++ b/include/linux/regulator/ab8500.h @@ -155,6 +155,10 @@ enum ab9540_regulator_reg { }; /* AB8500 external regulators */ +struct ab8500_ext_regulator_cfg { + bool hwreq; /* requires hw mode or high power mode */ +}; + enum ab8500_ext_regulator_id { AB8500_EXT_SUPPLY1, AB8500_EXT_SUPPLY2,