diff options
author | Steve Glendinning <steve.glendinning@shawell.net> | 2012-11-22 03:05:25 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-11-23 14:15:18 -0500 |
commit | 319b95b5f47e2ee67782f39fbb2c7fbd2c60c631 (patch) | |
tree | a52259dc09bd6ba8a15d45893d3973e9b0cc240d /drivers/net/usb | |
parent | e5e3af8348945b7c0b96e720c35309c79c24e98f (diff) |
smsc95xx: refactor entering suspend modes
This patch splits out the logic for entering suspend modes
to separate functions, to reduce the complexity of the
smsc95xx_suspend function.
Signed-off-by: Steve Glendinning <steve.glendinning@shawell.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/usb')
-rw-r--r-- | drivers/net/usb/smsc95xx.c | 178 |
1 files changed, 99 insertions, 79 deletions
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index e98ff8c77ec5..bf8854386b88 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c | |||
@@ -1130,6 +1130,102 @@ static int smsc95xx_link_ok_nopm(struct usbnet *dev) | |||
1130 | return !!(ret & BMSR_LSTATUS); | 1130 | return !!(ret & BMSR_LSTATUS); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | static int smsc95xx_enter_suspend0(struct usbnet *dev) | ||
1134 | { | ||
1135 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
1136 | u32 val; | ||
1137 | int ret; | ||
1138 | |||
1139 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1140 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1141 | |||
1142 | val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); | ||
1143 | val |= PM_CTL_SUS_MODE_0; | ||
1144 | |||
1145 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1146 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1147 | |||
1148 | /* clear wol status */ | ||
1149 | val &= ~PM_CTL_WUPS_; | ||
1150 | val |= PM_CTL_WUPS_WOL_; | ||
1151 | |||
1152 | /* enable energy detection */ | ||
1153 | if (pdata->wolopts & WAKE_PHY) | ||
1154 | val |= PM_CTL_WUPS_ED_; | ||
1155 | |||
1156 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1157 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1158 | |||
1159 | /* read back PM_CTRL */ | ||
1160 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1161 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1162 | |||
1163 | smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); | ||
1164 | |||
1165 | return 0; | ||
1166 | } | ||
1167 | |||
1168 | static int smsc95xx_enter_suspend1(struct usbnet *dev) | ||
1169 | { | ||
1170 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); | ||
1171 | struct mii_if_info *mii = &dev->mii; | ||
1172 | u32 val; | ||
1173 | int ret; | ||
1174 | |||
1175 | /* reconfigure link pulse detection timing for | ||
1176 | * compatibility with non-standard link partners | ||
1177 | */ | ||
1178 | if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) | ||
1179 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG, | ||
1180 | PHY_EDPD_CONFIG_DEFAULT); | ||
1181 | |||
1182 | /* enable energy detect power-down mode */ | ||
1183 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS); | ||
1184 | check_warn_return(ret, "Error reading PHY_MODE_CTRL_STS"); | ||
1185 | |||
1186 | ret |= MODE_CTRL_STS_EDPWRDOWN_; | ||
1187 | |||
1188 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret); | ||
1189 | |||
1190 | /* enter SUSPEND1 mode */ | ||
1191 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1192 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1193 | |||
1194 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); | ||
1195 | val |= PM_CTL_SUS_MODE_1; | ||
1196 | |||
1197 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1198 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1199 | |||
1200 | /* clear wol status, enable energy detection */ | ||
1201 | val &= ~PM_CTL_WUPS_; | ||
1202 | val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); | ||
1203 | |||
1204 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1205 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1206 | |||
1207 | smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); | ||
1208 | |||
1209 | return 0; | ||
1210 | } | ||
1211 | |||
1212 | static int smsc95xx_enter_suspend2(struct usbnet *dev) | ||
1213 | { | ||
1214 | u32 val; | ||
1215 | int ret; | ||
1216 | |||
1217 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1218 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1219 | |||
1220 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); | ||
1221 | val |= PM_CTL_SUS_MODE_2; | ||
1222 | |||
1223 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1224 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1225 | |||
1226 | return 0; | ||
1227 | } | ||
1228 | |||
1133 | static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) | 1229 | static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) |
1134 | { | 1230 | { |
1135 | struct usbnet *dev = usb_get_intfdata(intf); | 1231 | struct usbnet *dev = usb_get_intfdata(intf); |
@@ -1167,17 +1263,7 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) | |||
1167 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | 1263 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
1168 | check_warn_return(ret, "Error writing PM_CTRL"); | 1264 | check_warn_return(ret, "Error writing PM_CTRL"); |
1169 | 1265 | ||
1170 | /* enter suspend2 mode */ | 1266 | return smsc95xx_enter_suspend2(dev); |
1171 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1172 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1173 | |||
1174 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); | ||
1175 | val |= PM_CTL_SUS_MODE_2; | ||
1176 | |||
1177 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1178 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1179 | |||
1180 | return 0; | ||
1181 | } | 1267 | } |
1182 | 1268 | ||
1183 | if (pdata->wolopts & WAKE_PHY) { | 1269 | if (pdata->wolopts & WAKE_PHY) { |
@@ -1189,47 +1275,8 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) | |||
1189 | * otherwise enter SUSPEND0 below | 1275 | * otherwise enter SUSPEND0 below |
1190 | */ | 1276 | */ |
1191 | if (!link_up) { | 1277 | if (!link_up) { |
1192 | struct mii_if_info *mii = &dev->mii; | ||
1193 | netdev_info(dev->net, "entering SUSPEND1 mode"); | 1278 | netdev_info(dev->net, "entering SUSPEND1 mode"); |
1194 | 1279 | return smsc95xx_enter_suspend1(dev); | |
1195 | /* reconfigure link pulse detection timing for | ||
1196 | * compatibility with non-standard link partners | ||
1197 | */ | ||
1198 | if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) | ||
1199 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, | ||
1200 | PHY_EDPD_CONFIG, | ||
1201 | PHY_EDPD_CONFIG_DEFAULT); | ||
1202 | |||
1203 | /* enable energy detect power-down mode */ | ||
1204 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, | ||
1205 | PHY_MODE_CTRL_STS); | ||
1206 | check_warn_return(ret, "Error reading PHY_MODE_CTRL_STS"); | ||
1207 | |||
1208 | ret |= MODE_CTRL_STS_EDPWRDOWN_; | ||
1209 | |||
1210 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, | ||
1211 | PHY_MODE_CTRL_STS, ret); | ||
1212 | |||
1213 | /* enter SUSPEND1 mode */ | ||
1214 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1215 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1216 | |||
1217 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); | ||
1218 | val |= PM_CTL_SUS_MODE_1; | ||
1219 | |||
1220 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1221 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1222 | |||
1223 | /* clear wol status, enable energy detection */ | ||
1224 | val &= ~PM_CTL_WUPS_; | ||
1225 | val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); | ||
1226 | |||
1227 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1228 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1229 | |||
1230 | smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); | ||
1231 | |||
1232 | return 0; | ||
1233 | } | 1280 | } |
1234 | } | 1281 | } |
1235 | 1282 | ||
@@ -1383,34 +1430,7 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) | |||
1383 | 1430 | ||
1384 | /* some wol options are enabled, so enter SUSPEND0 */ | 1431 | /* some wol options are enabled, so enter SUSPEND0 */ |
1385 | netdev_info(dev->net, "entering SUSPEND0 mode"); | 1432 | netdev_info(dev->net, "entering SUSPEND0 mode"); |
1386 | 1433 | return smsc95xx_enter_suspend0(dev); | |
1387 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1388 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1389 | |||
1390 | val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); | ||
1391 | val |= PM_CTL_SUS_MODE_0; | ||
1392 | |||
1393 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1394 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1395 | |||
1396 | /* clear wol status */ | ||
1397 | val &= ~PM_CTL_WUPS_; | ||
1398 | val |= PM_CTL_WUPS_WOL_; | ||
1399 | |||
1400 | /* enable energy detection */ | ||
1401 | if (pdata->wolopts & WAKE_PHY) | ||
1402 | val |= PM_CTL_WUPS_ED_; | ||
1403 | |||
1404 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); | ||
1405 | check_warn_return(ret, "Error writing PM_CTRL"); | ||
1406 | |||
1407 | /* read back PM_CTRL */ | ||
1408 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); | ||
1409 | check_warn_return(ret, "Error reading PM_CTRL"); | ||
1410 | |||
1411 | smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); | ||
1412 | |||
1413 | return 0; | ||
1414 | } | 1434 | } |
1415 | 1435 | ||
1416 | static int smsc95xx_resume(struct usb_interface *intf) | 1436 | static int smsc95xx_resume(struct usb_interface *intf) |