reset: make the provider of reset-gpios the parent of the reset device

Auxiliary devices really do need a parent so ahead of converting the
reset-gpios driver to registering on the auxiliary bus, make the GPIO
device that provides the reset GPIO the parent of the reset-gpio device.
To that end move the lookup of the GPIO device by fwnode to the
beginning of __reset_add_reset_gpio_device() which has the added benefit
of bailing out earlier, before allocating resources for the virtual
device, if the chip is not up yet.

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
Bartosz Golaszewski 2025-11-20 14:24:02 +01:00 committed by Philipp Zabel
parent 97d85328e3
commit 46dae84a90
1 changed files with 10 additions and 8 deletions

View File

@ -849,11 +849,11 @@ static void __reset_control_put_internal(struct reset_control *rstc)
kref_put(&rstc->refcnt, __reset_control_release); kref_put(&rstc->refcnt, __reset_control_release);
} }
static int __reset_add_reset_gpio_lookup(int id, struct device_node *np, static int __reset_add_reset_gpio_lookup(struct gpio_device *gdev, int id,
struct device_node *np,
unsigned int gpio, unsigned int gpio,
unsigned int of_flags) unsigned int of_flags)
{ {
const struct fwnode_handle *fwnode = of_fwnode_handle(np);
unsigned int lookup_flags; unsigned int lookup_flags;
const char *label_tmp; const char *label_tmp;
@ -868,10 +868,6 @@ static int __reset_add_reset_gpio_lookup(int id, struct device_node *np,
return -EINVAL; return -EINVAL;
} }
struct gpio_device *gdev __free(gpio_device_put) = gpio_device_find_by_fwnode(fwnode);
if (!gdev)
return -EPROBE_DEFER;
label_tmp = gpio_device_get_label(gdev); label_tmp = gpio_device_get_label(gdev);
if (!label_tmp) if (!label_tmp)
return -EINVAL; return -EINVAL;
@ -926,6 +922,11 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
*/ */
lockdep_assert_not_held(&reset_list_mutex); lockdep_assert_not_held(&reset_list_mutex);
struct gpio_device *gdev __free(gpio_device_put) =
gpio_device_find_by_fwnode(of_fwnode_handle(args->np));
if (!gdev)
return -EPROBE_DEFER;
guard(mutex)(&reset_gpio_lookup_mutex); guard(mutex)(&reset_gpio_lookup_mutex);
list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) {
@ -946,7 +947,7 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
goto err_ida_free; goto err_ida_free;
} }
ret = __reset_add_reset_gpio_lookup(id, args->np, args->args[0], ret = __reset_add_reset_gpio_lookup(gdev, id, args->np, args->args[0],
args->args[1]); args->args[1]);
if (ret < 0) if (ret < 0)
goto err_kfree; goto err_kfree;
@ -958,7 +959,8 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
* Hold reference as long as rgpio_dev memory is valid. * Hold reference as long as rgpio_dev memory is valid.
*/ */
of_node_get(rgpio_dev->of_args.np); of_node_get(rgpio_dev->of_args.np);
pdev = platform_device_register_data(NULL, "reset-gpio", id, pdev = platform_device_register_data(gpio_device_to_device(gdev),
"reset-gpio", id,
&rgpio_dev->of_args, &rgpio_dev->of_args,
sizeof(rgpio_dev->of_args)); sizeof(rgpio_dev->of_args));
ret = PTR_ERR_OR_ZERO(pdev); ret = PTR_ERR_OR_ZERO(pdev);