Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.19 poweroff #44

Merged
merged 2 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Documentation/devicetree/bindings/mfd/mt6397.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
- Clock
- LED
- Keys
- Power controller

It is interfaced to host controller using SPI interface by a proprietary hardware
called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
Expand All @@ -22,8 +23,10 @@ compatible: "mediatek,mt6397" or "mediatek,mt6323"
Optional subnodes:

- rtc
Required properties:
Required properties: Should be one of follows
- compatible: "mediatek,mt6323-rtc"
- compatible: "mediatek,mt6397-rtc"
For details, see Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
- regulators
Required properties:
- compatible: "mediatek,mt6397-regulator"
Expand All @@ -46,6 +49,11 @@ Optional subnodes:
- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt

- power-controller
Required properties:
- compatible: "mediatek,mt6323-pwrc"
For details, see Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt

Example:
pwrap: pwrap@1000f000 {
compatible = "mediatek,mt8135-pwrap";
Expand Down
20 changes: 20 additions & 0 deletions Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Device Tree Bindings for Power Controller on MediaTek PMIC

The power controller which could be found on PMIC is responsible for externally
powering off or on the remote MediaTek SoC through the circuit BBPU.

Required properties:
- compatible: Should be one of follows
"mediatek,mt6323-pwrc": for MT6323 PMIC

Example:

pmic {
compatible = "mediatek,mt6323";

...

power-controller {
compatible = "mediatek,mt6323-pwrc";
};
}
29 changes: 29 additions & 0 deletions Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Device-Tree bindings for MediaTek PMIC based RTC

MediaTek PMIC based RTC is an independent function of MediaTek PMIC that works
as a type of multi-function device (MFD). The RTC can be configured and set up
with PMIC wrapper bus which is a common resource shared with the other
functions found on the same PMIC.

For MediaTek PMIC MFD bindings, see:
Documentation/devicetree/bindings/mfd/mt6397.txt

For MediaTek PMIC wrapper bus bindings, see:
Documentation/devicetree/bindings/soc/mediatek/pwrap.txt

Required properties:
- compatible: Should be one of follows
"mediatek,mt6323-rtc": for MT6323 PMIC
"mediatek,mt6397-rtc": for MT6397 PMIC

Example:

pmic {
compatible = "mediatek,mt6323";

...

rtc {
compatible = "mediatek,mt6323-rtc";
};
};
7 changes: 7 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -9197,6 +9197,13 @@ S: Maintained
F: drivers/net/dsa/mt7530.*
F: net/dsa/tag_mtk.c

MEDIATEK BOARD LEVEL SHUTDOWN DRIVERS
M: Sean Wang <sean.wang@mediatek.com>
L: linux-pm@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
F: drivers/power/reset/mt6323-poweroff.c

MEDIATEK JPEG DRIVER
M: Rick Chang <rick.chang@mediatek.com>
M: Bin Liu <bin.liu@mediatek.com>
Expand Down
46 changes: 45 additions & 1 deletion arch/arm/boot/dts/mt6323.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@
compatible = "mediatek,mt6323-led";
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";

led@0 {
reg = <0>;
label = "bpi-r2:isink:green";
default-state = "off";
};

led@1 {
reg = <1>;
label = "bpi-r2:isink:red";
default-state = "off";
};

led@2 {
reg = <2>;
label = "bpi-r2:isink:blue";
default-state = "off";
};
};

mt6323regulator: mt6323regulator{
Expand Down Expand Up @@ -238,5 +255,32 @@
regulator-enable-ramp-delay = <216>;
};
};

mt6323keys: mt6323keys {
compatible = "mediatek,mt6323-keys";
mediatek,long-press-mode = <1>;
power-off-time-sec = <0>;

power {
linux,keycodes = <116>;
wakeup-source;
};

home {
linux,keycodes = <114>;
};
};

codec: mt6397codec {
compatible = "mediatek,mt6397-codec";
};

power-controller {
compatible = "mediatek,mt6323-pwrc";
};

rtc {
compatible = "mediatek,mt6323-rtc";
};
};
};
4 changes: 4 additions & 0 deletions arch/arm/configs/mt7623n_evb_fwu_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ CONFIG_SPI_MASTER=y
CONFIG_SPI_SPIDEV=m
CONFIG_SPI_MT65XX=m

CONFIG_RTC_DRV_MT6397=y

CONFIG_PWM=y
CONFIG_PWM_MEDIATEK=m

Expand Down Expand Up @@ -420,6 +422,8 @@ CONFIG_XFS_FS=m
#RTC/POWER
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_MT6397_RTC=y
CONFIG_POWER_RESET_MT6323=y
CONFIG_KEYBOARD_MTK_PMIC=m

#unused drivers which are set by default
CONFIG_WLAN_VENDOR_ADMTEK=n
Expand Down
40 changes: 29 additions & 11 deletions drivers/mfd/mt6397-core.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014 MediaTek Inc.
* Copyright (c) 2014-2018 MediaTek Inc.
* Author: Flora Fu, MediaTek
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -13,6 +13,7 @@
*/

#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/of_irq.h>
Expand All @@ -23,24 +24,27 @@
#include <linux/mfd/mt6397/registers.h>
#include <linux/mfd/mt6323/registers.h>

#define MT6323_RTC_BASE 0x8000
#define MT6323_RTC_SIZE 0x40

#define MT6397_RTC_BASE 0xe000
#define MT6397_RTC_SIZE 0x3e

#define MT6323_PWRC_BASE 0x8000
#define MT6323_PWRC_SIZE 0x40

#define MT6323_CID_CODE 0x23
#define MT6391_CID_CODE 0x91
#define MT6397_CID_CODE 0x97

static const struct resource mt6323_rtc_resources[] = {
DEFINE_RES_MEM(MT6323_RTC_BASE, MT6323_RTC_SIZE),
DEFINE_RES_IRQ(MT6323_IRQ_STATUS_RTC),
};

static const struct resource mt6397_rtc_resources[] = {
{
.start = MT6397_RTC_BASE,
.end = MT6397_RTC_BASE + MT6397_RTC_SIZE,
.flags = IORESOURCE_MEM,
},
{
.start = MT6397_IRQ_RTC,
.end = MT6397_IRQ_RTC,
.flags = IORESOURCE_IRQ,
},
DEFINE_RES_MEM(MT6397_RTC_BASE, MT6397_RTC_SIZE),
DEFINE_RES_IRQ(MT6397_IRQ_RTC),
};

static const struct resource mt6323_keys_resources[] = {
Expand All @@ -53,8 +57,17 @@ static const struct resource mt6397_keys_resources[] = {
DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
};

static const struct resource mt6323_pwrc_resources[] = {
DEFINE_RES_MEM(MT6323_PWRC_BASE, MT6323_PWRC_SIZE),
};

static const struct mfd_cell mt6323_devs[] = {
{
.name = "mt6323-rtc",
.num_resources = ARRAY_SIZE(mt6323_rtc_resources),
.resources = mt6323_rtc_resources,
.of_compatible = "mediatek,mt6323-rtc",
}, {
.name = "mt6323-regulator",
.of_compatible = "mediatek,mt6323-regulator"
}, {
Expand All @@ -65,6 +78,11 @@ static const struct mfd_cell mt6323_devs[] = {
.num_resources = ARRAY_SIZE(mt6323_keys_resources),
.resources = mt6323_keys_resources,
.of_compatible = "mediatek,mt6323-keys"
}, {
.name = "mt6323-pwrc",
.num_resources = ARRAY_SIZE(mt6323_pwrc_resources),
.resources = mt6323_pwrc_resources,
.of_compatible = "mediatek,mt6323-pwrc"
},
};

Expand Down
10 changes: 10 additions & 0 deletions drivers/power/reset/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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");
Loading