Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 118232
b: refs/heads/master
c: 12a9ee3
h: refs/heads/master
v: v3
  • Loading branch information
Krzysztof Helt authored and David S. Miller committed Oct 29, 2008
1 parent e566523 commit 10403ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 56 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: be376649344ba2c3d00021f8bbf64392aa01ad55
refs/heads/master: 12a9ee3cce256ae0f178d604f2c8764fb2942cfe
27 changes: 4 additions & 23 deletions trunk/arch/sparc/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,16 @@ static unsigned char mostek_read_byte(struct device *dev, u32 ofs)
{
struct platform_device *pdev = to_platform_device(dev);
struct m48t59_plat_data *pdata = pdev->dev.platform_data;
void __iomem *regs = pdata->ioaddr;
unsigned char val = readb(regs + ofs);

/* the year 0 is 1968 */
if (ofs == pdata->offset + M48T59_YEAR) {
val += 0x68;
if ((val & 0xf) > 9)
val += 6;
}
return val;

return readb(pdata->ioaddr + ofs);
}

static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
{
struct platform_device *pdev = to_platform_device(dev);
struct m48t59_plat_data *pdata = pdev->dev.platform_data;
void __iomem *regs = pdata->ioaddr;

if (ofs == pdata->offset + M48T59_YEAR) {
if (val < 0x68)
val += 0x32;
else
val -= 0x68;
if ((val & 0xf) > 9)
val += 6;
if ((val & 0xf0) > 0x9A)
val += 0x60;
}
writeb(val, regs + ofs);

writeb(val, pdata->ioaddr + ofs);
}

static struct m48t59_plat_data m48t59_data = {
Expand Down
33 changes: 5 additions & 28 deletions trunk/arch/sparc64/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,39 +503,16 @@ static struct of_platform_driver bq4802_driver = {
static unsigned char mostek_read_byte(struct device *dev, u32 ofs)
{
struct platform_device *pdev = to_platform_device(dev);
struct m48t59_plat_data *pdata = pdev->dev.platform_data;
void __iomem *regs;
unsigned char val;

regs = (void __iomem *) pdev->resource[0].start;
val = readb(regs + ofs);

/* the year 0 is 1968 */
if (ofs == pdata->offset + M48T59_YEAR) {
val += 0x68;
if ((val & 0xf) > 9)
val += 6;
}
return val;
void __iomem *regs = (void __iomem *) pdev->resource[0].start;

return readb(regs + ofs);
}

static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
{
struct platform_device *pdev = to_platform_device(dev);
struct m48t59_plat_data *pdata = pdev->dev.platform_data;
void __iomem *regs;

regs = (void __iomem *) pdev->resource[0].start;
if (ofs == pdata->offset + M48T59_YEAR) {
if (val < 0x68)
val += 0x32;
else
val -= 0x68;
if ((val & 0xf) > 9)
val += 6;
if ((val & 0xf0) > 0x9A)
val += 0x60;
}
void __iomem *regs = (void __iomem *) pdev->resource[0].start;

writeb(val, regs + ofs);
}

Expand Down
34 changes: 30 additions & 4 deletions trunk/drivers/rtc/rtc-m48t59.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
dev_dbg(dev, "Century bit is enabled\n");
tm->tm_year += 100; /* one century */
}
#ifdef CONFIG_SPARC
/* Sun SPARC machines count years since 1968 */
tm->tm_year += 68;
#endif

tm->tm_wday = bcd2bin(val & 0x07);
tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F);
Expand All @@ -110,11 +114,20 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
unsigned long flags;
u8 val = 0;
int year = tm->tm_year;

#ifdef CONFIG_SPARC
/* Sun SPARC machines count years since 1968 */
year -= 68;
#endif

dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
year + 1900, tm->tm_mon, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);

if (year < 0)
return -EINVAL;

spin_lock_irqsave(&m48t59->lock, flags);
/* Issue the WRITE command */
M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
Expand All @@ -125,9 +138,9 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY);
/* tm_mon is 0-11 */
M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH);
M48T59_WRITE(bin2bcd(tm->tm_year % 100), M48T59_YEAR);
M48T59_WRITE(bin2bcd(year % 100), M48T59_YEAR);

if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100))
if (pdata->type == M48T59RTC_TYPE_M48T59 && (year / 100))
val = (M48T59_WDAY_CEB | M48T59_WDAY_CB);
val |= (bin2bcd(tm->tm_wday) & 0x07);
M48T59_WRITE(val, M48T59_WDAY);
Expand Down Expand Up @@ -159,6 +172,10 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);

tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
#ifdef CONFIG_SPARC
/* Sun SPARC machines count years since 1968 */
tm->tm_year += 68;
#endif
/* tm_mon is 0-11 */
tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;

Expand Down Expand Up @@ -192,11 +209,20 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
struct rtc_time *tm = &alrm->time;
u8 mday, hour, min, sec;
unsigned long flags;
int year = tm->tm_year;

#ifdef CONFIG_SPARC
/* Sun SPARC machines count years since 1968 */
year -= 68;
#endif

/* If no irq, we don't support ALARM */
if (m48t59->irq == NO_IRQ)
return -EIO;

if (year < 0)
return -EINVAL;

/*
* 0xff means "always match"
*/
Expand Down Expand Up @@ -228,7 +254,7 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
spin_unlock_irqrestore(&m48t59->lock, flags);

dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
year + 1900, tm->tm_mon, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
return 0;
}
Expand Down

0 comments on commit 10403ce

Please sign in to comment.