From a23a175795cdb202619ac176129b2f0c2a5c9456 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Tue, 17 Feb 2009 10:06:41 +0100 Subject: mfd: convert DS1WM to use MFD core This patch converts the DS1WM driver into an MFD cell. It also calculates the bus_shift parameter from the memory resource size. Signed-off-by: Philipp Zabel Signed-off-by: Samuel Ortiz --- drivers/w1/masters/ds1wm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'drivers/w1/masters/ds1wm.c') diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c index 29e144f81cbe..f1e6b3dd1e43 100644 --- a/drivers/w1/masters/ds1wm.c +++ b/drivers/w1/masters/ds1wm.c @@ -19,7 +19,8 @@ #include #include #include -#include +#include +#include #include @@ -89,7 +90,7 @@ struct ds1wm_data { void __iomem *map; int bus_shift; /* # of shifts to calc register offsets */ struct platform_device *pdev; - struct ds1wm_platform_data *pdata; + struct mfd_cell *cell; int irq; int active_high; struct clk *clk; @@ -217,8 +218,8 @@ static void ds1wm_up(struct ds1wm_data *ds1wm_data) { int gclk, divisor; - if (ds1wm_data->pdata->enable) - ds1wm_data->pdata->enable(ds1wm_data->pdev); + if (ds1wm_data->cell->enable) + ds1wm_data->cell->enable(ds1wm_data->pdev); gclk = clk_get_rate(ds1wm_data->clk); clk_enable(ds1wm_data->clk); @@ -244,8 +245,8 @@ static void ds1wm_down(struct ds1wm_data *ds1wm_data) ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0); - if (ds1wm_data->pdata->disable) - ds1wm_data->pdata->disable(ds1wm_data->pdev); + if (ds1wm_data->cell->disable) + ds1wm_data->cell->disable(ds1wm_data->pdev); clk_disable(ds1wm_data->clk); } @@ -330,13 +331,18 @@ static struct w1_bus_master ds1wm_master = { static int ds1wm_probe(struct platform_device *pdev) { struct ds1wm_data *ds1wm_data; - struct ds1wm_platform_data *plat; + struct ds1wm_driver_data *plat; struct resource *res; + struct mfd_cell *cell; int ret; if (!pdev) return -ENODEV; + cell = pdev->dev.platform_data; + if (!cell) + return -ENODEV; + ds1wm_data = kzalloc(sizeof(*ds1wm_data), GFP_KERNEL); if (!ds1wm_data) return -ENOMEM; @@ -348,15 +354,18 @@ static int ds1wm_probe(struct platform_device *pdev) ret = -ENXIO; goto err0; } - ds1wm_data->map = ioremap(res->start, res->end - res->start + 1); + ds1wm_data->map = ioremap(res->start, resource_size(res)); if (!ds1wm_data->map) { ret = -ENOMEM; goto err0; } - plat = pdev->dev.platform_data; - ds1wm_data->bus_shift = plat->bus_shift; + plat = cell->driver_data; + + /* calculate bus shift from mem resource */ + ds1wm_data->bus_shift = resource_size(res) >> 3; + ds1wm_data->pdev = pdev; - ds1wm_data->pdata = plat; + ds1wm_data->cell = cell; res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!res) { -- cgit v1.2.3 From 7d33ccbeecd8393cc690cf9a71008236cdd7cc2c Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Tue, 17 Feb 2009 10:09:19 +0100 Subject: mfd: remove DS1WM clock handling This driver requests a clock that usually is supplied by the MFD in which the DS1WM is contained. Currently, it is impossible for a MFD to register their clocks with the generic clock API due to different implementations across architectures. For now, this patch removes the clock handling from DS1WM altogether, trusting that the MFD enable/disable functions will switch the clock if needed. The clock rate is obtained from a new parameter in driver_data. Signed-off-by: Philipp Zabel Signed-off-by: Samuel Ortiz --- drivers/w1/masters/ds1wm.c | 27 +++++++-------------------- include/linux/mfd/ds1wm.h | 1 + 2 files changed, 8 insertions(+), 20 deletions(-) (limited to 'drivers/w1/masters/ds1wm.c') diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c index f1e6b3dd1e43..37f08c850608 100644 --- a/drivers/w1/masters/ds1wm.c +++ b/drivers/w1/masters/ds1wm.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -93,7 +92,6 @@ struct ds1wm_data { struct mfd_cell *cell; int irq; int active_high; - struct clk *clk; int slave_present; void *reset_complete; void *read_complete; @@ -216,17 +214,17 @@ static int ds1wm_find_divisor(int gclk) static void ds1wm_up(struct ds1wm_data *ds1wm_data) { - int gclk, divisor; + int divisor; + struct ds1wm_driver_data *plat = ds1wm_data->cell->driver_data; if (ds1wm_data->cell->enable) ds1wm_data->cell->enable(ds1wm_data->pdev); - gclk = clk_get_rate(ds1wm_data->clk); - clk_enable(ds1wm_data->clk); - divisor = ds1wm_find_divisor(gclk); + divisor = ds1wm_find_divisor(plat->clock_rate); if (divisor == 0) { dev_err(&ds1wm_data->pdev->dev, - "no suitable divisor for %dHz clock\n", gclk); + "no suitable divisor for %dHz clock\n", + plat->clock_rate); return; } ds1wm_write_register(ds1wm_data, DS1WM_CLKDIV, divisor); @@ -247,8 +245,6 @@ static void ds1wm_down(struct ds1wm_data *ds1wm_data) if (ds1wm_data->cell->disable) ds1wm_data->cell->disable(ds1wm_data->pdev); - - clk_disable(ds1wm_data->clk); } /* --------------------------------------------------------------------- */ @@ -385,26 +381,18 @@ static int ds1wm_probe(struct platform_device *pdev) if (ret) goto err1; - ds1wm_data->clk = clk_get(&pdev->dev, "ds1wm"); - if (IS_ERR(ds1wm_data->clk)) { - ret = PTR_ERR(ds1wm_data->clk); - goto err2; - } - ds1wm_up(ds1wm_data); ds1wm_master.data = (void *)ds1wm_data; ret = w1_add_master_device(&ds1wm_master); if (ret) - goto err3; + goto err2; return 0; -err3: - ds1wm_down(ds1wm_data); - clk_put(ds1wm_data->clk); err2: + ds1wm_down(ds1wm_data); free_irq(ds1wm_data->irq, ds1wm_data); err1: iounmap(ds1wm_data->map); @@ -443,7 +431,6 @@ static int ds1wm_remove(struct platform_device *pdev) w1_remove_master_device(&ds1wm_master); ds1wm_down(ds1wm_data); - clk_put(ds1wm_data->clk); free_irq(ds1wm_data->irq, ds1wm_data); iounmap(ds1wm_data->map); kfree(ds1wm_data); diff --git a/include/linux/mfd/ds1wm.h b/include/linux/mfd/ds1wm.h index d4898ba18207..be469a357cbb 100644 --- a/include/linux/mfd/ds1wm.h +++ b/include/linux/mfd/ds1wm.h @@ -2,4 +2,5 @@ struct ds1wm_driver_data { int active_high; + int clock_rate; }; -- cgit v1.2.3