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