Skip to contentSkip to conversation

clk: introduce omap_clk_associate

PATCH New Felipe Balbi 1 participant 3 messages Oct 25, 2008

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

PATCH 1/3 clk: introduce omap_clk_associate

From: Felipe Balbi <[email protected]>

Introduce a new mechanism to omap's clk implementation to associate consumer device(s) with its clock during platform_device registration.

With this mechanism we can also be sure drivers won't be able to clk_get the wrong clk (only true when we move all drivers to this new mechanism and drop the old ones).

---
 arch/arm/plat-omap/clock.c              |   47 ++++++++++++++++++++++++++++--
 arch/arm/plat-omap/include/mach/clock.h |    4 ++
 2 files changed, 47 insertions(+), 4 deletions(-)
arch/arm/plat-omap/clock.c +43 -4
index 5178701..083a3ff 100644
@@ -44,6 +44,7 @@ static struct clk_functions *arch_clock;
 struct clk * clk_get(struct device *dev, const char *id)
 {
 	struct clk *p, *clk = ERR_PTR(-ENOENT);
+	struct device *d;
 	int idno;
 
 	if (dev == NULL || dev->bus != &platform_bus_type)
@@ -54,27 +55,65 @@ struct clk * clk_get(struct device *dev, const char *id)
 	mutex_lock(&clocks_mutex);
 
 	list_for_each_entry(p, &clocks, node) {
+		list_for_each_entry(d, &p->consumers, node) {
+			if (dev == d) {
+				clk = p;
+				break;
+			}
+		}
+
 		if (p->id == idno &&
 		    strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
 			clk = p;
-			goto found;
+			break;
 		}
-	}
 
-	list_for_each_entry(p, &clocks, node) {
 		if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
 			clk = p;
 			break;
 		}
 	}
 
-found:
 	mutex_unlock(&clocks_mutex);
 
 	return clk;
 }
 EXPORT_SYMBOL(clk_get);
 
+/**
+ * omap_clk_associate - associates a clock to its consumer device(s)
+ * @id: clock id as defined in arch/arm/mach-omapX/clkxxxx.h
+ * @dev: device pointer for the clock consumer
+ *
+ * This function attempts to simplify clock handling for device drivers
+ * by letting struct clk know which device is the correct consumer for
+ * that clock. By making this trick, we let drivers get the correct
+ * clock without knowing about different clock names between omap
+ * versions.
+ */
+void __init omap_clk_associate(const char *id, struct device *dev)
+{
+	struct clk *clk = clk_get(NULL, id);
+
+	if (!clk || IS_ERR(clk)) {
+		pr_debug("%s: unable to get clock\n", __func__);
+		return;
+	}
+
+	if (!dev) {
+		pr_debug("%s: missing device to associate with\n", __func__);
+		clk_put(clk);
+		return;
+	}
+
+	if (list_empty(&clk->consumers))
+		INIT_LIST_HEAD(&clk->consumers);
+
+	/* add device to consumer list */
+	list_add(&dev->node, &clk->consumers);
+	clk_put(clk);
+};
+
 int clk_enable(struct clk *clk)
 {
 	unsigned long flags;
arch/arm/plat-omap/include/mach/clock.h +4 -0
index 9088925..1600a14 100644
@@ -13,6 +13,8 @@
 #ifndef __ARCH_ARM_OMAP_CLOCK_H
 #define __ARCH_ARM_OMAP_CLOCK_H
 
+#include <linux/device.h>
+
 struct module;
 struct clk;
 struct clockdomain;
@@ -61,6 +63,7 @@ struct dpll_data {
 
 struct clk {
 	struct list_head	node;
+	struct list_head	consumers;
 	struct module		*owner;
 	const char		*name;
 	int			id;
@@ -116,6 +119,7 @@ struct clk_functions {
 
 extern unsigned int mpurate;
 
+extern void omap_clk_associate(const char *id, struct device *dev);
 extern int clk_init(struct clk_functions *custom_clocks);
 extern int clk_register(struct clk *clk);
 extern void clk_unregister(struct clk *clk);
Signature · 1 line
1.6.0.2.307.gc427
#1 lore raw

PATCH 2/3 clk: use clk_associate for musb driver

From: Felipe Balbi <[email protected]>

Let musb use clk_associate to avoid introducing non-standard clk functions and passing a clk name via pdata.

---
 arch/arm/mach-omap2/board-n800-usb.c |   26 --------------------------
 arch/arm/mach-omap2/usb-musb.c       |   34 +++++++++-------------------------
 arch/arm/mach-omap2/usb-tusb6010.c   |    2 ++
 drivers/usb/musb/musb_core.c         |   23 +++++++----------------
 4 files changed, 18 insertions(+), 67 deletions(-)
arch/arm/mach-omap2/board-n800-usb.c +0 -26
index fc128f2..c5abc83 100644
@@ -25,7 +25,6 @@
 #define GPIO_TUSB_ENABLE	0
 
 static int tusb_set_power(int state);
-static int tusb_set_clock(struct clk *osc_ck, int state);
 
 #if	defined(CONFIG_USB_MUSB_OTG)
 #	define BOARD_MODE	MUSB_OTG
@@ -82,10 +81,8 @@ static struct musb_hdrc_config musb_config = {
 static struct musb_hdrc_platform_data tusb_data = {
 	.mode		= BOARD_MODE,
 	.set_power	= tusb_set_power,
-	.set_clock	= tusb_set_clock,
 	.min_power	= 25,	/* x2 = 50 mA drawn from VBUS as peripheral */
 	.power		= 100,	/* Max 100 mA VBUS for host mode */
-	.clock		= "osc_ck",
 	.config		= &musb_config,
 };
 
@@ -121,29 +118,6 @@ static int tusb_set_power(int state)
 	return retval;
 }
 
-static int		osc_ck_on;
-
-static int tusb_set_clock(struct clk *osc_ck, int state)
-{
-	if (state) {
-		if (osc_ck_on > 0)
-			return -ENODEV;
-
-		omap2_block_sleep();
-		clk_enable(osc_ck);
-		osc_ck_on = 1;
-	} else {
-		if (osc_ck_on == 0)
-			return -ENODEV;
-
-		clk_disable(osc_ck);
-		osc_ck_on = 0;
-		omap2_allow_sleep();
-	}
-
-	return 0;
-}
-
 void __init n800_usb_init(void)
 {
 	int ret = 0;
arch/arm/mach-omap2/usb-musb.c +9 -25
index 61c5709..99a1b4e 100644
@@ -31,6 +31,7 @@
 #include <mach/pm.h>
 #include <mach/mux.h>
 #include <mach/usb.h>
+#include <mach/clock.h>
 
 #ifdef CONFIG_USB_MUSB_SOC
 static struct resource musb_resources[] = {
@@ -53,27 +54,6 @@ static struct resource musb_resources[] = {
 	},
 };
 
-static int clk_on;
-
-static int musb_set_clock(struct clk *clk, int state)
-{
-	if (state) {
-		if (clk_on > 0)
-			return -ENODEV;
-
-		clk_enable(clk);
-		clk_on = 1;
-	} else {
-		if (clk_on == 0)
-			return -ENODEV;
-
-		clk_disable(clk);
-		clk_on = 0;
-	}
-
-	return 0;
-}
-
 static struct musb_hdrc_eps_bits musb_eps[] = {
 	{	"ep1_tx", 10,	},
 	{	"ep1_rx", 10,	},
@@ -127,10 +107,6 @@ static struct musb_hdrc_platform_data musb_plat = {
 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
 	.mode		= MUSB_PERIPHERAL,
 #endif
-	.clock		= cpu_is_omap34xx()
-			? "hsotgusb_ick"
-			: "usbhs_ick",
-	.set_clock	= musb_set_clock,
 	.config		= &musb_config,
 
 	/* REVISIT charge pump on TWL4030 can supply up to
@@ -159,6 +135,14 @@ static struct platform_device musb_device = {
 void __init usb_musb_init(void)
 {
 #ifdef CONFIG_USB_MUSB_SOC
+	/* associate musb clocks with musb device */
+
+	if (cpu_is_omap34xx())
+		omap_clk_associate("hsotgusb_ick", &musb_device.dev);
+
+	if (cpu_is_omap24xx())
+		omap_clk_associate("usbhs_ick", &musb_device.dev);
+
 	if (platform_device_register(&musb_device) < 0) {
 		printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
 		return;
arch/arm/mach-omap2/usb-tusb6010.c +2 -0
index 2c88207..86e1f42 100644
@@ -18,6 +18,7 @@
 #include <mach/gpmc.h>
 #include <mach/gpio.h>
 #include <mach/mux.h>
+#include <mach/clock.h>
 
 
 static u8		async_cs, sync_cs;
@@ -250,6 +251,7 @@ tusb6010_setup_interface(struct musb_hdrc_platform_data *data,
 		printk(error, 1, status);
 		return status;
 	}
+	omap_clk_associate("osc_ck", &tusb_device.dev);
 	tusb_resources[0].end = tusb_resources[0].start + 0x9ff;
 	async_cs = async;
 	gpmc_cs_write_reg(async, GPMC_CS_CONFIG1,
drivers/usb/musb/musb_core.c +7 -16
index 128e949..ea9dd90 100644
@@ -1922,7 +1922,6 @@ bad_config:
 	spin_lock_init(&musb->lock);
 	musb->board_mode = plat->mode;
 	musb->board_set_power = plat->set_power;
-	musb->set_clock = plat->set_clock;
 	musb->min_power = plat->min_power;
 
 	/* Clock usage is chip-specific ... functional clock (DaVinci,
@@ -1930,13 +1929,11 @@ bad_config:
 	 * code does is make sure a clock handle is available; platform
 	 * code manages it during start/stop and suspend/resume.
 	 */
-	if (plat->clock) {
-		musb->clock = clk_get(dev, plat->clock);
-		if (IS_ERR(musb->clock)) {
-			status = PTR_ERR(musb->clock);
-			musb->clock = NULL;
-			goto fail;
-		}
+	musb->clock = clk_get(dev, "iclk");
+	if (IS_ERR(musb->clock)) {
+		status = PTR_ERR(musb->clock);
+		musb->clock = NULL;
+		goto fail;
 	}
 
 	/* assume vbus is off */
@@ -2159,10 +2156,7 @@ static int musb_suspend(struct platform_device *pdev, pm_message_t message)
 		 */
 	}
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 0);
-	else
-		clk_disable(musb->clock);
+	clk_disable(musb->clock);
 	spin_unlock_irqrestore(&musb->lock, flags);
 	return 0;
 }
@@ -2177,10 +2171,7 @@ static int musb_resume(struct platform_device *pdev)
 
 	spin_lock_irqsave(&musb->lock, flags);
 
-	if (musb->set_clock)
-		musb->set_clock(musb->clock, 1);
-	else
-		clk_enable(musb->clock);
+	clk_enable(musb->clock);
 
 	/* for static cmos like DaVinci, register values were preserved
 	 * unless for some reason the whole soc powered down and we're
Signature · 1 line
1.6.0.2.307.gc427
#2 lore raw

PATCH 3/3 clk: use clk_associate on watchdog driver

From: Felipe Balbi <[email protected]>

Get rid of clk mess on omap_watchdog driver by
using clk_associate.

Cc Wim Van Sebroeck <[email protected]>
---
 arch/arm/plat-omap/devices.c |   18 ++++++--
 drivers/watchdog/omap_wdt.c  |   87 ++++++++++++-----------------------------
 2 files changed, 39 insertions(+), 66 deletions(-)
arch/arm/plat-omap/devices.c +13 -5
index c22bd5f..c53c333 100644
@@ -298,16 +298,24 @@ static struct platform_device omap_wdt_device = {
 
 static void omap_init_wdt(void)
 {
-	if (cpu_is_omap16xx())
+	if (cpu_is_omap16xx()) {
+		omap_clk_associate("armwdt_ck", &omap_wdt_device.dev);
 		wdt_resources[0].start = 0xfffeb000;
-	else if (cpu_is_omap2420())
+	} else if (cpu_is_omap2420()) {
+		omap_clk_associate("mpu_wdt_fck", &omap_wdt_device.dev);
+		omap_clk_associate("mpu_wdt_ick", &omap_wdt_device.dev);
 		wdt_resources[0].start = 0x48022000; /* WDT2 */
-	else if (cpu_is_omap2430())
+	} else if (cpu_is_omap2430()) {
+		omap_clk_associate("mpu_wdt_fck", &omap_wdt_device.dev);
+		omap_clk_associate("mpu_wdt_ick", &omap_wdt_device.dev);
 		wdt_resources[0].start = 0x49016000; /* WDT2 */
-	else if (cpu_is_omap343x())
+	} else if (cpu_is_omap343x()) {
+		omap_clk_associate("wdt2_fck", &omap_wdt_device.dev);
+		omap_clk_associate("wdt2_ick", &omap_wdt_device.dev);
 		wdt_resources[0].start = 0x48314000; /* WDT2 */
-	else
+	} else {
 		return;
+	}
 
 	wdt_resources[0].end = wdt_resources[0].start + 0x4f;
 
drivers/watchdog/omap_wdt.c +26 -61

123 lines not on this page · raw message

Signature · 1 line
1.6.0.2.307.gc427