Ilya Yanok | eb81955 | 2012-11-06 13:48:21 +0000 | [diff] [blame] | 1 | #ifndef __USB_COMPAT_H__ |
| 2 | #define __USB_COMPAT_H__ |
| 3 | |
| 4 | #include "usb.h" |
| 5 | |
| 6 | struct usb_hcd { |
| 7 | void *hcd_priv; |
| 8 | }; |
| 9 | |
| 10 | struct usb_host_endpoint { |
| 11 | struct usb_endpoint_descriptor desc; |
| 12 | struct list_head urb_list; |
| 13 | void *hcpriv; |
| 14 | }; |
| 15 | |
| 16 | /* |
| 17 | * urb->transfer_flags: |
| 18 | * |
| 19 | * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb(). |
| 20 | */ |
| 21 | #define URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */ |
| 22 | #define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */ |
| 23 | |
| 24 | struct urb; |
| 25 | |
| 26 | typedef void (*usb_complete_t)(struct urb *); |
| 27 | |
| 28 | struct urb { |
| 29 | void *hcpriv; /* private data for host controller */ |
| 30 | struct list_head urb_list; /* list head for use by the urb's |
| 31 | * current owner */ |
| 32 | struct usb_device *dev; /* (in) pointer to associated device */ |
| 33 | struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */ |
| 34 | unsigned int pipe; /* (in) pipe information */ |
| 35 | int status; /* (return) non-ISO status */ |
| 36 | unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ |
| 37 | void *transfer_buffer; /* (in) associated data buffer */ |
| 38 | dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */ |
| 39 | u32 transfer_buffer_length; /* (in) data buffer length */ |
| 40 | u32 actual_length; /* (return) actual transfer length */ |
| 41 | unsigned char *setup_packet; /* (in) setup packet (control only) */ |
| 42 | int start_frame; /* (modify) start frame (ISO) */ |
| 43 | usb_complete_t complete; /* (in) completion routine */ |
| 44 | }; |
| 45 | |
| 46 | #define usb_hcd_link_urb_to_ep(hcd, urb) ({ \ |
| 47 | int ret = 0; \ |
| 48 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); \ |
| 49 | ret; }) |
| 50 | #define usb_hcd_unlink_urb_from_ep(hcd, urb) list_del_init(&urb->urb_list) |
| 51 | |
| 52 | static inline void usb_hcd_giveback_urb(struct usb_hcd *hcd, |
| 53 | struct urb *urb, |
| 54 | int status) |
| 55 | { |
| 56 | urb->status = status; |
| 57 | if (urb->complete) |
| 58 | urb->complete(urb); |
| 59 | } |
| 60 | |
| 61 | static inline int usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, |
| 62 | struct urb *urb) |
| 63 | { |
| 64 | /* TODO: add cache invalidation here */ |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static inline u16 find_tt(struct usb_device *dev) |
| 69 | { |
| 70 | u8 chid; |
| 71 | u8 hub; |
| 72 | |
| 73 | /* Find out the nearest parent which is high speed */ |
| 74 | while (dev->parent->parent != NULL) |
| 75 | if (dev->parent->speed != USB_SPEED_HIGH) |
| 76 | dev = dev->parent; |
| 77 | else |
| 78 | break; |
| 79 | |
| 80 | /* determine the port address at that hub */ |
| 81 | hub = dev->parent->devnum; |
| 82 | for (chid = 0; chid < USB_MAXCHILDREN; chid++) |
| 83 | if (dev->parent->children[chid] == dev) |
| 84 | break; |
| 85 | |
| 86 | return (hub << 8) | chid; |
| 87 | } |
| 88 | #endif /* __USB_COMPAT_H__ */ |