Skip to content

Commit

Permalink
ARM: PNX4008: move i2c clock start/stop into driver
Browse files Browse the repository at this point in the history
Acked-by: Vitaly Wool <vitalywool@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King committed Feb 12, 2010
1 parent a0dcf19 commit 0321cb8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 47 deletions.
36 changes: 0 additions & 36 deletions arch/arm/mach-pnx4008/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,6 @@
#include <mach/irqs.h>
#include <mach/i2c.h>

static int set_clock_run(struct platform_device *pdev)
{
struct clk *clk;
int retval = 0;

clk = clk_get(&pdev->dev, NULL);
if (!IS_ERR(clk)) {
clk_set_rate(clk, 1);
clk_put(clk);
} else
retval = -ENOENT;

return retval;
}

static int set_clock_stop(struct platform_device *pdev)
{
struct clk *clk;
int retval = 0;

clk = clk_get(&pdev->dev, NULL);
if (!IS_ERR(clk)) {
clk_set_rate(clk, 0);
clk_put(clk);
} else
retval = -ENOENT;

return retval;
}

static u32 calculate_input_freq(struct platform_device *pdev)
{
return HCLK_MHZ;
Expand Down Expand Up @@ -85,22 +55,16 @@ static struct i2c_adapter pnx_adapter2 = {

static struct i2c_pnx_data i2c0_data = {
.calculate_input_freq = calculate_input_freq,
.set_clock_run = set_clock_run,
.set_clock_stop = set_clock_stop,
.adapter = &pnx_adapter0,
};

static struct i2c_pnx_data i2c1_data = {
.calculate_input_freq = calculate_input_freq,
.set_clock_run = set_clock_run,
.set_clock_stop = set_clock_stop,
.adapter = &pnx_adapter1,
};

static struct i2c_pnx_data i2c2_data = {
.calculate_input_freq = calculate_input_freq,
.set_clock_run = set_clock_run,
.set_clock_stop = set_clock_stop,
.adapter = &pnx_adapter2,
};

Expand Down
39 changes: 30 additions & 9 deletions drivers/i2c/busses/i2c-pnx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <linux/platform_device.h>
#include <linux/i2c-pnx.h>
#include <linux/io.h>
#include <linux/err.h>
#include <linux/clk.h>

#include <mach/hardware.h>
#include <mach/i2c.h>
#include <asm/irq.h>
Expand Down Expand Up @@ -550,13 +553,22 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev,
pm_message_t state)
{
struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
return i2c_pnx->set_clock_run(pdev);
struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data;

/* FIXME: disable clock? */
clk_set_rate(alg_data->clk, 1);

return 0;
}

static int i2c_pnx_controller_resume(struct platform_device *pdev)
{
struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
return i2c_pnx->set_clock_run(pdev);
struct i2c_pnx_algo_data *alg_data = i2c_pnx->adapter->algo_data;

clk_set_rate(alg_data->clk, 1);

return 0;
}
#else
#define i2c_pnx_controller_suspend NULL
Expand All @@ -580,6 +592,15 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, i2c_pnx);

i2c_pnx->adapter->algo = &pnx_algorithm;
alg_data = i2c_pnx->adapter->algo_data;

alg_data->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(alg_data->clk)) {
ret = PTR_ERR(alg_data->clk);
goto out_drvdata;
}

if (i2c_pnx->calculate_input_freq)
freq_mhz = i2c_pnx->calculate_input_freq(pdev);
else {
Expand All @@ -588,9 +609,6 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
"%d MHz\n", freq_mhz);
}

i2c_pnx->adapter->algo = &pnx_algorithm;

alg_data = i2c_pnx->adapter->algo_data;
init_timer(&alg_data->mif.timer);
alg_data->mif.timer.function = i2c_pnx_timeout;
alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter;
Expand All @@ -602,7 +620,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
"I/O region 0x%08x for I2C already in use.\n",
alg_data->base);
ret = -ENODEV;
goto out_drvdata;
goto out_clkget;
}

if (!(alg_data->ioaddr =
Expand All @@ -612,7 +630,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
goto out_release;
}

i2c_pnx->set_clock_run(pdev);
clk_set_rate(alg_data->clk, 1);

/*
* Clock Divisor High This value is the number of system clocks
Expand Down Expand Up @@ -658,11 +676,13 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
out_irq:
free_irq(alg_data->irq, i2c_pnx->adapter);
out_clock:
i2c_pnx->set_clock_stop(pdev);
clk_set_rate(alg_data->clk, 0);
out_unmap:
iounmap((void *)alg_data->ioaddr);
out_release:
release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
out_clkget:
clk_put(alg_data->clk);
out_drvdata:
platform_set_drvdata(pdev, NULL);
out:
Expand All @@ -677,9 +697,10 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)

free_irq(alg_data->irq, i2c_pnx->adapter);
i2c_del_adapter(adap);
i2c_pnx->set_clock_stop(pdev);
clk_set_rate(alg_data->clk, 0);
iounmap((void *)alg_data->ioaddr);
release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
clk_put(alg_data->clk);
platform_set_drvdata(pdev, NULL);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions include/linux/i2c-pnx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define __I2C_PNX_H__

struct platform_device;
struct clk;

struct i2c_pnx_mif {
int ret; /* Return value */
Expand All @@ -29,12 +30,11 @@ struct i2c_pnx_algo_data {
int irq;
struct i2c_pnx_mif mif;
int last;
struct clk *clk;
};

struct i2c_pnx_data {
u32 (*calculate_input_freq) (struct platform_device *pdev);
int (*set_clock_run) (struct platform_device *pdev);
int (*set_clock_stop) (struct platform_device *pdev);
struct i2c_adapter *adapter;
};

Expand Down

0 comments on commit 0321cb8

Please sign in to comment.