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); |
Robert Baldyga | ab93e01 | 2013-09-19 11:50:17 +0200 | [diff] [blame] | 1033 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1034 | /** |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1035 | * s3c_hsotg_stall_ep0 - stall ep0 |
| 1036 | * @hsotg: The device state |
| 1037 | * |
| 1038 | * Set stall for ep0 as response for setup request. |
| 1039 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1040 | static void s3c_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) |
Jingoo Han | e9ebe7c | 2014-06-03 22:14:56 +0900 | [diff] [blame] | 1041 | { |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1042 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
| 1043 | u32 reg; |
| 1044 | u32 ctrl; |
| 1045 | |
| 1046 | dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); |
| 1047 | reg = (ep0->dir_in) ? DIEPCTL0 : DOEPCTL0; |
| 1048 | |
| 1049 | /* |
| 1050 | * DxEPCTL_Stall will be cleared by EP once it has |
| 1051 | * taken effect, so no need to clear later. |
| 1052 | */ |
| 1053 | |
| 1054 | ctrl = readl(hsotg->regs + reg); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1055 | ctrl |= DXEPCTL_STALL; |
| 1056 | ctrl |= DXEPCTL_CNAK; |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1057 | writel(ctrl, hsotg->regs + reg); |
| 1058 | |
| 1059 | dev_dbg(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1060 | "written DXEPCTL=0x%08x to %08x (DXEPCTL=0x%08x)\n", |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1061 | ctrl, reg, readl(hsotg->regs + reg)); |
| 1062 | |
| 1063 | /* |
| 1064 | * complete won't be called, so we enqueue |
| 1065 | * setup request here |
| 1066 | */ |
| 1067 | s3c_hsotg_enqueue_setup(hsotg); |
| 1068 | } |
| 1069 | |
| 1070 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1071 | * s3c_hsotg_process_control - process a control request |
| 1072 | * @hsotg: The device state |
| 1073 | * @ctrl: The control request received |
| 1074 | * |
| 1075 | * The controller has received the SETUP phase of a control request, and |
| 1076 | * needs to work out what to do next (and whether to pass it on to the |
| 1077 | * gadget driver). |
| 1078 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1079 | static void s3c_hsotg_process_control(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1080 | struct usb_ctrlrequest *ctrl) |
| 1081 | { |
| 1082 | struct s3c_hsotg_ep *ep0 = &hsotg->eps[0]; |
| 1083 | int ret = 0; |
| 1084 | u32 dcfg; |
| 1085 | |
| 1086 | ep0->sent_zlp = 0; |
| 1087 | |
| 1088 | dev_dbg(hsotg->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n", |
| 1089 | ctrl->bRequest, ctrl->bRequestType, |
| 1090 | ctrl->wValue, ctrl->wLength); |
| 1091 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1092 | /* |
| 1093 | * record the direction of the request, for later use when enquing |
| 1094 | * packets onto EP0. |
| 1095 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1096 | |
| 1097 | ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; |
| 1098 | dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in); |
| 1099 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1100 | /* |
| 1101 | * if we've no data with this request, then the last part of the |
| 1102 | * transaction is going to implicitly be IN. |
| 1103 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1104 | if (ctrl->wLength == 0) |
| 1105 | ep0->dir_in = 1; |
| 1106 | |
| 1107 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
| 1108 | switch (ctrl->bRequest) { |
| 1109 | case USB_REQ_SET_ADDRESS: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1110 | dcfg = readl(hsotg->regs + DCFG); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1111 | dcfg &= ~DCFG_DEVADDR_MASK; |
Paul Zimmerman | d5dbd3f | 2014-04-25 14:18:13 -0700 | [diff] [blame] | 1112 | dcfg |= (le16_to_cpu(ctrl->wValue) << |
| 1113 | DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1114 | writel(dcfg, hsotg->regs + DCFG); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1115 | |
| 1116 | dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); |
| 1117 | |
| 1118 | ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); |
| 1119 | return; |
| 1120 | |
| 1121 | case USB_REQ_GET_STATUS: |
| 1122 | ret = s3c_hsotg_process_req_status(hsotg, ctrl); |
| 1123 | break; |
| 1124 | |
| 1125 | case USB_REQ_CLEAR_FEATURE: |
| 1126 | case USB_REQ_SET_FEATURE: |
| 1127 | ret = s3c_hsotg_process_req_feature(hsotg, ctrl); |
| 1128 | break; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | /* as a fallback, try delivering it to the driver to deal with */ |
| 1133 | |
| 1134 | if (ret == 0 && hsotg->driver) { |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1135 | spin_unlock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1136 | ret = hsotg->driver->setup(&hsotg->gadget, ctrl); |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1137 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1138 | if (ret < 0) |
| 1139 | dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); |
| 1140 | } |
| 1141 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1142 | /* |
| 1143 | * the request is either unhandlable, or is not formatted correctly |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1144 | * so respond with a STALL for the status stage to indicate failure. |
| 1145 | */ |
| 1146 | |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 1147 | if (ret < 0) |
| 1148 | s3c_hsotg_stall_ep0(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1151 | /** |
| 1152 | * s3c_hsotg_complete_setup - completion of a setup transfer |
| 1153 | * @ep: The endpoint the request was on. |
| 1154 | * @req: The request completed. |
| 1155 | * |
| 1156 | * Called on completion of any requests the driver itself submitted for |
| 1157 | * EP0 setup packets |
| 1158 | */ |
| 1159 | static void s3c_hsotg_complete_setup(struct usb_ep *ep, |
| 1160 | struct usb_request *req) |
| 1161 | { |
| 1162 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1163 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1164 | |
| 1165 | if (req->status < 0) { |
| 1166 | dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1170 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1171 | if (req->actual == 0) |
| 1172 | s3c_hsotg_enqueue_setup(hsotg); |
| 1173 | else |
| 1174 | s3c_hsotg_process_control(hsotg, req->buf); |
Robert Baldyga | 93f599f | 2013-11-21 13:49:17 +0100 | [diff] [blame] | 1175 | spin_unlock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * s3c_hsotg_enqueue_setup - start a request for EP0 packets |
| 1180 | * @hsotg: The device state. |
| 1181 | * |
| 1182 | * Enqueue a request on EP0 if necessary to received any SETUP packets |
| 1183 | * received from the host. |
| 1184 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1185 | static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1186 | { |
| 1187 | struct usb_request *req = hsotg->ctrl_req; |
| 1188 | struct s3c_hsotg_req *hs_req = our_req(req); |
| 1189 | int ret; |
| 1190 | |
| 1191 | dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); |
| 1192 | |
| 1193 | req->zero = 0; |
| 1194 | req->length = 8; |
| 1195 | req->buf = hsotg->ctrl_buff; |
| 1196 | req->complete = s3c_hsotg_complete_setup; |
| 1197 | |
| 1198 | if (!list_empty(&hs_req->queue)) { |
| 1199 | dev_dbg(hsotg->dev, "%s already queued???\n", __func__); |
| 1200 | return; |
| 1201 | } |
| 1202 | |
| 1203 | hsotg->eps[0].dir_in = 0; |
| 1204 | |
| 1205 | ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC); |
| 1206 | if (ret < 0) { |
| 1207 | dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1208 | /* |
| 1209 | * Don't think there's much we can do other than watch the |
| 1210 | * driver fail. |
| 1211 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1216 | * s3c_hsotg_complete_request - complete a request given to us |
| 1217 | * @hsotg: The device state. |
| 1218 | * @hs_ep: The endpoint the request was on. |
| 1219 | * @hs_req: The request to complete. |
| 1220 | * @result: The result code (0 => Ok, otherwise errno) |
| 1221 | * |
| 1222 | * The given request has finished, so call the necessary completion |
| 1223 | * if it has one and then look to see if we can start a new request |
| 1224 | * on the endpoint. |
| 1225 | * |
| 1226 | * Note, expects the ep to already be locked as appropriate. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1227 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1228 | static void s3c_hsotg_complete_request(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1229 | struct s3c_hsotg_ep *hs_ep, |
| 1230 | struct s3c_hsotg_req *hs_req, |
| 1231 | int result) |
| 1232 | { |
| 1233 | bool restart; |
| 1234 | |
| 1235 | if (!hs_req) { |
| 1236 | dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); |
| 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", |
| 1241 | hs_ep, hs_ep->ep.name, hs_req, result, hs_req->req.complete); |
| 1242 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1243 | /* |
| 1244 | * only replace the status if we've not already set an error |
| 1245 | * from a previous transaction |
| 1246 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1247 | |
| 1248 | if (hs_req->req.status == -EINPROGRESS) |
| 1249 | hs_req->req.status = result; |
| 1250 | |
| 1251 | hs_ep->req = NULL; |
| 1252 | list_del_init(&hs_req->queue); |
| 1253 | |
| 1254 | if (using_dma(hsotg)) |
| 1255 | s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); |
| 1256 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1257 | /* |
| 1258 | * call the complete request with the locks off, just in case the |
| 1259 | * request tries to queue more work for this endpoint. |
| 1260 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1261 | |
| 1262 | if (hs_req->req.complete) { |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 1263 | spin_unlock(&hsotg->lock); |
Michal Sojka | 304f7e5 | 2014-09-24 22:43:19 +0200 | [diff] [blame] | 1264 | usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req); |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 1265 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1268 | /* |
| 1269 | * 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] | 1270 | * 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] | 1271 | * so be careful when doing this. |
| 1272 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1273 | |
| 1274 | if (!hs_ep->req && result >= 0) { |
| 1275 | restart = !list_empty(&hs_ep->queue); |
| 1276 | if (restart) { |
| 1277 | hs_req = get_ep_head(hs_ep); |
| 1278 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, false); |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1284 | * s3c_hsotg_rx_data - receive data from the FIFO for an endpoint |
| 1285 | * @hsotg: The device state. |
| 1286 | * @ep_idx: The endpoint index for the data |
| 1287 | * @size: The size of data in the fifo, in bytes |
| 1288 | * |
| 1289 | * The FIFO status shows there is data to read from the FIFO for a given |
| 1290 | * endpoint, so sort out whether we need to read the data into a request |
| 1291 | * that has been made for that endpoint. |
| 1292 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1293 | 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] | 1294 | { |
| 1295 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; |
| 1296 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1297 | void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1298 | int to_read; |
| 1299 | int max_req; |
| 1300 | int read_ptr; |
| 1301 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 1302 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1303 | if (!hs_req) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1304 | u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1305 | int ptr; |
| 1306 | |
| 1307 | dev_warn(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1308 | "%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] | 1309 | __func__, size, ep_idx, epctl); |
| 1310 | |
| 1311 | /* dump the data from the FIFO, we've nothing we can do */ |
| 1312 | for (ptr = 0; ptr < size; ptr += 4) |
| 1313 | (void)readl(fifo); |
| 1314 | |
| 1315 | return; |
| 1316 | } |
| 1317 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1318 | to_read = size; |
| 1319 | read_ptr = hs_req->req.actual; |
| 1320 | max_req = hs_req->req.length - read_ptr; |
| 1321 | |
Ben Dooks | a33e713 | 2010-07-19 09:40:49 +0100 | [diff] [blame] | 1322 | dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", |
| 1323 | __func__, to_read, max_req, read_ptr, hs_req->req.length); |
| 1324 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1325 | if (to_read > max_req) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1326 | /* |
| 1327 | * more data appeared than we where willing |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1328 | * to deal with in this request. |
| 1329 | */ |
| 1330 | |
| 1331 | /* currently we don't deal this */ |
| 1332 | WARN_ON_ONCE(1); |
| 1333 | } |
| 1334 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1335 | hs_ep->total_data += to_read; |
| 1336 | hs_req->req.actual += to_read; |
| 1337 | to_read = DIV_ROUND_UP(to_read, 4); |
| 1338 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1339 | /* |
| 1340 | * note, we might over-write the buffer end by 3 bytes depending on |
| 1341 | * alignment of the data. |
| 1342 | */ |
Matt Porter | 1a7ed5b | 2014-02-03 10:29:09 -0500 | [diff] [blame] | 1343 | ioread32_rep(fifo, hs_req->req.buf + read_ptr, to_read); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * s3c_hsotg_send_zlp - send zero-length packet on control endpoint |
| 1348 | * @hsotg: The device instance |
| 1349 | * @req: The request currently on this endpoint |
| 1350 | * |
| 1351 | * Generate a zero-length IN packet request for terminating a SETUP |
| 1352 | * transaction. |
| 1353 | * |
| 1354 | * 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] | 1355 | * 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] | 1356 | * the TxFIFO. |
| 1357 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1358 | static void s3c_hsotg_send_zlp(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1359 | struct s3c_hsotg_req *req) |
| 1360 | { |
| 1361 | u32 ctrl; |
| 1362 | |
| 1363 | if (!req) { |
| 1364 | dev_warn(hsotg->dev, "%s: no request?\n", __func__); |
| 1365 | return; |
| 1366 | } |
| 1367 | |
| 1368 | if (req->req.length == 0) { |
| 1369 | hsotg->eps[0].sent_zlp = 1; |
| 1370 | s3c_hsotg_enqueue_setup(hsotg); |
| 1371 | return; |
| 1372 | } |
| 1373 | |
| 1374 | hsotg->eps[0].dir_in = 1; |
| 1375 | hsotg->eps[0].sent_zlp = 1; |
| 1376 | |
| 1377 | dev_dbg(hsotg->dev, "sending zero-length packet\n"); |
| 1378 | |
| 1379 | /* issue a zero-sized packet to terminate this */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1380 | writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | |
| 1381 | DXEPTSIZ_XFERSIZE(0), hsotg->regs + DIEPTSIZ(0)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1382 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1383 | ctrl = readl(hsotg->regs + DIEPCTL0); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1384 | ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ |
| 1385 | ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ |
| 1386 | ctrl |= DXEPCTL_USBACTEP; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1387 | writel(ctrl, hsotg->regs + DIEPCTL0); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * s3c_hsotg_handle_outdone - handle receiving OutDone/SetupDone from RXFIFO |
| 1392 | * @hsotg: The device instance |
| 1393 | * @epnum: The endpoint received from |
| 1394 | * @was_setup: Set if processing a SetupDone event. |
| 1395 | * |
| 1396 | * The RXFIFO has delivered an OutDone event, which means that the data |
| 1397 | * transfer for an OUT endpoint has been completed, either by a short |
| 1398 | * packet or by the finish of a transfer. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1399 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1400 | static void s3c_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1401 | int epnum, bool was_setup) |
| 1402 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1403 | u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1404 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; |
| 1405 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
| 1406 | struct usb_request *req = &hs_req->req; |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1407 | unsigned size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1408 | int result = 0; |
| 1409 | |
| 1410 | if (!hs_req) { |
| 1411 | dev_dbg(hsotg->dev, "%s: no request active\n", __func__); |
| 1412 | return; |
| 1413 | } |
| 1414 | |
| 1415 | if (using_dma(hsotg)) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1416 | unsigned size_done; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1417 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1418 | /* |
| 1419 | * Calculate the size of the transfer by checking how much |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1420 | * is left in the endpoint size register and then working it |
| 1421 | * out from the amount we loaded for the transfer. |
| 1422 | * |
| 1423 | * We need to do this as DMA pointers are always 32bit aligned |
| 1424 | * so may overshoot/undershoot the transfer. |
| 1425 | */ |
| 1426 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1427 | size_done = hs_ep->size_loaded - size_left; |
| 1428 | size_done += hs_ep->last_load; |
| 1429 | |
| 1430 | req->actual = size_done; |
| 1431 | } |
| 1432 | |
Ben Dooks | a33e713 | 2010-07-19 09:40:49 +0100 | [diff] [blame] | 1433 | /* if there is more request to do, schedule new transfer */ |
| 1434 | if (req->actual < req->length && size_left == 0) { |
| 1435 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); |
| 1436 | return; |
Lukasz Majewski | 71225be | 2012-05-04 14:17:03 +0200 | [diff] [blame] | 1437 | } else if (epnum == 0) { |
| 1438 | /* |
| 1439 | * After was_setup = 1 => |
| 1440 | * set CNAK for non Setup requests |
| 1441 | */ |
| 1442 | hsotg->setup = was_setup ? 0 : 1; |
Ben Dooks | a33e713 | 2010-07-19 09:40:49 +0100 | [diff] [blame] | 1443 | } |
| 1444 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1445 | if (req->actual < req->length && req->short_not_ok) { |
| 1446 | dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", |
| 1447 | __func__, req->actual, req->length); |
| 1448 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1449 | /* |
| 1450 | * todo - what should we return here? there's no one else |
| 1451 | * even bothering to check the status. |
| 1452 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | if (epnum == 0) { |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1456 | /* |
| 1457 | * Condition req->complete != s3c_hsotg_complete_setup says: |
| 1458 | * send ZLP when we have an asynchronous request from gadget |
| 1459 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1460 | if (!was_setup && req->complete != s3c_hsotg_complete_setup) |
| 1461 | s3c_hsotg_send_zlp(hsotg, hs_req); |
| 1462 | } |
| 1463 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 1464 | s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | /** |
| 1468 | * s3c_hsotg_read_frameno - read current frame number |
| 1469 | * @hsotg: The device instance |
| 1470 | * |
| 1471 | * Return the current frame number |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1472 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1473 | static u32 s3c_hsotg_read_frameno(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1474 | { |
| 1475 | u32 dsts; |
| 1476 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1477 | dsts = readl(hsotg->regs + DSTS); |
| 1478 | dsts &= DSTS_SOFFN_MASK; |
| 1479 | dsts >>= DSTS_SOFFN_SHIFT; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1480 | |
| 1481 | return dsts; |
| 1482 | } |
| 1483 | |
| 1484 | /** |
| 1485 | * s3c_hsotg_handle_rx - RX FIFO has data |
| 1486 | * @hsotg: The device instance |
| 1487 | * |
| 1488 | * The IRQ handler has detected that the RX FIFO has some data in it |
| 1489 | * that requires processing, so find out what is in there and do the |
| 1490 | * appropriate read. |
| 1491 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1492 | * 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] | 1493 | * chunks, so if you have x packets received on an endpoint you'll get x |
| 1494 | * FIFO events delivered, each with a packet's worth of data in it. |
| 1495 | * |
| 1496 | * When using DMA, we should not be processing events from the RXFIFO |
| 1497 | * as the actual data should be sent to the memory directly and we turn |
| 1498 | * on the completion interrupts to get notifications of transfer completion. |
| 1499 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1500 | static void s3c_hsotg_handle_rx(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1501 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1502 | u32 grxstsr = readl(hsotg->regs + GRXSTSP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1503 | u32 epnum, status, size; |
| 1504 | |
| 1505 | WARN_ON(using_dma(hsotg)); |
| 1506 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1507 | epnum = grxstsr & GRXSTS_EPNUM_MASK; |
| 1508 | status = grxstsr & GRXSTS_PKTSTS_MASK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1509 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1510 | size = grxstsr & GRXSTS_BYTECNT_MASK; |
| 1511 | size >>= GRXSTS_BYTECNT_SHIFT; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1512 | |
| 1513 | if (1) |
| 1514 | dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", |
| 1515 | __func__, grxstsr, size, epnum); |
| 1516 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1517 | switch ((status & GRXSTS_PKTSTS_MASK) >> GRXSTS_PKTSTS_SHIFT) { |
| 1518 | case GRXSTS_PKTSTS_GLOBALOUTNAK: |
| 1519 | dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1520 | break; |
| 1521 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1522 | case GRXSTS_PKTSTS_OUTDONE: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1523 | dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", |
| 1524 | s3c_hsotg_read_frameno(hsotg)); |
| 1525 | |
| 1526 | if (!using_dma(hsotg)) |
| 1527 | s3c_hsotg_handle_outdone(hsotg, epnum, false); |
| 1528 | break; |
| 1529 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1530 | case GRXSTS_PKTSTS_SETUPDONE: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1531 | dev_dbg(hsotg->dev, |
| 1532 | "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
| 1533 | s3c_hsotg_read_frameno(hsotg), |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1534 | readl(hsotg->regs + DOEPCTL(0))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1535 | |
| 1536 | s3c_hsotg_handle_outdone(hsotg, epnum, true); |
| 1537 | break; |
| 1538 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1539 | case GRXSTS_PKTSTS_OUTRX: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1540 | s3c_hsotg_rx_data(hsotg, epnum, size); |
| 1541 | break; |
| 1542 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1543 | case GRXSTS_PKTSTS_SETUPRX: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1544 | dev_dbg(hsotg->dev, |
| 1545 | "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
| 1546 | s3c_hsotg_read_frameno(hsotg), |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1547 | readl(hsotg->regs + DOEPCTL(0))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1548 | |
| 1549 | s3c_hsotg_rx_data(hsotg, epnum, size); |
| 1550 | break; |
| 1551 | |
| 1552 | default: |
| 1553 | dev_warn(hsotg->dev, "%s: unknown status %08x\n", |
| 1554 | __func__, grxstsr); |
| 1555 | |
| 1556 | s3c_hsotg_dump(hsotg); |
| 1557 | break; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | /** |
| 1562 | * s3c_hsotg_ep0_mps - turn max packet size into register setting |
| 1563 | * @mps: The maximum packet size in bytes. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1564 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1565 | static u32 s3c_hsotg_ep0_mps(unsigned int mps) |
| 1566 | { |
| 1567 | switch (mps) { |
| 1568 | case 64: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1569 | return D0EPCTL_MPS_64; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1570 | case 32: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1571 | return D0EPCTL_MPS_32; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1572 | case 16: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1573 | return D0EPCTL_MPS_16; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1574 | case 8: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1575 | return D0EPCTL_MPS_8; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | /* bad max packet size, warn and return invalid result */ |
| 1579 | WARN_ON(1); |
| 1580 | return (u32)-1; |
| 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * s3c_hsotg_set_ep_maxpacket - set endpoint's max-packet field |
| 1585 | * @hsotg: The driver state. |
| 1586 | * @ep: The index number of the endpoint |
| 1587 | * @mps: The maximum packet size in bytes |
| 1588 | * |
| 1589 | * Configure the maximum packet size for the given endpoint, updating |
| 1590 | * the hardware control registers to reflect this. |
| 1591 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1592 | static void s3c_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1593 | unsigned int ep, unsigned int mps) |
| 1594 | { |
| 1595 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; |
| 1596 | void __iomem *regs = hsotg->regs; |
| 1597 | u32 mpsval; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 1598 | u32 mcval; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1599 | u32 reg; |
| 1600 | |
| 1601 | if (ep == 0) { |
| 1602 | /* EP0 is a special case */ |
| 1603 | mpsval = s3c_hsotg_ep0_mps(mps); |
| 1604 | if (mpsval > 3) |
| 1605 | goto bad_mps; |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 1606 | hs_ep->ep.maxpacket = mps; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 1607 | hs_ep->mc = 1; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1608 | } else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1609 | mpsval = mps & DXEPCTL_MPS_MASK; |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 1610 | if (mpsval > 1024) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1611 | goto bad_mps; |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 1612 | mcval = ((mps >> 11) & 0x3) + 1; |
| 1613 | hs_ep->mc = mcval; |
| 1614 | if (mcval > 3) |
| 1615 | goto bad_mps; |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 1616 | hs_ep->ep.maxpacket = mpsval; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1619 | /* |
| 1620 | * update both the in and out endpoint controldir_ registers, even |
| 1621 | * if one of the directions may not be in use. |
| 1622 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1623 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1624 | reg = readl(regs + DIEPCTL(ep)); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1625 | reg &= ~DXEPCTL_MPS_MASK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1626 | reg |= mpsval; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1627 | writel(reg, regs + DIEPCTL(ep)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1628 | |
Anton Tikhomirov | 659ad60 | 2012-03-06 14:07:29 +0900 | [diff] [blame] | 1629 | if (ep) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1630 | reg = readl(regs + DOEPCTL(ep)); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1631 | reg &= ~DXEPCTL_MPS_MASK; |
Anton Tikhomirov | 659ad60 | 2012-03-06 14:07:29 +0900 | [diff] [blame] | 1632 | reg |= mpsval; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1633 | writel(reg, regs + DOEPCTL(ep)); |
Anton Tikhomirov | 659ad60 | 2012-03-06 14:07:29 +0900 | [diff] [blame] | 1634 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1635 | |
| 1636 | return; |
| 1637 | |
| 1638 | bad_mps: |
| 1639 | dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); |
| 1640 | } |
| 1641 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1642 | /** |
| 1643 | * s3c_hsotg_txfifo_flush - flush Tx FIFO |
| 1644 | * @hsotg: The driver state |
| 1645 | * @idx: The index for the endpoint (0..15) |
| 1646 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1647 | 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] | 1648 | { |
| 1649 | int timeout; |
| 1650 | int val; |
| 1651 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1652 | writel(GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1653 | hsotg->regs + GRSTCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1654 | |
| 1655 | /* wait until the fifo is flushed */ |
| 1656 | timeout = 100; |
| 1657 | |
| 1658 | while (1) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1659 | val = readl(hsotg->regs + GRSTCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1660 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1661 | if ((val & (GRSTCTL_TXFFLSH)) == 0) |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1662 | break; |
| 1663 | |
| 1664 | if (--timeout == 0) { |
| 1665 | dev_err(hsotg->dev, |
| 1666 | "%s: timeout flushing fifo (GRSTCTL=%08x)\n", |
| 1667 | __func__, val); |
Marek Szyprowski | e0cbe59 | 2014-09-09 10:44:10 +0200 | [diff] [blame] | 1668 | break; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | udelay(1); |
| 1672 | } |
| 1673 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1674 | |
| 1675 | /** |
| 1676 | * s3c_hsotg_trytx - check to see if anything needs transmitting |
| 1677 | * @hsotg: The driver state |
| 1678 | * @hs_ep: The driver endpoint to check. |
| 1679 | * |
| 1680 | * Check to see if there is a request that has data to send, and if so |
| 1681 | * make an attempt to write data into the FIFO. |
| 1682 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1683 | static int s3c_hsotg_trytx(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1684 | struct s3c_hsotg_ep *hs_ep) |
| 1685 | { |
| 1686 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
| 1687 | |
Robert Baldyga | afcf416 | 2013-09-19 11:50:19 +0200 | [diff] [blame] | 1688 | if (!hs_ep->dir_in || !hs_req) { |
| 1689 | /** |
| 1690 | * if request is not enqueued, we disable interrupts |
| 1691 | * for endpoints, excepting ep0 |
| 1692 | */ |
| 1693 | if (hs_ep->index != 0) |
| 1694 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, |
| 1695 | hs_ep->dir_in, 0); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1696 | return 0; |
Robert Baldyga | afcf416 | 2013-09-19 11:50:19 +0200 | [diff] [blame] | 1697 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1698 | |
| 1699 | if (hs_req->req.actual < hs_req->req.length) { |
| 1700 | dev_dbg(hsotg->dev, "trying to write more for ep%d\n", |
| 1701 | hs_ep->index); |
| 1702 | return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); |
| 1703 | } |
| 1704 | |
| 1705 | return 0; |
| 1706 | } |
| 1707 | |
| 1708 | /** |
| 1709 | * s3c_hsotg_complete_in - complete IN transfer |
| 1710 | * @hsotg: The device state. |
| 1711 | * @hs_ep: The endpoint that has just completed. |
| 1712 | * |
| 1713 | * An IN transfer has been completed, update the transfer's state and then |
| 1714 | * call the relevant completion routines. |
| 1715 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1716 | static void s3c_hsotg_complete_in(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1717 | struct s3c_hsotg_ep *hs_ep) |
| 1718 | { |
| 1719 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1720 | u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1721 | int size_left, size_done; |
| 1722 | |
| 1723 | if (!hs_req) { |
| 1724 | dev_dbg(hsotg->dev, "XferCompl but no req\n"); |
| 1725 | return; |
| 1726 | } |
| 1727 | |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1728 | /* Finish ZLP handling for IN EP0 transactions */ |
| 1729 | if (hsotg->eps[0].sent_zlp) { |
| 1730 | dev_dbg(hsotg->dev, "zlp packet received\n"); |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 1731 | s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1732 | return; |
| 1733 | } |
| 1734 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1735 | /* |
| 1736 | * Calculate the size of the transfer by checking how much is left |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1737 | * in the endpoint size register and then working it out from |
| 1738 | * the amount we loaded for the transfer. |
| 1739 | * |
| 1740 | * We do this even for DMA, as the transfer may have incremented |
| 1741 | * past the end of the buffer (DMA transfers are always 32bit |
| 1742 | * aligned). |
| 1743 | */ |
| 1744 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1745 | size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1746 | |
| 1747 | size_done = hs_ep->size_loaded - size_left; |
| 1748 | size_done += hs_ep->last_load; |
| 1749 | |
| 1750 | if (hs_req->req.actual != size_done) |
| 1751 | dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", |
| 1752 | __func__, hs_req->req.actual, size_done); |
| 1753 | |
| 1754 | hs_req->req.actual = size_done; |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1755 | dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", |
| 1756 | hs_req->req.length, hs_req->req.actual, hs_req->req.zero); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1757 | |
Lukasz Majewski | d3ca025 | 2012-05-04 14:17:04 +0200 | [diff] [blame] | 1758 | /* |
| 1759 | * Check if dealing with Maximum Packet Size(MPS) IN transfer at EP0 |
| 1760 | * When sent data is a multiple MPS size (e.g. 64B ,128B ,192B |
| 1761 | * ,256B ... ), after last MPS sized packet send IN ZLP packet to |
| 1762 | * inform the host that no more data is available. |
| 1763 | * The state of req.zero member is checked to be sure that the value to |
| 1764 | * send is smaller than wValue expected from host. |
| 1765 | * Check req.length to NOT send another ZLP when the current one is |
| 1766 | * under completion (the one for which this completion has been called). |
| 1767 | */ |
| 1768 | if (hs_req->req.length && hs_ep->index == 0 && hs_req->req.zero && |
| 1769 | hs_req->req.length == hs_req->req.actual && |
| 1770 | !(hs_req->req.length % hs_ep->ep.maxpacket)) { |
| 1771 | |
| 1772 | dev_dbg(hsotg->dev, "ep0 zlp IN packet sent\n"); |
| 1773 | s3c_hsotg_send_zlp(hsotg, hs_req); |
| 1774 | |
| 1775 | return; |
| 1776 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1777 | |
| 1778 | if (!size_left && hs_req->req.actual < hs_req->req.length) { |
| 1779 | dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); |
| 1780 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); |
| 1781 | } else |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 1782 | s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | /** |
| 1786 | * s3c_hsotg_epint - handle an in/out endpoint interrupt |
| 1787 | * @hsotg: The driver state |
| 1788 | * @idx: The index for the endpoint (0..15) |
| 1789 | * @dir_in: Set if this is an IN endpoint |
| 1790 | * |
| 1791 | * Process and clear any interrupt pending for an individual endpoint |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1792 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1793 | static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1794 | int dir_in) |
| 1795 | { |
| 1796 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1797 | u32 epint_reg = dir_in ? DIEPINT(idx) : DOEPINT(idx); |
| 1798 | u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); |
| 1799 | u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1800 | u32 ints; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1801 | u32 ctrl; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1802 | |
| 1803 | ints = readl(hsotg->regs + epint_reg); |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1804 | ctrl = readl(hsotg->regs + epctl_reg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1805 | |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 1806 | /* Clear endpoint interrupts */ |
| 1807 | writel(ints, hsotg->regs + epint_reg); |
| 1808 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1809 | dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", |
| 1810 | __func__, idx, dir_in ? "in" : "out", ints); |
| 1811 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1812 | if (ints & DXEPINT_XFERCOMPL) { |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1813 | if (hs_ep->isochronous && hs_ep->interval == 1) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1814 | if (ctrl & DXEPCTL_EOFRNUM) |
| 1815 | ctrl |= DXEPCTL_SETEVENFR; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1816 | else |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1817 | ctrl |= DXEPCTL_SETODDFR; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1818 | writel(ctrl, hsotg->regs + epctl_reg); |
| 1819 | } |
| 1820 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1821 | dev_dbg(hsotg->dev, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1822 | "%s: XferCompl: DxEPCTL=0x%08x, DXEPTSIZ=%08x\n", |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1823 | __func__, readl(hsotg->regs + epctl_reg), |
| 1824 | readl(hsotg->regs + epsiz_reg)); |
| 1825 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1826 | /* |
| 1827 | * we get OutDone from the FIFO, so we only need to look |
| 1828 | * at completing IN requests here |
| 1829 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1830 | if (dir_in) { |
| 1831 | s3c_hsotg_complete_in(hsotg, hs_ep); |
| 1832 | |
Ben Dooks | c9a64ea | 2010-07-19 09:40:46 +0100 | [diff] [blame] | 1833 | if (idx == 0 && !hs_ep->req) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1834 | s3c_hsotg_enqueue_setup(hsotg); |
| 1835 | } else if (using_dma(hsotg)) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1836 | /* |
| 1837 | * We're using DMA, we need to fire an OutDone here |
| 1838 | * as we ignore the RXFIFO. |
| 1839 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1840 | |
| 1841 | s3c_hsotg_handle_outdone(hsotg, idx, false); |
| 1842 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1843 | } |
| 1844 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1845 | if (ints & DXEPINT_EPDISBLD) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1846 | dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1847 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1848 | if (dir_in) { |
| 1849 | int epctl = readl(hsotg->regs + epctl_reg); |
| 1850 | |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 1851 | s3c_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1852 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1853 | if ((epctl & DXEPCTL_STALL) && |
| 1854 | (epctl & DXEPCTL_EPTYPE_BULK)) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1855 | int dctl = readl(hsotg->regs + DCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1856 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1857 | dctl |= DCTL_CGNPINNAK; |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1858 | writel(dctl, hsotg->regs + DCTL); |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1863 | if (ints & DXEPINT_AHBERR) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1864 | dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1865 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1866 | if (ints & DXEPINT_SETUP) { /* Setup or Timeout */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1867 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); |
| 1868 | |
| 1869 | if (using_dma(hsotg) && idx == 0) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1870 | /* |
| 1871 | * this is the notification we've received a |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1872 | * setup packet. In non-DMA mode we'd get this |
| 1873 | * from the RXFIFO, instead we need to process |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1874 | * the setup here. |
| 1875 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1876 | |
| 1877 | if (dir_in) |
| 1878 | WARN_ON_ONCE(1); |
| 1879 | else |
| 1880 | s3c_hsotg_handle_outdone(hsotg, 0, true); |
| 1881 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1884 | if (ints & DXEPINT_BACK2BACKSETUP) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1885 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1886 | |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 1887 | if (dir_in && !hs_ep->isochronous) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1888 | /* not sure if this is important, but we'll clear it anyway */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1889 | if (ints & DIEPMSK_INTKNTXFEMPMSK) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1890 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", |
| 1891 | __func__, idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | /* this probably means something bad is happening */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1895 | if (ints & DIEPMSK_INTKNEPMISMSK) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1896 | dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", |
| 1897 | __func__, idx); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1898 | } |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 1899 | |
| 1900 | /* FIFO has space or is empty (see GAHBCFG) */ |
| 1901 | if (hsotg->dedicated_fifos && |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1902 | ints & DIEPMSK_TXFIFOEMPTY) { |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 1903 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", |
| 1904 | __func__, idx); |
Anton Tikhomirov | 70fa030 | 2012-03-06 14:08:29 +0900 | [diff] [blame] | 1905 | if (!using_dma(hsotg)) |
| 1906 | s3c_hsotg_trytx(hsotg, hs_ep); |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 1907 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1908 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | /** |
| 1912 | * s3c_hsotg_irq_enumdone - Handle EnumDone interrupt (enumeration done) |
| 1913 | * @hsotg: The device state. |
| 1914 | * |
| 1915 | * Handle updating the device settings after the enumeration phase has |
| 1916 | * been completed. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1917 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1918 | static void s3c_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1919 | { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1920 | u32 dsts = readl(hsotg->regs + DSTS); |
Jingoo Han | 9b2667f | 2014-08-20 12:04:09 +0900 | [diff] [blame] | 1921 | int ep0_mps = 0, ep_mps = 8; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1922 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1923 | /* |
| 1924 | * This should signal the finish of the enumeration phase |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1925 | * of the USB handshaking, so we should now know what rate |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1926 | * we connected at. |
| 1927 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1928 | |
| 1929 | dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); |
| 1930 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1931 | /* |
| 1932 | * 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] | 1933 | * 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] | 1934 | * not advertise a 64byte MPS on EP0. |
| 1935 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1936 | |
| 1937 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1938 | switch (dsts & DSTS_ENUMSPD_MASK) { |
| 1939 | case DSTS_ENUMSPD_FS: |
| 1940 | case DSTS_ENUMSPD_FS48: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1941 | hsotg->gadget.speed = USB_SPEED_FULL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1942 | ep0_mps = EP0_MPS_LIMIT; |
Robert Baldyga | 295538f | 2013-12-06 13:03:44 +0100 | [diff] [blame] | 1943 | ep_mps = 1023; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1944 | break; |
| 1945 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1946 | case DSTS_ENUMSPD_HS: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1947 | hsotg->gadget.speed = USB_SPEED_HIGH; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1948 | ep0_mps = EP0_MPS_LIMIT; |
Robert Baldyga | 295538f | 2013-12-06 13:03:44 +0100 | [diff] [blame] | 1949 | ep_mps = 1024; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1950 | break; |
| 1951 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 1952 | case DSTS_ENUMSPD_LS: |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1953 | hsotg->gadget.speed = USB_SPEED_LOW; |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1954 | /* |
| 1955 | * note, we don't actually support LS in this driver at the |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1956 | * moment, and the documentation seems to imply that it isn't |
| 1957 | * supported by the PHYs on some of the devices. |
| 1958 | */ |
| 1959 | break; |
| 1960 | } |
Michal Nazarewicz | e538dfd | 2011-08-30 17:11:19 +0200 | [diff] [blame] | 1961 | dev_info(hsotg->dev, "new device is %s\n", |
| 1962 | usb_speed_string(hsotg->gadget.speed)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1963 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 1964 | /* |
| 1965 | * we should now know the maximum packet size for an |
| 1966 | * endpoint, so set the endpoints to a default value. |
| 1967 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1968 | |
| 1969 | if (ep0_mps) { |
| 1970 | int i; |
| 1971 | s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 1972 | for (i = 1; i < hsotg->num_of_eps; i++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1973 | s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps); |
| 1974 | } |
| 1975 | |
| 1976 | /* ensure after enumeration our EP0 is active */ |
| 1977 | |
| 1978 | s3c_hsotg_enqueue_setup(hsotg); |
| 1979 | |
| 1980 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 1981 | readl(hsotg->regs + DIEPCTL0), |
| 1982 | readl(hsotg->regs + DOEPCTL0)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /** |
| 1986 | * kill_all_requests - remove all requests from the endpoint's queue |
| 1987 | * @hsotg: The device state. |
| 1988 | * @ep: The endpoint the requests may be on. |
| 1989 | * @result: The result code to use. |
| 1990 | * @force: Force removal of any current requests |
| 1991 | * |
| 1992 | * Go through the requests on the given endpoint and mark them |
| 1993 | * completed with the given result code. |
| 1994 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 1995 | static void kill_all_requests(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 1996 | struct s3c_hsotg_ep *ep, |
| 1997 | int result, bool force) |
| 1998 | { |
| 1999 | struct s3c_hsotg_req *req, *treq; |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2000 | unsigned size; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2001 | |
| 2002 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2003 | /* |
| 2004 | * currently, we can't do much about an already |
| 2005 | * running request on an in endpoint |
| 2006 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2007 | |
| 2008 | if (ep->req == req && ep->dir_in && !force) |
| 2009 | continue; |
| 2010 | |
| 2011 | s3c_hsotg_complete_request(hsotg, ep, req, |
| 2012 | result); |
| 2013 | } |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2014 | if (!hsotg->dedicated_fifos) |
| 2015 | return; |
| 2016 | size = (readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4; |
| 2017 | if (size < ep->fifo_size) |
| 2018 | s3c_hsotg_txfifo_flush(hsotg, ep->fifo_index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2019 | } |
| 2020 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2021 | /** |
Lukasz Majewski | 5e89134 | 2012-05-04 14:17:07 +0200 | [diff] [blame] | 2022 | * s3c_hsotg_disconnect - disconnect service |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2023 | * @hsotg: The device state. |
| 2024 | * |
Lukasz Majewski | 5e89134 | 2012-05-04 14:17:07 +0200 | [diff] [blame] | 2025 | * The device has been disconnected. Remove all current |
| 2026 | * transactions and signal the gadget driver that this |
| 2027 | * has happened. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2028 | */ |
Marek Szyprowski | 4ace06e | 2014-11-21 15:14:47 +0100 | [diff] [blame^] | 2029 | void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2030 | { |
| 2031 | unsigned ep; |
| 2032 | |
Marek Szyprowski | 4ace06e | 2014-11-21 15:14:47 +0100 | [diff] [blame^] | 2033 | if (!hsotg->connected) |
| 2034 | return; |
| 2035 | |
| 2036 | hsotg->connected = 0; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2037 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2038 | kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); |
| 2039 | |
| 2040 | call_gadget(hsotg, disconnect); |
| 2041 | } |
Marek Szyprowski | 4ace06e | 2014-11-21 15:14:47 +0100 | [diff] [blame^] | 2042 | EXPORT_SYMBOL_GPL(s3c_hsotg_disconnect); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2043 | |
| 2044 | /** |
| 2045 | * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler |
| 2046 | * @hsotg: The device state: |
| 2047 | * @periodic: True if this is a periodic FIFO interrupt |
| 2048 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2049 | static void s3c_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2050 | { |
| 2051 | struct s3c_hsotg_ep *ep; |
| 2052 | int epno, ret; |
| 2053 | |
| 2054 | /* look through for any more data to transmit */ |
| 2055 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2056 | for (epno = 0; epno < hsotg->num_of_eps; epno++) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2057 | ep = &hsotg->eps[epno]; |
| 2058 | |
| 2059 | if (!ep->dir_in) |
| 2060 | continue; |
| 2061 | |
| 2062 | if ((periodic && !ep->periodic) || |
| 2063 | (!periodic && ep->periodic)) |
| 2064 | continue; |
| 2065 | |
| 2066 | ret = s3c_hsotg_trytx(hsotg, ep); |
| 2067 | if (ret < 0) |
| 2068 | break; |
| 2069 | } |
| 2070 | } |
| 2071 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2072 | /* IRQ flags which will trigger a retry around the IRQ loop */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2073 | #define IRQ_RETRY_MASK (GINTSTS_NPTXFEMP | \ |
| 2074 | GINTSTS_PTXFEMP | \ |
| 2075 | GINTSTS_RXFLVL) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2076 | |
| 2077 | /** |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2078 | * s3c_hsotg_corereset - issue softreset to the core |
| 2079 | * @hsotg: The device state |
| 2080 | * |
| 2081 | * 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] | 2082 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2083 | static int s3c_hsotg_corereset(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2084 | { |
| 2085 | int timeout; |
| 2086 | u32 grstctl; |
| 2087 | |
| 2088 | dev_dbg(hsotg->dev, "resetting core\n"); |
| 2089 | |
| 2090 | /* issue soft reset */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2091 | writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2092 | |
Du, Changbin | 2868fea | 2012-07-24 08:19:25 +0800 | [diff] [blame] | 2093 | timeout = 10000; |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2094 | do { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2095 | grstctl = readl(hsotg->regs + GRSTCTL); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2096 | } while ((grstctl & GRSTCTL_CSFTRST) && timeout-- > 0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2097 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2098 | if (grstctl & GRSTCTL_CSFTRST) { |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2099 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); |
| 2100 | return -EINVAL; |
| 2101 | } |
| 2102 | |
Du, Changbin | 2868fea | 2012-07-24 08:19:25 +0800 | [diff] [blame] | 2103 | timeout = 10000; |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2104 | |
| 2105 | while (1) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2106 | u32 grstctl = readl(hsotg->regs + GRSTCTL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2107 | |
| 2108 | if (timeout-- < 0) { |
| 2109 | dev_info(hsotg->dev, |
| 2110 | "%s: reset failed, GRSTCTL=%08x\n", |
| 2111 | __func__, grstctl); |
| 2112 | return -ETIMEDOUT; |
| 2113 | } |
| 2114 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2115 | if (!(grstctl & GRSTCTL_AHBIDLE)) |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2116 | continue; |
| 2117 | |
| 2118 | break; /* reset done */ |
| 2119 | } |
| 2120 | |
| 2121 | dev_dbg(hsotg->dev, "reset successful\n"); |
| 2122 | return 0; |
| 2123 | } |
| 2124 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2125 | /** |
| 2126 | * s3c_hsotg_core_init - issue softreset to the core |
| 2127 | * @hsotg: The device state |
| 2128 | * |
| 2129 | * Issue a soft reset to the core, and await the core finishing it. |
| 2130 | */ |
Dinh Nguyen | 510ffaa | 2014-11-11 11:13:36 -0600 | [diff] [blame] | 2131 | void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2132 | { |
| 2133 | s3c_hsotg_corereset(hsotg); |
| 2134 | |
| 2135 | /* |
| 2136 | * we must now enable ep0 ready for host detection and then |
| 2137 | * set configuration. |
| 2138 | */ |
| 2139 | |
| 2140 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2141 | writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2142 | (0x5 << 10), hsotg->regs + GUSBCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2143 | |
| 2144 | s3c_hsotg_init_fifo(hsotg); |
| 2145 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2146 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2147 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2148 | writel(1 << 18 | DCFG_DEVSPD_HS, hsotg->regs + DCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2149 | |
| 2150 | /* Clear any pending OTG interrupts */ |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2151 | writel(0xffffffff, hsotg->regs + GOTGINT); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2152 | |
| 2153 | /* Clear any pending interrupts */ |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2154 | writel(0xffffffff, hsotg->regs + GINTSTS); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2155 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2156 | writel(GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT | |
| 2157 | GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF | |
| 2158 | GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST | |
| 2159 | GINTSTS_ENUMDONE | GINTSTS_OTGINT | |
| 2160 | GINTSTS_USBSUSP | GINTSTS_WKUPINT, |
| 2161 | hsotg->regs + GINTMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2162 | |
| 2163 | if (using_dma(hsotg)) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2164 | writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | |
| 2165 | GAHBCFG_HBSTLEN_INCR4, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2166 | hsotg->regs + GAHBCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2167 | else |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2168 | writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL | |
| 2169 | GAHBCFG_P_TXF_EMP_LVL) : 0) | |
| 2170 | GAHBCFG_GLBL_INTR_EN, |
Robert Baldyga | 8acc829 | 2013-09-19 11:50:23 +0200 | [diff] [blame] | 2171 | hsotg->regs + GAHBCFG); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2172 | |
| 2173 | /* |
Robert Baldyga | 8acc829 | 2013-09-19 11:50:23 +0200 | [diff] [blame] | 2174 | * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts |
| 2175 | * when we have no data to transfer. Otherwise we get being flooded by |
| 2176 | * interrupts. |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2177 | */ |
| 2178 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2179 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY | |
| 2180 | DIEPMSK_INTKNTXFEMPMSK : 0) | |
| 2181 | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK | |
| 2182 | DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | |
| 2183 | DIEPMSK_INTKNEPMISMSK, |
| 2184 | hsotg->regs + DIEPMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2185 | |
| 2186 | /* |
| 2187 | * don't need XferCompl, we get that from RXFIFO in slave mode. In |
| 2188 | * DMA mode we may need this. |
| 2189 | */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2190 | writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | |
| 2191 | DIEPMSK_TIMEOUTMSK) : 0) | |
| 2192 | DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK | |
| 2193 | DOEPMSK_SETUPMSK, |
| 2194 | hsotg->regs + DOEPMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2195 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2196 | writel(0, hsotg->regs + DAINTMSK); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2197 | |
| 2198 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2199 | readl(hsotg->regs + DIEPCTL0), |
| 2200 | readl(hsotg->regs + DOEPCTL0)); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2201 | |
| 2202 | /* enable in and out endpoint interrupts */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2203 | s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2204 | |
| 2205 | /* |
| 2206 | * Enable the RXFIFO when in slave mode, as this is how we collect |
| 2207 | * the data. In DMA mode, we get events from the FIFO but also |
| 2208 | * things we cannot process, so do not use it. |
| 2209 | */ |
| 2210 | if (!using_dma(hsotg)) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2211 | s3c_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2212 | |
| 2213 | /* Enable interrupts for EP0 in and out */ |
| 2214 | s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); |
| 2215 | s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); |
| 2216 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2217 | __orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2218 | udelay(10); /* see openiboot */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2219 | __bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2220 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2221 | dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2222 | |
| 2223 | /* |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2224 | * DxEPCTL_USBActEp says RO in manual, but seems to be set by |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2225 | * writing to the EPCTL register.. |
| 2226 | */ |
| 2227 | |
| 2228 | /* set to read 1 8byte packet */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2229 | writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | |
| 2230 | DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2231 | |
| 2232 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2233 | DXEPCTL_CNAK | DXEPCTL_EPENA | |
| 2234 | DXEPCTL_USBACTEP, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2235 | hsotg->regs + DOEPCTL0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2236 | |
| 2237 | /* enable, but don't activate EP0in */ |
| 2238 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2239 | DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2240 | |
| 2241 | s3c_hsotg_enqueue_setup(hsotg); |
| 2242 | |
| 2243 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2244 | readl(hsotg->regs + DIEPCTL0), |
| 2245 | readl(hsotg->regs + DOEPCTL0)); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2246 | |
| 2247 | /* clear global NAKs */ |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2248 | writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK | DCTL_SFTDISCON, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2249 | hsotg->regs + DCTL); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2250 | |
| 2251 | /* must be at-least 3ms to allow bus to see disconnect */ |
| 2252 | mdelay(3); |
| 2253 | |
Marek Szyprowski | ac3c81f | 2014-10-20 12:45:35 +0200 | [diff] [blame] | 2254 | hsotg->last_rst = jiffies; |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2255 | } |
Marek Szyprowski | ac3c81f | 2014-10-20 12:45:35 +0200 | [diff] [blame] | 2256 | |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2257 | static void s3c_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2258 | { |
| 2259 | /* set the soft-disconnect bit */ |
| 2260 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
| 2261 | } |
| 2262 | |
Dinh Nguyen | 510ffaa | 2014-11-11 11:13:36 -0600 | [diff] [blame] | 2263 | void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2264 | { |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2265 | /* remove the soft-disconnect and let's go */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2266 | __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
Lukasz Majewski | 308d734 | 2012-05-04 14:17:05 +0200 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | /** |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2270 | * s3c_hsotg_irq - handle device interrupt |
| 2271 | * @irq: The IRQ number triggered |
| 2272 | * @pw: The pw value when registered the handler. |
| 2273 | */ |
| 2274 | static irqreturn_t s3c_hsotg_irq(int irq, void *pw) |
| 2275 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2276 | struct dwc2_hsotg *hsotg = pw; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2277 | int retry_count = 8; |
| 2278 | u32 gintsts; |
| 2279 | u32 gintmsk; |
| 2280 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2281 | spin_lock(&hsotg->lock); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2282 | irq_retry: |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2283 | gintsts = readl(hsotg->regs + GINTSTS); |
| 2284 | gintmsk = readl(hsotg->regs + GINTMSK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2285 | |
| 2286 | dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", |
| 2287 | __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count); |
| 2288 | |
| 2289 | gintsts &= gintmsk; |
| 2290 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2291 | if (gintsts & GINTSTS_ENUMDONE) { |
| 2292 | writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2293 | |
| 2294 | s3c_hsotg_irq_enumdone(hsotg); |
Marek Szyprowski | 4ace06e | 2014-11-21 15:14:47 +0100 | [diff] [blame^] | 2295 | hsotg->connected = 1; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2296 | } |
| 2297 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2298 | if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2299 | u32 daint = readl(hsotg->regs + DAINT); |
Robert Baldyga | 7e80465 | 2013-09-19 11:50:20 +0200 | [diff] [blame] | 2300 | u32 daintmsk = readl(hsotg->regs + DAINTMSK); |
| 2301 | u32 daint_out, daint_in; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2302 | int ep; |
| 2303 | |
Robert Baldyga | 7e80465 | 2013-09-19 11:50:20 +0200 | [diff] [blame] | 2304 | daint &= daintmsk; |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2305 | daint_out = daint >> DAINT_OUTEP_SHIFT; |
| 2306 | daint_in = daint & ~(daint_out << DAINT_OUTEP_SHIFT); |
Robert Baldyga | 7e80465 | 2013-09-19 11:50:20 +0200 | [diff] [blame] | 2307 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2308 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); |
| 2309 | |
| 2310 | for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { |
| 2311 | if (daint_out & 1) |
| 2312 | s3c_hsotg_epint(hsotg, ep, 0); |
| 2313 | } |
| 2314 | |
| 2315 | for (ep = 0; ep < 15 && daint_in; ep++, daint_in >>= 1) { |
| 2316 | if (daint_in & 1) |
| 2317 | s3c_hsotg_epint(hsotg, ep, 1); |
| 2318 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2319 | } |
| 2320 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2321 | if (gintsts & GINTSTS_USBRST) { |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2322 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2323 | u32 usb_status = readl(hsotg->regs + GOTGCTL); |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2324 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2325 | dev_info(hsotg->dev, "%s: USBRst\n", __func__); |
| 2326 | dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2327 | readl(hsotg->regs + GNPTXSTS)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2328 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2329 | writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2330 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2331 | if (usb_status & GOTGCTL_BSESVLD) { |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2332 | if (time_after(jiffies, hsotg->last_rst + |
| 2333 | msecs_to_jiffies(200))) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2334 | |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2335 | kill_all_requests(hsotg, &hsotg->eps[0], |
| 2336 | -ECONNRESET, true); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2337 | |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2338 | s3c_hsotg_core_init_disconnected(hsotg); |
| 2339 | s3c_hsotg_core_connect(hsotg); |
Lukasz Majewski | 12a1f4d | 2012-05-04 14:17:08 +0200 | [diff] [blame] | 2340 | } |
| 2341 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /* check both FIFOs */ |
| 2345 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2346 | if (gintsts & GINTSTS_NPTXFEMP) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2347 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); |
| 2348 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2349 | /* |
| 2350 | * Disable the interrupt to stop it happening again |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2351 | * unless one of these endpoint routines decides that |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2352 | * it needs re-enabling |
| 2353 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2354 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2355 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2356 | s3c_hsotg_irq_fifoempty(hsotg, false); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2357 | } |
| 2358 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2359 | if (gintsts & GINTSTS_PTXFEMP) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2360 | dev_dbg(hsotg->dev, "PTxFEmp\n"); |
| 2361 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2362 | /* See note in GINTSTS_NPTxFEmp */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2363 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2364 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2365 | s3c_hsotg_irq_fifoempty(hsotg, true); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2368 | if (gintsts & GINTSTS_RXFLVL) { |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2369 | /* |
| 2370 | * note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2371 | * we need to retry s3c_hsotg_handle_rx if this is still |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2372 | * set. |
| 2373 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2374 | |
| 2375 | s3c_hsotg_handle_rx(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2376 | } |
| 2377 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2378 | if (gintsts & GINTSTS_ERLYSUSP) { |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2379 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2380 | writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2381 | } |
| 2382 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2383 | /* |
| 2384 | * these next two seem to crop-up occasionally causing the core |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2385 | * to shutdown the USB transfer, so try clearing them and logging |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2386 | * the occurrence. |
| 2387 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2388 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2389 | if (gintsts & GINTSTS_GOUTNAKEFF) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2390 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); |
| 2391 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2392 | writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2393 | |
| 2394 | s3c_hsotg_dump(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2395 | } |
| 2396 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2397 | if (gintsts & GINTSTS_GINNAKEFF) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2398 | dev_info(hsotg->dev, "GINNakEff triggered\n"); |
| 2399 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2400 | writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); |
Anton Tikhomirov | a3395f0 | 2011-04-21 17:06:39 +0900 | [diff] [blame] | 2401 | |
| 2402 | s3c_hsotg_dump(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2405 | /* |
| 2406 | * if we've had fifo events, we should try and go around the |
| 2407 | * loop again to see if there's any point in returning yet. |
| 2408 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2409 | |
| 2410 | if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) |
| 2411 | goto irq_retry; |
| 2412 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2413 | spin_unlock(&hsotg->lock); |
| 2414 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2415 | return IRQ_HANDLED; |
| 2416 | } |
| 2417 | |
| 2418 | /** |
| 2419 | * s3c_hsotg_ep_enable - enable the given endpoint |
| 2420 | * @ep: The USB endpint to configure |
| 2421 | * @desc: The USB endpoint descriptor to configure with. |
| 2422 | * |
| 2423 | * This is called from the USB gadget code's usb_ep_enable(). |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2424 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2425 | static int s3c_hsotg_ep_enable(struct usb_ep *ep, |
| 2426 | const struct usb_endpoint_descriptor *desc) |
| 2427 | { |
| 2428 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2429 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2430 | unsigned long flags; |
| 2431 | int index = hs_ep->index; |
| 2432 | u32 epctrl_reg; |
| 2433 | u32 epctrl; |
| 2434 | u32 mps; |
| 2435 | int dir_in; |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2436 | int i, val, size; |
Julia Lawall | 19c190f | 2010-03-29 17:36:44 +0200 | [diff] [blame] | 2437 | int ret = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2438 | |
| 2439 | dev_dbg(hsotg->dev, |
| 2440 | "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n", |
| 2441 | __func__, ep->name, desc->bEndpointAddress, desc->bmAttributes, |
| 2442 | desc->wMaxPacketSize, desc->bInterval); |
| 2443 | |
| 2444 | /* not to be called for EP0 */ |
| 2445 | WARN_ON(index == 0); |
| 2446 | |
| 2447 | dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; |
| 2448 | if (dir_in != hs_ep->dir_in) { |
| 2449 | dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); |
| 2450 | return -EINVAL; |
| 2451 | } |
| 2452 | |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 2453 | mps = usb_endpoint_maxp(desc); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2454 | |
| 2455 | /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ |
| 2456 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2457 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2458 | epctrl = readl(hsotg->regs + epctrl_reg); |
| 2459 | |
| 2460 | dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", |
| 2461 | __func__, epctrl, epctrl_reg); |
| 2462 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2463 | spin_lock_irqsave(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2464 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2465 | epctrl &= ~(DXEPCTL_EPTYPE_MASK | DXEPCTL_MPS_MASK); |
| 2466 | epctrl |= DXEPCTL_MPS(mps); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2467 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2468 | /* |
| 2469 | * mark the endpoint as active, otherwise the core may ignore |
| 2470 | * transactions entirely for this endpoint |
| 2471 | */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2472 | epctrl |= DXEPCTL_USBACTEP; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2473 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2474 | /* |
| 2475 | * set the NAK status on the endpoint, otherwise we might try and |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2476 | * do something with data that we've yet got a request to process |
| 2477 | * since the RXFIFO will take data for an endpoint even if the |
| 2478 | * size register hasn't been set. |
| 2479 | */ |
| 2480 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2481 | epctrl |= DXEPCTL_SNAK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2482 | |
| 2483 | /* update the endpoint state */ |
Robert Baldyga | e9edd199 | 2013-10-09 08:20:02 +0200 | [diff] [blame] | 2484 | s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2485 | |
| 2486 | /* default, set to non-periodic */ |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 2487 | hs_ep->isochronous = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2488 | hs_ep->periodic = 0; |
Robert Baldyga | a18ed7b | 2013-09-19 11:50:21 +0200 | [diff] [blame] | 2489 | hs_ep->halted = 0; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 2490 | hs_ep->interval = desc->bInterval; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2491 | |
Robert Baldyga | 4fca54a | 2013-10-09 09:00:02 +0200 | [diff] [blame] | 2492 | if (hs_ep->interval > 1 && hs_ep->mc > 1) |
| 2493 | dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); |
| 2494 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2495 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
| 2496 | case USB_ENDPOINT_XFER_ISOC: |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2497 | epctrl |= DXEPCTL_EPTYPE_ISO; |
| 2498 | epctrl |= DXEPCTL_SETEVENFR; |
Robert Baldyga | 1479e84 | 2013-10-09 08:41:57 +0200 | [diff] [blame] | 2499 | hs_ep->isochronous = 1; |
| 2500 | if (dir_in) |
| 2501 | hs_ep->periodic = 1; |
| 2502 | break; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2503 | |
| 2504 | case USB_ENDPOINT_XFER_BULK: |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2505 | epctrl |= DXEPCTL_EPTYPE_BULK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2506 | break; |
| 2507 | |
| 2508 | case USB_ENDPOINT_XFER_INT: |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2509 | if (dir_in) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2510 | hs_ep->periodic = 1; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2511 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2512 | epctrl |= DXEPCTL_EPTYPE_INTERRUPT; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2513 | break; |
| 2514 | |
| 2515 | case USB_ENDPOINT_XFER_CONTROL: |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2516 | epctrl |= DXEPCTL_EPTYPE_CONTROL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2517 | break; |
| 2518 | } |
| 2519 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2520 | /* |
| 2521 | * if the hardware has dedicated fifos, we must give each IN EP |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 2522 | * a unique tx-fifo even if it is non-periodic. |
| 2523 | */ |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2524 | if (dir_in && hsotg->dedicated_fifos) { |
| 2525 | size = hs_ep->ep.maxpacket*hs_ep->mc; |
| 2526 | for (i = 1; i <= 8; ++i) { |
| 2527 | if (hsotg->fifo_map & (1<<i)) |
| 2528 | continue; |
| 2529 | val = readl(hsotg->regs + DPTXFSIZN(i)); |
| 2530 | val = (val >> FIFOSIZE_DEPTH_SHIFT)*4; |
| 2531 | if (val < size) |
| 2532 | continue; |
| 2533 | hsotg->fifo_map |= 1<<i; |
| 2534 | |
| 2535 | epctrl |= DXEPCTL_TXFNUM(i); |
| 2536 | hs_ep->fifo_index = i; |
| 2537 | hs_ep->fifo_size = val; |
| 2538 | break; |
| 2539 | } |
Sudip Mukherjee | b585a48 | 2014-10-17 10:14:02 +0530 | [diff] [blame] | 2540 | if (i == 8) { |
| 2541 | ret = -ENOMEM; |
| 2542 | goto error; |
| 2543 | } |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2544 | } |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 2545 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2546 | /* for non control endpoints, set PID to D0 */ |
| 2547 | if (index) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2548 | epctrl |= DXEPCTL_SETD0PID; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2549 | |
| 2550 | dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", |
| 2551 | __func__, epctrl); |
| 2552 | |
| 2553 | writel(epctrl, hsotg->regs + epctrl_reg); |
| 2554 | dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", |
| 2555 | __func__, readl(hsotg->regs + epctrl_reg)); |
| 2556 | |
| 2557 | /* enable the endpoint interrupt */ |
| 2558 | s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); |
| 2559 | |
Sudip Mukherjee | b585a48 | 2014-10-17 10:14:02 +0530 | [diff] [blame] | 2560 | error: |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2561 | spin_unlock_irqrestore(&hsotg->lock, flags); |
Julia Lawall | 19c190f | 2010-03-29 17:36:44 +0200 | [diff] [blame] | 2562 | return ret; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2563 | } |
| 2564 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2565 | /** |
| 2566 | * s3c_hsotg_ep_disable - disable given endpoint |
| 2567 | * @ep: The endpoint to disable. |
| 2568 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2569 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) |
| 2570 | { |
| 2571 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2572 | struct dwc2_hsotg *hsotg = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2573 | int dir_in = hs_ep->dir_in; |
| 2574 | int index = hs_ep->index; |
| 2575 | unsigned long flags; |
| 2576 | u32 epctrl_reg; |
| 2577 | u32 ctrl; |
| 2578 | |
Marek Szyprowski | 1e01129 | 2014-09-09 10:44:54 +0200 | [diff] [blame] | 2579 | dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2580 | |
| 2581 | if (ep == &hsotg->eps[0].ep) { |
| 2582 | dev_err(hsotg->dev, "%s: called for ep0\n", __func__); |
| 2583 | return -EINVAL; |
| 2584 | } |
| 2585 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2586 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2587 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2588 | spin_lock_irqsave(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2589 | /* terminate all requests with shutdown */ |
| 2590 | kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); |
| 2591 | |
Robert Baldyga | b203d0a | 2014-09-09 10:44:56 +0200 | [diff] [blame] | 2592 | hsotg->fifo_map &= ~(1<<hs_ep->fifo_index); |
| 2593 | hs_ep->fifo_index = 0; |
| 2594 | hs_ep->fifo_size = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2595 | |
| 2596 | ctrl = readl(hsotg->regs + epctrl_reg); |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2597 | ctrl &= ~DXEPCTL_EPENA; |
| 2598 | ctrl &= ~DXEPCTL_USBACTEP; |
| 2599 | ctrl |= DXEPCTL_SNAK; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2600 | |
| 2601 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
| 2602 | writel(ctrl, hsotg->regs + epctrl_reg); |
| 2603 | |
| 2604 | /* disable endpoint interrupts */ |
| 2605 | s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); |
| 2606 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2607 | spin_unlock_irqrestore(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2608 | return 0; |
| 2609 | } |
| 2610 | |
| 2611 | /** |
| 2612 | * on_list - check request is on the given endpoint |
| 2613 | * @ep: The endpoint to check. |
| 2614 | * @test: The request to test if it is on the endpoint. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2615 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2616 | static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) |
| 2617 | { |
| 2618 | struct s3c_hsotg_req *req, *treq; |
| 2619 | |
| 2620 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
| 2621 | if (req == test) |
| 2622 | return true; |
| 2623 | } |
| 2624 | |
| 2625 | return false; |
| 2626 | } |
| 2627 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2628 | /** |
| 2629 | * s3c_hsotg_ep_dequeue - dequeue given endpoint |
| 2630 | * @ep: The endpoint to dequeue. |
| 2631 | * @req: The request to be removed from a queue. |
| 2632 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2633 | static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) |
| 2634 | { |
| 2635 | struct s3c_hsotg_req *hs_req = our_req(req); |
| 2636 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2637 | struct dwc2_hsotg *hs = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2638 | unsigned long flags; |
| 2639 | |
Marek Szyprowski | 1e01129 | 2014-09-09 10:44:54 +0200 | [diff] [blame] | 2640 | dev_dbg(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2641 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2642 | spin_lock_irqsave(&hs->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2643 | |
| 2644 | if (!on_list(hs_ep, hs_req)) { |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2645 | spin_unlock_irqrestore(&hs->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2646 | return -EINVAL; |
| 2647 | } |
| 2648 | |
| 2649 | s3c_hsotg_complete_request(hs, hs_ep, hs_req, -ECONNRESET); |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 2650 | spin_unlock_irqrestore(&hs->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2651 | |
| 2652 | return 0; |
| 2653 | } |
| 2654 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2655 | /** |
| 2656 | * s3c_hsotg_ep_sethalt - set halt on a given endpoint |
| 2657 | * @ep: The endpoint to set halt. |
| 2658 | * @value: Set or unset the halt. |
| 2659 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2660 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) |
| 2661 | { |
| 2662 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2663 | struct dwc2_hsotg *hs = hs_ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2664 | int index = hs_ep->index; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2665 | u32 epreg; |
| 2666 | u32 epctl; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2667 | u32 xfertype; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2668 | |
| 2669 | dev_info(hs->dev, "%s(ep %p %s, %d)\n", __func__, ep, ep->name, value); |
| 2670 | |
Robert Baldyga | c9f721b | 2014-01-14 08:36:00 +0100 | [diff] [blame] | 2671 | if (index == 0) { |
| 2672 | if (value) |
| 2673 | s3c_hsotg_stall_ep0(hs); |
| 2674 | else |
| 2675 | dev_warn(hs->dev, |
| 2676 | "%s: can't clear halt on ep0\n", __func__); |
| 2677 | return 0; |
| 2678 | } |
| 2679 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2680 | /* write both IN and OUT control registers */ |
| 2681 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2682 | epreg = DIEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2683 | epctl = readl(hs->regs + epreg); |
| 2684 | |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2685 | if (value) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2686 | epctl |= DXEPCTL_STALL + DXEPCTL_SNAK; |
| 2687 | if (epctl & DXEPCTL_EPENA) |
| 2688 | epctl |= DXEPCTL_EPDIS; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2689 | } else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2690 | epctl &= ~DXEPCTL_STALL; |
| 2691 | xfertype = epctl & DXEPCTL_EPTYPE_MASK; |
| 2692 | if (xfertype == DXEPCTL_EPTYPE_BULK || |
| 2693 | xfertype == DXEPCTL_EPTYPE_INTERRUPT) |
| 2694 | epctl |= DXEPCTL_SETD0PID; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2695 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2696 | |
| 2697 | writel(epctl, hs->regs + epreg); |
| 2698 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2699 | epreg = DOEPCTL(index); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2700 | epctl = readl(hs->regs + epreg); |
| 2701 | |
| 2702 | if (value) |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2703 | epctl |= DXEPCTL_STALL; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2704 | else { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2705 | epctl &= ~DXEPCTL_STALL; |
| 2706 | xfertype = epctl & DXEPCTL_EPTYPE_MASK; |
| 2707 | if (xfertype == DXEPCTL_EPTYPE_BULK || |
| 2708 | xfertype == DXEPCTL_EPTYPE_INTERRUPT) |
| 2709 | epctl |= DXEPCTL_SETD0PID; |
Anton Tikhomirov | 9c39ddc | 2011-04-21 17:06:41 +0900 | [diff] [blame] | 2710 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2711 | |
| 2712 | writel(epctl, hs->regs + epreg); |
| 2713 | |
Robert Baldyga | a18ed7b | 2013-09-19 11:50:21 +0200 | [diff] [blame] | 2714 | hs_ep->halted = value; |
| 2715 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2716 | return 0; |
| 2717 | } |
| 2718 | |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2719 | /** |
| 2720 | * s3c_hsotg_ep_sethalt_lock - set halt on a given endpoint with lock held |
| 2721 | * @ep: The endpoint to set halt. |
| 2722 | * @value: Set or unset the halt. |
| 2723 | */ |
| 2724 | static int s3c_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value) |
| 2725 | { |
| 2726 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2727 | struct dwc2_hsotg *hs = hs_ep->parent; |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2728 | unsigned long flags = 0; |
| 2729 | int ret = 0; |
| 2730 | |
| 2731 | spin_lock_irqsave(&hs->lock, flags); |
| 2732 | ret = s3c_hsotg_ep_sethalt(ep, value); |
| 2733 | spin_unlock_irqrestore(&hs->lock, flags); |
| 2734 | |
| 2735 | return ret; |
| 2736 | } |
| 2737 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2738 | static struct usb_ep_ops s3c_hsotg_ep_ops = { |
| 2739 | .enable = s3c_hsotg_ep_enable, |
| 2740 | .disable = s3c_hsotg_ep_disable, |
| 2741 | .alloc_request = s3c_hsotg_ep_alloc_request, |
| 2742 | .free_request = s3c_hsotg_ep_free_request, |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2743 | .queue = s3c_hsotg_ep_queue_lock, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2744 | .dequeue = s3c_hsotg_ep_dequeue, |
Lukasz Majewski | 5ad1d31 | 2012-06-14 10:02:26 +0200 | [diff] [blame] | 2745 | .set_halt = s3c_hsotg_ep_sethalt_lock, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2746 | /* note, don't believe we have any call for the fifo routines */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2747 | }; |
| 2748 | |
| 2749 | /** |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2750 | * s3c_hsotg_phy_enable - enable platform phy dev |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2751 | * @hsotg: The driver state |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2752 | * |
| 2753 | * A wrapper for platform code responsible for controlling |
| 2754 | * low-level USB code |
| 2755 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2756 | static void s3c_hsotg_phy_enable(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2757 | { |
| 2758 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
| 2759 | |
| 2760 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 2761 | |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2762 | if (hsotg->uphy) |
| 2763 | usb_phy_init(hsotg->uphy); |
| 2764 | else if (hsotg->plat && hsotg->plat->phy_init) |
| 2765 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); |
| 2766 | else { |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 2767 | phy_init(hsotg->phy); |
| 2768 | phy_power_on(hsotg->phy); |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2769 | } |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * s3c_hsotg_phy_disable - disable platform phy dev |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2774 | * @hsotg: The driver state |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2775 | * |
| 2776 | * A wrapper for platform code responsible for controlling |
| 2777 | * low-level USB code |
| 2778 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2779 | static void s3c_hsotg_phy_disable(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2780 | { |
| 2781 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
| 2782 | |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2783 | if (hsotg->uphy) |
| 2784 | usb_phy_shutdown(hsotg->uphy); |
| 2785 | else if (hsotg->plat && hsotg->plat->phy_exit) |
| 2786 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
| 2787 | else { |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 2788 | phy_power_off(hsotg->phy); |
| 2789 | phy_exit(hsotg->phy); |
Kamil Debski | ca2c5ba | 2014-09-09 10:44:09 +0200 | [diff] [blame] | 2790 | } |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 2791 | } |
| 2792 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2793 | /** |
| 2794 | * s3c_hsotg_init - initalize the usb core |
| 2795 | * @hsotg: The driver state |
| 2796 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2797 | static void s3c_hsotg_init(struct dwc2_hsotg *hsotg) |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2798 | { |
| 2799 | /* unmask subset of endpoint interrupts */ |
| 2800 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2801 | writel(DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | |
| 2802 | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK, |
| 2803 | hsotg->regs + DIEPMSK); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2804 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2805 | writel(DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | |
| 2806 | DOEPMSK_EPDISBLDMSK | DOEPMSK_XFERCOMPLMSK, |
| 2807 | hsotg->regs + DOEPMSK); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2808 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2809 | writel(0, hsotg->regs + DAINTMSK); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2810 | |
| 2811 | /* Be in disconnected state until gadget is registered */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2812 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2813 | |
| 2814 | if (0) { |
| 2815 | /* post global nak until we're ready */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2816 | writel(DCTL_SGNPINNAK | DCTL_SGOUTNAK, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2817 | hsotg->regs + DCTL); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | /* setup fifos */ |
| 2821 | |
| 2822 | dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2823 | readl(hsotg->regs + GRXFSIZ), |
| 2824 | readl(hsotg->regs + GNPTXFSIZ)); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2825 | |
| 2826 | s3c_hsotg_init_fifo(hsotg); |
| 2827 | |
| 2828 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2829 | writel(GUSBCFG_PHYIF16 | GUSBCFG_TOUTCAL(7) | (0x5 << 10), |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2830 | hsotg->regs + GUSBCFG); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2831 | |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 2832 | writel(using_dma(hsotg) ? GAHBCFG_DMA_EN : 0x0, |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 2833 | hsotg->regs + GAHBCFG); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2836 | /** |
| 2837 | * s3c_hsotg_udc_start - prepare the udc for work |
| 2838 | * @gadget: The usb gadget state |
| 2839 | * @driver: The usb gadget driver |
| 2840 | * |
| 2841 | * Perform initialization to prepare udc device and driver |
| 2842 | * to work. |
| 2843 | */ |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2844 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, |
| 2845 | struct usb_gadget_driver *driver) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2846 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2847 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2848 | unsigned long flags; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2849 | int ret; |
| 2850 | |
| 2851 | if (!hsotg) { |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 2852 | pr_err("%s: called with no device\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2853 | return -ENODEV; |
| 2854 | } |
| 2855 | |
| 2856 | if (!driver) { |
| 2857 | dev_err(hsotg->dev, "%s: no driver\n", __func__); |
| 2858 | return -EINVAL; |
| 2859 | } |
| 2860 | |
Michal Nazarewicz | 7177aed | 2011-11-19 18:27:38 +0100 | [diff] [blame] | 2861 | if (driver->max_speed < USB_SPEED_FULL) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2862 | dev_err(hsotg->dev, "%s: bad speed\n", __func__); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2863 | |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2864 | if (!driver->setup) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2865 | dev_err(hsotg->dev, "%s: missing entry points\n", __func__); |
| 2866 | return -EINVAL; |
| 2867 | } |
| 2868 | |
| 2869 | WARN_ON(hsotg->driver); |
| 2870 | |
| 2871 | driver->driver.bus = NULL; |
| 2872 | hsotg->driver = driver; |
Alexandre Pereira da Silva | 7d7b229 | 2012-06-26 11:27:10 -0300 | [diff] [blame] | 2873 | hsotg->gadget.dev.of_node = hsotg->dev->of_node; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2874 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
| 2875 | |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2876 | clk_enable(hsotg->clk); |
| 2877 | |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2878 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
| 2879 | hsotg->supplies); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2880 | if (ret) { |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2881 | dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2882 | goto err; |
| 2883 | } |
| 2884 | |
Marek Szyprowski | c816c47 | 2014-10-20 12:45:37 +0200 | [diff] [blame] | 2885 | s3c_hsotg_phy_enable(hsotg); |
| 2886 | |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2887 | spin_lock_irqsave(&hsotg->lock, flags); |
| 2888 | s3c_hsotg_init(hsotg); |
| 2889 | s3c_hsotg_core_init_disconnected(hsotg); |
| 2890 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 2891 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2892 | dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2893 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2894 | return 0; |
| 2895 | |
| 2896 | err: |
| 2897 | hsotg->driver = NULL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2898 | return ret; |
| 2899 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2900 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2901 | /** |
| 2902 | * s3c_hsotg_udc_stop - stop the udc |
| 2903 | * @gadget: The usb gadget state |
| 2904 | * @driver: The usb gadget driver |
| 2905 | * |
| 2906 | * Stop udc hw block and stay tunned for future transmissions |
| 2907 | */ |
Felipe Balbi | 22835b8 | 2014-10-17 12:05:12 -0500 | [diff] [blame] | 2908 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2909 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2910 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
Lukasz Majewski | 2b19a52 | 2012-06-14 10:02:25 +0200 | [diff] [blame] | 2911 | unsigned long flags = 0; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2912 | int ep; |
| 2913 | |
| 2914 | if (!hsotg) |
| 2915 | return -ENODEV; |
| 2916 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2917 | /* all endpoints should be shutdown */ |
Robert Baldyga | 604eac3c | 2014-09-09 10:44:13 +0200 | [diff] [blame] | 2918 | for (ep = 1; ep < hsotg->num_of_eps; ep++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2919 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
| 2920 | |
Lukasz Majewski | 2b19a52 | 2012-06-14 10:02:25 +0200 | [diff] [blame] | 2921 | spin_lock_irqsave(&hsotg->lock, flags); |
| 2922 | |
Marek Szyprowski | 32805c3 | 2014-10-20 12:45:33 +0200 | [diff] [blame] | 2923 | hsotg->driver = NULL; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2924 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2925 | |
Lukasz Majewski | 2b19a52 | 2012-06-14 10:02:25 +0200 | [diff] [blame] | 2926 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 2927 | |
Marek Szyprowski | c816c47 | 2014-10-20 12:45:37 +0200 | [diff] [blame] | 2928 | s3c_hsotg_phy_disable(hsotg); |
| 2929 | |
Marek Szyprowski | c8c1025 | 2013-09-12 16:18:48 +0200 | [diff] [blame] | 2930 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2931 | |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2932 | clk_disable(hsotg->clk); |
| 2933 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2934 | return 0; |
| 2935 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2936 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 2937 | /** |
| 2938 | * s3c_hsotg_gadget_getframe - read the frame number |
| 2939 | * @gadget: The usb gadget state |
| 2940 | * |
| 2941 | * Read the {micro} frame number |
| 2942 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2943 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) |
| 2944 | { |
| 2945 | return s3c_hsotg_read_frameno(to_hsotg(gadget)); |
| 2946 | } |
| 2947 | |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2948 | /** |
| 2949 | * s3c_hsotg_pullup - connect/disconnect the USB PHY |
| 2950 | * @gadget: The usb gadget state |
| 2951 | * @is_on: Current state of the USB PHY |
| 2952 | * |
| 2953 | * Connect/Disconnect the USB PHY pullup |
| 2954 | */ |
| 2955 | static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) |
| 2956 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2957 | struct dwc2_hsotg *hsotg = to_hsotg(gadget); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2958 | unsigned long flags = 0; |
| 2959 | |
Andrzej Pietrasiewicz | d784f1e | 2014-09-09 10:44:53 +0200 | [diff] [blame] | 2960 | dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2961 | |
| 2962 | spin_lock_irqsave(&hsotg->lock, flags); |
| 2963 | if (is_on) { |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2964 | clk_enable(hsotg->clk); |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 2965 | s3c_hsotg_core_connect(hsotg); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2966 | } else { |
Marek Szyprowski | 5b9451f | 2014-10-20 12:45:38 +0200 | [diff] [blame] | 2967 | s3c_hsotg_core_disconnect(hsotg); |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 2968 | clk_disable(hsotg->clk); |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
| 2972 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 2973 | |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
Felipe Balbi | eeef458 | 2013-01-24 17:58:16 +0200 | [diff] [blame] | 2977 | static const struct usb_gadget_ops s3c_hsotg_gadget_ops = { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2978 | .get_frame = s3c_hsotg_gadget_getframe, |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 2979 | .udc_start = s3c_hsotg_udc_start, |
| 2980 | .udc_stop = s3c_hsotg_udc_stop, |
Lukasz Majewski | a188b68 | 2012-06-22 09:29:56 +0200 | [diff] [blame] | 2981 | .pullup = s3c_hsotg_pullup, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2982 | }; |
| 2983 | |
| 2984 | /** |
| 2985 | * s3c_hsotg_initep - initialise a single endpoint |
| 2986 | * @hsotg: The device state. |
| 2987 | * @hs_ep: The endpoint to be initialised. |
| 2988 | * @epnum: The endpoint number |
| 2989 | * |
| 2990 | * Initialise the given endpoint (as part of the probe and device state |
| 2991 | * creation) to give to the gadget driver. Setup the endpoint name, any |
| 2992 | * direction information and other state that may be required. |
| 2993 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 2994 | static void s3c_hsotg_initep(struct dwc2_hsotg *hsotg, |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2995 | struct s3c_hsotg_ep *hs_ep, |
| 2996 | int epnum) |
| 2997 | { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 2998 | char *dir; |
| 2999 | |
| 3000 | if (epnum == 0) |
| 3001 | dir = ""; |
| 3002 | else if ((epnum % 2) == 0) { |
| 3003 | dir = "out"; |
| 3004 | } else { |
| 3005 | dir = "in"; |
| 3006 | hs_ep->dir_in = 1; |
| 3007 | } |
| 3008 | |
| 3009 | hs_ep->index = epnum; |
| 3010 | |
| 3011 | snprintf(hs_ep->name, sizeof(hs_ep->name), "ep%d%s", epnum, dir); |
| 3012 | |
| 3013 | INIT_LIST_HEAD(&hs_ep->queue); |
| 3014 | INIT_LIST_HEAD(&hs_ep->ep.ep_list); |
| 3015 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3016 | /* add to the list of endpoints known by the gadget driver */ |
| 3017 | if (epnum) |
| 3018 | list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); |
| 3019 | |
| 3020 | hs_ep->parent = hsotg; |
| 3021 | hs_ep->ep.name = hs_ep->name; |
Robert Baldyga | e117e74 | 2013-12-13 12:23:38 +0100 | [diff] [blame] | 3022 | 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] | 3023 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
| 3024 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3025 | /* |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3026 | * 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] | 3027 | * to be something valid. |
| 3028 | */ |
| 3029 | |
| 3030 | if (using_dma(hsotg)) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3031 | u32 next = DXEPCTL_NEXTEP((epnum + 1) % 15); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3032 | writel(next, hsotg->regs + DIEPCTL(epnum)); |
| 3033 | writel(next, hsotg->regs + DOEPCTL(epnum)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3037 | /** |
| 3038 | * s3c_hsotg_hw_cfg - read HW configuration registers |
| 3039 | * @param: The device state |
| 3040 | * |
| 3041 | * Read the USB core HW configuration registers |
| 3042 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3043 | static void s3c_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3044 | { |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3045 | u32 cfg2, cfg3, cfg4; |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 3046 | /* check hardware configuration */ |
| 3047 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3048 | cfg2 = readl(hsotg->regs + 0x48); |
| 3049 | hsotg->num_of_eps = (cfg2 >> 10) & 0xF; |
| 3050 | |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3051 | cfg3 = readl(hsotg->regs + 0x4C); |
| 3052 | hsotg->fifo_mem = (cfg3 >> 16); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3053 | |
Ben Dooks | 10aebc7 | 2010-07-19 09:40:44 +0100 | [diff] [blame] | 3054 | cfg4 = readl(hsotg->regs + 0x50); |
| 3055 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; |
| 3056 | |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3057 | dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", |
| 3058 | hsotg->num_of_eps, |
| 3059 | hsotg->dedicated_fifos ? "dedicated" : "shared", |
| 3060 | hsotg->fifo_mem); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3061 | } |
| 3062 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3063 | /** |
| 3064 | * s3c_hsotg_dump - dump state of the udc |
| 3065 | * @param: The device state |
| 3066 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3067 | static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3068 | { |
Mark Brown | 83a0180 | 2011-06-01 17:16:15 +0100 | [diff] [blame] | 3069 | #ifdef DEBUG |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3070 | struct device *dev = hsotg->dev; |
| 3071 | void __iomem *regs = hsotg->regs; |
| 3072 | u32 val; |
| 3073 | int idx; |
| 3074 | |
| 3075 | dev_info(dev, "DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3076 | readl(regs + DCFG), readl(regs + DCTL), |
| 3077 | readl(regs + DIEPMSK)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3078 | |
| 3079 | dev_info(dev, "GAHBCFG=0x%08x, 0x44=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3080 | readl(regs + GAHBCFG), readl(regs + 0x44)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3081 | |
| 3082 | dev_info(dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3083 | readl(regs + GRXFSIZ), readl(regs + GNPTXFSIZ)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3084 | |
| 3085 | /* show periodic fifo settings */ |
| 3086 | |
| 3087 | for (idx = 1; idx <= 15; idx++) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3088 | val = readl(regs + DPTXFSIZN(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3089 | dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3090 | val >> FIFOSIZE_DEPTH_SHIFT, |
| 3091 | val & FIFOSIZE_STARTADDR_MASK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | for (idx = 0; idx < 15; idx++) { |
| 3095 | dev_info(dev, |
| 3096 | "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] | 3097 | readl(regs + DIEPCTL(idx)), |
| 3098 | readl(regs + DIEPTSIZ(idx)), |
| 3099 | readl(regs + DIEPDMA(idx))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3100 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3101 | val = readl(regs + DOEPCTL(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3102 | dev_info(dev, |
| 3103 | "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] | 3104 | idx, readl(regs + DOEPCTL(idx)), |
| 3105 | readl(regs + DOEPTSIZ(idx)), |
| 3106 | readl(regs + DOEPDMA(idx))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3107 | |
| 3108 | } |
| 3109 | |
| 3110 | dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3111 | readl(regs + DVBUSDIS), readl(regs + DVBUSPULSE)); |
Mark Brown | 83a0180 | 2011-06-01 17:16:15 +0100 | [diff] [blame] | 3112 | #endif |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3113 | } |
| 3114 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3115 | /** |
| 3116 | * state_show - debugfs: show overall driver and device state. |
| 3117 | * @seq: The seq file to write to. |
| 3118 | * @v: Unused parameter. |
| 3119 | * |
| 3120 | * This debugfs entry shows the overall state of the hardware and |
| 3121 | * some general information about each of the endpoints available |
| 3122 | * to the system. |
| 3123 | */ |
| 3124 | static int state_show(struct seq_file *seq, void *v) |
| 3125 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3126 | struct dwc2_hsotg *hsotg = seq->private; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3127 | void __iomem *regs = hsotg->regs; |
| 3128 | int idx; |
| 3129 | |
| 3130 | 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] | 3131 | readl(regs + DCFG), |
| 3132 | readl(regs + DCTL), |
| 3133 | readl(regs + DSTS)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3134 | |
| 3135 | seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3136 | readl(regs + DIEPMSK), readl(regs + DOEPMSK)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3137 | |
| 3138 | seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3139 | readl(regs + GINTMSK), |
| 3140 | readl(regs + GINTSTS)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3141 | |
| 3142 | seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3143 | readl(regs + DAINTMSK), |
| 3144 | readl(regs + DAINT)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3145 | |
| 3146 | seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3147 | readl(regs + GNPTXSTS), |
| 3148 | readl(regs + GRXSTSR)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3149 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3150 | seq_puts(seq, "\nEndpoint status:\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3151 | |
| 3152 | for (idx = 0; idx < 15; idx++) { |
| 3153 | u32 in, out; |
| 3154 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3155 | in = readl(regs + DIEPCTL(idx)); |
| 3156 | out = readl(regs + DOEPCTL(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3157 | |
| 3158 | seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", |
| 3159 | idx, in, out); |
| 3160 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3161 | in = readl(regs + DIEPTSIZ(idx)); |
| 3162 | out = readl(regs + DOEPTSIZ(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3163 | |
| 3164 | seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", |
| 3165 | in, out); |
| 3166 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3167 | seq_puts(seq, "\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | return 0; |
| 3171 | } |
| 3172 | |
| 3173 | static int state_open(struct inode *inode, struct file *file) |
| 3174 | { |
| 3175 | return single_open(file, state_show, inode->i_private); |
| 3176 | } |
| 3177 | |
| 3178 | static const struct file_operations state_fops = { |
| 3179 | .owner = THIS_MODULE, |
| 3180 | .open = state_open, |
| 3181 | .read = seq_read, |
| 3182 | .llseek = seq_lseek, |
| 3183 | .release = single_release, |
| 3184 | }; |
| 3185 | |
| 3186 | /** |
| 3187 | * fifo_show - debugfs: show the fifo information |
| 3188 | * @seq: The seq_file to write data to. |
| 3189 | * @v: Unused parameter. |
| 3190 | * |
| 3191 | * Show the FIFO information for the overall fifo and all the |
| 3192 | * periodic transmission FIFOs. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3193 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3194 | static int fifo_show(struct seq_file *seq, void *v) |
| 3195 | { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3196 | struct dwc2_hsotg *hsotg = seq->private; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3197 | void __iomem *regs = hsotg->regs; |
| 3198 | u32 val; |
| 3199 | int idx; |
| 3200 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3201 | seq_puts(seq, "Non-periodic FIFOs:\n"); |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3202 | seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3203 | |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3204 | val = readl(regs + GNPTXFSIZ); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3205 | seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3206 | val >> FIFOSIZE_DEPTH_SHIFT, |
| 3207 | val & FIFOSIZE_DEPTH_MASK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3208 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3209 | seq_puts(seq, "\nPeriodic TXFIFOs:\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3210 | |
| 3211 | for (idx = 1; idx <= 15; idx++) { |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3212 | val = readl(regs + DPTXFSIZN(idx)); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3213 | |
| 3214 | seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, |
Dinh Nguyen | 47a1685 | 2014-04-14 14:13:34 -0700 | [diff] [blame] | 3215 | val >> FIFOSIZE_DEPTH_SHIFT, |
| 3216 | val & FIFOSIZE_STARTADDR_MASK); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
| 3222 | static int fifo_open(struct inode *inode, struct file *file) |
| 3223 | { |
| 3224 | return single_open(file, fifo_show, inode->i_private); |
| 3225 | } |
| 3226 | |
| 3227 | static const struct file_operations fifo_fops = { |
| 3228 | .owner = THIS_MODULE, |
| 3229 | .open = fifo_open, |
| 3230 | .read = seq_read, |
| 3231 | .llseek = seq_lseek, |
| 3232 | .release = single_release, |
| 3233 | }; |
| 3234 | |
| 3235 | |
| 3236 | static const char *decode_direction(int is_in) |
| 3237 | { |
| 3238 | return is_in ? "in" : "out"; |
| 3239 | } |
| 3240 | |
| 3241 | /** |
| 3242 | * ep_show - debugfs: show the state of an endpoint. |
| 3243 | * @seq: The seq_file to write data to. |
| 3244 | * @v: Unused parameter. |
| 3245 | * |
| 3246 | * This debugfs entry shows the state of the given endpoint (one is |
| 3247 | * registered for each available). |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3248 | */ |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3249 | static int ep_show(struct seq_file *seq, void *v) |
| 3250 | { |
| 3251 | struct s3c_hsotg_ep *ep = seq->private; |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3252 | struct dwc2_hsotg *hsotg = ep->parent; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3253 | struct s3c_hsotg_req *req; |
| 3254 | void __iomem *regs = hsotg->regs; |
| 3255 | int index = ep->index; |
| 3256 | int show_limit = 15; |
| 3257 | unsigned long flags; |
| 3258 | |
| 3259 | seq_printf(seq, "Endpoint index %d, named %s, dir %s:\n", |
| 3260 | ep->index, ep->ep.name, decode_direction(ep->dir_in)); |
| 3261 | |
| 3262 | /* first show the register state */ |
| 3263 | |
| 3264 | seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3265 | readl(regs + DIEPCTL(index)), |
| 3266 | readl(regs + DOEPCTL(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3267 | |
| 3268 | seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3269 | readl(regs + DIEPDMA(index)), |
| 3270 | readl(regs + DOEPDMA(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3271 | |
| 3272 | seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3273 | readl(regs + DIEPINT(index)), |
| 3274 | readl(regs + DOEPINT(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3275 | |
| 3276 | seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", |
Lukasz Majewski | 94cb8fd | 2012-05-04 14:17:14 +0200 | [diff] [blame] | 3277 | readl(regs + DIEPTSIZ(index)), |
| 3278 | readl(regs + DOEPTSIZ(index))); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3279 | |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3280 | seq_puts(seq, "\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3281 | seq_printf(seq, "mps %d\n", ep->ep.maxpacket); |
| 3282 | seq_printf(seq, "total_data=%ld\n", ep->total_data); |
| 3283 | |
| 3284 | seq_printf(seq, "request list (%p,%p):\n", |
| 3285 | ep->queue.next, ep->queue.prev); |
| 3286 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 3287 | spin_lock_irqsave(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3288 | |
| 3289 | list_for_each_entry(req, &ep->queue, queue) { |
| 3290 | if (--show_limit < 0) { |
Pavel Machek | a023da3 | 2013-09-30 14:56:02 +0200 | [diff] [blame] | 3291 | seq_puts(seq, "not showing more requests...\n"); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3292 | break; |
| 3293 | } |
| 3294 | |
| 3295 | seq_printf(seq, "%c req %p: %d bytes @%p, ", |
| 3296 | req == ep->req ? '*' : ' ', |
| 3297 | req, req->req.length, req->req.buf); |
| 3298 | seq_printf(seq, "%d done, res %d\n", |
| 3299 | req->req.actual, req->req.status); |
| 3300 | } |
| 3301 | |
Lukasz Majewski | 22258f4 | 2012-06-14 10:02:24 +0200 | [diff] [blame] | 3302 | spin_unlock_irqrestore(&hsotg->lock, flags); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3303 | |
| 3304 | return 0; |
| 3305 | } |
| 3306 | |
| 3307 | static int ep_open(struct inode *inode, struct file *file) |
| 3308 | { |
| 3309 | return single_open(file, ep_show, inode->i_private); |
| 3310 | } |
| 3311 | |
| 3312 | static const struct file_operations ep_fops = { |
| 3313 | .owner = THIS_MODULE, |
| 3314 | .open = ep_open, |
| 3315 | .read = seq_read, |
| 3316 | .llseek = seq_lseek, |
| 3317 | .release = single_release, |
| 3318 | }; |
| 3319 | |
| 3320 | /** |
| 3321 | * s3c_hsotg_create_debug - create debugfs directory and files |
| 3322 | * @hsotg: The driver state |
| 3323 | * |
| 3324 | * Create the debugfs files to allow the user to get information |
| 3325 | * about the state of the system. The directory name is created |
| 3326 | * with the same name as the device itself, in case we end up |
| 3327 | * with multiple blocks in future systems. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3328 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3329 | static void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3330 | { |
| 3331 | struct dentry *root; |
| 3332 | unsigned epidx; |
| 3333 | |
| 3334 | root = debugfs_create_dir(dev_name(hsotg->dev), NULL); |
| 3335 | hsotg->debug_root = root; |
| 3336 | if (IS_ERR(root)) { |
| 3337 | dev_err(hsotg->dev, "cannot create debug root\n"); |
| 3338 | return; |
| 3339 | } |
| 3340 | |
| 3341 | /* create general state file */ |
| 3342 | |
| 3343 | hsotg->debug_file = debugfs_create_file("state", 0444, root, |
| 3344 | hsotg, &state_fops); |
| 3345 | |
| 3346 | if (IS_ERR(hsotg->debug_file)) |
| 3347 | dev_err(hsotg->dev, "%s: failed to create state\n", __func__); |
| 3348 | |
| 3349 | hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root, |
| 3350 | hsotg, &fifo_fops); |
| 3351 | |
| 3352 | if (IS_ERR(hsotg->debug_fifo)) |
| 3353 | dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__); |
| 3354 | |
| 3355 | /* create one file for each endpoint */ |
| 3356 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3357 | for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3358 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; |
| 3359 | |
| 3360 | ep->debugfs = debugfs_create_file(ep->name, 0444, |
| 3361 | root, ep, &ep_fops); |
| 3362 | |
| 3363 | if (IS_ERR(ep->debugfs)) |
| 3364 | dev_err(hsotg->dev, "failed to create %s debug file\n", |
| 3365 | ep->name); |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | /** |
| 3370 | * s3c_hsotg_delete_debug - cleanup debugfs entries |
| 3371 | * @hsotg: The driver state |
| 3372 | * |
| 3373 | * Cleanup (remove) the debugfs files for use on module exit. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3374 | */ |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3375 | static void s3c_hsotg_delete_debug(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3376 | { |
| 3377 | unsigned epidx; |
| 3378 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3379 | for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3380 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; |
| 3381 | debugfs_remove(ep->debugfs); |
| 3382 | } |
| 3383 | |
| 3384 | debugfs_remove(hsotg->debug_file); |
| 3385 | debugfs_remove(hsotg->debug_fifo); |
| 3386 | debugfs_remove(hsotg->debug_root); |
| 3387 | } |
| 3388 | |
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 | * dwc2_gadget_init - init function for gadget |
| 3391 | * @dwc2: The data structure for the DWC2 driver. |
| 3392 | * @irq: The IRQ number for the controller. |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3393 | */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3394 | int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3395 | { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3396 | struct device *dev = hsotg->dev; |
| 3397 | struct s3c_hsotg_plat *plat = dev->platform_data; |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3398 | struct phy *phy; |
| 3399 | struct usb_phy *uphy; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3400 | struct s3c_hsotg_ep *eps; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3401 | int epnum; |
| 3402 | int ret; |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3403 | int i; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3404 | |
Kamil Debski | 1b59fc7 | 2014-09-09 10:44:52 +0200 | [diff] [blame] | 3405 | /* Set default UTMI width */ |
| 3406 | hsotg->phyif = GUSBCFG_PHYIF16; |
| 3407 | |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3408 | /* |
| 3409 | * Attempt to find a generic PHY, then look for an old style |
| 3410 | * USB PHY, finally fall back to pdata |
| 3411 | */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3412 | phy = devm_phy_get(dev, "usb2-phy"); |
Felipe Balbi | f4f5ba5 | 2013-03-15 10:56:19 +0200 | [diff] [blame] | 3413 | if (IS_ERR(phy)) { |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3414 | uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
| 3415 | if (IS_ERR(uphy)) { |
| 3416 | /* Fallback for pdata */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3417 | plat = dev_get_platdata(dev); |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3418 | if (!plat) { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3419 | dev_err(dev, |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3420 | "no platform data or transceiver defined\n"); |
| 3421 | return -EPROBE_DEFER; |
| 3422 | } |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 3423 | hsotg->plat = plat; |
Matt Porter | 7408484 | 2013-12-19 09:23:06 -0500 | [diff] [blame] | 3424 | } else |
| 3425 | hsotg->uphy = uphy; |
Kamil Debski | 1b59fc7 | 2014-09-09 10:44:52 +0200 | [diff] [blame] | 3426 | } else { |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 3427 | hsotg->phy = phy; |
Kamil Debski | 1b59fc7 | 2014-09-09 10:44:52 +0200 | [diff] [blame] | 3428 | /* |
| 3429 | * If using the generic PHY framework, check if the PHY bus |
| 3430 | * width is 8-bit and set the phyif appropriately. |
| 3431 | */ |
| 3432 | if (phy_get_bus_width(phy) == 8) |
| 3433 | hsotg->phyif = GUSBCFG_PHYIF8; |
| 3434 | } |
Praveen Paneri | b2e587d | 2012-11-14 15:57:16 +0530 | [diff] [blame] | 3435 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3436 | hsotg->clk = devm_clk_get(dev, "otg"); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3437 | if (IS_ERR(hsotg->clk)) { |
Dinh Nguyen | 8d736d8 | 2014-11-11 11:13:38 -0600 | [diff] [blame] | 3438 | hsotg->clk = NULL; |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3439 | dev_err(dev, "cannot get otg clock\n"); |
Sachin Kamat | 338edab | 2012-05-18 14:33:46 +0530 | [diff] [blame] | 3440 | return PTR_ERR(hsotg->clk); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3441 | } |
| 3442 | |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 3443 | hsotg->gadget.max_speed = USB_SPEED_HIGH; |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3444 | hsotg->gadget.ops = &s3c_hsotg_gadget_ops; |
| 3445 | hsotg->gadget.name = dev_name(dev); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3446 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3447 | /* reset the system */ |
| 3448 | |
Lukasz Majewski | 04b4a0f | 2012-05-04 14:17:15 +0200 | [diff] [blame] | 3449 | clk_prepare_enable(hsotg->clk); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3450 | |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3451 | /* regulators */ |
| 3452 | |
| 3453 | for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) |
| 3454 | hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; |
| 3455 | |
Sachin Kamat | cd76213 | 2013-01-08 14:27:00 +0530 | [diff] [blame] | 3456 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3457 | hsotg->supplies); |
| 3458 | if (ret) { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3459 | dev_err(dev, "failed to request supplies: %d\n", ret); |
Sachin Kamat | 338edab | 2012-05-18 14:33:46 +0530 | [diff] [blame] | 3460 | goto err_clk; |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
| 3464 | hsotg->supplies); |
| 3465 | |
| 3466 | if (ret) { |
Dinh Nguyen | 941fcce | 2014-11-11 11:13:33 -0600 | [diff] [blame] | 3467 | dev_err(dev, "failed to enable supplies: %d\n", ret); |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3468 | goto err_supplies; |
| 3469 | } |
| 3470 | |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 3471 | /* usb phy enable */ |
| 3472 | s3c_hsotg_phy_enable(hsotg); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3473 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3474 | s3c_hsotg_corereset(hsotg); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3475 | s3c_hsotg_hw_cfg(hsotg); |
Marek Szyprowski | cff9eb7 | 2014-09-09 10:44:55 +0200 | [diff] [blame] | 3476 | s3c_hsotg_init(hsotg); |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3477 | |
Dinh Nguyen | db8178c | 2014-11-11 11:13:37 -0600 | [diff] [blame] | 3478 | ret = devm_request_irq(hsotg->dev, irq, s3c_hsotg_irq, IRQF_SHARED, |
| 3479 | dev_name(hsotg->dev), hsotg); |
Marek Szyprowski | eb3c56c | 2014-09-09 10:44:12 +0200 | [diff] [blame] | 3480 | if (ret < 0) { |
| 3481 | s3c_hsotg_phy_disable(hsotg); |
| 3482 | clk_disable_unprepare(hsotg->clk); |
| 3483 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
| 3484 | hsotg->supplies); |
Dinh Nguyen | db8178c | 2014-11-11 11:13:37 -0600 | [diff] [blame] | 3485 | dev_err(dev, "cannot claim IRQ for gadget\n"); |
Marek Szyprowski | eb3c56c | 2014-09-09 10:44:12 +0200 | [diff] [blame] | 3486 | goto err_clk; |
| 3487 | } |
| 3488 | |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3489 | /* hsotg->num_of_eps holds number of EPs other than ep0 */ |
| 3490 | |
| 3491 | if (hsotg->num_of_eps == 0) { |
| 3492 | dev_err(dev, "wrong number of EPs (zero)\n"); |
Julia Lawall | dfdda5a | 2012-08-14 08:47:34 +0200 | [diff] [blame] | 3493 | ret = -EINVAL; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3494 | goto err_supplies; |
| 3495 | } |
| 3496 | |
| 3497 | eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), |
| 3498 | GFP_KERNEL); |
| 3499 | if (!eps) { |
Julia Lawall | dfdda5a | 2012-08-14 08:47:34 +0200 | [diff] [blame] | 3500 | ret = -ENOMEM; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3501 | goto err_supplies; |
| 3502 | } |
| 3503 | |
| 3504 | hsotg->eps = eps; |
| 3505 | |
| 3506 | /* setup endpoint information */ |
| 3507 | |
| 3508 | INIT_LIST_HEAD(&hsotg->gadget.ep_list); |
| 3509 | hsotg->gadget.ep0 = &hsotg->eps[0].ep; |
| 3510 | |
| 3511 | /* allocate EP0 request */ |
| 3512 | |
| 3513 | hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep, |
| 3514 | GFP_KERNEL); |
| 3515 | if (!hsotg->ctrl_req) { |
| 3516 | dev_err(dev, "failed to allocate ctrl req\n"); |
Julia Lawall | dfdda5a | 2012-08-14 08:47:34 +0200 | [diff] [blame] | 3517 | ret = -ENOMEM; |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3518 | goto err_ep_mem; |
| 3519 | } |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3520 | |
| 3521 | /* initialise the endpoints now the core has been initialised */ |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3522 | for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3523 | s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); |
| 3524 | |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 3525 | /* disable power and clock */ |
Marek Szyprowski | 3a8146a | 2014-10-20 12:45:34 +0200 | [diff] [blame] | 3526 | s3c_hsotg_phy_disable(hsotg); |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 3527 | |
| 3528 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
| 3529 | hsotg->supplies); |
| 3530 | if (ret) { |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3531 | dev_err(dev, "failed to disable supplies: %d\n", ret); |
Lukasz Majewski | f65f0f1 | 2012-05-04 14:17:10 +0200 | [diff] [blame] | 3532 | goto err_ep_mem; |
| 3533 | } |
| 3534 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3535 | ret = usb_add_gadget_udc(dev, &hsotg->gadget); |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3536 | if (ret) |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3537 | goto err_ep_mem; |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3538 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3539 | s3c_hsotg_create_debug(hsotg); |
| 3540 | |
| 3541 | s3c_hsotg_dump(hsotg); |
| 3542 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3543 | return 0; |
| 3544 | |
Lukasz Majewski | 1d144c6 | 2012-05-04 14:17:16 +0200 | [diff] [blame] | 3545 | err_ep_mem: |
Lukasz Majewski | b3f489b | 2012-05-04 14:17:09 +0200 | [diff] [blame] | 3546 | kfree(eps); |
Lukasz Majewski | fc9a731 | 2012-05-04 14:17:02 +0200 | [diff] [blame] | 3547 | err_supplies: |
Lukasz Majewski | 4118878 | 2012-05-04 14:17:01 +0200 | [diff] [blame] | 3548 | s3c_hsotg_phy_disable(hsotg); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3549 | err_clk: |
Lukasz Majewski | 1d144c6 | 2012-05-04 14:17:16 +0200 | [diff] [blame] | 3550 | clk_disable_unprepare(hsotg->clk); |
Sachin Kamat | 338edab | 2012-05-18 14:33:46 +0530 | [diff] [blame] | 3551 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3552 | return ret; |
| 3553 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3554 | EXPORT_SYMBOL_GPL(dwc2_gadget_init); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3555 | |
Lukasz Majewski | 8b9bc46 | 2012-05-04 14:17:11 +0200 | [diff] [blame] | 3556 | /** |
| 3557 | * s3c_hsotg_remove - remove function for hsotg driver |
| 3558 | * @pdev: The platform information for the driver |
| 3559 | */ |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3560 | int s3c_hsotg_remove(struct dwc2_hsotg *hsotg) |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3561 | { |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3562 | usb_del_gadget_udc(&hsotg->gadget); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3563 | s3c_hsotg_delete_debug(hsotg); |
Lukasz Majewski | 04b4a0f | 2012-05-04 14:17:15 +0200 | [diff] [blame] | 3564 | clk_disable_unprepare(hsotg->clk); |
Marek Szyprowski | 31ee04d | 2010-07-19 16:01:42 +0200 | [diff] [blame] | 3565 | |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3566 | return 0; |
| 3567 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3568 | EXPORT_SYMBOL_GPL(s3c_hsotg_remove); |
Ben Dooks | 5b7d70c | 2009-06-02 14:58:06 +0100 | [diff] [blame] | 3569 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3570 | int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3571 | { |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3572 | unsigned long flags; |
| 3573 | int ret = 0; |
| 3574 | |
| 3575 | if (hsotg->driver) |
| 3576 | dev_info(hsotg->dev, "suspending usb gadget %s\n", |
| 3577 | hsotg->driver->driver.name); |
| 3578 | |
| 3579 | spin_lock_irqsave(&hsotg->lock, flags); |
Marek Szyprowski | 7b093f7 | 2014-10-20 12:45:39 +0200 | [diff] [blame] | 3580 | s3c_hsotg_core_disconnect(hsotg); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3581 | s3c_hsotg_disconnect(hsotg); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3582 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
| 3583 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 3584 | |
Marek Szyprowski | 7b093f7 | 2014-10-20 12:45:39 +0200 | [diff] [blame] | 3585 | s3c_hsotg_phy_disable(hsotg); |
| 3586 | |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3587 | if (hsotg->driver) { |
| 3588 | int ep; |
| 3589 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
| 3590 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
| 3591 | |
| 3592 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
| 3593 | hsotg->supplies); |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 3594 | clk_disable(hsotg->clk); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | return ret; |
| 3598 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3599 | EXPORT_SYMBOL_GPL(s3c_hsotg_suspend); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3600 | |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3601 | int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3602 | { |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3603 | unsigned long flags; |
| 3604 | int ret = 0; |
| 3605 | |
| 3606 | if (hsotg->driver) { |
| 3607 | dev_info(hsotg->dev, "resuming usb gadget %s\n", |
| 3608 | hsotg->driver->driver.name); |
Robert Baldyga | d00b414 | 2014-09-09 10:44:57 +0200 | [diff] [blame] | 3609 | |
| 3610 | clk_enable(hsotg->clk); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3611 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
| 3612 | hsotg->supplies); |
| 3613 | } |
| 3614 | |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3615 | s3c_hsotg_phy_enable(hsotg); |
Marek Szyprowski | 7b093f7 | 2014-10-20 12:45:39 +0200 | [diff] [blame] | 3616 | |
| 3617 | spin_lock_irqsave(&hsotg->lock, flags); |
Marek Szyprowski | ad38dc5 | 2014-10-20 12:45:36 +0200 | [diff] [blame] | 3618 | s3c_hsotg_core_init_disconnected(hsotg); |
| 3619 | s3c_hsotg_core_connect(hsotg); |
Marek Szyprowski | b83e333 | 2014-02-28 13:06:11 +0100 | [diff] [blame] | 3620 | spin_unlock_irqrestore(&hsotg->lock, flags); |
| 3621 | |
| 3622 | return ret; |
| 3623 | } |
Dinh Nguyen | 117777b | 2014-11-11 11:13:34 -0600 | [diff] [blame] | 3624 | EXPORT_SYMBOL_GPL(s3c_hsotg_resume); |