RTC v3020 fixes
PATCH 1/1 RTC v3020 fixes
Fix off-by-one in month calculations
Add delay for bus accesses to satisfy Tw > 500ns
drivers/rtc/rtc-v3020.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/rtc/rtc-v3020.c +7 -2
@@ -26,6 +26,7 @@#include <linux/types.h> #include <linux/bcd.h> #include <linux/rtc-v3020.h> +#include <linux/delay.h> #include <asm/io.h>
@@ -47,6 +48,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address,for (i =0 ; i <4 ; i++) {writel ((tmp &1 ) << chip->leftshift, chip->ioaddress); tmp >>=1 ; +udelay (1 ); }/* Commands dont have data */
@@ -54,6 +56,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address,for (i =0 ; i <8 ; i++) {writel ((data &1 ) << chip->leftshift, chip->ioaddress); data >>=1 ; +udelay (1 ); } } }
@@ -66,12 +69,14 @@ static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address)for (i =0 ; i <4 ; i++) {writel ((address &1 ) << chip->leftshift, chip->ioaddress); address >>=1 ; +udelay (1 ); }for (i =0 ; i <8 ; i++) { data >>=1 ;if (readl (chip->ioaddress) & (1 << chip->leftshift)) data |=0x80 ; +udelay (1 ); }return data;
@@ -95,7 +100,7 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt) tmp =v3020_get_reg (chip,V3020_MONTH_DAY ); dt->tm_mday =BCD2BIN (tmp); tmp =v3020_get_reg (chip,V3020_MONTH ); - dt->tm_mon =BCD2BIN (tmp); + dt->tm_mon =BCD2BIN (tmp) -1 ; tmp =v3020_get_reg (chip,V3020_WEEK_DAY ); dt->tm_wday =BCD2BIN (tmp); tmp =v3020_get_reg (chip,V3020_YEAR );
@@ -135,7 +140,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)v3020_set_reg (chip,V3020_MINUTES ,BIN2BCD (dt->tm_min));v3020_set_reg (chip,V3020_HOURS ,BIN2BCD (dt->tm_hour));v3020_set_reg (chip,V3020_MONTH_DAY ,BIN2BCD (dt->tm_mday)); -v3020_set_reg (chip,V3020_MONTH ,BIN2BCD (dt->tm_mon)); +v3020_set_reg (chip,V3020_MONTH ,BIN2BCD (dt->tm_mon) +1 );v3020_set_reg (chip,V3020_WEEK_DAY ,BIN2BCD (dt->tm_wday));v3020_set_reg (chip,V3020_YEAR ,BIN2BCD (dt->tm_year %100 ));
Quoted 3 lines · Mike Rapoport
Fix off-by-one in month calculations
Add delay for bus accesses to satisfy Tw > 500ns
*snip*
drivers/rtc/rtc-v3020.c static int v3020_set_time(struct device *dev, struct · line 144
Quoted 7 lines
drivers/rtc/rtc-v3020.c +1
-1@@ -135,7 +140,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt) v3020_set_reg(chip, V3020_MINUTES, BIN2BCD(dt->tm_min));v3020_set_reg (chip,V3020_HOURS ,BIN2BCD (dt->tm_hour));v3020_set_reg (chip,V3020_MONTH_DAY ,BIN2BCD (dt->tm_mday)); -v3020_set_reg (chip,V3020_MONTH ,BIN2BCD (dt->tm_mon)); +v3020_set_reg (chip,V3020_MONTH ,BIN2BCD (dt->tm_mon) +1 );
This should be BIN2BCD(dt->tm_mon + 1)) instead. Otherwise, in october (month 9), the final value will be 0xa instead of 0x10.
Other than that, the patch looks fine to me. You can add
Please add Alessandro Zummo <[email protected]> in the CC list to make sure he sees it.
Best regards,
Raphaël Assénat
Mike Rapoport
Acked-by Raphael AssenatQuoted 5 lines · Raphaël Assénat
Quoted 3 lines · Mike Rapoport
Fix off-by-one in month calculations
Add delay for bus accesses to satisfy Tw > 500ns*snip*
Quoted 9 lines
Review static int v3020_set_time(struct device *dev, · line 144
Quoted 7 lines
(quoted diff) +1
-1@@ -135,7 +140,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt) v3020_set_reg(chip, V3020_MINUTES, BIN2BCD(dt->tm_min)); v3020_set_reg(chip, V3020_HOURS, BIN2BCD(dt->tm_hour)); v3020_set_reg(chip, V3020_MONTH_DAY, BIN2BCD(dt->tm_mday)); - v3020_set_reg(chip, V3020_MONTH, BIN2BCD(dt->tm_mon)); + v3020_set_reg(chip, V3020_MONTH, BIN2BCD(dt->tm_mon) + 1);This should be
BIN2BCD(dt->tm_mon + 1)) instead. Otherwise, in october (month 9), the final value will be0xainstead of0x10.
Fixed.
Quoted 7 lines
Other than that, the patch looks fine to me. You can add
Please add Alessandro Zummo <[email protected]> in the CC list to make sure he sees it.
Best regards,
Raphaël Assénat
drivers/rtc/rtc-v3020.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/rtc/rtc-v3020.c +7 -2
@@ -26,6 +26,7 @@#include <linux/types.h> #include <linux/bcd.h> #include <linux/rtc-v3020.h> +#include <linux/delay.h> #include <asm/io.h>
@@ -47,6 +48,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address,for (i =0 ; i <4 ; i++) {writel ((tmp &1 ) << chip->leftshift, chip->ioaddress); tmp >>=1 ; +udelay (1 ); }/* Commands dont have data */
@@ -54,6 +56,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address,for (i =0 ; i <8 ; i++) {writel ((data &1 ) << chip->leftshift, chip->ioaddress); data >>=1 ; +udelay (1 ); } } }
@@ -66,12 +69,14 @@ static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address)for (i =0 ; i <4 ; i++) {writel ((address &1 ) << chip->leftshift, chip->ioaddress); address >>=1 ; +udelay (1 ); }for (i =0 ; i <8 ; i++) { data >>=1 ;if (readl (chip->ioaddress) & (1 << chip->leftshift)) data |=0x80 ; +udelay (1 ); }return data;
@@ -95,7 +100,7 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt) tmp =v3020_get_reg (chip,V3020_MONTH_DAY ); dt->tm_mday =BCD2BIN (tmp); tmp =v3020_get_reg (chip,V3020_MONTH ); - dt->tm_mon =BCD2BIN (tmp); + dt->tm_mon =BCD2BIN (tmp) -1 ; tmp =v3020_get_reg (chip,V3020_WEEK_DAY ); dt->tm_wday =BCD2BIN (tmp); tmp =v3020_get_reg (chip,V3020_YEAR );
@@ -135,7 +140,7 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)v3020_set_reg (chip,V3020_MINUTES ,BIN2BCD (dt->tm_min));v3020_set_reg (chip,V3020_HOURS ,BIN2BCD (dt->tm_hour));v3020_set_reg (chip,V3020_MONTH_DAY ,BIN2BCD (dt->tm_mday)); -v3020_set_reg (chip,V3020_MONTH ,BIN2BCD (dt->tm_mon)); +v3020_set_reg (chip,V3020_MONTH ,BIN2BCD (dt->tm_mon +1 ));v3020_set_reg (chip,V3020_WEEK_DAY ,BIN2BCD (dt->tm_wday));v3020_set_reg (chip,V3020_YEAR ,BIN2BCD (dt->tm_year %100 ));
Signature · 2 lines
Sincerely yours, Mike.