1 //#include "mtk-usb-hcd.h"
2 //#include <linux/usb.h>
3 //#include <linux/usb/hcd.h>
4 #include <linux/slab.h>
5 #include <linux/dma-mapping.h>
6 #include <asm/unaligned.h>
11 /* Device for a quirk */
12 #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
13 #define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
16 /* FIXME tune these based on pool statistics ... */
17 static const size_t pool_max
[HCD_BUFFER_POOLS
] = {
18 /* platforms without dma-friendly caches might need to
19 * prevent cacheline sharing...
25 /* bigger --> allocate pages */
30 * hcd_buffer_create - initialize buffer pools
31 * @hcd: the bus whose buffer pools are to be initialized
32 * Context: !in_interrupt()
34 * Call this as part of initializing a host controller that uses the dma
35 * memory allocators. It initializes some pools of dma-coherent memory that
36 * will be shared by all drivers using that controller, or returns a negative
37 * errno value on error.
39 * Call hcd_buffer_destroy() to clean up after using those pools.
41 int hcd_buffer_create(struct usb_hcd
*hcd
)
46 if (!hcd
->self
.controller
->dma_mask
&&
47 !(hcd
->driver
->flags
& HCD_LOCAL_MEM
))
50 for (i
= 0; i
< HCD_BUFFER_POOLS
; i
++) {
54 snprintf(name
, sizeof name
, "buffer-%d", size
);
55 hcd
->pool
[i
] = dma_pool_create(name
, hcd
->self
.controller
,
58 hcd_buffer_destroy(hcd
);
67 * hcd_buffer_destroy - deallocate buffer pools
68 * @hcd: the bus whose buffer pools are to be destroyed
69 * Context: !in_interrupt()
71 * This frees the buffer pools created by hcd_buffer_create().
73 void hcd_buffer_destroy(struct usb_hcd
*hcd
)
77 for (i
= 0; i
< HCD_BUFFER_POOLS
; i
++) {
78 struct dma_pool
*pool
= hcd
->pool
[i
];
80 dma_pool_destroy(pool
);
88 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
89 * @irq: the IRQ being raised
90 * @__hcd: pointer to the HCD whose IRQ is being signaled
92 * If the controller isn't HALTed, calls the driver's irq handler.
93 * Checks whether the controller is now dead.
95 irqreturn_t
usb_hcd_irq (int irq
, void *__hcd
)
97 struct usb_hcd
*hcd
= __hcd
;
101 /* IRQF_DISABLED doesn't work correctly with shared IRQs
102 * when the first handler doesn't use it. So let's just
103 * assume it's never used.
105 local_irq_save(flags
);
106 if (unlikely(hcd
->state
== HC_STATE_HALT
||
107 !test_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
))) {
109 } else if (hcd
->driver
->irq(hcd
) == IRQ_NONE
) {
112 set_bit(HCD_FLAG_SAW_IRQ
, &hcd
->flags
);
114 if (unlikely(hcd
->state
== HC_STATE_HALT
))
119 local_irq_restore(flags
);
124 /* Returns 1 if @usb_bus is WUSB, 0 otherwise */
125 static unsigned usb_bus_is_wusb(struct usb_bus
*bus
)
127 struct usb_hcd
*hcd
= container_of(bus
, struct usb_hcd
, self
);
128 return hcd
->wireless
;
132 struct usb_device
*mtk_usb_alloc_dev(struct usb_device
*parent
, struct usb_bus
*bus
, unsigned port1
){
133 struct usb_device
*dev
;
134 struct usb_hcd
*usb_hcd
= container_of(bus
, struct usb_hcd
, self
);
135 unsigned root_hub
= 0;
137 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
141 if (!usb_get_hcd(bus_to_hcd(bus
))) {
145 device_initialize(&dev
->dev
);
146 dev
->children
= kzalloc(31 * sizeof(struct usb_device
*), GFP_KERNEL
);
148 /* Save readable and stable topology id, distinguishing devices
149 * by location for diagnostics, tools, driver model, etc. The
150 * string is a path along hub ports, from the root. Each device's
151 * dev->devpath will be stable until USB is re-cabled, and hubs
152 * are often labeled with these port numbers. The name isn't
153 * as stable: bus->busnum changes easily from modprobe order,
154 * cardbus or pci hotplugging, and so on.
156 if (unlikely(!parent
)) {
157 dev
->devpath
[0] = '0';
160 dev
->dev
.parent
= bus
->controller
;
161 dev_set_name(&dev
->dev
, "usb%d", bus
->busnum
);
164 /* match any labeling on the hubs; it's one-based */
165 if (parent
->devpath
[0] == '0') {
166 snprintf(dev
->devpath
, sizeof dev
->devpath
, "%d", port1
);
167 /* Root ports are not counted in route string */
169 printk(KERN_DEBUG
"device attached on roothub\n");
171 snprintf(dev
->devpath
, sizeof dev
->devpath
, "%s.%d", parent
->devpath
, port1
);
172 /* Route string assumes hubs have less than 16 ports */
174 dev
->route
= parent
->route
+
175 (port1
<< ((parent
->level
- 1)*4));
177 dev
->route
= parent
->route
+
178 (15 << ((parent
->level
- 1)*4));
179 printk(KERN_DEBUG
"device route string %d\n", dev
->route
);
180 printk(KERN_DEBUG
"parent level %d\n", parent
->level
);
181 printk(KERN_DEBUG
"parent route string %d\n", parent
->route
);
184 dev
->dev
.parent
= &parent
->dev
;
185 dev_set_name(&dev
->dev
, "%d-%s", bus
->busnum
, dev
->devpath
);
187 /* hub driver sets up TT records */
189 dev
->portnum
= port1
;
191 dev
->parent
= parent
;
192 if (root_hub
) /* Root hub always ok [and always wired] */
195 dev
->authorized
= usb_hcd
->authorized_default
;
196 // dev->wusb = usb_bus_is_wusb(bus)? 1 : 0;
199 dev
->ep0
.desc
.bLength
= USB_DT_ENDPOINT_SIZE
;
200 dev
->ep0
.desc
.bDescriptorType
= USB_DT_ENDPOINT
;
201 dev
->ep0
.enabled
= 1;
202 dev
->ep_in
[0] = &dev
->ep0
;
203 dev
->ep_out
[0] = &dev
->ep0
;
205 /* ep0 maxpacket comes later, from device descriptor */
206 usb_enable_endpoint(dev
, &dev
->ep0
, false);
213 void *hcd_buffer_alloc(
220 struct usb_hcd
*hcd
= bus_to_hcd(bus
);
223 /* some USB hosts just use PIO */
224 if (!bus
->controller
->dma_mask
&&
225 !(hcd
->driver
->flags
& HCD_LOCAL_MEM
)) {
226 *dma
= ~(dma_addr_t
) 0;
227 return kmalloc(size
, mem_flags
);
230 for (i
= 0; i
< HCD_BUFFER_POOLS
; i
++) {
231 if (size
<= pool_max
[i
])
232 return dma_pool_alloc(hcd
->pool
[i
], mem_flags
, dma
);
234 return dma_alloc_coherent(hcd
->self
.controller
, size
, dma
, mem_flags
);
237 void hcd_buffer_free(
244 struct usb_hcd
*hcd
= bus_to_hcd(bus
);
250 if (!bus
->controller
->dma_mask
&&
251 !(hcd
->driver
->flags
& HCD_LOCAL_MEM
)) {
256 for (i
= 0; i
< HCD_BUFFER_POOLS
; i
++) {
257 if (size
<= pool_max
[i
]) {
258 dma_pool_free(hcd
->pool
[i
], addr
, dma
);
262 dma_free_coherent(hcd
->self
.controller
, size
, addr
, dma
);
267 * Some usb host controllers can only perform dma using a small SRAM area.
268 * The usb core itself is however optimized for host controllers that can dma
269 * using regular system memory - like pci devices doing bus mastering.
271 * To support host controllers with limited dma capabilites we provide dma
272 * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag.
273 * For this to work properly the host controller code must first use the
274 * function dma_declare_coherent_memory() to point out which memory area
275 * that should be used for dma allocations.
277 * The HCD_LOCAL_MEM flag then tells the usb code to allocate all data for
278 * dma using dma_alloc_coherent() which in turn allocates from the memory
279 * area pointed out with dma_declare_coherent_memory().
281 * So, to summarize...
283 * - We need "local" memory, canonical example being
284 * a small SRAM on a discrete controller being the
285 * only memory that the controller can read ...
286 * (a) "normal" kernel memory is no good, and
287 * (b) there's not enough to share
289 * - The only *portable* hook for such stuff in the
290 * DMA framework is dma_declare_coherent_memory()
292 * - So we use that, even though the primary requirement
293 * is that the memory be "local" (hence addressible
294 * by that device), not "coherent".
298 static int hcd_alloc_coherent(struct usb_bus
*bus
,
299 gfp_t mem_flags
, dma_addr_t
*dma_handle
,
300 void **vaddr_handle
, size_t size
,
301 enum dma_data_direction dir
)
303 unsigned char *vaddr
;
305 vaddr
= hcd_buffer_alloc(bus
, size
+ sizeof(vaddr
),
306 mem_flags
, dma_handle
);
311 * Store the virtual address of the buffer at the end
312 * of the allocated dma buffer. The size of the buffer
313 * may be uneven so use unaligned functions instead
314 * of just rounding up. It makes sense to optimize for
315 * memory footprint over access speed since the amount
316 * of memory available for dma may be limited.
318 put_unaligned((unsigned long)*vaddr_handle
,
319 (unsigned long *)(vaddr
+ size
));
321 if (dir
== DMA_TO_DEVICE
)
322 memcpy(vaddr
, *vaddr_handle
, size
);
324 *vaddr_handle
= vaddr
;
328 void hcd_free_coherent(struct usb_bus
*bus
, dma_addr_t
*dma_handle
,
329 void **vaddr_handle
, size_t size
,
330 enum dma_data_direction dir
)
332 unsigned char *vaddr
= *vaddr_handle
;
334 vaddr
= (void *)get_unaligned((unsigned long *)(vaddr
+ size
));
336 if (dir
== DMA_FROM_DEVICE
)
337 memcpy(vaddr
, *vaddr_handle
, size
);
339 hcd_buffer_free(bus
, size
+ sizeof(vaddr
), *vaddr_handle
, *dma_handle
);
341 *vaddr_handle
= vaddr
;
346 void unmap_urb_for_dma(struct usb_hcd
*hcd
, struct urb
*urb
)
348 enum dma_data_direction dir
;
350 dir
= usb_urb_dir_in(urb
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
;
351 hcd_free_coherent(urb
->dev
->bus
,
353 &urb
->transfer_buffer
,
354 urb
->transfer_buffer_length
,
360 int map_urb_for_dma(struct usb_hcd
*hcd
, struct urb
*urb
,
363 enum dma_data_direction dir
;
365 dir
= usb_urb_dir_in(urb
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
;
366 /* Map the URB's buffers for DMA access.
367 * Lower level HCD code should use *_dma exclusively,
368 * unless it uses pio or talks to another transport,
369 * or uses the provided scatter gather list for bulk.
371 ret
= hcd_alloc_coherent(
372 urb
->dev
->bus
, mem_flags
,
374 &urb
->transfer_buffer
,
375 urb
->transfer_buffer_length
,
379 urb
->transfer_flags
|= URB_MAP_LOCAL
;
383 void rh_port_clear_change(struct xhci_hcd
*xhci
, int port_id
){
389 addr
= &xhci
->op_regs
->port_status_base
+ NUM_PORT_REGS
*(port_id
& 0xff);
390 temp
= xhci_readl(xhci
, addr
);
391 xhci_dbg(xhci
, "to clear port change, actual port %d status = 0x%x\n", port_id
, temp
);
392 temp
= mtktest_xhci_port_state_to_clear_change(temp
);
393 xhci_writel(xhci
, temp
, addr
);
394 temp
= xhci_readl(xhci
, addr
);
395 xhci_dbg(xhci
, "clear port change, actual port %d status = 0x%x\n", port_id
, temp
);
398 int rh_get_port_status(struct xhci_hcd
*xhci
, int port_id
){
405 addr
= &xhci
->op_regs
->port_status_base
+ NUM_PORT_REGS
*(port_id
& 0xff);
406 temp
= xhci_readl(xhci
, addr
);
407 xhci_dbg(xhci
, "get port status, actual port %d status = 0x%x\n", port_id
, temp
);
409 /* wPortChange bits */
411 status
|= USB_PORT_STAT_C_CONNECTION
<< 16;
413 status
|= USB_PORT_STAT_C_ENABLE
<< 16;
414 if ((temp
& PORT_OCC
))
415 status
|= USB_PORT_STAT_C_OVERCURRENT
<< 16;
416 if ((temp
& PORT_RC
))
417 status
|= USB_PORT_STAT_C_RESET
<< 16;
418 if ((temp
& PORT_PLC
))
419 status
|= USB_PORT_STAT_C_SUSPEND
<< 16;
421 * FIXME ignoring suspend, reset, and USB 2.1/3.0 specific
424 if (temp
& PORT_CONNECT
) {
425 status
|= USB_PORT_STAT_CONNECTION
;
426 status
|= mtktest_xhci_port_speed(temp
);
429 status
|= USB_PORT_STAT_ENABLE
;
431 status
|= USB_PORT_STAT_OVERCURRENT
;
432 if (temp
& PORT_RESET
)
433 status
|= USB_PORT_STAT_RESET
;
434 if (temp
& PORT_POWER
)
435 status
|= USB_PORT_STAT_POWER
;
436 xhci_dbg(xhci
, "Get port status returned 0x%x\n", status
);
437 temp
= mtktest_xhci_port_state_to_neutral(temp
);
438 xhci_writel(xhci
, temp
, addr
);
439 temp
= xhci_readl(xhci
, addr
);
440 xhci_dbg(xhci
, "clear port change, actual port %d status = 0x%x\n", port_id
, temp
);
442 put_unaligned(cpu_to_le32(status
), (__le32
*) buf
);
448 int mtk_map_urb_for_dma(struct usb_hcd
*hcd
, struct urb
*urb
, gfp_t mem_flags
){
449 enum dma_data_direction dir
;
451 dir
= usb_urb_dir_in(urb
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
;
452 /* Map the URB's buffers for DMA access.
453 * Lower level HCD code should use *_dma exclusively,
454 * unless it uses pio or talks to another transport,
455 * or uses the provided scatter gather list for bulk.
457 ret
= hcd_alloc_coherent(
458 urb
->dev
->bus
, mem_flags
,
460 &urb
->transfer_buffer
,
461 urb
->transfer_buffer_length
,
465 urb
->transfer_flags
|= URB_MAP_LOCAL
;
468 void mtk_unmap_urb_for_dma(struct usb_hcd
*hcd
, struct urb
*urb
){
469 enum dma_data_direction dir
;
471 dir
= usb_urb_dir_in(urb
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
;
472 hcd_free_coherent(urb
->dev
->bus
,
474 &urb
->transfer_buffer
,
475 urb
->transfer_buffer_length
,
480 * usb_alloc_dev - usb device constructor (usbcore-internal)
481 * @parent: hub to which device is connected; null to allocate a root hub
482 * @bus: bus used to access the device
483 * @port1: one-based index of port; ignored for root hubs
484 * Context: !in_interrupt()
486 * Only hub drivers (including virtual root hub drivers for host
487 * controllers) should ever call this.
489 * This call may not be used in a non-sleeping context.
491 struct usb_device
*mtk_usb_alloc_rhdev(struct usb_device
*parent
,
492 struct usb_bus
*bus
, unsigned port1
)
494 struct usb_device
*dev
;
495 struct usb_hcd
*usb_hcd
= container_of(bus
, struct usb_hcd
, self
);
496 unsigned root_hub
= 0;
498 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
502 if (!usb_get_hcd(bus_to_hcd(bus
))) {
506 device_initialize(&dev
->dev
);
507 dev
->children
= kzalloc(31 * sizeof(struct usb_device
*), GFP_KERNEL
);
508 dev
->dev
.dma_mask
= bus
->controller
->dma_mask
;
509 atomic_set(&dev
->urbnum
, 0);
512 /* Save readable and stable topology id, distinguishing devices
513 * by location for diagnostics, tools, driver model, etc. The
514 * string is a path along hub ports, from the root. Each device's
515 * dev->devpath will be stable until USB is re-cabled, and hubs
516 * are often labeled with these port numbers. The name isn't
517 * as stable: bus->busnum changes easily from modprobe order,
518 * cardbus or pci hotplugging, and so on.
520 if (unlikely(!parent
)) {
521 dev
->devpath
[0] = '0';
523 dev
->dev
.parent
= bus
->controller
;
524 dev_set_name(&dev
->dev
, "usb%d", bus
->busnum
);
528 dev
->portnum
= port1
;
530 dev
->parent
= parent
;
538 * usb_add_hcd - finish generic HCD structure initialization and register
539 * @hcd: the usb_hcd structure to initialize
540 * @irqnum: Interrupt line to allocate
541 * @irqflags: Interrupt type flags
543 * Finish the remaining parts of generic HCD initialization: allocate the
544 * buffers of consistent memory, register the bus, request the IRQ line,
545 * and call the driver's reset() and start() routines.
547 int mtk_usb_add_hcd(struct usb_hcd
*hcd
,
548 unsigned int irqnum
, unsigned long irqflags
)
551 struct usb_device
*rhdev
;
552 dev_info(hcd
->self
.controller
, "%s\n", hcd
->product_desc
);
554 hcd
->authorized_default
= hcd
->wireless
? 0 : 1;
555 set_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
557 /* HC is in reset state, but accessible. Now do the one-time init,
558 * bottom up so that hcds can customize the root hubs before khubd
559 * starts talking to them. (Note, bus id is assigned early too.)
561 if ((retval
= hcd_buffer_create(hcd
)) != 0) {
562 dev_dbg(hcd
->self
.controller
, "pool alloc failed\n");
566 if ((rhdev
= mtk_usb_alloc_rhdev(NULL
, &hcd
->self
, 0)) == NULL
) {
567 dev_err(hcd
->self
.controller
, "unable to allocate root hub\n");
569 goto err_allocate_root_hub
;
571 hcd
->self
.root_hub
= rhdev
;
573 if ((retval
= usb_register_bus(&hcd
->self
)) < 0)
574 goto err_register_bus
;
576 if ((rhdev
= usb_alloc_dev(NULL
, &hcd
->self
, 0)) == NULL
) {
577 dev_err(hcd
->self
.controller
, "unable to allocate root hub\n");
579 goto err_allocate_root_hub
;
582 switch (hcd
->driver
->flags
& HCD_MASK
) {
584 rhdev
->speed
= USB_SPEED_FULL
;
587 rhdev
->speed
= USB_SPEED_HIGH
;
590 rhdev
->speed
= USB_SPEED_SUPER
;
593 goto err_allocate_root_hub
;
595 hcd
->self
.root_hub
= rhdev
;
597 /* wakeup flag init defaults to "everything works" for root hubs,
598 * but drivers can override it in reset() if needed, along with
599 * recording the overall controller's system wakeup capability.
601 device_init_wakeup(&rhdev
->dev
, 1);
604 /* "reset" is misnamed; its role is now one-time init. the controller
605 * should already have been reset (and boot firmware kicked off etc).
607 printk(KERN_DEBUG
"call xhci_mtk_setup\n");
608 if (hcd
->driver
->reset
&& (retval
= hcd
->driver
->reset(hcd
)) < 0) {
609 dev_err(hcd
->self
.controller
, "can't setup\n");
610 goto err_hcd_driver_setup
;
613 /* NOTE: root hub and controller capabilities may not be the same */
614 if (device_can_wakeup(hcd
->self
.controller
)
615 && device_can_wakeup(&hcd
->self
.root_hub
->dev
))
616 dev_dbg(hcd
->self
.controller
, "supports USB remote wakeup\n");
618 /* enable irqs just before we start the controller */
619 if (hcd
->driver
->irq
) {
621 /* IRQF_DISABLED doesn't work as advertised when used together
622 * with IRQF_SHARED. As usb_hcd_irq() will always disable
623 * interrupts we can remove it here.
625 if (irqflags
& IRQF_SHARED
)
626 irqflags
&= ~IRQF_DISABLED
;
628 snprintf(hcd
->irq_descr
, sizeof(hcd
->irq_descr
), "%s:usb%d",
629 hcd
->driver
->description
, hcd
->self
.busnum
);
630 if ((retval
= request_irq(irqnum
, &usb_hcd_irq
, irqflags
,
631 hcd
->irq_descr
, hcd
)) != 0) {
632 dev_err(hcd
->self
.controller
,
633 "request interrupt %d failed\n", irqnum
);
634 goto err_request_irq
;
637 dev_info(hcd
->self
.controller
, "irq %d, %s 0x%08llx\n", irqnum
,
638 (hcd
->driver
->flags
& HCD_MEMORY
) ?
639 "io mem" : "io base",
640 (unsigned long long)hcd
->rsrc_start
);
644 dev_info(hcd
->self
.controller
, "%s 0x%08llx\n",
645 (hcd
->driver
->flags
& HCD_MEMORY
) ?
646 "io mem" : "io base",
647 (unsigned long long)hcd
->rsrc_start
);
650 if ((retval
= hcd
->driver
->start(hcd
)) < 0) {
651 dev_err(hcd
->self
.controller
, "startup error %d\n", retval
);
652 goto err_hcd_driver_start
;
655 /* starting here, usbcore will pay attention to this root hub */
656 rhdev
->bus_mA
= min(500u, hcd
->power_budget
);
657 if ((retval
= register_root_hub(hcd
)) != 0)
658 goto err_register_root_hub
;
660 retval
= sysfs_create_group(&rhdev
->dev
.kobj
, &usb_bus_attr_group
);
662 printk(KERN_ERR
"Cannot register USB bus sysfs attributes: %d\n",
664 goto error_create_attr_group
;
666 if (hcd
->uses_new_polling
&& hcd
->poll_rh
)
667 usb_hcd_poll_rh_status(hcd
);
671 error_create_attr_group
:
672 mutex_lock(&usb_bus_list_lock
);
673 usb_disconnect(&hcd
->self
.root_hub
);
674 mutex_unlock(&usb_bus_list_lock
);
675 err_register_root_hub
:
676 hcd
->driver
->stop(hcd
);
677 err_hcd_driver_start
:
679 free_irq(irqnum
, hcd
);
681 err_hcd_driver_setup
:
682 hcd
->self
.root_hub
= NULL
;
685 err_allocate_root_hub
:
686 hcd
->driver
->stop(hcd
);
689 hcd_buffer_destroy(hcd
);
695 * usb_remove_hcd - shutdown processing for generic HCDs
696 * @hcd: the usb_hcd structure to remove
697 * Context: !in_interrupt()
699 * Disconnects the root hub, then reverses the effects of usb_add_hcd(),
700 * invoking the HCD's stop() method.
702 void mtk_usb_remove_hcd(struct usb_hcd
*hcd
)
704 dev_info(hcd
->self
.controller
, "remove, state %x\n", hcd
->state
);
706 if (HC_IS_RUNNING (hcd
->state
))
707 hcd
->state
= HC_STATE_QUIESCING
;
709 dev_dbg(hcd
->self
.controller
, "roothub graceful disconnect\n");
711 spin_lock_irq (&hcd_root_hub_lock
);
712 hcd
->rh_registered
= 0;
713 spin_unlock_irq (&hcd_root_hub_lock
);
715 #if 0 //#ifdef CONFIG_USB_SUSPEND
716 cancel_work_sync(&hcd
->wakeup_work
);
719 sysfs_remove_group(&hcd
->self
.root_hub
->dev
.kobj
, &usb_bus_attr_group
);
720 mutex_lock(&usb_bus_list_lock
);
721 usb_disconnect(&hcd
->self
.root_hub
);
722 mutex_unlock(&usb_bus_list_lock
);
724 hcd
->driver
->stop(hcd
);
725 hcd
->state
= HC_STATE_HALT
;
728 del_timer_sync(&hcd
->rh_timer
);
731 free_irq(hcd
->irq
, hcd
);
733 usb_deregister_bus(&hcd
->self
);
735 hcd_buffer_destroy(hcd
);
738 * usb_bus_init - shared initialization code
739 * @bus: the bus structure being initialized
741 * This code is used to initialize a usb_bus structure, memory for which is
742 * separately managed.
744 static void mtk_usb_bus_init (struct usb_bus
*bus
)
746 memset (&bus
->devmap
, 0, sizeof(struct usb_devmap
));
748 bus
->devnum_next
= 1;
750 bus
->root_hub
= NULL
;
752 bus
->bandwidth_allocated
= 0;
753 bus
->bandwidth_int_reqs
= 0;
754 bus
->bandwidth_isoc_reqs
= 0;
756 INIT_LIST_HEAD (&bus
->bus_list
);
759 /*-------------------------------------------------------------------------*/
762 * usb_create_hcd - create and initialize an HCD structure
763 * @driver: HC driver that will use this hcd
764 * @dev: device for this HC, stored in hcd->self.controller
765 * @bus_name: value to store in hcd->self.bus_name
766 * Context: !in_interrupt()
768 * Allocate a struct usb_hcd, with extra space at the end for the
769 * HC driver's private data. Initialize the generic members of the
772 * If memory is unavailable, returns NULL.
774 struct usb_hcd
*mtk_usb_create_hcd (const struct hc_driver
*driver
,
775 struct device
*dev
, const char *bus_name
)
779 hcd
= kzalloc(sizeof(*hcd
) + driver
->hcd_priv_size
, GFP_KERNEL
);
781 dev_dbg (dev
, "hcd alloc failed\n");
785 hcd
->bandwidth_mutex
= kmalloc(sizeof(*hcd
->bandwidth_mutex
), GFP_KERNEL
);
786 if (!hcd
->bandwidth_mutex
) {
788 dev_dbg(dev
, "hcd bandwidth mutex alloc failed\n");
791 mutex_init(hcd
->bandwidth_mutex
);
793 printk(KERN_ERR
"====%s(%d)==== hcd->pool[0] = 0x%p!\n", __func__
, __LINE__
, hcd
->pool
[0]);
794 dev_set_drvdata(dev
, hcd
);
795 kref_init(&hcd
->kref
);
797 printk(KERN_ERR
"====%s(%d)==== hcd->pool[0] = 0x%p!\n", __func__
, __LINE__
, hcd
->pool
[0]);
799 mtk_usb_bus_init(&hcd
->self
);
800 hcd
->self
.controller
= dev
;
801 hcd
->self
.bus_name
= bus_name
;
802 hcd
->self
.uses_dma
= (dev
->dma_mask
!= NULL
);
804 printk(KERN_ERR
"====%s(%d)==== hcd->pool[0] = 0x%p!\n", __func__
, __LINE__
, hcd
->pool
[0]);
806 // init_timer(&hcd->rh_timer);
807 // hcd->rh_timer.function = rh_timer_func;
808 // hcd->rh_timer.data = (unsigned long) hcd;
809 #if 0 //#ifdef CONFIG_USB_SUSPEND
810 INIT_WORK(&hcd
->wakeup_work
, hcd_resume_work
);
812 printk(KERN_ERR
"====%s(%d)==== hcd->pool[0] = 0x%p!\n", __func__
, __LINE__
, hcd
->pool
[0]);
813 hcd
->driver
= driver
;
814 hcd
->product_desc
= (driver
->product_desc
) ? driver
->product_desc
:
815 "USB Host Controller";
820 /* Find the flag for this endpoint (for use in the control context). Use the
821 * endpoint index to create a bitmask. The slot context is bit 0, endpoint 0 is
824 unsigned int mtktest_xhci_get_endpoint_flag(struct usb_endpoint_descriptor
*desc
)
826 return 1 << (mtktest_xhci_get_endpoint_index(desc
) + 1);