1
2#ifndef __ASPEED_VHUB_H
3#define __ASPEED_VHUB_H
4
5
6
7
8
9
10
11#define AST_VHUB_CTRL 0x00
12#define AST_VHUB_CONF 0x04
13#define AST_VHUB_IER 0x08
14#define AST_VHUB_ISR 0x0C
15#define AST_VHUB_EP_ACK_IER 0x10
16#define AST_VHUB_EP_NACK_IER 0x14
17#define AST_VHUB_EP_ACK_ISR 0x18
18#define AST_VHUB_EP_NACK_ISR 0x1C
19#define AST_VHUB_SW_RESET 0x20
20#define AST_VHUB_USBSTS 0x24
21#define AST_VHUB_EP_TOGGLE 0x28
22#define AST_VHUB_ISO_FAIL_ACC 0x2C
23#define AST_VHUB_EP0_CTRL 0x30
24#define AST_VHUB_EP0_DATA 0x34
25#define AST_VHUB_EP1_CTRL 0x38
26#define AST_VHUB_EP1_STS_CHG 0x3C
27#define AST_VHUB_SETUP0 0x80
28#define AST_VHUB_SETUP1 0x84
29
30
31#define VHUB_CTRL_PHY_CLK (1 << 31)
32#define VHUB_CTRL_PHY_LOOP_TEST (1 << 25)
33#define VHUB_CTRL_DN_PWN (1 << 24)
34#define VHUB_CTRL_DP_PWN (1 << 23)
35#define VHUB_CTRL_LONG_DESC (1 << 18)
36#define VHUB_CTRL_ISO_RSP_CTRL (1 << 17)
37#define VHUB_CTRL_SPLIT_IN (1 << 16)
38#define VHUB_CTRL_LOOP_T_RESULT (1 << 15)
39#define VHUB_CTRL_LOOP_T_STS (1 << 14)
40#define VHUB_CTRL_PHY_BIST_RESULT (1 << 13)
41#define VHUB_CTRL_PHY_BIST_CTRL (1 << 12)
42#define VHUB_CTRL_PHY_RESET_DIS (1 << 11)
43#define VHUB_CTRL_SET_TEST_MODE(x) ((x) << 8)
44#define VHUB_CTRL_MANUAL_REMOTE_WAKEUP (1 << 4)
45#define VHUB_CTRL_AUTO_REMOTE_WAKEUP (1 << 3)
46#define VHUB_CTRL_CLK_STOP_SUSPEND (1 << 2)
47#define VHUB_CTRL_FULL_SPEED_ONLY (1 << 1)
48#define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0)
49
50
51#define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18)
52#define VHUB_IRQ_EP_POOL_NAK (1 << 17)
53#define VHUB_IRQ_EP_POOL_ACK_STALL (1 << 16)
54#define VHUB_IRQ_DEVICE5 (1 << 13)
55#define VHUB_IRQ_DEVICE4 (1 << 12)
56#define VHUB_IRQ_DEVICE3 (1 << 11)
57#define VHUB_IRQ_DEVICE2 (1 << 10)
58#define VHUB_IRQ_DEVICE1 (1 << 9)
59#define VHUB_IRQ_BUS_RESUME (1 << 8)
60#define VHUB_IRQ_BUS_SUSPEND (1 << 7)
61#define VHUB_IRQ_BUS_RESET (1 << 6)
62#define VHUB_IRQ_HUB_EP1_IN_DATA_ACK (1 << 5)
63#define VHUB_IRQ_HUB_EP0_IN_DATA_NAK (1 << 4)
64#define VHUB_IRQ_HUB_EP0_IN_ACK_STALL (1 << 3)
65#define VHUB_IRQ_HUB_EP0_OUT_NAK (1 << 2)
66#define VHUB_IRQ_HUB_EP0_OUT_ACK_STALL (1 << 1)
67#define VHUB_IRQ_HUB_EP0_SETUP (1 << 0)
68#define VHUB_IRQ_ACK_ALL 0x1ff
69
70
71#define VHUB_SW_RESET_EP_POOL (1 << 9)
72#define VHUB_SW_RESET_DMA_CONTROLLER (1 << 8)
73#define VHUB_SW_RESET_DEVICE5 (1 << 5)
74#define VHUB_SW_RESET_DEVICE4 (1 << 4)
75#define VHUB_SW_RESET_DEVICE3 (1 << 3)
76#define VHUB_SW_RESET_DEVICE2 (1 << 2)
77#define VHUB_SW_RESET_DEVICE1 (1 << 1)
78#define VHUB_SW_RESET_ROOT_HUB (1 << 0)
79#define VHUB_SW_RESET_ALL (VHUB_SW_RESET_EP_POOL | \
80 VHUB_SW_RESET_DMA_CONTROLLER | \
81 VHUB_SW_RESET_DEVICE5 | \
82 VHUB_SW_RESET_DEVICE4 | \
83 VHUB_SW_RESET_DEVICE3 | \
84 VHUB_SW_RESET_DEVICE2 | \
85 VHUB_SW_RESET_DEVICE1 | \
86 VHUB_SW_RESET_ROOT_HUB)
87
88#define VHUB_EP_IRQ(n) (1 << (n))
89#define VHUB_EP_IRQ_ALL 0x7fff
90
91
92#define VHUB_USBSTS_HISPEED (1 << 27)
93
94
95#define VHUB_EP_TOGGLE_VALUE (1 << 8)
96#define VHUB_EP_TOGGLE_SET_EPNUM(x) ((x) & 0x1f)
97
98
99#define VHUB_EP0_CTRL_STALL (1 << 0)
100#define VHUB_EP0_TX_BUFF_RDY (1 << 1)
101#define VHUB_EP0_RX_BUFF_RDY (1 << 2)
102#define VHUB_EP0_RX_LEN(x) (((x) >> 16) & 0x7f)
103#define VHUB_EP0_SET_TX_LEN(x) (((x) & 0x7f) << 8)
104
105
106#define VHUB_EP1_CTRL_RESET_TOGGLE (1 << 2)
107#define VHUB_EP1_CTRL_STALL (1 << 1)
108#define VHUB_EP1_CTRL_ENABLE (1 << 0)
109
110
111
112
113
114
115#define AST_VHUB_DEV_EN_CTRL 0x00
116#define AST_VHUB_DEV_ISR 0x04
117#define AST_VHUB_DEV_EP0_CTRL 0x08
118#define AST_VHUB_DEV_EP0_DATA 0x0c
119
120
121#define VHUB_DEV_EN_SET_ADDR(x) ((x) << 8)
122#define VHUB_DEV_EN_ADDR_MASK ((0xff) << 8)
123#define VHUB_DEV_EN_EP0_NAK_IRQEN (1 << 6)
124#define VHUB_DEV_EN_EP0_IN_ACK_IRQEN (1 << 5)
125#define VHUB_DEV_EN_EP0_OUT_NAK_IRQEN (1 << 4)
126#define VHUB_DEV_EN_EP0_OUT_ACK_IRQEN (1 << 3)
127#define VHUB_DEV_EN_EP0_SETUP_IRQEN (1 << 2)
128#define VHUB_DEV_EN_SPEED_SEL_HIGH (1 << 1)
129#define VHUB_DEV_EN_ENABLE_PORT (1 << 0)
130
131
132#define VHUV_DEV_IRQ_EP0_IN_DATA_NACK (1 << 4)
133#define VHUV_DEV_IRQ_EP0_IN_ACK_STALL (1 << 3)
134#define VHUV_DEV_IRQ_EP0_OUT_DATA_NACK (1 << 2)
135#define VHUV_DEV_IRQ_EP0_OUT_ACK_STALL (1 << 1)
136#define VHUV_DEV_IRQ_EP0_SETUP (1 << 0)
137
138
139
140
141
142
143#define VHUB_DEV_EP0_CTRL_STALL VHUB_EP0_CTRL_STALL
144#define VHUB_DEV_EP0_TX_BUFF_RDY VHUB_EP0_TX_BUFF_RDY
145#define VHUB_DEV_EP0_RX_BUFF_RDY VHUB_EP0_RX_BUFF_RDY
146#define VHUB_DEV_EP0_RX_LEN(x) VHUB_EP0_RX_LEN(x)
147#define VHUB_DEV_EP0_SET_TX_LEN(x) VHUB_EP0_SET_TX_LEN(x)
148
149
150
151
152
153
154
155#define AST_VHUB_EP_CONFIG 0x00
156#define AST_VHUB_EP_DMA_CTLSTAT 0x04
157#define AST_VHUB_EP_DESC_BASE 0x08
158#define AST_VHUB_EP_DESC_STATUS 0x0C
159
160
161#define VHUB_EP_CFG_SET_MAX_PKT(x) (((x) & 0x3ff) << 16)
162#define VHUB_EP_CFG_AUTO_DATA_DISABLE (1 << 13)
163#define VHUB_EP_CFG_STALL_CTRL (1 << 12)
164#define VHUB_EP_CFG_SET_EP_NUM(x) (((x) & 0xf) << 8)
165#define VHUB_EP_CFG_SET_TYPE(x) ((x) << 5)
166#define EP_TYPE_OFF 0
167#define EP_TYPE_BULK 1
168#define EP_TYPE_INT 2
169#define EP_TYPE_ISO 3
170#define VHUB_EP_CFG_DIR_OUT (1 << 4)
171#define VHUB_EP_CFG_SET_DEV(x) ((x) << 1)
172#define VHUB_EP_CFG_ENABLE (1 << 0)
173
174
175#define VHUB_EP_DMA_PROC_STATUS(x) (((x) >> 4) & 0xf)
176#define EP_DMA_PROC_RX_IDLE 0
177#define EP_DMA_PROC_TX_IDLE 8
178#define VHUB_EP_DMA_IN_LONG_MODE (1 << 3)
179#define VHUB_EP_DMA_OUT_CONTIG_MODE (1 << 3)
180#define VHUB_EP_DMA_CTRL_RESET (1 << 2)
181#define VHUB_EP_DMA_SINGLE_STAGE (1 << 1)
182#define VHUB_EP_DMA_DESC_MODE (1 << 0)
183
184
185#define VHUB_EP_DMA_SET_TX_SIZE(x) ((x) << 16)
186#define VHUB_EP_DMA_TX_SIZE(x) (((x) >> 16) & 0x7ff)
187#define VHUB_EP_DMA_RPTR(x) (((x) >> 8) & 0xff)
188#define VHUB_EP_DMA_SET_RPTR(x) (((x) & 0xff) << 8)
189#define VHUB_EP_DMA_SET_CPU_WPTR(x) (x)
190#define VHUB_EP_DMA_SINGLE_KICK (1 << 0)
191
192
193
194
195
196
197
198
199#define VHUB_DSC1_IN_INTERRUPT (1 << 31)
200#define VHUB_DSC1_IN_SPID_DATA0 (0 << 14)
201#define VHUB_DSC1_IN_SPID_DATA2 (1 << 14)
202#define VHUB_DSC1_IN_SPID_DATA1 (2 << 14)
203#define VHUB_DSC1_IN_SPID_MDATA (3 << 14)
204#define VHUB_DSC1_IN_SET_LEN(x) ((x) & 0xfff)
205#define VHUB_DSC1_IN_LEN(x) ((x) & 0xfff)
206
207
208
209
210
211
212
213#define AST_VHUB_NUM_GEN_EPs 15
214#define AST_VHUB_NUM_PORTS 5
215#define AST_VHUB_EP0_MAX_PACKET 64
216#define AST_VHUB_EPn_MAX_PACKET 1024
217#define AST_VHUB_DESCS_COUNT 256
218
219
220
221struct ast_vhub;
222struct ast_vhub_dev;
223
224
225
226
227
228struct ast_vhub_desc {
229 __le32 w0;
230 __le32 w1;
231};
232
233
234struct ast_vhub_req {
235 struct usb_request req;
236 struct list_head queue;
237
238
239 unsigned int act_count;
240
241
242
243
244
245 int last_desc;
246
247
248 bool active : 1;
249
250
251 bool internal : 1;
252};
253#define to_ast_req(__ureq) container_of(__ureq, struct ast_vhub_req, req)
254
255
256enum ep0_state {
257 ep0_state_token,
258 ep0_state_data,
259 ep0_state_status,
260};
261
262
263
264
265
266
267struct ast_vhub_ep {
268 struct usb_ep ep;
269
270
271 struct list_head queue;
272
273
274 unsigned int d_idx;
275
276
277 struct ast_vhub_dev *dev;
278
279
280 struct ast_vhub *vhub;
281
282
283
284
285
286 void *buf;
287 dma_addr_t buf_dma;
288
289
290 union {
291
292 struct {
293
294
295
296
297
298 void __iomem *ctlstat;
299 void __iomem *setup;
300
301
302 enum ep0_state state;
303 bool dir_in;
304
305
306 struct ast_vhub_req req;
307 } ep0;
308
309
310 struct {
311
312 void __iomem *regs;
313
314
315 unsigned int g_idx;
316
317
318 struct ast_vhub_desc *descs;
319 dma_addr_t descs_dma;
320 unsigned int d_next;
321 unsigned int d_last;
322 unsigned int dma_conf;
323
324
325 unsigned int chunk_max;
326
327
328 bool is_in : 1;
329 bool is_iso : 1;
330 bool stalled : 1;
331 bool wedged : 1;
332 bool enabled : 1;
333 bool desc_mode : 1;
334 } epn;
335 };
336};
337#define to_ast_ep(__uep) container_of(__uep, struct ast_vhub_ep, ep)
338
339
340struct ast_vhub_dev {
341 struct ast_vhub *vhub;
342 void __iomem *regs;
343
344
345 unsigned int index;
346 const char *name;
347
348
349 struct device *port_dev;
350
351
352 struct usb_gadget gadget;
353 struct usb_gadget_driver *driver;
354 bool registered : 1;
355 bool wakeup_en : 1;
356 bool suspended : 1;
357 bool enabled : 1;
358
359
360 struct ast_vhub_ep ep0;
361 struct ast_vhub_ep *epns[AST_VHUB_NUM_GEN_EPs];
362
363};
364#define to_ast_dev(__g) container_of(__g, struct ast_vhub_dev, gadget)
365
366
367struct ast_vhub_port {
368
369 u16 status;
370 u16 change;
371
372
373 struct ast_vhub_dev dev;
374};
375
376
377struct ast_vhub {
378 struct platform_device *pdev;
379 void __iomem *regs;
380 int irq;
381 spinlock_t lock;
382 struct work_struct wake_work;
383 struct clk *clk;
384
385
386 void *ep0_bufs;
387 dma_addr_t ep0_bufs_dma;
388
389
390 struct ast_vhub_ep ep0;
391
392
393 bool ep1_stalled : 1;
394
395
396 struct ast_vhub_port ports[AST_VHUB_NUM_PORTS];
397
398
399 struct ast_vhub_ep epns[AST_VHUB_NUM_GEN_EPs];
400
401
402 bool suspended : 1;
403
404
405 bool wakeup_en : 1;
406
407
408 bool force_usb1 : 1;
409
410
411 unsigned int speed;
412};
413
414
415enum std_req_rc {
416 std_req_stall = -1,
417 std_req_complete = 0,
418 std_req_data = 1,
419 std_req_driver = 2,
420};
421
422#ifdef CONFIG_USB_GADGET_VERBOSE
423#define UDCVDBG(u, fmt...) dev_dbg(&(u)->pdev->dev, fmt)
424
425#define EPVDBG(ep, fmt, ...) do { \
426 dev_dbg(&(ep)->vhub->pdev->dev, \
427 "%s:EP%d " fmt, \
428 (ep)->dev ? (ep)->dev->name : "hub", \
429 (ep)->d_idx, ##__VA_ARGS__); \
430 } while(0)
431
432#define DVDBG(d, fmt, ...) do { \
433 dev_dbg(&(d)->vhub->pdev->dev, \
434 "%s " fmt, (d)->name, \
435 ##__VA_ARGS__); \
436 } while(0)
437
438#else
439#define UDCVDBG(u, fmt...) do { } while(0)
440#define EPVDBG(ep, fmt, ...) do { } while(0)
441#define DVDBG(d, fmt, ...) do { } while(0)
442#endif
443
444#ifdef CONFIG_USB_GADGET_DEBUG
445#define UDCDBG(u, fmt...) dev_dbg(&(u)->pdev->dev, fmt)
446
447#define EPDBG(ep, fmt, ...) do { \
448 dev_dbg(&(ep)->vhub->pdev->dev, \
449 "%s:EP%d " fmt, \
450 (ep)->dev ? (ep)->dev->name : "hub", \
451 (ep)->d_idx, ##__VA_ARGS__); \
452 } while(0)
453
454#define DDBG(d, fmt, ...) do { \
455 dev_dbg(&(d)->vhub->pdev->dev, \
456 "%s " fmt, (d)->name, \
457 ##__VA_ARGS__); \
458 } while(0)
459#else
460#define UDCDBG(u, fmt...) do { } while(0)
461#define EPDBG(ep, fmt, ...) do { } while(0)
462#define DDBG(d, fmt, ...) do { } while(0)
463#endif
464
465static inline void vhub_dma_workaround(void *addr)
466{
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494 mb();
495 (void)__raw_readl((void __iomem *)addr);
496}
497
498
499void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req,
500 int status);
501void ast_vhub_nuke(struct ast_vhub_ep *ep, int status);
502struct usb_request *ast_vhub_alloc_request(struct usb_ep *u_ep,
503 gfp_t gfp_flags);
504void ast_vhub_free_request(struct usb_ep *u_ep, struct usb_request *u_req);
505void ast_vhub_init_hw(struct ast_vhub *vhub);
506
507
508void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack);
509void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep);
510void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep,
511 struct ast_vhub_dev *dev);
512int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len);
513int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...);
514#define ast_vhub_simple_reply(udc, ...) \
515 __ast_vhub_simple_reply((udc), \
516 sizeof((u8[]) { __VA_ARGS__ })/sizeof(u8), \
517 __VA_ARGS__)
518
519
520void ast_vhub_init_hub(struct ast_vhub *vhub);
521enum std_req_rc ast_vhub_std_hub_request(struct ast_vhub_ep *ep,
522 struct usb_ctrlrequest *crq);
523enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,
524 struct usb_ctrlrequest *crq);
525void ast_vhub_device_connect(struct ast_vhub *vhub, unsigned int port,
526 bool on);
527void ast_vhub_hub_suspend(struct ast_vhub *vhub);
528void ast_vhub_hub_resume(struct ast_vhub *vhub);
529void ast_vhub_hub_reset(struct ast_vhub *vhub);
530void ast_vhub_hub_wake_all(struct ast_vhub *vhub);
531
532
533int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx);
534void ast_vhub_del_dev(struct ast_vhub_dev *d);
535void ast_vhub_dev_irq(struct ast_vhub_dev *d);
536int ast_vhub_std_dev_request(struct ast_vhub_ep *ep,
537 struct usb_ctrlrequest *crq);
538
539
540void ast_vhub_epn_ack_irq(struct ast_vhub_ep *ep);
541void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep);
542struct ast_vhub_ep *ast_vhub_alloc_epn(struct ast_vhub_dev *d, u8 addr);
543void ast_vhub_dev_suspend(struct ast_vhub_dev *d);
544void ast_vhub_dev_resume(struct ast_vhub_dev *d);
545void ast_vhub_dev_reset(struct ast_vhub_dev *d);
546
547#endif
548