diff options
Diffstat (limited to 'drivers/usb/gadget/udc-core.c')
-rw-r--r-- | drivers/usb/gadget/udc-core.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index 0b0d12ccc487..56da49f31d6c 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/device.h> | 22 | #include <linux/device.h> |
23 | #include <linux/list.h> | 23 | #include <linux/list.h> |
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/dma-mapping.h> | ||
25 | 26 | ||
26 | #include <linux/usb/ch9.h> | 27 | #include <linux/usb/ch9.h> |
27 | #include <linux/usb/gadget.h> | 28 | #include <linux/usb/gadget.h> |
@@ -49,6 +50,57 @@ static DEFINE_MUTEX(udc_lock); | |||
49 | 50 | ||
50 | /* ------------------------------------------------------------------------- */ | 51 | /* ------------------------------------------------------------------------- */ |
51 | 52 | ||
53 | int usb_gadget_map_request(struct usb_gadget *gadget, | ||
54 | struct usb_request *req, int is_in) | ||
55 | { | ||
56 | if (req->length == 0) | ||
57 | return 0; | ||
58 | |||
59 | if (req->num_sgs) { | ||
60 | int mapped; | ||
61 | |||
62 | mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs, | ||
63 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
64 | if (mapped == 0) { | ||
65 | dev_err(&gadget->dev, "failed to map SGs\n"); | ||
66 | return -EFAULT; | ||
67 | } | ||
68 | |||
69 | req->num_mapped_sgs = mapped; | ||
70 | } else { | ||
71 | req->dma = dma_map_single(&gadget->dev, req->buf, req->length, | ||
72 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
73 | |||
74 | if (dma_mapping_error(&gadget->dev, req->dma)) { | ||
75 | dev_err(&gadget->dev, "failed to map buffer\n"); | ||
76 | return -EFAULT; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | EXPORT_SYMBOL_GPL(usb_gadget_map_request); | ||
83 | |||
84 | void usb_gadget_unmap_request(struct usb_gadget *gadget, | ||
85 | struct usb_request *req, int is_in) | ||
86 | { | ||
87 | if (req->length == 0) | ||
88 | return; | ||
89 | |||
90 | if (req->num_mapped_sgs) { | ||
91 | dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs, | ||
92 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
93 | |||
94 | req->num_mapped_sgs = 0; | ||
95 | } else { | ||
96 | dma_unmap_single(&gadget->dev, req->dma, req->length, | ||
97 | is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
98 | } | ||
99 | } | ||
100 | EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); | ||
101 | |||
102 | /* ------------------------------------------------------------------------- */ | ||
103 | |||
52 | /** | 104 | /** |
53 | * usb_gadget_start - tells usb device controller to start up | 105 | * usb_gadget_start - tells usb device controller to start up |
54 | * @gadget: The gadget we want to get started | 106 | * @gadget: The gadget we want to get started |