Skip to content

Commit

Permalink
W1: OMAP HDQ1W: use runtime PM
Browse files Browse the repository at this point in the history
Convert the OMAP HDQ driver to use runtime PM.  Compile- and boot-tested,
but not tested in actual use.

Signed-off-by: Paul Walmsley <paul@pwsan.com>
Cc: NeilBrown <neilb@suse.de>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Tested-by: NeilBrown <neilb@suse.de>
  • Loading branch information
Paul Walmsley committed Jun 22, 2012
1 parent 96b1b29 commit c354a86
Showing 1 changed file with 13 additions and 65 deletions.
78 changes: 13 additions & 65 deletions drivers/w1/masters/omap_hdq.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* drivers/w1/masters/omap_hdq.c
*
* Copyright (C) 2007 Texas Instruments, Inc.
* Copyright (C) 2007,2012 Texas Instruments, Inc.
*
* This file is licensed under the terms of the GNU General Public License
* version 2. This program is licensed "as is" without any warranty of any
Expand All @@ -14,9 +14,9 @@
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/sched.h>
#include <linux/pm_runtime.h>

#include <asm/irq.h>
#include <mach/hardware.h>
Expand Down Expand Up @@ -61,8 +61,6 @@ struct hdq_data {
/* lock status update */
struct mutex hdq_mutex;
int hdq_usecount;
struct clk *hdq_ick;
struct clk *hdq_fck;
u8 hdq_irqstatus;
/* device lock */
spinlock_t hdq_spinlock;
Expand Down Expand Up @@ -419,17 +417,8 @@ static int omap_hdq_get(struct hdq_data *hdq_data)
hdq_data->hdq_usecount++;
try_module_get(THIS_MODULE);
if (1 == hdq_data->hdq_usecount) {
if (clk_enable(hdq_data->hdq_ick)) {
dev_dbg(hdq_data->dev, "Can not enable ick\n");
ret = -ENODEV;
goto clk_err;
}
if (clk_enable(hdq_data->hdq_fck)) {
dev_dbg(hdq_data->dev, "Can not enable fck\n");
clk_disable(hdq_data->hdq_ick);
ret = -ENODEV;
goto clk_err;
}

pm_runtime_get_sync(hdq_data->dev);

/* make sure HDQ is out of reset */
if (!(hdq_reg_in(hdq_data, OMAP_HDQ_SYSSTATUS) &
Expand All @@ -450,9 +439,6 @@ static int omap_hdq_get(struct hdq_data *hdq_data)
}
}

clk_err:
clk_put(hdq_data->hdq_ick);
clk_put(hdq_data->hdq_fck);
out:
mutex_unlock(&hdq_data->hdq_mutex);
rtn:
Expand All @@ -475,10 +461,8 @@ static int omap_hdq_put(struct hdq_data *hdq_data)
} else {
hdq_data->hdq_usecount--;
module_put(THIS_MODULE);
if (0 == hdq_data->hdq_usecount) {
clk_disable(hdq_data->hdq_ick);
clk_disable(hdq_data->hdq_fck);
}
if (0 == hdq_data->hdq_usecount)
pm_runtime_put_sync(hdq_data->dev);
}
mutex_unlock(&hdq_data->hdq_mutex);

Expand Down Expand Up @@ -591,35 +575,11 @@ static int __devinit omap_hdq_probe(struct platform_device *pdev)
goto err_ioremap;
}

/* get interface & functional clock objects */
hdq_data->hdq_ick = clk_get(&pdev->dev, "ick");
if (IS_ERR(hdq_data->hdq_ick)) {
dev_dbg(&pdev->dev, "Can't get HDQ ick clock object\n");
ret = PTR_ERR(hdq_data->hdq_ick);
goto err_ick;
}

hdq_data->hdq_fck = clk_get(&pdev->dev, "fck");
if (IS_ERR(hdq_data->hdq_fck)) {
dev_dbg(&pdev->dev, "Can't get HDQ fck clock object\n");
ret = PTR_ERR(hdq_data->hdq_fck);
goto err_fck;
}

hdq_data->hdq_usecount = 0;
mutex_init(&hdq_data->hdq_mutex);

if (clk_enable(hdq_data->hdq_ick)) {
dev_dbg(&pdev->dev, "Can not enable ick\n");
ret = -ENODEV;
goto err_intfclk;
}

if (clk_enable(hdq_data->hdq_fck)) {
dev_dbg(&pdev->dev, "Can not enable fck\n");
ret = -ENODEV;
goto err_fnclk;
}
pm_runtime_enable(&pdev->dev);
pm_runtime_get_sync(&pdev->dev);

rev = hdq_reg_in(hdq_data, OMAP_HDQ_REVISION);
dev_info(&pdev->dev, "OMAP HDQ Hardware Rev %c.%c. Driver in %s mode\n",
Expand All @@ -641,9 +601,7 @@ static int __devinit omap_hdq_probe(struct platform_device *pdev)

omap_hdq_break(hdq_data);

/* don't clock the HDQ until it is needed */
clk_disable(hdq_data->hdq_ick);
clk_disable(hdq_data->hdq_fck);
pm_runtime_put_sync(&pdev->dev);

omap_w1_master.data = hdq_data;

Expand All @@ -655,20 +613,11 @@ static int __devinit omap_hdq_probe(struct platform_device *pdev)

return 0;

err_w1:
err_irq:
clk_disable(hdq_data->hdq_fck);

err_fnclk:
clk_disable(hdq_data->hdq_ick);

err_intfclk:
clk_put(hdq_data->hdq_fck);

err_fck:
clk_put(hdq_data->hdq_ick);
pm_runtime_put_sync(&pdev->dev);
err_w1:
pm_runtime_disable(&pdev->dev);

err_ick:
iounmap(hdq_data->hdq_base);

err_ioremap:
Expand Down Expand Up @@ -696,8 +645,7 @@ static int omap_hdq_remove(struct platform_device *pdev)
mutex_unlock(&hdq_data->hdq_mutex);

/* remove module dependency */
clk_put(hdq_data->hdq_ick);
clk_put(hdq_data->hdq_fck);
pm_runtime_disable(&pdev->dev);
free_irq(INT_24XX_HDQ_IRQ, hdq_data);
platform_set_drvdata(pdev, NULL);
iounmap(hdq_data->hdq_base);
Expand Down

0 comments on commit c354a86

Please sign in to comment.