Skip to content

Commit 8ff0598

Browse files
lategoodbyelinusw
authored andcommitted
pinctrl: bcm2835: Make pin freeing behavior configurable
Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN. So in case it was configured as GPIO_OUT before the configured output level also get lost. As long as GPIO sysfs was used this wasn't actually a problem because the pins and their possible output level were kept by sysfs. Since more and more Raspberry Pi users start using libgpiod they are confused about this behavior. So make the pin freeing behavior of GPIO_OUT configurable via module parameter. In case pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is kept. This patch based on the downstream work of Phil Elwell. Link: raspberrypi/linux#6117 Signed-off-by: Stefan Wahren <[email protected]> Message-ID: <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 4ad4f6e commit 8ff0598

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/pinctrl/bcm/pinctrl-bcm2835.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ static const char * const irq_type_names[] = {
244244
[IRQ_TYPE_LEVEL_LOW] = "level-low",
245245
};
246246

247+
static bool persist_gpio_outputs;
248+
module_param(persist_gpio_outputs, bool, 0644);
249+
MODULE_PARM_DESC(persist_gpio_outputs, "Enable GPIO_OUT persistence when pin is freed");
250+
247251
static inline u32 bcm2835_gpio_rd(struct bcm2835_pinctrl *pc, unsigned reg)
248252
{
249253
return readl(pc->base + reg);
@@ -926,6 +930,13 @@ static int bcm2835_pmx_free(struct pinctrl_dev *pctldev,
926930
unsigned offset)
927931
{
928932
struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
933+
enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, offset);
934+
935+
if (fsel == BCM2835_FSEL_GPIO_IN)
936+
return 0;
937+
938+
if (persist_gpio_outputs && fsel == BCM2835_FSEL_GPIO_OUT)
939+
return 0;
929940

930941
/* disable by setting to GPIO_IN */
931942
bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN);
@@ -970,10 +981,7 @@ static void bcm2835_pmx_gpio_disable_free(struct pinctrl_dev *pctldev,
970981
struct pinctrl_gpio_range *range,
971982
unsigned offset)
972983
{
973-
struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
974-
975-
/* disable by setting to GPIO_IN */
976-
bcm2835_pinctrl_fsel_set(pc, offset, BCM2835_FSEL_GPIO_IN);
984+
bcm2835_pmx_free(pctldev, offset);
977985
}
978986

979987
static int bcm2835_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
@@ -1419,6 +1427,9 @@ static int bcm2835_pinctrl_probe(struct platform_device *pdev)
14191427
goto out_remove;
14201428
}
14211429

1430+
dev_info(dev, "GPIO_OUT persistence: %s\n",
1431+
persist_gpio_outputs ? "yes" : "no");
1432+
14221433
return 0;
14231434

14241435
out_remove:

0 commit comments

Comments
 (0)