Re: [PATCH 2/3] PCI: brcmstb: Add regulator support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 2/12/2020 6:59 PM, Jaedon Shin wrote:
> ARM-based Broadcom STB SoCs have GPIO-based voltage regulator for PCIe
> turning off/on power supplies.
> 
> Signed-off-by: Jaedon Shin <jaedon.shin@xxxxxxxxx>
> ---
>  drivers/gpio/gpio-brcmstb.c           | 13 ++++-
>  drivers/pci/controller/pcie-brcmstb.c | 76 +++++++++++++++++++++++++++
>  2 files changed, 88 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c
> index 05e3f99ae59c..0cee5fcd2782 100644
> --- a/drivers/gpio/gpio-brcmstb.c
> +++ b/drivers/gpio/gpio-brcmstb.c
> @@ -777,7 +777,18 @@ static struct platform_driver brcmstb_gpio_driver = {
>  	.remove = brcmstb_gpio_remove,
>  	.shutdown = brcmstb_gpio_shutdown,
>  };
> -module_platform_driver(brcmstb_gpio_driver);
> +
> +static int __init brcmstb_gpio_init(void)
> +{
> +	return platform_driver_register(&brcmstb_gpio_driver);
> +}
> +subsys_initcall(brcmstb_gpio_init);
> +
> +static void __exit brcmstb_gpio_exit(void)
> +{
> +	platform_driver_unregister(&brcmstb_gpio_driver);
> +}
> +module_exit(brcmstb_gpio_exit);

We do this in the downstream tree, but there is no reason, we should
just deal with EPROBE_DEFER being returned from the regulator subsystem
until the GPIO provide is available.

[snip]

> +static void brcm_pcie_regulator_init(struct brcm_pcie *pcie)
> +{
> +	struct device_node *np = pcie->dev->of_node;
> +	struct device *dev = pcie->dev;
> +	const char *name;
> +	struct regulator *reg;
> +	int i;
> +
> +	pcie->num_regs = of_property_count_strings(np, "supply-names");
> +	if (pcie->num_regs <= 0) {
> +		pcie->num_regs = 0;
> +		return;
> +	}
> +
> +	pcie->regs = devm_kcalloc(dev, pcie->num_regs, sizeof(pcie->regs[0]),
> +				  GFP_KERNEL);
> +	if (!pcie->regs) {
> +		pcie->num_regs = 0;
> +		return;
> +	}
> +
> +	for (i = 0; i < pcie->num_regs; i++) {
> +		if (of_property_read_string_index(np, "supply-names", i, &name))
> +			continue;
> +
> +		reg = devm_regulator_get_optional(dev, name);
> +		if (IS_ERR(reg))
> +			continue;

You need to handle EPROBE_DEFER here and propagate that back to the
caller to defer the entire driver from probing until the regulator
providers are available.

> +
> +		pcie->regs[i] = reg;
> +	}
> +}
> +#else
> +static inline void brcm_pcie_regulator_enable(struct brcm_pcie *pcie) { }
> +static inline void brcm_pcie_regulator_disable(struct brcm_pcie *pcie) { }
> +static inline void brcm_pcie_regulator_init(struct brcm_pcie *pcie) { }
> +#endif
> +
>  /*
>   * This is to convert the size of the inbound "BAR" region to the
>   * non-linear values of PCIE_X_MISC_RC_BAR[123]_CONFIG_LO.SIZE
> @@ -898,6 +970,7 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie)
>  {
>  	brcm_msi_remove(pcie);
>  	brcm_pcie_turn_off(pcie);
> +	brcm_pcie_regulator_disable(pcie);
>  	clk_disable_unprepare(pcie->clk);
>  	clk_put(pcie->clk);
>  }
> @@ -955,6 +1028,9 @@ static int brcm_pcie_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	brcm_pcie_regulator_init(pcie);
> +	brcm_pcie_regulator_enable(pcie);

And deal with errors here.

> +
>  	ret = brcm_pcie_setup(pcie);
>  	if (ret)
>  		goto fail;
> 

-- 
Florian



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux