Commit 843f9205 authored by Justin Chen's avatar Justin Chen Committed by Jakub Kicinski

net: usb: ax88179_178a: clean up pm calls

Instead of passing in_pm flags all over the place, use the private
struct to handle in_pm mode.
Signed-off-by: default avatarJustin Chen <justinpopo6@gmail.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 9718f9ce
...@@ -171,6 +171,7 @@ struct ax88179_data { ...@@ -171,6 +171,7 @@ struct ax88179_data {
u8 eee_active; u8 eee_active;
u16 rxctl; u16 rxctl;
u16 reserved; u16 reserved;
u8 in_pm;
}; };
struct ax88179_int_data { struct ax88179_int_data {
...@@ -187,15 +188,29 @@ static const struct { ...@@ -187,15 +188,29 @@ static const struct {
{7, 0xcc, 0x4c, 0x18, 8}, {7, 0xcc, 0x4c, 0x18, 8},
}; };
static void ax88179_set_pm_mode(struct usbnet *dev, bool pm_mode)
{
struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
ax179_data->in_pm = pm_mode;
}
static int ax88179_in_pm(struct usbnet *dev)
{
struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
return ax179_data->in_pm;
}
static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
u16 size, void *data, int in_pm) u16 size, void *data)
{ {
int ret; int ret;
int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
BUG_ON(!dev); BUG_ON(!dev);
if (!in_pm) if (!ax88179_in_pm(dev))
fn = usbnet_read_cmd; fn = usbnet_read_cmd;
else else
fn = usbnet_read_cmd_nopm; fn = usbnet_read_cmd_nopm;
...@@ -211,14 +226,14 @@ static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, ...@@ -211,14 +226,14 @@ static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
} }
static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
u16 size, const void *data, int in_pm) u16 size, const void *data)
{ {
int ret; int ret;
int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
BUG_ON(!dev); BUG_ON(!dev);
if (!in_pm) if (!ax88179_in_pm(dev))
fn = usbnet_write_cmd; fn = usbnet_write_cmd;
else else
fn = usbnet_write_cmd_nopm; fn = usbnet_write_cmd_nopm;
...@@ -251,47 +266,6 @@ static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, ...@@ -251,47 +266,6 @@ static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
} }
} }
static int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
u16 index, u16 size, void *data)
{
int ret;
if (2 == size) {
u16 buf;
ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
le16_to_cpus(&buf);
*((u16 *)data) = buf;
} else if (4 == size) {
u32 buf;
ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
le32_to_cpus(&buf);
*((u32 *)data) = buf;
} else {
ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1);
}
return ret;
}
static int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
u16 index, u16 size, const void *data)
{
int ret;
if (2 == size) {
u16 buf;
buf = *((u16 *)data);
cpu_to_le16s(&buf);
ret = __ax88179_write_cmd(dev, cmd, value, index,
size, &buf, 1);
} else {
ret = __ax88179_write_cmd(dev, cmd, value, index,
size, data, 1);
}
return ret;
}
static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
u16 size, void *data) u16 size, void *data)
{ {
...@@ -299,16 +273,16 @@ static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, ...@@ -299,16 +273,16 @@ static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
if (2 == size) { if (2 == size) {
u16 buf = 0; u16 buf = 0;
ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf);
le16_to_cpus(&buf); le16_to_cpus(&buf);
*((u16 *)data) = buf; *((u16 *)data) = buf;
} else if (4 == size) { } else if (4 == size) {
u32 buf = 0; u32 buf = 0;
ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf);
le32_to_cpus(&buf); le32_to_cpus(&buf);
*((u32 *)data) = buf; *((u32 *)data) = buf;
} else { } else {
ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0); ret = __ax88179_read_cmd(dev, cmd, value, index, size, data);
} }
return ret; return ret;
...@@ -324,10 +298,10 @@ static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, ...@@ -324,10 +298,10 @@ static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
buf = *((u16 *)data); buf = *((u16 *)data);
cpu_to_le16s(&buf); cpu_to_le16s(&buf);
ret = __ax88179_write_cmd(dev, cmd, value, index, ret = __ax88179_write_cmd(dev, cmd, value, index,
size, &buf, 0); size, &buf);
} else { } else {
ret = __ax88179_write_cmd(dev, cmd, value, index, ret = __ax88179_write_cmd(dev, cmd, value, index,
size, data, 0); size, data);
} }
return ret; return ret;
...@@ -430,52 +404,46 @@ static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) ...@@ -430,52 +404,46 @@ static int ax88179_suspend(struct usb_interface *intf, pm_message_t message)
u16 tmp16; u16 tmp16;
u8 tmp8; u8 tmp8;
ax88179_set_pm_mode(dev, true);
usbnet_suspend(intf, message); usbnet_suspend(intf, message);
/* Disable RX path */ /* Disable RX path */
ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2, 2, &tmp16); 2, 2, &tmp16);
tmp16 &= ~AX_MEDIUM_RECEIVE_EN; tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2, 2, &tmp16); 2, 2, &tmp16);
/* Force bulk-in zero length */ /* Force bulk-in zero length */
ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2, 2, &tmp16); 2, 2, &tmp16);
tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL; tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2, 2, &tmp16); 2, 2, &tmp16);
/* change clock */ /* change clock */
tmp8 = 0; tmp8 = 0;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
/* Configure RX control register => stop operation */ /* Configure RX control register => stop operation */
tmp16 = AX_RX_CTL_STOP; tmp16 = AX_RX_CTL_STOP;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
ax88179_set_pm_mode(dev, false);
return 0; return 0;
} }
/* This function is used to enable the autodetach function. */ /* This function is used to enable the autodetach function. */
/* This function is determined by offset 0x43 of EEPROM */ /* This function is determined by offset 0x43 of EEPROM */
static int ax88179_auto_detach(struct usbnet *dev, int in_pm) static int ax88179_auto_detach(struct usbnet *dev)
{ {
u16 tmp16; u16 tmp16;
u8 tmp8; u8 tmp8;
int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *);
int (*fnw)(struct usbnet *, u8, u16, u16, u16, const void *);
if (!in_pm) {
fnr = ax88179_read_cmd;
fnw = ax88179_write_cmd;
} else {
fnr = ax88179_read_cmd_nopm;
fnw = ax88179_write_cmd_nopm;
}
if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0) if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0)
return 0; return 0;
if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100))) if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100)))
...@@ -483,13 +451,13 @@ static int ax88179_auto_detach(struct usbnet *dev, int in_pm) ...@@ -483,13 +451,13 @@ static int ax88179_auto_detach(struct usbnet *dev, int in_pm)
/* Enable Auto Detach bit */ /* Enable Auto Detach bit */
tmp8 = 0; tmp8 = 0;
fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
tmp8 |= AX_CLK_SELECT_ULR; tmp8 |= AX_CLK_SELECT_ULR;
fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
tmp16 |= AX_PHYPWR_RSTCTL_AT; tmp16 |= AX_PHYPWR_RSTCTL_AT;
fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
return 0; return 0;
} }
...@@ -500,32 +468,36 @@ static int ax88179_resume(struct usb_interface *intf) ...@@ -500,32 +468,36 @@ static int ax88179_resume(struct usb_interface *intf)
u16 tmp16; u16 tmp16;
u8 tmp8; u8 tmp8;
ax88179_set_pm_mode(dev, true);
usbnet_link_change(dev, 0, 0); usbnet_link_change(dev, 0, 0);
/* Power up ethernet PHY */ /* Power up ethernet PHY */
tmp16 = 0; tmp16 = 0;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2, 2, &tmp16); 2, 2, &tmp16);
udelay(1000); udelay(1000);
tmp16 = AX_PHYPWR_RSTCTL_IPRL; tmp16 = AX_PHYPWR_RSTCTL_IPRL;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2, 2, &tmp16); 2, 2, &tmp16);
msleep(200); msleep(200);
/* Ethernet PHY Auto Detach*/ /* Ethernet PHY Auto Detach*/
ax88179_auto_detach(dev, 1); ax88179_auto_detach(dev);
/* Enable clock */ /* Enable clock */
ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
msleep(100); msleep(100);
/* Configure RX control register => start operation */ /* Configure RX control register => start operation */
tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
ax88179_set_pm_mode(dev, false);
return usbnet_resume(intf); return usbnet_resume(intf);
} }
...@@ -601,8 +573,7 @@ ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, ...@@ -601,8 +573,7 @@ ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
/* ax88179/178A returns 2 bytes from eeprom on read */ /* ax88179/178A returns 2 bytes from eeprom on read */
for (i = first_word; i <= last_word; i++) { for (i = first_word; i <= last_word; i++) {
ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2,
&eeprom_buff[i - first_word], &eeprom_buff[i - first_word]);
0);
if (ret < 0) { if (ret < 0) {
kfree(eeprom_buff); kfree(eeprom_buff);
return -EIO; return -EIO;
...@@ -1071,7 +1042,7 @@ static int ax88179_check_eeprom(struct usbnet *dev) ...@@ -1071,7 +1042,7 @@ static int ax88179_check_eeprom(struct usbnet *dev)
} while (buf & EEP_BUSY); } while (buf & EEP_BUSY);
__ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
2, 2, &eeprom[i * 2], 0); 2, 2, &eeprom[i * 2]);
if ((i == 0) && (eeprom[0] == 0xFF)) if ((i == 0) && (eeprom[0] == 0xFF))
return -EINVAL; return -EINVAL;
...@@ -1640,7 +1611,7 @@ static int ax88179_reset(struct usbnet *dev) ...@@ -1640,7 +1611,7 @@ static int ax88179_reset(struct usbnet *dev)
msleep(100); msleep(100);
/* Ethernet PHY Auto Detach*/ /* Ethernet PHY Auto Detach*/
ax88179_auto_detach(dev, 0); ax88179_auto_detach(dev);
/* Read MAC address from DTB or asix chip */ /* Read MAC address from DTB or asix chip */
ax88179_get_mac_addr(dev); ax88179_get_mac_addr(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment