From 5b9c454fb71a891f19fb9bd3178e742609cb9305 Mon Sep 17 00:00:00 2001 From: Wu Liang feng Date: Tue, 26 Jul 2016 20:05:09 +0800 Subject: [PATCH] phy: rockchip-inno-usb2: make utmi vbus configurable in DT Rockchip USB2 phy provides utmi_avalid and utmi_bvalid for user to check UTMI vbus status. Generally, both of them can reflect the vbus status correctly, and the utmi_bvalid has higher sensitivity, so we select the utmi_bvalid to get vbus status by default. But some special SoCs may not provide utmi_bvalid, so we need to select utmi_avalid in this case. Change-Id: I0d47c2237f852cb67ebd82fe2673b2bd2e6ccce6 Signed-off-by: Wu Liang feng --- .../bindings/phy/phy-rockchip-inno-usb2.txt | 3 +++ drivers/phy/phy-rockchip-inno-usb2.c | 22 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt b/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt index 3c29c77a7018..1155aaa853f6 100644 --- a/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt +++ b/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt @@ -29,6 +29,9 @@ Required properties (port (child) node): Optional properties: - phy-supply : phandle to a regulator that provides power to VBUS. See ./phy-bindings.txt for details. + - rockchip,utmi-avalid : when set, the usb2 phy will use avalid + status bit to get vbus status. If not, it will use + bvalid status bit to get vbus status by default. Example: diff --git a/drivers/phy/phy-rockchip-inno-usb2.c b/drivers/phy/phy-rockchip-inno-usb2.c index 4a798bd6624a..e3336eb59593 100644 --- a/drivers/phy/phy-rockchip-inno-usb2.c +++ b/drivers/phy/phy-rockchip-inno-usb2.c @@ -130,7 +130,8 @@ struct rockchip_chg_det_reg { * @ls_det_en: linestate detection enable register. * @ls_det_st: linestate detection state register. * @ls_det_clr: linestate detection clear register. - * @utmi_bvalid: utmi vbus valid status register. + * @utmi_avalid: utmi vbus avalid status register. + * @utmi_bvalid: utmi vbus bvalid status register. * @utmi_ls: utmi linestate state register. * @utmi_hstdet: utmi host disconnect register. */ @@ -142,6 +143,7 @@ struct rockchip_usb2phy_port_cfg { struct usb2phy_reg ls_det_en; struct usb2phy_reg ls_det_st; struct usb2phy_reg ls_det_clr; + struct usb2phy_reg utmi_avalid; struct usb2phy_reg utmi_bvalid; struct usb2phy_reg utmi_ls; struct usb2phy_reg utmi_hstdet; @@ -168,6 +170,9 @@ struct rockchip_usb2phy_cfg { * struct rockchip_usb2phy_port: usb-phy port data. * @port_id: flag for otg port or host port. * @suspended: phy suspended flag. + * @utmi_avalid: utmi avalid status usage flag. + * true - use avalid to get vbus status + * flase - use bvalid to get vbus status * @vbus_attached: otg device vbus status. * @bvalid_irq: IRQ number assigned for vbus valid rise detection. * @ls_irq: IRQ number assigned for linestate detection. @@ -185,6 +190,7 @@ struct rockchip_usb2phy_port { struct phy *phy; unsigned int port_id; bool suspended; + bool utmi_avalid; bool vbus_attached; int bvalid_irq; int ls_irq; @@ -519,7 +525,13 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work) unsigned long delay; bool vbus_attach, sch_work, notify_charger; - vbus_attach = property_enabled(rphy, &rport->port_cfg->utmi_bvalid); + if (rport->utmi_avalid) + vbus_attach = + property_enabled(rphy, &rport->port_cfg->utmi_avalid); + else + vbus_attach = + property_enabled(rphy, &rport->port_cfg->utmi_bvalid); + sch_work = false; notify_charger = false; delay = OTG_SCHEDULE_DELAY; @@ -975,6 +987,9 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, INIT_DELAYED_WORK(&rport->chg_work, rockchip_chg_detect_work); INIT_DELAYED_WORK(&rport->otg_sm_work, rockchip_usb2phy_otg_sm_work); + rport->utmi_avalid = + of_property_read_bool(child_np, "rockchip,utmi-avalid"); + rport->bvalid_irq = of_irq_get_byname(child_np, "otg-bvalid"); if (rport->bvalid_irq < 0) { dev_err(rphy->dev, "no vbus valid irq provided\n"); @@ -1188,7 +1203,8 @@ static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = { .bvalid_det_en = { 0xe3c0, 3, 3, 0, 1 }, .bvalid_det_st = { 0xe3e0, 3, 3, 0, 1 }, .bvalid_det_clr = { 0xe3d0, 3, 3, 0, 1 }, - .utmi_bvalid = { 0xe2ac, 7, 7, 0, 1 }, + .utmi_avalid = { 0xe2ac, 7, 7, 0, 1 }, + .utmi_bvalid = { 0xe2ac, 12, 12, 0, 1 }, }, [USB2PHY_PORT_HOST] = { .phy_sus = { 0xe458, 1, 0, 0x2, 0x1 }, -- 2.34.1