Commit 46dae84a authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by Philipp Zabel
Browse files

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: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
parent 97d85328
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -849,11 +849,11 @@ static void __reset_control_put_internal(struct reset_control *rstc)
	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 of_flags)
{
	const struct fwnode_handle *fwnode = of_fwnode_handle(np);
	unsigned int lookup_flags;
	const char *label_tmp;

@@ -868,10 +868,6 @@ static int __reset_add_reset_gpio_lookup(int id, struct device_node *np,
		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);
	if (!label_tmp)
		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);

	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);

	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;
	}

	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]);
	if (ret < 0)
		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.
	 */
	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,
					     sizeof(rgpio_dev->of_args));
	ret = PTR_ERR_OR_ZERO(pdev);