Skip to contentSkip to conversation

fix PASIC3/DS1WM, use MFD core

PATCH In review Philipp Zabel 3 participants 10 messages Feb 5, 2009 – Feb 6, 2009

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover fix PASIC3/DS1WM, use MFD core

Hi,

the following patches turn DS1WM into an MFD cell driver, make PASIC3 use the MFD core functions to register it and remove the generic clock API code from DS1WM as MFDs currently can't register their clocks with it. With those applied, 1-Wire is finally in a working state on magician.

Patch #2 depends on #1, patch #4 depends on #3 and patch #6 depends on #5. Therefor I propose that this whole patchset be queued in the mfd tree. If so, #4 could be merged into #2. But it won't hurt to just leave out #3 and #4 for now and apply them as cleanups later.

Philipp Zabel (6):
mfd: DS1WM: convert to use MFD core
mfd: PASIC3: convert to use MFD core
pxa/magician: remove deprecated .bus_shift from PASIC3 platform_data
mfd: PASIC3: remove unused bus_shift field
mfd: DS1WM: remove clock handling
mfd: PASIC3: supply clock_rate to DS1WM via driver_data

 arch/arm/mach-pxa/magician.c   |    1 -
 drivers/mfd/Kconfig            |    1 +
 drivers/mfd/htc-pasic3.c       |  169 ++++++++++++++++------------------------
 drivers/w1/masters/ds1wm.c     |   53 ++++++-------
 include/linux/ds1wm.h          |   12 ---
 include/linux/mfd/ds1wm.h      |    6 ++
 include/linux/mfd/htc-pasic3.h |    1 -
 7 files changed, 100 insertions(+), 143 deletions(-)
 delete mode 100644 include/linux/ds1wm.h
 create mode 100644 include/linux/mfd/ds1wm.h
#1 lore raw

PATCH 1/6 mfd: DS1WM: convert 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.

---
 drivers/w1/masters/ds1wm.c |   31 ++++++++++++++++++++-----------
 include/linux/ds1wm.h      |   12 ------------
 include/linux/mfd/ds1wm.h  |    5 +++++
 3 files changed, 25 insertions(+), 23 deletions(-)
 delete mode 100644 include/linux/ds1wm.h
 create mode 100644 include/linux/mfd/ds1wm.h
drivers/w1/masters/ds1wm.c +20 -11
index 29e144f..f1e6b3d 100644
@@ -19,7 +19,8 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/delay.h>
-#include <linux/ds1wm.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/ds1wm.h>
 
 #include <asm/io.h>
 
@@ -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) {
include/linux/ds1wm.h deleted +0 -12
deleted file mode 100644
index d3c65e4..0000000
@@ -1,12 +0,0 @@
-/* platform data for the DS1WM driver */
-
-struct ds1wm_platform_data {
-	int bus_shift;	    /* number of shifts needed to calculate the
-			     * offset between DS1WM registers;
-			     * e.g. on h5xxx and h2200 this is 2
-			     * (registers aligned to 4-byte boundaries),
-			     * while on hx4700 this is 1 */
-	int active_high;
-	void (*enable)(struct platform_device *pdev);
-	void (*disable)(struct platform_device *pdev);
-};
include/linux/mfd/ds1wm.h new file +5 -0
new file mode 100644
index 0000000..d4898ba
@@ -0,0 +1,5 @@
+/* MFD cell driver data for the DS1WM driver */
+
+struct ds1wm_driver_data {
+	int active_high;
+};
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 2/6 mfd: PASIC3: convert to use MFD core

In reply to Philipp Zabel

This patch makes htc-pasic3 register the DS1WM and LED cell drivers through the MFD core infrastructure instead of allocating the platform devices manually. It also calculates the bus_shift parameter from the memory resource size.

---
 drivers/mfd/Kconfig      |    1 +
 drivers/mfd/htc-pasic3.c |  159 ++++++++++++++++++----------------------------
 2 files changed, 62 insertions(+), 98 deletions(-)
drivers/mfd/Kconfig +1 -0
index 06a2b0f..da2d4c5 100644
@@ -52,6 +52,7 @@ config HTC_EGPIO
 
 config HTC_PASIC3
 	tristate "HTC PASIC3 LED/DS1WM chip support"
+	select MFD_CORE
 	help
 	  This core driver provides register access for the LED/DS1WM
 	  chips labeled "AIC2" and "AIC3", found on HTC Blueangel and
drivers/mfd/htc-pasic3.c +61 -98

240 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 3/6 pxa/magician: remove deprecated .bus_shift from PASIC3 platform_data

In reply to Philipp Zabel

The PASIC3 driver now calculates its register spacing from the resource size.

---
 arch/arm/mach-pxa/magician.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
arch/arm/mach-pxa/magician.c +0 -1
index 21b821e..8e21181 100644
@@ -495,7 +495,6 @@ static struct resource pasic3_resources[] = {
 };
 
 static struct pasic3_platform_data pasic3_platform_data = {
-	.bus_shift  = 2,
 	.led_pdata  = &pasic3_leds_info,
 	.clock_rate = 4000000,
 };
Signature · 1 line
1.5.6.5
#4 lore raw

PATCH 4/6 mfd: PASIC3: remove unused bus_shift field

In reply to Philipp Zabel

Removes the now-unused bus_shift field from pasic3_platform_data.

---
 include/linux/mfd/htc-pasic3.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
include/linux/mfd/htc-pasic3.h +0 -1
index b4294f1..3d3ed67 100644
@@ -48,7 +48,6 @@ struct pasic3_leds_machinfo {
 
 struct pasic3_platform_data {
 	struct pasic3_leds_machinfo *led_pdata;
-	unsigned int                 bus_shift;
 	unsigned int                 clock_rate;
 };
 
Signature · 1 line
1.5.6.5
#5 lore raw

PATCH 5/6 mfd: DS1WM: remove clock handling

In reply to Philipp Zabel

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.

---
 drivers/w1/masters/ds1wm.c |   22 +++++-----------------
 include/linux/mfd/ds1wm.h  |    1 +
 2 files changed, 6 insertions(+), 17 deletions(-)
drivers/w1/masters/ds1wm.c +5 -17
index f1e6b3d..b982aa6 100644
@@ -16,7 +16,6 @@
 #include <linux/irq.h>
 #include <linux/pm.h>
 #include <linux/platform_device.h>
-#include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/delay.h>
 #include <linux/mfd/core.h>
@@ -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,12 +381,6 @@ 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;
@@ -403,7 +393,6 @@ static int ds1wm_probe(struct platform_device *pdev)
 
 err3:
 	ds1wm_down(ds1wm_data);
-	clk_put(ds1wm_data->clk);
 err2:
 	free_irq(ds1wm_data->irq, ds1wm_data);
 err1:
@@ -443,7 +432,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);
include/linux/mfd/ds1wm.h +1 -0
index d4898ba..be469a3 100644
@@ -2,4 +2,5 @@
 
 struct ds1wm_driver_data {
 	int active_high;
+	int clock_rate;
 };
Signature · 1 line
1.5.6.5
#6 lore raw

PATCH 1/1 mfd: DS1WM: remove warning about unused label err2

Hi Samuel,

thanks for queuing the patchset. Could you please fold this into the DS1WM clock removal patch?

---
 drivers/w1/masters/ds1wm.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/w1/masters/ds1wm.c +2 -3
index b982aa6..37f08c8 100644
@@ -387,13 +387,12 @@ static int ds1wm_probe(struct platform_device *pdev)
 
 	ret = w1_add_master_device(&ds1wm_master);
 	if (ret)
-		goto err3;
+		goto err2;
 
 	return 0;
 
-err3:
-	ds1wm_down(ds1wm_data);
 err2:
+	ds1wm_down(ds1wm_data);
 	free_irq(ds1wm_data->irq, ds1wm_data);
 err1:
 	iounmap(ds1wm_data->map);
Signature · 1 line
1.5.6.5
#7 lore raw

PATCH 6/6 mfd: PASIC3: supply clock_rate to DS1WM via driver_data

In reply to Philipp Zabel
---
 drivers/mfd/htc-pasic3.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)
drivers/mfd/htc-pasic3.c +13 -9
index 92b6837..386da15 100644
@@ -167,15 +167,19 @@ static int __init pasic3_probe(struct platform_device *pdev)
 	/* calculate bus shift from mem resource */
 	asic->bus_shift = (resource_size(r) - 5) >> 3;
 
-	/* the first 5 PASIC3 registers control the DS1WM */
-	ds1wm_resources[0].end = (5 << asic->bus_shift) - 1;
-	ds1wm_cell.platform_data = &ds1wm_cell;
-	ds1wm_cell.data_size = sizeof(ds1wm_cell);
-	ret = mfd_add_devices(&pdev->dev, pdev->id, &ds1wm_cell, 1, r, irq);
-	if (ret < 0)
-		dev_warn(dev, "failed to register DS1WM\n");
-
-	if (pdata->led_pdata) {
+	if (pdata && pdata->clock_rate) {
+		ds1wm_pdata.clock_rate = pdata->clock_rate;
+		/* the first 5 PASIC3 registers control the DS1WM */
+		ds1wm_resources[0].end = (5 << asic->bus_shift) - 1;
+		ds1wm_cell.platform_data = &ds1wm_cell;
+		ds1wm_cell.data_size = sizeof(ds1wm_cell);
+		ret = mfd_add_devices(&pdev->dev, pdev->id,
+				&ds1wm_cell, 1, r, irq);
+		if (ret < 0)
+			dev_warn(dev, "failed to register DS1WM\n");
+	}
+
+	if (pdata && pdata->led_pdata) {
 		led_cell.driver_data = pdata->led_pdata;
 		led_cell.platform_data = &led_cell;
 		led_cell.data_size = sizeof(ds1wm_cell);
Signature · 1 line
1.5.6.5
#8 lore raw
In reply to Philipp Zabel

Hi Philipp.

Quoted 4 lines · Philipp Zabel

the following patches turn DS1WM into an MFD cell driver, make PASIC3 use the MFD core functions to register it and remove the generic clock API code from DS1WM as MFDs currently can't register their clocks with it. With those applied, 1-Wire is finally in a working state on magician.

Looks good. Feel free to add my ack if needed.
Drop a mail if you want to me to push it upstream separately from the core part it depends on.

Signature · 1 line
	Evgeniy Polyakov
#9 lore raw
In reply to Philipp Zabel

Hi Philipp,

Quoted 11 lines · Philipp Zabel

Hi,

the following patches turn DS1WM into an MFD cell driver, make PASIC3 use the MFD core functions to register it and remove the generic clock API code from DS1WM as MFDs currently can't register their clocks with it. With those applied, 1-Wire is finally in a working state on magician.

Patch #2 depends on #1, patch #4 depends on #3 and patch #6 depends on #5. Therefor I propose that this whole patchset be queued in the mfd tree. If so, #4 could be merged into #2. But it won't hurt to just leave out #3 and #4 for now and apply them as cleanups later.

The patches look good to me. I'll merge the 6 of them into my for-next branch.

Thanks for this work.

Cheers,
Samuel.

Quoted 18 lines

Philipp Zabel (6):
mfd: DS1WM: convert to use MFD core
mfd: PASIC3: convert to use MFD core
pxa/magician: remove deprecated .bus_shift from PASIC3 platform_data
mfd: PASIC3: remove unused bus_shift field
mfd: DS1WM: remove clock handling
mfd: PASIC3: supply clock_rate to DS1WM via driver_data

 arch/arm/mach-pxa/magician.c   |    1 -
 drivers/mfd/Kconfig            |    1 +
 drivers/mfd/htc-pasic3.c       |  169 ++++++++++++++++------------------------
 drivers/w1/masters/ds1wm.c     |   53 ++++++-------
 include/linux/ds1wm.h          |   12 ---
 include/linux/mfd/ds1wm.h      |    6 ++
 include/linux/mfd/htc-pasic3.h |    1 -
 7 files changed, 100 insertions(+), 143 deletions(-)
 delete mode 100644 include/linux/ds1wm.h
 create mode 100644 include/linux/mfd/ds1wm.h
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/