linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] implement poweroff for mt6323/6397
@ 2019-07-03 16:48 Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 1/7] docs: dt-bindings: add poweroff Frank Wunderlich
                   ` (6 more replies)
  0 siblings, 7 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Frank Wunderlich

mainline-driver does not support mt6323

this series adds mt6323 to mt6397-rtc-driver and implement
power-controller on it.

with this poweroff is working on bananapi-r2

Original Patch from Josef Friedl

changes since v1:
	- splitted into functional parts
	- more infos about changes

Josef Friedl (7):
  docs: dt-bindings: add poweroff
  rtc: mt6397: move some common definitions into rtc.h
  rtc: mt6397: improvements of rtc driver
  mfd: mt6323: some improvements of mt6397-core
  power: reset: add driver for mt6323 poweroff
  MAINTAINERS: add Mediatek shutdown drivers
  arm: dts: mt6323: add keys, power-controller, rtc and codec

 .../devicetree/bindings/mfd/mt6397.txt        |  10 +-
 .../bindings/power/reset/mt6323-poweroff.txt  |  20 ++++
 .../devicetree/bindings/rtc/rtc-mt6397.txt    |  29 +++++
 MAINTAINERS                                   |   7 ++
 arch/arm/boot/dts/mt6323.dtsi                 |  27 +++++
 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                      | 110 ++++--------------
 include/linux/mfd/mt6397/core.h               |   2 +
 include/linux/mfd/mt6397/rtc.h                |  71 +++++++++++
 12 files changed, 325 insertions(+), 99 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

--
2.17.1


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 1/7] docs: dt-bindings: add poweroff
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  2019-07-04 18:54   ` Alexandre Belloni
  2019-07-03 16:48 ` [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h Frank Wunderlich
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

add documentation for pmic, rtc and power/reset devicetree bindings

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>
---
 .../devicetree/bindings/mfd/mt6397.txt        | 10 ++++++-
 .../bindings/power/reset/mt6323-poweroff.txt  | 20 +++++++++++++
 .../devicetree/bindings/rtc/rtc-mt6397.txt    | 29 +++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 0ebd08af777d..44acb9827716 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -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.
@@ -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"
@@ -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";
diff --git a/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt b/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
new file mode 100644
index 000000000000..933f0c48e887
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
@@ -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";
+               };
+       }
diff --git a/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt b/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
new file mode 100644
index 000000000000..ebd1cf80dcc8
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
@@ -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";
+               };
+       };
--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 1/7] docs: dt-bindings: add poweroff Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  2019-07-04  9:11   ` Matthias Brugger
  2019-07-03 16:48 ` [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver Frank Wunderlich
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

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>
---
 drivers/rtc/rtc-mt6397.c       | 55 +-------------------------
 include/linux/mfd/mt6397/rtc.h | 71 ++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 54 deletions(-)
 create mode 100644 include/linux/mfd/mt6397/rtc.h

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index b46ed4dc7015..c08ee5edf865 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -9,60 +9,7 @@
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
-#include <linux/irqdomain.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)
-
-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)
 {
diff --git a/include/linux/mfd/mt6397/rtc.h b/include/linux/mfd/mt6397/rtc.h
new file mode 100644
index 000000000000..b702c29e8c74
--- /dev/null
+++ b/include/linux/mfd/mt6397/rtc.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2014-2018 MediaTek Inc.
+ *
+ * Author: Tianping.Fang <tianping.fang@mediatek.com>
+ *        Sean Wang <sean.wang@mediatek.com>
+ */
+
+#ifndef _LINUX_MFD_MT6397_RTC_H_
+#define _LINUX_MFD_MT6397_RTC_H_
+
+#include <linux/jiffies.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+
+#define RTC_BBPU               0x0000
+#define RTC_BBPU_CBUSY         BIT(6)
+#define RTC_BBPU_KEY            (0x43 << 8)
+
+#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;
+
+	/* Protect register access from multiple tasks */
+	struct mutex            lock;
+	struct regmap           *regmap;
+	int                     irq;
+	u32                     addr_base;
+};
+
+#endif /* _LINUX_MFD_MT6397_RTC_H_ */
--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 1/7] docs: dt-bindings: add poweroff Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  2019-07-04  9:13   ` Matthias Brugger
  2019-07-04 20:43   ` Alexandre Belloni
  2019-07-03 16:48 ` [PATCH v2 4/7] mfd: mt6323: some improvements of mt6397-core Frank Wunderlich
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

- use regmap_read_poll_timeout to drop while-loop
- use devm-api to drop remove-callback
- add new compatible for mt6323

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
 drivers/rtc/rtc-mt6397.c | 55 ++++++++++++++++------------------------
 1 file changed, 22 insertions(+), 33 deletions(-)

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index c08ee5edf865..e5ddf0d0b6f1 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -4,16 +4,19 @@
 * Author: Tianping.Fang <tianping.fang@mediatek.com>
 */

-#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/mfd/mt6397/rtc.h>
+#include <linux/mod_devicetable.h>

 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 {
-	unsigned long timeout = jiffies + HZ;
 	int ret;
 	u32 data;

@@ -21,19 +24,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;
 }
@@ -271,14 +268,11 @@ static int mtk_rtc_probe(struct platform_device *pdev)

 	platform_set_drvdata(pdev, rtc);

-	rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev);
-	if (IS_ERR(rtc->rtc_dev))
-		return PTR_ERR(rtc->rtc_dev);
+	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
+					mtk_rtc_irq_handler_thread,
+					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
+					"mt6397-rtc", rtc);

-	ret = request_threaded_irq(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);
@@ -287,6 +281,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)

 	device_init_wakeup(&pdev->dev, 1);

+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
 	rtc->rtc_dev->ops = &mtk_rtc_ops;

 	ret = rtc_register_device(rtc->rtc_dev);
@@ -302,15 +300,6 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 	return ret;
 }

-static int mtk_rtc_remove(struct platform_device *pdev)
-{
-	struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
-
-	free_irq(rtc->irq, rtc);
-
-	return 0;
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int mt6397_rtc_suspend(struct device *dev)
 {
@@ -337,6 +326,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", },
 	{ }
 };
@@ -349,7 +339,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);
--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 4/7] mfd: mt6323: some improvements of mt6397-core
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
                   ` (2 preceding siblings ...)
  2019-07-03 16:48 ` [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff Frank Wunderlich
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

- simplyfications (resource definitions my DEFINE_RES_* macros)
- add mt6323 rtc+pwrc

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
 drivers/mfd/mt6397-core.c | 40 ++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 337bcccdb914..a4abce00f156 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -1,10 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2014 MediaTek Inc.
+ * Copyright (c) 2014-2018 MediaTek Inc.
  * Author: Flora Fu, MediaTek
  */

 #include <linux/interrupt.h>
+#include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
@@ -15,24 +16,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[] = {
@@ -45,8 +49,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"
 	}, {
@@ -57,6 +70,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"
 	},
 };

--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
                   ` (3 preceding siblings ...)
  2019-07-03 16:48 ` [PATCH v2 4/7] mfd: mt6323: some improvements of mt6397-core Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  2019-07-04  9:15   ` Matthias Brugger
  2019-07-04 10:03   ` Ran Bi
  2019-07-03 16:48 ` [PATCH v2 6/7] MAINTAINERS: add Mediatek shutdown drivers Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 7/7] arm: dts: mt6323: add keys, power-controller, rtc and codec Frank Wunderlich
  6 siblings, 2 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

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>
---
 drivers/power/reset/Kconfig           | 10 +++
 drivers/power/reset/Makefile          |  1 +
 drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++
 include/linux/mfd/mt6397/core.h       |  2 +
 4 files changed, 110 insertions(+)
 create mode 100644 drivers/power/reset/mt6323-poweroff.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 980951dff834..492678e22088 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -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
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 0aebee954ac1..94eaceb01d66 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -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
diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/mt6323-poweroff.c
new file mode 100644
index 000000000000..1caf43d9e46d
--- /dev/null
+++ b/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");
diff --git a/include/linux/mfd/mt6397/core.h b/include/linux/mfd/mt6397/core.h
index 25a95e72179b..652da61e3711 100644
--- a/include/linux/mfd/mt6397/core.h
+++ b/include/linux/mfd/mt6397/core.h
@@ -7,6 +7,8 @@
 #ifndef __MFD_MT6397_CORE_H__
 #define __MFD_MT6397_CORE_H__

+#include <linux/mutex.h>
+
 enum mt6397_irq_numbers {
 	MT6397_IRQ_SPKL_AB = 0,
 	MT6397_IRQ_SPKR_AB,
--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 6/7] MAINTAINERS: add Mediatek shutdown drivers
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
                   ` (4 preceding siblings ...)
  2019-07-03 16:48 ` [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  2019-07-03 16:48 ` [PATCH v2 7/7] arm: dts: mt6323: add keys, power-controller, rtc and codec Frank Wunderlich
  6 siblings, 0 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 01a52fc964da..31c1e882b7d2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9920,6 +9920,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>
--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 7/7] arm: dts: mt6323: add keys, power-controller, rtc and codec
  2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
                   ` (5 preceding siblings ...)
  2019-07-03 16:48 ` [PATCH v2 6/7] MAINTAINERS: add Mediatek shutdown drivers Frank Wunderlich
@ 2019-07-03 16:48 ` Frank Wunderlich
  6 siblings, 0 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-03 16:48 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl, Frank Wunderlich

From: Josef Friedl <josef.friedl@speed.at>

support poweroff and power-related keys on bpi-r2

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>
---
 arch/arm/boot/dts/mt6323.dtsi | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/arch/arm/boot/dts/mt6323.dtsi b/arch/arm/boot/dts/mt6323.dtsi
index ba397407c1dd..7fda40ab5fe8 100644
--- a/arch/arm/boot/dts/mt6323.dtsi
+++ b/arch/arm/boot/dts/mt6323.dtsi
@@ -238,5 +238,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";
+		};
 	};
 };
--
2.17.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h
  2019-07-03 16:48 ` [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h Frank Wunderlich
@ 2019-07-04  9:11   ` Matthias Brugger
  2019-07-04 11:49     ` Aw: " Frank Wunderlich
  0 siblings, 1 reply; 21+ messages in thread
From: Matthias Brugger @ 2019-07-04  9:11 UTC (permalink / raw)
  To: Frank Wunderlich, Lee Jones, Rob Herring, Mark Rutland,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl



On 03/07/2019 18:48, Frank Wunderlich wrote:
> From: Josef Friedl <josef.friedl@speed.at>
>

Still missing commit message. Describe here why you need to do that.


> 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>
> =2D--

Please check your email setting as discussed offline. Otherwise your patches
won't get accepted.

Regards,
Matthias

>  drivers/rtc/rtc-mt6397.c       | 55 +-------------------------
>  include/linux/mfd/mt6397/rtc.h | 71 ++++++++++++++++++++++++++++++++++
>  2 files changed, 72 insertions(+), 54 deletions(-)
>  create mode 100644 include/linux/mfd/mt6397/rtc.h
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index b46ed4dc7015..c08ee5edf865 100644
> =2D-- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -9,60 +9,7 @@
>  #include <linux/module.h>
>  #include <linux/regmap.h>
>  #include <linux/rtc.h>
> -#include <linux/irqdomain.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)
> -
> -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)
>  {
> diff --git a/include/linux/mfd/mt6397/rtc.h b/include/linux/mfd/mt6397/rtc=
> .h
> new file mode 100644
> index 000000000000..b702c29e8c74
> =2D-- /dev/null
> +++ b/include/linux/mfd/mt6397/rtc.h
> @@ -0,0 +1,71 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2014-2018 MediaTek Inc.
> + *
> + * Author: Tianping.Fang <tianping.fang@mediatek.com>
> + *        Sean Wang <sean.wang@mediatek.com>
> + */
> +
> +#ifndef _LINUX_MFD_MT6397_RTC_H_
> +#define _LINUX_MFD_MT6397_RTC_H_
> +
> +#include <linux/jiffies.h>
> +#include <linux/mutex.h>
> +#include <linux/regmap.h>
> +#include <linux/rtc.h>
> +
> +#define RTC_BBPU               0x0000
> +#define RTC_BBPU_CBUSY         BIT(6)
> +#define RTC_BBPU_KEY            (0x43 << 8)
> +
> +#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;
> +
> +	/* Protect register access from multiple tasks */
> +	struct mutex            lock;
> +	struct regmap           *regmap;
> +	int                     irq;
> +	u32                     addr_base;
> +};
> +
> +#endif /* _LINUX_MFD_MT6397_RTC_H_ */
> =2D-
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-03 16:48 ` [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver Frank Wunderlich
@ 2019-07-04  9:13   ` Matthias Brugger
  2019-07-04 11:08     ` Aw: " Frank Wunderlich
  2019-07-04 20:43   ` Alexandre Belloni
  1 sibling, 1 reply; 21+ messages in thread
From: Matthias Brugger @ 2019-07-04  9:13 UTC (permalink / raw)
  To: Frank Wunderlich, Lee Jones, Rob Herring, Mark Rutland,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl



On 03/07/2019 18:48, Frank Wunderlich wrote:
> From: Josef Friedl <josef.friedl@speed.at>
> 
> - use regmap_read_poll_timeout to drop while-loop
> - use devm-api to drop remove-callback
> - add new compatible for mt6323
>

It's up to the maintainer but I don't like patches doing clean-ups together with
adding support for new HW, although it's a trivial one here.


> Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
> =2D--
>  drivers/rtc/rtc-mt6397.c | 55 ++++++++++++++++------------------------
>  1 file changed, 22 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> index c08ee5edf865..e5ddf0d0b6f1 100644
> =2D-- a/drivers/rtc/rtc-mt6397.c
> +++ b/drivers/rtc/rtc-mt6397.c
> @@ -4,16 +4,19 @@
>  * Author: Tianping.Fang <tianping.fang@mediatek.com>

Missing in the CC list.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff
  2019-07-03 16:48 ` [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff Frank Wunderlich
@ 2019-07-04  9:15   ` Matthias Brugger
  2019-07-04 10:03   ` Ran Bi
  1 sibling, 0 replies; 21+ messages in thread
From: Matthias Brugger @ 2019-07-04  9:15 UTC (permalink / raw)
  To: Frank Wunderlich, Lee Jones, Rob Herring, Mark Rutland,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney
  Cc: Josef Friedl



On 03/07/2019 18:48, Frank Wunderlich wrote:
> From: Josef Friedl <josef.friedl@speed.at>
> 
> Suggested-by: Frank Wunderlich <frank-w@public-files.de>
> Signed-off-by: Josef Friedl <josef.friedl@speed.at>

Why is there a Signed-off-by from Josef for this patch but not for the others?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff
  2019-07-03 16:48 ` [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff Frank Wunderlich
  2019-07-04  9:15   ` Matthias Brugger
@ 2019-07-04 10:03   ` Ran Bi
  2019-07-04 11:06     ` Aw: " Frank Wunderlich
  1 sibling, 1 reply; 21+ messages in thread
From: Ran Bi @ 2019-07-04 10:03 UTC (permalink / raw)
  To: Frank Wunderlich
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney, Josef Friedl,
	Yingjoe Chen, Sean Wang, Ran Bi

On Wed, 2019-07-03 at 18:48 +0200, Frank Wunderlich wrote:
> From: Josef Friedl <josef.friedl@speed.at>
> 
> 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>
> ---
>  drivers/power/reset/Kconfig           | 10 +++
>  drivers/power/reset/Makefile          |  1 +
>  drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++
>  include/linux/mfd/mt6397/core.h       |  2 +
>  4 files changed, 110 insertions(+)
>  create mode 100644 drivers/power/reset/mt6323-poweroff.c
> 
> --
> 2.17.1
> 
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 980951dff834..492678e22088 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -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
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index 0aebee954ac1..94eaceb01d66 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -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
> diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/mt6323-poweroff.c
> new file mode 100644
> index 000000000000..1caf43d9e46d
> --- /dev/null
> +++ b/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;

We had implement MT8173 poweroff function in arm-trusted-firmware's PSCI
plat_system_off() function. MT8173 SoC is using PMIC MT6397. (Ref:
https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/mediatek/mt8173/plat_pm.c and https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/mediatek/mt8173/drivers/rtc) Do you think it's better to implement poweroff function into arm-trusted-firmware compared to hijack pm_poweroff() function in Kernel? Right now, we are doing the upstream of other PMIC chip like MT6358's poweroff function in arm-trusted-firmware too.

> +
> +	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");
> diff --git a/include/linux/mfd/mt6397/core.h b/include/linux/mfd/mt6397/core.h
> index 25a95e72179b..652da61e3711 100644
> --- a/include/linux/mfd/mt6397/core.h
> +++ b/include/linux/mfd/mt6397/core.h
> @@ -7,6 +7,8 @@
>  #ifndef __MFD_MT6397_CORE_H__
>  #define __MFD_MT6397_CORE_H__
> 
> +#include <linux/mutex.h>
> +
>  enum mt6397_irq_numbers {
>  	MT6397_IRQ_SPKL_AB = 0,



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Aw: Re: [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff
  2019-07-04 10:03   ` Ran Bi
@ 2019-07-04 11:06     ` Frank Wunderlich
  0 siblings, 0 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-04 11:06 UTC (permalink / raw)
  To: Ran Bi
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, devicetree, linux-arm-kernel, linux-mediatek,
	linux-kernel, linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney, Josef Friedl,
	Yingjoe Chen, Ran Bi

> Gesendet: Donnerstag, 04. Juli 2019 um 12:03 Uhr
> Von: "Ran Bi" <ran.bi@mediatek.com>

> We had implement MT8173 poweroff function in arm-trusted-firmware's PSCI
> plat_system_off() function. MT8173 SoC is using PMIC MT6397. (Ref:
> https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/mediatek/mt8173/plat_pm.c and https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/mediatek/mt8173/drivers/rtc) Do you think it's better to implement poweroff function into arm-trusted-firmware compared to hijack pm_poweroff() function in Kernel? Right now, we are doing the upstream of other PMIC chip like MT6358's poweroff function in arm-trusted-firmware too.

ATF imho only used for arm64, my board is 32bit armv7 and i (currently) do not boot up with ATF

regards Frank

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Aw: Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-04  9:13   ` Matthias Brugger
@ 2019-07-04 11:08     ` Frank Wunderlich
  0 siblings, 0 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-04 11:08 UTC (permalink / raw)
  Cc: Lee Jones, Rob Herring, Mark Rutland, Sean Wang,
	Sebastian Reichel, Alessandro Zummo, Alexandre Belloni,
	devicetree, linux-arm-kernel, linux-mediatek, linux-kernel,
	linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney, Josef Friedl

> Gesendet: Donnerstag, 04. Juli 2019 um 11:13 Uhr
> Von: "Matthias Brugger" <matthias.bgg@gmail.com>

> It's up to the maintainer but I don't like patches doing clean-ups together with
> adding support for new HW, although it's a trivial one here.

i can split again to have clean-up and new functions separated

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Aw: Re: [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h
  2019-07-04  9:11   ` Matthias Brugger
@ 2019-07-04 11:49     ` Frank Wunderlich
  0 siblings, 0 replies; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-04 11:49 UTC (permalink / raw)
  To: Matthias Brugger
  Cc: Lee Jones, Rob Herring, Mark Rutland, Sean Wang,
	Sebastian Reichel, Alessandro Zummo, Alexandre Belloni,
	devicetree, linux-arm-kernel, linux-mediatek, linux-kernel,
	linux-pm, linux-rtc, Eddie Huang, Thomas Gleixner,
	Richard Fontana, Allison Randal, David S . Miller,
	Mauro Carvalho Chehab, Greg Kroah-Hartman, Rob Herring,
	Linus Walleij, Nicolas Ferre, Paul E . McKenney, Josef Friedl

> Still missing commit message. Describe here why you need to do that.

ok, added note that headers are reused in power-off-driver

https://github.com/frank-w/BPI-R2-4.14/commits/5.2-poweroff-mainline

> Please check your email setting as discussed offline. Otherwise your patches
> won't get accepted.

tested with webmailer where it looks good :(

seems the problem is only shown when imported to patchwork

using only git sendemail in ubuntu 18.4 without any mta (have sendmail not installed) and no changes made to git sendemail except authentication.

i see that (except cover-letter which is quoted-printable) all is send with
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

so i have forced git sendemail now to
sendemail.composeencoding UTF-8

if this does not work i can try instead
sendemail.transferEncoding 8bit

regards Frank

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] docs: dt-bindings: add poweroff
  2019-07-03 16:48 ` [PATCH v2 1/7] docs: dt-bindings: add poweroff Frank Wunderlich
@ 2019-07-04 18:54   ` Alexandre Belloni
  0 siblings, 0 replies; 21+ messages in thread
From: Alexandre Belloni @ 2019-07-04 18:54 UTC (permalink / raw)
  To: Frank Wunderlich
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel, linux-pm,
	linux-rtc, Eddie Huang, Thomas Gleixner, Richard Fontana,
	Allison Randal, David S . Miller, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Rob Herring, Linus Walleij, Nicolas Ferre,
	Paul E . McKenney, Josef Friedl

Please use a better subject line.

On 03/07/2019 18:48:16+0200, Frank Wunderlich wrote:
> From: Josef Friedl <josef.friedl@speed.at>
> 
> add documentation for pmic, rtc and power/reset devicetree bindings
> 
> 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>
> ---
>  .../devicetree/bindings/mfd/mt6397.txt        | 10 ++++++-
>  .../bindings/power/reset/mt6323-poweroff.txt  | 20 +++++++++++++
>  .../devicetree/bindings/rtc/rtc-mt6397.txt    | 29 +++++++++++++++++++

This file is unrelated to the patch, it should be separated.

>  3 files changed, 58 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
>  create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
> 
> diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt b/Documentation/devicetree/bindings/mfd/mt6397.txt
> index 0ebd08af777d..44acb9827716 100644
> --- a/Documentation/devicetree/bindings/mfd/mt6397.txt
> +++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
> @@ -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.
> @@ -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"
> @@ -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";
> diff --git a/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt b/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
> new file mode 100644
> index 000000000000..933f0c48e887
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
> @@ -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";
> +               };
> +       }
> diff --git a/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt b/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
> new file mode 100644
> index 000000000000..ebd1cf80dcc8
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
> @@ -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";
> +               };
> +       };
> --
> 2.17.1
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-03 16:48 ` [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver Frank Wunderlich
  2019-07-04  9:13   ` Matthias Brugger
@ 2019-07-04 20:43   ` Alexandre Belloni
  2019-07-05 15:35     ` Aw: " Frank Wunderlich
  1 sibling, 1 reply; 21+ messages in thread
From: Alexandre Belloni @ 2019-07-04 20:43 UTC (permalink / raw)
  To: Frank Wunderlich
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel, linux-pm,
	linux-rtc, Eddie Huang, Thomas Gleixner, Richard Fontana,
	Allison Randal, David S . Miller, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Rob Herring, Linus Walleij, Nicolas Ferre,
	Paul E . McKenney, Josef Friedl

On 03/07/2019 18:48:18+0200, Frank Wunderlich wrote:
> @@ -271,14 +268,11 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> 
>  	platform_set_drvdata(pdev, rtc);
> 
> -	rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev);
> -	if (IS_ERR(rtc->rtc_dev))
> -		return PTR_ERR(rtc->rtc_dev);
> +	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
> +					mtk_rtc_irq_handler_thread,
> +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> +					"mt6397-rtc", rtc);
> 

This change may lead to a crash and the allocation was intentionally
placed before the irq request.

> -	ret = request_threaded_irq(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);
> @@ -287,6 +281,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> 
>  	device_init_wakeup(&pdev->dev, 1);
> 
> +	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
> +	if (IS_ERR(rtc->rtc_dev))
> +		return PTR_ERR(rtc->rtc_dev);
> +
>  	rtc->rtc_dev->ops = &mtk_rtc_ops;
> 
>  	ret = rtc_register_device(rtc->rtc_dev);
> @@ -302,15 +300,6 @@ static int mtk_rtc_probe(struct platform_device *pdev)
>  	return ret;
>  }
> 
> -static int mtk_rtc_remove(struct platform_device *pdev)
> -{
> -	struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
> -
> -	free_irq(rtc->irq, rtc);
> -
> -	return 0;
> -}
> -
>  #ifdef CONFIG_PM_SLEEP
>  static int mt6397_rtc_suspend(struct device *dev)
>  {
> @@ -337,6 +326,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", },

Unrelated change, this is not an improvement and must be accompanied by
a documentation change.

>  	{ .compatible = "mediatek,mt6397-rtc", },
>  	{ }
>  };
> @@ -349,7 +339,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);
> --
> 2.17.1
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Aw: Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-04 20:43   ` Alexandre Belloni
@ 2019-07-05 15:35     ` Frank Wunderlich
  2019-07-05 21:24       ` Alexandre Belloni
  0 siblings, 1 reply; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-05 15:35 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel, linux-pm,
	linux-rtc, Eddie Huang, Thomas Gleixner, Richard Fontana,
	Allison Randal, David S . Miller, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Rob Herring, Linus Walleij, Nicolas Ferre,
	Paul E . McKenney, Josef Friedl

Hi Alexander,

thank you for the Review

> Gesendet: Donnerstag, 04. Juli 2019 um 22:43 Uhr
> Von: "Alexandre Belloni" <alexandre.belloni@bootlin.com>
> > -	rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev);
> > -	if (IS_ERR(rtc->rtc_dev))
> > -		return PTR_ERR(rtc->rtc_dev);
> > +	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
> > +					mtk_rtc_irq_handler_thread,
> > +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > +					"mt6397-rtc", rtc);
> >
>
> This change may lead to a crash and the allocation was intentionally
> placed before the irq request.

i got no crash till now, but i will try to move the allocation before irq-request

> > -	ret = request_threaded_irq(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);
> > @@ -287,6 +281,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> >
> >  	device_init_wakeup(&pdev->dev, 1);
> >
> > +	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
> > +	if (IS_ERR(rtc->rtc_dev))
> > +		return PTR_ERR(rtc->rtc_dev);
> > +
> >  	rtc->rtc_dev->ops = &mtk_rtc_ops;


> >  static const struct of_device_id mt6397_rtc_of_match[] = {
> > +	{ .compatible = "mediatek,mt6323-rtc", },
>
> Unrelated change, this is not an improvement and must be accompanied by
> a documentation change.

documentation is changed in 1/7 defining this compatible. i called it improvement because existing driver now supports another chip

regards Frank

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-05 15:35     ` Aw: " Frank Wunderlich
@ 2019-07-05 21:24       ` Alexandre Belloni
  2019-07-06 16:15         ` Aw: " Frank Wunderlich
  0 siblings, 1 reply; 21+ messages in thread
From: Alexandre Belloni @ 2019-07-05 21:24 UTC (permalink / raw)
  To: Frank Wunderlich
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel, linux-pm,
	linux-rtc, Eddie Huang, Thomas Gleixner, Richard Fontana,
	Allison Randal, David S . Miller, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Rob Herring, Linus Walleij, Nicolas Ferre,
	Paul E . McKenney, Josef Friedl

On 05/07/2019 17:35:46+0200, Frank Wunderlich wrote:
> Hi Alexander,
> 
> thank you for the Review
> 
> > Gesendet: Donnerstag, 04. Juli 2019 um 22:43 Uhr
> > Von: "Alexandre Belloni" <alexandre.belloni@bootlin.com>
> > > -	rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev);
> > > -	if (IS_ERR(rtc->rtc_dev))
> > > -		return PTR_ERR(rtc->rtc_dev);
> > > +	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
> > > +					mtk_rtc_irq_handler_thread,
> > > +					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
> > > +					"mt6397-rtc", rtc);
> > >
> >
> > This change may lead to a crash and the allocation was intentionally
> > placed before the irq request.
> 
> i got no crash till now, but i will try to move the allocation before irq-request
> 

Let's say the RTC has been used to start your platform, then the irq
handler will be called as soon as the irq is requested, leading to a
null pointer dereference.

> > > -	ret = request_threaded_irq(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);
> > > @@ -287,6 +281,10 @@ static int mtk_rtc_probe(struct platform_device *pdev)
> > >
> > >  	device_init_wakeup(&pdev->dev, 1);
> > >
> > > +	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
> > > +	if (IS_ERR(rtc->rtc_dev))
> > > +		return PTR_ERR(rtc->rtc_dev);
> > > +
> > >  	rtc->rtc_dev->ops = &mtk_rtc_ops;
> 
> 
> > >  static const struct of_device_id mt6397_rtc_of_match[] = {
> > > +	{ .compatible = "mediatek,mt6323-rtc", },
> >
> > Unrelated change, this is not an improvement and must be accompanied by
> > a documentation change.
> 
> documentation is changed in 1/7 defining this compatible. i called it improvement because existing driver now supports another chip
> 

Yes and IIRC, I did comment that the rtc change also had to be separated
from 1/7.

Also, I really doubt this new compatible is necessary at all as you
could simply directly use mediatek,mt6397-rtc.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Aw: Re: Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-05 21:24       ` Alexandre Belloni
@ 2019-07-06 16:15         ` Frank Wunderlich
  2019-07-06 20:04           ` Alexandre Belloni
  0 siblings, 1 reply; 21+ messages in thread
From: Frank Wunderlich @ 2019-07-06 16:15 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel, linux-pm,
	linux-rtc, Eddie Huang, Thomas Gleixner, Richard Fontana,
	Allison Randal, David S . Miller, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Rob Herring, Linus Walleij, Nicolas Ferre,
	Paul E . McKenney, Josef Friedl

> Gesendet: Freitag, 05. Juli 2019 um 23:24 Uhr
> Von: "Alexandre Belloni" <alexandre.belloni@bootlin.com>

> Let's say the RTC has been used to start your platform, then the irq
> handler will be called as soon as the irq is requested, leading to a
> null pointer dereference.

i cannot test this with my platform, but i have changed it in my repo

https://github.com/frank-w/BPI-R2-4.14/commits/5.2-poweroff-mainline

> Yes and IIRC, I did comment that the rtc change also had to be separated
> from 1/7.

also this is put in separate commit, can you take a look before i post v3?

> Also, I really doubt this new compatible is necessary at all as you
> could simply directly use mediatek,mt6397-rtc.

imho this can confuse because the wrong chip-name is used in dts

regards Frank

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Re: Re: [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver
  2019-07-06 16:15         ` Aw: " Frank Wunderlich
@ 2019-07-06 20:04           ` Alexandre Belloni
  0 siblings, 0 replies; 21+ messages in thread
From: Alexandre Belloni @ 2019-07-06 20:04 UTC (permalink / raw)
  To: Frank Wunderlich
  Cc: Lee Jones, Rob Herring, Mark Rutland, Matthias Brugger,
	Sean Wang, Sebastian Reichel, Alessandro Zummo, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel, linux-pm,
	linux-rtc, Eddie Huang, Thomas Gleixner, Richard Fontana,
	Allison Randal, David S . Miller, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Rob Herring, Linus Walleij, Nicolas Ferre,
	Paul E . McKenney, Josef Friedl

On 06/07/2019 18:15:20+0200, Frank Wunderlich wrote:
> > Gesendet: Freitag, 05. Juli 2019 um 23:24 Uhr
> > Von: "Alexandre Belloni" <alexandre.belloni@bootlin.com>
> 
> > Let's say the RTC has been used to start your platform, then the irq
> > handler will be called as soon as the irq is requested, leading to a
> > null pointer dereference.
> 
> i cannot test this with my platform, but i have changed it in my repo
> 
> https://github.com/frank-w/BPI-R2-4.14/commits/5.2-poweroff-mainline
> 
> > Yes and IIRC, I did comment that the rtc change also had to be separated
> > from 1/7.
> 
> also this is put in separate commit, can you take a look before i post v3?
> 
> > Also, I really doubt this new compatible is necessary at all as you
> > could simply directly use mediatek,mt6397-rtc.
> 
> imho this can confuse because the wrong chip-name is used in dts
> 

This is not true, we do that all the time and the immediate benefit of
using the mt6397 compatible is that then there is no need to
synchronize between subsystems. If you want to be absolutely
conservative, you could use

compatible = "mediatek,mt6323-rtc", "mediatek,mt6397-rtc";

in your DT.


-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2019-07-06 20:04 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 16:48 [PATCH v2 0/7] implement poweroff for mt6323/6397 Frank Wunderlich
2019-07-03 16:48 ` [PATCH v2 1/7] docs: dt-bindings: add poweroff Frank Wunderlich
2019-07-04 18:54   ` Alexandre Belloni
2019-07-03 16:48 ` [PATCH v2 2/7] rtc: mt6397: move some common definitions into rtc.h Frank Wunderlich
2019-07-04  9:11   ` Matthias Brugger
2019-07-04 11:49     ` Aw: " Frank Wunderlich
2019-07-03 16:48 ` [PATCH v2 3/7] rtc: mt6397: improvements of rtc driver Frank Wunderlich
2019-07-04  9:13   ` Matthias Brugger
2019-07-04 11:08     ` Aw: " Frank Wunderlich
2019-07-04 20:43   ` Alexandre Belloni
2019-07-05 15:35     ` Aw: " Frank Wunderlich
2019-07-05 21:24       ` Alexandre Belloni
2019-07-06 16:15         ` Aw: " Frank Wunderlich
2019-07-06 20:04           ` Alexandre Belloni
2019-07-03 16:48 ` [PATCH v2 4/7] mfd: mt6323: some improvements of mt6397-core Frank Wunderlich
2019-07-03 16:48 ` [PATCH v2 5/7] power: reset: add driver for mt6323 poweroff Frank Wunderlich
2019-07-04  9:15   ` Matthias Brugger
2019-07-04 10:03   ` Ran Bi
2019-07-04 11:06     ` Aw: " Frank Wunderlich
2019-07-03 16:48 ` [PATCH v2 6/7] MAINTAINERS: add Mediatek shutdown drivers Frank Wunderlich
2019-07-03 16:48 ` [PATCH v2 7/7] arm: dts: mt6323: add keys, power-controller, rtc and codec Frank Wunderlich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).