From 6bf52fb9a6df0c7af7746277855691fcc49111fc Mon Sep 17 00:00:00 2001 From: Meng Dongyang Date: Tue, 13 Mar 2018 09:24:57 +0800 Subject: [PATCH] phy: rockchip-inno-usb2: make u2phy enter low power mode Make u2phy enter low power mode when suspend. If config the DT of u2phy port with "rockchip,low-power-mode" property, the port will be config to lower power state when suspend. Bvalid irq and linestate irq will be disabled in this mode. Change-Id: Ie7d40a9a181b0622b1f8d062a741661548cabd59 Signed-off-by: Meng Dongyang Signed-off-by: Frank Wang --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 111ce6f534cb..994188078177 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -132,6 +132,9 @@ struct rockchip_chg_det_reg { * @bypass_dm_en: usb bypass uart DM enable register. * @bypass_sel: usb bypass uart select register. * @bypass_iomux: usb bypass uart GRF iomux register. + * @bypass_bc: bypass battery charging module. + * @bypass_otg: bypass otg module. + * @bypass_host: bypass host module. * @ls_det_en: linestate detection enable register. * @ls_det_st: linestate detection state register. * @ls_det_clr: linestate detection clear register. @@ -159,6 +162,9 @@ struct rockchip_usb2phy_port_cfg { struct usb2phy_reg bypass_dm_en; struct usb2phy_reg bypass_sel; struct usb2phy_reg bypass_iomux; + struct usb2phy_reg bypass_bc; + struct usb2phy_reg bypass_otg; + struct usb2phy_reg bypass_host; struct usb2phy_reg ls_det_en; struct usb2phy_reg ls_det_st; struct usb2phy_reg ls_det_clr; @@ -198,6 +204,7 @@ struct rockchip_usb2phy_cfg { /** * struct rockchip_usb2phy_port: usb-phy port data. * @port_id: flag for otg port or host port. + * @low_power_en: enable enter low power when suspend. * @perip_connected: flag for periphyeral connect status. * @suspended: phy suspended flag. * @utmi_avalid: utmi avalid status usage flag. @@ -226,6 +233,7 @@ struct rockchip_usb2phy_cfg { struct rockchip_usb2phy_port { struct phy *phy; unsigned int port_id; + bool low_power_en; bool perip_connected; bool suspended; bool utmi_avalid; @@ -1496,6 +1504,10 @@ static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy, rport->port_id = USB2PHY_PORT_HOST; rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST]; + /* enter lower power state when suspend */ + rport->low_power_en = + of_property_read_bool(child_np, "rockchip,low-power-mode"); + mutex_init(&rport->mutex); INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work); @@ -1563,6 +1575,10 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, rport->utmi_avalid = of_property_read_bool(child_np, "rockchip,utmi-avalid"); + /* enter lower power state when suspend */ + rport->low_power_en = + of_property_read_bool(child_np, "rockchip,low-power-mode"); + /* Get Vbus regulators */ rport->vbus = devm_regulator_get_optional(&rport->phy->dev, "vbus"); if (IS_ERR(rport->vbus)) { @@ -1861,6 +1877,42 @@ disable_clks: return ret; } +static int __maybe_unused +rockchip_usb2phy_low_power_enable(struct rockchip_usb2phy *rphy, + struct rockchip_usb2phy_port *rport, + bool value) +{ + int ret = 0; + + if (!rport->low_power_en) + return ret; + + if (rport->port_id == USB2PHY_PORT_OTG) { + dev_info(&rport->phy->dev, "set otg port low power state %d\n", + value); + ret = property_enable(rphy->grf, &rport->port_cfg->bypass_bc, + value); + if (ret) + return ret; + + ret = property_enable(rphy->grf, &rport->port_cfg->bypass_otg, + value); + if (ret) + return ret; + + ret = property_enable(rphy->grf, &rport->port_cfg->vbus_det_en, + !value); + } else if (rport->port_id == USB2PHY_PORT_HOST) { + dev_info(&rport->phy->dev, "set host port low power state %d\n", + value); + + ret = property_enable(rphy->grf, &rport->port_cfg->bypass_host, + value); + } + + return ret; +} + static int rk312x_usb2phy_tuning(struct rockchip_usb2phy *rphy) { int ret; @@ -2046,6 +2098,9 @@ static int rockchip_usb2phy_pm_suspend(struct device *dev) dev_err(rphy->dev, "failed to enable linestate irq\n"); return ret; } + + /* enter low power state */ + rockchip_usb2phy_low_power_enable(rphy, rport, true); } return ret; @@ -2095,6 +2150,9 @@ static int rockchip_usb2phy_pm_resume(struct device *dev) return ret; } } + + /* exit low power state */ + rockchip_usb2phy_low_power_enable(rphy, rport, false); } return ret; @@ -2297,6 +2355,8 @@ static const struct rockchip_usb2phy_cfg rk3328_phy_cfgs[] = { .bvalid_det_en = { 0x0110, 2, 2, 0, 1 }, .bvalid_det_st = { 0x0114, 2, 2, 0, 1 }, .bvalid_det_clr = { 0x0118, 2, 2, 0, 1 }, + .bypass_bc = { 0x0008, 14, 14, 0, 1 }, + .bypass_otg = { 0x0018, 15, 15, 1, 0 }, .iddig_output = { 0x0100, 10, 10, 0, 1 }, .iddig_en = { 0x0100, 9, 9, 0, 1 }, .idfall_det_en = { 0x0110, 5, 5, 0, 1 }, @@ -2316,6 +2376,7 @@ static const struct rockchip_usb2phy_cfg rk3328_phy_cfgs[] = { }, [USB2PHY_PORT_HOST] = { .phy_sus = { 0x104, 8, 0, 0, 0x1d1 }, + .bypass_host = { 0x048, 15, 15, 1, 0 }, .ls_det_en = { 0x110, 1, 1, 0, 1 }, .ls_det_st = { 0x114, 1, 1, 0, 1 }, .ls_det_clr = { 0x118, 1, 1, 0, 1 },