usb: gadget: aspeed: allow to customize vhub device
Subsystems (3)
v2 cover usb: gadget: aspeed: allow to customize vhub device
From: Tao Ren <[email protected]>
This patch series allows people to customize aspeed-usb-vhub device IDs and strings via device tree.
Patch #1 converts the single "usb_gadget_strings" instance to a list of "usb_gadget_strings" so it's more convenient to support miltiple languages.
Patch #2 moves LANGID validation code from configfs.c to usbstring.c so it can be used by aspeed-vhub driver.
Patch #3 initializes aspeed-vhub strings with default, or from device tree if according device tree properties are defined.
Patch #4 overrides aspeed-vhub's device IDs if according properties are defined in device tree.
Patch #5 moves fixup-usb1-dev-desc logic from get-descriptor handler to vhub-init time so the descriptor is patched only once.
Patch #6 documents new device tree properties in dt-binding document.
Tao Ren (6):
usb: gadget: aspeed: support multiple language strings
usb: gadget: add "usb_validate_langid" function
usb: gadget: aspeed: allow to set usb strings in device tree
usb: gadget: aspeed: allow to set device IDs in device tree
usb: gadget: aspeed: fixup usb1 device descriptor at init time
dt-bindings: usb: document aspeed vhub device ID/string properties
.../bindings/usb/aspeed,usb-vhub.yaml | 68 +++++ drivers/usb/gadget/configfs.c | 14 +- drivers/usb/gadget/udc/aspeed-vhub/core.c | 4 +- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 236 ++++++++++++++++-- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 4 +- drivers/usb/gadget/usbstring.c | 24 ++ include/linux/usb/gadget.h | 3 + 7 files changed, 312 insertions(+), 41 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/6 usb: gadget: aspeed: support multiple language strings
From: Tao Ren <[email protected]>
This patch introduces a link list to store string descriptors with different languages, and "ast_vhub_rep_string" function is also improved to support multiple language usb strings.
---
No change in v2:
- the patch is added into the series since v2.
drivers/usb/gadget/udc/aspeed-vhub/core.c | 4 +- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 140 +++++++++++++++++++--- drivers/usb/gadget/udc/aspeed-vhub/vhub.h | 4 +- 3 files changed, 131 insertions(+), 17 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/core.c +3 -1
@@ -408,7 +408,9 @@ static int ast_vhub_probe(struct platform_device *pdev) goto err;/* Init hub emulation */ -ast_vhub_init_hub (vhub); + rc =ast_vhub_init_hub (vhub); +if (rc) + goto err;/* Initialize HW */ ast_vhub_init_hw (vhub);
drivers/usb/gadget/udc/aspeed-vhub/hub.c +126 -14
178 lines not on this page · raw message
drivers/usb/gadget/udc/aspeed-vhub/vhub.h +2 -2
@@ -421,7 +421,7 @@ struct ast_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; +struct list_head vhub_str_desc; };/* Standard request handlers result codes */
@@ -531,7 +531,7 @@ int __ast_vhub_simple_reply(struct ast_vhub_ep *ep, int len, ...); __VA_ARGS__)/* hub.c */ -void ast_vhub_init_hub (struct ast_vhub *vhub); +int ast_vhub_init_hub (struct ast_vhub *vhub);enum std_req_rc ast_vhub_std_hub_request (struct ast_vhub_ep *ep,struct usb_ctrlrequest *crq); enum std_req_rc ast_vhub_class_hub_request(struct ast_vhub_ep *ep,
Signature · 1 line
2.17.1
PATCH v2 2/6 usb: gadget: add "usb_validate_langid" function
In reply to [email protected]From: Tao Ren <[email protected]>
The USB LANGID validation code in "check_user_usb_string" function is moved to "usb_validate_langid" function which can be used by other usb gadget drivers.
---
No change in v2:
- the patch is added into the series since v2.
drivers/usb/gadget/configfs.c | 14 +------------- drivers/usb/gadget/usbstring.c | 24 ++++++++++++++++++++++++ include/linux/usb/gadget.h | 3 +++ 3 files changed, 28 insertions(+), 13 deletions(-)
drivers/usb/gadget/configfs.c +1 -13
@@ -13,8 +13,6 @@int check_user_usb_string (const char *name,struct usb_gadget_strings *stringtab_dev) { -unsigned primary_lang; -unsigned sub_lang;u16 num;int ret;
@@ -22,17 +20,7 @@ int check_user_usb_string(const char *name,if (ret)return ret; - primary_lang = num &0x3ff ; - sub_lang = num >>10 ; - -/* simple sanity check for valid langid */ -switch (primary_lang) { -case 0 : - case 0x62 ... 0xfe: - case 0x100 ... 0x3ff: -return -EINVAL ; - } -if (!sub_lang) +if (!usb_validate_langid (num))return -EINVAL ; stringtab_dev->language = num;
drivers/usb/gadget/usbstring.c +24 -0
@@ -65,3 +65,27 @@ usb_gadget_get_string (const struct usb_gadget_strings *table, int id, u8 *buf)return buf [0 ]; }EXPORT_SYMBOL_GPL (usb_gadget_get_string); + +/** +* usb_validate_langid - validate usb language identifiers +* @lang: usb language identifier +* +* Returns true for valid language identifier, otherwise false. +*/ +bool usb_validate_langid (u16 langid) +{ +u16 primary_lang = langid &0x3ff ;/* bit [9:0] */ +u16 sub_lang = langid >>10 ;/* bit [15:10] */ + +switch (primary_lang) { +case 0 : + case 0x62 ... 0xfe: + case 0x100 ... 0x3ff: +return false; + } +if (!sub_lang) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (usb_validate_langid);
include/linux/usb/gadget.h +3 -0
@@ -773,6 +773,9 @@ struct usb_gadget_string_container {/* put descriptor for string with that id into buf (buflen >= 256) */ int usb_gadget_get_string (const struct usb_gadget_strings *table,int id,u8 *buf); +/* check if the given language identifier is valid */ +bool usb_validate_langid (u16 langid); +/*-------------------------------------------------------------------------*/ /* utility to simplify managing config descriptors */
Signature · 1 line
2.17.1
PATCH v2 3/6 usb: gadget: aspeed: allow to set usb strings in device tree
In reply to [email protected]From: Tao Ren <[email protected]>
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.
---
No change in v2:
- the patch is added into the series since v2.
drivers/usb/gadget/udc/aspeed-vhub/hub.c | 58 +++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/aspeed-vhub/hub.c +57 -1
@@ -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,
@@ -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; }
Signature · 1 line
2.17.1
PATCH v2 4/6 usb: gadget: aspeed: allow to set device IDs in device tree
In reply to [email protected]From: Tao Ren <[email protected]>
The patch overrides idVendor, idProduct and bcdDevice fields in vhub Device Descriptor if according device tree properties are defined.
---
Changes in v2:
- update per-vhub device descriptor instance instead of the global default descriptor.
drivers/usb/gadget/udc/aspeed-vhub/hub.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/usb/gadget/udc/aspeed-vhub/hub.c +21 -0
@@ -887,6 +887,26 @@ void ast_vhub_hub_reset(struct ast_vhub *vhub)writel (0 , vhub->regs +AST_VHUB_EP1_STS_CHG ); } +static void ast_vhub_of_parse_dev_desc (struct ast_vhub *vhub, +const struct device_node *vhub_np) +{ +u16 id; +u32 data; + +if (!of_property_read_u32 (vhub_np,"vhub-vendor-id" , &data)) { + id = (u16 )data; + vhub->vhub_dev_desc.idVendor =cpu_to_le16 (id); + } +if (!of_property_read_u32 (vhub_np,"vhub-product-id" , &data)) { + id = (u16 )data; + vhub->vhub_dev_desc.idProduct =cpu_to_le16 (id); + } +if (!of_property_read_u32 (vhub_np,"vhub-device-revision" , &data)) { + id = (u16 )data; + vhub->vhub_dev_desc.bcdDevice =cpu_to_le16 (id); + } +} +static struct usb_gadget_string_container *ast_vhub_str_container_alloc (struct ast_vhub *vhub) {
@@ -1000,6 +1020,7 @@ static int 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)); +ast_vhub_of_parse_dev_desc (vhub, vhub_np);/* Initialize vhub Configuration Descriptor. */ memcpy(&vhub->vhub_conf_desc, &ast_vhub_conf_desc,
Signature · 1 line
2.17.1
PATCH v2 5/6 usb: gadget: aspeed: fixup usb1 device descriptor at init time
In reply to [email protected]From: Tao Ren <[email protected]>
This patch moves patch-usb1-dev-desc logic from get-descriptor handler to "ast_vhub_fixup_usb1_dev_desc" function so the code is executed only once (at vhub initial time).
---
Changes in v2:
- update per-vhub device descriptor instance instead of the global default descriptor.
drivers/usb/gadget/udc/aspeed-vhub/hub.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/hub.c +8 -11
@@ -73,13 +73,6 @@ static const struct usb_device_descriptor ast_vhub_dev_desc = { .bNumConfigurations = 1, }; -/* Patches to the above when forcing USB1 mode */ -static void ast_vhub_patch_dev_desc_usb1 (struct usb_device_descriptor *desc) -{ - desc->bcdUSB =cpu_to_le16 (0x0100 ); - desc->bDeviceProtocol =0 ; -} -/* * Configuration descriptor: same comments as above * regarding handling USB1 mode.
@@ -303,10 +296,6 @@ static int ast_vhub_rep_desc(struct ast_vhub_ep *ep,if (len > dsize) len = dsize; -/* Patch it if forcing USB1 */ -if (desc_type ==USB_DT_DEVICE && ep->vhub->force_usb1) -ast_vhub_patch_dev_desc_usb1 (ep->buf); -/* Shoot it from the EP buffer */ return ast_vhub_reply (ep,NULL , len); }
@@ -907,6 +896,12 @@ static void ast_vhub_of_parse_dev_desc(struct ast_vhub *vhub, } } +static void ast_vhub_fixup_usb1_dev_desc (struct ast_vhub *vhub) +{ + vhub->vhub_dev_desc.bcdUSB =cpu_to_le16 (0x0100 ); + vhub->vhub_dev_desc.bDeviceProtocol =0 ; +} +static struct usb_gadget_string_container *ast_vhub_str_container_alloc (struct ast_vhub *vhub) {
@@ -1021,6 +1016,8 @@ static int ast_vhub_init_desc(struct ast_vhub *vhub)memcpy (&vhub->vhub_dev_desc, &ast_vhub_dev_desc,sizeof (vhub->vhub_dev_desc));ast_vhub_of_parse_dev_desc (vhub, vhub_np); +if (vhub->force_usb1) +ast_vhub_fixup_usb1_dev_desc (vhub);/* Initialize vhub Configuration Descriptor. */ memcpy(&vhub->vhub_conf_desc, &ast_vhub_conf_desc,
Signature · 1 line
2.17.1
PATCH v2 6/6 dt-bindings: usb: document aspeed vhub device ID/string properties
In reply to [email protected]From: Tao Ren <[email protected]>
Update device tree binding document for aspeed vhub's device IDs and string properties.
---
No change in v2:
- the patch is added into the series since v2.
.../bindings/usb/aspeed,usb-vhub.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+)
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +68 -0
@@ -52,6 +52,59 @@ properties: minimum: 1 maximum: 21 + vhub-vendor-id: + description: vhub Vendor ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-product-id: + description: vhub Product ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-device-revision: + description: vhub Device Revision in binary-coded decimal + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-strings: + type: object + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^string@[0-9a-f]+$': + type: object + description: string descriptors of the specific language + + properties: + reg: + maxItems: 1 + description: 16-bit Language Identifier defined by USB-IF + + manufacturer: + description: vhub manufacturer + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + product: + description: vhub product name + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + serial-number: + description: vhub device serial number + allOf: + - $ref: /schemas/types.yaml#/definitions/string + required: - compatible - reg
@@ -74,4 +127,19 @@ examples: aspeed,vhub-generic-endpoints = <15>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_usb2ad_default>; + + vhub-vendor-id = <0x1d6b>; + vhub-product-id = <0x0107>; + vhub-device-revision = <0x0100>; + vhub-strings { + #address-cells = <1>; + #size-cells = <0>; + + string at 0409 { + reg = <0x0409>; + manufacturer = "ASPEED"; + product = "USB Virtual Hub"; + serial-number = "0000"; + }; + }; };
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH v2 6/6] dt-bindings: usb: document aspeed vhub device ID/string properties
Quoted 22 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
Update device tree binding document for aspeed vhub's device IDs and string properties.
Signed-off-by Tao Ren <[email protected]>---
No change in v2:
- the patch is added into the series since v2..../bindings/usb/aspeed,usb-vhub.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+)Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +1
-0@@ -52,6 +52,59 @@ properties: minimum: 1 maximum: 21 + vhub-vendor-id:
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 65
Quoted 10 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +10
-0+ description: vhub Vendor ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-product-id: + description: vhub Product ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535
There's already standard 'vendor-id' and 'device-id' properties. Use those.
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 67
Quoted 2 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +2
-0+ + vhub-device-revision:
Specific to USB, not vhub.
Quoted 29 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +29
-0+ description: vhub Device Revision in binary-coded decimal + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-strings: + type: object + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^string@[0-9a-f]+$': + type: object + description: string descriptors of the specific language + + properties: + reg: + maxItems: 1 + description: 16-bit Language Identifier defined by USB-IF + + manufacturer: + description: vhub manufacturer + allOf: + - $ref: /schemas/types.yaml#/definitions/string
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 106
Quoted 10 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +10
-0+ + product: + description: vhub product name + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + serial-number: + description: vhub device serial number + allOf: + - $ref: /schemas/types.yaml#/definitions/string
For all of this, it's USB specific, not vhub specific. I'm not sure this is the right approach. It might be better to just define properties which are just raw USB descriptors rather than inventing some DT format that then has to be converted into USB descriptors.
Rob
Re: [PATCH v2 6/6] dt-bindings: usb: document aspeed vhub device ID/string properties
Quoted 22 lines · Rob Herring
Quoted 21 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
Update device tree binding document for aspeed vhub's device IDs and string properties.
Signed-off-by Tao Ren <[email protected]>---
No change in v2:
- the patch is added into the series since v2..../bindings/usb/aspeed,usb-vhub.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+)Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +0
-0@@ -52,6 +52,59 @@ properties: minimum: 1 maximum: 21
Quoted 14 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 65
Quoted 11 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +11
-0+ vhub-vendor-id: + description: vhub Vendor ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-product-id: + description: vhub Product ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535There's already standard 'vendor-id' and 'device-id' properties. Use those.
So yes and no... I don't fundamentally object but keep in mind that traditionally, the properties are about matching with a physical hardware.
In this case however, we are describing a virtual piece of HW and so those IDs are going to be picked up to be exposed as the USB vendor/device of the vhub on the USB bus.
Not necessarily an issue but it's more "configuration" than "matching" and as such, it might make sense to expose that with a prefix, though I would prefer something like usb-vendor-id or usb,vendor-id...
Quoted 4 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 67
Quoted 2 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +2
-0+ + vhub-device-revision:Specific to USB, not vhub.
Same as the above.
Quoted 36 lines
Quoted 36 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +36
-0+ description: vhub Device Revision in binary-coded decimal + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-strings: + type: object + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^string@[0-9a-f]+$': + type: object + description: string descriptors of the specific language + + properties: + reg: + maxItems: 1 + description: 16-bit Language Identifier defined by USB-IF + + manufacturer: + description: vhub manufacturer + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + product: + description: vhub product name + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + serial-number:
Quoted 8 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 106
Quoted 3 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +3
-0+ description: vhub device serial number + allOf: + - $ref: /schemas/types.yaml#/definitions/stringFor all of this, it's USB specific, not vhub specific. I'm not sure this is the right approach. It might be better to just define properties which are just raw USB descriptors rather than inventing some DT format that then has to be converted into USB descriptors.
Raw blob in the DT is rather annoying and leads to hard to parse stuff for both humans and scripts. The main strenght of the DT is it's easy to read and manipulate.
Also not the entire descriptor is configurable this way.
That said, it could be that using the DT for the above is overkill and instead, we should consider a configfs like the rest of USB gadget. Though it isn't obvious how to do that, the current gadget stuff doesn't really "fit" what we need here.
Maybe we could expose the port as UDCs but not actually expose them on the bus until the hub is "activated" via a special configfs entry...
Cheers,
Ben.
Quoted 2 lines
os the
Rob
Rob Herring
maintainerRe: [PATCH v2 6/6] dt-bindings: usb: document aspeed vhub device ID/string properties
Quoted 43 lines · Benjamin Herrenschmidt
Quoted 22 lines · Rob Herring
Quoted 21 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
Update device tree binding document for aspeed vhub's device IDs and string properties.
Signed-off-by Tao Ren <[email protected]>---
No change in v2:
- the patch is added into the series since v2..../bindings/usb/aspeed,usb-vhub.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+)Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +0
-0@@ -52,6 +52,59 @@ properties: minimum: 1 maximum: 21Quoted 14 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 65
Quoted 11 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +11
-0+ vhub-vendor-id: + description: vhub Vendor ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-product-id: + description: vhub Product ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535There's already standard 'vendor-id' and 'device-id' properties. Use those.
So yes and no... I don't fundamentally object but keep in mind that traditionally, the properties are about matching with a physical hardware.
Quoted 7 lines
In this case however, we are describing a virtual piece of HW and so those IDs are going to be picked up to be exposed as the USB vendor/device of the vhub on the USB bus.
Not necessarily an issue but it's more "configuration" than "matching" and as such, it might make sense to expose that with a prefix, though I would prefer something like usb-vendor-id or usb,vendor-id...
For FDT uses, it's pretty much been configuration. It's mostly been for PCI that I've seen these properties used.
Quoted 52 lines
Quoted 4 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 67
Quoted 2 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +2
-0+ + vhub-device-revision:Specific to USB, not vhub.
Same as the above.
Quoted 36 lines
Quoted 36 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +36
-0+ description: vhub Device Revision in binary-coded decimal + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-strings: + type: object + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^string@[0-9a-f]+$': + type: object + description: string descriptors of the specific language + + properties: + reg: + maxItems: 1 + description: 16-bit Language Identifier defined by USB-IF + + manufacturer: + description: vhub manufacturer + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + product: + description: vhub product name + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + serial-number:Quoted 8 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 106
Quoted 3 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +3
-0+ description: vhub device serial number + allOf: + - $ref: /schemas/types.yaml#/definitions/stringFor all of this, it's USB specific, not vhub specific. I'm not sure this is the right approach. It might be better to just define properties which are just raw USB descriptors rather than inventing some DT format that then has to be converted into USB descriptors.
Quoted 3 lines
Raw blob in the DT is rather annoying and leads to hard to parse stuff for both humans and scripts. The main strenght of the DT is it's easy to read and manipulate.
True, and I'd certainly agree when we're talking about some vendor specific blob. but there's already code/tools to parse USB descriptors.
Quoted 6 lines
Also not the entire descriptor is configurable this way.
That said, it could be that using the DT for the above is overkill and instead, we should consider a configfs like the rest of USB gadget. Though it isn't obvious how to do that, the current gadget stuff doesn't really "fit" what we need here.
Surely the descriptor building code can be shared at a minimum.
Regardless of whether gadget configfs fits, usually it is pretty clear whether something belongs in DT or userspace. That should be decided first.
Quoted 2 lines
Maybe we could expose the port as UDCs but not actually expose them on the bus until the hub is "activated" via a special configfs entry...
If control of the hub is done by userspace, I'd think configuration should be there too.
Rob
Re: [PATCH v2 6/6] dt-bindings: usb: document aspeed vhub device ID/string properties
Quoted 49 lines · Rob Herring
Quoted 47 lines · Benjamin Herrenschmidt
Quoted 22 lines · Rob Herring
Quoted 21 lines · rentao.bupt at gmail.com
From: Tao Ren <[email protected]>
Update device tree binding document for aspeed vhub's device IDs and string properties.
Signed-off-by Tao Ren <[email protected]>---
No change in v2:
- the patch is added into the series since v2..../bindings/usb/aspeed,usb-vhub.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+)Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +0
-0@@ -52,6 +52,59 @@ properties: minimum: 1 maximum: 21Quoted 14 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 65
Quoted 11 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +11
-0+ vhub-vendor-id: + description: vhub Vendor ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-product-id: + description: vhub Product ID + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535There's already standard 'vendor-id' and 'device-id' properties. Use those.
So yes and no... I don't fundamentally object but keep in mind that traditionally, the properties are about matching with a physical hardware.
In this case however, we are describing a virtual piece of HW and so those IDs are going to be picked up to be exposed as the USB vendor/device of the vhub on the USB bus.
Quoted 6 lines
Quoted 3 lines
Not necessarily an issue but it's more "configuration" than "matching" and as such, it might make sense to expose that with a prefix, though I would prefer something like usb-vendor-id or usb,vendor-id...
For FDT uses, it's pretty much been configuration. It's mostly been for PCI that I've seen these properties used.
Thank you Rob and Ben for the comments. I thought about using "vendor-id" or "idVendor" prefixed with "usb", "hub" or "vhub", and I chose "vhub" just to distinguish from per-port usb devices' properties in the future. Anyways I'm very happy to update the names per your suggestions.
Quoted 74 lines
Quoted 53 lines
Quoted 5 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 67
Quoted 3 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +2
-0+ + vhub-device-revision:Specific to USB, not vhub.
Same as the above.
Quoted 36 lines
Quoted 36 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +36
-0+ description: vhub Device Revision in binary-coded decimal + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + - maximum: 65535 + + vhub-strings: + type: object + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^string@[0-9a-f]+$': + type: object + description: string descriptors of the specific language + + properties: + reg: + maxItems: 1 + description: 16-bit Language Identifier defined by USB-IF + + manufacturer: + description: vhub manufacturer + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + product: + description: vhub product name + allOf: + - $ref: /schemas/types.yaml#/definitions/string + + serial-number:Quoted 8 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml properties: · line 106
Quoted 3 lines
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml +3
-0+ description: vhub device serial number + allOf: + - $ref: /schemas/types.yaml#/definitions/stringFor all of this, it's USB specific, not vhub specific. I'm not sure this is the right approach. It might be better to just define properties which are just raw USB descriptors rather than inventing some DT format that then has to be converted into USB descriptors.
Quoted 3 lines
Raw blob in the DT is rather annoying and leads to hard to parse stuff for both humans and scripts. The main strenght of the DT is it's easy to read and manipulate.
True, and I'd certainly agree when we're talking about some vendor specific blob. but there's already code/tools to parse USB descriptors.
Quoted 6 lines
Also not the entire descriptor is configurable this way.
That said, it could be that using the DT for the above is overkill and instead, we should consider a configfs like the rest of USB gadget. Though it isn't obvious how to do that, the current gadget stuff doesn't really "fit" what we need here.
Surely the descriptor building code can be shared at a minimum.
Regardless of whether gadget configfs fits, usually it is pretty clear whether something belongs in DT or userspace. That should be decided first.
Quoted 7 lines
Quoted 2 lines
Maybe we could expose the port as UDCs but not actually expose them on the bus until the hub is "activated" via a special configfs entry...
If control of the hub is done by userspace, I'd think configuration should be there too.
Rob
Perhaps it's my lack of greater knowledge in gadget/dt areas, and I'm not quite clear what would be the recommended/accepted approach for this case. I'm looking forward for more suggestions.
Cheers,
Tao
Re: [PATCH v2 6/6] dt-bindings: usb: document aspeed vhub device ID/string properties
In reply to Rob HerringQuoted 11 lines · Rob Herring
Surely the descriptor building code can be shared at a minimum.
Regardless of whether gadget configfs fits, usually it is pretty clear whether something belongs in DT or userspace. That should be decided first.
Quoted 2 lines
Maybe we could expose the port as UDCs but not actually expose them on the bus until the hub is "activated" via a special configfs entry...
If control of the hub is done by userspace, I'd think configuration should be there too.
It's not in the current driver. For now, I expose the hub when the driver loads/initializes, and it creates UDCs for each port, which are then controlled from userspace.
That said, I did it this way because it was easy, not because there are fundamental reasons to do so...
The main reason to want to change the hub descriptor is for the device to advertise a vendor/device ID rather than our generic linux one, which some vendors might want to do for ... reasons. I didn't implement that functionality initially as in openbmc case, we didn't care. But I know some vendors would like to, if anything because from a user perspective, it's actually nice to have the string tell you that it's your BMC rather than Linux Fundation Hub.
Originally I suggested we allow that via the device-tree because it was the simplest way to get there and I love have to deal with less code .. :)
However, if we want to support the whole language string set etc... it gets really clumsy. So if there's a strong will to get there all the way, then configfs is probably the way to go.
In that case, some sugery will probably be needed to make the gadget descriptor building code a bit less dependent on the overall gadget stuff... either that, or pre-create a "hub" gadget at driver loading time that userspace can modify before "plugging".
In that case, the discussion should move back to linux-usb...
Cheers,
Ben.