* [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver [not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.73717b19-477a-47ab-9efb-48f096304ca8@emailsignatures365.codetwo.com> @ 2023-05-09 7:46 ` Mike Looijmans [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.3007118c-795d-4ecd-9a82-6f1b4cd17152@emailsignatures365.codetwo.com> 2023-05-09 8:02 ` [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver Krzysztof Kozlowski 0 siblings, 2 replies; 4+ messages in thread From: Mike Looijmans @ 2023-05-09 7:46 UTC (permalink / raw) To: devicetree, linux-usb Cc: Mike Looijmans, Greg Kroah-Hartman, Krzysztof Kozlowski, Rob Herring, linux-kernel The USB5807 is a 7-port USB 3.1 hub that can be configured by I2C. This driver resets the chip, optionally allows D+/D- lines to be swapped in the devicetree config, and then sends an ATTACH command to put the device in operational mode. Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl> --- .../devicetree/bindings/usb/usb5807.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/usb5807.yaml diff --git a/Documentation/devicetree/bindings/usb/usb5807.yaml b/Documentation/devicetree/bindings/usb/usb5807.yaml new file mode 100644 index 000000000000..06b94210c281 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usb5807.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/usb5807.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip USB 3.1 SuperSpeed Hub Controller + +maintainers: + - Mike Looijmans <mike.looijmans@topic.nl> + +properties: + compatible: + enum: + - microchip,usb5807 + + reg: + maxItems: 1 + + reset-gpios: + description: | + Should specify the gpio for hub reset + + swap-dx-lanes: + $ref: /schemas/types.yaml#/definitions/uint8-array + description: | + Specifies the ports which will swap the differential-pair (D+/D-), + default is not-swapped. + +additionalProperties: false + +required: + - compatible + - reg + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + usb-hub@2d { + compatible = "microchip,usb5807"; + reg = <0x2d>; + reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>; + /* Swapped D+/D- on port 0 */ + swap-dx-lanes = <0>; + }; + }; -- 2.17.1 Met vriendelijke groet / kind regards, Mike Looijmans System Expert TOPIC Embedded Products B.V. Materiaalweg 4, 5681 RJ Best The Netherlands T: +31 (0) 499 33 69 69 E: mike.looijmans@topicproducts.com W: www.topic.nl Please consider the environment before printing this e-mail ^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.3007118c-795d-4ecd-9a82-6f1b4cd17152@emailsignatures365.codetwo.com>]
* [PATCH 2/2] usb: misc: usb5807: Add driver [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.3007118c-795d-4ecd-9a82-6f1b4cd17152@emailsignatures365.codetwo.com> @ 2023-05-09 7:46 ` Mike Looijmans 0 siblings, 0 replies; 4+ messages in thread From: Mike Looijmans @ 2023-05-09 7:46 UTC (permalink / raw) To: devicetree, linux-usb Cc: Mike Looijmans, Douglas Anderson, Greg Kroah-Hartman, Jean Delvare, Lukas Bulwahn, Matthias Kaehlcke, Uwe Kleine-König, linux-kernel The USB5807 is a 7-port USB 3.1 hub that can be configured by I2C. This drivers resets the chip, optionally allows D+/D- lines to be swapped in the devicetree config, and then sends an ATTACH command to put the device in operational mode. Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl> --- drivers/usb/misc/Kconfig | 9 ++ drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb5807.c | 175 +++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 drivers/usb/misc/usb5807.c diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index 99b15b77dfd5..6659e917ea26 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig @@ -251,6 +251,15 @@ config USB_EZUSB_FX2 Say Y here if you need EZUSB device support. (Cypress FX/FX2/FX2LP microcontrollers) +config USB_HUB_USB5807 + tristate "USB5807 Hub Controller Configuration Driver" + depends on I2C + help + This option enables support for configuration via SMBus of the + Microchip USB5807 USB 3.1 Hub Controller. Configuration parameters may + be set in devicetree. + Say Y or M here if you need to configure such a device via SMBus. + config USB_HUB_USB251XB tristate "USB251XB Hub Controller Configuration Driver" depends on I2C diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile index 1992cc284d8a..e827ed251fa5 100644 --- a/drivers/usb/misc/Makefile +++ b/drivers/usb/misc/Makefile @@ -25,6 +25,7 @@ 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_HUB_USB5807) += usb5807.o obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o obj-$(CONFIG_USB_HSIC_USB4604) += usb4604.o obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o diff --git a/drivers/usb/misc/usb5807.c b/drivers/usb/misc/usb5807.c new file mode 100644 index 000000000000..04080ca81d4d --- /dev/null +++ b/drivers/usb/misc/usb5807.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Driver for Microchip USB5807 USB 3.1 Hub + * Configuration via SMBus. + * + * Copyright (c) 2023 Topic Embedded Products + */ + +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/gpio/consumer.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of_device.h> + +#define USB5807_CMD_ATTACH 0xAA55 +#define USB5807_CMD_CONFIG 0x9937 + +#define USB5807_REG_LANE_SWAP 0x30FA + +#define USB5807_NUM_PORTS 7 + + +static int usb5807_write(struct i2c_client *i2c, void *buf, u8 len) +{ + int ret; + struct i2c_msg msg = { + .addr = i2c->addr, + .flags = 0x0, + .len = len, + .buf = buf, + }; + + ret = i2c_transfer(i2c->adapter, &msg, 1); + return ret < 0 ? ret : 0; +} + +/* + * Send a command sequence, which is an I2C write transaction, with the command + * word in big endian and a terminating "0" byte. + */ +static int usb5807_command(struct i2c_client *i2c, u16 cmd) +{ + u8 buf[3] = {cmd >> 8, cmd & 0xff, 0}; + + return usb5807_write(i2c, buf, sizeof(buf)); +} + +static int usb5807_prepare_reg_u8(struct i2c_client *i2c, u16 reg, u8 value) +{ + u8 buf[] = { + 0x00, + 0x00, /* Memory offset */ + 1 + 4, /* Transaction size */ + 0x00, /* 0 = Register write operation */ + 1, /* Size of register data */ + (reg >> 8) & 0xff, + reg & 0xff, /* Register offset */ + value, /* Register data */ + 0 /* Terminating zero */ + }; + + return usb5807_write(i2c, buf, sizeof(buf)); +} + +/* + * Write an 8-bit register. First we must write the "set register" operation to + * the chip's internal memory at offset 0, then issue a command to execute said + * operation. + */ +static int usb5807_write_reg_u8(struct i2c_client *i2c, u16 reg, u8 value) +{ + int ret; + + ret = usb5807_prepare_reg_u8(i2c, reg, value); + if (ret) + return ret; + + return usb5807_command(i2c, USB5807_CMD_CONFIG); +} + +/* Decode array of port numbers property into bit mask */ +static u8 usb5807_get_ports_field(struct device *dev, const char *prop_name) +{ + struct property *prop; + const __be32 *p; + u32 port; + u8 result = 0; + + of_property_for_each_u32(dev->of_node, prop_name, prop, p, port) { + if (port < USB5807_NUM_PORTS) + result |= BIT(port); + else + dev_warn(dev, "%s: port %u doesn't exist\n", prop_name, + port); + } + return result; +} + +static int usb5807_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct device_node *np = i2c->dev.of_node; + struct gpio_desc *reset_gpio; + int ret; + u8 val; + + /* Reset the chip to bring it into configuration mode */ + reset_gpio = devm_gpiod_get_optional(&i2c->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(reset_gpio)) { + return dev_err_probe(&i2c->dev, PTR_ERR(reset_gpio), + "Failed to request reset GPIO\n"); + } + /* Reset timing: Assert for >= 5 us */ + usleep_range(5, 10); + + /* Lock the bus for >= 1ms while the hub reads the I2C strapping */ + i2c_lock_bus(i2c->adapter, I2C_LOCK_SEGMENT); + + gpiod_set_value_cansleep(reset_gpio, 0); + usleep_range(1000, 2000); + + i2c_unlock_bus(i2c->adapter, I2C_LOCK_SEGMENT); + + /* The hub device needs additional time to boot up */ + msleep(20); + + val = usb5807_get_ports_field(&i2c->dev, "swap-dx-lanes"); + if (val) { + ret = usb5807_write_reg_u8(i2c, USB5807_REG_LANE_SWAP, val); + if (ret < 0) + dev_err(&i2c->dev, "Failed writing config: %d\n", ret); + } + + /* + * Send the "Attach" command which makes the device disappear from the + * I2C bus and starts USB enumeration. + */ + ret = usb5807_command(i2c, USB5807_CMD_ATTACH); + if (ret) { + dev_err(&i2c->dev, "Failed sending ATTACH command: %d\n", ret); + return ret; + } + + return 0; +} + +static const struct of_device_id usb5807_of_match[] = { + { .compatible = "microchip,usb5807" }, + { } /* sentinel */ +}; +MODULE_DEVICE_TABLE(of, usb5807_of_match); + +static const struct i2c_device_id usb5807_id[] = { + { "usb5807", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, usb5807_id); + +static struct i2c_driver usb5807_i2c_driver = { + .driver = { + .name = "usb5807", + .of_match_table = of_match_ptr(usb5807_of_match), + }, + .probe = usb5807_i2c_probe, + .id_table = usb5807_id, +}; + +module_i2c_driver(usb5807_i2c_driver); + +MODULE_AUTHOR("Mike Looijmans <mike.looijmans@topic.nl>"); +MODULE_DESCRIPTION("USB5807 USB 3.1 Hub Controller Driver"); +MODULE_LICENSE("GPL"); -- 2.17.1 Met vriendelijke groet / kind regards, Mike Looijmans System Expert TOPIC Embedded Products B.V. Materiaalweg 4, 5681 RJ Best The Netherlands T: +31 (0) 499 33 69 69 E: mike.looijmans@topicproducts.com W: www.topic.nl Please consider the environment before printing this e-mail ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver 2023-05-09 7:46 ` [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver Mike Looijmans [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.3007118c-795d-4ecd-9a82-6f1b4cd17152@emailsignatures365.codetwo.com> @ 2023-05-09 8:02 ` Krzysztof Kozlowski 2023-05-10 15:04 ` Mike Looijmans 1 sibling, 1 reply; 4+ messages in thread From: Krzysztof Kozlowski @ 2023-05-09 8:02 UTC (permalink / raw) To: Mike Looijmans, devicetree, linux-usb Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Rob Herring, linux-kernel On 09/05/2023 09:46, Mike Looijmans wrote: > The USB5807 is a 7-port USB 3.1 hub that can be configured by I2C. > This driver resets the chip, optionally allows D+/D- lines to be > swapped in the devicetree config, and then sends an ATTACH command to > put the device in operational mode. > > Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl> > Subject: drop misc prefix. Subject: drop "driver", you are not adding driver here. > --- > > .../devicetree/bindings/usb/usb5807.yaml | 51 +++++++++++++++++++ > 1 file changed, 51 insertions(+) > create mode 100644 Documentation/devicetree/bindings/usb/usb5807.yaml > > diff --git a/Documentation/devicetree/bindings/usb/usb5807.yaml b/Documentation/devicetree/bindings/usb/usb5807.yaml > new file mode 100644 > index 000000000000..06b94210c281 > --- /dev/null > +++ b/Documentation/devicetree/bindings/usb/usb5807.yaml Filename like compatible. > @@ -0,0 +1,51 @@ > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/usb/usb5807.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: Microchip USB 3.1 SuperSpeed Hub Controller > + > +maintainers: > + - Mike Looijmans <mike.looijmans@topic.nl> > + > +properties: > + compatible: > + enum: > + - microchip,usb5807 > + > + reg: > + maxItems: 1 > + > + reset-gpios: > + description: | > + Should specify the gpio for hub reset Drop description, obvious. maxItems instead. If you decide to add description, then keep it useful, e.g. mention active low. > + > + swap-dx-lanes: > + $ref: /schemas/types.yaml#/definitions/uint8-array > + description: | Do not need '|' unless you need to preserve formatting. > + Specifies the ports which will swap the differential-pair (D+/D-), > + default is not-swapped. maxItems (and minItems if it differs) No supply? How does the hub gets power? I see at least two supplies in datasheet. > + > +additionalProperties: false > + > +required: > + - compatible > + - reg Best regards, Krzysztof ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver 2023-05-09 8:02 ` [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver Krzysztof Kozlowski @ 2023-05-10 15:04 ` Mike Looijmans 0 siblings, 0 replies; 4+ messages in thread From: Mike Looijmans @ 2023-05-10 15:04 UTC (permalink / raw) To: Krzysztof Kozlowski, devicetree, linux-usb Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Rob Herring, linux-kernel I'll fix the issues and send a v2. I'll add supply/regulators as well. Will take a few days though. Thanks for the quick feedback, much appreciated. -- Met vriendelijke groet / kind regards, Mike Looijmans System Expert TOPIC Embedded Products B.V. Materiaalweg 4, 5681 RJ Best The Netherlands T: +31 (0) 499 33 69 69 E: mike.looijmans@topicproducts.com W: www.topic.nl Please consider the environment before printing this e-mail On 09-05-2023 10:02, Krzysztof Kozlowski wrote: > On 09/05/2023 09:46, Mike Looijmans wrote: >> The USB5807 is a 7-port USB 3.1 hub that can be configured by I2C. >> This driver resets the chip, optionally allows D+/D- lines to be >> swapped in the devicetree config, and then sends an ATTACH command to >> put the device in operational mode. >> >> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl> >> > Subject: drop misc prefix. > Subject: drop "driver", you are not adding driver here. > >> --- >> >> .../devicetree/bindings/usb/usb5807.yaml | 51 +++++++++++++++++++ >> 1 file changed, 51 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/usb/usb5807.yaml >> >> diff --git a/Documentation/devicetree/bindings/usb/usb5807.yaml b/Documentation/devicetree/bindings/usb/usb5807.yaml >> new file mode 100644 >> index 000000000000..06b94210c281 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/usb/usb5807.yaml > Filename like compatible. > >> @@ -0,0 +1,51 @@ >> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) >> +%YAML 1.2 >> +--- >> +$id: http://devicetree.org/schemas/usb/usb5807.yaml# >> +$schema: http://devicetree.org/meta-schemas/core.yaml# >> + >> +title: Microchip USB 3.1 SuperSpeed Hub Controller >> + >> +maintainers: >> + - Mike Looijmans <mike.looijmans@topic.nl> >> + >> +properties: >> + compatible: >> + enum: >> + - microchip,usb5807 >> + >> + reg: >> + maxItems: 1 >> + >> + reset-gpios: >> + description: | >> + Should specify the gpio for hub reset > Drop description, obvious. maxItems instead. If you decide to add > description, then keep it useful, e.g. mention active low. > > >> + >> + swap-dx-lanes: >> + $ref: /schemas/types.yaml#/definitions/uint8-array >> + description: | > Do not need '|' unless you need to preserve formatting. > >> + Specifies the ports which will swap the differential-pair (D+/D-), >> + default is not-swapped. > maxItems (and minItems if it differs) > > No supply? How does the hub gets power? I see at least two supplies in > datasheet. > >> + >> +additionalProperties: false >> + >> +required: >> + - compatible >> + - reg > Best regards, > Krzysztof > -- Mike Looijmans ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-10 15:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.73717b19-477a-47ab-9efb-48f096304ca8@emailsignatures365.codetwo.com>
2023-05-09 7:46 ` [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver Mike Looijmans
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.3007118c-795d-4ecd-9a82-6f1b4cd17152@emailsignatures365.codetwo.com>
2023-05-09 7:46 ` [PATCH 2/2] usb: misc: usb5807: Add driver Mike Looijmans
2023-05-09 8:02 ` [PATCH 1/2] dt-bindings: usb: misc: Add microchip USB5807 HUB driver Krzysztof Kozlowski
2023-05-10 15:04 ` Mike Looijmans
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).