Skip to content

Commit 32c170f

Browse files
VCASTMlinusw
authored andcommitted
pinctrl: stm32: set default gpio line names using pin names
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 <[email protected]> Acked-by: Alexandre TORGUE <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent fc8a204 commit 32c170f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

drivers/pinctrl/stm32/pinctrl-stm32.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,28 @@ static const struct pinconf_ops stm32_pconf_ops = {
12741274
.pin_config_dbg_show = stm32_pconf_dbg_show,
12751275
};
12761276

1277+
static struct stm32_desc_pin *stm32_pctrl_get_desc_pin_from_gpio(struct stm32_pinctrl *pctl,
1278+
struct stm32_gpio_bank *bank,
1279+
unsigned int offset)
1280+
{
1281+
unsigned int stm32_pin_nb = bank->bank_nr * STM32_GPIO_PINS_PER_BANK + offset;
1282+
struct stm32_desc_pin *pin_desc;
1283+
int i;
1284+
1285+
/* With few exceptions (e.g. bank 'Z'), pin number matches with pin index in array */
1286+
pin_desc = pctl->pins + stm32_pin_nb;
1287+
if (pin_desc->pin.number == stm32_pin_nb)
1288+
return pin_desc;
1289+
1290+
/* Otherwise, loop all array to find the pin with the right number */
1291+
for (i = 0; i < pctl->npins; i++) {
1292+
pin_desc = pctl->pins + i;
1293+
if (pin_desc->pin.number == stm32_pin_nb)
1294+
return pin_desc;
1295+
}
1296+
return NULL;
1297+
}
1298+
12771299
static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode_handle *fwnode)
12781300
{
12791301
struct stm32_gpio_bank *bank = &pctl->banks[pctl->nbanks];
@@ -1284,6 +1306,8 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
12841306
struct resource res;
12851307
int npins = STM32_GPIO_PINS_PER_BANK;
12861308
int bank_nr, err, i = 0;
1309+
struct stm32_desc_pin *stm32_pin;
1310+
char **names;
12871311

12881312
if (!IS_ERR(bank->rstc))
12891313
reset_control_deassert(bank->rstc);
@@ -1353,6 +1377,17 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
13531377
}
13541378
}
13551379

1380+
names = devm_kcalloc(dev, npins, sizeof(char *), GFP_KERNEL);
1381+
for (i = 0; i < npins; i++) {
1382+
stm32_pin = stm32_pctrl_get_desc_pin_from_gpio(pctl, bank, i);
1383+
if (stm32_pin && stm32_pin->pin.name)
1384+
names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s", stm32_pin->pin.name);
1385+
else
1386+
names[i] = NULL;
1387+
}
1388+
1389+
bank->gpio_chip.names = (const char * const *)names;
1390+
13561391
err = gpiochip_add_data(&bank->gpio_chip, bank);
13571392
if (err) {
13581393
dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_nr);

0 commit comments

Comments
 (0)