From: <sean.wang@mediatek.com> To: <robh+dt@kernel.org>, <mark.rutland@arm.com>, <sre@kernel.org>, <lee.jones@linaro.org>, <a.zummo@towertech.it>, <alexandre.belloni@free-electrons.com>, <eddie.huang@mediatek.com> Cc: <devicetree@vger.kernel.org>, <linux-rtc@vger.kernel.org>, <linux-pm@vger.kernel.org>, <linux-mediatek@lists.infradead.org>, <linux-kernel@vger.kernel.org>, Sean Wang <sean.wang@mediatek.com> Subject: [PATCH v1 14/16] power: reset: mediatek: add a power-off driver using PMIC RTC device Date: Fri, 23 Mar 2018 17:15:11 +0800 [thread overview] Message-ID: <ba7cd65b58f335b44896bd671f8b0f851d04fc01.1521794177.git.sean.wang@mediatek.com> (raw) In-Reply-To: <cover.1521794176.git.sean.wang@mediatek.com> From: Sean Wang <sean.wang@mediatek.com> The power device is responsible for externally down or up the power of the remote MediaTek SoC through the tiny circuit BBPU inside PMIC RTC. Though it's a part of RTC device, it would be better to be a standalone driver against existent RTC driver so as to make concentration on works about power-controlling topic and help gather more improvements while the subsystem's constantly growing. Currently, the most basic functionality supported is to just power off the system by writing to a special bit field in BBPU register after the system has reached pm_poweroff. Signed-off-by: Sean Wang <sean.wang@mediatek.com> --- drivers/power/reset/Kconfig | 9 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/mt6397-rtc-poweroff.c | 100 ++++++++++++++++++++++++++++++ include/linux/rtc/mt6397.h | 1 + 4 files changed, 111 insertions(+) create mode 100644 drivers/power/reset/mt6397-rtc-poweroff.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index a102e74..0bd4603 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -121,6 +121,15 @@ 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_MT6397_RTC + bool "MediaTek MT6397 RTC power-off driver" + help + This driver supports turning off a remote MediaTek SoC by + controlling BBPU on MT6397 or MT6323 RTC. + + Select this if you're building a kernel with your MediaTek SoC + with an equipment with MT6397 or MT6323 PMIC. + 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 dcc92f5..d45099e 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_MT6397_RTC) += mt6397-rtc-poweroff.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o diff --git a/drivers/power/reset/mt6397-rtc-poweroff.c b/drivers/power/reset/mt6397-rtc-poweroff.c new file mode 100644 index 0000000..9b57366 --- /dev/null +++ b/drivers/power/reset/mt6397-rtc-poweroff.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Power-off using MediaTek PMIC RTC device + * + * Copyright (C) 2018 MediaTek Inc. + * + * Author: Sean Wang <sean.wang@mediatek.com> + * + */ + +#include <linux/err.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/rtc/mt6397.h> + +struct mt6397_rtc_powercon { + struct device *dev; + struct mt6397_rtc *rtc; +}; + +static struct mt6397_rtc_powercon *mt_powercon; + +static void mt6397_rtc_do_poweroff(void) +{ + struct mt6397_rtc_powercon *powercon = mt_powercon; + struct mt6397_rtc *rtc = powercon->rtc; + unsigned int val; + int ret; + + regmap_write(rtc->regmap, rtc->addr_base + RTC_BBPU, RTC_BBPU_KEY); + regmap_write(rtc->regmap, rtc->addr_base + RTC_WRTGR, 1); + + ret = regmap_read_poll_timeout(rtc->regmap, + rtc->addr_base + RTC_BBPU, val, + !(val & RTC_BBPU_CBUSY), + MTK_RTC_POLL_DELAY_US, + MTK_RTC_POLL_TIMEOUT); + if (ret) + dev_err(powercon->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 poweroff system\n"); +} + +static int mt6397_rtc_poweroff_probe(struct platform_device *pdev) +{ + struct mt6397_rtc *rtc = dev_get_drvdata(pdev->dev.parent); + struct mt6397_rtc_powercon *powercon; + + if (!rtc) { + dev_err(&pdev->dev, "Can't find RTC as the parent\n"); + return -ENODEV; + } + + powercon = devm_kzalloc(&pdev->dev, sizeof(*powercon), GFP_KERNEL); + if (!powercon) + return -ENOMEM; + + powercon->dev = &pdev->dev; + powercon->rtc = rtc; + mt_powercon = powercon; + + pm_power_off = &mt6397_rtc_do_poweroff; + + return 0; +} + +static int mt6397_rtc_poweroff_remove(struct platform_device *pdev) +{ + if (pm_power_off == &mt6397_rtc_do_poweroff) + pm_power_off = NULL; + + return 0; +} + +static const struct of_device_id mt6397_rtc_poweroff_dt_match[] = { + { .compatible = "mediatek,mt6323-rtc-poweroff" }, + { .compatible = "mediatek,mt6397-rtc-poweroff" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mt6397_rtc_poweroff_dt_match); + +static struct platform_driver mt6397_rtc_poweroff_driver = { + .probe = mt6397_rtc_poweroff_probe, + .remove = mt6397_rtc_poweroff_remove, + .driver = { + .name = "mt6397-rtc-poweroff", + .of_match_table = mt6397_rtc_poweroff_dt_match, + }, +}; + +module_platform_driver(mt6397_rtc_poweroff_driver); + +MODULE_DESCRIPTION("Poweroff driver using MediaTek PMIC RTC"); +MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:mt6397-rtc-poweroff"); diff --git a/include/linux/rtc/mt6397.h b/include/linux/rtc/mt6397.h index 4b19f51..e618974 100644 --- a/include/linux/rtc/mt6397.h +++ b/include/linux/rtc/mt6397.h @@ -17,6 +17,7 @@ #define RTC_BBPU 0x0000 #define RTC_BBPU_CBUSY BIT(6) +#define RTC_BBPU_KEY (0x43 << 8) #define RTC_WRTGR 0x003c -- 2.7.4
next prev parent reply other threads:[~2018-03-23 9:15 UTC|newest] Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-23 9:14 [PATCH v1 00/16] Add support to MT6323 RTC and its power device sean.wang 2018-03-23 9:14 ` [PATCH v1 01/16] dt-bindings: power: reset: mediatek: add bindings for " sean.wang 2018-03-26 22:24 ` Rob Herring 2018-03-27 3:21 ` Sean Wang 2018-03-23 9:14 ` [PATCH v1 02/16] dt-bindings: rtc: mediatek: add bindings for PMIC RTC sean.wang 2018-03-23 9:41 ` Alexandre Belloni 2018-03-23 10:15 ` Alexandre Belloni 2018-03-24 19:36 ` Sean Wang 2018-03-27 15:18 ` Alexandre Belloni 2018-03-28 3:53 ` Sean Wang 2018-03-28 9:19 ` Alexandre Belloni 2018-03-23 9:15 ` [PATCH v1 03/16] dt-bindings: mfd: mediatek: add a description for MT6323 RTC sean.wang 2018-03-26 22:24 ` Rob Herring 2018-03-28 11:13 ` Lee Jones 2018-03-23 9:15 ` [PATCH v1 04/16] mfd: mt6397: add MT6323 RTC support into MT6397 driver sean.wang 2018-03-28 11:15 ` Lee Jones 2018-03-23 9:15 ` [PATCH v1 05/16] rtc: mediatek: add MT6323 support to RTC driver sean.wang 2018-03-23 10:01 ` Alexandre Belloni 2018-03-24 7:06 ` Sean Wang 2018-03-23 9:15 ` [PATCH v1 06/16] rtc: mediatek: remove unnecessary parentheses sean.wang 2018-03-23 10:21 ` Alexandre Belloni 2018-03-24 7:14 ` Sean Wang 2018-03-24 18:53 ` Alexandre Belloni 2018-03-24 19:21 ` Sean Wang 2018-03-23 9:15 ` [PATCH v1 07/16] rtc: mediatek: replace a poll with regmap_read_poll_timeout sean.wang 2018-03-23 9:15 ` [PATCH v1 08/16] rtc: mediatek: remove unnecessary irq_dispose_mapping sean.wang 2018-03-23 10:38 ` Alexandre Belloni 2018-03-26 2:22 ` Sean Wang 2018-03-23 9:15 ` [PATCH v1 09/16] rtc: mediatek: convert to use device managed functions sean.wang 2018-03-23 10:50 ` Alexandre Belloni 2018-03-26 4:07 ` Sean Wang 2018-03-27 15:07 ` Alexandre Belloni 2018-03-23 9:15 ` [PATCH v1 10/16] rtc: mediatek: add devm_of_platform_populate sean.wang 2018-03-23 9:15 ` [PATCH v1 11/16] rtc: mediatek: move the declaration into a globally visible header file sean.wang 2018-03-23 9:57 ` Alexandre Belloni 2018-03-24 7:31 ` Sean Wang 2018-03-24 18:54 ` Alexandre Belloni 2018-03-24 20:00 ` Fabio Estevam 2018-03-25 3:13 ` Sean Wang 2018-03-23 9:15 ` [PATCH v1 12/16] rtc: mediatek: cleanup header files to include sean.wang 2018-03-25 4:17 ` kbuild test robot 2018-03-25 5:21 ` kbuild test robot 2018-03-23 9:15 ` [PATCH v1 13/16] rtc: mediatek: update license converting to using SPDX identifiers sean.wang 2018-03-23 9:15 ` sean.wang [this message] 2018-03-23 9:15 ` [PATCH v1 15/16] MAINTAINERS: update entry for ARM/Mediatek RTC DRIVER sean.wang 2018-03-23 9:15 ` [PATCH v1 16/16] MAINTAINERS: add an entry for MediaTek board level shutdown driver sean.wang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ba7cd65b58f335b44896bd671f8b0f851d04fc01.1521794177.git.sean.wang@mediatek.com \ --to=sean.wang@mediatek.com \ --cc=a.zummo@towertech.it \ --cc=alexandre.belloni@free-electrons.com \ --cc=devicetree@vger.kernel.org \ --cc=eddie.huang@mediatek.com \ --cc=lee.jones@linaro.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mediatek@lists.infradead.org \ --cc=linux-pm@vger.kernel.org \ --cc=linux-rtc@vger.kernel.org \ --cc=mark.rutland@arm.com \ --cc=robh+dt@kernel.org \ --cc=sre@kernel.org \ --subject='Re: [PATCH v1 14/16] power: reset: mediatek: add a power-off driver using PMIC RTC device' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).