* [PATCH 0/2] usb: usb251xb: support usage case without I2C control @ 2025-08-15 2:55 Jisheng Zhang 2025-08-15 2:55 ` [PATCH 1/2] dt-bindings: usb: usb251xb: make reg optional for no I2C ctrl use case Jisheng Zhang 2025-08-15 2:55 ` [PATCH 2/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang 0 siblings, 2 replies; 4+ messages in thread From: Jisheng Zhang @ 2025-08-15 2:55 UTC (permalink / raw) To: Richard Leitner, Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-usb, devicetree, linux-kernel Refactor so that register writes for configuration are only performed if the device has a i2c_client provided and also register as a platform driver. This allows the driver to be used to manage GPIO based control of the device. Jisheng Zhang (2): dt-bindings: usb: usb251xb: make reg optional for no I2C ctrl use case usb: usb251xb: support usage case without I2C control .../devicetree/bindings/usb/usb251xb.yaml | 1 - drivers/usb/misc/usb251xb.c | 108 +++++++++++++++--- 2 files changed, 94 insertions(+), 15 deletions(-) -- 2.50.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] dt-bindings: usb: usb251xb: make reg optional for no I2C ctrl use case 2025-08-15 2:55 [PATCH 0/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang @ 2025-08-15 2:55 ` Jisheng Zhang 2025-08-15 2:55 ` [PATCH 2/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang 1 sibling, 0 replies; 4+ messages in thread From: Jisheng Zhang @ 2025-08-15 2:55 UTC (permalink / raw) To: Richard Leitner, Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-usb, devicetree, linux-kernel Make "reg" optional to allow the driver to be used to manage GPIO based control of the device. Signed-off-by: Jisheng Zhang <jszhang@kernel.org> --- Documentation/devicetree/bindings/usb/usb251xb.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/usb/usb251xb.yaml b/Documentation/devicetree/bindings/usb/usb251xb.yaml index ac5b99710332..4b676c010f3e 100644 --- a/Documentation/devicetree/bindings/usb/usb251xb.yaml +++ b/Documentation/devicetree/bindings/usb/usb251xb.yaml @@ -240,7 +240,6 @@ additionalProperties: false required: - compatible - - reg examples: - | -- 2.50.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] usb: usb251xb: support usage case without I2C control 2025-08-15 2:55 [PATCH 0/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang 2025-08-15 2:55 ` [PATCH 1/2] dt-bindings: usb: usb251xb: make reg optional for no I2C ctrl use case Jisheng Zhang @ 2025-08-15 2:55 ` Jisheng Zhang 2025-08-15 3:31 ` Jisheng Zhang 1 sibling, 1 reply; 4+ messages in thread From: Jisheng Zhang @ 2025-08-15 2:55 UTC (permalink / raw) To: Richard Leitner, Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-usb, devicetree, linux-kernel Refactor so that register writes for configuration are only performed if the device has a i2c_client provided and also register as a platform driver. This allows the driver to be used to manage GPIO based control of the device. Signed-off-by: Jisheng Zhang <jszhang@kernel.org> --- drivers/usb/misc/usb251xb.c | 108 +++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c index 4fb453ca5450..ef5873009599 100644 --- a/drivers/usb/misc/usb251xb.c +++ b/drivers/usb/misc/usb251xb.c @@ -17,6 +17,7 @@ #include <linux/module.h> #include <linux/nls.h> #include <linux/of.h> +#include <linux/platform_device.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> @@ -242,15 +243,19 @@ static int usb251xb_check_dev_children(struct device *dev, void *child) static int usb251x_check_gpio_chip(struct usb251xb *hub) { struct gpio_chip *gc = gpiod_to_chip(hub->gpio_reset); - struct i2c_adapter *adap = hub->i2c->adapter; + struct i2c_adapter *adap; int ret; + if (!hub->i2c) + return 0; + if (!hub->gpio_reset) return 0; if (!gc) return -EINVAL; + adap = hub->i2c->adapter; ret = usb251xb_check_dev_children(&adap->dev, gc->parent); if (ret) { dev_err(hub->dev, "Reset GPIO chip is at the same i2c-bus\n"); @@ -271,7 +276,8 @@ static void usb251xb_reset(struct usb251xb *hub) if (!hub->gpio_reset) return; - i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); + if (hub->i2c) + i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); gpiod_set_value_cansleep(hub->gpio_reset, 1); usleep_range(1, 10); /* >=1us RESET_N asserted */ @@ -280,7 +286,8 @@ static void usb251xb_reset(struct usb251xb *hub) /* wait for hub recovery/stabilization */ usleep_range(500, 750); /* >=500us after RESET_N deasserted */ - i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); + if (hub->i2c) + i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); } static int usb251xb_connect(struct usb251xb *hub) @@ -289,7 +296,11 @@ static int usb251xb_connect(struct usb251xb *hub) int err, i; char i2c_wb[USB251XB_I2C_REG_SZ]; - memset(i2c_wb, 0, USB251XB_I2C_REG_SZ); + if (!hub->i2c) { + usb251xb_reset(hub); + dev_info(dev, "hub is put in default configuration.\n"); + return 0; + } if (hub->skip_config) { dev_info(dev, "Skip hub configuration, only attach.\n"); @@ -698,18 +709,13 @@ static int usb251xb_i2c_probe(struct i2c_client *i2c) return usb251xb_probe(hub); } -static int __maybe_unused usb251xb_suspend(struct device *dev) +static int usb251xb_suspend(struct usb251xb *hub) { - struct i2c_client *client = to_i2c_client(dev); - struct usb251xb *hub = i2c_get_clientdata(client); - return regulator_disable(hub->vdd); } -static int __maybe_unused usb251xb_resume(struct device *dev) +static int usb251xb_resume(struct usb251xb *hub) { - struct i2c_client *client = to_i2c_client(dev); - struct usb251xb *hub = i2c_get_clientdata(client); int err; err = regulator_enable(hub->vdd); @@ -719,7 +725,23 @@ static int __maybe_unused usb251xb_resume(struct device *dev) return usb251xb_connect(hub); } -static SIMPLE_DEV_PM_OPS(usb251xb_pm_ops, usb251xb_suspend, usb251xb_resume); +static int usb251xb_i2c_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct usb251xb *hub = i2c_get_clientdata(client); + + return usb251xb_suspend(hub); +} + +static int usb251xb_i2c_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct usb251xb *hub = i2c_get_clientdata(client); + + return usb251xb_resume(hub); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_i2c_pm_ops, usb251xb_i2c_suspend, usb251xb_i2c_resume); static const struct i2c_device_id usb251xb_id[] = { { "usb2422" }, @@ -739,13 +761,71 @@ static struct i2c_driver usb251xb_i2c_driver = { .driver = { .name = DRIVER_NAME, .of_match_table = usb251xb_of_match, - .pm = &usb251xb_pm_ops, + .pm = pm_sleep_ptr(&usb251xb_i2c_pm_ops), }, .probe = usb251xb_i2c_probe, .id_table = usb251xb_id, }; -module_i2c_driver(usb251xb_i2c_driver); +static int usb251xb_plat_probe(struct platform_device *pdev) +{ + struct usb251xb *hub; + + hub = devm_kzalloc(&pdev->dev, sizeof(*hub), GFP_KERNEL); + if (!hub) + return -ENOMEM; + + platform_set_drvdata(pdev, hub); + hub->dev = &pdev->dev; + + return usb251xb_probe(hub); +} + +static int usb251xb_plat_suspend(struct device *dev) +{ + return usb251xb_suspend(dev_get_drvdata(dev)); +} + +static int usb251xb_plat_resume(struct device *dev) +{ + return usb251xb_resume(dev_get_drvdata(dev)); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_plat_pm_ops, usb251xb_plat_suspend, usb251xb_plat_resume); + +static struct platform_driver usb251xb_plat_driver = { + .driver = { + .name = DRIVER_NAME, + .of_match_table = of_match_ptr(usb251xb_of_match), + .pm = pm_ptr(&usb251xb_plat_pm_ops), + }, + .probe = usb251xb_plat_probe, +}; + +static int __init usb251xb_init(void) +{ + int err; + + err = i2c_add_driver(&usb251xb_i2c_driver); + if (err) + return err; + + err = platform_driver_register(&usb251xb_plat_driver); + if (err) { + i2c_del_driver(&usb251xb_i2c_driver); + return err; + } + + return 0; +} +module_init(usb251xb_init); + +static void __exit usb251xb_exit(void) +{ + platform_driver_unregister(&usb251xb_plat_driver); + i2c_del_driver(&usb251xb_i2c_driver); +} +module_exit(usb251xb_exit); MODULE_AUTHOR("Richard Leitner <richard.leitner@skidata.com>"); MODULE_DESCRIPTION("USB251x/xBi USB 2.0 Hub Controller Driver"); -- 2.50.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] usb: usb251xb: support usage case without I2C control 2025-08-15 2:55 ` [PATCH 2/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang @ 2025-08-15 3:31 ` Jisheng Zhang 0 siblings, 0 replies; 4+ messages in thread From: Jisheng Zhang @ 2025-08-15 3:31 UTC (permalink / raw) To: Richard Leitner, Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: linux-usb, devicetree, linux-kernel On Fri, Aug 15, 2025 at 10:55:40AM +0800, Jisheng Zhang wrote: > Refactor so that register writes for configuration are only performed if > the device has a i2c_client provided and also register as a platform > driver. This allows the driver to be used to manage GPIO based control > of the device. > > Signed-off-by: Jisheng Zhang <jszhang@kernel.org> > --- > drivers/usb/misc/usb251xb.c | 108 +++++++++++++++++++++++++++++++----- > 1 file changed, 94 insertions(+), 14 deletions(-) > > diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c > index 4fb453ca5450..ef5873009599 100644 > --- a/drivers/usb/misc/usb251xb.c > +++ b/drivers/usb/misc/usb251xb.c > @@ -17,6 +17,7 @@ > #include <linux/module.h> > #include <linux/nls.h> > #include <linux/of.h> > +#include <linux/platform_device.h> > #include <linux/regulator/consumer.h> > #include <linux/slab.h> > > @@ -242,15 +243,19 @@ static int usb251xb_check_dev_children(struct device *dev, void *child) > static int usb251x_check_gpio_chip(struct usb251xb *hub) > { > struct gpio_chip *gc = gpiod_to_chip(hub->gpio_reset); > - struct i2c_adapter *adap = hub->i2c->adapter; > + struct i2c_adapter *adap; > int ret; > > + if (!hub->i2c) > + return 0; > + > if (!hub->gpio_reset) > return 0; > > if (!gc) > return -EINVAL; > > + adap = hub->i2c->adapter; > ret = usb251xb_check_dev_children(&adap->dev, gc->parent); > if (ret) { > dev_err(hub->dev, "Reset GPIO chip is at the same i2c-bus\n"); > @@ -271,7 +276,8 @@ static void usb251xb_reset(struct usb251xb *hub) > if (!hub->gpio_reset) > return; > > - i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); > + if (hub->i2c) > + i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); > > gpiod_set_value_cansleep(hub->gpio_reset, 1); > usleep_range(1, 10); /* >=1us RESET_N asserted */ > @@ -280,7 +286,8 @@ static void usb251xb_reset(struct usb251xb *hub) > /* wait for hub recovery/stabilization */ > usleep_range(500, 750); /* >=500us after RESET_N deasserted */ > > - i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); > + if (hub->i2c) > + i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); > } > > static int usb251xb_connect(struct usb251xb *hub) > @@ -289,7 +296,11 @@ static int usb251xb_connect(struct usb251xb *hub) > int err, i; > char i2c_wb[USB251XB_I2C_REG_SZ]; > > - memset(i2c_wb, 0, USB251XB_I2C_REG_SZ); > + if (!hub->i2c) { > + usb251xb_reset(hub); > + dev_info(dev, "hub is put in default configuration.\n"); > + return 0; > + } > > if (hub->skip_config) { > dev_info(dev, "Skip hub configuration, only attach.\n"); > @@ -698,18 +709,13 @@ static int usb251xb_i2c_probe(struct i2c_client *i2c) > return usb251xb_probe(hub); > } > > -static int __maybe_unused usb251xb_suspend(struct device *dev) > +static int usb251xb_suspend(struct usb251xb *hub) > { > - struct i2c_client *client = to_i2c_client(dev); > - struct usb251xb *hub = i2c_get_clientdata(client); > - > return regulator_disable(hub->vdd); > } > > -static int __maybe_unused usb251xb_resume(struct device *dev) > +static int usb251xb_resume(struct usb251xb *hub) > { > - struct i2c_client *client = to_i2c_client(dev); > - struct usb251xb *hub = i2c_get_clientdata(client); > int err; > > err = regulator_enable(hub->vdd); > @@ -719,7 +725,23 @@ static int __maybe_unused usb251xb_resume(struct device *dev) > return usb251xb_connect(hub); > } > > -static SIMPLE_DEV_PM_OPS(usb251xb_pm_ops, usb251xb_suspend, usb251xb_resume); > +static int usb251xb_i2c_suspend(struct device *dev) > +{ > + struct i2c_client *client = to_i2c_client(dev); > + struct usb251xb *hub = i2c_get_clientdata(client); > + > + return usb251xb_suspend(hub); > +} > + > +static int usb251xb_i2c_resume(struct device *dev) > +{ > + struct i2c_client *client = to_i2c_client(dev); > + struct usb251xb *hub = i2c_get_clientdata(client); > + > + return usb251xb_resume(hub); > +} > + > +static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_i2c_pm_ops, usb251xb_i2c_suspend, usb251xb_i2c_resume); It seems this PM macros usage should be in a seperate patch. I will send a v2 this night. > > static const struct i2c_device_id usb251xb_id[] = { > { "usb2422" }, > @@ -739,13 +761,71 @@ static struct i2c_driver usb251xb_i2c_driver = { > .driver = { > .name = DRIVER_NAME, > .of_match_table = usb251xb_of_match, > - .pm = &usb251xb_pm_ops, > + .pm = pm_sleep_ptr(&usb251xb_i2c_pm_ops), > }, > .probe = usb251xb_i2c_probe, > .id_table = usb251xb_id, > }; > > -module_i2c_driver(usb251xb_i2c_driver); > +static int usb251xb_plat_probe(struct platform_device *pdev) > +{ > + struct usb251xb *hub; > + > + hub = devm_kzalloc(&pdev->dev, sizeof(*hub), GFP_KERNEL); > + if (!hub) > + return -ENOMEM; > + > + platform_set_drvdata(pdev, hub); > + hub->dev = &pdev->dev; > + > + return usb251xb_probe(hub); > +} > + > +static int usb251xb_plat_suspend(struct device *dev) > +{ > + return usb251xb_suspend(dev_get_drvdata(dev)); > +} > + > +static int usb251xb_plat_resume(struct device *dev) > +{ > + return usb251xb_resume(dev_get_drvdata(dev)); > +} > + > +static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_plat_pm_ops, usb251xb_plat_suspend, usb251xb_plat_resume); > + > +static struct platform_driver usb251xb_plat_driver = { > + .driver = { > + .name = DRIVER_NAME, > + .of_match_table = of_match_ptr(usb251xb_of_match), > + .pm = pm_ptr(&usb251xb_plat_pm_ops), > + }, > + .probe = usb251xb_plat_probe, > +}; > + > +static int __init usb251xb_init(void) > +{ > + int err; > + > + err = i2c_add_driver(&usb251xb_i2c_driver); > + if (err) > + return err; > + > + err = platform_driver_register(&usb251xb_plat_driver); > + if (err) { > + i2c_del_driver(&usb251xb_i2c_driver); > + return err; > + } > + > + return 0; > +} > +module_init(usb251xb_init); > + > +static void __exit usb251xb_exit(void) > +{ > + platform_driver_unregister(&usb251xb_plat_driver); > + i2c_del_driver(&usb251xb_i2c_driver); > +} > +module_exit(usb251xb_exit); > > MODULE_AUTHOR("Richard Leitner <richard.leitner@skidata.com>"); > MODULE_DESCRIPTION("USB251x/xBi USB 2.0 Hub Controller Driver"); > -- > 2.50.0 > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-15 3:48 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-15 2:55 [PATCH 0/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang 2025-08-15 2:55 ` [PATCH 1/2] dt-bindings: usb: usb251xb: make reg optional for no I2C ctrl use case Jisheng Zhang 2025-08-15 2:55 ` [PATCH 2/2] usb: usb251xb: support usage case without I2C control Jisheng Zhang 2025-08-15 3:31 ` Jisheng Zhang
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).