diff options
-rw-r--r-- | arch/sparc/kernel/time.c | 27 | ||||
-rw-r--r-- | arch/sparc64/kernel/time.c | 33 | ||||
-rw-r--r-- | drivers/rtc/rtc-m48t59.c | 34 |
3 files changed, 39 insertions, 55 deletions
diff --git a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c index 62c1d94cb434..00f7383c7657 100644 --- a/arch/sparc/kernel/time.c +++ b/arch/sparc/kernel/time.c | |||
@@ -119,35 +119,16 @@ static unsigned char mostek_read_byte(struct device *dev, u32 ofs) | |||
119 | { | 119 | { |
120 | struct platform_device *pdev = to_platform_device(dev); | 120 | struct platform_device *pdev = to_platform_device(dev); |
121 | struct m48t59_plat_data *pdata = pdev->dev.platform_data; | 121 | struct m48t59_plat_data *pdata = pdev->dev.platform_data; |
122 | void __iomem *regs = pdata->ioaddr; | 122 | |
123 | unsigned char val = readb(regs + ofs); | 123 | return readb(pdata->ioaddr + 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 | } | 124 | } |
133 | 125 | ||
134 | static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) | 126 | static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) |
135 | { | 127 | { |
136 | struct platform_device *pdev = to_platform_device(dev); | 128 | struct platform_device *pdev = to_platform_device(dev); |
137 | struct m48t59_plat_data *pdata = pdev->dev.platform_data; | 129 | struct m48t59_plat_data *pdata = pdev->dev.platform_data; |
138 | void __iomem *regs = pdata->ioaddr; | 130 | |
139 | 131 | writeb(val, pdata->ioaddr + ofs); | |
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 | } | 132 | } |
152 | 133 | ||
153 | static struct m48t59_plat_data m48t59_data = { | 134 | static struct m48t59_plat_data m48t59_data = { |
diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c index 80d71a5ce1e3..dfd1b33e770a 100644 --- a/arch/sparc64/kernel/time.c +++ b/arch/sparc64/kernel/time.c | |||
@@ -503,39 +503,16 @@ static struct of_platform_driver bq4802_driver = { | |||
503 | static unsigned char mostek_read_byte(struct device *dev, u32 ofs) | 503 | static unsigned char mostek_read_byte(struct device *dev, u32 ofs) |
504 | { | 504 | { |
505 | struct platform_device *pdev = to_platform_device(dev); | 505 | struct platform_device *pdev = to_platform_device(dev); |
506 | struct m48t59_plat_data *pdata = pdev->dev.platform_data; | 506 | void __iomem *regs = (void __iomem *) pdev->resource[0].start; |
507 | void __iomem *regs; | 507 | |
508 | unsigned char val; | 508 | return readb(regs + ofs); |
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 | } | 509 | } |
521 | 510 | ||
522 | static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) | 511 | static void mostek_write_byte(struct device *dev, u32 ofs, u8 val) |
523 | { | 512 | { |
524 | struct platform_device *pdev = to_platform_device(dev); | 513 | struct platform_device *pdev = to_platform_device(dev); |
525 | struct m48t59_plat_data *pdata = pdev->dev.platform_data; | 514 | void __iomem *regs = (void __iomem *) pdev->resource[0].start; |
526 | void __iomem *regs; | 515 | |
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); | 516 | writeb(val, regs + ofs); |
540 | } | 517 | } |
541 | 518 | ||
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c index 04b63dab6932..43afb7ab5289 100644 --- a/drivers/rtc/rtc-m48t59.c +++ b/drivers/rtc/rtc-m48t59.c | |||
@@ -87,6 +87,10 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
87 | dev_dbg(dev, "Century bit is enabled\n"); | 87 | dev_dbg(dev, "Century bit is enabled\n"); |
88 | tm->tm_year += 100; /* one century */ | 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 | tm->tm_wday = bcd2bin(val & 0x07); | 95 | tm->tm_wday = bcd2bin(val & 0x07); |
92 | tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); | 96 | tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); |
@@ -110,11 +114,20 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
110 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); | 114 | struct m48t59_private *m48t59 = platform_get_drvdata(pdev); |
111 | unsigned long flags; | 115 | unsigned long flags; |
112 | u8 val = 0; | 116 | u8 val = 0; |
117 | int year = tm->tm_year; | ||
118 | |||
119 | #ifdef CONFIG_SPARC | ||
120 | /* Sun SPARC machines count years since 1968 */ | ||
121 | year -= 68; | ||
122 | #endif | ||
113 | 123 | ||
114 | dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n", | 124 | dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n", |
115 | tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, | 125 | year + 1900, tm->tm_mon, tm->tm_mday, |
116 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 126 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
117 | 127 | ||
128 | if (year < 0) | ||
129 | return -EINVAL; | ||
130 | |||
118 | spin_lock_irqsave(&m48t59->lock, flags); | 131 | spin_lock_irqsave(&m48t59->lock, flags); |
119 | /* Issue the WRITE command */ | 132 | /* Issue the WRITE command */ |
120 | M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL); | 133 | M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL); |
@@ -125,9 +138,9 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
125 | M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY); | 138 | M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY); |
126 | /* tm_mon is 0-11 */ | 139 | /* tm_mon is 0-11 */ |
127 | M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); | 140 | M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); |
128 | M48T59_WRITE(bin2bcd(tm->tm_year % 100), M48T59_YEAR); | 141 | M48T59_WRITE(bin2bcd(year % 100), M48T59_YEAR); |
129 | 142 | ||
130 | if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100)) | 143 | if (pdata->type == M48T59RTC_TYPE_M48T59 && (year / 100)) |
131 | val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); | 144 | val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); |
132 | val |= (bin2bcd(tm->tm_wday) & 0x07); | 145 | val |= (bin2bcd(tm->tm_wday) & 0x07); |
133 | M48T59_WRITE(val, M48T59_WDAY); | 146 | M48T59_WRITE(val, M48T59_WDAY); |
@@ -159,6 +172,10 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
159 | M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); | 172 | M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); |
160 | 173 | ||
161 | tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); | 174 | tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); |
175 | #ifdef CONFIG_SPARC | ||
176 | /* Sun SPARC machines count years since 1968 */ | ||
177 | tm->tm_year += 68; | ||
178 | #endif | ||
162 | /* tm_mon is 0-11 */ | 179 | /* tm_mon is 0-11 */ |
163 | tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; | 180 | tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; |
164 | 181 | ||
@@ -192,11 +209,20 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
192 | struct rtc_time *tm = &alrm->time; | 209 | struct rtc_time *tm = &alrm->time; |
193 | u8 mday, hour, min, sec; | 210 | u8 mday, hour, min, sec; |
194 | unsigned long flags; | 211 | unsigned long flags; |
212 | int year = tm->tm_year; | ||
213 | |||
214 | #ifdef CONFIG_SPARC | ||
215 | /* Sun SPARC machines count years since 1968 */ | ||
216 | year -= 68; | ||
217 | #endif | ||
195 | 218 | ||
196 | /* If no irq, we don't support ALARM */ | 219 | /* If no irq, we don't support ALARM */ |
197 | if (m48t59->irq == NO_IRQ) | 220 | if (m48t59->irq == NO_IRQ) |
198 | return -EIO; | 221 | return -EIO; |
199 | 222 | ||
223 | if (year < 0) | ||
224 | return -EINVAL; | ||
225 | |||
200 | /* | 226 | /* |
201 | * 0xff means "always match" | 227 | * 0xff means "always match" |
202 | */ | 228 | */ |
@@ -228,7 +254,7 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
228 | spin_unlock_irqrestore(&m48t59->lock, flags); | 254 | spin_unlock_irqrestore(&m48t59->lock, flags); |
229 | 255 | ||
230 | dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n", | 256 | dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n", |
231 | tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, | 257 | year + 1900, tm->tm_mon, tm->tm_mday, |
232 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 258 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
233 | return 0; | 259 | return 0; |
234 | } | 260 | } |