Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 42923
b: refs/heads/master
c: f9231a0
h: refs/heads/master
i:
  42921: bbf302a
  42919: 0ebb3d6
v: v3
  • Loading branch information
Torsten Ertbjerg Rasmussen authored and Linus Torvalds committed Dec 7, 2006
1 parent 4e0d5e2 commit fef15fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 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: 3908fd2ed920af818aa596672da68ba26173ff27
refs/heads/master: f9231a0ca1afd05543d9f83539d6ecd5c018e8cf
4 changes: 2 additions & 2 deletions trunk/drivers/rtc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ config RTC_DRV_DS1672
will be called rtc-ds1672.

config RTC_DRV_DS1742
tristate "Dallas DS1742"
tristate "Dallas DS1742/1743"
depends on RTC_CLASS
help
If you say yes here you get support for the
Dallas DS1742 timekeeping chip.
Dallas DS1742/1743 timekeeping chip.

This driver can also be built as a module. If so, the module
will be called rtc-ds1742.
Expand Down
67 changes: 39 additions & 28 deletions trunk/drivers/rtc/rtc-ds1742.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Copyright (C) 2006 Torsten Ertbjerg Rasmussen <tr@newtec.dk>
* - nvram size determined from resource
* - this ds1742 driver now supports ds1743.
*/

#include <linux/bcd.h>
Expand All @@ -17,20 +21,19 @@
#include <linux/platform_device.h>
#include <linux/io.h>

#define DRV_VERSION "0.2"
#define DRV_VERSION "0.3"

#define RTC_REG_SIZE 0x800
#define RTC_OFFSET 0x7f8
#define RTC_SIZE 8

#define RTC_CONTROL (RTC_OFFSET + 0)
#define RTC_CENTURY (RTC_OFFSET + 0)
#define RTC_SECONDS (RTC_OFFSET + 1)
#define RTC_MINUTES (RTC_OFFSET + 2)
#define RTC_HOURS (RTC_OFFSET + 3)
#define RTC_DAY (RTC_OFFSET + 4)
#define RTC_DATE (RTC_OFFSET + 5)
#define RTC_MONTH (RTC_OFFSET + 6)
#define RTC_YEAR (RTC_OFFSET + 7)
#define RTC_CONTROL 0
#define RTC_CENTURY 0
#define RTC_SECONDS 1
#define RTC_MINUTES 2
#define RTC_HOURS 3
#define RTC_DAY 4
#define RTC_DATE 5
#define RTC_MONTH 6
#define RTC_YEAR 7

#define RTC_CENTURY_MASK 0x3f
#define RTC_SECONDS_MASK 0x7f
Expand All @@ -48,7 +51,10 @@

struct rtc_plat_data {
struct rtc_device *rtc;
void __iomem *ioaddr;
void __iomem *ioaddr_nvram;
void __iomem *ioaddr_rtc;
size_t size_nvram;
size_t size;
unsigned long baseaddr;
unsigned long last_jiffies;
};
Expand All @@ -57,7 +63,7 @@ static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct platform_device *pdev = to_platform_device(dev);
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
void __iomem *ioaddr = pdata->ioaddr;
void __iomem *ioaddr = pdata->ioaddr_rtc;
u8 century;

century = BIN2BCD((tm->tm_year + 1900) / 100);
Expand All @@ -82,7 +88,7 @@ static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct platform_device *pdev = to_platform_device(dev);
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
void __iomem *ioaddr = pdata->ioaddr;
void __iomem *ioaddr = pdata->ioaddr_rtc;
unsigned int year, month, day, hour, minute, second, week;
unsigned int century;

Expand Down Expand Up @@ -127,10 +133,10 @@ static ssize_t ds1742_nvram_read(struct kobject *kobj, char *buf,
struct platform_device *pdev =
to_platform_device(container_of(kobj, struct device, kobj));
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
void __iomem *ioaddr = pdata->ioaddr;
void __iomem *ioaddr = pdata->ioaddr_nvram;
ssize_t count;

for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--)
*buf++ = readb(ioaddr + pos++);
return count;
}
Expand All @@ -141,10 +147,10 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj, char *buf,
struct platform_device *pdev =
to_platform_device(container_of(kobj, struct device, kobj));
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
void __iomem *ioaddr = pdata->ioaddr;
void __iomem *ioaddr = pdata->ioaddr_nvram;
ssize_t count;

for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--)
writeb(*buf++, ioaddr + pos++);
return count;
}
Expand All @@ -155,7 +161,6 @@ static struct bin_attribute ds1742_nvram_attr = {
.mode = S_IRUGO | S_IWUGO,
.owner = THIS_MODULE,
},
.size = RTC_OFFSET,
.read = ds1742_nvram_read,
.write = ds1742_nvram_write,
};
Expand All @@ -175,19 +180,23 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev)
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) {
pdata->size = res->end - res->start + 1;
if (!request_mem_region(res->start, pdata->size, pdev->name)) {
ret = -EBUSY;
goto out;
}
pdata->baseaddr = res->start;
ioaddr = ioremap(pdata->baseaddr, RTC_REG_SIZE);
ioaddr = ioremap(pdata->baseaddr, pdata->size);
if (!ioaddr) {
ret = -ENOMEM;
goto out;
}
pdata->ioaddr = ioaddr;
pdata->ioaddr_nvram = ioaddr;
pdata->size_nvram = pdata->size - RTC_SIZE;
pdata->ioaddr_rtc = ioaddr + pdata->size_nvram;

/* turn RTC on if it was not on */
ioaddr = pdata->ioaddr_rtc;
sec = readb(ioaddr + RTC_SECONDS);
if (sec & RTC_STOP) {
sec &= RTC_SECONDS_MASK;
Expand All @@ -208,17 +217,19 @@ static int __init ds1742_rtc_probe(struct platform_device *pdev)
pdata->rtc = rtc;
pdata->last_jiffies = jiffies;
platform_set_drvdata(pdev, pdata);
ds1742_nvram_attr.size = max(ds1742_nvram_attr.size,
pdata->size_nvram);
ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr);
if (ret)
goto out;
return 0;
out:
if (pdata->rtc)
rtc_device_unregister(pdata->rtc);
if (ioaddr)
iounmap(ioaddr);
if (pdata->ioaddr_nvram)
iounmap(pdata->ioaddr_nvram);
if (pdata->baseaddr)
release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
release_mem_region(pdata->baseaddr, pdata->size);
kfree(pdata);
return ret;
}
Expand All @@ -229,8 +240,8 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev)

sysfs_remove_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr);
rtc_device_unregister(pdata->rtc);
iounmap(pdata->ioaddr);
release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
iounmap(pdata->ioaddr_nvram);
release_mem_region(pdata->baseaddr, pdata->size);
kfree(pdata);
return 0;
}
Expand Down

0 comments on commit fef15fe

Please sign in to comment.