2009-09-23 06:46:24 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2009 ST-Ericsson AB
|
|
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
|
|
* Real Time Clock interface for ST-Ericsson AB COH 901 331 RTC.
|
|
|
|
* Author: Linus Walleij <linus.walleij@stericsson.com>
|
|
|
|
* Based on rtc-pl031.c by Deepak Saxena <dsaxena@plexity.net>
|
|
|
|
* Copyright 2006 (c) MontaVista Software, Inc.
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
2018-06-20 12:47:28 +07:00
|
|
|
#include <linux/mod_devicetable.h>
|
2009-09-23 06:46:24 +07:00
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-09-23 06:46:24 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Registers in the COH 901 331
|
|
|
|
*/
|
|
|
|
/* Alarm value 32bit (R/W) */
|
|
|
|
#define COH901331_ALARM 0x00U
|
|
|
|
/* Used to set current time 32bit (R/W) */
|
|
|
|
#define COH901331_SET_TIME 0x04U
|
|
|
|
/* Indication if current time is valid 32bit (R/-) */
|
|
|
|
#define COH901331_VALID 0x08U
|
|
|
|
/* Read the current time 32bit (R/-) */
|
|
|
|
#define COH901331_CUR_TIME 0x0cU
|
|
|
|
/* Event register for the "alarm" interrupt */
|
|
|
|
#define COH901331_IRQ_EVENT 0x10U
|
|
|
|
/* Mask register for the "alarm" interrupt */
|
|
|
|
#define COH901331_IRQ_MASK 0x14U
|
|
|
|
/* Force register for the "alarm" interrupt */
|
|
|
|
#define COH901331_IRQ_FORCE 0x18U
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reference to RTC block clock
|
|
|
|
* Notice that the frequent clk_enable()/clk_disable() on this
|
|
|
|
* clock is mainly to be able to turn on/off other clocks in the
|
|
|
|
* hierarchy as needed, the RTC clock is always on anyway.
|
|
|
|
*/
|
|
|
|
struct coh901331_port {
|
|
|
|
struct rtc_device *rtc;
|
|
|
|
struct clk *clk;
|
|
|
|
void __iomem *virtbase;
|
|
|
|
int irq;
|
2013-04-30 06:21:00 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2009-09-23 06:46:24 +07:00
|
|
|
u32 irqmaskstore;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t coh901331_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct coh901331_port *rtap = data;
|
|
|
|
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
/* Ack IRQ */
|
|
|
|
writel(1, rtap->virtbase + COH901331_IRQ_EVENT);
|
2009-11-14 07:03:24 +07:00
|
|
|
/*
|
|
|
|
* Disable the interrupt. This is necessary because
|
|
|
|
* the RTC lives on a lower-clocked line and will
|
|
|
|
* not release the IRQ line until after a few (slower)
|
|
|
|
* clock cycles. The interrupt will be re-enabled when
|
|
|
|
* a new alarm is set anyway.
|
|
|
|
*/
|
|
|
|
writel(0, rtap->virtbase + COH901331_IRQ_MASK);
|
2009-09-23 06:46:24 +07:00
|
|
|
clk_disable(rtap->clk);
|
2009-11-14 07:03:24 +07:00
|
|
|
|
2009-09-23 06:46:24 +07:00
|
|
|
/* Set alarm flag */
|
|
|
|
rtc_update_irq(rtap->rtc, 1, RTC_AF);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coh901331_read_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
/* Check if the time is valid */
|
|
|
|
if (readl(rtap->virtbase + COH901331_VALID)) {
|
|
|
|
rtc_time_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
|
|
|
|
clk_disable(rtap->clk);
|
2018-02-19 22:23:55 +07:00
|
|
|
return 0;
|
2009-09-23 06:46:24 +07:00
|
|
|
}
|
|
|
|
clk_disable(rtap->clk);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coh901331_set_mmss(struct device *dev, unsigned long secs)
|
|
|
|
{
|
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
writel(secs, rtap->virtbase + COH901331_SET_TIME);
|
|
|
|
clk_disable(rtap->clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
|
|
|
|
{
|
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
rtc_time_to_tm(readl(rtap->virtbase + COH901331_ALARM), &alarm->time);
|
|
|
|
alarm->pending = readl(rtap->virtbase + COH901331_IRQ_EVENT) & 1U;
|
|
|
|
alarm->enabled = readl(rtap->virtbase + COH901331_IRQ_MASK) & 1U;
|
|
|
|
clk_disable(rtap->clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coh901331_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
|
|
|
|
{
|
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
|
|
|
unsigned long time;
|
|
|
|
|
|
|
|
rtc_tm_to_time(&alarm->time, &time);
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
writel(time, rtap->virtbase + COH901331_ALARM);
|
|
|
|
writel(alarm->enabled, rtap->virtbase + COH901331_IRQ_MASK);
|
|
|
|
clk_disable(rtap->clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int coh901331_alarm_irq_enable(struct device *dev, unsigned int enabled)
|
|
|
|
{
|
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
if (enabled)
|
|
|
|
writel(1, rtap->virtbase + COH901331_IRQ_MASK);
|
|
|
|
else
|
|
|
|
writel(0, rtap->virtbase + COH901331_IRQ_MASK);
|
|
|
|
clk_disable(rtap->clk);
|
2009-11-14 07:03:24 +07:00
|
|
|
|
|
|
|
return 0;
|
2009-09-23 06:46:24 +07:00
|
|
|
}
|
|
|
|
|
rtc: constify rtc_class_ops structures
Check for rtc_class_ops structures that are only passed to
devm_rtc_device_register, rtc_device_register,
platform_device_register_data, all of which declare the corresponding
parameter as const. Declare rtc_class_ops structures that have these
properties as const.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r disable optional_qualifier@
identifier i;
position p;
@@
static struct rtc_class_ops i@p = { ... };
@ok@
identifier r.i;
expression e1,e2,e3,e4;
position p;
@@
(
devm_rtc_device_register(e1,e2,&i@p,e3)
|
rtc_device_register(e1,e2,&i@p,e3)
|
platform_device_register_data(e1,e2,e3,&i@p,e4)
)
@bad@
position p != {r.p,ok.p};
identifier r.i;
@@
i@p
@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
struct rtc_class_ops i = { ... };
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Baruch Siach <baruch@tkos.co.il>
Acked-by: Hans Ulli Kroll <ulli.kroll@googlemail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
2016-08-31 15:05:25 +07:00
|
|
|
static const struct rtc_class_ops coh901331_ops = {
|
2009-09-23 06:46:24 +07:00
|
|
|
.read_time = coh901331_read_time,
|
|
|
|
.set_mmss = coh901331_set_mmss,
|
|
|
|
.read_alarm = coh901331_read_alarm,
|
|
|
|
.set_alarm = coh901331_set_alarm,
|
|
|
|
.alarm_irq_enable = coh901331_alarm_irq_enable,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __exit coh901331_remove(struct platform_device *pdev)
|
|
|
|
{
|
2013-07-04 05:07:12 +07:00
|
|
|
struct coh901331_port *rtap = platform_get_drvdata(pdev);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
2013-07-04 05:06:16 +07:00
|
|
|
if (rtap)
|
2012-07-31 04:41:31 +07:00
|
|
|
clk_unprepare(rtap->clk);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int __init coh901331_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct coh901331_port *rtap;
|
|
|
|
struct resource *res;
|
|
|
|
|
2012-07-31 04:41:32 +07:00
|
|
|
rtap = devm_kzalloc(&pdev->dev,
|
|
|
|
sizeof(struct coh901331_port), GFP_KERNEL);
|
2009-09-23 06:46:24 +07:00
|
|
|
if (!rtap)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-04-04 04:49:47 +07:00
|
|
|
rtap->virtbase = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(rtap->virtbase))
|
|
|
|
return PTR_ERR(rtap->virtbase);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
|
|
|
rtap->irq = platform_get_irq(pdev, 0);
|
2012-07-31 04:41:32 +07:00
|
|
|
if (devm_request_irq(&pdev->dev, rtap->irq, coh901331_interrupt, 0,
|
|
|
|
"RTC COH 901 331 Alarm", rtap))
|
|
|
|
return -EIO;
|
2009-09-23 06:46:24 +07:00
|
|
|
|
2013-02-22 07:45:38 +07:00
|
|
|
rtap->clk = devm_clk_get(&pdev->dev, NULL);
|
2009-09-23 06:46:24 +07:00
|
|
|
if (IS_ERR(rtap->clk)) {
|
|
|
|
ret = PTR_ERR(rtap->clk);
|
|
|
|
dev_err(&pdev->dev, "could not get clock\n");
|
2012-07-31 04:41:32 +07:00
|
|
|
return ret;
|
2009-09-23 06:46:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We enable/disable the clock only to assure it works */
|
2012-07-31 04:41:31 +07:00
|
|
|
ret = clk_prepare_enable(rtap->clk);
|
2009-09-23 06:46:24 +07:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "could not enable clock\n");
|
2013-02-22 07:45:38 +07:00
|
|
|
return ret;
|
2009-09-23 06:46:24 +07:00
|
|
|
}
|
|
|
|
clk_disable(rtap->clk);
|
|
|
|
|
2011-04-18 01:32:19 +07:00
|
|
|
platform_set_drvdata(pdev, rtap);
|
2013-04-30 06:18:56 +07:00
|
|
|
rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331",
|
|
|
|
&coh901331_ops, THIS_MODULE);
|
2009-09-23 06:46:24 +07:00
|
|
|
if (IS_ERR(rtap->rtc)) {
|
|
|
|
ret = PTR_ERR(rtap->rtc);
|
|
|
|
goto out_no_rtc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_no_rtc:
|
2012-07-31 04:41:31 +07:00
|
|
|
clk_unprepare(rtap->clk);
|
2009-09-23 06:46:24 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:21:00 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int coh901331_suspend(struct device *dev)
|
2009-09-23 06:46:24 +07:00
|
|
|
{
|
2013-04-30 06:21:00 +07:00
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this RTC alarm will be used for waking the system up,
|
|
|
|
* don't disable it of course. Else we just disable the alarm
|
|
|
|
* and await suspension.
|
|
|
|
*/
|
2013-04-30 06:21:00 +07:00
|
|
|
if (device_may_wakeup(dev)) {
|
2009-09-23 06:46:24 +07:00
|
|
|
enable_irq_wake(rtap->irq);
|
|
|
|
} else {
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
rtap->irqmaskstore = readl(rtap->virtbase + COH901331_IRQ_MASK);
|
|
|
|
writel(0, rtap->virtbase + COH901331_IRQ_MASK);
|
|
|
|
clk_disable(rtap->clk);
|
|
|
|
}
|
2012-07-31 04:41:31 +07:00
|
|
|
clk_unprepare(rtap->clk);
|
2009-09-23 06:46:24 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:21:00 +07:00
|
|
|
static int coh901331_resume(struct device *dev)
|
2009-09-23 06:46:24 +07:00
|
|
|
{
|
2013-04-30 06:21:00 +07:00
|
|
|
struct coh901331_port *rtap = dev_get_drvdata(dev);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
2012-07-31 04:41:31 +07:00
|
|
|
clk_prepare(rtap->clk);
|
2013-04-30 06:21:00 +07:00
|
|
|
if (device_may_wakeup(dev)) {
|
2009-09-23 06:46:24 +07:00
|
|
|
disable_irq_wake(rtap->irq);
|
2010-03-06 04:44:31 +07:00
|
|
|
} else {
|
2009-09-23 06:46:24 +07:00
|
|
|
clk_enable(rtap->clk);
|
|
|
|
writel(rtap->irqmaskstore, rtap->virtbase + COH901331_IRQ_MASK);
|
|
|
|
clk_disable(rtap->clk);
|
2010-03-06 04:44:31 +07:00
|
|
|
}
|
2009-09-23 06:46:24 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-30 06:21:00 +07:00
|
|
|
static SIMPLE_DEV_PM_OPS(coh901331_pm_ops, coh901331_suspend, coh901331_resume);
|
|
|
|
|
2009-09-23 06:46:24 +07:00
|
|
|
static void coh901331_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
2013-07-04 05:07:12 +07:00
|
|
|
struct coh901331_port *rtap = platform_get_drvdata(pdev);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
|
|
|
clk_enable(rtap->clk);
|
|
|
|
writel(0, rtap->virtbase + COH901331_IRQ_MASK);
|
2012-10-05 07:14:07 +07:00
|
|
|
clk_disable_unprepare(rtap->clk);
|
2009-09-23 06:46:24 +07:00
|
|
|
}
|
|
|
|
|
2013-04-19 18:03:13 +07:00
|
|
|
static const struct of_device_id coh901331_dt_match[] = {
|
|
|
|
{ .compatible = "stericsson,coh901331" },
|
|
|
|
{},
|
|
|
|
};
|
2015-08-27 18:52:02 +07:00
|
|
|
MODULE_DEVICE_TABLE(of, coh901331_dt_match);
|
2013-04-19 18:03:13 +07:00
|
|
|
|
2009-09-23 06:46:24 +07:00
|
|
|
static struct platform_driver coh901331_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "rtc-coh901331",
|
2013-04-30 06:21:00 +07:00
|
|
|
.pm = &coh901331_pm_ops,
|
2013-04-19 18:03:13 +07:00
|
|
|
.of_match_table = coh901331_dt_match,
|
2009-09-23 06:46:24 +07:00
|
|
|
},
|
|
|
|
.remove = __exit_p(coh901331_remove),
|
|
|
|
.shutdown = coh901331_shutdown,
|
|
|
|
};
|
|
|
|
|
2013-04-30 06:18:37 +07:00
|
|
|
module_platform_driver_probe(coh901331_driver, coh901331_probe);
|
2009-09-23 06:46:24 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
|
|
|
|
MODULE_DESCRIPTION("ST-Ericsson AB COH 901 331 RTC Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|