Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: stm32: handle semaphore acquisition when handling pinctrl/pinmux

When a GPIO RIF configuration is in semaphore mode, and the semaphore
hasn't been taken before configuring the GPIO, the write operations
silently fail.

To avoid a silent fail when applying a pinctrl, if the pins that are
being configured are in semaphore mode, take the semaphore. Note that
there is no proper release of the RIF semaphore yet for pinctrl.

Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Gatien Chevallier and committed by
Linus Walleij
7959deaa dbd2317d

+27 -8
+27 -8
drivers/pinctrl/stm32/pinctrl-stm32.c
··· 362 362 return -EINVAL; 363 363 } 364 364 365 - if (bank->rif_control) { 366 - if (!stm32_gpio_rif_acquire_semaphore(bank, offset)) { 367 - dev_err(pctl->dev, "pin %d not available.\n", pin); 368 - return -EINVAL; 369 - } 365 + if (bank->rif_control && !stm32_gpio_rif_acquire_semaphore(bank, offset)) { 366 + dev_err(pctl->dev, "pin %d not available.\n", offset); 367 + return -EACCES; 370 368 } 371 369 372 370 return pinctrl_gpio_request(chip, offset); ··· 1038 1040 static int stm32_pmx_request(struct pinctrl_dev *pctldev, unsigned int gpio) 1039 1041 { 1040 1042 struct stm32_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); 1043 + unsigned int offset = stm32_gpio_pin(gpio); 1041 1044 struct pinctrl_gpio_range *range; 1045 + struct stm32_gpio_bank *bank; 1042 1046 1043 1047 range = pinctrl_find_gpio_range_from_pin_nolock(pctldev, gpio); 1044 1048 if (!range) { ··· 1048 1048 return -EINVAL; 1049 1049 } 1050 1050 1051 - if (!gpiochip_line_is_valid(range->gc, stm32_gpio_pin(gpio))) { 1051 + if (!gpiochip_line_is_valid(range->gc, offset)) { 1052 1052 dev_warn(pctl->dev, "Can't access gpio %d\n", gpio); 1053 + return -EACCES; 1054 + } 1055 + 1056 + bank = gpiochip_get_data(range->gc); 1057 + if (!bank) 1058 + return -ENODEV; 1059 + 1060 + if (bank->rif_control && !stm32_gpio_rif_acquire_semaphore(bank, offset)) { 1061 + dev_err(pctl->dev, "pin %d not available.\n", offset); 1053 1062 return -EACCES; 1054 1063 } 1055 1064 ··· 1400 1391 1401 1392 if (!gpiochip_line_is_valid(range->gc, offset)) { 1402 1393 dev_warn(pctl->dev, "Can't access gpio %d\n", pin); 1394 + return -EACCES; 1395 + } 1396 + 1397 + if (bank->rif_control && !stm32_gpio_rif_acquire_semaphore(bank, offset)) { 1398 + dev_err(pctl->dev, "pin %d not available.\n", offset); 1403 1399 return -EACCES; 1404 1400 } 1405 1401 ··· 2028 2014 if (!range) 2029 2015 return 0; 2030 2016 2017 + bank = gpiochip_get_data(range->gc); 2018 + 2031 2019 if (!gpiochip_line_is_valid(range->gc, offset)) 2032 2020 return 0; 2021 + 2022 + if (bank->rif_control && !stm32_gpio_rif_acquire_semaphore(bank, offset)) { 2023 + dev_err(pctl->dev, "pin %d not available.\n", offset); 2024 + return -EACCES; 2025 + } 2033 2026 2034 2027 pin_is_irq = gpiochip_line_is_irq(range->gc, offset); 2035 2028 2036 2029 if (!desc || (!pin_is_irq && !desc->gpio_owner)) 2037 2030 return 0; 2038 - 2039 - bank = gpiochip_get_data(range->gc); 2040 2031 2041 2032 mode = bank->pin_backup[offset].mode; 2042 2033 ret = stm32_pmx_set_mode(bank, offset, mode, bank->pin_backup[offset].alt);