2009-08-18 19:06:30 +02:00
|
|
|
/* The industrial I/O periodic RTC trigger driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Jonathan Cameron
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This is a heavily rewritten version of the periodic timer system in
|
|
|
|
* earlier version of industrialio. It supplies the same functionality
|
|
|
|
* but via a trigger rather than a specific periodic timer system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-08-18 19:06:30 +02:00
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include "../iio.h"
|
|
|
|
#include "../trigger.h"
|
|
|
|
|
2010-05-05 07:31:22 +02:00
|
|
|
static LIST_HEAD(iio_prtc_trigger_list);
|
|
|
|
static DEFINE_MUTEX(iio_prtc_trigger_list_lock);
|
2009-08-18 19:06:30 +02:00
|
|
|
|
|
|
|
struct iio_prtc_trigger_info {
|
|
|
|
struct rtc_device *rtc;
|
|
|
|
int frequency;
|
|
|
|
struct rtc_task task;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
|
|
|
|
{
|
|
|
|
struct iio_prtc_trigger_info *trig_info = trig->private_data;
|
|
|
|
if (trig_info->frequency == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
printk(KERN_INFO "trigger frequency is %d\n", trig_info->frequency);
|
|
|
|
return rtc_irq_set_state(trig_info->rtc, &trig_info->task, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t iio_trig_periodic_read_freq(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct iio_trigger *trig = dev_get_drvdata(dev);
|
|
|
|
struct iio_prtc_trigger_info *trig_info = trig->private_data;
|
|
|
|
return sprintf(buf, "%u\n", trig_info->frequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t iio_trig_periodic_write_freq(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
struct iio_trigger *trig = dev_get_drvdata(dev);
|
|
|
|
struct iio_prtc_trigger_info *trig_info = trig->private_data;
|
|
|
|
unsigned long val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = strict_strtoul(buf, 10, &val);
|
|
|
|
if (ret)
|
|
|
|
goto error_ret;
|
|
|
|
|
|
|
|
ret = rtc_irq_set_freq(trig_info->rtc, &trig_info->task, val);
|
|
|
|
if (ret)
|
|
|
|
goto error_ret;
|
|
|
|
|
|
|
|
trig_info->frequency = val;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
|
|
|
|
error_ret:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-04 18:54:48 +02:00
|
|
|
static IIO_TRIGGER_NAME_ATTR;
|
2009-08-21 22:59:08 +02:00
|
|
|
static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR,
|
2009-08-18 19:06:30 +02:00
|
|
|
iio_trig_periodic_read_freq,
|
|
|
|
iio_trig_periodic_write_freq);
|
|
|
|
|
|
|
|
static struct attribute *iio_trig_prtc_attrs[] = {
|
|
|
|
&dev_attr_frequency.attr,
|
|
|
|
&dev_attr_name.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
static const struct attribute_group iio_trig_prtc_attr_group = {
|
|
|
|
.attrs = iio_trig_prtc_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void iio_prtc_trigger_poll(void *private_data)
|
|
|
|
{
|
2010-07-11 17:39:11 +02:00
|
|
|
/* Timestamp is not provided currently */
|
|
|
|
iio_trigger_poll(private_data, 0);
|
2009-08-18 19:06:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
char **pdata = dev->dev.platform_data;
|
|
|
|
struct iio_prtc_trigger_info *trig_info;
|
|
|
|
struct iio_trigger *trig, *trig2;
|
|
|
|
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
if (pdata[i] == NULL)
|
|
|
|
break;
|
|
|
|
trig = iio_allocate_trigger();
|
|
|
|
if (!trig) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error_free_completed_registrations;
|
|
|
|
}
|
|
|
|
list_add(&trig->alloc_list, &iio_prtc_trigger_list);
|
|
|
|
|
|
|
|
trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
|
|
|
|
if (!trig_info) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error_put_trigger_and_remove_from_list;
|
|
|
|
}
|
|
|
|
trig->private_data = trig_info;
|
|
|
|
trig->owner = THIS_MODULE;
|
|
|
|
trig->set_trigger_state = &iio_trig_periodic_rtc_set_state;
|
2010-07-11 17:39:08 +02:00
|
|
|
trig->name = kasprintf(GFP_KERNEL, "periodic%s", pdata[i]);
|
2009-08-18 19:06:30 +02:00
|
|
|
if (trig->name == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto error_free_trig_info;
|
|
|
|
}
|
2010-07-11 17:39:08 +02:00
|
|
|
|
2009-08-18 19:06:30 +02:00
|
|
|
/* RTC access */
|
|
|
|
trig_info->rtc
|
|
|
|
= rtc_class_open(pdata[i]);
|
|
|
|
if (trig_info->rtc == NULL) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto error_free_name;
|
|
|
|
}
|
|
|
|
trig_info->task.func = iio_prtc_trigger_poll;
|
|
|
|
trig_info->task.private_data = trig;
|
|
|
|
ret = rtc_irq_register(trig_info->rtc, &trig_info->task);
|
|
|
|
if (ret)
|
|
|
|
goto error_close_rtc;
|
|
|
|
trig->control_attrs = &iio_trig_prtc_attr_group;
|
|
|
|
ret = iio_trigger_register(trig);
|
|
|
|
if (ret)
|
|
|
|
goto error_unregister_rtc_irq;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
error_unregister_rtc_irq:
|
|
|
|
rtc_irq_unregister(trig_info->rtc, &trig_info->task);
|
|
|
|
error_close_rtc:
|
|
|
|
rtc_class_close(trig_info->rtc);
|
|
|
|
error_free_name:
|
|
|
|
kfree(trig->name);
|
|
|
|
error_free_trig_info:
|
|
|
|
kfree(trig_info);
|
|
|
|
error_put_trigger_and_remove_from_list:
|
|
|
|
list_del(&trig->alloc_list);
|
|
|
|
iio_put_trigger(trig);
|
|
|
|
error_free_completed_registrations:
|
|
|
|
list_for_each_entry_safe(trig,
|
|
|
|
trig2,
|
|
|
|
&iio_prtc_trigger_list,
|
|
|
|
alloc_list) {
|
|
|
|
trig_info = trig->private_data;
|
|
|
|
rtc_irq_unregister(trig_info->rtc, &trig_info->task);
|
|
|
|
rtc_class_close(trig_info->rtc);
|
|
|
|
kfree(trig->name);
|
|
|
|
kfree(trig_info);
|
|
|
|
iio_trigger_unregister(trig);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iio_trig_periodic_rtc_remove(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
struct iio_trigger *trig, *trig2;
|
|
|
|
struct iio_prtc_trigger_info *trig_info;
|
|
|
|
mutex_lock(&iio_prtc_trigger_list_lock);
|
|
|
|
list_for_each_entry_safe(trig,
|
|
|
|
trig2,
|
|
|
|
&iio_prtc_trigger_list,
|
|
|
|
alloc_list) {
|
|
|
|
trig_info = trig->private_data;
|
|
|
|
rtc_irq_unregister(trig_info->rtc, &trig_info->task);
|
|
|
|
rtc_class_close(trig_info->rtc);
|
|
|
|
kfree(trig->name);
|
|
|
|
kfree(trig_info);
|
|
|
|
iio_trigger_unregister(trig);
|
|
|
|
}
|
|
|
|
mutex_unlock(&iio_prtc_trigger_list_lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver iio_trig_periodic_rtc_driver = {
|
|
|
|
.probe = iio_trig_periodic_rtc_probe,
|
|
|
|
.remove = iio_trig_periodic_rtc_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "iio_prtc_trigger",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init iio_trig_periodic_rtc_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&iio_trig_periodic_rtc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit iio_trig_periodic_rtc_exit(void)
|
|
|
|
{
|
|
|
|
return platform_driver_unregister(&iio_trig_periodic_rtc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(iio_trig_periodic_rtc_init);
|
|
|
|
module_exit(iio_trig_periodic_rtc_exit);
|
|
|
|
MODULE_AUTHOR("Jonathan Cameron <jic23@cam.ac.uk>");
|
|
|
|
MODULE_DESCRIPTION("Periodic realtime clock trigger for the iio subsystem");
|
|
|
|
MODULE_LICENSE("GPL v2");
|