2 * Intel Langwell USB Device Controller driver
3 * Copyright (C) 2008-2009, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
10 #include <linux/usb/langwell_udc.h>
11 #include <linux/usb/langwell_otg.h>
13 /*-------------------------------------------------------------------------*/
15 /* driver data structures and utilities */
18 * dTD: Device Endpoint Transfer Descriptor
19 * describe to the device controller the location and quantity of
20 * data to be send/received for given transfer
24 /* bits 31:5, next transfer element pointer */
25 #define DTD_NEXT(d) (((d)>>5)&0x7ffffff)
26 #define DTD_NEXT_MASK (0x7ffffff << 5)
28 #define DTD_TERM BIT(0)
29 /* bits 7:0, execution back states */
31 #define DTD_STATUS(d) (((d)>>0)&0xff)
32 #define DTD_STS_ACTIVE BIT(7) /* active */
33 #define DTD_STS_HALTED BIT(6) /* halted */
34 #define DTD_STS_DBE BIT(5) /* data buffer error */
35 #define DTD_STS_TRE BIT(3) /* transaction error */
38 /* bits 11:10, multipier override */
40 #define DTD_MULTO (BIT(11) | BIT(10))
43 /* bit 15, interrupt on complete */
45 #define DTD_IOC BIT(15)
46 /* bits 30:16, total bytes */
48 #define DTD_TOTAL(d) (((d)>>16)&0x7fff)
49 #define DTD_MAX_TRANSFER_LENGTH 0x4000
52 /* dTD buffer pointer page 0 to 4 */
54 #define DTD_OFFSET_MASK 0xfff
55 /* bits 31:12, buffer pointer */
56 #define DTD_BUFFER(d) (((d)>>12)&0x3ff)
57 /* bits 11:0, current offset */
58 #define DTD_C_OFFSET(d) (((d)>>0)&0xfff)
59 /* bits 10:0, frame number */
60 #define DTD_FRAME(d) (((d)>>0)&0x7ff)
62 /* driver-private parts */
66 /* next dtd virtual address */
67 struct langwell_dtd
*next_dtd_virt
;
72 * dQH: Device Endpoint Queue Head
73 * describe where all transfers are managed
74 * 48-byte data structure, aligned on 64-byte boundary
76 * These are associated with dTD structure
79 /* endpoint capabilities and characteristics */
80 u32 dqh_res0
:15; /* bits 14:0 */
81 u32 dqh_ios
:1; /* bit 15, interrupt on setup */
82 #define DQH_IOS BIT(15)
83 u32 dqh_mpl
:11; /* bits 26:16, maximum packet length */
84 #define DQH_MPL (0x7ff << 16)
85 u32 dqh_res1
:2; /* bits 28:27 */
86 u32 dqh_zlt
:1; /* bit 29, zero length termination */
87 #define DQH_ZLT BIT(29)
88 u32 dqh_mult
:2; /* bits 31:30 */
89 #define DQH_MULT (BIT(30) | BIT(31))
91 /* current dTD pointer */
92 u32 dqh_current
; /* locate the transfer in progress */
93 #define DQH_C_DTD(e) \
94 (((e)>>5)&0x7ffffff) /* bits 31:5, current dTD pointer */
96 /* transfer overlay, hardware parts of a struct langwell_dtd */
98 u32 dtd_status
:8; /* bits 7:0, execution back states */
99 u32 dtd_res0
:2; /* bits 9:8 */
100 u32 dtd_multo
:2; /* bits 11:10, multipier override */
101 u32 dtd_res1
:3; /* bits 14:12 */
102 u32 dtd_ioc
:1; /* bit 15, interrupt on complete */
103 u32 dtd_total
:15; /* bits 30:16, total bytes */
104 u32 dtd_res2
:1; /* bit 31 */
105 u32 dtd_buf
[5]; /* dTD buffer pointer page 0 to 4 */
108 struct usb_ctrlrequest dqh_setup
; /* setup packet buffer */
109 } __attribute__ ((aligned(64)));
112 /* endpoint data structure */
116 struct langwell_udc
*dev
;
118 struct list_head queue
;
119 struct langwell_dqh
*dqh
;
120 const struct usb_endpoint_descriptor
*desc
;
128 /* request data structure */
129 struct langwell_request
{
130 struct usb_request req
;
131 struct langwell_dtd
*dtd
, *head
, *tail
;
132 struct langwell_ep
*ep
;
134 struct list_head queue
;
140 /* ep0 transfer state */
150 /* device suspend state */
153 LPM_L1
, /* LPM L1 sleep */
154 LPM_L2
, /* suspend */
159 /* device data structure */
160 struct langwell_udc
{
161 /* each pci device provides one gadget, several endpoints */
162 struct usb_gadget gadget
;
163 spinlock_t lock
; /* device lock */
164 struct langwell_ep
*ep
;
165 struct usb_gadget_driver
*driver
;
166 struct otg_transceiver
*transceiver
;
171 enum lpm_state lpm_state
;
172 enum ep0_state ep0_state
;
188 lpm
:1, /* LPM capability */
189 has_sram
:1, /* SRAM caching */
192 /* pci state used to access those endpoints */
193 struct pci_dev
*pdev
;
195 /* Langwell otg transceiver */
196 struct langwell_otg
*lotg
;
198 /* control registers */
199 struct langwell_cap_regs __iomem
*cap_regs
;
200 struct langwell_op_regs __iomem
*op_regs
;
202 struct usb_ctrlrequest local_setup_buff
;
203 struct langwell_dqh
*ep_dqh
;
205 dma_addr_t ep_dqh_dma
;
207 /* ep0 status request */
208 struct langwell_request
*status_req
;
211 struct dma_pool
*dtd_pool
;
213 /* make sure release() is done */
214 struct completion
*done
;
216 /* for private SRAM caching */
217 unsigned int sram_addr
;
218 unsigned int sram_size
;
220 /* device status data for get_status request */
224 #define gadget_to_langwell(g) container_of((g), struct langwell_udc, gadget)