From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lothar =?UTF-8?B?V2HDn21hbm4=?= Date: Tue, 20 Jun 2017 14:06:43 +0200 Subject: [U-Boot] [PATCH v7 08/10] usb: host: ohci-generic: add CLOCK support In-Reply-To: <1497952751-28477-9-git-send-email-patrice.chotard@st.com> References: <1497952751-28477-1-git-send-email-patrice.chotard@st.com> <1497952751-28477-9-git-send-email-patrice.chotard@st.com> Message-ID: <20170620140643.6ffdfbd4@karo-electronics.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi, On Tue, 20 Jun 2017 11:59:09 +0200 patrice.chotard at st.com wrote: > From: Patrice Chotard >=20 > use array to save enabled clocks reference in order to > disabled them in case of error during probe() or during > driver removal. >=20 > Signed-off-by: Patrice Chotard > --- > v7: _ replace clk_count() by ofnode_count_phandle_with_args() >=20 > v6: _ none >=20 > v5: _ none >=20 > v4: _ use generic_phy_valid() before generic_phy_exit() call >=20 > 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 >=20 > v2: _ add error path management > _ add .remove callback >=20 > drivers/usb/host/ohci-generic.c | 59 +++++++++++++++++++++++++++++++++++= ++++-- > 1 file changed, 57 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-gene= ric.c > index f85738f..f76a1c2 100644 > --- a/drivers/usb/host/ohci-generic.c > +++ b/drivers/usb/host/ohci-generic.c > @@ -5,27 +5,83 @@ > */ > =20 > #include > +#include > #include > #include "ohci.h" > =20 > +#include > + > #if !defined(CONFIG_USB_OHCI_NEW) > # error "Generic OHCI driver requires CONFIG_USB_OHCI_NEW" > #endif > =20 > struct generic_ohci { > ohci_t ohci; > + struct clk *clocks; > + int clock_count; > }; > =20 > static int ohci_usb_probe(struct udevice *dev) > { > struct ohci_regs *regs =3D (struct ohci_regs *)devfdt_get_addr(dev); > + struct generic_ohci *priv =3D dev_get_priv(dev); > + int i, err, ret, clock_nb; > + > + err =3D 0; > + priv->clock_count =3D 0; > + clock_nb =3D ofnode_count_phandle_with_args(dev_ofnode(dev), "clocks", > + "#clock-cells"); > + if (clock_nb > 0) { > + priv->clocks =3D devm_kmalloc(dev, sizeof(struct clk) * clock_nb, > + GFP_KERNEL); > + if (!priv->clocks) { > + error("Can't allocate resource\n"); > + return -ENOMEM; > + } > + > + for (i =3D 0; i < clock_nb; i++) { > + err =3D 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 !=3D -ENOENT) { > + error("failed to get clock phandle(%d)\n", clock_nb); > + return clock_nb; > + } > + } > =20 > - return ohci_register(dev, regs); > + err =3D ohci_register(dev, regs); > + if (!err) > + return err; > + if (err) goto clk_err; return 0; would be more easy to follow. > +clk_err: > + ret =3D clk_disable_all(priv->clocks, priv->clock_count); > + if (ret) > + return ret; > + > + return err; > } > =20 > static int ohci_usb_remove(struct udevice *dev) > { > - return ohci_deregister(dev); > + struct generic_ohci *priv =3D dev_get_priv(dev); > + int ret; > + > + ret =3D ohci_deregister(dev); > + if (ret) > + return ret; > + > + return clk_disable_all(priv->clocks, priv->clock_count); > } > =20 > static const struct udevice_id ohci_usb_ids[] =3D { Lothar Wa=C3=9Fmann