Skip to content

Commit 1dea45d

Browse files
authored
4.19 poweroff new (#49)
[poweroff] add power-off patch from jofri
1 parent 25240db commit 1dea45d

File tree

13 files changed

+355
-127
lines changed

13 files changed

+355
-127
lines changed

Documentation/devicetree/bindings/mfd/mt6397.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
88
- Clock
99
- LED
1010
- Keys
11+
- Power controller
1112

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

2425
- rtc
25-
Required properties:
26+
Required properties: Should be one of follows
27+
- compatible: "mediatek,mt6323-rtc"
2628
- compatible: "mediatek,mt6397-rtc"
29+
For details, see Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
2730
- regulators
2831
Required properties:
2932
- compatible: "mediatek,mt6397-regulator"
@@ -46,6 +49,11 @@ Optional subnodes:
4649
- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
4750
see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
4851

52+
- power-controller
53+
Required properties:
54+
- compatible: "mediatek,mt6323-pwrc"
55+
For details, see Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
56+
4957
Example:
5058
pwrap: pwrap@1000f000 {
5159
compatible = "mediatek,mt8135-pwrap";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Device Tree Bindings for Power Controller on MediaTek PMIC
2+
3+
The power controller which could be found on PMIC is responsible for externally
4+
powering off or on the remote MediaTek SoC through the circuit BBPU.
5+
6+
Required properties:
7+
- compatible: Should be one of follows
8+
"mediatek,mt6323-pwrc": for MT6323 PMIC
9+
10+
Example:
11+
12+
pmic {
13+
compatible = "mediatek,mt6323";
14+
15+
...
16+
17+
power-controller {
18+
compatible = "mediatek,mt6323-pwrc";
19+
};
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Device-Tree bindings for MediaTek PMIC based RTC
2+
3+
MediaTek PMIC based RTC is an independent function of MediaTek PMIC that works
4+
as a type of multi-function device (MFD). The RTC can be configured and set up
5+
with PMIC wrapper bus which is a common resource shared with the other
6+
functions found on the same PMIC.
7+
8+
For MediaTek PMIC MFD bindings, see:
9+
Documentation/devicetree/bindings/mfd/mt6397.txt
10+
11+
For MediaTek PMIC wrapper bus bindings, see:
12+
Documentation/devicetree/bindings/soc/mediatek/pwrap.txt
13+
14+
Required properties:
15+
- compatible: Should be one of follows
16+
"mediatek,mt6323-rtc": for MT6323 PMIC
17+
"mediatek,mt6397-rtc": for MT6397 PMIC
18+
19+
Example:
20+
21+
pmic {
22+
compatible = "mediatek,mt6323";
23+
24+
...
25+
26+
rtc {
27+
compatible = "mediatek,mt6323-rtc";
28+
};
29+
};

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9227,6 +9227,13 @@ S: Maintained
92279227
F: drivers/net/dsa/mt7530.*
92289228
F: net/dsa/tag_mtk.c
92299229

9230+
MEDIATEK BOARD LEVEL SHUTDOWN DRIVERS
9231+
M: Sean Wang <sean.wang@mediatek.com>
9232+
L: linux-pm@vger.kernel.org
9233+
S: Maintained
9234+
F: Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
9235+
F: drivers/power/reset/mt6323-poweroff.c
9236+
92309237
MEDIATEK JPEG DRIVER
92319238
M: Rick Chang <rick.chang@mediatek.com>
92329239
M: Bin Liu <bin.liu@mediatek.com>

arch/arm/boot/dts/mt6323.dtsi

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,24 @@
1818
compatible = "mediatek,mt6323-led";
1919
#address-cells = <1>;
2020
#size-cells = <0>;
21-
status = "disabled";
21+
22+
led@0 {
23+
reg = <0>;
24+
label = "bpi-r2:isink:green";
25+
default-state = "off";
26+
};
27+
28+
led@1 {
29+
reg = <1>;
30+
label = "bpi-r2:isink:red";
31+
default-state = "off";
32+
};
33+
34+
led@2 {
35+
reg = <2>;
36+
label = "bpi-r2:isink:blue";
37+
default-state = "off";
38+
};
2239
};
2340

2441
mt6323regulator: mt6323regulator{
@@ -238,5 +255,32 @@
238255
regulator-enable-ramp-delay = <216>;
239256
};
240257
};
258+
259+
mt6323keys: mt6323keys {
260+
compatible = "mediatek,mt6323-keys";
261+
mediatek,long-press-mode = <1>;
262+
power-off-time-sec = <0>;
263+
264+
power {
265+
linux,keycodes = <116>;
266+
wakeup-source;
267+
};
268+
269+
home {
270+
linux,keycodes = <114>;
271+
};
272+
};
273+
274+
codec: mt6397codec {
275+
compatible = "mediatek,mt6397-codec";
276+
};
277+
278+
power-controller {
279+
compatible = "mediatek,mt6323-pwrc";
280+
};
281+
282+
rtc {
283+
compatible = "mediatek,mt6323-rtc";
284+
};
241285
};
242286
};

arch/arm/configs/mt7623n_evb_fwu_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ CONFIG_I2C_CHARDEV=m
424424
CONFIG_RTC_CLASS=y
425425
CONFIG_RTC_DRV_DS1307=m
426426
CONFIG_RTC_DRV_DS1307_CENTURY=y
427-
CONFIG_RTC_DRV_MT6397=m
427+
CONFIG_RTC_DRV_MT6397=y
428428

429429
CONFIG_SPI=y
430430
CONFIG_SPI_MASTER=y

drivers/mfd/mt6397-core.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014 MediaTek Inc.
2+
* Copyright (c) 2014-2018 MediaTek Inc.
33
* Author: Flora Fu, MediaTek
44
*
55
* This program is free software; you can redistribute it and/or modify
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include <linux/interrupt.h>
16+
#include <linux/ioport.h>
1617
#include <linux/module.h>
1718
#include <linux/of_device.h>
1819
#include <linux/of_irq.h>
@@ -23,24 +24,27 @@
2324
#include <linux/mfd/mt6397/registers.h>
2425
#include <linux/mfd/mt6323/registers.h>
2526

27+
#define MT6323_RTC_BASE 0x8000
28+
#define MT6323_RTC_SIZE 0x40
29+
2630
#define MT6397_RTC_BASE 0xe000
2731
#define MT6397_RTC_SIZE 0x3e
2832

33+
#define MT6323_PWRC_BASE 0x8000
34+
#define MT6323_PWRC_SIZE 0x40
35+
2936
#define MT6323_CID_CODE 0x23
3037
#define MT6391_CID_CODE 0x91
3138
#define MT6397_CID_CODE 0x97
3239

40+
static const struct resource mt6323_rtc_resources[] = {
41+
DEFINE_RES_MEM(MT6323_RTC_BASE, MT6323_RTC_SIZE),
42+
DEFINE_RES_IRQ(MT6323_IRQ_STATUS_RTC),
43+
};
44+
3345
static const struct resource mt6397_rtc_resources[] = {
34-
{
35-
.start = MT6397_RTC_BASE,
36-
.end = MT6397_RTC_BASE + MT6397_RTC_SIZE,
37-
.flags = IORESOURCE_MEM,
38-
},
39-
{
40-
.start = MT6397_IRQ_RTC,
41-
.end = MT6397_IRQ_RTC,
42-
.flags = IORESOURCE_IRQ,
43-
},
46+
DEFINE_RES_MEM(MT6397_RTC_BASE, MT6397_RTC_SIZE),
47+
DEFINE_RES_IRQ(MT6397_IRQ_RTC),
4448
};
4549

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

60+
static const struct resource mt6323_pwrc_resources[] = {
61+
DEFINE_RES_MEM(MT6323_PWRC_BASE, MT6323_PWRC_SIZE),
62+
};
63+
5664
static const struct mfd_cell mt6323_devs[] = {
5765
{
66+
.name = "mt6323-rtc",
67+
.num_resources = ARRAY_SIZE(mt6323_rtc_resources),
68+
.resources = mt6323_rtc_resources,
69+
.of_compatible = "mediatek,mt6323-rtc",
70+
}, {
5871
.name = "mt6323-regulator",
5972
.of_compatible = "mediatek,mt6323-regulator"
6073
}, {
@@ -65,6 +78,11 @@ static const struct mfd_cell mt6323_devs[] = {
6578
.num_resources = ARRAY_SIZE(mt6323_keys_resources),
6679
.resources = mt6323_keys_resources,
6780
.of_compatible = "mediatek,mt6323-keys"
81+
}, {
82+
.name = "mt6323-pwrc",
83+
.num_resources = ARRAY_SIZE(mt6323_pwrc_resources),
84+
.resources = mt6323_pwrc_resources,
85+
.of_compatible = "mediatek,mt6323-pwrc"
6886
},
6987
};
7088

drivers/power/reset/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ config POWER_RESET_LTC2952
139139
This driver supports an external powerdown trigger and board power
140140
down via the LTC2952. Bindings are made in the device tree.
141141

142+
config POWER_RESET_MT6323
143+
bool "MediaTek MT6323 power-off driver"
144+
depends on MFD_MT6397
145+
help
146+
The power-off driver is responsible for externally shutdown down
147+
the power of a remote MediaTek SoC MT6323 is connected to through
148+
controlling a tiny circuit BBPU inside MT6323 RTC.
149+
150+
Say Y if you have a board where MT6323 could be found.
151+
142152
config POWER_RESET_QNAP
143153
bool "QNAP power-off driver"
144154
depends on OF_GPIO && PLAT_ORION

drivers/power/reset/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
1111
obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
1212
obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
1313
obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
14+
obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
1415
obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
1516
obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o
1617
obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Power off through MediaTek PMIC
4+
*
5+
* Copyright (C) 2018 MediaTek Inc.
6+
*
7+
* Author: Sean Wang <sean.wang@mediatek.com>
8+
*
9+
*/
10+
11+
#include <linux/err.h>
12+
#include <linux/module.h>
13+
#include <linux/of.h>
14+
#include <linux/platform_device.h>
15+
#include <linux/mfd/mt6397/core.h>
16+
#include <linux/mfd/mt6397/rtc.h>
17+
18+
struct mt6323_pwrc {
19+
struct device *dev;
20+
struct regmap *regmap;
21+
u32 base;
22+
};
23+
24+
static struct mt6323_pwrc *mt_pwrc;
25+
26+
static void mt6323_do_pwroff(void)
27+
{
28+
struct mt6323_pwrc *pwrc = mt_pwrc;
29+
unsigned int val;
30+
int ret;
31+
32+
regmap_write(pwrc->regmap, pwrc->base + RTC_BBPU, RTC_BBPU_KEY);
33+
regmap_write(pwrc->regmap, pwrc->base + RTC_WRTGR, 1);
34+
35+
ret = regmap_read_poll_timeout(pwrc->regmap,
36+
pwrc->base + RTC_BBPU, val,
37+
!(val & RTC_BBPU_CBUSY),
38+
MTK_RTC_POLL_DELAY_US,
39+
MTK_RTC_POLL_TIMEOUT);
40+
if (ret)
41+
dev_err(pwrc->dev, "failed to write BBPU: %d\n", ret);
42+
43+
/* Wait some time until system down, otherwise, notice with a warn */
44+
mdelay(1000);
45+
46+
WARN_ONCE(1, "Unable to power off system\n");
47+
}
48+
49+
static int mt6323_pwrc_probe(struct platform_device *pdev)
50+
{
51+
struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev->dev.parent);
52+
struct mt6323_pwrc *pwrc;
53+
struct resource *res;
54+
55+
pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
56+
if (!pwrc)
57+
return -ENOMEM;
58+
59+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
60+
pwrc->base = res->start;
61+
pwrc->regmap = mt6397_chip->regmap;
62+
pwrc->dev = &pdev->dev;
63+
mt_pwrc = pwrc;
64+
65+
pm_power_off = &mt6323_do_pwroff;
66+
67+
return 0;
68+
}
69+
70+
static int mt6323_pwrc_remove(struct platform_device *pdev)
71+
{
72+
if (pm_power_off == &mt6323_do_pwroff)
73+
pm_power_off = NULL;
74+
75+
return 0;
76+
}
77+
78+
static const struct of_device_id mt6323_pwrc_dt_match[] = {
79+
{ .compatible = "mediatek,mt6323-pwrc" },
80+
{},
81+
};
82+
MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match);
83+
84+
static struct platform_driver mt6323_pwrc_driver = {
85+
.probe = mt6323_pwrc_probe,
86+
.remove = mt6323_pwrc_remove,
87+
.driver = {
88+
.name = "mt6323-pwrc",
89+
.of_match_table = mt6323_pwrc_dt_match,
90+
},
91+
};
92+
93+
module_platform_driver(mt6323_pwrc_driver);
94+
95+
MODULE_DESCRIPTION("Poweroff driver for MT6323 PMIC");
96+
MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
97+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)