diff mbox series

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

Message ID 1581166975-22949-3-git-send-email-stefan.wahren@i2se.com (mailing list archive)
State Mainlined
Commit 90bfaf028d61a6d523c685b63c2bcc94eebb8057
Headers show
Series pinctrl: bcm2835: Add support for all BCM2711 GPIOs | expand

Commit Message

Stefan Wahren Feb. 8, 2020, 1:02 p.m. UTC
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@i2se.com>
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 57 +++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 13 deletions(-)

Comments

Nicolas Saenz Julienne Feb. 12, 2020, 6:33 p.m. UTC | #1
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@i2se.com>
> ---

Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>

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);
Linus Walleij Feb. 14, 2020, 10:48 a.m. UTC | #2
On Sat, Feb 8, 2020 at 2:03 PM Stefan Wahren <stefan.wahren@i2se.com> 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@i2se.com>

Patch applied with Nicolas' Review tag.

Yours,
Linus Walleij
diff mbox series

Patch

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