Skip to contentSkip to conversation

clk: Add non CONFIG_HAVE_CLK routines

PATCH Superseded Viresh Kumar 2 participants 14 messages Apr 24, 2012

Subsystems (10)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover clk: Add non CONFIG_HAVE_CLK routines

Many drivers are shared between architectures that may or may not have HAVE_CLK selected for them. To remove compilation errors for them we enclose clk_*() calls in these drivers within #ifdef CONFIG_HAVE_CLK, #endif.

This patchset removes the need of these CONFIG_HAVE_CLK statements, by introducing dummy routines when HAVE_CLK is not selected by platforms. So, definition of these routines will always be available. These calls will return error for platforms that don't select HAVE_CLK.

V1->V2:
- Removed few patches as they might break working drivers
- Updated 1st patch, as it doesn't apply cleanly on latest linux-next after this got applied.

commit a8a97db984bdc5e89d42e41891543d2daaf314cb
Author: Mark Brown <[email protected]>
Date: Thu Apr 5 11:42:09 2012 +0100

ARM: 7376/1: clkdev: Implement managed clk_get()

- Similarly, updated stmmac patch as there were updates for it too.

Viresh Kumar (9):
clk: Add non CONFIG_HAVE_CLK routines
clk: Remove redundant depends on from drivers/Kconfig ata/pata_arasan: Remove conditional compilation of clk code ata/sata_mv: Remove conditional compilation of clk code net/c_can: Remove conditional compilation of clk code net/stmmac: Remove conditional compilation of clk code gadget/m66592: Remove conditional compilation of clk code gadget/r8a66597: Remove conditional compilation of clk code usb/host/r8a66597: Remove conditional compilation of clk code

 drivers/ata/pata_arasan_cf.c                      |   39 ++---
 drivers/ata/sata_mv.c                             |   10 --
 drivers/clk/Kconfig                               |    2 -
 drivers/net/can/c_can/c_can_platform.c            |   28 ++--
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |   41 -----
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   31 +++--
 drivers/usb/gadget/m66592-udc.c                   |   19 +--
 drivers/usb/gadget/m66592-udc.h                   |    5 -
 drivers/usb/gadget/r8a66597-udc.c                 |   21 +--
 drivers/usb/gadget/r8a66597-udc.h                 |    5 -
 drivers/usb/host/r8a66597-hcd.c                   |   28 +---
 drivers/usb/host/r8a66597.h                       |    5 -
 include/linux/clk.h                               |  168 +++++++++++++-------
 13 files changed, 176 insertions(+), 226 deletions(-)
Signature · 1 line
1.7.9
#1 lore raw

PATCH v2 1/9 clk: Add non CONFIG_HAVE_CLK routines

Many drivers are shared between architectures that may or may not have HAVE_CLK selected for them. To remove compilation errors for them we enclose clk_*() calls in these drivers within #ifdef CONFIG_HAVE_CLK, #endif.

This patch removes the need of these CONFIG_HAVE_CLK statements, by introducing dummy routines when HAVE_CLK is not selected by platforms. So, definition of these routines will always be available. These calls will return error for platforms that don't select HAVE_CLK.

---
 include/linux/clk.h |  168 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 109 insertions(+), 59 deletions(-)
include/linux/clk.h +109 -59
index 70cf722..3266b0c 100644
@@ -84,6 +84,43 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb);
 #endif /* !CONFIG_COMMON_CLK */
 
 /**
+ * clk_prepare - prepare a clock source
+ * @clk: clock source
+ *
+ * This prepares the clock source for use.
+ *
+ * Must not be called from within atomic context.
+ */
+#ifdef CONFIG_HAVE_CLK_PREPARE
+int clk_prepare(struct clk *clk);
+#else
+static inline int clk_prepare(struct clk *clk)
+{
+	might_sleep();
+	return 0;
+}
+#endif
+
+/**
+ * clk_unprepare - undo preparation of a clock source
+ * @clk: clock source
+ *
+ * This undoes a previously prepared clock.  The caller must balance
+ * the number of prepare and unprepare calls.
+ *
+ * Must not be called from within atomic context.
+ */
+#ifdef CONFIG_HAVE_CLK_PREPARE
+void clk_unprepare(struct clk *clk);
+#else
+static inline void clk_unprepare(struct clk *clk)
+{
+	might_sleep();
+}
+#endif
+
+#ifdef CONFIG_HAVE_CLK
+/**
  * clk_get - lookup and obtain a reference to a clock producer.
  * @dev: device for clock "consumer"
  * @id: clock comsumer ID
@@ -121,24 +158,6 @@ struct clk *clk_get(struct device *dev, const char *id);
 struct clk *devm_clk_get(struct device *dev, const char *id);
 
 /**
- * clk_prepare - prepare a clock source
- * @clk: clock source
- *
- * This prepares the clock source for use.
- *
- * Must not be called from within atomic context.
- */
-#ifdef CONFIG_HAVE_CLK_PREPARE
-int clk_prepare(struct clk *clk);
-#else
-static inline int clk_prepare(struct clk *clk)
-{
-	might_sleep();
-	return 0;
-}
-#endif
-
-/**
  * clk_enable - inform the system when the clock source should be running.
  * @clk: clock source
  *
@@ -166,47 +185,6 @@ int clk_enable(struct clk *clk);
  */
 void clk_disable(struct clk *clk);
 
-
-/**
- * clk_unprepare - undo preparation of a clock source
- * @clk: clock source
- *
- * This undoes a previously prepared clock.  The caller must balance
- * the number of prepare and unprepare calls.
- *
- * Must not be called from within atomic context.
- */
-#ifdef CONFIG_HAVE_CLK_PREPARE
-void clk_unprepare(struct clk *clk);
-#else
-static inline void clk_unprepare(struct clk *clk)
-{
-	might_sleep();
-}
-#endif
-
-/* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
-static inline int clk_prepare_enable(struct clk *clk)
-{
-	int ret;
-
-	ret = clk_prepare(clk);
-	if (ret)
-		return ret;
-	ret = clk_enable(clk);
-	if (ret)
-		clk_unprepare(clk);
-
-	return ret;
-}
-
-/* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
-static inline void clk_disable_unprepare(struct clk *clk)
-{
-	clk_disable(clk);
-	clk_unprepare(clk);
-}
-
 /**
  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
  *		  This is only valid once the clock source has been enabled.
@@ -297,6 +275,78 @@ struct clk *clk_get_parent(struct clk *clk);
  */
 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
 
+#else /* !CONFIG_HAVE_CLK */
+
+static inline struct clk *clk_get(struct device *dev, const char *id)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline struct clk *devm_clk_get(struct device *dev, const char *id)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline void clk_put(struct clk *clk) {}
+
+static inline void devm_clk_put(struct device *dev, struct clk *clk) {}
+
+static inline int clk_enable(struct clk *clk)
+{
+	return -ENODEV;
+}
+
+static inline void clk_disable(struct clk *clk) {}
+
+static inline unsigned long clk_get_rate(struct clk *clk)
+{
+	return -ENODEV;
+}
+
+static inline int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+	return -ENODEV;
+}
+
+static inline long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+	return -ENODEV;
+}
+
+static inline int clk_set_parent(struct clk *clk, struct clk *parent)
+{
+	return -ENODEV;
+}
+
+static inline struct clk *clk_get_parent(struct clk *clk)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+#endif
+
+/* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
+static inline int clk_prepare_enable(struct clk *clk)
+{
+	int ret;
+
+	ret = clk_prepare(clk);
+	if (ret)
+		return ret;
+	ret = clk_enable(clk);
+	if (ret)
+		clk_unprepare(clk);
+
+	return ret;
+}
+
+/* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
+static inline void clk_disable_unprepare(struct clk *clk)
+{
+	clk_disable(clk);
+	clk_unprepare(clk);
+}
+
 /**
  * clk_add_alias - add a new clock alias
  * @alias: name for clock alias
Signature · 1 line
1.7.9
#2 lore raw

PATCH v2 2/9 clk: Remove redundant depends on from drivers/Kconfig

In reply to Viresh Kumar

menu "Common Clock Framework" has "depends on COMMON_CLK" and so configs defined within menu don't require these "depends on COMMON_CLK again".

---
 drivers/clk/Kconfig |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/clk/Kconfig +0 -2
index 165e1fe..4f10a21 100644
@@ -24,7 +24,6 @@ menu "Common Clock Framework"
 
 config COMMON_CLK_DISABLE_UNUSED
 	bool "Disabled unused clocks at boot"
-	depends on COMMON_CLK
 	---help---
 	  Traverses the entire clock tree and disables any clocks that are
 	  enabled in hardware but have not been enabled by any device drivers.
@@ -35,7 +34,6 @@ config COMMON_CLK_DISABLE_UNUSED
 
 config COMMON_CLK_DEBUG
 	bool "DebugFS representation of clock tree"
-	depends on COMMON_CLK
 	select DEBUG_FS
 	---help---
 	  Creates a directory hierchy in debugfs for visualizing the clk
Signature · 1 line
1.7.9
#3 lore raw

PATCH v2 3/9 ata/pata_arasan: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc Jeff Garzik <[email protected]>
Cc linux-ide at vger.kernel.org
---
 drivers/ata/pata_arasan_cf.c |   39 ++++++++++++++++-----------------------
 1 files changed, 16 insertions(+), 23 deletions(-)
drivers/ata/pata_arasan_cf.c +16 -23
index fc2db2a..b370e35 100644
@@ -184,10 +184,8 @@
 struct arasan_cf_dev {
 	/* pointer to ata_host structure */
 	struct ata_host *host;
-	/* clk structure, only if HAVE_CLK is defined */
-#ifdef CONFIG_HAVE_CLK
+	/* clk structure */
 	struct clk *clk;
-#endif
 
 	/* physical base address of controller */
 	dma_addr_t pbase;
@@ -312,13 +310,13 @@ static int cf_init(struct arasan_cf_dev *acdev)
 	unsigned long flags;
 	int ret = 0;
 
-#ifdef CONFIG_HAVE_CLK
-	ret = clk_enable(acdev->clk);
-	if (ret) {
-		dev_dbg(acdev->host->dev, "clock enable failed");
-		return ret;
+	if (!IS_ERR(acdev->clk)) {
+		ret = clk_enable(acdev->clk);
+		if (ret) {
+			dev_dbg(acdev->host->dev, "clock enable failed");
+			return ret;
+		}
 	}
-#endif
 
 	spin_lock_irqsave(&acdev->host->lock, flags);
 	/* configure CF interface clock */
@@ -344,9 +342,9 @@ static void cf_exit(struct arasan_cf_dev *acdev)
 	writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB,
 			acdev->vbase + OP_MODE);
 	spin_unlock_irqrestore(&acdev->host->lock, flags);
-#ifdef CONFIG_HAVE_CLK
-	clk_disable(acdev->clk);
-#endif
+
+	if (!IS_ERR(acdev->clk))
+		clk_disable(acdev->clk);
 }
 
 static void dma_callback(void *dev)
@@ -828,13 +826,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-#ifdef CONFIG_HAVE_CLK
 	acdev->clk = clk_get(&pdev->dev, NULL);
-	if (IS_ERR(acdev->clk)) {
+	if (IS_ERR(acdev->clk))
 		dev_warn(&pdev->dev, "Clock not found\n");
-		return PTR_ERR(acdev->clk);
-	}
-#endif
 
 	/* allocate host */
 	host = ata_host_alloc(&pdev->dev, 1);
@@ -899,9 +893,8 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
 			&arasan_cf_sht);
 
 free_clk:
-#ifdef CONFIG_HAVE_CLK
-	clk_put(acdev->clk);
-#endif
+	if (!IS_ERR(acdev->clk))
+		clk_put(acdev->clk);
 	return ret;
 }
 
@@ -912,9 +905,9 @@ static int __devexit arasan_cf_remove(struct platform_device *pdev)
 
 	ata_host_detach(host);
 	cf_exit(acdev);
-#ifdef CONFIG_HAVE_CLK
-	clk_put(acdev->clk);
-#endif
+
+	if (!IS_ERR(acdev->clk))
+		clk_put(acdev->clk);
 
 	return 0;
 }
Signature · 1 line
1.7.9
#4 lore raw

PATCH v2 4/9 ata/sata_mv: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc Jeff Garzik <[email protected]>
Cc linux-ide at vger.kernel.org
---
 drivers/ata/sata_mv.c |   10 ----------
 1 files changed, 0 insertions(+), 10 deletions(-)
drivers/ata/sata_mv.c +0 -10
index 7336d4a..37503b8 100644
@@ -551,9 +551,7 @@ struct mv_host_priv {
 	u32			irq_mask_offset;
 	u32			unmask_all_irqs;
 
-#if defined(CONFIG_HAVE_CLK)
 	struct clk		*clk;
-#endif
 	/*
 	 * These consistent DMA memory pools give us guaranteed
 	 * alignment for hardware-accessed data structures,
@@ -4063,13 +4061,11 @@ static int mv_platform_probe(struct platform_device *pdev)
 				   resource_size(res));
 	hpriv->base -= SATAHC0_REG_BASE;
 
-#if defined(CONFIG_HAVE_CLK)
 	hpriv->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(hpriv->clk))
 		dev_notice(&pdev->dev, "cannot get clkdev\n");
 	else
 		clk_enable(hpriv->clk);
-#endif
 
 	/*
 	 * (Re-)program MBUS remapping windows if we are asked to.
@@ -4096,12 +4092,10 @@ static int mv_platform_probe(struct platform_device *pdev)
 		return 0;
 
 err:
-#if defined(CONFIG_HAVE_CLK)
 	if (!IS_ERR(hpriv->clk)) {
 		clk_disable(hpriv->clk);
 		clk_put(hpriv->clk);
 	}
-#endif
 
 	return rc;
 }
@@ -4117,17 +4111,13 @@ err:
 static int __devexit mv_platform_remove(struct platform_device *pdev)
 {
 	struct ata_host *host = platform_get_drvdata(pdev);
-#if defined(CONFIG_HAVE_CLK)
 	struct mv_host_priv *hpriv = host->private_data;
-#endif
 	ata_host_detach(host);
 
-#if defined(CONFIG_HAVE_CLK)
 	if (!IS_ERR(hpriv->clk)) {
 		clk_disable(hpriv->clk);
 		clk_put(hpriv->clk);
 	}
-#endif
 	return 0;
 }
 
Signature · 1 line
1.7.9
#5 lore raw

PATCH v2 5/9 net/c_can: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc David S. Miller <[email protected]>
Cc Bhupesh Sharma <[email protected]>
---
 drivers/net/can/c_can/c_can_platform.c |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)
drivers/net/can/c_can/c_can_platform.c +11 -17
index 5e1a5ff..d28904d 100644
@@ -73,17 +73,12 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 	struct c_can_priv *priv;
 	struct resource *mem;
 	int irq;
-#ifdef CONFIG_HAVE_CLK
 	struct clk *clk;
 
 	/* get the appropriate clk */
 	clk = clk_get(&pdev->dev, NULL);
-	if (IS_ERR(clk)) {
+	if (IS_ERR(clk))
 		dev_err(&pdev->dev, "no clock defined\n");
-		ret = -ENODEV;
-		goto exit;
-	}
-#endif
 
 	/* get the platform data */
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -118,10 +113,11 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
 
 	dev->irq = irq;
 	priv->regs = addr;
-#ifdef CONFIG_HAVE_CLK
-	priv->can.clock.freq = clk_get_rate(clk);
-	priv->priv = clk;
-#endif
+
+	if (!IS_ERR(clk)) {
+		priv->can.clock.freq = clk_get_rate(clk);
+		priv->priv = clk;
+	}
 
 	switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) {
 	case IORESOURCE_MEM_32BIT:
@@ -157,10 +153,9 @@ exit_iounmap:
 exit_release_mem:
 	release_mem_region(mem->start, resource_size(mem));
 exit_free_clk:
-#ifdef CONFIG_HAVE_CLK
-	clk_put(clk);
-exit:
-#endif
+	if (!IS_ERR(clk))
+		clk_put(clk);
+
 	dev_err(&pdev->dev, "probe failed\n");
 
 	return ret;
@@ -181,9 +176,8 @@ static int __devexit c_can_plat_remove(struct platform_device *pdev)
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(mem->start, resource_size(mem));
 
-#ifdef CONFIG_HAVE_CLK
-	clk_put(priv->priv);
-#endif
+	if (!IS_ERR(priv->priv))
+		clk_put(priv->priv);
 
 	return 0;
 }
Signature · 1 line
1.7.9
#6 lore raw

PATCH v2 6/9 net/stmmac: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc Giuseppe Cavallaro <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |   41 ---------------------
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   31 ++++++++++------
 2 files changed, 19 insertions(+), 53 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +0 -41
index db2de9a..7f85895 100644
@@ -81,9 +81,7 @@ struct stmmac_priv {
 	struct stmmac_counters mmc;
 	struct dma_features dma_cap;
 	int hw_cap_support;
-#ifdef CONFIG_HAVE_CLK
 	struct clk *stmmac_clk;
-#endif
 	int clk_csr;
 };
 
@@ -103,42 +101,3 @@ int stmmac_dvr_remove(struct net_device *ndev);
 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 				     struct plat_stmmacenet_data *plat_dat,
 				     void __iomem *addr);
-
-#ifdef CONFIG_HAVE_CLK
-static inline int stmmac_clk_enable(struct stmmac_priv *priv)
-{
-	if (!IS_ERR(priv->stmmac_clk))
-		return clk_enable(priv->stmmac_clk);
-
-	return 0;
-}
-
-static inline void stmmac_clk_disable(struct stmmac_priv *priv)
-{
-	if (IS_ERR(priv->stmmac_clk))
-		return;
-
-	clk_disable(priv->stmmac_clk);
-}
-static inline int stmmac_clk_get(struct stmmac_priv *priv)
-{
-	priv->stmmac_clk = clk_get(priv->device, NULL);
-
-	if (IS_ERR(priv->stmmac_clk))
-		return PTR_ERR(priv->stmmac_clk);
-
-	return 0;
-}
-#else
-static inline int stmmac_clk_enable(struct stmmac_priv *priv)
-{
-	return 0;
-}
-static inline void stmmac_clk_disable(struct stmmac_priv *priv)
-{
-}
-static inline int stmmac_clk_get(struct stmmac_priv *priv)
-{
-	return 0;
-}
-#endif /* CONFIG_HAVE_CLK */
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +19 -12
index 1a4cf81..18ce287 100644
@@ -28,6 +28,7 @@
 	https://bugzilla.stlinux.com/
 *******************************************************************************/
 
+#include <linux/clk.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/ip.h>
@@ -165,7 +166,6 @@ static void stmmac_verify_args(void)
 
 static void stmmac_clk_csr_set(struct stmmac_priv *priv)
 {
-#ifdef CONFIG_HAVE_CLK
 	u32 clk_rate;
 
 	if (IS_ERR(priv->stmmac_clk))
@@ -192,7 +192,6 @@ static void stmmac_clk_csr_set(struct stmmac_priv *priv)
 	   * we can not estimate the proper divider as it is not known
 	   * the frequency of clk_csr_i. So we do not change the default
 	   * divider. */
-#endif
 }
 
 #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
@@ -971,7 +970,8 @@ static int stmmac_open(struct net_device *dev)
 	} else
 		priv->tm->enable = 1;
 #endif
-	stmmac_clk_enable(priv);
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_enable(priv->stmmac_clk);
 
 	stmmac_check_ether_addr(priv);
 
@@ -1075,7 +1075,8 @@ open_error:
 	if (priv->phydev)
 		phy_disconnect(priv->phydev);
 
-	stmmac_clk_disable(priv);
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_disable(priv->stmmac_clk);
 
 	return ret;
 }
@@ -1128,7 +1129,9 @@ static int stmmac_release(struct net_device *dev)
 #ifdef CONFIG_STMMAC_DEBUG_FS
 	stmmac_exit_fs();
 #endif
-	stmmac_clk_disable(priv);
+
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_disable(priv->stmmac_clk);
 
 	return 0;
 }
@@ -1925,7 +1928,8 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 		goto error;
 	}
 
-	if (stmmac_clk_get(priv))
+	priv->stmmac_clk = clk_get(priv->device, NULL);
+	if (IS_ERR(priv->stmmac_clk))
 		pr_warning("%s: warning: cannot get CSR clock\n", __func__);
 
 	/* If a specific clk_csr value is passed from the platform
@@ -1934,10 +1938,12 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 	 * set the MDC clock dynamically according to the csr actual
 	 * clock input.
 	 */
-	if (!priv->plat->clk_csr)
-		stmmac_clk_csr_set(priv);
-	else
+	if (!priv->plat->clk_csr) {
+		if (!IS_ERR(priv->stmmac_clk))
+			stmmac_clk_csr_set(priv);
+	} else {
 		priv->clk_csr = priv->plat->clk_csr;
+	}
 
 	/* MDIO bus Registration */
 	ret = stmmac_mdio_register(ndev);
@@ -2020,7 +2026,8 @@ int stmmac_suspend(struct net_device *ndev)
 	else {
 		stmmac_set_mac(priv->ioaddr, false);
 		/* Disable clock in case of PWM is off */
-		stmmac_clk_disable(priv);
+		if (!IS_ERR(priv->stmmac_clk))
+			clk_disable(priv->stmmac_clk);
 	}
 	spin_unlock(&priv->lock);
 	return 0;
@@ -2042,9 +2049,9 @@ int stmmac_resume(struct net_device *ndev)
 	 * from another devices (e.g. serial console). */
 	if (device_may_wakeup(priv->device))
 		priv->hw->mac->pmt(priv->ioaddr, 0);
-	else
+	else if (!IS_ERR(priv->stmmac_clk))
 		/* enable the clk prevously disabled */
-		stmmac_clk_enable(priv);
+			clk_enable(priv->stmmac_clk);
 
 	netif_device_attach(ndev);
 
Signature · 1 line
1.7.9
#11 lore raw

PATCH v2 7/9 gadget/m66592: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc Greg Kroah-Hartman <[email protected]>
Cc linux-usb at vger.kernel.org
---
 drivers/usb/gadget/m66592-udc.c |   19 +++++--------------
 drivers/usb/gadget/m66592-udc.h |    5 -----
 2 files changed, 5 insertions(+), 19 deletions(-)
drivers/usb/gadget/m66592-udc.c +5 -14
index 3608b3b..34eee07 100644
@@ -1583,12 +1583,10 @@ static int __exit m66592_remove(struct platform_device *pdev)
 	iounmap(m66592->reg);
 	free_irq(platform_get_irq(pdev, 0), m66592);
 	m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
-#ifdef CONFIG_HAVE_CLK
-	if (m66592->pdata->on_chip) {
+	if (m66592->pdata->on_chip && !IS_ERR(m66592->clk)) {
 		clk_disable(m66592->clk);
 		clk_put(m66592->clk);
 	}
-#endif
 	kfree(m66592);
 	return 0;
 }
@@ -1602,9 +1600,7 @@ static int __init m66592_probe(struct platform_device *pdev)
 	struct resource *res, *ires;
 	void __iomem *reg = NULL;
 	struct m66592 *m66592 = NULL;
-#ifdef CONFIG_HAVE_CLK
 	char clk_name[8];
-#endif
 	int ret = 0;
 	int i;
 
@@ -1671,19 +1667,17 @@ static int __init m66592_probe(struct platform_device *pdev)
 		goto clean_up;
 	}
 
-#ifdef CONFIG_HAVE_CLK
 	if (m66592->pdata->on_chip) {
 		snprintf(clk_name, sizeof(clk_name), "usbf%d", pdev->id);
 		m66592->clk = clk_get(&pdev->dev, clk_name);
 		if (IS_ERR(m66592->clk)) {
 			dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
 				clk_name);
-			ret = PTR_ERR(m66592->clk);
-			goto clean_up2;
+		} else {
+			clk_enable(m66592->clk);
 		}
-		clk_enable(m66592->clk);
 	}
-#endif
+
 	INIT_LIST_HEAD(&m66592->gadget.ep_list);
 	m66592->gadget.ep0 = &m66592->ep[0].ep;
 	INIT_LIST_HEAD(&m66592->gadget.ep0->ep_list);
@@ -1731,13 +1725,10 @@ err_add_udc:
 	m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
 
 clean_up3:
-#ifdef CONFIG_HAVE_CLK
-	if (m66592->pdata->on_chip) {
+	if (m66592->pdata->on_chip && !IS_ERR(m66592->clk)) {
 		clk_disable(m66592->clk);
 		clk_put(m66592->clk);
 	}
-clean_up2:
-#endif
 	free_irq(ires->start, m66592);
 clean_up:
 	if (m66592) {
drivers/usb/gadget/m66592-udc.h +0 -5
index 9d9f7e3..a044ad3 100644
@@ -13,10 +13,7 @@
 #ifndef __M66592_UDC_H__
 #define __M66592_UDC_H__
 
-#ifdef CONFIG_HAVE_CLK
 #include <linux/clk.h>
-#endif
-
 #include <linux/usb/m66592.h>
 
 #define M66592_SYSCFG		0x00
@@ -468,9 +465,7 @@ struct m66592_ep {
 struct m66592 {
 	spinlock_t		lock;
 	void __iomem		*reg;
-#ifdef CONFIG_HAVE_CLK
 	struct clk *clk;
-#endif
 	struct m66592_platdata	*pdata;
 	unsigned long		irq_trigger;
 
Signature · 1 line
1.7.9
#12 lore raw

PATCH v2 8/9 gadget/r8a66597: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc Greg Kroah-Hartman <[email protected]>
Cc linux-usb at vger.kernel.org
---
 drivers/usb/gadget/r8a66597-udc.c |   21 +++++++--------------
 drivers/usb/gadget/r8a66597-udc.h |    5 -----
 2 files changed, 7 insertions(+), 19 deletions(-)
drivers/usb/gadget/r8a66597-udc.c +7 -14
index c4401e7..85aa56d 100644
@@ -1818,12 +1818,11 @@ static int __exit r8a66597_remove(struct platform_device *pdev)
 		iounmap(r8a66597->sudmac_reg);
 	free_irq(platform_get_irq(pdev, 0), r8a66597);
 	r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
-#ifdef CONFIG_HAVE_CLK
-	if (r8a66597->pdata->on_chip) {
+
+	if (r8a66597->pdata->on_chip && !IS_ERR(r8a66597->clk)) {
 		clk_disable(r8a66597->clk);
 		clk_put(r8a66597->clk);
 	}
-#endif
 	device_unregister(&r8a66597->gadget.dev);
 	kfree(r8a66597);
 	return 0;
@@ -1855,9 +1854,7 @@ static int __init r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597,
 
 static int __init r8a66597_probe(struct platform_device *pdev)
 {
-#ifdef CONFIG_HAVE_CLK
 	char clk_name[8];
-#endif
 	struct resource *res, *ires;
 	int irq;
 	void __iomem *reg = NULL;
@@ -1921,19 +1918,17 @@ static int __init r8a66597_probe(struct platform_device *pdev)
 	r8a66597->timer.data = (unsigned long)r8a66597;
 	r8a66597->reg = reg;
 
-#ifdef CONFIG_HAVE_CLK
 	if (r8a66597->pdata->on_chip) {
 		snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id);
 		r8a66597->clk = clk_get(&pdev->dev, clk_name);
 		if (IS_ERR(r8a66597->clk)) {
 			dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
 				clk_name);
-			ret = PTR_ERR(r8a66597->clk);
-			goto clean_up_dev;
+		} else {
+			clk_enable(r8a66597->clk);
 		}
-		clk_enable(r8a66597->clk);
 	}
-#endif
+
 	if (r8a66597->pdata->sudmac) {
 		ret = r8a66597_sudmac_ioremap(r8a66597, pdev);
 		if (ret < 0)
@@ -1993,13 +1988,11 @@ err_add_udc:
 clean_up3:
 	free_irq(irq, r8a66597);
 clean_up2:
-#ifdef CONFIG_HAVE_CLK
-	if (r8a66597->pdata->on_chip) {
+	if (r8a66597->pdata->on_chip && !IS_ERR(r8a66597->clk)) {
 		clk_disable(r8a66597->clk);
 		clk_put(r8a66597->clk);
 	}
-clean_up_dev:
-#endif
+
 	device_unregister(&r8a66597->gadget.dev);
 clean_up:
 	if (r8a66597) {
drivers/usb/gadget/r8a66597-udc.h +0 -5
index 8e3de61..d2a5ad2 100644
@@ -13,10 +13,7 @@
 #ifndef __R8A66597_H__
 #define __R8A66597_H__
 
-#ifdef CONFIG_HAVE_CLK
 #include <linux/clk.h>
-#endif
-
 #include <linux/usb/r8a66597.h>
 
 #define R8A66597_MAX_SAMPLING	10
@@ -92,9 +89,7 @@ struct r8a66597 {
 	void __iomem		*reg;
 	void __iomem		*sudmac_reg;
 
-#ifdef CONFIG_HAVE_CLK
 	struct clk *clk;
-#endif
 	struct r8a66597_platdata	*pdata;
 
 	struct usb_gadget		gadget;
Signature · 1 line
1.7.9
#13 lore raw

PATCH v2 9/9 usb/host/r8a66597: Remove conditional compilation of clk code

In reply to Viresh Kumar

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Cc Greg Kroah-Hartman <[email protected]>
Cc linux-usb at vger.kernel.org
---
 drivers/usb/host/r8a66597-hcd.c |   28 +++++++++-------------------
 drivers/usb/host/r8a66597.h     |    5 -----
 2 files changed, 9 insertions(+), 24 deletions(-)
drivers/usb/host/r8a66597-hcd.c +9 -19
index 2bf1320..6d11553 100644
@@ -95,9 +95,9 @@ static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
 	int i = 0;
 
 	if (r8a66597->pdata->on_chip) {
-#ifdef CONFIG_HAVE_CLK
-		clk_enable(r8a66597->clk);
-#endif
+		if (!IS_ERR(r8a66597->clk))
+			clk_enable(r8a66597->clk);
+
 		do {
 			r8a66597_write(r8a66597, SCKE, SYSCFG0);
 			tmp = r8a66597_read(r8a66597, SYSCFG0);
@@ -141,9 +141,8 @@ static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
 	udelay(1);
 
 	if (r8a66597->pdata->on_chip) {
-#ifdef CONFIG_HAVE_CLK
-		clk_disable(r8a66597->clk);
-#endif
+		if (!IS_ERR(r8a66597->clk))
+			clk_disable(r8a66597->clk);
 	} else {
 		r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
 		r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
@@ -2406,19 +2405,16 @@ static int __devexit r8a66597_remove(struct platform_device *pdev)
 	del_timer_sync(&r8a66597->rh_timer);
 	usb_remove_hcd(hcd);
 	iounmap(r8a66597->reg);
-#ifdef CONFIG_HAVE_CLK
-	if (r8a66597->pdata->on_chip)
+	if (r8a66597->pdata->on_chip && !IS_ERR(r8a66597->clk))
 		clk_put(r8a66597->clk);
-#endif
+
 	usb_put_hcd(hcd);
 	return 0;
 }
 
 static int __devinit r8a66597_probe(struct platform_device *pdev)
 {
-#ifdef CONFIG_HAVE_CLK
 	char clk_name[8];
-#endif
 	struct resource *res = NULL, *ires;
 	int irq = -1;
 	void __iomem *reg = NULL;
@@ -2482,16 +2478,12 @@ static int __devinit r8a66597_probe(struct platform_device *pdev)
 	r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
 
 	if (r8a66597->pdata->on_chip) {
-#ifdef CONFIG_HAVE_CLK
 		snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id);
 		r8a66597->clk = clk_get(&pdev->dev, clk_name);
 		if (IS_ERR(r8a66597->clk)) {
 			dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
 				clk_name);
-			ret = PTR_ERR(r8a66597->clk);
-			goto clean_up2;
 		}
-#endif
 		r8a66597->max_root_hub = 1;
 	} else
 		r8a66597->max_root_hub = 2;
@@ -2531,11 +2523,9 @@ static int __devinit r8a66597_probe(struct platform_device *pdev)
 	return 0;
 
 clean_up3:
-#ifdef CONFIG_HAVE_CLK
-	if (r8a66597->pdata->on_chip)
+	if (r8a66597->pdata->on_chip && !IS_ERR(r8a66597->clk))
 		clk_put(r8a66597->clk);
-clean_up2:
-#endif
+
 	usb_put_hcd(hcd);
 
 clean_up:
drivers/usb/host/r8a66597.h +0 -5
index f28782d..672cea3 100644
@@ -26,10 +26,7 @@
 #ifndef __R8A66597_H__
 #define __R8A66597_H__
 
-#ifdef CONFIG_HAVE_CLK
 #include <linux/clk.h>
-#endif
-
 #include <linux/usb/r8a66597.h>
 
 #define R8A66597_MAX_NUM_PIPE		10
@@ -113,9 +110,7 @@ struct r8a66597_root_hub {
 struct r8a66597 {
 	spinlock_t lock;
 	void __iomem *reg;
-#ifdef CONFIG_HAVE_CLK
 	struct clk *clk;
-#endif
 	struct r8a66597_platdata	*pdata;
 	struct r8a66597_device		device0;
 	struct r8a66597_root_hub	root_hub[R8A66597_MAX_ROOT_HUB];
Signature · 1 line
1.7.9
Acked-by on v2 6/9
#7 lore raw

Re: [PATCH V2 6/9] net/stmmac: Remove conditional compilation of clk code

In reply to Viresh Kumar
Quoted 3 lines · Viresh KUMAR

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Hello Viresh

patch only applies fine against the net-next repository so on top of the diver version: March_2012 and it builds fine on arch w/ w/o HAVE_CLK (just tested).

Thanks a lot.

Quoted 172 lines
Cc Giuseppe Cavallaro <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |   41 ---------------------
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   31 ++++++++++------
 2 files changed, 19 insertions(+), 53 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +0 -41
index db2de9a..7f85895 100644
@@ -81,9 +81,7 @@ struct stmmac_priv {
 	struct stmmac_counters mmc;
 	struct dma_features dma_cap;
 	int hw_cap_support;
-#ifdef CONFIG_HAVE_CLK
 	struct clk *stmmac_clk;
-#endif
 	int clk_csr;
 };
 
@@ -103,42 +101,3 @@ int stmmac_dvr_remove(struct net_device *ndev);
 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 				     struct plat_stmmacenet_data *plat_dat,
 				     void __iomem *addr);
-
-#ifdef CONFIG_HAVE_CLK
-static inline int stmmac_clk_enable(struct stmmac_priv *priv)
-{
-	if (!IS_ERR(priv->stmmac_clk))
-		return clk_enable(priv->stmmac_clk);
-
-	return 0;
-}
-
-static inline void stmmac_clk_disable(struct stmmac_priv *priv)
-{
-	if (IS_ERR(priv->stmmac_clk))
-		return;
-
-	clk_disable(priv->stmmac_clk);
-}
-static inline int stmmac_clk_get(struct stmmac_priv *priv)
-{
-	priv->stmmac_clk = clk_get(priv->device, NULL);
-
-	if (IS_ERR(priv->stmmac_clk))
-		return PTR_ERR(priv->stmmac_clk);
-
-	return 0;
-}
-#else
-static inline int stmmac_clk_enable(struct stmmac_priv *priv)
-{
-	return 0;
-}
-static inline void stmmac_clk_disable(struct stmmac_priv *priv)
-{
-}
-static inline int stmmac_clk_get(struct stmmac_priv *priv)
-{
-	return 0;
-}
-#endif /* CONFIG_HAVE_CLK */
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +19 -12
index 1a4cf81..18ce287 100644
@@ -28,6 +28,7 @@
 	https://bugzilla.stlinux.com/
 *******************************************************************************/
 
+#include <linux/clk.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/ip.h>
@@ -165,7 +166,6 @@ static void stmmac_verify_args(void)
 
 static void stmmac_clk_csr_set(struct stmmac_priv *priv)
 {
-#ifdef CONFIG_HAVE_CLK
 	u32 clk_rate;
 
 	if (IS_ERR(priv->stmmac_clk))
@@ -192,7 +192,6 @@ static void stmmac_clk_csr_set(struct stmmac_priv *priv)
 	   * we can not estimate the proper divider as it is not known
 	   * the frequency of clk_csr_i. So we do not change the default
 	   * divider. */
-#endif
 }
 
 #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
@@ -971,7 +970,8 @@ static int stmmac_open(struct net_device *dev)
 	} else
 		priv->tm->enable = 1;
 #endif
-	stmmac_clk_enable(priv);
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_enable(priv->stmmac_clk);
 
 	stmmac_check_ether_addr(priv);
 
@@ -1075,7 +1075,8 @@ open_error:
 	if (priv->phydev)
 		phy_disconnect(priv->phydev);
 
-	stmmac_clk_disable(priv);
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_disable(priv->stmmac_clk);
 
 	return ret;
 }
@@ -1128,7 +1129,9 @@ static int stmmac_release(struct net_device *dev)
 #ifdef CONFIG_STMMAC_DEBUG_FS
 	stmmac_exit_fs();
 #endif
-	stmmac_clk_disable(priv);
+
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_disable(priv->stmmac_clk);
 
 	return 0;
 }
@@ -1925,7 +1928,8 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 		goto error;
 	}
 
-	if (stmmac_clk_get(priv))
+	priv->stmmac_clk = clk_get(priv->device, NULL);
+	if (IS_ERR(priv->stmmac_clk))
 		pr_warning("%s: warning: cannot get CSR clock\n", __func__);
 
 	/* If a specific clk_csr value is passed from the platform
@@ -1934,10 +1938,12 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 	 * set the MDC clock dynamically according to the csr actual
 	 * clock input.
 	 */
-	if (!priv->plat->clk_csr)
-		stmmac_clk_csr_set(priv);
-	else
+	if (!priv->plat->clk_csr) {
+		if (!IS_ERR(priv->stmmac_clk))
+			stmmac_clk_csr_set(priv);
+	} else {
 		priv->clk_csr = priv->plat->clk_csr;
+	}
 
 	/* MDIO bus Registration */
 	ret = stmmac_mdio_register(ndev);
@@ -2020,7 +2026,8 @@ int stmmac_suspend(struct net_device *ndev)
 	else {
 		stmmac_set_mac(priv->ioaddr, false);
 		/* Disable clock in case of PWM is off */
-		stmmac_clk_disable(priv);
+		if (!IS_ERR(priv->stmmac_clk))
+			clk_disable(priv->stmmac_clk);
 	}
 	spin_unlock(&priv->lock);
 	return 0;
@@ -2042,9 +2049,9 @@ int stmmac_resume(struct net_device *ndev)
 	 * from another devices (e.g. serial console). */
 	if (device_may_wakeup(priv->device))
 		priv->hw->mac->pmt(priv->ioaddr, 0);
-	else
+	else if (!IS_ERR(priv->stmmac_clk))
 		/* enable the clk prevously disabled */
-		stmmac_clk_enable(priv);
+			clk_enable(priv->stmmac_clk);
 
 	netif_device_attach(ndev);
 
#8 lore raw

Re: [PATCH V2 6/9] net/stmmac: Remove conditional compilation of clk code

Quoted 10 lines · Giuseppe CAVALLARO
Quoted 3 lines · Viresh KUMAR

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

Hello Viresh

patch only applies fine against the net-next repository so on top of the diver version: March_2012 and it builds fine on arch w/ w/o HAVE_CLK (just tested).

Oops, sorry but on a build I got:

CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
drivers/built-in.o: In function `stmmac_release':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1134:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_open':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:974:
undefined reference to `clk_enable' /stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1079:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_dvr_probe':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1931:
undefined reference to `clk_get'
drivers/built-in.o: In function `stmmac_clk_csr_set':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:174:
undefined reference to `clk_get_rate'
drivers/built-in.o: In function `stmmac_suspend':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2030:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_resume':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2054:
undefined reference to `clk_enable'
make: *** [.tmp_vmlinux1] Error 1

Pls, can you verify?

Peppe

Quoted 183 lines

Thanks a lot.

Quoted 162 lines
Cc Giuseppe Cavallaro <[email protected]>
Cc David S. Miller <[email protected]>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |   41 ---------------------
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |   31 ++++++++++------
 2 files changed, 19 insertions(+), 53 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +0 -41
index db2de9a..7f85895 100644
@@ -81,9 +81,7 @@ struct stmmac_priv {
 	struct stmmac_counters mmc;
 	struct dma_features dma_cap;
 	int hw_cap_support;
-#ifdef CONFIG_HAVE_CLK
 	struct clk *stmmac_clk;
-#endif
 	int clk_csr;
 };
 
@@ -103,42 +101,3 @@ int stmmac_dvr_remove(struct net_device *ndev);
 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 				     struct plat_stmmacenet_data *plat_dat,
 				     void __iomem *addr);
-
-#ifdef CONFIG_HAVE_CLK
-static inline int stmmac_clk_enable(struct stmmac_priv *priv)
-{
-	if (!IS_ERR(priv->stmmac_clk))
-		return clk_enable(priv->stmmac_clk);
-
-	return 0;
-}
-
-static inline void stmmac_clk_disable(struct stmmac_priv *priv)
-{
-	if (IS_ERR(priv->stmmac_clk))
-		return;
-
-	clk_disable(priv->stmmac_clk);
-}
-static inline int stmmac_clk_get(struct stmmac_priv *priv)
-{
-	priv->stmmac_clk = clk_get(priv->device, NULL);
-
-	if (IS_ERR(priv->stmmac_clk))
-		return PTR_ERR(priv->stmmac_clk);
-
-	return 0;
-}
-#else
-static inline int stmmac_clk_enable(struct stmmac_priv *priv)
-{
-	return 0;
-}
-static inline void stmmac_clk_disable(struct stmmac_priv *priv)
-{
-}
-static inline int stmmac_clk_get(struct stmmac_priv *priv)
-{
-	return 0;
-}
-#endif /* CONFIG_HAVE_CLK */
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +17 -10
index 1a4cf81..18ce287 100644
@@ -28,6 +28,7 @@
 	https://bugzilla.stlinux.com/
 *******************************************************************************/
 
+#include <linux/clk.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/ip.h>
@@ -165,7 +166,6 @@ static void stmmac_verify_args(void)
 
 static void stmmac_clk_csr_set(struct stmmac_priv *priv)
 {
-#ifdef CONFIG_HAVE_CLK
 	u32 clk_rate;
 
 	if (IS_ERR(priv->stmmac_clk))
@@ -192,7 +192,6 @@ static void stmmac_clk_csr_set(struct stmmac_priv *priv)
 	   * we can not estimate the proper divider as it is not known
 	   * the frequency of clk_csr_i. So we do not change the default
 	   * divider. */
-#endif
 }
 
 #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
@@ -971,7 +970,8 @@ static int stmmac_open(struct net_device *dev)
 	} else
 		priv->tm->enable = 1;
 #endif
-	stmmac_clk_enable(priv);
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_enable(priv->stmmac_clk);
 
 	stmmac_check_ether_addr(priv);
 
@@ -1075,7 +1075,8 @@ open_error:
 	if (priv->phydev)
 		phy_disconnect(priv->phydev);
 
-	stmmac_clk_disable(priv);
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_disable(priv->stmmac_clk);
 
 	return ret;
 }
@@ -1128,7 +1129,9 @@ static int stmmac_release(struct net_device *dev)
 #ifdef CONFIG_STMMAC_DEBUG_FS
 	stmmac_exit_fs();
 #endif
-	stmmac_clk_disable(priv);
+
+	if (!IS_ERR(priv->stmmac_clk))
+		clk_disable(priv->stmmac_clk);
 
 	return 0;
 }
@@ -1925,7 +1928,8 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 		goto error;
 	}
 
-	if (stmmac_clk_get(priv))
+	priv->stmmac_clk = clk_get(priv->device, NULL);
+	if (IS_ERR(priv->stmmac_clk))
 		pr_warning("%s: warning: cannot get CSR clock\n", __func__);
 
 	/* If a specific clk_csr value is passed from the platform
@@ -1934,10 +1938,12 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 	 * set the MDC clock dynamically according to the csr actual
 	 * clock input.
 	 */
-	if (!priv->plat->clk_csr)
-		stmmac_clk_csr_set(priv);
-	else
+	if (!priv->plat->clk_csr) {
+		if (!IS_ERR(priv->stmmac_clk))
+			stmmac_clk_csr_set(priv);
+	} else {
 		priv->clk_csr = priv->plat->clk_csr;
+	}
 
 	/* MDIO bus Registration */
 	ret = stmmac_mdio_register(ndev);
@@ -2020,7 +2026,8 @@ int stmmac_suspend(struct net_device *ndev)
 	else {
 		stmmac_set_mac(priv->ioaddr, false);
 		/* Disable clock in case of PWM is off */
-		stmmac_clk_disable(priv);
+		if (!IS_ERR(priv->stmmac_clk))
+			clk_disable(priv->stmmac_clk);
 	}
 	spin_unlock(&priv->lock);
 	return 0;
@@ -2042,9 +2049,9 @@ int stmmac_resume(struct net_device *ndev)
 	 * from another devices (e.g. serial console). */

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_resume(struct net_device *ndev) · line 2057

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -2
 	if (device_may_wakeup(priv->device))
 		priv->hw->mac->pmt(priv->ioaddr, 0);
-	else
+	else if (!IS_ERR(priv->stmmac_clk))
 		/* enable the clk prevously disabled */
-		stmmac_clk_enable(priv);
+			clk_enable(priv->stmmac_clk);
 
 	netif_device_attach(ndev);
 

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH V2 6/9] net/stmmac: Remove conditional compilation of clk code

Quoted 27 lines · Giuseppe CAVALLARO

Oops, sorry but on a build I got:

CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
drivers/built-in.o: In function `stmmac_release':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1134:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_open':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:974:
undefined reference to `clk_enable' /stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1079:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_dvr_probe':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1931:
undefined reference to `clk_get'
drivers/built-in.o: In function `stmmac_clk_csr_set':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:174:
undefined reference to `clk_get_rate'
drivers/built-in.o: In function `stmmac_suspend':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2030:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_resume':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2054:
undefined reference to `clk_enable'
make: *** [.tmp_vmlinux1] Error 1

Quoted 1 line

Pls, can you verify?

I believe, you haven't applied:

[PATCH V2 1/9] clk: Add non CONFIG_HAVE_CLK routines

which must be applied before testing this.

Signature · 1 line
viresh
#10 lore raw

Re: [PATCH V2 6/9] net/stmmac: Remove conditional compilation of clk code

Quoted 28 lines · Viresh Kumar
Quoted 27 lines · Giuseppe CAVALLARO

Oops, sorry but on a build I got:

CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
drivers/built-in.o: In function `stmmac_release':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1134:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_open':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:974:
undefined reference to `clk_enable' /stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1079:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_dvr_probe':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1931:
undefined reference to `clk_get'
drivers/built-in.o: In function `stmmac_clk_csr_set':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:174:
undefined reference to `clk_get_rate'
drivers/built-in.o: In function `stmmac_suspend':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2030:
undefined reference to `clk_disable'
drivers/built-in.o: In function `stmmac_resume':
/stlinux/cavagiu/git/mirror/net-next.git/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2054:
undefined reference to `clk_enable'
make: *** [.tmp_vmlinux1] Error 1

Quoted 7 lines
Quoted 1 line

Pls, can you verify?

I believe, you haven't applied:

[PATCH V2 1/9] clk: Add non CONFIG_HAVE_CLK routines

which must be applied before testing this.

Yes with it applied the build is ok.

Peppe

Quoted 1 line