diff options
author | Felipe Balbi <balbi@ti.com> | 2011-12-19 04:57:16 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2012-02-28 07:49:06 -0500 |
commit | ade78f9feb2ee3e03460ef3730d7656c4903d999 (patch) | |
tree | f0156074f42656e539c1c4a24dfe496382284cba /drivers/usb/renesas_usbhs | |
parent | ac8a138cb61d641e1522f3470f1a85f2df21b8bf (diff) |
usb: renesas: gadget: use generic map/unmap routines
those routines have everything we need to map/unmap
USB requests and it's better to use them.
Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/renesas_usbhs')
-rw-r--r-- | drivers/usb/renesas_usbhs/mod_gadget.c | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index f37b20c82c80..937f2d40c747 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c | |||
@@ -165,69 +165,32 @@ static void usbhsg_queue_push(struct usbhsg_uep *uep, | |||
165 | /* | 165 | /* |
166 | * dma map/unmap | 166 | * dma map/unmap |
167 | */ | 167 | */ |
168 | static int usbhsg_dma_map(struct device *dev, | 168 | static int usbhsg_dma_map_ctrl(struct usbhs_pkt *pkt, int map) |
169 | struct usbhs_pkt *pkt, | ||
170 | enum dma_data_direction dir) | ||
171 | { | ||
172 | struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt); | ||
173 | struct usb_request *req = &ureq->req; | ||
174 | |||
175 | if (pkt->dma != DMA_ADDR_INVALID) { | ||
176 | dev_err(dev, "dma is already mapped\n"); | ||
177 | return -EIO; | ||
178 | } | ||
179 | |||
180 | if (req->dma == DMA_ADDR_INVALID) { | ||
181 | pkt->dma = dma_map_single(dev, pkt->buf, pkt->length, dir); | ||
182 | } else { | ||
183 | dma_sync_single_for_device(dev, req->dma, req->length, dir); | ||
184 | pkt->dma = req->dma; | ||
185 | } | ||
186 | |||
187 | if (dma_mapping_error(dev, pkt->dma)) { | ||
188 | dev_err(dev, "dma mapping error %llx\n", (u64)pkt->dma); | ||
189 | return -EIO; | ||
190 | } | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static int usbhsg_dma_unmap(struct device *dev, | ||
196 | struct usbhs_pkt *pkt, | ||
197 | enum dma_data_direction dir) | ||
198 | { | 169 | { |
199 | struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt); | 170 | struct usbhsg_request *ureq = usbhsg_pkt_to_ureq(pkt); |
200 | struct usb_request *req = &ureq->req; | 171 | struct usb_request *req = &ureq->req; |
201 | |||
202 | if (pkt->dma == DMA_ADDR_INVALID) { | ||
203 | dev_err(dev, "dma is not mapped\n"); | ||
204 | return -EIO; | ||
205 | } | ||
206 | |||
207 | if (req->dma == DMA_ADDR_INVALID) | ||
208 | dma_unmap_single(dev, pkt->dma, pkt->length, dir); | ||
209 | else | ||
210 | dma_sync_single_for_cpu(dev, req->dma, req->length, dir); | ||
211 | |||
212 | pkt->dma = DMA_ADDR_INVALID; | ||
213 | |||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | static int usbhsg_dma_map_ctrl(struct usbhs_pkt *pkt, int map) | ||
218 | { | ||
219 | struct usbhs_pipe *pipe = pkt->pipe; | 172 | struct usbhs_pipe *pipe = pkt->pipe; |
220 | struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe); | 173 | struct usbhsg_uep *uep = usbhsg_pipe_to_uep(pipe); |
221 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); | 174 | struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); |
222 | struct device *dev = usbhsg_gpriv_to_dev(gpriv); | ||
223 | enum dma_data_direction dir; | 175 | enum dma_data_direction dir; |
176 | int ret = 0; | ||
224 | 177 | ||
225 | dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | 178 | dir = usbhs_pipe_is_dir_host(pipe); |
226 | 179 | ||
227 | if (map) | 180 | if (map) { |
228 | return usbhsg_dma_map(dev, pkt, dir); | 181 | /* it can not use scatter/gather */ |
229 | else | 182 | WARN_ON(req->num_sgs); |
230 | return usbhsg_dma_unmap(dev, pkt, dir); | 183 | |
184 | ret = usb_gadget_map_request(&gpriv->gadget, req, dir); | ||
185 | if (ret < 0) | ||
186 | return ret; | ||
187 | |||
188 | pkt->dma = req->dma; | ||
189 | } else { | ||
190 | usb_gadget_unmap_request(&gpriv->gadget, req, dir); | ||
191 | } | ||
192 | |||
193 | return ret; | ||
231 | } | 194 | } |
232 | 195 | ||
233 | /* | 196 | /* |
@@ -657,8 +620,6 @@ static struct usb_request *usbhsg_ep_alloc_request(struct usb_ep *ep, | |||
657 | 620 | ||
658 | usbhs_pkt_init(usbhsg_ureq_to_pkt(ureq)); | 621 | usbhs_pkt_init(usbhsg_ureq_to_pkt(ureq)); |
659 | 622 | ||
660 | ureq->req.dma = DMA_ADDR_INVALID; | ||
661 | |||
662 | return &ureq->req; | 623 | return &ureq->req; |
663 | } | 624 | } |
664 | 625 | ||