From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Sender: rtc-linux@googlegroups.com Received: from mail.free-electrons.com (down.free-electrons.com. [37.187.137.238]) by gmr-mx.google.com with ESMTP id d92si222642wma.2.2016.04.22.16.37.26 for ; Fri, 22 Apr 2016 16:37:26 -0700 (PDT) Date: Sat, 23 Apr 2016 01:37:16 +0200 From: Alexandre Belloni To: =?iso-8859-1?Q?Myl=E8ne?= Josserand Cc: rtc-linux@googlegroups.com, Alessandro Zummo , linux-kernel@vger.kernel.org Subject: [rtc-linux] Re: [PATCH 5/6] rtc: rv3029: enable AE_x bits on set_alarm Message-ID: <20160422233716.GH17051@piout.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 In-Reply-To: Reply-To: rtc-linux@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , On 21/04/2016 at 20:24:18 +0200, Myl=C4=8Dne Josserand wrote : > The RTC RV3029 handles different types of alarms : seconds, minutes, ... > These alarms can be enabled or disabled individually using an AE_x bit > which is the last bit (BIT(7)) on each alarm registers. >=20 > To prepare the alarm IRQ support, the current code enables all the alarm > types by setting each AE_x to 1. > It also fixes month and weekday errors : it was performing -1 instead > of +1. >=20 > Signed-off-by: Myl=C4=8Dne Josserand > --- > drivers/rtc/rtc-rv3029c2.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) >=20 > diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c > index a849005..42de1a3 100644 > --- a/drivers/rtc/rtc-rv3029c2.c > +++ b/drivers/rtc/rtc-rv3029c2.c > @@ -76,6 +76,7 @@ > #define RV3029_A_DW 0x14 > #define RV3029_A_MO 0x15 > #define RV3029_A_YR 0x16 > +#define RV3029_A_AE_X BIT(7) > #define RV3029_ALARM_SECTION_LEN 0x07 > =20 > /* timer section */ > @@ -436,14 +437,22 @@ static int rv3029_set_alarm(struct device *dev, str= uct rtc_wkalrm *alarm) > dev_err(dev, "%s: reading SR failed\n", __func__); > return -EIO; > } > - regs[RV3029_A_SC - RV3029_A_SC] =3D bin2bcd(tm->tm_sec & 0x7f); > - regs[RV3029_A_MN - RV3029_A_SC] =3D bin2bcd(tm->tm_min & 0x7f); > - regs[RV3029_A_HR - RV3029_A_SC] =3D bin2bcd(tm->tm_hour & 0x3f); > - regs[RV3029_A_DT - RV3029_A_SC] =3D bin2bcd(tm->tm_mday & 0x3f); > - regs[RV3029_A_MO - RV3029_A_SC] =3D bin2bcd((tm->tm_mon & 0x1f) - 1); > - regs[RV3029_A_DW - RV3029_A_SC] =3D bin2bcd((tm->tm_wday & 7) - 1); > - regs[RV3029_A_YR - RV3029_A_SC] =3D bin2bcd((tm->tm_year & 0x7f) - 100)= ; > =20 > + /* Activate all the alarms with AE_x bit */ > + regs[RV3029_A_SC - RV3029_A_SC] =3D (bin2bcd(tm->tm_sec)) | RV3029_A_AE= _X; > + regs[RV3029_A_MN - RV3029_A_SC] =3D (bin2bcd(tm->tm_min)) | RV3029_A_AE= _X; > + regs[RV3029_A_HR - RV3029_A_SC] =3D (bin2bcd(tm->tm_hour & 0x3f)) > + | RV3029_A_AE_X; > + regs[RV3029_A_DT - RV3029_A_SC] =3D (bin2bcd(tm->tm_mday & 0x3f)) > + | RV3029_A_AE_X; > + regs[RV3029_A_MO - RV3029_A_SC] =3D (bin2bcd((tm->tm_mon & 0x1f) + 1)) > + | RV3029_A_AE_X; > + regs[RV3029_A_DW - RV3029_A_SC] =3D (bin2bcd((tm->tm_wday & 7) + 1)) > + | RV3029_A_AE_X; > + regs[RV3029_A_YR - RV3029_A_SC] =3D (bin2bcd((tm->tm_year) - 100)) > + | RV3029_A_AE_X; > + Alarms probably never worked anyway because this still suffers form another bug: (bin2bcd(tm->tm_hour & 0x3f)) should be (bin2bcd(tm->tm_hour) & 0x3f), and the same for the other members. note that (bin2bcd((tm->tm_mon & 0x1f) + 1)) must be (bin2bcd(tm->tm_mon + 1) & 0x1f) etc... > + /* Write the alarm */ > ret =3D rv3029_write_regs(dev, RV3029_A_SC, regs, > RV3029_ALARM_SECTION_LEN); > if (ret < 0) > --=20 > 2.8.0.rc3 >=20 --=20 Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com --=20 --=20 You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. ---=20 You received this message because you are subscribed to the Google Groups "= rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to rtc-linux+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752120AbcDVXha (ORCPT ); Fri, 22 Apr 2016 19:37:30 -0400 Received: from down.free-electrons.com ([37.187.137.238]:54051 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751470AbcDVXh3 (ORCPT ); Fri, 22 Apr 2016 19:37:29 -0400 Date: Sat, 23 Apr 2016 01:37:16 +0200 From: Alexandre Belloni To: =?iso-8859-1?Q?Myl=E8ne?= Josserand Cc: rtc-linux@googlegroups.com, Alessandro Zummo , linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/6] rtc: rv3029: enable AE_x bits on set_alarm Message-ID: <20160422233716.GH17051@piout.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/04/2016 at 20:24:18 +0200, Mylène Josserand wrote : > The RTC RV3029 handles different types of alarms : seconds, minutes, ... > These alarms can be enabled or disabled individually using an AE_x bit > which is the last bit (BIT(7)) on each alarm registers. > > To prepare the alarm IRQ support, the current code enables all the alarm > types by setting each AE_x to 1. > It also fixes month and weekday errors : it was performing -1 instead > of +1. > > Signed-off-by: Mylène Josserand > --- > drivers/rtc/rtc-rv3029c2.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c > index a849005..42de1a3 100644 > --- a/drivers/rtc/rtc-rv3029c2.c > +++ b/drivers/rtc/rtc-rv3029c2.c > @@ -76,6 +76,7 @@ > #define RV3029_A_DW 0x14 > #define RV3029_A_MO 0x15 > #define RV3029_A_YR 0x16 > +#define RV3029_A_AE_X BIT(7) > #define RV3029_ALARM_SECTION_LEN 0x07 > > /* timer section */ > @@ -436,14 +437,22 @@ static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) > dev_err(dev, "%s: reading SR failed\n", __func__); > return -EIO; > } > - regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec & 0x7f); > - regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min & 0x7f); > - regs[RV3029_A_HR - RV3029_A_SC] = bin2bcd(tm->tm_hour & 0x3f); > - regs[RV3029_A_DT - RV3029_A_SC] = bin2bcd(tm->tm_mday & 0x3f); > - regs[RV3029_A_MO - RV3029_A_SC] = bin2bcd((tm->tm_mon & 0x1f) - 1); > - regs[RV3029_A_DW - RV3029_A_SC] = bin2bcd((tm->tm_wday & 7) - 1); > - regs[RV3029_A_YR - RV3029_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100); > > + /* Activate all the alarms with AE_x bit */ > + regs[RV3029_A_SC - RV3029_A_SC] = (bin2bcd(tm->tm_sec)) | RV3029_A_AE_X; > + regs[RV3029_A_MN - RV3029_A_SC] = (bin2bcd(tm->tm_min)) | RV3029_A_AE_X; > + regs[RV3029_A_HR - RV3029_A_SC] = (bin2bcd(tm->tm_hour & 0x3f)) > + | RV3029_A_AE_X; > + regs[RV3029_A_DT - RV3029_A_SC] = (bin2bcd(tm->tm_mday & 0x3f)) > + | RV3029_A_AE_X; > + regs[RV3029_A_MO - RV3029_A_SC] = (bin2bcd((tm->tm_mon & 0x1f) + 1)) > + | RV3029_A_AE_X; > + regs[RV3029_A_DW - RV3029_A_SC] = (bin2bcd((tm->tm_wday & 7) + 1)) > + | RV3029_A_AE_X; > + regs[RV3029_A_YR - RV3029_A_SC] = (bin2bcd((tm->tm_year) - 100)) > + | RV3029_A_AE_X; > + Alarms probably never worked anyway because this still suffers form another bug: (bin2bcd(tm->tm_hour & 0x3f)) should be (bin2bcd(tm->tm_hour) & 0x3f), and the same for the other members. note that (bin2bcd((tm->tm_mon & 0x1f) + 1)) must be (bin2bcd(tm->tm_mon + 1) & 0x1f) etc... > + /* Write the alarm */ > ret = rv3029_write_regs(dev, RV3029_A_SC, regs, > RV3029_ALARM_SECTION_LEN); > if (ret < 0) > -- > 2.8.0.rc3 > -- Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com