* [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB [not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.f4f6ec47-9e6b-4978-b229-53520227ed28@emailsignatures365.codetwo.com> @ 2023-05-15 6:25 ` Mike Looijmans [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.10e3aa89-d7f2-4182-9838-42342e94a83d@emailsignatures365.codetwo.com> ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Mike Looijmans @ 2023-05-15 6:25 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> --- Changes in v2: Rename to microchip,usb5807.yaml Remove reset-gpios description Add maxItems Add vddXX-supply properties .../bindings/usb/microchip,usb5807.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/microchip,usb5807.yaml diff --git a/Documentation/devicetree/bindings/usb/microchip,usb5807.yaml b/Documentation/devicetree/bindings/usb/microchip,usb5807.yaml new file mode 100644 index 000000000000..ac5f1a959aae --- /dev/null +++ b/Documentation/devicetree/bindings/usb/microchip,usb5807.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/microchip,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: + maxItems: 1 + + vdd12-supply: + description: core power supply (1.2V) + + vdd33-supply: + description: main power supply (3.3V) + + swap-dx-lanes: + $ref: /schemas/types.yaml#/definitions/uint32-array + maxItems: 8 + 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 [flat|nested] 5+ messages in thread
[parent not found: <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.10e3aa89-d7f2-4182-9838-42342e94a83d@emailsignatures365.codetwo.com>]
* [PATCH v2 2/2] usb: misc: usb5807: Add driver [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.10e3aa89-d7f2-4182-9838-42342e94a83d@emailsignatures365.codetwo.com> @ 2023-05-15 6:25 ` Mike Looijmans 0 siblings, 0 replies; 5+ messages in thread From: Mike Looijmans @ 2023-05-15 6:25 UTC (permalink / raw) To: devicetree, linux-usb Cc: Mike Looijmans, Greg Kroah-Hartman, Jean Delvare, Lukas Bulwahn, Matthias Kaehlcke, Ravi Chandra Sadineni, 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> --- Changes in v2: Add regulator support for vddXX supplies drivers/usb/misc/Kconfig | 9 ++ drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb5807.c | 184 +++++++++++++++++++++++++++++++++++++ 3 files changed, 194 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..c617f3371fa1 --- /dev/null +++ b/drivers/usb/misc/usb5807.c @@ -0,0 +1,184 @@ +// 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> +#include <linux/regulator/consumer.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) +{ + 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"); + } + + /* Enable power supplies while chip is held in reset */ + ret = devm_regulator_get_enable(&i2c->dev, "vdd12"); + if (ret) + return ret; + + ret = devm_regulator_get_enable(&i2c->dev, "vdd33"); + if (ret) + return ret; + + /* 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_new = 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 [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB 2023-05-15 6:25 ` [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB Mike Looijmans [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.10e3aa89-d7f2-4182-9838-42342e94a83d@emailsignatures365.codetwo.com> @ 2023-05-15 10:15 ` Krzysztof Kozlowski 2023-05-15 10:38 ` Krzysztof Kozlowski 2 siblings, 0 replies; 5+ messages in thread From: Krzysztof Kozlowski @ 2023-05-15 10:15 UTC (permalink / raw) To: Mike Looijmans Cc: linux-usb, Greg Kroah-Hartman, Krzysztof Kozlowski, Rob Herring, linux-kernel, devicetree On Mon, 15 May 2023 08:25:01 +0200, 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> > > --- > > Changes in v2: > Rename to microchip,usb5807.yaml > Remove reset-gpios description > Add maxItems > Add vddXX-supply properties > > .../bindings/usb/microchip,usb5807.yaml | 57 +++++++++++++++++++ > 1 file changed, 57 insertions(+) > create mode 100644 Documentation/devicetree/bindings/usb/microchip,usb5807.yaml > My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13): yamllint warnings/errors: dtschema/dtc warnings/errors: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/usb/usb251xb.example.dtb: usb-hub@2d: swap-dx-lanes: size is 32, expected 8 From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/usb/usb251xb.yaml See https://patchwork.ozlabs.org/patch/1781103 This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1. If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date: pip3 install dtschema --upgrade Please check and re-submit. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB 2023-05-15 6:25 ` [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB Mike Looijmans [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.10e3aa89-d7f2-4182-9838-42342e94a83d@emailsignatures365.codetwo.com> 2023-05-15 10:15 ` [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB Krzysztof Kozlowski @ 2023-05-15 10:38 ` Krzysztof Kozlowski 2023-05-15 13:13 ` Mike Looijmans 2 siblings, 1 reply; 5+ messages in thread From: Krzysztof Kozlowski @ 2023-05-15 10:38 UTC (permalink / raw) To: Mike Looijmans, devicetree, linux-usb Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Rob Herring, linux-kernel On 15/05/2023 08:25, Mike Looijmans wrote: > The USB5807 is a 7-port USB 3.1 hub that can be configured by I2C. Thank you for your patch. There is something to discuss/improve. > + > + swap-dx-lanes: > + $ref: /schemas/types.yaml#/definitions/uint32-array > + maxItems: 8 Missing minItems. Bug in the other binding caused this one to be hidden. > + description: > + Specifies the ports which will swap the differential-pair (D+/D-), > + default is not-swapped. Best regards, Krzysztof ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB 2023-05-15 10:38 ` Krzysztof Kozlowski @ 2023-05-15 13:13 ` Mike Looijmans 0 siblings, 0 replies; 5+ messages in thread From: Mike Looijmans @ 2023-05-15 13:13 UTC (permalink / raw) To: Krzysztof Kozlowski, devicetree, linux-usb Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Rob Herring, linux-kernel See below (mailserver has a top-post fetish) 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 15-05-2023 12:38, Krzysztof Kozlowski wrote: > On 15/05/2023 08:25, Mike Looijmans wrote: >> The USB5807 is a 7-port USB 3.1 hub that can be configured by I2C. > > Thank you for your patch. There is something to discuss/improve. > >> + >> + swap-dx-lanes: >> + $ref: /schemas/types.yaml#/definitions/uint32-array >> + maxItems: 8 > Missing minItems. Bug in the other binding caused this one to be hidden. Will add "minItems: 0" in v3... I initially based the code and binding on the usb251xb. Later found the mismatch and fixed it, but somehow forgot that I copied the "int8-array" too. > >> + description: >> + Specifies the ports which will swap the differential-pair (D+/D-), >> + default is not-swapped. > > Best regards, > Krzysztof > -- Mike Looijmans ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-15 13:14 UTC | newest]
Thread overview: 5+ 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.f4f6ec47-9e6b-4978-b229-53520227ed28@emailsignatures365.codetwo.com>
2023-05-15 6:25 ` [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB Mike Looijmans
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.10e3aa89-d7f2-4182-9838-42342e94a83d@emailsignatures365.codetwo.com>
2023-05-15 6:25 ` [PATCH v2 2/2] usb: misc: usb5807: Add driver Mike Looijmans
2023-05-15 10:15 ` [PATCH v2 1/2] dt-bindings: usb: Add microchip USB5807 HUB Krzysztof Kozlowski
2023-05-15 10:38 ` Krzysztof Kozlowski
2023-05-15 13:13 ` Mike Looijmans
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®