summaryrefslogtreecommitdiffstats
path: root/target/linux/xburst/files-2.6.32/drivers/usb/gadget/jz4740_udc.h
blob: ac1540f05f9454992d5849ec36c7489945abe60f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * linux/drivers/usb/gadget/jz4740_udc.h
 *
 * Ingenic JZ4740 on-chip high speed USB device controller
 *
 * Copyright (C) 2006 Ingenic Semiconductor Inc.
 * Author: <jlwei@ingenic.cn>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#ifndef __USB_GADGET_JZ4740_H__
#define __USB_GADGET_JZ4740_H__

/*-------------------------------------------------------------------------*/

// Max packet size
#define EP0_MAXPACKETSIZE  	64
#define EPBULK_MAXPACKETSIZE  	512
#define EPINTR_MAXPACKETSIZE  	64

#define UDC_MAX_ENDPOINTS       4

/*-------------------------------------------------------------------------*/

typedef enum ep_type {
	ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
} ep_type_t;

struct jz4740_ep {
	struct usb_ep ep;
	struct jz4740_udc *dev;

	const struct usb_endpoint_descriptor *desc;
	unsigned long pio_irqs;

	uint8_t stopped;
	uint8_t bEndpointAddress;
	uint8_t bmAttributes;

	ep_type_t type;
	size_t fifo;
	u32 csr;

	uint32_t reg_addr;
	struct list_head queue;
};

struct jz4740_request {
	struct usb_request req;
	struct list_head queue;
};

enum ep0state {
	WAIT_FOR_SETUP,		/* between STATUS ack and SETUP report */
	DATA_STATE_XMIT, 	/* data tx stage */
	DATA_STATE_NEED_ZLP,	/* data tx zlp stage */
	WAIT_FOR_OUT_STATUS,	/* status stages */
	DATA_STATE_RECV,	/* data rx stage */
};

/* For function binding with UDC Disable - Added by River */
typedef enum {
	UDC_STATE_ENABLE = 0,
	UDC_STATE_DISABLE,
}udc_state_t;

struct jz4740_udc {
	struct usb_gadget gadget;
	struct usb_gadget_driver *driver;
	struct device *dev;
	spinlock_t lock;

	enum ep0state ep0state;
	struct jz4740_ep ep[UDC_MAX_ENDPOINTS];

	unsigned char usb_address;
	
	udc_state_t state;

	struct resource *mem;
	void __iomem *base;
	int irq;
	uint32_t in_mask;
	uint32_t out_mask;

	struct clk *clk;
};

extern struct jz4740_udc *the_controller;

#define ep_is_in(EP) 		(((EP)->bEndpointAddress&USB_DIR_IN)==USB_DIR_IN)
#define ep_maxpacket(EP) 	((EP)->ep.maxpacket)
#define ep_index(EP) 		((EP)->bEndpointAddress&0xF)

#endif /* __USB_GADGET_JZ4740_H__ */