linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Jason McMullan <jason.mcmullan@timesys.com>
To: linuxppc-embedded <linuxppc-embedded@ozlabs.org>
Subject: Re: [PATCH 2.6.11.6] CPM2 Timers API
Date: Thu, 31 Mar 2005 15:33:45 -0500	[thread overview]
Message-ID: <1112301225.3337.19.camel@ad.doubleclick.net> (raw)
In-Reply-To: <1112298886.3337.14.camel@ad.doubleclick.net>


[-- Attachment #1.1: Type: text/plain, Size: 187 bytes --]

A brown bag error handling and Lindent patch, to be applied in that
order, to my previous CPM timers patch.


-- 
Jason McMullan <jason.mcmullan@timesys.com>
TimeSys Corporation


[-- Attachment #1.2: cpm-timer.brown-bag.patch --]
[-- Type: text/x-patch, Size: 638 bytes --]

--- linux-2.6.patch/arch/ppc/syslib/cpm_timer.c.orig	2005-03-31 14:50:29.000000000 -0500
+++ linux-2.6.patch/arch/ppc/syslib/cpm_timer.c	2005-03-31 15:01:39.417496033 -0500
@@ -114,12 +114,16 @@
 
 	tm->start = (timer_id>>4)&0xf;
 	tm->end   = timer_id & 0xf;
-	if (tm->start > 3)
+	if (tm->start > 3) {
+		kfree(tm);
 		return -EINVAL;
+	}
 
 	if ((tm->end != tm->start) && 
-	    ((tm->start & 1) || (tm->end != (tm->start+1))))
-	    return -EINVAL;
+	    ((tm->start & 1) || (tm->end != (tm->start+1)))) {
+		kfree(tm);
+		return -EINVAL;
+	}
 
 	err = request_resource(&cpm_timer_resource,tm);
 	if (err < 0) {

[-- Attachment #1.3: cpm-timer.lindent.patch --]
[-- Type: text/x-patch, Size: 7152 bytes --]

--- linux-2.6/arch/ppc/syslib/cpm_timer.c	2005-03-31 15:15:59.100629916 -0500
+++ linux-2.6.patch/arch/ppc/syslib/cpm_timer.c	2005-03-31 15:15:38.838272681 -0500
@@ -42,7 +42,7 @@
 static struct resource cpm_timer_resource = {
 	.name = "CPM Timers",
 	.start = 0,
-	.end   = 3,
+	.end = 3,
 };
 
 static struct cpm_timer_s {
@@ -101,52 +101,56 @@
  * Returns 0 on success, -errno on error
  */
 EXPORT_SYMBOL(cpm_timer_alloc);
-int cpm_timer_alloc(int timer_id, cpm_timer_t *ptm)
+int cpm_timer_alloc(int timer_id, cpm_timer_t * ptm)
 {
 	struct resource *tm;
 	int err;
 	uint16_t mask;
-      
-	tm = kmalloc(sizeof(struct resource)+16, GFP_KERNEL);
-	memset(tm,0,sizeof(struct resource)+16);
+
+	tm = kmalloc(sizeof(struct resource) + 16, GFP_KERNEL);
+	memset(tm, 0, sizeof(struct resource) + 16);
 	if (tm == NULL)
 		return -ENOMEM;
 
-	tm->start = (timer_id>>4)&0xf;
-	tm->end   = timer_id & 0xf;
+	tm->start = (timer_id >> 4) & 0xf;
+	tm->end = timer_id & 0xf;
 	if (tm->start > 3) {
 		kfree(tm);
 		return -EINVAL;
 	}
 
-	if ((tm->end != tm->start) && 
-	    ((tm->start & 1) || (tm->end != (tm->start+1)))) {
+	if ((tm->end != tm->start) &&
+	    ((tm->start & 1) || (tm->end != (tm->start + 1)))) {
 		kfree(tm);
 		return -EINVAL;
 	}
 
-	err = request_resource(&cpm_timer_resource,tm);
+	err = request_resource(&cpm_timer_resource, tm);
 	if (err < 0) {
 		kfree(tm);
 		return err;
 	}
 
-	*ptm = (cpm_timer_t)(tm);
+	*ptm = (cpm_timer_t) (tm);
 
 	tm->name = ((void *)tm) + sizeof(struct resource);
 	if (tm->start == tm->end) {
-		sprintf((char *)tm->name,"timer%ld",tm->start+1);
+		sprintf((char *)tm->name, "timer%ld", tm->start + 1);
 	} else {
-		sprintf((char *)tm->name,"timer%ld-%ld",tm->start+1,tm->end+1);
+		sprintf((char *)tm->name, "timer%ld-%ld", tm->start + 1,
+			tm->end + 1);
 	}
 
-	err = request_irq(cpm_timer[tm->end].irq,cpm_timer_irq,SA_INTERRUPT,tm->name,&cpm_timer[tm->end]);
+	err =
+	    request_irq(cpm_timer[tm->end].irq, cpm_timer_irq, SA_INTERRUPT,
+			tm->name, &cpm_timer[tm->end]);
 	if (err < 0) {
-		printk(KERN_ERR "CPM Timer %s: Can't allocate IRQ %d.\n",tm->name,cpm_timer[tm->end].irq);
+		printk(KERN_ERR "CPM Timer %s: Can't allocate IRQ %d.\n",
+		       tm->name, cpm_timer[tm->end].irq);
 	}
 
 	/* Step 1 - enable and stop the timer */
-	mask = (TGCR_RST|TGCR_STP) << (4*((tm->end)&1));
+	mask = (TGCR_RST | TGCR_STP) << (4 * ((tm->end) & 1));
 	if (tm->start < 2) {
 		timer_base->cpmt_tgcr1 |= mask;
 	} else {
@@ -188,7 +192,7 @@
 	uint16_t mask;
 
 	cpm_timer_stop(tm);
-	free_irq(cpm_timer[tm->end].irq,&cpm_timer[tm->end]);
+	free_irq(cpm_timer[tm->end].irq, &cpm_timer[tm->end]);
 	if (tm->start != tm->end) {
 		if (tm->start == 0) {
 			timer_base->cpmt_tgcr1 &= ~(TGCR_CAS << 4);
@@ -199,8 +203,8 @@
 	wmb();
 
 	/* Disable the timer */
-	mask = (TGCR_RST << (4*((tm->start)&1))) |
-	       (TGCR_RST << (4*((tm->end)&1)));
+	mask = (TGCR_RST << (4 * ((tm->start) & 1))) |
+	    (TGCR_RST << (4 * ((tm->end) & 1)));
 	if (tm->start < 2) {
 		timer_base->cpmt_tgcr1 &= ~mask;
 	} else {
@@ -219,7 +223,7 @@
 {
 	uint8_t mask;
 
-	mask = (TGCR_STP << (4*((tm->end)&1)));
+	mask = (TGCR_STP << (4 * ((tm->end) & 1)));
 	if (tm->start < 2) {
 		timer_base->cpmt_tgcr1 |= mask;
 	} else {
@@ -236,7 +240,7 @@
 {
 	uint8_t mask;
 
-	mask = (TGCR_STP << (4*((tm->end)&1)));
+	mask = (TGCR_STP << (4 * ((tm->end) & 1)));
 	if (tm->start < 2) {
 		timer_base->cpmt_tgcr1 &= ~mask;
 	} else {
@@ -256,7 +260,7 @@
 	int mask;
 	int tmr;
 
-	mask = ((TGCR_STP|TGCR_RST) << (4*((tm->end)&1)));
+	mask = ((TGCR_STP | TGCR_RST) << (4 * ((tm->end) & 1)));
 	tmr = *cpm_timer[tm->end].ctrl.tmr;
 
 	if (tm->start < 2) {
@@ -290,9 +294,9 @@
 	/* For the mpc85xx, we're just using core frequency/16
 	 */
 	extern unsigned char __res[];
-	bd_t *bd = (bd_t *)__res;
+	bd_t *bd = (bd_t *) __res;
 
-	return bd->bi_busfreq/1000000*16;
+	return bd->bi_busfreq / 1000000 * 16;
 }
 
 /* Get the timer value, in ticks
@@ -317,7 +321,8 @@
  * You cannot call cpm_timer_free() within that context.
  */
 
-static int cpm_timer_call_common(cpm_timer_t tm, unsigned long ticks, cpm_timer_f func, void *func_data)
+static int cpm_timer_call_common(cpm_timer_t tm, unsigned long ticks,
+				 cpm_timer_f func, void *func_data)
 {
 	if (cpm_timer[tm->start].func != NULL)
 		return -EBUSY;
@@ -347,15 +352,15 @@
 	return 0;
 }
 
-
 /* This is the one-shot timer.
  */
 EXPORT_SYMBOL(cpm_timer_call_once);
-int cpm_timer_call_once(cpm_timer_t tm, unsigned long ticks, cpm_timer_f func, void *func_data)
+int cpm_timer_call_once(cpm_timer_t tm, unsigned long ticks, cpm_timer_f func,
+			void *func_data)
 {
 	int err;
 
-	err = cpm_timer_call_common(tm,ticks,func,func_data);
+	err = cpm_timer_call_common(tm, ticks, func, func_data);
 	if (err < 0)
 		return err;
 
@@ -363,16 +368,16 @@
 
 	return 0;
 }
-	
 
 /* This is the repeat-timer function
  */
 EXPORT_SYMBOL(cpm_timer_call_every);
-int cpm_timer_call_every(cpm_timer_t tm, unsigned long ticks, cpm_timer_f func, void *func_data)
+int cpm_timer_call_every(cpm_timer_t tm, unsigned long ticks, cpm_timer_f func,
+			 void *func_data)
 {
 	int err;
 
-	err = cpm_timer_call_common(tm,ticks,func,func_data);
+	err = cpm_timer_call_common(tm, ticks, func, func_data);
 	if (err < 0)
 		return err;
 
@@ -380,7 +385,7 @@
 
 	return 0;
 }
-	
+
 /* Cancel any pending timer functions
  */
 EXPORT_SYMBOL(cpm_timer_call_none);
@@ -411,10 +416,10 @@
 }
 
 static struct file_operations proc_cpm_timer_operations = {
-	.open		= cpm_timer_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
+	.open = cpm_timer_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
 };
 
 static int __init cpm_timer_proc_init(void)
@@ -432,13 +437,13 @@
 	remove_proc_entry("cpm-timer", NULL);
 }
 
-#endif /* CONFIG_PROC_FS */
+#endif				/* CONFIG_PROC_FS */
 
 static int __devinit cpm_timer_probe(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	int i;
-	struct resource *res,*irqs;
+	struct resource *res, *irqs;
 
 	if (timer_base != NULL)
 		return -EBUSY;
@@ -448,10 +453,10 @@
 		return -EINVAL;
 
 	irqs = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-	if (res == NULL || ((irqs->end+1)-irqs->start) != 4)
+	if (res == NULL || ((irqs->end + 1) - irqs->start) != 4)
 		return -EINVAL;
 
-	timer_base = ioremap(res->start,sizeof(cpmtimer_cpm2_t));
+	timer_base = ioremap(res->start, sizeof(cpmtimer_cpm2_t));
 	if (timer_base == NULL)
 		return -ENOMEM;
 
@@ -477,8 +482,8 @@
 	CPM_TIMER_D_SETUP(tcn);
 
 	for (i = 0; i < 4; i++) {
-		sprintf(cpm_timer[i].name,"CPM Timer %d",i+1);
-		cpm_timer[i].irq = irqs->start+i;
+		sprintf(cpm_timer[i].name, "CPM Timer %d", i + 1);
+		cpm_timer[i].irq = irqs->start + i;
 	}
 
 #ifdef CONFIG_PROC_FS
@@ -522,5 +527,3 @@
 
 module_init(cpm_timer_init);
 module_exit(cpm_timer_exit);
-
-

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2005-03-31 20:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-31 19:54 [PATCH 2.6.11.6] CPM2 Timers API Jason McMullan
2005-03-31 20:33 ` Jason McMullan [this message]
2005-04-01 13:50   ` Jason McMullan

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=1112301225.3337.19.camel@ad.doubleclick.net \
    --to=jason.mcmullan@timesys.com \
    --cc=linuxppc-embedded@ozlabs.org \
    /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).