~ubuntu-branches/ubuntu/precise/linux-linaro-u8500/precise

« back to all changes in this revision

Viewing changes to drivers/usb/core/hcd.c

  • Committer: Bazaar Package Importer
  • Author(s): John Rigby, Upstream Fixes, Andy Green, John Rigby
  • Date: 2011-04-14 12:16:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110414121606-b77podkyqgr2oix7
Tags: 2.6.38-1002.3
[ Upstream Fixes ]

* MUSB: shutdown: Make sure block is awake before doing shutdown
  - LP: #745737
* Fixed gpio polarity of gpio USB-phy reset.
  - LP: #747639

[ Andy Green ]

* LINARO: SAUCE: disable CONFIG_OMAP_RESET_CLOCKS
  - LP: #752900

[ John Rigby ]

* Rebase to new upstreams:
  Linux v2.6.38.1
  linaro-linux-2.6.38-upstream-29Mar2011
  Ubuntu-2.6.38-7.35
* SAUCE: OMAP4: clock: wait for module to become accessible on
  a clk enable
  - LP: #745737
* Rebase to new upstreams:
  Linux v2.6.38.2
  linaro-linux-2.6.38-upstream-5Apr2011
  Ubuntu-2.6.38-8.41
  - LP: #732842
* Update configs for device tree, dvfs and lttng
* LINARO: add building of dtb's
* LINARO: SAUCE: Disable lowest operating freqs on omap34xx
  - LP: #732912

Show diffs side-by-side

added added

removed removed

Lines of Context:
297
297
        /* one configuration */
298
298
        0x09,       /*  __u8  bLength; */
299
299
        0x02,       /*  __u8  bDescriptorType; Configuration */
300
 
        0x19, 0x00, /*  __le16 wTotalLength; FIXME */
 
300
        0x1f, 0x00, /*  __le16 wTotalLength; */
301
301
        0x01,       /*  __u8  bNumInterfaces; (1) */
302
302
        0x01,       /*  __u8  bConfigurationValue; */
303
303
        0x00,       /*  __u8  iConfiguration; */
327
327
                    /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
328
328
                     * see hub.c:hub_configure() for details. */
329
329
        (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
330
 
        0x0c        /*  __u8  ep_bInterval; (256ms -- usb 2.0 spec) */
331
 
        /*
332
 
         * All 3.0 hubs should have an endpoint companion descriptor,
333
 
         * but we're ignoring that for now.  FIXME?
334
 
         */
 
330
        0x0c,       /*  __u8  ep_bInterval; (256ms -- usb 2.0 spec) */
 
331
 
 
332
        /* one SuperSpeed endpoint companion descriptor */
 
333
        0x06,        /* __u8 ss_bLength */
 
334
        0x30,        /* __u8 ss_bDescriptorType; SuperSpeed EP Companion */
 
335
        0x00,        /* __u8 ss_bMaxBurst; allows 1 TX between ACKs */
 
336
        0x00,        /* __u8 ss_bmAttributes; 1 packet per service interval */
 
337
        0x02, 0x00   /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */
335
338
};
336
339
 
337
340
/*-------------------------------------------------------------------------*/
504
507
        case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
505
508
                switch (wValue & 0xff00) {
506
509
                case USB_DT_DEVICE << 8:
507
 
                        switch (hcd->driver->flags & HCD_MASK) {
 
510
                        switch (hcd->speed) {
508
511
                        case HCD_USB3:
509
512
                                bufp = usb3_rh_dev_descriptor;
510
513
                                break;
522
525
                                patch_protocol = 1;
523
526
                        break;
524
527
                case USB_DT_CONFIG << 8:
525
 
                        switch (hcd->driver->flags & HCD_MASK) {
 
528
                        switch (hcd->speed) {
526
529
                        case HCD_USB3:
527
530
                                bufp = ss_rh_config_descriptor;
528
531
                                len = sizeof ss_rh_config_descriptor;
983
986
                spin_unlock_irq (&hcd_root_hub_lock);
984
987
 
985
988
                /* Did the HC die before the root hub was registered? */
986
 
                if (hcd->state == HC_STATE_HALT)
 
989
                if (HCD_DEAD(hcd) || hcd->state == HC_STATE_HALT)
987
990
                        usb_hc_died (hcd);      /* This time clean up */
988
991
        }
989
992
 
1089
1092
         * Check the host controller's state and add the URB to the
1090
1093
         * endpoint's queue.
1091
1094
         */
1092
 
        switch (hcd->state) {
1093
 
        case HC_STATE_RUNNING:
1094
 
        case HC_STATE_RESUMING:
 
1095
        if (HCD_RH_RUNNING(hcd)) {
1095
1096
                urb->unlinked = 0;
1096
1097
                list_add_tail(&urb->urb_list, &urb->ep->urb_list);
1097
 
                break;
1098
 
        default:
 
1098
        } else {
1099
1099
                rc = -ESHUTDOWN;
1100
1100
                goto done;
1101
1101
        }
1153
1153
                dev_warn(hcd->self.controller, "Unlink after no-IRQ?  "
1154
1154
                        "Controller is probably using the wrong IRQ.\n");
1155
1155
                set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
 
1156
                if (hcd->shared_hcd)
 
1157
                        set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
1156
1158
        }
1157
1159
 
1158
1160
        return 0;
1262
1264
        *dma_handle = 0;
1263
1265
}
1264
1266
 
1265
 
void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb)
 
1267
void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb)
1266
1268
{
1267
1269
        if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
1268
1270
                dma_unmap_single(hcd->self.controller,
1279
1281
        /* Make it safe to call this routine more than once */
1280
1282
        urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL);
1281
1283
}
1282
 
EXPORT_SYMBOL_GPL(unmap_urb_setup_for_dma);
1283
 
 
1284
 
void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
 
1284
EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma);
 
1285
 
 
1286
static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
 
1287
{
 
1288
        if (hcd->driver->unmap_urb_for_dma)
 
1289
                hcd->driver->unmap_urb_for_dma(hcd, urb);
 
1290
        else
 
1291
                usb_hcd_unmap_urb_for_dma(hcd, urb);
 
1292
}
 
1293
 
 
1294
void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1285
1295
{
1286
1296
        enum dma_data_direction dir;
1287
1297
 
1288
 
        unmap_urb_setup_for_dma(hcd, urb);
 
1298
        usb_hcd_unmap_urb_setup_for_dma(hcd, urb);
1289
1299
 
1290
1300
        dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1291
1301
        if (urb->transfer_flags & URB_DMA_MAP_SG)
1314
1324
        urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1315
1325
                        URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
1316
1326
}
1317
 
EXPORT_SYMBOL_GPL(unmap_urb_for_dma);
 
1327
EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma);
1318
1328
 
1319
1329
static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1320
1330
                           gfp_t mem_flags)
1321
1331
{
 
1332
        if (hcd->driver->map_urb_for_dma)
 
1333
                return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags);
 
1334
        else
 
1335
                return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
 
1336
}
 
1337
 
 
1338
int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 
1339
                            gfp_t mem_flags)
 
1340
{
1322
1341
        enum dma_data_direction dir;
1323
1342
        int ret = 0;
1324
1343
 
1410
1429
                }
1411
1430
                if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
1412
1431
                                URB_SETUP_MAP_LOCAL)))
1413
 
                        unmap_urb_for_dma(hcd, urb);
 
1432
                        usb_hcd_unmap_urb_for_dma(hcd, urb);
1414
1433
        }
1415
1434
        return ret;
1416
1435
}
 
1436
EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma);
1417
1437
 
1418
1438
/*-------------------------------------------------------------------------*/
1419
1439
 
1913
1933
{
1914
1934
        struct usb_hcd  *hcd = bus_to_hcd(udev->bus);
1915
1935
 
1916
 
        if (!HC_IS_RUNNING (hcd->state))
 
1936
        if (!HCD_RH_RUNNING(hcd))
1917
1937
                return -ESHUTDOWN;
1918
1938
        return hcd->driver->get_frame_number (hcd);
1919
1939
}
1930
1950
 
1931
1951
        dev_dbg(&rhdev->dev, "bus %s%s\n",
1932
1952
                        (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend");
 
1953
        if (HCD_DEAD(hcd)) {
 
1954
                dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend");
 
1955
                return 0;
 
1956
        }
 
1957
 
1933
1958
        if (!hcd->driver->bus_suspend) {
1934
1959
                status = -ENOENT;
1935
1960
        } else {
 
1961
                clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1936
1962
                hcd->state = HC_STATE_QUIESCING;
1937
1963
                status = hcd->driver->bus_suspend(hcd);
1938
1964
        }
1940
1966
                usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
1941
1967
                hcd->state = HC_STATE_SUSPENDED;
1942
1968
        } else {
1943
 
                hcd->state = old_state;
 
1969
                spin_lock_irq(&hcd_root_hub_lock);
 
1970
                if (!HCD_DEAD(hcd)) {
 
1971
                        set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
 
1972
                        hcd->state = old_state;
 
1973
                }
 
1974
                spin_unlock_irq(&hcd_root_hub_lock);
1944
1975
                dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
1945
1976
                                "suspend", status);
1946
1977
        }
1955
1986
 
1956
1987
        dev_dbg(&rhdev->dev, "usb %s%s\n",
1957
1988
                        (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume");
 
1989
        if (HCD_DEAD(hcd)) {
 
1990
                dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume");
 
1991
                return 0;
 
1992
        }
1958
1993
        if (!hcd->driver->bus_resume)
1959
1994
                return -ENOENT;
1960
 
        if (hcd->state == HC_STATE_RUNNING)
 
1995
        if (HCD_RH_RUNNING(hcd))
1961
1996
                return 0;
1962
1997
 
1963
1998
        hcd->state = HC_STATE_RESUMING;
1966
2001
        if (status == 0) {
1967
2002
                /* TRSMRCY = 10 msec */
1968
2003
                msleep(10);
1969
 
                usb_set_device_state(rhdev, rhdev->actconfig
1970
 
                                ? USB_STATE_CONFIGURED
1971
 
                                : USB_STATE_ADDRESS);
1972
 
                hcd->state = HC_STATE_RUNNING;
 
2004
                spin_lock_irq(&hcd_root_hub_lock);
 
2005
                if (!HCD_DEAD(hcd)) {
 
2006
                        usb_set_device_state(rhdev, rhdev->actconfig
 
2007
                                        ? USB_STATE_CONFIGURED
 
2008
                                        : USB_STATE_ADDRESS);
 
2009
                        set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
 
2010
                        hcd->state = HC_STATE_RUNNING;
 
2011
                }
 
2012
                spin_unlock_irq(&hcd_root_hub_lock);
1973
2013
        } else {
1974
2014
                hcd->state = old_state;
1975
2015
                dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
2080
2120
         */
2081
2121
        local_irq_save(flags);
2082
2122
 
2083
 
        if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) {
 
2123
        if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) {
2084
2124
                rc = IRQ_NONE;
2085
2125
        } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
2086
2126
                rc = IRQ_NONE;
2087
2127
        } else {
2088
2128
                set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
 
2129
                if (hcd->shared_hcd)
 
2130
                        set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags);
2089
2131
 
2090
2132
                if (unlikely(hcd->state == HC_STATE_HALT))
2091
2133
                        usb_hc_died(hcd);
2105
2147
 *
2106
2148
 * This is called by bus glue to report a USB host controller that died
2107
2149
 * while operations may still have been pending.  It's called automatically
2108
 
 * by the PCI glue, so only glue for non-PCI busses should need to call it. 
 
2150
 * by the PCI glue, so only glue for non-PCI busses should need to call it.
 
2151
 *
 
2152
 * Only call this function with the primary HCD.
2109
2153
 */
2110
2154
void usb_hc_died (struct usb_hcd *hcd)
2111
2155
{
2114
2158
        dev_err (hcd->self.controller, "HC died; cleaning up\n");
2115
2159
 
2116
2160
        spin_lock_irqsave (&hcd_root_hub_lock, flags);
 
2161
        clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
 
2162
        set_bit(HCD_FLAG_DEAD, &hcd->flags);
2117
2163
        if (hcd->rh_registered) {
2118
2164
                clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2119
2165
 
2122
2168
                                USB_STATE_NOTATTACHED);
2123
2169
                usb_kick_khubd (hcd->self.root_hub);
2124
2170
        }
 
2171
        if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) {
 
2172
                hcd = hcd->shared_hcd;
 
2173
                if (hcd->rh_registered) {
 
2174
                        clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
 
2175
 
 
2176
                        /* make khubd clean up old urbs and devices */
 
2177
                        usb_set_device_state(hcd->self.root_hub,
 
2178
                                        USB_STATE_NOTATTACHED);
 
2179
                        usb_kick_khubd(hcd->self.root_hub);
 
2180
                }
 
2181
        }
2125
2182
        spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
 
2183
        /* Make sure that the other roothub is also deallocated. */
2126
2184
}
2127
2185
EXPORT_SYMBOL_GPL (usb_hc_died);
2128
2186
 
2129
2187
/*-------------------------------------------------------------------------*/
2130
2188
 
2131
2189
/**
2132
 
 * usb_create_hcd - create and initialize an HCD structure
 
2190
 * usb_create_shared_hcd - create and initialize an HCD structure
2133
2191
 * @driver: HC driver that will use this hcd
2134
2192
 * @dev: device for this HC, stored in hcd->self.controller
2135
2193
 * @bus_name: value to store in hcd->self.bus_name
 
2194
 * @primary_hcd: a pointer to the usb_hcd structure that is sharing the
 
2195
 *              PCI device.  Only allocate certain resources for the primary HCD
2136
2196
 * Context: !in_interrupt()
2137
2197
 *
2138
2198
 * Allocate a struct usb_hcd, with extra space at the end for the
2141
2201
 *
2142
2202
 * If memory is unavailable, returns NULL.
2143
2203
 */
2144
 
struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
2145
 
                struct device *dev, const char *bus_name)
 
2204
struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
 
2205
                struct device *dev, const char *bus_name,
 
2206
                struct usb_hcd *primary_hcd)
2146
2207
{
2147
2208
        struct usb_hcd *hcd;
2148
2209
 
2151
2212
                dev_dbg (dev, "hcd alloc failed\n");
2152
2213
                return NULL;
2153
2214
        }
2154
 
        dev_set_drvdata(dev, hcd);
 
2215
        if (primary_hcd == NULL) {
 
2216
                hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex),
 
2217
                                GFP_KERNEL);
 
2218
                if (!hcd->bandwidth_mutex) {
 
2219
                        kfree(hcd);
 
2220
                        dev_dbg(dev, "hcd bandwidth mutex alloc failed\n");
 
2221
                        return NULL;
 
2222
                }
 
2223
                mutex_init(hcd->bandwidth_mutex);
 
2224
                dev_set_drvdata(dev, hcd);
 
2225
        } else {
 
2226
                hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex;
 
2227
                hcd->primary_hcd = primary_hcd;
 
2228
                primary_hcd->primary_hcd = primary_hcd;
 
2229
                hcd->shared_hcd = primary_hcd;
 
2230
                primary_hcd->shared_hcd = hcd;
 
2231
        }
 
2232
 
2155
2233
        kref_init(&hcd->kref);
2156
2234
 
2157
2235
        usb_bus_init(&hcd->self);
2165
2243
#ifdef CONFIG_USB_SUSPEND
2166
2244
        INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2167
2245
#endif
2168
 
        mutex_init(&hcd->bandwidth_mutex);
2169
2246
 
2170
2247
        hcd->driver = driver;
 
2248
        hcd->speed = driver->flags & HCD_MASK;
2171
2249
        hcd->product_desc = (driver->product_desc) ? driver->product_desc :
2172
2250
                        "USB Host Controller";
2173
2251
        return hcd;
2174
2252
}
 
2253
EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
 
2254
 
 
2255
/**
 
2256
 * usb_create_hcd - create and initialize an HCD structure
 
2257
 * @driver: HC driver that will use this hcd
 
2258
 * @dev: device for this HC, stored in hcd->self.controller
 
2259
 * @bus_name: value to store in hcd->self.bus_name
 
2260
 * Context: !in_interrupt()
 
2261
 *
 
2262
 * Allocate a struct usb_hcd, with extra space at the end for the
 
2263
 * HC driver's private data.  Initialize the generic members of the
 
2264
 * hcd structure.
 
2265
 *
 
2266
 * If memory is unavailable, returns NULL.
 
2267
 */
 
2268
struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
 
2269
                struct device *dev, const char *bus_name)
 
2270
{
 
2271
        return usb_create_shared_hcd(driver, dev, bus_name, NULL);
 
2272
}
2175
2273
EXPORT_SYMBOL_GPL(usb_create_hcd);
2176
2274
 
 
2275
/*
 
2276
 * Roothubs that share one PCI device must also share the bandwidth mutex.
 
2277
 * Don't deallocate the bandwidth_mutex until the last shared usb_hcd is
 
2278
 * deallocated.
 
2279
 *
 
2280
 * Make sure to only deallocate the bandwidth_mutex when the primary HCD is
 
2281
 * freed.  When hcd_release() is called for the non-primary HCD, set the
 
2282
 * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be
 
2283
 * freed shortly).
 
2284
 */
2177
2285
static void hcd_release (struct kref *kref)
2178
2286
{
2179
2287
        struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);
2180
2288
 
 
2289
        if (usb_hcd_is_primary_hcd(hcd))
 
2290
                kfree(hcd->bandwidth_mutex);
 
2291
        else
 
2292
                hcd->shared_hcd->shared_hcd = NULL;
2181
2293
        kfree(hcd);
2182
2294
}
2183
2295
 
2196
2308
}
2197
2309
EXPORT_SYMBOL_GPL(usb_put_hcd);
2198
2310
 
 
2311
int usb_hcd_is_primary_hcd(struct usb_hcd *hcd)
 
2312
{
 
2313
        if (!hcd->primary_hcd)
 
2314
                return 1;
 
2315
        return hcd == hcd->primary_hcd;
 
2316
}
 
2317
EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd);
 
2318
 
 
2319
static int usb_hcd_request_irqs(struct usb_hcd *hcd,
 
2320
                unsigned int irqnum, unsigned long irqflags)
 
2321
{
 
2322
        int retval;
 
2323
 
 
2324
        if (hcd->driver->irq) {
 
2325
 
 
2326
                /* IRQF_DISABLED doesn't work as advertised when used together
 
2327
                 * with IRQF_SHARED. As usb_hcd_irq() will always disable
 
2328
                 * interrupts we can remove it here.
 
2329
                 */
 
2330
                if (irqflags & IRQF_SHARED)
 
2331
                        irqflags &= ~IRQF_DISABLED;
 
2332
 
 
2333
                snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
 
2334
                                hcd->driver->description, hcd->self.busnum);
 
2335
                retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
 
2336
                                hcd->irq_descr, hcd);
 
2337
                if (retval != 0) {
 
2338
                        dev_err(hcd->self.controller,
 
2339
                                        "request interrupt %d failed\n",
 
2340
                                        irqnum);
 
2341
                        return retval;
 
2342
                }
 
2343
                hcd->irq = irqnum;
 
2344
                dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
 
2345
                                (hcd->driver->flags & HCD_MEMORY) ?
 
2346
                                        "io mem" : "io base",
 
2347
                                        (unsigned long long)hcd->rsrc_start);
 
2348
        } else {
 
2349
                hcd->irq = -1;
 
2350
                if (hcd->rsrc_start)
 
2351
                        dev_info(hcd->self.controller, "%s 0x%08llx\n",
 
2352
                                        (hcd->driver->flags & HCD_MEMORY) ?
 
2353
                                        "io mem" : "io base",
 
2354
                                        (unsigned long long)hcd->rsrc_start);
 
2355
        }
 
2356
        return 0;
 
2357
}
 
2358
 
2199
2359
/**
2200
2360
 * usb_add_hcd - finish generic HCD structure initialization and register
2201
2361
 * @hcd: the usb_hcd structure to initialize
2236
2396
        }
2237
2397
        hcd->self.root_hub = rhdev;
2238
2398
 
2239
 
        switch (hcd->driver->flags & HCD_MASK) {
 
2399
        switch (hcd->speed) {
2240
2400
        case HCD_USB11:
2241
2401
                rhdev->speed = USB_SPEED_FULL;
2242
2402
                break;
2256
2416
         */
2257
2417
        device_init_wakeup(&rhdev->dev, 1);
2258
2418
 
 
2419
        /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is
 
2420
         * registered.  But since the controller can die at any time,
 
2421
         * let's initialize the flag before touching the hardware.
 
2422
         */
 
2423
        set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
 
2424
 
2259
2425
        /* "reset" is misnamed; its role is now one-time init. the controller
2260
2426
         * should already have been reset (and boot firmware kicked off etc).
2261
2427
         */
2271
2437
                dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
2272
2438
 
2273
2439
        /* enable irqs just before we start the controller */
2274
 
        if (hcd->driver->irq) {
2275
 
 
2276
 
                /* IRQF_DISABLED doesn't work as advertised when used together
2277
 
                 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2278
 
                 * interrupts we can remove it here.
2279
 
                 */
2280
 
                if (irqflags & IRQF_SHARED)
2281
 
                        irqflags &= ~IRQF_DISABLED;
2282
 
 
2283
 
                snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2284
 
                                hcd->driver->description, hcd->self.busnum);
2285
 
                if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
2286
 
                                hcd->irq_descr, hcd)) != 0) {
2287
 
                        dev_err(hcd->self.controller,
2288
 
                                        "request interrupt %d failed\n", irqnum);
 
2440
        if (usb_hcd_is_primary_hcd(hcd)) {
 
2441
                retval = usb_hcd_request_irqs(hcd, irqnum, irqflags);
 
2442
                if (retval)
2289
2443
                        goto err_request_irq;
2290
 
                }
2291
 
                hcd->irq = irqnum;
2292
 
                dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
2293
 
                                (hcd->driver->flags & HCD_MEMORY) ?
2294
 
                                        "io mem" : "io base",
2295
 
                                        (unsigned long long)hcd->rsrc_start);
2296
 
        } else {
2297
 
                hcd->irq = -1;
2298
 
                if (hcd->rsrc_start)
2299
 
                        dev_info(hcd->self.controller, "%s 0x%08llx\n",
2300
 
                                        (hcd->driver->flags & HCD_MEMORY) ?
2301
 
                                        "io mem" : "io base",
2302
 
                                        (unsigned long long)hcd->rsrc_start);
2303
2444
        }
2304
2445
 
2305
 
        if ((retval = hcd->driver->start(hcd)) < 0) {
 
2446
        hcd->state = HC_STATE_RUNNING;
 
2447
        retval = hcd->driver->start(hcd);
 
2448
        if (retval < 0) {
2306
2449
                dev_err(hcd->self.controller, "startup error %d\n", retval);
2307
2450
                goto err_hcd_driver_start;
2308
2451
        }
2323
2466
        return retval;
2324
2467
 
2325
2468
error_create_attr_group:
 
2469
        clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2326
2470
        if (HC_IS_RUNNING(hcd->state))
2327
2471
                hcd->state = HC_STATE_QUIESCING;
2328
2472
        spin_lock_irq(&hcd_root_hub_lock);
2344
2488
        clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2345
2489
        del_timer_sync(&hcd->rh_timer);
2346
2490
err_hcd_driver_start:
2347
 
        if (hcd->irq >= 0)
 
2491
        if (usb_hcd_is_primary_hcd(hcd) && hcd->irq >= 0)
2348
2492
                free_irq(irqnum, hcd);
2349
2493
err_request_irq:
2350
2494
err_hcd_driver_setup:
2375
2519
        usb_get_dev(rhdev);
2376
2520
        sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
2377
2521
 
 
2522
        clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2378
2523
        if (HC_IS_RUNNING (hcd->state))
2379
2524
                hcd->state = HC_STATE_QUIESCING;
2380
2525
 
2407
2552
        clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2408
2553
        del_timer_sync(&hcd->rh_timer);
2409
2554
 
2410
 
        if (hcd->irq >= 0)
2411
 
                free_irq(hcd->irq, hcd);
 
2555
        if (usb_hcd_is_primary_hcd(hcd)) {
 
2556
                if (hcd->irq >= 0)
 
2557
                        free_irq(hcd->irq, hcd);
 
2558
        }
2412
2559
 
2413
2560
        usb_put_dev(hcd->self.root_hub);
2414
2561
        usb_deregister_bus(&hcd->self);