BPI-R2 already has an on-board RTC

… unfortunately without a battery. This means the RTC will run as long is power is applied to the board. It survives a software power-off or software reset, but when you pull the power plug it will stop. Not ideal, but better than nothing…

It’s part of the MT6323 PMIC (the voltage regulator). A few days ago Sean Wang from Mediatek posted a patchset which seems to work just fine even though it’s not yet part of the kernel. You can find his first version (all-in-on for kernel 4.14) as part of my Yocto repo here:

along with his patch to add poweroff support - which also works for me:

It requires an addition to the PMIC wrapper (‘pwrap’) section of the devicetree:

&pwrap {
	mt6323 {
		mt6323led: led {
			compatible = "mediatek,mt6323-led";
			#address-cells = <1>;
			#size-cells = <0>;

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

		[...]

		};
	        mt6323rtc: rtc {
    			compatible = "mediatek,mt6323-rtc";

			power-off {
				compatible = "mediatek,mt6323-rtc-poweroff";
			};
	        };
	};
};
2 Likes

should this patch also poweroff the board? power seems to be the same (4.7w -> 4.4w on poweroff-command)

I didn’t measure power consumption, I just noticed all LEDs going off. Given that the code is for the PMIC, it’s probably fair to assume that stuff that’s not powered by the PMIC will remain powered on.

1 Like

Moreover, the whole series for PMIC RTC and Power off https://patchwork.kernel.org/patch/10303005/ should depend on the series for PMIC KEY https://patchwork.kernel.org/patch/10026727/

once the two series are included, you can see rtc and pmic key (only for power key found on bpi r2 board) are both supported

Hi Frank,

I noticed that the poweroff in 4.14-main does not work.

I have therefore revert commit 5a350ae40cbd6d8994157584ab8e040bb4c2900a and following 2 patch series recorded and adapted to 4.14-main.

https://patchwork.kernel.org/patch/10026727/

https://patchwork.kernel.org/patch/10362171/

this allows ‘shutown -P now’ as well as power-key to put the r2 in the initial state.

just to test my patch

revert 5a350ae40cbd6d8994157584ab8e040bb4c2900a

revert.patch (17,5 KB)

pmic-key.patch (17 KB)

rtc-poweroff.patch (19,3 KB)

in the order they should be able to be imported without hunk

1 Like

thank you, i will try your patches

i have tested original ones and got problems with network-device detection (all interfaces disappear), no idea why

works well…5w running and 0.2w if shutdown, all net-interfaces still present

@jofri with this patches, power-button now acts as real power-button, which triggers power-off on running system at the moment of pressung it. can this be changed (time to press,disable) without affecting the poweroff?

some people have soldered power-pins (to bootup on powersupply available) which now causes a boot-loop

There are more options.

Remove all acpi packages especially ‘acpi-support-base’,

or the easiest one will be to insert the module

echo “blacklist mtk_pmic_keys” >/etc/modprobe.d/blacklist.conf

@jofri can you try to port power-off-patches (pmic-key,rtc-poweroff) to 4.19?

poweroff currently does not work in 4.19

Patches seems to be mostly already applied,except pmic-keys in dts

Hello Frank,

Unfortunately, I can not test because I have my only BPI-R2 currently in productive use.

But have your branch 4.19-rc last commit e94c8a9699337dbb1b16e4248c9923986df30ff5 trying to insert poweroff. He compiles without errors.

Can you test poweroff.patch?poweroff.patch (19,7 KB)

1 Like

seems not to work…

Compiles fine,but does not poweroff :frowning:

@jofri Should i add debug-messages? Where/which to make it easier for you to debug?

Hi Frank,

can you please check if in .config CONFIG_POWER_RESET_MT6323 is active.

For me it was not, though included in mt7623_ebv_fwu_defconfig.

Some clock drivers for mediatek were also not activated.

In general, menuconfig behaves oddly ‘.config’ and ‘.config.old’ are always the same

1 Like

is not active and not set in defconfig…after activating it does poweroff :slight_smile:

which clocks do you mean?

# Clock driver for MediaTek SoC
#
CONFIG_COMMON_CLK_MEDIATEK=y
CONFIG_COMMON_CLK_MT2701=y
# CONFIG_COMMON_CLK_MT2701_MMSYS is not set
# CONFIG_COMMON_CLK_MT2701_IMGSYS is not set
# CONFIG_COMMON_CLK_MT2701_VDECSYS is not set
CONFIG_COMMON_CLK_MT2701_HIFSYS=y
CONFIG_COMMON_CLK_MT2701_ETHSYS=y
# CONFIG_COMMON_CLK_MT2701_BDPSYS is not set
# CONFIG_COMMON_CLK_MT2701_AUDSYS is not set
# CONFIG_COMMON_CLK_MT2701_G3DSYS is not set
CONFIG_COMMON_CLK_MT7622=y
# CONFIG_COMMON_CLK_MT7622_ETHSYS is not set
# CONFIG_COMMON_CLK_MT7622_HIFSYS is not set
# CONFIG_COMMON_CLK_MT7622_AUDSYS is not set
CONFIG_COMMON_CLK_MT8135=y
CONFIG_COMMON_CLK_MT8173=y
# CONFIG_HWSPINLOCK is not set

which clocks do you need? mt7622 is for other soc, 8135 and 8173 same…

mmsys,imgsys,vdecsysg3dsys are for hdmi/drm (imho not included in 4.19)

I only noticed it compared to 4.14-main.

ok, 4.14 currently supports much more features like hdmi (second gmac, hnat, …) which may cause more options…basic hdmi-patches (by mediatek) maybe included, but at least dts-nodes and fbdev is missing

@jofri: if i activate rtc_class=y (see my defconfig in 4.19-rc) i get the following errors:

  CC      drivers/rtc/rtc-mt6397.o
In file included from drivers/rtc/rtc-mt6397.c:13:
./include/linux/mfd/mt6397/core.h:59:15: error: field 'irqlock' has incomplete type
  struct mutex irqlock;
               ^~~~~~~
drivers/rtc/rtc-mt6397.c:320:34: error: array type has incomplete element type 'struct of_device_id'
 static const struct of_device_id mt6397_rtc_of_match[] = {
                                  ^~~~~~~~~~~~~~~~~~~
drivers/rtc/rtc-mt6397.c:321:4: error: field name not in record or union initializer
  { .compatible = "mediatek,mt6323-rtc", },
    ^
drivers/rtc/rtc-mt6397.c:321:4: note: (near initialization for 'mt6397_rtc_of_match')
drivers/rtc/rtc-mt6397.c:322:4: error: field name not in record or union initializer
  { .compatible = "mediatek,mt6397-rtc", },
    ^
drivers/rtc/rtc-mt6397.c:322:4: note: (near initialization for 'mt6397_rtc_of_match')
drivers/rtc/rtc-mt6397.c:320:34: warning: 'mt6397_rtc_of_match' defined but not used [-Wunused-variable]
 static const struct of_device_id mt6397_rtc_of_match[] = {
                                  ^~~~~~~~~~~~~~~~~~~
scripts/Makefile.build:307: recipe for target 'drivers/rtc/rtc-mt6397.o' failed
make[2]: *** [drivers/rtc/rtc-mt6397.o] Error 1
scripts/Makefile.build:548: recipe for target 'drivers/rtc' failed
make[1]: *** [drivers/rtc] Error 2
Makefile:1057: recipe for target 'drivers' failed
make: *** [drivers] Error 2

can you take a look at this? First one seems to be missing include

https://elixir.bootlin.com/linux/v4.19-rc1/source/include/linux/mutex.h#L53

fixed

1 Like
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 1ebeaaf11dfa..c3ed1e660f85 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -17,6 +17,7 @@
 #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)
 {
diff --git a/include/linux/mfd/mt6397/core.h b/include/linux/mfd/mt6397/core.h
index d678f526e498..0425c68cc187 100644
--- a/include/linux/mfd/mt6397/core.h
+++ b/include/linux/mfd/mt6397/core.h
@@ -15,6 +15,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,
(END)