RTC wakealarm mode without IRQ specification in devicetree

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTC wakealarm mode without IRQ specification in devicetree

Jump to solution
2,121 Views
_Anthony
Contributor II
Hello, I'm working with Soc i.MX6 ARM based system and Linux kernel 4.19.
 
An RTC ds-1371, compatible with the rtc-ds1374.c (Linux kernel 4.19 driver) is wired in the i2C bus on my embedded card. I would like to use the alarm mode for this component, but the problem is :
 
There is no GPIO interrupt pin wired between rtc and CPU(i.MX6). So as the driver need it to activate the alarm mode, I decided to modify the driver source file "Linux/drivers/rtc/rtc-ds1374.c" by activating the alarm mode whithout interrupt specifier in devicetree.
 
My modification consist in adding a parameter in the devicetree that the driver will detect to enable alarm mode.
 
I named this parameter: "wakeup-capable". It's just a boolean.
 
So my devicetree seems like that:
--------------------------------
ds1374:rtc@68 {
    compatible = "dallas,ds1374";
    wakeup-capable;
    reg = <0x68>;
};
--------------------------------

then, in the probe function of the driver rtc-ds1374.c, I added the "else if" following condition :

----------------------------------------------------------------------------
if (client->irq > 0) {
        ret = devm_request_irq(&client->dev, client->irq, ds1374_irq, 0,
                    "ds1374", client);
        if (ret) {
            dev_err(&client->dev, "unable to request IRQ\n");
            return ret;
        }

        device_set_wakeup_capable(&client->dev, 1);
    }
    else if (device_property_read_bool(&client->dev, "wakeup-capable")) {
        device_set_wakeup_capable(&client->dev, 1);
    }
----------------------------------------------------------------------------
It permit to see the wakealarm file in "/sys/class/rtc/rtc0/wakealarm", but it's not already complete because trying to write 20 seconds in this file cause a value error.
 
Exemple:
 
user@machine:~$ echo +20 > /sys/class/rtc/rtc0/wakealarm
“-sh: echo: write error: Invalid argument”
 
but command "hwclock" works perfectly fine.
 
To solve the first problem, I discovered it had a link with the driver function "ds1374_set_alarm" and "ds1374_read_alarm".
Specifically the first condition:
 
--------------------------
if (client->irq <= 0)
        return -EINVAL;
-----------------------------
 
So I decided to comment it in both functions "ds1374_set_alarm" and "ds1374_read_alarm". So the command "echo +20 > /sys/class/rtc/rtc0/wakealarm" worked fine but the command hwclock gived me this error:
 
"hwclock: select() to /dev/rtc0 to wait for clock tick timed out"
 
I'm sure it's because I comments the folowing code:
 
--------------------------
//if (client->irq <= 0)
//        return -EINVAL;
-----------------------------
 
Actually, I would like the command "echo +20 > /sys/class/rtc/rtc0/wakealarm" and "hwclock" working both, but it seems to be possible only by declaring interrupt in devicetree like the following code:
 
--------------------------------
ds1374:rtc@68 {
    compatible = "dallas,ds1374";
    interrupt-parent = <&gpio8>;
    interrupts = <7 IRQ_TYPE_EDGE_FALLING>;//or interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
    reg = <0x68>;
};
--------------------------------
 
 
Is there a way to bypass IRQ dependency, just by declaring a boolean like "wakeup-capable" in the devicetree the driver could parse in order to have set alarm and hwclock working both?
 
Do you know a method to get both commands "hwclock" and "echo +20 > /sys/class/rtc/rtc0/wakealarm" working?
Thanks for all, and best reguards: Anthony.
Labels (1)
0 Kudos
1 Solution
2,094 Views
_Anthony
Contributor II

The problem was solved by modifing the driver for kernel 4.19.89:

(see the join file).

View solution in original post

0 Kudos
3 Replies
2,113 Views
igorpadykov
NXP Employee
NXP Employee

Hi _Anthony

 

>There is no GPIO interrupt pin wired between rtc and CPU(i.MX6)..

 

I am afraid without gpio connection it is not possible to wake i.MX6Q as i2c can not wake

processor in the same way as SNVS RTC or for example UART. Wake capability

is described specially in each module chapter of  i.MX 6Dual/6Quad Applications Processor Reference Manual

For UART please look at sect.64.8 Low Power Modes. I2C module has not such special wake

capability.

Example of external rtc can be found on :

https://community.nxp.com/t5/i-MX-Processors/how-to-make-spi-interface-rtc-function-work-for-imx8mq-...

 

Best regards
igor

0 Kudos
2,106 Views
_Anthony
Contributor II

Hi Igor, thanks for the reply.

To be more specific, the supply that powered the embedded card (not only the i.MX6), is wired to a smart switch. And the rtc ds1371 "SQW/INT" pin is wired to this switch. So if the switch detect the rtc interrupt alarm, then, it power on the card, else, the embedded card stay in its actual state (ON if it was ON, and OFF if it was OFF).

So as RTC alarm is used like this, SQW/INT pin is just linked to the switch and not i.MX6 gpio interrupt.

 

There is a link to the componant ds 1371 here: https://datasheets.maximintegrated.com/en/ds/DS1371.pdf

Thanks for all and best reguards: Anthony.

0 Kudos
2,095 Views
_Anthony
Contributor II

The problem was solved by modifing the driver for kernel 4.19.89:

(see the join file).

0 Kudos