Skip to contentSkip to conversation

Add driver for Mellanox BlueField-3 GPIO controller

PATCH In review Asmaa Mnebhi 3 participants 15 messages Apr 18, 2022 – Sep 6, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add driver for Mellanox BlueField-3 GPIO controller

This patch adds support for the GPIO controller used by Mellanox BlueField-3 SOCs. By default (after a reset for example), only the hardware has control over the GPIO values. The GPIOs need to be configured accordingly for the software to control them. We don't allow the user to manipulate the GPIO pins unless it is allowed by the ACPI table property "ctrl_gpio_mask".

---
 drivers/gpio/Kconfig       |   7 +
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-mlxbf3.c | 337 +++++++++++++++++++++++++++++++++++++
 3 files changed, 345 insertions(+)
 create mode 100644 drivers/gpio/gpio-mlxbf3.c
drivers/gpio/Kconfig +7 -0
index 45764ec3b2eb..d470117e7254 100644
@@ -1530,6 +1530,13 @@ config GPIO_MLXBF2
 	help
 	  Say Y here if you want GPIO support on Mellanox BlueField 2 SoC.
 
+config GPIO_MLXBF3
+	tristate "Mellanox BlueField 3 SoC GPIO"
+	depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST)
+	select GPIO_GENERIC
+	help
+	  Say Y here if you want GPIO support on Mellanox BlueField 3 SoC.
+
 config GPIO_ML_IOH
 	tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
 	depends on X86 || COMPILE_TEST
drivers/gpio/Makefile +1 -0
index 14352f6dfe8e..eb24e8e4c4e1 100644
@@ -97,6 +97,7 @@ obj-$(CONFIG_GPIO_MERRIFIELD)		+= gpio-merrifield.o
 obj-$(CONFIG_GPIO_ML_IOH)		+= gpio-ml-ioh.o
 obj-$(CONFIG_GPIO_MLXBF)		+= gpio-mlxbf.o
 obj-$(CONFIG_GPIO_MLXBF2)		+= gpio-mlxbf2.o
+obj-$(CONFIG_GPIO_MLXBF3)		+= gpio-mlxbf3.o
 obj-$(CONFIG_GPIO_MM_LANTIQ)		+= gpio-mm-lantiq.o
 obj-$(CONFIG_GPIO_MOCKUP)		+= gpio-mockup.o
 obj-$(CONFIG_GPIO_MOXTET)		+= gpio-moxtet.o
drivers/gpio/gpio-mlxbf3.c new file +337 -0

337 lines not on this page · raw message

Signature · 1 line
2.30.1
#1 lore raw

Hi,

Could you please have a look at this patch?

Thank you,
Asmaa

-----Original Message-----
From: Asmaa Mnebhi <[email protected]>
Sent: Monday, April 18, 2022 10:14 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Asmaa Mnebhi <[email protected]>
Subject: [PATCH v1 1/1] Add driver for Mellanox BlueField-3 GPIO controller
Importance: High

This patch adds support for the GPIO controller used by Mellanox BlueField-3 SOCs.
By default (after a reset for example), only the hardware has control over the GPIO values.
The GPIOs need to be configured accordingly for the software to control them.
We don't allow the user to manipulate the GPIO pins unless it is allowed by the ACPI table property "ctrl_gpio_mask".

---
 drivers/gpio/Kconfig       |   7 +
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-mlxbf3.c | 337 +++++++++++++++++++++++++++++++++++++
 3 files changed, 345 insertions(+)
 create mode 100644 drivers/gpio/gpio-mlxbf3.c
drivers/gpio/Kconfig +7 -0
@@ -1530,6 +1530,13 @@ config GPIO_MLXBF2
 	help
 	  Say Y here if you want GPIO support on Mellanox BlueField 2 SoC.
 
+config GPIO_MLXBF3
+	tristate "Mellanox BlueField 3 SoC GPIO"
+	depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST)
+	select GPIO_GENERIC
+	help
+	  Say Y here if you want GPIO support on Mellanox BlueField 3 SoC.
+
 config GPIO_ML_IOH
 	tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
 	depends on X86 || COMPILE_TEST
drivers/gpio/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_GPIO_MERRIFIELD)		+= gpio-merrifield.o
 obj-$(CONFIG_GPIO_ML_IOH)		+= gpio-ml-ioh.o
 obj-$(CONFIG_GPIO_MLXBF)		+= gpio-mlxbf.o
 obj-$(CONFIG_GPIO_MLXBF2)		+= gpio-mlxbf2.o
+obj-$(CONFIG_GPIO_MLXBF3)		+= gpio-mlxbf3.o
 obj-$(CONFIG_GPIO_MM_LANTIQ)		+= gpio-mm-lantiq.o
 obj-$(CONFIG_GPIO_MOCKUP)		+= gpio-mockup.o
 obj-$(CONFIG_GPIO_MOXTET)		+= gpio-moxtet.o
drivers/gpio/gpio-mlxbf3.c new file +325 -0

325 lines not on this page · raw message

--
2.30.1

#2 lore raw
Quoted 1 line

Could you please have a look at this patch?

Sure!

drivers/gpio/gpio-mlxbf3.c line 61

Quoted 2 lines
drivers/gpio/gpio-mlxbf3.c new file +2 -0
+static void mlxbf3_gpio_set(struct gpio_chip *chip, unsigned int
+offset, int val) {

Put opening bracket on new line.
Run your code through scripts/checkpatch.pl before submitting.

Quoted 6 lines
drivers/gpio/gpio-mlxbf3.c new file +6 -0
+       struct mlxbf3_gpio_context *gs = gpiochip_get_data(chip);
+
+       /* Software can only control GPIO pins defined by ctrl_gpio_mask */
+       if (!(BIT(offset) & gs->ctrl_gpio_mask))
+               return;
+

drivers/gpio/gpio-mlxbf3.c line 77

Quoted 10 lines
drivers/gpio/gpio-mlxbf3.c new file +10 -0
+       if (val)
+               writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_DATA_OUT_SET);
+       else
+               writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_DATA_OUT_CLEAR);
+
+       /* Make sure all previous writes are done before changing YU_GPIO_FW_CONTROL_SET */
+       wmb();
+
+       /* This needs to be done last to avoid glitches */
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_CONTROL_SET); }

Bracket on new line. This coding style is very odd.

The hardware is a bit odd too but I see why you can't use GPIO_GENERIC properly with this FW_CONTROL_SET business :/

Quoted 21 lines
drivers/gpio/gpio-mlxbf3.c new file +21 -0
+static int mlxbf3_gpio_direction_input(struct gpio_chip *chip,
+                                      unsigned int offset)
+{
+       struct mlxbf3_gpio_context *gs = gpiochip_get_data(chip);
+       unsigned long flags;
+
+       spin_lock_irqsave(&gs->gc.bgpio_lock, flags);
+
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_OUTPUT_ENABLE_CLEAR);
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_CONTROL_CLEAR);
+
+       spin_unlock_irqrestore(&gs->gc.bgpio_lock, flags);
+
+       return 0;
+}
+
+static int mlxbf3_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned int offset,
+                                       int value)
+{
+       struct mlxbf3_gpio_context *gs = gpiochip_get_data(chip);

drivers/gpio/gpio-mlxbf3.c line 109

Quoted 10 lines
drivers/gpio/gpio-mlxbf3.c new file +10 -0
+       unsigned long flags;
+
+       spin_lock_irqsave(&gs->gc.bgpio_lock, flags);
+
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_OUTPUT_ENABLE_SET);
+
+       spin_unlock_irqrestore(&gs->gc.bgpio_lock, flags);
+
+       return 0;
+}

Why isn't FW_CONTROL_CLEAR/SET used when making a line into an output? Seems unsymmetric? At least put a comment in the code why this is different from making a line into input.

Quoted 5 lines
drivers/gpio/gpio-mlxbf3.c new file +5 -0
+       /* To set the direction to input, just give control to HW by setting
+        * YU_GPIO_FW_CONTROL_CLEAR.
+        * If the GPIO is controlled by HW, read its value via read_data_in register.
+        *
+        * When the direction = output, the GPIO is controlled by SW and

drivers/gpio/gpio-mlxbf3.c line 249

Quoted 10 lines
drivers/gpio/gpio-mlxbf3.c new file +10 -0
+        * datain=dataout. If software modifies the value of the GPIO pin,
+        * the value can be read from read_data_in without changing the direction.
+        */
+       ret = bgpio_init(gc, dev, 4,
+                       gs->gpio_io + YU_GPIO_READ_DATA_IN,
+                       NULL,
+                       NULL,
+                       NULL,
+                       NULL,
+                       0);

Hm. Is it still worth it?

MVH
Linus Walleij

#3 lore raw

-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Thursday, May 5, 2022 11:12 AM
To: Asmaa Mnebhi <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 1/1] Add driver for Mellanox BlueField-3 GPIO controller
Importance: High

Quoted 1 line

Could you please have a look at this patch?

Sure!

drivers/gpio/gpio-mlxbf3.c line 61

Quoted 2 lines
drivers/gpio/gpio-mlxbf3.c new file +2 -0
+static void mlxbf3_gpio_set(struct gpio_chip *chip, unsigned int 
+offset, int val) {

Put opening bracket on new line.
Run your code through scripts/checkpatch.pl before submitting.

It is odd that it got sent this way in the email. In my patch and my local file, the bracket is aligned correctly as follows:
+static void mlxbf3_gpio_set(struct gpio_chip *chip, unsigned int offset, int val)
+{

I did run checkpatch.pl before sending this. I will resend the email , hopefully it will be sent properly this time.

Quoted 7 lines
drivers/gpio/gpio-mlxbf3.c new file +7 -0
+       struct mlxbf3_gpio_context *gs = gpiochip_get_data(chip);
+
+       /* Software can only control GPIO pins defined by ctrl_gpio_mask */
+       if (!(BIT(offset) & gs->ctrl_gpio_mask))
+               return;
+
+       if (val)

drivers/gpio/gpio-mlxbf3.c line 77

Quoted 10 lines
drivers/gpio/gpio-mlxbf3.c new file +10 -0
+               writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_DATA_OUT_SET);
+       else
+               writel(BIT(offset), gs->gpio_io + 
+ YU_GPIO_FW_DATA_OUT_CLEAR);
+
+       /* Make sure all previous writes are done before changing YU_GPIO_FW_CONTROL_SET */
+       wmb();
+
+       /* This needs to be done last to avoid glitches */
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_CONTROL_SET); }

Bracket on new line. This coding style is very odd.

Same comment as above. Not sure why the email prints it this way.

The hardware is a bit odd too but I see why you can't use GPIO_GENERIC properly with this FW_CONTROL_SET business :/

Quoted 20 lines
drivers/gpio/gpio-mlxbf3.c new file +20 -0
+static int mlxbf3_gpio_direction_input(struct gpio_chip *chip,
+                                      unsigned int offset) {
+       struct mlxbf3_gpio_context *gs = gpiochip_get_data(chip);
+       unsigned long flags;
+
+       spin_lock_irqsave(&gs->gc.bgpio_lock, flags);
+
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_OUTPUT_ENABLE_CLEAR);
+       writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_CONTROL_CLEAR);
+
+       spin_unlock_irqrestore(&gs->gc.bgpio_lock, flags);
+
+       return 0;
+}
+
+static int mlxbf3_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned int offset,
+                                       int value) {
+       struct mlxbf3_gpio_context *gs = gpiochip_get_data(chip);
+       unsigned long flags;

drivers/gpio/gpio-mlxbf3.c line 109

Quoted 10 lines
drivers/gpio/gpio-mlxbf3.c new file +10 -0
+
+       spin_lock_irqsave(&gs->gc.bgpio_lock, flags);
+
+       writel(BIT(offset), gs->gpio_io + 
+ YU_GPIO_FW_OUTPUT_ENABLE_SET);
+
+       spin_unlock_irqrestore(&gs->gc.bgpio_lock, flags);
+
+       return 0;
+}

Why isn't FW_CONTROL_CLEAR/SET used when making a line into an output? Seems unsymmetric? At least put a comment in the code why this is different from making a line into input.

Ok I will add a comment.

All GPIOs are always controlled by HW by default.
FW_CONTROL_SET is used when we want to release control of the GPIO by HW and give the control to software instead. We want to give control to software only after changing the value of a GPIO pin to avoid any glitches in the HW, so this is the only case where YU_GPIO_FW_CONTROL_SET is set. This is why we don’t do it in mlxbf3_gpio_direction_output. Anyways, the user cannot set a gpio pin to a certain value from linux, if they haven't changed the direction of the gpio to out in the first place. It is a bit an odd implementation but basically even if we set this bit in mlxbf3_gpio_direction_output:
writel(BIT(offset), gs->gpio_io + YU_GPIO_FW_OUTPUT_ENABLE_SET);
It doesn’t actually take effect until we also set the corresponding bit in YU_GPIO_FW_CONTROL_SET. But it was advised by our HW team to set YU_GPIO_FW_CONTROL_SET only after setting the desired GPIO value to avoid HW glitches.

Quoted 5 lines
drivers/gpio/gpio-mlxbf3.c new file +5 -0
+       /* To set the direction to input, just give control to HW by setting
+        * YU_GPIO_FW_CONTROL_CLEAR.
+        * If the GPIO is controlled by HW, read its value via read_data_in register.
+        *
+        * When the direction = output, the GPIO is controlled by SW and

drivers/gpio/gpio-mlxbf3.c line 249

Quoted 10 lines
drivers/gpio/gpio-mlxbf3.c new file +10 -0
+        * datain=dataout. If software modifies the value of the GPIO pin,
+        * the value can be read from read_data_in without changing the direction.
+        */
+       ret = bgpio_init(gc, dev, 4,
+                       gs->gpio_io + YU_GPIO_READ_DATA_IN,
+                       NULL,
+                       NULL,
+                       NULL,
+                       NULL,
+                       0);

Hm. Is it still worth it?

MVH
Linus Walleij

#4 lore raw
Quoted 1 line · Asmaa Mnebhi

Your email is broken. Please, fix the client or other parts that make your email unreadable.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
In reply to Asmaa Mnebhi
Quoted 10 lines · Asmaa Mnebhi
Quoted 3 lines

Why isn't FW_CONTROL_CLEAR/SET used when making a line into an output? Seems unsymmetric? At least put a comment in the code why this is different from making a line into input.

Ok I will add a comment.

All GPIOs are always controlled by HW by default.
FW_CONTROL_SET is used when we want to release
control of the GPIO by HW and give the control to
software instead.

What does that mean in practice? What way does hardware control a GPIO?

It's not some way of remuxing the pins is it, so you what you are calling "controlled by hardware" is actually that it is controlled by e.g. I2C and other stuff that may be muxed in?

Yours,
Linus Walleij

#6 lore raw
Quoted 4 lines

All GPIOs are always controlled by HW by default. FW_CONTROL_SET is used when we want to release control of the GPIO by HW and give the control to software instead.

What does that mean in practice? What way does hardware control a GPIO?

It's not some way of remuxing the pins is it, so you what you are calling "controlled by hardware" is actually that it is controlled by e.g. I2C and other stuff that may be muxed in?

Yes exactly. These GPIO pins are already assigned a specific HW functionality like I2C SDA/SCL, MDIO etc... but we would like to support the option to control them from software if desired.

#7 lore raw
Quoted 6 lines · Asmaa Mnebhi
Quoted 6 lines
Quoted 3 lines

All GPIOs are always controlled by HW by default. FW_CONTROL_SET is used when we want to release control of the GPIO by HW and give the control to software instead.

What does that mean in practice? What way does hardware control a GPIO?

Quoted 7 lines
Quoted 3 lines

It's not some way of remuxing the pins is it, so you what you are calling "controlled by hardware" is actually that it is controlled by e.g. I2C and other stuff that may be muxed in?

Yes exactly. These GPIO pins are already assigned a specific HW functionality like I2C SDA/SCL, MDIO etc... but we would like to support the option to control them from software if desired.

But how does that play with your pin controller?

I mean: is the multiplexing of different other devices also software controlled, so this should have a proper pin control driver rather than just a GPIO driver?

Yours,
Linus Walleij

#8 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

All GPIOs are always controlled by HW by default. FW_CONTROL_SET is used when we want to release control of the GPIO by HW and give the control to software instead.

What does that mean in practice? What way does hardware control a GPIO?

Quoted 7 lines
Quoted 3 lines

It's not some way of remuxing the pins is it, so you what you are calling "controlled by hardware" is actually that it is controlled by e.g. I2C and other stuff that may be muxed in?

Yes exactly. These GPIO pins are already assigned a specific HW functionality like I2C SDA/SCL, MDIO etc... but we would like to support the option to control them from software if desired.

But how does that play with your pin controller?

I mean: is the multiplexing of different other devices also software controlled, so this should have a proper pin control driver rather than just a GPIO driver?

So these GPIO pins are assigned one specific HW functionality on the boards and software should never change them.
By default, for security purposes, I think we shouldn't let the user have the option to control the GPIO pins since they have a specific HW functionality.
But for bringup/debug purposes, we would like to support the option of software being able to change these pin values. We also might have customers that choose to change the default HW connection of a certain GPIO pin and connect it to control their LEDs for instance.

Thanks.
Asmaa

#9 lore raw
Quoted 10 lines · Asmaa Mnebhi

So these GPIO pins are assigned one specific HW functionality on the boards
and software should never change them.

By default, for security purposes, I think we shouldn't let the user have the option to control the GPIO pins since they have a specific HW functionality.

But for bringup/debug purposes, we would like to support the option of software being able to change these pin values. We also might have customers that choose to change the default HW connection of a certain GPIO pin and connect it to control their LEDs for instance.

The fact that the usecase is bringup/debug does not mean we cut corners and do "quick fixes". The proper APIs have to be implemented, the alternative is to not submit the driver at all.

What I hear is that these pins have two modes:

1. Used for a device (I2C etc)
2. Used as GPIO by setting a bit in YU_GPIO_FW_CONTROL_SET

This is two pin control multiplexing states already.

So this should have a simple pin control driver as back-end with the GPIO as front end. A shortcut to enabling pins into GPIO mode can be provided using .gpio_request_enable() from struct pinmux_ops.

Please refer to
https://docs.kernel.org/driver-api/pin-control.html

I know this means more work and is kind of complex. But drivers/pinctrl has a lot of examples you can follow, for example drivers/pinctrl/pinctrl-sx150x.c and other simple multipurpose chips.

Yours,
Linus Walleij

#10 lore raw

Thank you for the feedback Linus! I will address your comments in my next patch.

Best,
Asmaa

-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Wednesday, May 18, 2022 9:51 AM
To: Asmaa Mnebhi <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 1/1] Add driver for Mellanox BlueField-3 GPIO controller
Importance: High

Quoted 10 lines · Asmaa Mnebhi

So these GPIO pins are assigned one specific HW functionality on the boards and software should never change them.

By default, for security purposes, I think we shouldn't let the user have the option to control the GPIO pins since they have a specific HW functionality.

But for bringup/debug purposes, we would like to support the option of software being able to change these pin values. We also might have customers that choose to change the default HW connection of a certain GPIO pin and connect it to control their LEDs for instance.

The fact that the usecase is bringup/debug does not mean we cut corners and do "quick fixes". The proper APIs have to be implemented, the alternative is to not submit the driver at all.

What I hear is that these pins have two modes:

1. Used for a device (I2C etc)
2. Used as GPIO by setting a bit in YU_GPIO_FW_CONTROL_SET

This is two pin control multiplexing states already.

So this should have a simple pin control driver as back-end with the GPIO as front end. A shortcut to enabling pins into GPIO mode can be provided using .gpio_request_enable() from struct pinmux_ops.

Please refer to
https://docs.kernel.org/driver-api/pin-control.html

I know this means more work and is kind of complex. But drivers/pinctrl has a lot of examples you can follow, for example drivers/pinctrl/pinctrl-sx150x.c and other simple multipurpose chips.

Yours,
Linus Walleij

#11 lore raw
In reply to Linus Walleij

Hi Linus,

Sorry for the long delay. I did work on adding the pinctrl driver besides the gpio driver and I am working on testing it. I added the following to the gpio driver:
gc->set = mlxbf3_gpio_set;
gc->direction_input = mlxbf3_gpio_direction_input;
gc->direction_output = mlxbf3_gpio_direction_output;
gc->request = gpiochip_generic_request;
gc->free = gpiochip_generic_free;

In the pinctrl driver, I defined the following:
static const struct pinmux_ops mlxbf_pmx_ops = {
.get_functions_count = mlxbf_pmx_get_funcs_count,
.get_function_name = mlxbf_pmx_get_func_name,
.get_function_groups = mlxbf_pmx_get_groups,
.set_mux = mlxbf_pmx_set,
.gpio_request_enable = mlxbf_gpio_request_enable,
.gpio_disable_free = mlxbf_gpio_disable_free,
};

During testing, I use the sysfs to change the gpio value as follows:
Cd /sys/class/gpio
echo 480 > export
When I do the export, I see that gpiochip_generic_request is being called which calls .gpio_request_enable = mlxbf_gpio_request_enable.

Is this how it also works in other driver? Or am I missing something?
I wanted to disallow muxing from user space. I would like that to be controlled by the ACPI table only. For example, use devm_gpio_request from some other driver if needed.

Thanks.
Asmaa
-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Wednesday, May 18, 2022 9:51 AM
To: Asmaa Mnebhi <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 1/1] Add driver for Mellanox BlueField-3 GPIO controller
Importance: High

Quoted 10 lines · Asmaa Mnebhi

So these GPIO pins are assigned one specific HW functionality on the boards and software should never change them.

By default, for security purposes, I think we shouldn't let the user have the option to control the GPIO pins since they have a specific HW functionality.

But for bringup/debug purposes, we would like to support the option of software being able to change these pin values. We also might have customers that choose to change the default HW connection of a certain GPIO pin and connect it to control their LEDs for instance.

The fact that the usecase is bringup/debug does not mean we cut corners and do "quick fixes". The proper APIs have to be implemented, the alternative is to not submit the driver at all.

What I hear is that these pins have two modes:

1. Used for a device (I2C etc)
2. Used as GPIO by setting a bit in YU_GPIO_FW_CONTROL_SET

This is two pin control multiplexing states already.

So this should have a simple pin control driver as back-end with the GPIO as front end. A shortcut to enabling pins into GPIO mode can be provided using .gpio_request_enable() from struct pinmux_ops.

Please refer to
https://docs.kernel.org/driver-api/pin-control.html

I know this means more work and is kind of complex. But drivers/pinctrl has a lot of examples you can follow, for example drivers/pinctrl/pinctrl-sx150x.c and other simple multipurpose chips.

Yours,
Linus Walleij

#12 lore raw
Quoted 4 lines · Asmaa Mnebhi

During testing, I use the sysfs to change the gpio value as follows:
Cd /sys/class/gpio
echo 480 > export
When I do the export, I see that gpiochip_generic_request is being called which calls .gpio_request_enable = mlxbf_gpio_request_enable.

Yes but don't use the deprecated sysfs to test GPIO, use libgpiod
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/

Quoted 1 line

Is this how it also works in other driver? Or am I missing something?

The gpio_chip usually works as a front end for pin control.

Quoted 1 line

I wanted to disallow muxing from user space.

If you ask for a GPIO then it will be muxed in if you implement .gpio_request_enable().

If you want to make it impossible to use certain gpios alter .valid_mask.

If you don't want people to use the sysfs ABI (which by the way requires you to first select the "CONFIG_EXPERT" option) then do not compile it into the kernel. It is a big risk to use it in any case, so just don't.

If you use the character device (which is enabled by default), you can set permissions on /dev/gpiochipN such that only privileged users can access it, just like you protect any other block/character device.

Quoted 1 line

I would like that to be controlled by the ACPI table only.

I don't know if it is possible to restrict GPIOs to just be used from ACPI.

Quoted 1 line

For example, use devm_gpio_request from some other driver if needed.

If you only want other kernel consumers to use GPIOs, the disable the sysfs ABI, and also disable the character device, then only the kernel can use GPIOs.

Yours,
Linus Walleij

#13 lore raw

Thank you for your response! All clear!

-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Friday, September 2, 2022 5:55 PM
To: Asmaa Mnebhi <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 1/1] Add driver for Mellanox BlueField-3 GPIO controller
Importance: High

Quoted 4 lines · Asmaa Mnebhi

During testing, I use the sysfs to change the gpio value as follows:
Cd /sys/class/gpio
echo 480 > export
When I do the export, I see that gpiochip_generic_request is being called which calls .gpio_request_enable = mlxbf_gpio_request_enable.

Yes but don't use the deprecated sysfs to test GPIO, use libgpiod https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/

Quoted 1 line

Is this how it also works in other driver? Or am I missing something?

The gpio_chip usually works as a front end for pin control.

Quoted 1 line

I wanted to disallow muxing from user space.

If you ask for a GPIO then it will be muxed in if you implement .gpio_request_enable().

If you want to make it impossible to use certain gpios alter .valid_mask.

If you don't want people to use the sysfs ABI (which by the way requires you to first select the "CONFIG_EXPERT" option) then do not compile it into the kernel. It is a big risk to use it in any case, so just don't.

If you use the character device (which is enabled by default), you can set permissions on /dev/gpiochipN such that only privileged users can access it, just like you protect any other block/character device.

Quoted 1 line

I would like that to be controlled by the ACPI table only.

I don't know if it is possible to restrict GPIOs to just be used from ACPI.

Quoted 1 line

For example, use devm_gpio_request from some other driver if needed.

If you only want other kernel consumers to use GPIOs, the disable the sysfs ABI, and also disable the character device, then only the kernel can use GPIOs.

Yours,
Linus Walleij

#14 lore raw
Quoted 4 lines · Asmaa Mnebhi

-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Friday, September 2, 2022 5:55 PM
On Fri, Sep 2, 2022 at 5:55 PM Asmaa Mnebhi <[email protected]> wrote:

...

Quoted 3 lines
Quoted 1 line

I would like that to be controlled by the ACPI table only.

I don't know if it is possible to restrict GPIOs to just be used from ACPI.

On Intel platforms that's done with HW assistance, i.e. firmware configures special registers inside pin control / GPIO address space that reflect ownership. The driver rejects any attempts to request such GPIOs. As a workaround one may simply disable all user space interfaces (as you already discussed in this thread).

Signature · 2 lines
With Best Regards,
Andy Shevchenko