[RFC,2/4] pinctrl: bcm2835: Refactor platform data
diff mbox series

Message ID 1580148908-4863-3-git-send-email-stefan.wahren@i2se.com
State New
Headers show
Series
  • pinctrl: bcm2835: Add support for all BCM2711 GPIOs
Related show

Commit Message

Stefan Wahren Jan. 27, 2020, 6:15 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 Jan. 28, 2020, 9:44 a.m. UTC | #1
Hi Stefan,
thanks for the series!

On Mon Jan 27, 2020 at 7:15 PM, 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>
> ---

[...]

> @@ -1083,6 +1112,7 @@ static int bcm2835_pinctrl_probe(struct
> platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct device_node *np = dev->of_node;
> struct bcm2835_pinctrl *pc;
> + struct bcm_plat_data *pdata;

You could define pdata as const here...

> struct gpio_irq_chip *girq;
> struct resource iomem;
> int err, i;
> @@ -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 = (struct bcm_plat_data *)match->data;

...And avoid this cast.

> +
> + memcpy(&pc->gpio_chip, pdata->gpio_chip, sizeof(pc->gpio_chip));

Here (and below) you could do:

	pc->gpio_chip = *pdata->gpio_chip;

IMO it's nicer, but it's a matter of taste.

> 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);
> + memcpy(&pc->pctl_desc, pdata->pctl_desc, sizeof(pc->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;
> + memcpy(&pc->gpio_range, pdata->gpio_range, sizeof(pc->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);
> --
> 2.7.4
Nicolas Saenz Julienne Jan. 29, 2020, 1:52 p.m. UTC | #2
Hi Stefan,
thanks for the series!

On Mon, 2020-01-27 at 19:15 +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>
> ---

[...]

> @@ -1083,6 +1112,7 @@ static int bcm2835_pinctrl_probe(struct platform_device
> *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct device_node *np = dev->of_node;
>  	struct bcm2835_pinctrl *pc;
> +	struct bcm_plat_data *pdata;

You could define this as const...

>  	struct gpio_irq_chip *girq;
>  	struct resource iomem;
>  	int err, i;
> @@ -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 = (struct bcm_plat_data *)match->data;

...and drop this cast.

> +
> +	memcpy(&pc->gpio_chip, pdata->gpio_chip, sizeof(pc->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);
> +	memcpy(&pc->pctl_desc, pdata->pctl_desc, sizeof(pc->pctl_desc));

I suggest doing (here and below):

	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;
> +	memcpy(&pc->gpio_range, pdata->gpio_range, sizeof(pc->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);

Regards,
Nicolas

Patch
diff mbox series

diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index 3fc2638..ffd069a 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,
 	},
 	{}
 };
@@ -1083,6 +1112,7 @@  static int bcm2835_pinctrl_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
 	struct bcm2835_pinctrl *pc;
+	struct bcm_plat_data *pdata;
 	struct gpio_irq_chip *girq;
 	struct resource iomem;
 	int err, i;
@@ -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 = (struct bcm_plat_data *)match->data;
+
+	memcpy(&pc->gpio_chip, pdata->gpio_chip, sizeof(pc->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);
+	memcpy(&pc->pctl_desc, pdata->pctl_desc, sizeof(pc->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;
+	memcpy(&pc->gpio_range, pdata->gpio_range, sizeof(pc->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);