Re: [RFC] driver core: add a virtual bus for use when a simple device/bus is needed
From: Greg Kroah-Hartman
Date: Mon Feb 03 2025 - 05:03:41 EST
On Mon, Feb 03, 2025 at 10:39:58AM +0100, Greg Kroah-Hartman wrote:
> --- a/drivers/regulator/dummy.c
> +++ b/drivers/regulator/dummy.c
> @@ -13,7 +13,7 @@
>
> #include <linux/err.h>
> #include <linux/export.h>
> -#include <linux/platform_device.h>
> +#include <linux/device/virtual.h>
> #include <linux/regulator/driver.h>
> #include <linux/regulator/machine.h>
>
> @@ -37,15 +37,15 @@ static const struct regulator_desc dummy_desc = {
> .ops = &dummy_ops,
> };
>
> -static int dummy_regulator_probe(struct platform_device *pdev)
> +static int dummy_regulator_probe(struct virtual_device *vdev)
> {
> struct regulator_config config = { };
> int ret;
>
> - config.dev = &pdev->dev;
> + config.dev = &vdev->dev;
> config.init_data = &dummy_initdata;
>
> - dummy_regulator_rdev = devm_regulator_register(&pdev->dev, &dummy_desc,
> + dummy_regulator_rdev = devm_regulator_register(&vdev->dev, &dummy_desc,
> &config);
> if (IS_ERR(dummy_regulator_rdev)) {
> ret = PTR_ERR(dummy_regulator_rdev);
> @@ -56,36 +56,17 @@ static int dummy_regulator_probe(struct platform_device *pdev)
> return 0;
> }
>
> -static struct platform_driver dummy_regulator_driver = {
> +struct virtual_driver_ops dummy_regulator_driver = {
> .probe = dummy_regulator_probe,
> - .driver = {
> - .name = "reg-dummy",
> - .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> - },
> };
>
> -static struct platform_device *dummy_pdev;
> +static struct virtual_device *dummy_vdev;
>
> void __init regulator_dummy_init(void)
> {
> - int ret;
> -
> - dummy_pdev = platform_device_alloc("reg-dummy", -1);
> - if (!dummy_pdev) {
> + dummy_vdev = virtual_device_create(&dummy_regulator_driver, "reg-dummy");
> + if (!dummy_vdev) {
I originally was thinking that many platform_device_alloc() calls could
be replaced with this, but in looking further, I think we can get rid of
almost all calls to platform_device_register_simple() with this api
instead, including most of the use of that in the drm tree where all
that is being used is the device structure and not the platform one at
all.
I'll dig into that later today...
thanks,
greg k-h