Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: nomadik: grab optional reset control and deassert it at probe

Fetch a reference to the optional shared reset control and deassert it
if it exists.

Optional because not all platforms that use this driver have a reset
attached to the reset block. Shared because some platforms that use the
reset (at least Mobileye EyeQ5) share the reset across banks.

Do not keep a reference to the reset control as it is not needed
afterwards; the driver does not handle suspend, does not use runtime
PM, does not register a remove callback and does not support unbinding
from sysfs (made explicit with suppress_bind_attrs).

The operation is done in nmk_gpio_populate_chip(). This function is
called by either gpio-nomadik or pinctrl-nomadik, whoever comes first.
This is here for historic reasons and could probably be removed now; it
seems gpio-ranges enforces the ordering to be pinctrl-first. It is not
the topic of the present patch however.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-25-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Théo Lebrun and committed by
Linus Walleij
6ad679cf 3c30cc26

+21
+21
drivers/gpio/gpio-nomadik.c
··· 509 509 { 510 510 struct nmk_gpio_chip *nmk_chip; 511 511 struct platform_device *gpio_pdev; 512 + struct reset_control *reset; 512 513 struct device *gpio_dev; 513 514 struct gpio_chip *chip; 514 515 struct clk *clk; 515 516 void __iomem *base; 516 517 u32 id, ngpio; 518 + int ret; 517 519 518 520 gpio_dev = bus_find_device_by_of_node(&platform_bus_type, np); 519 521 if (!gpio_dev) { ··· 573 571 } 574 572 clk_prepare(clk); 575 573 nmk_chip->clk = clk; 574 + 575 + reset = devm_reset_control_get_optional_shared(gpio_dev, NULL); 576 + if (IS_ERR(reset)) { 577 + dev_err(&pdev->dev, "failed getting reset control: %ld\n", 578 + PTR_ERR(reset)); 579 + return ERR_CAST(reset); 580 + } 581 + 582 + /* 583 + * Reset might be shared and asserts/deasserts calls are unbalanced. We 584 + * only support sharing this reset with other gpio-nomadik devices that 585 + * use this reset to ensure deassertion at probe. 586 + */ 587 + ret = reset_control_deassert(reset); 588 + if (ret) { 589 + dev_err(&pdev->dev, "failed reset deassert: %d\n", ret); 590 + return ERR_PTR(ret); 591 + } 576 592 577 593 #ifdef CONFIG_PINCTRL_NOMADIK 578 594 BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips)); ··· 710 690 .driver = { 711 691 .name = "nomadik-gpio", 712 692 .of_match_table = nmk_gpio_match, 693 + .suppress_bind_attrs = true, 713 694 }, 714 695 .probe = nmk_gpio_probe, 715 696 };