Skip to content

Commit

Permalink
USB: straighten out port feature vs. port status usage
Browse files Browse the repository at this point in the history
This patch (as1349b) clears up the confusion in many USB host
controller drivers between port features and port statuses.  In mosty
cases it's true that the status bit is in the position given by the
corresponding feature value, but that's not always true and it's not
guaranteed in the USB spec.

There's no functional change, just replacing expressions of the form
(1 << USB_PORT_FEAT_x) with USB_PORT_STAT_x, which has the same value.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Alan Stern authored and Greg Kroah-Hartman committed May 20, 2010
1 parent 288ead4 commit 749da5f
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 90 deletions.
2 changes: 1 addition & 1 deletion drivers/usb/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,

/* maybe switch power back on (e.g. root hub was reset) */
if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2
&& !(portstatus & (1 << USB_PORT_FEAT_POWER)))
&& !(portstatus & USB_PORT_STAT_POWER))
set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);

if (portstatus & USB_PORT_STAT_ENABLE)
Expand Down
24 changes: 12 additions & 12 deletions drivers/usb/host/ehci-hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static int ehci_hub_control (
* Even if OWNER is set, so the port is owned by the
* companion controller, khubd needs to be able to clear
* the port-change status bits (especially
* USB_PORT_FEAT_C_CONNECTION).
* USB_PORT_STAT_C_CONNECTION).
*/

switch (wValue) {
Expand Down Expand Up @@ -729,12 +729,12 @@ static int ehci_hub_control (

// wPortChange bits
if (temp & PORT_CSC)
status |= 1 << USB_PORT_FEAT_C_CONNECTION;
status |= USB_PORT_STAT_C_CONNECTION << 16;
if (temp & PORT_PEC)
status |= 1 << USB_PORT_FEAT_C_ENABLE;
status |= USB_PORT_STAT_C_ENABLE << 16;

if ((temp & PORT_OCC) && !ignore_oc){
status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT;
status |= USB_PORT_STAT_C_OVERCURRENT << 16;

/*
* Hubs should disable port power on over-current.
Expand Down Expand Up @@ -791,7 +791,7 @@ static int ehci_hub_control (
if ((temp & PORT_RESET)
&& time_after_eq(jiffies,
ehci->reset_done[wIndex])) {
status |= 1 << USB_PORT_FEAT_C_RESET;
status |= USB_PORT_STAT_C_RESET << 16;
ehci->reset_done [wIndex] = 0;

/* force reset to complete */
Expand Down Expand Up @@ -833,7 +833,7 @@ static int ehci_hub_control (
*/

if (temp & PORT_CONNECT) {
status |= 1 << USB_PORT_FEAT_CONNECTION;
status |= USB_PORT_STAT_CONNECTION;
// status may be from integrated TT
if (ehci->has_hostpc) {
temp1 = ehci_readl(ehci, hostpc_reg);
Expand All @@ -842,11 +842,11 @@ static int ehci_hub_control (
status |= ehci_port_speed(ehci, temp);
}
if (temp & PORT_PE)
status |= 1 << USB_PORT_FEAT_ENABLE;
status |= USB_PORT_STAT_ENABLE;

/* maybe the port was unsuspended without our knowledge */
if (temp & (PORT_SUSPEND|PORT_RESUME)) {
status |= 1 << USB_PORT_FEAT_SUSPEND;
status |= USB_PORT_STAT_SUSPEND;
} else if (test_bit(wIndex, &ehci->suspended_ports)) {
clear_bit(wIndex, &ehci->suspended_ports);
ehci->reset_done[wIndex] = 0;
Expand All @@ -855,13 +855,13 @@ static int ehci_hub_control (
}

if (temp & PORT_OC)
status |= 1 << USB_PORT_FEAT_OVER_CURRENT;
status |= USB_PORT_STAT_OVERCURRENT;
if (temp & PORT_RESET)
status |= 1 << USB_PORT_FEAT_RESET;
status |= USB_PORT_STAT_RESET;
if (temp & PORT_POWER)
status |= 1 << USB_PORT_FEAT_POWER;
status |= USB_PORT_STAT_POWER;
if (test_bit(wIndex, &ehci->port_c_suspend))
status |= 1 << USB_PORT_FEAT_C_SUSPEND;
status |= USB_PORT_STAT_C_SUSPEND << 16;

#ifndef VERBOSE_DEBUG
if (status & ~0xffff) /* only if wPortChange is interesting */
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/host/isp1362-hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ static int isp1362_urb_enqueue(struct usb_hcd *hcd,

/* don't submit to a dead or disabled port */
if (!((isp1362_hcd->rhport[0] | isp1362_hcd->rhport[1]) &
(1 << USB_PORT_FEAT_ENABLE)) ||
USB_PORT_STAT_ENABLE) ||
!HC_IS_RUNNING(hcd->state)) {
kfree(ep);
retval = -ENODEV;
Expand Down
18 changes: 9 additions & 9 deletions drivers/usb/host/isp1760-hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
* Even if OWNER is set, so the port is owned by the
* companion controller, khubd needs to be able to clear
* the port-change status bits (especially
* USB_PORT_FEAT_C_CONNECTION).
* USB_PORT_STAT_C_CONNECTION).
*/

switch (wValue) {
Expand Down Expand Up @@ -1987,7 +1987,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,

/* wPortChange bits */
if (temp & PORT_CSC)
status |= 1 << USB_PORT_FEAT_C_CONNECTION;
status |= USB_PORT_STAT_C_CONNECTION << 16;


/* whoever resumes must GetPortStatus to complete it!! */
Expand All @@ -2007,7 +2007,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
/* resume completed? */
else if (time_after_eq(jiffies,
priv->reset_done)) {
status |= 1 << USB_PORT_FEAT_C_SUSPEND;
status |= USB_PORT_STAT_C_SUSPEND << 16;
priv->reset_done = 0;

/* stop resume signaling */
Expand All @@ -2031,7 +2031,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
if ((temp & PORT_RESET)
&& time_after_eq(jiffies,
priv->reset_done)) {
status |= 1 << USB_PORT_FEAT_C_RESET;
status |= USB_PORT_STAT_C_RESET << 16;
priv->reset_done = 0;

/* force reset to complete */
Expand Down Expand Up @@ -2062,18 +2062,18 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
printk(KERN_ERR "Warning: PORT_OWNER is set\n");

if (temp & PORT_CONNECT) {
status |= 1 << USB_PORT_FEAT_CONNECTION;
status |= USB_PORT_STAT_CONNECTION;
/* status may be from integrated TT */
status |= ehci_port_speed(priv, temp);
}
if (temp & PORT_PE)
status |= 1 << USB_PORT_FEAT_ENABLE;
status |= USB_PORT_STAT_ENABLE;
if (temp & (PORT_SUSPEND|PORT_RESUME))
status |= 1 << USB_PORT_FEAT_SUSPEND;
status |= USB_PORT_STAT_SUSPEND;
if (temp & PORT_RESET)
status |= 1 << USB_PORT_FEAT_RESET;
status |= USB_PORT_STAT_RESET;
if (temp & PORT_POWER)
status |= 1 << USB_PORT_FEAT_POWER;
status |= USB_PORT_STAT_POWER;

put_unaligned(cpu_to_le32(status), (__le32 *) buf);
break;
Expand Down
24 changes: 12 additions & 12 deletions drivers/usb/host/oxu210hp-hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
* Even if OWNER is set, so the port is owned by the
* companion controller, khubd needs to be able to clear
* the port-change status bits (especially
* USB_PORT_FEAT_C_CONNECTION).
* USB_PORT_STAT_C_CONNECTION).
*/

switch (wValue) {
Expand Down Expand Up @@ -3263,11 +3263,11 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,

/* wPortChange bits */
if (temp & PORT_CSC)
status |= 1 << USB_PORT_FEAT_C_CONNECTION;
status |= USB_PORT_STAT_C_CONNECTION << 16;
if (temp & PORT_PEC)
status |= 1 << USB_PORT_FEAT_C_ENABLE;
status |= USB_PORT_STAT_C_ENABLE << 16;
if ((temp & PORT_OCC) && !ignore_oc)
status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT;
status |= USB_PORT_STAT_C_OVERCURRENT << 16;

/* whoever resumes must GetPortStatus to complete it!! */
if (temp & PORT_RESUME) {
Expand All @@ -3285,7 +3285,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
/* resume completed? */
else if (time_after_eq(jiffies,
oxu->reset_done[wIndex])) {
status |= 1 << USB_PORT_FEAT_C_SUSPEND;
status |= USB_PORT_STAT_C_SUSPEND << 16;
oxu->reset_done[wIndex] = 0;

/* stop resume signaling */
Expand All @@ -3308,7 +3308,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
if ((temp & PORT_RESET)
&& time_after_eq(jiffies,
oxu->reset_done[wIndex])) {
status |= 1 << USB_PORT_FEAT_C_RESET;
status |= USB_PORT_STAT_C_RESET << 16;
oxu->reset_done[wIndex] = 0;

/* force reset to complete */
Expand Down Expand Up @@ -3347,20 +3347,20 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
*/

if (temp & PORT_CONNECT) {
status |= 1 << USB_PORT_FEAT_CONNECTION;
status |= USB_PORT_STAT_CONNECTION;
/* status may be from integrated TT */
status |= oxu_port_speed(oxu, temp);
}
if (temp & PORT_PE)
status |= 1 << USB_PORT_FEAT_ENABLE;
status |= USB_PORT_STAT_ENABLE;
if (temp & (PORT_SUSPEND|PORT_RESUME))
status |= 1 << USB_PORT_FEAT_SUSPEND;
status |= USB_PORT_STAT_SUSPEND;
if (temp & PORT_OC)
status |= 1 << USB_PORT_FEAT_OVER_CURRENT;
status |= USB_PORT_STAT_OVERCURRENT;
if (temp & PORT_RESET)
status |= 1 << USB_PORT_FEAT_RESET;
status |= USB_PORT_STAT_RESET;
if (temp & PORT_POWER)
status |= 1 << USB_PORT_FEAT_POWER;
status |= USB_PORT_STAT_POWER;

#ifndef OXU_VERBOSE_DEBUG
if (status & ~0xffff) /* only if wPortChange is interesting */
Expand Down
30 changes: 15 additions & 15 deletions drivers/usb/host/r8a66597-hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,10 @@ static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port,
rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
rh->scount = R8A66597_MAX_SAMPLING;
if (connect)
rh->port |= 1 << USB_PORT_FEAT_CONNECTION;
rh->port |= USB_PORT_STAT_CONNECTION;
else
rh->port &= ~(1 << USB_PORT_FEAT_CONNECTION);
rh->port |= 1 << USB_PORT_FEAT_C_CONNECTION;
rh->port &= ~USB_PORT_STAT_CONNECTION;
rh->port |= USB_PORT_STAT_C_CONNECTION << 16;

r8a66597_root_hub_start_polling(r8a66597);
}
Expand Down Expand Up @@ -1065,8 +1065,8 @@ static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port)
else if (speed == LSMODE)
rh->port |= USB_PORT_STAT_LOW_SPEED;

rh->port &= ~(1 << USB_PORT_FEAT_RESET);
rh->port |= 1 << USB_PORT_FEAT_ENABLE;
rh->port &= USB_PORT_STAT_RESET;
rh->port |= USB_PORT_STAT_ENABLE;
}

/* this function must be called with interrupt disabled */
Expand Down Expand Up @@ -1705,7 +1705,7 @@ static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
u16 tmp;
struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];

if (rh->port & (1 << USB_PORT_FEAT_RESET)) {
if (rh->port & USB_PORT_STAT_RESET) {
unsigned long dvstctr_reg = get_dvstctr_reg(port);

tmp = r8a66597_read(r8a66597, dvstctr_reg);
Expand All @@ -1717,7 +1717,7 @@ static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
r8a66597_usb_connect(r8a66597, port);
}

if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) {
if (!(rh->port & USB_PORT_STAT_CONNECTION)) {
r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
}
Expand Down Expand Up @@ -2185,7 +2185,7 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,

switch (wValue) {
case USB_PORT_FEAT_ENABLE:
rh->port &= ~(1 << USB_PORT_FEAT_POWER);
rh->port &= ~USB_PORT_STAT_POWER;
break;
case USB_PORT_FEAT_SUSPEND:
break;
Expand Down Expand Up @@ -2226,12 +2226,12 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
break;
case USB_PORT_FEAT_POWER:
r8a66597_port_power(r8a66597, port, 1);
rh->port |= (1 << USB_PORT_FEAT_POWER);
rh->port |= USB_PORT_STAT_POWER;
break;
case USB_PORT_FEAT_RESET: {
struct r8a66597_device *dev = rh->dev;

rh->port |= (1 << USB_PORT_FEAT_RESET);
rh->port |= USB_PORT_STAT_RESET;

disable_r8a66597_pipe_all(r8a66597, dev);
free_usb_address(r8a66597, dev, 1);
Expand Down Expand Up @@ -2269,12 +2269,12 @@ static int r8a66597_bus_suspend(struct usb_hcd *hcd)
struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
unsigned long dvstctr_reg = get_dvstctr_reg(port);

if (!(rh->port & (1 << USB_PORT_FEAT_ENABLE)))
if (!(rh->port & USB_PORT_STAT_ENABLE))
continue;

dbg("suspend port = %d", port);
r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */
rh->port |= 1 << USB_PORT_FEAT_SUSPEND;
rh->port |= USB_PORT_STAT_SUSPEND;

if (rh->dev->udev->do_remote_wakeup) {
msleep(3); /* waiting last SOF */
Expand All @@ -2300,12 +2300,12 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd)
struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
unsigned long dvstctr_reg = get_dvstctr_reg(port);

if (!(rh->port & (1 << USB_PORT_FEAT_SUSPEND)))
if (!(rh->port & USB_PORT_STAT_SUSPEND))
continue;

dbg("resume port = %d", port);
rh->port &= ~(1 << USB_PORT_FEAT_SUSPEND);
rh->port |= 1 << USB_PORT_FEAT_C_SUSPEND;
rh->port &= ~USB_PORT_STAT_SUSPEND;
rh->port |= USB_PORT_STAT_C_SUSPEND < 16;
r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg);
msleep(50);
r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg);
Expand Down
Loading

0 comments on commit 749da5f

Please sign in to comment.