From patchwork Thu Jan 12 16:15:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 9513543 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 B741E601E7 for ; Thu, 12 Jan 2017 16:15:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A644328633 for ; Thu, 12 Jan 2017 16:15:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97C01286E1; Thu, 12 Jan 2017 16:15:38 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 98C6428633 for ; Thu, 12 Jan 2017 16:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750819AbdALQPM (ORCPT ); Thu, 12 Jan 2017 11:15:12 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33248 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750886AbdALQPL (ORCPT ); Thu, 12 Jan 2017 11:15:11 -0500 Received: by mail-wm0-f67.google.com with SMTP id r144so4756486wme.0; Thu, 12 Jan 2017 08:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YdF5RT8yaYijPEiN5BpTdJvtr+iFkLQtZbizaSiBVeE=; b=agLI2xv+n3Z6tjsDVx9P5e0bjLb5yNicudaW15iCdoCf9GmuN7pErDRcGTiSb5M3vj ZjkiVnH6BKLnFfiMkJS7oNGENchlOrvEhHYSKlNkn9e0pEy7OMY5jq7i+NN3xPFFfECc lA7M8WkaGYvXqCajVQZOfmnArpXobG9KjGzJfbhT8FcK7elc2hPdmyGZ+qwQrRi8I64X G5TuUxNBMux9vj+I8l6n0u1AdQKbeZ2wv9mMSPrUB9OgDUV+Mp/jl+6+HBveuUI4dtX5 6mF5ypqjpNGdkuV7BF99FR2Q4yvzurI+vNh93rnSYAzi/v7OgEad9qOD2IUYhpqvzGq2 MP0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=YdF5RT8yaYijPEiN5BpTdJvtr+iFkLQtZbizaSiBVeE=; b=MKlm/Gb4MeprVwvjD/ZQphEIRy+3BBXRipHt2dfwwZdHDrPoPn3vRlrb3ffrNrcIle L+cJK6617zHj6/9zl8qzmXhzakKoUswM/MF9drnGSCLC8s3ohzB3VsG8ecwdtmKZhHxi z/QJmTUXIc6J2ZQ+I9jZ5tzVvrFyd06Ab1cG7y0FMHMFMHe0SiZQfjTU/swIT86dcBEa 2kvaOd07+sYDtwnw/2QhqAcw+pWDP3qBHLxiMs3WSc2yK3wXRGbrODYfba29nYlIUz6E DZOjn0yOV5RNjWgmWL8SGL1kEuB2TGi4BP1bgNis2zAaNNfstZHcgSB2oox06AvjKluM OpYw== X-Gm-Message-State: AIkVDXKizLWk3RSBKCIapO9xFZH7Ot/e1b/I1NcLj9eaib1vrcRB7FNvgbv3xDRPZGUK7Q== X-Received: by 10.223.160.172 with SMTP id m41mr7473364wrm.116.1484237709401; Thu, 12 Jan 2017 08:15:09 -0800 (PST) Received: from localhost (port-6463.pppoe.wtnet.de. [84.46.25.88]) by smtp.gmail.com with ESMTPSA id c81sm3904439wmf.22.2017.01.12.08.15.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jan 2017 08:15:08 -0800 (PST) From: Thierry Reding To: Sebastian Reichel Cc: Laxman Dewangan , Martin Michlmayr , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chaitanya Bandi Subject: [PATCH] power: reset: Add MAX77620 support Date: Thu, 12 Jan 2017 17:15:07 +0100 Message-Id: <20170112161507.23774-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding The Maxim MAX77620 PMIC has the ability to power off and restart the system. Add a driver that supports power off (via pm_power_off()) and restart (via arm_pm_restart() on 32-bit and 64-bit ARM). Based on work by Chaitanya Bandi . Cc: Chaitanya Bandi Signed-off-by: Thierry Reding --- drivers/power/reset/Kconfig | 6 ++ drivers/power/reset/Makefile | 1 + drivers/power/reset/max77620-poweroff.c | 146 ++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 drivers/power/reset/max77620-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index abeb77217a21..f0d0c20632f8 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -98,6 +98,12 @@ config POWER_RESET_IMX say N here or disable in dts to make sure pm_power_off never be overwrote wrongly by this driver. +config POWER_RESET_MAX77620 + bool "Maxim MAX77620 PMIC power-off driver" + depends on MFD_MAX77620 + help + Power off and restart support for Maxim MAX77620 PMICs. + config POWER_RESET_MSM bool "Qualcomm MSM power-off driver" depends on ARCH_QCOM diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 11dae3b56ff9..74511d2f037a 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o obj-$(CONFIG_POWER_RESET_IMX) += imx-snvs-poweroff.o +obj-$(CONFIG_POWER_RESET_MAX77620) += max77620-poweroff.o obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o diff --git a/drivers/power/reset/max77620-poweroff.c b/drivers/power/reset/max77620-poweroff.c new file mode 100644 index 000000000000..4f2682d10925 --- /dev/null +++ b/drivers/power/reset/max77620-poweroff.c @@ -0,0 +1,146 @@ +/* + * Power off driver for Maxim MAX77620 device. + * + * Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved. + * + * Based on work by Chaitanya Bandi . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, + * whether express or implied; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) +#include +#endif + +struct max77620_power { + struct regmap *regmap; + struct device *dev; +}; + +static struct max77620_power *system_power_controller = NULL; + +static void max77620_pm_power_off(void) +{ + struct max77620_power *power = system_power_controller; + unsigned int value; + int err; + + if (!power) + return; + + /* clear power key interrupts */ + err = regmap_read(power->regmap, MAX77620_REG_ONOFFIRQ, &value); + if (err < 0) + dev_err(power->dev, "failed to clear power key interrupts: %d\n", err); + + /* clear RTC interrupts */ + /* + err = regmap_read(power->regmap, MAX77620_REG_RTCINT, &value); + if (err < 0) + dev_err(power->dev, "failed to clear RTC interrupts: %d\n", err); + */ + + /* clear TOP interrupts */ + err = regmap_read(power->regmap, MAX77620_REG_IRQTOP, &value); + if (err < 0) + dev_err(power->dev, "failed to clear interrupts: %d\n", err); + + err = regmap_update_bits(power->regmap, MAX77620_REG_ONOFFCNFG2, + MAX77620_ONOFFCNFG2_SFT_RST_WK, 0); + if (err < 0) + dev_err(power->dev, "failed to clear SFT_RST_WK: %d\n", err); + + err = regmap_update_bits(power->regmap, MAX77620_REG_ONOFFCNFG1, + MAX77620_ONOFFCNFG1_SFT_RST, + MAX77620_ONOFFCNFG1_SFT_RST); + if (err < 0) + dev_err(power->dev, "failed to set SFT_RST: %d\n", err); +} + +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) +static void max77620_pm_restart(enum reboot_mode mode, const char *cmd) +{ + struct max77620_power *power = system_power_controller; + int err; + + if (!power) + return; + + err = regmap_update_bits(power->regmap, MAX77620_REG_ONOFFCNFG2, + MAX77620_ONOFFCNFG2_SFT_RST_WK, + MAX77620_ONOFFCNFG2_SFT_RST_WK); + if (err < 0) + dev_err(power->dev, "failed to set SFT_RST_WK: %d\n", err); + + err = regmap_update_bits(power->regmap, MAX77620_REG_ONOFFCNFG1, + MAX77620_ONOFFCNFG1_SFT_RST, + MAX77620_ONOFFCNFG1_SFT_RST); + if (err < 0) + dev_err(power->dev, "failed to set SFT_RST: %d\n", err); +} +#endif + +static int max77620_poweroff_probe(struct platform_device *pdev) +{ + struct max77620_chip *max77620 = dev_get_drvdata(pdev->dev.parent); + struct device_node *np = pdev->dev.parent->of_node; + struct max77620_power *power; + unsigned int value; + int err; + + if (!of_property_read_bool(np, "system-power-controller")) + return 0; + + power = devm_kzalloc(&pdev->dev, sizeof(*power), GFP_KERNEL); + if (!power) + return -ENOMEM; + + power->regmap = max77620->rmap; + power->dev = &pdev->dev; + + err = regmap_read(power->regmap, MAX77620_REG_NVERC, &value); + if (err < 0) { + dev_err(power->dev, "failed to read event recorder: %d\n", err); + return err; + } + + dev_dbg(&pdev->dev, "event recorder: %#x\n", value); + + system_power_controller = power; + pm_power_off = max77620_pm_power_off; +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) + arm_pm_restart = max77620_pm_restart; +#endif + + return 0; +} + +static struct platform_driver max77620_poweroff_driver = { + .driver = { + .name = "max77620-power", + }, + .probe = max77620_poweroff_probe, +}; +module_platform_driver(max77620_poweroff_driver); + +MODULE_DESCRIPTION("Maxim MAX77620 PMIC power off and restart driver"); +MODULE_AUTHOR("Thierry Reding "); +MODULE_ALIAS("platform:max77620-power"); +MODULE_LICENSE("GPL v2");