usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver
Subsystems (3)
Richard Leitner
maintainerPATCH v2 1/1 usb: misc: add USB251xB/xBi Hi-Speed Hub Controller Driver
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
---
CHANGES v2:
- fix max-{b,s}p-current property name
- add descriptor string handling from platform_data
- fix non-dt handling
--- Documentation/devicetree/bindings/usb/usb251xb.txt | 83 +++ MAINTAINERS | 8 + drivers/usb/misc/Kconfig | 9 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb251xb.c | 771 +++++++++++++++++++++ include/linux/platform_data/usb251xb.h | 33 + 6 files changed, 905 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/usb251xb.txt create mode 100644 drivers/usb/misc/usb251xb.c create mode 100644 include/linux/platform_data/usb251xb.h
Documentation/devicetree/bindings/usb/usb251xb.txt new file +83 -0
@@ -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
@@ -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
@@ -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
@@ -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 +771 -0
771 lines not on this page · raw message
include/linux/platform_data/usb251xb.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef __USB251XB_H__ +#define __USB251XB_H__ + +struct usb251xb_platform_data { +int gpio_reset; +u16 vendor_id; +u16 product_id; +u16 device_id; +u8 conf_data1; +u8 conf_data2; +u8 conf_data3; +u8 non_rem_dev; +u8 port_disable_sp; +u8 port_disable_bp; +u8 max_power_sp; +u8 max_power_bp; +u8 max_current_sp; +u8 max_current_bp; +u8 power_on_time; +u16 lang_id; +char manufacturer[31 ];/* NULL terminated ASCII string */ +char product[31 ];/* NULL terminated ASCII string */ +char serial[31 ];/* NULL terminated ASCII string */ +u8 bat_charge_en; +u8 boost_up; +u8 boost_x; +u8 port_swap; +u8 port_map12; +u8 port_map34; +u8 status; +}; + +#endif
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
Greg KH
maintainerQuoted 22 lines · Richard Leitner
drivers/usb/misc/usb251xb.c new file +22
-0+/** +* 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 +* +* Note: +* The UTF-16LE USB String descriptors can contain at most 31 characters (as +* specified in the datasheet); input strings longer than that are truncated. +* +* Based on ascii2desc from drivers/usb/core/hcd.c +*/ +static unsigned int ascii2utf16le (char const *s,u8 *buf,unsigned int len) +{ +unsigned int n, t =2 *strlen (s); + +if (t >USB251XB_STRING_BUFSIZE ) + t =USB251XB_STRING_BUFSIZE ; +if (len > t) + len = t;
drivers/usb/misc/usb251xb.c line 233
Quoted 10 lines
drivers/usb/misc/usb251xb.c new file +10
-0+ n = len; +while (n--) { + t = (unsigned char )*s++; + *buf++ = t; +if (!n--) +break ; + *buf++ = t >>8 ; + } +return len; +}
Don't we have a kernel function for this already? If we need to export ascii2desc() from the USB core, we can do that, or better yet, move both of them to a string library function in the core part of the kernel. We shouldn't have to duplicate this type of thin in an individual driver.
Quoted 24 lines
include/linux/platform_data/usb251xb.h new file +21
-0@@ -0,0 +1,33 @@ +#ifndef __USB251XB_H__ +#define __USB251XB_H__ + +struct usb251xb_platform_data { + int gpio_reset; + u16 vendor_id; + u16 product_id; + u16 device_id; + u8 conf_data1; + u8 conf_data2; + u8 conf_data3; + u8 non_rem_dev; + u8 port_disable_sp; + u8 port_disable_bp; + u8 max_power_sp; + u8 max_power_bp; + u8 max_current_sp; + u8 max_current_bp; + u8 power_on_time; + u16 lang_id; + char manufacturer[31]; /* NULL terminated ASCII string */
include/linux/platform_data/usb251xb.h line 31
Quoted 10 lines
include/linux/platform_data/usb251xb.h new file +10
-0+char product[31 ];/* NULL terminated ASCII string */ +char serial[31 ];/* NULL terminated ASCII string */ +u8 bat_charge_en; +u8 boost_up; +u8 boost_x; +u8 port_swap; +u8 port_map12; +u8 port_map34; +u8 status; +};
Do you need a platform data structure here? Shouldn't we be only using DT now?
thanks,
greg k-h
Richard Leitner
maintainerQuoted 16 lines · Greg KH
Quoted 6 lines · Richard Leitner
+/**
+ *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.
+ *Quoted 8 lines
+ * Return: The number of bytes filled in: 2*strlen(s) or @len, whichever is less
+ *
+ * Note:
+ * The UTF-16LE USB String descriptors can contain at most 31 characters (as
+ * specified in the datasheet); input strings longer than that are truncated.
+ *
+ * Based on ascii2desc fromdrivers/usb/core/hcd.c
+ */
Quoted 4 lines
Don't we have a kernel function for this already? If we need to export
ascii2desc()from the USB core, we can do that, or better yet, move both of them to a string library function in the core part of the kernel. We shouldn't have to duplicate this type of thin in an individual driver.
Ok. So I'll move the ascii2utf16le function to lib/string.c (?) and call it from ascii2desc in drivers/usb/core/hcd.c (due to the fact ascii2desc also prepends 2 bytes) and the USB251xB driver? Would that be OK?
Quoted 7 lines
include/linux/platform_data/usb251xb.h
Quoted 4 lines
include/linux/platform_data/usb251xb.h new file +0
-0@@ -0,0 +1,33 @@Do you need a platform data structure here? Shouldn't we be only using DT now?
I don't need the platform data support at all. I just added it because it is also available in the USB3503 driver. So if it's OK for you I'd be glad to remove it.
Thank you for your feedback, Greg!
regards,
Richard L
P.S.: A mainline-contribution-beginner question on the process:
Should I send a v3 with those changes applied now or wait for some more feedback?
Greg KH
maintainerQuoted 17 lines · Richard Leitner
Quoted 16 lines · Greg KH
Quoted 14 lines · Richard Leitner
+/**
+ *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
+ *
+ * Note:
+ * The UTF-16LE USB String descriptors can contain at most 31 characters (as
+ * specified in the datasheet); input strings longer than that are truncated.
+ *
+ * Based on ascii2desc fromdrivers/usb/core/hcd.c
+ */
Quoted 8 lines
Quoted 4 lines
Don't we have a kernel function for this already? If we need to export
ascii2desc()from the USB core, we can do that, or better yet, move both of them to a string library function in the core part of the kernel. We shouldn't have to duplicate this type of thin in an individual driver.Ok. So I'll move the ascii2utf16le function to
lib/string.c(?) and call it from ascii2desc indrivers/usb/core/hcd.c(due to the fact ascii2desc also prepends 2 bytes) and the USB251xB driver? Would that be OK?
That sounds good to me.
Quoted 10 lines
Quoted 6 lines
include/linux/platform_data/usb251xb.h
Quoted 3 lines
include/linux/platform_data/usb251xb.h new file +0
-0@@ -0,0 +1,33 @@Do you need a platform data structure here? Shouldn't we be only using DT now?
I don't need the platform data support at all. I just added it because it is also available in the USB3503 driver. So if it's OK for you I'd be glad to remove it.
Great, please remove it! :)
thanks,
greg k-h
--
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