rtc-m48t59: shift zero year to 1968 on sparc (rev 2)

Shift the first year to 1968 for Sun SPARC machines.

Move this logic from platform specific files to rtc driver
as this fixes problems with calculating a century bit.

Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Tested-by: Alexander Beregalov
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Krzysztof Helt and committed by David S. Miller 12a9ee3c be376649

+35 -51
+2 -21
arch/sparc/kernel/time.c
··· 119 { 120 struct platform_device *pdev = to_platform_device(dev); 121 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 122 - void __iomem *regs = pdata->ioaddr; 123 - unsigned char val = readb(regs + ofs); 124 125 - /* the year 0 is 1968 */ 126 - if (ofs == pdata->offset + M48T59_YEAR) { 127 - val += 0x68; 128 - if ((val & 0xf) > 9) 129 - val += 6; 130 - } 131 - return val; 132 } 133 134 static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) 135 { 136 struct platform_device *pdev = to_platform_device(dev); 137 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 138 - void __iomem *regs = pdata->ioaddr; 139 140 - if (ofs == pdata->offset + M48T59_YEAR) { 141 - if (val < 0x68) 142 - val += 0x32; 143 - else 144 - val -= 0x68; 145 - if ((val & 0xf) > 9) 146 - val += 6; 147 - if ((val & 0xf0) > 0x9A) 148 - val += 0x60; 149 - } 150 - writeb(val, regs + ofs); 151 } 152 153 static struct m48t59_plat_data m48t59_data = {
··· 119 { 120 struct platform_device *pdev = to_platform_device(dev); 121 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 122 123 + return readb(pdata->ioaddr + ofs); 124 } 125 126 static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) 127 { 128 struct platform_device *pdev = to_platform_device(dev); 129 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 130 131 + writeb(val, pdata->ioaddr + ofs); 132 } 133 134 static struct m48t59_plat_data m48t59_data = {
+3 -26
arch/sparc64/kernel/time.c
··· 503 static unsigned char mostek_read_byte(struct device *dev, u32 ofs) 504 { 505 struct platform_device *pdev = to_platform_device(dev); 506 - struct m48t59_plat_data *pdata = pdev->dev.platform_data; 507 - void __iomem *regs; 508 - unsigned char val; 509 510 - regs = (void __iomem *) pdev->resource[0].start; 511 - val = readb(regs + ofs); 512 - 513 - /* the year 0 is 1968 */ 514 - if (ofs == pdata->offset + M48T59_YEAR) { 515 - val += 0x68; 516 - if ((val & 0xf) > 9) 517 - val += 6; 518 - } 519 - return val; 520 } 521 522 static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) 523 { 524 struct platform_device *pdev = to_platform_device(dev); 525 - struct m48t59_plat_data *pdata = pdev->dev.platform_data; 526 - void __iomem *regs; 527 528 - regs = (void __iomem *) pdev->resource[0].start; 529 - if (ofs == pdata->offset + M48T59_YEAR) { 530 - if (val < 0x68) 531 - val += 0x32; 532 - else 533 - val -= 0x68; 534 - if ((val & 0xf) > 9) 535 - val += 6; 536 - if ((val & 0xf0) > 0x9A) 537 - val += 0x60; 538 - } 539 writeb(val, regs + ofs); 540 } 541
··· 503 static unsigned char mostek_read_byte(struct device *dev, u32 ofs) 504 { 505 struct platform_device *pdev = to_platform_device(dev); 506 + void __iomem *regs = (void __iomem *) pdev->resource[0].start; 507 508 + return readb(regs + ofs); 509 } 510 511 static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) 512 { 513 struct platform_device *pdev = to_platform_device(dev); 514 + void __iomem *regs = (void __iomem *) pdev->resource[0].start; 515 516 writeb(val, regs + ofs); 517 } 518
+30 -4
drivers/rtc/rtc-m48t59.c
··· 87 dev_dbg(dev, "Century bit is enabled\n"); 88 tm->tm_year += 100; /* one century */ 89 } 90 91 tm->tm_wday = bcd2bin(val & 0x07); 92 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); ··· 114 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 115 unsigned long flags; 116 u8 val = 0; 117 118 dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n", 119 - tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 120 tm->tm_hour, tm->tm_min, tm->tm_sec); 121 122 spin_lock_irqsave(&m48t59->lock, flags); 123 /* Issue the WRITE command */ ··· 138 M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY); 139 /* tm_mon is 0-11 */ 140 M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); 141 - M48T59_WRITE(bin2bcd(tm->tm_year % 100), M48T59_YEAR); 142 143 - if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100)) 144 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); 145 val |= (bin2bcd(tm->tm_wday) & 0x07); 146 M48T59_WRITE(val, M48T59_WDAY); ··· 172 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 173 174 tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); 175 /* tm_mon is 0-11 */ 176 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; 177 ··· 209 struct rtc_time *tm = &alrm->time; 210 u8 mday, hour, min, sec; 211 unsigned long flags; 212 213 /* If no irq, we don't support ALARM */ 214 if (m48t59->irq == NO_IRQ) 215 return -EIO; 216 217 /* 218 * 0xff means "always match" ··· 254 spin_unlock_irqrestore(&m48t59->lock, flags); 255 256 dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n", 257 - tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 258 tm->tm_hour, tm->tm_min, tm->tm_sec); 259 return 0; 260 }
··· 87 dev_dbg(dev, "Century bit is enabled\n"); 88 tm->tm_year += 100; /* one century */ 89 } 90 + #ifdef CONFIG_SPARC 91 + /* Sun SPARC machines count years since 1968 */ 92 + tm->tm_year += 68; 93 + #endif 94 95 tm->tm_wday = bcd2bin(val & 0x07); 96 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); ··· 110 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 111 unsigned long flags; 112 u8 val = 0; 113 + int year = tm->tm_year; 114 + 115 + #ifdef CONFIG_SPARC 116 + /* Sun SPARC machines count years since 1968 */ 117 + year -= 68; 118 + #endif 119 120 dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n", 121 + year + 1900, tm->tm_mon, tm->tm_mday, 122 tm->tm_hour, tm->tm_min, tm->tm_sec); 123 + 124 + if (year < 0) 125 + return -EINVAL; 126 127 spin_lock_irqsave(&m48t59->lock, flags); 128 /* Issue the WRITE command */ ··· 125 M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY); 126 /* tm_mon is 0-11 */ 127 M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); 128 + M48T59_WRITE(bin2bcd(year % 100), M48T59_YEAR); 129 130 + if (pdata->type == M48T59RTC_TYPE_M48T59 && (year / 100)) 131 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); 132 val |= (bin2bcd(tm->tm_wday) & 0x07); 133 M48T59_WRITE(val, M48T59_WDAY); ··· 159 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 160 161 tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); 162 + #ifdef CONFIG_SPARC 163 + /* Sun SPARC machines count years since 1968 */ 164 + tm->tm_year += 68; 165 + #endif 166 /* tm_mon is 0-11 */ 167 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; 168 ··· 192 struct rtc_time *tm = &alrm->time; 193 u8 mday, hour, min, sec; 194 unsigned long flags; 195 + int year = tm->tm_year; 196 + 197 + #ifdef CONFIG_SPARC 198 + /* Sun SPARC machines count years since 1968 */ 199 + year -= 68; 200 + #endif 201 202 /* If no irq, we don't support ALARM */ 203 if (m48t59->irq == NO_IRQ) 204 return -EIO; 205 + 206 + if (year < 0) 207 + return -EINVAL; 208 209 /* 210 * 0xff means "always match" ··· 228 spin_unlock_irqrestore(&m48t59->lock, flags); 229 230 dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n", 231 + year + 1900, tm->tm_mon, tm->tm_mday, 232 tm->tm_hour, tm->tm_min, tm->tm_sec); 233 return 0; 234 }