aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/fsl_qe_udc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/fsl_qe_udc.c')
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c371
1 files changed, 149 insertions, 222 deletions
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 877a2c46672b..51881f3bd07a 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -71,9 +71,6 @@ static struct usb_endpoint_descriptor qe_ep0_desc = {
71 .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, 71 .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD,
72}; 72};
73 73
74/* it is initialized in probe() */
75static struct qe_udc *udc_controller;
76
77/******************************************************************** 74/********************************************************************
78 * Internal Used Function Start 75 * Internal Used Function Start
79********************************************************************/ 76********************************************************************/
@@ -188,8 +185,8 @@ static int qe_ep0_stall(struct qe_udc *udc)
188{ 185{
189 qe_eptx_stall_change(&udc->eps[0], 1); 186 qe_eptx_stall_change(&udc->eps[0], 1);
190 qe_eprx_stall_change(&udc->eps[0], 1); 187 qe_eprx_stall_change(&udc->eps[0], 1);
191 udc_controller->ep0_state = WAIT_FOR_SETUP; 188 udc->ep0_state = WAIT_FOR_SETUP;
192 udc_controller->ep0_dir = 0; 189 udc->ep0_dir = 0;
193 return 0; 190 return 0;
194} 191}
195 192
@@ -450,13 +447,13 @@ static int qe_ep_rxbd_update(struct qe_ep *ep)
450 447
451 ep->rxbuf_d = virt_to_phys((void *)ep->rxbuffer); 448 ep->rxbuf_d = virt_to_phys((void *)ep->rxbuffer);
452 if (ep->rxbuf_d == DMA_ADDR_INVALID) { 449 if (ep->rxbuf_d == DMA_ADDR_INVALID) {
453 ep->rxbuf_d = dma_map_single(udc_controller->gadget.dev.parent, 450 ep->rxbuf_d = dma_map_single(ep->udc->gadget.dev.parent,
454 ep->rxbuffer, 451 ep->rxbuffer,
455 size, 452 size,
456 DMA_FROM_DEVICE); 453 DMA_FROM_DEVICE);
457 ep->rxbufmap = 1; 454 ep->rxbufmap = 1;
458 } else { 455 } else {
459 dma_sync_single_for_device(udc_controller->gadget.dev.parent, 456 dma_sync_single_for_device(ep->udc->gadget.dev.parent,
460 ep->rxbuf_d, size, 457 ep->rxbuf_d, size,
461 DMA_FROM_DEVICE); 458 DMA_FROM_DEVICE);
462 ep->rxbufmap = 0; 459 ep->rxbufmap = 0;
@@ -489,10 +486,10 @@ static int qe_ep_register_init(struct qe_udc *udc, unsigned char pipe_num)
489 epparam = udc->ep_param[pipe_num]; 486 epparam = udc->ep_param[pipe_num];
490 487
491 usep = 0; 488 usep = 0;
492 logepnum = (ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 489 logepnum = (ep->ep.desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
493 usep |= (logepnum << USB_EPNUM_SHIFT); 490 usep |= (logepnum << USB_EPNUM_SHIFT);
494 491
495 switch (ep->desc->bmAttributes & 0x03) { 492 switch (ep->ep.desc->bmAttributes & 0x03) {
496 case USB_ENDPOINT_XFER_BULK: 493 case USB_ENDPOINT_XFER_BULK:
497 usep |= USB_TRANS_BULK; 494 usep |= USB_TRANS_BULK;
498 break; 495 break;
@@ -644,7 +641,7 @@ static int qe_ep_init(struct qe_udc *udc,
644 /* initialize ep structure */ 641 /* initialize ep structure */
645 ep->ep.maxpacket = max; 642 ep->ep.maxpacket = max;
646 ep->tm = (u8)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); 643 ep->tm = (u8)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
647 ep->desc = desc; 644 ep->ep.desc = desc;
648 ep->stopped = 0; 645 ep->stopped = 0;
649 ep->init = 1; 646 ep->init = 1;
650 647
@@ -698,14 +695,14 @@ en_done:
698 return -ENODEV; 695 return -ENODEV;
699} 696}
700 697
701static inline void qe_usb_enable(void) 698static inline void qe_usb_enable(struct qe_udc *udc)
702{ 699{
703 setbits8(&udc_controller->usb_regs->usb_usmod, USB_MODE_EN); 700 setbits8(&udc->usb_regs->usb_usmod, USB_MODE_EN);
704} 701}
705 702
706static inline void qe_usb_disable(void) 703static inline void qe_usb_disable(struct qe_udc *udc)
707{ 704{
708 clrbits8(&udc_controller->usb_regs->usb_usmod, USB_MODE_EN); 705 clrbits8(&udc->usb_regs->usb_usmod, USB_MODE_EN);
709} 706}
710 707
711/*----------------------------------------------------------------------------* 708/*----------------------------------------------------------------------------*
@@ -1599,7 +1596,7 @@ static int qe_ep_enable(struct usb_ep *_ep,
1599 ep = container_of(_ep, struct qe_ep, ep); 1596 ep = container_of(_ep, struct qe_ep, ep);
1600 1597
1601 /* catch various bogus parameters */ 1598 /* catch various bogus parameters */
1602 if (!_ep || !desc || ep->desc || _ep->name == ep_name[0] || 1599 if (!_ep || !desc || ep->ep.desc || _ep->name == ep_name[0] ||
1603 (desc->bDescriptorType != USB_DT_ENDPOINT)) 1600 (desc->bDescriptorType != USB_DT_ENDPOINT))
1604 return -EINVAL; 1601 return -EINVAL;
1605 1602
@@ -1629,7 +1626,7 @@ static int qe_ep_disable(struct usb_ep *_ep)
1629 ep = container_of(_ep, struct qe_ep, ep); 1626 ep = container_of(_ep, struct qe_ep, ep);
1630 udc = ep->udc; 1627 udc = ep->udc;
1631 1628
1632 if (!_ep || !ep->desc) { 1629 if (!_ep || !ep->ep.desc) {
1633 dev_dbg(udc->dev, "%s not enabled\n", _ep ? ep->ep.name : NULL); 1630 dev_dbg(udc->dev, "%s not enabled\n", _ep ? ep->ep.name : NULL);
1634 return -EINVAL; 1631 return -EINVAL;
1635 } 1632 }
@@ -1637,7 +1634,6 @@ static int qe_ep_disable(struct usb_ep *_ep)
1637 spin_lock_irqsave(&udc->lock, flags); 1634 spin_lock_irqsave(&udc->lock, flags);
1638 /* Nuke all pending requests (does flush) */ 1635 /* Nuke all pending requests (does flush) */
1639 nuke(ep, -ESHUTDOWN); 1636 nuke(ep, -ESHUTDOWN);
1640 ep->desc = NULL;
1641 ep->ep.desc = NULL; 1637 ep->ep.desc = NULL;
1642 ep->stopped = 1; 1638 ep->stopped = 1;
1643 ep->tx_req = NULL; 1639 ep->tx_req = NULL;
@@ -1656,13 +1652,13 @@ static int qe_ep_disable(struct usb_ep *_ep)
1656 if (ep->dir != USB_DIR_IN) { 1652 if (ep->dir != USB_DIR_IN) {
1657 kfree(ep->rxframe); 1653 kfree(ep->rxframe);
1658 if (ep->rxbufmap) { 1654 if (ep->rxbufmap) {
1659 dma_unmap_single(udc_controller->gadget.dev.parent, 1655 dma_unmap_single(udc->gadget.dev.parent,
1660 ep->rxbuf_d, size, 1656 ep->rxbuf_d, size,
1661 DMA_FROM_DEVICE); 1657 DMA_FROM_DEVICE);
1662 ep->rxbuf_d = DMA_ADDR_INVALID; 1658 ep->rxbuf_d = DMA_ADDR_INVALID;
1663 } else { 1659 } else {
1664 dma_sync_single_for_cpu( 1660 dma_sync_single_for_cpu(
1665 udc_controller->gadget.dev.parent, 1661 udc->gadget.dev.parent,
1666 ep->rxbuf_d, size, 1662 ep->rxbuf_d, size,
1667 DMA_FROM_DEVICE); 1663 DMA_FROM_DEVICE);
1668 } 1664 }
@@ -1715,7 +1711,7 @@ static int __qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req)
1715 dev_dbg(udc->dev, "bad params\n"); 1711 dev_dbg(udc->dev, "bad params\n");
1716 return -EINVAL; 1712 return -EINVAL;
1717 } 1713 }
1718 if (!_ep || (!ep->desc && ep_index(ep))) { 1714 if (!_ep || (!ep->ep.desc && ep_index(ep))) {
1719 dev_dbg(udc->dev, "bad ep\n"); 1715 dev_dbg(udc->dev, "bad ep\n");
1720 return -EINVAL; 1716 return -EINVAL;
1721 } 1717 }
@@ -1826,7 +1822,7 @@ static int qe_ep_set_halt(struct usb_ep *_ep, int value)
1826 struct qe_udc *udc; 1822 struct qe_udc *udc;
1827 1823
1828 ep = container_of(_ep, struct qe_ep, ep); 1824 ep = container_of(_ep, struct qe_ep, ep);
1829 if (!_ep || !ep->desc) { 1825 if (!_ep || !ep->ep.desc) {
1830 status = -EINVAL; 1826 status = -EINVAL;
1831 goto out; 1827 goto out;
1832 } 1828 }
@@ -1880,9 +1876,10 @@ static struct usb_ep_ops qe_ep_ops = {
1880/* Get the current frame number */ 1876/* Get the current frame number */
1881static int qe_get_frame(struct usb_gadget *gadget) 1877static int qe_get_frame(struct usb_gadget *gadget)
1882{ 1878{
1879 struct qe_udc *udc = container_of(gadget, struct qe_udc, gadget);
1883 u16 tmp; 1880 u16 tmp;
1884 1881
1885 tmp = in_be16(&udc_controller->usb_param->frame_n); 1882 tmp = in_be16(&udc->usb_param->frame_n);
1886 if (tmp & 0x8000) 1883 if (tmp & 0x8000)
1887 tmp = tmp & 0x07ff; 1884 tmp = tmp & 0x07ff;
1888 else 1885 else
@@ -1891,57 +1888,16 @@ static int qe_get_frame(struct usb_gadget *gadget)
1891 return (int)tmp; 1888 return (int)tmp;
1892} 1889}
1893 1890
1894/* Tries to wake up the host connected to this gadget 1891static int fsl_qe_start(struct usb_gadget *gadget,
1895 * 1892 struct usb_gadget_driver *driver);
1896 * Return : 0-success 1893static int fsl_qe_stop(struct usb_gadget *gadget,
1897 * Negative-this feature not enabled by host or not supported by device hw 1894 struct usb_gadget_driver *driver);
1898 */
1899static int qe_wakeup(struct usb_gadget *gadget)
1900{
1901 return -ENOTSUPP;
1902}
1903
1904/* Notify controller that VBUS is powered, Called by whatever
1905 detects VBUS sessions */
1906static int qe_vbus_session(struct usb_gadget *gadget, int is_active)
1907{
1908 return -ENOTSUPP;
1909}
1910
1911/* constrain controller's VBUS power usage
1912 * This call is used by gadget drivers during SET_CONFIGURATION calls,
1913 * reporting how much power the device may consume. For example, this
1914 * could affect how quickly batteries are recharged.
1915 *
1916 * Returns zero on success, else negative errno.
1917 */
1918static int qe_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1919{
1920 return -ENOTSUPP;
1921}
1922
1923/* Change Data+ pullup status
1924 * this func is used by usb_gadget_connect/disconnect
1925 */
1926static int qe_pullup(struct usb_gadget *gadget, int is_on)
1927{
1928 return -ENOTSUPP;
1929}
1930
1931static int fsl_qe_start(struct usb_gadget_driver *driver,
1932 int (*bind)(struct usb_gadget *));
1933static int fsl_qe_stop(struct usb_gadget_driver *driver);
1934 1895
1935/* defined in usb_gadget.h */ 1896/* defined in usb_gadget.h */
1936static struct usb_gadget_ops qe_gadget_ops = { 1897static struct usb_gadget_ops qe_gadget_ops = {
1937 .get_frame = qe_get_frame, 1898 .get_frame = qe_get_frame,
1938 .wakeup = qe_wakeup, 1899 .udc_start = fsl_qe_start,
1939/* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */ 1900 .udc_stop = fsl_qe_stop,
1940 .vbus_session = qe_vbus_session,
1941 .vbus_draw = qe_vbus_draw,
1942 .pullup = qe_pullup,
1943 .start = fsl_qe_start,
1944 .stop = fsl_qe_stop,
1945}; 1901};
1946 1902
1947/*------------------------------------------------------------------------- 1903/*-------------------------------------------------------------------------
@@ -2015,7 +1971,7 @@ static void ch9getstatus(struct qe_udc *udc, u8 request_type, u16 value,
2015 u16 usep; 1971 u16 usep;
2016 1972
2017 /* stall if endpoint doesn't exist */ 1973 /* stall if endpoint doesn't exist */
2018 if (!target_ep->desc) 1974 if (!target_ep->ep.desc)
2019 goto stall; 1975 goto stall;
2020 1976
2021 usep = in_be16(&udc->usb_regs->usb_usep[pipe]); 1977 usep = in_be16(&udc->usb_regs->usb_usep[pipe]);
@@ -2190,7 +2146,7 @@ static int reset_irq(struct qe_udc *udc)
2190 if (udc->usb_state == USB_STATE_DEFAULT) 2146 if (udc->usb_state == USB_STATE_DEFAULT)
2191 return 0; 2147 return 0;
2192 2148
2193 qe_usb_disable(); 2149 qe_usb_disable(udc);
2194 out_8(&udc->usb_regs->usb_usadr, 0); 2150 out_8(&udc->usb_regs->usb_usadr, 0);
2195 2151
2196 for (i = 0; i < USB_MAX_ENDPOINTS; i++) { 2152 for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
@@ -2202,7 +2158,7 @@ static int reset_irq(struct qe_udc *udc)
2202 udc->usb_state = USB_STATE_DEFAULT; 2158 udc->usb_state = USB_STATE_DEFAULT;
2203 udc->ep0_state = WAIT_FOR_SETUP; 2159 udc->ep0_state = WAIT_FOR_SETUP;
2204 udc->ep0_dir = USB_DIR_OUT; 2160 udc->ep0_dir = USB_DIR_OUT;
2205 qe_usb_enable(); 2161 qe_usb_enable(udc);
2206 return 0; 2162 return 0;
2207} 2163}
2208 2164
@@ -2327,92 +2283,65 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc)
2327/*------------------------------------------------------------------------- 2283/*-------------------------------------------------------------------------
2328 Gadget driver probe and unregister. 2284 Gadget driver probe and unregister.
2329 --------------------------------------------------------------------------*/ 2285 --------------------------------------------------------------------------*/
2330static int fsl_qe_start(struct usb_gadget_driver *driver, 2286static int fsl_qe_start(struct usb_gadget *gadget,
2331 int (*bind)(struct usb_gadget *)) 2287 struct usb_gadget_driver *driver)
2332{ 2288{
2333 int retval; 2289 struct qe_udc *udc;
2334 unsigned long flags = 0; 2290 unsigned long flags;
2335
2336 /* standard operations */
2337 if (!udc_controller)
2338 return -ENODEV;
2339
2340 if (!driver || driver->max_speed < USB_SPEED_FULL
2341 || !bind || !driver->disconnect || !driver->setup)
2342 return -EINVAL;
2343
2344 if (udc_controller->driver)
2345 return -EBUSY;
2346 2291
2292 udc = container_of(gadget, struct qe_udc, gadget);
2347 /* lock is needed but whether should use this lock or another */ 2293 /* lock is needed but whether should use this lock or another */
2348 spin_lock_irqsave(&udc_controller->lock, flags); 2294 spin_lock_irqsave(&udc->lock, flags);
2349 2295
2350 driver->driver.bus = NULL; 2296 driver->driver.bus = NULL;
2351 /* hook up the driver */ 2297 /* hook up the driver */
2352 udc_controller->driver = driver; 2298 udc->driver = driver;
2353 udc_controller->gadget.dev.driver = &driver->driver; 2299 udc->gadget.dev.driver = &driver->driver;
2354 udc_controller->gadget.speed = driver->max_speed; 2300 udc->gadget.speed = driver->max_speed;
2355 spin_unlock_irqrestore(&udc_controller->lock, flags);
2356
2357 retval = bind(&udc_controller->gadget);
2358 if (retval) {
2359 dev_err(udc_controller->dev, "bind to %s --> %d",
2360 driver->driver.name, retval);
2361 udc_controller->gadget.dev.driver = NULL;
2362 udc_controller->driver = NULL;
2363 return retval;
2364 }
2365 2301
2366 /* Enable IRQ reg and Set usbcmd reg EN bit */ 2302 /* Enable IRQ reg and Set usbcmd reg EN bit */
2367 qe_usb_enable(); 2303 qe_usb_enable(udc);
2368 2304
2369 out_be16(&udc_controller->usb_regs->usb_usber, 0xffff); 2305 out_be16(&udc->usb_regs->usb_usber, 0xffff);
2370 out_be16(&udc_controller->usb_regs->usb_usbmr, USB_E_DEFAULT_DEVICE); 2306 out_be16(&udc->usb_regs->usb_usbmr, USB_E_DEFAULT_DEVICE);
2371 udc_controller->usb_state = USB_STATE_ATTACHED; 2307 udc->usb_state = USB_STATE_ATTACHED;
2372 udc_controller->ep0_state = WAIT_FOR_SETUP; 2308 udc->ep0_state = WAIT_FOR_SETUP;
2373 udc_controller->ep0_dir = USB_DIR_OUT; 2309 udc->ep0_dir = USB_DIR_OUT;
2374 dev_info(udc_controller->dev, "%s bind to driver %s \n", 2310 spin_unlock_irqrestore(&udc->lock, flags);
2375 udc_controller->gadget.name, driver->driver.name); 2311
2312 dev_info(udc->dev, "%s bind to driver %s\n", udc->gadget.name,
2313 driver->driver.name);
2376 return 0; 2314 return 0;
2377} 2315}
2378 2316
2379static int fsl_qe_stop(struct usb_gadget_driver *driver) 2317static int fsl_qe_stop(struct usb_gadget *gadget,
2318 struct usb_gadget_driver *driver)
2380{ 2319{
2320 struct qe_udc *udc;
2381 struct qe_ep *loop_ep; 2321 struct qe_ep *loop_ep;
2382 unsigned long flags; 2322 unsigned long flags;
2383 2323
2384 if (!udc_controller) 2324 udc = container_of(gadget, struct qe_udc, gadget);
2385 return -ENODEV;
2386
2387 if (!driver || driver != udc_controller->driver)
2388 return -EINVAL;
2389
2390 /* stop usb controller, disable intr */ 2325 /* stop usb controller, disable intr */
2391 qe_usb_disable(); 2326 qe_usb_disable(udc);
2392 2327
2393 /* in fact, no needed */ 2328 /* in fact, no needed */
2394 udc_controller->usb_state = USB_STATE_ATTACHED; 2329 udc->usb_state = USB_STATE_ATTACHED;
2395 udc_controller->ep0_state = WAIT_FOR_SETUP; 2330 udc->ep0_state = WAIT_FOR_SETUP;
2396 udc_controller->ep0_dir = 0; 2331 udc->ep0_dir = 0;
2397 2332
2398 /* stand operation */ 2333 /* stand operation */
2399 spin_lock_irqsave(&udc_controller->lock, flags); 2334 spin_lock_irqsave(&udc->lock, flags);
2400 udc_controller->gadget.speed = USB_SPEED_UNKNOWN; 2335 udc->gadget.speed = USB_SPEED_UNKNOWN;
2401 nuke(&udc_controller->eps[0], -ESHUTDOWN); 2336 nuke(&udc->eps[0], -ESHUTDOWN);
2402 list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list, 2337 list_for_each_entry(loop_ep, &udc->gadget.ep_list, ep.ep_list)
2403 ep.ep_list)
2404 nuke(loop_ep, -ESHUTDOWN); 2338 nuke(loop_ep, -ESHUTDOWN);
2405 spin_unlock_irqrestore(&udc_controller->lock, flags); 2339 spin_unlock_irqrestore(&udc->lock, flags);
2406
2407 /* report disconnect; the controller is already quiesced */
2408 driver->disconnect(&udc_controller->gadget);
2409 2340
2410 /* unbind gadget and unhook driver. */ 2341 udc->gadget.dev.driver = NULL;
2411 driver->unbind(&udc_controller->gadget); 2342 udc->driver = NULL;
2412 udc_controller->gadget.dev.driver = NULL;
2413 udc_controller->driver = NULL;
2414 2343
2415 dev_info(udc_controller->dev, "unregistered gadget driver '%s'\r\n", 2344 dev_info(udc->dev, "unregistered gadget driver '%s'\r\n",
2416 driver->driver.name); 2345 driver->driver.name);
2417 return 0; 2346 return 0;
2418} 2347}
@@ -2502,7 +2431,7 @@ static int __devinit qe_ep_config(struct qe_udc *udc, unsigned char pipe_num)
2502 ep->ep.ops = &qe_ep_ops; 2431 ep->ep.ops = &qe_ep_ops;
2503 ep->stopped = 1; 2432 ep->stopped = 1;
2504 ep->ep.maxpacket = (unsigned short) ~0; 2433 ep->ep.maxpacket = (unsigned short) ~0;
2505 ep->desc = NULL; 2434 ep->ep.desc = NULL;
2506 ep->dir = 0xff; 2435 ep->dir = 0xff;
2507 ep->epnum = (u8)pipe_num; 2436 ep->epnum = (u8)pipe_num;
2508 ep->sent = 0; 2437 ep->sent = 0;
@@ -2531,21 +2460,22 @@ static int __devinit qe_ep_config(struct qe_udc *udc, unsigned char pipe_num)
2531 *----------------------------------------------------------------------*/ 2460 *----------------------------------------------------------------------*/
2532static void qe_udc_release(struct device *dev) 2461static void qe_udc_release(struct device *dev)
2533{ 2462{
2534 int i = 0; 2463 struct qe_udc *udc = container_of(dev, struct qe_udc, gadget.dev);
2464 int i;
2535 2465
2536 complete(udc_controller->done); 2466 complete(udc->done);
2537 cpm_muram_free(cpm_muram_offset(udc_controller->ep_param[0])); 2467 cpm_muram_free(cpm_muram_offset(udc->ep_param[0]));
2538 for (i = 0; i < USB_MAX_ENDPOINTS; i++) 2468 for (i = 0; i < USB_MAX_ENDPOINTS; i++)
2539 udc_controller->ep_param[i] = NULL; 2469 udc->ep_param[i] = NULL;
2540 2470
2541 kfree(udc_controller); 2471 kfree(udc);
2542 udc_controller = NULL;
2543} 2472}
2544 2473
2545/* Driver probe functions */ 2474/* Driver probe functions */
2546static const struct of_device_id qe_udc_match[]; 2475static const struct of_device_id qe_udc_match[];
2547static int __devinit qe_udc_probe(struct platform_device *ofdev) 2476static int __devinit qe_udc_probe(struct platform_device *ofdev)
2548{ 2477{
2478 struct qe_udc *udc;
2549 const struct of_device_id *match; 2479 const struct of_device_id *match;
2550 struct device_node *np = ofdev->dev.of_node; 2480 struct device_node *np = ofdev->dev.of_node;
2551 struct qe_ep *ep; 2481 struct qe_ep *ep;
@@ -2562,44 +2492,44 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev)
2562 return -ENODEV; 2492 return -ENODEV;
2563 2493
2564 /* Initialize the udc structure including QH member and other member */ 2494 /* Initialize the udc structure including QH member and other member */
2565 udc_controller = qe_udc_config(ofdev); 2495 udc = qe_udc_config(ofdev);
2566 if (!udc_controller) { 2496 if (!udc) {
2567 dev_err(&ofdev->dev, "failed to initialize\n"); 2497 dev_err(&ofdev->dev, "failed to initialize\n");
2568 return -ENOMEM; 2498 return -ENOMEM;
2569 } 2499 }
2570 2500
2571 udc_controller->soc_type = (unsigned long)match->data; 2501 udc->soc_type = (unsigned long)match->data;
2572 udc_controller->usb_regs = of_iomap(np, 0); 2502 udc->usb_regs = of_iomap(np, 0);
2573 if (!udc_controller->usb_regs) { 2503 if (!udc->usb_regs) {
2574 ret = -ENOMEM; 2504 ret = -ENOMEM;
2575 goto err1; 2505 goto err1;
2576 } 2506 }
2577 2507
2578 /* initialize usb hw reg except for regs for EP, 2508 /* initialize usb hw reg except for regs for EP,
2579 * leave usbintr reg untouched*/ 2509 * leave usbintr reg untouched*/
2580 qe_udc_reg_init(udc_controller); 2510 qe_udc_reg_init(udc);
2581 2511
2582 /* here comes the stand operations for probe 2512 /* here comes the stand operations for probe
2583 * set the qe_udc->gadget.xxx */ 2513 * set the qe_udc->gadget.xxx */
2584 udc_controller->gadget.ops = &qe_gadget_ops; 2514 udc->gadget.ops = &qe_gadget_ops;
2585 2515
2586 /* gadget.ep0 is a pointer */ 2516 /* gadget.ep0 is a pointer */
2587 udc_controller->gadget.ep0 = &udc_controller->eps[0].ep; 2517 udc->gadget.ep0 = &udc->eps[0].ep;
2588 2518
2589 INIT_LIST_HEAD(&udc_controller->gadget.ep_list); 2519 INIT_LIST_HEAD(&udc->gadget.ep_list);
2590 2520
2591 /* modify in register gadget process */ 2521 /* modify in register gadget process */
2592 udc_controller->gadget.speed = USB_SPEED_UNKNOWN; 2522 udc->gadget.speed = USB_SPEED_UNKNOWN;
2593 2523
2594 /* name: Identifies the controller hardware type. */ 2524 /* name: Identifies the controller hardware type. */
2595 udc_controller->gadget.name = driver_name; 2525 udc->gadget.name = driver_name;
2596 2526
2597 device_initialize(&udc_controller->gadget.dev); 2527 device_initialize(&udc->gadget.dev);
2598 2528
2599 dev_set_name(&udc_controller->gadget.dev, "gadget"); 2529 dev_set_name(&udc->gadget.dev, "gadget");
2600 2530
2601 udc_controller->gadget.dev.release = qe_udc_release; 2531 udc->gadget.dev.release = qe_udc_release;
2602 udc_controller->gadget.dev.parent = &ofdev->dev; 2532 udc->gadget.dev.parent = &ofdev->dev;
2603 2533
2604 /* initialize qe_ep struct */ 2534 /* initialize qe_ep struct */
2605 for (i = 0; i < USB_MAX_ENDPOINTS ; i++) { 2535 for (i = 0; i < USB_MAX_ENDPOINTS ; i++) {
@@ -2608,104 +2538,104 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev)
2608 2538
2609 /* setup the qe_ep struct and link ep.ep.list 2539 /* setup the qe_ep struct and link ep.ep.list
2610 * into gadget.ep_list */ 2540 * into gadget.ep_list */
2611 qe_ep_config(udc_controller, (unsigned char)i); 2541 qe_ep_config(udc, (unsigned char)i);
2612 } 2542 }
2613 2543
2614 /* ep0 initialization in here */ 2544 /* ep0 initialization in here */
2615 ret = qe_ep_init(udc_controller, 0, &qe_ep0_desc); 2545 ret = qe_ep_init(udc, 0, &qe_ep0_desc);
2616 if (ret) 2546 if (ret)
2617 goto err2; 2547 goto err2;
2618 2548
2619 /* create a buf for ZLP send, need to remain zeroed */ 2549 /* create a buf for ZLP send, need to remain zeroed */
2620 udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); 2550 udc->nullbuf = kzalloc(256, GFP_KERNEL);
2621 if (udc_controller->nullbuf == NULL) { 2551 if (udc->nullbuf == NULL) {
2622 dev_err(udc_controller->dev, "cannot alloc nullbuf\n"); 2552 dev_err(udc->dev, "cannot alloc nullbuf\n");
2623 ret = -ENOMEM; 2553 ret = -ENOMEM;
2624 goto err3; 2554 goto err3;
2625 } 2555 }
2626 2556
2627 /* buffer for data of get_status request */ 2557 /* buffer for data of get_status request */
2628 udc_controller->statusbuf = kzalloc(2, GFP_KERNEL); 2558 udc->statusbuf = kzalloc(2, GFP_KERNEL);
2629 if (udc_controller->statusbuf == NULL) { 2559 if (udc->statusbuf == NULL) {
2630 ret = -ENOMEM; 2560 ret = -ENOMEM;
2631 goto err4; 2561 goto err4;
2632 } 2562 }
2633 2563
2634 udc_controller->nullp = virt_to_phys((void *)udc_controller->nullbuf); 2564 udc->nullp = virt_to_phys((void *)udc->nullbuf);
2635 if (udc_controller->nullp == DMA_ADDR_INVALID) { 2565 if (udc->nullp == DMA_ADDR_INVALID) {
2636 udc_controller->nullp = dma_map_single( 2566 udc->nullp = dma_map_single(
2637 udc_controller->gadget.dev.parent, 2567 udc->gadget.dev.parent,
2638 udc_controller->nullbuf, 2568 udc->nullbuf,
2639 256, 2569 256,
2640 DMA_TO_DEVICE); 2570 DMA_TO_DEVICE);
2641 udc_controller->nullmap = 1; 2571 udc->nullmap = 1;
2642 } else { 2572 } else {
2643 dma_sync_single_for_device(udc_controller->gadget.dev.parent, 2573 dma_sync_single_for_device(udc->gadget.dev.parent,
2644 udc_controller->nullp, 256, 2574 udc->nullp, 256,
2645 DMA_TO_DEVICE); 2575 DMA_TO_DEVICE);
2646 } 2576 }
2647 2577
2648 tasklet_init(&udc_controller->rx_tasklet, ep_rx_tasklet, 2578 tasklet_init(&udc->rx_tasklet, ep_rx_tasklet,
2649 (unsigned long)udc_controller); 2579 (unsigned long)udc);
2650 /* request irq and disable DR */ 2580 /* request irq and disable DR */
2651 udc_controller->usb_irq = irq_of_parse_and_map(np, 0); 2581 udc->usb_irq = irq_of_parse_and_map(np, 0);
2652 if (!udc_controller->usb_irq) { 2582 if (!udc->usb_irq) {
2653 ret = -EINVAL; 2583 ret = -EINVAL;
2654 goto err_noirq; 2584 goto err_noirq;
2655 } 2585 }
2656 2586
2657 ret = request_irq(udc_controller->usb_irq, qe_udc_irq, 0, 2587 ret = request_irq(udc->usb_irq, qe_udc_irq, 0,
2658 driver_name, udc_controller); 2588 driver_name, udc);
2659 if (ret) { 2589 if (ret) {
2660 dev_err(udc_controller->dev, "cannot request irq %d err %d \n", 2590 dev_err(udc->dev, "cannot request irq %d err %d\n",
2661 udc_controller->usb_irq, ret); 2591 udc->usb_irq, ret);
2662 goto err5; 2592 goto err5;
2663 } 2593 }
2664 2594
2665 ret = device_add(&udc_controller->gadget.dev); 2595 ret = device_add(&udc->gadget.dev);
2666 if (ret) 2596 if (ret)
2667 goto err6; 2597 goto err6;
2668 2598
2669 ret = usb_add_gadget_udc(&ofdev->dev, &udc_controller->gadget); 2599 ret = usb_add_gadget_udc(&ofdev->dev, &udc->gadget);
2670 if (ret) 2600 if (ret)
2671 goto err7; 2601 goto err7;
2672 2602
2673 dev_info(udc_controller->dev, 2603 dev_set_drvdata(&ofdev->dev, udc);
2604 dev_info(udc->dev,
2674 "%s USB controller initialized as device\n", 2605 "%s USB controller initialized as device\n",
2675 (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); 2606 (udc->soc_type == PORT_QE) ? "QE" : "CPM");
2676 return 0; 2607 return 0;
2677 2608
2678err7: 2609err7:
2679 device_unregister(&udc_controller->gadget.dev); 2610 device_unregister(&udc->gadget.dev);
2680err6: 2611err6:
2681 free_irq(udc_controller->usb_irq, udc_controller); 2612 free_irq(udc->usb_irq, udc);
2682err5: 2613err5:
2683 irq_dispose_mapping(udc_controller->usb_irq); 2614 irq_dispose_mapping(udc->usb_irq);
2684err_noirq: 2615err_noirq:
2685 if (udc_controller->nullmap) { 2616 if (udc->nullmap) {
2686 dma_unmap_single(udc_controller->gadget.dev.parent, 2617 dma_unmap_single(udc->gadget.dev.parent,
2687 udc_controller->nullp, 256, 2618 udc->nullp, 256,
2688 DMA_TO_DEVICE); 2619 DMA_TO_DEVICE);
2689 udc_controller->nullp = DMA_ADDR_INVALID; 2620 udc->nullp = DMA_ADDR_INVALID;
2690 } else { 2621 } else {
2691 dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, 2622 dma_sync_single_for_cpu(udc->gadget.dev.parent,
2692 udc_controller->nullp, 256, 2623 udc->nullp, 256,
2693 DMA_TO_DEVICE); 2624 DMA_TO_DEVICE);
2694 } 2625 }
2695 kfree(udc_controller->statusbuf); 2626 kfree(udc->statusbuf);
2696err4: 2627err4:
2697 kfree(udc_controller->nullbuf); 2628 kfree(udc->nullbuf);
2698err3: 2629err3:
2699 ep = &udc_controller->eps[0]; 2630 ep = &udc->eps[0];
2700 cpm_muram_free(cpm_muram_offset(ep->rxbase)); 2631 cpm_muram_free(cpm_muram_offset(ep->rxbase));
2701 kfree(ep->rxframe); 2632 kfree(ep->rxframe);
2702 kfree(ep->rxbuffer); 2633 kfree(ep->rxbuffer);
2703 kfree(ep->txframe); 2634 kfree(ep->txframe);
2704err2: 2635err2:
2705 iounmap(udc_controller->usb_regs); 2636 iounmap(udc->usb_regs);
2706err1: 2637err1:
2707 kfree(udc_controller); 2638 kfree(udc);
2708 udc_controller = NULL;
2709 return ret; 2639 return ret;
2710} 2640}
2711 2641
@@ -2723,44 +2653,41 @@ static int qe_udc_resume(struct platform_device *dev)
2723 2653
2724static int __devexit qe_udc_remove(struct platform_device *ofdev) 2654static int __devexit qe_udc_remove(struct platform_device *ofdev)
2725{ 2655{
2656 struct qe_udc *udc = dev_get_drvdata(&ofdev->dev);
2726 struct qe_ep *ep; 2657 struct qe_ep *ep;
2727 unsigned int size; 2658 unsigned int size;
2728
2729 DECLARE_COMPLETION(done); 2659 DECLARE_COMPLETION(done);
2730 2660
2731 if (!udc_controller) 2661 usb_del_gadget_udc(&udc->gadget);
2732 return -ENODEV;
2733
2734 usb_del_gadget_udc(&udc_controller->gadget);
2735 2662
2736 udc_controller->done = &done; 2663 udc->done = &done;
2737 tasklet_disable(&udc_controller->rx_tasklet); 2664 tasklet_disable(&udc->rx_tasklet);
2738 2665
2739 if (udc_controller->nullmap) { 2666 if (udc->nullmap) {
2740 dma_unmap_single(udc_controller->gadget.dev.parent, 2667 dma_unmap_single(udc->gadget.dev.parent,
2741 udc_controller->nullp, 256, 2668 udc->nullp, 256,
2742 DMA_TO_DEVICE); 2669 DMA_TO_DEVICE);
2743 udc_controller->nullp = DMA_ADDR_INVALID; 2670 udc->nullp = DMA_ADDR_INVALID;
2744 } else { 2671 } else {
2745 dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, 2672 dma_sync_single_for_cpu(udc->gadget.dev.parent,
2746 udc_controller->nullp, 256, 2673 udc->nullp, 256,
2747 DMA_TO_DEVICE); 2674 DMA_TO_DEVICE);
2748 } 2675 }
2749 kfree(udc_controller->statusbuf); 2676 kfree(udc->statusbuf);
2750 kfree(udc_controller->nullbuf); 2677 kfree(udc->nullbuf);
2751 2678
2752 ep = &udc_controller->eps[0]; 2679 ep = &udc->eps[0];
2753 cpm_muram_free(cpm_muram_offset(ep->rxbase)); 2680 cpm_muram_free(cpm_muram_offset(ep->rxbase));
2754 size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (USB_BDRING_LEN + 1); 2681 size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (USB_BDRING_LEN + 1);
2755 2682
2756 kfree(ep->rxframe); 2683 kfree(ep->rxframe);
2757 if (ep->rxbufmap) { 2684 if (ep->rxbufmap) {
2758 dma_unmap_single(udc_controller->gadget.dev.parent, 2685 dma_unmap_single(udc->gadget.dev.parent,
2759 ep->rxbuf_d, size, 2686 ep->rxbuf_d, size,
2760 DMA_FROM_DEVICE); 2687 DMA_FROM_DEVICE);
2761 ep->rxbuf_d = DMA_ADDR_INVALID; 2688 ep->rxbuf_d = DMA_ADDR_INVALID;
2762 } else { 2689 } else {
2763 dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, 2690 dma_sync_single_for_cpu(udc->gadget.dev.parent,
2764 ep->rxbuf_d, size, 2691 ep->rxbuf_d, size,
2765 DMA_FROM_DEVICE); 2692 DMA_FROM_DEVICE);
2766 } 2693 }
@@ -2768,14 +2695,14 @@ static int __devexit qe_udc_remove(struct platform_device *ofdev)
2768 kfree(ep->rxbuffer); 2695 kfree(ep->rxbuffer);
2769 kfree(ep->txframe); 2696 kfree(ep->txframe);
2770 2697
2771 free_irq(udc_controller->usb_irq, udc_controller); 2698 free_irq(udc->usb_irq, udc);
2772 irq_dispose_mapping(udc_controller->usb_irq); 2699 irq_dispose_mapping(udc->usb_irq);
2773 2700
2774 tasklet_kill(&udc_controller->rx_tasklet); 2701 tasklet_kill(&udc->rx_tasklet);
2775 2702
2776 iounmap(udc_controller->usb_regs); 2703 iounmap(udc->usb_regs);
2777 2704
2778 device_unregister(&udc_controller->gadget.dev); 2705 device_unregister(&udc->gadget.dev);
2779 /* wait for release() of gadget.dev to free udc */ 2706 /* wait for release() of gadget.dev to free udc */
2780 wait_for_completion(&done); 2707 wait_for_completion(&done);
2781 2708