2006-03-27 17:16:45 +08:00
|
|
|
/*
|
|
|
|
* A driver for the RTC embedded in the Cirrus Logic EP93XX processors
|
|
|
|
* Copyright (c) 2006 Tower Technologies
|
|
|
|
*
|
|
|
|
* Author: Alessandro Zummo <a.zummo@towertech.it>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include <linux/platform_device.h>
|
2009-04-16 06:18:26 +08:00
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2009-04-16 06:18:26 +08:00
|
|
|
|
|
|
|
#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"
|
2006-03-27 17:16:45 +08:00
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
/*
|
|
|
|
* struct device dev.platform_data is used to store our private data
|
|
|
|
* because struct rtc_device does not have a variable to hold it.
|
|
|
|
*/
|
|
|
|
struct ep93xx_rtc {
|
|
|
|
void __iomem *mmio_base;
|
2011-08-10 21:11:26 +08:00
|
|
|
struct rtc_device *rtc;
|
2009-04-16 06:18:26 +08:00
|
|
|
};
|
2006-03-27 17:16:45 +08:00
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
|
2006-03-27 17:16:45 +08:00
|
|
|
unsigned short *delete)
|
|
|
|
{
|
2009-04-16 06:18:26 +08:00
|
|
|
struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
|
|
|
|
unsigned long comp;
|
|
|
|
|
|
|
|
comp = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
if (preload)
|
2009-04-16 06:18:26 +08:00
|
|
|
*preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK)
|
|
|
|
>> EP93XX_RTC_SWCOMP_INT_SHIFT;
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
if (delete)
|
2009-04-16 06:18:26 +08:00
|
|
|
*delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK)
|
|
|
|
>> EP93XX_RTC_SWCOMP_DEL_SHIFT;
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
2009-04-16 06:18:26 +08:00
|
|
|
struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
|
|
|
|
unsigned long time;
|
|
|
|
|
|
|
|
time = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
rtc_time_to_tm(time, tm);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
|
|
|
|
{
|
2009-04-16 06:18:26 +08:00
|
|
|
struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
|
|
|
|
|
|
|
|
__raw_writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
|
2006-03-27 17:16:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
|
|
|
|
{
|
|
|
|
unsigned short preload, delete;
|
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
ep93xx_rtc_get_swcomp(dev, &preload, &delete);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
seq_printf(seq, "preload\t\t: %d\n", preload);
|
|
|
|
seq_printf(seq, "delete\t\t: %d\n", delete);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-01 14:28:17 +08:00
|
|
|
static const struct rtc_class_ops ep93xx_rtc_ops = {
|
2006-03-27 17:16:45 +08:00
|
|
|
.read_time = ep93xx_rtc_read_time,
|
|
|
|
.set_mmss = ep93xx_rtc_set_mmss,
|
|
|
|
.proc = ep93xx_rtc_proc,
|
|
|
|
};
|
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev,
|
2006-03-27 17:16:45 +08:00
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned short preload;
|
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
ep93xx_rtc_get_swcomp(dev, &preload, NULL);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", preload);
|
|
|
|
}
|
2009-04-16 06:18:26 +08:00
|
|
|
static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
|
2006-03-27 17:16:45 +08:00
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned short delete;
|
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
ep93xx_rtc_get_swcomp(dev, NULL, &delete);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", delete);
|
|
|
|
}
|
2009-04-16 06:18:26 +08:00
|
|
|
static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
2010-03-06 05:44:20 +08:00
|
|
|
static struct attribute *ep93xx_rtc_attrs[] = {
|
|
|
|
&dev_attr_comp_preload.attr,
|
|
|
|
&dev_attr_comp_delete.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group ep93xx_rtc_sysfs_files = {
|
|
|
|
.attrs = ep93xx_rtc_attrs,
|
|
|
|
};
|
2006-03-27 17:16:45 +08:00
|
|
|
|
2012-12-22 05:09:38 +08:00
|
|
|
static int ep93xx_rtc_probe(struct platform_device *pdev)
|
2006-03-27 17:16:45 +08:00
|
|
|
{
|
2009-04-16 06:18:26 +08:00
|
|
|
struct ep93xx_rtc *ep93xx_rtc;
|
|
|
|
struct resource *res;
|
|
|
|
int err;
|
|
|
|
|
2010-03-06 05:44:20 +08:00
|
|
|
ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL);
|
|
|
|
if (!ep93xx_rtc)
|
2009-04-16 06:18:26 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-09-12 05:24:27 +08:00
|
|
|
ep93xx_rtc->mmio_base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(ep93xx_rtc->mmio_base))
|
|
|
|
return PTR_ERR(ep93xx_rtc->mmio_base);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
pdev->dev.platform_data = ep93xx_rtc;
|
2011-08-10 21:11:26 +08:00
|
|
|
platform_set_drvdata(pdev, ep93xx_rtc);
|
2009-04-16 06:18:26 +08:00
|
|
|
|
2013-04-30 07:19:02 +08:00
|
|
|
ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev,
|
|
|
|
pdev->name, &ep93xx_rtc_ops, THIS_MODULE);
|
2011-08-10 21:11:26 +08:00
|
|
|
if (IS_ERR(ep93xx_rtc->rtc)) {
|
|
|
|
err = PTR_ERR(ep93xx_rtc->rtc);
|
2010-03-06 05:44:20 +08:00
|
|
|
goto exit;
|
2006-03-27 17:16:45 +08:00
|
|
|
}
|
|
|
|
|
2010-03-06 05:44:20 +08:00
|
|
|
err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
|
2009-04-16 06:18:26 +08:00
|
|
|
if (err)
|
2013-04-30 07:19:02 +08:00
|
|
|
goto exit;
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
return 0;
|
2009-04-16 06:18:26 +08:00
|
|
|
|
2010-03-06 05:44:20 +08:00
|
|
|
exit:
|
|
|
|
pdev->dev.platform_data = NULL;
|
2009-04-16 06:18:26 +08:00
|
|
|
return err;
|
2006-03-27 17:16:45 +08:00
|
|
|
}
|
|
|
|
|
2012-12-22 05:09:38 +08:00
|
|
|
static int ep93xx_rtc_remove(struct platform_device *pdev)
|
2006-03-27 17:16:45 +08:00
|
|
|
{
|
2010-03-06 05:44:20 +08:00
|
|
|
sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
|
2009-04-16 06:18:26 +08:00
|
|
|
pdev->dev.platform_data = NULL;
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-16 06:18:26 +08:00
|
|
|
static struct platform_driver ep93xx_rtc_driver = {
|
2006-03-27 17:16:45 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "ep93xx-rtc",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
2012-05-30 06:07:36 +08:00
|
|
|
.probe = ep93xx_rtc_probe,
|
2012-12-22 05:09:38 +08:00
|
|
|
.remove = ep93xx_rtc_remove,
|
2006-03-27 17:16:45 +08:00
|
|
|
};
|
|
|
|
|
2012-05-30 06:07:36 +08:00
|
|
|
module_platform_driver(ep93xx_rtc_driver);
|
2006-03-27 17:16:45 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
|
|
|
|
MODULE_DESCRIPTION("EP93XX RTC driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(DRV_VERSION);
|
2012-05-30 06:07:36 +08:00
|
|
|
MODULE_ALIAS("platform:ep93xx-rtc");
|