Skip to contentSkip to conversation

Add support to MT6323 RTC and its power device

PATCH In review [email protected] 3 participants 23 messages Apr 25, 2018 – May 8, 2018

Subsystems (7)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v2 cover Add support to MT6323 RTC and its power device

From: Sean Wang <[email protected]>

v2:

- The changes must be relative to the below tree since one critial patch for the rtc-mt6397.c the series depends on was being applied into the tree. Otherwise, for example, if the series are applied on the top of [1], a build error must happen due to an implicit declaration of function 'irq_create_mapping' as kbuild test robot was reporting in [2].

tree : https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git
branch : mfd/ib-mfd-input-rtc-4.18

- changes since v1:
* Define the power controller as a function of MT6323 MFD.
* Refine the whole series commit message and title.
* Add tag Reviewed-by and Acked-by got from v1 result.
* Reuse use the DEFINE_RES_* helpers in mfd driver.
* Remove an overdone patch rtc: mediatek: remove unnecessary parentheses.
* Use devm_rtc_allocate_device() and rtc_register_device instead of devm_rtc_device_register.
* Have an improvement according to the license rule the SPDX notation for C header file.
* Move a file from include/linux/rtc/mt6397.h to include/linux/mfd/mt6397/rtc.h
* Refine include/linux/mfd/mt6397/rtc.h

[1] https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git
[2] http://lists.infradead.org/pipermail/linux-mediatek/2018-March/012548.html

v1:

Hi,

The series keeps to extend the capability of BPI-R2 board with MT7623 and the result can as well bring benefits into the other MediaTek PMICs such as MT6397 or SoCs.

The series sent across mfd, rtc, pm, dt-binding sub-system is for hoping to let people have a simple cross-reference to know the exact dependency and why those patches are being split in that way between each one.

Patch 1-3: Add dt-binding to the related devices newly or already
supported.
Patch 4-5: Extend driver with the functionality of MT6323 RTC device. Patch 6-9 and 12-13: Add a few of trivial fixups, cleanups and
improvements.
Patch 10-11: It's a preparation for Patch 14 adding a new driver. Patch 14: Add a new driver for a power-off driver.
Patch 15-16: Update MAINTAINERS with these new files being added.

Sean

Sean Wang (17):
dt-bindings: power: reset: mt6323: add bindings for MT6323 power
controller
dt-bindings: rtc: mt6397: add bindings for MediaTek PMIC based RTC
dt-bindings: mfd: mt6397: add a description for MT6323 RTC
dt-bindings: mfd: mt6397: add a description for MT6323 power
controller
mfd: mt6397: add MT6323 RTC support into MT6397 driver
mfd: mt6397: add support for MT6323 power controller into MT6397
driver
mfd: mt6397: reuse DEFINE_RES_* helpers
rtc: mt6397: add MT6323 support to RTC driver
rtc: mt6397: replace a poll with regmap_read_poll_timeout
rtc: mt6397: remove unnecessary irq_dispose_mapping
rtc: mt6397: convert to use device managed functions
rtc: mt6397: move the declaration into a globally visible header file
rtc: mt6397: cleanup header files to include
rtc: mt6397: update license converting to using SPDX identifiers
power: reset: mt6323: add a driver for MT6323 power controller
MAINTAINERS: update entry for ARM/Mediatek RTC DRIVER
MAINTAINERS: add an entry for MediaTek board level shutdown driver

 Documentation/devicetree/bindings/mfd/mt6397.txt   |  10 +-
 .../bindings/power/reset/mt6323-poweroff.txt       |  20 +++
 .../devicetree/bindings/rtc/rtc-mt6397.txt         |  29 ++++
 MAINTAINERS                                        |   9 ++
 drivers/mfd/mt6397-core.c                          |  40 ++++--
 drivers/power/reset/Kconfig                        |  10 ++
 drivers/power/reset/Makefile                       |   1 +
 drivers/power/reset/mt6323-poweroff.c              |  97 ++++++++++++++
 drivers/rtc/rtc-mt6397.c                           | 146 +++++----------------
 include/linux/mfd/mt6397/rtc.h                     |  71 ++++++++++
 10 files changed, 308 insertions(+), 125 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
 create mode 100644 drivers/power/reset/mt6323-poweroff.c
 create mode 100644 include/linux/mfd/mt6397/rtc.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v2 1/17 dt-bindings: power: reset: mt6323: add bindings for MT6323 power controller

From: Sean Wang <[email protected]>

Adding device-tree binding for the power controller which is a tiny circuit block present as a part of MT6323 PMIC and is responsible for externally powering off or on a remote SoC the PMIC is connected to.

Cc devicetree at vger.kernel.org
---
 .../bindings/power/reset/mt6323-poweroff.txt         | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +20 -0
new file mode 100644
index 0000000..6f7c590
@@ -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";
+		};
+	}
Signature · 1 line
2.7.4
author maintainer
#4 lore raw

PATCH v2 2/17 dt-bindings: rtc: mt6397: add bindings for MediaTek PMIC based RTC

In reply to [email protected]

From: Sean Wang <[email protected]>

Add device-tree binding for MediaTek PMIC based RTC

Cc devicetree at vger.kernel.org
---
 .../devicetree/bindings/rtc/rtc-mt6397.txt         | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
Documentation/devicetree/bindings/rtc/rtc-mt6397.txt new file +29 -0
new file mode 100644
index 0000000..6e97248
@@ -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";
+		};
+	};
Signature · 1 line
2.7.4
author maintainer
#6 lore raw

PATCH v2 3/17 dt-bindings: mfd: mt6397: add a description for MT6323 RTC

In reply to [email protected]

From: Sean Wang <[email protected]>

Add a description for MT6323 RTC and link it to the detailed binding documentation.

Cc devicetree at vger.kernel.org
---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mfd/mt6397.txt +3 -1
index d1df77f..11a748d 100644
@@ -22,8 +22,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"
Signature · 1 line
2.7.4
author maintainer
#7 lore raw

PATCH v2 4/17 dt-bindings: mfd: mt6397: add a description for MT6323 power controller

In reply to [email protected]

From: Sean Wang <[email protected]>

Add a description for MT6323 power controller on MT6323 and link it to the detailed binding documentation.

Cc devicetree at vger.kernel.org
---
 Documentation/devicetree/bindings/mfd/mt6397.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/mfd/mt6397.txt +6 -0
index 11a748d..61115ea 100644
@@ -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.
@@ -48,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 at 1000f000 {
 		compatible = "mediatek,mt8135-pwrap";
Signature · 1 line
2.7.4
author maintainer
#8 lore raw

PATCH v2 5/17 mfd: mt6397: add MT6323 RTC support into MT6397 driver

In reply to [email protected]

From: Sean Wang <[email protected]>

Add compatible string as "mt6323-rtc" that will make the OF core spawn child devices for the RTC subnode of that MT6323 MFD device.

---
 drivers/mfd/mt6397-core.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/mfd/mt6397-core.c +15 -1
index 77b64bd..c70d5b2 100644
@@ -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
@@ -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>
@@ -23,6 +24,9 @@
 #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
 
@@ -30,6 +34,11 @@
 #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,
@@ -55,6 +64,11 @@ static const struct resource mt6397_keys_resources[] = {
 
 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"
 	}, {
Signature · 1 line
2.7.4
author maintainer
#9 lore raw

PATCH v2 6/17 mfd: mt6397: add support for MT6323 power controller into MT6397 driver

In reply to [email protected]

From: Sean Wang <[email protected]>

Add compatible string as "mt6323-pwrc" that will make the OF core spawn child devices for the power-controller subnode of that MT6323 MFD device.

---
 drivers/mfd/mt6397-core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/mfd/mt6397-core.c +12 -0
index c70d5b2..c4ad5c3 100644
@@ -30,6 +30,9 @@
 #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
@@ -62,6 +65,10 @@ 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",
@@ -79,6 +86,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"
 	},
 };
 
Signature · 1 line
2.7.4
author maintainer
#10 lore raw

PATCH v2 7/17 mfd: mt6397: reuse DEFINE_RES_* helpers

In reply to [email protected]

From: Sean Wang <[email protected]>

Reuse DEFINE_RES_* helpers instead of an open-coded handling.

---
 drivers/mfd/mt6397-core.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/mfd/mt6397-core.c +2 -10
index c4ad5c3..e0012e2 100644
@@ -43,16 +43,8 @@ static const struct resource mt6323_rtc_resources[] = {
 };
 
 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[] = {
Signature · 1 line
2.7.4
author maintainer
#11 lore raw

PATCH v2 8/17 rtc: mt6397: add MT6323 support to RTC driver

In reply to [email protected]

From: Sean Wang <[email protected]>

Just to add MT6323 support to existing RTC driver

---
 drivers/rtc/rtc-mt6397.c | 1 +
 1 file changed, 1 insertion(+)
drivers/rtc/rtc-mt6397.c +1 -0
index 385f830..0df7ccd 100644
@@ -398,6 +398,7 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend,
 			mt6397_rtc_resume);
 
 static const struct of_device_id mt6397_rtc_of_match[] = {
+	{ .compatible = "mediatek,mt6323-rtc", },
 	{ .compatible = "mediatek,mt6397-rtc", },
 	{ }
 };
Signature · 1 line
2.7.4
author maintainer
#12 lore raw

PATCH v2 9/17 rtc: mt6397: replace a poll with regmap_read_poll_timeout

In reply to [email protected]

From: Sean Wang <[email protected]>

Reuse the helper regmap_read_poll_timeout instead of an open-coding handling to simpify the logic.

Furthermore, the time for a wait in each iteration changed from cpu_relax to 20us is for matching the usage of the helper, but it wouldn't acctually break any the existent functionality according to a good test on MT6323 PMIC.

---
 drivers/rtc/rtc-mt6397.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/rtc/rtc-mt6397.c +11 -14
index 0df7ccd..efb9370 100644
@@ -18,6 +18,7 @@
 #include <linux/regmap.h>
 #include <linux/rtc.h>
 #include <linux/irqdomain.h>
+#include <linux/jiffies.h>
 #include <linux/platform_device.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
@@ -63,6 +64,9 @@
 #define RTC_NUM_YEARS		128
 #define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
 
+#define MTK_RTC_POLL_DELAY_US	10
+#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
+
 struct mt6397_rtc {
 	struct device		*dev;
 	struct rtc_device	*rtc_dev;
@@ -74,7 +78,6 @@ struct mt6397_rtc {
 
 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 {
-	unsigned long timeout = jiffies + HZ;
 	int ret;
 	u32 data;
 
@@ -82,19 +85,13 @@ static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 	if (ret < 0)
 		return ret;
 
-	while (1) {
-		ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_BBPU,
-				  &data);
-		if (ret < 0)
-			break;
-		if (!(data & RTC_BBPU_CBUSY))
-			break;
-		if (time_after(jiffies, timeout)) {
-			ret = -ETIMEDOUT;
-			break;
-		}
-		cpu_relax();
-	}
+	ret = regmap_read_poll_timeout(rtc->regmap,
+				       rtc->addr_base + RTC_BBPU, data,
+				       !(data & RTC_BBPU_CBUSY),
+				       MTK_RTC_POLL_DELAY_US,
+				       MTK_RTC_POLL_TIMEOUT);
+	if (ret < 0)
+		dev_err(rtc->dev, "failed to write WRTGE: %d\n", ret);
 
 	return ret;
 }
Signature · 1 line
2.7.4
author maintainer
#13 lore raw

PATCH v2 10/17 rtc: mt6397: remove unnecessary irq_dispose_mapping

In reply to [email protected]

From: Sean Wang <[email protected]>

With the patch [1], the job irq_create_mapping had been moved from the rtc driver to mfd core, so it should be unnecessary to keep irq_dispose_mapping in all paths of the leaf driver.

[1] http://lists.infradead.org/pipermail/linux-mediatek/2017-September/010455.html

---
 drivers/rtc/rtc-mt6397.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/rtc/rtc-mt6397.c +2 -5
index efb9370..398bae5 100644
@@ -17,7 +17,6 @@
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
-#include <linux/irqdomain.h>
 #include <linux/jiffies.h>
 #include <linux/platform_device.h>
 #include <linux/of_address.h>
@@ -336,7 +335,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
 			rtc->irq, ret);
-		goto out_dispose_irq;
+		return ret;
 	}
 
 	device_init_wakeup(&pdev->dev, 1);
@@ -353,8 +352,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 
 out_free_irq:
 	free_irq(rtc->irq, rtc->rtc_dev);
-out_dispose_irq:
-	irq_dispose_mapping(rtc->irq);
+
 	return ret;
 }
 
@@ -364,7 +362,6 @@ static int mtk_rtc_remove(struct platform_device *pdev)
 
 	rtc_device_unregister(rtc->rtc_dev);
 	free_irq(rtc->irq, rtc->rtc_dev);
-	irq_dispose_mapping(rtc->irq);
 
 	return 0;
 }
Signature · 1 line
2.7.4
author maintainer
#14 lore raw

PATCH v2 11/17 rtc: mt6397: convert to use device managed functions

In reply to [email protected]

From: Sean Wang <[email protected]>

Use device managed operation to simplify error handling, reduce source code size, and reduce the likelyhood of bugs, and remove our removal callback which contains anything already done by device managed functions.

v1 -> v2:
- Use devm_rtc_allocate_device() and rtc_register_device instead of devm_rtc_device_register.

---
 drivers/rtc/rtc-mt6397.c | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)
drivers/rtc/rtc-mt6397.c +10 -27
index 398bae5..91d584a 100644
@@ -14,6 +14,7 @@
 
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
@@ -328,10 +329,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, rtc);
 
-	ret = request_threaded_irq(rtc->irq, NULL,
-				   mtk_rtc_irq_handler_thread,
-				   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
-				   "mt6397-rtc", rtc);
+	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
+					mtk_rtc_irq_handler_thread,
+					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
+					"mt6397-rtc", rtc);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
 			rtc->irq, ret);
@@ -340,30 +341,13 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 1);
 
-	rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev,
-					   &mtk_rtc_ops, THIS_MODULE);
-	if (IS_ERR(rtc->rtc_dev)) {
-		dev_err(&pdev->dev, "register rtc device failed\n");
-		ret = PTR_ERR(rtc->rtc_dev);
-		goto out_free_irq;
-	}
-
-	return 0;
-
-out_free_irq:
-	free_irq(rtc->irq, rtc->rtc_dev);
-
-	return ret;
-}
+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
 
-static int mtk_rtc_remove(struct platform_device *pdev)
-{
-	struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
+	rtc->rtc_dev->ops = &mtk_rtc_ops;
 
-	rtc_device_unregister(rtc->rtc_dev);
-	free_irq(rtc->irq, rtc->rtc_dev);
-
-	return 0;
+	return rtc_register_device(rtc->rtc_dev);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -405,7 +389,6 @@ static struct platform_driver mtk_rtc_driver = {
 		.pm = &mt6397_pm_ops,
 	},
 	.probe	= mtk_rtc_probe,
-	.remove = mtk_rtc_remove,
 };
 
 module_platform_driver(mtk_rtc_driver);
Signature · 1 line
2.7.4
author maintainer
#15 lore raw

PATCH v2 12/17 rtc: mt6397: move the declaration into a globally visible header file

In reply to [email protected]

From: Sean Wang <[email protected]>

This is in preparation for allowing other drivers can share the declaration, so move the declaration into a globally visible header file.

---
 drivers/rtc/rtc-mt6397.c       | 53 +-------------------------------
 include/linux/mfd/mt6397/rtc.h | 70 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 52 deletions(-)
 create mode 100644 include/linux/mfd/mt6397/rtc.h
drivers/rtc/rtc-mt6397.c +1 -52
index 91d584a..4c5cdaa 100644
@@ -18,63 +18,12 @@
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
-#include <linux/jiffies.h>
 #include <linux/platform_device.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/io.h>
 #include <linux/mfd/mt6397/core.h>
-
-#define RTC_BBPU		0x0000
-#define RTC_BBPU_CBUSY		BIT(6)
-
-#define RTC_WRTGR		0x003c
-
-#define RTC_IRQ_STA		0x0002
-#define RTC_IRQ_STA_AL		BIT(0)
-#define RTC_IRQ_STA_LP		BIT(3)
-
-#define RTC_IRQ_EN		0x0004
-#define RTC_IRQ_EN_AL		BIT(0)
-#define RTC_IRQ_EN_ONESHOT	BIT(2)
-#define RTC_IRQ_EN_LP		BIT(3)
-#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
-
-#define RTC_AL_MASK		0x0008
-#define RTC_AL_MASK_DOW		BIT(4)
-
-#define RTC_TC_SEC		0x000a
-/* Min, Hour, Dom... register offset to RTC_TC_SEC */
-#define RTC_OFFSET_SEC		0
-#define RTC_OFFSET_MIN		1
-#define RTC_OFFSET_HOUR		2
-#define RTC_OFFSET_DOM		3
-#define RTC_OFFSET_DOW		4
-#define RTC_OFFSET_MTH		5
-#define RTC_OFFSET_YEAR		6
-#define RTC_OFFSET_COUNT	7
-
-#define RTC_AL_SEC		0x0018
-
-#define RTC_PDN2		0x002e
-#define RTC_PDN2_PWRON_ALARM	BIT(4)
-
-#define RTC_MIN_YEAR		1968
-#define RTC_BASE_YEAR		1900
-#define RTC_NUM_YEARS		128
-#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
-
-#define MTK_RTC_POLL_DELAY_US	10
-#define MTK_RTC_POLL_TIMEOUT	(jiffies_to_usecs(HZ))
-
-struct mt6397_rtc {
-	struct device		*dev;
-	struct rtc_device	*rtc_dev;
-	struct mutex		lock;
-	struct regmap		*regmap;
-	int			irq;
-	u32			addr_base;
-};
+#include <linux/mfd/mt6397/rtc.h>
 
 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 {
include/linux/mfd/mt6397/rtc.h new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#16 lore raw

PATCH v2 13/17 rtc: mt6397: cleanup header files to include

In reply to [email protected]

From: Sean Wang <[email protected]>

Clean up those included header files by removing unreferenced ones, add missing ones the driver explicitly depends on and finally list all #includes in alphabetical order.

---
 drivers/rtc/rtc-mt6397.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/rtc/rtc-mt6397.c +4 -7
index 4c5cdaa..3672d622 100644
@@ -12,17 +12,14 @@
 * GNU General Public License for more details.
 */
 
-#include <linux/delay.h>
-#include <linux/init.h>
+#include <linux/err.h>
 #include <linux/interrupt.h>
+#include <linux/mfd/mt6397/core.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
-#include <linux/platform_device.h>
-#include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/io.h>
-#include <linux/mfd/mt6397/core.h>
 #include <linux/mfd/mt6397/rtc.h>
 
 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
Signature · 1 line
2.7.4
author maintainer
#17 lore raw

PATCH v2 14/17 rtc: mt6397: update license converting to using SPDX identifiers

In reply to [email protected]

From: Sean Wang <[email protected]>

update the license and convert to using SPDX identifiers

---
 drivers/rtc/rtc-mt6397.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/rtc/rtc-mt6397.c +8 -12
index 3672d622..1ebeaaf 100644
@@ -1,16 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) 2014-2015 MediaTek Inc.
-* Author: Tianping.Fang <[email protected]>
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License version 2 as
-* published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*/
+ * MediaTek PMIC RTC driver
+ *
+ * Copyright (C) 2014-2018 MediaTek Inc.
+ *
+ * Author: Tianping.Fang <[email protected]>
+ *	   Sean Wang <[email protected]>
+ */
 
 #include <linux/err.h>
 #include <linux/interrupt.h>
Signature · 1 line
2.7.4
author maintainer
#18 lore raw

PATCH v2 15/17 power: reset: mt6323: add a driver for MT6323 power controller

In reply to [email protected]

From: Sean Wang <[email protected]>

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 than to be a part of existent RTC driver so as to let us make concentration on works about power-controlling topic and to obtain improvements while the subsystem power/reset 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.

---
 drivers/power/reset/Kconfig           | 10 ++++
 drivers/power/reset/Makefile          |  1 +
 drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/mt6397/rtc.h        |  1 +
 4 files changed, 109 insertions(+)
 create mode 100644 drivers/power/reset/mt6323-poweroff.c
drivers/power/reset/Kconfig +10 -0
index df58fc8..7b49d71 100644
@@ -128,6 +128,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
drivers/power/reset/Makefile +1 -0
index 7778c74..8836172 100644
@@ -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_OCELOT_RESET) += ocelot-reset.o
 obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
 obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
drivers/power/reset/mt6323-poweroff.c new file +97 -0

97 lines not on this page · raw message

include/linux/mfd/mt6397/rtc.h +1 -0
index 480977c..ac932c9 100644
@@ -16,6 +16,7 @@
 
 #define RTC_BBPU		0x0000
 #define RTC_BBPU_CBUSY		BIT(6)
+#define RTC_BBPU_KEY            (0x43 << 8)
 
 #define RTC_WRTGR		0x003c
 
Signature · 1 line
2.7.4
author maintainer
#21 lore raw

PATCH v2 16/17 MAINTAINERS: update entry for ARM/Mediatek RTC DRIVER

In reply to [email protected]

From: Sean Wang <[email protected]>

Add new files for new dt-bindings and a globally visible header file.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 0a1410d..a7ef37f 100644
@@ -1607,9 +1607,11 @@ M:	Sean Wang <[email protected]>
 L:	linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
 L:	linux-mediatek at lists.infradead.org (moderated for non-subscribers)
 S:	Maintained
+F:	Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
 F:	Documentation/devicetree/bindings/rtc/rtc-mt7622.txt
 F:	drivers/rtc/rtc-mt6397.c
 F:	drivers/rtc/rtc-mt7622.c
+F:	include/linux/mfd/mt6397/rtc.h
 
 ARM/Mediatek SoC support
 M:	Matthias Brugger <[email protected]>
Signature · 1 line
2.7.4
author maintainer
#22 lore raw

PATCH v2 17/17 MAINTAINERS: add an entry for MediaTek board level shutdown driver

In reply to [email protected]

From: Sean Wang <[email protected]>

Add an entry for the MediaTek board level shutdown driver.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index a7ef37f..816554b 100644
@@ -8912,6 +8912,13 @@ S:	Maintained
 F:	drivers/net/dsa/mt7530.*
 F:	net/dsa/tag_mtk.c
 
+MEDIATEK BOARD LEVEL SHUTDOWN DRIVERS
+M:	Sean Wang <[email protected]>
+L:	linux-pm at 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 <[email protected]>
 M:	Bin Liu <[email protected]>
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v2 01/17] dt-bindings: power: reset: mt6323: add bindings for MT6323 power controller

In reply to [email protected]
Quoted 27 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

Adding device-tree binding for the power controller which is a tiny circuit block present as a part of MT6323 PMIC and is responsible for externally powering off or on a remote SoC the PMIC is connected to.

Cc devicetree at vger.kernel.org
---
 .../bindings/power/reset/mt6323-poweroff.txt         | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +8 -0
new file mode 100644
index 0000000..6f7c590
@@ -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

Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt line 18

Quoted 10 lines
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +10 -0
+
+Example:
+
+	pmic {
+		compatible = "mediatek,mt6323";
+
+		...
+
+		power-controller {
+			compatible = "mediatek,mt6323-pwrc";

Why do you need this in DT? It doesn't define any resources. The parent can just as well register a reset or poweroff handler.

Rob

Quoted 5 lines
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +2 -0
+		};
+	}
Signature · 1 line
2.7.4
author maintainer
#3 lore raw

Re: [PATCH v2 01/17] dt-bindings: power: reset: mt6323: add bindings for MT6323 power controller

Quoted 42 lines · Rob Herring
Quoted 27 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

Adding device-tree binding for the power controller which is a tiny circuit block present as a part of MT6323 PMIC and is responsible for externally powering off or on a remote SoC the PMIC is connected to.

Cc devicetree at vger.kernel.org
---
 .../bindings/power/reset/mt6323-poweroff.txt         | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +8 -0
new file mode 100644
index 0000000..6f7c590
@@ -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

Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt line 18

Quoted 10 lines
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +10 -0
+
+Example:
+
+	pmic {
+		compatible = "mediatek,mt6323";
+
+		...
+
+		power-controller {
+			compatible = "mediatek,mt6323-pwrc";

Why do you need this in DT? It doesn't define any resources. The parent can just as well register a reset or poweroff handler.

Quoted 2 lines

Rob

Yes, those binding can be removed.

I tend to use platform_device_register_data embedded in mfd driver to probe the existent poweroff driver in the next version.

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt new file +2 -0
+		};
+	}
Signature · 1 line
2.7.4
#19 lore raw

Re: [PATCH v2 15/17] power: reset: mt6323: add a driver for MT6323 power controller

In reply to [email protected]

Hi,

Quoted 9 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

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 than to be a part of existent RTC driver so as to let us make concentration on works about power-controlling topic and to obtain improvements while the subsystem power/reset constantly growing.

I don't understand the above sentence. (I'm fine with adding the driver)

Quoted 55 lines

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.

---
 drivers/power/reset/Kconfig           | 10 ++++
 drivers/power/reset/Makefile          |  1 +
 drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/mt6397/rtc.h        |  1 +
 4 files changed, 109 insertions(+)
 create mode 100644 drivers/power/reset/mt6323-poweroff.c
drivers/power/reset/Kconfig +10 -0
index df58fc8..7b49d71 100644
@@ -128,6 +128,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
drivers/power/reset/Makefile +1 -0
index 7778c74..8836172 100644
@@ -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_OCELOT_RESET) += ocelot-reset.o
 obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
 obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
drivers/power/reset/mt6323-poweroff.c new file +3 -0
new file mode 100644
index 0000000..c195766
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Power off through MediaTek PMIC

drivers/power/reset/mt6323-poweroff.c line 13

Quoted 10 lines
drivers/power/reset/mt6323-poweroff.c new file +10 -0
+ *
+ * Copyright (C) 2018 MediaTek Inc.
+ *
+ * Author: Sean Wang <[email protected]>
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/of.h>

Not needed

Quoted 59 lines
drivers/power/reset/mt6323-poweroff.c new file +59 -0
+#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)

drivers/power/reset/mt6323-poweroff.c line 82

Quoted 10 lines
drivers/power/reset/mt6323-poweroff.c new file +10 -0
+		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);

Don't forget to remove the DT table when you respin the series for the requested binding changes.

Quoted 19 lines
drivers/power/reset/mt6323-poweroff.c new file +14 -0
+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 <[email protected]>");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/mt6397/rtc.h +0 -0
index 480977c..ac932c9 100644

include/linux/mfd/mt6397/rtc.h line 21

Quoted 6 lines
include/linux/mfd/mt6397/rtc.h +1 -0
@@ -16,6 +16,7 @@
 
 #define RTC_BBPU		0x0000
 #define RTC_BBPU_CBUSY		BIT(6)
+#define RTC_BBPU_KEY            (0x43 << 8)
 
 #define RTC_WRTGR		0x003c

The driver looks fine otherwise.

-- Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180501/4f8022fa/attachment.sig>

author maintainer
#20 lore raw

Re: Re: [PATCH v2 15/17] power: reset: mt6323: add a driver for MT6323 power controller

Quoted 8 lines · Sebastian Reichel

Hi,

Quoted 5 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

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.

Quoted 7 lines
Quoted 4 lines

Though it's a part of RTC device, it would be better to be a standalone driver than to be a part of existent RTC driver so as to let us make concentration on works about power-controlling topic and to obtain improvements while the subsystem power/reset constantly growing.

I don't understand the above sentence. (I'm fine with adding the driver)

Which I was actually meaning is that taking the poweroff driver as the standalone one and placing it under driver/reset/power seems can simply get a help from its subsystem either for function extension or bugfix in the future. I thought that way is better than just an embedded one somewhere in rtc driver or other drivers.

Quoted 59 lines
Quoted 59 lines

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.

---
 drivers/power/reset/Kconfig           | 10 ++++
 drivers/power/reset/Makefile          |  1 +
 drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/mt6397/rtc.h        |  1 +
 4 files changed, 109 insertions(+)
 create mode 100644 drivers/power/reset/mt6323-poweroff.c
drivers/power/reset/Kconfig +10 -0
index df58fc8..7b49d71 100644
@@ -128,6 +128,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
drivers/power/reset/Makefile +1 -0
index 7778c74..8836172 100644
@@ -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_OCELOT_RESET) += ocelot-reset.o
 obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
 obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
drivers/power/reset/mt6323-poweroff.c new file +7 -0
new file mode 100644
index 0000000..c195766
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Power off through MediaTek PMIC
+ *
+ * Copyright (C) 2018 MediaTek Inc.
+ *
+ * Author: Sean Wang <[email protected]>
Quoted 8 lines

drivers/power/reset/mt6323-poweroff.c line 13

Quoted 6 lines
drivers/power/reset/mt6323-poweroff.c new file +6 -0
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/of.h>

Not needed

Will be removed.

Quoted 65 lines
Quoted 65 lines
drivers/power/reset/mt6323-poweroff.c new file +64 -0
+#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;
+}
+
Quoted 9 lines

drivers/power/reset/mt6323-poweroff.c line 82

Quoted 5 lines
drivers/power/reset/mt6323-poweroff.c new file +5 -0
+static const struct of_device_id mt6323_pwrc_dt_match[] = {
+	{ .compatible = "mediatek,mt6323-pwrc" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match);

Don't forget to remove the DT table when you respin the series for the requested binding changes.

Thanks. This table will be removed in the next version.

Quoted 20 lines
Quoted 20 lines
drivers/power/reset/mt6323-poweroff.c new file +14 -0
+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 <[email protected]>");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/mt6397/rtc.h +0 -0
index 480977c..ac932c9 100644
@@ -16,6 +16,7 @@
 
Quoted 8 lines

include/linux/mfd/mt6397/rtc.h line 21

Quoted 5 lines
include/linux/mfd/mt6397/rtc.h +1 -0
 #define RTC_BBPU		0x0000
 #define RTC_BBPU_CBUSY		BIT(6)
+#define RTC_BBPU_KEY            (0x43 << 8)
 
 #define RTC_WRTGR		0x003c

The driver looks fine otherwise.

Thanks.

Quoted 5 lines

-- Sebastian
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

maintainer Reviewed-by on v2 2/17
#5 lore raw

Re: [PATCH v2 02/17] dt-bindings: rtc: mt6397: add bindings for MediaTek PMIC based RTC

In reply to [email protected]
Quoted 10 lines · sean.wang at mediatek.com

From: Sean Wang <[email protected]>

Add device-tree binding for MediaTek PMIC based RTC

Cc devicetree at vger.kernel.org
---
 .../devicetree/bindings/rtc/rtc-mt6397.txt         | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt