Skip to contentSkip to conversation

usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver

PATCH Superseded Richard Leitner 3 participants 10 messages Feb 6, 2017 – Feb 8, 2017

Subsystems (5)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Richard Leitner

author maintainer
#0 lore raw

v3 cover usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver

This patch series adds a driver for configuration of the Microchip USB251xB USB 2.0 hub controller series with USB 2.0 upstream connectivity, SMBus configuration interface and two to four USB 2.0 downstream ports.

CHANGES v3:
- move ascii2utf16le() to lib/string.c and also use it also for ascii2desc in drivers/usb/core/hcd.c
- remove platform data support from usb251xb driver

CHANGES v2:
- fix max-{b,s}p-current property name
- add descriptor string handling from platform_data
- fix non-dt handling

Richard Leitner (3):
lib/string: introduce ascii2utf16le() helper
usb: core: hcd: use ascii2utf16le() in ascii2desc()
usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver

 Documentation/devicetree/bindings/usb/usb251xb.txt |  83 +++
 MAINTAINERS                                        |   8 +
 drivers/usb/core/hcd.c                             |  22 +-
 drivers/usb/misc/Kconfig                           |   9 +
 drivers/usb/misc/Makefile                          |   1 +
 drivers/usb/misc/usb251xb.c                        | 664 +++++++++++++++++++++
 include/linux/string.h                             |   1 +
 lib/string.c                                       |  26 +
 8 files changed, 802 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/usb251xb.txt
 create mode 100644 drivers/usb/misc/usb251xb.c
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#1 lore raw

PATCH v3 1/3 lib/string: introduce ascii2utf16le() helper

For USB string descriptors we need to convert ASCII strings to UTF16-LE. Therefore make a simple helper function (based on ascii2desc from drivers/usb/core/hcd.c) for that purpose.

---
 include/linux/string.h |  1 +
 lib/string.c           | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
include/linux/string.h +1 -0
index 26b6f6a..48fd0c6 100644
@@ -135,6 +135,7 @@ static inline int strtobool(const char *s, bool *res)
 }
 
 int match_string(const char * const *array, size_t n, const char *string);
+unsigned int ascii2utf16le(char const *s, u8 *buf, unsigned int len);
 
 #ifdef CONFIG_BINARY_PRINTF
 int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
lib/string.c +26 -0
index ed83562..a113e3e 100644
@@ -952,3 +952,29 @@ char *strreplace(char *s, char old, char new)
 	return s;
 }
 EXPORT_SYMBOL(strreplace);
+
+/**
+ * ascii2utf16le() - Helper routine for producing UTF-16LE string descriptors
+ * @s: Null-terminated ASCII (actually ISO-8859-1) string
+ * @buf: Buffer for UTF-16LE string
+ * @len: Length (in bytes; may be odd) of UTF-16LE buffer.
+ *
+ * Return: The number of bytes filled in: 2*strlen(s) or @len, whichever is less
+ */
+unsigned int ascii2utf16le(char const *s, u8 *buf, unsigned int len)
+{
+	unsigned int n, t = 2 * strlen(s);
+
+	if (len > t)
+		len = t;
+	n = len;
+	while (n--) {
+		t = (unsigned char)*s++;
+		*buf++ = t;
+		if (!n--)
+			break;
+		*buf++ = t >> 8;
+	}
+	return len;
+}
+EXPORT_SYMBOL(ascii2utf16le);
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper

Quoted 3 lines · Richard Leitner

For USB string descriptors we need to convert ASCII strings to UTF16-LE. Therefore make a simple helper function (based on ascii2desc from drivers/usb/core/hcd.c) for that purpose.

You know, we already have utf8s_to_utf16s() in fs/nls/nls_base.c. Maybe it doesn't do exactly what you want, but it should be pretty close. Adding another helper function to do essentially the same thing seems unnecessary.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#3 lore raw

Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper

Quoted 10 lines · Alan Stern
Quoted 3 lines · Richard Leitner

For USB string descriptors we need to convert ASCII strings to UTF16-LE. Therefore make a simple helper function (based on ascii2desc from drivers/usb/core/hcd.c) for that purpose.

You know, we already have utf8s_to_utf16s() in fs/nls/nls_base.c. Maybe it doesn't do exactly what you want, but it should be pretty close. Adding another helper function to do essentially the same thing seems unnecessary.

Thanks for that pointer. I totally agree with you.

So it would be OK to include linux/nls.h and use utf8s_to_utf16s() in drivers/usb/{core/hcd.c,misc/usb251xb.c}?

Thanks & regards,
Richard L
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper

Quoted 12 lines · Richard Leitner
Quoted 10 lines · Alan Stern
Quoted 3 lines · Richard Leitner

For USB string descriptors we need to convert ASCII strings to UTF16-LE. Therefore make a simple helper function (based on ascii2desc from drivers/usb/core/hcd.c) for that purpose.

You know, we already have utf8s_to_utf16s() in fs/nls/nls_base.c. Maybe it doesn't do exactly what you want, but it should be pretty close. Adding another helper function to do essentially the same thing seems unnecessary.

Quoted 4 lines

Thanks for that pointer. I totally agree with you.

So it would be OK to include linux/nls.h and use utf8s_to_utf16s() in drivers/usb/{core/hcd.c,misc/usb251xb.c}?

Well, we already include linux/nls.h in drivers/usb/core/message.c and a few files under drivers/usb/gadget. Putting it in a few more places shouldn't hurt.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#5 lore raw

Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper

Quoted 7 lines · Alan Stern
Quoted 2 lines · Richard Leitner

So it would be OK to include linux/nls.h and use utf8s_to_utf16s() in drivers/usb/{core/hcd.c,misc/usb251xb.c}?

Well, we already include linux/nls.h in drivers/usb/core/message.c and a few files under drivers/usb/gadget. Putting it in a few more places shouldn't hurt.

OK. Thanks! I will change that for v4.

regards,
Richard L

#6 lore raw

Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper

In reply to Richard Leitner

Hello!

Quoted 5 lines · Richard Leitner

For USB string descriptors we need to convert ASCII strings to UTF16-LE. Therefore make a simple helper function (based on ascii2desc from drivers/usb/core/hcd.c) for that purpose.

[...]

Quoted 20 lines
lib/string.c +12 -0
index ed83562..a113e3e 100644
@@ -952,3 +952,29 @@ char *strreplace(char *s, char old, char new)
 	return s;
 }
 EXPORT_SYMBOL(strreplace);
+
+/**
+ * ascii2utf16le() - Helper routine for producing UTF-16LE string descriptors
+ * @s: Null-terminated ASCII (actually ISO-8859-1) string
+ * @buf: Buffer for UTF-16LE string
+ * @len: Length (in bytes; may be odd) of UTF-16LE buffer.
+ *
+ * Return: The number of bytes filled in: 2*strlen(s) or @len, whichever is less
+ */
+unsigned int ascii2utf16le(char const *s, u8 *buf, unsigned int len)
+{
+	unsigned int n, t = 2 * strlen(s);

lib/string.c char *strreplace(char *s, char old, char new) · line 976

Quoted 10 lines
lib/string.c +10 -0
+
+	if (len > t)
+		len = t;
+	n = len;
+	while (n--) {
+		t = (unsigned char)*s++;
+		*buf++ = t;
+		if (!n--)
+			break;
+		*buf++ = t >> 8;

Isn't it always 0?

lib/string.c char *strreplace(char *s, char old, char new) · line 980

Quoted 4 lines
lib/string.c +4 -0
+	}
+	return len;
+}
+EXPORT_SYMBOL(ascii2utf16le);

MBR, Sergei

author maintainer
#7 lore raw

Re: [PATCH v3 1/3] lib/string: introduce ascii2utf16le() helper

Quoted 36 lines · Sergei Shtylyov

Hello!

Quoted 5 lines · Richard Leitner

For USB string descriptors we need to convert ASCII strings to UTF16-LE. Therefore make a simple helper function (based on ascii2desc from drivers/usb/core/hcd.c) for that purpose.

[...]

Quoted 26 lines
lib/string.c +3 -0
index ed83562..a113e3e 100644
@@ -952,3 +952,29 @@ char *strreplace(char *s, char old, char new)
     return s;
 }
 EXPORT_SYMBOL(strreplace);
+
+/**
+ * ascii2utf16le() - Helper routine for producing UTF-16LE string

descriptors
+ * @s: Null-terminated ASCII (actually ISO-8859-1) string
+ * @buf: Buffer for UTF-16LE string
+ * @len: Length (in bytes; may be odd) of UTF-16LE buffer.
+ *
+ * Return: The number of bytes filled in: 2*strlen(s) or @len, whichever is less
+ */

lib/string.c +7 -0
+unsigned int ascii2utf16le(char const *s, u8 *buf, unsigned int len)
+{
+    unsigned int n, t = 2 * strlen(s);
+
+    if (len > t)
+        len = t;
+    n = len;
Quoted 8 lines

lib/string.c char *strreplace(char *s, char old, char new) · line 976

Quoted 6 lines
lib/string.c +6 -0
+    while (n--) {
+        t = (unsigned char)*s++;
+        *buf++ = t;
+        if (!n--)
+            break;
+        *buf++ = t >> 8;

Isn't it always 0?

As I will remove this function and use utf8s_to_utf16s() instead (as suggested by Alan Stern) IMHO this issue needs no more attention.

Nonetheless, thank you for your feedback!

Quoted 5 lines

lib/string.c char *strreplace(char *s, char old, char new) · line 980

Quoted 5 lines
lib/string.c +4 -0
+    }
+    return len;
+}
+EXPORT_SYMBOL(ascii2utf16le);

regards,
Richard L

author maintainer
#8 lore raw

PATCH v3 2/3 usb: core: hcd: use ascii2utf16le() in ascii2desc()

In reply to Richard Leitner

As string.c now provides ascii2utf16le() use it in ascii2desc() for converting the string descriptor.

Furthermore fix checkpatch.pl issues in ascii2desc().

---
 drivers/usb/core/hcd.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/usb/core/hcd.c +10 -12
index 479e223..9f84548 100644
@@ -407,27 +407,25 @@ MODULE_PARM_DESC(authorized_default,
  * USB String descriptors can contain at most 126 characters; input
  * strings longer than that are truncated.
  */
-static unsigned
-ascii2desc(char const *s, u8 *buf, unsigned len)
+static unsigned int
+ascii2desc(char const *s, u8 *buf, unsigned int len)
 {
-	unsigned n, t = 2 + 2*strlen(s);
+	unsigned int t = 2 + 2 * strlen(s);
 
 	if (t > 254)
 		t = 254;	/* Longest possible UTF string descriptor */
 	if (len > t)
 		len = t;
+	if (!len)
+		return 0;
 
 	t += USB_DT_STRING << 8;	/* Now t is first 16 bits to store */
+	*buf++ = t;
+	if (len < 2)
+		return len;
+	*buf++ = t >> 8;
 
-	n = len;
-	while (n--) {
-		*buf++ = t;
-		if (!n--)
-			break;
-		*buf++ = t >> 8;
-		t = (unsigned char)*s++;
-	}
-	return len;
+	return ascii2utf16le(s, buf, (len - 2)) + 2;
 }
 
 /**
Signature · 1 line
2.1.4
author maintainer
#9 lore raw

PATCH v3 3/3 usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver

In reply to Richard Leitner

This patch adds a driver for configuration of the Microchip USB251xB/xBi USB 2.0 hub controller series with USB 2.0 upstream connectivity, SMBus configuration interface and two to four USB 2.0 downstream ports.

Furthermore add myself as a maintainer for this driver.

The datasheet can be found at the manufacturers website, see [1]. All device-tree exposed configuration features have been tested on a i.MX6 platform with a USB2512B hub.

[1] http://ww1.microchip.com/downloads/en/DeviceDoc/00001692C.pdf

---
 Documentation/devicetree/bindings/usb/usb251xb.txt |  83 +++
 MAINTAINERS                                        |   8 +
 drivers/usb/misc/Kconfig                           |   9 +
 drivers/usb/misc/Makefile                          |   1 +
 drivers/usb/misc/usb251xb.c                        | 664 +++++++++++++++++++++
 5 files changed, 765 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/usb251xb.txt
 create mode 100644 drivers/usb/misc/usb251xb.c
Documentation/devicetree/bindings/usb/usb251xb.txt new file +83 -0
new file mode 100644
index 0000000..0c065f7
@@ -0,0 +1,83 @@
+Microchip USB 2.0 Hi-Speed Hub Controller
+
+The device node for the configuration of a Microchip USB251xB/xBi USB 2.0
+Hi-Speed Controller.
+
+Required properties :
+ - compatible : Should be "microchip,usb251xb" or one of the specific types:
+	"microchip,usb2512b", "microchip,usb2512bi", "microchip,usb2513b",
+	"microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi"
+ - hub-reset-gpios : Should specify the gpio for hub reset
+
+Optional properties :
+ - reg : I2C address on the selected bus (default is <0x2C>)
+ - skip-config : Skip Hub configuration, but only send the USB-Attach command
+ - vendor-id : USB Vendor ID of the hub (16 bit, default is 0x0424)
+ - product-id : USB Product ID of the hub (16 bit, default depends on type)
+ - device-id : USB Device ID of the hub (16 bit, default is 0x0bb3)
+ - language-id : USB Language ID (16 bit, default is 0x0000)
+ - manufacturer : USB Manufacturer string (max 31 characters long)
+ - product : USB Product string (max 31 characters long)
+ - serial : USB Serial string (max 31 characters long)
+ - {bus,self}-powered : selects between self- and bus-powered operation (default
+	is self-powered)
+ - disable-hi-speed : disable USB Hi-Speed support
+ - {multi,single}-tt : selects between multi- and single-transaction-translator
+	(default is multi-tt)
+ - disable-eop : disable End of Packet generation in full-speed mode
+ - {ganged,individual}-sensing : select over-current sense type in self-powered
+	mode (default is individual)
+ - {ganged,individual}-port-switching : select port power switching mode
+	(default is individual)
+ - dynamic-power-switching : enable auto-switching from self- to bus-powered
+	operation if the local power source is removed or unavailable
+ - oc-delay-{100us,4ms,8ms,16ms} : set over current timer delay (default is 8ms)
+ - compound-device : indicated the hub is part of a compound device
+ - port-mapping-mode : enable port mapping mode
+ - string-support : enable string descriptor support (required for manufacturer,
+	product and serial string configuration)
+ - non-removable-ports : Should specify the ports which have a non-removable
+	device connected.
+ - sp-disabled-ports : Specifies the ports which will be self-power disabled
+ - bp-disabled-ports : Specifies the ports which will be bus-power disabled
+ - max-sp-power : Specifies the maximum current the hub consumes from an
+	upstream port when operating as self-powered hub including the power
+	consumption of a permanently attached peripheral if the hub is
+	configured as a compound device. The value is given in mA in a 0 - 500
+	range (default is 2).
+ - max-bp-power : Specifies the maximum current the hub consumes from an
+	upstream port when operating as bus-powered hub including the power
+	consumption of a permanently attached peripheral if the hub is
+	configured as a compound device. The value is given in mA in a 0 - 500
+	range (default is 100).
+ - max-sp-current : Specifies the maximum current the hub consumes from an
+	upstream port when operating as self-powered hub EXCLUDING the power
+	consumption of a permanently attached peripheral if the hub is
+	configured as a compound device. The value is given in mA in a 0 - 500
+	range (default is 2).
+ - max-bp-current : Specifies the maximum current the hub consumes from an
+	upstream port when operating as bus-powered hub EXCLUDING the power
+	consumption of a permanently attached peripheral if the hub is
+	configured as a compound device. The value is given in mA in a 0 - 500
+	range (default is 100).
+ - power-on-time : Specifies the time it takes from the time the host initiates
+	the power-on sequence to a port until the port has adequate power. The
+	value is given in ms in a 0 - 510 range (default is 100ms).
+
+Examples:
+	usb2512b@2c {
+		compatible = "microchip,usb2512b";
+		hub-reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
+	};
+
+	usb2514b@2c {
+		compatible = "microchip,usb2514b";
+		reg = <0x2c>;
+		reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
+		vendor-id = /bits/ 16 <0x0000>;
+		product-id = /bits/ 16 <0x0000>;
+		string-support;
+		manufacturer = "Foo";
+		product = "Foo-Bar";
+		serial = "1234567890A";
+	};
MAINTAINERS +8 -0
index 187b961..cd705bf 100644
@@ -8201,6 +8201,14 @@ F:	drivers/media/platform/atmel/atmel-isc.c
 F:	drivers/media/platform/atmel/atmel-isc-regs.h
 F:	devicetree/bindings/media/atmel-isc.txt
 
+MICROCHIP USB251XB DRIVER
+M:	Richard Leitner <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/usb/misc/usb251xb.c
+F:	include/linux/platform_data/usb251xb.h
+F:	Documentation/devicetree/bindings/usb/usb251xb.txt
+
 MICROSOFT SURFACE PRO 3 BUTTON DRIVER
 M:	Chen Yu <[email protected]>
 L:	[email protected]
drivers/usb/misc/Kconfig +9 -0
index 47b3577..1d1d70d 100644
@@ -233,6 +233,15 @@ config USB_EZUSB_FX2
 	  Say Y here if you need EZUSB device support.
 	  (Cypress FX/FX2/FX2LP microcontrollers)
 
+config USB_HUB_USB251XB
+	tristate "USB251XB Hub Controller Configuration Driver"
+	depends on I2C
+	help
+	  This option enables support for configuration via SMBus of the
+	  Microchip USB251xB/xBi USB 2.0 Hub Controller series.
+	  Configuration parameters may be set in devicetree or platform data.
+	  Say Y or M here if you need to configure such a device via SMBus.
+
 config USB_HSIC_USB3503
        tristate "USB3503 HSIC to USB20 Driver"
        depends on I2C
drivers/usb/misc/Makefile +1 -0
index 3d19927..f6ac6c9 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_USB_TRANCEVIBRATOR)	+= trancevibrator.o
 obj-$(CONFIG_USB_USS720)		+= uss720.o
 obj-$(CONFIG_USB_SEVSEG)		+= usbsevseg.o
 obj-$(CONFIG_USB_YUREX)			+= yurex.o
+obj-$(CONFIG_USB_HUB_USB251XB)		+= usb251xb.o
 obj-$(CONFIG_USB_HSIC_USB3503)		+= usb3503.o
 obj-$(CONFIG_USB_HSIC_USB4604)		+= usb4604.o
 obj-$(CONFIG_USB_CHAOSKEY)		+= chaoskey.o
drivers/usb/misc/usb251xb.c new file +664 -0

664 lines not on this page · raw message

Signature · 1 line
2.1.4