| .. | .. |
|---|
| 2 | 2 | #ifndef __ASPEED_VHUB_H |
|---|
| 3 | 3 | #define __ASPEED_VHUB_H |
|---|
| 4 | 4 | |
|---|
| 5 | +#include <linux/usb.h> |
|---|
| 6 | +#include <linux/usb/ch11.h> |
|---|
| 7 | + |
|---|
| 5 | 8 | /***************************** |
|---|
| 6 | 9 | * * |
|---|
| 7 | 10 | * VHUB register definitions * |
|---|
| .. | .. |
|---|
| 48 | 51 | #define VHUB_CTRL_UPSTREAM_CONNECT (1 << 0) |
|---|
| 49 | 52 | |
|---|
| 50 | 53 | /* IER & ISR */ |
|---|
| 54 | +#define VHUB_IRQ_DEV1_BIT 9 |
|---|
| 51 | 55 | #define VHUB_IRQ_USB_CMD_DEADLOCK (1 << 18) |
|---|
| 52 | 56 | #define VHUB_IRQ_EP_POOL_NAK (1 << 17) |
|---|
| 53 | 57 | #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) |
|---|
| 58 | +#define VHUB_IRQ_DEVICE1 (1 << (VHUB_IRQ_DEV1_BIT)) |
|---|
| 59 | 59 | #define VHUB_IRQ_BUS_RESUME (1 << 8) |
|---|
| 60 | 60 | #define VHUB_IRQ_BUS_SUSPEND (1 << 7) |
|---|
| 61 | 61 | #define VHUB_IRQ_BUS_RESET (1 << 6) |
|---|
| .. | .. |
|---|
| 67 | 67 | #define VHUB_IRQ_HUB_EP0_SETUP (1 << 0) |
|---|
| 68 | 68 | #define VHUB_IRQ_ACK_ALL 0x1ff |
|---|
| 69 | 69 | |
|---|
| 70 | +/* Downstream device IRQ mask. */ |
|---|
| 71 | +#define VHUB_DEV_IRQ(n) (VHUB_IRQ_DEVICE1 << (n)) |
|---|
| 72 | + |
|---|
| 70 | 73 | /* SW reset reg */ |
|---|
| 71 | 74 | #define VHUB_SW_RESET_EP_POOL (1 << 9) |
|---|
| 72 | 75 | #define VHUB_SW_RESET_DMA_CONTROLLER (1 << 8) |
|---|
| .. | .. |
|---|
| 76 | 79 | #define VHUB_SW_RESET_DEVICE2 (1 << 2) |
|---|
| 77 | 80 | #define VHUB_SW_RESET_DEVICE1 (1 << 1) |
|---|
| 78 | 81 | #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) |
|---|
| 82 | + |
|---|
| 87 | 83 | /* EP ACK/NACK IRQ masks */ |
|---|
| 88 | 84 | #define VHUB_EP_IRQ(n) (1 << (n)) |
|---|
| 89 | | -#define VHUB_EP_IRQ_ALL 0x7fff /* 15 EPs */ |
|---|
| 90 | 85 | |
|---|
| 91 | 86 | /* USB status reg */ |
|---|
| 92 | 87 | #define VHUB_USBSTS_HISPEED (1 << 27) |
|---|
| .. | .. |
|---|
| 210 | 205 | * * |
|---|
| 211 | 206 | ****************************************/ |
|---|
| 212 | 207 | |
|---|
| 208 | +/* |
|---|
| 209 | + * AST_VHUB_NUM_GEN_EPs and AST_VHUB_NUM_PORTS are kept to avoid breaking |
|---|
| 210 | + * existing AST2400/AST2500 platforms. AST2600 and future vhub revisions |
|---|
| 211 | + * should define number of downstream ports and endpoints in device tree. |
|---|
| 212 | + */ |
|---|
| 213 | 213 | #define AST_VHUB_NUM_GEN_EPs 15 /* Generic non-0 EPs */ |
|---|
| 214 | 214 | #define AST_VHUB_NUM_PORTS 5 /* vHub ports */ |
|---|
| 215 | 215 | #define AST_VHUB_EP0_MAX_PACKET 64 /* EP0's max packet size */ |
|---|
| .. | .. |
|---|
| 257 | 257 | ep0_state_token, |
|---|
| 258 | 258 | ep0_state_data, |
|---|
| 259 | 259 | ep0_state_status, |
|---|
| 260 | + ep0_state_stall, |
|---|
| 260 | 261 | }; |
|---|
| 261 | 262 | |
|---|
| 262 | 263 | /* |
|---|
| .. | .. |
|---|
| 311 | 312 | /* Registers */ |
|---|
| 312 | 313 | void __iomem *regs; |
|---|
| 313 | 314 | |
|---|
| 314 | | - /* Index in global pool (0..14) */ |
|---|
| 315 | + /* Index in global pool (zero-based) */ |
|---|
| 315 | 316 | unsigned int g_idx; |
|---|
| 316 | 317 | |
|---|
| 317 | 318 | /* DMA Descriptors */ |
|---|
| .. | .. |
|---|
| 341 | 342 | struct ast_vhub *vhub; |
|---|
| 342 | 343 | void __iomem *regs; |
|---|
| 343 | 344 | |
|---|
| 344 | | - /* Device index (0...4) and name string */ |
|---|
| 345 | + /* Device index (zero-based) and name string */ |
|---|
| 345 | 346 | unsigned int index; |
|---|
| 346 | 347 | const char *name; |
|---|
| 347 | 348 | |
|---|
| .. | .. |
|---|
| 353 | 354 | struct usb_gadget_driver *driver; |
|---|
| 354 | 355 | bool registered : 1; |
|---|
| 355 | 356 | bool wakeup_en : 1; |
|---|
| 356 | | - bool suspended : 1; |
|---|
| 357 | 357 | bool enabled : 1; |
|---|
| 358 | 358 | |
|---|
| 359 | 359 | /* Endpoint structures */ |
|---|
| 360 | 360 | struct ast_vhub_ep ep0; |
|---|
| 361 | | - struct ast_vhub_ep *epns[AST_VHUB_NUM_GEN_EPs]; |
|---|
| 361 | + struct ast_vhub_ep **epns; |
|---|
| 362 | + u32 max_epns; |
|---|
| 362 | 363 | |
|---|
| 363 | 364 | }; |
|---|
| 364 | 365 | #define to_ast_dev(__g) container_of(__g, struct ast_vhub_dev, gadget) |
|---|
| .. | .. |
|---|
| 372 | 373 | /* Associated device slot */ |
|---|
| 373 | 374 | struct ast_vhub_dev dev; |
|---|
| 374 | 375 | }; |
|---|
| 376 | + |
|---|
| 377 | +struct ast_vhub_full_cdesc { |
|---|
| 378 | + struct usb_config_descriptor cfg; |
|---|
| 379 | + struct usb_interface_descriptor intf; |
|---|
| 380 | + struct usb_endpoint_descriptor ep; |
|---|
| 381 | +} __packed; |
|---|
| 375 | 382 | |
|---|
| 376 | 383 | /* Global vhub structure */ |
|---|
| 377 | 384 | struct ast_vhub { |
|---|
| .. | .. |
|---|
| 393 | 400 | bool ep1_stalled : 1; |
|---|
| 394 | 401 | |
|---|
| 395 | 402 | /* Per-port info */ |
|---|
| 396 | | - struct ast_vhub_port ports[AST_VHUB_NUM_PORTS]; |
|---|
| 403 | + struct ast_vhub_port *ports; |
|---|
| 404 | + u32 max_ports; |
|---|
| 405 | + u32 port_irq_mask; |
|---|
| 397 | 406 | |
|---|
| 398 | 407 | /* Generic EP data structures */ |
|---|
| 399 | | - struct ast_vhub_ep epns[AST_VHUB_NUM_GEN_EPs]; |
|---|
| 408 | + struct ast_vhub_ep *epns; |
|---|
| 409 | + u32 max_epns; |
|---|
| 400 | 410 | |
|---|
| 401 | 411 | /* Upstream bus is suspended ? */ |
|---|
| 402 | 412 | bool suspended : 1; |
|---|
| .. | .. |
|---|
| 409 | 419 | |
|---|
| 410 | 420 | /* Upstream bus speed captured at bus reset */ |
|---|
| 411 | 421 | unsigned int speed; |
|---|
| 422 | + |
|---|
| 423 | + /* Standard USB Descriptors of the vhub. */ |
|---|
| 424 | + struct usb_device_descriptor vhub_dev_desc; |
|---|
| 425 | + struct ast_vhub_full_cdesc vhub_conf_desc; |
|---|
| 426 | + struct usb_hub_descriptor vhub_hub_desc; |
|---|
| 427 | + struct list_head vhub_str_desc; |
|---|
| 412 | 428 | }; |
|---|
| 413 | 429 | |
|---|
| 414 | 430 | /* Standard request handlers result codes */ |
|---|
| .. | .. |
|---|
| 507 | 523 | /* ep0.c */ |
|---|
| 508 | 524 | void ast_vhub_ep0_handle_ack(struct ast_vhub_ep *ep, bool in_ack); |
|---|
| 509 | 525 | void ast_vhub_ep0_handle_setup(struct ast_vhub_ep *ep); |
|---|
| 526 | +void ast_vhub_reset_ep0(struct ast_vhub_dev *dev); |
|---|
| 510 | 527 | void ast_vhub_init_ep0(struct ast_vhub *vhub, struct ast_vhub_ep *ep, |
|---|
| 511 | 528 | struct ast_vhub_dev *dev); |
|---|
| 512 | 529 | int ast_vhub_reply(struct ast_vhub_ep *ep, char *ptr, int len); |
|---|
| .. | .. |
|---|
| 517 | 534 | __VA_ARGS__) |
|---|
| 518 | 535 | |
|---|
| 519 | 536 | /* hub.c */ |
|---|
| 520 | | -void ast_vhub_init_hub(struct ast_vhub *vhub); |
|---|
| 537 | +int ast_vhub_init_hub(struct ast_vhub *vhub); |
|---|
| 521 | 538 | enum std_req_rc ast_vhub_std_hub_request(struct ast_vhub_ep *ep, |
|---|
| 522 | 539 | struct usb_ctrlrequest *crq); |
|---|
| 523 | 540 | enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep, |
|---|