Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1 | /** |
Anton Tikhomirov | dfbc6fa | 2011-04-21 17:06:43 +0900 | [diff] [blame] | 2 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 3 | * http://www.samsung.com |
| 4 | * |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 5 | * Copyright 2008 Openmoko, Inc. |
| 6 | * Copyright 2008 Simtec Electronics |
| 7 | * Ben Dooks <ben@simtec.co.uk> |
| 8 | * http://armlinux.simtec.co.uk/ |
| 9 | * |
| 10 | * S3C USB2.0 High-speed / OtG driver |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 15 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/spinlock.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/dma-mapping.h> |
| 23 | #include <linux/debugfs.h> |
| 24 | #include <linux/seq_file.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Maurus Cuelenaere | e50bf38 | 2010-07-19 09:40:50 +0100 | [diff] [blame] | 28 | #include <linux/clk.h> |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 29 | #include <linux/regulator/consumer.h> |
Tomasz Figa | c50f056c | 2013-06-25 17:38:23 +0200 | [diff] [blame] | 30 | #include <linux/of_platform.h> |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 31 | #include <linux/phy/phy.h> |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 32 | |
| 33 | #include <linux/usb/ch9.h> |
| 34 | #include <linux/usb/gadget.h> |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 35 | #include <linux/usb/phy.h> |
Lukasz Majewski | 126625e | 2012-05-09 13:16:53 +0200 | [diff] [blame] | 36 | #include <linux/platform_data/s3c-hsotg.h> |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 37 | |
Dinh Nguyen | f7c0b14 | 2014-04-14 14:13:35 -0700 | [diff] [blame] | 38 | #include "core.h" |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 39 | #include "hw.h" |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 40 | |
| 41 | /* conversion functions */ |
| 42 | static inline struct s3c_hsotg_req *our_req(struct usb_request *req) |
| 43 | { |
| 44 | return container_of(req, struct s3c_hsotg_req, req); |
| 45 | } |
| 46 | |
| 47 | static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep) |
| 48 | { |
| 49 | return container_of(ep, struct s3c_hsotg_ep, ep); |
| 50 | } |
| 51 | |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 52 | static inline struct dwc2_hsotg *to_hsotg(struct usb_gadget *gadget) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 53 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 54 | return container_of(gadget, struct dwc2_hsotg, gadget); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static inline void __orr32(void __iomem *ptr, u32 val) |
| 58 | { |
| 59 | writel(readl(ptr) | val, ptr); |
| 60 | } |
| 61 | |
| 62 | static inline void __bic32(void __iomem *ptr, u32 val) |
| 63 | { |
| 64 | writel(readl(ptr) & ~val, ptr); |
| 65 | } |
| 66 | |
| 67 | /* forward decleration of functions */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 68 | static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * using_dma - return the DMA status of the driver. |
| 72 | * @hsotg: The driver state. |
| 73 | * |
| 74 | * Return true if we're using DMA. |
| 75 | * |
| 76 | * Currently, we have the DMA support code worked into everywhere |
| 77 | * that needs it, but the AMBA DMA implementation in the hardware can |
| 78 | * only DMA from 32bit aligned addresses. This means that gadgets such |
| 79 | * as the CDC Ethernet cannot work as they often pass packets which are |
| 80 | * not 32bit aligned. |
| 81 | * |
| 82 | * Unfortunately the choice to use DMA or not is global to the controller |
| 83 | * and seems to be only settable when the controller is being put through |
| 84 | * a core reset. This means we either need to fix the gadgets to take |
| 85 | * account of DMA alignment, or add bounce buffers (yuerk). |
| 86 | * |
| 87 | * Until this issue is sorted out, we always return 'false'. |
| 88 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 89 | static inline bool using_dma(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 90 | { |
| 91 | return false; /* support is not complete */ |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * s3c_hsotg_en_gsint - enable one or more of the general interrupt |
| 96 | * @hsotg: The device state |
| 97 | * @ints: A bitmask of the interrupts to enable |
| 98 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 99 | static void s3c_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 100 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 101 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 102 | u32 new_gsintmsk; |
| 103 | |
| 104 | new_gsintmsk = gsintmsk | ints; |
| 105 | |
| 106 | if (new_gsintmsk != gsintmsk) { |
| 107 | dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 108 | writel(new_gsintmsk, hsotg->regs + GINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * s3c_hsotg_disable_gsint - disable one or more of the general interrupt |
| 114 | * @hsotg: The device state |
| 115 | * @ints: A bitmask of the interrupts to enable |
| 116 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 117 | static void s3c_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 118 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 119 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 120 | u32 new_gsintmsk; |
| 121 | |
| 122 | new_gsintmsk = gsintmsk & ~ints; |
| 123 | |
| 124 | if (new_gsintmsk != gsintmsk) |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 125 | writel(new_gsintmsk, hsotg->regs + GINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
| 129 | * s3c_hsotg_ctrl_epint - enable/disable an endpoint irq |
| 130 | * @hsotg: The device state |
| 131 | * @ep: The endpoint index |
| 132 | * @dir_in: True if direction is in. |
| 133 | * @en: The enable value, true to enable |
| 134 | * |
| 135 | * Set or clear the mask for an individual endpoint's interrupt |
| 136 | * request. |
| 137 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 138 | static void s3c_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 139 | unsigned int ep, unsigned int dir_in, |
| 140 | unsigned int en) |
| 141 | { |
| 142 | unsigned long flags; |
| 143 | u32 bit = 1 << ep; |
| 144 | u32 daint; |
| 145 | |
| 146 | if (!dir_in) |
| 147 | bit <<= 16; |
| 148 | |
| 149 | local_irq_save(flags); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 150 | daint = readl(hsotg->regs + DAINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 151 | if (en) |
| 152 | daint |= bit; |
| 153 | else |
| 154 | daint &= ~bit; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 155 | writel(daint, hsotg->regs + DAINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 156 | local_irq_restore(flags); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * s3c_hsotg_init_fifo - initialise non-periodic FIFOs |
| 161 | * @hsotg: The device instance. |
| 162 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 163 | static void s3c_hsotg_init_fifo(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 164 | { |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 165 | unsigned int ep; |
| 166 | unsigned int addr; |
| 167 | unsigned int size; |
Ben Dooks | 1703a6d | 2010-05-25 05:36:52 +0100 | [diff] [blame] | 168 | int timeout; |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 169 | u32 val; |
| 170 | |
Ben Dooks | 6d091ee7 | 2010-07-19 09:40:40 +0100 | [diff] [blame] | 171 | /* set FIFO sizes to 2048/1024 */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 172 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 173 | writel(2048, hsotg->regs + GRXFSIZ); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 174 | writel((2048 << FIFOSIZE_STARTADDR_SHIFT) | |
| 175 | (1024 << FIFOSIZE_DEPTH_SHIFT), hsotg->regs + GNPTXFSIZ); |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 176 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 177 | /* |
| 178 | * arange all the rest of the TX FIFOs, as some versions of this |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 179 | * block have overlapping default addresses. This also ensures |
| 180 | * that if the settings have been changed, then they are set to |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 181 | * known values. |
| 182 | */ |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 183 | |
| 184 | /* start at the end of the GNPTXFSIZ, rounded up */ |
| 185 | addr = 2048 + 1024; |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 186 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 187 | /* |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 188 | * Because we have not enough memory to have each TX FIFO of size at |
| 189 | * least 3072 bytes (the maximum single packet size), we create four |
| 190 | * FIFOs of lenght 1024, and four of length 3072 bytes, and assing |
| 191 | * them to endpoints dynamically according to maxpacket size value of |
| 192 | * given endpoint. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 193 | */ |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 194 | |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 195 | /* 256*4=1024 bytes FIFO length */ |
| 196 | size = 256; |
| 197 | for (ep = 1; ep <= 4; ep++) { |
| 198 | val = addr; |
| 199 | val |= size << FIFOSIZE_DEPTH_SHIFT; |
| 200 | WARN_ONCE(addr + size > hsotg->fifo_mem, |
| 201 | "insufficient fifo memory"); |
| 202 | addr += size; |
| 203 | |
| 204 | writel(val, hsotg->regs + DPTXFSIZN(ep)); |
| 205 | } |
| 206 | /* 768*4=3072 bytes FIFO length */ |
| 207 | size = 768; |
| 208 | for (ep = 5; ep <= 8; ep++) { |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 209 | val = addr; |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 210 | val |= size << FIFOSIZE_DEPTH_SHIFT; |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 211 | WARN_ONCE(addr + size > hsotg->fifo_mem, |
| 212 | "insufficient fifo memory"); |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 213 | addr += size; |
| 214 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 215 | writel(val, hsotg->regs + DPTXFSIZN(ep)); |
Ben Dooks | 0f002d2 | 2010-05-25 05:36:50 +0100 | [diff] [blame] | 216 | } |
Ben Dooks | 1703a6d | 2010-05-25 05:36:52 +0100 | [diff] [blame] | 217 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 218 | /* |
| 219 | * according to p428 of the design guide, we need to ensure that |
| 220 | * all fifos are flushed before continuing |
| 221 | */ |
Ben Dooks | 1703a6d | 2010-05-25 05:36:52 +0100 | [diff] [blame] | 222 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 223 | writel(GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | |
| 224 | GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL); |
Ben Dooks | 1703a6d | 2010-05-25 05:36:52 +0100 | [diff] [blame] | 225 | |
| 226 | /* wait until the fifos are both flushed */ |
| 227 | timeout = 100; |
| 228 | while (1) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 229 | val = readl(hsotg->regs + GRSTCTL); |
Ben Dooks | 1703a6d | 2010-05-25 05:36:52 +0100 | [diff] [blame] | 230 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 231 | if ((val & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH)) == 0) |
Ben Dooks | 1703a6d | 2010-05-25 05:36:52 +0100 | [diff] [blame] | 232 | break; |
| 233 | |
| 234 | if (--timeout == 0) { |
| 235 | dev_err(hsotg->dev, |
| 236 | "%s: timeout flushing fifos (GRSTCTL=%08x)\n", |
| 237 | __func__, val); |
| 238 | } |
| 239 | |
| 240 | udelay(1); |
| 241 | } |
| 242 | |
| 243 | dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
| 247 | * @ep: USB endpoint to allocate request for. |
| 248 | * @flags: Allocation flags |
| 249 | * |
| 250 | * Allocate a new USB request structure appropriate for the specified endpoint |
| 251 | */ |
Mark Brown | 0978f8c | 2010-01-18 13:18:35 +0000 | [diff] [blame] | 252 | static struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep, |
| 253 | gfp_t flags) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 254 | { |
| 255 | struct s3c_hsotg_req *req; |
| 256 | |
| 257 | req = kzalloc(sizeof(struct s3c_hsotg_req), flags); |
| 258 | if (!req) |
| 259 | return NULL; |
| 260 | |
| 261 | INIT_LIST_HEAD(&req->queue); |
| 262 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 263 | return &req->req; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * is_ep_periodic - return true if the endpoint is in periodic mode. |
| 268 | * @hs_ep: The endpoint to query. |
| 269 | * |
| 270 | * Returns true if the endpoint is in periodic mode, meaning it is being |
| 271 | * used for an Interrupt or ISO transfer. |
| 272 | */ |
| 273 | static inline int is_ep_periodic(struct s3c_hsotg_ep *hs_ep) |
| 274 | { |
| 275 | return hs_ep->periodic; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * s3c_hsotg_unmap_dma - unmap the DMA memory being used for the request |
| 280 | * @hsotg: The device state. |
| 281 | * @hs_ep: The endpoint for the request |
| 282 | * @hs_req: The request being processed. |
| 283 | * |
| 284 | * This is the reverse of s3c_hsotg_map_dma(), called for the completion |
| 285 | * of a request to ensure the buffer is ready for access by the caller. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 286 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 287 | static void s3c_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 288 | struct s3c_hsotg_ep *hs_ep, |
| 289 | struct s3c_hsotg_req *hs_req) |
| 290 | { |
| 291 | struct usb_request *req = &hs_req->req; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 292 | |
| 293 | /* ignore this if we're not moving any data */ |
| 294 | if (hs_req->req.length == 0) |
| 295 | return; |
| 296 | |
Jingoo Han | 17d966a | 2013-05-11 21:14:00 +0900 | [diff] [blame] | 297 | usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * s3c_hsotg_write_fifo - write packet Data to the TxFIFO |
| 302 | * @hsotg: The controller state. |
| 303 | * @hs_ep: The endpoint we're going to write for. |
| 304 | * @hs_req: The request to write data for. |
| 305 | * |
| 306 | * This is called when the TxFIFO has some space in it to hold a new |
| 307 | * transmission and we have something to give it. The actual setup of |
| 308 | * the data size is done elsewhere, so all we have to do is to actually |
| 309 | * write the data. |
| 310 | * |
| 311 | * The return value is zero if there is more space (or nothing was done) |
| 312 | * otherwise -ENOSPC is returned if the FIFO space was used up. |
| 313 | * |
| 314 | * This routine is only needed for PIO |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 315 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 316 | static int s3c_hsotg_write_fifo(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 317 | struct s3c_hsotg_ep *hs_ep, |
| 318 | struct s3c_hsotg_req *hs_req) |
| 319 | { |
| 320 | bool periodic = is_ep_periodic(hs_ep); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 321 | u32 gnptxsts = readl(hsotg->regs + GNPTXSTS); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 322 | int buf_pos = hs_req->req.actual; |
| 323 | int to_write = hs_ep->size_loaded; |
| 324 | void *data; |
| 325 | int can_write; |
| 326 | int pkt_round; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 327 | int max_transfer; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 328 | |
| 329 | to_write -= (buf_pos - hs_ep->last_load); |
| 330 | |
| 331 | /* if there's nothing to write, get out early */ |
| 332 | if (to_write == 0) |
| 333 | return 0; |
| 334 | |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 335 | if (periodic && !hsotg->dedicated_fifos) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 336 | u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 337 | int size_left; |
| 338 | int size_done; |
| 339 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 340 | /* |
| 341 | * work out how much data was loaded so we can calculate |
| 342 | * how much data is left in the fifo. |
| 343 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 344 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 345 | size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 346 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 347 | /* |
| 348 | * if shared fifo, we cannot write anything until the |
Ben Dooks | e7a9ff5 | 2010-07-19 09:40:42 +0100 | [diff] [blame] | 349 | * previous data has been completely sent. |
| 350 | */ |
| 351 | if (hs_ep->fifo_load != 0) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 352 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); |
Ben Dooks | e7a9ff5 | 2010-07-19 09:40:42 +0100 | [diff] [blame] | 353 | return -ENOSPC; |
| 354 | } |
| 355 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 356 | dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", |
| 357 | __func__, size_left, |
| 358 | hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size); |
| 359 | |
| 360 | /* how much of the data has moved */ |
| 361 | size_done = hs_ep->size_loaded - size_left; |
| 362 | |
| 363 | /* how much data is left in the fifo */ |
| 364 | can_write = hs_ep->fifo_load - size_done; |
| 365 | dev_dbg(hsotg->dev, "%s: => can_write1=%d\n", |
| 366 | __func__, can_write); |
| 367 | |
| 368 | can_write = hs_ep->fifo_size - can_write; |
| 369 | dev_dbg(hsotg->dev, "%s: => can_write2=%d\n", |
| 370 | __func__, can_write); |
| 371 | |
| 372 | if (can_write <= 0) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 373 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 374 | return -ENOSPC; |
| 375 | } |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 376 | } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 377 | can_write = readl(hsotg->regs + DTXFSTS(hs_ep->index)); |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 378 | |
| 379 | can_write &= 0xffff; |
| 380 | can_write *= 4; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 381 | } else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 382 | if (GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(gnptxsts) == 0) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 383 | dev_dbg(hsotg->dev, |
| 384 | "%s: no queue slots available (0x%08x)\n", |
| 385 | __func__, gnptxsts); |
| 386 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 387 | s3c_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 388 | return -ENOSPC; |
| 389 | } |
| 390 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 391 | can_write = GNPTXSTS_NP_TXF_SPC_AVAIL_GET(gnptxsts); |
Ben Dooks | 679f9b7 | 2010-07-19 09:40:41 +0100 | [diff] [blame] | 392 | can_write *= 4; /* fifo size is in 32bit quantities. */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 393 | } |
| 394 | |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 395 | max_transfer = hs_ep->ep.maxpacket * hs_ep->mc; |
| 396 | |
| 397 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", |
| 398 | __func__, gnptxsts, can_write, to_write, max_transfer); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 399 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 400 | /* |
| 401 | * limit to 512 bytes of data, it seems at least on the non-periodic |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 402 | * FIFO, requests of >512 cause the endpoint to get stuck with a |
| 403 | * fragment of the end of the transfer in it. |
| 404 | */ |
Robert Baldyga | 811f330 | 2013-09-24 11:24:28 +0200 | [diff] [blame] | 405 | if (can_write > 512 && !periodic) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 406 | can_write = 512; |
| 407 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 408 | /* |
| 409 | * limit the write to one max-packet size worth of data, but allow |
Ben Dooks | 03e10e5 | 2010-07-19 09:40:45 +0100 | [diff] [blame] | 410 | * the transfer to return that it did not run out of fifo space |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 411 | * doing it. |
| 412 | */ |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 413 | if (to_write > max_transfer) { |
| 414 | to_write = max_transfer; |
Ben Dooks | 03e10e5 | 2010-07-19 09:40:45 +0100 | [diff] [blame] | 415 | |
Robert Baldyga | 5cb2ff0 | 2013-09-19 11:50:18 +0200 | [diff] [blame] | 416 | /* it's needed only when we do not use dedicated fifos */ |
| 417 | if (!hsotg->dedicated_fifos) |
| 418 | s3c_hsotg_en_gsint(hsotg, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 419 | periodic ? GINTSTS_PTXFEMP : |
| 420 | GINTSTS_NPTXFEMP); |
Ben Dooks | 03e10e5 | 2010-07-19 09:40:45 +0100 | [diff] [blame] | 421 | } |
| 422 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 423 | /* see if we can write data */ |
| 424 | |
| 425 | if (to_write > can_write) { |
| 426 | to_write = can_write; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 427 | pkt_round = to_write % max_transfer; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 428 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 429 | /* |
| 430 | * Round the write down to an |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 431 | * exact number of packets. |
| 432 | * |
| 433 | * Note, we do not currently check to see if we can ever |
| 434 | * write a full packet or not to the FIFO. |
| 435 | */ |
| 436 | |
| 437 | if (pkt_round) |
| 438 | to_write -= pkt_round; |
| 439 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 440 | /* |
| 441 | * enable correct FIFO interrupt to alert us when there |
| 442 | * is more room left. |
| 443 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 444 | |
Robert Baldyga | 5cb2ff0 | 2013-09-19 11:50:18 +0200 | [diff] [blame] | 445 | /* it's needed only when we do not use dedicated fifos */ |
| 446 | if (!hsotg->dedicated_fifos) |
| 447 | s3c_hsotg_en_gsint(hsotg, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 448 | periodic ? GINTSTS_PTXFEMP : |
| 449 | GINTSTS_NPTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", |
| 453 | to_write, hs_req->req.length, can_write, buf_pos); |
| 454 | |
| 455 | if (to_write <= 0) |
| 456 | return -ENOSPC; |
| 457 | |
| 458 | hs_req->req.actual = buf_pos + to_write; |
| 459 | hs_ep->total_data += to_write; |
| 460 | |
| 461 | if (periodic) |
| 462 | hs_ep->fifo_load += to_write; |
| 463 | |
| 464 | to_write = DIV_ROUND_UP(to_write, 4); |
| 465 | data = hs_req->req.buf + buf_pos; |
| 466 | |
Matt Porter | 1a7ed5b | 2014-02-03 10:29:09 -0500 | [diff] [blame] | 467 | iowrite32_rep(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 468 | |
| 469 | return (to_write >= can_write) ? -ENOSPC : 0; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * get_ep_limit - get the maximum data legnth for this endpoint |
| 474 | * @hs_ep: The endpoint |
| 475 | * |
| 476 | * Return the maximum data that can be queued in one go on a given endpoint |
| 477 | * so that transfers that are too long can be split. |
| 478 | */ |
| 479 | static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) |
| 480 | { |
| 481 | int index = hs_ep->index; |
| 482 | unsigned maxsize; |
| 483 | unsigned maxpkt; |
| 484 | |
| 485 | if (index != 0) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 486 | maxsize = DXEPTSIZ_XFERSIZE_LIMIT + 1; |
| 487 | maxpkt = DXEPTSIZ_PKTCNT_LIMIT + 1; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 488 | } else { |
Ben Dooks | b05ca58 | 2010-07-19 09:40:48 +0100 | [diff] [blame] | 489 | maxsize = 64+64; |
Jingoo Han | 66e5c64 | 2011-05-13 21:26:15 +0900 | [diff] [blame] | 490 | if (hs_ep->dir_in) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 491 | maxpkt = DIEPTSIZ0_PKTCNT_LIMIT + 1; |
Jingoo Han | 66e5c64 | 2011-05-13 21:26:15 +0900 | [diff] [blame] | 492 | else |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 493 | maxpkt = 2; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /* we made the constant loading easier above by using +1 */ |
| 497 | maxpkt--; |
| 498 | maxsize--; |
| 499 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 500 | /* |
| 501 | * constrain by packet count if maxpkts*pktsize is greater |
| 502 | * than the length register size. |
| 503 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 504 | |
| 505 | if ((maxpkt * hs_ep->ep.maxpacket) < maxsize) |
| 506 | maxsize = maxpkt * hs_ep->ep.maxpacket; |
| 507 | |
| 508 | return maxsize; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * s3c_hsotg_start_req - start a USB request from an endpoint's queue |
| 513 | * @hsotg: The controller state. |
| 514 | * @hs_ep: The endpoint to process a request for |
| 515 | * @hs_req: The request to start. |
| 516 | * @continuing: True if we are doing more for the current request. |
| 517 | * |
| 518 | * Start the given request running by setting the endpoint registers |
| 519 | * appropriately, and writing any data to the FIFOs. |
| 520 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 521 | static void s3c_hsotg_start_req(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 522 | struct s3c_hsotg_ep *hs_ep, |
| 523 | struct s3c_hsotg_req *hs_req, |
| 524 | bool continuing) |
| 525 | { |
| 526 | struct usb_request *ureq = &hs_req->req; |
| 527 | int index = hs_ep->index; |
| 528 | int dir_in = hs_ep->dir_in; |
| 529 | u32 epctrl_reg; |
| 530 | u32 epsize_reg; |
| 531 | u32 epsize; |
| 532 | u32 ctrl; |
| 533 | unsigned length; |
| 534 | unsigned packets; |
| 535 | unsigned maxreq; |
| 536 | |
| 537 | if (index != 0) { |
| 538 | if (hs_ep->req && !continuing) { |
| 539 | dev_err(hsotg->dev, "%s: active request\n", __func__); |
| 540 | WARN_ON(1); |
| 541 | return; |
| 542 | } else if (hs_ep->req != hs_req && continuing) { |
| 543 | dev_err(hsotg->dev, |
| 544 | "%s: continue different req\n", __func__); |
| 545 | WARN_ON(1); |
| 546 | return; |
| 547 | } |
| 548 | } |
| 549 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 550 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
| 551 | epsize_reg = dir_in ? DIEPTSIZ(index) : DOEPTSIZ(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 552 | |
| 553 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", |
| 554 | __func__, readl(hsotg->regs + epctrl_reg), index, |
| 555 | hs_ep->dir_in ? "in" : "out"); |
| 556 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 557 | /* If endpoint is stalled, we will restart request later */ |
| 558 | ctrl = readl(hsotg->regs + epctrl_reg); |
| 559 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 560 | if (ctrl & DXEPCTL_STALL) { |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 561 | dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); |
| 562 | return; |
| 563 | } |
| 564 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 565 | length = ureq->length - ureq->actual; |
Lukasz Majewski | 71225be | 2012-05-04 14:17:03 +0200 | [diff] [blame] | 566 | dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", |
| 567 | ureq->length, ureq->actual); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 568 | if (0) |
| 569 | dev_dbg(hsotg->dev, |
Fabio Estevam | 0cc4cf6 | 2014-04-29 00:49:42 -0300 | [diff] [blame] | 570 | "REQ buf %p len %d dma %pad noi=%d zp=%d snok=%d\n", |
Jingoo Han | 8b3bc14 | 2014-02-04 14:25:29 +0900 | [diff] [blame] | 571 | ureq->buf, length, &ureq->dma, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 572 | ureq->no_interrupt, ureq->zero, ureq->short_not_ok); |
| 573 | |
| 574 | maxreq = get_ep_limit(hs_ep); |
| 575 | if (length > maxreq) { |
| 576 | int round = maxreq % hs_ep->ep.maxpacket; |
| 577 | |
| 578 | dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n", |
| 579 | __func__, length, maxreq, round); |
| 580 | |
| 581 | /* round down to multiple of packets */ |
| 582 | if (round) |
| 583 | maxreq -= round; |
| 584 | |
| 585 | length = maxreq; |
| 586 | } |
| 587 | |
| 588 | if (length) |
| 589 | packets = DIV_ROUND_UP(length, hs_ep->ep.maxpacket); |
| 590 | else |
| 591 | packets = 1; /* send one packet if length is zero. */ |
| 592 | |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 593 | if (hs_ep->isochronous && length > (hs_ep->mc * hs_ep->ep.maxpacket)) { |
| 594 | dev_err(hsotg->dev, "req length > maxpacket*mc\n"); |
| 595 | return; |
| 596 | } |
| 597 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 598 | if (dir_in && index != 0) |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 599 | if (hs_ep->isochronous) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 600 | epsize = DXEPTSIZ_MC(packets); |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 601 | else |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 602 | epsize = DXEPTSIZ_MC(1); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 603 | else |
| 604 | epsize = 0; |
| 605 | |
| 606 | if (index != 0 && ureq->zero) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 607 | /* |
| 608 | * test for the packets being exactly right for the |
| 609 | * transfer |
| 610 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 611 | |
| 612 | if (length == (packets * hs_ep->ep.maxpacket)) |
| 613 | packets++; |
| 614 | } |
| 615 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 616 | epsize |= DXEPTSIZ_PKTCNT(packets); |
| 617 | epsize |= DXEPTSIZ_XFERSIZE(length); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 618 | |
| 619 | dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", |
| 620 | __func__, packets, length, ureq->length, epsize, epsize_reg); |
| 621 | |
| 622 | /* store the request as the current one we're doing */ |
| 623 | hs_ep->req = hs_req; |
| 624 | |
| 625 | /* write size / packets */ |
| 626 | writel(epsize, hsotg->regs + epsize_reg); |
| 627 | |
Anton Tikhomirov | db1d8ba | 2012-03-06 14:09:19 +0900 | [diff] [blame] | 628 | if (using_dma(hsotg) && !continuing) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 629 | unsigned int dma_reg; |
| 630 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 631 | /* |
| 632 | * write DMA address to control register, buffer already |
| 633 | * synced by s3c_hsotg_ep_queue(). |
| 634 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 635 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 636 | dma_reg = dir_in ? DIEPDMA(index) : DOEPDMA(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 637 | writel(ureq->dma, hsotg->regs + dma_reg); |
| 638 | |
Fabio Estevam | 0cc4cf6 | 2014-04-29 00:49:42 -0300 | [diff] [blame] | 639 | dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", |
Jingoo Han | 8b3bc14 | 2014-02-04 14:25:29 +0900 | [diff] [blame] | 640 | __func__, &ureq->dma, dma_reg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 641 | } |
| 642 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 643 | ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ |
| 644 | ctrl |= DXEPCTL_USBACTEP; |
Lukasz Majewski | 71225be | 2012-05-04 14:17:03 +0200 | [diff] [blame] | 645 | |
| 646 | dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->setup); |
| 647 | |
| 648 | /* For Setup request do not clear NAK */ |
| 649 | if (hsotg->setup && index == 0) |
| 650 | hsotg->setup = 0; |
| 651 | else |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 652 | ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ |
Lukasz Majewski | 71225be | 2012-05-04 14:17:03 +0200 | [diff] [blame] | 653 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 654 | |
| 655 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
| 656 | writel(ctrl, hsotg->regs + epctrl_reg); |
| 657 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 658 | /* |
| 659 | * set these, it seems that DMA support increments past the end |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 660 | * of the packet buffer so we need to calculate the length from |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 661 | * this information. |
| 662 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 663 | hs_ep->size_loaded = length; |
| 664 | hs_ep->last_load = ureq->actual; |
| 665 | |
| 666 | if (dir_in && !using_dma(hsotg)) { |
| 667 | /* set these anyway, we may need them for non-periodic in */ |
| 668 | hs_ep->fifo_load = 0; |
| 669 | |
| 670 | s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); |
| 671 | } |
| 672 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 673 | /* |
| 674 | * clear the INTknTXFEmpMsk when we start request, more as a aide |
| 675 | * to debugging to see what is going on. |
| 676 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 677 | if (dir_in) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 678 | writel(DIEPMSK_INTKNTXFEMPMSK, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 679 | hsotg->regs + DIEPINT(index)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 680 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 681 | /* |
| 682 | * Note, trying to clear the NAK here causes problems with transmit |
| 683 | * on the S3C6400 ending up with the TXFIFO becoming full. |
| 684 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 685 | |
| 686 | /* check ep is enabled */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 687 | if (!(readl(hsotg->regs + epctrl_reg) & DXEPCTL_EPENA)) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 688 | dev_warn(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 689 | "ep%d: failed to become enabled (DXEPCTL=0x%08x)?\n", |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 690 | index, readl(hsotg->regs + epctrl_reg)); |
| 691 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 692 | dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 693 | __func__, readl(hsotg->regs + epctrl_reg)); |
Robert Baldyga | afcf416 | 2013-09-19 11:50:19 +0200 | [diff] [blame] | 694 | |
| 695 | /* enable ep interrupts */ |
| 696 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
| 700 | * s3c_hsotg_map_dma - map the DMA memory being used for the request |
| 701 | * @hsotg: The device state. |
| 702 | * @hs_ep: The endpoint the request is on. |
| 703 | * @req: The request being processed. |
| 704 | * |
| 705 | * We've been asked to queue a request, so ensure that the memory buffer |
| 706 | * is correctly setup for DMA. If we've been passed an extant DMA address |
| 707 | * then ensure the buffer has been synced to memory. If our buffer has no |
| 708 | * DMA memory, then we map the memory and mark our request to allow us to |
| 709 | * cleanup on completion. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 710 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 711 | static int s3c_hsotg_map_dma(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 712 | struct s3c_hsotg_ep *hs_ep, |
| 713 | struct usb_request *req) |
| 714 | { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 715 | struct s3c_hsotg_req *hs_req = our_req(req); |
Felipe Balbi | e58ebcd | 2013-01-28 14:48:36 +0200 | [diff] [blame] | 716 | int ret; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 717 | |
| 718 | /* if the length is zero, ignore the DMA data */ |
| 719 | if (hs_req->req.length == 0) |
| 720 | return 0; |
| 721 | |
Felipe Balbi | e58ebcd | 2013-01-28 14:48:36 +0200 | [diff] [blame] | 722 | ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); |
| 723 | if (ret) |
| 724 | goto dma_error; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 725 | |
| 726 | return 0; |
| 727 | |
| 728 | dma_error: |
| 729 | dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n", |
| 730 | __func__, req->buf, req->length); |
| 731 | |
| 732 | return -EIO; |
| 733 | } |
| 734 | |
| 735 | static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, |
| 736 | gfp_t gfp_flags) |
| 737 | { |
| 738 | struct s3c_hsotg_req *hs_req = our_req(req); |
| 739 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 740 | struct dwc2_hsotg *hs = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 741 | bool first; |
| 742 | |
| 743 | dev_dbg(hs->dev, "%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n", |
| 744 | ep->name, req, req->length, req->buf, req->no_interrupt, |
| 745 | req->zero, req->short_not_ok); |
| 746 | |
| 747 | /* initialise status of the request */ |
| 748 | INIT_LIST_HEAD(&hs_req->queue); |
| 749 | req->actual = 0; |
| 750 | req->status = -EINPROGRESS; |
| 751 | |
| 752 | /* if we're using DMA, sync the buffers as necessary */ |
| 753 | if (using_dma(hs)) { |
| 754 | int ret = s3c_hsotg_map_dma(hs, hs_ep, req); |
| 755 | if (ret) |
| 756 | return ret; |
| 757 | } |
| 758 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 759 | first = list_empty(&hs_ep->queue); |
| 760 | list_add_tail(&hs_req->queue, &hs_ep->queue); |
| 761 | |
| 762 | if (first) |
| 763 | s3c_hsotg_start_req(hs, hs_ep, hs_req, false); |
| 764 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 768 | static int s3c_hsotg_ep_queue_lock(struct usb_ep *ep, struct usb_request *req, |
| 769 | gfp_t gfp_flags) |
| 770 | { |
| 771 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 772 | struct dwc2_hsotg *hs = hs_ep->parent; |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 773 | unsigned long flags = 0; |
| 774 | int ret = 0; |
| 775 | |
| 776 | spin_lock_irqsave(&hs->lock, flags); |
| 777 | ret = s3c_hsotg_ep_queue(ep, req, gfp_flags); |
| 778 | spin_unlock_irqrestore(&hs->lock, flags); |
| 779 | |
| 780 | return ret; |
| 781 | } |
| 782 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 783 | static void s3c_hsotg_ep_free_request(struct usb_ep *ep, |
| 784 | struct usb_request *req) |
| 785 | { |
| 786 | struct s3c_hsotg_req *hs_req = our_req(req); |
| 787 | |
| 788 | kfree(hs_req); |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * s3c_hsotg_complete_oursetup - setup completion callback |
| 793 | * @ep: The endpoint the request was on. |
| 794 | * @req: The request completed. |
| 795 | * |
| 796 | * Called on completion of any requests the driver itself |
| 797 | * submitted that need cleaning up. |
| 798 | */ |
| 799 | static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, |
| 800 | struct usb_request *req) |
| 801 | { |
| 802 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 803 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 804 | |
| 805 | dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); |
| 806 | |
| 807 | s3c_hsotg_ep_free_request(ep, req); |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * ep_from_windex - convert control wIndex value to endpoint |
| 812 | * @hsotg: The driver state. |
| 813 | * @windex: The control request wIndex field (in host order). |
| 814 | * |
| 815 | * Convert the given wIndex into a pointer to an driver endpoint |
| 816 | * structure, or return NULL if it is not a valid endpoint. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 817 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 818 | static struct s3c_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 819 | u32 windex) |
| 820 | { |
| 821 | struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F]; |
| 822 | int dir = (windex & USB_DIR_IN) ? 1 : 0; |
| 823 | int idx = windex & 0x7F; |
| 824 | |
| 825 | if (windex >= 0x100) |
| 826 | return NULL; |
| 827 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 828 | if (idx > hsotg->num_of_eps) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 829 | return NULL; |
| 830 | |
| 831 | if (idx && ep->dir_in != dir) |
| 832 | return NULL; |
| 833 | |
| 834 | return ep; |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * s3c_hsotg_send_reply - send reply to control request |
| 839 | * @hsotg: The device state |
| 840 | * @ep: Endpoint 0 |
| 841 | * @buff: Buffer for request |
| 842 | * @length: Length of reply. |
| 843 | * |
| 844 | * Create a request and queue it on the given endpoint. This is useful as |
| 845 | * an internal method of sending replies to certain control requests, etc. |
| 846 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 847 | static int s3c_hsotg_send_reply(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 848 | struct s3c_hsotg_ep *ep, |
| 849 | void *buff, |
| 850 | int length) |
| 851 | { |
| 852 | struct usb_request *req; |
| 853 | int ret; |
| 854 | |
| 855 | dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length); |
| 856 | |
| 857 | req = s3c_hsotg_ep_alloc_request(&ep->ep, GFP_ATOMIC); |
| 858 | hsotg->ep0_reply = req; |
| 859 | if (!req) { |
| 860 | dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__); |
| 861 | return -ENOMEM; |
| 862 | } |
| 863 | |
| 864 | req->buf = hsotg->ep0_buff; |
| 865 | req->length = length; |
| 866 | req->zero = 1; /* always do zero-length final transfer */ |
| 867 | req->complete = s3c_hsotg_complete_oursetup; |
| 868 | |
| 869 | if (length) |
| 870 | memcpy(req->buf, buff, length); |
| 871 | else |
| 872 | ep->sent_zlp = 1; |
| 873 | |
| 874 | ret = s3c_hsotg_ep_queue(&ep->ep, req, GFP_ATOMIC); |
| 875 | if (ret) { |
| 876 | dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__); |
| 877 | return ret; |
| 878 | } |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * s3c_hsotg_process_req_status - process request GET_STATUS |
| 885 | * @hsotg: The device state |
| 886 | * @ctrl: USB control request |
| 887 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 888 | static int s3c_hsotg_process_req_status(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 889 | struct usb_ctrlrequest *ctrl) |
| 890 | { |
| 891 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
| 892 | struct s3c_hsotg_ep *ep; |
| 893 | __le16 reply; |
| 894 | int ret; |
| 895 | |
| 896 | dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__); |
| 897 | |
| 898 | if (!ep0->dir_in) { |
| 899 | dev_warn(hsotg->dev, "%s: direction out?\n", __func__); |
| 900 | return -EINVAL; |
| 901 | } |
| 902 | |
| 903 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
| 904 | case USB_RECIP_DEVICE: |
| 905 | reply = cpu_to_le16(0); /* bit 0 => self powered, |
| 906 | * bit 1 => remote wakeup */ |
| 907 | break; |
| 908 | |
| 909 | case USB_RECIP_INTERFACE: |
| 910 | /* currently, the data result should be zero */ |
| 911 | reply = cpu_to_le16(0); |
| 912 | break; |
| 913 | |
| 914 | case USB_RECIP_ENDPOINT: |
| 915 | ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); |
| 916 | if (!ep) |
| 917 | return -ENOENT; |
| 918 | |
| 919 | reply = cpu_to_le16(ep->halted ? 1 : 0); |
| 920 | break; |
| 921 | |
| 922 | default: |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | if (le16_to_cpu(ctrl->wLength) != 2) |
| 927 | return -EINVAL; |
| 928 | |
| 929 | ret = s3c_hsotg_send_reply(hsotg, ep0, &reply, 2); |
| 930 | if (ret) { |
| 931 | dev_err(hsotg->dev, "%s: failed to send reply\n", __func__); |
| 932 | return ret; |
| 933 | } |
| 934 | |
| 935 | return 1; |
| 936 | } |
| 937 | |
| 938 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value); |
| 939 | |
| 940 | /** |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 941 | * get_ep_head - return the first request on the endpoint |
| 942 | * @hs_ep: The controller endpoint to get |
| 943 | * |
| 944 | * Get the first request on the endpoint. |
| 945 | */ |
| 946 | static struct s3c_hsotg_req *get_ep_head(struct s3c_hsotg_ep *hs_ep) |
| 947 | { |
| 948 | if (list_empty(&hs_ep->queue)) |
| 949 | return NULL; |
| 950 | |
| 951 | return list_first_entry(&hs_ep->queue, struct s3c_hsotg_req, queue); |
| 952 | } |
| 953 | |
| 954 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 955 | * s3c_hsotg_process_req_featire - process request {SET,CLEAR}_FEATURE |
| 956 | * @hsotg: The device state |
| 957 | * @ctrl: USB control request |
| 958 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 959 | static int s3c_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 960 | struct usb_ctrlrequest *ctrl) |
| 961 | { |
Anton Tikhomirov | 26ab3d0 | 2011-04-21 17:06:40 +0900 | [diff] [blame] | 962 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 963 | struct s3c_hsotg_req *hs_req; |
| 964 | bool restart; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 965 | bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); |
| 966 | struct s3c_hsotg_ep *ep; |
Anton Tikhomirov | 26ab3d0 | 2011-04-21 17:06:40 +0900 | [diff] [blame] | 967 | int ret; |
Robert Baldyga | bd9ef7b | 2013-09-19 11:50:22 +0200 | [diff] [blame] | 968 | bool halted; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 969 | |
| 970 | dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", |
| 971 | __func__, set ? "SET" : "CLEAR"); |
| 972 | |
| 973 | if (ctrl->bRequestType == USB_RECIP_ENDPOINT) { |
| 974 | ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); |
| 975 | if (!ep) { |
| 976 | dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n", |
| 977 | __func__, le16_to_cpu(ctrl->wIndex)); |
| 978 | return -ENOENT; |
| 979 | } |
| 980 | |
| 981 | switch (le16_to_cpu(ctrl->wValue)) { |
| 982 | case USB_ENDPOINT_HALT: |
Robert Baldyga | bd9ef7b | 2013-09-19 11:50:22 +0200 | [diff] [blame] | 983 | halted = ep->halted; |
| 984 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 985 | s3c_hsotg_ep_sethalt(&ep->ep, set); |
Anton Tikhomirov | 26ab3d0 | 2011-04-21 17:06:40 +0900 | [diff] [blame] | 986 | |
| 987 | ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); |
| 988 | if (ret) { |
| 989 | dev_err(hsotg->dev, |
| 990 | "%s: failed to send reply\n", __func__); |
| 991 | return ret; |
| 992 | } |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 993 | |
Robert Baldyga | bd9ef7b | 2013-09-19 11:50:22 +0200 | [diff] [blame] | 994 | /* |
| 995 | * we have to complete all requests for ep if it was |
| 996 | * halted, and the halt was cleared by CLEAR_FEATURE |
| 997 | */ |
| 998 | |
| 999 | if (!set && halted) { |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1000 | /* |
| 1001 | * If we have request in progress, |
| 1002 | * then complete it |
| 1003 | */ |
| 1004 | if (ep->req) { |
| 1005 | hs_req = ep->req; |
| 1006 | ep->req = NULL; |
| 1007 | list_del_init(&hs_req->queue); |
Michal Sojka | 304f7e5 | 2014-09-24 22:43:19 +0200 | [diff] [blame] | 1008 | usb_gadget_giveback_request(&ep->ep, |
| 1009 | &hs_req->req); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /* If we have pending request, then start it */ |
| 1013 | restart = !list_empty(&ep->queue); |
| 1014 | if (restart) { |
| 1015 | hs_req = get_ep_head(ep); |
| 1016 | s3c_hsotg_start_req(hsotg, ep, |
| 1017 | hs_req, false); |
| 1018 | } |
| 1019 | } |
| 1020 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1021 | break; |
| 1022 | |
| 1023 | default: |
| 1024 | return -ENOENT; |
| 1025 | } |
| 1026 | } else |
| 1027 | return -ENOENT; /* currently only deal with endpoint */ |
| 1028 | |
| 1029 | return 1; |
| 1030 | } |
| 1031 | |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1032 | static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg); |
| 1033 | static void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg); |
Robert Baldyga | ab93e01 | 2013-09-19 11:50:17 +0200 | [diff] [blame] | 1034 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1035 | /** |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1036 | * s3c_hsotg_stall_ep0 - stall ep0 |
| 1037 | * @hsotg: The device state |
| 1038 | * |
| 1039 | * Set stall for ep0 as response for setup request. |
| 1040 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1041 | static void s3c_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) |
Jingoo Han | e9ebe7c | 2014-06-03 22:14:56 +0900 | [diff] [blame] | 1042 | { |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1043 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
| 1044 | u32 reg; |
| 1045 | u32 ctrl; |
| 1046 | |
| 1047 | dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); |
| 1048 | reg = (ep0->dir_in) ? DIEPCTL0 : DOEPCTL0; |
| 1049 | |
| 1050 | /* |
| 1051 | * DxEPCTL_Stall will be cleared by EP once it has |
| 1052 | * taken effect, so no need to clear later. |
| 1053 | */ |
| 1054 | |
| 1055 | ctrl = readl(hsotg->regs + reg); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1056 | ctrl |= DXEPCTL_STALL; |
| 1057 | ctrl |= DXEPCTL_CNAK; |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1058 | writel(ctrl, hsotg->regs + reg); |
| 1059 | |
| 1060 | dev_dbg(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1061 | "written DXEPCTL=0x%08x to %08x (DXEPCTL=0x%08x)\n", |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1062 | ctrl, reg, readl(hsotg->regs + reg)); |
| 1063 | |
| 1064 | /* |
| 1065 | * complete won't be called, so we enqueue |
| 1066 | * setup request here |
| 1067 | */ |
| 1068 | s3c_hsotg_enqueue_setup(hsotg); |
| 1069 | } |
| 1070 | |
| 1071 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1072 | * s3c_hsotg_process_control - process a control request |
| 1073 | * @hsotg: The device state |
| 1074 | * @ctrl: The control request received |
| 1075 | * |
| 1076 | * The controller has received the SETUP phase of a control request, and |
| 1077 | * needs to work out what to do next (and whether to pass it on to the |
| 1078 | * gadget driver). |
| 1079 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1080 | static void s3c_hsotg_process_control(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1081 | struct usb_ctrlrequest *ctrl) |
| 1082 | { |
| 1083 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
| 1084 | int ret = 0; |
| 1085 | u32 dcfg; |
| 1086 | |
| 1087 | ep0->sent_zlp = 0; |
| 1088 | |
| 1089 | dev_dbg(hsotg->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n", |
| 1090 | ctrl->bRequest, ctrl->bRequestType, |
| 1091 | ctrl->wValue, ctrl->wLength); |
| 1092 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1093 | /* |
| 1094 | * record the direction of the request, for later use when enquing |
| 1095 | * packets onto EP0. |
| 1096 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1097 | |
| 1098 | ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; |
| 1099 | dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in); |
| 1100 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1101 | /* |
| 1102 | * if we've no data with this request, then the last part of the |
| 1103 | * transaction is going to implicitly be IN. |
| 1104 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1105 | if (ctrl->wLength == 0) |
| 1106 | ep0->dir_in = 1; |
| 1107 | |
| 1108 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
| 1109 | switch (ctrl->bRequest) { |
| 1110 | case USB_REQ_SET_ADDRESS: |
Robert Baldyga | d18f7116 | 2013-11-21 13:49:18 +0100 | [diff] [blame] | 1111 | s3c_hsotg_disconnect(hsotg); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1112 | dcfg = readl(hsotg->regs + DCFG); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1113 | dcfg &= ~DCFG_DEVADDR_MASK; |
Paul Zimmerman | d5dbd3f | 2014-04-25 14:18:13 -0700 | [diff] [blame] | 1114 | dcfg |= (le16_to_cpu(ctrl->wValue) << |
| 1115 | DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1116 | writel(dcfg, hsotg->regs + DCFG); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1117 | |
| 1118 | dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); |
| 1119 | |
| 1120 | ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); |
| 1121 | return; |
| 1122 | |
| 1123 | case USB_REQ_GET_STATUS: |
| 1124 | ret = s3c_hsotg_process_req_status(hsotg, ctrl); |
| 1125 | break; |
| 1126 | |
| 1127 | case USB_REQ_CLEAR_FEATURE: |
| 1128 | case USB_REQ_SET_FEATURE: |
| 1129 | ret = s3c_hsotg_process_req_feature(hsotg, ctrl); |
| 1130 | break; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | /* as a fallback, try delivering it to the driver to deal with */ |
| 1135 | |
| 1136 | if (ret == 0 && hsotg->driver) { |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1137 | spin_unlock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1138 | ret = hsotg->driver->setup(&hsotg->gadget, ctrl); |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1139 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1140 | if (ret < 0) |
| 1141 | dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); |
| 1142 | } |
| 1143 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1144 | /* |
| 1145 | * the request is either unhandlable, or is not formatted correctly |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1146 | * so respond with a STALL for the status stage to indicate failure. |
| 1147 | */ |
| 1148 | |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1149 | if (ret < 0) |
| 1150 | s3c_hsotg_stall_ep0(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1153 | /** |
| 1154 | * s3c_hsotg_complete_setup - completion of a setup transfer |
| 1155 | * @ep: The endpoint the request was on. |
| 1156 | * @req: The request completed. |
| 1157 | * |
| 1158 | * Called on completion of any requests the driver itself submitted for |
| 1159 | * EP0 setup packets |
| 1160 | */ |
| 1161 | static void s3c_hsotg_complete_setup(struct usb_ep *ep, |
| 1162 | struct usb_request *req) |
| 1163 | { |
| 1164 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1165 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1166 | |
| 1167 | if (req->status < 0) { |
| 1168 | dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); |
| 1169 | return; |
| 1170 | } |
| 1171 | |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1172 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1173 | if (req->actual == 0) |
| 1174 | s3c_hsotg_enqueue_setup(hsotg); |
| 1175 | else |
| 1176 | s3c_hsotg_process_control(hsotg, req->buf); |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1177 | spin_unlock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | /** |
| 1181 | * s3c_hsotg_enqueue_setup - start a request for EP0 packets |
| 1182 | * @hsotg: The device state. |
| 1183 | * |
| 1184 | * Enqueue a request on EP0 if necessary to received any SETUP packets |
| 1185 | * received from the host. |
| 1186 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1187 | static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1188 | { |
| 1189 | struct usb_request *req = hsotg->ctrl_req; |
| 1190 | struct s3c_hsotg_req *hs_req = our_req(req); |
| 1191 | int ret; |
| 1192 | |
| 1193 | dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); |
| 1194 | |
| 1195 | req->zero = 0; |
| 1196 | req->length = 8; |
| 1197 | req->buf = hsotg->ctrl_buff; |
| 1198 | req->complete = s3c_hsotg_complete_setup; |
| 1199 | |
| 1200 | if (!list_empty(&hs_req->queue)) { |
| 1201 | dev_dbg(hsotg->dev, "%s already queued???\n", __func__); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | hsotg->eps[0].dir_in = 0; |
| 1206 | |
| 1207 | ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC); |
| 1208 | if (ret < 0) { |
| 1209 | dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1210 | /* |
| 1211 | * Don't think there's much we can do other than watch the |
| 1212 | * driver fail. |
| 1213 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1218 | * s3c_hsotg_complete_request - complete a request given to us |
| 1219 | * @hsotg: The device state. |
| 1220 | * @hs_ep: The endpoint the request was on. |
| 1221 | * @hs_req: The request to complete. |
| 1222 | * @result: The result code (0 => Ok, otherwise errno) |
| 1223 | * |
| 1224 | * The given request has finished, so call the necessary completion |
| 1225 | * if it has one and then look to see if we can start a new request |
| 1226 | * on the endpoint. |
| 1227 | * |
| 1228 | * Note, expects the ep to already be locked as appropriate. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1229 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1230 | static void s3c_hsotg_complete_request(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1231 | struct s3c_hsotg_ep *hs_ep, |
| 1232 | struct s3c_hsotg_req *hs_req, |
| 1233 | int result) |
| 1234 | { |
| 1235 | bool restart; |
| 1236 | |
| 1237 | if (!hs_req) { |
| 1238 | dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", |
| 1243 | hs_ep, hs_ep->ep.name, hs_req, result, hs_req->req.complete); |
| 1244 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1245 | /* |
| 1246 | * only replace the status if we've not already set an error |
| 1247 | * from a previous transaction |
| 1248 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1249 | |
| 1250 | if (hs_req->req.status == -EINPROGRESS) |
| 1251 | hs_req->req.status = result; |
| 1252 | |
| 1253 | hs_ep->req = NULL; |
| 1254 | list_del_init(&hs_req->queue); |
| 1255 | |
| 1256 | if (using_dma(hsotg)) |
| 1257 | s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); |
| 1258 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1259 | /* |
| 1260 | * call the complete request with the locks off, just in case the |
| 1261 | * request tries to queue more work for this endpoint. |
| 1262 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1263 | |
| 1264 | if (hs_req->req.complete) { |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 1265 | spin_unlock(&hsotg->lock); |
Michal Sojka | 304f7e5 | 2014-09-24 22:43:19 +0200 | [diff] [blame] | 1266 | usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req); |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 1267 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1270 | /* |
| 1271 | * Look to see if there is anything else to do. Note, the completion |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1272 | * of the previous request may have caused a new request to be started |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1273 | * so be careful when doing this. |
| 1274 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1275 | |
| 1276 | if (!hs_ep->req && result >= 0) { |
| 1277 | restart = !list_empty(&hs_ep->queue); |
| 1278 | if (restart) { |
| 1279 | hs_req = get_ep_head(hs_ep); |
| 1280 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, false); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1286 | * s3c_hsotg_rx_data - receive data from the FIFO for an endpoint |
| 1287 | * @hsotg: The device state. |
| 1288 | * @ep_idx: The endpoint index for the data |
| 1289 | * @size: The size of data in the fifo, in bytes |
| 1290 | * |
| 1291 | * The FIFO status shows there is data to read from the FIFO for a given |
| 1292 | * endpoint, so sort out whether we need to read the data into a request |
| 1293 | * that has been made for that endpoint. |
| 1294 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1295 | static void s3c_hsotg_rx_data(struct dwc2_hsotg *hsotg, int ep_idx, int size) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1296 | { |
| 1297 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; |
| 1298 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1299 | void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1300 | int to_read; |
| 1301 | int max_req; |
| 1302 | int read_ptr; |
| 1303 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 1304 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1305 | if (!hs_req) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1306 | u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1307 | int ptr; |
| 1308 | |
| 1309 | dev_warn(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1310 | "%s: FIFO %d bytes on ep%d but no req (DXEPCTl=0x%08x)\n", |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1311 | __func__, size, ep_idx, epctl); |
| 1312 | |
| 1313 | /* dump the data from the FIFO, we've nothing we can do */ |
| 1314 | for (ptr = 0; ptr < size; ptr += 4) |
| 1315 | (void)readl(fifo); |
| 1316 | |
| 1317 | return; |
| 1318 | } |
| 1319 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1320 | to_read = size; |
| 1321 | read_ptr = hs_req->req.actual; |
| 1322 | max_req = hs_req->req.length - read_ptr; |
| 1323 | |
Ben Dooks | a33e713 | 2010-07-19 09:40:49 +0100 | [diff] [blame] | 1324 | dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", |
| 1325 | __func__, to_read, max_req, read_ptr, hs_req->req.length); |
| 1326 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1327 | if (to_read > max_req) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1328 | /* |
| 1329 | * more data appeared than we where willing |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1330 | * to deal with in this request. |
| 1331 | */ |
| 1332 | |
| 1333 | /* currently we don't deal this */ |
| 1334 | WARN_ON_ONCE(1); |
| 1335 | } |
| 1336 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1337 | hs_ep->total_data += to_read; |
| 1338 | hs_req->req.actual += to_read; |
| 1339 | to_read = DIV_ROUND_UP(to_read, 4); |
| 1340 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1341 | /* |
| 1342 | * note, we might over-write the buffer end by 3 bytes depending on |
| 1343 | * alignment of the data. |
| 1344 | */ |
Matt Porter | 1a7ed5b | 2014-02-03 10:29:09 -0500 | [diff] [blame] | 1345 | ioread32_rep(fifo, hs_req->req.buf + read_ptr, to_read); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * s3c_hsotg_send_zlp - send zero-length packet on control endpoint |
| 1350 | * @hsotg: The device instance |
| 1351 | * @req: The request currently on this endpoint |
| 1352 | * |
| 1353 | * Generate a zero-length IN packet request for terminating a SETUP |
| 1354 | * transaction. |
| 1355 | * |
| 1356 | * Note, since we don't write any data to the TxFIFO, then it is |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1357 | * currently believed that we do not need to wait for any space in |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1358 | * the TxFIFO. |
| 1359 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1360 | static void s3c_hsotg_send_zlp(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1361 | struct s3c_hsotg_req *req) |
| 1362 | { |
| 1363 | u32 ctrl; |
| 1364 | |
| 1365 | if (!req) { |
| 1366 | dev_warn(hsotg->dev, "%s: no request?\n", __func__); |
| 1367 | return; |
| 1368 | } |
| 1369 | |
| 1370 | if (req->req.length == 0) { |
| 1371 | hsotg->eps[0].sent_zlp = 1; |
| 1372 | s3c_hsotg_enqueue_setup(hsotg); |
| 1373 | return; |
| 1374 | } |
| 1375 | |
| 1376 | hsotg->eps[0].dir_in = 1; |
| 1377 | hsotg->eps[0].sent_zlp = 1; |
| 1378 | |
| 1379 | dev_dbg(hsotg->dev, "sending zero-length packet\n"); |
| 1380 | |
| 1381 | /* issue a zero-sized packet to terminate this */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1382 | writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | |
| 1383 | DXEPTSIZ_XFERSIZE(0), hsotg->regs + DIEPTSIZ(0)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1384 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1385 | ctrl = readl(hsotg->regs + DIEPCTL0); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1386 | ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ |
| 1387 | ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ |
| 1388 | ctrl |= DXEPCTL_USBACTEP; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1389 | writel(ctrl, hsotg->regs + DIEPCTL0); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * s3c_hsotg_handle_outdone - handle receiving OutDone/SetupDone from RXFIFO |
| 1394 | * @hsotg: The device instance |
| 1395 | * @epnum: The endpoint received from |
| 1396 | * @was_setup: Set if processing a SetupDone event. |
| 1397 | * |
| 1398 | * The RXFIFO has delivered an OutDone event, which means that the data |
| 1399 | * transfer for an OUT endpoint has been completed, either by a short |
| 1400 | * packet or by the finish of a transfer. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1401 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1402 | static void s3c_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1403 | int epnum, bool was_setup) |
| 1404 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1405 | u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1406 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; |
| 1407 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
| 1408 | struct usb_request *req = &hs_req->req; |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1409 | unsigned size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1410 | int result = 0; |
| 1411 | |
| 1412 | if (!hs_req) { |
| 1413 | dev_dbg(hsotg->dev, "%s: no request active\n", __func__); |
| 1414 | return; |
| 1415 | } |
| 1416 | |
| 1417 | if (using_dma(hsotg)) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1418 | unsigned size_done; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1419 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1420 | /* |
| 1421 | * Calculate the size of the transfer by checking how much |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1422 | * is left in the endpoint size register and then working it |
| 1423 | * out from the amount we loaded for the transfer. |
| 1424 | * |
| 1425 | * We need to do this as DMA pointers are always 32bit aligned |
| 1426 | * so may overshoot/undershoot the transfer. |
| 1427 | */ |
| 1428 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1429 | size_done = hs_ep->size_loaded - size_left; |
| 1430 | size_done += hs_ep->last_load; |
| 1431 | |
| 1432 | req->actual = size_done; |
| 1433 | } |
| 1434 | |
Ben Dooks | a33e713 | 2010-07-19 09:40:49 +0100 | [diff] [blame] | 1435 | /* if there is more request to do, schedule new transfer */ |
| 1436 | if (req->actual < req->length && size_left == 0) { |
| 1437 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); |
| 1438 | return; |
Lukasz Majewski | 71225be | 2012-05-04 14:17:03 +0200 | [diff] [blame] | 1439 | } else if (epnum == 0) { |
| 1440 | /* |
| 1441 | * After was_setup = 1 => |
| 1442 | * set CNAK for non Setup requests |
| 1443 | */ |
| 1444 | hsotg->setup = was_setup ? 0 : 1; |
Ben Dooks | a33e713 | 2010-07-19 09:40:49 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1447 | if (req->actual < req->length && req->short_not_ok) { |
| 1448 | dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", |
| 1449 | __func__, req->actual, req->length); |
| 1450 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1451 | /* |
| 1452 | * todo - what should we return here? there's no one else |
| 1453 | * even bothering to check the status. |
| 1454 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | if (epnum == 0) { |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1458 | /* |
| 1459 | * Condition req->complete != s3c_hsotg_complete_setup says: |
| 1460 | * send ZLP when we have an asynchronous request from gadget |
| 1461 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1462 | if (!was_setup && req->complete != s3c_hsotg_complete_setup) |
| 1463 | s3c_hsotg_send_zlp(hsotg, hs_req); |
| 1464 | } |
| 1465 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 1466 | s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * s3c_hsotg_read_frameno - read current frame number |
| 1471 | * @hsotg: The device instance |
| 1472 | * |
| 1473 | * Return the current frame number |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1474 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1475 | static u32 s3c_hsotg_read_frameno(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1476 | { |
| 1477 | u32 dsts; |
| 1478 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1479 | dsts = readl(hsotg->regs + DSTS); |
| 1480 | dsts &= DSTS_SOFFN_MASK; |
| 1481 | dsts >>= DSTS_SOFFN_SHIFT; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1482 | |
| 1483 | return dsts; |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * s3c_hsotg_handle_rx - RX FIFO has data |
| 1488 | * @hsotg: The device instance |
| 1489 | * |
| 1490 | * The IRQ handler has detected that the RX FIFO has some data in it |
| 1491 | * that requires processing, so find out what is in there and do the |
| 1492 | * appropriate read. |
| 1493 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1494 | * The RXFIFO is a true FIFO, the packets coming out are still in packet |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1495 | * chunks, so if you have x packets received on an endpoint you'll get x |
| 1496 | * FIFO events delivered, each with a packet's worth of data in it. |
| 1497 | * |
| 1498 | * When using DMA, we should not be processing events from the RXFIFO |
| 1499 | * as the actual data should be sent to the memory directly and we turn |
| 1500 | * on the completion interrupts to get notifications of transfer completion. |
| 1501 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1502 | static void s3c_hsotg_handle_rx(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1503 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1504 | u32 grxstsr = readl(hsotg->regs + GRXSTSP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1505 | u32 epnum, status, size; |
| 1506 | |
| 1507 | WARN_ON(using_dma(hsotg)); |
| 1508 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1509 | epnum = grxstsr & GRXSTS_EPNUM_MASK; |
| 1510 | status = grxstsr & GRXSTS_PKTSTS_MASK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1511 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1512 | size = grxstsr & GRXSTS_BYTECNT_MASK; |
| 1513 | size >>= GRXSTS_BYTECNT_SHIFT; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1514 | |
| 1515 | if (1) |
| 1516 | dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", |
| 1517 | __func__, grxstsr, size, epnum); |
| 1518 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1519 | switch ((status & GRXSTS_PKTSTS_MASK) >> GRXSTS_PKTSTS_SHIFT) { |
| 1520 | case GRXSTS_PKTSTS_GLOBALOUTNAK: |
| 1521 | dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1522 | break; |
| 1523 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1524 | case GRXSTS_PKTSTS_OUTDONE: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1525 | dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", |
| 1526 | s3c_hsotg_read_frameno(hsotg)); |
| 1527 | |
| 1528 | if (!using_dma(hsotg)) |
| 1529 | s3c_hsotg_handle_outdone(hsotg, epnum, false); |
| 1530 | break; |
| 1531 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1532 | case GRXSTS_PKTSTS_SETUPDONE: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1533 | dev_dbg(hsotg->dev, |
| 1534 | "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
| 1535 | s3c_hsotg_read_frameno(hsotg), |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1536 | readl(hsotg->regs + DOEPCTL(0))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1537 | |
| 1538 | s3c_hsotg_handle_outdone(hsotg, epnum, true); |
| 1539 | break; |
| 1540 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1541 | case GRXSTS_PKTSTS_OUTRX: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1542 | s3c_hsotg_rx_data(hsotg, epnum, size); |
| 1543 | break; |
| 1544 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1545 | case GRXSTS_PKTSTS_SETUPRX: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1546 | dev_dbg(hsotg->dev, |
| 1547 | "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
| 1548 | s3c_hsotg_read_frameno(hsotg), |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1549 | readl(hsotg->regs + DOEPCTL(0))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1550 | |
| 1551 | s3c_hsotg_rx_data(hsotg, epnum, size); |
| 1552 | break; |
| 1553 | |
| 1554 | default: |
| 1555 | dev_warn(hsotg->dev, "%s: unknown status %08x\n", |
| 1556 | __func__, grxstsr); |
| 1557 | |
| 1558 | s3c_hsotg_dump(hsotg); |
| 1559 | break; |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | /** |
| 1564 | * s3c_hsotg_ep0_mps - turn max packet size into register setting |
| 1565 | * @mps: The maximum packet size in bytes. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1566 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1567 | static u32 s3c_hsotg_ep0_mps(unsigned int mps) |
| 1568 | { |
| 1569 | switch (mps) { |
| 1570 | case 64: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1571 | return D0EPCTL_MPS_64; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1572 | case 32: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1573 | return D0EPCTL_MPS_32; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1574 | case 16: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1575 | return D0EPCTL_MPS_16; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1576 | case 8: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1577 | return D0EPCTL_MPS_8; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /* bad max packet size, warn and return invalid result */ |
| 1581 | WARN_ON(1); |
| 1582 | return (u32)-1; |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * s3c_hsotg_set_ep_maxpacket - set endpoint's max-packet field |
| 1587 | * @hsotg: The driver state. |
| 1588 | * @ep: The index number of the endpoint |
| 1589 | * @mps: The maximum packet size in bytes |
| 1590 | * |
| 1591 | * Configure the maximum packet size for the given endpoint, updating |
| 1592 | * the hardware control registers to reflect this. |
| 1593 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1594 | static void s3c_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1595 | unsigned int ep, unsigned int mps) |
| 1596 | { |
| 1597 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; |
| 1598 | void __iomem *regs = hsotg->regs; |
| 1599 | u32 mpsval; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 1600 | u32 mcval; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1601 | u32 reg; |
| 1602 | |
| 1603 | if (ep == 0) { |
| 1604 | /* EP0 is a special case */ |
| 1605 | mpsval = s3c_hsotg_ep0_mps(mps); |
| 1606 | if (mpsval > 3) |
| 1607 | goto bad_mps; |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 1608 | hs_ep->ep.maxpacket = mps; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 1609 | hs_ep->mc = 1; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1610 | } else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1611 | mpsval = mps & DXEPCTL_MPS_MASK; |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 1612 | if (mpsval > 1024) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1613 | goto bad_mps; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 1614 | mcval = ((mps >> 11) & 0x3) + 1; |
| 1615 | hs_ep->mc = mcval; |
| 1616 | if (mcval > 3) |
| 1617 | goto bad_mps; |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 1618 | hs_ep->ep.maxpacket = mpsval; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1621 | /* |
| 1622 | * update both the in and out endpoint controldir_ registers, even |
| 1623 | * if one of the directions may not be in use. |
| 1624 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1625 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1626 | reg = readl(regs + DIEPCTL(ep)); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1627 | reg &= ~DXEPCTL_MPS_MASK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1628 | reg |= mpsval; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1629 | writel(reg, regs + DIEPCTL(ep)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1630 | |
Anton Tikhomirov | 659ad60 | 2012-03-06 14:07:29 +0900 | [diff] [blame] | 1631 | if (ep) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1632 | reg = readl(regs + DOEPCTL(ep)); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1633 | reg &= ~DXEPCTL_MPS_MASK; |
Anton Tikhomirov | 659ad60 | 2012-03-06 14:07:29 +0900 | [diff] [blame] | 1634 | reg |= mpsval; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1635 | writel(reg, regs + DOEPCTL(ep)); |
Anton Tikhomirov | 659ad60 | 2012-03-06 14:07:29 +0900 | [diff] [blame] | 1636 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1637 | |
| 1638 | return; |
| 1639 | |
| 1640 | bad_mps: |
| 1641 | dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); |
| 1642 | } |
| 1643 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1644 | /** |
| 1645 | * s3c_hsotg_txfifo_flush - flush Tx FIFO |
| 1646 | * @hsotg: The driver state |
| 1647 | * @idx: The index for the endpoint (0..15) |
| 1648 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1649 | static void s3c_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1650 | { |
| 1651 | int timeout; |
| 1652 | int val; |
| 1653 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1654 | writel(GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1655 | hsotg->regs + GRSTCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1656 | |
| 1657 | /* wait until the fifo is flushed */ |
| 1658 | timeout = 100; |
| 1659 | |
| 1660 | while (1) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1661 | val = readl(hsotg->regs + GRSTCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1662 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1663 | if ((val & (GRSTCTL_TXFFLSH)) == 0) |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1664 | break; |
| 1665 | |
| 1666 | if (--timeout == 0) { |
| 1667 | dev_err(hsotg->dev, |
| 1668 | "%s: timeout flushing fifo (GRSTCTL=%08x)\n", |
| 1669 | __func__, val); |
Marek Szyprowski | e0cbe59 | 2014-09-09 10:44:10 +0200 | [diff] [blame] | 1670 | break; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | udelay(1); |
| 1674 | } |
| 1675 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1676 | |
| 1677 | /** |
| 1678 | * s3c_hsotg_trytx - check to see if anything needs transmitting |
| 1679 | * @hsotg: The driver state |
| 1680 | * @hs_ep: The driver endpoint to check. |
| 1681 | * |
| 1682 | * Check to see if there is a request that has data to send, and if so |
| 1683 | * make an attempt to write data into the FIFO. |
| 1684 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1685 | static int s3c_hsotg_trytx(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1686 | struct s3c_hsotg_ep *hs_ep) |
| 1687 | { |
| 1688 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
| 1689 | |
Robert Baldyga | afcf416 | 2013-09-19 11:50:19 +0200 | [diff] [blame] | 1690 | if (!hs_ep->dir_in || !hs_req) { |
| 1691 | /** |
| 1692 | * if request is not enqueued, we disable interrupts |
| 1693 | * for endpoints, excepting ep0 |
| 1694 | */ |
| 1695 | if (hs_ep->index != 0) |
| 1696 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, |
| 1697 | hs_ep->dir_in, 0); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1698 | return 0; |
Robert Baldyga | afcf416 | 2013-09-19 11:50:19 +0200 | [diff] [blame] | 1699 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1700 | |
| 1701 | if (hs_req->req.actual < hs_req->req.length) { |
| 1702 | dev_dbg(hsotg->dev, "trying to write more for ep%d\n", |
| 1703 | hs_ep->index); |
| 1704 | return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); |
| 1705 | } |
| 1706 | |
| 1707 | return 0; |
| 1708 | } |
| 1709 | |
| 1710 | /** |
| 1711 | * s3c_hsotg_complete_in - complete IN transfer |
| 1712 | * @hsotg: The device state. |
| 1713 | * @hs_ep: The endpoint that has just completed. |
| 1714 | * |
| 1715 | * An IN transfer has been completed, update the transfer's state and then |
| 1716 | * call the relevant completion routines. |
| 1717 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1718 | static void s3c_hsotg_complete_in(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1719 | struct s3c_hsotg_ep *hs_ep) |
| 1720 | { |
| 1721 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1722 | u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1723 | int size_left, size_done; |
| 1724 | |
| 1725 | if (!hs_req) { |
| 1726 | dev_dbg(hsotg->dev, "XferCompl but no req\n"); |
| 1727 | return; |
| 1728 | } |
| 1729 | |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1730 | /* Finish ZLP handling for IN EP0 transactions */ |
| 1731 | if (hsotg->eps[0].sent_zlp) { |
| 1732 | dev_dbg(hsotg->dev, "zlp packet received\n"); |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 1733 | s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1734 | return; |
| 1735 | } |
| 1736 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1737 | /* |
| 1738 | * Calculate the size of the transfer by checking how much is left |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1739 | * in the endpoint size register and then working it out from |
| 1740 | * the amount we loaded for the transfer. |
| 1741 | * |
| 1742 | * We do this even for DMA, as the transfer may have incremented |
| 1743 | * past the end of the buffer (DMA transfers are always 32bit |
| 1744 | * aligned). |
| 1745 | */ |
| 1746 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1747 | size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1748 | |
| 1749 | size_done = hs_ep->size_loaded - size_left; |
| 1750 | size_done += hs_ep->last_load; |
| 1751 | |
| 1752 | if (hs_req->req.actual != size_done) |
| 1753 | dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", |
| 1754 | __func__, hs_req->req.actual, size_done); |
| 1755 | |
| 1756 | hs_req->req.actual = size_done; |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1757 | dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", |
| 1758 | hs_req->req.length, hs_req->req.actual, hs_req->req.zero); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1759 | |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1760 | /* |
| 1761 | * Check if dealing with Maximum Packet Size(MPS) IN transfer at EP0 |
| 1762 | * When sent data is a multiple MPS size (e.g. 64B ,128B ,192B |
| 1763 | * ,256B ... ), after last MPS sized packet send IN ZLP packet to |
| 1764 | * inform the host that no more data is available. |
| 1765 | * The state of req.zero member is checked to be sure that the value to |
| 1766 | * send is smaller than wValue expected from host. |
| 1767 | * Check req.length to NOT send another ZLP when the current one is |
| 1768 | * under completion (the one for which this completion has been called). |
| 1769 | */ |
| 1770 | if (hs_req->req.length && hs_ep->index == 0 && hs_req->req.zero && |
| 1771 | hs_req->req.length == hs_req->req.actual && |
| 1772 | !(hs_req->req.length % hs_ep->ep.maxpacket)) { |
| 1773 | |
| 1774 | dev_dbg(hsotg->dev, "ep0 zlp IN packet sent\n"); |
| 1775 | s3c_hsotg_send_zlp(hsotg, hs_req); |
| 1776 | |
| 1777 | return; |
| 1778 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1779 | |
| 1780 | if (!size_left && hs_req->req.actual < hs_req->req.length) { |
| 1781 | dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); |
| 1782 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); |
| 1783 | } else |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 1784 | s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * s3c_hsotg_epint - handle an in/out endpoint interrupt |
| 1789 | * @hsotg: The driver state |
| 1790 | * @idx: The index for the endpoint (0..15) |
| 1791 | * @dir_in: Set if this is an IN endpoint |
| 1792 | * |
| 1793 | * Process and clear any interrupt pending for an individual endpoint |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1794 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1795 | static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1796 | int dir_in) |
| 1797 | { |
| 1798 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1799 | u32 epint_reg = dir_in ? DIEPINT(idx) : DOEPINT(idx); |
| 1800 | u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); |
| 1801 | u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1802 | u32 ints; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1803 | u32 ctrl; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1804 | |
| 1805 | ints = readl(hsotg->regs + epint_reg); |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1806 | ctrl = readl(hsotg->regs + epctl_reg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1807 | |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 1808 | /* Clear endpoint interrupts */ |
| 1809 | writel(ints, hsotg->regs + epint_reg); |
| 1810 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1811 | dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", |
| 1812 | __func__, idx, dir_in ? "in" : "out", ints); |
| 1813 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1814 | if (ints & DXEPINT_XFERCOMPL) { |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1815 | if (hs_ep->isochronous && hs_ep->interval == 1) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1816 | if (ctrl & DXEPCTL_EOFRNUM) |
| 1817 | ctrl |= DXEPCTL_SETEVENFR; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1818 | else |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1819 | ctrl |= DXEPCTL_SETODDFR; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1820 | writel(ctrl, hsotg->regs + epctl_reg); |
| 1821 | } |
| 1822 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1823 | dev_dbg(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1824 | "%s: XferCompl: DxEPCTL=0x%08x, DXEPTSIZ=%08x\n", |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1825 | __func__, readl(hsotg->regs + epctl_reg), |
| 1826 | readl(hsotg->regs + epsiz_reg)); |
| 1827 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1828 | /* |
| 1829 | * we get OutDone from the FIFO, so we only need to look |
| 1830 | * at completing IN requests here |
| 1831 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1832 | if (dir_in) { |
| 1833 | s3c_hsotg_complete_in(hsotg, hs_ep); |
| 1834 | |
Ben Dooks | c9a64ea | 2010-07-19 09:40:46 +0100 | [diff] [blame] | 1835 | if (idx == 0 && !hs_ep->req) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1836 | s3c_hsotg_enqueue_setup(hsotg); |
| 1837 | } else if (using_dma(hsotg)) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1838 | /* |
| 1839 | * We're using DMA, we need to fire an OutDone here |
| 1840 | * as we ignore the RXFIFO. |
| 1841 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1842 | |
| 1843 | s3c_hsotg_handle_outdone(hsotg, idx, false); |
| 1844 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1847 | if (ints & DXEPINT_EPDISBLD) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1848 | dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1849 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1850 | if (dir_in) { |
| 1851 | int epctl = readl(hsotg->regs + epctl_reg); |
| 1852 | |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 1853 | s3c_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1854 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1855 | if ((epctl & DXEPCTL_STALL) && |
| 1856 | (epctl & DXEPCTL_EPTYPE_BULK)) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1857 | int dctl = readl(hsotg->regs + DCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1858 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1859 | dctl |= DCTL_CGNPINNAK; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1860 | writel(dctl, hsotg->regs + DCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | } |
| 1864 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1865 | if (ints & DXEPINT_AHBERR) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1866 | dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1867 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1868 | if (ints & DXEPINT_SETUP) { /* Setup or Timeout */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1869 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); |
| 1870 | |
| 1871 | if (using_dma(hsotg) && idx == 0) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1872 | /* |
| 1873 | * this is the notification we've received a |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1874 | * setup packet. In non-DMA mode we'd get this |
| 1875 | * from the RXFIFO, instead we need to process |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1876 | * the setup here. |
| 1877 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1878 | |
| 1879 | if (dir_in) |
| 1880 | WARN_ON_ONCE(1); |
| 1881 | else |
| 1882 | s3c_hsotg_handle_outdone(hsotg, 0, true); |
| 1883 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1886 | if (ints & DXEPINT_BACK2BACKSETUP) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1887 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1888 | |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1889 | if (dir_in && !hs_ep->isochronous) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1890 | /* not sure if this is important, but we'll clear it anyway */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1891 | if (ints & DIEPMSK_INTKNTXFEMPMSK) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1892 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", |
| 1893 | __func__, idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /* this probably means something bad is happening */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1897 | if (ints & DIEPMSK_INTKNEPMISMSK) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1898 | dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", |
| 1899 | __func__, idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1900 | } |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 1901 | |
| 1902 | /* FIFO has space or is empty (see GAHBCFG) */ |
| 1903 | if (hsotg->dedicated_fifos && |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1904 | ints & DIEPMSK_TXFIFOEMPTY) { |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 1905 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", |
| 1906 | __func__, idx); |
Anton Tikhomirov | 70fa030 | 2012-03-06 14:08:29 +0900 | [diff] [blame] | 1907 | if (!using_dma(hsotg)) |
| 1908 | s3c_hsotg_trytx(hsotg, hs_ep); |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 1909 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1910 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * s3c_hsotg_irq_enumdone - Handle EnumDone interrupt (enumeration done) |
| 1915 | * @hsotg: The device state. |
| 1916 | * |
| 1917 | * Handle updating the device settings after the enumeration phase has |
| 1918 | * been completed. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1919 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1920 | static void s3c_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1921 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1922 | u32 dsts = readl(hsotg->regs + DSTS); |
Jingoo Han | 9b2667f | 2014-08-20 12:04:09 +0900 | [diff] [blame] | 1923 | int ep0_mps = 0, ep_mps = 8; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1924 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1925 | /* |
| 1926 | * This should signal the finish of the enumeration phase |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1927 | * of the USB handshaking, so we should now know what rate |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1928 | * we connected at. |
| 1929 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1930 | |
| 1931 | dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); |
| 1932 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1933 | /* |
| 1934 | * note, since we're limited by the size of transfer on EP0, and |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1935 | * it seems IN transfers must be a even number of packets we do |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1936 | * not advertise a 64byte MPS on EP0. |
| 1937 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1938 | |
| 1939 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1940 | switch (dsts & DSTS_ENUMSPD_MASK) { |
| 1941 | case DSTS_ENUMSPD_FS: |
| 1942 | case DSTS_ENUMSPD_FS48: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1943 | hsotg->gadget.speed = USB_SPEED_FULL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1944 | ep0_mps = EP0_MPS_LIMIT; |
Robert Baldyga | 295538f | 2013-12-06 13:03:44 +0100 | [diff] [blame] | 1945 | ep_mps = 1023; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1946 | break; |
| 1947 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1948 | case DSTS_ENUMSPD_HS: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1949 | hsotg->gadget.speed = USB_SPEED_HIGH; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1950 | ep0_mps = EP0_MPS_LIMIT; |
Robert Baldyga | 295538f | 2013-12-06 13:03:44 +0100 | [diff] [blame] | 1951 | ep_mps = 1024; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1952 | break; |
| 1953 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1954 | case DSTS_ENUMSPD_LS: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1955 | hsotg->gadget.speed = USB_SPEED_LOW; |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1956 | /* |
| 1957 | * note, we don't actually support LS in this driver at the |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1958 | * moment, and the documentation seems to imply that it isn't |
| 1959 | * supported by the PHYs on some of the devices. |
| 1960 | */ |
| 1961 | break; |
| 1962 | } |
Michal Nazarewicz | e538dfd | 2011-08-30 17:11:19 +0200 | [diff] [blame] | 1963 | dev_info(hsotg->dev, "new device is %s\n", |
| 1964 | usb_speed_string(hsotg->gadget.speed)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1965 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1966 | /* |
| 1967 | * we should now know the maximum packet size for an |
| 1968 | * endpoint, so set the endpoints to a default value. |
| 1969 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1970 | |
| 1971 | if (ep0_mps) { |
| 1972 | int i; |
| 1973 | s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 1974 | for (i = 1; i < hsotg->num_of_eps; i++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1975 | s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps); |
| 1976 | } |
| 1977 | |
| 1978 | /* ensure after enumeration our EP0 is active */ |
| 1979 | |
| 1980 | s3c_hsotg_enqueue_setup(hsotg); |
| 1981 | |
| 1982 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1983 | readl(hsotg->regs + DIEPCTL0), |
| 1984 | readl(hsotg->regs + DOEPCTL0)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * kill_all_requests - remove all requests from the endpoint's queue |
| 1989 | * @hsotg: The device state. |
| 1990 | * @ep: The endpoint the requests may be on. |
| 1991 | * @result: The result code to use. |
| 1992 | * @force: Force removal of any current requests |
| 1993 | * |
| 1994 | * Go through the requests on the given endpoint and mark them |
| 1995 | * completed with the given result code. |
| 1996 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1997 | static void kill_all_requests(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1998 | struct s3c_hsotg_ep *ep, |
| 1999 | int result, bool force) |
| 2000 | { |
| 2001 | struct s3c_hsotg_req *req, *treq; |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2002 | unsigned size; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2003 | |
| 2004 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2005 | /* |
| 2006 | * currently, we can't do much about an already |
| 2007 | * running request on an in endpoint |
| 2008 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2009 | |
| 2010 | if (ep->req == req && ep->dir_in && !force) |
| 2011 | continue; |
| 2012 | |
| 2013 | s3c_hsotg_complete_request(hsotg, ep, req, |
| 2014 | result); |
| 2015 | } |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2016 | if (!hsotg->dedicated_fifos) |
| 2017 | return; |
| 2018 | size = (readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4; |
| 2019 | if (size < ep->fifo_size) |
| 2020 | s3c_hsotg_txfifo_flush(hsotg, ep->fifo_index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2021 | } |
| 2022 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2023 | /** |
Lukasz Majewski | 5e89134 | 2012-05-04 14:17:07 +0200 | [diff] [blame] | 2024 | * s3c_hsotg_disconnect - disconnect service |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2025 | * @hsotg: The device state. |
| 2026 | * |
Lukasz Majewski | 5e89134 | 2012-05-04 14:17:07 +0200 | [diff] [blame] | 2027 | * The device has been disconnected. Remove all current |
| 2028 | * transactions and signal the gadget driver that this |
| 2029 | * has happened. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2030 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2031 | static void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2032 | { |
| 2033 | unsigned ep; |
| 2034 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2035 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2036 | kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); |
| 2037 | |
| 2038 | call_gadget(hsotg, disconnect); |
| 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler |
| 2043 | * @hsotg: The device state: |
| 2044 | * @periodic: True if this is a periodic FIFO interrupt |
| 2045 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2046 | static void s3c_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2047 | { |
| 2048 | struct s3c_hsotg_ep *ep; |
| 2049 | int epno, ret; |
| 2050 | |
| 2051 | /* look through for any more data to transmit */ |
| 2052 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2053 | for (epno = 0; epno < hsotg->num_of_eps; epno++) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2054 | ep = &hsotg->eps[epno]; |
| 2055 | |
| 2056 | if (!ep->dir_in) |
| 2057 | continue; |
| 2058 | |
| 2059 | if ((periodic && !ep->periodic) || |
| 2060 | (!periodic && ep->periodic)) |
| 2061 | continue; |
| 2062 | |
| 2063 | ret = s3c_hsotg_trytx(hsotg, ep); |
| 2064 | if (ret < 0) |
| 2065 | break; |
| 2066 | } |
| 2067 | } |
| 2068 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2069 | /* IRQ flags which will trigger a retry around the IRQ loop */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2070 | #define IRQ_RETRY_MASK (GINTSTS_NPTXFEMP | \ |
| 2071 | GINTSTS_PTXFEMP | \ |
| 2072 | GINTSTS_RXFLVL) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2073 | |
| 2074 | /** |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2075 | * s3c_hsotg_corereset - issue softreset to the core |
| 2076 | * @hsotg: The device state |
| 2077 | * |
| 2078 | * Issue a soft reset to the core, and await the core finishing it. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2079 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2080 | static int s3c_hsotg_corereset(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2081 | { |
| 2082 | int timeout; |
| 2083 | u32 grstctl; |
| 2084 | |
| 2085 | dev_dbg(hsotg->dev, "resetting core\n"); |
| 2086 | |
| 2087 | /* issue soft reset */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2088 | writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2089 | |
Du, Changbin | 2868fea | 2012-07-24 08:19:25 +0800 | [diff] [blame] | 2090 | timeout = 10000; |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2091 | do { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2092 | grstctl = readl(hsotg->regs + GRSTCTL); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2093 | } while ((grstctl & GRSTCTL_CSFTRST) && timeout-- > 0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2094 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2095 | if (grstctl & GRSTCTL_CSFTRST) { |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2096 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); |
| 2097 | return -EINVAL; |
| 2098 | } |
| 2099 | |
Du, Changbin | 2868fea | 2012-07-24 08:19:25 +0800 | [diff] [blame] | 2100 | timeout = 10000; |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2101 | |
| 2102 | while (1) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2103 | u32 grstctl = readl(hsotg->regs + GRSTCTL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2104 | |
| 2105 | if (timeout-- < 0) { |
| 2106 | dev_info(hsotg->dev, |
| 2107 | "%s: reset failed, GRSTCTL=%08x\n", |
| 2108 | __func__, grstctl); |
| 2109 | return -ETIMEDOUT; |
| 2110 | } |
| 2111 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2112 | if (!(grstctl & GRSTCTL_AHBIDLE)) |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2113 | continue; |
| 2114 | |
| 2115 | break; /* reset done */ |
| 2116 | } |
| 2117 | |
| 2118 | dev_dbg(hsotg->dev, "reset successful\n"); |
| 2119 | return 0; |
| 2120 | } |
| 2121 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2122 | /** |
| 2123 | * s3c_hsotg_core_init - issue softreset to the core |
| 2124 | * @hsotg: The device state |
| 2125 | * |
| 2126 | * Issue a soft reset to the core, and await the core finishing it. |
| 2127 | */ |
Dinh Nguyen | 510ffaa | 2014-11-11 11:13:36 -0600 | [diff] [blame] | 2128 | void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2129 | { |
| 2130 | s3c_hsotg_corereset(hsotg); |
| 2131 | |
| 2132 | /* |
| 2133 | * we must now enable ep0 ready for host detection and then |
| 2134 | * set configuration. |
| 2135 | */ |
| 2136 | |
| 2137 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2138 | writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2139 | (0x5 << 10), hsotg->regs + GUSBCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2140 | |
| 2141 | s3c_hsotg_init_fifo(hsotg); |
| 2142 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2143 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2144 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2145 | writel(1 << 18 | DCFG_DEVSPD_HS, hsotg->regs + DCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2146 | |
| 2147 | /* Clear any pending OTG interrupts */ |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2148 | writel(0xffffffff, hsotg->regs + GOTGINT); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2149 | |
| 2150 | /* Clear any pending interrupts */ |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2151 | writel(0xffffffff, hsotg->regs + GINTSTS); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2152 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2153 | writel(GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT | |
| 2154 | GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF | |
| 2155 | GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST | |
| 2156 | GINTSTS_ENUMDONE | GINTSTS_OTGINT | |
| 2157 | GINTSTS_USBSUSP | GINTSTS_WKUPINT, |
| 2158 | hsotg->regs + GINTMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2159 | |
| 2160 | if (using_dma(hsotg)) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2161 | writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | |
| 2162 | GAHBCFG_HBSTLEN_INCR4, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2163 | hsotg->regs + GAHBCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2164 | else |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2165 | writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL | |
| 2166 | GAHBCFG_P_TXF_EMP_LVL) : 0) | |
| 2167 | GAHBCFG_GLBL_INTR_EN, |
Robert Baldyga | 8acc829 | 2013-09-19 11:50:23 +0200 | [diff] [blame] | 2168 | hsotg->regs + GAHBCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2169 | |
| 2170 | /* |
Robert Baldyga | 8acc829 | 2013-09-19 11:50:23 +0200 | [diff] [blame] | 2171 | * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts |
| 2172 | * when we have no data to transfer. Otherwise we get being flooded by |
| 2173 | * interrupts. |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2174 | */ |
| 2175 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2176 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY | |
| 2177 | DIEPMSK_INTKNTXFEMPMSK : 0) | |
| 2178 | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK | |
| 2179 | DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | |
| 2180 | DIEPMSK_INTKNEPMISMSK, |
| 2181 | hsotg->regs + DIEPMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2182 | |
| 2183 | /* |
| 2184 | * don't need XferCompl, we get that from RXFIFO in slave mode. In |
| 2185 | * DMA mode we may need this. |
| 2186 | */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2187 | writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | |
| 2188 | DIEPMSK_TIMEOUTMSK) : 0) | |
| 2189 | DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK | |
| 2190 | DOEPMSK_SETUPMSK, |
| 2191 | hsotg->regs + DOEPMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2192 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2193 | writel(0, hsotg->regs + DAINTMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2194 | |
| 2195 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2196 | readl(hsotg->regs + DIEPCTL0), |
| 2197 | readl(hsotg->regs + DOEPCTL0)); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2198 | |
| 2199 | /* enable in and out endpoint interrupts */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2200 | s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2201 | |
| 2202 | /* |
| 2203 | * Enable the RXFIFO when in slave mode, as this is how we collect |
| 2204 | * the data. In DMA mode, we get events from the FIFO but also |
| 2205 | * things we cannot process, so do not use it. |
| 2206 | */ |
| 2207 | if (!using_dma(hsotg)) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2208 | s3c_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2209 | |
| 2210 | /* Enable interrupts for EP0 in and out */ |
| 2211 | s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); |
| 2212 | s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); |
| 2213 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2214 | __orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2215 | udelay(10); /* see openiboot */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2216 | __bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2217 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2218 | dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2219 | |
| 2220 | /* |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2221 | * DxEPCTL_USBActEp says RO in manual, but seems to be set by |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2222 | * writing to the EPCTL register.. |
| 2223 | */ |
| 2224 | |
| 2225 | /* set to read 1 8byte packet */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2226 | writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | |
| 2227 | DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2228 | |
| 2229 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2230 | DXEPCTL_CNAK | DXEPCTL_EPENA | |
| 2231 | DXEPCTL_USBACTEP, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2232 | hsotg->regs + DOEPCTL0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2233 | |
| 2234 | /* enable, but don't activate EP0in */ |
| 2235 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2236 | DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2237 | |
| 2238 | s3c_hsotg_enqueue_setup(hsotg); |
| 2239 | |
| 2240 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2241 | readl(hsotg->regs + DIEPCTL0), |
| 2242 | readl(hsotg->regs + DOEPCTL0)); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2243 | |
| 2244 | /* clear global NAKs */ |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2245 | writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK | DCTL_SFTDISCON, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2246 | hsotg->regs + DCTL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2247 | |
| 2248 | /* must be at-least 3ms to allow bus to see disconnect */ |
| 2249 | mdelay(3); |
| 2250 | |
Marek Szyprowski | ac3c81f | 2014-10-20 12:45:35 +0200 | [diff] [blame] | 2251 | hsotg->last_rst = jiffies; |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2252 | } |
Marek Szyprowski | ac3c81f | 2014-10-20 12:45:35 +0200 | [diff] [blame] | 2253 | |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2254 | static void s3c_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2255 | { |
| 2256 | /* set the soft-disconnect bit */ |
| 2257 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
| 2258 | } |
| 2259 | |
Dinh Nguyen | 510ffaa | 2014-11-11 11:13:36 -0600 | [diff] [blame] | 2260 | void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2261 | { |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2262 | /* remove the soft-disconnect and let's go */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2263 | __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2267 | * s3c_hsotg_irq - handle device interrupt |
| 2268 | * @irq: The IRQ number triggered |
| 2269 | * @pw: The pw value when registered the handler. |
| 2270 | */ |
| 2271 | static irqreturn_t s3c_hsotg_irq(int irq, void *pw) |
| 2272 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2273 | struct dwc2_hsotg *hsotg = pw; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2274 | int retry_count = 8; |
| 2275 | u32 gintsts; |
| 2276 | u32 gintmsk; |
| 2277 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2278 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2279 | irq_retry: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2280 | gintsts = readl(hsotg->regs + GINTSTS); |
| 2281 | gintmsk = readl(hsotg->regs + GINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2282 | |
| 2283 | dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", |
| 2284 | __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count); |
| 2285 | |
| 2286 | gintsts &= gintmsk; |
| 2287 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2288 | if (gintsts & GINTSTS_ENUMDONE) { |
| 2289 | writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2290 | |
| 2291 | s3c_hsotg_irq_enumdone(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2292 | } |
| 2293 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2294 | if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2295 | u32 daint = readl(hsotg->regs + DAINT); |
Robert Baldyga | 7e80465 | 2013-09-19 11:50:20 +0200 | [diff] [blame] | 2296 | u32 daintmsk = readl(hsotg->regs + DAINTMSK); |
| 2297 | u32 daint_out, daint_in; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2298 | int ep; |
| 2299 | |
Robert Baldyga | 7e80465 | 2013-09-19 11:50:20 +0200 | [diff] [blame] | 2300 | daint &= daintmsk; |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2301 | daint_out = daint >> DAINT_OUTEP_SHIFT; |
| 2302 | daint_in = daint & ~(daint_out << DAINT_OUTEP_SHIFT); |
Robert Baldyga | 7e80465 | 2013-09-19 11:50:20 +0200 | [diff] [blame] | 2303 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2304 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); |
| 2305 | |
| 2306 | for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { |
| 2307 | if (daint_out & 1) |
| 2308 | s3c_hsotg_epint(hsotg, ep, 0); |
| 2309 | } |
| 2310 | |
| 2311 | for (ep = 0; ep < 15 && daint_in; ep++, daint_in >>= 1) { |
| 2312 | if (daint_in & 1) |
| 2313 | s3c_hsotg_epint(hsotg, ep, 1); |
| 2314 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2317 | if (gintsts & GINTSTS_USBRST) { |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2318 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2319 | u32 usb_status = readl(hsotg->regs + GOTGCTL); |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2320 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2321 | dev_info(hsotg->dev, "%s: USBRst\n", __func__); |
| 2322 | dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2323 | readl(hsotg->regs + GNPTXSTS)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2324 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2325 | writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2326 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2327 | if (usb_status & GOTGCTL_BSESVLD) { |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2328 | if (time_after(jiffies, hsotg->last_rst + |
| 2329 | msecs_to_jiffies(200))) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2330 | |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2331 | kill_all_requests(hsotg, &hsotg->eps[0], |
| 2332 | -ECONNRESET, true); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2333 | |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2334 | s3c_hsotg_core_init_disconnected(hsotg); |
| 2335 | s3c_hsotg_core_connect(hsotg); |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2336 | } |
| 2337 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | /* check both FIFOs */ |
| 2341 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2342 | if (gintsts & GINTSTS_NPTXFEMP) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2343 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); |
| 2344 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2345 | /* |
| 2346 | * Disable the interrupt to stop it happening again |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2347 | * unless one of these endpoint routines decides that |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2348 | * it needs re-enabling |
| 2349 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2350 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2351 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2352 | s3c_hsotg_irq_fifoempty(hsotg, false); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2353 | } |
| 2354 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2355 | if (gintsts & GINTSTS_PTXFEMP) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2356 | dev_dbg(hsotg->dev, "PTxFEmp\n"); |
| 2357 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2358 | /* See note in GINTSTS_NPTxFEmp */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2359 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2360 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2361 | s3c_hsotg_irq_fifoempty(hsotg, true); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2364 | if (gintsts & GINTSTS_RXFLVL) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2365 | /* |
| 2366 | * note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2367 | * we need to retry s3c_hsotg_handle_rx if this is still |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2368 | * set. |
| 2369 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2370 | |
| 2371 | s3c_hsotg_handle_rx(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2372 | } |
| 2373 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2374 | if (gintsts & GINTSTS_ERLYSUSP) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2375 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2376 | writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2377 | } |
| 2378 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2379 | /* |
| 2380 | * these next two seem to crop-up occasionally causing the core |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2381 | * to shutdown the USB transfer, so try clearing them and logging |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2382 | * the occurrence. |
| 2383 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2384 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2385 | if (gintsts & GINTSTS_GOUTNAKEFF) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2386 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); |
| 2387 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2388 | writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2389 | |
| 2390 | s3c_hsotg_dump(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2391 | } |
| 2392 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2393 | if (gintsts & GINTSTS_GINNAKEFF) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2394 | dev_info(hsotg->dev, "GINNakEff triggered\n"); |
| 2395 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2396 | writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2397 | |
| 2398 | s3c_hsotg_dump(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2399 | } |
| 2400 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2401 | /* |
| 2402 | * if we've had fifo events, we should try and go around the |
| 2403 | * loop again to see if there's any point in returning yet. |
| 2404 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2405 | |
| 2406 | if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) |
| 2407 | goto irq_retry; |
| 2408 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2409 | spin_unlock(&hsotg->lock); |
| 2410 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2411 | return IRQ_HANDLED; |
| 2412 | } |
| 2413 | |
| 2414 | /** |
| 2415 | * s3c_hsotg_ep_enable - enable the given endpoint |
| 2416 | * @ep: The USB endpint to configure |
| 2417 | * @desc: The USB endpoint descriptor to configure with. |
| 2418 | * |
| 2419 | * This is called from the USB gadget code's usb_ep_enable(). |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2420 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2421 | static int s3c_hsotg_ep_enable(struct usb_ep *ep, |
| 2422 | const struct usb_endpoint_descriptor *desc) |
| 2423 | { |
| 2424 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2425 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2426 | unsigned long flags; |
| 2427 | int index = hs_ep->index; |
| 2428 | u32 epctrl_reg; |
| 2429 | u32 epctrl; |
| 2430 | u32 mps; |
| 2431 | int dir_in; |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2432 | int i, val, size; |
Julia Lawall | 19c190f | 2010-03-29 17:36:44 +0200 | [diff] [blame] | 2433 | int ret = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2434 | |
| 2435 | dev_dbg(hsotg->dev, |
| 2436 | "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n", |
| 2437 | __func__, ep->name, desc->bEndpointAddress, desc->bmAttributes, |
| 2438 | desc->wMaxPacketSize, desc->bInterval); |
| 2439 | |
| 2440 | /* not to be called for EP0 */ |
| 2441 | WARN_ON(index == 0); |
| 2442 | |
| 2443 | dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; |
| 2444 | if (dir_in != hs_ep->dir_in) { |
| 2445 | dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); |
| 2446 | return -EINVAL; |
| 2447 | } |
| 2448 | |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 2449 | mps = usb_endpoint_maxp(desc); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2450 | |
| 2451 | /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ |
| 2452 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2453 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2454 | epctrl = readl(hsotg->regs + epctrl_reg); |
| 2455 | |
| 2456 | dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", |
| 2457 | __func__, epctrl, epctrl_reg); |
| 2458 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2459 | spin_lock_irqsave(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2460 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2461 | epctrl &= ~(DXEPCTL_EPTYPE_MASK | DXEPCTL_MPS_MASK); |
| 2462 | epctrl |= DXEPCTL_MPS(mps); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2463 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2464 | /* |
| 2465 | * mark the endpoint as active, otherwise the core may ignore |
| 2466 | * transactions entirely for this endpoint |
| 2467 | */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2468 | epctrl |= DXEPCTL_USBACTEP; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2469 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2470 | /* |
| 2471 | * set the NAK status on the endpoint, otherwise we might try and |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2472 | * do something with data that we've yet got a request to process |
| 2473 | * since the RXFIFO will take data for an endpoint even if the |
| 2474 | * size register hasn't been set. |
| 2475 | */ |
| 2476 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2477 | epctrl |= DXEPCTL_SNAK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2478 | |
| 2479 | /* update the endpoint state */ |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 2480 | s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2481 | |
| 2482 | /* default, set to non-periodic */ |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 2483 | hs_ep->isochronous = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2484 | hs_ep->periodic = 0; |
Robert Baldyga | a18ed7b | 2013-09-19 11:50:21 +0200 | [diff] [blame] | 2485 | hs_ep->halted = 0; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 2486 | hs_ep->interval = desc->bInterval; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2487 | |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 2488 | if (hs_ep->interval > 1 && hs_ep->mc > 1) |
| 2489 | dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); |
| 2490 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2491 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
| 2492 | case USB_ENDPOINT_XFER_ISOC: |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2493 | epctrl |= DXEPCTL_EPTYPE_ISO; |
| 2494 | epctrl |= DXEPCTL_SETEVENFR; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 2495 | hs_ep->isochronous = 1; |
| 2496 | if (dir_in) |
| 2497 | hs_ep->periodic = 1; |
| 2498 | break; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2499 | |
| 2500 | case USB_ENDPOINT_XFER_BULK: |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2501 | epctrl |= DXEPCTL_EPTYPE_BULK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2502 | break; |
| 2503 | |
| 2504 | case USB_ENDPOINT_XFER_INT: |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2505 | if (dir_in) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2506 | hs_ep->periodic = 1; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2507 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2508 | epctrl |= DXEPCTL_EPTYPE_INTERRUPT; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2509 | break; |
| 2510 | |
| 2511 | case USB_ENDPOINT_XFER_CONTROL: |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2512 | epctrl |= DXEPCTL_EPTYPE_CONTROL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2513 | break; |
| 2514 | } |
| 2515 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2516 | /* |
| 2517 | * if the hardware has dedicated fifos, we must give each IN EP |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 2518 | * a unique tx-fifo even if it is non-periodic. |
| 2519 | */ |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2520 | if (dir_in && hsotg->dedicated_fifos) { |
| 2521 | size = hs_ep->ep.maxpacket*hs_ep->mc; |
| 2522 | for (i = 1; i <= 8; ++i) { |
| 2523 | if (hsotg->fifo_map & (1<<i)) |
| 2524 | continue; |
| 2525 | val = readl(hsotg->regs + DPTXFSIZN(i)); |
| 2526 | val = (val >> FIFOSIZE_DEPTH_SHIFT)*4; |
| 2527 | if (val < size) |
| 2528 | continue; |
| 2529 | hsotg->fifo_map |= 1<<i; |
| 2530 | |
| 2531 | epctrl |= DXEPCTL_TXFNUM(i); |
| 2532 | hs_ep->fifo_index = i; |
| 2533 | hs_ep->fifo_size = val; |
| 2534 | break; |
| 2535 | } |
Sudip Mukherjee | b585a48 | 2014-10-17 10:14:02 +0530 | [diff] [blame] | 2536 | if (i == 8) { |
| 2537 | ret = -ENOMEM; |
| 2538 | goto error; |
| 2539 | } |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2540 | } |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 2541 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2542 | /* for non control endpoints, set PID to D0 */ |
| 2543 | if (index) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2544 | epctrl |= DXEPCTL_SETD0PID; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2545 | |
| 2546 | dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", |
| 2547 | __func__, epctrl); |
| 2548 | |
| 2549 | writel(epctrl, hsotg->regs + epctrl_reg); |
| 2550 | dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", |
| 2551 | __func__, readl(hsotg->regs + epctrl_reg)); |
| 2552 | |
| 2553 | /* enable the endpoint interrupt */ |
| 2554 | s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); |
| 2555 | |
Sudip Mukherjee | b585a48 | 2014-10-17 10:14:02 +0530 | [diff] [blame] | 2556 | error: |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2557 | spin_unlock_irqrestore(&hsotg->lock, flags); |
Julia Lawall | 19c190f | 2010-03-29 17:36:44 +0200 | [diff] [blame] | 2558 | return ret; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2559 | } |
| 2560 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2561 | /** |
| 2562 | * s3c_hsotg_ep_disable - disable given endpoint |
| 2563 | * @ep: The endpoint to disable. |
| 2564 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2565 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) |
| 2566 | { |
| 2567 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2568 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2569 | int dir_in = hs_ep->dir_in; |
| 2570 | int index = hs_ep->index; |
| 2571 | unsigned long flags; |
| 2572 | u32 epctrl_reg; |
| 2573 | u32 ctrl; |
| 2574 | |
Marek Szyprowski | 1e01129 | 2014-09-09 10:44:54 +0200 | [diff] [blame] | 2575 | dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2576 | |
| 2577 | if (ep == &hsotg->eps[0].ep) { |
| 2578 | dev_err(hsotg->dev, "%s: called for ep0\n", __func__); |
| 2579 | return -EINVAL; |
| 2580 | } |
| 2581 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2582 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2583 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2584 | spin_lock_irqsave(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2585 | /* terminate all requests with shutdown */ |
| 2586 | kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); |
| 2587 | |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2588 | hsotg->fifo_map &= ~(1<<hs_ep->fifo_index); |
| 2589 | hs_ep->fifo_index = 0; |
| 2590 | hs_ep->fifo_size = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2591 | |
| 2592 | ctrl = readl(hsotg->regs + epctrl_reg); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2593 | ctrl &= ~DXEPCTL_EPENA; |
| 2594 | ctrl &= ~DXEPCTL_USBACTEP; |
| 2595 | ctrl |= DXEPCTL_SNAK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2596 | |
| 2597 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
| 2598 | writel(ctrl, hsotg->regs + epctrl_reg); |
| 2599 | |
| 2600 | /* disable endpoint interrupts */ |
| 2601 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); |
| 2602 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2603 | spin_unlock_irqrestore(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2604 | return 0; |
| 2605 | } |
| 2606 | |
| 2607 | /** |
| 2608 | * on_list - check request is on the given endpoint |
| 2609 | * @ep: The endpoint to check. |
| 2610 | * @test: The request to test if it is on the endpoint. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2611 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2612 | static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) |
| 2613 | { |
| 2614 | struct s3c_hsotg_req *req, *treq; |
| 2615 | |
| 2616 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
| 2617 | if (req == test) |
| 2618 | return true; |
| 2619 | } |
| 2620 | |
| 2621 | return false; |
| 2622 | } |
| 2623 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2624 | /** |
| 2625 | * s3c_hsotg_ep_dequeue - dequeue given endpoint |
| 2626 | * @ep: The endpoint to dequeue. |
| 2627 | * @req: The request to be removed from a queue. |
| 2628 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2629 | static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) |
| 2630 | { |
| 2631 | struct s3c_hsotg_req *hs_req = our_req(req); |
| 2632 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2633 | struct dwc2_hsotg *hs = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2634 | unsigned long flags; |
| 2635 | |
Marek Szyprowski | 1e01129 | 2014-09-09 10:44:54 +0200 | [diff] [blame] | 2636 | dev_dbg(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2637 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2638 | spin_lock_irqsave(&hs->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2639 | |
| 2640 | if (!on_list(hs_ep, hs_req)) { |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2641 | spin_unlock_irqrestore(&hs->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2642 | return -EINVAL; |
| 2643 | } |
| 2644 | |
| 2645 | s3c_hsotg_complete_request(hs, hs_ep, hs_req, -ECONNRESET); |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2646 | spin_unlock_irqrestore(&hs->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2647 | |
| 2648 | return 0; |
| 2649 | } |
| 2650 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2651 | /** |
| 2652 | * s3c_hsotg_ep_sethalt - set halt on a given endpoint |
| 2653 | * @ep: The endpoint to set halt. |
| 2654 | * @value: Set or unset the halt. |
| 2655 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2656 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) |
| 2657 | { |
| 2658 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2659 | struct dwc2_hsotg *hs = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2660 | int index = hs_ep->index; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2661 | u32 epreg; |
| 2662 | u32 epctl; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2663 | u32 xfertype; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2664 | |
| 2665 | dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value); |
| 2666 | |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 2667 | if (index == 0) { |
| 2668 | if (value) |
| 2669 | s3c_hsotg_stall_ep0(hs); |
| 2670 | else |
| 2671 | dev_warn(hs->dev, |
| 2672 | "%s: can't clear halt on ep0\n", __func__); |
| 2673 | return 0; |
| 2674 | } |
| 2675 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2676 | /* write both IN and OUT control registers */ |
| 2677 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2678 | epreg = DIEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2679 | epctl = readl(hs->regs + epreg); |
| 2680 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2681 | if (value) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2682 | epctl |= DXEPCTL_STALL + DXEPCTL_SNAK; |
| 2683 | if (epctl & DXEPCTL_EPENA) |
| 2684 | epctl |= DXEPCTL_EPDIS; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2685 | } else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2686 | epctl &= ~DXEPCTL_STALL; |
| 2687 | xfertype = epctl & DXEPCTL_EPTYPE_MASK; |
| 2688 | if (xfertype == DXEPCTL_EPTYPE_BULK || |
| 2689 | xfertype == DXEPCTL_EPTYPE_INTERRUPT) |
| 2690 | epctl |= DXEPCTL_SETD0PID; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2691 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2692 | |
| 2693 | writel(epctl, hs->regs + epreg); |
| 2694 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2695 | epreg = DOEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2696 | epctl = readl(hs->regs + epreg); |
| 2697 | |
| 2698 | if (value) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2699 | epctl |= DXEPCTL_STALL; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2700 | else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2701 | epctl &= ~DXEPCTL_STALL; |
| 2702 | xfertype = epctl & DXEPCTL_EPTYPE_MASK; |
| 2703 | if (xfertype == DXEPCTL_EPTYPE_BULK || |
| 2704 | xfertype == DXEPCTL_EPTYPE_INTERRUPT) |
| 2705 | epctl |= DXEPCTL_SETD0PID; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2706 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2707 | |
| 2708 | writel(epctl, hs->regs + epreg); |
| 2709 | |
Robert Baldyga | a18ed7b | 2013-09-19 11:50:21 +0200 | [diff] [blame] | 2710 | hs_ep->halted = value; |
| 2711 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2712 | return 0; |
| 2713 | } |
| 2714 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2715 | /** |
| 2716 | * s3c_hsotg_ep_sethalt_lock - set halt on a given endpoint with lock held |
| 2717 | * @ep: The endpoint to set halt. |
| 2718 | * @value: Set or unset the halt. |
| 2719 | */ |
| 2720 | static int s3c_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value) |
| 2721 | { |
| 2722 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2723 | struct dwc2_hsotg *hs = hs_ep->parent; |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2724 | unsigned long flags = 0; |
| 2725 | int ret = 0; |
| 2726 | |
| 2727 | spin_lock_irqsave(&hs->lock, flags); |
| 2728 | ret = s3c_hsotg_ep_sethalt(ep, value); |
| 2729 | spin_unlock_irqrestore(&hs->lock, flags); |
| 2730 | |
| 2731 | return ret; |
| 2732 | } |
| 2733 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2734 | static struct usb_ep_ops s3c_hsotg_ep_ops = { |
| 2735 | .enable = s3c_hsotg_ep_enable, |
| 2736 | .disable = s3c_hsotg_ep_disable, |
| 2737 | .alloc_request = s3c_hsotg_ep_alloc_request, |
| 2738 | .free_request = s3c_hsotg_ep_free_request, |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2739 | .queue = s3c_hsotg_ep_queue_lock, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2740 | .dequeue = s3c_hsotg_ep_dequeue, |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2741 | .set_halt = s3c_hsotg_ep_sethalt_lock, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2742 | /* note, don't believe we have any call for the fifo routines */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2743 | }; |
| 2744 | |
| 2745 | /** |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2746 | * s3c_hsotg_phy_enable - enable platform phy dev |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2747 | * @hsotg: The driver state |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2748 | * |
| 2749 | * A wrapper for platform code responsible for controlling |
| 2750 | * low-level USB code |
| 2751 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2752 | static void s3c_hsotg_phy_enable(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2753 | { |
| 2754 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
| 2755 | |
| 2756 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 2757 | |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2758 | if (hsotg->uphy) |
| 2759 | usb_phy_init(hsotg->uphy); |
| 2760 | else if (hsotg->plat && hsotg->plat->phy_init) |
| 2761 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); |
| 2762 | else { |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 2763 | phy_init(hsotg->phy); |
| 2764 | phy_power_on(hsotg->phy); |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2765 | } |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | /** |
| 2769 | * s3c_hsotg_phy_disable - disable platform phy dev |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2770 | * @hsotg: The driver state |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2771 | * |
| 2772 | * A wrapper for platform code responsible for controlling |
| 2773 | * low-level USB code |
| 2774 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2775 | static void s3c_hsotg_phy_disable(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2776 | { |
| 2777 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
| 2778 | |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2779 | if (hsotg->uphy) |
| 2780 | usb_phy_shutdown(hsotg->uphy); |
| 2781 | else if (hsotg->plat && hsotg->plat->phy_exit) |
| 2782 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
| 2783 | else { |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 2784 | phy_power_off(hsotg->phy); |
| 2785 | phy_exit(hsotg->phy); |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2786 | } |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2787 | } |
| 2788 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2789 | /** |
| 2790 | * s3c_hsotg_init - initalize the usb core |
| 2791 | * @hsotg: The driver state |
| 2792 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2793 | static void s3c_hsotg_init(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2794 | { |
| 2795 | /* unmask subset of endpoint interrupts */ |
| 2796 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2797 | writel(DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | |
| 2798 | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK, |
| 2799 | hsotg->regs + DIEPMSK); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2800 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2801 | writel(DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | |
| 2802 | DOEPMSK_EPDISBLDMSK | DOEPMSK_XFERCOMPLMSK, |
| 2803 | hsotg->regs + DOEPMSK); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2804 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2805 | writel(0, hsotg->regs + DAINTMSK); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2806 | |
| 2807 | /* Be in disconnected state until gadget is registered */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2808 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2809 | |
| 2810 | if (0) { |
| 2811 | /* post global nak until we're ready */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2812 | writel(DCTL_SGNPINNAK | DCTL_SGOUTNAK, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2813 | hsotg->regs + DCTL); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | /* setup fifos */ |
| 2817 | |
| 2818 | dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2819 | readl(hsotg->regs + GRXFSIZ), |
| 2820 | readl(hsotg->regs + GNPTXFSIZ)); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2821 | |
| 2822 | s3c_hsotg_init_fifo(hsotg); |
| 2823 | |
| 2824 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2825 | writel(GUSBCFG_PHYIF16 | GUSBCFG_TOUTCAL(7) | (0x5 << 10), |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2826 | hsotg->regs + GUSBCFG); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2827 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2828 | writel(using_dma(hsotg) ? GAHBCFG_DMA_EN : 0x0, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2829 | hsotg->regs + GAHBCFG); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2830 | } |
| 2831 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2832 | /** |
| 2833 | * s3c_hsotg_udc_start - prepare the udc for work |
| 2834 | * @gadget: The usb gadget state |
| 2835 | * @driver: The usb gadget driver |
| 2836 | * |
| 2837 | * Perform initialization to prepare udc device and driver |
| 2838 | * to work. |
| 2839 | */ |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2840 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, |
| 2841 | struct usb_gadget_driver *driver) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2842 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2843 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2844 | unsigned long flags; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2845 | int ret; |
| 2846 | |
| 2847 | if (!hsotg) { |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 2848 | pr_err("%s: called with no device\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2849 | return -ENODEV; |
| 2850 | } |
| 2851 | |
| 2852 | if (!driver) { |
| 2853 | dev_err(hsotg->dev, "%s: no driver\n", __func__); |
| 2854 | return -EINVAL; |
| 2855 | } |
| 2856 | |
Michal Nazarewicz | 7177aed | 2011-11-19 18:27:38 +0100 | [diff] [blame] | 2857 | if (driver->max_speed < USB_SPEED_FULL) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2858 | dev_err(hsotg->dev, "%s: bad speed\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2859 | |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2860 | if (!driver->setup) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2861 | dev_err(hsotg->dev, "%s: missing entry points\n", __func__); |
| 2862 | return -EINVAL; |
| 2863 | } |
| 2864 | |
| 2865 | WARN_ON(hsotg->driver); |
| 2866 | |
| 2867 | driver->driver.bus = NULL; |
| 2868 | hsotg->driver = driver; |
Alexandre Pereira da Silva | 7d7b229 | 2012-06-26 11:27:10 -0300 | [diff] [blame] | 2869 | hsotg->gadget.dev.of_node = hsotg->dev->of_node; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2870 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
| 2871 | |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2872 | clk_enable(hsotg->clk); |
| 2873 | |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2874 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
| 2875 | hsotg->supplies); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2876 | if (ret) { |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2877 | dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2878 | goto err; |
| 2879 | } |
| 2880 | |
Marek Szyprowski | c816c47 | 2014-10-20 12:45:37 +0200 | [diff] [blame] | 2881 | s3c_hsotg_phy_enable(hsotg); |
| 2882 | |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2883 | spin_lock_irqsave(&hsotg->lock, flags); |
| 2884 | s3c_hsotg_init(hsotg); |
| 2885 | s3c_hsotg_core_init_disconnected(hsotg); |
| 2886 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 2887 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2888 | dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2889 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2890 | return 0; |
| 2891 | |
| 2892 | err: |
| 2893 | hsotg->driver = NULL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2894 | return ret; |
| 2895 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2896 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2897 | /** |
| 2898 | * s3c_hsotg_udc_stop - stop the udc |
| 2899 | * @gadget: The usb gadget state |
| 2900 | * @driver: The usb gadget driver |
| 2901 | * |
| 2902 | * Stop udc hw block and stay tunned for future transmissions |
| 2903 | */ |
Felipe Balbi | 22835b8 | 2014-10-17 12:05:12 -0500 | [diff] [blame] | 2904 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2905 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2906 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
Lukasz Majewski | 2b19a52 | 2012-06-14 10:02:25 +0200 | [diff] [blame] | 2907 | unsigned long flags = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2908 | int ep; |
| 2909 | |
| 2910 | if (!hsotg) |
| 2911 | return -ENODEV; |
| 2912 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2913 | /* all endpoints should be shutdown */ |
Robert Baldyga | 604eac3c | 2014-09-09 10:44:13 +0200 | [diff] [blame] | 2914 | for (ep = 1; ep < hsotg->num_of_eps; ep++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2915 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
| 2916 | |
Lukasz Majewski | 2b19a52 | 2012-06-14 10:02:25 +0200 | [diff] [blame] | 2917 | spin_lock_irqsave(&hsotg->lock, flags); |
| 2918 | |
Marek Szyprowski | 32805c3 | 2014-10-20 12:45:33 +0200 | [diff] [blame] | 2919 | hsotg->driver = NULL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2920 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2921 | |
Lukasz Majewski | 2b19a52 | 2012-06-14 10:02:25 +0200 | [diff] [blame] | 2922 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 2923 | |
Marek Szyprowski | c816c47 | 2014-10-20 12:45:37 +0200 | [diff] [blame] | 2924 | s3c_hsotg_phy_disable(hsotg); |
| 2925 | |
Marek Szyprowski | c8c1025 | 2013-09-12 16:18:48 +0200 | [diff] [blame] | 2926 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2927 | |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2928 | clk_disable(hsotg->clk); |
| 2929 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2930 | return 0; |
| 2931 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2932 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2933 | /** |
| 2934 | * s3c_hsotg_gadget_getframe - read the frame number |
| 2935 | * @gadget: The usb gadget state |
| 2936 | * |
| 2937 | * Read the {micro} frame number |
| 2938 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2939 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) |
| 2940 | { |
| 2941 | return s3c_hsotg_read_frameno(to_hsotg(gadget)); |
| 2942 | } |
| 2943 | |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2944 | /** |
| 2945 | * s3c_hsotg_pullup - connect/disconnect the USB PHY |
| 2946 | * @gadget: The usb gadget state |
| 2947 | * @is_on: Current state of the USB PHY |
| 2948 | * |
| 2949 | * Connect/Disconnect the USB PHY pullup |
| 2950 | */ |
| 2951 | static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) |
| 2952 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2953 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2954 | unsigned long flags = 0; |
| 2955 | |
Andrzej Pietrasiewicz | d784f1e | 2014-09-09 10:44:53 +0200 | [diff] [blame] | 2956 | dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2957 | |
| 2958 | spin_lock_irqsave(&hsotg->lock, flags); |
| 2959 | if (is_on) { |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2960 | clk_enable(hsotg->clk); |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2961 | s3c_hsotg_core_connect(hsotg); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2962 | } else { |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2963 | s3c_hsotg_core_disconnect(hsotg); |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2964 | clk_disable(hsotg->clk); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
| 2968 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 2969 | |
| 2970 | return 0; |
| 2971 | } |
| 2972 | |
Felipe Balbi | eeef458 | 2013-01-24 17:58:16 +0200 | [diff] [blame] | 2973 | static const struct usb_gadget_ops s3c_hsotg_gadget_ops = { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2974 | .get_frame = s3c_hsotg_gadget_getframe, |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2975 | .udc_start = s3c_hsotg_udc_start, |
| 2976 | .udc_stop = s3c_hsotg_udc_stop, |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2977 | .pullup = s3c_hsotg_pullup, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2978 | }; |
| 2979 | |
| 2980 | /** |
| 2981 | * s3c_hsotg_initep - initialise a single endpoint |
| 2982 | * @hsotg: The device state. |
| 2983 | * @hs_ep: The endpoint to be initialised. |
| 2984 | * @epnum: The endpoint number |
| 2985 | * |
| 2986 | * Initialise the given endpoint (as part of the probe and device state |
| 2987 | * creation) to give to the gadget driver. Setup the endpoint name, any |
| 2988 | * direction information and other state that may be required. |
| 2989 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2990 | static void s3c_hsotg_initep(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2991 | struct s3c_hsotg_ep *hs_ep, |
| 2992 | int epnum) |
| 2993 | { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2994 | char *dir; |
| 2995 | |
| 2996 | if (epnum == 0) |
| 2997 | dir = ""; |
| 2998 | else if ((epnum % 2) == 0) { |
| 2999 | dir = "out"; |
| 3000 | } else { |
| 3001 | dir = "in"; |
| 3002 | hs_ep->dir_in = 1; |
| 3003 | } |
| 3004 | |
| 3005 | hs_ep->index = epnum; |
| 3006 | |
| 3007 | snprintf(hs_ep->name, sizeof(hs_ep->name), "ep%d%s", epnum, dir); |
| 3008 | |
| 3009 | INIT_LIST_HEAD(&hs_ep->queue); |
| 3010 | INIT_LIST_HEAD(&hs_ep->ep.ep_list); |
| 3011 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3012 | /* add to the list of endpoints known by the gadget driver */ |
| 3013 | if (epnum) |
| 3014 | list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); |
| 3015 | |
| 3016 | hs_ep->parent = hsotg; |
| 3017 | hs_ep->ep.name = hs_ep->name; |
Robert Baldyga | e117e74 | 2013-12-13 12:23:38 +0100 | [diff] [blame] | 3018 | usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3019 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
| 3020 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3021 | /* |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3022 | * if we're using dma, we need to set the next-endpoint pointer |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3023 | * to be something valid. |
| 3024 | */ |
| 3025 | |
| 3026 | if (using_dma(hsotg)) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3027 | u32 next = DXEPCTL_NEXTEP((epnum + 1) % 15); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3028 | writel(next, hsotg->regs + DIEPCTL(epnum)); |
| 3029 | writel(next, hsotg->regs + DOEPCTL(epnum)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3033 | /** |
| 3034 | * s3c_hsotg_hw_cfg - read HW configuration registers |
| 3035 | * @param: The device state |
| 3036 | * |
| 3037 | * Read the USB core HW configuration registers |
| 3038 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3039 | static void s3c_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3040 | { |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3041 | u32 cfg2, cfg3, cfg4; |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 3042 | /* check hardware configuration */ |
| 3043 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3044 | cfg2 = readl(hsotg->regs + 0x48); |
| 3045 | hsotg->num_of_eps = (cfg2 >> 10) & 0xF; |
| 3046 | |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3047 | cfg3 = readl(hsotg->regs + 0x4C); |
| 3048 | hsotg->fifo_mem = (cfg3 >> 16); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3049 | |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 3050 | cfg4 = readl(hsotg->regs + 0x50); |
| 3051 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; |
| 3052 | |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3053 | dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", |
| 3054 | hsotg->num_of_eps, |
| 3055 | hsotg->dedicated_fifos ? "dedicated" : "shared", |
| 3056 | hsotg->fifo_mem); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3057 | } |
| 3058 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3059 | /** |
| 3060 | * s3c_hsotg_dump - dump state of the udc |
| 3061 | * @param: The device state |
| 3062 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3063 | static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3064 | { |
Mark Brown | 83a0180 | 2011-06-01 17:16:15 +0100 | [diff] [blame] | 3065 | #ifdef DEBUG |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3066 | struct device *dev = hsotg->dev; |
| 3067 | void __iomem *regs = hsotg->regs; |
| 3068 | u32 val; |
| 3069 | int idx; |
| 3070 | |
| 3071 | dev_info(dev, "DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3072 | readl(regs + DCFG), readl(regs + DCTL), |
| 3073 | readl(regs + DIEPMSK)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3074 | |
| 3075 | dev_info(dev, "GAHBCFG=0x%08x, 0x44=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3076 | readl(regs + GAHBCFG), readl(regs + 0x44)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3077 | |
| 3078 | dev_info(dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3079 | readl(regs + GRXFSIZ), readl(regs + GNPTXFSIZ)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3080 | |
| 3081 | /* show periodic fifo settings */ |
| 3082 | |
| 3083 | for (idx = 1; idx <= 15; idx++) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3084 | val = readl(regs + DPTXFSIZN(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3085 | dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3086 | val >> FIFOSIZE_DEPTH_SHIFT, |
| 3087 | val & FIFOSIZE_STARTADDR_MASK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | for (idx = 0; idx < 15; idx++) { |
| 3091 | dev_info(dev, |
| 3092 | "ep%d-in: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", idx, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3093 | readl(regs + DIEPCTL(idx)), |
| 3094 | readl(regs + DIEPTSIZ(idx)), |
| 3095 | readl(regs + DIEPDMA(idx))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3096 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3097 | val = readl(regs + DOEPCTL(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3098 | dev_info(dev, |
| 3099 | "ep%d-out: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3100 | idx, readl(regs + DOEPCTL(idx)), |
| 3101 | readl(regs + DOEPTSIZ(idx)), |
| 3102 | readl(regs + DOEPDMA(idx))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3103 | |
| 3104 | } |
| 3105 | |
| 3106 | dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3107 | readl(regs + DVBUSDIS), readl(regs + DVBUSPULSE)); |
Mark Brown | 83a0180 | 2011-06-01 17:16:15 +0100 | [diff] [blame] | 3108 | #endif |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3109 | } |
| 3110 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3111 | /** |
| 3112 | * state_show - debugfs: show overall driver and device state. |
| 3113 | * @seq: The seq file to write to. |
| 3114 | * @v: Unused parameter. |
| 3115 | * |
| 3116 | * This debugfs entry shows the overall state of the hardware and |
| 3117 | * some general information about each of the endpoints available |
| 3118 | * to the system. |
| 3119 | */ |
| 3120 | static int state_show(struct seq_file *seq, void *v) |
| 3121 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3122 | struct dwc2_hsotg *hsotg = seq->private; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3123 | void __iomem *regs = hsotg->regs; |
| 3124 | int idx; |
| 3125 | |
| 3126 | seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3127 | readl(regs + DCFG), |
| 3128 | readl(regs + DCTL), |
| 3129 | readl(regs + DSTS)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3130 | |
| 3131 | seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3132 | readl(regs + DIEPMSK), readl(regs + DOEPMSK)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3133 | |
| 3134 | seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3135 | readl(regs + GINTMSK), |
| 3136 | readl(regs + GINTSTS)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3137 | |
| 3138 | seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3139 | readl(regs + DAINTMSK), |
| 3140 | readl(regs + DAINT)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3141 | |
| 3142 | seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3143 | readl(regs + GNPTXSTS), |
| 3144 | readl(regs + GRXSTSR)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3145 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3146 | seq_puts(seq, "\nEndpoint status:\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3147 | |
| 3148 | for (idx = 0; idx < 15; idx++) { |
| 3149 | u32 in, out; |
| 3150 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3151 | in = readl(regs + DIEPCTL(idx)); |
| 3152 | out = readl(regs + DOEPCTL(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3153 | |
| 3154 | seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", |
| 3155 | idx, in, out); |
| 3156 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3157 | in = readl(regs + DIEPTSIZ(idx)); |
| 3158 | out = readl(regs + DOEPTSIZ(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3159 | |
| 3160 | seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", |
| 3161 | in, out); |
| 3162 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3163 | seq_puts(seq, "\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | return 0; |
| 3167 | } |
| 3168 | |
| 3169 | static int state_open(struct inode *inode, struct file *file) |
| 3170 | { |
| 3171 | return single_open(file, state_show, inode->i_private); |
| 3172 | } |
| 3173 | |
| 3174 | static const struct file_operations state_fops = { |
| 3175 | .owner = THIS_MODULE, |
| 3176 | .open = state_open, |
| 3177 | .read = seq_read, |
| 3178 | .llseek = seq_lseek, |
| 3179 | .release = single_release, |
| 3180 | }; |
| 3181 | |
| 3182 | /** |
| 3183 | * fifo_show - debugfs: show the fifo information |
| 3184 | * @seq: The seq_file to write data to. |
| 3185 | * @v: Unused parameter. |
| 3186 | * |
| 3187 | * Show the FIFO information for the overall fifo and all the |
| 3188 | * periodic transmission FIFOs. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3189 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3190 | static int fifo_show(struct seq_file *seq, void *v) |
| 3191 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3192 | struct dwc2_hsotg *hsotg = seq->private; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3193 | void __iomem *regs = hsotg->regs; |
| 3194 | u32 val; |
| 3195 | int idx; |
| 3196 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3197 | seq_puts(seq, "Non-periodic FIFOs:\n"); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3198 | seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3199 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3200 | val = readl(regs + GNPTXFSIZ); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3201 | seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3202 | val >> FIFOSIZE_DEPTH_SHIFT, |
| 3203 | val & FIFOSIZE_DEPTH_MASK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3204 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3205 | seq_puts(seq, "\nPeriodic TXFIFOs:\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3206 | |
| 3207 | for (idx = 1; idx <= 15; idx++) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3208 | val = readl(regs + DPTXFSIZN(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3209 | |
| 3210 | seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3211 | val >> FIFOSIZE_DEPTH_SHIFT, |
| 3212 | val & FIFOSIZE_STARTADDR_MASK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | return 0; |
| 3216 | } |
| 3217 | |
| 3218 | static int fifo_open(struct inode *inode, struct file *file) |
| 3219 | { |
| 3220 | return single_open(file, fifo_show, inode->i_private); |
| 3221 | } |
| 3222 | |
| 3223 | static const struct file_operations fifo_fops = { |
| 3224 | .owner = THIS_MODULE, |
| 3225 | .open = fifo_open, |
| 3226 | .read = seq_read, |
| 3227 | .llseek = seq_lseek, |
| 3228 | .release = single_release, |
| 3229 | }; |
| 3230 | |
| 3231 | |
| 3232 | static const char *decode_direction(int is_in) |
| 3233 | { |
| 3234 | return is_in ? "in" : "out"; |
| 3235 | } |
| 3236 | |
| 3237 | /** |
| 3238 | * ep_show - debugfs: show the state of an endpoint. |
| 3239 | * @seq: The seq_file to write data to. |
| 3240 | * @v: Unused parameter. |
| 3241 | * |
| 3242 | * This debugfs entry shows the state of the given endpoint (one is |
| 3243 | * registered for each available). |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3244 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3245 | static int ep_show(struct seq_file *seq, void *v) |
| 3246 | { |
| 3247 | struct s3c_hsotg_ep *ep = seq->private; |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3248 | struct dwc2_hsotg *hsotg = ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3249 | struct s3c_hsotg_req *req; |
| 3250 | void __iomem *regs = hsotg->regs; |
| 3251 | int index = ep->index; |
| 3252 | int show_limit = 15; |
| 3253 | unsigned long flags; |
| 3254 | |
| 3255 | seq_printf(seq, "Endpoint index %d, named %s, dir %s:\n", |
| 3256 | ep->index, ep->ep.name, decode_direction(ep->dir_in)); |
| 3257 | |
| 3258 | /* first show the register state */ |
| 3259 | |
| 3260 | seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3261 | readl(regs + DIEPCTL(index)), |
| 3262 | readl(regs + DOEPCTL(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3263 | |
| 3264 | seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3265 | readl(regs + DIEPDMA(index)), |
| 3266 | readl(regs + DOEPDMA(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3267 | |
| 3268 | seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3269 | readl(regs + DIEPINT(index)), |
| 3270 | readl(regs + DOEPINT(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3271 | |
| 3272 | seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3273 | readl(regs + DIEPTSIZ(index)), |
| 3274 | readl(regs + DOEPTSIZ(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3275 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3276 | seq_puts(seq, "\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3277 | seq_printf(seq, "mps %d\n", ep->ep.maxpacket); |
| 3278 | seq_printf(seq, "total_data=%ld\n", ep->total_data); |
| 3279 | |
| 3280 | seq_printf(seq, "request list (%p,%p):\n", |
| 3281 | ep->queue.next, ep->queue.prev); |
| 3282 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 3283 | spin_lock_irqsave(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3284 | |
| 3285 | list_for_each_entry(req, &ep->queue, queue) { |
| 3286 | if (--show_limit < 0) { |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3287 | seq_puts(seq, "not showing more requests...\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3288 | break; |
| 3289 | } |
| 3290 | |
| 3291 | seq_printf(seq, "%c req %p: %d bytes @%p, ", |
| 3292 | req == ep->req ? '*' : ' ', |
| 3293 | req, req->req.length, req->req.buf); |
| 3294 | seq_printf(seq, "%d done, res %d\n", |
| 3295 | req->req.actual, req->req.status); |
| 3296 | } |
| 3297 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 3298 | spin_unlock_irqrestore(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3299 | |
| 3300 | return 0; |
| 3301 | } |
| 3302 | |
| 3303 | static int ep_open(struct inode *inode, struct file *file) |
| 3304 | { |
| 3305 | return single_open(file, ep_show, inode->i_private); |
| 3306 | } |
| 3307 | |
| 3308 | static const struct file_operations ep_fops = { |
| 3309 | .owner = THIS_MODULE, |
| 3310 | .open = ep_open, |
| 3311 | .read = seq_read, |
| 3312 | .llseek = seq_lseek, |
| 3313 | .release = single_release, |
| 3314 | }; |
| 3315 | |
| 3316 | /** |
| 3317 | * s3c_hsotg_create_debug - create debugfs directory and files |
| 3318 | * @hsotg: The driver state |
| 3319 | * |
| 3320 | * Create the debugfs files to allow the user to get information |
| 3321 | * about the state of the system. The directory name is created |
| 3322 | * with the same name as the device itself, in case we end up |
| 3323 | * with multiple blocks in future systems. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3324 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3325 | static void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3326 | { |
| 3327 | struct dentry *root; |
| 3328 | unsigned epidx; |
| 3329 | |
| 3330 | root = debugfs_create_dir(dev_name(hsotg->dev), NULL); |
| 3331 | hsotg->debug_root = root; |
| 3332 | if (IS_ERR(root)) { |
| 3333 | dev_err(hsotg->dev, "cannot create debug root\n"); |
| 3334 | return; |
| 3335 | } |
| 3336 | |
| 3337 | /* create general state file */ |
| 3338 | |
| 3339 | hsotg->debug_file = debugfs_create_file("state", 0444, root, |
| 3340 | hsotg, &state_fops); |
| 3341 | |
| 3342 | if (IS_ERR(hsotg->debug_file)) |
| 3343 | dev_err(hsotg->dev, "%s: failed to create state\n", __func__); |
| 3344 | |
| 3345 | hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root, |
| 3346 | hsotg, &fifo_fops); |
| 3347 | |
| 3348 | if (IS_ERR(hsotg->debug_fifo)) |
| 3349 | dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__); |
| 3350 | |
| 3351 | /* create one file for each endpoint */ |
| 3352 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3353 | for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3354 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; |
| 3355 | |
| 3356 | ep->debugfs = debugfs_create_file(ep->name, 0444, |
| 3357 | root, ep, &ep_fops); |
| 3358 | |
| 3359 | if (IS_ERR(ep->debugfs)) |
| 3360 | dev_err(hsotg->dev, "failed to create %s debug file\n", |
| 3361 | ep->name); |
| 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | /** |
| 3366 | * s3c_hsotg_delete_debug - cleanup debugfs entries |
| 3367 | * @hsotg: The driver state |
| 3368 | * |
| 3369 | * Cleanup (remove) the debugfs files for use on module exit. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3370 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3371 | static void s3c_hsotg_delete_debug(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3372 | { |
| 3373 | unsigned epidx; |
| 3374 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3375 | for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3376 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; |
| 3377 | debugfs_remove(ep->debugfs); |
| 3378 | } |
| 3379 | |
| 3380 | debugfs_remove(hsotg->debug_file); |
| 3381 | debugfs_remove(hsotg->debug_fifo); |
| 3382 | debugfs_remove(hsotg->debug_root); |
| 3383 | } |
| 3384 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3385 | /** |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3386 | * dwc2_gadget_init - init function for gadget |
| 3387 | * @dwc2: The data structure for the DWC2 driver. |
| 3388 | * @irq: The IRQ number for the controller. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3389 | */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3390 | int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3391 | { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3392 | struct device *dev = hsotg->dev; |
| 3393 | struct s3c_hsotg_plat *plat = dev->platform_data; |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3394 | struct phy *phy; |
| 3395 | struct usb_phy *uphy; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3396 | struct s3c_hsotg_ep *eps; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3397 | int epnum; |
| 3398 | int ret; |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3399 | int i; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3400 | |
Kamil Debski | 1b59fc7 | 2014-09-09 10:44:52 +0200 | [diff] [blame] | 3401 | /* Set default UTMI width */ |
| 3402 | hsotg->phyif = GUSBCFG_PHYIF16; |
| 3403 | |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3404 | /* |
| 3405 | * Attempt to find a generic PHY, then look for an old style |
| 3406 | * USB PHY, finally fall back to pdata |
| 3407 | */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3408 | phy = devm_phy_get(dev, "usb2-phy"); |
Felipe Balbi | f4f5ba5 | 2013-03-15 10:56:19 +0200 | [diff] [blame] | 3409 | if (IS_ERR(phy)) { |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3410 | uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
| 3411 | if (IS_ERR(uphy)) { |
| 3412 | /* Fallback for pdata */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3413 | plat = dev_get_platdata(dev); |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3414 | if (!plat) { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3415 | dev_err(dev, |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3416 | "no platform data or transceiver defined\n"); |
| 3417 | return -EPROBE_DEFER; |
| 3418 | } |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 3419 | hsotg->plat = plat; |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3420 | } else |
| 3421 | hsotg->uphy = uphy; |
Kamil Debski | 1b59fc7 | 2014-09-09 10:44:52 +0200 | [diff] [blame] | 3422 | } else { |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 3423 | hsotg->phy = phy; |
Kamil Debski | 1b59fc7 | 2014-09-09 10:44:52 +0200 | [diff] [blame] | 3424 | /* |
| 3425 | * If using the generic PHY framework, check if the PHY bus |
| 3426 | * width is 8-bit and set the phyif appropriately. |
| 3427 | */ |
| 3428 | if (phy_get_bus_width(phy) == 8) |
| 3429 | hsotg->phyif = GUSBCFG_PHYIF8; |
| 3430 | } |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 3431 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3432 | hsotg->clk = devm_clk_get(dev, "otg"); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3433 | if (IS_ERR(hsotg->clk)) { |
Dinh Nguyen | 8d736d8 | 2014-11-11 11:13:38 -0600 | [diff] [blame^] | 3434 | hsotg->clk = NULL; |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3435 | dev_err(dev, "cannot get otg clock\n"); |
Sachin Kamat | 338edab | 2012-05-18 14:33:46 +0530 | [diff] [blame] | 3436 | return PTR_ERR(hsotg->clk); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3437 | } |
| 3438 | |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 3439 | hsotg->gadget.max_speed = USB_SPEED_HIGH; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3440 | hsotg->gadget.ops = &s3c_hsotg_gadget_ops; |
| 3441 | hsotg->gadget.name = dev_name(dev); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3442 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3443 | /* reset the system */ |
| 3444 | |
Lukasz Majewski | 04b4a0f | 2012-05-04 14:17:15 +0200 | [diff] [blame] | 3445 | clk_prepare_enable(hsotg->clk); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3446 | |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3447 | /* regulators */ |
| 3448 | |
| 3449 | for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) |
| 3450 | hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; |
| 3451 | |
Sachin Kamat | cd76213 | 2013-01-08 14:27:00 +0530 | [diff] [blame] | 3452 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3453 | hsotg->supplies); |
| 3454 | if (ret) { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3455 | dev_err(dev, "failed to request supplies: %d\n", ret); |
Sachin Kamat | 338edab | 2012-05-18 14:33:46 +0530 | [diff] [blame] | 3456 | goto err_clk; |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
| 3460 | hsotg->supplies); |
| 3461 | |
| 3462 | if (ret) { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3463 | dev_err(dev, "failed to enable supplies: %d\n", ret); |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3464 | goto err_supplies; |
| 3465 | } |
| 3466 | |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 3467 | /* usb phy enable */ |
| 3468 | s3c_hsotg_phy_enable(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3469 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3470 | s3c_hsotg_corereset(hsotg); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3471 | s3c_hsotg_hw_cfg(hsotg); |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3472 | s3c_hsotg_init(hsotg); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3473 | |
Dinh Nguyen | db8178c | 2014-11-11 11:13:37 -0600 | [diff] [blame] | 3474 | ret = devm_request_irq(hsotg->dev, irq, s3c_hsotg_irq, IRQF_SHARED, |
| 3475 | dev_name(hsotg->dev), hsotg); |
Marek Szyprowski | eb3c56c | 2014-09-09 10:44:12 +0200 | [diff] [blame] | 3476 | if (ret < 0) { |
| 3477 | s3c_hsotg_phy_disable(hsotg); |
| 3478 | clk_disable_unprepare(hsotg->clk); |
| 3479 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
| 3480 | hsotg->supplies); |
Dinh Nguyen | db8178c | 2014-11-11 11:13:37 -0600 | [diff] [blame] | 3481 | dev_err(dev, "cannot claim IRQ for gadget\n"); |
Marek Szyprowski | eb3c56c | 2014-09-09 10:44:12 +0200 | [diff] [blame] | 3482 | goto err_clk; |
| 3483 | } |
| 3484 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3485 | /* hsotg->num_of_eps holds number of EPs other than ep0 */ |
| 3486 | |
| 3487 | if (hsotg->num_of_eps == 0) { |
| 3488 | dev_err(dev, "wrong number of EPs (zero)\n"); |
Julia Lawall | dfdda5a | 2012-08-14 08:47:34 +0200 | [diff] [blame] | 3489 | ret = -EINVAL; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3490 | goto err_supplies; |
| 3491 | } |
| 3492 | |
| 3493 | eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), |
| 3494 | GFP_KERNEL); |
| 3495 | if (!eps) { |
Julia Lawall | dfdda5a | 2012-08-14 08:47:34 +0200 | [diff] [blame] | 3496 | ret = -ENOMEM; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3497 | goto err_supplies; |
| 3498 | } |
| 3499 | |
| 3500 | hsotg->eps = eps; |
| 3501 | |
| 3502 | /* setup endpoint information */ |
| 3503 | |
| 3504 | INIT_LIST_HEAD(&hsotg->gadget.ep_list); |
| 3505 | hsotg->gadget.ep0 = &hsotg->eps[0].ep; |
| 3506 | |
| 3507 | /* allocate EP0 request */ |
| 3508 | |
| 3509 | hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep, |
| 3510 | GFP_KERNEL); |
| 3511 | if (!hsotg->ctrl_req) { |
| 3512 | dev_err(dev, "failed to allocate ctrl req\n"); |
Julia Lawall | dfdda5a | 2012-08-14 08:47:34 +0200 | [diff] [blame] | 3513 | ret = -ENOMEM; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3514 | goto err_ep_mem; |
| 3515 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3516 | |
| 3517 | /* initialise the endpoints now the core has been initialised */ |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3518 | for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3519 | s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); |
| 3520 | |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 3521 | /* disable power and clock */ |
Marek Szyprowski | 3a8146a | 2014-10-20 12:45:34 +0200 | [diff] [blame] | 3522 | s3c_hsotg_phy_disable(hsotg); |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 3523 | |
| 3524 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
| 3525 | hsotg->supplies); |
| 3526 | if (ret) { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3527 | dev_err(dev, "failed to disable supplies: %d\n", ret); |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 3528 | goto err_ep_mem; |
| 3529 | } |
| 3530 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3531 | ret = usb_add_gadget_udc(dev, &hsotg->gadget); |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3532 | if (ret) |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3533 | goto err_ep_mem; |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3534 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3535 | s3c_hsotg_create_debug(hsotg); |
| 3536 | |
| 3537 | s3c_hsotg_dump(hsotg); |
| 3538 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3539 | return 0; |
| 3540 | |
Lukasz Majewski | 1d144c6 | 2012-05-04 14:17:16 +0200 | [diff] [blame] | 3541 | err_ep_mem: |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3542 | kfree(eps); |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3543 | err_supplies: |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 3544 | s3c_hsotg_phy_disable(hsotg); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3545 | err_clk: |
Lukasz Majewski | 1d144c6 | 2012-05-04 14:17:16 +0200 | [diff] [blame] | 3546 | clk_disable_unprepare(hsotg->clk); |
Sachin Kamat | 338edab | 2012-05-18 14:33:46 +0530 | [diff] [blame] | 3547 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3548 | return ret; |
| 3549 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3550 | EXPORT_SYMBOL_GPL(dwc2_gadget_init); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3551 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3552 | /** |
| 3553 | * s3c_hsotg_remove - remove function for hsotg driver |
| 3554 | * @pdev: The platform information for the driver |
| 3555 | */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3556 | int s3c_hsotg_remove(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3557 | { |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3558 | usb_del_gadget_udc(&hsotg->gadget); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3559 | s3c_hsotg_delete_debug(hsotg); |
Lukasz Majewski | 04b4a0f | 2012-05-04 14:17:15 +0200 | [diff] [blame] | 3560 | clk_disable_unprepare(hsotg->clk); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3561 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3562 | return 0; |
| 3563 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3564 | EXPORT_SYMBOL_GPL(s3c_hsotg_remove); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3565 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3566 | int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3567 | { |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3568 | unsigned long flags; |
| 3569 | int ret = 0; |
| 3570 | |
| 3571 | if (hsotg->driver) |
| 3572 | dev_info(hsotg->dev, "suspending usb gadget %s\n", |
| 3573 | hsotg->driver->driver.name); |
| 3574 | |
| 3575 | spin_lock_irqsave(&hsotg->lock, flags); |
Marek Szyprowski | 7b093f7 | 2014-10-20 12:45:39 +0200 | [diff] [blame] | 3576 | s3c_hsotg_core_disconnect(hsotg); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3577 | s3c_hsotg_disconnect(hsotg); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3578 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
| 3579 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 3580 | |
Marek Szyprowski | 7b093f7 | 2014-10-20 12:45:39 +0200 | [diff] [blame] | 3581 | s3c_hsotg_phy_disable(hsotg); |
| 3582 | |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3583 | if (hsotg->driver) { |
| 3584 | int ep; |
| 3585 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
| 3586 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
| 3587 | |
| 3588 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
| 3589 | hsotg->supplies); |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 3590 | clk_disable(hsotg->clk); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | return ret; |
| 3594 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3595 | EXPORT_SYMBOL_GPL(s3c_hsotg_suspend); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3596 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3597 | int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3598 | { |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3599 | unsigned long flags; |
| 3600 | int ret = 0; |
| 3601 | |
| 3602 | if (hsotg->driver) { |
| 3603 | dev_info(hsotg->dev, "resuming usb gadget %s\n", |
| 3604 | hsotg->driver->driver.name); |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 3605 | |
| 3606 | clk_enable(hsotg->clk); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3607 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
| 3608 | hsotg->supplies); |
| 3609 | } |
| 3610 | |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3611 | s3c_hsotg_phy_enable(hsotg); |
Marek Szyprowski | 7b093f7 | 2014-10-20 12:45:39 +0200 | [diff] [blame] | 3612 | |
| 3613 | spin_lock_irqsave(&hsotg->lock, flags); |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 3614 | s3c_hsotg_core_init_disconnected(hsotg); |
| 3615 | s3c_hsotg_core_connect(hsotg); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3616 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 3617 | |
| 3618 | return ret; |
| 3619 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3620 | EXPORT_SYMBOL_GPL(s3c_hsotg_resume); |