From patchwork Tue Oct 10 15:26:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9996567 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A769C603B5 for ; Tue, 10 Oct 2017 15:29:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98DAE209CC for ; Tue, 10 Oct 2017 15:29:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D32E274D1; Tue, 10 Oct 2017 15:29:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25CBF209CC for ; Tue, 10 Oct 2017 15:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932287AbdJJP0j (ORCPT ); Tue, 10 Oct 2017 11:26:39 -0400 Received: from albert.telenet-ops.be ([195.130.137.90]:34878 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932271AbdJJP0f (ORCPT ); Tue, 10 Oct 2017 11:26:35 -0400 Received: from ayla.of.borg ([84.195.106.246]) by albert.telenet-ops.be with bizsmtp id KrSV1w00J5JzmfG06rSV8q; Tue, 10 Oct 2017 17:26:34 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1e1wQP-0007Sz-9a; Tue, 10 Oct 2017 17:26:29 +0200 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1e1wQP-0008Cu-89; Tue, 10 Oct 2017 17:26:29 +0200 From: Geert Uytterhoeven To: Marek Vasut , Rob Herring , Mark Rutland , Liam Girdwood , Mark Brown Cc: Simon Horman , Magnus Damm , Lee Jones , linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC 4/5] regulator: bd9571mwv: Add support for backup mode Date: Tue, 10 Oct 2017 17:26:17 +0200 Message-Id: <1507649178-31473-5-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507649178-31473-1-git-send-email-geert+renesas@glider.be> References: <1507649178-31473-1-git-send-email-geert+renesas@glider.be> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The BD9571MWV PMIC supports backup mode, which keeps one or more DDR rails powered while the main SoC is powered down. Which DDR rails are to be kept powered is board-specific, and controlled using the optional "rohm,ddr-backup-power" DT property. In the absence of this property, backup mode is not available. Backup mode is not enabled automatically, as e.g. on Renesas Salvator-X(S) boards enabling backup mode changes the role of the ACC switch from a power switch to a wake-up switch. Hence enabling it prevents the board from being powered off using the ACC switch, which may confuse the user. Backup mode can be enabled or disabled by the user using the "backup_mode" sysfs file, e.g. echo on > /sys/devices/platform/soc/e60b0000.i2c/i2c-7/7-0030/bd9571mwv-regulator.3.auto/backup_mode If enabled by the boot loader, initial backup mode state is retained. As state is lost by PSCI system suspend, it is restored during system resume. Signed-off-by: Geert Uytterhoeven --- What's the right place to document regulator sysfs files? --- drivers/regulator/bd9571mwv-regulator.c | 121 +++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c index c67a83d53c4cb76b..c7ff67938c3eb48a 100644 --- a/drivers/regulator/bd9571mwv-regulator.c +++ b/drivers/regulator/bd9571mwv-regulator.c @@ -24,6 +24,14 @@ #include +struct bd9571mwv_reg { + struct bd9571mwv *bd; + + /* DDR Backup Power */ + u8 bkup_mode_cnt_keepon; /* from "rohm,ddr-backup-power" */ + u8 bkup_mode_cnt_shadow; +}; + enum bd9571mwv_regulators { VD09, VD18, VD25, VD33, DVFS }; #define BD9571MWV_REG(_name, _of, _id, _ops, _vr, _vm, _nv, _min, _step, _lmin)\ @@ -131,14 +139,99 @@ static struct regulator_desc regulators[] = { 0x80, 600000, 10000, 0x3c), }; +static int bd9571mwv_bkup_mode_set(struct bd9571mwv_reg *bdreg, u8 mode) +{ + int ret; + + ret = regmap_write(bdreg->bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode); + if (ret) { + dev_err(bdreg->bd->dev, + "Failed to configure backup mode 0x%x (ret=%i)\n", + mode, ret); + return ret; + } + + bdreg->bkup_mode_cnt_shadow = mode; + return 0; +} + +static ssize_t backup_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev); + int enabled = bdreg->bkup_mode_cnt_shadow & + BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK; + + return sprintf(buf, "%s\n", enabled ? "on" : "off"); +} + +static ssize_t backup_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev); + bool enable; + ssize_t ret; + u8 mode; + + if (!count) + return 0; + + ret = kstrtobool(buf, &enable); + if (ret) + return ret; + + mode = bdreg->bkup_mode_cnt_shadow & + ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK; + if (enable) + mode |= bdreg->bkup_mode_cnt_keepon; + + if (mode == bdreg->bkup_mode_cnt_shadow) + return count; + + ret = bd9571mwv_bkup_mode_set(bdreg, mode); + if (ret) + return ret; + + return count; +} + +DEVICE_ATTR_RW(backup_mode); + +#ifdef CONFIG_PM_SLEEP +static int bd9571mwv_resume(struct device *dev) +{ + struct bd9571mwv_reg *bdreg = dev_get_drvdata(dev); + + return bd9571mwv_bkup_mode_set(bdreg, bdreg->bkup_mode_cnt_shadow); +} + +static const struct dev_pm_ops bd9571mwv_pm = { + SET_SYSTEM_SLEEP_PM_OPS(NULL, bd9571mwv_resume) +}; + +#define DEV_PM_OPS &bd9571mwv_pm +#else +#define DEV_PM_OPS NULL +#endif /* CONFIG_PM_SLEEP */ + static int bd9571mwv_regulator_probe(struct platform_device *pdev) { struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent); struct regulator_config config = { }; + struct bd9571mwv_reg *bdreg; struct regulator_dev *rdev; - int i; + unsigned int val; + int i, ret; + + bdreg = devm_kzalloc(&pdev->dev, sizeof(*bdreg), GFP_KERNEL); + if (!bdreg) + return -ENOMEM; + + bdreg->bd = bd; - platform_set_drvdata(pdev, bd); + platform_set_drvdata(pdev, bdreg); config.dev = &pdev->dev; config.dev->of_node = bd->dev->of_node; @@ -155,6 +248,28 @@ static int bd9571mwv_regulator_probe(struct platform_device *pdev) } } + val = 0; + of_property_read_u32(bd->dev->of_node, "rohm,ddr-backup-power", &val); + if (val & ~BD9571MWV_BKUP_MODE_CNT_KEEPON_MASK) { + dev_err(bd->dev, "invalid %s mode %u\n", + "rohm,ddr-backup-power", val); + return -EINVAL; + } + bdreg->bkup_mode_cnt_keepon = val; + + ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, &val); + if (ret) { + dev_err(bd->dev, "Failed to read backup mode (ret=%i)\n", ret); + return ret; + } + bdreg->bkup_mode_cnt_shadow = val; + + return device_create_file(&pdev->dev, &dev_attr_backup_mode); +} + +static int bd9571mwv_regulator_remove(struct platform_device *pdev) +{ + device_remove_file(&pdev->dev, &dev_attr_backup_mode); return 0; } @@ -167,8 +282,10 @@ MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table); static struct platform_driver bd9571mwv_regulator_driver = { .driver = { .name = "bd9571mwv-regulator", + .pm = DEV_PM_OPS, }, .probe = bd9571mwv_regulator_probe, + .remove = bd9571mwv_regulator_remove, .id_table = bd9571mwv_regulator_id_table, }; module_platform_driver(bd9571mwv_regulator_driver);