Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/gadget/s3c_udc_otg.c |
| 3 | * Samsung S3C on-chip full/high speed USB OTG 2.0 device controllers |
| 4 | * |
| 5 | * Copyright (C) 2008 for Samsung Electronics |
| 6 | * |
| 7 | * BSP Support for Samsung's UDC driver |
| 8 | * available at: |
| 9 | * git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git |
| 10 | * |
| 11 | * State machine bugfixes: |
| 12 | * Marek Szyprowski <m.szyprowski@samsung.com> |
| 13 | * |
| 14 | * Ported to u-boot: |
| 15 | * Marek Szyprowski <m.szyprowski@samsung.com> |
| 16 | * Lukasz Majewski <l.majewski@samsumg.com> |
| 17 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 18 | * SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 19 | */ |
Lukasz Majewski | 8fb78fd | 2012-05-02 13:11:38 +0200 | [diff] [blame] | 20 | #undef DEBUG |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 21 | #include <common.h> |
| 22 | #include <asm/errno.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <malloc.h> |
| 25 | |
| 26 | #include <linux/usb/ch9.h> |
| 27 | #include <linux/usb/gadget.h> |
| 28 | |
| 29 | #include <asm/byteorder.h> |
Tom Rini | 7342452 | 2011-12-15 08:40:51 -0700 | [diff] [blame] | 30 | #include <asm/unaligned.h> |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 31 | #include <asm/io.h> |
| 32 | |
| 33 | #include <asm/mach-types.h> |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 34 | |
Marek Vasut | f64a25c | 2015-12-04 00:54:16 +0100 | [diff] [blame] | 35 | #include "s3c_udc_otg_regs.h" |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 36 | #include <usb/lin_gadget_compat.h> |
| 37 | |
| 38 | /***********************************************************/ |
| 39 | |
| 40 | #define OTG_DMA_MODE 1 |
| 41 | |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 42 | #define DEBUG_SETUP 0 |
| 43 | #define DEBUG_EP0 0 |
| 44 | #define DEBUG_ISR 0 |
| 45 | #define DEBUG_OUT_EP 0 |
| 46 | #define DEBUG_IN_EP 0 |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 47 | |
| 48 | #include <usb/s3c_udc.h> |
| 49 | |
| 50 | #define EP0_CON 0 |
| 51 | #define EP_MASK 0xF |
| 52 | |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 53 | static char *state_names[] = { |
| 54 | "WAIT_FOR_SETUP", |
| 55 | "DATA_STATE_XMIT", |
| 56 | "DATA_STATE_NEED_ZLP", |
| 57 | "WAIT_FOR_OUT_STATUS", |
| 58 | "DATA_STATE_RECV", |
| 59 | "WAIT_FOR_COMPLETE", |
| 60 | "WAIT_FOR_OUT_COMPLETE", |
| 61 | "WAIT_FOR_IN_COMPLETE", |
| 62 | "WAIT_FOR_NULL_COMPLETE", |
| 63 | }; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 64 | |
| 65 | #define DRIVER_DESC "S3C HS USB OTG Device Driver, (c) Samsung Electronics" |
| 66 | #define DRIVER_VERSION "15 March 2009" |
| 67 | |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 68 | struct dwc2_udc *the_controller; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 69 | |
| 70 | static const char driver_name[] = "s3c-udc"; |
| 71 | static const char driver_desc[] = DRIVER_DESC; |
| 72 | static const char ep0name[] = "ep0-control"; |
| 73 | |
| 74 | /* Max packet size*/ |
| 75 | static unsigned int ep0_fifo_size = 64; |
| 76 | static unsigned int ep_fifo_size = 512; |
| 77 | static unsigned int ep_fifo_size2 = 1024; |
| 78 | static int reset_available = 1; |
| 79 | |
| 80 | static struct usb_ctrlrequest *usb_ctrl; |
| 81 | static dma_addr_t usb_ctrl_dma_addr; |
| 82 | |
| 83 | /* |
| 84 | Local declarations. |
| 85 | */ |
| 86 | static int s3c_ep_enable(struct usb_ep *ep, |
| 87 | const struct usb_endpoint_descriptor *); |
| 88 | static int s3c_ep_disable(struct usb_ep *ep); |
| 89 | static struct usb_request *s3c_alloc_request(struct usb_ep *ep, |
| 90 | gfp_t gfp_flags); |
| 91 | static void s3c_free_request(struct usb_ep *ep, struct usb_request *); |
| 92 | |
| 93 | static int s3c_queue(struct usb_ep *ep, struct usb_request *, gfp_t gfp_flags); |
| 94 | static int s3c_dequeue(struct usb_ep *ep, struct usb_request *); |
| 95 | static int s3c_fifo_status(struct usb_ep *ep); |
| 96 | static void s3c_fifo_flush(struct usb_ep *ep); |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 97 | static void s3c_ep0_read(struct dwc2_udc *dev); |
| 98 | static void s3c_ep0_kick(struct dwc2_udc *dev, struct s3c_ep *ep); |
| 99 | static void s3c_handle_ep0(struct dwc2_udc *dev); |
| 100 | static int s3c_ep0_write(struct dwc2_udc *dev); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 101 | static int write_fifo_ep0(struct s3c_ep *ep, struct s3c_request *req); |
| 102 | static void done(struct s3c_ep *ep, struct s3c_request *req, int status); |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 103 | static void stop_activity(struct dwc2_udc *dev, |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 104 | struct usb_gadget_driver *driver); |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 105 | static int udc_enable(struct dwc2_udc *dev); |
| 106 | static void udc_set_address(struct dwc2_udc *dev, unsigned char address); |
| 107 | static void reconfig_usbd(struct dwc2_udc *dev); |
| 108 | static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 109 | static void nuke(struct s3c_ep *ep, int status); |
| 110 | static int s3c_udc_set_halt(struct usb_ep *_ep, int value); |
| 111 | static void s3c_udc_set_nak(struct s3c_ep *ep); |
| 112 | |
Lukasz Majewski | 8fb78fd | 2012-05-02 13:11:38 +0200 | [diff] [blame] | 113 | void set_udc_gadget_private_data(void *p) |
| 114 | { |
| 115 | debug_cond(DEBUG_SETUP != 0, |
| 116 | "%s: the_controller: 0x%p, p: 0x%p\n", __func__, |
| 117 | the_controller, p); |
| 118 | the_controller->gadget.dev.device_data = p; |
| 119 | } |
| 120 | |
| 121 | void *get_udc_gadget_private_data(struct usb_gadget *gadget) |
| 122 | { |
| 123 | return gadget->dev.device_data; |
| 124 | } |
| 125 | |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 126 | static struct usb_ep_ops s3c_ep_ops = { |
| 127 | .enable = s3c_ep_enable, |
| 128 | .disable = s3c_ep_disable, |
| 129 | |
| 130 | .alloc_request = s3c_alloc_request, |
| 131 | .free_request = s3c_free_request, |
| 132 | |
| 133 | .queue = s3c_queue, |
| 134 | .dequeue = s3c_dequeue, |
| 135 | |
| 136 | .set_halt = s3c_udc_set_halt, |
| 137 | .fifo_status = s3c_fifo_status, |
| 138 | .fifo_flush = s3c_fifo_flush, |
| 139 | }; |
| 140 | |
| 141 | #define create_proc_files() do {} while (0) |
| 142 | #define remove_proc_files() do {} while (0) |
| 143 | |
| 144 | /***********************************************************/ |
| 145 | |
| 146 | void __iomem *regs_otg; |
Marek Vasut | 67ec9dc | 2015-12-04 01:11:45 +0100 | [diff] [blame^] | 147 | struct dwc2_usbotg_reg *reg; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 148 | |
Lukasz Majewski | ef73102 | 2014-08-25 11:07:29 +0200 | [diff] [blame] | 149 | bool dfu_usb_get_reset(void) |
| 150 | { |
| 151 | return !!(readl(®->gintsts) & INT_RESET); |
| 152 | } |
| 153 | |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 154 | __weak void otg_phy_init(struct dwc2_udc *dev) {} |
| 155 | __weak void otg_phy_off(struct dwc2_udc *dev) {} |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 156 | |
| 157 | /***********************************************************/ |
| 158 | |
| 159 | #include "s3c_udc_otg_xfer_dma.c" |
| 160 | |
| 161 | /* |
| 162 | * udc_disable - disable USB device controller |
| 163 | */ |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 164 | static void udc_disable(struct dwc2_udc *dev) |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 165 | { |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 166 | debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 167 | |
| 168 | udc_set_address(dev, 0); |
| 169 | |
| 170 | dev->ep0state = WAIT_FOR_SETUP; |
| 171 | dev->gadget.speed = USB_SPEED_UNKNOWN; |
| 172 | dev->usb_address = 0; |
| 173 | |
| 174 | otg_phy_off(dev); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * udc_reinit - initialize software state |
| 179 | */ |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 180 | static void udc_reinit(struct dwc2_udc *dev) |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 181 | { |
| 182 | unsigned int i; |
| 183 | |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 184 | debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 185 | |
| 186 | /* device/ep0 records init */ |
| 187 | INIT_LIST_HEAD(&dev->gadget.ep_list); |
| 188 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); |
| 189 | dev->ep0state = WAIT_FOR_SETUP; |
| 190 | |
| 191 | /* basic endpoint records init */ |
| 192 | for (i = 0; i < S3C_MAX_ENDPOINTS; i++) { |
| 193 | struct s3c_ep *ep = &dev->ep[i]; |
| 194 | |
| 195 | if (i != 0) |
| 196 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); |
| 197 | |
| 198 | ep->desc = 0; |
| 199 | ep->stopped = 0; |
| 200 | INIT_LIST_HEAD(&ep->queue); |
| 201 | ep->pio_irqs = 0; |
| 202 | } |
| 203 | |
| 204 | /* the rest was statically initialized, and is read-only */ |
| 205 | } |
| 206 | |
| 207 | #define BYTES2MAXP(x) (x / 8) |
| 208 | #define MAXP2BYTES(x) (x * 8) |
| 209 | |
| 210 | /* until it's enabled, this UDC should be completely invisible |
| 211 | * to any USB host. |
| 212 | */ |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 213 | static int udc_enable(struct dwc2_udc *dev) |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 214 | { |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 215 | debug_cond(DEBUG_SETUP != 0, "%s: %p\n", __func__, dev); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 216 | |
| 217 | otg_phy_init(dev); |
Marek Vasut | 8030088 | 2014-11-04 04:23:25 +0100 | [diff] [blame] | 218 | reconfig_usbd(dev); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 219 | |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 220 | debug_cond(DEBUG_SETUP != 0, |
| 221 | "S3C USB 2.0 OTG Controller Core Initialized : 0x%x\n", |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 222 | readl(®->gintmsk)); |
| 223 | |
| 224 | dev->gadget.speed = USB_SPEED_UNKNOWN; |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | Register entry point for the peripheral controller driver. |
| 231 | */ |
| 232 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) |
| 233 | { |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 234 | struct dwc2_udc *dev = the_controller; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 235 | int retval = 0; |
Bo Shen | 60dc40c | 2014-08-27 17:28:18 +0800 | [diff] [blame] | 236 | unsigned long flags = 0; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 237 | |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 238 | debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name"); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 239 | |
| 240 | if (!driver |
| 241 | || (driver->speed != USB_SPEED_FULL |
| 242 | && driver->speed != USB_SPEED_HIGH) |
| 243 | || !driver->bind || !driver->disconnect || !driver->setup) |
| 244 | return -EINVAL; |
| 245 | if (!dev) |
| 246 | return -ENODEV; |
| 247 | if (dev->driver) |
| 248 | return -EBUSY; |
| 249 | |
| 250 | spin_lock_irqsave(&dev->lock, flags); |
| 251 | /* first hook up the driver ... */ |
| 252 | dev->driver = driver; |
| 253 | spin_unlock_irqrestore(&dev->lock, flags); |
| 254 | |
| 255 | if (retval) { /* TODO */ |
| 256 | printf("target device_add failed, error %d\n", retval); |
| 257 | return retval; |
| 258 | } |
| 259 | |
| 260 | retval = driver->bind(&dev->gadget); |
| 261 | if (retval) { |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 262 | debug_cond(DEBUG_SETUP != 0, |
| 263 | "%s: bind to driver --> error %d\n", |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 264 | dev->gadget.name, retval); |
| 265 | dev->driver = 0; |
| 266 | return retval; |
| 267 | } |
| 268 | |
| 269 | enable_irq(IRQ_OTG); |
| 270 | |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 271 | debug_cond(DEBUG_SETUP != 0, |
| 272 | "Registered gadget driver %s\n", dev->gadget.name); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 273 | udc_enable(dev); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Unregister entry point for the peripheral controller driver. |
| 280 | */ |
| 281 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) |
| 282 | { |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 283 | struct dwc2_udc *dev = the_controller; |
Bo Shen | 60dc40c | 2014-08-27 17:28:18 +0800 | [diff] [blame] | 284 | unsigned long flags = 0; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 285 | |
| 286 | if (!dev) |
| 287 | return -ENODEV; |
| 288 | if (!driver || driver != dev->driver) |
| 289 | return -EINVAL; |
| 290 | |
| 291 | spin_lock_irqsave(&dev->lock, flags); |
| 292 | dev->driver = 0; |
| 293 | stop_activity(dev, driver); |
| 294 | spin_unlock_irqrestore(&dev->lock, flags); |
| 295 | |
| 296 | driver->unbind(&dev->gadget); |
| 297 | |
| 298 | disable_irq(IRQ_OTG); |
| 299 | |
| 300 | udc_disable(dev); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * done - retire a request; caller blocked irqs |
| 306 | */ |
| 307 | static void done(struct s3c_ep *ep, struct s3c_request *req, int status) |
| 308 | { |
| 309 | unsigned int stopped = ep->stopped; |
| 310 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 311 | debug("%s: %s %p, req = %p, stopped = %d\n", |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 312 | __func__, ep->ep.name, ep, &req->req, stopped); |
| 313 | |
| 314 | list_del_init(&req->queue); |
| 315 | |
| 316 | if (likely(req->req.status == -EINPROGRESS)) |
| 317 | req->req.status = status; |
| 318 | else |
| 319 | status = req->req.status; |
| 320 | |
| 321 | if (status && status != -ESHUTDOWN) { |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 322 | debug("complete %s req %p stat %d len %u/%u\n", |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 323 | ep->ep.name, &req->req, status, |
| 324 | req->req.actual, req->req.length); |
| 325 | } |
| 326 | |
| 327 | /* don't modify queue heads during completion callback */ |
| 328 | ep->stopped = 1; |
| 329 | |
Lukasz Majewski | 0dfeb00 | 2012-05-02 13:11:35 +0200 | [diff] [blame] | 330 | #ifdef DEBUG |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 331 | printf("calling complete callback\n"); |
| 332 | { |
| 333 | int i, len = req->req.length; |
| 334 | |
| 335 | printf("pkt[%d] = ", req->req.length); |
| 336 | if (len > 64) |
| 337 | len = 64; |
| 338 | for (i = 0; i < len; i++) { |
| 339 | printf("%02x", ((u8 *)req->req.buf)[i]); |
| 340 | if ((i & 7) == 7) |
| 341 | printf(" "); |
| 342 | } |
| 343 | printf("\n"); |
| 344 | } |
| 345 | #endif |
| 346 | spin_unlock(&ep->dev->lock); |
| 347 | req->req.complete(&ep->ep, &req->req); |
| 348 | spin_lock(&ep->dev->lock); |
| 349 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 350 | debug("callback completed\n"); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 351 | |
| 352 | ep->stopped = stopped; |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * nuke - dequeue ALL requests |
| 357 | */ |
| 358 | static void nuke(struct s3c_ep *ep, int status) |
| 359 | { |
| 360 | struct s3c_request *req; |
| 361 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 362 | debug("%s: %s %p\n", __func__, ep->ep.name, ep); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 363 | |
| 364 | /* called with irqs blocked */ |
| 365 | while (!list_empty(&ep->queue)) { |
| 366 | req = list_entry(ep->queue.next, struct s3c_request, queue); |
| 367 | done(ep, req, status); |
| 368 | } |
| 369 | } |
| 370 | |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 371 | static void stop_activity(struct dwc2_udc *dev, |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 372 | struct usb_gadget_driver *driver) |
| 373 | { |
| 374 | int i; |
| 375 | |
| 376 | /* don't disconnect drivers more than once */ |
| 377 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) |
| 378 | driver = 0; |
| 379 | dev->gadget.speed = USB_SPEED_UNKNOWN; |
| 380 | |
| 381 | /* prevent new request submissions, kill any outstanding requests */ |
| 382 | for (i = 0; i < S3C_MAX_ENDPOINTS; i++) { |
| 383 | struct s3c_ep *ep = &dev->ep[i]; |
| 384 | ep->stopped = 1; |
| 385 | nuke(ep, -ESHUTDOWN); |
| 386 | } |
| 387 | |
| 388 | /* report disconnect; the driver is already quiesced */ |
| 389 | if (driver) { |
| 390 | spin_unlock(&dev->lock); |
| 391 | driver->disconnect(&dev->gadget); |
| 392 | spin_lock(&dev->lock); |
| 393 | } |
| 394 | |
| 395 | /* re-init driver-visible data structures */ |
| 396 | udc_reinit(dev); |
| 397 | } |
| 398 | |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 399 | static void reconfig_usbd(struct dwc2_udc *dev) |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 400 | { |
| 401 | /* 2. Soft-reset OTG Core and then unreset again. */ |
| 402 | int i; |
| 403 | unsigned int uTemp = writel(CORE_SOFT_RESET, ®->grstctl); |
Marek Vasut | 8030088 | 2014-11-04 04:23:25 +0100 | [diff] [blame] | 404 | uint32_t dflt_gusbcfg; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 405 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 406 | debug("Reseting OTG controller\n"); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 407 | |
Marek Vasut | 8030088 | 2014-11-04 04:23:25 +0100 | [diff] [blame] | 408 | dflt_gusbcfg = |
| 409 | 0<<15 /* PHY Low Power Clock sel*/ |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 410 | |1<<14 /* Non-Periodic TxFIFO Rewind Enable*/ |
| 411 | |0x5<<10 /* Turnaround time*/ |
| 412 | |0<<9 | 0<<8 /* [0:HNP disable,1:HNP enable][ 0:SRP disable*/ |
| 413 | /* 1:SRP enable] H1= 1,1*/ |
| 414 | |0<<7 /* Ulpi DDR sel*/ |
| 415 | |0<<6 /* 0: high speed utmi+, 1: full speed serial*/ |
| 416 | |0<<4 /* 0: utmi+, 1:ulpi*/ |
| 417 | |1<<3 /* phy i/f 0:8bit, 1:16bit*/ |
Marek Vasut | 8030088 | 2014-11-04 04:23:25 +0100 | [diff] [blame] | 418 | |0x7<<0; /* HS/FS Timeout**/ |
| 419 | |
| 420 | if (dev->pdata->usb_gusbcfg) |
| 421 | dflt_gusbcfg = dev->pdata->usb_gusbcfg; |
| 422 | |
| 423 | writel(dflt_gusbcfg, ®->gusbcfg); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 424 | |
| 425 | /* 3. Put the OTG device core in the disconnected state.*/ |
| 426 | uTemp = readl(®->dctl); |
| 427 | uTemp |= SOFT_DISCONNECT; |
| 428 | writel(uTemp, ®->dctl); |
| 429 | |
| 430 | udelay(20); |
| 431 | |
| 432 | /* 4. Make the OTG device core exit from the disconnected state.*/ |
| 433 | uTemp = readl(®->dctl); |
| 434 | uTemp = uTemp & ~SOFT_DISCONNECT; |
| 435 | writel(uTemp, ®->dctl); |
| 436 | |
| 437 | /* 5. Configure OTG Core to initial settings of device mode.*/ |
| 438 | /* [][1: full speed(30Mhz) 0:high speed]*/ |
| 439 | writel(EP_MISS_CNT(1) | DEV_SPEED_HIGH_SPEED_20, ®->dcfg); |
| 440 | |
| 441 | mdelay(1); |
| 442 | |
| 443 | /* 6. Unmask the core interrupts*/ |
| 444 | writel(GINTMSK_INIT, ®->gintmsk); |
| 445 | |
| 446 | /* 7. Set NAK bit of EP0, EP1, EP2*/ |
| 447 | writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->out_endp[EP0_CON].doepctl); |
| 448 | writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->in_endp[EP0_CON].diepctl); |
| 449 | |
| 450 | for (i = 1; i < S3C_MAX_ENDPOINTS; i++) { |
| 451 | writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->out_endp[i].doepctl); |
| 452 | writel(DEPCTL_EPDIS|DEPCTL_SNAK, ®->in_endp[i].diepctl); |
| 453 | } |
| 454 | |
| 455 | /* 8. Unmask EPO interrupts*/ |
| 456 | writel(((1 << EP0_CON) << DAINT_OUT_BIT) |
| 457 | | (1 << EP0_CON), ®->daintmsk); |
| 458 | |
| 459 | /* 9. Unmask device OUT EP common interrupts*/ |
| 460 | writel(DOEPMSK_INIT, ®->doepmsk); |
| 461 | |
| 462 | /* 10. Unmask device IN EP common interrupts*/ |
| 463 | writel(DIEPMSK_INIT, ®->diepmsk); |
| 464 | |
| 465 | /* 11. Set Rx FIFO Size (in 32-bit words) */ |
| 466 | writel(RX_FIFO_SIZE >> 2, ®->grxfsiz); |
| 467 | |
| 468 | /* 12. Set Non Periodic Tx FIFO Size */ |
| 469 | writel((NPTX_FIFO_SIZE >> 2) << 16 | ((RX_FIFO_SIZE >> 2)) << 0, |
| 470 | ®->gnptxfsiz); |
| 471 | |
| 472 | for (i = 1; i < S3C_MAX_HW_ENDPOINTS; i++) |
| 473 | writel((PTX_FIFO_SIZE >> 2) << 16 | |
| 474 | ((RX_FIFO_SIZE + NPTX_FIFO_SIZE + |
| 475 | PTX_FIFO_SIZE*(i-1)) >> 2) << 0, |
| 476 | ®->dieptxf[i-1]); |
| 477 | |
| 478 | /* Flush the RX FIFO */ |
| 479 | writel(RX_FIFO_FLUSH, ®->grstctl); |
| 480 | while (readl(®->grstctl) & RX_FIFO_FLUSH) |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 481 | debug("%s: waiting for S3C_UDC_OTG_GRSTCTL\n", __func__); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 482 | |
| 483 | /* Flush all the Tx FIFO's */ |
| 484 | writel(TX_FIFO_FLUSH_ALL, ®->grstctl); |
| 485 | writel(TX_FIFO_FLUSH_ALL | TX_FIFO_FLUSH, ®->grstctl); |
| 486 | while (readl(®->grstctl) & TX_FIFO_FLUSH) |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 487 | debug("%s: waiting for S3C_UDC_OTG_GRSTCTL\n", __func__); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 488 | |
| 489 | /* 13. Clear NAK bit of EP0, EP1, EP2*/ |
| 490 | /* For Slave mode*/ |
| 491 | /* EP0: Control OUT */ |
| 492 | writel(DEPCTL_EPDIS | DEPCTL_CNAK, |
| 493 | ®->out_endp[EP0_CON].doepctl); |
| 494 | |
| 495 | /* 14. Initialize OTG Link Core.*/ |
| 496 | writel(GAHBCFG_INIT, ®->gahbcfg); |
| 497 | } |
| 498 | |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 499 | static void set_max_pktsize(struct dwc2_udc *dev, enum usb_device_speed speed) |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 500 | { |
| 501 | unsigned int ep_ctrl; |
| 502 | int i; |
| 503 | |
| 504 | if (speed == USB_SPEED_HIGH) { |
| 505 | ep0_fifo_size = 64; |
| 506 | ep_fifo_size = 512; |
| 507 | ep_fifo_size2 = 1024; |
| 508 | dev->gadget.speed = USB_SPEED_HIGH; |
| 509 | } else { |
| 510 | ep0_fifo_size = 64; |
| 511 | ep_fifo_size = 64; |
| 512 | ep_fifo_size2 = 64; |
| 513 | dev->gadget.speed = USB_SPEED_FULL; |
| 514 | } |
| 515 | |
| 516 | dev->ep[0].ep.maxpacket = ep0_fifo_size; |
| 517 | for (i = 1; i < S3C_MAX_ENDPOINTS; i++) |
| 518 | dev->ep[i].ep.maxpacket = ep_fifo_size; |
| 519 | |
| 520 | /* EP0 - Control IN (64 bytes)*/ |
| 521 | ep_ctrl = readl(®->in_endp[EP0_CON].diepctl); |
| 522 | writel(ep_ctrl|(0<<0), ®->in_endp[EP0_CON].diepctl); |
| 523 | |
| 524 | /* EP0 - Control OUT (64 bytes)*/ |
| 525 | ep_ctrl = readl(®->out_endp[EP0_CON].doepctl); |
| 526 | writel(ep_ctrl|(0<<0), ®->out_endp[EP0_CON].doepctl); |
| 527 | } |
| 528 | |
| 529 | static int s3c_ep_enable(struct usb_ep *_ep, |
| 530 | const struct usb_endpoint_descriptor *desc) |
| 531 | { |
| 532 | struct s3c_ep *ep; |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 533 | struct dwc2_udc *dev; |
Bo Shen | 60dc40c | 2014-08-27 17:28:18 +0800 | [diff] [blame] | 534 | unsigned long flags = 0; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 535 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 536 | debug("%s: %p\n", __func__, _ep); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 537 | |
| 538 | ep = container_of(_ep, struct s3c_ep, ep); |
| 539 | if (!_ep || !desc || ep->desc || _ep->name == ep0name |
| 540 | || desc->bDescriptorType != USB_DT_ENDPOINT |
| 541 | || ep->bEndpointAddress != desc->bEndpointAddress |
Tom Rini | 7342452 | 2011-12-15 08:40:51 -0700 | [diff] [blame] | 542 | || ep_maxpacket(ep) < |
| 543 | le16_to_cpu(get_unaligned(&desc->wMaxPacketSize))) { |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 544 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 545 | debug("%s: bad ep or descriptor\n", __func__); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 546 | return -EINVAL; |
| 547 | } |
| 548 | |
| 549 | /* xfer types must match, except that interrupt ~= bulk */ |
| 550 | if (ep->bmAttributes != desc->bmAttributes |
| 551 | && ep->bmAttributes != USB_ENDPOINT_XFER_BULK |
| 552 | && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { |
| 553 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 554 | debug("%s: %s type mismatch\n", __func__, _ep->name); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 555 | return -EINVAL; |
| 556 | } |
| 557 | |
| 558 | /* hardware _could_ do smaller, but driver doesn't */ |
| 559 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK |
Tom Rini | 7342452 | 2011-12-15 08:40:51 -0700 | [diff] [blame] | 560 | && le16_to_cpu(get_unaligned(&desc->wMaxPacketSize)) != |
| 561 | ep_maxpacket(ep)) || !get_unaligned(&desc->wMaxPacketSize)) { |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 562 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 563 | debug("%s: bad %s maxpacket\n", __func__, _ep->name); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 564 | return -ERANGE; |
| 565 | } |
| 566 | |
| 567 | dev = ep->dev; |
| 568 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { |
| 569 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 570 | debug("%s: bogus device state\n", __func__); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 571 | return -ESHUTDOWN; |
| 572 | } |
| 573 | |
| 574 | ep->stopped = 0; |
| 575 | ep->desc = desc; |
| 576 | ep->pio_irqs = 0; |
Tom Rini | 7342452 | 2011-12-15 08:40:51 -0700 | [diff] [blame] | 577 | ep->ep.maxpacket = le16_to_cpu(get_unaligned(&desc->wMaxPacketSize)); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 578 | |
| 579 | /* Reset halt state */ |
| 580 | s3c_udc_set_nak(ep); |
| 581 | s3c_udc_set_halt(_ep, 0); |
| 582 | |
| 583 | spin_lock_irqsave(&ep->dev->lock, flags); |
| 584 | s3c_udc_ep_activate(ep); |
| 585 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
| 586 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 587 | debug("%s: enabled %s, stopped = %d, maxpacket = %d\n", |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 588 | __func__, _ep->name, ep->stopped, ep->ep.maxpacket); |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | /* |
| 593 | * Disable EP |
| 594 | */ |
| 595 | static int s3c_ep_disable(struct usb_ep *_ep) |
| 596 | { |
| 597 | struct s3c_ep *ep; |
Bo Shen | 60dc40c | 2014-08-27 17:28:18 +0800 | [diff] [blame] | 598 | unsigned long flags = 0; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 599 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 600 | debug("%s: %p\n", __func__, _ep); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 601 | |
| 602 | ep = container_of(_ep, struct s3c_ep, ep); |
| 603 | if (!_ep || !ep->desc) { |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 604 | debug("%s: %s not enabled\n", __func__, |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 605 | _ep ? ep->ep.name : NULL); |
| 606 | return -EINVAL; |
| 607 | } |
| 608 | |
| 609 | spin_lock_irqsave(&ep->dev->lock, flags); |
| 610 | |
| 611 | /* Nuke all pending requests */ |
| 612 | nuke(ep, -ESHUTDOWN); |
| 613 | |
| 614 | ep->desc = 0; |
| 615 | ep->stopped = 1; |
| 616 | |
| 617 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
| 618 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 619 | debug("%s: disabled %s\n", __func__, _ep->name); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static struct usb_request *s3c_alloc_request(struct usb_ep *ep, |
| 624 | gfp_t gfp_flags) |
| 625 | { |
| 626 | struct s3c_request *req; |
| 627 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 628 | debug("%s: %s %p\n", __func__, ep->name, ep); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 629 | |
Mike Frysinger | 1f19e3f | 2012-04-26 02:34:44 +0000 | [diff] [blame] | 630 | req = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*req)); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 631 | if (!req) |
| 632 | return 0; |
| 633 | |
| 634 | memset(req, 0, sizeof *req); |
| 635 | INIT_LIST_HEAD(&req->queue); |
| 636 | |
| 637 | return &req->req; |
| 638 | } |
| 639 | |
| 640 | static void s3c_free_request(struct usb_ep *ep, struct usb_request *_req) |
| 641 | { |
| 642 | struct s3c_request *req; |
| 643 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 644 | debug("%s: %p\n", __func__, ep); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 645 | |
| 646 | req = container_of(_req, struct s3c_request, req); |
| 647 | WARN_ON(!list_empty(&req->queue)); |
| 648 | kfree(req); |
| 649 | } |
| 650 | |
| 651 | /* dequeue JUST ONE request */ |
| 652 | static int s3c_dequeue(struct usb_ep *_ep, struct usb_request *_req) |
| 653 | { |
| 654 | struct s3c_ep *ep; |
| 655 | struct s3c_request *req; |
Bo Shen | 60dc40c | 2014-08-27 17:28:18 +0800 | [diff] [blame] | 656 | unsigned long flags = 0; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 657 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 658 | debug("%s: %p\n", __func__, _ep); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 659 | |
| 660 | ep = container_of(_ep, struct s3c_ep, ep); |
| 661 | if (!_ep || ep->ep.name == ep0name) |
| 662 | return -EINVAL; |
| 663 | |
| 664 | spin_lock_irqsave(&ep->dev->lock, flags); |
| 665 | |
| 666 | /* make sure it's actually queued on this endpoint */ |
| 667 | list_for_each_entry(req, &ep->queue, queue) { |
| 668 | if (&req->req == _req) |
| 669 | break; |
| 670 | } |
| 671 | if (&req->req != _req) { |
| 672 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
| 673 | return -EINVAL; |
| 674 | } |
| 675 | |
| 676 | done(ep, req, -ECONNRESET); |
| 677 | |
| 678 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | /* |
| 683 | * Return bytes in EP FIFO |
| 684 | */ |
| 685 | static int s3c_fifo_status(struct usb_ep *_ep) |
| 686 | { |
| 687 | int count = 0; |
| 688 | struct s3c_ep *ep; |
| 689 | |
| 690 | ep = container_of(_ep, struct s3c_ep, ep); |
| 691 | if (!_ep) { |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 692 | debug("%s: bad ep\n", __func__); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 693 | return -ENODEV; |
| 694 | } |
| 695 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 696 | debug("%s: %d\n", __func__, ep_index(ep)); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 697 | |
| 698 | /* LPD can't report unclaimed bytes from IN fifos */ |
| 699 | if (ep_is_in(ep)) |
| 700 | return -EOPNOTSUPP; |
| 701 | |
| 702 | return count; |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * Flush EP FIFO |
| 707 | */ |
| 708 | static void s3c_fifo_flush(struct usb_ep *_ep) |
| 709 | { |
| 710 | struct s3c_ep *ep; |
| 711 | |
| 712 | ep = container_of(_ep, struct s3c_ep, ep); |
| 713 | if (unlikely(!_ep || (!ep->desc && ep->ep.name != ep0name))) { |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 714 | debug("%s: bad ep\n", __func__); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 715 | return; |
| 716 | } |
| 717 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 718 | debug("%s: %d\n", __func__, ep_index(ep)); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static const struct usb_gadget_ops s3c_udc_ops = { |
| 722 | /* current versions must always be self-powered */ |
| 723 | }; |
| 724 | |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 725 | static struct dwc2_udc memory = { |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 726 | .usb_address = 0, |
| 727 | .gadget = { |
| 728 | .ops = &s3c_udc_ops, |
| 729 | .ep0 = &memory.ep[0].ep, |
| 730 | .name = driver_name, |
| 731 | }, |
| 732 | |
| 733 | /* control endpoint */ |
| 734 | .ep[0] = { |
| 735 | .ep = { |
| 736 | .name = ep0name, |
| 737 | .ops = &s3c_ep_ops, |
| 738 | .maxpacket = EP0_FIFO_SIZE, |
| 739 | }, |
| 740 | .dev = &memory, |
| 741 | |
| 742 | .bEndpointAddress = 0, |
| 743 | .bmAttributes = 0, |
| 744 | |
| 745 | .ep_type = ep_control, |
| 746 | }, |
| 747 | |
| 748 | /* first group of endpoints */ |
| 749 | .ep[1] = { |
| 750 | .ep = { |
| 751 | .name = "ep1in-bulk", |
| 752 | .ops = &s3c_ep_ops, |
| 753 | .maxpacket = EP_FIFO_SIZE, |
| 754 | }, |
| 755 | .dev = &memory, |
| 756 | |
| 757 | .bEndpointAddress = USB_DIR_IN | 1, |
| 758 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 759 | |
| 760 | .ep_type = ep_bulk_out, |
| 761 | .fifo_num = 1, |
| 762 | }, |
| 763 | |
| 764 | .ep[2] = { |
| 765 | .ep = { |
| 766 | .name = "ep2out-bulk", |
| 767 | .ops = &s3c_ep_ops, |
| 768 | .maxpacket = EP_FIFO_SIZE, |
| 769 | }, |
| 770 | .dev = &memory, |
| 771 | |
| 772 | .bEndpointAddress = USB_DIR_OUT | 2, |
| 773 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
| 774 | |
| 775 | .ep_type = ep_bulk_in, |
| 776 | .fifo_num = 2, |
| 777 | }, |
| 778 | |
| 779 | .ep[3] = { |
| 780 | .ep = { |
| 781 | .name = "ep3in-int", |
| 782 | .ops = &s3c_ep_ops, |
| 783 | .maxpacket = EP_FIFO_SIZE, |
| 784 | }, |
| 785 | .dev = &memory, |
| 786 | |
| 787 | .bEndpointAddress = USB_DIR_IN | 3, |
| 788 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
| 789 | |
| 790 | .ep_type = ep_interrupt, |
| 791 | .fifo_num = 3, |
| 792 | }, |
| 793 | }; |
| 794 | |
| 795 | /* |
| 796 | * probe - binds to the platform device |
| 797 | */ |
| 798 | |
| 799 | int s3c_udc_probe(struct s3c_plat_otg_data *pdata) |
| 800 | { |
Marek Vasut | 1a639ff | 2015-12-04 00:57:58 +0100 | [diff] [blame] | 801 | struct dwc2_udc *dev = &memory; |
Lukasz Majewski | 904f8f7 | 2014-02-05 10:10:44 +0100 | [diff] [blame] | 802 | int retval = 0; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 803 | |
Anatolij Gustschin | e63ce4f | 2011-12-19 04:20:35 +0000 | [diff] [blame] | 804 | debug("%s: %p\n", __func__, pdata); |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 805 | |
| 806 | dev->pdata = pdata; |
| 807 | |
Marek Vasut | 67ec9dc | 2015-12-04 01:11:45 +0100 | [diff] [blame^] | 808 | reg = (struct dwc2_usbotg_reg *)pdata->regs_otg; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 809 | |
| 810 | /* regs_otg = (void *)pdata->regs_otg; */ |
| 811 | |
| 812 | dev->gadget.is_dualspeed = 1; /* Hack only*/ |
| 813 | dev->gadget.is_otg = 0; |
| 814 | dev->gadget.is_a_peripheral = 0; |
| 815 | dev->gadget.b_hnp_enable = 0; |
| 816 | dev->gadget.a_hnp_support = 0; |
| 817 | dev->gadget.a_alt_hnp_support = 0; |
| 818 | |
| 819 | the_controller = dev; |
| 820 | |
Lukasz Majewski | 904f8f7 | 2014-02-05 10:10:44 +0100 | [diff] [blame] | 821 | usb_ctrl = memalign(CONFIG_SYS_CACHELINE_SIZE, |
| 822 | ROUND(sizeof(struct usb_ctrlrequest), |
| 823 | CONFIG_SYS_CACHELINE_SIZE)); |
| 824 | if (!usb_ctrl) { |
| 825 | error("No memory available for UDC!\n"); |
| 826 | return -ENOMEM; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 827 | } |
Lukasz Majewski | 904f8f7 | 2014-02-05 10:10:44 +0100 | [diff] [blame] | 828 | |
| 829 | usb_ctrl_dma_addr = (dma_addr_t) usb_ctrl; |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 830 | |
| 831 | udc_reinit(dev); |
| 832 | |
| 833 | return retval; |
| 834 | } |
| 835 | |
Kishon Vijay Abraham I | 4763e16 | 2015-02-23 18:40:23 +0530 | [diff] [blame] | 836 | int usb_gadget_handle_interrupts(int index) |
Lukasz Majewski | ac3c831 | 2011-10-27 10:36:46 +0200 | [diff] [blame] | 837 | { |
| 838 | u32 intr_status = readl(®->gintsts); |
| 839 | u32 gintmsk = readl(®->gintmsk); |
| 840 | |
| 841 | if (intr_status & gintmsk) |
| 842 | return s3c_udc_irq(1, (void *)the_controller); |
| 843 | return 0; |
| 844 | } |