Commit 6dbf05fc authored by Tao Ren's avatar Tao Ren Committed by Felipe Balbi

usb: gadget: aspeed: support per-vhub usb descriptors

This patch store vhub's standard usb descriptors in struct "ast_vhub" so
it's more convenient to customize descriptors and potentially support
multiple vhub instances in the future.
Signed-off-by: default avatarTao Ren <rentao.bupt@gmail.com>
Acked-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
parent eaea6efe
...@@ -93,11 +93,7 @@ static void ast_vhub_patch_dev_desc_usb1(struct usb_device_descriptor *desc) ...@@ -93,11 +93,7 @@ static void ast_vhub_patch_dev_desc_usb1(struct usb_device_descriptor *desc)
USB_DT_INTERFACE_SIZE + \ USB_DT_INTERFACE_SIZE + \
USB_DT_ENDPOINT_SIZE) USB_DT_ENDPOINT_SIZE)
static const struct ast_vhub_full_cdesc { static const struct ast_vhub_full_cdesc ast_vhub_conf_desc = {
struct usb_config_descriptor cfg;
struct usb_interface_descriptor intf;
struct usb_endpoint_descriptor ep;
} __attribute__ ((packed)) ast_vhub_conf_desc = {
.cfg = { .cfg = {
.bLength = USB_DT_CONFIG_SIZE, .bLength = USB_DT_CONFIG_SIZE,
.bDescriptorType = USB_DT_CONFIG, .bDescriptorType = USB_DT_CONFIG,
...@@ -266,6 +262,7 @@ static int ast_vhub_rep_desc(struct ast_vhub_ep *ep, ...@@ -266,6 +262,7 @@ static int ast_vhub_rep_desc(struct ast_vhub_ep *ep,
u8 desc_type, u16 len) u8 desc_type, u16 len)
{ {
size_t dsize; size_t dsize;
struct ast_vhub *vhub = ep->vhub;
EPDBG(ep, "GET_DESCRIPTOR(type:%d)\n", desc_type); EPDBG(ep, "GET_DESCRIPTOR(type:%d)\n", desc_type);
...@@ -281,20 +278,20 @@ static int ast_vhub_rep_desc(struct ast_vhub_ep *ep, ...@@ -281,20 +278,20 @@ static int ast_vhub_rep_desc(struct ast_vhub_ep *ep,
switch(desc_type) { switch(desc_type) {
case USB_DT_DEVICE: case USB_DT_DEVICE:
dsize = USB_DT_DEVICE_SIZE; dsize = USB_DT_DEVICE_SIZE;
memcpy(ep->buf, &ast_vhub_dev_desc, dsize); memcpy(ep->buf, &vhub->vhub_dev_desc, dsize);
BUILD_BUG_ON(dsize > sizeof(ast_vhub_dev_desc)); BUILD_BUG_ON(dsize > sizeof(vhub->vhub_dev_desc));
BUILD_BUG_ON(USB_DT_DEVICE_SIZE >= AST_VHUB_EP0_MAX_PACKET); BUILD_BUG_ON(USB_DT_DEVICE_SIZE >= AST_VHUB_EP0_MAX_PACKET);
break; break;
case USB_DT_CONFIG: case USB_DT_CONFIG:
dsize = AST_VHUB_CONF_DESC_SIZE; dsize = AST_VHUB_CONF_DESC_SIZE;
memcpy(ep->buf, &ast_vhub_conf_desc, dsize); memcpy(ep->buf, &vhub->vhub_conf_desc, dsize);
BUILD_BUG_ON(dsize > sizeof(ast_vhub_conf_desc)); BUILD_BUG_ON(dsize > sizeof(vhub->vhub_conf_desc));
BUILD_BUG_ON(AST_VHUB_CONF_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET); BUILD_BUG_ON(AST_VHUB_CONF_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET);
break; break;
case USB_DT_HUB: case USB_DT_HUB:
dsize = AST_VHUB_HUB_DESC_SIZE; dsize = AST_VHUB_HUB_DESC_SIZE;
memcpy(ep->buf, &ast_vhub_hub_desc, dsize); memcpy(ep->buf, &vhub->vhub_hub_desc, dsize);
BUILD_BUG_ON(dsize > sizeof(ast_vhub_hub_desc)); BUILD_BUG_ON(dsize > sizeof(vhub->vhub_hub_desc));
BUILD_BUG_ON(AST_VHUB_HUB_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET); BUILD_BUG_ON(AST_VHUB_HUB_DESC_SIZE >= AST_VHUB_EP0_MAX_PACKET);
break; break;
default: default:
...@@ -317,7 +314,8 @@ static int ast_vhub_rep_string(struct ast_vhub_ep *ep, ...@@ -317,7 +314,8 @@ static int ast_vhub_rep_string(struct ast_vhub_ep *ep,
u8 string_id, u16 lang_id, u8 string_id, u16 lang_id,
u16 len) u16 len)
{ {
int rc = usb_gadget_get_string (&ast_vhub_strings, string_id, ep->buf); int rc = usb_gadget_get_string(&ep->vhub->vhub_str_desc,
string_id, ep->buf);
/* /*
* This should never happen unless we put too big strings in * This should never happen unless we put too big strings in
...@@ -834,9 +832,30 @@ void ast_vhub_hub_reset(struct ast_vhub *vhub) ...@@ -834,9 +832,30 @@ void ast_vhub_hub_reset(struct ast_vhub *vhub)
writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG); writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG);
} }
static void ast_vhub_init_desc(struct ast_vhub *vhub)
{
/* Initialize vhub Device Descriptor. */
memcpy(&vhub->vhub_dev_desc, &ast_vhub_dev_desc,
sizeof(vhub->vhub_dev_desc));
/* Initialize vhub Configuration Descriptor. */
memcpy(&vhub->vhub_conf_desc, &ast_vhub_conf_desc,
sizeof(vhub->vhub_conf_desc));
/* Initialize vhub Hub Descriptor. */
memcpy(&vhub->vhub_hub_desc, &ast_vhub_hub_desc,
sizeof(vhub->vhub_hub_desc));
/* Initialize vhub String Descriptors. */
memcpy(&vhub->vhub_str_desc, &ast_vhub_strings,
sizeof(vhub->vhub_str_desc));
}
void ast_vhub_init_hub(struct ast_vhub *vhub) void ast_vhub_init_hub(struct ast_vhub *vhub)
{ {
vhub->speed = USB_SPEED_UNKNOWN; vhub->speed = USB_SPEED_UNKNOWN;
INIT_WORK(&vhub->wake_work, ast_vhub_wake_work); INIT_WORK(&vhub->wake_work, ast_vhub_wake_work);
ast_vhub_init_desc(vhub);
} }
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#ifndef __ASPEED_VHUB_H #ifndef __ASPEED_VHUB_H
#define __ASPEED_VHUB_H #define __ASPEED_VHUB_H
#include <linux/usb.h>
#include <linux/usb/ch11.h>
/***************************** /*****************************
* * * *
* VHUB register definitions * * VHUB register definitions *
...@@ -373,6 +376,12 @@ struct ast_vhub_port { ...@@ -373,6 +376,12 @@ struct ast_vhub_port {
struct ast_vhub_dev dev; struct ast_vhub_dev dev;
}; };
struct ast_vhub_full_cdesc {
struct usb_config_descriptor cfg;
struct usb_interface_descriptor intf;
struct usb_endpoint_descriptor ep;
} __packed;
/* Global vhub structure */ /* Global vhub structure */
struct ast_vhub { struct ast_vhub {
struct platform_device *pdev; struct platform_device *pdev;
...@@ -409,6 +418,12 @@ struct ast_vhub { ...@@ -409,6 +418,12 @@ struct ast_vhub {
/* Upstream bus speed captured at bus reset */ /* Upstream bus speed captured at bus reset */
unsigned int speed; unsigned int speed;
/* Standard USB Descriptors of the vhub. */
struct usb_device_descriptor vhub_dev_desc;
struct ast_vhub_full_cdesc vhub_conf_desc;
struct usb_hub_descriptor vhub_hub_desc;
struct usb_gadget_strings vhub_str_desc;
}; };
/* Standard request handlers result codes */ /* Standard request handlers result codes */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment