Search code examples
linux-device-driverembedded-linuximx6real-time-clock

Regulator configuration for RTC backup battery in i.MX6 PMIC


I'm switching with the phycore i.MX6 som from phytec's dev kit to an own board. The usermanuals for both the som and devkit can be found on phytec's page. Now I want to configure the rtc to keep the time during reboot's and poweroffs.

The battery (in my case supercap) is connected to the VDD_BAT pin of the phycore i.MX6 som (page 10). The internal PMIC is the da9062 connected via the i2c bus which is configured in the som dtsi file as rtc1.

imx6qdl-phytec-phycore-som.dtsi:

...
aliases {
    rtc1 = &da9062_rtc;
};
...
&i2c3 {
    pmic@58 {
         da9062_rtc: rtc {
             compatible = "dlg,da9062-rtc";
         };
    };
};

This file I didn't touch at all.

Next, I told the kernel to take his hwclock and systime time from rtc1 instead of rtc0:

CONFIG_RTC_HCTOSYS_DEVICE="rtc1"
CONFIG_RTC_SYSTOHC_DEVICE="rtc1"

The driver is being loaded correctly as far as I can tell:

dmesg | grep rtc
[    2.489836] da9063-rtc da9062-rtc: rtc core: registered da9063-rtc as rtc1
[    2.499713] snvs_rtc 20cc000.snvs:snvs-rtc-lp: rtc core: registered 20cc000.snvs:snvs-rtc-lp as rtc2
[    3.260348] da9063-rtc da9062-rtc: setting system clock to 2000-01-01 02:37:55 UTC (946694275)

and

cat /sys/class/rtc/rtc1/name 
da9063-rtc da9062-rtc

Now, I can set the time via date and transfer it to the hwclock via

hwclock --systohc

.

After rebooting the system and hwclock is set to the previously set date which is fine. After cutting the power the clock gets reset.

I've measured the voltage of the supercap which is around 220mV. The datasheet of the da9062 tells me the chip does have an regulator for the battery which needs to be configured (Table 127: BBAT_CONT (0x0C5)).

As far as I understand the kernel/rtc subsystem, the driver for the rtc should take care of the charging of the battery or provide an userspace interface so I can do it myself. But I can't find anything on this topic.

I am using yocto to build the kernel/image for my board.

Is there something I'm missing or do I need to patch the driver myself in order to charge the supercap? Maybe there's an option in the devicetree to set the charging voltage and current for the cap?

I appreciate any ideas and suggestions, thanks.


Solution

  • Aparently the driver does not support charging a battery/supercap out of the box and it has exclusive access rights to the i2c device address which prevents userspace applications to access the device.

    My solution to this problem is to set those values before the driver takes over: Since this i2c bus is already configured in my barebox devicetree, I can access it before I boot the kernel (provided barebox is compiled with the i2c subsystem enabled in menuconfig). Here I can run a script which sets the BBAT and PD registers to enable charging the supercap.

    Though, the cleaner solution would be to extend the driver and provide a userspace interface for this functionality.

    Another possible solution I did not investigate would be to check if the driver can be compiled as a module, so I could unload the module, set the registers and load it again.