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