Skip to content

Commit 7c5b026

Browse files
author
Lee Jones
committed
Merge branches 'ib-mfd-doc-sparc-libdevres-5.5' and 'ib-mfd-power-rtc-5.5' into ibs-for-mfd-merged
2 parents 7b8c4d7 + 9d0863b commit 7c5b026

7 files changed

Lines changed: 236 additions & 86 deletions

File tree

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+
../mfd/mt6397.txt
10+
11+
For MediaTek PMIC wrapper bus bindings, see:
12+
../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
@@ -10266,6 +10266,13 @@ S: Maintained
1026610266
F: drivers/net/dsa/mt7530.*
1026710267
F: net/dsa/tag_mtk.c
1026810268

10269+
MEDIATEK BOARD LEVEL SHUTDOWN DRIVERS
10270+
M: Sean Wang <sean.wang@mediatek.com>
10271+
L: linux-pm@vger.kernel.org
10272+
S: Maintained
10273+
F: Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
10274+
F: drivers/power/reset/mt6323-poweroff.c
10275+
1026910276
MEDIATEK JPEG DRIVER
1027010277
M: Rick Chang <rick.chang@mediatek.com>
1027110278
M: Bin Liu <bin.liu@mediatek.com>

‎drivers/power/reset/Kconfig‎

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

143+
config POWER_RESET_MT6323
144+
bool "MediaTek MT6323 power-off driver"
145+
depends on MFD_MT6397
146+
help
147+
The power-off driver is responsible for externally shutdown down
148+
the power of a remote MediaTek SoC MT6323 is connected to through
149+
controlling a tiny circuit BBPU inside MT6323 RTC.
150+
151+
Say Y if you have a board where MT6323 could be found.
152+
143153
config POWER_RESET_QNAP
144154
bool "QNAP power-off driver"
145155
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");

‎drivers/rtc/rtc-mt6397.c‎

Lines changed: 21 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,33 @@
44
* Author: Tianping.Fang <tianping.fang@mediatek.com>
55
*/
66

7-
#include <linux/delay.h>
8-
#include <linux/init.h>
7+
#include <linux/err.h>
8+
#include <linux/interrupt.h>
9+
#include <linux/mfd/mt6397/core.h>
910
#include <linux/module.h>
11+
#include <linux/mutex.h>
12+
#include <linux/platform_device.h>
1013
#include <linux/regmap.h>
1114
#include <linux/rtc.h>
12-
#include <linux/irqdomain.h>
13-
#include <linux/platform_device.h>
14-
#include <linux/of_address.h>
15-
#include <linux/of_irq.h>
16-
#include <linux/io.h>
17-
#include <linux/mfd/mt6397/core.h>
18-
19-
#define RTC_BBPU 0x0000
20-
#define RTC_BBPU_CBUSY BIT(6)
21-
22-
#define RTC_WRTGR 0x003c
23-
24-
#define RTC_IRQ_STA 0x0002
25-
#define RTC_IRQ_STA_AL BIT(0)
26-
#define RTC_IRQ_STA_LP BIT(3)
27-
28-
#define RTC_IRQ_EN 0x0004
29-
#define RTC_IRQ_EN_AL BIT(0)
30-
#define RTC_IRQ_EN_ONESHOT BIT(2)
31-
#define RTC_IRQ_EN_LP BIT(3)
32-
#define RTC_IRQ_EN_ONESHOT_AL (RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
33-
34-
#define RTC_AL_MASK 0x0008
35-
#define RTC_AL_MASK_DOW BIT(4)
36-
37-
#define RTC_TC_SEC 0x000a
38-
/* Min, Hour, Dom... register offset to RTC_TC_SEC */
39-
#define RTC_OFFSET_SEC 0
40-
#define RTC_OFFSET_MIN 1
41-
#define RTC_OFFSET_HOUR 2
42-
#define RTC_OFFSET_DOM 3
43-
#define RTC_OFFSET_DOW 4
44-
#define RTC_OFFSET_MTH 5
45-
#define RTC_OFFSET_YEAR 6
46-
#define RTC_OFFSET_COUNT 7
47-
48-
#define RTC_AL_SEC 0x0018
49-
50-
#define RTC_PDN2 0x002e
51-
#define RTC_PDN2_PWRON_ALARM BIT(4)
52-
53-
#define RTC_MIN_YEAR 1968
54-
#define RTC_BASE_YEAR 1900
55-
#define RTC_NUM_YEARS 128
56-
#define RTC_MIN_YEAR_OFFSET (RTC_MIN_YEAR - RTC_BASE_YEAR)
57-
58-
struct mt6397_rtc {
59-
struct device *dev;
60-
struct rtc_device *rtc_dev;
61-
struct mutex lock;
62-
struct regmap *regmap;
63-
int irq;
64-
u32 addr_base;
65-
};
15+
#include <linux/mfd/mt6397/rtc.h>
16+
#include <linux/mod_devicetable.h>
6617

6718
static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
6819
{
69-
unsigned long timeout = jiffies + HZ;
7020
int ret;
7121
u32 data;
7222

7323
ret = regmap_write(rtc->regmap, rtc->addr_base + RTC_WRTGR, 1);
7424
if (ret < 0)
7525
return ret;
7626

77-
while (1) {
78-
ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_BBPU,
79-
&data);
80-
if (ret < 0)
81-
break;
82-
if (!(data & RTC_BBPU_CBUSY))
83-
break;
84-
if (time_after(jiffies, timeout)) {
85-
ret = -ETIMEDOUT;
86-
break;
87-
}
88-
cpu_relax();
89-
}
27+
ret = regmap_read_poll_timeout(rtc->regmap,
28+
rtc->addr_base + RTC_BBPU, data,
29+
!(data & RTC_BBPU_CBUSY),
30+
MTK_RTC_POLL_DELAY_US,
31+
MTK_RTC_POLL_TIMEOUT);
32+
if (ret < 0)
33+
dev_err(rtc->dev, "failed to write WRTGE: %d\n", ret);
9034

9135
return ret;
9236
}
@@ -319,19 +263,19 @@ static int mtk_rtc_probe(struct platform_device *pdev)
319263
return rtc->irq;
320264

321265
rtc->regmap = mt6397_chip->regmap;
322-
rtc->dev = &pdev->dev;
323266
mutex_init(&rtc->lock);
324267

325268
platform_set_drvdata(pdev, rtc);
326269

327-
rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev);
270+
rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
328271
if (IS_ERR(rtc->rtc_dev))
329272
return PTR_ERR(rtc->rtc_dev);
330273

331-
ret = request_threaded_irq(rtc->irq, NULL,
332-
mtk_rtc_irq_handler_thread,
333-
IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
334-
"mt6397-rtc", rtc);
274+
ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
275+
mtk_rtc_irq_handler_thread,
276+
IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
277+
"mt6397-rtc", rtc);
278+
335279
if (ret) {
336280
dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
337281
rtc->irq, ret);
@@ -353,15 +297,6 @@ static int mtk_rtc_probe(struct platform_device *pdev)
353297
return ret;
354298
}
355299

356-
static int mtk_rtc_remove(struct platform_device *pdev)
357-
{
358-
struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
359-
360-
free_irq(rtc->irq, rtc);
361-
362-
return 0;
363-
}
364-
365300
#ifdef CONFIG_PM_SLEEP
366301
static int mt6397_rtc_suspend(struct device *dev)
367302
{
@@ -388,6 +323,7 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend,
388323
mt6397_rtc_resume);
389324

390325
static const struct of_device_id mt6397_rtc_of_match[] = {
326+
{ .compatible = "mediatek,mt6323-rtc", },
391327
{ .compatible = "mediatek,mt6397-rtc", },
392328
{ }
393329
};
@@ -400,7 +336,6 @@ static struct platform_driver mtk_rtc_driver = {
400336
.pm = &mt6397_pm_ops,
401337
},
402338
.probe = mtk_rtc_probe,
403-
.remove = mtk_rtc_remove,
404339
};
405340

406341
module_platform_driver(mtk_rtc_driver);

0 commit comments

Comments
 (0)