Skip to content

Commit

Permalink
power: reset: add driver for mt6323 poweroff
Browse files Browse the repository at this point in the history
add poweroff driver for mt6323 and make Makefile and Kconfig-Entries

Suggested-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v5: split out mfd/mt6397/core.h
changes since v4: none
changes since v3: none
changes since v2: none (=v2 part 5)
  • Loading branch information
Josef Friedl authored and frank-w committed Aug 28, 2019
1 parent 3b14895 commit df62831
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/power/reset/Kconfig
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/power/reset/Makefile
Expand Up @@ -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
Expand Down
97 changes: 97 additions & 0 deletions 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 <sean.wang@mediatek.com>
*
*/

#include <linux/err.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/mfd/mt6397/core.h>
#include <linux/mfd/mt6397/rtc.h>

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 <sean.wang@mediatek.com>");
MODULE_LICENSE("GPL v2");

0 comments on commit df62831

Please sign in to comment.