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 <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
This commit is contained in:
Meng Dongyang
2018-03-13 09:24:57 +08:00
committed by Tao Huang
parent 2f6076d7bf
commit 6bf52fb9a6

View File

@@ -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 },