commit: http://blackfin.uclinux.org/git/?p=linux-kernel;a=commitdiff;h=4815a458cc3d1bead9205372067134e89b027932
branch: http://blackfin.uclinux.org/git/?p=linux-kernel;a=shortlog;h=refs/heads/trunk

add ioctl cmd for gptimer test app
codecleanup, remove spaces

Signed-off-by: Steven Miao <[email protected]>
---
 arch/blackfin/include/asm/bfin_simple_timer.h |   10 ++++--
 drivers/char/bfin_simple_timer.c              |   38 +++++++++++++++++++++----
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/arch/blackfin/include/asm/bfin_simple_timer.h b/arch/blackfin/include/asm/bfin_simple_timer.h
index 5248c13..aadfb1a 100644
--- a/arch/blackfin/include/asm/bfin_simple_timer.h
+++ b/arch/blackfin/include/asm/bfin_simple_timer.h
@@ -11,9 +11,11 @@
 
 #define BFIN_SIMPLE_TIMER_IOCTL_MAGIC 't'
 
-#define BFIN_SIMPLE_TIMER_SET_PERIOD _IO (BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  2)
-#define BFIN_SIMPLE_TIMER_START      _IO (BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  6)
-#define BFIN_SIMPLE_TIMER_STOP       _IO (BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  8)
-#define BFIN_SIMPLE_TIMER_READ       _IO (BFIN_SIMPLE_TIMER_IOCTL_MAGIC, 10)
+#define BFIN_SIMPLE_TIMER_SET_PERIOD _IO(BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  2)
+#define BFIN_SIMPLE_TIMER_SET_WIDTH _IO(BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  3)
+#define BFIN_SIMPLE_TIMER_SET_MODE _IO(BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  4)
+#define BFIN_SIMPLE_TIMER_START      _IO(BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  6)
+#define BFIN_SIMPLE_TIMER_STOP       _IO(BFIN_SIMPLE_TIMER_IOCTL_MAGIC,  8)
+#define BFIN_SIMPLE_TIMER_READ       _IO(BFIN_SIMPLE_TIMER_IOCTL_MAGIC, 10)
 
 #endif
diff --git a/drivers/char/bfin_simple_timer.c b/drivers/char/bfin_simple_timer.c
index b1cfe97..56bd06d 100644
--- a/drivers/char/bfin_simple_timer.c
+++ b/drivers/char/bfin_simple_timer.c
@@ -75,18 +75,43 @@ static long
 timer_ioctl(struct file *filp, uint cmd, unsigned long arg)
 {
 	struct timer *t = filp->private_data;
-	unsigned long n;
+	unsigned long period = 0, width = 0, mode = 0;
 	switch (cmd) {
 	case BFIN_SIMPLE_TIMER_SET_PERIOD:
 		if (arg < 2)
 			return -EFAULT;
-		n = ((get_sclk() / 1000) * arg) / 1000;
-		set_gptimer_period(t->id, n);
-		set_gptimer_pwidth(t->id, n >> 1);
-		pr_debug(DRV_NAME ": TIMER_SET_PERIOD: arg=%lu, period=%lu, width=%lu\n",
-			arg, n, n >> 1);
+		period = arg;
+		set_gptimer_period(t->id, period);
+		pr_debug(DRV_NAME ": TIMER_SET_PERIOD: arg=%lu, period=%lu\n",
+			arg, period);
+		break;
+	case BFIN_SIMPLE_TIMER_SET_WIDTH:
+		width = arg;
+		set_gptimer_pwidth(t->id, width);
+		pr_debug(DRV_NAME ": TIMER_SET_WIDTH: arg=%lu, width=%lu\n",
+			arg, width);
+		break;
+	case BFIN_SIMPLE_TIMER_SET_MODE:
+		mode = arg;
+		switch (mode) {
+		case 0:
+			set_gptimer_config(t->id, OUT_DIS | PWM_OUT | PERIOD_CNT | IRQ_ENA);
+			break;
+		case 1:
+			set_gptimer_config(t->id, PWM_OUT | PERIOD_CNT | IRQ_ENA);
+			break;
+		default:
+			pr_debug(DRV_NAME ": error mode\n");
+		}
 		break;
 	case BFIN_SIMPLE_TIMER_START:
+		period = get_gptimer_period(t->id);
+		width = get_gptimer_pwidth(t->id);
+		pr_debug(DRV_NAME ": TIMER_START: period=%lu, width=%lu\n",
+				period, width);
+		if (period < width)
+			return -EFAULT;
+
 		enable_gptimers(t->bit);
 		break;
 	case BFIN_SIMPLE_TIMER_STOP:
@@ -161,6 +186,7 @@ timer_read_proc(char *buf, char **start, off_t offset, int cnt, int *eof, void *
 {
 	int i, ret = 0;
 
+	ret += sprintf(buf + ret, "sclk = %lu\n", get_sclk());
 	for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i)
 		ret += sprintf(buf + ret, "timer %2d isr count: %lu\n",
 			i, timer_code[i].isr_count);
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to