From: "Lothar Waßmann" <LW@KARO-electronics.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v7 08/10] usb: host: ohci-generic: add CLOCK support
Date: Tue, 20 Jun 2017 14:06:43 +0200 [thread overview]
Message-ID: <20170620140643.6ffdfbd4@karo-electronics.de> (raw)
In-Reply-To: <1497952751-28477-9-git-send-email-patrice.chotard@st.com>
Hi,
On Tue, 20 Jun 2017 11:59:09 +0200 patrice.chotard at st.com wrote:
> 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>
> ---
> v7: _ replace clk_count() by ofnode_count_phandle_with_args()
>
> v6: _ none
>
> v5: _ none
>
> 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 | 59 +++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 57 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
> index f85738f..f76a1c2 100644
> --- a/drivers/usb/host/ohci-generic.c
> +++ b/drivers/usb/host/ohci-generic.c
> @@ -5,27 +5,83 @@
> */
>
> #include <common.h>
> +#include <clk.h>
> #include <dm.h>
> #include "ohci.h"
>
> +#include <dm/ofnode.h>
> +
> #if !defined(CONFIG_USB_OHCI_NEW)
> # error "Generic OHCI driver requires CONFIG_USB_OHCI_NEW"
> #endif
>
> 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 *)devfdt_get_addr(dev);
> + struct generic_ohci *priv = dev_get_priv(dev);
> + int i, err, ret, clock_nb;
> +
> + err = 0;
> + priv->clock_count = 0;
> + clock_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "clocks",
> + "#clock-cells");
> + if (clock_nb > 0) {
> + 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]);
>
You free the freshly allocated clock right away and use it lateron?
> + } else {
> + if (clock_nb != -ENOENT) {
> + error("failed to get clock phandle(%d)\n", clock_nb);
> + return clock_nb;
> + }
> + }
>
> - return ohci_register(dev, regs);
> + err = ohci_register(dev, regs);
> + if (!err)
> + return err;
> +
if (err)
goto clk_err;
return 0;
would be more easy to follow.
> +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[] = {
Lothar Waßmann
next prev parent reply other threads:[~2017-06-20 12:06 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-20 9:59 [U-Boot] [PATCH v7 00/10] usb: Extend ehci and ohci generic drivers patrice.chotard at st.com
2017-06-20 9:59 ` [U-Boot] [PATCH v7 01/10] reset: add reset_request() patrice.chotard at st.com
2017-06-20 9:59 ` [U-Boot] [PATCH v7 02/10] reset: add reset_assert_all() patrice.chotard at st.com
2017-06-20 9:59 ` [U-Boot] [PATCH v7 03/10] clk: add clk_disable_all() patrice.chotard at st.com
2017-06-20 12:11 ` Lothar Waßmann
2017-06-20 12:40 ` Patrice CHOTARD
2017-06-20 9:59 ` [U-Boot] [PATCH v7 04/10] dm: core: add ofnode_count_phandle_with_args() patrice.chotard at st.com
2017-06-20 18:26 ` Simon Glass
2017-06-20 9:59 ` [U-Boot] [PATCH v7 05/10] usb: host: ehci-generic: replace printf() by error() patrice.chotard at st.com
2017-06-20 9:59 ` [U-Boot] [PATCH v7 06/10] usb: host: ehci-generic: add error path and .remove callback patrice.chotard at st.com
2017-06-20 10:09 ` Marek Vasut
2017-06-20 11:26 ` Lothar Waßmann
2017-06-20 12:22 ` Patrice CHOTARD
2017-06-20 11:32 ` Lothar Waßmann
2017-06-20 12:28 ` Patrice CHOTARD
2017-06-20 9:59 ` [U-Boot] [PATCH v7 07/10] usb: host: ehci-generic: add generic PHY support patrice.chotard at st.com
2017-06-20 9:59 ` [U-Boot] [PATCH v7 08/10] usb: host: ohci-generic: add CLOCK support patrice.chotard at st.com
2017-06-20 12:06 ` Lothar Waßmann [this message]
2017-06-20 12:56 ` Patrice CHOTARD
2017-06-21 7:56 ` Lothar Waßmann
2017-06-21 8:36 ` Patrice CHOTARD
2017-06-20 9:59 ` [U-Boot] [PATCH v7 09/10] usb: host: ohci-generic: add RESET support patrice.chotard at st.com
2017-06-20 18:26 ` Simon Glass
2017-06-20 9:59 ` [U-Boot] [PATCH v7 10/10] usb: host: ohci-generic: add generic PHY 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=20170620140643.6ffdfbd4@karo-electronics.de \
--to=lw@karo-electronics.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox