From patchwork Sun Jun 26 01:15:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 9198937 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 1D4746077D for ; Sun, 26 Jun 2016 01:16:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DD0C2845C for ; Sun, 26 Jun 2016 01:16:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0248128528; Sun, 26 Jun 2016 01:16:56 +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=unavailable 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 831B02845C for ; Sun, 26 Jun 2016 01:16:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bGygw-0001yu-Cd; Sun, 26 Jun 2016 01:16:54 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bGygS-0001VT-2M; Sun, 26 Jun 2016 01:16:26 +0000 Received: from trochilidae.lan (unknown [IPv6:2601:602:8802:504f:3e97:eff:fe92:db3b]) by mail.kmu-office.ch (Postfix) with ESMTPSA id E374C5C17E9; Sun, 26 Jun 2016 03:12:40 +0200 (CEST) From: Stefan Agner To: lee.jones@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, khilman@baylibre.com, carlo@caione.org Subject: [PATCH v3 5/5] mfd: rn5t618: register restart handler Date: Sat, 25 Jun 2016 18:15:15 -0700 Message-Id: <20160626011515.4428-6-stefan@agner.ch> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160626011515.4428-1-stefan@agner.ch> References: <20160626011515.4428-1-stefan@agner.ch> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1466903564; bh=zNNFwp4jnxjx6xJ7HbvBwTqmiDYPBt9wd4lyKr6Dez8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=hLP/T7cV90Ye/R5WffM+EEQtxGC9POMWEOY/VyfiEkaIUMPrVjLK+LZ+F+9S7lZ1Jqb+EvHsw5cn8usUfjaYMQvdQ9dKCGWOYYcZUSi16XXjPsRj/uoQRFfksv4O3kJ2s6XeX5cnw75lnLM4ssAAFHfkUFxnGHfmbx4GnxqVSqA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160625_181624_615140_01C8B802 X-CRM114-Status: GOOD ( 11.78 ) 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 and use a slightly elevated priority of 192 since the PMIC has suprior reset capability (causing a system wide reset). 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 1831740..14f3b5f 100644 --- a/drivers/mfd/rn5t618.c +++ b/drivers/mfd/rn5t618.c @@ -12,11 +12,13 @@ * along with this program. If not, see . */ +#include #include #include #include #include #include +#include #include static const struct mfd_cell rn5t618_cells[] = { @@ -50,17 +52,37 @@ 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); + + /* + * Repower factor detection on PMIC side is not instant. 1ms + * proved to be enouth time until reset takes effect. + */ + mdelay(1); + + return NOTIFY_DONE; +} + static const struct of_device_id rn5t618_of_match[] = { { .compatible = "ricoh,rn5t567", .data = (void *)RN5T567 }, { .compatible = "ricoh,rn5t618", .data = (void *)RN5T618 }, @@ -102,13 +124,21 @@ 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_warn(&i2c->dev, "Poweroff callback already assigned\n"); - } + } + + rn5t618_restart_handler.notifier_call = rn5t618_restart; + rn5t618_restart_handler.priority = 192; + + ret = register_restart_handler(&rn5t618_restart_handler); + if (ret) { + dev_err(&i2c->dev, "cannot register restart handler, %d\n", ret); + return ret; } return 0;