From patchwork Sun Jun 5 00:17:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 9155043 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 221B860221 for ; Sun, 5 Jun 2016 00:19:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12FFA282E8 for ; Sun, 5 Jun 2016 00:19:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0650128327; Sun, 5 Jun 2016 00:19:25 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5109C25E13 for ; Sun, 5 Jun 2016 00:19:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b9Lml-0003F8-Hd; Sun, 05 Jun 2016 00:19:23 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b9LmD-0002gK-6H; Sun, 05 Jun 2016 00:18:51 +0000 Received: from trochilidae.toradex.int (unknown [IPv6:2601:602:8f02:dcfc:3e97:eff:fe92:db3b]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 92BE45C183B; Sun, 5 Jun 2016 02:15:35 +0200 (CEST) From: Stefan Agner To: lee.jones@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, khilman@baylibre.com, carlo@caione.org Subject: [PATCH 5/5] mfd: rn5t618: register restart handler Date: Sat, 4 Jun 2016 17:17:49 -0700 Message-Id: <20160605001749.4062-7-stefan@agner.ch> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160605001749.4062-1-stefan@agner.ch> References: <20160605001749.4062-1-stefan@agner.ch> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1465085739; bh=U1uHhIf+vgpEwYNRbGwDNy5rPcmeFhqCB3ZubRTHgG0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=VcjtXDzv5sWTxwJygX93BRA/193DzNjUCfsmIEFfwkWBfBTXMJIVCn98sXDzdjRFTVWZjXLJcfRGi+4h+ERjdoDGZy8Ei6NqqHRGc3TimxbMWLjRqn1ZTSLXNisOuKGBYMTdoP3l6CxHXP+L9NQ/HuM25vSkK4zw7a5oceyj/ag= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160604_171849_819428_625E2BA4 X-CRM114-Status: GOOD ( 11.70 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, pawel.moll@arm.com, ijc+devicetree@hellion.org.uk, max.oss.09@gmail.com, linux@armlinux.org.uk, Stefan Agner , linux-kernel@vger.kernel.org, b.galvani@gmail.com, robh+dt@kernel.org, marcel@ziswiler.com, galak@codeaurora.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use the PMIC's repower capability for reboots. Register a restart handler with use a default priority of 128. Signed-off-by: Stefan Agner Reviewed-by: Marcel Ziswiler --- drivers/mfd/rn5t618.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/drivers/mfd/rn5t618.c b/drivers/mfd/rn5t618.c index d9b4d40..d9bd61c 100644 --- a/drivers/mfd/rn5t618.c +++ b/drivers/mfd/rn5t618.c @@ -12,13 +12,17 @@ * along with this program. If not, see . */ +#include #include #include #include #include #include +#include #include +#include + static const struct mfd_cell rn5t618_cells[] = { { .name = "rn5t618-regulator" }, { .name = "rn5t618-wdt" }, @@ -50,17 +54,34 @@ static const struct regmap_config rn5t618_regmap_config = { }; static struct rn5t618 *rn5t618_pm_power_off; +static struct notifier_block rn5t618_restart_handler; -static void rn5t618_power_off(void) +static void rn5t618_trigger_poweroff_sequence(bool repower) { /* disable automatic repower-on */ regmap_update_bits(rn5t618_pm_power_off->regmap, RN5T618_REPCNT, - RN5T618_REPCNT_REPWRON, 0); + RN5T618_REPCNT_REPWRON, repower); /* start power-off sequence */ regmap_update_bits(rn5t618_pm_power_off->regmap, RN5T618_SLPCNT, RN5T618_SLPCNT_SWPWROFF, RN5T618_SLPCNT_SWPWROFF); } +static void rn5t618_power_off(void) +{ + rn5t618_trigger_poweroff_sequence(false); +} + +static int rn5t618_restart(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rn5t618_trigger_poweroff_sequence(true); + + mdelay(10); + + return NOTIFY_DONE; +} + + static const struct of_device_id rn5t618_of_match[] = { { .compatible = "ricoh,rn5t567", .data = (void *)RN5T567 }, { .compatible = "ricoh,rn5t618", .data = (void *)RN5T618 }, @@ -103,13 +124,22 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c, return ret; } + rn5t618_pm_power_off = priv; if (of_device_is_system_power_controller(i2c->dev.of_node)) { - if (!pm_power_off) { - rn5t618_pm_power_off = priv; + if (!pm_power_off) pm_power_off = rn5t618_power_off; - } else { + else dev_err(&i2c->dev, "Failed to set poweroff capability, already defined\n"); - } + } + + rn5t618_restart_handler.notifier_call = rn5t618_restart; + rn5t618_restart_handler.priority = 128; + + ret = register_restart_handler(&rn5t618_restart_handler); + if (ret) { + dev_err(&i2c->dev, "%s: cannot register restart handler, %d\n", + __func__, ret); + return ret; } return 0;