linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: stm32: set default gpio line names using pin names
@ 2023-06-20 10:43 Valentin Caron
  2023-06-21  7:18 ` Linus Walleij
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Valentin Caron @ 2023-06-20 10:43 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Torgue, linux-gpio, linux-stm32, linux-arm-kernel,
	linux-kernel, Valentin Caron

Add stm32_pctrl_get_desc_pin_from_gpio function to find a stm32 pin
descriptor which is matching with a gpio.
Most of the time pin number is equal to pin index in array. So the first
part of the function is useful to speed up.

And during gpio bank register, we set default gpio names with pin names.

Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
 drivers/pinctrl/stm32/pinctrl-stm32.c | 35 +++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index 4b97bd00191b..eedbb9b97a65 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1275,6 +1275,28 @@ static const struct pinconf_ops stm32_pconf_ops = {
 	.pin_config_dbg_show	= stm32_pconf_dbg_show,
 };
 
+static struct stm32_desc_pin *stm32_pctrl_get_desc_pin_from_gpio(struct stm32_pinctrl *pctl,
+								 struct stm32_gpio_bank *bank,
+								 unsigned int offset)
+{
+	unsigned int stm32_pin_nb = bank->bank_nr * STM32_GPIO_PINS_PER_BANK + offset;
+	struct stm32_desc_pin *pin_desc;
+	int i;
+
+	/* With few exceptions (e.g. bank 'Z'), pin number matches with pin index in array */
+	pin_desc = pctl->pins + stm32_pin_nb;
+	if (pin_desc->pin.number == stm32_pin_nb)
+		return pin_desc;
+
+	/* Otherwise, loop all array to find the pin with the right number */
+	for (i = 0; i < pctl->npins; i++) {
+		pin_desc = pctl->pins + i;
+		if (pin_desc->pin.number == stm32_pin_nb)
+			return pin_desc;
+	}
+	return NULL;
+}
+
 static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode_handle *fwnode)
 {
 	struct stm32_gpio_bank *bank = &pctl->banks[pctl->nbanks];
@@ -1285,6 +1307,8 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
 	struct resource res;
 	int npins = STM32_GPIO_PINS_PER_BANK;
 	int bank_nr, err, i = 0;
+	struct stm32_desc_pin *stm32_pin;
+	char **names;
 
 	if (!IS_ERR(bank->rstc))
 		reset_control_deassert(bank->rstc);
@@ -1354,6 +1378,17 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
 		}
 	}
 
+	names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
+	for (i = 0; i < npins; i++) {
+		stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
+		if (stm32_pin && stm32_pin->pin.name)
+			names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", stm32_pin->pin.name);
+		else
+			names[i] = NULL;
+	}
+
+	bank->gpio_chip.names = (const char * const *)names;
+
 	err = gpiochip_add_data(&bank->gpio_chip, bank);
 	if (err) {
 		dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_nr);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] pinctrl: stm32: set default gpio line names using pin names
  2023-06-20 10:43 [PATCH] pinctrl: stm32: set default gpio line names using pin names Valentin Caron
@ 2023-06-21  7:18 ` Linus Walleij
  2023-06-21  8:18 ` Alexandre TORGUE
  2023-08-10  8:12 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2023-06-21  7:18 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Alexandre Torgue, linux-gpio, linux-stm32, linux-arm-kernel,
	linux-kernel

On Tue, Jun 20, 2023 at 12:43 PM Valentin Caron
<valentin.caron@foss.st.com> wrote:

> Add stm32_pctrl_get_desc_pin_from_gpio function to find a stm32 pin
> descriptor which is matching with a gpio.
> Most of the time pin number is equal to pin index in array. So the first
> part of the function is useful to speed up.
>
> And during gpio bank register, we set default gpio names with pin names.
>
> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>

If I get some ACK from the STM32 pinctrl maintainers I can merge
this, seems useful! Maybe you already reviewed it internally at ST?
I personally don't mind if you bring over internal reviewed-by tags.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pinctrl: stm32: set default gpio line names using pin names
  2023-06-20 10:43 [PATCH] pinctrl: stm32: set default gpio line names using pin names Valentin Caron
  2023-06-21  7:18 ` Linus Walleij
@ 2023-06-21  8:18 ` Alexandre TORGUE
  2023-08-03 13:26   ` Valentin CARON
  2023-08-10  8:12 ` Linus Walleij
  2 siblings, 1 reply; 5+ messages in thread
From: Alexandre TORGUE @ 2023-06-21  8:18 UTC (permalink / raw)
  To: Valentin Caron, Linus Walleij
  Cc: linux-gpio, linux-stm32, linux-arm-kernel, linux-kernel

Hi

On 6/20/23 12:43, Valentin Caron wrote:
> Add stm32_pctrl_get_desc_pin_from_gpio function to find a stm32 pin
> descriptor which is matching with a gpio.
> Most of the time pin number is equal to pin index in array. So the first
> part of the function is useful to speed up.
> 
> And during gpio bank register, we set default gpio names with pin names.
> 
> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
> ---

Acked-by: Alexandre TORGUE <alexandre.torgue@foss.st.com>

>   drivers/pinctrl/stm32/pinctrl-stm32.c | 35 +++++++++++++++++++++++++++
>   1 file changed, 35 insertions(+)
> 
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index 4b97bd00191b..eedbb9b97a65 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -1275,6 +1275,28 @@ static const struct pinconf_ops stm32_pconf_ops = {
>   	.pin_config_dbg_show	= stm32_pconf_dbg_show,
>   };
>   
> +static struct stm32_desc_pin *stm32_pctrl_get_desc_pin_from_gpio(struct stm32_pinctrl *pctl,
> +								 struct stm32_gpio_bank *bank,
> +								 unsigned int offset)
> +{
> +	unsigned int stm32_pin_nb = bank->bank_nr * STM32_GPIO_PINS_PER_BANK + offset;
> +	struct stm32_desc_pin *pin_desc;
> +	int i;
> +
> +	/* With few exceptions (e.g. bank 'Z'), pin number matches with pin index in array */
> +	pin_desc = pctl->pins + stm32_pin_nb;
> +	if (pin_desc->pin.number == stm32_pin_nb)
> +		return pin_desc;
> +
> +	/* Otherwise, loop all array to find the pin with the right number */
> +	for (i = 0; i < pctl->npins; i++) {
> +		pin_desc = pctl->pins + i;
> +		if (pin_desc->pin.number == stm32_pin_nb)
> +			return pin_desc;
> +	}
> +	return NULL;
> +}
> +
>   static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode_handle *fwnode)
>   {
>   	struct stm32_gpio_bank *bank = &pctl->banks[pctl->nbanks];
> @@ -1285,6 +1307,8 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
>   	struct resource res;
>   	int npins = STM32_GPIO_PINS_PER_BANK;
>   	int bank_nr, err, i = 0;
> +	struct stm32_desc_pin *stm32_pin;
> +	char **names;
>   
>   	if (!IS_ERR(bank->rstc))
>   		reset_control_deassert(bank->rstc);
> @@ -1354,6 +1378,17 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
>   		}
>   	}
>   
> +	names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
> +	for (i = 0; i < npins; i++) {
> +		stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
> +		if (stm32_pin && stm32_pin->pin.name)
> +			names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", stm32_pin->pin.name);
> +		else
> +			names[i] = NULL;
> +	}
> +
> +	bank->gpio_chip.names = (const char * const *)names;
> +
>   	err = gpiochip_add_data(&bank->gpio_chip, bank);
>   	if (err) {
>   		dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_nr);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pinctrl: stm32: set default gpio line names using pin names
  2023-06-21  8:18 ` Alexandre TORGUE
@ 2023-08-03 13:26   ` Valentin CARON
  0 siblings, 0 replies; 5+ messages in thread
From: Valentin CARON @ 2023-08-03 13:26 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre TORGUE, linux-gpio, linux-stm32, linux-arm-kernel,
	linux-kernel

Hi Linus,

Is the Acked-by from Alexandre enough ?

He is maintainer of arm/stm32 architecture.

Thanks,
Valentin

On 6/21/23 10:18, Alexandre TORGUE wrote:
> Hi
>
> On 6/20/23 12:43, Valentin Caron wrote:
>> Add stm32_pctrl_get_desc_pin_from_gpio function to find a stm32 pin
>> descriptor which is matching with a gpio.
>> Most of the time pin number is equal to pin index in array. So the first
>> part of the function is useful to speed up.
>>
>> And during gpio bank register, we set default gpio names with pin names.
>>
>> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
>> ---
>
> Acked-by: Alexandre TORGUE <alexandre.torgue@foss.st.com>
>
>>   drivers/pinctrl/stm32/pinctrl-stm32.c | 35 +++++++++++++++++++++++++++
>>   1 file changed, 35 insertions(+)
>>
>> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c 
>> b/drivers/pinctrl/stm32/pinctrl-stm32.c
>> index 4b97bd00191b..eedbb9b97a65 100644
>> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
>> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
>> @@ -1275,6 +1275,28 @@ static const struct pinconf_ops 
>> stm32_pconf_ops = {
>>       .pin_config_dbg_show    = stm32_pconf_dbg_show,
>>   };
>>   +static struct stm32_desc_pin 
>> *stm32_pctrl_get_desc_pin_from_gpio(struct stm32_pinctrl *pctl,
>> +                                 struct stm32_gpio_bank *bank,
>> +                                 unsigned int offset)
>> +{
>> +    unsigned int stm32_pin_nb = bank->bank_nr * 
>> STM32_GPIO_PINS_PER_BANK + offset;
>> +    struct stm32_desc_pin *pin_desc;
>> +    int i;
>> +
>> +    /* With few exceptions (e.g. bank 'Z'), pin number matches with 
>> pin index in array */
>> +    pin_desc = pctl->pins + stm32_pin_nb;
>> +    if (pin_desc->pin.number == stm32_pin_nb)
>> +        return pin_desc;
>> +
>> +    /* Otherwise, loop all array to find the pin with the right 
>> number */
>> +    for (i = 0; i < pctl->npins; i++) {
>> +        pin_desc = pctl->pins + i;
>> +        if (pin_desc->pin.number == stm32_pin_nb)
>> +            return pin_desc;
>> +    }
>> +    return NULL;
>> +}
>> +
>>   static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, 
>> struct fwnode_handle *fwnode)
>>   {
>>       struct stm32_gpio_bank *bank = &pctl->banks[pctl->nbanks];
>> @@ -1285,6 +1307,8 @@ static int stm32_gpiolib_register_bank(struct 
>> stm32_pinctrl *pctl, struct fwnode
>>       struct resource res;
>>       int npins = STM32_GPIO_PINS_PER_BANK;
>>       int bank_nr, err, i = 0;
>> +    struct stm32_desc_pin *stm32_pin;
>> +    char **names;
>>         if (!IS_ERR(bank->rstc))
>>           reset_control_deassert(bank->rstc);
>> @@ -1354,6 +1378,17 @@ static int stm32_gpiolib_register_bank(struct 
>> stm32_pinctrl *pctl, struct fwnode
>>           }
>>       }
>>   +    names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
>> +    for (i = 0; i < npins; i++) {
>> +        stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
>> +        if (stm32_pin && stm32_pin->pin.name)
>> +            names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", 
>> stm32_pin->pin.name);
>> +        else
>> +            names[i] = NULL;
>> +    }
>> +
>> +    bank->gpio_chip.names = (const char * const *)names;
>> +
>>       err = gpiochip_add_data(&bank->gpio_chip, bank);
>>       if (err) {
>>           dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_nr);
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] pinctrl: stm32: set default gpio line names using pin names
  2023-06-20 10:43 [PATCH] pinctrl: stm32: set default gpio line names using pin names Valentin Caron
  2023-06-21  7:18 ` Linus Walleij
  2023-06-21  8:18 ` Alexandre TORGUE
@ 2023-08-10  8:12 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2023-08-10  8:12 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Alexandre Torgue, linux-gpio, linux-stm32, linux-arm-kernel,
	linux-kernel

On Tue, Jun 20, 2023 at 12:43 PM Valentin Caron
<valentin.caron@foss.st.com> wrote:

> Add stm32_pctrl_get_desc_pin_from_gpio function to find a stm32 pin
> descriptor which is matching with a gpio.
> Most of the time pin number is equal to pin index in array. So the first
> part of the function is useful to speed up.
>
> And during gpio bank register, we set default gpio names with pin names.
>
> Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>

Patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-10  8:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-20 10:43 [PATCH] pinctrl: stm32: set default gpio line names using pin names Valentin Caron
2023-06-21  7:18 ` Linus Walleij
2023-06-21  8:18 ` Alexandre TORGUE
2023-08-03 13:26   ` Valentin CARON
2023-08-10  8:12 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).