diff options
author | Pieter Palmers <pieterp@joow.be> | 2007-02-03 17:44:39 +0100 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2007-02-17 14:39:33 +0100 |
commit | 3dc5ea9b31a8c83cffa338aba91adbc9bd387002 (patch) | |
tree | 5a9d9682d77fb3a1cfd3dc27654301f69ababf12 /drivers/ieee1394/ieee1394_core.c | |
parent | 91efa462054d44ae52b0c6c8325ed5e899f2cd17 (diff) | |
download | linux-3dc5ea9b31a8c83cffa338aba91adbc9bd387002.tar.bz2 |
ieee1394: cycle timer read extension for raw1394
This implements the simultaneous read of the isochronous cycle timer and
the system clock (in usecs). This allows to express the exact receive
time of an ISO packet as a system time with microsecond accuracy.
http://bugzilla.kernel.org/show_bug.cgi?id=7773
The counterpart patch for libraw1394 can be found at
http://thread.gmane.org/gmane.linux.kernel.firewire.devel/8934
Patch update (Stefan R.): Disable preemption and local interrupts.
Prevent integer overflow. Add paranoid error checks and kerneldoc to
hpsb_read_cycle_timer. Move it to other ieee1394_core high-level API
functions. Change comments. Adjust whitespace. Rename struct
_raw1394_cycle_timer.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Acked-by: Pieter Palmers <pieterp@joow.be>
Acked-by: Dan Dennedy <dan@dennedy.org>
Diffstat (limited to 'drivers/ieee1394/ieee1394_core.c')
-rw-r--r-- | drivers/ieee1394/ieee1394_core.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c index 1521e57e124b..d791d08c743c 100644 --- a/drivers/ieee1394/ieee1394_core.c +++ b/drivers/ieee1394/ieee1394_core.c @@ -33,7 +33,10 @@ #include <linux/skbuff.h> #include <linux/suspend.h> #include <linux/kthread.h> +#include <linux/preempt.h> +#include <linux/time.h> +#include <asm/system.h> #include <asm/byteorder.h> #include "ieee1394_types.h" @@ -186,6 +189,45 @@ int hpsb_reset_bus(struct hpsb_host *host, int type) } } +/** + * hpsb_read_cycle_timer - read cycle timer register and system time + * @host: host whose isochronous cycle timer register is read + * @cycle_timer: address of bitfield to return the register contents + * @local_time: address to return the system time + * + * The format of * @cycle_timer, is described in OHCI 1.1 clause 5.13. This + * format is also read from non-OHCI controllers. * @local_time contains the + * system time in microseconds since the Epoch, read at the moment when the + * cycle timer was read. + * + * Return value: 0 for success or error number otherwise. + */ +int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer, + u64 *local_time) +{ + int ctr; + struct timeval tv; + unsigned long flags; + + if (!host || !cycle_timer || !local_time) + return -EINVAL; + + preempt_disable(); + local_irq_save(flags); + + ctr = host->driver->devctl(host, GET_CYCLE_COUNTER, 0); + if (ctr) + do_gettimeofday(&tv); + + local_irq_restore(flags); + preempt_enable(); + + if (!ctr) + return -EIO; + *cycle_timer = ctr; + *local_time = tv.tv_sec * 1000000ULL + tv.tv_usec; + return 0; +} int hpsb_bus_reset(struct hpsb_host *host) { @@ -1190,6 +1232,7 @@ EXPORT_SYMBOL(hpsb_alloc_packet); EXPORT_SYMBOL(hpsb_free_packet); EXPORT_SYMBOL(hpsb_send_packet); EXPORT_SYMBOL(hpsb_reset_bus); +EXPORT_SYMBOL(hpsb_read_cycle_timer); EXPORT_SYMBOL(hpsb_bus_reset); EXPORT_SYMBOL(hpsb_selfid_received); EXPORT_SYMBOL(hpsb_selfid_complete); |