From: Holger Dengler <dengler@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Peter Mahler <mahler@xkrug.com>,
Juergen Bubeck <bubeck@xkrug.com>,
Benedikt Spranger <b.spranger@linutronix.de>,
Holger Dengler <dengler@linutronix.de>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 11/11] clocksource: flexcard: Support timestamp trigger selection
Date: Wed, 25 Mar 2015 10:52:00 +0100 [thread overview]
Message-ID: <1427277120-16924-12-git-send-email-dengler@linutronix.de> (raw)
In-Reply-To: <1427277120-16924-1-git-send-email-dengler@linutronix.de>
From: Benedikt Spranger <b.spranger@linutronix.de>
The Flexcard timestamp counter can be triggered from two external
trigger inputs or an internal clock at 1 MHz, 10 Mhz or 100 MHz.
Add support for timestamp trigger selection.
Signed-off-by: Holger Dengler <dengler@linutronix.de>
Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
cc: Daniel Lezcano <daniel.lezcano@linaro.org>
cc: Thomas Gleixner <tglx@linutronix.de>
---
drivers/clocksource/flexcard-time.c | 50 ++++++++++++++++++++++++++++++++++---
include/uapi/linux/flexcard.h | 16 ++++++++++++
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/drivers/clocksource/flexcard-time.c b/drivers/clocksource/flexcard-time.c
index f2efb53..101a989 100644
--- a/drivers/clocksource/flexcard-time.c
+++ b/drivers/clocksource/flexcard-time.c
@@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
+#include <linux/flexcard.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
@@ -26,8 +27,10 @@ static dev_t flexcard_clk_devt;
static struct class *flexcard_clk_class;
struct flexcard_clk {
+ struct flexcard_clk_desc desc;
struct posix_clock clock;
dev_t devid;
+ u32 mul;
struct device *dev;
void __iomem *ts64;
void __iomem *reset;
@@ -35,8 +38,9 @@ struct flexcard_clk {
static int flexcard_clk_getres(struct posix_clock *pc, struct timespec *tp)
{
+ struct flexcard_clk *clk = container_of(pc, struct flexcard_clk, clock);
tp->tv_sec = 0;
- tp->tv_nsec = 1000;
+ tp->tv_nsec = clk->mul;
return 0;
}
@@ -54,7 +58,7 @@ retry:
goto retry;
tp->tv_sec = div_u64_rem(now, clk->desc.freq, &rem);
- tp->tv_nsec = rem * 1000;
+ tp->tv_nsec = rem * clk->mul;
return 0;
}
@@ -73,11 +77,48 @@ static int flexcard_clk_settime(struct posix_clock *pc,
return 0;
}
+static long flexcard_clk_ioctl(struct posix_clock *pc, unsigned int cmd,
+ unsigned long arg)
+{
+ struct flexcard_clk *clk = container_of(pc, struct flexcard_clk, clock);
+ struct flexcard_clk_desc desc;
+
+ if (copy_from_user(&desc, (void __user *)arg, sizeof(desc)))
+ return -EFAULT;
+
+ switch (cmd) {
+ case FLEXCARD_CLK_1MHZ:
+ clk->desc.freq = 1000000;
+ break;
+ case FLEXCARD_CLK_10MHZ:
+ clk->desc.freq = 10000000;
+ break;
+ case FLEXCARD_CLK_100MHZ:
+ clk->desc.freq = 100000000;
+ break;
+ case FLEXCARD_CLK_EXT1:
+ case FLEXCARD_CLK_EXT2:
+ if (desc.freq < 1 || desc.freq > NSEC_PER_SEC)
+ return -EINVAL;
+ break;
+ default:
+ return -ENOTTY;
+ }
+
+ clk->desc = desc;
+ clk->mul = NSEC_PER_SEC/desc.freq;
+ writel(clk->desc.type, clk->ts64 + CLKSEL_OFF);
+ writel(FLEXCARD_RST_TS, clk->reset);
+
+ return 0;
+}
+
static struct posix_clock_operations flexcard_clk_ops = {
.owner = THIS_MODULE,
.clock_getres = flexcard_clk_getres,
.clock_gettime = flexcard_clk_gettime,
.clock_settime = flexcard_clk_settime,
+ .ioctl = flexcard_clk_ioctl,
};
static int flexcard_clksrc_iomap(struct platform_device *pdev)
@@ -134,8 +175,11 @@ static int flexcard_clksrc_probe(struct platform_device *pdev)
clk->devid = MKDEV(major, cell->id);
clk->clock.ops = flexcard_clk_ops;
+ clk->desc.type = FLEXCARD_CLK_1MHZ;
+ clk->desc.freq = 1000000;
+ clk->mul = 1000;
- writel(FLEXCARD_CLK_1MHZ, clk->ts64 + CLKSEL_OFF);
+ writel(clk->desc.type, clk->ts64 + CLKSEL_OFF);
writel(FLEXCARD_RST_TS, clk->reset);
clk->dev = device_create(flexcard_clk_class, &pdev->dev, clk->devid,
diff --git a/include/uapi/linux/flexcard.h b/include/uapi/linux/flexcard.h
index 9b73d8d..7939d94 100644
--- a/include/uapi/linux/flexcard.h
+++ b/include/uapi/linux/flexcard.h
@@ -15,6 +15,22 @@
#include <linux/types.h>
+enum flexcard_clk_type {
+ FLEXCARD_CLK_1MHZ = 0x0,
+ FLEXCARD_CLK_10MHZ = 0x1,
+ FLEXCARD_CLK_100MHZ = 0x2,
+ FLEXCARD_CLK_EXT1 = 0x11,
+ FLEXCARD_CLK_EXT2 = 0x12,
+};
+
+struct flexcard_clk_desc {
+ enum flexcard_clk_type type;
+ __u32 freq;
+};
+
+#define FCGCLKSRC _IOR(0xeb, 0, struct flexcard_clk_desc)
+#define FCSCLKSRC _IOW(0xeb, 1, struct flexcard_clk_desc)
+
struct fc_version {
__u8 dev;
__u8 min;
--
2.1.4
prev parent reply other threads:[~2015-03-25 9:53 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-25 9:51 [PATCH 00/11] Eberspaecher Flexcard PMC II base support Holger Dengler
2015-03-25 9:51 ` [PATCH 01/11] mfd: Eberspaecher Flexcard PMC II Carrier Board support Holger Dengler
2015-03-30 7:57 ` Lee Jones
2015-03-25 9:51 ` [PATCH 02/11] mfd: flexcard: add flexcard core device Holger Dengler
2015-03-30 8:06 ` Lee Jones
2015-03-25 9:51 ` [PATCH 03/11] mfd: flexcard: add device attributes Holger Dengler
2015-03-30 8:15 ` Lee Jones
2015-03-25 9:51 ` [PATCH 04/11] mfd: flexcard: add clocksrc device Holger Dengler
2015-03-30 8:30 ` Lee Jones
2015-03-25 9:51 ` [PATCH 05/11] mfd: flexcard: add interrupt support Holger Dengler
2015-03-30 8:46 ` Lee Jones
2015-03-25 9:51 ` [PATCH 06/11] mfd: flexcard: add DMA interrupt domain Holger Dengler
2015-03-30 8:50 ` Lee Jones
2015-03-25 9:51 ` [PATCH 07/11] mfd: flexcard: add UIO IRQ devices Holger Dengler
2015-03-30 8:57 ` Lee Jones
2015-03-25 9:51 ` [PATCH 08/11] mfd: flexcard: add DMA device Holger Dengler
2015-03-30 8:59 ` Lee Jones
2015-03-25 9:51 ` [PATCH 09/11] mfd: flexcard: add DMA ringbuffer demux driver Holger Dengler
2015-03-30 9:02 ` Lee Jones
2015-03-25 9:51 ` [PATCH 10/11] clocksource: flexcard: Add basic timestamp counter support Holger Dengler
2015-03-26 9:41 ` Daniel Lezcano
2015-03-26 11:01 ` Holger Dengler
2015-03-26 16:34 ` John Stultz
2015-03-27 12:27 ` Holger Dengler
2015-03-25 9:52 ` Holger Dengler [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1427277120-16924-12-git-send-email-dengler@linutronix.de \
--to=dengler@linutronix.de \
--cc=b.spranger@linutronix.de \
--cc=bubeck@xkrug.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mahler@xkrug.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).