[PATCH 1/3] Misc: phantom, synchronize_irq() on suspend

Previous thread: [PATCH 1/5] Char: rocket, fix dynamic_dev tty by Jiri Slaby on Monday, October 15, 2007 - 12:29 pm. (5 messages)

Next thread: [patch] scsi: fix crash in gdth_timeout() by Ingo Molnar on Monday, October 15, 2007 - 12:55 pm. (11 messages)
To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>
Date: Monday, October 15, 2007 - 12:32 pm

phantom, synchronize_irq() on suspend

Wait after disabling device's interrupt until the handler finishes its
work if still in progress.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 7e792ef384190b517f2fb27cd0237fa30dbe0775
tree 17b15e5ab7c90eef0e7ae57e532839e81b831d58
parent 5c008a5651ee92ebe020dd5108a66a7db74fe41d
author Jiri Slaby <jirislaby@gmail.com> Mon, 15 Oct 2007 15:52:21 +0200
committer Jiri Slaby <jirislaby@gmail.com> Mon, 15 Oct 2007 15:52:21 +0200

drivers/misc/phantom.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 5108b7c..6e61a79 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -378,6 +378,8 @@ static int phantom_suspend(struct pci_dev *pdev, pm_message_t state)
iowrite32(0, dev->caddr + PHN_IRQCTL);
ioread32(dev->caddr + PHN_IRQCTL); /* PCI posting */

+ synchronize_irq(pdev->irq);
+
return 0;
}

-

To: Jiri Slaby <jirislaby@...>
Cc: <linux-kernel@...>, Rafael J. Wysocki <rjw@...>, Greg KH <greg@...>
Date: Monday, October 15, 2007 - 7:23 pm

On Mon, 15 Oct 2007 09:32:28 -0700

What inspired this change? Some bug report, or does it just seem the right
thing to do?

Would it be logical to do this operation from the PCI core somewhere, on
behalf of all PCI drivers?

-

To: Andrew Morton <akpm@...>
Cc: Jiri Slaby <jirislaby@...>, <linux-kernel@...>, Greg KH <greg@...>, Alan Stern <stern@...>, Len Brown <lenb@...>, Pavel Machek <pavel@...>, pm list <linux-pm@...>
Date: Tuesday, October 16, 2007 - 8:09 am

Yes, it would.

The problem is that we don't have a common template for PCI devices' .suspend()
and .resume() callbacks and I don't feel confident enough to propose one.
-

To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>
Date: Monday, October 15, 2007 - 12:33 pm

phantom, improved data passing

this new version guarantees amb_bit switch in small enough intervals, so
that the device won't stop working in the middle of a movement anymore.
However it preserves old (openhaptics) functionality.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit e820ffda8d5f6c8a1d463955f6df7cf18544ca92
tree bba23481215cfcb6f3b7d6fec1d57d6902dc1098
parent 931e139b87d4fdb9fcae6a39cc0a157ff2fc07e1
author Jiri Slaby <jirislaby@gmail.com> Mon, 15 Oct 2007 16:03:38 +0200
committer Jiri Slaby <jirislaby@gmail.com> Mon, 15 Oct 2007 16:03:38 +0200

drivers/misc/phantom.c | 79 +++++++++++++++++++++++++++++++++++++----------
include/linux/phantom.h | 6 +++-
2 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index bc532ac..4a610cc 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -25,13 +25,14 @@
#include <asm/atomic.h>
#include <asm/io.h>

-#define PHANTOM_VERSION "n0.9.5"
+#define PHANTOM_VERSION "n0.9.7"

#define PHANTOM_MAX_MINORS 8

#define PHN_IRQCTL 0x4c /* irq control in caddr space */

#define PHB_RUNNING 1
+#define PHB_NOT_OH 2

static struct class *phantom_class;
static int phantom_major;
@@ -48,7 +49,11 @@ struct phantom_device {
struct cdev cdev;

struct mutex open_lock;
- spinlock_t ioctl_lock;
+ spinlock_t regs_lock;
+
+ /* used in NOT_OH mode */
+ struct phm_regs oregs;
+ u32 ctl_reg;
};

static unsigned char phantom_devices[PHANTOM_MAX_MINORS];
@@ -83,6 +88,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
struct phm_regs rs;
struct phm_reg r;
void __user *argp = (void __user *)arg;
+ unsigned long flags;
unsigned int i;

if (_IOC_TYPE(cmd) != PH_IOC_MAGIC ||
@@ -97,32 +103,42 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
if (r.reg > 7)
return -EINVAL;

- spin_lock(&dev->ioctl_lock);
+ spin_lock_irqsave(...

To: Jiri Slaby <jirislaby@...>
Cc: <linux-kernel@...>
Date: Monday, October 15, 2007 - 7:31 pm

On Mon, 15 Oct 2007 09:33:49 -0700

But this is the interrupt handler, and there's a pointer chase as well as
the min() each time around the loop (I assume). I doubt if the world will

-

To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>
Date: Tuesday, October 16, 2007 - 1:50 pm

Hmm, the compiler isn't as smart as I though. The fix follows, thanks.

--

misc-phantom-improved-data-passing-fix

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit d1d9a974c008af6e7ad0347df7f9ca372da1bb4c
tree 9c9cda79e150a752f052831ea18f35f31c8f9a5f
parent 228d539e706cd42c2950aa26ac01590e413d8f51
author Jiri Slaby <jirislaby@gmail.com> Tue, 16 Oct 2007 16:46:28 +0200
committer Jiri Slaby <jirislaby@gmail.com> Tue, 16 Oct 2007 16:46:28 +0200

drivers/misc/phantom.c | 37 ++++++++++++++++++++++++-------------
1 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 4a610cc..cd221fd 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -113,9 +113,11 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
pr_debug("phantom: writing %x to %u\n", r.value, r.reg);

/* preserve amp bit (don't allow to change it when in NOT_OH) */
- if (r.reg == PHN_CONTROL && (dev->status & PHB_NOT_OH))
- dev->ctl_reg = r.value = (r.value & ~PHN_CTL_AMP) |
- (dev->ctl_reg & PHN_CTL_AMP);
+ if (r.reg == PHN_CONTROL && (dev->status & PHB_NOT_OH)) {
+ r.value &= ~PHN_CTL_AMP;
+ r.value |= dev->ctl_reg & PHN_CTL_AMP;
+ dev->ctl_reg = r.value;
+ }

iowrite32(r.value, dev->iaddr + r.reg);
ioread32(dev->iaddr); /* PCI posting */
@@ -133,7 +135,8 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
if (dev->status & PHB_NOT_OH)
memcpy(&dev->oregs, &rs, sizeof(rs));
else {
- for (i = 0; i < min(rs.count, 8U); i++)
+ u32 m = min(rs.count, 8U);
+ for (i = 0; i < m; i++)
if (rs.mask & BIT(i))
iowrite32(rs.values[i], dev->oaddr + i);
ioread32(dev->iaddr); /* PCI posting */
@@ -152,13 +155,17 @@ static long phantom_ioctl(struct file *file, unsigned int cmd,
if (copy_to_user(argp, &r, sizeof(r)))
return ...

To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>
Date: Monday, October 15, 2007 - 12:33 pm

phantom, add comment about openhaptics

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 931e139b87d4fdb9fcae6a39cc0a157ff2fc07e1
tree f0f98cff767ed04a2289a5c8ebbcad0d5757b23b
parent 7e792ef384190b517f2fb27cd0237fa30dbe0775
author Jiri Slaby <jirislaby@gmail.com> Mon, 15 Oct 2007 15:53:06 +0200
committer Jiri Slaby <jirislaby@gmail.com> Mon, 15 Oct 2007 15:53:06 +0200

drivers/misc/phantom.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 6e61a79..bc532ac 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -9,6 +9,7 @@
* You need an userspace library to cooperate with this driver. It (and other
* info) may be obtained here:
* http://www.fi.muni.cz/~xslaby/phantom.html
+ * or alternatively, you might use OpenHaptics provided by Sensable.
*/

#include <linux/kernel.h>
-

Previous thread: [PATCH 1/5] Char: rocket, fix dynamic_dev tty by Jiri Slaby on Monday, October 15, 2007 - 12:29 pm. (5 messages)

Next thread: [patch] scsi: fix crash in gdth_timeout() by Ingo Molnar on Monday, October 15, 2007 - 12:55 pm. (11 messages)