rtc: pcf8563: Clear event flags and disable interrupts before requesting irq [Linux 5.3]

This Linux kernel change "rtc: pcf8563: Clear event flags and disable interrupts before requesting irq" is included in the Linux 5.3 release. This change is authored by Chen-Yu Tsai <wens [at] csie.org> on Tue Jun 4 12:23:36 2019 +0800. The commit for this change in Linux stable tree is 3572e8a (patch).

rtc: pcf8563: Clear event flags and disable interrupts before requesting irq

Besides the alarm, the PCF8563 also has a timer triggered interrupt.
In cases where the previous system left the timer and interrupts on,
or somehow the bits got enabled, the interrupt would keep triggering
as the kernel doesn't know about it.

Clear both the alarm and timer event flags, and disable the interrupts,
before requesting the interrupt line.

Fixes: ede3e9d47cca ("drivers/rtc/rtc-pcf8563.c: add alarm support")
Fixes: a45d528aab8b ("rtc: pcf8563: clear expired alarm at boot time")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

There are 11 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/rtc/rtc-pcf8563.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index e358313..d8adf69 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -563,7 +563,6 @@ static int pcf8563_probe(struct i2c_client *client,
    struct pcf8563 *pcf8563;
    int err;
    unsigned char buf;
-   unsigned char alm_pending;

    dev_dbg(&client->dev, "%s\n", __func__);

@@ -587,13 +586,13 @@ static int pcf8563_probe(struct i2c_client *client,
        return err;
    }

-   err = pcf8563_get_alarm_mode(client, NULL, &alm_pending);
-   if (err) {
-       dev_err(&client->dev, "%s: read error\n", __func__);
+   /* Clear flags and disable interrupts */
+   buf = 0;
+   err = pcf8563_write_block_data(client, PCF8563_REG_ST2, 1, &buf);
+   if (err < 0) {
+       dev_err(&client->dev, "%s: write error\n", __func__);
        return err;
    }
-   if (alm_pending)
-       pcf8563_set_alarm_mode(client, 0);

    pcf8563->rtc = devm_rtc_device_register(&client->dev,
                pcf8563_driver.driver.name,

Leave a Reply

Your email address will not be published. Required fields are marked *