From 6099cc2bb0ce2463caaab7171d897af6fa699fb7 Mon Sep 17 00:00:00 2001 From: William Wu Date: Tue, 13 Dec 2016 17:29:24 +0800 Subject: [PATCH] phy: rockchip-inno-usb2: support otg vbus always powered on Some platforms (e.g. RK3399 BOX board) otg port connector interface is not standard, that is a Type-A connector with vbus always powered on, looks like to work as host mode, however, the otg port still need to support DRD mode. In the current code, if otg vbus is always powered on, it will cause USB2 PHY to detect a floating charger in error case and power off USB2 PHY. This patch adds a new property "rockchip,vbus-always-on" to fix this issue. With this patch, we handle this case as otg host only mode, and avoid to do charger detection and power off USB2 PHY. Change-Id: I69e5e87021f3f2d654793e547264aec55ac664ef Signed-off-by: William Wu Signed-off-by: Frank Wang --- .../bindings/phy/phy-rockchip-inno-usb2.yaml | 4 ++++ drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.yaml b/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.yaml index 56938f32fa56..110c0d4681dc 100644 --- a/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.yaml +++ b/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.yaml @@ -115,6 +115,10 @@ properties: get vbus status. If not, it will use bvalid status bit to get vbus status by default. + rockchip,vbus-always-on: + $ref: /schemas/types.yaml#/definitions/flag + description: when set, indicates that the otg vbus is always powered on. + required: - "#phy-cells" - interrupts diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 46ebdb1460a3..b815282b0ca1 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -160,6 +160,7 @@ struct rockchip_usb2phy_cfg { * @port_id: flag for otg port or host port. * @suspended: phy suspended flag. * @vbus_attached: otg device vbus status. + * @vbus_always_on: otg vbus is always powered on. * @bvalid_irq: IRQ number assigned for vbus valid rise detection. * @ls_irq: IRQ number assigned for linestate detection. * @otg_mux_irq: IRQ number which multiplex otg-id/otg-bvalid/linestate @@ -178,6 +179,7 @@ struct rockchip_usb2phy_port { unsigned int port_id; bool suspended; bool vbus_attached; + bool vbus_always_on; int bvalid_irq; int ls_irq; int otg_mux_irq; @@ -410,7 +412,8 @@ static int rockchip_usb2phy_init(struct phy *phy) if (rport->port_id == USB2PHY_PORT_OTG) { if (rport->mode != USB_DR_MODE_HOST && - rport->mode != USB_DR_MODE_UNKNOWN) { + rport->mode != USB_DR_MODE_UNKNOWN && + !rport->vbus_always_on) { /* clear bvalid status and enable bvalid detect irq */ ret = property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, @@ -505,7 +508,8 @@ static int rockchip_usb2phy_exit(struct phy *phy) if (rport->port_id == USB2PHY_PORT_OTG && rport->mode != USB_DR_MODE_HOST && - rport->mode != USB_DR_MODE_UNKNOWN) { + rport->mode != USB_DR_MODE_UNKNOWN && + !rport->vbus_always_on) { cancel_delayed_work_sync(&rport->otg_sm_work); cancel_delayed_work_sync(&rport->chg_work); } else if (rport->port_id == USB2PHY_PORT_HOST) @@ -997,9 +1001,13 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, mutex_init(&rport->mutex); + rport->vbus_always_on = + of_property_read_bool(child_np, "rockchip,vbus-always-on"); + rport->mode = of_usb_get_dr_mode_by_phy(child_np, -1); if (rport->mode == USB_DR_MODE_HOST || - rport->mode == USB_DR_MODE_UNKNOWN) { + rport->mode == USB_DR_MODE_UNKNOWN || + rport->vbus_always_on) { ret = 0; goto out; }