Commit 38f7b009 authored by Hartley Sweeten's avatar Hartley Sweeten Committed by Russell King

[ARM] 5452/1: ep93x: rtc: use ioremap'ed addresses

Update the rtc-ep93xx driver to use ioremap'ed addresses.

This removes the dependency on <mach/hardware.h> and properly
reports the memory addresses used by the driver in /proc/iomem.

In addition, ep93xx_rtc_init() is updated to use
platform_driver_probe() instead of platform_driver_register().

Also, the device_create_file() calls are now properly checked for
error conditions.  The created sysfs files are also now removed
when the driver is removed.

The version number for the driver has been bumped at the request
of Alessandro Zummo.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 924a158a
...@@ -450,10 +450,19 @@ static struct amba_device uart3_device = { ...@@ -450,10 +450,19 @@ static struct amba_device uart3_device = {
}; };
static struct resource ep93xx_rtc_resource[] = {
{
.start = EP93XX_RTC_PHYS_BASE,
.end = EP93XX_RTC_PHYS_BASE + 0x10c - 1,
.flags = IORESOURCE_MEM,
},
};
static struct platform_device ep93xx_rtc_device = { static struct platform_device ep93xx_rtc_device = {
.name = "ep93xx-rtc", .name = "ep93xx-rtc",
.id = -1, .id = -1,
.num_resources = 0, .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
.resource = ep93xx_rtc_resource,
}; };
......
...@@ -147,6 +147,7 @@ ...@@ -147,6 +147,7 @@
#define EP93XX_PWM_BASE (EP93XX_APB_VIRT_BASE + 0x00110000) #define EP93XX_PWM_BASE (EP93XX_APB_VIRT_BASE + 0x00110000)
#define EP93XX_RTC_BASE (EP93XX_APB_VIRT_BASE + 0x00120000) #define EP93XX_RTC_BASE (EP93XX_APB_VIRT_BASE + 0x00120000)
#define EP93XX_RTC_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00120000)
#define EP93XX_SYSCON_BASE (EP93XX_APB_VIRT_BASE + 0x00130000) #define EP93XX_SYSCON_BASE (EP93XX_APB_VIRT_BASE + 0x00130000)
#define EP93XX_SYSCON_REG(x) (EP93XX_SYSCON_BASE + (x)) #define EP93XX_SYSCON_REG(x) (EP93XX_SYSCON_BASE + (x))
......
...@@ -12,32 +12,56 @@ ...@@ -12,32 +12,56 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <mach/hardware.h> #include <linux/io.h>
#define EP93XX_RTC_DATA 0x000
#define EP93XX_RTC_MATCH 0x004
#define EP93XX_RTC_STATUS 0x008
#define EP93XX_RTC_STATUS_INTR (1<<0)
#define EP93XX_RTC_LOAD 0x00C
#define EP93XX_RTC_CONTROL 0x010
#define EP93XX_RTC_CONTROL_MIE (1<<0)
#define EP93XX_RTC_SWCOMP 0x108
#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
#define EP93XX_RTC_SWCOMP_INT_SHIFT 0
#define DRV_VERSION "0.3"
#define EP93XX_RTC_REG(x) (EP93XX_RTC_BASE + (x)) /*
#define EP93XX_RTC_DATA EP93XX_RTC_REG(0x0000) * struct device dev.platform_data is used to store our private data
#define EP93XX_RTC_LOAD EP93XX_RTC_REG(0x000C) * because struct rtc_device does not have a variable to hold it.
#define EP93XX_RTC_SWCOMP EP93XX_RTC_REG(0x0108) */
struct ep93xx_rtc {
#define DRV_VERSION "0.2" void __iomem *mmio_base;
};
static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload, static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
unsigned short *delete) unsigned short *delete)
{ {
unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP); struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
unsigned long comp;
comp = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
if (preload) if (preload)
*preload = comp & 0xffff; *preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK)
>> EP93XX_RTC_SWCOMP_INT_SHIFT;
if (delete) if (delete)
*delete = (comp >> 16) & 0x1f; *delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK)
>> EP93XX_RTC_SWCOMP_DEL_SHIFT;
return 0; return 0;
} }
static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
{ {
unsigned long time = __raw_readl(EP93XX_RTC_DATA); struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
unsigned long time;
time = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
rtc_time_to_tm(time, tm); rtc_time_to_tm(time, tm);
return 0; return 0;
...@@ -45,7 +69,9 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -45,7 +69,9 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
{ {
__raw_writel(secs + 1, EP93XX_RTC_LOAD); struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
__raw_writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
return 0; return 0;
} }
...@@ -53,7 +79,7 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq) ...@@ -53,7 +79,7 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
{ {
unsigned short preload, delete; unsigned short preload, delete;
ep93xx_get_swcomp(dev, &preload, &delete); ep93xx_rtc_get_swcomp(dev, &preload, &delete);
seq_printf(seq, "preload\t\t: %d\n", preload); seq_printf(seq, "preload\t\t: %d\n", preload);
seq_printf(seq, "delete\t\t: %d\n", delete); seq_printf(seq, "delete\t\t: %d\n", delete);
...@@ -67,54 +93,104 @@ static const struct rtc_class_ops ep93xx_rtc_ops = { ...@@ -67,54 +93,104 @@ static const struct rtc_class_ops ep93xx_rtc_ops = {
.proc = ep93xx_rtc_proc, .proc = ep93xx_rtc_proc,
}; };
static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev, static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
unsigned short preload; unsigned short preload;
ep93xx_get_swcomp(dev, &preload, NULL); ep93xx_rtc_get_swcomp(dev, &preload, NULL);
return sprintf(buf, "%d\n", preload); return sprintf(buf, "%d\n", preload);
} }
static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL); static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL);
static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev, static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
unsigned short delete; unsigned short delete;
ep93xx_get_swcomp(dev, NULL, &delete); ep93xx_rtc_get_swcomp(dev, NULL, &delete);
return sprintf(buf, "%d\n", delete); return sprintf(buf, "%d\n", delete);
} }
static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL); static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
static int __devinit ep93xx_rtc_probe(struct platform_device *dev) static int __init ep93xx_rtc_probe(struct platform_device *pdev)
{ {
struct rtc_device *rtc = rtc_device_register("ep93xx", struct ep93xx_rtc *ep93xx_rtc;
&dev->dev, &ep93xx_rtc_ops, THIS_MODULE); struct resource *res;
struct rtc_device *rtc;
int err;
ep93xx_rtc = kzalloc(sizeof(struct ep93xx_rtc), GFP_KERNEL);
if (ep93xx_rtc == NULL)
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL)
return -ENXIO;
res = request_mem_region(res->start, resource_size(res), pdev->name);
if (res == NULL)
return -EBUSY;
ep93xx_rtc->mmio_base = ioremap(res->start, resource_size(res));
if (ep93xx_rtc->mmio_base == NULL) {
err = -ENXIO;
goto fail;
}
pdev->dev.platform_data = ep93xx_rtc;
rtc = rtc_device_register(pdev->name,
&pdev->dev, &ep93xx_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) { if (IS_ERR(rtc)) {
return PTR_ERR(rtc); err = PTR_ERR(rtc);
goto fail;
} }
platform_set_drvdata(dev, rtc); platform_set_drvdata(pdev, rtc);
device_create_file(&dev->dev, &dev_attr_comp_preload); err = device_create_file(&pdev->dev, &dev_attr_comp_preload);
device_create_file(&dev->dev, &dev_attr_comp_delete); if (err)
goto fail;
err = device_create_file(&pdev->dev, &dev_attr_comp_delete);
if (err) {
device_remove_file(&pdev->dev, &dev_attr_comp_preload);
goto fail;
}
return 0; return 0;
fail:
if (ep93xx_rtc->mmio_base) {
iounmap(ep93xx_rtc->mmio_base);
pdev->dev.platform_data = NULL;
}
release_mem_region(res->start, resource_size(res));
return err;
} }
static int __devexit ep93xx_rtc_remove(struct platform_device *dev) static int __exit ep93xx_rtc_remove(struct platform_device *pdev)
{ {
struct rtc_device *rtc = platform_get_drvdata(dev); struct rtc_device *rtc = platform_get_drvdata(pdev);
struct ep93xx_rtc *ep93xx_rtc = pdev->dev.platform_data;
struct resource *res;
/* cleanup sysfs */
device_remove_file(&pdev->dev, &dev_attr_comp_delete);
device_remove_file(&pdev->dev, &dev_attr_comp_preload);
if (rtc)
rtc_device_unregister(rtc); rtc_device_unregister(rtc);
platform_set_drvdata(dev, NULL); iounmap(ep93xx_rtc->mmio_base);
pdev->dev.platform_data = NULL;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
platform_set_drvdata(pdev, NULL);
return 0; return 0;
} }
...@@ -122,23 +198,22 @@ static int __devexit ep93xx_rtc_remove(struct platform_device *dev) ...@@ -122,23 +198,22 @@ static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
/* work with hotplug and coldplug */ /* work with hotplug and coldplug */
MODULE_ALIAS("platform:ep93xx-rtc"); MODULE_ALIAS("platform:ep93xx-rtc");
static struct platform_driver ep93xx_rtc_platform_driver = { static struct platform_driver ep93xx_rtc_driver = {
.driver = { .driver = {
.name = "ep93xx-rtc", .name = "ep93xx-rtc",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.probe = ep93xx_rtc_probe, .remove = __exit_p(ep93xx_rtc_remove),
.remove = __devexit_p(ep93xx_rtc_remove),
}; };
static int __init ep93xx_rtc_init(void) static int __init ep93xx_rtc_init(void)
{ {
return platform_driver_register(&ep93xx_rtc_platform_driver); return platform_driver_probe(&ep93xx_rtc_driver, ep93xx_rtc_probe);
} }
static void __exit ep93xx_rtc_exit(void) static void __exit ep93xx_rtc_exit(void)
{ {
platform_driver_unregister(&ep93xx_rtc_platform_driver); platform_driver_unregister(&ep93xx_rtc_driver);
} }
MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment