| .. | .. |
|---|
| 24 | 24 | #include <linux/module.h> |
|---|
| 25 | 25 | #include <linux/of.h> |
|---|
| 26 | 26 | #include <linux/platform_device.h> |
|---|
| 27 | +#include <linux/prefetch.h> |
|---|
| 27 | 28 | #include <linux/proc_fs.h> |
|---|
| 28 | 29 | #include <linux/slab.h> |
|---|
| 29 | 30 | #include <linux/usb/ch9.h> |
|---|
| .. | .. |
|---|
| 34 | 35 | #include <linux/debugfs.h> |
|---|
| 35 | 36 | #include <linux/seq_file.h> |
|---|
| 36 | 37 | #endif |
|---|
| 37 | | - |
|---|
| 38 | | -#include <mach/hardware.h> |
|---|
| 39 | 38 | |
|---|
| 40 | 39 | /* |
|---|
| 41 | 40 | * USB device configuration structure |
|---|
| .. | .. |
|---|
| 115 | 114 | bool wedge; |
|---|
| 116 | 115 | }; |
|---|
| 117 | 116 | |
|---|
| 117 | +enum atx_type { |
|---|
| 118 | + ISP1301, |
|---|
| 119 | + STOTG04, |
|---|
| 120 | +}; |
|---|
| 121 | + |
|---|
| 118 | 122 | /* |
|---|
| 119 | 123 | * Common UDC structure |
|---|
| 120 | 124 | */ |
|---|
| .. | .. |
|---|
| 129 | 133 | |
|---|
| 130 | 134 | /* Board and device specific */ |
|---|
| 131 | 135 | struct lpc32xx_usbd_cfg *board; |
|---|
| 132 | | - u32 io_p_start; |
|---|
| 133 | | - u32 io_p_size; |
|---|
| 134 | 136 | void __iomem *udp_baseaddr; |
|---|
| 135 | 137 | int udp_irq[4]; |
|---|
| 136 | 138 | struct clk *usb_slv_clk; |
|---|
| .. | .. |
|---|
| 151 | 153 | u8 last_vbus; |
|---|
| 152 | 154 | int pullup; |
|---|
| 153 | 155 | int poweron; |
|---|
| 156 | + enum atx_type atx; |
|---|
| 154 | 157 | |
|---|
| 155 | 158 | /* Work queues related to I2C support */ |
|---|
| 156 | 159 | struct work_struct pullup_job; |
|---|
| 157 | | - struct work_struct vbus_job; |
|---|
| 158 | 160 | struct work_struct power_job; |
|---|
| 159 | 161 | |
|---|
| 160 | 162 | /* USB device peripheral - various */ |
|---|
| .. | .. |
|---|
| 493 | 495 | } |
|---|
| 494 | 496 | } |
|---|
| 495 | 497 | |
|---|
| 496 | | -static int proc_udc_show(struct seq_file *s, void *unused) |
|---|
| 498 | +static int udc_show(struct seq_file *s, void *unused) |
|---|
| 497 | 499 | { |
|---|
| 498 | 500 | struct lpc32xx_udc *udc = s->private; |
|---|
| 499 | 501 | struct lpc32xx_ep *ep; |
|---|
| .. | .. |
|---|
| 522 | 524 | return 0; |
|---|
| 523 | 525 | } |
|---|
| 524 | 526 | |
|---|
| 525 | | -static int proc_udc_open(struct inode *inode, struct file *file) |
|---|
| 526 | | -{ |
|---|
| 527 | | - return single_open(file, proc_udc_show, PDE_DATA(inode)); |
|---|
| 528 | | -} |
|---|
| 529 | | - |
|---|
| 530 | | -static const struct file_operations proc_ops = { |
|---|
| 531 | | - .owner = THIS_MODULE, |
|---|
| 532 | | - .open = proc_udc_open, |
|---|
| 533 | | - .read = seq_read, |
|---|
| 534 | | - .llseek = seq_lseek, |
|---|
| 535 | | - .release = single_release, |
|---|
| 536 | | -}; |
|---|
| 527 | +DEFINE_SHOW_ATTRIBUTE(udc); |
|---|
| 537 | 528 | |
|---|
| 538 | 529 | static void create_debug_file(struct lpc32xx_udc *udc) |
|---|
| 539 | 530 | { |
|---|
| 540 | | - udc->pde = debugfs_create_file(debug_filename, 0, NULL, udc, &proc_ops); |
|---|
| 531 | + udc->pde = debugfs_create_file(debug_filename, 0, NULL, udc, &udc_fops); |
|---|
| 541 | 532 | } |
|---|
| 542 | 533 | |
|---|
| 543 | 534 | static void remove_debug_file(struct lpc32xx_udc *udc) |
|---|
| .. | .. |
|---|
| 553 | 544 | /* Primary initialization sequence for the ISP1301 transceiver */ |
|---|
| 554 | 545 | static void isp1301_udc_configure(struct lpc32xx_udc *udc) |
|---|
| 555 | 546 | { |
|---|
| 547 | + u8 value; |
|---|
| 548 | + s32 vendor, product; |
|---|
| 549 | + |
|---|
| 550 | + vendor = i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00); |
|---|
| 551 | + product = i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x02); |
|---|
| 552 | + |
|---|
| 553 | + if (vendor == 0x0483 && product == 0xa0c4) |
|---|
| 554 | + udc->atx = STOTG04; |
|---|
| 555 | + |
|---|
| 556 | 556 | /* LPC32XX only supports DAT_SE0 USB mode */ |
|---|
| 557 | 557 | /* This sequence is important */ |
|---|
| 558 | 558 | |
|---|
| .. | .. |
|---|
| 572 | 572 | */ |
|---|
| 573 | 573 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 574 | 574 | (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR), ~0); |
|---|
| 575 | + |
|---|
| 576 | + value = MC2_BI_DI; |
|---|
| 577 | + if (udc->atx != STOTG04) |
|---|
| 578 | + value |= MC2_SPD_SUSP_CTRL; |
|---|
| 575 | 579 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 576 | | - ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_SPD_SUSP_CTRL)); |
|---|
| 580 | + ISP1301_I2C_MODE_CONTROL_2, value); |
|---|
| 577 | 581 | |
|---|
| 578 | 582 | /* Driver VBUS_DRV high or low depending on board setup */ |
|---|
| 579 | 583 | if (udc->board->vbus_drv_pol != 0) |
|---|
| .. | .. |
|---|
| 601 | 605 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), |
|---|
| 602 | 606 | OTG1_VBUS_DISCHRG); |
|---|
| 603 | 607 | |
|---|
| 604 | | - /* Clear and enable VBUS high edge interrupt */ |
|---|
| 605 | 608 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 606 | 609 | ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
|---|
| 610 | + |
|---|
| 607 | 611 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 608 | 612 | ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
|---|
| 609 | 613 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 610 | | - ISP1301_I2C_INTERRUPT_FALLING, INT_VBUS_VLD); |
|---|
| 611 | | - i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 612 | 614 | ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
|---|
| 613 | | - i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 614 | | - ISP1301_I2C_INTERRUPT_RISING, INT_VBUS_VLD); |
|---|
| 615 | 615 | |
|---|
| 616 | | - dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n", |
|---|
| 617 | | - i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00)); |
|---|
| 618 | | - dev_info(udc->dev, "ISP1301 Product ID : 0x%04x\n", |
|---|
| 619 | | - i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x02)); |
|---|
| 616 | + dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n", vendor); |
|---|
| 617 | + dev_info(udc->dev, "ISP1301 Product ID : 0x%04x\n", product); |
|---|
| 620 | 618 | dev_info(udc->dev, "ISP1301 Version ID : 0x%04x\n", |
|---|
| 621 | 619 | i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x14)); |
|---|
| 620 | + |
|---|
| 622 | 621 | } |
|---|
| 623 | 622 | |
|---|
| 624 | 623 | /* Enables or disables the USB device pullup via the ISP1301 transceiver */ |
|---|
| .. | .. |
|---|
| 661 | 660 | /* Powers up or down the ISP1301 transceiver */ |
|---|
| 662 | 661 | static void isp1301_set_powerstate(struct lpc32xx_udc *udc, int enable) |
|---|
| 663 | 662 | { |
|---|
| 663 | + /* There is no "global power down" register for stotg04 */ |
|---|
| 664 | + if (udc->atx == STOTG04) |
|---|
| 665 | + return; |
|---|
| 666 | + |
|---|
| 664 | 667 | if (enable != 0) |
|---|
| 665 | 668 | /* Power up ISP1301 - this ISP1301 will automatically wakeup |
|---|
| 666 | 669 | when VBUS is detected */ |
|---|
| .. | .. |
|---|
| 727 | 730 | * response data */ |
|---|
| 728 | 731 | static u32 udc_protocol_cmd_r(struct lpc32xx_udc *udc, u32 cmd) |
|---|
| 729 | 732 | { |
|---|
| 730 | | - u32 tmp; |
|---|
| 731 | 733 | int to = 1000; |
|---|
| 732 | 734 | |
|---|
| 733 | 735 | /* Write a command and read data from the protocol engine */ |
|---|
| .. | .. |
|---|
| 737 | 739 | /* Write command code */ |
|---|
| 738 | 740 | udc_protocol_cmd_w(udc, cmd); |
|---|
| 739 | 741 | |
|---|
| 740 | | - tmp = readl(USBD_DEVINTST(udc->udp_baseaddr)); |
|---|
| 741 | 742 | while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & USBD_CDFULL)) |
|---|
| 742 | 743 | && (to > 0)) |
|---|
| 743 | 744 | to--; |
|---|
| .. | .. |
|---|
| 1139 | 1140 | u32 *p32, tmp, cbytes; |
|---|
| 1140 | 1141 | |
|---|
| 1141 | 1142 | /* Use optimal data transfer method based on source address and size */ |
|---|
| 1142 | | - switch (((u32) data) & 0x3) { |
|---|
| 1143 | + switch (((uintptr_t) data) & 0x3) { |
|---|
| 1143 | 1144 | case 0: /* 32-bit aligned */ |
|---|
| 1144 | 1145 | p32 = (u32 *) data; |
|---|
| 1145 | 1146 | cbytes = (bytes & ~0x3); |
|---|
| .. | .. |
|---|
| 1240 | 1241 | u32 *p32, tmp, cbytes; |
|---|
| 1241 | 1242 | |
|---|
| 1242 | 1243 | /* Use optimal data transfer method based on source address and size */ |
|---|
| 1243 | | - switch (((u32) data) & 0x3) { |
|---|
| 1244 | + switch (((uintptr_t) data) & 0x3) { |
|---|
| 1244 | 1245 | case 0: /* 32-bit aligned */ |
|---|
| 1245 | 1246 | p32 = (u32 *) data; |
|---|
| 1246 | 1247 | cbytes = (bytes & ~0x3); |
|---|
| .. | .. |
|---|
| 1914 | 1915 | }; |
|---|
| 1915 | 1916 | |
|---|
| 1916 | 1917 | /* Send a ZLP on a non-0 IN EP */ |
|---|
| 1917 | | -void udc_send_in_zlp(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) |
|---|
| 1918 | +static void udc_send_in_zlp(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) |
|---|
| 1918 | 1919 | { |
|---|
| 1919 | 1920 | /* Clear EP status */ |
|---|
| 1920 | 1921 | udc_clearep_getsts(udc, ep->hwep_num); |
|---|
| .. | .. |
|---|
| 1928 | 1929 | * This function will only be called when a delayed ZLP needs to be sent out |
|---|
| 1929 | 1930 | * after a DMA transfer has filled both buffers. |
|---|
| 1930 | 1931 | */ |
|---|
| 1931 | | -void udc_handle_eps(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) |
|---|
| 1932 | +static void udc_handle_eps(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) |
|---|
| 1932 | 1933 | { |
|---|
| 1933 | 1934 | u32 epstatus; |
|---|
| 1934 | 1935 | struct lpc32xx_request *req; |
|---|
| .. | .. |
|---|
| 1978 | 1979 | /* DMA end of transfer completion */ |
|---|
| 1979 | 1980 | static void udc_handle_dma_ep(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) |
|---|
| 1980 | 1981 | { |
|---|
| 1981 | | - u32 status, epstatus; |
|---|
| 1982 | + u32 status; |
|---|
| 1982 | 1983 | struct lpc32xx_request *req; |
|---|
| 1983 | 1984 | struct lpc32xx_usbd_dd_gad *dd; |
|---|
| 1984 | 1985 | |
|---|
| .. | .. |
|---|
| 2072 | 2073 | if (udc_clearep_getsts(udc, ep->hwep_num) & EP_SEL_F) { |
|---|
| 2073 | 2074 | udc_clearep_getsts(udc, ep->hwep_num); |
|---|
| 2074 | 2075 | uda_enable_hwepint(udc, ep->hwep_num); |
|---|
| 2075 | | - epstatus = udc_clearep_getsts(udc, ep->hwep_num); |
|---|
| 2076 | + udc_clearep_getsts(udc, ep->hwep_num); |
|---|
| 2076 | 2077 | |
|---|
| 2077 | 2078 | /* Let the EP interrupt handle the ZLP */ |
|---|
| 2078 | 2079 | return; |
|---|
| .. | .. |
|---|
| 2184 | 2185 | struct lpc32xx_ep *ep, *ep0 = &udc->ep[0]; |
|---|
| 2185 | 2186 | struct usb_ctrlrequest ctrlpkt; |
|---|
| 2186 | 2187 | int i, bytes; |
|---|
| 2187 | | - u16 wIndex, wValue, wLength, reqtype, req, tmp; |
|---|
| 2188 | + u16 wIndex, wValue, reqtype, req, tmp; |
|---|
| 2188 | 2189 | |
|---|
| 2189 | 2190 | /* Nuke previous transfers */ |
|---|
| 2190 | 2191 | nuke(ep0, -EPROTO); |
|---|
| .. | .. |
|---|
| 2200 | 2201 | /* Native endianness */ |
|---|
| 2201 | 2202 | wIndex = le16_to_cpu(ctrlpkt.wIndex); |
|---|
| 2202 | 2203 | wValue = le16_to_cpu(ctrlpkt.wValue); |
|---|
| 2203 | | - wLength = le16_to_cpu(ctrlpkt.wLength); |
|---|
| 2204 | 2204 | reqtype = le16_to_cpu(ctrlpkt.bRequestType); |
|---|
| 2205 | 2205 | |
|---|
| 2206 | 2206 | /* Set direction of EP0 */ |
|---|
| .. | .. |
|---|
| 2251 | 2251 | default: |
|---|
| 2252 | 2252 | break; |
|---|
| 2253 | 2253 | } |
|---|
| 2254 | | - |
|---|
| 2254 | + break; |
|---|
| 2255 | 2255 | |
|---|
| 2256 | 2256 | case USB_REQ_SET_ADDRESS: |
|---|
| 2257 | 2257 | if (reqtype == (USB_TYPE_STANDARD | USB_RECIP_DEVICE)) { |
|---|
| .. | .. |
|---|
| 2830 | 2830 | * VBUS detection, pullup handler, and Gadget cable state notification |
|---|
| 2831 | 2831 | * |
|---|
| 2832 | 2832 | */ |
|---|
| 2833 | | -static void vbus_work(struct work_struct *work) |
|---|
| 2833 | +static void vbus_work(struct lpc32xx_udc *udc) |
|---|
| 2834 | 2834 | { |
|---|
| 2835 | 2835 | u8 value; |
|---|
| 2836 | | - struct lpc32xx_udc *udc = container_of(work, struct lpc32xx_udc, |
|---|
| 2837 | | - vbus_job); |
|---|
| 2838 | 2836 | |
|---|
| 2839 | 2837 | if (udc->enabled != 0) { |
|---|
| 2840 | 2838 | /* Discharge VBUS real quick */ |
|---|
| .. | .. |
|---|
| 2870 | 2868 | lpc32xx_vbus_session(&udc->gadget, udc->vbus); |
|---|
| 2871 | 2869 | } |
|---|
| 2872 | 2870 | } |
|---|
| 2873 | | - |
|---|
| 2874 | | - /* Re-enable after completion */ |
|---|
| 2875 | | - enable_irq(udc->udp_irq[IRQ_USB_ATX]); |
|---|
| 2876 | 2871 | } |
|---|
| 2877 | 2872 | |
|---|
| 2878 | 2873 | static irqreturn_t lpc32xx_usb_vbus_irq(int irq, void *_udc) |
|---|
| 2879 | 2874 | { |
|---|
| 2880 | 2875 | struct lpc32xx_udc *udc = _udc; |
|---|
| 2881 | 2876 | |
|---|
| 2882 | | - /* Defer handling of VBUS IRQ to work queue */ |
|---|
| 2883 | | - disable_irq_nosync(udc->udp_irq[IRQ_USB_ATX]); |
|---|
| 2884 | | - schedule_work(&udc->vbus_job); |
|---|
| 2877 | + vbus_work(udc); |
|---|
| 2885 | 2878 | |
|---|
| 2886 | 2879 | return IRQ_HANDLED; |
|---|
| 2887 | 2880 | } |
|---|
| .. | .. |
|---|
| 2890 | 2883 | struct usb_gadget_driver *driver) |
|---|
| 2891 | 2884 | { |
|---|
| 2892 | 2885 | struct lpc32xx_udc *udc = to_udc(gadget); |
|---|
| 2893 | | - int i; |
|---|
| 2894 | 2886 | |
|---|
| 2895 | 2887 | if (!driver || driver->max_speed < USB_SPEED_FULL || !driver->setup) { |
|---|
| 2896 | 2888 | dev_err(udc->dev, "bad parameter.\n"); |
|---|
| .. | .. |
|---|
| 2910 | 2902 | |
|---|
| 2911 | 2903 | /* Force VBUS process once to check for cable insertion */ |
|---|
| 2912 | 2904 | udc->last_vbus = udc->vbus = 0; |
|---|
| 2913 | | - schedule_work(&udc->vbus_job); |
|---|
| 2905 | + vbus_work(udc); |
|---|
| 2914 | 2906 | |
|---|
| 2915 | | - /* Do not re-enable ATX IRQ (3) */ |
|---|
| 2916 | | - for (i = IRQ_USB_LP; i < IRQ_USB_ATX; i++) |
|---|
| 2917 | | - enable_irq(udc->udp_irq[i]); |
|---|
| 2907 | + /* enable interrupts */ |
|---|
| 2908 | + i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 2909 | + ISP1301_I2C_INTERRUPT_FALLING, INT_SESS_VLD | INT_VBUS_VLD); |
|---|
| 2910 | + i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 2911 | + ISP1301_I2C_INTERRUPT_RISING, INT_SESS_VLD | INT_VBUS_VLD); |
|---|
| 2918 | 2912 | |
|---|
| 2919 | 2913 | return 0; |
|---|
| 2920 | 2914 | } |
|---|
| 2921 | 2915 | |
|---|
| 2922 | 2916 | static int lpc32xx_stop(struct usb_gadget *gadget) |
|---|
| 2923 | 2917 | { |
|---|
| 2924 | | - int i; |
|---|
| 2925 | 2918 | struct lpc32xx_udc *udc = to_udc(gadget); |
|---|
| 2926 | 2919 | |
|---|
| 2927 | | - for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) |
|---|
| 2928 | | - disable_irq(udc->udp_irq[i]); |
|---|
| 2920 | + i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 2921 | + ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
|---|
| 2922 | + i2c_smbus_write_byte_data(udc->isp1301_i2c_client, |
|---|
| 2923 | + ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); |
|---|
| 2929 | 2924 | |
|---|
| 2930 | 2925 | if (udc->clocked) { |
|---|
| 2931 | 2926 | spin_lock(&udc->lock); |
|---|
| .. | .. |
|---|
| 2980 | 2975 | /* Enable or disable USB remote wakeup */ |
|---|
| 2981 | 2976 | } |
|---|
| 2982 | 2977 | |
|---|
| 2983 | | -struct lpc32xx_usbd_cfg lpc32xx_usbddata = { |
|---|
| 2978 | +static struct lpc32xx_usbd_cfg lpc32xx_usbddata = { |
|---|
| 2984 | 2979 | .vbus_drv_pol = 0, |
|---|
| 2985 | 2980 | .conn_chgb = &lpc32xx_usbd_conn_chg, |
|---|
| 2986 | 2981 | .susp_chgb = &lpc32xx_usbd_susp_chg, |
|---|
| .. | .. |
|---|
| 2995 | 2990 | struct device *dev = &pdev->dev; |
|---|
| 2996 | 2991 | struct lpc32xx_udc *udc; |
|---|
| 2997 | 2992 | int retval, i; |
|---|
| 2998 | | - struct resource *res; |
|---|
| 2999 | 2993 | dma_addr_t dma_handle; |
|---|
| 3000 | 2994 | struct device_node *isp1301_node; |
|---|
| 3001 | 2995 | |
|---|
| 3002 | | - udc = kmemdup(&controller_template, sizeof(*udc), GFP_KERNEL); |
|---|
| 2996 | + udc = devm_kmemdup(dev, &controller_template, sizeof(*udc), GFP_KERNEL); |
|---|
| 3003 | 2997 | if (!udc) |
|---|
| 3004 | 2998 | return -ENOMEM; |
|---|
| 3005 | 2999 | |
|---|
| .. | .. |
|---|
| 3021 | 3015 | } |
|---|
| 3022 | 3016 | |
|---|
| 3023 | 3017 | udc->isp1301_i2c_client = isp1301_get_client(isp1301_node); |
|---|
| 3018 | + of_node_put(isp1301_node); |
|---|
| 3024 | 3019 | if (!udc->isp1301_i2c_client) { |
|---|
| 3025 | | - retval = -EPROBE_DEFER; |
|---|
| 3026 | | - goto phy_fail; |
|---|
| 3020 | + return -EPROBE_DEFER; |
|---|
| 3027 | 3021 | } |
|---|
| 3028 | 3022 | |
|---|
| 3029 | 3023 | dev_info(udc->dev, "ISP1301 I2C device at address 0x%x\n", |
|---|
| .. | .. |
|---|
| 3032 | 3026 | pdev->dev.dma_mask = &lpc32xx_usbd_dmamask; |
|---|
| 3033 | 3027 | retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 3034 | 3028 | if (retval) |
|---|
| 3035 | | - goto resource_fail; |
|---|
| 3029 | + return retval; |
|---|
| 3036 | 3030 | |
|---|
| 3037 | 3031 | udc->board = &lpc32xx_usbddata; |
|---|
| 3038 | 3032 | |
|---|
| .. | .. |
|---|
| 3044 | 3038 | * IORESOURCE_IRQ, USB device interrupt number |
|---|
| 3045 | 3039 | * IORESOURCE_IRQ, USB transceiver interrupt number |
|---|
| 3046 | 3040 | */ |
|---|
| 3047 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 3048 | | - if (!res) { |
|---|
| 3049 | | - retval = -ENXIO; |
|---|
| 3050 | | - goto resource_fail; |
|---|
| 3051 | | - } |
|---|
| 3052 | 3041 | |
|---|
| 3053 | 3042 | spin_lock_init(&udc->lock); |
|---|
| 3054 | 3043 | |
|---|
| 3055 | 3044 | /* Get IRQs */ |
|---|
| 3056 | 3045 | for (i = 0; i < 4; i++) { |
|---|
| 3057 | 3046 | udc->udp_irq[i] = platform_get_irq(pdev, i); |
|---|
| 3058 | | - if (udc->udp_irq[i] < 0) { |
|---|
| 3059 | | - dev_err(udc->dev, |
|---|
| 3060 | | - "irq resource %d not available!\n", i); |
|---|
| 3061 | | - retval = udc->udp_irq[i]; |
|---|
| 3062 | | - goto irq_fail; |
|---|
| 3063 | | - } |
|---|
| 3047 | + if (udc->udp_irq[i] < 0) |
|---|
| 3048 | + return udc->udp_irq[i]; |
|---|
| 3064 | 3049 | } |
|---|
| 3065 | 3050 | |
|---|
| 3066 | | - udc->io_p_start = res->start; |
|---|
| 3067 | | - udc->io_p_size = resource_size(res); |
|---|
| 3068 | | - if (!request_mem_region(udc->io_p_start, udc->io_p_size, driver_name)) { |
|---|
| 3069 | | - dev_err(udc->dev, "someone's using UDC memory\n"); |
|---|
| 3070 | | - retval = -EBUSY; |
|---|
| 3071 | | - goto request_mem_region_fail; |
|---|
| 3072 | | - } |
|---|
| 3073 | | - |
|---|
| 3074 | | - udc->udp_baseaddr = ioremap(udc->io_p_start, udc->io_p_size); |
|---|
| 3075 | | - if (!udc->udp_baseaddr) { |
|---|
| 3076 | | - retval = -ENOMEM; |
|---|
| 3051 | + udc->udp_baseaddr = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 3052 | + if (IS_ERR(udc->udp_baseaddr)) { |
|---|
| 3077 | 3053 | dev_err(udc->dev, "IO map failure\n"); |
|---|
| 3078 | | - goto io_map_fail; |
|---|
| 3054 | + return PTR_ERR(udc->udp_baseaddr); |
|---|
| 3079 | 3055 | } |
|---|
| 3080 | 3056 | |
|---|
| 3081 | 3057 | /* Get USB device clock */ |
|---|
| 3082 | | - udc->usb_slv_clk = clk_get(&pdev->dev, NULL); |
|---|
| 3058 | + udc->usb_slv_clk = devm_clk_get(&pdev->dev, NULL); |
|---|
| 3083 | 3059 | if (IS_ERR(udc->usb_slv_clk)) { |
|---|
| 3084 | 3060 | dev_err(udc->dev, "failed to acquire USB device clock\n"); |
|---|
| 3085 | | - retval = PTR_ERR(udc->usb_slv_clk); |
|---|
| 3086 | | - goto usb_clk_get_fail; |
|---|
| 3061 | + return PTR_ERR(udc->usb_slv_clk); |
|---|
| 3087 | 3062 | } |
|---|
| 3088 | 3063 | |
|---|
| 3089 | 3064 | /* Enable USB device clock */ |
|---|
| 3090 | 3065 | retval = clk_prepare_enable(udc->usb_slv_clk); |
|---|
| 3091 | 3066 | if (retval < 0) { |
|---|
| 3092 | 3067 | dev_err(udc->dev, "failed to start USB device clock\n"); |
|---|
| 3093 | | - goto usb_clk_enable_fail; |
|---|
| 3068 | + return retval; |
|---|
| 3094 | 3069 | } |
|---|
| 3095 | 3070 | |
|---|
| 3096 | 3071 | /* Setup deferred workqueue data */ |
|---|
| 3097 | 3072 | udc->poweron = udc->pullup = 0; |
|---|
| 3098 | 3073 | INIT_WORK(&udc->pullup_job, pullup_work); |
|---|
| 3099 | | - INIT_WORK(&udc->vbus_job, vbus_work); |
|---|
| 3100 | 3074 | #ifdef CONFIG_PM |
|---|
| 3101 | 3075 | INIT_WORK(&udc->power_job, power_work); |
|---|
| 3102 | 3076 | #endif |
|---|
| .. | .. |
|---|
| 3134 | 3108 | |
|---|
| 3135 | 3109 | /* Request IRQs - low and high priority USB device IRQs are routed to |
|---|
| 3136 | 3110 | * the same handler, while the DMA interrupt is routed elsewhere */ |
|---|
| 3137 | | - retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq, |
|---|
| 3138 | | - 0, "udc_lp", udc); |
|---|
| 3111 | + retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_LP], |
|---|
| 3112 | + lpc32xx_usb_lp_irq, 0, "udc_lp", udc); |
|---|
| 3139 | 3113 | if (retval < 0) { |
|---|
| 3140 | 3114 | dev_err(udc->dev, "LP request irq %d failed\n", |
|---|
| 3141 | 3115 | udc->udp_irq[IRQ_USB_LP]); |
|---|
| 3142 | | - goto irq_lp_fail; |
|---|
| 3116 | + goto irq_req_fail; |
|---|
| 3143 | 3117 | } |
|---|
| 3144 | | - retval = request_irq(udc->udp_irq[IRQ_USB_HP], lpc32xx_usb_hp_irq, |
|---|
| 3145 | | - 0, "udc_hp", udc); |
|---|
| 3118 | + retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_HP], |
|---|
| 3119 | + lpc32xx_usb_hp_irq, 0, "udc_hp", udc); |
|---|
| 3146 | 3120 | if (retval < 0) { |
|---|
| 3147 | 3121 | dev_err(udc->dev, "HP request irq %d failed\n", |
|---|
| 3148 | 3122 | udc->udp_irq[IRQ_USB_HP]); |
|---|
| 3149 | | - goto irq_hp_fail; |
|---|
| 3123 | + goto irq_req_fail; |
|---|
| 3150 | 3124 | } |
|---|
| 3151 | 3125 | |
|---|
| 3152 | | - retval = request_irq(udc->udp_irq[IRQ_USB_DEVDMA], |
|---|
| 3153 | | - lpc32xx_usb_devdma_irq, 0, "udc_dma", udc); |
|---|
| 3126 | + retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_DEVDMA], |
|---|
| 3127 | + lpc32xx_usb_devdma_irq, 0, "udc_dma", udc); |
|---|
| 3154 | 3128 | if (retval < 0) { |
|---|
| 3155 | 3129 | dev_err(udc->dev, "DEV request irq %d failed\n", |
|---|
| 3156 | 3130 | udc->udp_irq[IRQ_USB_DEVDMA]); |
|---|
| 3157 | | - goto irq_dev_fail; |
|---|
| 3131 | + goto irq_req_fail; |
|---|
| 3158 | 3132 | } |
|---|
| 3159 | 3133 | |
|---|
| 3160 | 3134 | /* The transceiver interrupt is used for VBUS detection and will |
|---|
| 3161 | 3135 | kick off the VBUS handler function */ |
|---|
| 3162 | | - retval = request_irq(udc->udp_irq[IRQ_USB_ATX], lpc32xx_usb_vbus_irq, |
|---|
| 3163 | | - 0, "udc_otg", udc); |
|---|
| 3136 | + retval = devm_request_threaded_irq(dev, udc->udp_irq[IRQ_USB_ATX], NULL, |
|---|
| 3137 | + lpc32xx_usb_vbus_irq, IRQF_ONESHOT, |
|---|
| 3138 | + "udc_otg", udc); |
|---|
| 3164 | 3139 | if (retval < 0) { |
|---|
| 3165 | 3140 | dev_err(udc->dev, "VBUS request irq %d failed\n", |
|---|
| 3166 | 3141 | udc->udp_irq[IRQ_USB_ATX]); |
|---|
| 3167 | | - goto irq_xcvr_fail; |
|---|
| 3142 | + goto irq_req_fail; |
|---|
| 3168 | 3143 | } |
|---|
| 3169 | 3144 | |
|---|
| 3170 | 3145 | /* Initialize wait queue */ |
|---|
| 3171 | 3146 | init_waitqueue_head(&udc->ep_disable_wait_queue); |
|---|
| 3172 | 3147 | atomic_set(&udc->enabled_ep_cnt, 0); |
|---|
| 3173 | | - |
|---|
| 3174 | | - /* Keep all IRQs disabled until GadgetFS starts up */ |
|---|
| 3175 | | - for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) |
|---|
| 3176 | | - disable_irq(udc->udp_irq[i]); |
|---|
| 3177 | 3148 | |
|---|
| 3178 | 3149 | retval = usb_add_gadget_udc(dev, &udc->gadget); |
|---|
| 3179 | 3150 | if (retval < 0) |
|---|
| .. | .. |
|---|
| 3190 | 3161 | return 0; |
|---|
| 3191 | 3162 | |
|---|
| 3192 | 3163 | add_gadget_fail: |
|---|
| 3193 | | - free_irq(udc->udp_irq[IRQ_USB_ATX], udc); |
|---|
| 3194 | | -irq_xcvr_fail: |
|---|
| 3195 | | - free_irq(udc->udp_irq[IRQ_USB_DEVDMA], udc); |
|---|
| 3196 | | -irq_dev_fail: |
|---|
| 3197 | | - free_irq(udc->udp_irq[IRQ_USB_HP], udc); |
|---|
| 3198 | | -irq_hp_fail: |
|---|
| 3199 | | - free_irq(udc->udp_irq[IRQ_USB_LP], udc); |
|---|
| 3200 | | -irq_lp_fail: |
|---|
| 3164 | +irq_req_fail: |
|---|
| 3201 | 3165 | dma_pool_destroy(udc->dd_cache); |
|---|
| 3202 | 3166 | dma_alloc_fail: |
|---|
| 3203 | 3167 | dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, |
|---|
| 3204 | 3168 | udc->udca_v_base, udc->udca_p_base); |
|---|
| 3205 | 3169 | i2c_fail: |
|---|
| 3206 | 3170 | clk_disable_unprepare(udc->usb_slv_clk); |
|---|
| 3207 | | -usb_clk_enable_fail: |
|---|
| 3208 | | - clk_put(udc->usb_slv_clk); |
|---|
| 3209 | | -usb_clk_get_fail: |
|---|
| 3210 | | - iounmap(udc->udp_baseaddr); |
|---|
| 3211 | | -io_map_fail: |
|---|
| 3212 | | - release_mem_region(udc->io_p_start, udc->io_p_size); |
|---|
| 3213 | 3171 | dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval); |
|---|
| 3214 | | -request_mem_region_fail: |
|---|
| 3215 | | -irq_fail: |
|---|
| 3216 | | -resource_fail: |
|---|
| 3217 | | -phy_fail: |
|---|
| 3218 | | - kfree(udc); |
|---|
| 3172 | + |
|---|
| 3219 | 3173 | return retval; |
|---|
| 3220 | 3174 | } |
|---|
| 3221 | 3175 | |
|---|
| .. | .. |
|---|
| 3231 | 3185 | udc_disable(udc); |
|---|
| 3232 | 3186 | pullup(udc, 0); |
|---|
| 3233 | 3187 | |
|---|
| 3234 | | - free_irq(udc->udp_irq[IRQ_USB_ATX], udc); |
|---|
| 3235 | | - |
|---|
| 3236 | 3188 | device_init_wakeup(&pdev->dev, 0); |
|---|
| 3237 | 3189 | remove_debug_file(udc); |
|---|
| 3238 | 3190 | |
|---|
| 3239 | 3191 | dma_pool_destroy(udc->dd_cache); |
|---|
| 3240 | 3192 | dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, |
|---|
| 3241 | 3193 | udc->udca_v_base, udc->udca_p_base); |
|---|
| 3242 | | - free_irq(udc->udp_irq[IRQ_USB_DEVDMA], udc); |
|---|
| 3243 | | - free_irq(udc->udp_irq[IRQ_USB_HP], udc); |
|---|
| 3244 | | - free_irq(udc->udp_irq[IRQ_USB_LP], udc); |
|---|
| 3245 | 3194 | |
|---|
| 3246 | 3195 | clk_disable_unprepare(udc->usb_slv_clk); |
|---|
| 3247 | | - clk_put(udc->usb_slv_clk); |
|---|
| 3248 | | - |
|---|
| 3249 | | - iounmap(udc->udp_baseaddr); |
|---|
| 3250 | | - release_mem_region(udc->io_p_start, udc->io_p_size); |
|---|
| 3251 | | - kfree(udc); |
|---|
| 3252 | 3196 | |
|---|
| 3253 | 3197 | return 0; |
|---|
| 3254 | 3198 | } |
|---|
| .. | .. |
|---|
| 3314 | 3258 | .suspend = lpc32xx_udc_suspend, |
|---|
| 3315 | 3259 | .resume = lpc32xx_udc_resume, |
|---|
| 3316 | 3260 | .driver = { |
|---|
| 3317 | | - .name = (char *) driver_name, |
|---|
| 3261 | + .name = driver_name, |
|---|
| 3318 | 3262 | .of_match_table = of_match_ptr(lpc32xx_udc_of_match), |
|---|
| 3319 | 3263 | }, |
|---|
| 3320 | 3264 | }; |
|---|