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