All of lore.kernel.org
 help / color / mirror / Atom feed
From: patrice.chotard at st.com <patrice.chotard@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 09/11] usb: host: ohci-generic: add CLOCK support
Date: Wed, 24 May 2017 15:01:55 +0200	[thread overview]
Message-ID: <1495630917-25272-10-git-send-email-patrice.chotard@st.com> (raw)
In-Reply-To: <1495630917-25272-1-git-send-email-patrice.chotard@st.com>

From: Patrice Chotard <patrice.chotard@st.com>

use array to save enabled clocks reference in order to
disabled them in case of error during probe() or during
driver removal.

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---

v4:     _ use generic_phy_valid() before generic_phy_exit() call

v3:	_ extract in this patch the CLOCK support add-on from previous patch 5
	_ keep enabled clocks reference in list in order to 
	  disable clocks in error path or in .remove callback

v2:	_ add error path management
	_ add .remove callback

 drivers/usb/host/ohci-generic.c | 53 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
index f3307f4..404fc98 100644
--- a/drivers/usb/host/ohci-generic.c
+++ b/drivers/usb/host/ohci-generic.c
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include "ohci.h"
 
@@ -14,18 +15,66 @@
 
 struct generic_ohci {
 	ohci_t ohci;
+	struct clk *clocks;
+	int clock_count;
 };
 
 static int ohci_usb_probe(struct udevice *dev)
 {
 	struct ohci_regs *regs = (struct ohci_regs *)dev_get_addr(dev);
+	struct generic_ohci *priv = dev_get_priv(dev);
+	int i, err, ret, clock_nb;
 
-	return ohci_register(dev, regs);
+	err = 0;
+	priv->clock_count = 0;
+	clock_nb = clk_count(dev);
+
+	if (clock_nb) {
+		priv->clocks = devm_kmalloc(dev, sizeof(struct clk) * clock_nb,
+					    GFP_KERNEL);
+		if (!priv->clocks) {
+			error("Can't allocate resource\n");
+			return -ENOMEM;
+		}
+
+		for (i = 0; i < clock_nb; i++) {
+			err = clk_get_by_index(dev, i, &priv->clocks[i]);
+			if (err < 0)
+				break;
+
+			priv->clock_count++;
+
+			if (clk_enable(&priv->clocks[i])) {
+				error("failed to enable clock %d\n", i);
+				clk_free(&priv->clocks[i]);
+				goto clk_err;
+			}
+			clk_free(&priv->clocks[i]);
+		}
+	}
+
+	err = ohci_register(dev, regs);
+	if (!err)
+		return err;
+
+clk_err:
+	ret = clk_disable_all(priv->clocks, priv->clock_count);
+	if (ret)
+		return ret;
+
+	return err;
 }
 
 static int ohci_usb_remove(struct udevice *dev)
 {
-	return ohci_deregister(dev);
+	struct generic_ohci *priv = dev_get_priv(dev);
+	int ret;
+
+	ret = ohci_deregister(dev);
+	if (ret)
+		return ret;
+
+	return clk_disable_all(priv->clocks, priv->clock_count);
 }
 
 static const struct udevice_id ohci_usb_ids[] = {
-- 
1.9.1

  parent reply	other threads:[~2017-05-24 13:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 13:01 [U-Boot] [PATCH v4 00/11] usb: Extend ehci and ohci generic drivers patrice.chotard at st.com
2017-05-24 13:01 ` [U-Boot] [PATCH v4 01/11] reset: add reset_request() patrice.chotard at st.com
2017-05-24 13:01 ` [U-Boot] [PATCH v4 02/11] reset: add reset_count() patrice.chotard at st.com
2017-06-01  3:10   ` Simon Glass
2017-06-01  7:49     ` Patrice CHOTARD
2017-05-24 13:01 ` [U-Boot] [PATCH v4 03/11] reset: add reset_assert_all() patrice.chotard at st.com
2017-06-01  3:10   ` Simon Glass
2017-05-24 13:01 ` [U-Boot] [PATCH v4 04/11] clk: add clk_count() patrice.chotard at st.com
2017-06-01  3:10   ` Simon Glass
2017-06-01  7:56     ` Patrice CHOTARD
2017-06-05  8:59       ` Patrice CHOTARD
2017-05-24 13:01 ` [U-Boot] [PATCH v4 05/11] clk: add clk_disable_all() patrice.chotard at st.com
2017-05-24 13:01 ` [U-Boot] [PATCH v4 06/11] usb: host: ehci-generic: replace printf() by error() patrice.chotard at st.com
2017-05-24 13:01 ` [U-Boot] [PATCH v4 07/11] usb: host: ehci-generic: add error path and .remove callback patrice.chotard at st.com
2017-06-01  3:10   ` Simon Glass
2017-05-24 13:01 ` [U-Boot] [PATCH v4 08/11] usb: host: ehci-generic: add generic PHY support patrice.chotard at st.com
2017-06-01  3:10   ` Simon Glass
2017-05-24 13:01 ` patrice.chotard at st.com [this message]
2017-06-01  3:10   ` [U-Boot] [PATCH v4 09/11] usb: host: ohci-generic: add CLOCK support Simon Glass
2017-05-24 13:01 ` [U-Boot] [PATCH v4 10/11] usb: host: ohci-generic: add RESET support patrice.chotard at st.com
2017-06-01  3:11   ` Simon Glass
2017-05-24 13:01 ` [U-Boot] [PATCH v4 11/11] usb: host: ohci-generic: add generic PHY support patrice.chotard at st.com
2017-06-01  3:11   ` Simon Glass
2017-05-24 13:04 ` [U-Boot] [PATCH v4 00/11] usb: Extend ehci and ohci generic drivers Patrice CHOTARD
2017-05-24 13:07 patrice.chotard at st.com
2017-05-24 13:07 ` [U-Boot] [PATCH v4 09/11] usb: host: ohci-generic: add CLOCK support patrice.chotard at st.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1495630917-25272-10-git-send-email-patrice.chotard@st.com \
    --to=patrice.chotard@st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.