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