Skip to contentSkip to conversation

gpio: add driver for Mellanox BlueField 2 GPIO controller

PATCH Superseded Asmaa Mnebhi 2 participants 3 messages Feb 21, 2020 GPIO

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover gpio: add driver for Mellanox BlueField 2 GPIO controller

This patch adds support for the GPIO controller used by Mellanox BlueFIeld 2 SOCs.

Asmaa Mnebhi (1):
gpio: add driver for Mellanox BlueField 2 GPIO controller

 drivers/gpio/Kconfig       |   7 +
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-mlxbf2.c | 411 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 419 insertions(+)
 create mode 100644 drivers/gpio/gpio-mlxbf2.c
Signature · 1 line
2.1.2
#1 lore raw

PATCH 1/1 gpio: add driver for Mellanox BlueField 2 GPIO controller

This patch adds support for the GPIO controller used by Mellanox BlueField 2 SOCs.

---
 drivers/gpio/Kconfig       |   7 +
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-mlxbf2.c | 411 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 419 insertions(+)
 create mode 100644 drivers/gpio/gpio-mlxbf2.c
drivers/gpio/Kconfig +7 -0
index b8013cf..6234ccc 100644
@@ -1399,6 +1399,13 @@ config GPIO_MLXBF
 	help
 	  Say Y here if you want GPIO support on Mellanox BlueField SoC.
 
+config GPIO_MLXBF2
+	tristate "Mellanox BlueField 2 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 2 SoC.
+
 config GPIO_ML_IOH
 	tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
 	depends on X86 || COMPILE_TEST
drivers/gpio/Makefile +1 -0
index 0b57126..b2cfc21 100644
@@ -93,6 +93,7 @@ obj-$(CONFIG_GPIO_MENZ127)		+= gpio-menz127.o
 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_MM_LANTIQ)		+= gpio-mm-lantiq.o
 obj-$(CONFIG_GPIO_MOCKUP)		+= gpio-mockup.o
 obj-$(CONFIG_GPIO_MOXTET)		+= gpio-moxtet.o
drivers/gpio/gpio-mlxbf2.c new file +411 -0

411 lines not on this page · raw message

Signature · 1 line
2.1.2
#2 lore raw

Hi Asmaa,

thanks for your patch!

Quoted 4 lines · Asmaa Mnebhi

This patch adds support for the GPIO controller used by Mellanox BlueField 2 SOCs.

(...)

drivers/gpio/Kconfig config GPIO_MLXBF · line 1405

Quoted 4 lines
drivers/gpio/Kconfig +4 -0
+config GPIO_MLXBF2
+       tristate "Mellanox BlueField 2 SoC GPIO"
+       depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST)
+       select GPIO_GENERIC

This selects GPIO_GENERIC but does not make use of it?

drivers/gpio/gpio-mlxbf2.c line 62

Quoted 12 lines
drivers/gpio/gpio-mlxbf2.c new file +12 -0
+/*
+ * gpio[x] block registers and their offset
+ */
+#define YU_GPIO_DATAOUT                        0x00
+#define YU_GPIO_DATAIN                 0x04
+#define YU_GPIO_MODE1                  0x08
+#define YU_GPIO_MODE0                  0x0c
+#define YU_GPIO_DATASET                        0x14
+#define YU_GPIO_DATACLEAR              0x18
+#define YU_GPIO_MODE1_CLEAR            0x50
+#define YU_GPIO_MODE0_SET              0x54
+#define YU_GPIO_MODE0_CLEAR            0x58

This however looks a lot like it could use GPIO_GENERIC.

drivers/gpio/gpio-mlxbf2.c line 88

Quoted 2 lines
drivers/gpio/gpio-mlxbf2.c new file +2 -0
+       /* Must hold this lock to modify shared data. */
+       spinlock_t lock;

Incidentally GPIO_GENERIC accessors also contains a lock so you don't need to implement that either.

drivers/gpio/gpio-mlxbf2.c line 315

Quoted 4 lines
drivers/gpio/gpio-mlxbf2.c new file +4 -0
+       /* All 3 YU GPIO block address */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, GPIO_BLOCKS);
+       if (!res)
+               return -ENODEV;

If there are 3 GPIO blocks, simply spawn 3 struct gpio_chip's so you can use the generic accessors?

drivers/gpio/gpio-mlxbf2.c line 324

Quoted 4 lines
drivers/gpio/gpio-mlxbf2.c new file +4 -0
+       /* YU ARM GPIO Lock address */
+       res = platform_get_resource(pdev, IORESOURCE_MEM, ARM_GPIO_LOCK);
+       if (!res)
+               return -ENOMEM;

If the direction setting needs some special lock/unlock to happen, why not just override the .set/get_direction() callbacks?

I would recommend:

- Split in one gpio_chip per instance
- Look at drivers/gpio/gpio-ftgpio010.c on how to populate callbacks for each with bgpio_init()
- In struct mlxbf2_gpio_state create some custom direction callbacks to store what comes back in direction_input/output and indirect the calls from direction_input/output to these with locking folded in.

Yours,
Linus Walleij