Skip to content

Commit 5e72cfa

Browse files
Meng Dongyangrkhuangtao
authored andcommitted
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 <[email protected]>
1 parent a3b1bb7 commit 5e72cfa

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

drivers/phy/rockchip/phy-rockchip-inno-usb2.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ struct rockchip_chg_det_reg {
133133
* @bypass_dm_en: usb bypass uart DM enable register.
134134
* @bypass_sel: usb bypass uart select register.
135135
* @bypass_iomux: usb bypass uart GRF iomux register.
136+
* @bypass_bc: bypass battery charging module.
137+
* @bypass_otg: bypass otg module.
138+
* @bypass_host: bypass host module.
136139
* @ls_det_en: linestate detection enable register.
137140
* @ls_det_st: linestate detection state register.
138141
* @ls_det_clr: linestate detection clear register.
@@ -160,6 +163,9 @@ struct rockchip_usb2phy_port_cfg {
160163
struct usb2phy_reg bypass_dm_en;
161164
struct usb2phy_reg bypass_sel;
162165
struct usb2phy_reg bypass_iomux;
166+
struct usb2phy_reg bypass_bc;
167+
struct usb2phy_reg bypass_otg;
168+
struct usb2phy_reg bypass_host;
163169
struct usb2phy_reg ls_det_en;
164170
struct usb2phy_reg ls_det_st;
165171
struct usb2phy_reg ls_det_clr;
@@ -199,6 +205,7 @@ struct rockchip_usb2phy_cfg {
199205
/**
200206
* struct rockchip_usb2phy_port: usb-phy port data.
201207
* @port_id: flag for otg port or host port.
208+
* @low_power_en: enable enter low power when suspend.
202209
* @perip_connected: flag for periphyeral connect status.
203210
* @suspended: phy suspended flag.
204211
* @utmi_avalid: utmi avalid status usage flag.
@@ -227,6 +234,7 @@ struct rockchip_usb2phy_cfg {
227234
struct rockchip_usb2phy_port {
228235
struct phy *phy;
229236
unsigned int port_id;
237+
bool low_power_en;
230238
bool perip_connected;
231239
bool suspended;
232240
bool utmi_avalid;
@@ -1477,6 +1485,10 @@ static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy,
14771485
rport->port_id = USB2PHY_PORT_HOST;
14781486
rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
14791487

1488+
/* enter lower power state when suspend */
1489+
rport->low_power_en =
1490+
of_property_read_bool(child_np, "rockchip,low-power-mode");
1491+
14801492
mutex_init(&rport->mutex);
14811493
INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work);
14821494

@@ -1543,6 +1555,10 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
15431555
rport->utmi_avalid =
15441556
of_property_read_bool(child_np, "rockchip,utmi-avalid");
15451557

1558+
/* enter lower power state when suspend */
1559+
rport->low_power_en =
1560+
of_property_read_bool(child_np, "rockchip,low-power-mode");
1561+
15461562
rport->ls_irq = of_irq_get_byname(child_np, "linestate");
15471563
if (rport->ls_irq < 0) {
15481564
dev_err(rphy->dev, "no linestate irq provided\n");
@@ -1810,6 +1826,41 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
18101826
return ret;
18111827
}
18121828

1829+
static int rockchip_usb2phy_low_power_enable(struct rockchip_usb2phy *rphy,
1830+
struct rockchip_usb2phy_port *rport,
1831+
bool value)
1832+
{
1833+
int ret = 0;
1834+
1835+
if (!rport->low_power_en)
1836+
return ret;
1837+
1838+
if (rport->port_id == USB2PHY_PORT_OTG) {
1839+
dev_info(&rport->phy->dev, "set otg port low power state %d\n",
1840+
value);
1841+
ret = property_enable(rphy, &rport->port_cfg->bypass_bc,
1842+
value);
1843+
if (ret)
1844+
return ret;
1845+
1846+
ret = property_enable(rphy, &rport->port_cfg->bypass_otg,
1847+
value);
1848+
if (ret)
1849+
return ret;
1850+
1851+
ret = property_enable(rphy, &rport->port_cfg->vbus_det_en,
1852+
!value);
1853+
} else if (rport->port_id == USB2PHY_PORT_HOST) {
1854+
dev_info(&rport->phy->dev, "set host port low power state %d\n",
1855+
value);
1856+
1857+
ret = property_enable(rphy, &rport->port_cfg->bypass_host,
1858+
value);
1859+
}
1860+
1861+
return ret;
1862+
}
1863+
18131864
static int rk312x_usb2phy_tuning(struct rockchip_usb2phy *rphy)
18141865
{
18151866
int ret;
@@ -1995,6 +2046,9 @@ static int rockchip_usb2phy_pm_suspend(struct device *dev)
19952046
dev_err(rphy->dev, "failed to enable linestate irq\n");
19962047
return ret;
19972048
}
2049+
2050+
/* enter low power state */
2051+
rockchip_usb2phy_low_power_enable(rphy, rport, true);
19982052
}
19992053

20002054
return ret;
@@ -2045,6 +2099,9 @@ static int rockchip_usb2phy_pm_resume(struct device *dev)
20452099
return ret;
20462100
}
20472101
}
2102+
2103+
/* exit low power state */
2104+
rockchip_usb2phy_low_power_enable(rphy, rport, false);
20482105
}
20492106

20502107
return ret;
@@ -2247,6 +2304,8 @@ static const struct rockchip_usb2phy_cfg rk3328_phy_cfgs[] = {
22472304
.bvalid_det_en = { 0x0110, 2, 2, 0, 1 },
22482305
.bvalid_det_st = { 0x0114, 2, 2, 0, 1 },
22492306
.bvalid_det_clr = { 0x0118, 2, 2, 0, 1 },
2307+
.bypass_bc = { 0x0008, 14, 14, 0, 1 },
2308+
.bypass_otg = { 0x0018, 15, 15, 1, 0 },
22502309
.iddig_output = { 0x0100, 10, 10, 0, 1 },
22512310
.iddig_en = { 0x0100, 9, 9, 0, 1 },
22522311
.idfall_det_en = { 0x0110, 5, 5, 0, 1 },
@@ -2266,6 +2325,7 @@ static const struct rockchip_usb2phy_cfg rk3328_phy_cfgs[] = {
22662325
},
22672326
[USB2PHY_PORT_HOST] = {
22682327
.phy_sus = { 0x104, 8, 0, 0, 0x1d1 },
2328+
.bypass_host = { 0x048, 15, 15, 1, 0 },
22692329
.ls_det_en = { 0x110, 1, 1, 0, 1 },
22702330
.ls_det_st = { 0x114, 1, 1, 0, 1 },
22712331
.ls_det_clr = { 0x118, 1, 1, 0, 1 },

0 commit comments

Comments
 (0)