Re: [PATCH 2/4] pinctrl: bcm2835: Refactor platform data

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

 



On Sat, 2020-02-08 at 14:02 +0100, Stefan Wahren wrote:
> This prepares the platform data to be easier to extend for more GPIOs.
> Except of this there is no functional change.
> 
> Signed-off-by: Stefan Wahren <stefan.wahren@xxxxxxxx>
> ---

Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@xxxxxxx>

Thanks!

>  drivers/pinctrl/bcm/pinctrl-bcm2835.c | 57 +++++++++++++++++++++++++++-------
> -
>  1 file changed, 44 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> index 3fc2638..7f0a9c6 100644
> --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> @@ -82,6 +82,7 @@ struct bcm2835_pinctrl {
>  
>  	struct pinctrl_dev *pctl_dev;
>  	struct gpio_chip gpio_chip;
> +	struct pinctrl_desc pctl_desc;
>  	struct pinctrl_gpio_range gpio_range;
>  
>  	raw_spinlock_t irq_lock[BCM2835_NUM_BANKS];
> @@ -1051,7 +1052,7 @@ static const struct pinconf_ops bcm2711_pinconf_ops = {
>  	.pin_config_set = bcm2711_pinconf_set,
>  };
>  
> -static struct pinctrl_desc bcm2835_pinctrl_desc = {
> +static const struct pinctrl_desc bcm2835_pinctrl_desc = {
>  	.name = MODULE_NAME,
>  	.pins = bcm2835_gpio_pins,
>  	.npins = ARRAY_SIZE(bcm2835_gpio_pins),
> @@ -1061,19 +1062,47 @@ static struct pinctrl_desc bcm2835_pinctrl_desc = {
>  	.owner = THIS_MODULE,
>  };
>  
> -static struct pinctrl_gpio_range bcm2835_pinctrl_gpio_range = {
> +static const struct pinctrl_desc bcm2711_pinctrl_desc = {
> +	.name = MODULE_NAME,
> +	.pins = bcm2835_gpio_pins,
> +	.npins = ARRAY_SIZE(bcm2835_gpio_pins),
> +	.pctlops = &bcm2835_pctl_ops,
> +	.pmxops = &bcm2835_pmx_ops,
> +	.confops = &bcm2711_pinconf_ops,
> +	.owner = THIS_MODULE,
> +};
> +
> +static const struct pinctrl_gpio_range bcm2835_pinctrl_gpio_range = {
>  	.name = MODULE_NAME,
>  	.npins = BCM2835_NUM_GPIOS,
>  };
>  
> +struct bcm_plat_data {
> +	const struct gpio_chip *gpio_chip;
> +	const struct pinctrl_desc *pctl_desc;
> +	const struct pinctrl_gpio_range *gpio_range;
> +};
> +
> +static const struct bcm_plat_data bcm2835_plat_data = {
> +	.gpio_chip = &bcm2835_gpio_chip,
> +	.pctl_desc = &bcm2835_pinctrl_desc,
> +	.gpio_range = &bcm2835_pinctrl_gpio_range,
> +};
> +
> +static const struct bcm_plat_data bcm2711_plat_data = {
> +	.gpio_chip = &bcm2835_gpio_chip,
> +	.pctl_desc = &bcm2711_pinctrl_desc,
> +	.gpio_range = &bcm2835_pinctrl_gpio_range,
> +};
> +
>  static const struct of_device_id bcm2835_pinctrl_match[] = {
>  	{
>  		.compatible = "brcm,bcm2835-gpio",
> -		.data = &bcm2835_pinconf_ops,
> +		.data = &bcm2835_plat_data,
>  	},
>  	{
>  		.compatible = "brcm,bcm2711-gpio",
> -		.data = &bcm2711_pinconf_ops,
> +		.data = &bcm2711_plat_data,
>  	},
>  	{}
>  };
> @@ -1082,6 +1111,7 @@ static int bcm2835_pinctrl_probe(struct platform_device
> *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  	struct device_node *np = dev->of_node;
> +	const struct bcm_plat_data *pdata;
>  	struct bcm2835_pinctrl *pc;
>  	struct gpio_irq_chip *girq;
>  	struct resource iomem;
> @@ -1108,7 +1138,13 @@ static int bcm2835_pinctrl_probe(struct platform_device
> *pdev)
>  	if (IS_ERR(pc->base))
>  		return PTR_ERR(pc->base);
>  
> -	pc->gpio_chip = bcm2835_gpio_chip;
> +	match = of_match_node(bcm2835_pinctrl_match, pdev->dev.of_node);
> +	if (!match)
> +		return -EINVAL;
> +
> +	pdata = match->data;
> +
> +	pc->gpio_chip = *pdata->gpio_chip;
>  	pc->gpio_chip.parent = dev;
>  	pc->gpio_chip.of_node = np;
>  
> @@ -1159,19 +1195,14 @@ static int bcm2835_pinctrl_probe(struct
> platform_device *pdev)
>  		return err;
>  	}
>  
> -	match = of_match_node(bcm2835_pinctrl_match, pdev->dev.of_node);
> -	if (match) {
> -		bcm2835_pinctrl_desc.confops =
> -			(const struct pinconf_ops *)match->data;
> -	}
> -
> -	pc->pctl_dev = devm_pinctrl_register(dev, &bcm2835_pinctrl_desc, pc);
> +	pc->pctl_desc = *pdata->pctl_desc;
> +	pc->pctl_dev = devm_pinctrl_register(dev, &pc->pctl_desc, pc);
>  	if (IS_ERR(pc->pctl_dev)) {
>  		gpiochip_remove(&pc->gpio_chip);
>  		return PTR_ERR(pc->pctl_dev);
>  	}
>  
> -	pc->gpio_range = bcm2835_pinctrl_gpio_range;
> +	pc->gpio_range = *pdata->gpio_range;
>  	pc->gpio_range.base = pc->gpio_chip.base;
>  	pc->gpio_range.gc = &pc->gpio_chip;
>  	pinctrl_add_gpio_range(pc->pctl_dev, &pc->gpio_range);

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux