Skip to content

Commit

Permalink
usb: gadget: aspeed: allow to set usb strings in device tree
Browse files Browse the repository at this point in the history
If "vhub,string-descriptor" device tree property is defined, the driver
will load string descriptors from device tree; otherwise, the default
string descriptors will be used.

Signed-off-by: Tao Ren <rentao.bupt@gmail.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
  • Loading branch information
Tao Ren authored and Felipe Balbi committed May 5, 2020
1 parent 17309a6 commit 30d2617
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion drivers/usb/gadget/udc/aspeed-vhub/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,61 @@ static int ast_vhub_str_alloc_add(struct ast_vhub *vhub,
return 0;
}

static const struct {
const char *name;
u8 id;
} str_id_map[] = {
{"manufacturer", AST_VHUB_STR_MANUF},
{"product", AST_VHUB_STR_PRODUCT},
{"serial-number", AST_VHUB_STR_SERIAL},
{},
};

static int ast_vhub_of_parse_str_desc(struct ast_vhub *vhub,
const struct device_node *desc_np)
{
u32 langid;
int ret = 0;
int i, offset;
const char *str;
struct device_node *child;
struct usb_string str_array[AST_VHUB_STR_INDEX_MAX];
struct usb_gadget_strings lang_str = {
.strings = (struct usb_string *)str_array,
};

for_each_child_of_node(desc_np, child) {
if (of_property_read_u32(child, "reg", &langid))
continue; /* no language identifier specified */

if (!usb_validate_langid(langid))
continue; /* invalid language identifier */

lang_str.language = langid;
for (i = offset = 0; str_id_map[i].name; i++) {
str = of_get_property(child, str_id_map[i].name, NULL);
if (str) {
str_array[offset].s = str;
str_array[offset].id = str_id_map[i].id;
offset++;
}
}
str_array[offset].id = 0;
str_array[offset].s = NULL;

ret = ast_vhub_str_alloc_add(vhub, &lang_str);
if (ret)
break;
}

return ret;
}

static int ast_vhub_init_desc(struct ast_vhub *vhub)
{
int ret;
struct device_node *desc_np;
const struct device_node *vhub_np = vhub->pdev->dev.of_node;

/* Initialize vhub Device Descriptor. */
memcpy(&vhub->vhub_dev_desc, &ast_vhub_dev_desc,
Expand All @@ -960,7 +1012,11 @@ static int ast_vhub_init_desc(struct ast_vhub *vhub)

/* Initialize vhub String Descriptors. */
INIT_LIST_HEAD(&vhub->vhub_str_desc);
ret = ast_vhub_str_alloc_add(vhub, &ast_vhub_strings);
desc_np = of_get_child_by_name(vhub_np, "vhub-strings");
if (desc_np)
ret = ast_vhub_of_parse_str_desc(vhub, desc_np);
else
ret = ast_vhub_str_alloc_add(vhub, &ast_vhub_strings);

return ret;
}
Expand Down

0 comments on commit 30d2617

Please sign in to comment.