[PATCH 1/2] UIO: add device clock support

From: Daniel Mack
Date: Wed Jun 24 2009 - 11:31:37 EST


Add a pointer to a 'struct clk' to uio_info. Drivers can set
this pointer if a clock is needed, and the UIO core will care
to enable and disable it upon device open and release.

Signed-off-by: Daniel Mack <daniel@xxxxxxxx>
Cc: Hans J. Koch <hjk@xxxxxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxx>
---
drivers/uio/uio.c | 15 ++++++++++++++-
include/linux/uio_driver.h | 2 ++
2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 03efb06..6ba95cf 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -479,6 +479,12 @@ static int uio_open(struct inode *inode, struct file *filep)
listener->event_count = atomic_read(&idev->event);
filep->private_data = listener;

+ if (idev->info->clk) {
+ ret = clk_enable(idev->info->clk);
+ if (ret)
+ goto err_clkenable;
+ }
+
if (idev->info->open) {
ret = idev->info->open(idev->info, inode);
if (ret)
@@ -486,6 +492,7 @@ static int uio_open(struct inode *inode, struct file *filep)
}
return 0;

+err_clkenable:
err_infoopen:
kfree(listener);

@@ -510,8 +517,14 @@ static int uio_release(struct inode *inode, struct file *filep)
struct uio_listener *listener = filep->private_data;
struct uio_device *idev = listener->dev;

- if (idev->info->release)
+ if (idev->info->release) {
ret = idev->info->release(idev->info, inode);
+ if (ret)
+ dev_err(idev->dev, "release() failed (%d)\n", ret);
+ }
+
+ if (idev->info->clk)
+ clk_disable(idev->info->clk);

module_put(idev->owner);
kfree(listener);
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 5dcc9ff..6bc0e7e 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -17,6 +17,7 @@
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
+#include <linux/clk.h>

struct uio_map;

@@ -87,6 +88,7 @@ struct uio_info {
long irq;
unsigned long irq_flags;
void *priv;
+ struct clk *clk;
irqreturn_t (*handler)(int irq, struct uio_info *dev_info);
int (*mmap)(struct uio_info *info, struct vm_area_struct *vma);
int (*open)(struct uio_info *info, struct inode *inode);
--
1.6.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/