From mboxrd@z Thu Jan 1 00:00:00 1970 From: Priit Laes Subject: Re: [PATCH v3 2/2] phy-sun4i-usb: Add support for the host usb-phys found on the H3 SoC Date: Tue, 01 Dec 2015 17:56:00 +0200 Message-ID: <1448985360.16313.2.camel@plaes.org> References: <1448470202-3628-1-git-send-email-hdegoede@redhat.com> <1448470202-3628-2-git-send-email-hdegoede@redhat.com> Reply-To: plaes-q/aMd4JkU83YtjvyW6yDsg@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1448470202-3628-2-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , To: hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, Kishon Vijay Abraham I Cc: "Reinder E.N. de Haan" , Maxime Ripard , Chen-Yu Tsai , linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, devicetree , linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, Reinder de Haan List-Id: devicetree@vger.kernel.org On Wed, 2015-11-25 at 17:50 +0100, Hans de Goede wrote: > From: Reinder de Haan >=20 > Note this commit only adds support for phys 1-3, phy 0, the otg phy, > is > not yet (fully) supported after this commit. >=20 > Signed-off-by: Reinder de Haan > Signed-off-by: Hans de Goede > --- > Changes in v2: > -Change break; after dev_err() to return, as intended, fixing a > compiler > =C2=A0warning (the dev_err case should never be reached) > Changes in v3: > -Use of_match_node to get model specific config data > --- > =C2=A0.../devicetree/bindings/phy/sun4i-usb-phy.txt=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0|=C2=A0=C2=A01 + > =C2=A0drivers/phy/phy-sun4i-usb.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0| 46 > +++++++++++++++++----- > =C2=A02 files changed, 38 insertions(+), 9 deletions(-) >=20 > diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt > b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt > index 0cebf74..95736d7 100644 > --- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt > +++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt > @@ -9,6 +9,7 @@ Required properties: > =C2=A0=C2=A0=C2=A0* allwinner,sun7i-a20-usb-phy > =C2=A0=C2=A0=C2=A0* allwinner,sun8i-a23-usb-phy > =C2=A0=C2=A0=C2=A0* allwinner,sun8i-a33-usb-phy > +=C2=A0=C2=A0* allwinner,sun8i-h3-usb-phy > =C2=A0- reg : a list of offset + length pairs > =C2=A0- reg-names : > =C2=A0=C2=A0=C2=A0* "phy_ctrl" > diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i- > usb.c > index 1d8f85d..2aed482 100644 > --- a/drivers/phy/phy-sun4i-usb.c > +++ b/drivers/phy/phy-sun4i-usb.c > @@ -46,6 +46,9 @@ > =C2=A0#define REG_PHYBIST 0x08 > =C2=A0#define REG_PHYTUNE 0x0c > =C2=A0#define REG_PHYCTL_A33 0x10 > +#define REG_PHY_UNK_H3 0x20 > + > +#define REG_PMU_UNK_H3 0x10 > =C2=A0 > =C2=A0#define PHYCTL_DATA BIT(7) > =C2=A0 > @@ -79,7 +82,7 @@ > =C2=A0#define PHY_DISCON_TH_SEL 0x2a > =C2=A0#define PHY_SQUELCH_DETECT 0x3c > =C2=A0 > -#define MAX_PHYS 3 > +#define MAX_PHYS 4 > =C2=A0 > =C2=A0/* > =C2=A0 * Note do not raise the debounce time, we must report Vusb high > within 100ms > @@ -91,6 +94,7 @@ > =C2=A0enum sun4i_usb_phy_type { > =C2=A0 sun4i_a10_phy, > =C2=A0 sun8i_a33_phy, > + sun8i_h3_phy, > =C2=A0}; > =C2=A0 > =C2=A0struct sun4i_usb_phy_cfg { > @@ -101,6 +105,7 @@ struct sun4i_usb_phy_cfg { > =C2=A0}; > =C2=A0 > =C2=A0struct sun4i_usb_phy_data { > + struct device *dev; > =C2=A0 void __iomem *base; > =C2=A0 const struct sun4i_usb_phy_cfg *cfg; > =C2=A0 struct mutex mutex; > @@ -183,6 +188,9 @@ static void sun4i_usb_phy_write(struct > sun4i_usb_phy *phy, u32 addr, u32 data, > =C2=A0 /* A33 needs us to set phyctl to 0 explicitly */ > =C2=A0 writel(0, phyctl); > =C2=A0 break; > + case sun8i_h3_phy: > + dev_err(phy_data->dev, "H3 usb_phy_write is not > supported\n"); You should unlock the mutex here. > + return; Also, it might make sense to add default case what WARN's on invalid enum. > =C2=A0 } > =C2=A0 > =C2=A0 for (i =3D 0; i < len; i++) { > @@ -243,6 +251,7 @@ static int sun4i_usb_phy_init(struct phy *_phy) > =C2=A0 struct sun4i_usb_phy *phy =3D phy_get_drvdata(_phy); > =C2=A0 struct sun4i_usb_phy_data *data =3D > to_sun4i_usb_phy_data(phy); > =C2=A0 int ret; > + u32 val; > =C2=A0 > =C2=A0 ret =3D clk_prepare_enable(phy->clk); > =C2=A0 if (ret) > @@ -254,16 +263,26 @@ static int sun4i_usb_phy_init(struct phy *_phy) > =C2=A0 return ret; > =C2=A0 } > =C2=A0 > - /* Enable USB 45 Ohm resistor calibration */ > - if (phy->index =3D=3D 0) > - sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1); > + if (data->cfg->type =3D=3D sun8i_h3_phy) { > + if (phy->index =3D=3D 0) { > + val =3D readl(data->base + REG_PHY_UNK_H3); > + writel(val & ~1, data->base + > REG_PHY_UNK_H3); > + } > =C2=A0 > - /* Adjust PHY's magnitude and rate */ > - sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5); > + val =3D readl(phy->pmu + REG_PMU_UNK_H3); > + writel(val & ~2, phy->pmu + REG_PMU_UNK_H3); > + } else { > + /* Enable USB 45 Ohm resistor calibration */ > + if (phy->index =3D=3D 0) > + sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, > 0x01, 1); > =C2=A0 > - /* Disconnect threshold adjustment */ > - sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, > - =C2=A0=C2=A0=C2=A0=C2=A0data->cfg->disc_thresh, 2); > + /* Adjust PHY's magnitude and rate */ > + sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, > 0x14, 5); > + > + /* Disconnect threshold adjustment */ > + sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, > + =C2=A0=C2=A0=C2=A0=C2=A0data->cfg->disc_thresh, 2); > + } > =C2=A0 > =C2=A0 sun4i_usb_phy_passby(phy, 1); > =C2=A0 > @@ -555,6 +574,13 @@ static const struct sun4i_usb_phy_cfg > sun8i_a33_cfg =3D { > =C2=A0 .dedicated_clocks =3D true, > =C2=A0}; > =C2=A0 > +static const struct sun4i_usb_phy_cfg sun8i_h3_cfg =3D { > + .num_phys =3D 4, > + .disc_thresh =3D 3, > + .type =3D sun8i_h3_phy, > + .dedicated_clocks =3D true, > +}; > + > =C2=A0static const struct of_device_id sun4i_usb_phy_of_match[] =3D { > =C2=A0 { .compatible =3D "allwinner,sun4i-a10-usb-phy", .data =3D > &sun4i_a10_cfg }, > =C2=A0 { .compatible =3D "allwinner,sun5i-a13-usb-phy", .data =3D > &sun5i_a13_cfg }, > @@ -562,6 +588,7 @@ static const struct of_device_id > sun4i_usb_phy_of_match[] =3D { > =C2=A0 { .compatible =3D "allwinner,sun7i-a20-usb-phy", .data =3D > &sun7i_a20_cfg }, > =C2=A0 { .compatible =3D "allwinner,sun8i-a23-usb-phy", .data =3D > &sun8i_a23_cfg }, > =C2=A0 { .compatible =3D "allwinner,sun8i-a33-usb-phy", .data =3D > &sun8i_a33_cfg }, > + { .compatible =3D "allwinner,sun8i-h3-usb-phy", .data =3D > &sun8i_h3_cfg }, > =C2=A0 { }, > =C2=A0}; > =C2=A0MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match); > @@ -595,6 +622,7 @@ static int sun4i_usb_phy_probe(struct > platform_device *pdev) > =C2=A0 mutex_init(&data->mutex); > =C2=A0 INIT_DELAYED_WORK(&data->detect, > sun4i_usb_phy0_id_vbus_det_scan); > =C2=A0 dev_set_drvdata(dev, data); > + data->dev =3D dev; > =C2=A0 data->cfg =3D match->data; > =C2=A0 > =C2=A0 res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, > "phy_ctrl"); > --=20 > 2.5.0 >=20 --=20 You received this message because you are subscribed to the Google Groups "= linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/d/optout.