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