Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5989863ybe; Tue, 10 Sep 2019 11:49:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyF6vIhDWuZRSJG4Pfg0BcuK5FnTSBwW63Mtqb/0nO9A7VlBtJmfvrZKbsYUyuAdrPTVwIu X-Received: by 2002:a17:906:3545:: with SMTP id s5mr25499589eja.73.1568141380519; Tue, 10 Sep 2019 11:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568141380; cv=none; d=google.com; s=arc-20160816; b=XS/Trh4ByGQIJocP9G6frAziWZQwZUPW7jESUS3Es5aQpXsvufQ7ySkU1Zpru3Klm1 QzLeaadaACcNyd2MHHAOWTk6/TJE359gXYbAT9nYZ/TsLO1q62U3XbvubUOgWaj8vb46 oR/qHdeBBUQ/0N/v/CzmNbHiINRrJPNo7n/XwI3KHlKUZdXMkcic1DA74Ktsr6kEjz5G lIftVtLAz93E30qMBF37wf+agLQownoItRDhUrXub3YS1VmGRkq3TNPs4HrJDyMqc1TD qGJgmT35dHdKkv2YY7RLWcZ/r2hvGONm4nuRY8JZcjD7H2KOZaGNOViQOxrDE1s+vHvv vPEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=wZvqG1ZGXAk7K0sSBzUZ9ZTyz54bEXH2x16LUx1I+5M=; b=imNgkMUdV9uHcF4YTSVZAD+UNr89BzRbP/Uhxgm5yZzzfNGhiq+5+loLoQ8mPfk4rH ouxPD2hDbIUZrJ1fwrO5hJnlnzPnfhYv+URCw5R+eCiclNf8WpQMDs3dGx2b2LhsSNOD WfQ7hVc5JTI/wJfYQA+dJsVbQBxhjBcbk9ahi3g7Xzqmm6pPMw96u5vwWdsbQlqO1JcD T6Qp7nmDMXm6c+kkPKhJORmH5nv4f6VbCnA7uNQu7vtx2NF9JZhk80rXE95Tm30twci/ 820f7Tgm66owFtfXhQTn5PPKH99jZo7GBcc6VsZRg1krqn+tAwMS/NVAqzx46Z81RMJ2 A0xQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sd1si9703056ejb.342.2019.09.10.11.49.16; Tue, 10 Sep 2019 11:49:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406644AbfIJHOg (ORCPT + 99 others); Tue, 10 Sep 2019 03:14:36 -0400 Received: from mxwww.masterlogin.de ([95.129.51.220]:43430 "EHLO mxwww.masterlogin.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404256AbfIJHOb (ORCPT ); Tue, 10 Sep 2019 03:14:31 -0400 X-Greylist: delayed 555 seconds by postgrey-1.27 at vger.kernel.org; Tue, 10 Sep 2019 03:14:29 EDT Received: from mxout2.routing.net (unknown [192.168.10.82]) by new.mxwww.masterlogin.de (Postfix) with ESMTPS id 2E88996365; Tue, 10 Sep 2019 07:05:18 +0000 (UTC) Received: from mxbox2.masterlogin.de (unknown [192.168.10.253]) by mxout2.routing.net (Postfix) with ESMTP id 69E126205B; Tue, 10 Sep 2019 07:05:18 +0000 (UTC) Received: from localhost.localdomain (fttx-pool-185.75.73.135.bambit.de [185.75.73.135]) by mxbox2.masterlogin.de (Postfix) with ESMTPSA id 613BD100A7E; Tue, 10 Sep 2019 07:05:17 +0000 (UTC) From: Frank Wunderlich To: linux-mediatek@lists.infradead.org Cc: Frank Wunderlich , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Alessandro Zummo , Alexandre Belloni , Eddie Huang , Josef Friedl , Lee Jones , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-rtc@vger.kernel.org, Mark Rutland , Matthias Brugger , Rob Herring , Sean Wang , Sebastian Reichel , "Tianping Fang" Subject: [PATCH v7 5/7] power: reset: add driver for mt6323 poweroff Date: Tue, 10 Sep 2019 09:04:44 +0200 Message-Id: <20190910070446.639-6-frank-w@public-files.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190910070446.639-1-frank-w@public-files.de> References: <20190910070446.639-1-frank-w@public-files.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Friedl add poweroff driver for mt6323 and make Makefile and Kconfig-Entries Suggested-by: Frank Wunderlich Signed-off-by: Josef Friedl Signed-off-by: Frank Wunderlich Acked-by: Sebastian Reichel --- changes since v6: none changes since v5: split out mfd/mt6397/core.h changes since v4: none changes since v3: none changes since v2: none (=v2 part 5) --- drivers/power/reset/Kconfig | 10 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 drivers/power/reset/mt6323-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index a564237278ff..c721939767eb 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -140,6 +140,16 @@ config POWER_RESET_LTC2952 This driver supports an external powerdown trigger and board power down via the LTC2952. Bindings are made in the device tree. +config POWER_RESET_MT6323 + bool "MediaTek MT6323 power-off driver" + depends on MFD_MT6397 + help + The power-off driver is responsible for externally shutdown down + the power of a remote MediaTek SoC MT6323 is connected to through + controlling a tiny circuit BBPU inside MT6323 RTC. + + Say Y if you have a board where MT6323 could be found. + config POWER_RESET_QNAP bool "QNAP power-off driver" depends on OF_GPIO && PLAT_ORION diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 85da3198e4e0..da37f8b851dc 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -11,6 +11,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_MSM) += msm-poweroff.o +obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/mt6323-poweroff.c new file mode 100644 index 000000000000..1caf43d9e46d --- /dev/null +++ b/drivers/power/reset/mt6323-poweroff.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Power off through MediaTek PMIC + * + * Copyright (C) 2018 MediaTek Inc. + * + * Author: Sean Wang + * + */ + +#include +#include +#include +#include +#include +#include + +struct mt6323_pwrc { + struct device *dev; + struct regmap *regmap; + u32 base; +}; + +static struct mt6323_pwrc *mt_pwrc; + +static void mt6323_do_pwroff(void) +{ + struct mt6323_pwrc *pwrc = mt_pwrc; + unsigned int val; + int ret; + + regmap_write(pwrc->regmap, pwrc->base + RTC_BBPU, RTC_BBPU_KEY); + regmap_write(pwrc->regmap, pwrc->base + RTC_WRTGR, 1); + + ret = regmap_read_poll_timeout(pwrc->regmap, + pwrc->base + RTC_BBPU, val, + !(val & RTC_BBPU_CBUSY), + MTK_RTC_POLL_DELAY_US, + MTK_RTC_POLL_TIMEOUT); + if (ret) + dev_err(pwrc->dev, "failed to write BBPU: %d\n", ret); + + /* Wait some time until system down, otherwise, notice with a warn */ + mdelay(1000); + + WARN_ONCE(1, "Unable to power off system\n"); +} + +static int mt6323_pwrc_probe(struct platform_device *pdev) +{ + struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev->dev.parent); + struct mt6323_pwrc *pwrc; + struct resource *res; + + pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL); + if (!pwrc) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + pwrc->base = res->start; + pwrc->regmap = mt6397_chip->regmap; + pwrc->dev = &pdev->dev; + mt_pwrc = pwrc; + + pm_power_off = &mt6323_do_pwroff; + + return 0; +} + +static int mt6323_pwrc_remove(struct platform_device *pdev) +{ + if (pm_power_off == &mt6323_do_pwroff) + pm_power_off = NULL; + + return 0; +} + +static const struct of_device_id mt6323_pwrc_dt_match[] = { + { .compatible = "mediatek,mt6323-pwrc" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match); + +static struct platform_driver mt6323_pwrc_driver = { + .probe = mt6323_pwrc_probe, + .remove = mt6323_pwrc_remove, + .driver = { + .name = "mt6323-pwrc", + .of_match_table = mt6323_pwrc_dt_match, + }, +}; + +module_platform_driver(mt6323_pwrc_driver); + +MODULE_DESCRIPTION("Poweroff driver for MT6323 PMIC"); +MODULE_AUTHOR("Sean Wang "); +MODULE_LICENSE("GPL v2"); -- 2.17.1